psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone
Blob Blame History Raw
From 592ad2e9e6bca314308389a60da421597f6c7d38 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 19 Dec 2013 14:22:26 +0000
Subject: [PATCH] launch: libvirt: Don't default to using NULL for libvirt
 connection URI (RHBZ#1045033).

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.

(cherry picked from commit d16db5a6180305543658f3a50657c70bbdf81b40)
---
 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 6909b50..1931055 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 b78590a..729f437 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.5.3