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

qemu: Add helper to retrieve vCPU pid

Instead of directly accessing the array add a helper to do this.
上级 220a2d51
...@@ -1043,7 +1043,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm) ...@@ -1043,7 +1043,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
goto cleanup; goto cleanup;
/* move the thread for vcpu to sub dir */ /* move the thread for vcpu to sub dir */
if (virCgroupAddTask(cgroup_vcpu, priv->vcpupids[i]) < 0) if (virCgroupAddTask(cgroup_vcpu,
qemuDomainGetVcpuPid(vm, i)) < 0)
goto cleanup; goto cleanup;
if (period || quota) { if (period || quota) {
......
...@@ -4131,3 +4131,23 @@ qemuDomainHasVcpuPids(virDomainObjPtr vm) ...@@ -4131,3 +4131,23 @@ qemuDomainHasVcpuPids(virDomainObjPtr vm)
return priv->nvcpupids > 0; return priv->nvcpupids > 0;
} }
/**
* qemuDomainGetVcpuPid:
* @vm: domain object
* @vcpu: cpu id
*
* Returns the vCPU pid. If @vcpu is offline or out of range 0 is returned.
*/
pid_t
qemuDomainGetVcpuPid(virDomainObjPtr vm,
unsigned int vcpu)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
if (vcpu >= priv->nvcpupids)
return 0;
return priv->vcpupids[vcpu];
}
...@@ -506,5 +506,6 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def, ...@@ -506,5 +506,6 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
const virDomainMemoryDef *mem); const virDomainMemoryDef *mem);
bool qemuDomainHasVcpuPids(virDomainObjPtr vm); bool qemuDomainHasVcpuPids(virDomainObjPtr vm);
pid_t qemuDomainGetVcpuPid(virDomainObjPtr vm, unsigned int vcpu);
#endif /* __QEMU_DOMAIN_H__ */ #endif /* __QEMU_DOMAIN_H__ */
...@@ -1449,7 +1449,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, ...@@ -1449,7 +1449,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
&(info[i].cpu), &(info[i].cpu),
NULL, NULL,
vm->pid, vm->pid,
priv->vcpupids[i]) < 0) { qemuDomainGetVcpuPid(vm, i)) < 0) {
virReportSystemError(errno, "%s", virReportSystemError(errno, "%s",
_("cannot get vCPU placement & pCPU time")); _("cannot get vCPU placement & pCPU time"));
return -1; return -1;
...@@ -1462,7 +1462,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo, ...@@ -1462,7 +1462,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v); unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
virBitmapPtr map = NULL; virBitmapPtr map = NULL;
if (!(map = virProcessGetAffinity(priv->vcpupids[v]))) if (!(map = virProcessGetAffinity(qemuDomainGetVcpuPid(vm, v))))
return -1; return -1;
virBitmapToDataBuf(map, cpumap, maplen); virBitmapToDataBuf(map, cpumap, maplen);
...@@ -5156,7 +5156,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom, ...@@ -5156,7 +5156,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
goto endjob; goto endjob;
} }
} else { } else {
if (virProcessSetAffinity(priv->vcpupids[vcpu], pcpumap) < 0) { if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, vcpu),
pcpumap) < 0) {
virReportError(VIR_ERR_SYSTEM_ERROR, virReportError(VIR_ERR_SYSTEM_ERROR,
_("failed to set cpu affinity for vcpu %d"), _("failed to set cpu affinity for vcpu %d"),
vcpu); vcpu);
......
...@@ -2234,7 +2234,6 @@ qemuProcessSetLinkStates(virQEMUDriverPtr driver, ...@@ -2234,7 +2234,6 @@ qemuProcessSetLinkStates(virQEMUDriverPtr driver,
static int static int
qemuProcessSetVcpuAffinities(virDomainObjPtr vm) qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr def = vm->def; virDomainDefPtr def = vm->def;
virDomainPinDefPtr pininfo; virDomainPinDefPtr pininfo;
int n; int n;
...@@ -2267,7 +2266,7 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm) ...@@ -2267,7 +2266,7 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
n))) n)))
continue; continue;
if (virProcessSetAffinity(priv->vcpupids[n], if (virProcessSetAffinity(qemuDomainGetVcpuPid(vm, n),
pininfo->cpumask) < 0) { pininfo->cpumask) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -2355,7 +2354,7 @@ qemuProcessSetSchedulers(virDomainObjPtr vm) ...@@ -2355,7 +2354,7 @@ qemuProcessSetSchedulers(virDomainObjPtr vm)
size_t i = 0; size_t i = 0;
for (i = 0; i < priv->nvcpupids; i++) { for (i = 0; i < priv->nvcpupids; i++) {
if (qemuProcessSetSchedParams(i, priv->vcpupids[i], if (qemuProcessSetSchedParams(i, qemuDomainGetVcpuPid(vm, i),
vm->def->cputune.nvcpusched, vm->def->cputune.nvcpusched,
vm->def->cputune.vcpusched) < 0) vm->def->cputune.vcpusched) < 0)
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册