Since a client is very likely to make further I/O calls at offsets
returned in a block status call (for example, 'nbdinfo --map
--totals'), and the blocksize-policy filter can set a minimum
alignment larger than what the plugin does by default, it makes sense
to force extents to that alignment.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
tests/Makefile.am | 2 ++
filters/blocksize-policy/policy.c | 15 ++++++++++++++-
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 63730821..242a03e4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1656,11 +1656,13 @@ TESTS += \
test-blocksize-policy.sh \
test-blocksize-error-policy.sh \
test-blocksize-write-disconnect.sh \
+ test-blocksize-policy-extents.sh \
$(NULL)
EXTRA_DIST += \
test-blocksize-policy.sh \
test-blocksize-error-policy.sh \
test-blocksize-write-disconnect.sh \
+ test-blocksize-policy-extents.sh \
$(NULL)
if HAVE_BZLIB
diff --git a/filters/blocksize-policy/policy.c b/filters/blocksize-policy/policy.c
index 51bea91e..d656c956 100644
--- a/filters/blocksize-policy/policy.c
+++ b/filters/blocksize-policy/policy.c
@@ -38,6 +38,7 @@
#include <inttypes.h>
#include <string.h>
#include <errno.h>
+#include <assert.h>
#include <nbdkit-filter.h>
@@ -373,10 +374,22 @@ policy_extents (nbdkit_next *next,
void *handle, uint32_t count, uint64_t offset, uint32_t flags,
struct nbdkit_extents *extents, int *err)
{
+ uint32_t minimum, preferred, maximum;
+ int res;
+
if (check_policy (next, handle, "extents", false, count, offset, err) == -1)
return -1;
- return next->extents (next, count, offset, flags, extents, err);
+ /* Munge the plugin's response to values that match the alignment we
+ * are enforcing; that way, a client that performs later operations
+ * at boundaries determined by the block status result will still be
+ * aligned. Since check_policy succeeded, policy_block_size will too.
+ */
+ res = policy_block_size (next, handle,
+ &minimum, &preferred, &maximum);
+ assert (res == 0);
+ return nbdkit_extents_aligned (next, count, offset, flags,
+ minimum ?: 1, extents, err);
}
static struct nbdkit_filter filter = {
--
2.49.0