提交 ee3da892 编写于 作者: P Peter Krempa

conf: Refactor emulatorpin handling

Store the emulator pinning cpu mask as a pure virBitmap rather than the
virDomainPinDef since it stores only the bitmap and refactor
qemuDomainPinEmulator to do the same operations in a much saner way.

As a side effect virDomainEmulatorPinAdd and virDomainEmulatorPinDel can
be removed since they don't add any value.
上级 ff4c42ed
......@@ -2474,7 +2474,7 @@ void virDomainDefFree(virDomainDefPtr def)
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);
......@@ -13569,36 +13569,26 @@ virDomainIOThreadPinDefParseXML(xmlNodePtr node,
}
/* 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;
}
......@@ -17768,50 +17758,6 @@ virDomainPinDel(virDomainPinDefPtr **pindef_list,
}
}
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,
......@@ -21105,7 +21051,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
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);
......
......@@ -2069,7 +2069,7 @@ struct _virDomainCputune {
long long emulator_quota;
size_t nvcpupin;
virDomainPinDefPtr *vcpupin;
virDomainPinDefPtr emulatorpin;
virBitmapPtr emulatorpin;
size_t nvcpusched;
virDomainThreadSchedParamPtr vcpusched;
......@@ -2674,12 +2674,6 @@ void virDomainPinDel(virDomainPinDefPtr **pindef_list,
size_t *npin,
int vcpu);
int virDomainEmulatorPinAdd(virDomainDefPtr def,
unsigned char *cpumap,
int maplen);
int virDomainEmulatorPinDel(virDomainDefPtr def);
void virDomainRNGDefFree(virDomainRNGDefPtr def);
bool virDomainDiskDefDstDuplicates(virDomainDefPtr def);
......
......@@ -273,8 +273,6 @@ virDomainDiskSetFormat;
virDomainDiskSetSource;
virDomainDiskSetType;
virDomainDiskSourceIsBlockType;
virDomainEmulatorPinAdd;
virDomainEmulatorPinDel;
virDomainFSDefFree;
virDomainFSIndexByName;
virDomainFSInsert;
......
......@@ -1114,7 +1114,7 @@ qemuSetupCgroupForEmulator(virDomainObjPtr vm)
goto cleanup;
if (def->cputune.emulatorpin)
cpumask = def->cputune.emulatorpin->cpumask;
cpumask = def->cputune.emulatorpin;
else if (def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO)
cpumask = priv->autoCpuset;
else if (def->cpumask)
......
......@@ -5374,23 +5374,19 @@ qemuDomainPinEmulator(virDomainPtr dom,
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);
......@@ -5436,65 +5432,33 @@ qemuDomainPinEmulator(virDomainPtr dom,
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;
......@@ -5510,22 +5474,12 @@ qemuDomainPinEmulator(virDomainPtr dom,
}
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;
......@@ -5592,7 +5546,7 @@ qemuDomainGetEmulatorPinInfo(virDomainPtr dom,
goto cleanup;
if (targetDef->cputune.emulatorpin) {
cpumask = targetDef->cputune.emulatorpin->cpumask;
cpumask = targetDef->cputune.emulatorpin;
} else if (targetDef->cpumask) {
cpumask = targetDef->cpumask;
} else {
......
......@@ -2414,7 +2414,7 @@ qemuProcessSetEmulatorAffinity(virDomainObjPtr vm)
int ret = -1;
if (def->cputune.emulatorpin)
cpumask = def->cputune.emulatorpin->cpumask;
cpumask = def->cputune.emulatorpin;
else if (def->cpumask)
cpumask = def->cpumask;
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册