Source-Changes-HG archive

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

[src/trunk]: src/sys/ufs/ufs - return (foo) -> return foo



details:   https://anonhg.NetBSD.org/src/rev/9f03bcd77be8
branches:  trunk
changeset: 453600:9f03bcd77be8
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Aug 19 09:30:30 2019 +0000

description:
- return (foo) -> return foo
- normalize all error messages to use __func__
- add more messages for startup failure (should perhaps auto-create
  the attributes directory and the user and system subdirs?)
- factor out common code

diffstat:

 sys/ufs/ufs/ufs_extattr.c |  272 ++++++++++++++++++++++-----------------------
 1 files changed, 131 insertions(+), 141 deletions(-)

diffs (truncated from 716 to 300 lines):

diff -r 723add26d265 -r 9f03bcd77be8 sys/ufs/ufs/ufs_extattr.c
--- a/sys/ufs/ufs/ufs_extattr.c Mon Aug 19 08:07:55 2019 +0000
+++ b/sys/ufs/ufs/ufs_extattr.c Mon Aug 19 09:30:30 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ufs_extattr.c,v 1.48 2016/11/09 05:08:35 dholland Exp $        */
+/*     $NetBSD: ufs_extattr.c,v 1.49 2019/08/19 09:30:30 christos Exp $        */
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ufs_extattr.c,v 1.48 2016/11/09 05:08:35 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ufs_extattr.c,v 1.49 2019/08/19 09:30:30 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ffs.h"
@@ -207,10 +207,10 @@
 {
 
        if (attrname == NULL)
-               return (0);
+               return 0;
        if (strlen(attrname) == 0)
-               return (0);
-       return (1);
+               return 0;
+       return 1;
 }
 
 /*
@@ -321,8 +321,8 @@
        VOP_UNLOCK(backing_vp);
 
        if (error != 0) {
-               printf("%s: write uef header failed for %s, error = %d\n", 
-                      __func__, attrname, error);
+               printf("%s: write uef header failed for `%s' (%d)\n", 
+                   __func__, attrname, error);
                vn_close(backing_vp, FREAD|FWRITE, l->l_cred);
                *uelep = NULL;
                return error;
@@ -335,8 +335,8 @@
        KASSERT(VOP_ISLOCKED(backing_vp) == 0);
 
        if (error != 0) {
-               printf("%s: enable %s failed, error %d\n", 
-                      __func__, attrname, error);
+               printf("%s: enable `%s' failed (%d)\n", 
+                   __func__, attrname, error);
                vn_close(backing_vp, FREAD|FWRITE, l->l_cred);
                *uelep = NULL;
                return error;
@@ -344,7 +344,7 @@
 
        uele = ufs_extattr_find_attr(ump, attrnamespace, attrname);
        if (uele == NULL) {
-               printf("%s: atttribute %s created but not found!\n",
+               printf("%s: atttribute `%s' created but not found!\n",
                       __func__, attrname);
                vn_close(backing_vp, FREAD|FWRITE, l->l_cred);
                *uelep = NULL;
@@ -352,7 +352,7 @@
        }
 
        printf("%s: EA backing store autocreated for %s\n",
-              mp->mnt_stat.f_mntonname, attrname);
+           mp->mnt_stat.f_mntonname, attrname);
 
        *uelep = uele;
        return 0;
@@ -374,11 +374,11 @@
                if (!(strncmp(attrname, search_attribute->uele_attrname,
                    UFS_EXTATTR_MAXEXTATTRNAME)) &&
                    (attrnamespace == search_attribute->uele_attrnamespace)) {
-                       return (search_attribute);
+                       return search_attribute;
                }
        }
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -453,8 +453,7 @@
 
  unlock:
        ufs_extattr_uepm_unlock(ump);
-
-       return (error);
+       return error;
 }
 
 /*
@@ -490,8 +489,8 @@
                        VOP_UNLOCK(start_dvp);
                }
                PNBUF_PUT(pnbuf);
-               printf("ufs_extattr_lookup: copystr failed\n");
-               return (error);
+               printf("%s: copystr failed (%d)\n", __func__, error);
+               return error;
        }
        cnp.cn_namelen--;       /* trim nul termination */
        vargs.a_desc = NULL;
