smbd/ioctl: add FSCTL_SET_ZERO_DATA support
authorDavid Disseldorp <ddiss@samba.org>
Tue, 10 Feb 2015 23:24:16 +0000 (00:24 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 9 Mar 2015 20:27:07 +0000 (21:27 +0100)
commit1359e859328567090bf80911083605e17fbd4519
treed4fca3226a1bf6b13e64bbea26de10c4bfc7f862
parent47f15b14ae4f3a9d83ed6f7c9ad31e74978e9606
smbd/ioctl: add FSCTL_SET_ZERO_DATA support

FSCTL_SET_ZERO_DATA can be used in two ways.
- When requested against a file marked as sparse, it provides a
  mechanism for requesting that the server deallocate the underlying
  disk space for the corresponding zeroed range.
- When requested against a non-sparse file, it indicates that the server
  should allocate and zero the corresponding range.

Both use cases can be handled in Samba using fallocate(). The Linux
specific FALLOC_FL_PUNCH_HOLE flag can be used to deallocate the
underlying disk space. After doing so, a normal fallocate() call can
be used to ensure that the zeroed range is allocated on non-sparse
files.

FSCTL_SET_ZERO_DATA requests must not result in a change to the file
size. The FSCTL_SET_ZERO_DATA handler always calls fallocate() with the
KEEP_SIZE flag set, ensuring that Samba meets this requirement.

Signed-off-by: David Disseldorp <ddiss@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/smbd/smb2_ioctl_filesys.c