[Libguestfs] [PATCH nbdkit 04/10] server: Calculate $uri in one place
Move the calculation of $uri to the main function (well, inlined there), and out of --run code. This is largely code motion. In theory it changes the content of $uri since we now shell quote it after generating it, but this ought not to have any practical effect. --- server/internal.h | 1 + server/captive.c | 41 ++-- server/main.c | 79 +++ 3 files changed, 82 insertions(+), 39 deletions(-) diff --git a/server/internal.h b/server/internal.h index 0652f8a86..656b6d8ce 100644 --- a/server/internal.h +++ b/server/internal.h @@ -142,6 +142,7 @@ extern const char *user, *group; extern bool verbose; extern bool vsock; extern enum service_mode service_mode; +extern char *uri; extern bool configured; extern int saved_stdin; extern int saved_stdout; diff --git a/server/captive.c b/server/captive.c index 40c4bb2ca..51dafca34 100644 --- a/server/captive.c +++ b/server/captive.c @@ -75,45 +75,8 @@ run_command (void) /* Construct $uri. */ fprintf (fp, "uri="); - switch (service_mode) { - case SERVICE_MODE_SOCKET_ACTIVATION: - case SERVICE_MODE_LISTEN_STDIN: -break; /* can't form a URI, leave it blank */ - case SERVICE_MODE_UNIXSOCKET: -fprintf (fp, "nbd%s+unix://", tls == 2 ? "s" : ""); -if (export_name && strcmp (export_name, "") != 0) { - putc ('/', fp); - uri_quote (export_name, fp); -} -fprintf (fp, "\\?socket="); -uri_quote (unixsocket, fp); -break; - case SERVICE_MODE_VSOCK: -/* 1 = VMADDR_CID_LOCAL */ -fprintf (fp, "nbd%s+vsock://1", tls == 2 ? "s" : ""); -if (port) { - putc (':', fp); - shell_quote (port, fp); -} -if (export_name && strcmp (export_name, "") != 0) { - putc ('/', fp); - uri_quote (export_name, fp); -} -break; - case SERVICE_MODE_TCPIP: -fprintf (fp, "nbd%s://localhost", tls == 2 ? "s" : ""); -if (port) { - putc (':', fp); - shell_quote (port, fp); -} -if (export_name && strcmp (export_name, "") != 0) { - putc ('/', fp); - uri_quote (export_name, fp); -} -break; - default: -abort (); - } + if (uri) +shell_quote (uri, fp); putc ('\n', fp); /* Since nbdkit 1.24, $nbd is a synonym for $uri. */ diff --git a/server/main.c b/server/main.c index 2a332bfdd..54eb348ba 100644 --- a/server/main.c +++ b/server/main.c @@ -66,6 +66,7 @@ #include "ascii-string.h" #include "exit-with-parent.h" #include "nbd-protocol.h" +#include "open_memstream.h" #include "realpath.h" #include "strndup.h" #include "syslog.h" @@ -79,6 +80,7 @@ #endif static char *make_random_fifo (void); +static char *make_uri (void); static struct backend *open_plugin_so (size_t i, const char *filename, int short_name); static struct backend *open_filter_so (struct backend *next, size_t i, @@ -118,6 +120,7 @@ bool verbose; /* -v */ bool vsock; /* --vsock */ unsigned int socket_activation; /* $LISTEN_FDS and $LISTEN_PID set */ enum service_mode service_mode; /* serving over TCP, Unix, etc */ +char *uri; /* NBD URI */ bool configured;/* .config_complete done */ int saved_stdin = -1; /* dup'd stdin during -s/--run */ int saved_stdout = -1; /* dup'd stdout during -s/--run */ @@ -630,6 +633,11 @@ main (int argc, char *argv[]) else service_mode = SERVICE_MODE_TCPIP; + /* By the point we have enough information to calculate the NBD URI. + * Note this may be NULL. + */ + uri = make_uri (); + /* The remaining command line arguments are the plugin name and * parameters. If --help, --version or --dump-plugin were specified * then we open the plugin so that we can display the per-plugin @@ -799,6 +807,7 @@ main (int argc, char *argv[]) free (unixsocket); free (pidfile); + free (uri); if (random_fifo) { unlink (random_fifo); @@ -856,6 +865,76 @@ make_random_fifo (void) return NULL; } +static char * +make_uri (void) +{ + FILE *fp; + size_t len = 0; + char *r = NULL; + + switch (service_mode) { + case SERVICE_MODE_SOCKET_ACTIVATION: + case SERVICE_MODE_LISTEN_STDIN: +/* can't form a URI, uri will be NULL */ +return NULL; + default: ; + } + + fp = open_memstream (, ); + if (fp == NULL) { +perror ("open_memstream"); +exit (EXIT_FAILURE); + } + + switch (service_mode) { + case SERVICE_MODE_UNIXSOCKET: +fprintf (fp, "nbd%s+unix://", tls == 2 ? "s" : ""); +if (export_name && strcmp (export_name, "") != 0) { + putc ('/', fp); + uri_quote (export_name, fp); +} +fprintf (fp, "?socket="); +uri_quote (unixsocket, fp); +break; + case SERVICE_MODE_VSOCK: +/* 1 = VMADDR_CID_LOCAL */ +fprintf (fp, "nbd%s+vsock://1", tls == 2 ? "s" : ""); +if (port) { + putc (':', fp); + fputs (port, fp); +} +if (export_name && strcmp
[Libguestfs] [PATCH nbdkit 01/10] server: Introduce service_mode concept
Previously there were two places where similiar-ish logic was used to decide if we are going to serve over a socket activation, -s, Unix socket, AF_VSOCK or TCP/IP. Let's abstract that into a service_mode. One place where we did this was when calculating the $uri variable for --run. This change adjusts and fixes this calculation (revealed as I made the above change). In particular if --port was not set then the $uri would contain fairly bogus values in some cases: $ nbdkit --vsock null 1M --run 'echo $uri ; nbdinfo $uri' nbd nbdinfo: nbd_connect_uri: NBD URI does not have a scheme: valid NBD URIs should start with a scheme like nbd://, nbds:// or nbd+unix://: Invalid argument (note uri='nbd') After this commit: $ nbdkit --vsock null 1M --run 'echo $uri ; nbdinfo $uri' nbd+vsock://1 protocol: newstyle-fixed without TLS, using structured packets export="": export-size: 1048576 (1M) content: data uri: nbd+vsock://1:10809/ ... --- server/internal.h | 11 +++ server/captive.c | 56 --- server/main.c | 75 ++- 3 files changed, 91 insertions(+), 51 deletions(-) diff --git a/server/internal.h b/server/internal.h index fcfbf0573..0652f8a86 100644 --- a/server/internal.h +++ b/server/internal.h @@ -108,6 +108,16 @@ enum log_to { LOG_TO_NULL, /* --log=null forced on the command line */ }; +enum service_mode { + /* These two modes cannot form an NBD URI: */ + SERVICE_MODE_SOCKET_ACTIVATION, /* socket activation. */ + SERVICE_MODE_LISTEN_STDIN, /* -s */ + + SERVICE_MODE_UNIXSOCKET,/* -U */ + SERVICE_MODE_VSOCK, /* --vsock */ + SERVICE_MODE_TCPIP, /* --port */ +}; + extern int tcpip_sock_af; extern struct debug_flag *debug_flags; extern const char *export_name; @@ -131,6 +141,7 @@ extern char *unixsocket; extern const char *user, *group; extern bool verbose; extern bool vsock; +extern enum service_mode service_mode; extern bool configured; extern int saved_stdin; extern int saved_stdout; diff --git a/server/captive.c b/server/captive.c index 2361bb60b..31fd949e5 100644 --- a/server/captive.c +++ b/server/captive.c @@ -78,36 +78,44 @@ run_command (void) /* Construct $uri. */ fprintf (fp, "uri="); - if (tls == 2) /* --tls=require */ -fprintf (fp, "nbds"); - else -fprintf (fp, "nbd"); - if (port) { -if (!vsock) { - fprintf (fp, "://localhost:"); - shell_quote (port, fp); - if (strcmp (export_name, "") != 0) { -putc ('/', fp); -uri_quote (export_name, fp); - } -} -else { - fprintf (fp, "+vsock://1:"); /* 1 = VMADDR_CID_LOCAL */ - shell_quote (port, fp); - if (strcmp (export_name, "") != 0) { -putc ('/', fp); -uri_quote (export_name, fp); - } -} - } - else if (unixsocket) { -fprintf (fp, "+unix://"); + switch (service_mode) { + case SERVICE_MODE_SOCKET_ACTIVATION: + case SERVICE_MODE_LISTEN_STDIN: +break; /* can't form a URI, leave it blank */ + case SERVICE_MODE_UNIXSOCKET: +fprintf (fp, "nbd%s+unix://", tls == 2 ? "s" : ""); if (strcmp (export_name, "") != 0) { putc ('/', fp); uri_quote (export_name, fp); } fprintf (fp, "\\?socket="); uri_quote (unixsocket, fp); +break; + case SERVICE_MODE_VSOCK: +/* 1 = VMADDR_CID_LOCAL */ +fprintf (fp, "nbd%s+vsock://1", tls == 2 ? "s" : ""); +if (port) { + putc (':', fp); + shell_quote (port, fp); +} +if (strcmp (export_name, "") != 0) { + putc ('/', fp); + uri_quote (export_name, fp); +} +break; + case SERVICE_MODE_TCPIP: +fprintf (fp, "nbd%s://localhost", tls == 2 ? "s" : ""); +if (port) { + putc (':', fp); + shell_quote (port, fp); +} +if (strcmp (export_name, "") != 0) { + putc ('/', fp); + uri_quote (export_name, fp); +} +break; + default: +abort (); } putc ('\n', fp); diff --git a/server/main.c b/server/main.c index 528a2dfea..2a332bfdd 100644 --- a/server/main.c +++ b/server/main.c @@ -117,6 +117,7 @@ const char *user, *group; /* -u & -g */ bool verbose; /* -v */ bool vsock; /* --vsock */ unsigned int socket_activation; /* $LISTEN_FDS and $LISTEN_PID set */ +enum service_mode service_mode; /* serving over TCP, Unix, etc */ bool configured;/* .config_complete done */ int saved_stdin = -1; /* dup'd stdin during -s/--run */ int saved_stdout = -1; /* dup'd stdout during -s/--run */ @@ -617,6 +618,18 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + /* By the point we have enough information to calculate the service mode. */ + if (socket_activation) +service_mode = SERVICE_MODE_SOCKET_ACTIVATION; + else if (listen_stdin) +service_mode = SERVICE_MODE_LISTEN_STDIN; + else
[Libguestfs] [PATCH nbdkit 09/10] tests: Remove references to -U - when it is implicit
In tests where we used 'nbdkit -U - ... --run', remove -U - as that is now implicit. --- tests/Makefile.am| 2 +- plugins/rust/test-ramdisk.sh | 4 +-- tests/test-S3.sh | 2 +- tests/test-blkio.sh | 2 +- tests/test-block-size-constraints.sh | 2 +- tests/test-blocksize-default.sh | 2 +- tests/test-blocksize-error-policy.sh | 2 +- tests/test-blocksize-extents.sh | 2 +- tests/test-blocksize-policy.sh | 12 +++ tests/test-blocksize-sharding.sh | 2 +- tests/test-blocksize-write-disconnect.sh | 2 +- tests/test-captive-tls.sh| 2 +- tests/test-captive.sh| 4 +-- tests/test-cc-cpp.sh | 2 +- tests/test-cc-ocaml.sh | 2 +- tests/test-cc.sh | 2 +- tests/test-checkwrite-bounds.sh | 2 +- tests/test-checkwrite.sh | 2 +- tests/test-cow-block-size.sh | 2 +- tests/test-cow-extents-large.sh | 2 +- tests/test-cow-null.sh | 2 +- tests/test-cow.sh| 2 +- tests/test-curl-file.sh | 2 +- tests/test-curl-header-script-fail.sh| 2 +- tests/test-data-bad.sh | 2 +- tests/test-data-extents.sh | 2 +- tests/test-data-format.sh| 8 ++--- tests/test-data-optimum.sh | 2 +- tests/test-data-partition.sh | 2 +- tests/test-data-raw-copy.sh | 2 +- tests/test-data-reloffset.sh | 4 +-- tests/test-data-size.sh | 2 +- tests/test-debug-flags.sh| 22 ++--- tests/test-delay-close.sh| 2 +- tests/test-delay-open.sh | 2 +- tests/test-disk2data.sh | 2 +- tests/test-eflags.sh | 2 +- tests/test-eval-cache.sh | 4 +-- tests/test-eval-exports.sh | 8 ++--- tests/test-eval-file.sh | 2 +- tests/test-eval.sh | 2 +- tests/test-evil-cosmic.sh| 2 +- tests/test-evil-large-p.sh | 6 ++-- tests/test-evil-small-p.sh | 6 ++-- tests/test-exportname.sh | 40 tests/test-extentlist.sh | 2 +- tests/test-file-dir.sh | 6 ++-- tests/test-file-extents.sh | 2 +- tests/test-ip-filter-anyunix.sh | 4 +-- tests/test-ip-filter-gid.sh | 4 +-- tests/test-ip-filter-pid.sh | 4 +-- tests/test-ip-filter-security.sh | 4 +-- tests/test-ip-filter-uid.sh | 4 +-- tests/test-linuxdisk-copy-out.sh | 2 +- tests/test-log-script-info.sh| 2 +- tests/test-long-name.sh | 14 - tests/test-luks-copy-zero.sh | 2 +- tests/test-luks-info.sh | 2 +- tests/test-multi-conn-name.sh| 4 +-- tests/test-multi-conn.sh | 18 +-- tests/test-nbd-block-size.sh | 4 +-- tests/test-nbd-extents.sh| 2 +- tests/test-nbd-vsock.sh | 2 +- tests/test-nbdkit-backend-debug.sh | 6 ++-- tests/test-nofilter.sh | 2 +- tests/test-nozero.sh | 2 +- tests/test-null-extents.sh | 2 +- tests/test-ocaml-fork.sh | 2 +- tests/test-ocaml-list-exports.sh | 2 +- tests/test-offset-extents.sh | 2 +- tests/test-offset-truncate.sh| 6 ++-- tests/test-old-plugins.sh| 2 +- tests/test-ondemand-list.sh | 2 +- tests/test-ones.sh | 6 ++-- tests/test-parallel-file.sh | 6 ++-- tests/test-parallel-nbd.sh | 4 +-- tests/test-parallel-sh.sh| 6 ++-- tests/test-partition-4k-gpt.sh | 2 +- tests/test-partition-4k-mbr.sh | 2 +- tests/test-partition1.sh | 2 +- tests/test-partition2.sh | 8 ++--- tests/test-partitioning1.sh | 6 ++-- tests/test-partitioning4.sh | 2 +- tests/test-partitioning6.sh | 2 +- tests/test-protect-ranges.sh | 2 +- tests/test-qcow2dec-map.sh | 2 +- tests/test-qcow2dec.sh | 2 +- tests/test-random-copy.sh| 2 +- tests/test-random-sock.sh| 4 +-- tests/test-rate-dynamic.sh | 2 +- tests/test-rate.sh | 2 +- tests/test-readahead-copy.sh | 4 +-- tests/test-readahead.sh | 2 +- tests/test-retry-extents.sh | 2 +- tests/test-retry-open.sh | 2 +- tests/test-retry-readonly.sh | 2 +-
[Libguestfs] [PATCH nbdkit 00/10] Make --run imply -U -
Should have done this a long time ago. I feel it is about time we change the default of nbdkit --run to imply -U -, rather than opening a public port. Patch series turned out to be a little bit more complicated than I anticipated, but it contains some nice clean ups. Last patch updating the documentation wouldn't be applied any time soon, so that the old docs stay around on the website. Rich. ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
[Libguestfs] [PATCH nbdkit 03/10] server: Don't set port as a side effect
This removes another long-range code dependency. --- server/sockets.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/sockets.c b/server/sockets.c index fe8b24409..d49b1755b 100644 --- a/server/sockets.c +++ b/server/sockets.c @@ -171,26 +171,26 @@ bind_unix_socket (sockets *socks) void bind_tcpip_socket (sockets *socks) { + const char *ipport; struct addrinfo *ai = NULL; struct addrinfo hints; struct addrinfo *a; int err, opt; int saved_errno = 0; - if (port == NULL) -port = "10809"; + ipport = port ? port : "10809"; memset (, 0, sizeof hints); hints.ai_flags = AI_PASSIVE; hints.ai_family = tcpip_sock_af; hints.ai_socktype = SOCK_STREAM; - err = getaddrinfo (ipaddr, port, , ); + err = getaddrinfo (ipaddr, ipport, , ); if (err != 0) { fprintf (stderr, "%s: getaddrinfo: %s: %s: %s\n", program_name, ipaddr ? ipaddr : "", - port, + ipport, gai_strerror (err)); exit (EXIT_FAILURE); } @@ -272,7 +272,7 @@ bind_tcpip_socket (sockets *socks) } debug ("bound to IP address %s:%s (%zu socket(s))", - ipaddr ? ipaddr : "", port, socks->len); + ipaddr ? ipaddr : "", ipport, socks->len); } void -- 2.41.0 ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
[Libguestfs] [PATCH nbdkit 06/10] server: Make --run imply -U -
Almost always when you used nbdkit --run you should also use -U - (to use a private Unix domain socket). Otherwise nbdkit listened on TCP port 10809, which had two bad side effects: It permitted other processes to interfere with your --run command, and it reserved a public TCP port which would stop two instances of nbdkit running at the same time. This was a frequent cause of bugs in test cases. Switch the default so now --run implies -U - You can still get the old behaviour by using --port explicitly, but that is almost certainly a bad idea. (Using --run and --vsock works the same way as before too. It is also usually a bad idea, although we use it in one test.) --- docs/nbdkit-captive.pod | 7 --- docs/nbdkit.pod | 9 - server/main.c | 9 + 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/docs/nbdkit-captive.pod b/docs/nbdkit-captive.pod index 34a1d0922..248f9df28 100644 --- a/docs/nbdkit-captive.pod +++ b/docs/nbdkit-captive.pod @@ -98,13 +98,6 @@ I<--run> implies I<--foreground>. It is not possible, and probably not desirable, to have nbdkit fork into the background when using I<--run>. -Even when running captive, nbdkit still listens on the regular TCP/IP -port, unless you specify the I<-p>/I<-U> options. If you want a truly -private captive nbdkit, then you should create a private random -Unix socket, like this: - - nbdkit -U - plugin [args] --run '...' - =head2 Copying data in and out of plugins with captive nbdkit Captive nbdkit + L can be used to copy data into and out diff --git a/docs/nbdkit.pod b/docs/nbdkit.pod index 634c97e3a..f62796886 100644 --- a/docs/nbdkit.pod +++ b/docs/nbdkit.pod @@ -382,6 +382,12 @@ like Debian this might not be a full-featured shell. This option implies I<--foreground>. +In nbdkit E 1.34 you normally had to add I<-U ->, otherwise nbdkit +would use a TCP/IP port which was normally not what you wanted. In +nbdkit E 1.36, using I<--run> implies I<-U ->. If you want the +old behaviour of nbdkit then you must add the I<--port> option +explicitly. + =item B<--selinux-label=>SOCKET-LABEL Apply the SELinux label C to the nbdkit listening @@ -481,7 +487,8 @@ should delete the socket file after use (else if you try to start nbdkit up again you will get an C error). If the socket name is I<-> then nbdkit generates a randomly named -private socket. This is useful with L. +private socket. This is implied by the I<--run> option. See also +L. =item B<-u> USER diff --git a/server/main.c b/server/main.c index 0c9019d94..978a720cf 100644 --- a/server/main.c +++ b/server/main.c @@ -621,6 +621,15 @@ main (int argc, char *argv[]) exit (EXIT_FAILURE); } + /* Since nbdkit 1.36, --run implies -U -, unless --vsock or --port + * was set explicitly. + */ + if (run && !unixsocket && !port && !vsock) { +unixsocket = make_random_fifo (); +if (!unixsocket) + exit (EXIT_FAILURE); + } + /* By the point we have enough information to calculate the service mode. */ if (socket_activation) service_mode = SERVICE_MODE_SOCKET_ACTIVATION; -- 2.41.0 ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
[Libguestfs] [PATCH nbdkit 10/10] XXX docs: Remove references to -U - when it is implicit
XXX NOTE XXX I would not apply this patch immediately, since online documentation will get updated as soon as I do that. Best to wait until after 1.36 is released at least. XXX END NOTE XXX --- docs/nbdkit-captive.pod | 6 +++--- filters/cacheextents/nbdkit-cacheextents-filter.pod | 2 +- filters/checkwrite/nbdkit-checkwrite-filter.pod | 6 +++--- filters/pause/nbdkit-pause-filter.pod | 2 +- filters/retry/nbdkit-retry-filter.pod | 2 +- plugins/linuxdisk/nbdkit-linuxdisk-plugin.pod | 4 ++-- plugins/nbd/nbdkit-nbd-plugin.pod | 2 +- plugins/random/nbdkit-random-plugin.pod | 2 +- plugins/sparse-random/nbdkit-sparse-random-plugin.pod | 2 +- plugins/torrent/nbdkit-torrent-plugin.pod | 6 +++--- plugins/vddk/nbdkit-vddk-plugin.pod | 4 ++-- BENCHMARKING | 4 ++-- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/nbdkit-captive.pod b/docs/nbdkit-captive.pod index 248f9df28..4f9740bc9 100644 --- a/docs/nbdkit-captive.pod +++ b/docs/nbdkit-captive.pod @@ -46,7 +46,7 @@ When guestfish exits, nbdkit is killed. Running nbdkit captive under nbdsh for unit testing: - nbdkit -U - memory 1 --run 'nbdsh -u "$uri" -c "print(h.pread(1, 0))"' + nbdkit memory 1 --run 'nbdsh -u "$uri" -c "print(h.pread(1, 0))"' The following shell variables are available in the I<--run> argument: @@ -104,7 +104,7 @@ Captive nbdkit + L can be used to copy data into and out of nbdkit plugins. For example L contains an embedded disk image. To copy it out: - nbdkit -U - example1 --run 'qemu-img convert $nbd disk.img' + nbdkit example1 --run 'qemu-img convert $nbd disk.img' If the source suffers from temporary network failures L or L may @@ -114,7 +114,7 @@ To overwrite a file inside an uncompressed tar file (the file being overwritten must be the same size), use L like this: - nbdkit -U - file data.tar --filter=tar tar-entry=disk.img \ + nbdkit file data.tar --filter=tar tar-entry=disk.img \ --run 'qemu-img convert -n disk.img $nbd' =head1 EXIT WITH PARENT diff --git a/filters/cacheextents/nbdkit-cacheextents-filter.pod b/filters/cacheextents/nbdkit-cacheextents-filter.pod index 77dc680c8..a2b2aa519 100644 --- a/filters/cacheextents/nbdkit-cacheextents-filter.pod +++ b/filters/cacheextents/nbdkit-cacheextents-filter.pod @@ -17,7 +17,7 @@ only one extent at a time (such as S>), but where the plugin can provide multiple extents for the same high latency as a single extent (such as L). For example: - nbdkit -U - --filter=cacheextents --run 'qemu-img map $nbd' vddk ... + nbdkit --filter=cacheextents --run 'qemu-img map $nbd' vddk ... For files with big extents (when it is unlikely for one extents() call to return multiple different extents) this does not slow down the diff --git a/filters/checkwrite/nbdkit-checkwrite-filter.pod b/filters/checkwrite/nbdkit-checkwrite-filter.pod index 67a466f87..6855d7988 100644 --- a/filters/checkwrite/nbdkit-checkwrite-filter.pod +++ b/filters/checkwrite/nbdkit-checkwrite-filter.pod @@ -28,17 +28,17 @@ You can check that a copying tool is copying data correctly by creating an nbdkit instance containing some test data, overlaying this filter, and copying from and to nbdkit at the same time: - nbdkit -U - --filter=checkwrite data "@32768 1" \ + nbdkit --filter=checkwrite data "@32768 1" \ --run 'nbdcopy "$uri" "$uri"' =for paragraph - nbdkit -U - --filter=checkwrite file disk.img \ + nbdkit --filter=checkwrite file disk.img \ --run 'nbdcopy "$uri" "$uri"' =for paragraph - nbdkit -U - --filter=checkwrite linuxdisk testdir/ \ + nbdkit --filter=checkwrite linuxdisk testdir/ \ --run 'qemu-img convert -n "$uri" "$uri"' If the copying program is buggy then you will see EIO errors and (if diff --git a/filters/pause/nbdkit-pause-filter.pod b/filters/pause/nbdkit-pause-filter.pod index 1bc083ddc..708e0b3ea 100644 --- a/filters/pause/nbdkit-pause-filter.pod +++ b/filters/pause/nbdkit-pause-filter.pod @@ -39,7 +39,7 @@ Any unknown commands are ignored. The filter responds with C<'X'>. Pick a large file, disk image or ISO, serve it over NBD, and start copying it: - nbdkit -U - --filter=pause --filter=rate \ + nbdkit --filter=pause --filter=rate \ file BIG_FILE.ISO rate=10M pause-control=sock \ --run 'qemu-img convert -p $nbd /var/tmp/out' diff --git a/filters/retry/nbdkit-retry-filter.pod b/filters/retry/nbdkit-retry-filter.pod index 6eba3d4ff..6179a507d 100644 --- a/filters/retry/nbdkit-retry-filter.pod +++ b/filters/retry/nbdkit-retry-filter.pod @@ -50,7 +50,7 @@ waiting in total about 1 minute before we give up. In this example we copy and convert a large file using L, L and L. - nbdkit -U - \ + nbdkit \ ssh host=remote.example.com /var/tmp/test.iso \ --filter=retry \ --run 'qemu-img convert
[Libguestfs] [PATCH nbdkit 08/10] tests: Be punctilious about using requires_run in tests that use --run
This requires that nbdkit is built with the --run feature, which (currently) is not true for Windows. (In some tests we separately checked for !Windows, but let's favour consistency.) --- plugins/rust/test-ramdisk.sh | 2 ++ tests/test-S3.sh | 1 + tests/test-blkio.sh | 1 + tests/test-block-size-constraints.sh | 1 + tests/test-blocksize-default.sh | 1 + tests/test-blocksize-error-policy.sh | 1 + tests/test-blocksize-extents.sh | 1 + tests/test-blocksize-policy.sh | 1 + tests/test-blocksize-sharding.sh | 1 + tests/test-blocksize-write-disconnect.sh | 1 + tests/test-cc-cpp.sh | 1 + tests/test-cc-ocaml.sh | 1 + tests/test-cc.sh | 1 + tests/test-cow-block-size.sh | 1 + tests/test-cow.sh| 1 + tests/test-curl-file.sh | 1 + tests/test-curl-header-script-fail.sh| 1 + tests/test-eflags.sh | 1 + tests/test-eval-cache.sh | 1 + tests/test-eval-exports.sh | 1 + tests/test-eval-file.sh | 1 + tests/test-eval.sh | 1 + tests/test-evil-cosmic.sh| 1 + tests/test-evil-large-p.sh | 1 + tests/test-evil-small-p.sh | 1 + tests/test-exportname.sh | 1 + tests/test-file-dir.sh | 1 + tests/test-file-extents.sh | 1 + tests/test-ip-filter-anyunix.sh | 1 + tests/test-ip-filter-anyvsock.sh | 1 + tests/test-ip-filter-gid.sh | 1 + tests/test-ip-filter-uid.sh | 1 + tests/test-linuxdisk-copy-out.sh | 1 + tests/test-multi-conn-name.sh| 1 + tests/test-multi-conn.sh | 1 + tests/test-nbd-block-size.sh | 1 + tests/test-nbd-extents.sh| 1 + tests/test-nbd-vsock.sh | 1 + tests/test-nozero.sh | 1 + tests/test-old-plugins.sh| 1 + tests/test-ondemand-list.sh | 1 + tests/test-parallel-file.sh | 1 + tests/test-parallel-nbd.sh | 1 + tests/test-parallel-sh.sh| 1 + tests/test-partition2.sh | 1 + tests/test-qcow2dec-map.sh | 1 + tests/test-qcow2dec.sh | 1 + tests/test-readahead.sh | 1 + tests/test-retry-extents.sh | 1 + tests/test-retry-open.sh | 1 + tests/test-retry-readonly.sh | 1 + tests/test-retry-reopen-fail.sh | 1 + tests/test-retry-request-open.sh | 1 + tests/test-retry-request.sh | 1 + tests/test-retry-size.sh | 1 + tests/test-retry-zero-flags.sh | 1 + tests/test-retry.sh | 1 + tests/test-sh-errors.sh | 1 + tests/test-sh-extents.sh | 1 + tests/test-shebang-cc.sh | 1 + tests/test-ssh.sh| 1 + tests/test-stdio.sh | 1 + tests/test-swab-extents.sh | 1 + tests/test-tar-info-xz-qcow2dec.sh | 1 + tests/test-tar-info-xz.sh| 1 + tests/test-tar-info.sh | 1 + tests/test-tls.sh| 1 + tests/test-tmpdisk-command.sh| 1 + tests/test-vddk-password-fd.sh | 1 + tests/test-vddk-password-interactive.sh | 1 + tests/test-vddk-real-create.sh | 1 + tests/test-vddk-real.sh | 1 + tests/test-vddk-reexec.sh| 1 + tests/test-vddk-run.sh | 1 + tests/test-vsock.sh | 1 + 75 files changed, 76 insertions(+) diff --git a/plugins/rust/test-ramdisk.sh b/plugins/rust/test-ramdisk.sh index a10f6300d..430ee5190 100755 --- a/plugins/rust/test-ramdisk.sh +++ b/plugins/rust/test-ramdisk.sh @@ -44,6 +44,8 @@ if is_windows; then exit 77 fi +requires_run + ramdisk=target/release/examples/libramdisk.so requires test -x $ramdisk diff --git a/tests/test-S3.sh b/tests/test-S3.sh index ec2177704..047c931ca 100755 --- a/tests/test-S3.sh +++ b/tests/test-S3.sh @@ -34,6 +34,7 @@ source ./functions.sh set -e set -x +requires_run requires hexdump --version requires $PYTHON --version requires_nbdcopy diff --git a/tests/test-blkio.sh b/tests/test-blkio.sh index 4e45126de..31896ad96 100755 --- a/tests/test-blkio.sh +++ b/tests/test-blkio.sh @@ -39,6 +39,7 @@ source ./functions.sh set -e set -x +requires_run requires_plugin blkio requires_nbdsh_uri requires test -f disk diff --git a/tests/test-block-size-constraints.sh b/tests/test-block-size-constraints.sh index e282923da..692a918e9 100755 --- a/tests/test-block-size-constraints.sh +++ b/tests/test-block-size-constraints.sh @@ -34,6 +34,7 @@ source ./functions.sh set -e set -x +requires_run
[Libguestfs] [PATCH nbdkit 07/10] tests/test-parallel-*.sh: Remove redundant comment
--- tests/test-parallel-file.sh | 1 - tests/test-parallel-nbd.sh | 1 - tests/test-parallel-sh.sh | 1 - 3 files changed, 3 deletions(-) diff --git a/tests/test-parallel-file.sh b/tests/test-parallel-file.sh index 3cbaa2d46..add60007a 100755 --- a/tests/test-parallel-file.sh +++ b/tests/test-parallel-file.sh @@ -32,7 +32,6 @@ source ./functions.sh -# Check file-data was created by Makefile and qemu-io exists. requires test -f file-data requires qemu-io --version requires timeout 60s true diff --git a/tests/test-parallel-nbd.sh b/tests/test-parallel-nbd.sh index ebecb6cab..3467e9f98 100755 --- a/tests/test-parallel-nbd.sh +++ b/tests/test-parallel-nbd.sh @@ -32,7 +32,6 @@ source ./functions.sh -# Check file-data was created by Makefile and qemu-io exists. requires test -f file-data requires qemu-io --version requires timeout 60s true diff --git a/tests/test-parallel-sh.sh b/tests/test-parallel-sh.sh index 73f5ab512..fae44e537 100755 --- a/tests/test-parallel-sh.sh +++ b/tests/test-parallel-sh.sh @@ -32,7 +32,6 @@ source ./functions.sh -# Check file-data was created by Makefile and qemu-io exists. requires test -f file-data requires qemu-io --version requires timeout 60s true -- 2.41.0 ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
[Libguestfs] [PATCH nbdkit 05/10] server: Add the NBD URI to debug output
Example after applying this patch: $ ./nbdkit -fv --port -e foo null 1M /home/rjones/d/nbdkit/server/nbdkit -f -v --port= -e foo -- /home/rjones/d/nbdkit/plugins/null/.libs/nbdkit-null-plugin.so 1M nbdkit: debug: nbdkit 1.35.12 nbdkit: debug: TLS disabled: could not load TLS certificates nbdkit: debug: NBD URI: nbd://localhost:/foo An alternative I considered was adding a --print-uri option which would print the URI on stdout. Maybe we could do this as an alternative later. Normally the server does not print anything on stdout, and it is problematic in some modes, like when using -s. --- server/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/main.c b/server/main.c index 54eb348ba..0c9019d94 100644 --- a/server/main.c +++ b/server/main.c @@ -637,6 +637,8 @@ main (int argc, char *argv[]) * Note this may be NULL. */ uri = make_uri (); + if (uri) +debug ("NBD URI: %s", uri); /* The remaining command line arguments are the plugin name and * parameters. If --help, --version or --dump-plugin were specified -- 2.41.0 ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs
[Libguestfs] [PATCH nbdkit 02/10] server: Don't set export_name as a side effect of using --run
Reduce long-range code dependencies by not setting export_name in run_command (--run functionality), especially as this function is not always called. If the -e option was not used at all then export_name will be NULL. --- server/captive.c | 12 +--- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/server/captive.c b/server/captive.c index 31fd949e5..40c4bb2ca 100644 --- a/server/captive.c +++ b/server/captive.c @@ -67,9 +67,6 @@ run_command (void) if (!run) return; - if (!export_name) -export_name = ""; - fp = open_memstream (, ); if (fp == NULL) { perror ("open_memstream"); @@ -84,7 +81,7 @@ run_command (void) break; /* can't form a URI, leave it blank */ case SERVICE_MODE_UNIXSOCKET: fprintf (fp, "nbd%s+unix://", tls == 2 ? "s" : ""); -if (strcmp (export_name, "") != 0) { +if (export_name && strcmp (export_name, "") != 0) { putc ('/', fp); uri_quote (export_name, fp); } @@ -98,7 +95,7 @@ run_command (void) putc (':', fp); shell_quote (port, fp); } -if (strcmp (export_name, "") != 0) { +if (export_name && strcmp (export_name, "") != 0) { putc ('/', fp); uri_quote (export_name, fp); } @@ -109,7 +106,7 @@ run_command (void) putc (':', fp); shell_quote (port, fp); } -if (strcmp (export_name, "") != 0) { +if (export_name && strcmp (export_name, "") != 0) { putc ('/', fp); uri_quote (export_name, fp); } @@ -124,7 +121,8 @@ run_command (void) /* Expose $exportname. */ fprintf (fp, "exportname="); - shell_quote (export_name, fp); + if (export_name) +shell_quote (export_name, fp); putc ('\n', fp); /* Construct $tls, $port and $unixsocket. */ -- 2.41.0 ___ Libguestfs mailing list Libguestfs@redhat.com https://listman.redhat.com/mailman/listinfo/libguestfs