1 From 28a3605906385cba43df77051dc26e865f237b09 Mon Sep 17 00:00:00 2001
2 From: Eric Blake <eblake@redhat.com>
3 Date: Wed, 29 Sep 2010 17:40:45 -0600
4 Subject: [PATCH 11/15] vcpu: complete vcpu support in qemu driver
6 * src/qemu/qemu_driver.c (qemudDomainSetVcpusFlags)
7 (qemudDomainGetVcpusFlags): Support all feasible flag
10 src/qemu/qemu_driver.c | 100 ++++++++++++++++++++++++++++++++++++++++-------
11 1 files changed, 85 insertions(+), 15 deletions(-)
13 diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
14 index c66dc04..a9e057f 100644
15 --- a/src/qemu/qemu_driver.c
16 +++ b/src/qemu/qemu_driver.c
17 @@ -5941,13 +5941,27 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
19 struct qemud_driver *driver = dom->conn->privateData;
21 + virDomainDefPtr def;
26 - if (flags != VIR_DOMAIN_VCPU_LIVE) {
27 - qemuReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"),
29 + virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
30 + VIR_DOMAIN_VCPU_CONFIG |
31 + VIR_DOMAIN_VCPU_MAXIMUM, -1);
33 + /* At least one of LIVE or CONFIG must be set. MAXIMUM cannot be
34 + * mixed with LIVE. */
35 + if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0 ||
36 + (flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) ==
37 + (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) {
38 + qemuReportError(VIR_ERR_INVALID_ARG,
39 + _("invalid flag combination: (0x%x)"), flags);
42 + if (!nvcpus || (unsigned short) nvcpus != nvcpus) {
43 + qemuReportError(VIR_ERR_INVALID_ARG,
44 + _("argument out of range: %d"), nvcpus);
48 @@ -5966,7 +5980,7 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
49 if (qemuDomainObjBeginJob(vm) < 0)
52 - if (!virDomainObjIsActive(vm)) {
53 + if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_VCPU_LIVE)) {
54 qemuReportError(VIR_ERR_OPERATION_INVALID,
55 "%s", _("domain is not running"));
57 @@ -5985,6 +5999,11 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
61 + if ((flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) ==
62 + VIR_DOMAIN_VCPU_LIVE && vm->def->maxvcpus < max) {
63 + max = vm->def->maxvcpus;
67 qemuReportError(VIR_ERR_INVALID_ARG,
68 _("requested vcpus is greater than max allowable"
69 @@ -5992,7 +6011,49 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
73 - ret = qemudDomainHotplugVcpus(vm, nvcpus);
75 + case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
77 + if (virDomainObjIsActive(vm)) {
81 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
82 + _("no persistent state"));
86 + def->maxvcpus = nvcpus;
87 + if (nvcpus < vm->newDef->vcpus)
88 + def->vcpus = nvcpus;
92 + case VIR_DOMAIN_VCPU_CONFIG:
94 + if (virDomainObjIsActive(vm)) {
98 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
99 + _("no persistent state"));
103 + def->vcpus = nvcpus;
107 + case VIR_DOMAIN_VCPU_LIVE:
108 + ret = qemudDomainHotplugVcpus(vm, nvcpus);
111 + case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
112 + ret = qemudDomainHotplugVcpus(vm, nvcpus);
113 + if (ret == 0 && vm->newDef)
114 + vm->newDef->vcpus = nvcpus;
119 if (qemuDomainObjEndJob(vm) == 0)
120 @@ -6171,12 +6232,17 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
122 struct qemud_driver *driver = dom->conn->privateData;
125 + virDomainDefPtr def;
128 - if (flags != (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
129 - qemuReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"),
131 + virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
132 + VIR_DOMAIN_VCPU_CONFIG |
133 + VIR_DOMAIN_VCPU_MAXIMUM, -1);
135 + /* Exactly one of LIVE or CONFIG must be set. */
136 + if (!(flags & VIR_DOMAIN_VCPU_LIVE) == !(flags & VIR_DOMAIN_VCPU_CONFIG)) {
137 + qemuReportError(VIR_ERR_INVALID_ARG,
138 + _("invalid flag combination: (0x%x)"), flags);
142 @@ -6192,14 +6258,18 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
146 - if (!(type = virDomainVirtTypeToString(vm->def->virtType))) {
147 - qemuReportError(VIR_ERR_INTERNAL_ERROR,
148 - _("unknown virt type in domain definition '%d'"),
149 - vm->def->virtType);
151 + if (flags & VIR_DOMAIN_VCPU_LIVE) {
152 + if (!virDomainObjIsActive(vm)) {
153 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
154 + _("domain not active"));
159 + def = vm->newDef ? vm->newDef : vm->def;
162 - ret = qemudGetMaxVCPUs(NULL, type);
163 + ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;