Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/miscfs Slightly clean-up layerfs and nullfs: update the ...



details:   https://anonhg.NetBSD.org/src/rev/da6c05122a51
branches:  trunk
changeset: 755991:da6c05122a51
user:      rmind <rmind%NetBSD.org@localhost>
date:      Fri Jul 02 03:16:00 2010 +0000

description:
Slightly clean-up layerfs and nullfs: update the big description more to
the reality (remove duplicate one in nullfs, merge some differences from
it), KNF, improve and update some comments, add few KASSERT()s, remove
unused declarations, avoid double inclusion of headers, misc.

No functional changes.

diffstat:

 sys/miscfs/genfs/layer_extern.h |   19 +-
 sys/miscfs/genfs/layer_subr.c   |  203 +++++++++++---------------
 sys/miscfs/genfs/layer_vfsops.c |   96 +++++-------
 sys/miscfs/genfs/layer_vnops.c  |  291 +++++++++++++++------------------------
 sys/miscfs/nullfs/null.h        |   17 +-
 sys/miscfs/nullfs/null_vfsops.c |  116 ++++-----------
 sys/miscfs/nullfs/null_vnops.c  |  192 ++++---------------------
 7 files changed, 322 insertions(+), 612 deletions(-)

diffs (truncated from 1670 to 300 lines):

diff -r c6e7034003a9 -r da6c05122a51 sys/miscfs/genfs/layer_extern.h
--- a/sys/miscfs/genfs/layer_extern.h   Thu Jul 01 19:50:11 2010 +0000
+++ b/sys/miscfs/genfs/layer_extern.h   Fri Jul 02 03:16:00 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: layer_extern.h,v 1.24 2008/01/28 14:31:18 dholland Exp $       */
+/*     $NetBSD: layer_extern.h,v 1.25 2010/07/02 03:16:00 rmind Exp $  */
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -32,6 +32,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+
 /*
  * Copyright (c) 1992, 1993, 1995
  *     The Regents of the University of California.  All rights reserved.
@@ -65,23 +66,26 @@
  *
  */
 
+#ifndef _MISCFS_GENFS_LAYER_EXTERN_H_
+#define _MISCFS_GENFS_LAYER_EXTERN_H_
+
 /*
  * Routines defined by layerfs
  */
 
-/* misc routines in layer_subr.c */
+/* Routines to manage nodes. */
 void   layerfs_init(void);
 void   layerfs_done(void);
 int    layer_node_alloc(struct mount *, struct vnode *, struct vnode **);
 int    layer_node_create(struct mount *, struct vnode *, struct vnode **);
-struct vnode *
-       layer_node_find(struct mount *, struct vnode *);
+struct vnode *layer_node_find(struct mount *, struct vnode *);
+
 #define LOG2_SIZEVNODE 7               /* log2(sizeof struct vnode) */
 #define LAYER_NHASH(lmp, vp) \
        (&((lmp)->layerm_node_hashtbl[(((u_long)vp)>>LOG2_SIZEVNODE) & \
                (lmp)->layerm_node_hash]))
 
-/* vfs routines */
+/* VFS routines */
 int    layerfs_start(struct mount *, int);
 int    layerfs_root(struct mount *, struct vnode **);
 int    layerfs_quotactl(struct mount *, int, uid_t, void *);
@@ -90,8 +94,7 @@
 int    layerfs_vget(struct mount *, ino_t, struct vnode **);
 int    layerfs_fhtovp(struct mount *, struct fid *, struct vnode **);
 int    layerfs_vptofh(struct vnode *, struct fid *, size_t *);
-int    layerfs_snapshot(struct mount *, struct vnode *,
-                           struct timespec *);
+int    layerfs_snapshot(struct mount *, struct vnode *, struct timespec *);
 int    layerfs_renamelock_enter(struct mount *);
 void   layerfs_renamelock_exit(struct mount *);
 
@@ -116,3 +119,5 @@
 int    layer_rmdir(void *);
 int    layer_getpages(void *);
 int    layer_putpages(void *);
