cifs: improve fallocate emulation
authorRonnie Sahlberg <lsahlber@redhat.com>
Thu, 3 Jun 2021 05:31:01 +0000 (15:31 +1000)
committerSteve French <stfrench@microsoft.com>
Mon, 21 Jun 2021 02:28:16 +0000 (21:28 -0500)
commit966a3cb7c7db786452a87afdc3b48858fc4d4d6b
tree08756e4a7f13bb4f49b363b1409d0e16c9c6b6a7
parentaaf36df3eddde763e6fe2b082db101820f2d2a90
cifs: improve fallocate emulation

RHBZ: 1866684

We don't have a real fallocate in the SMB2 protocol so we used to emulate fallocate
by simply switching the file to become non-sparse. But as that could potantially consume
a lot more data than we intended to fallocate (large sparse file and fallocating a thin
slice in the middle) we would only do this IFF the fallocate request was for virtually
the entire file.

This patch improves this and starts allowing us to fallocate smaller chunks of a file by
overwriting the region with 0, for the parts that are unallocated.

The method used is to first query the server for FSCTL_QUERY_ALLOCATED_RANGES to find what
is unallocated in the fallocate range and then to only overwrite-with-zero the unallocated
ranges to fill in the holes.

As overwriting-with-zero is different from just allocating blocks, and potentially much
more expensive, we limit this to only allow fallocate ranges up to 1Mb in size.

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Acked-by: Aurelien Aptel <aaptel@suse.com>
Acked-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/smb2ops.c