Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NkwXJ-0006lw-DZ for qemu-devel@nongnu.org; Fri, 26 Feb 2010 04:31:05 -0500 Received: from [199.232.76.173] (port=38509 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NkwXI-0006lo-1y for qemu-devel@nongnu.org; Fri, 26 Feb 2010 04:31:04 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NkwXG-0005xA-OE for qemu-devel@nongnu.org; Fri, 26 Feb 2010 04:31:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43440) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NkwXG-0005x6-CZ for qemu-devel@nongnu.org; Fri, 26 Feb 2010 04:31:02 -0500 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o1Q9V0BS014962 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 26 Feb 2010 04:31:00 -0500 From: Markus Armbruster References: <20100225114256.GC9116@redhat.com> <20100225120848.GA9223@redhat.com> <4B868B6F.8050900@redhat.com> Date: Fri, 26 Feb 2010 10:30:57 +0100 In-Reply-To: <4B868B6F.8050900@redhat.com> (Gerd Hoffmann's message of "Thu, 25 Feb 2010 15:38:39 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: [Qemu-devel] Re: [PATCH] qdev: Catch attempt to attach more than one device to a netdev List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: Mark McLoughlin , qemu-devel@nongnu.org, "Michael S. Tsirkin" Gerd Hoffmann writes: > Hi, > >> Gerd, what do you think about changing the contract for property parse >> methods to return -EINVAL, -EBUSY and such? > > Hmm, wouldn't it make more sense to integrate with qerror somehow? Depends. If you want to move error reporting from qdev_prop_parse() and set_property() into the parse methods, then simply use qemu_error() or qemu_error_new() there: + qemu_error_new(QERR_SYNTAX, str); return -1; This made a lot of sense if each parser threw largely different errors. Which isn't the case: we have one so far ("failed to parse"), and we just encountered a use for a second. We have the same very few errors occuring in many parsers, and we report them just the same, regardless of the parser used. Michael's proposal is optimized for that: it keeps the actual error reporting centralized in one place, qdev_prop_parse(), and keeps the code occuring many times to a bare minimum: - return -1; + return -EINVAL; You could attempt to do the same with QError rather than errno.h codes. Looks like this: - return -1; + return qemu_error_from_info2(__FILE__, __LINE__, __func__, QERR_SYNTAX, str); where qemu_error_from_info2() is to qemu_error_from_info() what printf() is to vprintf(). Naturally, you'd want sweep some of the ugliness under a macro-rug, so it actually looks more like this: - return -1; + return qerror_new2(QERR_SYNTAX, str); Except with a less unimaginative name, of course. qdev_prop_parse() could then query the QError member error (a QDict) to find out more about the error. But there's no need for that. All it wants to know about the error is "was there one?". We get: - if (prop->info->parse(dev, prop, value) != 0) { + qerr = prop->info->parse(dev, prop, value); + if (qerr) { - fprintf(stderr, "property \"%s.%s\": failed to parse \"%s\"\n", - dev->info->name, name, value); + qerror_emit(qerr); return -1; } No improvement over letting the parsers call qemu_error_new().