"bug fixes and cleanups from Rick Macklem"
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sun, 22 Oct 1989 03:33:02 +0000 (19:33 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sun, 22 Oct 1989 03:33:02 +0000 (19:33 -0800)
SCCS-vsn: sys/nfs/nfs_bio.c 7.3
SCCS-vsn: sys/nfs/nfs_vnops.c 7.7
SCCS-vsn: sys/nfs/nfs_node.c 7.6
SCCS-vsn: sys/nfs/nfs_subs.c 7.9

usr/src/sys/nfs/nfs_bio.c
usr/src/sys/nfs/nfs_node.c
usr/src/sys/nfs/nfs_subs.c
usr/src/sys/nfs/nfs_vnops.c

index c9592c9..21f1112 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)nfs_bio.c   7.2 (Berkeley) %G%
+ *     @(#)nfs_bio.c   7.3 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -95,15 +95,14 @@ nfs_read(vp, uio, offp, ioflag, cred)
                        goto out;
                if (error = nfs_getattr(vp, &vattr, cred))
                        goto out;
                        goto out;
                if (error = nfs_getattr(vp, &vattr, cred))
                        goto out;
-               np->n_size = vattr.va_size;
                np->n_mtime = vattr.va_mtime.tv_sec;
        } else {
                if (error = nfs_getattr(vp, &vattr, cred))
                        goto out;
                if (np->n_mtime != vattr.va_mtime.tv_sec) {
                np->n_mtime = vattr.va_mtime.tv_sec;
        } else {
                if (error = nfs_getattr(vp, &vattr, cred))
                        goto out;
                if (np->n_mtime != vattr.va_mtime.tv_sec) {
-                       if (error = nfs_blkflush(vp, (daddr_t)0, np->n_size, TRUE))
+                       if (error = nfs_blkflush(vp, (daddr_t)0,
+                               np->n_size, TRUE))
                                goto out;
                                goto out;
-                       np->n_size = vattr.va_size;
                        np->n_mtime = vattr.va_mtime.tv_sec;
                }
        }
                        np->n_mtime = vattr.va_mtime.tv_sec;
                }
        }
@@ -119,7 +118,7 @@ nfs_read(vp, uio, offp, ioflag, cred)
                        n = diff;
                bn = lbn*(NFS_BIOSIZE/DEV_BSIZE);
                rablock = (lbn+1)*(NFS_BIOSIZE/DEV_BSIZE);
                        n = diff;
                bn = lbn*(NFS_BIOSIZE/DEV_BSIZE);
                rablock = (lbn+1)*(NFS_BIOSIZE/DEV_BSIZE);
-               if (np->n_lastr+1 == lbn)
+               if (np->n_lastr+1 == lbn && np->n_size > (rablock*DEV_BSIZE))
                        error = breada(vp, bn, NFS_BIOSIZE, rablock, NFS_BIOSIZE,
                                cred, &bp);
                else
                        error = breada(vp, bn, NFS_BIOSIZE, rablock, NFS_BIOSIZE,
                                cred, &bp);
                else
