[PATCH v6 4/5] qemu: split qemuDomainMemoryStats into internal and external functions

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

 



From: Derbyshev Dmitry <dderbyshev@xxxxxxxxxxxxx>

Is necessary to call it from other contexts, such as qemuDomainGetStatsBalloon.

Signed-off-by: Derbyshev Dmitry <dderbyshev@xxxxxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 55 ++++++++++++++++++++++++++++++++------------------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2089359..0b76177 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10957,32 +10957,22 @@ qemuDomainGetInterfaceParameters(virDomainPtr dom,
     return ret;
 }
 
+/* This functions assumes that job QEMU_JOB_QUERY is started by a caller */
+
 static int
-qemuDomainMemoryStats(virDomainPtr dom,
-                      virDomainMemoryStatPtr stats,
-                      unsigned int nr_stats,
-                      unsigned int flags)
+qemuDomainMemoryStatsInternal(virQEMUDriverPtr driver,
+                              virDomainObjPtr vm,
+                              virDomainMemoryStatPtr stats,
+                              unsigned int nr_stats)
+
 {
-    virQEMUDriverPtr driver = dom->conn->privateData;
-    virDomainObjPtr vm;
     int ret = -1;
     long rss;
 
-    virCheckFlags(0, -1);
-
-    if (!(vm = qemuDomObjFromDomain(dom)))
-        goto cleanup;
-
-    if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
-        goto cleanup;
-
-    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
-        goto cleanup;
-
     if (!virDomainObjIsActive(vm)) {
         virReportError(VIR_ERR_OPERATION_INVALID,
                        "%s", _("domain is not running"));
-        goto endjob;
+        return -1;
     }
 
     if (vm->def->memballoon &&
@@ -10993,7 +10983,7 @@ qemuDomainMemoryStats(virDomainPtr dom,
             ret = -1;
 
         if (ret < 0 || ret >= nr_stats)
-            goto endjob;
+            return ret;
     } else {
         ret = 0;
     }
@@ -11007,7 +10997,32 @@ qemuDomainMemoryStats(virDomainPtr dom,
         ret++;
     }
 
- endjob:
+    return ret;
+}
+
+static int
+qemuDomainMemoryStats(virDomainPtr dom,
+                      virDomainMemoryStatPtr stats,
+                      unsigned int nr_stats,
+                      unsigned int flags)
+{
+    virQEMUDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = qemuDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainMemoryStatsEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+        goto cleanup;
+
+    ret = qemuDomainMemoryStatsInternal(driver, vm, stats, nr_stats);
+
     qemuDomainObjEndJob(driver, vm);
 
  cleanup:
-- 
1.9.5.msysgit.0

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