--- filters/blocksize/nbdkit-blocksize-filter.pod | 4 ++-- filters/blocksize/blocksize.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/filters/blocksize/nbdkit-blocksize-filter.pod b/filters/blocksize/nbdkit-blocksize-filter.pod index b6cf4dd..0abed2f 100644 --- a/filters/blocksize/nbdkit-blocksize-filter.pod +++ b/filters/blocksize/nbdkit-blocksize-filter.pod @@ -56,8 +56,8 @@ of 1024. =item B<maxlen=>SIZE -The maximum length for any single transaction without data (trim and -zero). If omitted, this defaults to 0xffffffff rounded down to +The maximum length for any single transaction without data (trim, zero +or extents). If omitted, this defaults to 0xffffffff rounded down to C<minsize> alignment (that is, the inherent 32-bit limit of the NBD protocol). This need not be a power of two, but must be an integer multiple of C<minblock>, and should be at least as large as diff --git a/filters/blocksize/blocksize.c b/filters/blocksize/blocksize.c index 9e0e713..55b2d59 100644 --- a/filters/blocksize/blocksize.c +++ b/filters/blocksize/blocksize.c @@ -45,6 +45,7 @@ #include <nbdkit-filter.h> #include "minmax.h" +#include "rounding.h" /* XXX See design comment in filters/cow/cow.c. */ #define THREAD_MODEL NBDKIT_THREAD_MODEL_SERIALIZE_ALL_REQUESTS @@ -372,6 +373,23 @@ blocksize_zero (struct nbdkit_next_ops *next_ops, void *nxdata, return 0; } +static int +blocksize_extents (struct nbdkit_next_ops *next_ops, void *nxdata, + void *handle, uint32_t count, uint64_t offset, + uint32_t flags, struct nbdkit_extents *extents, int *err) +{ + /* Ask the plugin for blocksize-aligned data. Since the extents + * list start is set to the real offset, everything before the + * offset is ignored automatically. Also we only need to ask for + * maxlen of data, because it's fine to return less than the full + * count as long as we're making progress. + */ + return next_ops->extents (nxdata, + MIN (count, maxlen), + ROUND_DOWN (offset, minblock), + flags, extents, err); +} + static struct nbdkit_filter filter = { .name = "blocksize", .longname = "nbdkit blocksize filter", @@ -386,6 +404,7 @@ static struct nbdkit_filter filter = { .pwrite = blocksize_pwrite, .trim = blocksize_trim, .zero = blocksize_zero, + .extents = blocksize_extents, }; NBDKIT_REGISTER_FILTER(filter) -- 2.20.1