[libvirt] [PATCH 3/9] vz: factor out block stats impl

Nikolay Shirokovskiy nshirokovskiy at virtuozzo.com
Fri Jun 24 14:32:32 UTC 2016


Now we can use intended ACL check for both API calls.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy at virtuozzo.com>
---
 src/vz/vz_driver.c | 45 +++++++++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 14 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 8e39a5d..f7e1c07 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1518,27 +1518,21 @@ vzDomainGetMaxMemory(virDomainPtr domain)
 }
 
 static int
-vzDomainBlockStats(virDomainPtr domain, const char *path,
-                   virDomainBlockStatsPtr stats)
+vzDomainBlockStatsImpl(virDomainObjPtr dom,
+                       const char *path,
+                       virDomainBlockStatsPtr stats)
 {
-    virDomainObjPtr dom = NULL;
-    vzDomObjPtr privdom;
-    int ret = -1;
+    vzDomObjPtr privdom = dom->privateData;
     size_t i;
     int idx;
 
-    if (!(dom = vzDomObjFromDomainRef(domain)))
-        return -1;
-
-    privdom = dom->privateData;
-
     if (*path) {
         if ((idx = virDomainDiskIndexByName(dom->def, path, false)) < 0) {
             virReportError(VIR_ERR_INVALID_ARG, _("invalid path: %s"), path);
-            goto cleanup;
+            return -1;
         }
         if (prlsdkGetBlockStats(privdom->stats, dom->def->disks[idx], stats) < 0)
-            goto cleanup;
+            return -1;
     } else {
         virDomainBlockStatsStruct s;
 
@@ -1551,7 +1545,7 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
 
         for (i = 0; i < dom->def->ndisks; i++) {
             if (prlsdkGetBlockStats(privdom->stats, dom->def->disks[i], &s) < 0)
-                goto cleanup;
+                return -1;
 
 #define PARALLELS_SUM_STATS(VAR, TYPE, NAME)        \
     if (s.VAR != -1)                                \
@@ -1563,6 +1557,23 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
         }
     }
     stats->errs = -1;
+    return 0;
+}
+
+static int
+vzDomainBlockStats(virDomainPtr domain,
+                   const char *path,
+                   virDomainBlockStatsPtr stats)
+{
+    virDomainObjPtr dom;
+    int ret = -1;
+
+    if (!(dom = vzDomObjFromDomainRef(domain)))
+        return -1;
+
+    if (vzDomainBlockStatsImpl(dom, path, stats) < 0)
+        goto cleanup;
+
     ret = 0;
 
  cleanup:
@@ -1579,6 +1590,7 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
                         unsigned int flags)
 {
     virDomainBlockStatsStruct stats;
+    virDomainObjPtr dom;
     int ret = -1;
     size_t i;
 
@@ -1586,7 +1598,10 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
     /* We don't return strings, and thus trivially support this flag.  */
     flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
 
-    if (vzDomainBlockStats(domain, path, &stats) < 0)
+    if (!(dom = vzDomObjFromDomainRef(domain)))
+        return -1;
+
+    if (vzDomainBlockStatsImpl(dom, path, &stats) < 0)
         goto cleanup;
 
     if (*nparams == 0) {
@@ -1618,6 +1633,8 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
     ret = 0;
 
  cleanup:
+    virDomainObjEndAPI(&dom);
+
     return ret;
 }
 
-- 
1.8.3.1




More information about the libvir-list mailing list