Allow to store driver specific data on a per-vcpu basis.
Move of the virDomainDef*Vcpus* functions was necessary as
virDomainXMLOptionPtr was declared below this block and I didn't want to
split the function headers.
_("Failed to parse number of vCPUs"));
goto error;
}
- if (virDomainDefSetVcpusMax(def, vcpus) < 0)
+ if (virDomainDefSetVcpusMax(def, vcpus, xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(def, vcpus) < 0)
goto error;
static virDomainVcpuDefPtr
-virDomainVcpuDefNew(void)
+virDomainVcpuDefNew(virDomainXMLOptionPtr xmlopt)
{
- virDomainVcpuDefPtr ret;
+ virObjectPtr priv = NULL;
+ virDomainVcpuDefPtr ret = NULL;
- ignore_value(VIR_ALLOC(ret));
+ if (xmlopt && xmlopt->privateData.vcpuNew &&
+ !(priv = xmlopt->privateData.vcpuNew()))
+ goto cleanup;
+
+ if (VIR_ALLOC(ret) < 0)
+ goto cleanup;
+
+ ret->privateData = priv;
+ priv = NULL;
+ cleanup:
+ virObjectUnref(priv);
return ret;
}
virBitmapFree(info->cpumask);
info->cpumask = NULL;
+ virObjectUnref(info->privateData);
VIR_FREE(info);
}
int
virDomainDefSetVcpusMax(virDomainDefPtr def,
- unsigned int maxvcpus)
+ unsigned int maxvcpus,
+ virDomainXMLOptionPtr xmlopt)
{
size_t oldmax = def->maxvcpus;
size_t i;
return -1;
for (i = oldmax; i < def->maxvcpus; i++) {
- if (!(def->vcpus[i] = virDomainVcpuDefNew()))
+ if (!(def->vcpus[i] = virDomainVcpuDefNew(xmlopt)))
return -1;
}
} else {
static int
virDomainVcpuParse(virDomainDefPtr def,
- xmlXPathContextPtr ctxt)
+ xmlXPathContextPtr ctxt,
+ virDomainXMLOptionPtr xmlopt)
{
int n;
char *tmp = NULL;
maxvcpus = 1;
}
- if (virDomainDefSetVcpusMax(def, maxvcpus) < 0)
+ if (virDomainDefSetVcpusMax(def, maxvcpus, xmlopt) < 0)
goto cleanup;
if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &vcpus)) < 0) {
&def->mem.swap_hard_limit) < 0)
goto error;
- if (virDomainVcpuParse(def, ctxt) < 0)
+ if (virDomainVcpuParse(def, ctxt, xmlopt) < 0)
goto error;
/* Optional - iothreads */
virBitmapPtr cpumask;
virDomainThreadSchedParam sched;
+
+ virObjectPtr privateData;
};
typedef struct _virDomainBlkiotune virDomainBlkiotune;
xmlNodePtr metadata;
};
-int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
-bool virDomainDefHasVcpusOffline(const virDomainDef *def);
-unsigned int virDomainDefGetVcpusMax(const virDomainDef *def);
-int virDomainDefSetVcpus(virDomainDefPtr def, unsigned int vcpus);
-unsigned int virDomainDefGetVcpus(const virDomainDef *def);
-virBitmapPtr virDomainDefGetOnlineVcpumap(const virDomainDef *def);
-virDomainVcpuDefPtr virDomainDefGetVcpu(virDomainDefPtr def, unsigned int vcpu)
- ATTRIBUTE_RETURN_CHECK;
unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
* virDomainDefCopy and similar functions */
virDomainXMLPrivateDataNewFunc diskNew;
virDomainXMLPrivateDataNewFunc hostdevNew;
+ virDomainXMLPrivateDataNewFunc vcpuNew;
virDomainXMLPrivateDataFormatFunc format;
virDomainXMLPrivateDataParseFunc parse;
};
return dom->def->id != -1;
}
+int virDomainDefSetVcpusMax(virDomainDefPtr def,
+ unsigned int vcpus,
+ virDomainXMLOptionPtr xmlopt);
+bool virDomainDefHasVcpusOffline(const virDomainDef *def);
+unsigned int virDomainDefGetVcpusMax(const virDomainDef *def);
+int virDomainDefSetVcpus(virDomainDefPtr def, unsigned int vcpus);
+unsigned int virDomainDefGetVcpus(const virDomainDef *def);
+virBitmapPtr virDomainDefGetOnlineVcpumap(const virDomainDef *def);
+virDomainVcpuDefPtr virDomainDefGetVcpu(virDomainDefPtr def, unsigned int vcpu)
+ ATTRIBUTE_RETURN_CHECK;
+
virDomainObjPtr virDomainObjNew(virDomainXMLOptionPtr caps)
ATTRIBUTE_NONNULL(1);
def->mem.cur_balloon = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */
if (virDomainDefSetVcpusMax(def,
- processorSettingData->data->VirtualQuantity) < 0)
+ processorSettingData->data->VirtualQuantity,
+ NULL) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def,
def = NULL;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
- if (virDomainDefSetVcpusMax(vm->def, d_info.vcpu_max_id + 1))
+ if (virDomainDefSetVcpusMax(vm->def, d_info.vcpu_max_id + 1, driver->xmlopt))
goto cleanup;
if (virDomainDefSetVcpus(vm->def, d_info.vcpu_online) < 0)
switch (flags) {
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
- if (virDomainDefSetVcpusMax(def, nvcpus) < 0)
+ if (virDomainDefSetVcpusMax(def, nvcpus, driver->xmlopt) < 0)
goto cleanup;
break;
/* Value not handled by the LXC driver, setting to
* minimum required to make XML parsing pass */
- if (virDomainDefSetVcpusMax(vmdef, 1) < 0)
+ if (virDomainDefSetVcpusMax(vmdef, 1, xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(vmdef, 1) < 0)
if (ret == 0 || vcpus == 0)
vcpus = openvzGetNodeCPUs();
- if (virDomainDefSetVcpusMax(def, vcpus) < 0)
+ if (virDomainDefSetVcpusMax(def, vcpus, driver->xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, vcpus) < 0)
static int openvzConnectGetMaxVcpus(virConnectPtr conn, const char *type);
static int openvzDomainGetMaxVcpus(virDomainPtr dom);
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
- unsigned int nvcpus);
+ unsigned int nvcpus,
+ virDomainXMLOptionPtr xmlopt);
static int openvzDomainSetMemoryInternal(virDomainObjPtr vm,
unsigned long long memory);
static int openvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason);
goto cleanup;
}
if (virDomainDefGetVcpusMax(vm->def)) {
- if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def)) < 0) {
+ if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def),
+ driver->xmlopt) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not set number of vCPUs"));
goto cleanup;
virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
if (virDomainDefGetVcpusMax(vm->def) > 0) {
- if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def)) < 0) {
+ if (openvzDomainSetVcpusInternal(vm, virDomainDefGetVcpusMax(vm->def),
+ driver->xmlopt) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not set number of vCPUs"));
goto cleanup;
}
static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
- unsigned int nvcpus)
+ unsigned int nvcpus,
+ virDomainXMLOptionPtr xmlopt)
{
char str_vcpus[32];
const char *prog[] = { VZCTL, "--quiet", "set", PROGRAM_SENTINEL,
if (virRun(prog, NULL) < 0)
return -1;
- if (virDomainDefSetVcpusMax(vm->def, nvcpus) < 0)
+ if (virDomainDefSetVcpusMax(vm->def, nvcpus, xmlopt) < 0)
return -1;
if (virDomainDefSetVcpus(vm->def, nvcpus) < 0)
goto cleanup;
}
- if (openvzDomainSetVcpusInternal(vm, nvcpus) < 0) {
+ if (openvzDomainSetVcpusInternal(vm, nvcpus, driver->xmlopt) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not set number of vCPUs"));
goto cleanup;
goto err;
}
- if (virDomainDefSetVcpusMax(&def, vcpus) < 0)
+ if (virDomainDefSetVcpusMax(&def, vcpus, phyp_driver->xmlopt) < 0)
goto err;
if (virDomainDefSetVcpus(&def, vcpus) < 0)
goto endjob;
}
- if (virDomainDefSetVcpusMax(persistentDef, nvcpus) < 0)
+ if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
goto endjob;
} else {
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
static int
qemuParseCommandLineSmp(virDomainDefPtr dom,
- const char *val)
+ const char *val,
+ virDomainXMLOptionPtr xmlopt)
{
unsigned int sockets = 0;
unsigned int cores = 0;
if (maxcpus == 0)
maxcpus = vcpus;
- if (virDomainDefSetVcpusMax(dom, maxcpus) < 0)
+ if (virDomainDefSetVcpusMax(dom, maxcpus, xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(dom, vcpus) < 0)
def->id = -1;
def->mem.cur_balloon = 64 * 1024;
virDomainDefSetMemoryTotal(def, def->mem.cur_balloon);
- if (virDomainDefSetVcpusMax(def, 1) < 0)
+ if (virDomainDefSetVcpusMax(def, 1, xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(def, 1) < 0)
goto error;
goto error;
} else if (STREQ(arg, "-smp")) {
WANT_VALUE();
- if (qemuParseCommandLineSmp(def, val) < 0)
+ if (qemuParseCommandLineSmp(def, val, xmlopt) < 0)
goto error;
} else if (STREQ(arg, "-uuid")) {
WANT_VALUE();
testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
unsigned int flags)
{
+ testDriverPtr driver = domain->conn->privateData;
virDomainObjPtr privdom = NULL;
virDomainDefPtr def;
virDomainDefPtr persistentDef;
if (persistentDef) {
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
- if (virDomainDefSetVcpusMax(persistentDef, nrCpus) < 0)
+ if (virDomainDefSetVcpusMax(persistentDef, nrCpus,
+ driver->xmlopt) < 0)
goto cleanup;
} else {
if (virDomainDefSetVcpus(persistentDef, nrCpus) < 0)
virDomainDefSetMemoryTotal(def, memorySize * 1024);
gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
- if (virDomainDefSetVcpusMax(def, CPUCount) < 0)
+ if (virDomainDefSetVcpusMax(def, CPUCount, data->xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, CPUCount) < 0)
def->dom->os.type = VIR_DOMAIN_OSTYPE_HVM;
def->dom->os.arch = virArchFromHost();
gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
- if (virDomainDefSetVcpusMax(def->dom, CPUCount) < 0)
+ if (virDomainDefSetVcpusMax(def->dom, CPUCount, data->xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def->dom, CPUCount) < 0)
goto cleanup;
}
- if (virDomainDefSetVcpusMax(def, numvcpus) < 0)
+ if (virDomainDefSetVcpusMax(def, numvcpus, xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, numvcpus) < 0)
static int
prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
- virDomainDefPtr def)
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt)
{
char *buf;
int hostcpus;
if (cpuCount > hostcpus)
cpuCount = hostcpus;
- if (virDomainDefSetVcpusMax(def, cpuCount) < 0)
+ if (virDomainDefSetVcpusMax(def, cpuCount, xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, cpuCount) < 0)
convert to Kbytes */
def->mem.cur_balloon = ram << 10;
- if (prlsdkConvertCpuInfo(sdkdom, def) < 0)
+ if (prlsdkConvertCpuInfo(sdkdom, def, driver->xmlopt) < 0)
goto error;
if (prlsdkConvertCpuMode(sdkdom, def) < 0)
}
if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
- if (virDomainDefSetVcpusMax(entry->def, vcpus) < 0)
+ if (virDomainDefSetVcpusMax(entry->def, vcpus, priv->xmlopt) < 0)
goto cleanup;
} else {
if (virDomainDefSetVcpus(entry->def, vcpus) < 0)
vcpus = xenapiDomainGetMaxVcpus(dom);
- if (virDomainDefSetVcpusMax(defPtr, vcpus) < 0)
+ if (virDomainDefSetVcpusMax(defPtr, vcpus, priv->xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(defPtr, vcpus) < 0)
static int
-xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
+xenParseCPUFeatures(virConfPtr conf,
+ virDomainDefPtr def,
+ virDomainXMLOptionPtr xmlopt)
{
unsigned long count = 0;
const char *str = NULL;
if (xenConfigGetULong(conf, "vcpus", &count, 1) < 0)
return -1;
- if (virDomainDefSetVcpusMax(def, count) < 0)
+ if (virDomainDefSetVcpusMax(def, count, xmlopt) < 0)
return -1;
if (virDomainDefSetVcpus(def, count) < 0)
if (xenConfigGetULong(conf, "maxvcpus", &count, 0) < 0)
return -1;
- if (virDomainDefSetVcpusMax(def, count) < 0)
+ if (virDomainDefSetVcpusMax(def, count, xmlopt) < 0)
return -1;
}
xenParseConfigCommon(virConfPtr conf,
virDomainDefPtr def,
virCapsPtr caps,
- const char *nativeFormat)
+ const char *nativeFormat,
+ virDomainXMLOptionPtr xmlopt)
{
if (xenParseGeneralMeta(conf, def, caps) < 0)
return -1;
if (xenParseEventsActions(conf, def) < 0)
return -1;
- if (xenParseCPUFeatures(conf, def) < 0)
+ if (xenParseCPUFeatures(conf, def, xmlopt) < 0)
return -1;
if (xenParseTimeOffset(conf, def) < 0)
int xenParseConfigCommon(virConfPtr conf,
virDomainDefPtr def,
virCapsPtr caps,
- const char *nativeFormat);
+ const char *nativeFormat,
+ virDomainXMLOptionPtr xmlopt);
int xenFormatConfigCommon(virConfPtr conf,
virDomainDefPtr def,
}
}
- if (virDomainDefSetVcpusMax(def, sexpr_int(root, "domain/vcpus")) < 0)
+ if (virDomainDefSetVcpusMax(def, sexpr_int(root, "domain/vcpus"), xmlopt) < 0)
goto error;
vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1;
- if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XL) < 0)
+ if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XL,
+ xmlopt) < 0)
goto cleanup;
if (xenParseXLOS(conf, def, caps) < 0)
def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1;
- if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XM) < 0)
+ if (xenParseConfigCommon(conf, def, caps, XEN_CONFIG_FORMAT_XM,
+ xmlopt) < 0)
goto cleanup;
if (xenParseXMOS(conf, def) < 0)