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.
This commit is contained in:
Peter Krempa 2015-03-10 10:02:40 +01:00
parent 32288fc9b9
commit 4f6b6788c4
3 changed files with 18 additions and 11 deletions

View File

@ -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;
} }

View File

@ -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,
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,
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,
} }
*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;

View File

@ -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,