[PATCH 32/34] qemu: Add helper to retrieve vCPU pid

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Instead of directly accessing the array add a helper to do this.
---
 src/qemu/qemu_cgroup.c  |  3 ++-
 src/qemu/qemu_domain.c  | 20 ++++++++++++++++++++
 src/qemu/qemu_domain.h  |  1 +
 src/qemu/qemu_driver.c  |  7 ++++---
 src/qemu/qemu_process.c |  5 ++---
 5 files changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 56c2e90..d8a2b03 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -1023,7 +1023,8 @@ qemuSetupCgroupForVcpu(virDomainObjPtr vm)
             goto cleanup;

         /* 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;

         if (period || quota) {
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 8a45825..be1f2b4 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -3971,3 +3971,23 @@ qemuDomainHasVCpuPids(virDomainObjPtr vm)

     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];
+}
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 7f2eca1..c1aad61 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -492,5 +492,6 @@ int qemuDomainDefValidateMemoryHotplug(const virDomainDef *def,
                                        const virDomainMemoryDef *mem);

 bool qemuDomainHasVCpuPids(virDomainObjPtr vm);
+pid_t qemuDomainGetVCpuPid(virDomainObjPtr vm, unsigned int vcpu);

 #endif /* __QEMU_DOMAIN_H__ */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4b7452c..c659328 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1449,7 +1449,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
                                        &(info[i].cpu),
                                        NULL,
                                        vm->pid,
-                                       priv->vcpupids[i]) < 0) {
+                                       qemuDomainGetVCpuPid(vm, i)) < 0) {
                     virReportSystemError(errno, "%s",
                                          _("cannot get vCPU placement & pCPU time"));
                     return -1;
@@ -1462,7 +1462,7 @@ qemuDomainHelperGetVcpus(virDomainObjPtr vm, virVcpuInfoPtr info, int maxinfo,
                 unsigned char *cpumap = VIR_GET_CPUMAP(cpumaps, maplen, v);
                 virBitmapPtr map = NULL;

-                if (!(map = virProcessGetAffinity(priv->vcpupids[v])))
+                if (!(map = virProcessGetAffinity(qemuDomainGetVCpuPid(vm, v))))
                     return -1;

                 virBitmapToDataBuf(map, cpumap, maplen);
@@ -5156,7 +5156,8 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
                 goto endjob;
             }
         } else {
-            if (virProcessSetAffinity(priv->vcpupids[vcpu], pcpumap) < 0) {
+            if (virProcessSetAffinity(qemuDomainGetVCpuPid(vm, vcpu),
+                                      pcpumap) < 0) {
                 virReportError(VIR_ERR_SYSTEM_ERROR,
                                _("failed to set cpu affinity for vcpu %d"),
                                vcpu);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d7f45b3..4a2cc66 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2286,7 +2286,6 @@ qemuProcessSetLinkStates(virQEMUDriverPtr driver,
 static int
 qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
 {
-    qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDefPtr def = vm->def;
     virDomainPinDefPtr pininfo;
     int n;
@@ -2319,7 +2318,7 @@ qemuProcessSetVcpuAffinities(virDomainObjPtr vm)
                                          n)))
             continue;

-        if (virProcessSetAffinity(priv->vcpupids[n],
+        if (virProcessSetAffinity(qemuDomainGetVCpuPid(vm, n),
                                   pininfo->cpumask) < 0) {
             goto cleanup;
         }
@@ -2407,7 +2406,7 @@ qemuProcessSetSchedulers(virDomainObjPtr vm)
     size_t i = 0;

     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.vcpusched) < 0)
             return -1;
-- 
2.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]