[Pkg-libvirt-commits] [libguestfs] 10/40: v2v: Fall back to virDomainGetInfo if remote libvirtd does not support virDomainGetState (RHBZ#1138586).
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:44:42 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.44-1
in repository libguestfs.
commit 516faa1bcb64a95b25ec7f3b2be0d2d1f6c0c60d
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Wed Sep 10 16:29:28 2014 +0100
v2v: Fall back to virDomainGetInfo if remote libvirtd does not support virDomainGetState (RHBZ#1138586).
RHEL 5 Xen doesn't support the relatively new virDomainGetState API.
Instead you will see a warning message on stderr:
libvirt: Remote Driver error : unknown procedure: 212
If we detect that virDomainGetState is not supported, then fall back
to calling virDomainGetInfo instead, which works everywhere.
This updates commit 096c05a750b8b525e48149c0c6522769c92ab07c.
See also:
https://bugzilla.redhat.com/show_bug.cgi?id=1139973#c2
https://bugzilla.redhat.com/show_bug.cgi?id=1138586
---
v2v/domainxml-c.c | 41 +++++++++++++++++++++++++++++++++--------
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/v2v/domainxml-c.c b/v2v/domainxml-c.c
index 6e68138..2bb1daf 100644
--- a/v2v/domainxml-c.c
+++ b/v2v/domainxml-c.c
@@ -33,6 +33,7 @@
#ifdef HAVE_LIBVIRT
#include <libvirt/libvirt.h>
+#include <libvirt/virterror.h>
#endif
#include "guestfs.h"
@@ -68,6 +69,30 @@ raise_error (const char *fs, ...)
caml_invalid_argument (msg);
}
+/* Get the remote domain state (running, etc.). Use virDomainGetState
+ * which is most efficient, but if it's not implemented, fall back to
+ * virDomainGetInfo. See equivalent code in virsh.
+ */
+static int
+get_dom_state (virDomainPtr dom)
+{
+ int state, reason;
+ virErrorPtr err;
+ virDomainInfo info;
+
+ if (virDomainGetState (dom, &state, &reason, 0) == 0)
+ return state;
+
+ err = virGetLastError ();
+ if (!err || err->code != VIR_ERR_NO_SUPPORT)
+ return -1;
+
+ if (virDomainGetInfo (dom, &info) == 0)
+ return info.state;
+
+ return -1;
+}
+
value
v2v_dumpxml (value connv, value domnamev)
{
@@ -77,7 +102,7 @@ v2v_dumpxml (value connv, value domnamev)
const char *domname;
virConnectPtr conn;
virDomainPtr dom;
- int is_test_uri = 0, state, reason;
+ int is_test_uri = 0;
char *xml;
if (connv != Val_int (0)) {
@@ -110,13 +135,13 @@ v2v_dumpxml (value connv, value domnamev)
* 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);
- }
+ int state = get_dom_state (dom);
+
+ 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);
}
}
--
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