[Libguestfs] [PATCH nbdkit v2 06/11] plugins: Return NBD_FLAG_CAN_MULTI_CONN from some readonly plugins.

Richard W.M. Jones rjones at redhat.com
Sat Jan 5 14:50:48 UTC 2019


It is safe to return NBD_FLAG_CAN_MULTI_CONN from almost all readonly
plugins.  However only do it where the plugin thread model is
NBDKIT_THREAD_MODEL_PARALLEL and the plugin could plausibly be used in
a high performance situation.
---
 plugins/floppy/floppy.c   | 8 ++++++++
 plugins/iso/iso.c         | 8 ++++++++
 plugins/pattern/pattern.c | 8 ++++++++
 plugins/random/random.c   | 8 ++++++++
 4 files changed, 32 insertions(+)

diff --git a/plugins/floppy/floppy.c b/plugins/floppy/floppy.c
index 5e23c88..0efb8dd 100644
--- a/plugins/floppy/floppy.c
+++ b/plugins/floppy/floppy.c
@@ -122,6 +122,13 @@ floppy_get_size (void *handle)
   return virtual_size (&floppy.regions);
 }
 
+/* Serves the same data over multiple connections. */
+static int
+floppy_can_multi_conn (void *handle)
+{
+  return 1;
+}
+
 /* Read data from the file. */
 static int
 floppy_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
@@ -192,6 +199,7 @@ static struct nbdkit_plugin plugin = {
   .magic_config_key  = "dir",
   .open              = floppy_open,
   .get_size          = floppy_get_size,
+  .can_multi_conn    = floppy_can_multi_conn,
   .pread             = floppy_pread,
   .errno_is_preserved = 1,
 };
diff --git a/plugins/iso/iso.c b/plugins/iso/iso.c
index 7ed5e7a..7431b48 100644
--- a/plugins/iso/iso.c
+++ b/plugins/iso/iso.c
@@ -258,6 +258,13 @@ iso_get_size (void *handle)
   return statbuf.st_size;
 }
 
+/* Serves the same data over multiple connections. */
+static int
+iso_can_multi_conn (void *handle)
+{
+  return 1;
+}
+
 /* Read data from the file. */
 static int
 iso_pread (void *handle, void *buf, uint32_t count, uint64_t offset)
@@ -291,6 +298,7 @@ static struct nbdkit_plugin plugin = {
   .magic_config_key  = "dir",
   .open              = iso_open,
   .get_size          = iso_get_size,
+  .can_multi_conn    = iso_can_multi_conn,
   .pread             = iso_pread,
   .errno_is_preserved = 1,
 };
diff --git a/plugins/pattern/pattern.c b/plugins/pattern/pattern.c
index 32db381..23e9019 100644
--- a/plugins/pattern/pattern.c
+++ b/plugins/pattern/pattern.c
@@ -88,6 +88,13 @@ pattern_get_size (void *handle)
   return size;
 }
 
+/* Serves the same data over multiple connections. */
+static int
+pattern_can_multi_conn (void *handle)
+{
+  return 1;
+}
+
 /* Read data. */
 static int
 pattern_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
@@ -118,6 +125,7 @@ static struct nbdkit_plugin plugin = {
   .config_help       = pattern_config_help,
   .open              = pattern_open,
   .get_size          = pattern_get_size,
+  .can_multi_conn    = pattern_can_multi_conn,
   .pread             = pattern_pread,
   /* In this plugin, errno is preserved properly along error return
    * paths from failed system calls.
diff --git a/plugins/random/random.c b/plugins/random/random.c
index 9c805ab..ba51520 100644
--- a/plugins/random/random.c
+++ b/plugins/random/random.c
@@ -107,6 +107,13 @@ random_get_size (void *handle)
   return size;
 }
 
+/* Serves the same data over multiple connections. */
+static int
+random_can_multi_conn (void *handle)
+{
+  return 1;
+}
+
 /* Read data. */
 static int
 random_pread (void *handle, void *buf, uint32_t count, uint64_t offset,
@@ -148,6 +155,7 @@ static struct nbdkit_plugin plugin = {
   .config_help       = random_config_help,
   .open              = random_open,
   .get_size          = random_get_size,
+  .can_multi_conn    = random_can_multi_conn,
   .pread             = random_pread,
   /* In this plugin, errno is preserved properly along error return
    * paths from failed system calls.
-- 
2.19.2




More information about the Libguestfs mailing list