+
+#endif /* _MISCFS_GENFS_LAYER_EXTERN_H_ */
diff -r c6e7034003a9 -r da6c05122a51 sys/miscfs/genfs/layer_subr.c
--- a/sys/miscfs/genfs/layer_subr.c     Thu Jul 01 19:50:11 2010 +0000
+++ b/sys/miscfs/genfs/layer_subr.c     Fri Jul 02 03:16:00 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: layer_subr.c,v 1.29 2010/06/06 08:01:31 hannken Exp $  */
+/*     $NetBSD: layer_subr.c,v 1.30 2010/07/02 03:16:00 rmind Exp $    */
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -32,6 +32,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
+
 /*
  * Copyright (c) 1992, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -68,7 +69,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.29 2010/06/06 08:01:31 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.30 2010/07/02 03:16:00 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -84,8 +85,6 @@
 #include <miscfs/genfs/layer.h>
 #include <miscfs/genfs/layer_extern.h>
 
-#define        NLAYERNODECACHE 16
-
 #ifdef LAYERFS_DIAGNOSTIC
 int layerfs_debug = 1;
 #endif
@@ -98,34 +97,23 @@
  * alias is removed the lower vnode is vrele'd.
  */
 
-/*
- * Initialise cache headers
- */
 void
 layerfs_init(void)
 {
-#ifdef LAYERFS_DIAGNOSTIC
-       if (layerfs_debug)
-               printf("layerfs_init\n");               /* printed during system boot */
-#endif
+       /* Nothing. */
+}
+
+void
+layerfs_done(void)
+{
+       /* Nothing. */
 }
 
 /*
- * Free global resources of layerfs.
- */
-void
-layerfs_done(void)
-{
-#ifdef LAYERFS_DIAGNOSTIC
-       if (layerfs_debug)
-               printf("layerfs_done\n");               /* printed on layerfs detach */
-#endif
-}
-
-/*
- * Return a locked, VREF'ed alias for lower vnode if already exists, else NULL.
- * The layermp's hashlock must be held on entry.
- * It will be held upon return iff we return NULL.
+ * layer_node_find: find and return alias for lower vnode or NULL.
+ *
+ * => Return alias vnode locked and referenced. if already exists.
+ * => The layermp's hashlock must be held on entry, we will unlock on success.
  */
 struct vnode *
 layer_node_find(struct mount *mp, struct vnode *lowervp)
@@ -137,58 +125,59 @@
        int error;
 
        /*
-        * Find hash base, and then search the (two-way) linked
-        * list looking for a layer_node structure which is referencing
-        * the lower vnode.  If found, the increment the layer_node
-        * reference count (but NOT the lower vnode's VREF counter)
-        * and return the vnode locked.
+        * Find hash bucket and search the (two-way) linked list looking
+        * for a layerfs node structure which is referencing the lower vnode.
+        * If found, the increment the layer_node reference count, but NOT
+        * the lower vnode's reference counter.  Return vnode locked.
         */
