[PATCH 04/10] vz: move getting stats in vzDomainGetInfo to the end

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

 



As a preparation to get statistics without domain lock. Let's
take all we want from domain cache first. After this point
domain lock can be dropped.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/vz/vz_driver.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 62d5047..810017c 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -601,6 +601,8 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
 {
     virDomainObjPtr privdom;
     int ret = -1;
+    size_t i;
+    unsigned int nvcpus;
 
     if (!(privdom = vzDomObjFromDomainRef(domain)))
         goto cleanup;
@@ -611,18 +613,22 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
     info->nrVirtCpu = virDomainDefGetVcpus(privdom->def);
     info->cpuTime = 0;
 
-    if (virDomainObjIsActive(privdom)) {
+    if (!virDomainObjIsActive(privdom)) {
+        ret = 0;
+        goto cleanup;
+    }
+
+    nvcpus = virDomainDefGetVcpus(privdom->def);
+
+    for (i = 0; i < nvcpus; ++i) {
         unsigned long long vtime;
-        size_t i;
 
-        for (i = 0; i < virDomainDefGetVcpus(privdom->def); ++i) {
-            if (prlsdkGetVcpuStats(privdom, i, &vtime) < 0) {
-                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                               _("cannot read cputime for domain"));
-                goto cleanup;
-            }
-            info->cpuTime += vtime;
+        if (prlsdkGetVcpuStats(privdom, i, &vtime) < 0) {
+            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                           _("cannot read cputime for domain"));
+            goto cleanup;
         }
+        info->cpuTime += vtime;
     }
     ret = 0;
 
-- 
1.8.3.1

--
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]