Module Name:    src
Committed By:   dyoung
Date:           Fri Jul 10 23:07:55 UTC 2009

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

Log Message:
In lwp_create(), take a reference to l2's filedesc_t instead of
taking a reference to curlwp's by calling fd_hold().  If lwp_create()
is called from fork1(), then l2 != curlwp, but l2's and not curlwp's
filedesc_t whose reference we should take.

This change stops the problem I describe in
<http://mail-index.netbsd.org/tech-kern/2009/07/09/msg005422.html>,
where /dev/rsd0a is never properly closed after fsck / runs on it.
This change seems to quiet my USB backup drive, sd0 at scsibus0 at
umass0, which had stopped spinning down when it was not in use:
The unit probably stayed open after mount(8) tried (and failed:
errant fstab entry) to mount it.

I am confident that this change is an improvement, but I doubt that
it is the last word on the matter.  I hate to get under the filedesc_t
abstraction by fiddling with fd_refcnt, and there may be something
I have missed, so somebody with greater understanding of the file
descriptors code should have a look.


To generate a diff of this commit:
cvs rdiff -u -r1.131 -r1.132 src/sys/kern/kern_lwp.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/kern_lwp.c
diff -u src/sys/kern/kern_lwp.c:1.131 src/sys/kern/kern_lwp.c:1.132
--- src/sys/kern/kern_lwp.c:1.131	Sat May 23 18:28:06 2009
+++ src/sys/kern/kern_lwp.c	Fri Jul 10 23:07:54 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_lwp.c,v 1.131 2009/05/23 18:28:06 ad Exp $	*/
+/*	$NetBSD: kern_lwp.c,v 1.132 2009/07/10 23:07:54 dyoung Exp $	*/
 
 /*-
  * Copyright (c) 2001, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -210,7 +210,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.131 2009/05/23 18:28:06 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.132 2009/07/10 23:07:54 dyoung Exp $");
 
 #include "opt_ddb.h"
 #include "opt_lockdebug.h"
@@ -606,7 +606,7 @@
 	l2->l_fd = p2->p_fd;
 	if (p2->p_nlwps != 0) {
 		KASSERT(l1->l_proc == p2);
-		fd_hold();
+		atomic_inc_uint(&l2->l_fd->fd_refcnt);
 	} else {
 		KASSERT(l1->l_proc != p2);
 	}

Reply via email to