Received: from eggs.gnu.org ([2001:4830:134:3::10]:49384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YbOnF-0005bm-Of for qemu-devel@nongnu.org; Fri, 27 Mar 2015 03:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YbOnE-0001BK-Qf for qemu-devel@nongnu.org; Fri, 27 Mar 2015 03:35:01 -0400 From: Markus Armbruster References: <1427276174-9130-1-git-send-email-wency@cn.fujitsu.com> <1427276174-9130-7-git-send-email-wency@cn.fujitsu.com> <20150326072146.GJ14724@ad.nay.redhat.com> <5513B61D.3040705@cn.fujitsu.com> <20150327010602.GL14724@ad.nay.redhat.com> Date: Fri, 27 Mar 2015 08:34:52 +0100 In-Reply-To: <20150327010602.GL14724@ad.nay.redhat.com> (Fam Zheng's message of "Fri, 27 Mar 2015 09:06:02 +0800") Message-ID: <87619mvqoz.fsf_-_@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] Use of QERR_ macros and error classes (was: [RFC PATCH COLO v2 06/13] NBD client: implement block driver interfaces for block replication) List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: Kevin Wolf , Lai Jiangshan , qemu block , Jiang Yunhong , Dong Eddie , "Dr. David Alan Gilbert" , qemu devel , Gonglei , Stefan Hajnoczi , Paolo Bonzini , Yang Hongyang , Max Reitz , zhanghailiang Fam Zheng writes: > On Thu, 03/26 15:32, Wen Congyang wrote: >> On 03/26/2015 03:21 PM, Fam Zheng wrote: >> > On Wed, 03/25 17:36, Wen Congyang wrote: >> >> Signed-off-by: Wen Congyang >> >> Signed-off-by: zhanghailiang >> >> Signed-off-by: Gonglei >> >> --- >> >> block/nbd.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ >> >> 1 file changed, 49 insertions(+) >> >> >> >> diff --git a/block/nbd.c b/block/nbd.c >> >> index 3faf865..753b322 100644 >> >> --- a/block/nbd.c >> >> +++ b/block/nbd.c >> >> @@ -458,6 +458,52 @@ static void nbd_refresh_filename(BlockDriverState *bs) >> >> bs->full_open_options = opts; >> >> } >> >> >> >> +static void nbd_start_replication(BlockDriverState *bs, COLOMode mode, >> >> + Error **errp) >> >> +{ >> >> + BDRVNBDState *s = bs->opaque; >> >> + >> >> + /* >> >> + * TODO: support COLO_SECONDARY_MODE if we allow secondary >> >> + * QEMU becoming primary QEMU. >> >> + */ >> >> + if (mode != COLO_MODE_PRIMARY) { >> >> + error_set(errp, QERR_INVALID_PARAMETER, "mode"); >> > >> > Please use error_setg. (Please grep the whole series :) >> >> Why? QERR_INVALID_PARAMETER includes ERROR_CLASS_GENERIC_ERROR. > > Because error classes are deprecated. See also commit 5b347c5410. Yes, new code should use ERROR_CLASS_GENERIC_ERROR, preferably through error_setg() or similar. The QERR_ macros in qerror.h expand to *two* expressions CLS, FMT, for use as function arguments. Dirty. Was done that way when error classes were introduced to reduce churn (commit 8546505..0f32cf6). Besides being dirty, they hide the error class. Bad, because we really want unusual things like a funky error class stand out right where the error is created. If they don't, we're prone to accidental uses of funky error classes creeping in. So far, we've eliminated all QERR_ macros using a funky error class but one: QERR_DEVICE_NOT_FOUND. That one needs to go, too. I've got patches in my queue for 2.4. In fact, all of qerror.h needs to go. I've got patches for 2.4 to clean it out except for a bunch of QERR_. Replacing these isn't hard, just prone to conflicts, so I'm saving it for a little later. For now, adding uses of QERR_ macros other than QERR_DEVICE_NOT_FOUND is still okay, it just creates a little extra work for me. But avoiding them makes their ultimate removal a bit easier, and is encouraged.