cvs commit: src/sys/nfsclient nfs.h nfs_lock.c nfs_lock.h nfs_nfsiod.c nfs_subs.c

Alfred Perlstein alfred at freebsd.org
Mon Dec 6 23:20:27 PST 2004


* Poul-Henning Kamp <phk at FreeBSD.org> [041206 00:31] wrote:
> phk         2004-12-06 08:31:33 UTC
> 
>   FreeBSD src repository
> 
>   Modified files:
>     sys/nfsclient        nfs.h nfs_lock.c nfs_lock.h nfs_nfsiod.c 
>                          nfs_subs.c 
>   Log:
>   For reasons unknown, the nfs locking code used a fifo to send requests to
>   userland and a dedicated system call to get replies.

Cool, thank you.  The reason it did this was that it was the code
I got from BSD/OS. :)

Anyhow, I think you can now commit this fix for filedesc locking:

Basically, others should be able to use the fdesc_mtx to make sure
that a fdesc wasn't going to disapear out from under you and also
that if you grabbed one, it would be locked valid, but because of
the nfs fifo there was a race that had to be in, which was we didn't
NULL out the fdesc pointer until too late.

Sorry if that's not so clear, but here's what should be done
if it's safe now. :)


Index: kern_descrip.c
===================================================================
RCS file: /home/ncvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.265
diff -u -r1.265 kern_descrip.c
--- kern_descrip.c	3 Dec 2004 21:29:25 -0000	1.265
+++ kern_descrip.c	7 Dec 2004 07:15:37 -0000
@@ -1570,17 +1570,17 @@
 	 * safely assume it will not change out from under us.
 	 */
 	FILEDESC_UNLOCK(fdp);
+
+	mtx_lock(&fdesc_mtx);
+	td->td_proc->p_fd = NULL;
+	mtx_unlock(&fdesc_mtx);
+
 	fpp = fdp->fd_ofiles;
 	for (i = fdp->fd_lastfile; i-- >= 0; fpp++) {
 		if (*fpp)
 			(void) closef(*fpp, td);
 	}
 
-	/* XXX This should happen earlier. */
-	mtx_lock(&fdesc_mtx);
-	td->td_proc->p_fd = NULL;
-	mtx_unlock(&fdesc_mtx);
-
 	if (fdp->fd_nfiles > NDFILE)
 		FREE(fdp->fd_ofiles, M_FILEDESC);
 	if (NDSLOTS(fdp->fd_nfiles) > NDSLOTS(NDFILE))

-- 
- Alfred Perlstein
- Research Engineering Development Inc.
- email: bright at mu.org cell: 408-480-4684


More information about the cvs-src mailing list