From 662e8088622360d8af1155902a0f8b55a451a63d Mon Sep 17 00:00:00 2001 From: Tomohiro Kusumi Date: Wed, 7 Mar 2018 03:27:04 +0900 Subject: [PATCH] sys/vfs/autofs: Cleanups Move local varaibles to inner scopes where possible. The existing local variable declarations are mostly from FreeBSD, but I've also changed NetBSD autofs the way this commit does. (Don't do this for autofs userspace though. Increasing diff from FreeBSD for non functional thing like this is much less important, whereas kernel side is basically a rewrite.) --- sys/vfs/autofs/autofs.c | 20 +++++++++++--------- sys/vfs/autofs/autofs_vfsops.c | 10 ++++++---- sys/vfs/autofs/autofs_vnops.c | 5 ++--- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/sys/vfs/autofs/autofs.c b/sys/vfs/autofs/autofs.c index eb1c404c90..5d1e5da5b1 100644 --- a/sys/vfs/autofs/autofs.c +++ b/sys/vfs/autofs/autofs.c @@ -303,7 +303,6 @@ bool autofs_cached(struct autofs_node *anp, const char *component, int componentlen) { struct autofs_mount *amp = anp->an_mount; - int error; KKASSERT(mtx_notlocked(&->am_lock)); @@ -315,6 +314,7 @@ autofs_cached(struct autofs_node *anp, const char *component, int componentlen) * no wildcards. */ if (anp->an_parent == NULL && componentlen != 0 && anp->an_wildcards) { + int error; KKASSERT(amp->am_root == anp); mtx_lock_sh_quick(&->am_lock); error = autofs_node_find(anp, component, componentlen, NULL); @@ -393,11 +393,9 @@ autofs_trigger_one(struct autofs_node *anp, { #define _taskqueue_thread (taskqueue_thread[mycpuid]) struct autofs_mount *amp = anp->an_mount; - struct autofs_node *firstanp; struct autofs_request *ar; - sigset_t oldset; char *key, *path; - int error = 0, request_error, last; + int error = 0, request_error; bool wildcards; KKASSERT(lockstatus(&autofs_softc->sc_lock, curthread) == LK_EXCLUSIVE); @@ -405,6 +403,7 @@ autofs_trigger_one(struct autofs_node *anp, if (anp->an_parent == NULL) { key = kstrndup(component, componentlen, M_AUTOFS); } else { + struct autofs_node *firstanp; for (firstanp = anp; firstanp->an_parent->an_parent != NULL; firstanp = firstanp->an_parent) continue; @@ -457,6 +456,7 @@ autofs_trigger_one(struct autofs_node *anp, cv_broadcast(&autofs_softc->sc_cv); while (ar->ar_done == false) { if (autofs_interruptible) { + sigset_t oldset; autofs_set_sigmask(&oldset); error = cv_wait_sig(&autofs_softc->sc_cv, &autofs_softc->sc_lock); @@ -478,8 +478,10 @@ autofs_trigger_one(struct autofs_node *anp, wildcards = ar->ar_wildcards; - last = refcount_release(&ar->ar_refcount); - if (last) { + /* + * Check if this is the last reference. + */ + if (refcount_release(&ar->ar_refcount)) { TAILQ_REMOVE(&autofs_softc->sc_requests, ar, ar_next); lockmgr(&autofs_softc->sc_lock, LK_RELEASE); taskqueue_cancel_timeout(_taskqueue_thread, &ar->ar_task, NULL); @@ -512,9 +514,9 @@ int autofs_trigger(struct autofs_node *anp, const char *component, int componentlen) { - int error, dummy; - for (;;) { + int error, dummy; + error = autofs_trigger_one(anp, component, componentlen); if (error == 0) { anp->an_retries = 0; @@ -548,10 +550,10 @@ autofs_ioctl_request(struct autofs_daemon_request *adr) { struct proc *curp = curproc; struct autofs_request *ar; - int error; lockmgr(&autofs_softc->sc_lock, LK_EXCLUSIVE); for (;;) { + int error; TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) { if (ar->ar_done) continue; diff --git a/sys/vfs/autofs/autofs_vfsops.c b/sys/vfs/autofs/autofs_vfsops.c index f4ba35a0cf..95f345ce8e 100644 --- a/sys/vfs/autofs/autofs_vfsops.c +++ b/sys/vfs/autofs/autofs_vfsops.c @@ -127,10 +127,7 @@ static int autofs_unmount(struct mount *mp, int mntflags) { struct autofs_mount *amp = VFSTOAUTOFS(mp); - struct autofs_node *anp; - struct autofs_request *ar; - int error, flags, dummy; - bool found; + int error, flags; flags = 0; if (mntflags & MNT_FORCE) @@ -146,6 +143,10 @@ autofs_unmount(struct mount *mp, int mntflags) * no new triggerings. */ for (;;) { + struct autofs_request *ar; + int dummy; + bool found; + found = false; lockmgr(&autofs_softc->sc_lock, LK_EXCLUSIVE); TAILQ_FOREACH(ar, &autofs_softc->sc_requests, ar_next) { @@ -169,6 +170,7 @@ autofs_unmount(struct mount *mp, int mntflags) mtx_lock_ex_quick(&->am_lock); while (!RB_EMPTY(&->am_root->an_children)) { + struct autofs_node *anp; anp = RB_MIN(autofs_node_tree, &->am_root->an_children); if (!RB_EMPTY(&anp->an_children)) { AUTOFS_DEBUG("%s has children", anp->an_name); diff --git a/sys/vfs/autofs/autofs_vnops.c b/sys/vfs/autofs/autofs_vnops.c index 7a650cd975..7c805b26ce 100644 --- a/sys/vfs/autofs/autofs_vnops.c +++ b/sys/vfs/autofs/autofs_vnops.c @@ -71,7 +71,6 @@ test_fs_root(struct vnode *vp) static int nlookup_fs_root(struct autofs_node *anp, struct vnode **vpp) { - struct vnode *vp; struct nlookupdata nd; char *path; int error; @@ -82,7 +81,7 @@ nlookup_fs_root(struct autofs_node *anp, struct vnode **vpp) if (error == 0) { error = nlookup(&nd); if (error == 0) { - vp = nd.nl_nch.ncp->nc_vp; + struct vnode *vp = nd.nl_nch.ncp->nc_vp; error = test_fs_root(vp); if (error == 0) *vpp = vp; @@ -439,7 +438,7 @@ static int autofs_mountctl(struct vop_mountctl_args *ap) { struct mount *mp; - int res; + int res = 0; mp = ap->a_head.a_ops->head.vv_mount; lwkt_gettoken(&mp->mnt_token); -- 2.41.0