mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-24 04:12:20 +00:00
qemu: monitor: Convert common code to a macro
The function that is extracting block stats data from the QMP monitor reply contains a lot of repeated code. Since I'd be changing each of the copies in the next patch, lets convert it to a macro right away.
This commit is contained in:
parent
f6563bc361
commit
4d8ebb7a35
@ -1789,66 +1789,23 @@ qemuMonitorJSONGetOneBlockStatsInfo(virJSONValuePtr dev,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virJSONValueObjectGetNumberLong(stats, "rd_bytes",
|
#define QEMU_MONITOR_BLOCK_STAT_GET(NAME, VAR, MANDATORY) \
|
||||||
&bstats->rd_bytes) < 0) {
|
if (MANDATORY || virJSONValueObjectHasKey(stats, NAME)) { \
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
if (virJSONValueObjectGetNumberLong(stats, NAME, &VAR) < 0) { \
|
||||||
_("cannot read %s statistic"),
|
virReportError(VIR_ERR_INTERNAL_ERROR, \
|
||||||
"rd_bytes");
|
_("cannot read %s statistic"), NAME); \
|
||||||
goto cleanup;
|
goto cleanup; \
|
||||||
}
|
} \
|
||||||
if (virJSONValueObjectGetNumberLong(stats, "rd_operations",
|
|
||||||
&bstats->rd_req) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"rd_operations");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectHasKey(stats, "rd_total_time_ns") &&
|
|
||||||
(virJSONValueObjectGetNumberLong(stats, "rd_total_time_ns",
|
|
||||||
&bstats->rd_total_times) < 0)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"rd_total_time_ns");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectGetNumberLong(stats, "wr_bytes",
|
|
||||||
&bstats->wr_bytes) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"wr_bytes");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectGetNumberLong(stats, "wr_operations",
|
|
||||||
&bstats->wr_req) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"wr_operations");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectHasKey(stats, "wr_total_time_ns") &&
|
|
||||||
(virJSONValueObjectGetNumberLong(stats, "wr_total_time_ns",
|
|
||||||
&bstats->wr_total_times) < 0)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"wr_total_time_ns");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectHasKey(stats, "flush_operations") &&
|
|
||||||
(virJSONValueObjectGetNumberLong(stats, "flush_operations",
|
|
||||||
&bstats->flush_req) < 0)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"flush_operations");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
if (virJSONValueObjectHasKey(stats, "flush_total_time_ns") &&
|
|
||||||
(virJSONValueObjectGetNumberLong(stats, "flush_total_time_ns",
|
|
||||||
&bstats->flush_total_times) < 0)) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot read %s statistic"),
|
|
||||||
"flush_total_time_ns");
|
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_bytes", bstats->rd_bytes, true);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_bytes", bstats->wr_bytes, true);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_operations", bstats->rd_req, true);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_operations", bstats->wr_req, true);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("rd_total_time_ns", bstats->rd_total_times, false);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("wr_total_time_ns", bstats->wr_total_times, false);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("flush_operations", bstats->flush_req, false);
|
||||||
|
QEMU_MONITOR_BLOCK_STAT_GET("flush_total_time_ns", bstats->flush_total_times, false);
|
||||||
|
#undef QEMU_MONITOR_BLOCK_STAT_GET
|
||||||
|
|
||||||
/* it's ok to not have this information here. Just skip silently. */
|
/* it's ok to not have this information here. Just skip silently. */
|
||||||
qemuMonitorJSONDevGetBlockExtent(dev, &bstats->wr_highest_offset);
|
qemuMonitorJSONDevGetBlockExtent(dev, &bstats->wr_highest_offset);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user