[libnbd PATCH] info: Try harder to report contents from nbd-server
nbd-server 3.25 blindly reports a size of 0 for NBD_OPT_INFO, regardless of whether it is exporting a block device or regular file. While that will likely be fixed for the next nbd-server release, we can at least rely on the accurate size after NBD_OPT_GO to report contents more accurately. A more invasive patch would be to unconditionally try NBD_OPT_GO if NBD_OPT_INFO reports a size of 0. Signed-off-by: Eric Blake <eblake@redhat.com> --- info/show.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/info/show.c b/info/show.c index ac483f34..a3a57ef0 100644 --- a/info/show.c +++ b/info/show.c @@ -355,10 +355,20 @@ get_content (struct nbd_handle *nbd, int64_t size) if (!probe_content) return NULL; - if (nbd_aio_is_negotiating (nbd) && - nbd_opt_go (nbd) == -1) { - fprintf (stderr, "%s: %s\n", progname, nbd_get_error ()); - exit (EXIT_FAILURE); + if (nbd_aio_is_negotiating (nbd)) { + if (nbd_opt_go (nbd) == -1) { + fprintf (stderr, "%s: %s\n", progname, nbd_get_error ()); + exit (EXIT_FAILURE); + } + /* nbd-server 3.25 only reports accurate size to NBD_OPT_GO and 0 + * to NBD_OPT_INFO; this hack won't fix what we report for size, + * but improves what we report for contents. + */ + if (size == 0) { + size = nbd_get_size (nbd); + if (size == -1) + size = 0; + } } /* Write the first part of the NBD export to a temporary file. */ -- 2.43.2
On Wed, Feb 21, 2024 at 10:54:04AM -0600, Eric Blake wrote:
nbd-server 3.25 blindly reports a size of 0 for NBD_OPT_INFO, regardless of whether it is exporting a block device or regular file. While that will likely be fixed for the next nbd-server release, we can at least rely on the accurate size after NBD_OPT_GO to report contents more accurately. A more invasive patch would be to unconditionally try NBD_OPT_GO if NBD_OPT_INFO reports a size of 0.
Signed-off-by: Eric Blake <eblake@redhat.com> --- info/show.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/info/show.c b/info/show.c index ac483f34..a3a57ef0 100644 --- a/info/show.c +++ b/info/show.c @@ -355,10 +355,20 @@ get_content (struct nbd_handle *nbd, int64_t size) if (!probe_content) return NULL;
- if (nbd_aio_is_negotiating (nbd) && - nbd_opt_go (nbd) == -1) { - fprintf (stderr, "%s: %s\n", progname, nbd_get_error ()); - exit (EXIT_FAILURE); + if (nbd_aio_is_negotiating (nbd)) { + if (nbd_opt_go (nbd) == -1) { + fprintf (stderr, "%s: %s\n", progname, nbd_get_error ()); + exit (EXIT_FAILURE); + } + /* nbd-server 3.25 only reports accurate size to NBD_OPT_GO and 0 + * to NBD_OPT_INFO; this hack won't fix what we report for size, + * but improves what we report for contents. + */ + if (size == 0) { + size = nbd_get_size (nbd); + if (size == -1) + size = 0; + } }
/* Write the first part of the NBD export to a temporary file. */
Niche, but I guess so. ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
participants (2)
-
Eric Blake -
Richard W.M. Jones