virDomainPinDefArrayFree(def->cputune.vcpupin, def->cputune.nvcpupin);
- virDomainPinDefFree(def->cputune.emulatorpin);
+ virBitmapFree(def->cputune.emulatorpin);
for (i = 0; i < def->cputune.nvcpusched; i++)
virBitmapFree(def->cputune.vcpusched[i].ids);
}
-
/* Parse the XML definition for emulatorpin.
* emulatorpin has the form of
* <emulatorpin cpuset='0'/>
*/
-static virDomainPinDefPtr
+static virBitmapPtr
virDomainEmulatorPinDefParseXML(xmlNodePtr node)
{
- virDomainPinDefPtr def;
+ virBitmapPtr def = NULL;
char *tmp = NULL;
- if (VIR_ALLOC(def) < 0)
- return NULL;
-
if (!(tmp = virXMLPropString(node, "cpuset"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("missing cpuset for emulatorpin"));
- goto error;
+ return NULL;
}
- if (virBitmapParse(tmp, 0, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
- goto error;
+ ignore_value(virBitmapParse(tmp, 0, &def, VIR_DOMAIN_CPUMASK_LEN));
VIR_FREE(tmp);
return def;
-
- error:
- VIR_FREE(tmp);
- VIR_FREE(def);
- return NULL;
}
}
}
-int
-virDomainEmulatorPinAdd(virDomainDefPtr def,
- unsigned char *cpumap,
- int maplen)
-{
- virDomainPinDefPtr emulatorpin = NULL;
-
- if (!def->cputune.emulatorpin) {
- /* No emulatorpin exists yet. */
- if (VIR_ALLOC(emulatorpin) < 0)
- return -1;
-
- emulatorpin->id = -1;
- emulatorpin->cpumask = virBitmapNewData(cpumap, maplen);
- if (!emulatorpin->cpumask) {
- virDomainPinDefFree(emulatorpin);
- return -1;
- }
-
- def->cputune.emulatorpin = emulatorpin;
- } else {
- /* Since there is only 1 emulatorpin for each vm,
- * juest replace the old one.
- */
- virBitmapFree(def->cputune.emulatorpin->cpumask);
- def->cputune.emulatorpin->cpumask = virBitmapNewData(cpumap, maplen);
- if (!def->cputune.emulatorpin->cpumask)
- return -1;
- }
-
- return 0;
-}
-
-int
-virDomainEmulatorPinDel(virDomainDefPtr def)
-{
- if (!def->cputune.emulatorpin)
- return 0;
-
- virDomainPinDefFree(def->cputune.emulatorpin);
- def->cputune.emulatorpin = NULL;
-
- return 0;
-}
static int
virDomainEventActionDefFormat(virBufferPtr buf,
char *cpumask;
virBufferAddLit(buf, "<emulatorpin ");
- if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin->cpumask)))
+ if (!(cpumask = virBitmapFormat(def->cputune.emulatorpin)))
goto error;
virBufferAsprintf(buf, "cpuset='%s'/>\n", cpumask);
virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm;
virCgroupPtr cgroup_emulator = NULL;
- pid_t pid;
virDomainDefPtr persistentDef = NULL;
int ret = -1;
qemuDomainObjPrivatePtr priv;
bool doReset = false;
- size_t newVcpuPinNum = 0;
- virDomainPinDefPtr *newVcpuPin = NULL;
virBitmapPtr pcpumap = NULL;
virQEMUDriverConfigPtr cfg = NULL;
virCapsPtr caps = NULL;
virObjectEventPtr event = NULL;
- char * str = NULL;
+ char *str = NULL;
virTypedParameterPtr eventParams = NULL;
int eventNparams = 0;
int eventMaxparams = 0;
-
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
if (virBitmapIsAllSet(pcpumap))
doReset = true;
- pid = vm->pid;
-
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
-
- if (priv->vcpupids != NULL) {
- if (VIR_ALLOC(newVcpuPin) < 0)
+ if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
+ if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR,
+ 0, false, &cgroup_emulator) < 0)
goto endjob;
- if (virDomainPinAdd(&newVcpuPin, &newVcpuPinNum, cpumap, maplen, -1) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to update vcpupin"));
- virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum);
+ if (qemuSetupCgroupCpusetCpus(cgroup_emulator, pcpumap) < 0) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("failed to set cpuset.cpus in cgroup"
+ " for emulator threads"));
goto endjob;
}
-
- if (virCgroupHasController(priv->cgroup,
- VIR_CGROUP_CONTROLLER_CPUSET)) {
- /*
- * Configure the corresponding cpuset cgroup.
- */
- if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR,
- 0, false, &cgroup_emulator) < 0)
- goto endjob;
- if (qemuSetupCgroupCpusetCpus(cgroup_emulator,
- newVcpuPin[0]->cpumask) < 0) {
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("failed to set cpuset.cpus in cgroup"
- " for emulator threads"));
- goto endjob;
- }
- } else {
- if (virProcessSetAffinity(pid, pcpumap) < 0) {
- virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
- _("failed to set cpu affinity for "
- "emulator threads"));
- goto endjob;
- }
+ } else {
+ if (virProcessSetAffinity(vm->pid, pcpumap) < 0) {
+ virReportError(VIR_ERR_SYSTEM_ERROR, "%s",
+ _("failed to set cpu affinity for "
+ "emulator thread"));
+ goto endjob;
}
+ }
- if (doReset) {
- if (virDomainEmulatorPinDel(vm->def) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to delete emulatorpin xml of "
- "a running domain"));
- goto endjob;
- }
- } else {
- virDomainPinDefFree(vm->def->cputune.emulatorpin);
- vm->def->cputune.emulatorpin = newVcpuPin[0];
- VIR_FREE(newVcpuPin);
- }
+ virBitmapFree(vm->def->cputune.emulatorpin);
+ vm->def->cputune.emulatorpin = NULL;
- if (newVcpuPin)
- virDomainPinDefArrayFree(newVcpuPin, newVcpuPinNum);
- } else {
- virReportError(VIR_ERR_OPERATION_INVALID,
- "%s", _("cpu affinity is not supported"));
+ if (!doReset &&
+ !(vm->def->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
goto endjob;
- }
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
goto endjob;
}
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ virBitmapFree(persistentDef->cputune.emulatorpin);
+ persistentDef->cputune.emulatorpin = NULL;
- if (doReset) {
- if (virDomainEmulatorPinDel(persistentDef) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to delete emulatorpin xml of "
- "a persistent domain"));
- goto endjob;
- }
- } else {
- if (virDomainEmulatorPinAdd(persistentDef, cpumap, maplen) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to update or add emulatorpin xml "
- "of a persistent domain"));
- goto endjob;
- }
- }
+ if (!doReset &&
+ !(persistentDef->cputune.emulatorpin = virBitmapNewCopy(pcpumap)))
+ goto endjob;
ret = virDomainSaveConfig(cfg->configDir, persistentDef);
goto endjob;
goto cleanup;
if (targetDef->cputune.emulatorpin) {
- cpumask = targetDef->cputune.emulatorpin->cpumask;
+ cpumask = targetDef->cputune.emulatorpin;
} else if (targetDef->cpumask) {
cpumask = targetDef->cpumask;
} else {