@@ -281,40 +280,51 @@ nfs_blkflush(vp, blkno, size, invalidate)
 {
        register struct buf *ep;
        struct buf *dp;
 {
        register struct buf *ep;
        struct buf *dp;
-       daddr_t curblkno, last;
+       daddr_t curblk, nextblk, ecurblk, lastblk;
        int s, error, allerrors = 0;
        int s, error, allerrors = 0;
-
-       last = blkno + btodb(size);
-       for (curblkno = blkno; curblkno <= last;
-            curblkno += (NFS_BIOSIZE / DEV_BSIZE)) {
-               dp = BUFHASH(vp, curblkno);
+     
+       /*
+        * Iterate through each possible hash chain.
+        */
+       lastblk = blkno + btodb(size+DEV_BSIZE-1) - 1;
+       for (curblk = blkno; curblk <= lastblk; curblk = nextblk) {
+#if RND & (RND-1)
+               nextblk = ((curblk / RND) + 1) * RND;
+#else
+               nextblk = ((curblk & ~(RND-1)) + RND);
+#endif
+               ecurblk = nextblk > lastblk ? lastblk : nextblk - 1;
+               dp = BUFHASH(vp, curblk);
 loop:
 loop:
-               for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
-                       if (ep->b_vp != vp || (ep->b_flags & B_INVAL))
-                               continue;
-                       if (curblkno != ep->b_blkno)
-                               continue;
-                       s = splbio();
-                       if (ep->b_flags & B_BUSY) {
-                               ep->b_flags |= B_WANTED;
-                               sleep((caddr_t)ep, PRIBIO+1);
-                               splx(s);
-                               goto loop;
-                       }
-                       splx(s);
-                       notavail(ep);
-                       if (ep->b_flags & B_DELWRI) {
-                               ep->b_flags &= ~B_ASYNC;
-                               if (error = bwrite(ep))
-                                       allerrors = error;
-                               goto loop;
-                       }
+               for (ep = dp->b_forw; ep != dp; ep = ep->b_forw) {
+                       if (ep->b_vp != vp || (ep->b_flags & B_INVAL))
+                               continue;
+                       /* look for overlap */
+                       if (ep->b_bcount == 0 || ep->b_blkno > ecurblk ||
+                           ep->b_blkno + btodb(ep->b_bcount) <= curblk)
+                               continue;
+                       s = splbio();
+                       if (ep->b_flags&B_BUSY) {
+                               ep->b_flags |= B_WANTED;
+                               sleep((caddr_t)ep, PRIBIO+1);
+                               splx(s);
+                               goto loop;
+                       }
+                       if (ep->b_flags & B_DELWRI) {
+                               splx(s);
+                               notavail(ep);
+                               if (error = bwrite(ep))
+                                       allerrors = error;
+                               goto loop;
+                       }
+                       splx(s);
                        if (invalidate) {
                        if (invalidate) {
+                               notavail(ep);
                                ep->b_flags |= B_INVAL;
                                brelvp(ep);
                                ep->b_flags |= B_INVAL;
                                brelvp(ep);
+                               brelse(ep);
                        }
                        }
-                       brelse(ep);
-               }
+               }
        }
        return (allerrors);
 }
        }
        return (allerrors);
 }
