]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: blockstats: Switch to caller allocated hash table
authorPeter Krempa <pkrempa@redhat.com>
Tue, 10 Mar 2015 09:02:40 +0000 (10:02 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 11 Mar 2015 10:28:03 +0000 (11:28 +0100)
Allocate the hash table in the monitor wrapper function instead of the
worker itself so that the text monitor impl that will be added in the
next patch doesn't have to duplicate it.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h

index 24e87b783c244e255892c2521b1a82a17a7bf32f..95a6989bf0969a0e08d49904b4d712ecefe4b10f 100644 (file)
@@ -1864,7 +1864,18 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
         return -1;
     }
 
-    return qemuMonitorJSONGetAllBlockStatsInfo(mon, ret_stats, backingChain);
+    if (!(*ret_stats = virHashCreate(10, virHashValueFree)))
+        goto error;
+
+    if (qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats, backingChain) < 0)
+        goto error;
+
+    return 0;
+
+ error:
+    virHashFree(*ret_stats);
+    *ret_stats = NULL;
+    return -1;
 }
 
 
index 612553b00798e441ac0a5eb857e4ce3849e04324..c88c7c3e2735ba400711ff52b6c6c1548dfaa06a 100644 (file)
@@ -1695,7 +1695,10 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
     if (flush_total_times)
         *flush_total_times = -1;
 
-    if (qemuMonitorJSONGetAllBlockStatsInfo(mon, &blockstats, false) < 0)
+    if (!(blockstats = virHashCreate(10, virHashValueFree)))
+        goto cleanup;
+
+    if (qemuMonitorJSONGetAllBlockStatsInfo(mon, blockstats, false) < 0)
         goto cleanup;
 
     if (!(stats = virHashLookup(blockstats, dev_name))) {
@@ -1870,7 +1873,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
 
 int
 qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
-                                    virHashTablePtr *ret_stats,
+                                    virHashTablePtr hash,
                                     bool backingChain)
 {
     int ret = -1;
@@ -1879,14 +1882,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
     virJSONValuePtr devices;
-    virHashTablePtr hash = NULL;
 
     if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL)))
         return -1;
 
-    if (!(hash = virHashCreate(10, virHashValueFree)))
-        goto cleanup;
-
     if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
         goto cleanup;
 
@@ -1924,12 +1923,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
 
     }
 
-    *ret_stats = hash;
-    hash = NULL;
     ret = 0;
 
  cleanup:
-    virHashFree(hash);
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;
index 23589cf4f1daad148d13d4470ecfb6a13186dae3..0fcb0c0f0d7e48d75dc7ca98a2a1ce7fc49e1979 100644 (file)
@@ -82,7 +82,7 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
                                      long long *flush_req,
                                      long long *flush_total_times);
 int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
-                                        virHashTablePtr *ret_stats,
+                                        virHashTablePtr hash,
                                         bool backingChain);
 int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
                                             virHashTablePtr stats,