Skip to content

Commit 93a4315

Browse files
dhowellsSteve French
authored andcommitted
cifs: Fix missing set of remote_i_size
Occasionally, the generic/001 xfstest will fail indicating corruption in one of the copy chains when run on cifs against a server that supports FSCTL_DUPLICATE_EXTENTS_TO_FILE (eg. Samba with a share on btrfs). The problem is that the remote_i_size value isn't updated by cifs_setsize() when called by smb2_duplicate_extents(), but i_size *is*. This may cause cifs_remap_file_range() to then skip the bit after calling ->duplicate_extents() that sets sizes. Fix this by calling netfs_resize_file() in smb2_duplicate_extents() before calling cifs_setsize() to set i_size. This means we don't then need to call netfs_resize_file() upon return from ->duplicate_extents(), but we also fix the test to compare against the pre-dup inode size. [Note that this goes back before the addition of remote_i_size with the netfs_inode struct. It should probably have been setting cifsi->server_eof previously.] Fixes: cfc63fc ("smb3: fix cached file size problems in duplicate extents (reflink)") Signed-off-by: David Howells <dhowells@redhat.com> cc: Steve French <sfrench@samba.org> cc: Paulo Alcantara <pc@manguebit.com> cc: Shyam Prasad N <nspmangalore@gmail.com> cc: Rohith Surabattula <rohiths.msft@gmail.com> cc: Jeff Layton <jlayton@kernel.org> cc: linux-cifs@vger.kernel.org cc: netfs@lists.linux.dev Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 8a16072 commit 93a4315

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fs/smb/client/cifsfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
12261226
struct cifsFileInfo *smb_file_src = src_file->private_data;
12271227
struct cifsFileInfo *smb_file_target = dst_file->private_data;
12281228
struct cifs_tcon *target_tcon, *src_tcon;
1229-
unsigned long long destend, fstart, fend, new_size;
1229+
unsigned long long destend, fstart, fend, old_size, new_size;
12301230
unsigned int xid;
12311231
int rc;
12321232

@@ -1293,6 +1293,7 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
12931293
goto unlock;
12941294
if (fend > target_cifsi->netfs.zero_point)
12951295
target_cifsi->netfs.zero_point = fend + 1;
1296+
old_size = target_cifsi->netfs.remote_i_size;
12961297

12971298
/* Discard all the folios that overlap the destination region. */
12981299
cifs_dbg(FYI, "about to discard pages %llx-%llx\n", fstart, fend);
@@ -1305,9 +1306,8 @@ static loff_t cifs_remap_file_range(struct file *src_file, loff_t off,
13051306
if (target_tcon->ses->server->ops->duplicate_extents) {
13061307
rc = target_tcon->ses->server->ops->duplicate_extents(xid,
13071308
smb_file_src, smb_file_target, off, len, destoff);
1308-
if (rc == 0 && new_size > i_size_read(target_inode)) {
1309+
if (rc == 0 && new_size > old_size) {
13091310
truncate_setsize(target_inode, new_size);
1310-
netfs_resize_file(&target_cifsi->netfs, new_size, true);
13111311
fscache_resize_cookie(cifs_inode_cookie(target_inode),
13121312
new_size);
13131313
}

fs/smb/client/smb2ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,6 +2028,7 @@ smb2_duplicate_extents(const unsigned int xid,
20282028
* size will be queried on next revalidate, but it is important
20292029
* to make sure that file's cached size is updated immediately
20302030
*/
2031+
netfs_resize_file(netfs_inode(inode), dest_off + len, true);
20312032
cifs_setsize(inode, dest_off + len);
20322033
}
20332034
rc = SMB2_ioctl(xid, tcon, trgtfile->fid.persistent_fid,

0 commit comments

Comments
 (0)