conf: Add private data for virDomainVcpuDef

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.
This commit is contained in:
Peter Krempa 2016-06-29 14:55:24 +02:00
parent 990b06de03
commit 5fe0b6b0a7
22 changed files with 87 additions and 52 deletions

View File

@ -663,7 +663,7 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
_("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;

View File

@ -1307,12 +1307,23 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
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;
}
@ -1325,13 +1336,15 @@ virDomainVcpuDefFree(virDomainVcpuDefPtr info)
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;
@ -1344,7 +1357,7 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
return -1;
for (i = oldmax; i < def->maxvcpus; i++) {
if (!(def->vcpus[i] = virDomainVcpuDefNew()))
if (!(def->vcpus[i] = virDomainVcpuDefNew(xmlopt)))
return -1;
}
} else {
@ -15465,7 +15478,8 @@ virDomainIOThreadSchedParse(xmlNodePtr node,
static int
virDomainVcpuParse(virDomainDefPtr def,
xmlXPathContextPtr ctxt)
xmlXPathContextPtr ctxt,
virDomainXMLOptionPtr xmlopt)
{
int n;
char *tmp = NULL;
@ -15483,7 +15497,7 @@ virDomainVcpuParse(virDomainDefPtr def,
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) {
@ -15952,7 +15966,7 @@ virDomainDefParseXML(xmlDocPtr xml,
&def->mem.swap_hard_limit) < 0)
goto error;
if (virDomainVcpuParse(def, ctxt) < 0)
if (virDomainVcpuParse(def, ctxt, xmlopt) < 0)
goto error;
/* Optional - iothreads */

View File

@ -2037,6 +2037,8 @@ struct _virDomainVcpuDef {
virBitmapPtr cpumask;
virDomainThreadSchedParam sched;
virObjectPtr privateData;
};
typedef struct _virDomainBlkiotune virDomainBlkiotune;
@ -2245,14 +2247,6 @@ struct _virDomainDef {
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);
@ -2408,6 +2402,7 @@ struct _virDomainXMLPrivateDataCallbacks {
* virDomainDefCopy and similar functions */
virDomainXMLPrivateDataNewFunc diskNew;
virDomainXMLPrivateDataNewFunc hostdevNew;
virDomainXMLPrivateDataNewFunc vcpuNew;
virDomainXMLPrivateDataFormatFunc format;
virDomainXMLPrivateDataParseFunc parse;
};
@ -2439,6 +2434,17 @@ virDomainObjIsActive(virDomainObjPtr dom)
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);

View File

@ -876,7 +876,8 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
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,

View File

@ -557,7 +557,7 @@ libxlAddDom0(libxlDriverPrivatePtr driver)
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)
@ -2182,7 +2182,7 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
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;

View File

