[Libguestfs] [libnbd PATCH v2 09/13] info: Simplify by using nbd_opt_go
Richard W.M. Jones
rjones at redhat.com
Mon Aug 17 11:10:06 UTC 2020
On Fri, Aug 14, 2020 at 05:00:28PM -0500, Eric Blake wrote:
> Instead of having to munge a URI to supply a different export name, we
> can exploit the fact that nbd_opt_mode lets us change the preferred
> export name after nbd_connect_uri has established its socket.
>
> In fact, by doing this, nbdinfo no longer needs to directly link
> against libxml2, so it can now be built regardless of whether the
> underlying libnbd.so supports URIs (although use of the program will
> fail if libnbd.so was not built against libxml2).
> ---
> info/Makefile.am | 6 ++---
> info/nbdinfo.c | 63 +++++++++++++++++++-----------------------------
> 2 files changed, 27 insertions(+), 42 deletions(-)
>
> diff --git a/info/Makefile.am b/info/Makefile.am
> index 05b8137..d049d16 100644
> --- a/info/Makefile.am
> +++ b/info/Makefile.am
> @@ -27,8 +27,6 @@ EXTRA_DIST = \
> nbdinfo.pod \
> $(NULL)
>
> -if HAVE_LIBXML2
> -
> TESTS_ENVIRONMENT = LIBNBD_DEBUG=1
> LOG_COMPILER = $(top_builddir)/run
> TESTS =
> @@ -39,11 +37,9 @@ nbdinfo_SOURCES = nbdinfo.c
> nbdinfo_CPPFLAGS = -I$(top_srcdir)/include
> nbdinfo_CFLAGS = \
> $(WARNINGS_CFLAGS) \
> - $(LIBXML2_CFLAGS) \
> $(NULL)
> nbdinfo_LDADD = \
> $(top_builddir)/lib/libnbd.la \
> - $(LIBXML2_LIBS) \
> $(NULL)
>
> if HAVE_POD
> @@ -59,6 +55,8 @@ nbdinfo.1: nbdinfo.pod $(top_builddir)/podwrapper.pl
>
> endif HAVE_POD
>
> +if HAVE_LIBXML2
> +
> TESTS += \
> info-list.sh \
> info-list-json.sh \
> diff --git a/info/nbdinfo.c b/info/nbdinfo.c
> index b54dfd4..394f5ac 100644
> --- a/info/nbdinfo.c
> +++ b/info/nbdinfo.c
> @@ -29,7 +29,6 @@
> #include <limits.h>
> #include <errno.h>
>
> -#include <libxml/uri.h>
> #include <libnbd.h>
>
> static bool list_all = false;
> @@ -422,7 +421,6 @@ static void
> list_all_exports (struct nbd_handle *nbd1, const char *uri)
> {
> int i;
> - xmlURIPtr xmluri = NULL;
> int count = nbd_get_nr_list_exports (nbd1);
>
> if (count == -1) {
> @@ -434,49 +432,38 @@ list_all_exports (struct nbd_handle *nbd1, const char *uri)
> printf ("\t\"exports\": []\n");
>
> for (i = 0; i < count; ++i) {
> - char *name, *desc, *new_path, *new_uri;
> + char *name, *desc;
> struct nbd_handle *nbd2;
>
> name = nbd_get_list_export_name (nbd1, i);
> - if (name) {
> - /* We have to modify the original URI to change the export name.
> - * In the URI spec, paths always start with '/' (which is ignored).
> - */
> - xmluri = xmlParseURI (uri);
> - if (!xmluri) {
> - fprintf (stderr, "unable to parse original URI: %s\n", uri);
> - exit (EXIT_FAILURE);
> - }
> - if (asprintf (&new_path, "/%s", name) == -1) {
> - perror ("asprintf");
> - exit (EXIT_FAILURE);
> - }
> - free (xmluri->path);
> - xmluri->path = new_path;
> - new_uri = (char *) xmlSaveUri (xmluri);
Yes, good to get rid of this horrible bit of code!
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
More information about the Libguestfs
mailing list