[Libguestfs] [nbdkit PATCH 3/3] RFC swab: Re-enable .extents

Eric Blake eblake at redhat.com
Tue Jul 7 22:22:47 UTC 2020


This reverts commit 2c5aec42cf04c567639bd885cf12a57192229215.

Now that we have an easy way to generate aligned extents from the
plugin, where the client will never see an unaligned extent
transition, it's time to put it to use.

Signed-off-by: Eric Blake <eblake at redhat.com>

---
Here's what I used on the command line; I need to turn it into a formal test:

$ ./nbdkit -U - eval pread='exit 1' get_size='echo 8' can_extents='exit 0' \
 extents='printf "0 3\n3 4 hole,zero\n7 1\n"' --run \
 'qemu-img map -f raw --output=json $uri'
$ ./nbdkit -U - --filter=swab eval pread='exit 1' get_size='echo 8' can_extents='exit 0' extents='printf "0 3\n3 4 hole,zero\n7 1\n"' --run 'qemu-img map -f raw --output=json $uri'

except it's currently failing:
nbdkit: eval[1]: error: swab: requests to this filter must be aligned
nbdkit: backend.c:621: backend_extents: Assertion `*err' failed.
qemu-img: Could not read file metadata: Input/output error
---
 filters/swab/swab.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/filters/swab/swab.c b/filters/swab/swab.c
index 57a51aee..2e423bbf 100644
--- a/filters/swab/swab.c
+++ b/filters/swab/swab.c
@@ -191,15 +191,15 @@ swab_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
   return next_ops->zero (nxdata, count, offset, flags, err);
 }

-/* FIXME: Extents could be useful, but if the underlying plugin ever reports
- * values not aligned to 2 bytes, it is complicated to adjust that correctly.
- * In the short term, we punt by disabling extents.
- */
+/* Extents. */
 static int
-swab_can_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
-                  void *handle)
+swab_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)
 {
-  return 0;
+  if (!is_aligned (count, offset)) return -1;
+  return nbdkit_extents_aligned (next_ops, nxdata, count, offset, flags,
+                                 bits/8, extents, err);
 }

 /* Cache. */
@@ -223,7 +223,7 @@ static struct nbdkit_filter filter = {
   .pwrite            = swab_pwrite,
   .trim              = swab_trim,
   .zero              = swab_zero,
-  .can_extents       = swab_can_extents,
+  .extents           = swab_extents,
   .cache             = swab_cache,
 };

-- 
2.27.0




More information about the Libguestfs mailing list