BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / nfs / nfs_bio.c
index f5bd53a..44a48a1 100644 (file)
@@ -5,30 +5,47 @@
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  Neither the name of the University nor the names of
- * its contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)nfs_bio.c   7.16 (Berkeley) 6/28/90
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)nfs_bio.c   7.19 (Berkeley) 4/16/91
  */
 
 #include "param.h"
  */
 
 #include "param.h"
-#include "user.h"
+#include "proc.h"
 #include "buf.h"
 #include "buf.h"
+#include "uio.h"
+#include "namei.h"
 #include "vnode.h"
 #include "trace.h"
 #include "mount.h"
 #include "vnode.h"
 #include "trace.h"
 #include "mount.h"
+#include "resourcevar.h"
+
 #include "nfsnode.h"
 #include "nfsv2.h"
 #include "nfs.h"
 #include "nfsnode.h"
 #include "nfsv2.h"
 #include "nfs.h"
@@ -60,8 +77,10 @@ nfs_bioread(vp, uio, ioflag, cred)
 #ifdef lint
        ioflag = ioflag;
 #endif /* lint */
 #ifdef lint
        ioflag = ioflag;
 #endif /* lint */
+#ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ)
                panic("nfs_read mode");
        if (uio->uio_rw != UIO_READ)
                panic("nfs_read mode");
+#endif
        if (uio->uio_resid == 0)
                return (0);
        if (uio->uio_offset < 0 && vp->v_type != VDIR)
        if (uio->uio_resid == 0)
                return (0);
        if (uio->uio_offset < 0 && vp->v_type != VDIR)
@@ -85,11 +104,13 @@ nfs_bioread(vp, uio, ioflag, cred)
                        vinvalbuf(vp, TRUE);
                        np->n_attrstamp = 0;
                        np->n_direofoffset = 0;
                        vinvalbuf(vp, TRUE);
                        np->n_attrstamp = 0;
                        np->n_direofoffset = 0;
-                       if (error = nfs_dogetattr(vp, &vattr, cred, 1))
+                       if (error = nfs_dogetattr(vp, &vattr, cred, 1,
+                           uio->uio_procp))
                                return (error);
                        np->n_mtime = vattr.va_mtime.tv_sec;
                } else {
                                return (error);
                        np->n_mtime = vattr.va_mtime.tv_sec;
                } else {
-                       if (error = nfs_dogetattr(vp, &vattr, cred, 1))
+                       if (error = nfs_dogetattr(vp, &vattr, cred, 1,
+                           uio->uio_procp))
                                return (error);
                        if (np->n_mtime != vattr.va_mtime.tv_sec) {
                                np->n_direofoffset = 0;
                                return (error);
                        if (np->n_mtime != vattr.va_mtime.tv_sec) {
                                np->n_direofoffset = 0;
@@ -134,8 +155,8 @@ nfs_bioread(vp, uio, ioflag, cred)
            case VDIR:
                nfsstats.biocache_readdirs++;
                on = 0;
            case VDIR:
                nfsstats.biocache_readdirs++;
                on = 0;
-               error = bread(vp, uio->uio_offset, DIRBLKSIZ, cred, &bp);
-               n = MIN(uio->uio_resid, DIRBLKSIZ - bp->b_resid);
+               error = bread(vp, uio->uio_offset, NFS_DIRBLKSIZ, cred, &bp);
+               n = MIN(uio->uio_resid, NFS_DIRBLKSIZ - bp->b_resid);
                break;
            };
            if (error) {
                break;
            };
            if (error) {
@@ -170,6 +191,7 @@ nfs_write(vp, uio, ioflag, cred)
        int ioflag;
        struct ucred *cred;
 {
        int ioflag;
        struct ucred *cred;
 {
+       struct proc *p = uio->uio_procp;
        register int biosize;
        struct buf *bp;
        struct nfsnode *np = VTONFS(vp);
        register int biosize;
        struct buf *bp;
        struct nfsnode *np = VTONFS(vp);
@@ -177,8 +199,12 @@ nfs_write(vp, uio, ioflag, cred)
        daddr_t lbn, bn;
        int n, on, error = 0;
 
        daddr_t lbn, bn;
        int n, on, error = 0;
 
+#ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_WRITE)
                panic("nfs_write mode");
        if (uio->uio_rw != UIO_WRITE)
                panic("nfs_write mode");
+       if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc)
+               panic("nfs_write proc");
+#endif
        if (vp->v_type != VREG)
                return (EIO);
        /* Should we try and do this ?? */
        if (vp->v_type != VREG)
                return (EIO);
        /* Should we try and do this ?? */
@@ -189,11 +215,11 @@ nfs_write(vp, uio, ioflag, cred)
                }
                if (ioflag & IO_APPEND) {
                        np->n_attrstamp = 0;
                }
                if (ioflag & IO_APPEND) {
                        np->n_attrstamp = 0;
-                       if (error = nfs_dogetattr(vp, &vattr, cred, 1))
+                       if (error = nfs_dogetattr(vp, &vattr, cred, 1, p))
                                return (error);
                        uio->uio_offset = np->n_size;
                }
                                return (error);
                        uio->uio_offset = np->n_size;
                }
-               return (nfs_writerpc(vp, uio, cred, u.u_procp));
+               return (nfs_writerpc(vp, uio, cred));
        }
 #ifdef notdef
        cnt = uio->uio_resid;
        }
 #ifdef notdef
        cnt = uio->uio_resid;
@@ -208,8 +234,8 @@ nfs_write(vp, uio, ioflag, cred)
         * file servers have no limits, i don't think it matters
         */
        if (uio->uio_offset + uio->uio_resid >
         * file servers have no limits, i don't think it matters
         */
        if (uio->uio_offset + uio->uio_resid >
-             u.u_rlimit[RLIMIT_FSIZE].rlim_cur) {
-               psignal(u.u_procp, SIGXFSZ);
+             p->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
+               psignal(p, SIGXFSZ);
                return (EFBIG);
        }
        /*
                return (EFBIG);
        }
        /*
@@ -224,8 +250,10 @@ nfs_write(vp, uio, ioflag, cred)
                lbn = uio->uio_offset / biosize;
                on = uio->uio_offset & (biosize-1);
                n = MIN((unsigned)(biosize - on), uio->uio_resid);
                lbn = uio->uio_offset / biosize;
                on = uio->uio_offset & (biosize-1);
                n = MIN((unsigned)(biosize - on), uio->uio_resid);
-               if (uio->uio_offset+n > np->n_size)
+               if (uio->uio_offset+n > np->n_size) {
                        np->n_size = uio->uio_offset+n;
                        np->n_size = uio->uio_offset+n;
+                       vnode_pager_setsize(vp, np->n_size);
+               }
                bn = lbn*(biosize/DEV_BSIZE);
 again:
                bp = getblk(vp, bn, biosize);
                bn = lbn*(biosize/DEV_BSIZE);
 again:
                bp = getblk(vp, bn, biosize);
@@ -243,7 +271,7 @@ again:
                                bp->b_dirtyoff = MIN(on, bp->b_dirtyoff);
                                bp->b_dirtyend = MAX((on+n), bp->b_dirtyend);
                        } else {
                                bp->b_dirtyoff = MIN(on, bp->b_dirtyoff);
                                bp->b_dirtyend = MAX((on+n), bp->b_dirtyend);
                        } else {
-                               bp->b_proc = u.u_procp;
+                               bp->b_proc = p;
                                if (error = bwrite(bp))
                                        return (error);
                                goto again;
                                if (error = bwrite(bp))
                                        return (error);
                                goto again;