index 7c28b29..06f8c1e 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)nfs_node.c  7.5 (Berkeley) %G%
+ *     @(#)nfs_node.c  7.6 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -181,9 +181,7 @@ loop:
        np->n_flag = NLOCKED;
        insque(np, nh);
        bcopy((caddr_t)fhp, (caddr_t)&np->n_fh, NFSX_FH);
        np->n_flag = NLOCKED;
        insque(np, nh);
        bcopy((caddr_t)fhp, (caddr_t)&np->n_fh, NFSX_FH);
-#ifndef notyet
        cache_purge(vp);
        cache_purge(vp);
-#endif
        np->n_attrstamp = 0;
        np->n_sillyrename = (struct sillyrename *)0;
        np->n_id = ++nextnfsnodeid;
        np->n_attrstamp = 0;
        np->n_sillyrename = (struct sillyrename *)0;
        np->n_id = ++nextnfsnodeid;
@@ -341,9 +339,6 @@ nfs_lock(vp)
 {
        register struct nfsnode *np = VTONFS(vp);
 
 {
        register struct nfsnode *np = VTONFS(vp);
 
-       if (np->n_flag & NLOCKED)
-               printf("pid %d hit locked nfsnode=0x%x\n",
-                   u.u_procp->p_pid, np);
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
                sleep((caddr_t)np, PINOD);
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
                sleep((caddr_t)np, PINOD);
@@ -359,15 +354,6 @@ nfs_unlock(vp)
 {
        register struct nfsnode *np = VTONFS(vp);
 
 {
        register struct nfsnode *np = VTONFS(vp);
 
-       if ((np->n_flag & NLOCKED) == 0) {
-               printf("pid %d unlocking unlocked nfsnode=0x%x ",
-                   u.u_procp->p_pid, np);
-               printf("fh0=0x%x fh1=0x%x fh2=0x%x fh3=0x%x fh4=0x%x fh5=0x%x fh6=0x%x fh7=0x%x\n",
-                       np->n_fh.fh_bytes[0],np->n_fh.fh_bytes[1],
-                       np->n_fh.fh_bytes[2],np->n_fh.fh_bytes[3],
-                       np->n_fh.fh_bytes[4],np->n_fh.fh_bytes[5],
-                       np->n_fh.fh_bytes[6],np->n_fh.fh_bytes[7]);
-       }
        np->n_flag &= ~NLOCKED;
        if (np->n_flag & NWANT) {
                np->n_flag &= ~NWANT;
        np->n_flag &= ~NLOCKED;
        if (np->n_flag & NWANT) {
                np->n_flag &= ~NWANT;
index d383917..553574e 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)nfs_subs.c  7.8 (Berkeley) %G%
+ *     @(#)nfs_subs.c  7.9 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -622,6 +622,24 @@ nfs_loadattrcache(vp, mdp, dposp, vaper)
        vap->va_gen = 0;
        vap->va_flags = 0;
        np->n_attrstamp = time.tv_sec;
        vap->va_gen = 0;
        vap->va_flags = 0;
        np->n_attrstamp = time.tv_sec;
+       /*
+        * If v_type == VNON it is a new node, so fill in the v_type,
+        * n_mtime fields. For v_type == VCHR also set the vnode ops
+        * and v_rdev fields.
+        */
+       if (vp->v_type == VNON) {
+               vp->v_type = vap->va_type;
+               np->n_mtime = vap->va_mtime.tv_sec;
+               /*
+                * Handling special files...
+                * For VCHR, use the nfs_node, but with the nfsv2chr_vnodeops
+                * that are a mix of nfs and blk vnode ops.
+                */
+               if (vp->v_type == VCHR) {
+                       vp->v_rdev = vap->va_rdev;
+                       vp->v_op = &nfsv2chr_vnodeops;
+               }
+       }
        *dposp = dpos;
        *mdp = md;
        if (vaper != NULL) {
        *dposp = dpos;
        *mdp = md;
        if (vaper != NULL) {
@@ -647,7 +665,9 @@ nfs_getattrcache(vp, vap)
        if ((time.tv_sec-np->n_attrstamp) < NFS_ATTRTIMEO) {
                nfsstats.attrcache_hits++;
                bcopy((caddr_t)&np->n_vattr,(caddr_t)vap,sizeof(struct vattr));
        if ((time.tv_sec-np->n_attrstamp) < NFS_ATTRTIMEO) {
                nfsstats.attrcache_hits++;
                bcopy((caddr_t)&np->n_vattr,(caddr_t)vap,sizeof(struct vattr));
-               if ((np->n_flag & NMODIFIED) && (np->n_size > vap->va_size))
+               if ((np->n_flag & NMODIFIED) == 0)
+                       np->n_size = vap->va_size;
+               else if (np->n_size > vap->va_size)
                        vap->va_size = np->n_size;
                return (0);
        } else {
                        vap->va_size = np->n_size;
                return (0);
        } else {
index d6c687e..8641874 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)nfs_vnops.c 7.6 (Berkeley) %G%
+ *     @(#)nfs_vnops.c 7.7 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -122,9 +122,7 @@ int blk_open(),
        blk_read(),
        blk_write(),
        blk_ioctl(),
        blk_read(),
        blk_write(),
        blk_ioctl(),
-       blk_select(),
-       ufs_bmap(),
-       blk_strategy();
+       blk_select();
 
 struct vnodeops nfsv2chr_vnodeops = {
        vfs_noop,
 
 struct vnodeops nfsv2chr_vnodeops = {
        vfs_noop,
@@ -154,8 +152,8 @@ struct vnodeops nfsv2chr_vnodeops = {
        nfs_inactive,
        nfs_lock,
        nfs_unlock,
        nfs_inactive,
        nfs_lock,
        nfs_unlock,
-       ufs_bmap,
-       blk_strategy,
+       vfs_noop,
+       vfs_noop,
 };
 
 extern u_long nfs_procids[NFS_NPROCS];
 };
 
 extern u_long nfs_procids[NFS_NPROCS];
@@ -323,6 +321,7 @@ nfs_setattr(vp, vap, cred)
 {
        register struct nfsv2_sattr *sp;
        nfsm_vars;
 {
        register struct nfsv2_sattr *sp;
        nfsm_vars;
+       struct nfsnode *np;
 
        nfsstats.rpccnt[NFSPROC_SETATTR]++;
        nfsm_reqhead(nfs_procids[NFSPROC_SETATTR], cred, NFSX_FH+NFSX_SATTR);
 
        nfsstats.rpccnt[NFSPROC_SETATTR]++;
        nfsm_reqhead(nfs_procids[NFSPROC_SETATTR], cred, NFSX_FH+NFSX_SATTR);
@@ -341,8 +340,13 @@ nfs_setattr(vp, vap, cred)
        else
                sp->sa_gid = txdr_unsigned(vap->va_gid);
        sp->sa_size = txdr_unsigned(vap->va_size);
        else
                sp->sa_gid = txdr_unsigned(vap->va_gid);
        sp->sa_size = txdr_unsigned(vap->va_size);
-       if (vap->va_size != VNOVAL)
-               VTONFS(vp)->n_size = vap->va_size;
+       if (vap->va_size != VNOVAL) {
+               np = VTONFS(vp);
+               if (np->n_flag & NMODIFIED) {
+                       np->n_flag &= ~NMODIFIED;
+                       nfs_blkflush(vp, (daddr_t)0, np->n_size, TRUE);
+               }
+       }
        txdr_time(&vap->va_atime, &sp->sa_atime);
        txdr_time(&vap->va_mtime, &sp->sa_mtime);
        nfsm_request(vp);
        txdr_time(&vap->va_atime, &sp->sa_atime);
        txdr_time(&vap->va_mtime, &sp->sa_mtime);
        nfsm_request(vp);
@@ -377,7 +381,6 @@ nfs_lookup(vp, ndp)
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        flag = ndp->ni_nameiop & OPFLAG;
        wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT);
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        flag = ndp->ni_nameiop & OPFLAG;
        wantparent = ndp->ni_nameiop & (LOCKPARENT|WANTPARENT);
-#ifndef notyet
        if ((error = cache_lookup(ndp)) && error != ENOENT) {
                struct vattr vattr;
                int vpid;
        if ((error = cache_lookup(ndp)) && error != ENOENT) {
                struct vattr vattr;
                int vpid;
@@ -403,10 +406,6 @@ nfs_lookup(vp, ndp)
                if (vpid == vdp->v_id &&
                   !nfs_getattr(vdp, &vattr, ndp->ni_cred)) {
                        nfsstats.lookupcache_hits++;
                if (vpid == vdp->v_id &&
                   !nfs_getattr(vdp, &vattr, ndp->ni_cred)) {
                        nfsstats.lookupcache_hits++;
-                       if (vdp->v_type == VNON) {
-                               vdp->v_type = vattr.va_type;
-                               VTONFS(vdp)->n_mtime = vattr.va_mtime.tv_sec;
-                       }
                        return (0);
                }
                nfs_nput(vdp);
                        return (0);
                }
                nfs_nput(vdp);
@@ -415,7 +414,6 @@ nfs_lookup(vp, ndp)
        }
        error = 0;
        nfsstats.lookupcache_misses++;
        }
        error = 0;
        nfsstats.lookupcache_misses++;
-#endif
        nfsstats.rpccnt[NFSPROC_LOOKUP]++;
        len = ndp->ni_namelen;
        nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len));
        nfsstats.rpccnt[NFSPROC_LOOKUP]++;
        len = ndp->ni_namelen;
        nfsm_reqhead(nfs_procids[NFSPROC_LOOKUP], ndp->ni_cred, NFSX_FH+NFSX_UNSIGNED+nfsm_rndup(len));
@@ -456,10 +454,6 @@ nfsmout:
                        m_freem(mrep);
                        return (error);
                }
                        m_freem(mrep);
                        return (error);
                }
-               if (newvp->v_type == VNON) {
-                       newvp->v_type = np->n_vattr.va_type;
-                       np->n_mtime = np->n_vattr.va_mtime.tv_sec;
-               }
                ndp->ni_vp = newvp;
                if (!lockparent)
                        nfs_unlock(vp);
                ndp->ni_vp = newvp;
                if (!lockparent)
                        nfs_unlock(vp);
@@ -517,28 +511,12 @@ nfsmout:
                return (error);
        }
        m_freem(mrep);
                return (error);
        }
        m_freem(mrep);
-       if (newvp->v_type == VNON) {
-               newvp->v_type = np->n_vattr.va_type;
-               np->n_mtime = np->n_vattr.va_mtime.tv_sec;
-       }
 
 
-       /*
-        * Handling special files...
-        * For VCHR, use the nfs_node, but with the nfsv2chr_vnodeops
-        * that are a mix of nfs and blk vnode ops.
-        * Also, returns right away to avoid loading the name cache
-        */
-       if (newvp->v_type == VCHR) {
-               newvp->v_rdev = np->n_vattr.va_rdev;
-               newvp->v_op = &nfsv2chr_vnodeops;
-       }
        if (vp != newvp && (!lockparent || *ndp->ni_next != '\0'))
                nfs_unlock(vp);
        ndp->ni_vp = newvp;
        if (vp != newvp && (!lockparent || *ndp->ni_next != '\0'))
                nfs_unlock(vp);
        ndp->ni_vp = newvp;
-#ifndef notyet
        if (error == 0 && ndp->ni_makeentry)
                cache_enter(ndp);
        if (error == 0 && ndp->ni_makeentry)
                cache_enter(ndp);
-#endif
        return (error);
 }
 
        return (error);
 }
 
@@ -756,13 +734,11 @@ nfs_rename(sndp, tndp)
        nfsm_strtom(tndp->ni_dent.d_name,tndp->ni_dent.d_namlen,NFS_MAXNAMLEN);
        nfsm_request(sndp->ni_dvp);
        nfsm_reqdone;
        nfsm_strtom(tndp->ni_dent.d_name,tndp->ni_dent.d_namlen,NFS_MAXNAMLEN);
        nfsm_request(sndp->ni_dvp);
        nfsm_reqdone;
-#ifndef notyet
        if (sndp->ni_vp->v_type == VDIR) {
                if (tndp->ni_vp != NULL && tndp->ni_vp->v_type == VDIR)
                        cache_purge(tndp->ni_dvp);
                cache_purge(sndp->ni_dvp);
        }
        if (sndp->ni_vp->v_type == VDIR) {
                if (tndp->ni_vp != NULL && tndp->ni_vp->v_type == VDIR)
                        cache_purge(tndp->ni_dvp);
                cache_purge(sndp->ni_dvp);
        }
-#endif
        nfs_abortop(sndp);
        nfs_abortop(tndp);
        return (error);
        nfs_abortop(sndp);
        nfs_abortop(tndp);
        return (error);
@@ -893,10 +869,8 @@ nfs_rmdir(ndp)
        nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN);
        nfsm_request(ndp->ni_dvp);
        nfsm_reqdone;
        nfsm_strtom(ndp->ni_dent.d_name, ndp->ni_dent.d_namlen, NFS_MAXNAMLEN);
        nfsm_request(ndp->ni_dvp);
        nfsm_reqdone;
-#ifndef notyet
        cache_purge(ndp->ni_dvp);
        cache_purge(ndp->ni_vp);
        cache_purge(ndp->ni_dvp);
        cache_purge(ndp->ni_vp);
-#endif
        nfs_nput(ndp->ni_vp);
        nfs_nput(ndp->ni_dvp);
        return (error);
        nfs_nput(ndp->ni_vp);
        nfs_nput(ndp->ni_dvp);
        return (error);