qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: lcapitulino@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 5/7] qbus_find_recursive(): terminate search by name in case of fatal error
Date: Fri,  1 Feb 2013 18:38:17 +0100	[thread overview]
Message-ID: <1359740299-27968-6-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1359740299-27968-1-git-send-email-lersek@redhat.com>

Use an Error to communicate the "stop the search" message.

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/qdev-monitor.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index 284dafa..83540fc 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -288,7 +288,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)
 }
 
 static BusState *qbus_find_recursive(BusState *bus, const char *name,
-                                     const char *type)
+                                     const char *type, Error **errp)
 {
     BusChild *kid;
 
@@ -303,8 +303,7 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
 
         /* bus is full -- fatal error for search by name */
         if (name != NULL) {
-            qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
-                          bus->name);
+            error_setg(errp, "Bus '%s' is full", bus->name);
             return NULL;
         }
     }
@@ -316,8 +315,8 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
         QLIST_FOREACH(child, &dev->child_bus, sibling) {
             BusState *ret;
 
-            ret = qbus_find_recursive(child, name, type);
-            if (ret) {
+            ret = qbus_find_recursive(child, name, type, errp);
+            if (ret || error_is_set(errp)) {
                 return ret;
             }
         }
@@ -337,13 +336,20 @@ static BusState *qbus_find(const char *path)
         bus = sysbus_get_default();
         pos = 0;
     } else {
+        Error *err = NULL;
+
         if (sscanf(path, "%127[^/]%n", elem, &len) != 1) {
             assert(!path[0]);
             elem[0] = len = 0;
         }
-        bus = qbus_find_recursive(sysbus_get_default(), elem, NULL);
+        bus = qbus_find_recursive(sysbus_get_default(), elem, NULL, &err);
         if (!bus) {
-            qerror_report(QERR_BUS_NOT_FOUND, elem);
+            if (error_is_set(&err)) {
+                qerror_report_err(err);
+                error_free(err);
+            } else {
+                qerror_report(QERR_BUS_NOT_FOUND, elem);
+            }
             return NULL;
         }
         pos = len;
@@ -458,8 +464,10 @@ DeviceState *qdev_device_add(QemuOpts *opts)
             return NULL;
         }
     } else {
-        bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type);
+        bus = qbus_find_recursive(sysbus_get_default(), NULL, k->bus_type,
+                                  &local_err);
         if (!bus) {
+            assert(!error_is_set(&local_err));
             qerror_report(QERR_NO_BUS_FOR_DEVICE,
                           k->bus_type, driver);
             return NULL;
-- 
1.7.1

  parent reply	other threads:[~2013-02-01 17:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-01 17:38 [Qemu-devel] [PATCH 0/7] propagate Errors to do_device_add() Laszlo Ersek
2013-02-01 17:38 ` [Qemu-devel] [PATCH 1/7] remove some trailing whitespace Laszlo Ersek
2013-02-01 17:38 ` [Qemu-devel] [PATCH 2/7] do_device_add(): look up "device" opts list with qemu_find_opts_err() Laszlo Ersek
2013-02-01 17:38 ` [Qemu-devel] [PATCH 3/7] qdev_prop_parse(): report errors via Error Laszlo Ersek
2013-02-01 17:38 ` [Qemu-devel] [PATCH 4/7] qbus_find_recursive(): reorganize Laszlo Ersek
2013-02-01 17:38 ` Laszlo Ersek [this message]
2013-02-01 17:38 ` [Qemu-devel] [PATCH 6/7] qbus_find(): report errors via Error Laszlo Ersek
2013-02-01 17:38 ` [Qemu-devel] [PATCH 7/7] qdev_device_add(): report errors with Error Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1359740299-27968-6-git-send-email-lersek@redhat.com \
    --to=lersek@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).