Received: from eggs.gnu.org ([2001:4830:134:3::10]:41371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzkS5-0002Bc-T5 for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YzkS1-0007Q9-Nh for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:33:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YzkS1-0007PY-HJ for qemu-devel@nongnu.org; Tue, 02 Jun 2015 07:33:45 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id F0D802CAF03 for ; Tue, 2 Jun 2015 11:33:44 +0000 (UTC) From: Markus Armbruster References: <1432815695-31687-1-git-send-email-armbru@redhat.com> <1432815695-31687-6-git-send-email-armbru@redhat.com> <55673FC2.8040804@redhat.com> Date: Tue, 02 Jun 2015 13:33:42 +0200 In-Reply-To: <55673FC2.8040804@redhat.com> (Eric Blake's message of "Thu, 28 May 2015 10:18:10 -0600") Message-ID: <878uc2cpk9.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 5/9] QemuOpts: Convert qemu_opts_foreach() to Error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: pbonzini@redhat.com, qemu-devel@nongnu.org Eric Blake writes: > On 05/28/2015 06:21 AM, Markus Armbruster wrote: >> Retain the function value for now, to permit selective conversion of >> its callers. >> >> Signed-off-by: Markus Armbruster >> --- >> block/blkdebug.c | 6 ++-- >> hw/core/qdev-properties-system.c | 5 +-- >> include/qemu/option.h | 4 +-- >> include/ui/console.h | 2 +- >> net/net.c | 9 ++--- >> net/vhost-user.c | 4 +-- >> numa.c | 5 +-- >> tpm.c | 6 ++-- >> ui/vnc.c | 2 +- >> util/qemu-config.c | 4 +-- >> util/qemu-option.c | 7 ++-- >> vl.c | 72 ++++++++++++++++++++++++---------------- >> 12 files changed, 72 insertions(+), 54 deletions(-) >> > >> diff --git a/block/blkdebug.c b/block/blkdebug.c >> index 58f5105..50ef1fc 100644 >> --- a/block/blkdebug.c >> +++ b/block/blkdebug.c >> @@ -219,7 +219,7 @@ struct add_rule_data { >> Error **errp; >> }; >> >> -static int add_rule(QemuOpts *opts, void *opaque) >> +static int add_rule(void *opaque, QemuOpts *opts, Error **errp) > >> +++ b/include/qemu/option.h >> @@ -125,9 +125,9 @@ QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, >> QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); >> void qemu_opts_absorb_qdict(QemuOpts *opts, QDict *qdict, Error **errp); >> >> -typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); >> +typedef int (*qemu_opts_loopfunc)(void *opaque, QemuOpts *opts, Error **errp); > > Might be nice to justify in the commit message why swapping the > arguments of the callback made sense. But doesn't affect code > correctness, so: > > Reviewed-by: Eric Blake Not sure what to write. Not even quite sure why I like it better this way, only that I do. Could be because it puts the object we're modifying (when we modify any of the argument objects) on the left. >> +++ b/util/qemu-option.c >> @@ -1047,13 +1047,14 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp) >> } >> >> /** >> - * For each member of @list, call @func(member, @opaque). >> + * For each member of @list, call @func(@opaque, member, @errp). >> * Call it with the current location temporarily set to the member's. >> + * @func() may store an Error through @errp, but must return non-zero then. >> * When @func() returns non-zero, break the loop and return that value. >> * Return zero when the loop completes. >> */ >> int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, >> - void *opaque) >> + void *opaque, Error **errp) >> { >> Location loc; >> QemuOpts *opts; >> @@ -1062,7 +1063,7 @@ int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, >> loc_push_none(&loc); >> QTAILQ_FOREACH(opts, &list->head, next) { >> loc_restore(&opts->loc); >> - rc = func(opts, opaque); >> + rc = func(opaque, opts, errp); >> if (rc) { >> return rc; >> } > > Do you want to enforce that if errp is set, that rc is non-zero, to > match your contract? Perhaps by assert(!*errp) at this point? But if > the return value goes away later in the series in favor of only using > errp, it may be a moot question. assert(!*errp) is incorrect, because callers may pass a null errp to ignore errors. Could do if (rc) { return rc; } assert(!errp || !*errp); Catches misbehaving func() only when caller passes non-null errp. To catcht it always, we'd need to use Error *err here, and error_propagate(errp, err). I doubt it's worth the trouble. What do you think?