summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_descrip.c
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2012-06-17 16:59:37 +0000
committerpjd <pjd@FreeBSD.org>2012-06-17 16:59:37 +0000
commit32ff81e94ffc0093230891906286153e73046786 (patch)
tree54fa2826781f96b9400c8fda1f39a603bfa8c2f0 /sys/kern/kern_descrip.c
parent9a81d01ee060edcfe2d98f6c8d5b7863f3120ce0 (diff)
downloadFreeBSD-src-32ff81e94ffc0093230891906286153e73046786.zip
FreeBSD-src-32ff81e94ffc0093230891906286153e73046786.tar.gz
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
Diffstat (limited to 'sys/kern/kern_descrip.c')
-rw-r--r--sys/kern/kern_descrip.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index d7a2c23..6850734 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -672,7 +672,23 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
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);
OpenPOWER on IntegriCloud