From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60637C4332C for ; Mon, 23 Sep 2019 20:54:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 338B4207FD for ; Mon, 23 Sep 2019 20:54:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 338B4207FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCVM5-0006dx-Rs for qemu-devel@archiver.kernel.org; Mon, 23 Sep 2019 16:54:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34769) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iCUUg-0006gX-2z for qemu-devel@nongnu.org; Mon, 23 Sep 2019 15:59:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iCUUe-00022S-Rk for qemu-devel@nongnu.org; Mon, 23 Sep 2019 15:59:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44822) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iCUUY-00020p-SV; Mon, 23 Sep 2019 15:59:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9320D8A1C8C; Mon, 23 Sep 2019 19:59:24 +0000 (UTC) Received: from [10.3.116.249] (ovpn-116-249.phx2.redhat.com [10.3.116.249]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 321B26017E; Mon, 23 Sep 2019 19:58:11 +0000 (UTC) Subject: Re: [RFC v2 1/9] error: auto propagated local_err To: Vladimir Sementsov-Ogievskiy , qemu-devel@nongnu.org References: <20190923161231.22028-1-vsementsov@virtuozzo.com> <20190923161231.22028-2-vsementsov@virtuozzo.com> From: Eric Blake Openpgp: preference=signencrypt Autocrypt: addr=eblake@redhat.com; keydata= xsBNBEvHyWwBCACw7DwsQIh0kAbUXyqhfiKAKOTVu6OiMGffw2w90Ggrp4bdVKmCaEXlrVLU xphBM8mb+wsFkU+pq9YR621WXo9REYVIl0FxKeQo9dyQBZ/XvmUMka4NOmHtFg74nvkpJFCD TUNzmqfcjdKhfFV0d7P/ixKQeZr2WP1xMcjmAQY5YvQ2lUoHP43m8TtpB1LkjyYBCodd+LkV GmCx2Bop1LSblbvbrOm2bKpZdBPjncRNob73eTpIXEutvEaHH72LzpzksfcKM+M18cyRH+nP sAd98xIbVjm3Jm4k4d5oQyE2HwOur+trk2EcxTgdp17QapuWPwMfhaNq3runaX7x34zhABEB AAHNHkVyaWMgQmxha2UgPGVibGFrZUByZWRoYXQuY29tPsLAegQTAQgAJAIbAwULCQgHAwUV CgkICwUWAgMBAAIeAQIXgAUCS8fL9QIZAQAKCRCnoWtKJSdDahBHCACbl/5FGkUqJ89GAjeX RjpAeJtdKhujir0iS4CMSIng7f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Message-ID: Date: Mon, 23 Sep 2019 14:58:10 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190923161231.22028-2-vsementsov@virtuozzo.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Mon, 23 Sep 2019 19:59:26 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Mon, 23 Sep 2019 16:51:49 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: stefanha@redhat.com, codyprime@gmail.com, jan.kiszka@siemens.com, berto@igalia.com, zhang.zhanghailiang@huawei.com, qemu-block@nongnu.org, arikalo@wavecomp.com, pasic@linux.ibm.com, hpoussin@reactos.org, anthony.perard@citrix.com, samuel.thibault@ens-lyon.org, philmd@redhat.com, green@moxielogic.com, lvivier@redhat.com, ehabkost@redhat.com, xiechanglong.d@gmail.com, pl@kamp.de, dgilbert@redhat.com, b.galvani@gmail.com, eric.auger@redhat.com, alex.williamson@redhat.com, ronniesahlberg@gmail.com, jsnow@redhat.com, rth@twiddle.net, kwolf@redhat.com, andrew@aj.id.au, crwulff@gmail.com, sundeep.lkml@gmail.com, michael@walle.cc, qemu-ppc@nongnu.org, kbastian@mail.uni-paderborn.de, imammedo@redhat.com, fam@euphon.net, peter.maydell@linaro.org, sheepdog@lists.wpkg.org, david@redhat.com, palmer@sifive.com, thuth@redhat.com, jcmvbkbc@gmail.com, den@openvz.org, hare@suse.com, sstabellini@kernel.org, arei.gonglei@huawei.com, namei.unix@gmail.com, atar4qemu@gmail.com, farman@linux.ibm.com, amit@kernel.org, sw@weilnetz.de, groug@kaod.org, qemu-s390x@nongnu.org, qemu-arm@nongnu.org, peter.chubb@nicta.com.au, clg@kaod.org, shorne@gmail.com, qemu-riscv@nongnu.org, cohuck@redhat.com, amarkovic@wavecomp.com, aurelien@aurel32.net, pburton@wavecomp.com, sagark@eecs.berkeley.edu, jasowang@redhat.com, kraxel@redhat.com, edgar.iglesias@gmail.com, gxt@mprc.pku.edu.cn, ari@tuxera.com, quintela@redhat.com, mdroth@linux.vnet.ibm.com, lersek@redhat.com, borntraeger@de.ibm.com, antonynpavlov@gmail.com, dillaman@redhat.com, joel@jms.id.au, xen-devel@lists.xenproject.org, integration@gluster.org, rjones@redhat.com, Andrew.Baumann@microsoft.com, mreitz@redhat.com, walling@linux.ibm.com, mst@redhat.com, mark.cave-ayland@ilande.co.uk, v.maffione@gmail.com, marex@denx.de, armbru@redhat.com, marcandre.lureau@redhat.com, alistair@alistair23.me, paul.durrant@citrix.com, pavel.dovgaluk@ispras.ru, g.lettieri@iet.unipi.it, rizzo@iet.unipi.it, david@gibson.dropbear.id.au, akrowiak@linux.ibm.com, berrange@redhat.com, xiaoguangrong.eric@gmail.com, pmorel@linux.ibm.com, wencongyang2@huawei.com, jcd@tribudubois.net, pbonzini@redhat.com, stefanb@linux.ibm.com Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 9/23/19 11:12 AM, Vladimir Sementsov-Ogievskiy wrote: > Here is introduced ERRP_FUNCTION_BEGIN macro, to be used at start of > any function with errp parameter. > > It has three goals: > > 1. Fix issue with error_fatal & error_append_hint: user can't see these > hints, because exit() happens in error_setg earlier than hint is > appended. [Reported by Greg Kurz] > > 2. Fix issue with error_abort & error_propagate: when we wrap > error_abort by local_err+error_propagate, resulting coredump will > refer to error_propagate and not to the place where error happened. > (the macro itself don't fix the issue, but it allows to [3.] drop all doesn't > local_err+error_propagate pattern, which will definitely fix the issue) > [Reported by Kevin Wolf] > > 3. Drop local_err+error_propagate pattern, which is used to workaround > void functions with errp parameter, when caller wants to know resulting > status. (Note: actually these functions should be merely updated to Maybe: s/should/could/ > return int error code). > > Signed-off-by: Vladimir Sementsov-Ogievskiy > --- > include/qapi/error.h | 37 +++++++++++++++++++++++++++++++++++++ > 1 file changed, 37 insertions(+) > > diff --git a/include/qapi/error.h b/include/qapi/error.h > index 3f95141a01..f6f4fa0fac 100644 > --- a/include/qapi/error.h > +++ b/include/qapi/error.h > @@ -322,6 +322,43 @@ void error_set_internal(Error **errp, > ErrorClass err_class, const char *fmt, ...) > GCC_FMT_ATTR(6, 7); > > +typedef struct ErrorPropagator { > + Error *local_err; > + Error **errp; > +} ErrorPropagator; > + > +static inline void error_propagator_cleanup(ErrorPropagator *prop) > +{ > + error_propagate(prop->errp, prop->local_err); > +} > + > +G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup); > + > +/* > + * ERRP_FUNCTION_BEGIN > + * > + * This macro MUST be the first line of EACH function with Error **errp > + * parameter. Maybe s/EACH function/ANY non-empty function/ (allowing our stub functions to be exemptions). > + * > + * If errp is NULL or points to error_fatal, it is rewritten to point to s/to/to a/ > + * local Error object, which will be automatically propagated to original s/to/to the/ > + * errp on function exit (see error_propagator_cleanup). > + * > + * After invocation of this macro it is always safe to dereference errp > + * (as it's not NULL anymore) and to append hint (by error_append_hint) s/append hint/append hints/ > + * (as, if it was error_fatal, we swapped it by local_error to be s/by local_error/with a local error/ > + * propagated on cleanup). > + * > + * Note: we don't wrap error_abort case, as we want resulting coredump > + * to point to the place where the error happened, not to error_propagate. s/wrap/wrap the/ > + */ > +#define ERRP_FUNCTION_BEGIN() \ > +g_auto(ErrorPropagator) __auto_errp_prop = {.errp = errp}; \ > +Error **__local_errp_unused __attribute__ ((unused)) = \ > + (errp = (errp == NULL || *errp == error_fatal ? \ > + &__auto_errp_prop.local_err : errp)) I'm not sold on why we need the dummy declaration (yeah, I know it's so that you don't have to fight the battle of mixing declarations and statements - but this is in a macro call whose usage LOOKS like a statement rather than a declaration, so we're already on fuzzy ground). We could make this macro expansion one line shorter and still be correct, but I'm not going to insist (we'll see what consensus is, and/or what Markus says). > + > + > /* > * Special error destination to abort on error. > * See error_setg() and error_propagate() for details. > -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org