[Pkg-libvirt-commits] [libguestfs] 41/63: v2v: -i libvirt: Check the domain is not running (RHBZ#1138586).

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:43:29 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.39-1
in repository libguestfs.

commit 096c05a750b8b525e48149c0c6522769c92ab07c
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Fri Sep 5 13:36:01 2014 +0100

    v2v: -i libvirt: Check the domain is not running (RHBZ#1138586).
    
    It will print an error like this:
    
      virt-v2v: error: internal error: invalid argument: libvirt domain 'windows'
      is running, it must be shut down in order to perform virt-v2v conversion
    
    This only works for libvirt domains, and is explicitly disabled for
    test:/// URIs since these domains are always "running", but we use
    these URIs for testing.
---
 v2v/domainxml-c.c    | 20 +++++++++++++++++++-
 v2v/input_libvirt.ml |  8 +++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c
index b8d7d9a..6e68138 100644
--- a/v2v/domainxml-c.c
+++ b/v2v/domainxml-c.c
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <string.h>
 #include <errno.h>
 
 #include <caml/alloc.h>
@@ -76,10 +77,13 @@ v2v_dumpxml (value connv, value domnamev)
   const char *domname;
   virConnectPtr conn;
   virDomainPtr dom;
+  int is_test_uri = 0, state, reason;
   char *xml;
 
-  if (connv != Val_int (0))
+  if (connv != Val_int (0)) {
     conn_uri = String_val (Field (connv, 0)); /* Some conn */
+    is_test_uri = STRPREFIX (conn_uri, "test:");
+  }
 
   /* We have to call the default authentication handler, not least
    * since it handles all the PolicyKit crap.  However it also makes
@@ -102,6 +106,20 @@ v2v_dumpxml (value connv, value domnamev)
     raise_error ("cannot find libvirt domain '%s'", domname);
   }
 
+  /* As a side-effect we check that the domain is shut down.  Of course
+   * this is only appropriate for virt-v2v.  (RHBZ#1138586)
+   */
+  if (!is_test_uri) {
+    if (virDomainGetState (dom, &state, &reason, 0) == 0) {
+      if (state == VIR_DOMAIN_RUNNING) {
+        virDomainFree (dom);
+        virConnectClose (conn);
+        raise_error ("libvirt domain '%s' is running, it must be shut down in order to perform virt-v2v conversion",
+                     domname);
+      }
+    }
+  }
+
   xml = virDomainGetXMLDesc (dom, 0);
   virDomainFree (dom);
   virConnectClose (conn);
diff --git a/v2v/input_libvirt.ml b/v2v/input_libvirt.ml
index 6d78976..9e8e6e7 100644
--- a/v2v/input_libvirt.ml
+++ b/v2v/input_libvirt.ml
@@ -45,6 +45,11 @@ object
       guest
 
   method source () =
+    (* Get the libvirt XML.  This also checks (as a side-effect)
+     * that the domain is not running.  (RHBZ#1138586)
+     *)
+    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
+
     (* Depending on the libvirt URI we may need to convert <source/>
      * paths so we can access them remotely (if that is possible).  This
      * is only true for remote, non-NULL URIs.  (We assume the user
@@ -89,9 +94,6 @@ object
             orig_uri;
           None, None in
 
-    (* Get the libvirt XML. *)
-    let xml = Domainxml.dumpxml ?conn:libvirt_uri guest in
-
     Input_libvirtxml.parse_libvirt_xml ?map_source_file ?map_source_dev xml
 end
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list