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

From: Alfred Perlstein <alfred_at_freebsd.org>
Date: Mon, 6 Dec 2004 23:20:24 -0800
* 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
_at__at_ -1570,17 +1570,17 _at__at_
 	 * 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
Received on Tue Dec 07 2004 - 07:20:26 UTC