plugins: Wire up file-based plugin support for NBD_INFO_INIT_STATE
commitc5dc657a0f52954ea222dc1b2f6b9afa1b82afbb
authorEric Blake <eblake@redhat.com>
Mon, 3 Feb 2020 22:36:37 +0000 (3 16:36 -0600)
committerEric Blake <eblake@redhat.com>
Mon, 10 Feb 2020 19:57:29 +0000 (10 13:57 -0600)
treef44d8b7203a7bfc2813de0549c38ea61b4e34cd4
parentfdc7fa02a4002bcbf2ff9add2eca2bb03373221a
plugins: Wire up file-based plugin support for NBD_INFO_INIT_STATE

The NBD protocol is adding an extension to let servers advertise
initialization state to the client: whether the image contains holes,
and whether it is known to read as all zeroes.  For file-based
plugins, we are already probing lseek(SEEK_HOLE) to learn if extents
are supported; a slight tweak to remember if that result is EOF tells
us if we are sparse, and a similar lseek(SEEK_DATA) returning ENXIO
tells us if the entire file is a hole, with at most two lseek calls
during open (rather than one lseek for each of .can_extents,
.init_sparse, and .init_zero).  The split plugin is similar to file.
For partitioning and linuxdisk, we know we are exposing a sparse
image.  For other file-based plugins, like ext2, we do not yet expose
.extents so it is not worth trying to expose .init_sparse or
.init_zero.

A successful test depends on whether the current file system creates
sparse files, but it was easy enough to ensure the test skips rather
than fails when that is not the case.

Signed-off-by: Eric Blake <eblake@redhat.com>
plugins/file/file.c
plugins/linuxdisk/linuxdisk.c
plugins/partitioning/partitioning.c
plugins/split/split.c
tests/Makefile.am
tests/test-file-init.sh [new file with mode: 0755]