Richard W.M. Jones
2013-Dec-19 14:33 UTC
[Libguestfs] [PATCH] launch: libvirt: Don't default to using NULL for libvirt connection URI (RHBZ#1045033).
From: "Richard W.M. Jones" <rjones@redhat.com> NULL means that libvirt gets to guess what connection URI we meant. Currently it guesses qemu:///session for non-root and qemu:///system for root. Except if LIBVIRT_DEFAULT_URI is set in which case this is used even if it's not appropriate. Except if Xen is installed in which case it guesses xen:/// which is not helpful at all. Instead use qemu:///session (or qemu:///system for root -- that's likely to be wrong, but we can't help that). If the user really wants to use NULL and let libvirt guess, then they can now specify the libvirt:null backend. See: https://bugzilla.redhat.com/show_bug.cgi?id=1045033 https://bugzilla.redhat.com/show_bug.cgi?id=886915 A good way to test this is: LIBVIRT_DEFAULT_URI=iambroken libguestfs-test-tool The libguestfs libvirt backend should (after this commit) ignore LIBVIRT_DEFAULT_URI. However other parts of libguestfs will still use it, eg. guestfs_add_drive_opts, guestfish '-d' option. --- src/guestfs.pod | 16 +++++++++++++--- src/launch-libvirt.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/guestfs.pod b/src/guestfs.pod index 1e4b16c..0aab4a9 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -1429,13 +1429,23 @@ note below. =item C<libvirt> +=item C<libvirt:null> + =item C<libvirt:I<URI>> Use libvirt to launch and manage the appliance. -The optional I<URI> is the libvirt connection URI to use (see -L<http://libvirt.org/uri.html>). The typical libvirt backend -with a URI would be C<libvirt:qemu:///session> +C<libvirt> causes libguestfs to choose a suitable URI for creating +session guests. If using the libvirt backend, you almost always +should use this. + +C<libvirt:null> causes libguestfs to use the C<NULL> connection URI, +which causes libvirt to try to guess what the user meant. You +probably don't want to use this. + +C<libvirt:I<URI>> uses I<URI> as the libvirt connection URI (see +L<http://libvirt.org/uri.html>). The typical libvirt backend with a +URI would be C<libvirt:qemu:///session> The libvirt backend supports more features, including hotplugging (see L</HOTPLUGGING>) and sVirt. diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c index 36e3df0..984c5aa 100644 --- a/src/launch-libvirt.c +++ b/src/launch-libvirt.c @@ -216,6 +216,16 @@ launch_libvirt (guestfs_h *g, void *datav, const char *libvirt_uri) if (g->verbose) guestfs___print_timestamped_message (g, "connect to libvirt"); + /* Decode the URI string. */ + if (!libvirt_uri) { /* "libvirt" */ + if (!params.current_proc_is_root) + libvirt_uri = "qemu:///session"; + else + libvirt_uri = "qemu:///system"; + } else if (STREQ (libvirt_uri, "null")) { /* libvirt:null */ + libvirt_uri = NULL; + } /* else nothing */ + /* Connect to libvirt, get capabilities. */ conn = guestfs___open_libvirt_connection (g, libvirt_uri, 0); if (!conn) { -- 1.8.3.1
Seemingly Similar Threads
- [PATCH v3 09/11] launch: Remove guestfs_int_print_timestamped_message function.
- [PATCH] New APIs: Model libvirt authentication events through the API.
- Re: libguestfs-tools with libvirt SASL authentication
- [PATCH] lib: libvirt: If root, run qemu as root.root.
- [PATCH 1/2] src: start unifying version handling