mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 14:05:18 +00:00
qemu: json: Extract gathering of block statistics
The code is useful also when gathering statistics per node name, so extract it to a separate functions. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
50edca1331
commit
8d9ca6cdb3
@ -2277,26 +2277,15 @@ int qemuMonitorJSONGetBlockInfo(qemuMonitorPtr mon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static qemuBlockStatsPtr
|
||||||
qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
qemuMonitorJSONBlockStatsCollectData(virJSONValuePtr dev,
|
||||||
const char *dev_name,
|
int *nstats)
|
||||||
int depth,
|
|
||||||
virHashTablePtr hash,
|
|
||||||
bool backingChain)
|
|
||||||
{
|
{
|
||||||
qemuBlockStatsPtr bstats = NULL;
|
qemuBlockStatsPtr bstats = NULL;
|
||||||
virJSONValuePtr stats;
|
qemuBlockStatsPtr ret = NULL;
|
||||||
virJSONValuePtr parent;
|
virJSONValuePtr parent;
|
||||||
virJSONValuePtr parentstats;
|
virJSONValuePtr parentstats;
|
||||||
int ret = -1;
|
virJSONValuePtr stats;
|
||||||
int nstats = 0;
|
|
||||||
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
|
||||||
virJSONValuePtr backing;
|
|
||||||
|
|
||||||
if (!entry_name)
|
|
||||||
goto cleanup;
|
|
||||||
if (VIR_ALLOC(bstats) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if ((stats = virJSONValueObjectGetObject(dev, "stats")) == NULL) {
|
if ((stats = virJSONValueObjectGetObject(dev, "stats")) == NULL) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -2305,6 +2294,9 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC(bstats) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
#define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
|
#define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
|
||||||
if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
|
if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
|
||||||
nstats++; \
|
nstats++; \
|
||||||
@ -2331,6 +2323,33 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
|||||||
bstats->wr_highest_offset_valid = true;
|
bstats->wr_highest_offset_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VIR_STEAL_PTR(ret, bstats);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(bstats);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
||||||
|
const char *dev_name,
|
||||||
|
int depth,
|
||||||
|
virHashTablePtr hash,
|
||||||
|
bool backingChain)
|
||||||
|
{
|
||||||
|
qemuBlockStatsPtr bstats = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
int nstats = 0;
|
||||||
|
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
|
||||||
|
virJSONValuePtr backing;
|
||||||
|
|
||||||
|
if (!entry_name)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (!(bstats = qemuMonitorJSONBlockStatsCollectData(dev, &nstats)))
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
if (virHashAddEntry(hash, entry_name, bstats) < 0)
|
if (virHashAddEntry(hash, entry_name, bstats) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
bstats = NULL;
|
bstats = NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user