@@ -504,11 +503,11 @@
                if (lockparent == 0) {
                        VOP_UNLOCK(start_dvp);
                }
-               return (error);
+               return error;
        }
 #if 0
        if (target_vp == start_dvp)
-               panic("ufs_extattr_lookup: target_vp == start_dvp");
+               panic("%s: target_vp == start_dvp", __func__);
 #endif
 
        if (target_vp != start_dvp) {
@@ -523,7 +522,7 @@
 
        KASSERT(VOP_ISLOCKED(target_vp) == LK_EXCLUSIVE);
        *vp = target_vp;
-       return (0);
+       return 0;
 }
 
 /*
@@ -541,10 +540,9 @@
 
        error = VOP_OPEN(vp, FREAD|FWRITE, l->l_cred);
        if (error) {
-               printf("ufs_extattr_enable_with_open.VOP_OPEN(): failed "
-                   "with %d\n", error);
+               printf("%s: VOP_OPEN(): failed (%d)\n", __func__, error);
                VOP_UNLOCK(vp);
-               return (error);
+               return error;
        }
 
        mutex_enter(vp->v_interlock);
@@ -558,7 +556,7 @@
        error = ufs_extattr_enable(ump, attrnamespace, attrname, vp, l);
        if (error != 0)
                vn_close(vp, FREAD|FWRITE, l->l_cred);
-       return (error);
+       return error;
 }
 
 /*
@@ -582,7 +580,7 @@
        int error, eofflag = 0;
 
        if (dvp->v_type != VDIR)
-               return (ENOTDIR);
+               return ENOTDIR;
 
        dirbuf = kmem_alloc(UFS_DIRBLKSIZ, KM_SLEEP);
 
@@ -606,9 +604,8 @@
                aiov.iov_len = UFS_DIRBLKSIZ;
                error = ufs_readdir(&vargs);
                if (error) {
-                       printf("ufs_extattr_iterate_directory: ufs_readdir "
-                           "%d\n", error);
-                       return (error);
+                       printf("%s: ufs_readdir (%d)\n", __func__, error);
+                       return error;
                }
 
                /*
@@ -631,8 +628,8 @@
                        if (error == ENOENT) {
                                goto next; /* keep silent */
                        } else if (error) {
-                               printf("ufs_extattr_iterate_directory: lookup "
-                                   "%s %d\n", dp->d_name, error);
+                               printf("%s: lookup `%s' (%d)\n", __func__,
+                                   dp->d_name, error);
                        } else if (attr_vp == dvp) {
                                vrele(attr_vp);
                        } else if (attr_vp->v_type != VREG) {
@@ -642,12 +639,11 @@
                                    attr_vp, attrnamespace, dp->d_name, l);
                                vrele(attr_vp);
                                if (error) {
-                                       printf("ufs_extattr_iterate_directory: "
-                                           "enable %s %d\n", dp->d_name,
-                                           error);
+                                       printf("%s: enable `%s' (%d)\n",
+                                           __func__, dp->d_name, error);
                                } else if (bootverbose) {
                                        printf("%s: EA %s loaded\n",
-                                              sbp->f_mntonname, dp->d_name);
+                                           sbp->f_mntonname, dp->d_name);
                                }
                        }
  next:
@@ -658,7 +654,32 @@
        }
        kmem_free(dirbuf, UFS_DIRBLKSIZ);
        
