daemon: Move TLS initialization to virInitialize
[libvirt/zwu.git] / docs / api_extension / 0011-complete-vcpu-support-in-qemu-driver.patch
blob251008fd01a3508c58dcbe57c6b21534b25c26b4
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
8 combinations.
9 ---
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;
20 virDomainObjPtr vm;
21 + virDomainDefPtr def;
22 const char * type;
23 int max;
24 int ret = -1;
26 - if (flags != VIR_DOMAIN_VCPU_LIVE) {
27 - qemuReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"),
28 - flags);
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);
40 + return -1;
41 + }
42 + if (!nvcpus || (unsigned short) nvcpus != nvcpus) {
43 + qemuReportError(VIR_ERR_INVALID_ARG,
44 + _("argument out of range: %d"), nvcpus);
45 return -1;
48 @@ -5966,7 +5980,7 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
49 if (qemuDomainObjBeginJob(vm) < 0)
50 goto cleanup;
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"));
56 goto endjob;
57 @@ -5985,6 +5999,11 @@ qemudDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
58 goto endjob;
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;
64 + }
66 if (nvcpus > max) {
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,
70 goto endjob;
73 - ret = qemudDomainHotplugVcpus(vm, nvcpus);
74 + switch (flags) {
75 + case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
76 + def = vm->def;
77 + if (virDomainObjIsActive(vm)) {
78 + if (vm->newDef)
79 + def = vm->newDef;
80 + else{
81 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
82 + _("no persistent state"));
83 + goto endjob;
84 + }
85 + }
86 + def->maxvcpus = nvcpus;
87 + if (nvcpus < vm->newDef->vcpus)
88 + def->vcpus = nvcpus;
89 + ret = 0;
90 + break;
92 + case VIR_DOMAIN_VCPU_CONFIG:
93 + def = vm->def;
94 + if (virDomainObjIsActive(vm)) {
95 + if (vm->newDef)
96 + def = vm->newDef;
97 + else {
98 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
99 + _("no persistent state"));
100 + goto endjob;
103 + def->vcpus = nvcpus;
104 + ret = 0;
105 + break;
107 + case VIR_DOMAIN_VCPU_LIVE:
108 + ret = qemudDomainHotplugVcpus(vm, nvcpus);
109 + break;
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;
115 + break;
118 endjob:
119 if (qemuDomainObjEndJob(vm) == 0)
120 @@ -6171,12 +6232,17 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
122 struct qemud_driver *driver = dom->conn->privateData;
123 virDomainObjPtr vm;
124 - const char *type;
125 + virDomainDefPtr def;
126 int ret = -1;
128 - if (flags != (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
129 - qemuReportError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"),
130 - flags);
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);
139 return -1;
142 @@ -6192,14 +6258,18 @@ qemudDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
143 goto cleanup;
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);
150 - goto cleanup;
151 + if (flags & VIR_DOMAIN_VCPU_LIVE) {
152 + if (!virDomainObjIsActive(vm)) {
153 + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
154 + _("domain not active"));
155 + goto cleanup;
157 + def = vm->def;
158 + } else {
159 + def = vm->newDef ? vm->newDef : vm->def;
162 - ret = qemudGetMaxVCPUs(NULL, type);
163 + ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
165 cleanup:
166 if (vm)
168 1.7.2.3