Re: [PATCH] vz: support cpu time in driver's domainGetInfo

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

 



On 10/30/2015 09:16 AM, Maxim Nestratov wrote:
28.10.2015 17:29, Nikolay Shirokovskiy пишет:
Just straight-forward patch.
Use reference counting for privdom as stats internally could drop domain lock.


OK, I've checked, it works, and patch look good, ACKed and pushed.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
  src/vz/vz_driver.c |   19 ++++++++++++++++---
  1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 6f1cbfb..0a968b9 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -554,7 +554,7 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
      virDomainObjPtr privdom;
      int ret = -1;
  -    if (!(privdom = vzDomObjFromDomain(domain)))
+    if (!(privdom = vzDomObjFromDomainRef(domain)))
          goto cleanup;
        info->state = virDomainObjGetState(privdom, NULL);
@@ -562,11 +562,24 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
      info->maxMem = virDomainDefGetMemoryActual(privdom->def);
      info->nrVirtCpu = privdom->def->vcpus;
      info->cpuTime = 0;
+
+    if (virDomainObjIsActive(privdom)) {
+        unsigned long long vtime;
+        size_t i;
+
+        for (i = 0; i < privdom->def->vcpus; ++i) {
+            if (prlsdkGetVcpuStats(privdom, i, &vtime) < 0) {
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                               _("cannot read cputime for domain"));
+                goto cleanup;
+            }
+            info->cpuTime += vtime;
+        }
+    }
      ret = 0;
     cleanup:
-    if (privdom)
-        virObjectUnlock(privdom);
+    virDomainObjEndAPI(&privdom);
      return ret;
  }

ACK. Looks good.


--
Dmitry Guryanov

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