+       KASSERT(mutex_owned(&lmp->layerm_hashlock));
        hd = LAYER_NHASH(lmp, lowervp);
 loop:
        LIST_FOREACH(a, hd, layer_hash) {
-               if (a->layer_lowervp == lowervp && LAYERTOV(a)->v_mount == mp) {
-                       vp = LAYERTOV(a);
-                       mutex_enter(&vp->v_interlock);
-                       /*
-                        * If we find a node being cleaned out, then
-                        * ignore it and continue.  A thread trying to
-                        * clean out the extant layer vnode needs to
-                        * acquire the shared lock (i.e. the lower
-                        * vnode's lock), which our caller already holds.
-                        * To allow the cleaning to succeed the current
-                        * thread must make progress.  So, for a brief
-                        * time more than one vnode in a layered file
-                        * system may refer to a single vnode in the
-                        * lower file system.
-                        */
-                       if ((vp->v_iflag & VI_XLOCK) != 0) {
-                               mutex_exit(&vp->v_interlock);
-                               continue;
-                       }
-                       mutex_exit(&lmp->layerm_hashlock);
-                       /*
-                        * We must not let vget() try to lock the layer
-                        * vp, since the lower vp is already locked and
-                        * locking the layer vp will involve locking
-                        * the lower vp.
-                        */
-                       error = vget(vp, LK_INTERLOCK | LK_NOWAIT);
-                       if (error) {
-                               kpause("layerfs", false, 1, NULL);
-                               mutex_enter(&lmp->layerm_hashlock);
-                               goto loop;
-                       }
-                       return (vp);
+               if (a->layer_lowervp != lowervp) {
+                       continue;
+               }
+               vp = LAYERTOV(a);
+               if (vp->v_mount != mp) {
+                       continue;
                }
+               mutex_enter(&vp->v_interlock);
+               /*
+                * If we find a node being cleaned out, then ignore it and
+                * continue.  A thread trying to clean out the extant layer
+                * vnode needs to acquire the shared lock (i.e. the lower
+                * vnode's lock), which our caller already holds.  To allow
+                * the cleaning to succeed the current thread must make
+                * progress.  So, for a brief time more than one vnode in a
+                * layered file system may refer to a single vnode in the
+                * lower file system.
+                */
+               if ((vp->v_iflag & VI_XLOCK) != 0) {
+                       mutex_exit(&vp->v_interlock);
+                       continue;
+               }
+               mutex_exit(&lmp->layerm_hashlock);
+               /*
+                * We must not let vget() try to lock the layer vp, since
+                * the lower vp is already locked and locking the layer vp
+                * will involve locking the lower vp.
+                */
+               error = vget(vp, LK_INTERLOCK | LK_NOWAIT);
+               if (error) {
+                       kpause("layerfs", false, 1, NULL);
+                       mutex_enter(&lmp->layerm_hashlock);
+                       goto loop;
+               }
+               return vp;
        }
        return NULL;
 }
 
-
 /*
- * Make a new layer_node node.
- * Vp is the alias vnode, lowervp is the lower vnode.
- * Maintain a reference to lowervp.
+ * layer_node_alloc: make a new layerfs vnode.
+ *
+ * => vp is the alias vnode, lowervp is the lower vnode.
+ * => We will hold a reference to lowervp.
  */
 int
 layer_node_alloc(struct mount *mp, struct vnode *lowervp, struct vnode **vpp)
@@ -201,8 +190,9 @@
        extern int (**dead_vnodeop_p)(void *);
 
        error = getnewvnode(lmp->layerm_tag, mp, lmp->layerm_vnodeop_p, &vp);
-       if (error != 0)
-               return (error);
+       if (error) {
+               return error;
+       }
        vp->v_type = lowervp->v_type;
        mutex_enter(&vp->v_interlock);
        vp->v_iflag |= VI_LAYER;
@@ -225,61 +215,57 @@
        xp->layer_flags = 0;
 
        /*
-        * Before we insert our new node onto the hash chains,
-        * check to see if someone else has beaten us to it.
-        * (We could have slept in MALLOC.)
+        * Before inserting the node into the hash, check if other thread
+        * did not race with us.  If so - return that node, destroy ours.
         */
        mutex_enter(&lmp->layerm_hashlock);
        if ((nvp = layer_node_find(mp, lowervp)) != NULL) {
-               *vpp = nvp;
-
-               /* free the substructures we've allocated. */
-               kmem_free(xp, lmp->layerm_size);
+               /* Free the structures we have created. */
                if (vp->v_type == VBLK || vp->v_type == VCHR)
                        spec_node_destroy(vp);
 
                vp->v_type = VBAD;              /* node is discarded */
                vp->v_op = dead_vnodeop_p;      /* so ops will still work */
                vrele(vp);                      /* get rid of it. */
-               return (0);
+               kmem_free(xp, lmp->layerm_size);
+               *vpp = nvp;
+               return 0;
        }
 
        /*
         * Insert the new node into the hash.
         * Add a reference to the lower node.
         */
-
-       *vpp = vp;
        vref(lowervp);
        hd = LAYER_NHASH(lmp, lowervp);
        LIST_INSERT_HEAD(hd, xp, layer_hash);
        uvm_vnp_setsize(vp, 0);
        mutex_exit(&lmp->layerm_hashlock);
-       return (0);



Home | Main Index | Thread Index | Old Index