From patchwork Fri Jun 26 13:31:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 50347 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 338D022902 for ; Fri, 26 Jun 2015 13:32:38 +0000 (UTC) Received: by lbcak1 with SMTP id ak1sf26778440lbc.2 for ; Fri, 26 Jun 2015 06:32:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=gqTvN56PN3tzMX0qbdV2QN6bl6alCSxKCzQwBsYEGaw=; b=GpQ2voLdtsxcrnoUeLkQHfxJPePul+I6gxuO1ezJkB/Rn09mCzNuMy9x9HNE6azaIn ItRE0Exnio4/xSiyq0lY8rpkVfVAnhySawoMDommeicR8hg1ngRxRvEZYRr2mg1JNZL4 V+36E3r0K63bM5epRZRUUNovmzD2N7bxON/QMWZRKuKbrwUUGDWqud6lWT6lJ/sumv1s KVT8c1Lc8xdIgyzpRRia7qB4OPodcGM7yZ8Por+Bll9Ej6T24ugqLpQp154RiOH68ksC azSVFynaJI91v40QfD+YVNtndwmEgNR/MCdeO0CALAere9+ODNNwbyWcvmG4rpIaPyFd dFIA== X-Gm-Message-State: ALoCoQmdKg3IMwhJ1JExfqE/+rkJ3bWLn8kL7+xX9y4uLeQZ034czUwM1lUg7tFsYDdyRX3ExCvG X-Received: by 10.112.9.100 with SMTP id y4mr1169893lba.20.1435325557170; Fri, 26 Jun 2015 06:32:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.7 with SMTP id bc7ls508424lab.74.gmail; Fri, 26 Jun 2015 06:32:36 -0700 (PDT) X-Received: by 10.152.7.239 with SMTP id m15mr1559950laa.95.1435325556897; Fri, 26 Jun 2015 06:32:36 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id az11si27018168lab.27.2015.06.26.06.32.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jun 2015 06:32:36 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by lbbpo10 with SMTP id po10so64514938lbb.3 for ; Fri, 26 Jun 2015 06:32:36 -0700 (PDT) X-Received: by 10.112.198.74 with SMTP id ja10mr1634531lbc.19.1435325556615; Fri, 26 Jun 2015 06:32:36 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp1330092lbb; Fri, 26 Jun 2015 06:32:35 -0700 (PDT) X-Received: by 10.140.201.81 with SMTP id w78mr2300625qha.39.1435325555135; Fri, 26 Jun 2015 06:32:35 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id n35si32876502qge.91.2015.06.26.06.32.34 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 26 Jun 2015 06:32:35 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:60003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8TkA-0003IH-91 for patch@linaro.org; Fri, 26 Jun 2015 09:32:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8TjC-0002JE-Ka for qemu-devel@nongnu.org; Fri, 26 Jun 2015 09:31:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8TjB-0001WP-3g for qemu-devel@nongnu.org; Fri, 26 Jun 2015 09:31:34 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:34512) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8TjA-0001QX-Rx for qemu-devel@nongnu.org; Fri, 26 Jun 2015 09:31:33 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Z8Tj2-0005Gj-7e for qemu-devel@nongnu.org; Fri, 26 Jun 2015 14:31:24 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 26 Jun 2015 14:31:21 +0100 Message-Id: <1435325484-20208-6-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1435325484-20208-1-git-send-email-peter.maydell@linaro.org> References: <1435325484-20208-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 5/7] qdev-properties-system: Change set_pointer's parse callback to use 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Instead of having set_pointer() call a parse callback which returns an error number that we then convert to an Error string with error_set_from_qdev_prop_error(), make the parse callback take an Error** and set the error itself. This will allow parse routines to provide more helpful error messages than the generic ones. Signed-off-by: Peter Maydell Reviewed-by: Markus Armbruster Reviewed-by: Stefan Hajnoczi Message-id: 1435068107-12594-2-git-send-email-peter.maydell@linaro.org --- hw/core/qdev-properties-system.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index aa794ca..c731bc6 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -35,15 +35,15 @@ static void get_pointer(Object *obj, Visitor *v, Property *prop, } static void set_pointer(Object *obj, Visitor *v, Property *prop, - int (*parse)(DeviceState *dev, const char *str, - void **ptr), + void (*parse)(DeviceState *dev, const char *str, + void **ptr, const char *propname, + Error **errp), const char *name, Error **errp) { DeviceState *dev = DEVICE(obj); Error *local_err = NULL; void **ptr = qdev_get_prop_ptr(dev, prop); char *str; - int ret; if (dev->realized) { qdev_prop_set_after_realize(dev, name, errp); @@ -60,26 +60,29 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop, *ptr = NULL; return; } - ret = parse(dev, str, ptr); - error_set_from_qdev_prop_error(errp, ret, dev, prop, str); + parse(dev, str, ptr, prop->name, errp); g_free(str); } /* --- drive --- */ -static int parse_drive(DeviceState *dev, const char *str, void **ptr) +static void parse_drive(DeviceState *dev, const char *str, void **ptr, + const char *propname, Error **errp) { BlockBackend *blk; blk = blk_by_name(str); if (!blk) { - return -ENOENT; + error_setg(errp, "Property '%s.%s' can't find value '%s'", + object_get_typename(OBJECT(dev)), propname, str); + return; } if (blk_attach_dev(blk, dev) < 0) { - return -EEXIST; + error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use", + object_get_typename(OBJECT(dev)), propname, str); + return; } *ptr = blk; - return 0; } static void release_drive(Object *obj, const char *name, void *opaque) @@ -121,17 +124,21 @@ PropertyInfo qdev_prop_drive = { /* --- character device --- */ -static int parse_chr(DeviceState *dev, const char *str, void **ptr) +static void parse_chr(DeviceState *dev, const char *str, void **ptr, + const char *propname, Error **errp) { CharDriverState *chr = qemu_chr_find(str); if (chr == NULL) { - return -ENOENT; + error_setg(errp, "Property '%s.%s' can't find value '%s'", + object_get_typename(OBJECT(dev)), propname, str); + return; } if (qemu_chr_fe_claim(chr) != 0) { - return -EEXIST; + error_setg(errp, "Property '%s.%s' can't take value '%s', it's in use", + object_get_typename(OBJECT(dev)), propname, str); + return; } *ptr = chr; - return 0; } static void release_chr(Object *obj, const char *name, void *opaque)