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 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)
*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;

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