We need this feature in the following patch.
---
include/libvirt/libvirt.h.in | 3 ++-
src/libvirt.c | 12 ++++++------
src/qemu/qemu_driver.c | 18 ++++++++++--------
3 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 8e20f75..14d6a88 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1234,8 +1234,9 @@ typedef virVcpuInfo *virVcpuInfoPtr;
/* Flags for controlling virtual CPU hot-plugging. */
typedef enum {
- /* Must choose at least one of these two bits; SetVcpus can choose both;
+ /* Must choose at least one of these three bits; SetVcpus can choose both;
see virDomainModificationImpact for details. */
+ VIR_DOMAIN_VCPU_CURRENT = VIR_DOMAIN_AFFECT_CURRENT,
VIR_DOMAIN_VCPU_LIVE = VIR_DOMAIN_AFFECT_LIVE,
VIR_DOMAIN_VCPU_CONFIG = VIR_DOMAIN_AFFECT_CONFIG,
diff --git a/src/libvirt.c b/src/libvirt.c
index e00c64f..9857e3b 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -6923,13 +6923,18 @@ error:
* @flags must include either VIR_DOMAIN_AFFECT_LIVE to query a
* running domain (which will fail if domain is not active), or
* VIR_DOMAIN_AFFECT_CONFIG to query the XML description of the
- * domain. It is an error to set both flags.
+ * domain, or VIR_DOMAIN_AFFECT_CURRENT to query a running domain
+ * (if domain is active) or query the XML description of the domain
+ * (if domain is not active).
+ * It is an error to set two of these three flags.
*
* If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then the maximum
* virtual CPU limit is queried. Otherwise, this call queries the
* current virtual CPU limit.
*
* Returns 0 in case of success, -1 in case of failure.
+ *
+ * NB. Not all hypervisor support VIR_DOMAIN_AFFECT_CURRENT.
*/
int
@@ -6947,11 +6952,6 @@ 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))
{
- virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
- goto error;
- }
conn = domain->conn;
if (conn->driver->domainGetVcpusFlags) {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8b65c26..9ddbc0f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3374,18 +3374,12 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
virDomainObjPtr vm;
virDomainDefPtr def;
int ret = -1;
+ bool isActive;
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);
@@ -3398,8 +3392,16 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
goto cleanup;
}
+ isActive = virDomainObjIsActive(vm);
+ if ((flags & ~VIR_DOMAIN_VCPU_MAXIMUM) == VIR_DOMAIN_AFFECT_CURRENT) {
+ if (isActive)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+ else
+ flags |= VIR_DOMAIN_AFFECT_CONFIG;
+ }
+
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
- if (!virDomainObjIsActive(vm)) {
+ if (!isActive) {
qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("domain not active"));
goto cleanup;
--
1.7.1