[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] vcpu: teach getVcpusFlags about current



Now that virDomainSetVcpusFlags knows about VIR_DOMAIN_AFFECT_CURRENT,
so should virDomainGetVcpusFlags.

Unfortunately, the virsh counterpart 'virsh vcpucount' has already
commandeered --current for a different meaning, so virsh does not
have a way to expose this new calling capability unless we either
break backward compatibility or consistency with other virsh commands
that take --live and --config.

* src/libvirt.c (virDomainGetVcpusFlags): Allow
VIR_DOMAIN_AFFECT_CURRENT.
* src/libxl/libxl_driver.c (libxlDomainGetVcpusFlags): Likewise.
* src/qemu/qemu_driver.c (qemudDomainGetVcpusFlags): Likewise.
* src/test/test_driver.c (testDomainGetVcpusFlags): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainGetVcpusFlags): Likewise.
---

In response to:
https://www.redhat.com/archives/libvir-list/2011-July/msg00967.html

 src/libvirt.c            |    4 ++--
 src/libxl/libxl_driver.c |   29 +++++++++++++++++++++--------
 src/qemu/qemu_driver.c   |   29 +++++++++++++++++++++--------
 src/test/test_driver.c   |   31 +++++++++++++++++++++++--------
 src/xen/xen_driver.c     |    7 -------
 5 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 4de718d..def3fb9 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -6951,8 +6951,8 @@ virDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
         return -1;
     }

-    /* Exactly one of these two flags should be set.  */
-    if (!(flags & VIR_DOMAIN_AFFECT_LIVE) == !(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+    /* At most one of these two flags should be set.  */
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
         virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
         goto error;
     }
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index cc37d05..2e0d377 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -2327,18 +2327,12 @@ libxlDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
     virDomainObjPtr vm;
     virDomainDefPtr def;
     int ret = -1;
+    bool active;

     virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);

-    /* Exactly one of LIVE or CONFIG must be set.  */
-    if (!(flags & VIR_DOMAIN_VCPU_LIVE) == !(flags & VIR_DOMAIN_VCPU_CONFIG)) {
-        libxlError(VIR_ERR_INVALID_ARG,
-                   _("invalid flag combination: (0x%x)"), flags);
-        return -1;
-    }
-
     libxlDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     libxlDriverUnlock(driver);
@@ -2348,14 +2342,33 @@ libxlDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
         goto cleanup;
     }

+    active = virDomainObjIsActive(vm);
+
+    if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0) {
+        if (active)
+            flags |= VIR_DOMAIN_VCPU_LIVE;
+        else
+            flags |= VIR_DOMAIN_VCPU_CONFIG;
+    }
+    if ((flags & VIR_DOMAIN_VCPU_LIVE) && (flags & VIR_DOMAIN_VCPU_CONFIG)) {
+        libxlError(VIR_ERR_INVALID_ARG,
+                   _("invalid flag combination: (0x%x)"), flags);
+        return -1;
+    }
+
     if (flags & VIR_DOMAIN_VCPU_LIVE) {
-        if (!virDomainObjIsActive(vm)) {
+        if (!active) {
             libxlError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("Domain is not running"));
             goto cleanup;
         }
         def = vm->def;
     } else {
+        if (!vm->persistent) {
+            libxlError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is transient"));
+            goto cleanup;
+        }
         def = vm->newDef ? vm->newDef : vm->def;
     }

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1a3fbfb..536cd5c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3408,18 +3408,12 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
     virDomainObjPtr vm;
     virDomainDefPtr def;
     int ret = -1;
+    bool active;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);

-    /* Exactly one of LIVE or CONFIG must be set.  */
-    if (!(flags & VIR_DOMAIN_AFFECT_LIVE) == !(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
-        qemuReportError(VIR_ERR_INVALID_ARG,
-                        _("invalid flag combination: (0x%x)"), flags);
-        return -1;
-    }
-
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     qemuDriverUnlock(driver);
@@ -3432,14 +3426,33 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
         goto cleanup;
     }

+    active = virDomainObjIsActive(vm);
+
+    if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0) {
+        if (active)
+            flags |= VIR_DOMAIN_VCPU_LIVE;
+        else
+            flags |= VIR_DOMAIN_VCPU_CONFIG;
+    }
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        qemuReportError(VIR_ERR_INVALID_ARG,
+                        _("invalid flag combination: (0x%x)"), flags);
+        return -1;
+    }
+
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-        if (!virDomainObjIsActive(vm)) {
+        if (!active) {
             qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
                             _("domain not active"));
             goto cleanup;
         }
         def = vm->def;
     } else {
+        if (!vm->persistent) {
+            qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                            _("domain is transient"));
+            goto cleanup;
+        }
         def = vm->newDef ? vm->newDef : vm->def;
     }

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 064a1cd..28da8e7 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2067,18 +2067,12 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
     virDomainObjPtr vm;
     virDomainDefPtr def;
     int ret = -1;
+    bool active;

     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);

-    /* Exactly one of LIVE or CONFIG must be set.  */
-    if (!(flags & VIR_DOMAIN_AFFECT_LIVE) == !(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
-        testError(VIR_ERR_INVALID_ARG,
-                  _("invalid flag combination: (0x%x)"), flags);
-        return -1;
-    }
-
     testDriverLock(privconn);
     vm = virDomainFindByUUID(&privconn->domains, domain->uuid);
     testDriverUnlock(privconn);
@@ -2091,14 +2085,35 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
         goto cleanup;
     }

+    active = virDomainObjIsActive(vm);
+
+    if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0) {
+        if (active)
+            flags |= VIR_DOMAIN_VCPU_LIVE;
+        else
+            flags |= VIR_DOMAIN_VCPU_CONFIG;
+    }
+    if ((flags & VIR_DOMAIN_AFFECT_LIVE) && (flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+        testError(VIR_ERR_INVALID_ARG,
+                  _("invalid flag combination: (0x%x)"), flags);
+        return -1;
+    }
+
+
+
     if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-        if (!virDomainObjIsActive(vm)) {
+        if (!active) {
             testError(VIR_ERR_OPERATION_INVALID, "%s",
                       _("domain not active"));
             goto cleanup;
         }
         def = vm->def;
     } else {
+        if (!vm->persistent) {
+            testError(VIR_ERR_OPERATION_INVALID, "%s",
+                      _("domain is transient"));
+            goto cleanup;
+        }
         def = vm->newDef ? vm->newDef : vm->def;
     }

diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index dd1ba6c..0f8b660 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1201,13 +1201,6 @@ xenUnifiedDomainGetVcpusFlags (virDomainPtr dom, unsigned int flags)
                   VIR_DOMAIN_VCPU_CONFIG |
                   VIR_DOMAIN_VCPU_MAXIMUM, -1);

-    /* Exactly one of LIVE or CONFIG must be set.  */
-    if (!(flags & VIR_DOMAIN_VCPU_LIVE) == !(flags & VIR_DOMAIN_VCPU_CONFIG)) {
-        xenUnifiedError(VIR_ERR_INVALID_ARG,
-                        _("invalid flag combination: (0x%x)"), flags);
-        return -1;
-    }
-
     if (priv->opened[XEN_UNIFIED_XEND_OFFSET]) {
         ret = xenDaemonDomainGetVcpusFlags(dom, flags);
         if (ret != -2)
-- 
1.7.4.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]