[Libguestfs] [PATCH nbdkit v5 FINAL 18/19] tests: Update layers test for can_extents.

Richard W.M. Jones rjones at redhat.com
Thu Mar 28 16:18:45 UTC 2019


Testing Block Status / extents is however rather more difficult, so
this commit punts on it and just adds a comment to the code.
---
 tests/test-layers-filter.c | 21 +++++++++++++++++++++
 tests/test-layers-plugin.c | 20 +++++++++++++++++++-
 tests/test-layers.c        | 12 ++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/tests/test-layers-filter.c b/tests/test-layers-filter.c
index 6da6ee6..48ca8e6 100644
--- a/tests/test-layers-filter.c
+++ b/tests/test-layers-filter.c
@@ -176,6 +176,15 @@ test_layers_filter_can_multi_conn (struct nbdkit_next_ops *next_ops,
   return next_ops->can_multi_conn (nxdata);
 }
 
+static int
+test_layers_filter_can_extents (struct nbdkit_next_ops *next_ops,
+                                void *nxdata,
+                                void *handle)
+{
+  DEBUG_FUNCTION;
+  return next_ops->can_extents (nxdata);
+}
+
 static int
 test_layers_filter_pread (struct nbdkit_next_ops *next_ops, void *nxdata,
                            void *handle, void *buf,
@@ -223,6 +232,16 @@ test_layers_filter_zero (struct nbdkit_next_ops *next_ops, void *nxdata,
   return next_ops->zero (nxdata, count, offset, flags, err);
 }
 
+static int
+test_layers_filter_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)
+{
+  DEBUG_FUNCTION;
+  return next_ops->extents (nxdata, count, offset, flags, extents, err);
+}
+
 static struct nbdkit_filter filter = {
   .name              = "testlayers" layer,
   .version           = PACKAGE_VERSION,
@@ -243,11 +262,13 @@ static struct nbdkit_filter filter = {
   .can_zero          = test_layers_filter_can_zero,
   .can_fua           = test_layers_filter_can_fua,
   .can_multi_conn    = test_layers_filter_can_multi_conn,
+  .can_extents       = test_layers_filter_can_extents,
   .pread             = test_layers_filter_pread,
   .pwrite            = test_layers_filter_pwrite,
   .flush             = test_layers_filter_flush,
   .trim              = test_layers_filter_trim,
   .zero              = test_layers_filter_zero,
+  .extents           = test_layers_filter_extents,
 };
 
 NBDKIT_REGISTER_FILTER(filter)
diff --git a/tests/test-layers-plugin.c b/tests/test-layers-plugin.c
index 042ecc3..c33d12d 100644
--- a/tests/test-layers-plugin.c
+++ b/tests/test-layers-plugin.c
@@ -1,5 +1,5 @@
 /* nbdkit
- * Copyright (C) 2018 Red Hat Inc.
+ * Copyright (C) 2018-2019 Red Hat Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -144,6 +144,13 @@ test_layers_plugin_can_multi_conn (void *handle)
   return 1;
 }
 
+static int
+test_layers_plugin_can_extents (void *handle)
+{
+  DEBUG_FUNCTION;
+  return 1;
+}
+
 static int
 test_layers_plugin_pread (void *handle,
                           void *buf, uint32_t count, uint64_t offset,
@@ -186,6 +193,15 @@ test_layers_plugin_zero (void *handle,
   return 0;
 }
 
+static int
+test_layers_plugin_extents (void *handle,
+                            uint32_t count, uint64_t offset, uint32_t flags,
+                            struct nbdkit_extents *extents)
+{
+  DEBUG_FUNCTION;
+  return 0;
+}
+
 static struct nbdkit_plugin plugin = {
   .name              = "testlayersplugin",
   .version           = PACKAGE_VERSION,
@@ -204,11 +220,13 @@ static struct nbdkit_plugin plugin = {
   .can_zero          = test_layers_plugin_can_zero,
   .can_fua           = test_layers_plugin_can_fua,
   .can_multi_conn    = test_layers_plugin_can_multi_conn,
+  .can_extents       = test_layers_plugin_can_extents,
   .pread             = test_layers_plugin_pread,
   .pwrite            = test_layers_plugin_pwrite,
   .flush             = test_layers_plugin_flush,
   .trim              = test_layers_plugin_trim,
   .zero              = test_layers_plugin_zero,
+  .extents           = test_layers_plugin_extents,
   /* In this plugin, errno is preserved properly along error return
    * paths from failed system calls.
    */
diff --git a/tests/test-layers.c b/tests/test-layers.c
index 96df9a6..7757f86 100644
--- a/tests/test-layers.c
+++ b/tests/test-layers.c
@@ -355,6 +355,12 @@ main (int argc, char *argv[])
      "filter1: test_layers_filter_can_multi_conn",
      "test_layers_plugin_can_multi_conn",
      NULL);
+  log_verify_seen_in_order
+    ("filter3: test_layers_filter_can_extents",
+     "filter2: test_layers_filter_can_extents",
+     "filter1: test_layers_filter_can_extents",
+     "test_layers_plugin_can_extents",
+     NULL);
 
   fprintf (stderr, "%s: protocol connected\n", program_name);
 
@@ -520,6 +526,12 @@ main (int argc, char *argv[])
      "test_layers_plugin_zero",
      NULL);
 
+  /* XXX We should test NBD_CMD_BLOCK_STATUS here.  However it
+   * requires that we negotiate structured replies and base:allocation
+   * in the handshake, and the format of the reply is more complex
+   * than what we expect in this naive test.
+   */
+
   /* Close the connection. */
   fprintf (stderr, "%s: closing the connection\n", program_name);
   request.type = htobe16 (NBD_CMD_DISC);
-- 
2.20.1




More information about the Libguestfs mailing list