cifs: Fix FALLOC_FL_ZERO_RANGE by setting i_size if EOF moved
authorDavid Howells <dhowells@redhat.com>
Wed, 29 Nov 2023 16:56:17 +0000 (16:56 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Dec 2023 07:52:15 +0000 (08:52 +0100)
commit 83d5518b124dfd605f10a68128482c839a239f9d upstream.

Fix the cifs filesystem implementations of FALLOC_FL_ZERO_RANGE, in
smb3_zero_range(), to set i_size after extending the file on the server.

Fixes: 72c419d9b073 ("cifs: fix smb3_zero_range so it can expand the file-size when required")
Cc: stable@vger.kernel.org
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: 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: linux-mm@kvack.org
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/smb/client/smb2ops.c

index 0f8fa78..16512f4 100644 (file)
@@ -3305,6 +3305,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
        struct inode *inode = file_inode(file);
        struct cifsInodeInfo *cifsi = CIFS_I(inode);
        struct cifsFileInfo *cfile = file->private_data;
+       unsigned long long new_size;
        long rc;
        unsigned int xid;
        __le64 eof;
@@ -3335,10 +3336,15 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
        /*
         * do we also need to change the size of the file?
         */
-       if (keep_size == false && i_size_read(inode) < offset + len) {
-               eof = cpu_to_le64(offset + len);
+       new_size = offset + len;
+       if (keep_size == false && (unsigned long long)i_size_read(inode) < new_size) {
+               eof = cpu_to_le64(new_size);
                rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
                                  cfile->fid.volatile_fid, cfile->pid, &eof);
+               if (rc >= 0) {
+                       truncate_setsize(inode, new_size);
+                       fscache_resize_cookie(cifs_inode_cookie(inode), new_size);
+               }
        }
 
  zero_range_exit: