From: NeilBrown An open() of a regular file can block if there is an active lease on that file, but this can be prevented by opening with O_NONBLOCK. An open(O_CREAT) of a non-existent file can block if there is an active delegation on the parent directory but this CANNOT be prevented with O_NONBLOCK. If nfsd is to use common VFS code for open/create it needs to be able to prevent this blocking. It is conceivable that a user-space application might need this too. So extend O_NONBLOCK protection to not block on a directory delegation when creating a file. Fixes: 134796f43a5e ("vfs: break parent dir delegations in open(..., O_CREAT) codepath") Reviewed-by: Jeff Layton Signed-off-by: NeilBrown --- fs/namei.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index d46f157e0cfc..11e3e1bee05a 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4671,8 +4671,14 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, } if (create_dir) { - struct dentry *res = vfs_mkdir_no_perm(idmap, dir_inode, dentry, mode, - &delegated_inode); + struct dentry *res; + + if (op->open_flag & O_NONBLOCK) + res = vfs_mkdir_no_perm(idmap, dir_inode, dentry, mode, + NULL); + else + res = vfs_mkdir_no_perm(idmap, dir_inode, dentry, mode, + &delegated_inode); error = PTR_ERR_OR_ZERO(res); if (!error) { dentry = res; @@ -4684,8 +4690,14 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, error = -EIO; } } else { - error = vfs_create_no_perm(idmap, dir_inode, dentry, mode, - &delegated_inode); + if (op->open_flag & O_NONBLOCK) + error = vfs_create_no_perm(idmap, dir_inode, dentry, + mode, NULL); + else + error = vfs_create_no_perm(idmap, dir_inode, dentry, + mode, &delegated_inode); + if (error) + goto out_dput; } if (error) goto out_dput; -- 2.50.0.107.gf914562f5916.dirty