[PATCH 01/10] vz: pass string instead of disk definition to block stat function

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

 



As a preparation to get statistics without domain lock. Without
this lock we can't use disk definition.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/vz/vz_driver.c | 15 +++++++++++++--
 src/vz/vz_sdk.c    | 21 ++++++++++++++++-----
 src/vz/vz_sdk.h    |  3 ++-
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 177a57a..725076f 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1274,6 +1274,7 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
     int ret = -1;
     size_t i;
     int idx;
+    char *disk = NULL;
 
     if (!(dom = vzDomObjFromDomainRef(domain)))
         return -1;
@@ -1283,7 +1284,11 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
             virReportError(VIR_ERR_INVALID_ARG, _("invalid path: %s"), path);
             goto cleanup;
         }
-        if (prlsdkGetBlockStats(dom, dom->def->disks[idx], stats) < 0)
+
+        if (!(disk = prlsdkGetDiskStatName(dom->def->disks[idx])))
+            goto cleanup;
+
+        if (prlsdkGetBlockStats(dom, disk, stats) < 0)
             goto cleanup;
     } else {
         virDomainBlockStatsStruct s;
@@ -1296,7 +1301,10 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
 #undef PARALLELS_ZERO_STATS
 
         for (i = 0; i < dom->def->ndisks; i++) {
-            if (prlsdkGetBlockStats(dom, dom->def->disks[i], &s) < 0)
+            if (!(disk = prlsdkGetDiskStatName(dom->def->disks[i])))
+                goto cleanup;
+
+            if (prlsdkGetBlockStats(dom, disk, &s) < 0)
                 goto cleanup;
 
 #define PARALLELS_SUM_STATS(VAR, TYPE, NAME)        \
@@ -1306,6 +1314,8 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
         PARALLELS_BLOCK_STATS_FOREACH(PARALLELS_SUM_STATS)
 
 #undef PARALLELS_SUM_STATS
+
+            VIR_FREE(disk);
         }
     }
     stats->errs = -1;
@@ -1314,6 +1324,7 @@ vzDomainBlockStats(virDomainPtr domain, const char *path,
  cleanup:
     if (dom)
         virDomainObjEndAPI(&dom);
+    VIR_FREE(disk);
 
     return ret;
 }
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 6c05698..b7627e7 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -4075,13 +4075,11 @@ prlsdkGetStatsParam(virDomainObjPtr dom, const char *name, long long *val)
     return -1;
 }
 
-int
-prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats)
+char* prlsdkGetDiskStatName(virDomainDiskDefPtr disk)
 {
     virDomainDeviceDriveAddressPtr address;
     int idx;
     const char *prefix;
-    int ret = -1;
     char *name = NULL;
 
     address = &disk->info.addr.drive;
@@ -4101,12 +4099,25 @@ prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBloc
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Unknown disk bus: %X"), disk->bus);
-        goto cleanup;
+        return NULL;
     }
 
+    if (virAsprintf(&name, "%s%d", prefix, idx) < 0)
+        return NULL;
+
+    return name;
+}
+
+int
+prlsdkGetBlockStats(virDomainObjPtr dom,
+                    const char *disk,
+                    virDomainBlockStatsPtr stats)
+{
+    int ret = -1;
+    char *name = NULL;
 
 #define PRLSDK_GET_STAT_PARAM(VAL, TYPE, NAME)                          \
-    if (virAsprintf(&name, "devices.%s%d.%s", prefix, idx, NAME) < 0)   \
+    if (virAsprintf(&name, "devices.%s.%s", disk, NAME) < 0)            \
         goto cleanup;                                                   \
     if (prlsdkGetStatsParam(dom, name, &stats->VAL) < 0)                \
         goto cleanup;                                                   \
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index f570560..033a3fe 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -66,8 +66,9 @@ int
 prlsdkAttachVolume(vzDriverPtr driver, virDomainObjPtr dom, virDomainDiskDefPtr disk);
 int
 prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk);
+char* prlsdkGetDiskStatName(virDomainDiskDefPtr disk);
 int
-prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats);
+prlsdkGetBlockStats(virDomainObjPtr dom, const char *disk, virDomainBlockStatsPtr stats);
 int
 prlsdkAttachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
 int
-- 
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]