[Libguestfs] [nbdkit PATCH v2 19/24] offset, partition: Implement .cache

Eric Blake eblake at redhat.com
Thu May 16 03:58:09 UTC 2019


In the offset and partition filters, all we need to do is adjust cache
requests to the correct offset (well, technically, this isn't enabled
until a later patch flips the default for .can_cache to pass-through).

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 filters/offset/offset.c       | 12 +++++++++++-
 filters/partition/partition.c | 12 ++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/filters/offset/offset.c b/filters/offset/offset.c
index 633a1c7..fe07d28 100644
--- a/filters/offset/offset.c
+++ b/filters/offset/offset.c
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2018 Red Hat Inc.
+ * Copyright (C) 2018-2019 Red Hat Inc.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -164,6 +164,15 @@ offset_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
   return 0;
 }

+/* Cache data. */
+static int
+offset_cache (struct nbdkit_next_ops *next_ops, void *nxdata,
+              void *handle, uint32_t count, uint64_t offs, uint32_t flags,
+              int *err)
+{
+  return next_ops->cache (nxdata, count, offs + offset, flags, err);
+}
+
 static struct nbdkit_filter filter = {
   .name              = "offset",
   .longname          = "nbdkit offset filter",
@@ -177,6 +186,7 @@ static struct nbdkit_filter filter = {
   .trim              = offset_trim,
   .zero              = offset_zero,
   .extents           = offset_extents,
+  .cache             = offset_cache,
 };

 NBDKIT_REGISTER_FILTER(filter)
diff --git a/filters/partition/partition.c b/filters/partition/partition.c
index a635df8..ee2cc77 100644
--- a/filters/partition/partition.c
+++ b/filters/partition/partition.c
@@ -254,6 +254,17 @@ partition_extents (struct nbdkit_next_ops *next_ops, void *nxdata,
   return 0;
 }

+/* Cache data. */
+static int
+partition_cache (struct nbdkit_next_ops *next_ops, void *nxdata,
+                 void *handle, uint32_t count, uint64_t offs, uint32_t flags,
+                 int *err)
+{
+  struct handle *h = handle;
+
+  return next_ops->cache (nxdata, count, offs + h->offset, flags, err);
+}
+
 static struct nbdkit_filter filter = {
   .name              = "partition",
   .longname          = "nbdkit partition filter",
@@ -270,6 +281,7 @@ static struct nbdkit_filter filter = {
   .trim              = partition_trim,
   .zero              = partition_zero,
   .extents           = partition_extents,
+  .cache             = partition_cache,
 };

 NBDKIT_REGISTER_FILTER(filter)
-- 
2.20.1




More information about the Libguestfs mailing list