]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cifs: truncate the inode and mapping when we simulate fcollapse
authorRonnie Sahlberg <lsahlber@redhat.com>
Wed, 23 Feb 2022 01:14:16 +0000 (11:14 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Apr 2022 11:57:16 +0000 (13:57 +0200)
commit 84330d41efb12bc227899e54dbdbe7d9590cb2b7 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>
fs/cifs/smb2ops.c

index af5d0830bc8a801e8897291f24234194e1c51002..891b11576e557b090503fcce4caff1f18de89333 100644 (file)
@@ -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 */
@@ -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;