Skip to content

Commit 3e3761f

Browse files
committed
smb3: use filemap_write_and_wait_range instead of filemap_write_and_wait
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]>
1 parent 9c8b7a2 commit 3e3761f

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

fs/cifs/cifsfs.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,8 +1219,6 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
12191219

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

1222-
filemap_write_and_wait(src_inode->i_mapping);
1223-
12241222
if (!src_file->private_data || !dst_file->private_data) {
12251223
rc = -EBADF;
12261224
cifs_dbg(VFS, "missing cifsFileInfo on copy range src file\n");
@@ -1250,6 +1248,12 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
12501248
lock_two_nondirectories(target_inode, src_inode);
12511249

12521250
cifs_dbg(FYI, "about to flush pages\n");
1251+
1252+
rc = filemap_write_and_wait_range(src_inode->i_mapping, off,
1253+
off + len - 1);
1254+
if (rc)
1255+
goto out;
1256+
12531257
/* should we flush first and last page first */
12541258
truncate_inode_pages(&target_inode->i_data, 0);
12551259

fs/cifs/smb2ops.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,10 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
36873687
}
36883688

36893689
filemap_invalidate_lock(inode->i_mapping);
3690-
filemap_write_and_wait(inode->i_mapping);
3690+
rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof - 1);
3691+
if (rc < 0)
3692+
goto out_2;
3693+
36913694
truncate_pagecache_range(inode, off, old_eof);
36923695

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

37403743
filemap_invalidate_lock(inode->i_mapping);
3741-
filemap_write_and_wait(inode->i_mapping);
3744+
rc = filemap_write_and_wait_range(inode->i_mapping, off, old_eof + len - 1);
3745+
if (rc < 0)
3746+
goto out_2;
37423747
truncate_pagecache_range(inode, off, old_eof);
37433748

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

0 commit comments

Comments
 (0)