lookup_open(): lock the parent shared unless O_CREAT is given
authorAl Viro <viro@zeniv.linux.org.uk>
Thu, 28 Apr 2016 23:35:16 +0000 (19:35 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Mon, 2 May 2016 23:51:17 +0000 (19:51 -0400)
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Documentation/filesystems/porting
fs/namei.c

index 12c57ab..46f3bb7 100644 (file)
@@ -575,3 +575,6 @@ in your dentry operations instead.
 
        Old method is only used if the new one is absent; eventually it will
        be removed.  Switch while you still can; the old one won't stay.
+--
+[mandatory]
+       ->atomic_open() calls without O_CREAT may happen in parallel.
index b84e6b2..01069dd 100644 (file)
@@ -3084,7 +3084,7 @@ static int do_last(struct nameidata *nd,
        }
 
 retry_lookup:
-       if (op->open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) {
+       if (open_flag & (O_CREAT | O_TRUNC | O_WRONLY | O_RDWR)) {
                error = mnt_want_write(nd->path.mnt);
                if (!error)
                        got_write = true;
@@ -3094,9 +3094,15 @@ retry_lookup:
                 * dropping this one anyway.
                 */
        }
-       inode_lock(dir->d_inode);
+       if (open_flag & O_CREAT)
+               inode_lock(dir->d_inode);
+       else
+               inode_lock_shared(dir->d_inode);
        error = lookup_open(nd, &path, file, op, got_write, opened);
-       inode_unlock(dir->d_inode);
+       if (open_flag & O_CREAT)
+               inode_unlock(dir->d_inode);
+       else
+               inode_unlock_shared(dir->d_inode);
 
        if (error <= 0) {
                if (error)