mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06: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
|
static int
|
||||||
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
||||||
const char *dev_name,
|
const char *dev_name,
|
||||||
@ -2453,33 +2484,13 @@ qemuMonitorJSONBlockStatsUpdateCapacityOne(virJSONValuePtr image,
|
|||||||
virHashTablePtr stats,
|
virHashTablePtr stats,
|
||||||
bool backingChain)
|
bool backingChain)
|
||||||
{
|
{
|
||||||
qemuBlockStatsPtr bstats;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
||||||
virJSONValuePtr backing;
|
virJSONValuePtr backing;
|
||||||
|
|
||||||
if (!(bstats = virHashLookup(stats, entry_name))) {
|
if (qemuMonitorJSONBlockStatsUpdateCapacityData(image, entry_name, stats) < 0)
|
||||||
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)
|
|
||||||
goto cleanup;
|
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 &&
|
if (backingChain &&
|
||||||
(backing = virJSONValueObjectGetObject(image, "backing-image"))) {
|
(backing = virJSONValueObjectGetObject(image, "backing-image"))) {
|
||||||
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
|
ret = qemuMonitorJSONBlockStatsUpdateCapacityOne(backing,
|
||||||
|
Loading…
Reference in New Issue
Block a user