From patchwork Fri Feb 1 17:38:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 217551 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 942AD2C0292 for ; Sat, 2 Feb 2013 04:49:04 +1100 (EST) Received: from localhost ([::1]:50253 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1KXt-0006Ju-9O for incoming@patchwork.ozlabs.org; Fri, 01 Feb 2013 12:37:01 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1KXQ-0005jA-97 for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U1KXK-0006GX-NC for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3461) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U1KXK-0006GS-FD for qemu-devel@nongnu.org; Fri, 01 Feb 2013 12:36:26 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r11HaPdN006074 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Feb 2013 12:36:25 -0500 Received: from lacos-laptop.usersys.redhat.com (vpn1-4-37.ams2.redhat.com [10.36.4.37]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r11HaIwS005493; Fri, 1 Feb 2013 12:36:25 -0500 From: Laszlo Ersek To: lcapitulino@redhat.com, qemu-devel@nongnu.org Date: Fri, 1 Feb 2013 18:38:17 +0100 Message-Id: <1359740299-27968-6-git-send-email-lersek@redhat.com> In-Reply-To: <1359740299-27968-1-git-send-email-lersek@redhat.com> References: <1359740299-27968-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/7] qbus_find_recursive(): terminate search by name in case of fatal error X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use an Error to communicate the "stop the search" message. Signed-off-by: Laszlo Ersek --- 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;