Skip to content

Commit

Permalink
smb3: use filemap_write_and_wait_range instead of filemap_write_and_wait
Browse files Browse the repository at this point in the history
When doing insert range and collapse range we should be
writing out the cached pages for the ranges affected but not
the whole file.

Fixes: c3a72bb ("smb3: Move the flush out of smb2_copychunk_range() into its callers")
Cc: [email protected]
Reviewed-by: Paulo Alcantara (SUSE) <[email protected]>
Reviewed-by: David Howells <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
Steve French committed Aug 30, 2022
1 parent 9c8b7a2 commit 3e3761f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions fs/cifs/cifsfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1219,8 +1219,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,

cifs_dbg(FYI, "copychunk range\n");

filemap_write_and_wait(src_inode->i_mapping);

if (!src_file->private_data || !dst_file->private_data) {
rc = -EBADF;
cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
Expand Down Expand Up @@ -1250,6 +1248,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
lock_two_nondirectories(target_inode, src_inode);

cifs_dbg(FYI, "about to flush pages\n");

rc = filemap_write_and_wait_range(src_inode->i_mapping, off,
off + len - 1);
if (rc)
goto out;

/* should we flush first and last page first */
truncate_inode_pages(&target_inode->i_data, 0);

Expand Down
9 changes: 7 additions & 2 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -3687,7 +3687,10 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
}

filemap_invalidate_lock(inode->i_mapping);
filemap_write_and_wait(inode->i_mapping);
rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
if (rc < 0)
goto out_2;

truncate_pagecache_range(inode, off, old_eof);

rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
Expand Down Expand Up @@ -3738,7 +3741,9 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
eof = cpu_to_le64(old_eof + len);

filemap_invalidate_lock(inode->i_mapping);
filemap_write_and_wait(inode->i_mapping);
rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
if (rc < 0)
goto out_2;
truncate_pagecache_range(inode, off, old_eof);

rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
Expand Down

0 comments on commit 3e3761f

Please sign in to comment.