-       return (0);
+       return 0;
+}
+
+static int
+ufs_extattr_subdir(struct lwp *l, struct mount *mp, struct vnode *attr_dvp,
+    const char *subdir, int namespace)
+{
+       int error;
+       struct vnode *attr_sub;
+       error = ufs_extattr_lookup(attr_dvp, LOCKPARENT, subdir, &attr_sub, l);
+       KASSERT(VOP_ISLOCKED(attr_dvp) == LK_EXCLUSIVE);
+       if (error) {
+               printf("%s: Can't find `%s/%s' (%d)\n",
+                   __func__, UFS_EXTATTR_FSROOTSUBDIR, subdir, error);
+               return error;
+       }
+       KASSERT(VOP_ISLOCKED(attr_sub) == LK_EXCLUSIVE);
+       error = ufs_extattr_iterate_directory(VFSTOUFS(mp),
+           attr_sub, namespace, l);
+       if (error) {
+               printf("%s: ufs_extattr_iterate_directory for `%s/%s' (%d)\n",
+                   __func__, UFS_EXTATTR_FSROOTSUBDIR, subdir, error);
+       }
+       KASSERT(VOP_ISLOCKED(attr_sub) == LK_EXCLUSIVE);
+       vput(attr_sub);
+       return error;
 }
 
 /*
@@ -668,7 +689,7 @@
 int
 ufs_extattr_autostart(struct mount *mp, struct lwp *l)
 {
-       struct vnode *rvp, *attr_dvp, *attr_system_dvp, *attr_user_dvp;
+       struct vnode *rvp, *attr_dvp;
        int error;
 
        /*
@@ -677,9 +698,8 @@
         */
        error = VFS_ROOT(mp, &rvp);
        if (error) {
-               printf("ufs_extattr_autostart.VFS_ROOT() returned %d\n",
-                   error);
-               return (error);
+               printf("%s: VFS_ROOT() (%d)\n", __func__, error);
+               return error;
        }
 
        KASSERT(VOP_ISLOCKED(rvp) == LK_EXCLUSIVE);
@@ -690,14 +710,18 @@
                /* rvp ref'd but now unlocked */
                KASSERT(VOP_ISLOCKED(rvp) == 0);
                vrele(rvp);
-               return (error);
+               printf("%s: lookup `%s' (%d)\n", __func__,
+                   UFS_EXTATTR_FSROOTSUBDIR, error);
+               return error;
        }
        if (rvp == attr_dvp) {
                /* Should never happen. */
                KASSERT(VOP_ISLOCKED(rvp) == LK_EXCLUSIVE);
                vrele(attr_dvp);
                vput(rvp);
-               return (EINVAL);
+               printf("%s: `/' == `%s' (%d)\n", __func__,
+                   UFS_EXTATTR_FSROOTSUBDIR, EINVAL);
+               return EINVAL;
        }
        KASSERT(VOP_ISLOCKED(rvp) == 0);
        vrele(rvp);
@@ -705,14 +729,14 @@
        KASSERT(VOP_ISLOCKED(attr_dvp) == LK_EXCLUSIVE);
 
        if (attr_dvp->v_type != VDIR) {
-               printf("ufs_extattr_autostart: %s != VDIR\n",
-                   UFS_EXTATTR_FSROOTSUBDIR);
+               printf("%s: `%s' is not a directory\n",
+                   __func__, UFS_EXTATTR_FSROOTSUBDIR);
                goto return_vput_attr_dvp;
        }
 
        error = ufs_extattr_start(mp, l);
        if (error) {
-               printf("ufs_extattr_autostart: ufs_extattr_start failed (%d)\n",
+               printf("%s: ufs_extattr_start failed (%d)\n", __func__,
                    error);
                goto return_vput_attr_dvp;
        }
@@ -724,33 +748,10 @@
         * result in an over-all failure.  attr_dvp is left locked to
         * be cleaned up on exit.
         */
-       error = ufs_extattr_lookup(attr_dvp, LOCKPARENT,
-           UFS_EXTATTR_SUBDIR_SYSTEM, &attr_system_dvp, l);



Home | Main Index | Thread Index | Old Index