Source-Changes-HG archive

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

[src/trunk]: src/sys/fs/tmpfs tmpfs_lookup: add comment, de-ident main path. ...



details:   https://anonhg.NetBSD.org/src/rev/fba1a0bde770
branches:  trunk
changeset: 755993:fba1a0bde770
user:      rmind <rmind%NetBSD.org@localhost>
date:      Fri Jul 02 03:29:47 2010 +0000

description:
tmpfs_lookup: add comment, de-ident main path.  No functional change.
tmpfs_dir_attach: add assert.

diffstat:

 sys/fs/tmpfs/tmpfs_subr.c  |    6 +-
 sys/fs/tmpfs/tmpfs_vnops.c |  189 +++++++++++++++++++++++---------------------
 2 files changed, 100 insertions(+), 95 deletions(-)

diffs (292 lines):

diff -r da0b0b6df1ff -r fba1a0bde770 sys/fs/tmpfs/tmpfs_subr.c
--- a/sys/fs/tmpfs/tmpfs_subr.c Fri Jul 02 03:25:27 2010 +0000
+++ b/sys/fs/tmpfs/tmpfs_subr.c Fri Jul 02 03:29:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_subr.c,v 1.57 2010/06/22 18:32:08 rmind Exp $    */
+/*     $NetBSD: tmpfs_subr.c,v 1.58 2010/07/02 03:29:47 rmind Exp $    */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.57 2010/06/22 18:32:08 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_subr.c,v 1.58 2010/07/02 03:29:47 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -536,6 +536,7 @@
 {
        struct tmpfs_node *dnode;
 
+       KASSERT(VOP_ISLOCKED(vp));
        dnode = VP_TO_TMPFS_DIR(vp);
 
        TAILQ_INSERT_TAIL(&dnode->tn_spec.tn_dir.tn_dir, de, td_entries);
@@ -563,7 +564,6 @@
        struct tmpfs_node *dnode;
 
        KASSERT(VOP_ISLOCKED(vp));
-
        dnode = VP_TO_TMPFS_DIR(vp);
 
        if (dnode->tn_spec.tn_dir.tn_readdir_lastp == de) {
diff -r da0b0b6df1ff -r fba1a0bde770 sys/fs/tmpfs/tmpfs_vnops.c
--- a/sys/fs/tmpfs/tmpfs_vnops.c        Fri Jul 02 03:25:27 2010 +0000
+++ b/sys/fs/tmpfs/tmpfs_vnops.c        Fri Jul 02 03:29:47 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tmpfs_vnops.c,v 1.71 2010/06/24 13:03:11 hannken Exp $ */
+/*     $NetBSD: tmpfs_vnops.c,v 1.72 2010/07/02 03:29:47 rmind Exp $   */
 
 /*
  * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.71 2010/06/24 13:03:11 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vnops.c,v 1.72 2010/07/02 03:29:47 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/dirent.h>
@@ -111,18 +111,28 @@
 const struct vnodeopv_desc tmpfs_vnodeop_opv_desc =
        { &tmpfs_vnodeop_p, tmpfs_vnodeop_entries };
 
-/* --------------------------------------------------------------------- */
-
+/*
+ * tmpfs_lookup: lookup routine.
+ *
+ * Arguments: dvp (directory being searched), vpp (result),
+ * cnp (component name - path).
+ *
+ * => Caller holds a reference and lock on dvp.
+ * => We return looked-up vnode (vpp) locked, with a reference held.
+ */
 int
 tmpfs_lookup(void *v)
 {
-       struct vnode *dvp = ((struct vop_lookup_args *)v)->a_dvp;
-       struct vnode **vpp = ((struct vop_lookup_args *)v)->a_vpp;
-       struct componentname *cnp = ((struct vop_lookup_args *)v)->a_cnp;
-
-       int error;
+       struct vop_lookup_args /* {
+               struct vnode *a_dvp;
+               struct vnode **a_vpp;
+               struct componentname *a_cnp;
+       } */ *ap = v;
+       struct vnode *dvp = ap->a_dvp, **vpp = ap->a_vpp;
+       struct componentname *cnp = ap->a_cnp;
        struct tmpfs_dirent *de;
        struct tmpfs_node *dnode;
+       int error;
 
        KASSERT(VOP_ISLOCKED(dvp));
 
@@ -134,8 +144,10 @@
        if (error != 0)
                goto out;
 
-       /* If requesting the last path component on a read-only file system
-        * with a write operation, deny it. */
+       /*
+        * If requesting the last path component on a read-only file system
+        * with a write operation, deny it.
+        */
        if ((cnp->cn_flags & ISLASTCN) &&
            (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
            (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
@@ -143,8 +155,10 @@
                goto out;
        }
 
-       /* Avoid doing a linear scan of the directory if the requested
-        * directory/name couple is already in the cache. */
+       /*
+        * Avoid doing a linear scan of the directory if the requested
+        * directory/name couple is already in the cache.
+        */
        error = cache_lookup(dvp, vpp, cnp);
        if (error >= 0)
                goto out;
@@ -162,107 +176,98 @@
                    dnode->tn_spec.tn_dir.tn_parent, vpp);
 
                vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
+               goto done;
+
        } else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
                vref(dvp);
                *vpp = dvp;
                error = 0;
+               goto done;
+       }
+
+       de = tmpfs_dir_lookup(dnode, cnp);
+       if (de == NULL) {
+               /*
+                * The entry was not found in the directory.  This is valid
+                * if we are creating or renaming an entry and are working
+                * on the last component of the path name.
+                */
+               if ((cnp->cn_flags & ISLASTCN) && (cnp->cn_nameiop == CREATE ||
+                   cnp->cn_nameiop == RENAME)) {
+                       error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
+                       if (error) {
+                               goto out;
+                       }
+                       /* Keep the component name for future uses. */
+                       cnp->cn_flags |= SAVENAME;
+                       error = EJUSTRETURN;
+               } else {
+                       error = ENOENT;
+               }
        } else {
-               de = tmpfs_dir_lookup(dnode, cnp);
-               if (de == NULL) {
-                       /* The entry was not found in the directory.
-                        * This is OK iff we are creating or renaming an
-                        * entry and are working on the last component of
-                        * the path name. */
-                       if ((cnp->cn_flags & ISLASTCN) &&
-                           (cnp->cn_nameiop == CREATE || \
-                           cnp->cn_nameiop == RENAME)) {
-                               error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
-                               if (error != 0)
-                                       goto out;
-
-                               /* Keep the component name in the buffer for
-                                * future uses. */
-                               cnp->cn_flags |= SAVENAME;
+               struct tmpfs_node *tnode = de->td_node;
 
-                               error = EJUSTRETURN;
-                       } else
-                               error = ENOENT;
-               } else {
-                       struct tmpfs_node *tnode;
-
-                       /* The entry was found, so get its associated
-                        * tmpfs_node. */
-                       tnode = de->td_node;
+               /*
+                * If we are not at the last path component and found a
+                * non-directory or non-link entry (which may itself be
+                * pointing to a directory), raise an error.
+                */
+               if ((tnode->tn_type != VDIR && tnode->tn_type != VLNK) &&
+                   (cnp->cn_flags & ISLASTCN) == 0) {
+                       error = ENOTDIR;
+                       goto out;
+               }
 
-                       /* If we are not at the last path component and
-                        * found a non-directory or non-link entry (which
-                        * may itself be pointing to a directory), raise
-                        * an error. */
-                       if ((tnode->tn_type != VDIR &&
-                           tnode->tn_type != VLNK) &&
-                           !(cnp->cn_flags & ISLASTCN)) {
-                               error = ENOTDIR;
-                               goto out;
+               /* Check permissions. */
+               if ((cnp->cn_flags & ISLASTCN) && (cnp->cn_nameiop == DELETE ||
+                   cnp->cn_nameiop == RENAME)) {
+                       kauth_action_t action = 0;
+
+                       /* This is the file-system's decision. */
+                       if ((dnode->tn_mode & S_ISTXT) != 0 &&
+                           kauth_cred_geteuid(cnp->cn_cred) != dnode->tn_uid &&
+                           kauth_cred_geteuid(cnp->cn_cred) != tnode->tn_uid)
+                               error = EPERM;
+                       else
+                               error = 0;
+
+                       /* Only bother if we are not already failing it. */
+                       if (!error) {
+                               error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
                        }
 
-                       /* Check permissions */
-                       if ((cnp->cn_flags & ISLASTCN) &&
-                           (cnp->cn_nameiop == DELETE ||
-                           cnp->cn_nameiop == RENAME)) {
-                               kauth_action_t action = 0;
-
-                               /* This is the file-system's decision. */
-                               if ((dnode->tn_mode & S_ISTXT) != 0 &&
-                                   kauth_cred_geteuid(cnp->cn_cred) != dnode->tn_uid &&
-                                   kauth_cred_geteuid(cnp->cn_cred) != tnode->tn_uid)
-                                       error = EPERM;
-                               else
-                                       error = 0;
-
-                               /* Only bother if we're not already failing it. */
-                               if (!error) {
-                                       error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
-                               }
-
-                               if (cnp->cn_nameiop == DELETE)
-                                       action |= KAUTH_VNODE_DELETE;
-                               else /* if (cnp->cn_nameiop == RENAME) */
-                                       action |= KAUTH_VNODE_RENAME;
-
-                               error = kauth_authorize_vnode(cnp->cn_cred,
-                                   action, *vpp, dvp, error);
-                               if (error != 0)
-                                       goto out;
-
-                               cnp->cn_flags |= SAVENAME;
-                       } else
-                               de = NULL;
-
-                       /* Allocate a new vnode on the matching entry. */
-                       error = tmpfs_alloc_vp(dvp->v_mount, tnode, vpp);
+                       if (cnp->cn_nameiop == DELETE) {
+                               action |= KAUTH_VNODE_DELETE;
+                       } else {
+                               KASSERT(cnp->cn_nameiop == RENAME);
+                               action |= KAUTH_VNODE_RENAME;
+                       }
+                       error = kauth_authorize_vnode(cnp->cn_cred,
+                           action, *vpp, dvp, error);
+                       if (error) {
+                               goto out;
+                       }
+                       cnp->cn_flags |= SAVENAME;
                }
+               /* Allocate a new vnode on the matching entry. */
+               error = tmpfs_alloc_vp(dvp->v_mount, tnode, vpp);
        }
-
-       /* Store the result of this lookup in the cache.  Avoid this if the
+done:
+       /*
+        * Store the result of this lookup in the cache.  Avoid this if the
         * request was for creation, as it does not improve timings on
-        * emprical tests. */
+        * emprical tests.
+        */
        if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE &&
            (cnp->cn_flags & ISDOTDOT) == 0)
                cache_enter(dvp, *vpp, cnp);
 
 out:
-       /* If there were no errors, *vpp cannot be null and it must be
-        * locked. */
        KASSERT(IFF(error == 0, *vpp != NULL && VOP_ISLOCKED(*vpp)));
-
-       /* dvp must always be locked. */
        KASSERT(VOP_ISLOCKED(dvp));
-
        return error;
 }
 
-/* --------------------------------------------------------------------- */
-
 int
 tmpfs_create(void *v)
 {



Home | Main Index | Thread Index | Old Index