[Libguestfs] [PATCH nbdkit 5/5] eval, sh: Implement get_ready method.

Richard W.M. Jones rjones at redhat.com
Tue Feb 25 10:30:56 UTC 2020


---
 plugins/eval/nbdkit-eval-plugin.pod |  2 ++
 plugins/sh/nbdkit-sh-plugin.pod     |  4 ++++
 plugins/sh/methods.h                |  1 +
 plugins/eval/eval.c                 |  2 ++
 plugins/sh/methods.c                | 25 +++++++++++++++++++++++++
 plugins/sh/sh.c                     |  1 +
 tests/test-eval.sh                  |  1 +
 7 files changed, 36 insertions(+)

diff --git a/plugins/eval/nbdkit-eval-plugin.pod b/plugins/eval/nbdkit-eval-plugin.pod
index a3601333..602fd3aa 100644
--- a/plugins/eval/nbdkit-eval-plugin.pod
+++ b/plugins/eval/nbdkit-eval-plugin.pod
@@ -100,6 +100,8 @@ features):
 
 =item B<flush=>SCRIPT
 
+=item B<get_ready=>SCRIPT
+
 =item B<get_size=>SCRIPT
 
 =item B<is_rotational=>SCRIPT
diff --git a/plugins/sh/nbdkit-sh-plugin.pod b/plugins/sh/nbdkit-sh-plugin.pod
index 2f265b05..ffd0310f 100644
--- a/plugins/sh/nbdkit-sh-plugin.pod
+++ b/plugins/sh/nbdkit-sh-plugin.pod
@@ -246,6 +246,10 @@ actually gets selected.
 If an error occurs, the script should output an error message and exit
 with status C<1>; unrecognized output is ignored.
 
+=item C<get_ready>
+
+ /path/to/script get_ready
+
 =item C<preconnect>
 
  /path/to/script preconnect <readonly> <exportname>
diff --git a/plugins/sh/methods.h b/plugins/sh/methods.h
index 8a8f179c..f11e67e7 100644
--- a/plugins/sh/methods.h
+++ b/plugins/sh/methods.h
@@ -41,6 +41,7 @@ extern const char *get_script (const char *method);
 
 extern void sh_dump_plugin (void);
 extern int sh_thread_model (void);
+extern int sh_get_ready (void);
 extern int sh_preconnect (int readonly);
 extern void *sh_open (int readonly);
 extern void sh_close (void *handle);
diff --git a/plugins/eval/eval.c b/plugins/eval/eval.c
index 9071b8c7..f09e49f3 100644
--- a/plugins/eval/eval.c
+++ b/plugins/eval/eval.c
@@ -70,6 +70,7 @@ static const char *known_methods[] = {
   "dump_plugin",
   "extents",
   "flush",
+  "get_ready",
   "get_size",
   "is_rotational",
   "missing",
@@ -409,6 +410,7 @@ static struct nbdkit_plugin plugin = {
   .config_complete   = eval_config_complete,
   .config_help       = eval_config_help,
   .thread_model      = sh_thread_model,
+  .get_ready         = sh_get_ready,
 
   .preconnect        = sh_preconnect,
   .open              = sh_open,
diff --git a/plugins/sh/methods.c b/plugins/sh/methods.c
index e8011284..56e2d410 100644
--- a/plugins/sh/methods.c
+++ b/plugins/sh/methods.c
@@ -139,6 +139,31 @@ sh_thread_model (void)
   }
 }
 
+int
+sh_get_ready (void)
+{
+  const char *method = "get_ready";
+  const char *script = get_script (method);
+  const char *args[] = { script, method, NULL };
+
+  switch (call (args)) {
+  case OK:
+  case MISSING:
+    return 0;
+
+  case ERROR:
+    return -1;
+
+  case RET_FALSE:
+    nbdkit_error ("%s: %s method returned unexpected code (3/false)",
+                  script, method);
+    errno = EIO;
+    return -1;
+
+  default: abort ();
+  }
+}
+
 int
 sh_preconnect (int readonly)
 {
diff --git a/plugins/sh/sh.c b/plugins/sh/sh.c
index 0d24edb4..736b8ef0 100644
--- a/plugins/sh/sh.c
+++ b/plugins/sh/sh.c
@@ -310,6 +310,7 @@ static struct nbdkit_plugin plugin = {
   .config_help       = sh_config_help,
   .magic_config_key  = "script",
   .thread_model      = sh_thread_model,
+  .get_ready         = sh_get_ready,
 
   .preconnect        = sh_preconnect,
   .open              = sh_open,
diff --git a/tests/test-eval.sh b/tests/test-eval.sh
index 868452f3..da7b8861 100755
--- a/tests/test-eval.sh
+++ b/tests/test-eval.sh
@@ -59,6 +59,7 @@ grep 'in missing: config_complete' eval.missing
 grep 'in missing: thread_model' eval.missing
 grep 'in missing: can_write' eval.missing
 grep 'in missing: is_rotational' eval.missing
+grep 'in missing: get_ready' eval.missing
 grep 'in missing: preconnect' eval.missing
 grep 'in missing: open' eval.missing
 grep 'in missing: close' eval.missing
-- 
2.25.0




More information about the Libguestfs mailing list