Skip to content

Commit 863f144

Browse files
author
Miklos Szeredi
committed
vfs: open inside ->tmpfile()
This is in preparation for adding tmpfile support to fuse, which requires that the tmpfile creation and opening are done as a single operation. Replace the 'struct dentry *' argument of i_op->tmpfile with 'struct file *'. Call finish_open_simple() as the last thing in ->tmpfile() instances (may be omitted in the error case). Change d_tmpfile() argument to 'struct file *' as well to make callers more readable. Reviewed-by: Christian Brauner (Microsoft) <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 9751b33 commit 863f144

File tree

19 files changed

+70
-49
lines changed

19 files changed

+70
-49
lines changed

Documentation/filesystems/locking.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ prototypes::
7979
int (*atomic_open)(struct inode *, struct dentry *,
8080
struct file *, unsigned open_flag,
8181
umode_t create_mode);
82-
int (*tmpfile) (struct inode *, struct dentry *, umode_t);
82+
int (*tmpfile) (struct user_namespace *, struct inode *,
83+
struct file *, umode_t);
8384
int (*fileattr_set)(struct user_namespace *mnt_userns,
8485
struct dentry *dentry, struct fileattr *fa);
8586
int (*fileattr_get)(struct dentry *dentry, struct fileattr *fa);

Documentation/filesystems/porting.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,3 +922,13 @@ is provided - file_open_root_mnt(). In-tree users adjusted.
922922
no_llseek is gone; don't set .llseek to that - just leave it NULL instead.
923923
Checks for "does that file have llseek(2), or should it fail with ESPIPE"
924924
should be done by looking at FMODE_LSEEK in file->f_mode.
925+
926+
---
927+
928+
**mandatory**
929+
930+
Calling conventions for ->tmpfile() have changed. It now takes a struct
931+
file pointer instead of struct dentry pointer. d_tmpfile() is similarly
932+
changed to simplify callers. The passed file is in a non-open state and on
933+
success must be opened before returning (e.g. by calling
934+
finish_open_simple()).

Documentation/filesystems/vfs.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ As of kernel 2.6.22, the following members are defined:
439439
void (*update_time)(struct inode *, struct timespec *, int);
440440
int (*atomic_open)(struct inode *, struct dentry *, struct file *,
441441
unsigned open_flag, umode_t create_mode);
442-
int (*tmpfile) (struct user_namespace *, struct inode *, struct dentry *, umode_t);
442+
int (*tmpfile) (struct user_namespace *, struct inode *, struct file *, umode_t);
443443
int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int);
444444
int (*fileattr_set)(struct user_namespace *mnt_userns,
445445
struct dentry *dentry, struct fileattr *fa);
@@ -589,7 +589,9 @@ otherwise noted.
589589
``tmpfile``
590590
called in the end of O_TMPFILE open(). Optional, equivalent to
591591
atomically creating, opening and unlinking a file in given
592-
directory.
592+
directory. On success needs to return with the file already
593+
open; this can be done by calling finish_open_simple() right at
594+
the end.
593595

594596
``fileattr_get``
595597
called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to

fs/bad_inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static int bad_inode_atomic_open(struct inode *inode, struct dentry *dentry,
147147
}
148148

149149
static int bad_inode_tmpfile(struct user_namespace *mnt_userns,
150-
struct inode *inode, struct dentry *dentry,
150+
struct inode *inode, struct file *file,
151151
umode_t mode)
152152
{
153153
return -EIO;

fs/btrfs/inode.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10168,15 +10168,15 @@ static int btrfs_permission(struct user_namespace *mnt_userns,
1016810168
}
1016910169

1017010170
static int btrfs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
10171-
struct dentry *dentry, umode_t mode)
10171+
struct file *file, umode_t mode)
1017210172
{
1017310173
struct btrfs_fs_info *fs_info = btrfs_sb(dir->i_sb);
1017410174
struct btrfs_trans_handle *trans;
1017510175
struct btrfs_root *root = BTRFS_I(dir)->root;
1017610176
struct inode *inode;
1017710177
struct btrfs_new_inode_args new_inode_args = {
1017810178
.dir = dir,
10179-
.dentry = dentry,
10179+
.dentry = file->f_path.dentry,
1018010180
.orphan = true,
1018110181
};
1018210182
unsigned int trans_num_items;
@@ -10213,7 +10213,7 @@ static int btrfs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
1021310213
set_nlink(inode, 1);
1021410214

1021510215
if (!ret) {
10216-
d_tmpfile(dentry, inode);
10216+
d_tmpfile(file, inode);
1021710217
unlock_new_inode(inode);
1021810218
mark_inode_dirty(inode);
1021910219
}
@@ -10225,7 +10225,7 @@ static int btrfs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
1022510225
out_inode:
1022610226
if (ret)
1022710227
iput(inode);
10228-
return ret;
10228+
return finish_open_simple(file, ret);
1022910229
}
1023010230

1023110231
void btrfs_set_range_writeback(struct btrfs_inode *inode, u64 start, u64 end)

