Received: from eggs.gnu.org ([2001:4830:134:3::10]:38044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciQbb-00020y-Gk for qemu-devel@nongnu.org; Mon, 27 Feb 2017 14:05:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciQbX-0005qy-J1 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 14:05:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33944) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciQbX-0005qp-DL for qemu-devel@nongnu.org; Mon, 27 Feb 2017 14:05:03 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B2D3C04BD32 for ; Mon, 27 Feb 2017 19:05:03 +0000 (UTC) Date: Mon, 27 Feb 2017 16:05:00 -0300 From: Eduardo Habkost Message-ID: <20170227190500.GE2778@thinpad.lan.raisama.net> References: <20170118135624.17368-1-ehabkost@redhat.com> <20170118135624.17368-2-ehabkost@redhat.com> <87bmtna50o.fsf@dusky.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87bmtna50o.fsf@dusky.pond.sub.org> Subject: Re: [Qemu-devel] [PATCH 1/2] config: qemu_config_parse() return number of config groups List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Paolo Bonzini On Mon, Feb 27, 2017 at 06:59:51PM +0100, Markus Armbruster wrote: > Uh, I totally forgot about this series. My apologies... > > Eduardo Habkost writes: > > > Change qemu_config_parse() to return the number of config groups > > in success and -EINVAL on error. This will allow callers of > > qemu_config_parse() to check if something was really loaded from > > the config file. > > > > All existing callers of qemu_config_parse() and > > qemu_read_config_file() only check if the return value was > > negative, so the change shouldn't affect them. > > Two of them: > > * read_config() maps negative value to -EINVAL. Callers: > > - blkdebug_open() passes it on. As a .bdrv_file_open() method, it's > supposed to return -errno on failure. Good. > > * qemu_read_config_file() maps non-zero value to -EINVAL. Callers: > > - qemu_read_default_config_file() maps -EINVAL to zero. WTF? qemu_read_config_file() maps -ENOENT to zero, not -EINVAL. It will ignore the error only if the default config file doesn't exist (if fopen() sets errno to ENOENT). > > - main() passes sterror(EINVAL) to error_report(). Good. > > Also: qemu_config_parse() reports errors with error_report(). Let's > have another look at its callers: > > * read_config() has an Error ** parameter. Bad. Care to convert the > sucker to Error? I can do it in a separate patch, unless you believe it must be done by this patch patch in a single step. > > * qemu_read_config_file() doesn't report errors. Callers: > > - qemu_read_default_config_file() doesn't report errors. Its called > by main(), and ... This means fopen() errors won't get reported. Good catch. I will send a separate fix. > > - main() reports with error_report(). Good. > [...] > > I think this mapping to -EINVAL is also superfluous now: > > diff --git a/block/blkdebug.c b/block/blkdebug.c > index 6117ce5..fbefa9e 100644 > --- a/block/blkdebug.c > +++ b/block/blkdebug.c > @@ -252,7 +252,6 @@ static int read_config(BDRVBlkdebugState *s, const char *filename, > ret = qemu_config_parse(f, config_groups, filename); > if (ret < 0) { > error_setg(errp, "Could not parse blkdebug config file"); > - ret = -EINVAL; > goto fail; Good catch. I will squash it into the patch. -- Eduardo