The commit 290e3c6b07a introduced an helper to factor a code path
which is shared between the existing API and the new bulk stats API.
In the bulk stats path errors must be silenced unless critical
(e.g. memory allocation failure).
To address this need, this patch adds an argument to disable error
reporting.
---
src/qemu/qemu_driver.c | 4 +-
src/qemu/qemu_monitor.c | 12 ++++--
src/qemu/qemu_monitor.h | 3 +-
src/qemu/qemu_monitor_json.c | 87 ++++++++++++++++++++++++++------------------
src/qemu/qemu_monitor_json.h | 3 +-
5 files changed, 65 insertions(+), 44 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3ff226f..36b96e5 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17696,12 +17696,12 @@ qemuDomainGetStatsBlock(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor(driver, dom);
nstats = qemuMonitorGetAllBlockStatsInfo(priv->mon, NULL,
- stats, nstats);
+ stats, nstats,
+ false);
qemuDomainObjExitMonitor(driver, dom);
if (nstats < 0) {
- virResetLastError();
ret = 0; /* still ok, again go ahead silently */
goto cleanup;
}
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 10f51c5..cac48d7 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1765,17 +1765,21 @@ int
qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
const char *dev_name,
qemuBlockStatsPtr stats,
- int nstats)
+ int nstats,
+ bool report)
{
int ret;
VIR_DEBUG("mon=%p dev=%s", mon, dev_name);
if (mon->json) {
ret = qemuMonitorJSONGetAllBlockStatsInfo(mon, dev_name,
- stats, nstats);
+ stats, nstats,
+ report);
} else {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("unable to query all block stats with this QEMU"));
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("unable to query all block stats "
+ "with this QEMU"));
return -1;
}
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 2a43a3c..1eeb7b9 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -363,7 +363,8 @@ struct _qemuBlockStats {
int qemuMonitorGetAllBlockStatsInfo(qemuMonitorPtr mon,
const char *dev_name,
qemuBlockStatsPtr stats,
- int nstats)
+ int nstats,
+ bool report)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
int qemuMonitorGetBlockStatsParamsNumber(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 857edf1..4810bd3 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -1749,7 +1749,8 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
if (flush_total_times)
*flush_total_times = -1;
- if (qemuMonitorJSONGetAllBlockStatsInfo(mon, dev_name, &stats, 1) != 1)
+ if (qemuMonitorJSONGetAllBlockStatsInfo(mon, dev_name,
+ &stats, 1, true) != 1)
goto cleanup;
*rd_req = stats.rd_req;
@@ -1777,7 +1778,8 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
const char *dev_name,
qemuBlockStatsPtr bstats,
- int nstats)
+ int nstats,
+ bool report)
{
int ret, count;
size_t i;
@@ -1802,8 +1804,9 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
devices = virJSONValueObjectGet(reply, "return");
if (!devices || devices->type != VIR_JSON_TYPE_ARRAY) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats reply was missing device list"));
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("blockstats reply was missing device list"));
goto cleanup;
}
@@ -1812,9 +1815,10 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virJSONValuePtr dev = virJSONValueArrayGet(devices, i);
virJSONValuePtr stats;
if (!dev || dev->type != VIR_JSON_TYPE_OBJECT) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats device entry was not "
- "in expected format"));
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("blockstats device entry was not "
+ "in expected format"));
goto cleanup;
}
@@ -1824,9 +1828,10 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
if (dev_name) {
const char *thisdev = virJSONValueObjectGetString(dev, "device");
if (!thisdev) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats device entry was not "
- "in expected format"));
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("blockstats device entry was not "
+ "in expected format"));
goto cleanup;
}
@@ -1843,46 +1848,52 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
if ((stats = virJSONValueObjectGet(dev, "stats")) == NULL ||
stats->type != VIR_JSON_TYPE_OBJECT) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("blockstats stats entry was not "
- "in expected format"));
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("blockstats stats entry was not "
+ "in expected format"));
goto cleanup;
}
if (virJSONValueObjectGetNumberLong(stats, "rd_bytes",
&bstats->rd_bytes) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot read %s statistic"),
- "rd_bytes");
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot read %s statistic"),
+ "rd_bytes");
goto cleanup;
}
if (virJSONValueObjectGetNumberLong(stats, "rd_operations",
&bstats->rd_req) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot read %s statistic"),
- "rd_operations");
+ if (report)
+ 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");
+ if (report)
+ 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");
+ if (report)
+ 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");
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot read %s statistic"),
+ "wr_operations");
goto cleanup;
}
if (virJSONValueObjectHasKey(stats, "wr_total_time_ns") &&
@@ -1896,17 +1907,19 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
if (virJSONValueObjectHasKey(stats, "flush_operations") &&
(virJSONValueObjectGetNumberLong(stats, "flush_operations",
&bstats->flush_req) < 0)) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot read %s statistic"),
- "flush_operations");
+ if (report)
+ 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");
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot read %s statistic"),
+ "flush_total_time_ns");
goto cleanup;
}
@@ -1918,8 +1931,10 @@ int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
}
if (dev_name && !count) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot find statistics for device '%s'"),
dev_name);
+ if (report)
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("cannot find statistics for device
'%s'"),
+ dev_name);
goto cleanup;
}
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 3daa759..924c79c 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -82,7 +82,8 @@ int qemuMonitorJSONGetBlockStatsInfo(qemuMonitorPtr mon,
int qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
const char *dev_name,
qemuBlockStatsPtr stats,
- int nstats);
+ int nstats,
+ bool report);
int qemuMonitorJSONGetBlockStatsParamsNumber(qemuMonitorPtr mon,
int *nparams);
int qemuMonitorJSONGetBlockExtent(qemuMonitorPtr mon,
--
1.9.3