[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/24] qdev-monitor: Convert qbus_find() to Error
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 11/24] qdev-monitor: Convert qbus_find() to Error |
Date: |
Mon, 22 Jun 2015 21:04:36 +0200 |
As usual, the conversion breaks printing explanatory messages after
the error: actual printing of the error gets delayed, so the
explanations precede rather than follow it.
Pity. Disable them for now. See also commit 7216ae3.
While there, eliminate QERR_BUS_NOT_FOUND, and clean up unusual
spelling in the error message.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
include/qapi/qmp/qerror.h | 3 ---
qdev-monitor.c | 32 ++++++++++++++++++++------------
2 files changed, 20 insertions(+), 15 deletions(-)
diff --git a/include/qapi/qmp/qerror.h b/include/qapi/qmp/qerror.h
index e567339..6468e40 100644
--- a/include/qapi/qmp/qerror.h
+++ b/include/qapi/qmp/qerror.h
@@ -43,9 +43,6 @@ void qerror_report_err(Error *err);
#define QERR_BUS_NO_HOTPLUG \
ERROR_CLASS_GENERIC_ERROR, "Bus '%s' does not support hotplugging"
-#define QERR_BUS_NOT_FOUND \
- ERROR_CLASS_GENERIC_ERROR, "Bus '%s' not found"
-
#define QERR_DEVICE_HAS_NO_MEDIUM \
ERROR_CLASS_GENERIC_ERROR, "Device '%s' has no medium"
diff --git a/qdev-monitor.c b/qdev-monitor.c
index afc0395..12d8f6b 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -288,12 +288,13 @@ static Object *qdev_get_peripheral_anon(void)
return dev;
}
+#if 0 /* conversion from qerror_report() to error_set() broke their use */
static void qbus_list_bus(DeviceState *dev)
{
BusState *child;
const char *sep = " ";
- error_printf("child busses at \"%s\":",
+ error_printf("child buses at \"%s\":",
dev->id ? dev->id : object_get_typename(OBJECT(dev)));
QLIST_FOREACH(child, &dev->child_bus, sibling) {
error_printf("%s\"%s\"", sep, child->name);
@@ -317,6 +318,7 @@ static void qbus_list_dev(BusState *bus)
}
error_printf("\n");
}
+#endif
static BusState *qbus_find_bus(DeviceState *dev, char *elem)
{
@@ -415,7 +417,7 @@ static BusState *qbus_find_recursive(BusState *bus, const
char *name,
return pick;
}
-static BusState *qbus_find(const char *path)
+static BusState *qbus_find(const char *path, Error **errp)
{
DeviceState *dev;
BusState *bus;
@@ -433,7 +435,7 @@ static BusState *qbus_find(const char *path)
}
bus = qbus_find_recursive(sysbus_get_default(), elem, NULL);
if (!bus) {
- qerror_report(QERR_BUS_NOT_FOUND, elem);
+ error_setg(errp, "Bus '%s' not found", elem);
return NULL;
}
pos = len;
@@ -456,10 +458,12 @@ static BusState *qbus_find(const char *path)
pos += len;
dev = qbus_find_dev(bus, elem);
if (!dev) {
- qerror_report(QERR_DEVICE_NOT_FOUND, elem);
+ error_set(errp, QERR_DEVICE_NOT_FOUND, elem);
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
if (!monitor_cur_is_qmp()) {
qbus_list_dev(bus);
}
+#endif
return NULL;
}
@@ -475,14 +479,15 @@ static BusState *qbus_find(const char *path)
break;
}
if (dev->num_child_bus) {
- qerror_report(ERROR_CLASS_GENERIC_ERROR,
- "Device '%s' has multiple child busses", elem);
+ error_setg(errp, "Device '%s' has multiple child buses",
+ elem);
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
if (!monitor_cur_is_qmp()) {
qbus_list_bus(dev);
}
+#endif
} else {
- qerror_report(ERROR_CLASS_GENERIC_ERROR,
- "Device '%s' has no child bus", elem);
+ error_setg(errp, "Device '%s' has no child bus", elem);
}
return NULL;
}
@@ -495,17 +500,18 @@ static BusState *qbus_find(const char *path)
pos += len;
bus = qbus_find_bus(dev, elem);
if (!bus) {
- qerror_report(QERR_BUS_NOT_FOUND, elem);
+ error_setg(errp, "Bus '%s' not found", elem);
+#if 0 /* conversion from qerror_report() to error_set() broke this: */
if (!monitor_cur_is_qmp()) {
qbus_list_bus(dev);
}
+#endif
return NULL;
}
}
if (qbus_is_full(bus)) {
- qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
- path);
+ error_setg(errp, "Bus '%s' is full", path);
return NULL;
}
return bus;
@@ -536,8 +542,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
/* find bus */
path = qemu_opt_get(opts, "bus");
if (path != NULL) {
- bus = qbus_find(path);
+ bus = qbus_find(path, &err);
if (!bus) {
+ qerror_report_err(err);
+ error_free(err);
return NULL;
}
if (!object_dynamic_cast(OBJECT(bus), dc->bus_type)) {
--
1.9.3
- [Qemu-devel] [PULL 00/24] Monitor patches, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 03/24] monitor: remove debug prints, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 05/24] monitor: Point to "help" command on syntax error, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 06/24] monitor: Fix failure path for "S" argument, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 12/24] qdev-monitor: Propagate errors through set_property(), Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 04/24] monitor: cleanup parsing of cmd name and cmd arguments, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 10/24] qdev-monitor: Fix check for full bus, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 09/24] qdev-monitor: Stop error avalanche in qbus_find_recursive(), Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 13/24] qdev-monitor: Propagate errors through qdev_device_add(), Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 15/24] vl: Avoid qerror_report() outside QMP command handlers, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 11/24] qdev-monitor: Convert qbus_find() to Error,
Markus Armbruster <=
- [Qemu-devel] [PULL 01/24] qobject: Use 'bool' for qbool, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 02/24] qobject: Use 'bool' inside qdict, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 16/24] vl: Use error_report() for --display errors, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 17/24] qerror: Eliminate QERR_DEVICE_NOT_FOUND, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 07/24] monitor: Split mon_get_cpu fn to remove ENV_GET_CPU, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 23/24] Include qapi/qmp/qerror.h exactly where needed, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 22/24] qerror: Move #include out of qerror.h, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 21/24] qerror: Finally unused, clean up, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 19/24] tpm: Avoid qerror_report() outside QMP command handlers, Markus Armbruster, 2015/06/22
- [Qemu-devel] [PULL 20/24] qmp: Wean off qerror_report(), Markus Armbruster, 2015/06/22