}
-/* Creates a hash table in 'ret_stats' with all block stats.
- * Returns <0 on error, 0 on success.
+/**
+ * qemuMonitorGetAllBlockStatsInfo:
+ * @mon: monitor object
+ * @ret_stats: pointer that is filled with a hash table containing the stats
+ * @backingChain: recurse into the backing chain of devices
+ *
+ * Creates a hash table in @ret_stats with block stats of all devices. In case
+ * @backingChain is true @ret_stats will additionally contain stats for
+ * backing chain members of block devices.
+ *
+ * Returns < 0 on error, count of supported block stats fields on success.
*/
int
qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
virHashTablePtr *ret_stats,
bool backingChain)
{
+ int ret = -1;
VIR_DEBUG("mon=%p ret_stats=%p, backing=%d", mon, ret_stats, backingChain);
if (!mon->json) {
goto error;
if (mon->json) {
- if (qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats, backingChain) < 0)
- goto error;
+ ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, *ret_stats,
+ backingChain);
} else {
if (backingChain) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
goto error;
}
- if (qemuMonitorTextGetAllBlockStatsInfo(mon, *ret_stats) < 0)
- goto error;
+ ret = qemuMonitorTextGetAllBlockStatsInfo(mon, *ret_stats);
}
- return 0;
+ if (ret < 0)
+ goto error;
+
+ return ret;
error:
virHashFree(*ret_stats);
qemuBlockStatsPtr bstats = NULL;
virJSONValuePtr stats;
int ret = -1;
+ int nstats = 0;
char *entry_name = qemuDomainStorageAlias(dev_name, depth);
virJSONValuePtr backing;
#define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
+ nstats++; \
if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
_("cannot read %s statistic"), NAME); \
hash, true) < 0)
goto cleanup;
- ret = 0;
+ ret = nstats;
cleanup:
VIR_FREE(bstats);
VIR_FREE(entry_name);
bool backingChain)
{
int ret = -1;
+ int nstats = 0;
int rc;
size_t i;
virJSONValuePtr cmd;
goto cleanup;
}
- if (qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash,
- backingChain) < 0)
+ rc = qemuMonitorJSONGetOneBlockStatsInfo(dev, dev_name, 0, hash,
+ backingChain);
+
+ if (rc < 0)
goto cleanup;
+ if (rc > nstats)
+ nstats = rc;
}
- ret = 0;
+ ret = nstats;
cleanup:
virJSONValueFree(cmd);
size_t i;
size_t j;
int ret = -1;
+ int nstats;
+ int maxstats = 0;
if (qemuMonitorHMPCommand(mon, "info blockstats", &info) < 0)
goto cleanup;
if (!(values = virStringSplit(line, " ", 0)))
goto cleanup;
+ nstats = 0;
+
for (j = 0; values[j] && *values[j]; j++) {
key = values[j];
#define QEMU_MONITOR_TEXT_READ_BLOCK_STAT(NAME, VAR) \
if (STREQ(key, NAME)) { \
+ nstats++; \
if (virStrToLong_ll(value, NULL, 10, &VAR) < 0) { \
virReportError(VIR_ERR_INTERNAL_ERROR, \
_("'info blockstats' contains malformed " \
VIR_DEBUG("unknown block stat field '%s'", key);
}
+ if (nstats > maxstats)
+ maxstats = nstats;
+
if (virHashAddEntry(hash, dev_name, stats) < 0)
goto cleanup;
stats = NULL;
values = NULL;
}
- ret = 0;
+ ret = maxstats;
cleanup:
virStringFreeList(lines);