Module Name:    src
Committed By:   dholland
Date:           Mon Apr 11 02:17:01 UTC 2011

Modified Files:
        src/sys/kern: vfs_lookup.c

Log Message:
description:
Fix lookup_for_nfsd_index() -- it wasn't locking the directory it was
searching. I'm not sure if this is something I introduced or if it's
just been wrong for ages; the code path is used only for serving
index.html in WebNFS and probably just ought to be removed.


To generate a diff of this commit:
cvs rdiff -u -r1.159 -r1.160 src/sys/kern/vfs_lookup.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_lookup.c
diff -u src/sys/kern/vfs_lookup.c:1.159 src/sys/kern/vfs_lookup.c:1.160
--- src/sys/kern/vfs_lookup.c:1.159	Mon Apr 11 02:16:27 2011
+++ src/sys/kern/vfs_lookup.c	Mon Apr 11 02:17:01 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_lookup.c,v 1.159 2011/04/11 02:16:27 dholland Exp $	*/
+/*	$NetBSD: vfs_lookup.c,v 1.160 2011/04/11 02:17:01 dholland Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.159 2011/04/11 02:16:27 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.160 2011/04/11 02:17:01 dholland Exp $");
 
 #include "opt_magiclinks.h"
 
@@ -1458,7 +1458,14 @@
 	else
 		cnp->cn_flags &= ~ISDOTDOT;
 
-	error = lookup_once(state, startdir, &ndp->ni_dvp, &foundobj);
+	/*
+	 * Because lookup_once can change the startdir, we need our
+	 * own reference to it to avoid consuming the caller's.
+	 */
+	vref(startdir);
+	vn_lock(startdir, LK_EXCLUSIVE | LK_RETRY);
+	error = lookup_once(state, startdir, &startdir, &foundobj);
+	vput(startdir);
 	if (error) {
 		goto bad;
 	}
@@ -1469,6 +1476,7 @@
 		return 0;
 	}
 
+	KASSERT((cnp->cn_flags & LOCKPARENT) == 0);
 	if ((cnp->cn_flags & LOCKLEAF) == 0) {
 		VOP_UNLOCK(foundobj);
 	}
@@ -1500,8 +1508,6 @@
 	ndp->ni_pnbuf = NULL;
 	ndp->ni_cnd.cn_nameptr = NULL;
 
-	vref(startdir);
-
 	namei_init(&state, ndp);
 	error = do_lookup_for_nfsd_index(&state, startdir);
 	namei_cleanup(&state);

Reply via email to