<domain>
...
<vcpu placement='static' cpuset="1-4,^3,6" current="1">2</vcpu>
+ <vcpus>
+ <vcpu id='0' enabled='yes' hotpluggable='no' order='1'/>
+ <vcpu id='1' enabled='no' hotpluggable='yes'/>
+ </vcpus>
...
</domain>
</pre>
</dd>
</dl>
</dd>
+ <dt><code>vcpus</code></dt>
+ <dd>
+ The vcpus element allows to control state of individual vcpus.
+
+ The <code>id</code> attribute specifies the vCPU id as used by libvirt
+ in other places such as vcpu pinning, scheduler information and NUMA
+ assignment. Note that the vcpu ID as seen in the guest may differ from
+ libvirt ID in certain cases. Valid IDs are from 0 to the maximum vcpu
+ count as set by the <code>vcpu</code> element minus 1.
+
+ The <code>enabled</code> attribute allows to control the state of the
+ vcpu. Valid values are <code>yes</code> and <code>no</code>.
+
+ <code>hotpluggable</code> controls whether given vcpu can be hotplugged
+ and hotunplugged in cases when the cpu is enabled at boot. Note that
+ all disabled vcpus must be hotpluggable. Valid values are
+ <code>yes</code> and <code>no</code>.
+
+ <code>order</code> allows to specify the order to add the vcpus. For
+ hypervisors/platforms that require to insert multiple vcpus at once
+ the order may be be duplicated accross all vcpus that need to be
+ enabled at once. Specifying order is not necessary, vcpus are then
+ added in an arbitrary order.
+
+ Note that hypervisors may create hotpluggable vcpus differently from
+ boot vcpus thus special initialization may be necessary.
+
+ Hypervisors may require that vcpus enabled on boot which are not
+ hotpluggable are clustered at the beginning starting with ID 0. It may
+ be also required that vcpu 0 is always present and non-hotpluggable.
+
+ Note that providing state for individual cpus may be necessary to enable
+ support of addressable vCPU hotplug and this feature may not be
+ supported by all hypervisors.
+ <span class="since">Since 2.2.0 (QEMU only)</span>
+ </dd>
</dl>
<h3><a name="elementsIOThreadsAllocation">IOThreads Allocation</a></h3>
}
}
+ if (UNSUPPORTED(VIR_DOMAIN_DEF_FEATURE_INDIVIDUAL_VCPUS) &&
+ def->individualvcpus) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("individual CPU state configuration is not supported"));
+ return -1;
+ }
+
return 0;
}
}
+static int
+virDomainVcpuDefPostParse(virDomainDefPtr def)
+{
+ virDomainVcpuDefPtr vcpu;
+ size_t maxvcpus = virDomainDefGetVcpusMax(def);
+ size_t i;
+
+ for (i = 0; i < maxvcpus; i++) {
+ vcpu = virDomainDefGetVcpu(def, i);
+
+ switch (vcpu->hotpluggable) {
+ case VIR_TRISTATE_BOOL_ABSENT:
+ if (vcpu->online)
+ vcpu->hotpluggable = VIR_TRISTATE_BOOL_NO;
+ else
+ vcpu->hotpluggable = VIR_TRISTATE_BOOL_YES;
+ break;
+
+ case VIR_TRISTATE_BOOL_NO:
+ if (!vcpu->online) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("vcpu '%zu' is both offline and not "
+ "hotpluggable"), i);
+ return -1;
+ }
+ break;
+
+ case VIR_TRISTATE_BOOL_YES:
+ case VIR_TRISTATE_BOOL_LAST:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+
static int
virDomainDefPostParseInternal(virDomainDefPtr def,
struct virDomainDefPostParseDeviceIteratorData *data)
return -1;
}
+ if (virDomainVcpuDefPostParse(def) < 0)
+ return -1;
+
if (virDomainDefPostParseMemory(def, data->parseFlags) < 0)
return -1;
virDomainXMLOptionPtr xmlopt)
{
int n;
+ xmlNodePtr *nodes = NULL;
+ size_t i;
char *tmp = NULL;
unsigned int maxvcpus;
unsigned int vcpus;
vcpus = maxvcpus;
}
- if (virDomainDefSetVcpus(def, vcpus) < 0)
- goto cleanup;
tmp = virXPathString("string(./vcpu[1]/@placement)", ctxt);
if (tmp) {
}
}
+ if ((n = virXPathNodeSet("./vcpus/vcpu", ctxt, &nodes)) < 0)
+ goto cleanup;
+
+ if (n) {
+ /* if individual vcpu states are provided take them as master */
+ def->individualvcpus = true;
+
+ for (i = 0; i < n; i++) {
+ virDomainVcpuDefPtr vcpu;
+ int state;
+ unsigned int id;
+ unsigned int order;
+
+ if (!(tmp = virXMLPropString(nodes[i], "id")) ||
+ virStrToLong_uip(tmp, NULL, 10, &id) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing or invalid vcpu id"));
+ goto cleanup;
+ }
+
+ VIR_FREE(tmp);
+
+ if (id >= def->maxvcpus) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("vcpu id '%u' is out of range of maximum "
+ "vcpu count"), id);
+ goto cleanup;
+ }
+
+ vcpu = virDomainDefGetVcpu(def, id);
+
+ if (!(tmp = virXMLPropString(nodes[i], "enabled"))) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("missing vcpu enabled state"));
+ goto cleanup;
+ }
+
+ if ((state = virTristateBoolTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("invalid vcpu 'enabled' value '%s'"), tmp);
+ goto cleanup;
+ }
+ VIR_FREE(tmp);
+
+ vcpu->online = state == VIR_TRISTATE_BOOL_YES;
+
+ if ((tmp = virXMLPropString(nodes[i], "hotpluggable"))) {
+ int hotpluggable;
+ if ((hotpluggable = virTristateBoolTypeFromString(tmp)) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("invalid vcpu 'hotpluggable' value '%s'"), tmp);
+ goto cleanup;
+ }
+ vcpu->hotpluggable = hotpluggable;
+ VIR_FREE(tmp);
+ }
+
+ if ((tmp = virXMLPropString(nodes[i], "order"))) {
+ if (virStrToLong_uip(tmp, NULL, 10, &order) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("invalid vcpu order"));
+ goto cleanup;
+ }
+ vcpu->order = order;
+ VIR_FREE(tmp);
+ }
+ }
+ } else {
+ if (virDomainDefSetVcpus(def, vcpus) < 0)
+ goto cleanup;
+ }
+
ret = 0;
cleanup:
+ VIR_FREE(nodes);
VIR_FREE(tmp);
return ret;
"destination definitions"), i);
return false;
}
+
+ if (svcpu->order != dvcpu->order) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("vcpu enable order of vCPU '%zu' differs between "
+ "source and destination definitions"), i);
+ return false;
+ }
}
return true;
virDomainCpuDefFormat(virBufferPtr buf,
const virDomainDef *def)
{
+ virDomainVcpuDefPtr vcpu;
+ size_t i;
char *cpumask = NULL;
int ret = -1;
virBufferAsprintf(buf, " current='%u'", virDomainDefGetVcpus(def));
virBufferAsprintf(buf, ">%u</vcpu>\n", virDomainDefGetVcpusMax(def));
+ if (def->individualvcpus) {
+ virBufferAddLit(buf, "<vcpus>\n");
+ virBufferAdjustIndent(buf, 2);
+ for (i = 0; i < def->maxvcpus; i++) {
+ vcpu = def->vcpus[i];
+
+ virBufferAsprintf(buf, "<vcpu id='%zu' enabled='%s'",
+ i, vcpu->online ? "yes" : "no");
+ if (vcpu->hotpluggable)
+ virBufferAsprintf(buf, " hotpluggable='%s'",
+ virTristateBoolTypeToString(vcpu->hotpluggable));
+
+ if (vcpu->order != 0)
+ virBufferAsprintf(buf, " order='%d'", vcpu->order);
+
+ virBufferAddLit(buf, "/>\n");
+ }
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "</vcpus>\n");
+ }
+
ret = 0;
cleanup: