Received: from eggs.gnu.org ([2001:4830:134:3::10]:57448) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUcM6-0001l5-OA for qemu-devel@nongnu.org; Thu, 18 Sep 2014 10:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUcM1-0004U6-Dp for qemu-devel@nongnu.org; Thu, 18 Sep 2014 10:06:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54735) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUcM1-0004TJ-6T for qemu-devel@nongnu.org; Thu, 18 Sep 2014 10:06:37 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8IE6Vjt010935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 18 Sep 2014 10:06:31 -0400 From: Markus Armbruster References: <1411034263-18132-1-git-send-email-kwolf@redhat.com> <541AD06B.1070804@redhat.com> Date: Thu, 18 Sep 2014 16:06:27 +0200 In-Reply-To: <541AD06B.1070804@redhat.com> (Eric Blake's message of "Thu, 18 Sep 2014 06:30:35 -0600") Message-ID: <87y4thm3a4.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] block: Catch simultaneous usage of options and their aliases List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Kevin Wolf , qemu-devel@nongnu.org, stefanha@redhat.com Eric Blake writes: > On 09/18/2014 03:57 AM, Kevin Wolf wrote: >> While thinking about precedence of conflicting block device options from >> different sources, I noticed that you can specify both an option and its >> legacy alias at the same time (e.g. readonly=on,read-only=off). Rather >> than specifying the order of precedence, we should simply forbid such >> combinations. >> >> Signed-off-by: Kevin Wolf >> --- >> blockdev.c | 46 +++++++++++++++++++++++++++++++--------------- >> tests/qemu-iotests/051 | 23 +++++++++++++++++++++++ >> tests/qemu-iotests/051.out | 45 +++++++++++++++++++++++++++++++++++++++++++++ >> 3 files changed, 99 insertions(+), 15 deletions(-) > > Reviewed-by: Eric Blake > >> >> -static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to) >> +static void qemu_opt_rename(QemuOpts *opts, const char *from, const char *to, >> + Error **errp) >> { >> const char *value; >> >> + if (*errp) { >> + return; >> + } > > Not the most typical usage, so it might be worth a comment that this > function can be called with errp already set. But since it's static, > it's not too hard to figure out as-is. The problem with this usage is it doesn't combine well with the common usage. That's why I purged it from the code back in May: commit 297a3646c2947ee64a6d42ca264039732c6218e0 Author: Markus Armbruster Date: Wed May 7 09:53:54 2014 +0200 qapi: Replace uncommon use of the error API by the common one We commonly use the error API like this: err = NULL; foo(..., &err); if (err) { goto out; } bar(..., &err); Every error source is checked separately. The second function is only called when the first one succeeds. Both functions are free to pass their argument to error_set(). Because error_set() asserts no error has been set, this effectively means they must not be called with an error set. The qapi-generated code uses the error API differently: // *errp was initialized to NULL somewhere up the call chain frob(..., errp); gnat(..., errp); Errors accumulate in *errp: first error wins, subsequent errors get dropped. To make this work, the second function does nothing when called with an error set. Requires non-null errp, or else the second function can't see the first one fail. This usage has also bled into visitor tests, and two device model object property getters rtc_get_date() and balloon_stats_get_all(). With the "accumulate" technique, you need fewer error checks in callers, and buy that with an error check in every callee. Can be nice. However, mixing the two techniques is confusing. You can't use the "accumulate" technique with functions designed for the "check separately" technique. You can use the "check separately" technique with functions designed for the "accumulate" technique, but then error_set() can't catch you setting an error more than once. Standardize on the "check separately" technique for now, because it's overwhelmingly prevalent. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino See also the thread leading up to this commit: https://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01424.html in particular the part starting at https://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01830.html I guess you're about as thrilled by what the common usage does to your code as I am: qemu_opt_rename(all_opts, "iops", "throttling.iops-total", &local_err); if (local_err) { goto fail_opt_rename; } qemu_opt_rename(all_opts, "iops_rd", "throttling.iops-read", &local_err); if (local_err) { goto fail_opt_rename; } qemu_opt_rename(all_opts, "iops_wr", "throttling.iops-write", &local_err); if (local_err) { goto fail_opt_rename; } [11 instances of the same pattern mercifully omitted...] fail_opt_rename: error_report("%s", error_get_pretty(local_err)); error_free(local_err); return NULL; But this code is annoyingly repetitive even before the patch! Here's what I'd do: static struct { const char *from, *to; } rename[] = { { "iops", "throttling.iops-total" }, { "iops_rd", "throttling.iops-read" }, { "iops_wr", "throttling.iops-write" }, { "bps", "throttling.bps-total" }, { "bps_rd", "throttling.bps-read" }, { "bps_wr", "throttling.bps-write" }, { "iops_max", "throttling.iops-total-max" }, { "iops_rd_max", "throttling.iops-read-max" }, { "iops_wr_max", "throttling.iops-write-max" }, { "bps_max", "throttling.bps-total-max" }, { "bps_rd_max", "throttling.bps-read-max" }, { "bps_wr_max", "throttling.bps-write-max" }, { "iops_size", "throttling.iops-size" }, { "readonly", "read-only" }, }; Error *local_err = NULL; int i; for (i = 0; i < ARRAY_SIZE(rename); i++) { qemu_opt_rename(all_opts, rename[i].from, rename[i].to, &local_err); if (local_err) { error_report("%s", error_get_pretty(local_err)); error_free(local_err); return NULL; } }