@ -1020,7 +1020,7 @@ lxcParseConfigString(const char *config,
/* 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)

View File

@ -572,7 +572,7 @@ int openvzLoadDomains(struct openvz_driver *driver)
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)

View File

@ -70,7 +70,8 @@ static int openvzGetProcessInfo(unsigned long long *cpuTime, int vpsid);
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);
@ -1032,7 +1033,8 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla
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;
@ -1130,7 +1132,8 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
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;
@ -1347,7 +1350,8 @@ static int openvzDomainGetMaxVcpus(virDomainPtr dom)
}
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,
@ -1364,7 +1368,7 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
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)
@ -1402,7 +1406,7 @@ static int openvzDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
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;

View File

@ -3296,7 +3296,7 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
goto err;
}
if (virDomainDefSetVcpusMax(&def, vcpus) < 0)
if (virDomainDefSetVcpusMax(&def, vcpus, phyp_driver->xmlopt) < 0)
goto err;
if (virDomainDefSetVcpus(&def, vcpus) < 0)

View File

@ -4849,7 +4849,7 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
goto endjob;
}
if (virDomainDefSetVcpusMax(persistentDef, nvcpus) < 0)
if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
goto endjob;
} else {
if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)

View File

@ -1659,7 +1659,8 @@ qemuParseCommandLineMem(virDomainDefPtr dom,
static int
qemuParseCommandLineSmp(virDomainDefPtr dom,
const char *val)
const char *val,
virDomainXMLOptionPtr xmlopt)
{
unsigned int sockets = 0;
unsigned int cores = 0;
@ -1701,7 +1702,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
if (maxcpus == 0)
maxcpus = vcpus;
if (virDomainDefSetVcpusMax(dom, maxcpus) < 0)
if (virDomainDefSetVcpusMax(dom, maxcpus, xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(dom, vcpus) < 0)
@ -1819,7 +1820,7 @@ qemuParseCommandLine(virCapsPtr caps,
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;
@ -1899,7 +1900,7 @@ qemuParseCommandLine(virCapsPtr caps,
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();

View File

@ -2336,6 +2336,7 @@ static int
testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
unsigned int flags)
{
testDriverPtr driver = domain->conn->privateData;
virDomainObjPtr privdom = NULL;
virDomainDefPtr def;
virDomainDefPtr persistentDef;
@ -2383,7 +2384,8 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
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)

View File

@ -3885,7 +3885,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
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)
@ -6044,7 +6044,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
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)

View File

@ -1457,7 +1457,7 @@ virVMXParseConfig(virVMXContext *ctx,
goto cleanup;
}
if (virDomainDefSetVcpusMax(def, numvcpus) < 0)
if (virDomainDefSetVcpusMax(def, numvcpus, xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, numvcpus) < 0)

View File

@ -1309,7 +1309,8 @@ prlsdkConvertDomainState(VIRTUAL_MACHINE_STATE domainState,
static int
prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
virDomainDefPtr def)
virDomainDefPtr def,
virDomainXMLOptionPtr xmlopt)
{
char *buf;
int hostcpus;
@ -1327,7 +1328,7 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
if (cpuCount > hostcpus)
cpuCount = hostcpus;
if (virDomainDefSetVcpusMax(def, cpuCount) < 0)
if (virDomainDefSetVcpusMax(def, cpuCount, xmlopt) < 0)
goto cleanup;
if (virDomainDefSetVcpus(def, cpuCount) < 0)
@ -1706,7 +1707,7 @@ prlsdkLoadDomain(vzDriverPtr driver, virDomainObjPtr dom)
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)

View File

@ -700,7 +700,7 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn,
}
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)

View File

@ -1505,7 +1505,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
vcpus = xenapiDomainGetMaxVcpus(dom);
if (virDomainDefSetVcpusMax(defPtr, vcpus) < 0)
if (virDomainDefSetVcpusMax(defPtr, vcpus, priv->xmlopt) < 0)
goto error;
if (virDomainDefSetVcpus(defPtr, vcpus) < 0)

View File

@ -483,7 +483,9 @@ xenParsePCI(virConfPtr conf, virDomainDefPtr def)
static int
xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
xenParseCPUFeatures(virConfPtr conf,
virDomainDefPtr def,
virDomainXMLOptionPtr xmlopt)
{
unsigned long count = 0;
const char *str = NULL;
@ -492,7 +494,7 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
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)
@ -502,7 +504,7 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
if (xenConfigGetULong(conf, "maxvcpus", &count, 0) < 0)
return -1;
if (virDomainDefSetVcpusMax(def, count) < 0)
if (virDomainDefSetVcpusMax(def, count, xmlopt) < 0)
return -1;
}
@ -1051,7 +1053,8 @@ int
xenParseConfigCommon(virConfPtr conf,
virDomainDefPtr def,
virCapsPtr caps,
const char *nativeFormat)
const char *nativeFormat,
virDomainXMLOptionPtr xmlopt)
{
if (xenParseGeneralMeta(conf, def, caps) < 0)
return -1;
@ -1062,7 +1065,7 @@ xenParseConfigCommon(virConfPtr conf,
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)

View File

@ -59,7 +59,8 @@ int xenConfigCopyStringOpt(virConfPtr conf,
int xenParseConfigCommon(virConfPtr conf,
virDomainDefPtr def,
virCapsPtr caps,
const char *nativeFormat);
const char *nativeFormat,
virDomainXMLOptionPtr xmlopt);
int xenFormatConfigCommon(virConfPtr conf,
virDomainDefPtr def,

View File

@ -1233,7 +1233,7 @@ xenParseSxpr(const struct sexpr *root,
}
}
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"));

View File

@ -594,7 +594,8 @@ xenParseXL(virConfPtr conf,
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)

View File

@ -447,7 +447,8 @@ xenParseXM(virConfPtr conf,
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)