[Libguestfs] [PATCH libnbd] info: Write output atomically.
Eric Blake
eblake at redhat.com
Tue Oct 6 18:01:49 UTC 2020
On 10/6/20 11:54 AM, Richard W.M. Jones wrote:
> If the server fails, nbdinfo can write partial output before the error
> message (albeit on different channels). Here is an example:
>
> $ nbdkit eval open='echo EIO fail >&2; exit 1' --run 'nbdinfo --json "$uri"'
> {
> "protocol": "newstyle-fixed",
> "TLS": false,
> nbdkit: eval[1]: error: /tmp/nbdkitii3pZW/open: fail
> nbdkit: eval[1]: error: /tmp/nbdkitii3pZW/open: fail
> nbdinfo: nbd_opt_go: server replied with error to opt_go request: No such file or directory
>
> Notice the partial JSON document, and the error message from nbdinfo.
>
> With this commit nbdinfo tries to produce either the complete output
> or the error message.
> ---
> info/Makefile.am | 1 +
> info/info-atomic-output.sh | 32 ++++++
> info/nbdinfo.c | 194 ++++++++++++++++++++++---------------
> 3 files changed, 147 insertions(+), 80 deletions(-)
ACK. Mostly mechanical, and memstreams make this nice.
> +++ b/info/info-atomic-output.sh
> @@ -0,0 +1,32 @@
> +. ../tests/functions.sh
> +
> +set -e
> +set -x
> +
> +requires nbdkit --version
> +requires nbdkit eval --version
You could simplify this: if the second line passes, the first line is
implied, therefore, only the second is needed.
> +
> +out=info-atomic-output.out
> +cleanup_fn rm -f $out
> +
> +nbdkit -U - eval open='echo EIO fail >&2; exit 1' \
> + --run '$VG nbdinfo --size "nbd+unix:///?socket=$unixsocket"' > $out ||:
nbdkit added $uri in 1.14, and the eval plugin in 1.18. You could
shorten this to --run '$VG nbdino --size "$uri"'. (We still use the
longhand elsewhere because of older RHEL having older nbdkit, but this
will already be skipped on those setups).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20201006/213cbb7c/attachment.sig>
More information about the Libguestfs
mailing list