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
This commit is contained in:
Pawel Jakub Dawidek 2012-06-17 16:59:37 +00:00
parent fd6049b186
commit 604a7c2f00
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=237199

View File

@ -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);