# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1216844583 25200
# Node ID 039b7c1f078d007f02224652235edea0a7113926
# Parent 3327f39024303cb8a218110d039e37bf9c2b12cd
Fix (again) domain_online()
In the neverending quest to get domain_online() to do the Right Thing(tm),
this patch attempts to count VIR_DOMAIN_NOSTATE as running for Xen,
and as offline for KVM and LXC.
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 3327f3902430 -r 039b7c1f078d libxkutil/misc_util.c
--- a/libxkutil/misc_util.c Wed Jul 23 12:22:04 2008 -0700
+++ b/libxkutil/misc_util.c Wed Jul 23 13:23:03 2008 -0700
@@ -383,21 +383,53 @@
{
virDomainInfo info;
virDomainPtr _dom;
- bool rc;
+ bool rc = false;
+ virConnectPtr conn = NULL;
+ int flags[] = {VIR_DOMAIN_BLOCKED,
+ VIR_DOMAIN_RUNNING,
+ VIR_DOMAIN_NOSTATE,
+ };
+ int compare_flags = 3;
+ int i;
+
+ conn = virDomainGetConnect(dom);
+ if (conn == NULL) {
+ CU_DEBUG("Unknown connection type, assuming RUNNING,BLOCKED");
+ compare_flags = 2;
+ } else if (STREQC(virConnectGetType(conn), "Xen")) {
+ CU_DEBUG("Type is Xen");
+ compare_flags = 3;
+ } else if (STREQC(virConnectGetType(conn), "QEMU")) {
+ CU_DEBUG("Type is KVM");
+ compare_flags = 2;
+ } else if (STREQC(virConnectGetType(conn), "LXC")) {
+ CU_DEBUG("Type is LXC");
+ compare_flags = 2;
+ } else {
+ CU_DEBUG("Unknown type `%s', assuming RUNNING,BLOCKED",
+ virConnectGetType(conn));
+ compare_flags = 2;
+ }
_dom = virDomainLookupByName(virDomainGetConnect(dom),
virDomainGetName(dom));
if (_dom == NULL) {
CU_DEBUG("Unable to re-lookup domain");
- return false;
+ goto out;
}
- if (virDomainGetInfo(_dom, &info) != 0)
+ if (virDomainGetInfo(_dom, &info) != 0) {
rc = false;
- else
- rc = (info.state == VIR_DOMAIN_BLOCKED) ||
- (info.state == VIR_DOMAIN_RUNNING) ||
- (info.state == VIR_DOMAIN_NOSTATE);
+ goto out;
+ }
+
+ for (i = 0; i < compare_flags; i++) {
+ if (info.state == flags[i]) {
+ rc = true;
+ break;
+ }
+ }
+ out:
virDomainFree(_dom);
return rc;