iget_locked et.al.: make sure we don't return bad inodes
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 4 Jul 2016 03:15:21 +0000 (23:15 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 4 Jul 2016 03:15:21 +0000 (23:15 -0400)
commit2864f301424227d9d3bde6d550bc224a83535b46
tree7d6535793143e2d542fa69bfdf6ba776b8846ccb
parent1a695a905c18548062509178b98bc91e67510864
iget_locked et.al.: make sure we don't return bad inodes

If one thread does iget_locked(), proceeds to try and set
the new inode up and fails, inode will be unhashed and dropped.
However, another thread doing ilookup/iget_locked in the middle
of that would end up finding a half-set-up inode, grabbing
a reference, waiting for it to come unlocked and getting the
resulting bad inode.  It's a race (if that ilookup had been
called just after the failure of setup attempt it wouldn't
have found the sucker at all), particularly unpleasant in
cases when failure is transient/caller-dependent/etc.

While it can be dealt with in the callers, there's no reason
not to handle it in fs/inode.c primitives, especially since
the cost is trivial.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/inode.c