From 59d042871ce9e6356f881c7d7296aee0614e13d1 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 15 Jul 2011 17:35:47 -0600 Subject: [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 teaching virsh to expose this in the next patch will require a bit of care. * 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. --- src/libvirt.c | 15 +++++++++------ 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, 74 insertions(+), 37 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 5ff8d8917d..996ab948f6 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -7373,10 +7373,13 @@ error: * not support it. This function requires privileged access to the * hypervisor. * - * @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. + * If @flags includes VIR_DOMAIN_AFFECT_LIVE, this will query a + * running domain (which will fail if domain is not active); if + * it includes VIR_DOMAIN_AFFECT_CONFIG, this will query the XML + * description of the domain. It is an error to set both flags. + * If neither flag is set (that is, VIR_DOMAIN_AFFECT_CURRENT), + * then the configuration queried depends on whether the domain + * is currently running. * * If @flags includes VIR_DOMAIN_VCPU_MAXIMUM, then the maximum * virtual CPU limit is queried. Otherwise, this call queries the @@ -7400,8 +7403,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 5583684f76..7cb362065b 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -2364,18 +2364,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); @@ -2385,14 +2379,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 130f474382..b92800415a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3543,18 +3543,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); @@ -3567,14 +3561,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 81a4ae8f12..fb14b106e9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2099,18 +2099,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); @@ -2123,14 +2117,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 8ebf86e492..155ffda858 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1239,13 +1239,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) -- GitLab