[Libguestfs] [nbdkit PATCH v2 06/24] nbd: Implement NBD_CMD_CACHE passthrough

Eric Blake eblake at redhat.com
Thu May 16 03:57:56 UTC 2019


In the nbd plugin, we expose caching to the client only if the server
exposed it to us.

Signed-off-by: Eric Blake <eblake at redhat.com>
---
 plugins/nbd/nbd.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/plugins/nbd/nbd.c b/plugins/nbd/nbd.c
index 821f256..df7d366 100644
--- a/plugins/nbd/nbd.c
+++ b/plugins/nbd/nbd.c
@@ -1151,6 +1151,16 @@ nbd_can_multi_conn (void *handle)
   return h->flags & NBD_FLAG_CAN_MULTI_CONN;
 }

+static int
+nbd_can_cache (void *handle)
+{
+  struct handle *h = handle;
+
+  if (h->flags & NBD_FLAG_SEND_CACHE)
+    return NBDKIT_CACHE_NATIVE;
+  return NBDKIT_CACHE_NONE;
+}
+
 static int
 nbd_can_extents (void *handle)
 {
@@ -1245,6 +1255,18 @@ nbd_extents (void *handle, uint32_t count, uint64_t offset,
   return c < 0 ? c : nbd_reply (h, c);
 }

+/* Cache a portion of the file. */
+static int
+nbd_cache (void *handle, uint32_t count, uint64_t offset, uint32_t flags)
+{
+  struct handle *h = handle;
+  int c;
+
+  assert (!flags);
+  c = nbd_request (h, 0, NBD_CMD_CACHE, offset, count);
+  return c < 0 ? c : nbd_reply (h, c);
+}
+
 static struct nbdkit_plugin plugin = {
   .name               = "nbd",
   .longname           = "nbdkit nbd plugin",
@@ -1264,12 +1286,14 @@ static struct nbdkit_plugin plugin = {
   .can_fua            = nbd_can_fua,
   .can_multi_conn     = nbd_can_multi_conn,
   .can_extents        = nbd_can_extents,
+  .can_cache          = nbd_can_cache,
   .pread              = nbd_pread,
   .pwrite             = nbd_pwrite,
   .zero               = nbd_zero,
   .flush              = nbd_flush,
   .trim               = nbd_trim,
   .extents            = nbd_extents,
+  .cache              = nbd_cache,
   .errno_is_preserved = 1,
 };

-- 
2.20.1




More information about the Libguestfs mailing list