Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jun 2012 16:59:37 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r237199 - head/sys/kern
Message-ID:  <201206171659.q5HGxbAZ018932@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pjd
Date: Sun Jun 17 16:59:37 2012
New Revision: 237199
URL: http://svn.freebsd.org/changeset/base/237199

Log:
  Extend the comment about checking for a race with close to explain why
  it is done and why we don't return an error in such case.
  
  Discussed with:	kib
  MFC after:	1 month

Modified:
  head/sys/kern/kern_descrip.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Sun Jun 17 16:32:32 2012	(r237198)
+++ head/sys/kern/kern_descrip.c	Sun Jun 17 16:59:37 2012	(r237199)
@@ -672,7 +672,23 @@ kern_fcntl(struct thread *td, int fd, in
 			fdrop(fp, td);
 			break;
 		}
-		/* Check for race with close */
+
+		/*
+		 * Check for a race with close.
+		 *
+		 * The vnode is now advisory locked (or unlocked, but this case
+		 * is not really important) as the caller requested.
+		 * We had to drop the filedesc lock, so we need to recheck if
+		 * the descriptor is still valid, because if it was closed
+		 * in the meantime we need to remove advisory lock from the
+		 * vnode - close on any descriptor leading to an advisory
+		 * locked vnode, removes that lock.
+		 * We will return 0 on purpose in that case, as the result of
+		 * successful advisory lock might have been externally visible
+		 * already. This is fine - effectively we pretend to the caller
+		 * that the closing thread was a bit slower and that the
+		 * advisory lock succeeded before the close.
+		 */
 		FILEDESC_SLOCK(fdp);
 		if (fget_locked(fdp, fd) != fp) {
 			FILEDESC_SUNLOCK(fdp);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201206171659.q5HGxbAZ018932>