[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH nbdkit] server: Make $nbd be a simple synonym for $uri.



While I was troubleshooting a problem with an nbdkit user recently,
they had a problem understanding the difference between $nbd and $uri.
In the past it was necessary to construct magical paths for qemu or
guestfish but both these tools now support standard NBD URIs (and if
we discover cases where they do not, we should fix those tools).

This change makes $nbd be a synonym for $uri, removing the magic.

If you are using very old qemu/guestfish you can still construct the
old paths manually using the other variables, but I would advise
upgrading.
---
 docs/nbdkit-captive.pod | 30 ++++++++++++++----------------
 server/captive.c        | 37 +++----------------------------------
 tests/test-captive.sh   |  4 ++--
 3 files changed, 19 insertions(+), 52 deletions(-)

diff --git a/docs/nbdkit-captive.pod b/docs/nbdkit-captive.pod
index 17489450..7f22bf2d 100644
--- a/docs/nbdkit-captive.pod
+++ b/docs/nbdkit-captive.pod
@@ -49,25 +49,23 @@ The following shell variables are available in the I<--run> argument:
 
 =over 4
 
+=item C<$nbd>
+
 =item C<$uri>
 
 A URI that refers to the nbdkit port or socket in the preferred form
-documented by the NBD project.  As this variable may contain a bare
-C<?> for Unix sockets, it is safest to use $uri within double quotes
-to avoid unintentional globbing.  For plugins that support distinct
-data based on export names, the B<-e> option to nbdkit controls which
-export name will be set in the URI.
-
-=item C<$nbd>
-
-An older URL that refers to the nbdkit port or socket in a manner
-specific to certain tools.
-
-Note there is some magic here, since qemu and guestfish URLs have a
-different format, so nbdkit tries to guess which you are running.  If
-the magic doesn't work, try using the variables below instead.
-
-This is not defined when you use I<--vsock>.  Use C<$uri> instead.
+documented by the NBD project.
+
+As this variable may contain a bare C<?> for Unix sockets, it is
+safest to use $uri within double quotes to avoid unintentional
+globbing.  For plugins that support distinct data based on export
+names, the B<-e> option to nbdkit controls which export name will be
+set in the URI.
+
+In nbdkit E<le> 1.22 C<$nbd> tried to guess if you were using qemu or
+guestfish and expanded differently.  Since NBD URIs are now widely
+supported this magic is no longer necessary.  In nbdkit E<ge> 1.24
+both variables expand to the same URI.
 
 =item C<$port>
 
diff --git a/server/captive.c b/server/captive.c
index 74cd6940..4d1969eb 100644
--- a/server/captive.c
+++ b/server/captive.c
@@ -106,45 +106,14 @@ run_command (void)
   }
   putc ('\n', fp);
 
+  /* Since nbdkit 1.24, $nbd is a synonym for $uri. */
+  fprintf (fp, "nbd=\"$uri\"\n");
+
   /* Expose $exportname. */
   fprintf (fp, "exportname=");
   shell_quote (export_name, fp);
   putc ('\n', fp);
 
-  /* Construct older $nbd "URL".  Unfortunately guestfish and qemu
-   * take different syntax, so try to guess which one we need.  We
-   * cannot generate the $nbd variable when using vsock, use $uri
-   * instead.
-   */
-  if (!vsock) {
-    fprintf (fp, "nbd=");
-    if (strstr (run, "guestfish")) {
-      if (port) {
-        fprintf (fp, "nbd://localhost:");
-        shell_quote (port, fp);
-      }
-      else if (unixsocket) {
-        fprintf (fp, "nbd://\\?socket=");
-        shell_quote (unixsocket, fp);
-      }
-      else
-        abort ();
-    }
-    else /* qemu */ {
-      if (port) {
-        fprintf (fp, "nbd:localhost:");
-        shell_quote (port, fp);
-      }
-      else if (unixsocket) {
-        fprintf (fp, "nbd:unix:");
-        shell_quote (unixsocket, fp);
-      }
-      else
-        abort ();
-    }
-    putc ('\n', fp);
-  }
-
   /* Construct $port and $unixsocket. */
   fprintf (fp, "port=");
   if (port)
diff --git a/tests/test-captive.sh b/tests/test-captive.sh
index 244ddcd5..af307163 100755
--- a/tests/test-captive.sh
+++ b/tests/test-captive.sh
@@ -46,11 +46,11 @@ rm -f $files
 cleanup_fn rm -f $files
 
 nbdkit -U $sock example1 --run '
-    echo nbd=$nbd; echo port=$port; echo socket=$unixsocket
+    echo uri=$uri; echo port=$port; echo socket=$unixsocket
   ' > captive.out
 
 # Check the output.
-if [ "$(cat captive.out)" != "nbd=nbd:unix:$sock
+if [ "$(cat captive.out)" != "uri=nbd+unix://?socket=$sock
 port=
 socket=$sock" ]; then
     echo "$0: unexpected output"
-- 
2.29.0.rc2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]