Skip to content

Commit

Permalink
cifs: truncate the inode and mapping when we simulate fcollapse
Browse files Browse the repository at this point in the history
commit 84330d4 upstream.

RHBZ:1997367

When we collapse a range in smb3_collapse_range() we must make sure
we update the inode size and pagecache accordingly.

If not, both inode size and pagecahce may be stale until it is refreshed.

This can be demonstrated for the inode size by running :

xfs_io -i -f -c "truncate 320k" -c "fcollapse 64k 128k" -c "fiemap -v"  \
/mnt/testfile

where we can see the result of stale data in the fiemap output.
The third line of the output is wrong, all this data should be truncated.

 EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
   0: [0..127]:        hole               128
   1: [128..383]:      128..383           256   0x1
   2: [384..639]:      hole               256

And the correct output, when the inode size has been updated correctly should
look like this:

 EXT: FILE-OFFSET      BLOCK-RANGE      TOTAL FLAGS
   0: [0..127]:        hole               128
   1: [128..383]:      128..383           256   0x1

Reported-by: Xiaoli Feng <xifeng@redhat.com>
Reported-by: kernel test robot <lkp@intel.com>
Cc: stable@vger.kernel.org
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ronnie Sahlberg authored and Greg Kroah-Hartman committed Apr 8, 2022
1 parent 4d51bbc commit 5c97206
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "smb2glob.h"
#include "cifs_ioctl.h"
#include "smbdirect.h"
#include "fscache.h"
#include "fs_context.h"

/* Change credits for different ops and return the total number of credits */
Expand Down Expand Up @@ -3887,29 +3888,38 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
{
int rc;
unsigned int xid;
struct inode *inode;
struct cifsFileInfo *cfile = file->private_data;
struct cifsInodeInfo *cifsi;
__le64 eof;

xid = get_xid();

if (off >= i_size_read(file->f_inode) ||
off + len >= i_size_read(file->f_inode)) {
inode = d_inode(cfile->dentry);
cifsi = CIFS_I(inode);

if (off >= i_size_read(inode) ||
off + len >= i_size_read(inode)) {
rc = -EINVAL;
goto out;
}

rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
i_size_read(file->f_inode) - off - len, off);
i_size_read(inode) - off - len, off);
if (rc < 0)
goto out;

eof = cpu_to_le64(i_size_read(file->f_inode) - len);
eof = cpu_to_le64(i_size_read(inode) - len);
rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
cfile->fid.volatile_fid, cfile->pid, &eof);
if (rc < 0)
goto out;

rc = 0;

cifsi->server_eof = i_size_read(inode) - len;
truncate_setsize(inode, cifsi->server_eof);
fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof);
out:
free_xid(xid);
return rc;
Expand Down

0 comments on commit 5c97206

Please sign in to comment.