Skip to content

Commit

Permalink
vfs: call vfs_clone_file_range() under freeze protection
Browse files Browse the repository at this point in the history
Move sb_start_write()/sb_end_write() out of the vfs helper and up into the
ioctl handler.

Signed-off-by: Amir Goldstein <[email protected]>
Signed-off-by: Miklos Szeredi <[email protected]>
  • Loading branch information
amir73il authored and Miklos Szeredi committed Dec 16, 2016
1 parent 913b86e commit 031a072
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static long ioctl_file_clone(struct file *dst_file, unsigned long srcfd,
ret = -EXDEV;
if (src_file.file->f_path.mnt != dst_file->f_path.mnt)
goto fdput;
ret = vfs_clone_file_range(src_file.file, off, dst_file, destoff, olen);
ret = do_clone_file_range(src_file.file, off, dst_file, destoff, olen);
fdput:
fdput(src_file);
return ret;
Expand Down
3 changes: 1 addition & 2 deletions fs/nfsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ __be32 nfsd4_set_nfs4_label(struct svc_rqst *rqstp, struct svc_fh *fhp,
__be32 nfsd4_clone_file_range(struct file *src, u64 src_pos, struct file *dst,
u64 dst_pos, u64 count)
{
return nfserrno(vfs_clone_file_range(src, src_pos, dst, dst_pos,
count));
return nfserrno(do_clone_file_range(src, src_pos, dst, dst_pos, count));
}

ssize_t nfsd_copy_file_range(struct file *src, u64 src_pos, struct file *dst,
Expand Down
3 changes: 0 additions & 3 deletions fs/read_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,16 +1687,13 @@ int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
if (pos_in + len > i_size_read(inode_in))
return -EINVAL;

sb_start_write(inode_out->i_sb);

ret = file_in->f_op->clone_file_range(file_in, pos_in,
file_out, pos_out, len);
if (!ret) {
fsnotify_access(file_in);
fsnotify_modify(file_out);
}

sb_end_write(inode_out->i_sb);
return ret;
}
EXPORT_SYMBOL(vfs_clone_file_range);
Expand Down
13 changes: 13 additions & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1783,6 +1783,19 @@ extern int vfs_clone_file_range(struct file *file_in, loff_t pos_in,
extern int vfs_dedupe_file_range(struct file *file,
struct file_dedupe_range *same);

static inline int do_clone_file_range(struct file *file_in, loff_t pos_in,
struct file *file_out, loff_t pos_out,
u64 len)
{
int ret;

sb_start_write(file_inode(file_out)->i_sb);
ret = vfs_clone_file_range(file_in, pos_in, file_out, pos_out, len);
sb_end_write(file_inode(file_out)->i_sb);

return ret;
}

struct super_operations {
struct inode *(*alloc_inode)(struct super_block *sb);
void (*destroy_inode)(struct inode *);
Expand Down

0 comments on commit 031a072

Please sign in to comment.