[Libguestfs] [PATCH nbdkit v5 FINAL 11/19] partition: Implement mapping of extents.
Martin Kletzander
mkletzan at redhat.com
Mon Apr 1 11:42:47 UTC 2019
On Thu, Mar 28, 2019 at 04:18:38PM +0000, Richard W.M. Jones wrote:
>---
> filters/partition/partition.c | 37 +++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
>diff --git a/filters/partition/partition.c b/filters/partition/partition.c
>index c1fe7a1..bc60480 100644
>--- a/filters/partition/partition.c
>+++ b/filters/partition/partition.c
>@@ -38,6 +38,7 @@
> #include <stdint.h>
> #include <string.h>
> #include <inttypes.h>
>+#include <assert.h>
>
Either:
a) you forgot `assert (!(flags & ~(NBDKIT_FLAG_REQ_ONE)));` in this and the
previous patch,
b) this is a leftover from previous version, or
c) I missed something.
> #include <nbdkit-filter.h>
>
>@@ -222,6 +223,41 @@ partition_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
> return next_ops->zero (nxdata, count, offs + h->offset, flags, err);
> }
>
>+/* Extents. */
>+static int
>+partition_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
>+ void *handle, uint32_t count, uint64_t offs, uint32_t flags,
>+ struct nbdkit_extents *extents, int *err)
>+{
>+ struct handle *h = handle;
>+ size_t i;
>+ struct nbdkit_extents *extents2;
>+ struct nbdkit_extent e;
>+ int64_t real_size = next_ops->get_size (nxdata);
>+
>+ extents2 = nbdkit_extents_new (offs + h->offset, real_size - h->offset);
>+ if (extents2 == NULL) {
>+ *err = errno;
>+ return -1;
>+ }
>+ if (next_ops->extents (nxdata, count, offs + h->offset,
>+ flags, extents2, err) == -1)
>+ goto error;
>+
>+ for (i = 0; i < nbdkit_extents_count (extents2); ++i) {
>+ e = nbdkit_get_extent (extents2, i);
>+ e.offset -= h->offset;
>+ if (nbdkit_add_extent (extents, e.offset, e.length, e.type) == -1)
>+ goto error;
>+ }
>+ nbdkit_extents_free (extents2);
>+ return 0;
>+
>+ error:
>+ nbdkit_extents_free (extents2);
>+ return -1;
>+}
>+
> static struct nbdkit_filter filter = {
> .name = "partition",
> .longname = "nbdkit partition filter",
>@@ -237,6 +273,7 @@ static struct nbdkit_filter filter = {
> .pwrite = partition_pwrite,
> .trim = partition_trim,
> .zero = partition_zero,
>+ .extents = partition_extents,
> };
>
> NBDKIT_REGISTER_FILTER(filter)
>--
>2.20.1
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190401/176b809c/attachment.sig>
More information about the Libguestfs
mailing list