PERFORCE change 94109 for review

John Baldwin jhb at FreeBSD.org
Mon Mar 27 13:43:00 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=94109

Change 94109 by jhb at jhb_tibook on 2006/03/27 13:42:14

	Use MPSAFE vn_open() to conditionally grab Giant around VFS operations
	in the kernel linker.

Affected files ...

.. //depot/projects/smpng/sys/kern/kern_linker.c#44 edit
.. //depot/projects/smpng/sys/kern/link_elf.c#33 edit
.. //depot/projects/smpng/sys/kern/link_elf_obj.c#9 edit
.. //depot/projects/smpng/sys/notes#69 edit

Differences ...

==== //depot/projects/smpng/sys/kern/kern_linker.c#44 (text+ko) ====

@@ -1406,7 +1406,7 @@
 	struct nameidata nd;
 	struct thread *td = curthread;	/* XXX */
 	char *result, **cpp, *sep;
-	int error, len, extlen, reclen, flags;
+	int error, len, extlen, reclen, flags, vfslocked;
 	enum vtype type;
 
 	extlen = 0;
@@ -1427,16 +1427,18 @@
 		 * Attempt to open the file, and return the path if
 		 * we succeed and it's a regular file.
 		 */
-		NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, td);
+		NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, result, td);
 		flags = FREAD;
 		error = vn_open(&nd, &flags, 0, -1);
 		if (error == 0) {
+			vfslocked = NDHASGIANT(&nd);
 			NDFREE(&nd, NDF_ONLY_PNBUF);
 			type = nd.ni_vp->v_type;
 			if (vap)
 				VOP_GETATTR(nd.ni_vp, vap, td->td_ucred, td);
 			VOP_UNLOCK(nd.ni_vp, 0, td);
 			vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
+			VFS_UNLOCK_GIANT(vfslocked);
 			if (type == VREG)
 				return (result);
 		}
@@ -1464,6 +1466,7 @@
 	u_char *hints = NULL;
 	u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep;
 	int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
+	int vfslocked = 0;
 
 	result = NULL;
 	bestver = found = 0;
@@ -1475,13 +1478,14 @@
 	snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep,
 	    linker_hintfile);
 
-	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, td);
+	NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, pathbuf, td);
 	flags = FREAD;
 	error = vn_open(&nd, &flags, 0, -1);
 	if (error)
 		goto bad;
+	vfslocked = NDHASGIANT(&nd);
 	NDFREE(&nd, NDF_ONLY_PNBUF);
-	if (nd.ni_vp->v_type != VREG)
+	if (nd.ni_vp->v_type != VREG) {
 		goto bad;
 	best = cp = NULL;
 	error = VOP_GETATTR(nd.ni_vp, &vattr, cred, td);
@@ -1503,6 +1507,7 @@
 		goto bad;
 	VOP_UNLOCK(nd.ni_vp, 0, td);
 	vn_close(nd.ni_vp, FREAD, cred, td);
+	VFS_UNLOCK_GIANT(vfslocked);
 	nd.ni_vp = NULL;
 	if (reclen != 0) {
 		printf("can't read %d\n", reclen);
@@ -1571,6 +1576,7 @@
 	if (nd.ni_vp != NULL) {
 		VOP_UNLOCK(nd.ni_vp, 0, td);
 		vn_close(nd.ni_vp, FREAD, cred, td);
+		VFS_UNLOCK_GIANT(vfslocked);
 	}
 	/*
 	 * If nothing found or hints is absent - fallback to the old

==== //depot/projects/smpng/sys/kern/link_elf.c#33 (text+ko) ====

@@ -556,17 +556,17 @@
     int symstrindex;
     int symcnt;
     int strcnt;
-
-    GIANT_REQUIRED;
+    int vfslocked;
 
     shdr = NULL;
     lf = NULL;
 
-    NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);
+    NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
     flags = FREAD;
     error = vn_open(&nd, &flags, 0, -1);
     if (error)
 	return error;
+    vfslocked = NDHASGIANT(&nd);
     NDFREE(&nd, NDF_ONLY_PNBUF);
 #ifdef MAC
     error = mac_check_kld_load(curthread->td_ucred, nd.ni_vp);
@@ -859,6 +859,7 @@
 	free(firstpage, M_LINKER);
     VOP_UNLOCK(nd.ni_vp, 0, td);
     vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
+    VFS_UNLOCK_GIANT(vfslocked);
 
     return error;
 }

==== //depot/projects/smpng/sys/kern/link_elf_obj.c#9 (text+ko) ====

@@ -393,19 +393,19 @@
 	int nsym;
 	int pb, rl, ra;
 	int alignmask;
-
-	GIANT_REQUIRED;
+	int vfslocked;
 
 	shdr = NULL;
 	lf = NULL;
 	mapsize = 0;
 	hdr = NULL;
 
-	NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td);
+	NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td);
 	flags = FREAD;
 	error = vn_open(&nd, &flags, 0, -1);
 	if (error)
 		return error;
+	vfslocked = NDHASGIANT(&nd);
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 #ifdef MAC
 	error = mac_check_kld_load(td->td_ucred, nd.ni_vp);
@@ -788,6 +788,7 @@
 		free(hdr, M_LINKER);
 	VOP_UNLOCK(nd.ni_vp, 0, td);
 	vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
+	VFS_UNLOCK_GIANT(vfslocked);
 
 	return error;
 }

==== //depot/projects/smpng/sys/notes#69 (text+ko) ====

@@ -104,6 +104,7 @@
       + linker_load_module
       + linker_file_lookup_set
       + linker_file_unload
+  - really remove Giant
 
 Active child branches:
 - jhb_intr - fast ithreads and MSI? (perhaps do MSI in jhb_acpipci)


More information about the p4-projects mailing list