diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2013-06-11 08:34:36 +0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2013-06-29 12:57:11 +0400 |
commit | f4e0c30c191f87851c4a53454abb55ee276f4a7e (patch) | |
tree | 8bdb4f81dea303f93f1d646034653c8af3fba323 /fs/namei.c | |
parent | 60545d0d4610b02e55f65d141c95b18ccf855b6e (diff) |
allow the temp files created by open() to be linked to
O_TMPFILE | O_CREAT => linkat() with AT_SYMLINK_FOLLOW and /proc/self/fd/<n>
as oldpath (i.e. flink()) will create a link
O_TMPFILE | O_CREAT | O_EXCL => ENOENT on attempt to link those guys
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/fs/namei.c b/fs/namei.c index 778e253e3d48..66998b06d822 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -2948,8 +2948,14 @@ static int do_tmpfile(int dfd, struct filename *pathname, if (error) goto out2; error = open_check_o_direct(file); - if (error) + if (error) { fput(file); + } else if (!(op->open_flag & O_EXCL)) { + struct inode *inode = file_inode(file); + spin_lock(&inode->i_lock); + inode->i_state |= I_LINKABLE; + spin_unlock(&inode->i_lock); + } out2: mnt_drop_write(nd->path.mnt); out: @@ -3628,12 +3634,18 @@ int vfs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *new_de mutex_lock(&inode->i_mutex); /* Make sure we don't allow creating hardlink to an unlinked file */ - if (inode->i_nlink == 0) + if (inode->i_nlink == 0 && !(inode->i_state & I_LINKABLE)) error = -ENOENT; else if (max_links && inode->i_nlink >= max_links) error = -EMLINK; else error = dir->i_op->link(old_dentry, dir, new_dentry); + + if (!error && (inode->i_state & I_LINKABLE)) { + spin_lock(&inode->i_lock); + inode->i_state &= ~I_LINKABLE; + spin_unlock(&inode->i_lock); + } mutex_unlock(&inode->i_mutex); if (!error) fsnotify_link(dir, inode, new_dentry); |