提交 4f6b6788 编写于 作者: P Peter Krempa

qemu: blockstats: Switch to caller allocated hash table

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.
上级 32288fc9
...@@ -1864,7 +1864,18 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon, ...@@ -1864,7 +1864,18 @@ qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
return -1; 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;
} }
......
...@@ -1695,7 +1695,10 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, ...@@ -1695,7 +1695,10 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
if (flush_total_times) if (flush_total_times)
*flush_total_times = -1; *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; goto cleanup;
if (!(stats = virHashLookup(blockstats, dev_name))) { if (!(stats = virHashLookup(blockstats, dev_name))) {
...@@ -1870,7 +1873,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev, ...@@ -1870,7 +1873,7 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
int int
qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virHashTablePtr *ret_stats, virHashTablePtr hash,
bool backingChain) bool backingChain)
{ {
int ret = -1; int ret = -1;
...@@ -1879,14 +1882,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, ...@@ -1879,14 +1882,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virJSONValuePtr cmd; virJSONValuePtr cmd;
virJSONValuePtr reply = NULL; virJSONValuePtr reply = NULL;
virJSONValuePtr devices; virJSONValuePtr devices;
virHashTablePtr hash = NULL;
if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL))) if (!(cmd = qemuMonitorJSONMakeCommand("query-blockstats", NULL)))
return -1; return -1;
if (!(hash = virHashCreate(10, virHashValueFree)))
goto cleanup;
if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0) if ((rc = qemuMonitorJSONCommand(mon, cmd, &reply)) < 0)
goto cleanup; goto cleanup;
...@@ -1924,12 +1923,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, ...@@ -1924,12 +1923,9 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
} }
*ret_stats = hash;
hash = NULL;
ret = 0; ret = 0;
cleanup: cleanup:
virHashFree(hash);
virJSONValueFree(cmd); virJSONValueFree(cmd);
virJSONValueFree(reply); virJSONValueFree(reply);
return ret; return ret;
......
...@@ -82,7 +82,7 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon, ...@@ -82,7 +82,7 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
long long *flush_req, long long *flush_req,
long long *flush_total_times); long long *flush_total_times);
int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virHashTablePtr *ret_stats, virHashTablePtr hash,
bool backingChain); bool backingChain);
int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon, int qemuMonitorJSONBlockStatsUpdateCapacity(qemuMonitorPtr mon,
virHashTablePtr stats, virHashTablePtr stats,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册