fs/dcache.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3258,8 +3258,10 @@ void d_genocide(struct dentry *parent)
32583258

32593259
EXPORT_SYMBOL(d_genocide);
32603260

3261-
void d_tmpfile(struct dentry *dentry, struct inode *inode)
3261+
void d_tmpfile(struct file *file, struct inode *inode)
32623262
{
3263+
struct dentry *dentry = file->f_path.dentry;
3264+
32633265
inode_dec_link_count(inode);
32643266
BUG_ON(dentry->d_name.name != dentry->d_iname ||
32653267
!hlist_unhashed(&dentry->d_u.d_alias) ||

fs/ext2/namei.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,17 @@ static int ext2_create (struct user_namespace * mnt_userns,
120120
}
121121

122122
static int ext2_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
123-
struct dentry *dentry, umode_t mode)
123+
struct file *file, umode_t mode)
124124
{
125125
struct inode *inode = ext2_new_inode(dir, mode, NULL);
126126
if (IS_ERR(inode))
127127
return PTR_ERR(inode);
128128

129129
ext2_set_file_ops(inode);
130130
mark_inode_dirty(inode);
131-
d_tmpfile(dentry, inode);
131+
d_tmpfile(file, inode);
132132
unlock_new_inode(inode);
133-
return 0;
133+
return finish_open_simple(file, 0);
134134
}
135135

136136
static int ext2_mknod (struct user_namespace * mnt_userns, struct inode * dir,

fs/ext4/namei.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2849,7 +2849,7 @@ static int ext4_mknod(struct user_namespace *mnt_userns, struct inode *dir,
28492849
}
28502850

28512851
static int ext4_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
2852-
struct dentry *dentry, umode_t mode)
2852+
struct file *file, umode_t mode)
28532853
{
28542854
handle_t *handle;
28552855
struct inode *inode;
@@ -2871,7 +2871,7 @@ static int ext4_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
28712871
inode->i_op = &ext4_file_inode_operations;
28722872
inode->i_fop = &ext4_file_operations;
28732873
ext4_set_aops(inode);
2874-
d_tmpfile(dentry, inode);
2874+
d_tmpfile(file, inode);
28752875
err = ext4_orphan_add(handle, inode);
28762876
if (err)
28772877
goto err_unlock_inode;
@@ -2882,7 +2882,7 @@ static int ext4_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
28822882
ext4_journal_stop(handle);
28832883
if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
28842884
goto retry;
2885-
return err;
2885+
return finish_open_simple(file, err);
28862886
err_unlock_inode:
28872887
ext4_journal_stop(handle);
28882888
unlock_new_inode(inode);

fs/f2fs/namei.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
845845
}
846846

847847
static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
848-
struct dentry *dentry, umode_t mode, bool is_whiteout,
848+
struct file *file, umode_t mode, bool is_whiteout,
849849
struct inode **new_inode)
850850
{
851851
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
@@ -892,8 +892,8 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
892892
inode->i_state |= I_LINKABLE;
893893
spin_unlock(&inode->i_lock);
894894
} else {
895-
if (dentry)
896-
d_tmpfile(dentry, inode);
895+
if (file)
896+
d_tmpfile(file, inode);
897897
else
898898
f2fs_i_links_write(inode, false);
899899
}
@@ -915,16 +915,19 @@ static int __f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
915915
}
916916

917917
static int f2fs_tmpfile(struct user_namespace *mnt_userns, struct inode *dir,
918-
struct dentry *dentry, umode_t mode)
918+
struct file *file, umode_t mode)
919919
{
920920
struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
921+
int err;
921922

922923
if (unlikely(f2fs_cp_error(sbi)))
923924
return -EIO;
924925
if (!f2fs_is_checkpoint_ready(sbi))
925926
return -ENOSPC;
926927

927-
return __f2fs_tmpfile(mnt_userns, dir, dentry, mode, false, NULL);
928+
err = __f2fs_tmpfile(mnt_userns, dir, file, mode, false, NULL);
929+
930+
return finish_open_simple(file, err);
928931
}
929932

930933
static int f2fs_create_whiteout(struct user_namespace *mnt_userns,

fs/hugetlbfs/inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ static int hugetlbfs_create(struct user_namespace *mnt_userns,
917917
}
918918

919919
static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns,
920-
struct inode *dir, struct dentry *dentry,
920+
struct inode *dir, struct file *file,
921921
umode_t mode)
922922
{
923923
struct inode *inode;
@@ -926,8 +926,8 @@ static int hugetlbfs_tmpfile(struct user_namespace *mnt_userns,
926926
if (!inode)
927927
return -ENOSPC;
928928
dir->i_ctime = dir->i_mtime = current_time(dir);
929-
d_tmpfile(dentry, inode);
930-
return 0;
929+
d_tmpfile(file, inode);
930+
return finish_open_simple(file, 0);
931931
}
932932

933933
static int hugetlbfs_symlink(struct user_namespace *mnt_userns,

0 commit comments

Comments
 (0)