提交 dbf990fd 编写于 作者: P Peter Krempa

qemu: monitor: Split out code to gather data from 'query-block'

Extract the code for future reuse.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 8d9ca6cd
...@@ -2447,39 +2447,50 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon, ...@@ -2447,39 +2447,50 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
static int static int
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image, qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr image,
const char *dev_name, const char *name,
int depth, virHashTablePtr stats)
virHashTablePtr stats,
bool backingChain)
{ {
qemuBlockStatsPtr bstats; qemuBlockStatsPtr bstats;
int ret = -1;
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
virJSONValuePtr backing;
if (!(bstats = virHashLookup(stats, entry_name))) { if (!(bstats = virHashLookup(stats, name))) {
if (VIR_ALLOC(bstats) < 0) if (VIR_ALLOC(bstats) < 0)
goto cleanup; return -1;
if (virHashAddEntry(stats, entry_name, bstats) < 0) { if (virHashAddEntry(stats, name, bstats) < 0) {
VIR_FREE(bstats); VIR_FREE(bstats);
goto cleanup; return -1;
} }
} }
/* After this point, we ignore failures; the stats were /* failures can be ignored after this point */
* zero-initialized when created which is a sane fallback. */
ret = 0;
if (virJSONValueObjectGetNumberUlong(image, "virtual-size", if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
&bstats->capacity) < 0) &bstats->capacity) < 0)
goto cleanup; return 0;
/* if actual-size is missing, image is not thin provisioned */ /* if actual-size is missing, image is not thin provisioned */
if (virJSONValueObjectGetNumberUlong(image, "actual-size", if (virJSONValueObjectGetNumberUlong(image, "actual-size",
&bstats->physical) < 0) &bstats->physical) < 0)
bstats->physical = bstats->capacity; bstats->physical = bstats->capacity;
return 0;
}
static int
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
const char *dev_name,
int depth,
virHashTablePtr stats,
bool backingChain)
{
int ret = -1;
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
virJSONValuePtr backing;
if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, entry_name, stats) < 0)
goto cleanup;
if (backingChain && if (backingChain &&
(backing = virJSONValueObjectGetObject(image, "backing-image"))) { (backing = virJSONValueObjectGetObject(image, "backing-image"))) {
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing, ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册