mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
qemu: monitor: Split out code to gather data from 'query-block'
Extract the code for future reuse. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8d9ca6cdb3
commit
dbf990fd31
@ -2446,6 +2446,37 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuMonitorJSONBlockStatsUpdateCapacityData(virJSONValuePtr image,
|
||||
const char *name,
|
||||
virHashTablePtr stats)
|
||||
{
|
||||
qemuBlockStatsPtr bstats;
|
||||
|
||||
if (!(bstats = virHashLookup(stats, name))) {
|
||||
if (VIR_ALLOC(bstats) < 0)
|
||||
return -1;
|
||||
|
||||
if (virHashAddEntry(stats, name, bstats) < 0) {
|
||||
VIR_FREE(bstats);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* failures can be ignored after this point */
|
||||
if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
|
||||
&bstats->capacity) < 0)
|
||||
return 0;
|
||||
|
||||
/* if actual-size is missing, image is not thin provisioned */
|
||||
if (virJSONValueObjectGetNumberUlong(image, "actual-size",
|
||||
&bstats->physical) < 0)
|
||||
bstats->physical = bstats->capacity;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
||||
const char *dev_name,
|
||||
@ -2453,33 +2484,13 @@ qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
||||
virHashTablePtr stats,
|
||||
bool backingChain)
|
||||
{
|
||||
qemuBlockStatsPtr bstats;
|
||||
int ret = -1;
|
||||
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
||||
virJSONValuePtr backing;
|
||||
|
||||
if (!(bstats = virHashLookup(stats, entry_name))) {
|
||||
if (VIR_ALLOC(bstats) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virHashAddEntry(stats, entry_name, bstats) < 0) {
|
||||
VIR_FREE(bstats);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
/* After this point, we ignore failures; the stats were
|
||||
* zero-initialized when created which is a sane fallback. */
|
||||
ret = 0;
|
||||
if (virJSONValueObjectGetNumberUlong(image, "virtual-size",
|
||||
&bstats->capacity) < 0)
|
||||
if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, entry_name, stats) < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* if actual-size is missing, image is not thin provisioned */
|
||||
if (virJSONValueObjectGetNumberUlong(image, "actual-size",
|
||||
&bstats->physical) < 0)
|
||||
bstats->physical = bstats->capacity;
|
||||
|
||||
if (backingChain &&
|
||||
(backing = virJSONValueObjectGetObject(image, "backing-image"))) {
|
||||
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
|
||||
|
Loading…
Reference in New Issue
Block a user