From patchwork Fri Oct 11 16:04:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11186631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65FE414E5 for ; Sat, 12 Oct 2019 04:55:59 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 3F93D2089C for ; Sat, 12 Oct 2019 04:55:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F93D2089C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iJ9Pq-0003L8-FL; Sat, 12 Oct 2019 04:54:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxT6-0001Vw-BR for xen-devel@lists.xenproject.org; Fri, 11 Oct 2019 16:08:40 +0000 X-Inumbo-ID: 62b4505c-ec41-11e9-933c-12813bfff9fa Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 62b4505c-ec41-11e9-933c-12813bfff9fa; Fri, 11 Oct 2019 16:08:39 +0000 (UTC) Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQb-0003XG-BC; Fri, 11 Oct 2019 19:06:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 19:04:10 +0300 Message-Id: <20191011160552.22907-25-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 12 Oct 2019 04:54:04 +0000 Subject: [Xen-devel] [RFC v5 024/126] error: auto propagated local_err X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ronnie Sahlberg , Jeff Cody , Jan Kiszka , Eric Blake , Alberto Garcia , Hailiang Zhang , qemu-block@nongnu.org, Aleksandar Rikalo , Halil Pasic , =?utf-8?q?Herv=C3=A9_Poussineau?= , Anthony Perard , Samuel Thibault , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Anthony Green , Laurent Vivier , Eduardo Habkost , Xie Changlong , Peter Lieven , "Dr. David Alan Gilbert" , Beniamino Galvani , Eric Auger , Alex Williamson , Stefan Hajnoczi , John Snow , Richard Henderson , Kevin Wolf , vsementsov@virtuozzo.com, Andrew Jeffery , Chris Wulff , Subbaraya Sundeep , Michael Walle , qemu-ppc@nongnu.org, Bastian Koppelmann , Igor Mammedov , Fam Zheng , Peter Maydell , sheepdog@lists.wpkg.org, Matthew Rosato , David Hildenbrand , Palmer Dabbelt , Thomas Huth , Max Filippov , "Denis V. Lunev" , Hannes Reinecke , Stefano Stabellini , "Gonglei \(Arei\)" , Marcel Apfelbaum , Liu Yuan , Artyom Tarasenko , Eric Farman , Amit Shah , Stefan Weil , Greg Kurz , Yuval Shaia , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Peter Chubb , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Stafford Horne , qemu-riscv@nongnu.org, Cornelia Huck , Aleksandar Markovic , Aurelien Jarno , Paul Burton , Sagar Karandikar , Paul Durrant , Jason Wang , Gerd Hoffmann , "Edgar E. Iglesias" , Guan Xuetao , Ari Sundholm , Juan Quintela , Michael Roth , Christian Borntraeger , Joel Stanley , Jason Dillaman , Antony Pavlov , xen-devel@lists.xenproject.org, integration@gluster.org, Laszlo Ersek , "Richard W.M. Jones" , Andrew Baumann , Max Reitz , "Michael S. Tsirkin" , Mark Cave-Ayland , Vincenzo Maffione , Marek Vasut , armbru@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Alistair Francis , Pavel Dovgalyuk , Giuseppe Lettieri , Luigi Rizzo , David Gibson , Tony Krowiak , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Xiao Guangrong , Pierre Morel , Wen Congyang , Jean-Christophe Dubois , Paolo Bonzini , Stefan Berger Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter. It has three goals: 1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [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 doesn't fix the issue, but it allows to [3.] drop all 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 could be merely updated to return int error code). To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Marc-André Lureau --- CC: Gerd Hoffmann CC: "Gonglei (Arei)" CC: Eduardo Habkost CC: Igor Mammedov CC: Laurent Vivier CC: Amit Shah CC: Kevin Wolf CC: Max Reitz CC: John Snow CC: Ari Sundholm CC: Pavel Dovgalyuk CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Fam Zheng CC: Stefan Weil CC: Ronnie Sahlberg CC: Peter Lieven CC: Eric Blake CC: "Denis V. Lunev" CC: Markus Armbruster CC: Alberto Garcia CC: Jason Dillaman CC: Wen Congyang CC: Xie Changlong CC: Liu Yuan CC: "Richard W.M. Jones" CC: Jeff Cody CC: "Marc-André Lureau" CC: "Daniel P. Berrangé" CC: Richard Henderson CC: Greg Kurz CC: "Michael S. Tsirkin" CC: Marcel Apfelbaum CC: Beniamino Galvani CC: Peter Maydell CC: "Cédric Le Goater" CC: Andrew Jeffery CC: Joel Stanley CC: Andrew Baumann CC: "Philippe Mathieu-Daudé" CC: Antony Pavlov CC: Jean-Christophe Dubois CC: Peter Chubb CC: Subbaraya Sundeep CC: Eric Auger CC: Alistair Francis CC: "Edgar E. Iglesias" CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: Paul Burton CC: Aleksandar Rikalo CC: Chris Wulff CC: Marek Vasut CC: David Gibson CC: Cornelia Huck CC: Halil Pasic CC: Christian Borntraeger CC: "Hervé Poussineau" CC: Xiao Guangrong CC: Aurelien Jarno CC: Aleksandar Markovic CC: Mark Cave-Ayland CC: Jason Wang CC: Laszlo Ersek CC: Yuval Shaia CC: Palmer Dabbelt CC: Sagar Karandikar CC: Bastian Koppelmann CC: David Hildenbrand CC: Thomas Huth CC: Eric Farman CC: Matthew Rosato CC: Hannes Reinecke CC: Michael Walle CC: Artyom Tarasenko CC: Stefan Berger CC: Samuel Thibault CC: Alex Williamson CC: Tony Krowiak CC: Pierre Morel CC: Michael Roth CC: Hailiang Zhang CC: Juan Quintela CC: "Dr. David Alan Gilbert" CC: Luigi Rizzo CC: Giuseppe Lettieri CC: Vincenzo Maffione CC: Jan Kiszka CC: Anthony Green CC: Stafford Horne CC: Guan Xuetao CC: Max Filippov CC: qemu-block@nongnu.org CC: integration@gluster.org CC: sheepdog@lists.wpkg.org CC: qemu-arm@nongnu.org CC: xen-devel@lists.xenproject.org CC: qemu-ppc@nongnu.org CC: qemu-s390x@nongnu.org CC: qemu-riscv@nongnu.org include/qapi/error.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/qapi/error.h b/include/qapi/error.h index d6898d833b..47238d9065 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -345,6 +345,44 @@ 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_AUTO_PROPAGATE + * + * This macro is created to be the first line of a function with Error **errp + * OUT parameter. It's needed only in cases where we want to use error_prepend, + * error_append_hint or dereference *errp. It's still safe (but useless) in + * other cases. + * + * If errp is NULL or points to error_fatal, it is rewritten to point to a + * local Error object, which will be automatically propagated to the original + * 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 add information (by error_prepend or + * error_append_hint) + * (as, if it was error_fatal, we swapped it with a local_error to be + * propagated on cleanup). + * + * Note: we don't wrap the error_abort case, as we want resulting coredump + * to point to the place where the error happened, not to error_propagate. + */ +#define ERRP_AUTO_PROPAGATE() \ + g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp}; \ + errp = ((errp == NULL || *errp == error_fatal) \ + ? &_auto_errp_prop.local_err : errp) + /* * Special error destination to abort on error. * See error_setg() and error_propagate() for details. From patchwork Fri Oct 11 16:04:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11186629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 472F71709 for ; Sat, 12 Oct 2019 04:55:56 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 21D4D20659 for ; Sat, 12 Oct 2019 04:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 21D4D20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iJ9Pq-0003L2-6N; Sat, 12 Oct 2019 04:54:06 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxSw-0001Tg-V9 for xen-devel@lists.xenproject.org; Fri, 11 Oct 2019 16:08:30 +0000 X-Inumbo-ID: 5cc167fc-ec41-11e9-8aca-bc764e2007e4 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5cc167fc-ec41-11e9-8aca-bc764e2007e4; Fri, 11 Oct 2019 16:08:29 +0000 (UTC) Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQb-0003XG-IB; Fri, 11 Oct 2019 19:06:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 19:04:11 +0300 Message-Id: <20191011160552.22907-26-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 12 Oct 2019 04:54:04 +0000 Subject: [Xen-devel] [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ronnie Sahlberg , Jeff Cody , Jan Kiszka , Eric Blake , Alberto Garcia , Hailiang Zhang , qemu-block@nongnu.org, Aleksandar Rikalo , Halil Pasic , =?utf-8?q?Herv=C3=A9_Poussineau?= , Anthony Perard , Samuel Thibault , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Anthony Green , Laurent Vivier , Eduardo Habkost , Xie Changlong , Peter Lieven , "Dr. David Alan Gilbert" , Beniamino Galvani , Eric Auger , Alex Williamson , Stefan Hajnoczi , John Snow , Richard Henderson , Kevin Wolf , vsementsov@virtuozzo.com, Andrew Jeffery , Chris Wulff , Subbaraya Sundeep , Michael Walle , qemu-ppc@nongnu.org, Bastian Koppelmann , Igor Mammedov , Fam Zheng , Peter Maydell , sheepdog@lists.wpkg.org, Matthew Rosato , David Hildenbrand , Palmer Dabbelt , Thomas Huth , Max Filippov , "Denis V. Lunev" , Hannes Reinecke , Stefano Stabellini , "Gonglei \(Arei\)" , Marcel Apfelbaum , Liu Yuan , Artyom Tarasenko , Eric Farman , Amit Shah , Stefan Weil , Greg Kurz , Yuval Shaia , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Peter Chubb , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Stafford Horne , qemu-riscv@nongnu.org, Cornelia Huck , Aleksandar Markovic , Aurelien Jarno , Paul Burton , Sagar Karandikar , Paul Durrant , Jason Wang , Gerd Hoffmann , "Edgar E. Iglesias" , Guan Xuetao , Ari Sundholm , Juan Quintela , Michael Roth , Christian Borntraeger , Joel Stanley , Jason Dillaman , Antony Pavlov , xen-devel@lists.xenproject.org, integration@gluster.org, Laszlo Ersek , "Richard W.M. Jones" , Andrew Baumann , Max Reitz , "Michael S. Tsirkin" , Mark Cave-Ayland , Vincenzo Maffione , Marek Vasut , armbru@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Alistair Francis , Pavel Dovgalyuk , Giuseppe Lettieri , Luigi Rizzo , David Gibson , Tony Krowiak , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Xiao Guangrong , Pierre Morel , Wen Congyang , Jean-Christophe Dubois , Paolo Bonzini , Stefan Berger Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Vladimir Sementsov-Ogievskiy --- CC: Gerd Hoffmann CC: "Gonglei (Arei)" CC: Eduardo Habkost CC: Igor Mammedov CC: Laurent Vivier CC: Amit Shah CC: Kevin Wolf CC: Max Reitz CC: John Snow CC: Ari Sundholm CC: Pavel Dovgalyuk CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Fam Zheng CC: Stefan Weil CC: Ronnie Sahlberg CC: Peter Lieven CC: Eric Blake CC: "Denis V. Lunev" CC: Markus Armbruster CC: Alberto Garcia CC: Jason Dillaman CC: Wen Congyang CC: Xie Changlong CC: Liu Yuan CC: "Richard W.M. Jones" CC: Jeff Cody CC: "Marc-André Lureau" CC: "Daniel P. Berrangé" CC: Richard Henderson CC: Greg Kurz CC: "Michael S. Tsirkin" CC: Marcel Apfelbaum CC: Beniamino Galvani CC: Peter Maydell CC: "Cédric Le Goater" CC: Andrew Jeffery CC: Joel Stanley CC: Andrew Baumann CC: "Philippe Mathieu-Daudé" CC: Antony Pavlov CC: Jean-Christophe Dubois CC: Peter Chubb CC: Subbaraya Sundeep CC: Eric Auger CC: Alistair Francis CC: "Edgar E. Iglesias" CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: Paul Burton CC: Aleksandar Rikalo CC: Chris Wulff CC: Marek Vasut CC: David Gibson CC: Cornelia Huck CC: Halil Pasic CC: Christian Borntraeger CC: "Hervé Poussineau" CC: Xiao Guangrong CC: Aurelien Jarno CC: Aleksandar Markovic CC: Mark Cave-Ayland CC: Jason Wang CC: Laszlo Ersek CC: Yuval Shaia CC: Palmer Dabbelt CC: Sagar Karandikar CC: Bastian Koppelmann CC: David Hildenbrand CC: Thomas Huth CC: Eric Farman CC: Matthew Rosato CC: Hannes Reinecke CC: Michael Walle CC: Artyom Tarasenko CC: Stefan Berger CC: Samuel Thibault CC: Alex Williamson CC: Tony Krowiak CC: Pierre Morel CC: Michael Roth CC: Hailiang Zhang CC: Juan Quintela CC: "Dr. David Alan Gilbert" CC: Luigi Rizzo CC: Giuseppe Lettieri CC: Vincenzo Maffione CC: Jan Kiszka CC: Anthony Green CC: Stafford Horne CC: Guan Xuetao CC: Max Filippov CC: qemu-block@nongnu.org CC: integration@gluster.org CC: sheepdog@lists.wpkg.org CC: qemu-arm@nongnu.org CC: xen-devel@lists.xenproject.org CC: qemu-ppc@nongnu.org CC: qemu-s390x@nongnu.org CC: qemu-riscv@nongnu.org scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci diff --git a/scripts/coccinelle/auto-propagated-errp.cocci b/scripts/coccinelle/auto-propagated-errp.cocci new file mode 100644 index 0000000000..d9731620aa --- /dev/null +++ b/scripts/coccinelle/auto-propagated-errp.cocci @@ -0,0 +1,118 @@ +@rule0@ +// Add invocation to errp-functions where necessary +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { ++ ERRP_AUTO_PROPAGATE(); + <+... +( + error_append_hint(errp, ...); +| + error_prepend(errp, ...); +| + Error *local_err = NULL; +) + ...+> + } + +@@ +// Drop doubled invocation +identifier rule0.fn; +@@ + + fn(...) +{ +- ERRP_AUTO_PROPAGATE(); + ERRP_AUTO_PROPAGATE(); + ... +} + +@rule1@ +// Drop local_err +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { + <... +- Error *local_err = NULL; + ...> + } + +@@ +// Handle pattern with goto, otherwise we'll finish up +// with labels at function end which will not compile. +identifier rule1.fn; +identifier rule1.local_err; +identifier OUT; +@@ + + fn(...) + { + <... +- goto OUT; ++ return; + ...> +- OUT: +- error_propagate(errp, local_err); + } + +@@ +identifier rule1.fn; +identifier rule1.local_err; +@@ + + fn(...) + { + <... +( +- error_free(local_err); +- local_err = NULL; ++ error_free_errp(errp); +| +- error_free(local_err); ++ error_free_errp(errp); +| +- error_report_err(local_err); ++ error_report_errp(errp); +| +- warn_report_err(local_err); ++ warn_report_errp(errp); +| +- error_propagate_prepend(errp, local_err, ++ error_prepend(errp, + ...); +| +- error_propagate(errp, local_err); +) + ...> + } + +@@ +identifier rule1.fn; +identifier rule1.local_err; +@@ + + fn(...) + { + <... +( +- &local_err ++ errp +| +- local_err ++ *errp +) + ...> + } + +@@ +symbol errp; +@@ + +- *errp != NULL ++ *errp From patchwork Fri Oct 11 16:04:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11186627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D690814DB for ; Sat, 12 Oct 2019 04:55:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 B0A2C20659 for ; Sat, 12 Oct 2019 04:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0A2C20659 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iJ9Pp-0003Kq-Jr; Sat, 12 Oct 2019 04:54:05 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxSh-0001Sf-6c for xen-devel@lists.xenproject.org; Fri, 11 Oct 2019 16:08:15 +0000 X-Inumbo-ID: 534cfc7c-ec41-11e9-bbab-bc764e2007e4 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 534cfc7c-ec41-11e9-bbab-bc764e2007e4; Fri, 11 Oct 2019 16:08:13 +0000 (UTC) Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQb-0003XG-Ro; Fri, 11 Oct 2019 19:06:05 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 19:04:12 +0300 Message-Id: <20191011160552.22907-27-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 12 Oct 2019 04:54:04 +0000 Subject: [Xen-devel] [RFC v5 026/126] python: add commit-per-subsystem.py X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ronnie Sahlberg , Jeff Cody , Jan Kiszka , Eric Blake , Alberto Garcia , Hailiang Zhang , qemu-block@nongnu.org, Aleksandar Rikalo , Halil Pasic , =?utf-8?q?Herv=C3=A9_Poussineau?= , Anthony Perard , Samuel Thibault , =?utf-8?q?Philippe_Mathieu-?= =?utf-8?q?Daud=C3=A9?= , Anthony Green , Laurent Vivier , Eduardo Habkost , Xie Changlong , Peter Lieven , "Dr. David Alan Gilbert" , Beniamino Galvani , Eric Auger , Alex Williamson , Stefan Hajnoczi , John Snow , Richard Henderson , Kevin Wolf , vsementsov@virtuozzo.com, Andrew Jeffery , Chris Wulff , Subbaraya Sundeep , Michael Walle , qemu-ppc@nongnu.org, Bastian Koppelmann , Igor Mammedov , Fam Zheng , Peter Maydell , sheepdog@lists.wpkg.org, Matthew Rosato , David Hildenbrand , Palmer Dabbelt , Thomas Huth , Max Filippov , "Denis V. Lunev" , Hannes Reinecke , Stefano Stabellini , "Gonglei \(Arei\)" , Marcel Apfelbaum , Liu Yuan , Artyom Tarasenko , Eric Farman , Amit Shah , Stefan Weil , Greg Kurz , Yuval Shaia , qemu-s390x@nongnu.org, qemu-arm@nongnu.org, Peter Chubb , =?utf-8?q?C?= =?utf-8?q?=C3=A9dric_Le_Goater?= , Stafford Horne , qemu-riscv@nongnu.org, Cornelia Huck , Aleksandar Markovic , Aurelien Jarno , Paul Burton , Sagar Karandikar , Paul Durrant , Jason Wang , Gerd Hoffmann , "Edgar E. Iglesias" , Guan Xuetao , Ari Sundholm , Juan Quintela , Michael Roth , Christian Borntraeger , Joel Stanley , Jason Dillaman , Antony Pavlov , xen-devel@lists.xenproject.org, integration@gluster.org, Laszlo Ersek , "Richard W.M. Jones" , Andrew Baumann , Max Reitz , "Michael S. Tsirkin" , Mark Cave-Ayland , Vincenzo Maffione , Marek Vasut , armbru@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Alistair Francis , Pavel Dovgalyuk , Giuseppe Lettieri , Luigi Rizzo , David Gibson , Tony Krowiak , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Xiao Guangrong , Pierre Morel , Wen Congyang , Jean-Christophe Dubois , Paolo Bonzini , Stefan Berger Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Add script to automatically commit tree-wide changes per-subsystem. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Aleksandar Markovic --- CC: Gerd Hoffmann CC: "Gonglei (Arei)" CC: Eduardo Habkost CC: Igor Mammedov CC: Laurent Vivier CC: Amit Shah CC: Kevin Wolf CC: Max Reitz CC: John Snow CC: Ari Sundholm CC: Pavel Dovgalyuk CC: Paolo Bonzini CC: Stefan Hajnoczi CC: Fam Zheng CC: Stefan Weil CC: Ronnie Sahlberg CC: Peter Lieven CC: Eric Blake CC: "Denis V. Lunev" CC: Markus Armbruster CC: Alberto Garcia CC: Jason Dillaman CC: Wen Congyang CC: Xie Changlong CC: Liu Yuan CC: "Richard W.M. Jones" CC: Jeff Cody CC: "Marc-André Lureau" CC: "Daniel P. Berrangé" CC: Richard Henderson CC: Greg Kurz CC: "Michael S. Tsirkin" CC: Marcel Apfelbaum CC: Beniamino Galvani CC: Peter Maydell CC: "Cédric Le Goater" CC: Andrew Jeffery CC: Joel Stanley CC: Andrew Baumann CC: "Philippe Mathieu-Daudé" CC: Antony Pavlov CC: Jean-Christophe Dubois CC: Peter Chubb CC: Subbaraya Sundeep CC: Eric Auger CC: Alistair Francis CC: "Edgar E. Iglesias" CC: Stefano Stabellini CC: Anthony Perard CC: Paul Durrant CC: Paul Burton CC: Aleksandar Rikalo CC: Chris Wulff CC: Marek Vasut CC: David Gibson CC: Cornelia Huck CC: Halil Pasic CC: Christian Borntraeger CC: "Hervé Poussineau" CC: Xiao Guangrong CC: Aurelien Jarno CC: Aleksandar Markovic CC: Mark Cave-Ayland CC: Jason Wang CC: Laszlo Ersek CC: Yuval Shaia CC: Palmer Dabbelt CC: Sagar Karandikar CC: Bastian Koppelmann CC: David Hildenbrand CC: Thomas Huth CC: Eric Farman CC: Matthew Rosato CC: Hannes Reinecke CC: Michael Walle CC: Artyom Tarasenko CC: Stefan Berger CC: Samuel Thibault CC: Alex Williamson CC: Tony Krowiak CC: Pierre Morel CC: Michael Roth CC: Hailiang Zhang CC: Juan Quintela CC: "Dr. David Alan Gilbert" CC: Luigi Rizzo CC: Giuseppe Lettieri CC: Vincenzo Maffione CC: Jan Kiszka CC: Anthony Green CC: Stafford Horne CC: Guan Xuetao CC: Max Filippov CC: qemu-block@nongnu.org CC: integration@gluster.org CC: sheepdog@lists.wpkg.org CC: qemu-arm@nongnu.org CC: xen-devel@lists.xenproject.org CC: qemu-ppc@nongnu.org CC: qemu-s390x@nongnu.org CC: qemu-riscv@nongnu.org python/commit-per-subsystem.py | 204 +++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100755 python/commit-per-subsystem.py diff --git a/python/commit-per-subsystem.py b/python/commit-per-subsystem.py new file mode 100755 index 0000000000..2ccf84cb15 --- /dev/null +++ b/python/commit-per-subsystem.py @@ -0,0 +1,204 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2019 Virtuozzo International GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import subprocess +import sys +import os +import glob + + +def git_add(pattern): + subprocess.run(['git', 'add', pattern]) + + +def git_commit(msg): + subprocess.run(['git', 'commit', '-m', msg], capture_output=True) + + +def git_changed_files(): + ret = subprocess.check_output(['git', 'diff', '--name-only'], encoding='utf-8').split('\n') + if ret[-1] == '': + del ret[-1] + return ret + + +maintainers = sys.argv[1] +message = sys.argv[2].strip() + +subsystem = None + +remap = { + 'Block layer core': 'block', + 'Block Jobs': 'block', + 'Dirty Bitmaps': 'block', + 'Block QAPI, monitor, command line': 'block', + 'Block I/O path': 'block', + 'Throttling infrastructure': 'block', + 'Architecture support': 's390x', + 'Guest CPU Cores (KVM)': 'kvm', + 'Guest CPU Cores (Xen)': 'xen', + 'Guest CPU cores (TCG)': 'tcg', + 'Network Block Device (NBD)': 'nbd', + 'Parallel NOR Flash devices': 'pflash', + 'Firmware configuration (fw_cfg)': 'fw_cfg', + 'Block SCSI subsystem': 'scsi', + 'Network device backends': 'net', + 'Netmap network backend': 'net', + 'Host Memory Backends': 'hostmem', + 'Cryptodev Backends': 'cryptodev', + 'QEMU Guest Agent': 'qga', + 'COLO Framework': 'colo', + 'Command line option argument parsing': 'cmdline', + 'Character device backends': 'chardev' +} + + +class Maintainers: + def add(self, subsystem, path, mapper, mapper_name, glob_count=1): + if subsystem in remap: + subsystem = remap[subsystem] + if subsystem not in self.subsystems: + self.subsystems.append(subsystem) + + if path[-1] == '/': + path = path[:-1] + + if path in mapper: + if mapper[path][1] == glob_count: + print('Warning: "{}" both in "{}" and "{}" in {} mapper with ' + 'same glob-count={}. {} ignored for this path.'.format( + path, mapper[path][0], subsystem, mapper_name, glob_count, + subsystem)) + return + if mapper[path][1] < glob_count: + # silently ignore worse match + return + + mapper[path] = (subsystem, glob_count) + + def __init__(self, file_name): + self.map_file = {} + self.map_glob_file = {} + self.map_dir = {} + self.map_glob_dir = {} + self.map_unmaintained_dir = { + 'python': ('python', 1), + 'hw/misc': ('misc', 1) + } + self.subsystems = ['python', 'misc'] + subsystem = None + + with open(file_name) as f: + mode2 = False + prevline = '' + for line in f: + line = line.rstrip() + if not line: + continue + if len(line) >= 2 and line[1] == ':': + if line[0] == 'F': + fname = line[3:] + if fname in ['*', '*/']: + continue + if os.path.isfile(fname): + self.add(subsystem, fname, self.map_file, 'file') + elif os.path.isdir(fname): + self.add(subsystem, fname, self.map_dir, 'dir') + else: + paths = glob.glob(fname) + if not paths: + print('Warning: nothing corresponds to "{}"'.format(fname)) + continue + + n = len(paths) + for f in paths: + if os.path.isfile(f): + self.add(subsystem, f, self.map_glob_file, 'glob-file', n) + else: + assert os.path.isdir(f) + self.add(subsystem, f, self.map_glob_dir, 'glob-dir', n) + elif line[:3] == '---': + subsystem = prevline + if subsystem == 'Devices': + mode2 = True + elif mode2: + subsystem = line + prevline = line + + def find_in_map_dir(self, file_name, mapper): + while file_name != '' and file_name not in mapper: + file_name = os.path.dirname(file_name) + + return None if file_name == '' else mapper[file_name][0] + + def find_in_map_file(self, file_name, mapper): + if file_name in mapper: + return mapper[file_name][0] + + def find_subsystem(self, file_name): + s = self.find_in_map_file(file_name, self.map_file) + if s is not None: + return s + + s = self.find_in_map_file(file_name, self.map_glob_file) + if s is not None: + return s + + s = self.find_in_map_dir(file_name, self.map_dir) + if s is not None: + return s + + s = self.find_in_map_dir(file_name, self.map_glob_dir) + if s is not None: + return s + + s = self.find_in_map_dir(file_name, self.map_unmaintained_dir) + if s is not None: + return s + + self.subsystems.append(file_name) + return file_name + + +def commit(subsystem): + msg = subsystem + if msg in remap: + msg = remap[msg] + msg += ': ' + message + git_commit(msg) + +mnt = Maintainers(maintainers) +res = {} +for f in git_changed_files(): + s = mnt.find_subsystem(f) + if s in res: + res[s].append(f) + else: + res[s] = [f] + +for s in mnt.subsystems: + if s in res: + print(s) + for f in res[s]: + print(' ', f) + +for s in mnt.subsystems: + if s in res: + for f in res[s]: + git_add(f) + commit(s) From patchwork Fri Oct 11 16:04:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 11185813 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1850A912 for ; Fri, 11 Oct 2019 16:08:19 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 DB24B206CD for ; Fri, 11 Oct 2019 16:08:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB24B206CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxR5-0001BL-KP; Fri, 11 Oct 2019 16:06:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iIxR4-0001BE-CU for xen-devel@lists.xenproject.org; Fri, 11 Oct 2019 16:06:34 +0000 X-Inumbo-ID: 171e0912-ec41-11e9-933c-12813bfff9fa Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 171e0912-ec41-11e9-933c-12813bfff9fa; Fri, 11 Oct 2019 16:06:32 +0000 (UTC) Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQd-0003XG-Ez; Fri, 11 Oct 2019 19:06:07 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 11 Oct 2019 19:04:17 +0300 Message-Id: <20191011160552.22907-32-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC v5 031/126] xen: introduce ERRP_AUTO_PROPAGATE X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, qemu-block@nongnu.org, Paul Durrant , armbru@redhat.com, Greg Kurz , Stefano Stabellini , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, Max Reitz Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy Acked-by: Anthony PERARD --- hw/block/dataplane/xen-block.c | 17 ++--- hw/block/xen-block.c | 119 ++++++++++++++------------------- hw/xen/xen-backend.c | 7 +- hw/xen/xen-bus.c | 92 ++++++++++++------------- hw/xen/xen-host-pci-device.c | 27 ++++---- hw/xen/xen_pt.c | 25 +++---- hw/xen/xen_pt_config_init.c | 20 +++--- 7 files changed, 139 insertions(+), 168 deletions(-) diff --git a/hw/block/dataplane/xen-block.c b/hw/block/dataplane/xen-block.c index 3b9caeb2fa..c38e3c3d85 100644 --- a/hw/block/dataplane/xen-block.c +++ b/hw/block/dataplane/xen-block.c @@ -727,8 +727,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, unsigned int protocol, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev = dataplane->xendev; - Error *local_err = NULL; unsigned int ring_size; unsigned int i; @@ -764,9 +764,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, } xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } @@ -774,9 +773,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, dataplane->ring_ref, dataplane->nr_ring_ref, PROT_READ | PROT_WRITE, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } @@ -809,9 +807,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane, dataplane->event_channel = xen_device_bind_event_channel(xendev, dataplane->ctx, event_channel, xen_block_dataplane_event, dataplane, - &local_err); - if (local_err) { - error_propagate(errp, local_err); + errp); + if (*errp) { goto stop; } diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 879fc310a4..8f4165edd9 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -194,6 +194,7 @@ static const BlockDevOps xen_block_dev_ops = { static void xen_block_realize(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev); XenBlockDeviceClass *blockdev_class = XEN_BLOCK_DEVICE_GET_CLASS(xendev); @@ -201,7 +202,6 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) XenBlockVdev *vdev = &blockdev->props.vdev; BlockConf *conf = &blockdev->props.conf; BlockBackend *blk = conf->blk; - Error *local_err = NULL; if (vdev->type == XEN_BLOCK_VDEV_TYPE_INVALID) { error_setg(errp, "vdev property not set"); @@ -211,9 +211,8 @@ static void xen_block_realize(XenDevice *xendev, Error **errp) trace_xen_block_realize(type, vdev->disk, vdev->partition); if (blockdev_class->realize) { - blockdev_class->realize(blockdev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + blockdev_class->realize(blockdev, errp); + if (*errp) { return; } } @@ -283,8 +282,8 @@ static void xen_block_frontend_changed(XenDevice *xendev, enum xenbus_state frontend_state, Error **errp) { + ERRP_AUTO_PROPAGATE(); enum xenbus_state backend_state = xen_device_backend_get_state(xendev); - Error *local_err = NULL; switch (frontend_state) { case XenbusStateInitialised: @@ -293,15 +292,13 @@ static void xen_block_frontend_changed(XenDevice *xendev, break; } - xen_block_disconnect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_disconnect(xendev, errp); + if (*errp) { break; } - xen_block_connect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_connect(xendev, errp); + if (*errp) { break; } @@ -314,9 +311,8 @@ static void xen_block_frontend_changed(XenDevice *xendev, case XenbusStateClosed: case XenbusStateUnknown: - xen_block_disconnect(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_disconnect(xendev, errp); + if (*errp) { break; } @@ -403,10 +399,10 @@ static int vbd_name_to_disk(const char *name, const char **endp, static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *dev = DEVICE(obj); Property *prop = opaque; XenBlockVdev *vdev = qdev_get_prop_ptr(dev, prop); - Error *local_err = NULL; char *str, *p; const char *end; @@ -415,9 +411,8 @@ static void xen_block_set_vdev(Object *obj, Visitor *v, const char *name, return; } - visit_type_str(v, name, &str, &local_err); - if (local_err) { - error_propagate(errp, local_err); + visit_type_str(v, name, &str, errp); + if (*errp) { return; } @@ -671,9 +666,9 @@ static void xen_block_blockdev_del(const char *node_name, Error **errp) static char *xen_block_blockdev_add(const char *id, QDict *qdict, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *driver = qdict_get_try_str(qdict, "driver"); BlockdevOptions *options = NULL; - Error *local_err = NULL; char *node_name; Visitor *v; @@ -688,18 +683,16 @@ static char *xen_block_blockdev_add(const char *id, QDict *qdict, trace_xen_block_blockdev_add(node_name); v = qobject_input_visitor_new(QOBJECT(qdict)); - visit_type_BlockdevOptions(v, NULL, &options, &local_err); + visit_type_BlockdevOptions(v, NULL, &options, errp); visit_free(v); - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { goto fail; } - qmp_blockdev_add(options, &local_err); + qmp_blockdev_add(options, errp); - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { goto fail; } @@ -718,14 +711,12 @@ fail: static void xen_block_drive_destroy(XenBlockDrive *drive, Error **errp) { + ERRP_AUTO_PROPAGATE(); char *node_name = drive->node_name; if (node_name) { - Error *local_err = NULL; - - xen_block_blockdev_del(node_name, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_block_blockdev_del(node_name, errp); + if (*errp) { return; } g_free(node_name); @@ -739,6 +730,7 @@ static XenBlockDrive *xen_block_drive_create(const char *id, const char *device_type, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *params = qdict_get_try_str(opts, "params"); const char *mode = qdict_get_try_str(opts, "mode"); const char *direct_io_safe = qdict_get_try_str(opts, "direct-io-safe"); @@ -746,7 +738,6 @@ static XenBlockDrive *xen_block_drive_create(const char *id, char *driver = NULL; char *filename = NULL; XenBlockDrive *drive = NULL; - Error *local_err = NULL; QDict *file_layer; QDict *driver_layer; @@ -825,13 +816,12 @@ static XenBlockDrive *xen_block_drive_create(const char *id, g_assert(!drive->node_name); drive->node_name = xen_block_blockdev_add(drive->id, driver_layer, - &local_err); + errp); qobject_unref(driver_layer); done: - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { xen_block_drive_destroy(drive, NULL); return NULL; } @@ -856,15 +846,13 @@ static void xen_block_iothread_destroy(XenBlockIOThread *iothread, static XenBlockIOThread *xen_block_iothread_create(const char *id, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBlockIOThread *iothread = g_new(XenBlockIOThread, 1); - Error *local_err = NULL; iothread->id = g_strdup(id); - qmp_object_add(TYPE_IOTHREAD, id, false, NULL, &local_err); - if (local_err) { - error_propagate(errp, local_err); - + qmp_object_add(TYPE_IOTHREAD, id, false, NULL, errp); + if (*errp) { g_free(iothread->id); g_free(iothread); return NULL; @@ -876,6 +864,7 @@ static XenBlockIOThread *xen_block_iothread_create(const char *id, static void xen_block_device_create(XenBackendInstance *backend, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus = xen_backend_get_bus(backend); const char *name = xen_backend_get_name(backend); unsigned long number; @@ -883,7 +872,6 @@ static void xen_block_device_create(XenBackendInstance *backend, XenBlockDrive *drive = NULL; XenBlockIOThread *iothread = NULL; XenDevice *xendev = NULL; - Error *local_err = NULL; const char *type; XenBlockDevice *blockdev; @@ -915,15 +903,15 @@ static void xen_block_device_create(XenBackendInstance *backend, goto fail; } - drive = xen_block_drive_create(vdev, device_type, opts, &local_err); + drive = xen_block_drive_create(vdev, device_type, opts, errp); if (!drive) { - error_propagate_prepend(errp, local_err, "failed to create drive: "); + error_prepend(errp, "failed to create drive: "); goto fail; } - iothread = xen_block_iothread_create(vdev, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + iothread = xen_block_iothread_create(vdev, errp); + if (*errp) { + error_prepend(errp, "failed to create iothread: "); goto fail; } @@ -931,24 +919,24 @@ static void xen_block_device_create(XenBackendInstance *backend, xendev = XEN_DEVICE(qdev_create(BUS(xenbus), type)); blockdev = XEN_BLOCK_DEVICE(xendev); - object_property_set_str(OBJECT(xendev), vdev, "vdev", &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "failed to set 'vdev': "); + object_property_set_str(OBJECT(xendev), vdev, "vdev", errp); + if (*errp) { + error_prepend(errp, "failed to set 'vdev': "); goto fail; } object_property_set_str(OBJECT(xendev), xen_block_drive_get_node_name(drive), "drive", - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, "failed to set 'drive': "); + errp); + if (*errp) { + error_prepend(errp, "failed to set 'drive': "); goto fail; } object_property_set_str(OBJECT(xendev), iothread->id, "iothread", - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + errp); + if (*errp) { + error_prepend(errp, "failed to set 'iothread': "); goto fail; } @@ -956,9 +944,9 @@ static void xen_block_device_create(XenBackendInstance *backend, blockdev->iothread = iothread; blockdev->drive = drive; - object_property_set_bool(OBJECT(xendev), true, "realized", &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + object_property_set_bool(OBJECT(xendev), true, "realized", errp); + if (*errp) { + error_prepend(errp, "realization of device %s failed: ", type); goto fail; @@ -984,6 +972,7 @@ fail: static void xen_block_device_destroy(XenBackendInstance *backend, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev = xen_backend_get_device(backend); XenBlockDevice *blockdev = XEN_BLOCK_DEVICE(xendev); XenBlockVdev *vdev = &blockdev->props.vdev; @@ -995,22 +984,18 @@ static void xen_block_device_destroy(XenBackendInstance *backend, object_unparent(OBJECT(xendev)); if (iothread) { - Error *local_err = NULL; - - xen_block_iothread_destroy(iothread, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + xen_block_iothread_destroy(iothread, errp); + if (*errp) { + error_prepend(errp, "failed to destroy iothread: "); return; } } if (drive) { - Error *local_err = NULL; - - xen_block_drive_destroy(drive, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + xen_block_drive_destroy(drive, errp); + if (*errp) { + error_prepend(errp, "failed to destroy drive: "); } } diff --git a/hw/xen/xen-backend.c b/hw/xen/xen-backend.c index da065f81b7..1cc0694053 100644 --- a/hw/xen/xen-backend.c +++ b/hw/xen/xen-backend.c @@ -98,9 +98,9 @@ static void xen_backend_list_remove(XenBackendInstance *backend) void xen_backend_device_create(XenBus *xenbus, const char *type, const char *name, QDict *opts, Error **errp) { + ERRP_AUTO_PROPAGATE(); const XenBackendImpl *impl = xen_backend_table_lookup(type); XenBackendInstance *backend; - Error *local_error = NULL; if (!impl) { return; @@ -110,9 +110,8 @@ void xen_backend_device_create(XenBus *xenbus, const char *type, backend->xenbus = xenbus; backend->name = g_strdup(name); - impl->create(backend, opts, &local_error); - if (local_error) { - error_propagate(errp, local_error); + impl->create(backend, opts, errp); + if (*errp) { g_free(backend->name); g_free(backend); return; diff --git a/hw/xen/xen-bus.c b/hw/xen/xen-bus.c index c2ad22a42d..ceecf0dacb 100644 --- a/hw/xen/xen-bus.c +++ b/hw/xen/xen-bus.c @@ -53,9 +53,9 @@ static char *xen_device_get_frontend_path(XenDevice *xendev) static void xen_device_unplug(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); const char *type = object_get_typename(OBJECT(xendev)); - Error *local_err = NULL; xs_transaction_t tid; trace_xen_device_unplug(type, xendev->name); @@ -69,14 +69,14 @@ again: } xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "online", - &local_err, "%u", 0); - if (local_err) { + errp, "%u", 0); + if (*errp) { goto abort; } xs_node_printf(xenbus->xsh, tid, xendev->backend_path, "state", - &local_err, "%u", XenbusStateClosing); - if (local_err) { + errp, "%u", XenbusStateClosing); + if (*errp) { goto abort; } @@ -96,7 +96,6 @@ abort: * from ending the transaction. */ xs_transaction_end(xenbus->xsh, tid, true); - error_propagate(errp, local_err); } static void xen_bus_print_dev(Monitor *mon, DeviceState *dev, int indent) @@ -205,15 +204,13 @@ static XenWatch *watch_list_add(XenWatchList *watch_list, const char *node, const char *key, XenWatchHandler handler, void *opaque, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenWatch *watch = new_watch(node, key, handler, opaque); - Error *local_err = NULL; notifier_list_add(&watch_list->notifiers, &watch->notifier); - xs_node_watch(watch_list->xsh, node, key, watch->token, &local_err); - if (local_err) { - error_propagate(errp, local_err); - + xs_node_watch(watch_list->xsh, node, key, watch->token, errp); + if (*errp) { notifier_remove(&watch->notifier); free_watch(watch); @@ -255,11 +252,11 @@ static void xen_bus_backend_create(XenBus *xenbus, const char *type, const char *name, char *path, Error **errp) { + ERRP_AUTO_PROPAGATE(); xs_transaction_t tid; char **key; QDict *opts; unsigned int i, n; - Error *local_err = NULL; trace_xen_bus_backend_create(type, path); @@ -314,11 +311,11 @@ again: return; } - xen_backend_device_create(xenbus, type, name, opts, &local_err); + xen_backend_device_create(xenbus, type, name, opts, errp); qobject_unref(opts); - if (local_err) { - error_propagate_prepend(errp, local_err, + if (*errp) { + error_prepend(errp, "failed to create '%s' device '%s': ", type, name); } @@ -451,9 +448,9 @@ static void xen_bus_unrealize(BusState *bus, Error **errp) static void xen_bus_realize(BusState *bus, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus = XEN_BUS(bus); unsigned int domid; - Error *local_err = NULL; trace_xen_bus_realize(); @@ -476,10 +473,10 @@ static void xen_bus_realize(BusState *bus, Error **errp) xenbus->backend_watch = xen_bus_add_watch(xenbus, "", /* domain root node */ - "backend", xen_bus_backend_changed, &local_err); - if (local_err) { + "backend", xen_bus_backend_changed, errp); + if (*errp) { /* This need not be treated as a hard error so don't propagate */ - error_reportf_err(local_err, + error_reportf_err(*errp, "failed to set up enumeration watch: "); } @@ -692,9 +689,9 @@ static void xen_device_remove_watch(XenDevice *xendev, XenWatch *watch, static void xen_device_backend_create(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); struct xs_permissions perms[2]; - Error *local_err = NULL; xendev->backend_path = xen_device_get_backend_path(xendev); @@ -706,9 +703,9 @@ static void xen_device_backend_create(XenDevice *xendev, Error **errp) g_assert(xenbus->xsh); xs_node_create(xenbus->xsh, XBT_NULL, xendev->backend_path, perms, - ARRAY_SIZE(perms), &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + ARRAY_SIZE(perms), errp); + if (*errp) { + error_prepend(errp, "failed to create backend: "); return; } @@ -716,9 +713,9 @@ static void xen_device_backend_create(XenDevice *xendev, Error **errp) xendev->backend_state_watch = xen_device_add_watch(xendev, xendev->backend_path, "state", xen_device_backend_changed, - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + errp); + if (*errp) { + error_prepend(errp, "failed to watch backend state: "); return; } @@ -726,9 +723,9 @@ static void xen_device_backend_create(XenDevice *xendev, Error **errp) xendev->backend_online_watch = xen_device_add_watch(xendev, xendev->backend_path, "online", xen_device_backend_changed, - &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + errp); + if (*errp) { + error_prepend(errp, "failed to watch backend online: "); return; } @@ -866,9 +863,9 @@ static bool xen_device_frontend_exists(XenDevice *xendev) static void xen_device_frontend_create(XenDevice *xendev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); struct xs_permissions perms[2]; - Error *local_err = NULL; xendev->frontend_path = xen_device_get_frontend_path(xendev); @@ -885,9 +882,9 @@ static void xen_device_frontend_create(XenDevice *xendev, Error **errp) g_assert(xenbus->xsh); xs_node_create(xenbus->xsh, XBT_NULL, xendev->frontend_path, perms, - ARRAY_SIZE(perms), &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + ARRAY_SIZE(perms), errp); + if (*errp) { + error_prepend(errp, "failed to create frontend: "); return; } @@ -895,9 +892,9 @@ static void xen_device_frontend_create(XenDevice *xendev, Error **errp) xendev->frontend_state_watch = xen_device_add_watch(xendev, xendev->frontend_path, "state", - xen_device_frontend_changed, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + xen_device_frontend_changed, errp); + if (*errp) { + error_prepend(errp, "failed to watch frontend state: "); } } @@ -1228,11 +1225,11 @@ static void xen_device_exit(Notifier *n, void *data) static void xen_device_realize(DeviceState *dev, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenDevice *xendev = XEN_DEVICE(dev); XenDeviceClass *xendev_class = XEN_DEVICE_GET_CLASS(xendev); XenBus *xenbus = XEN_BUS(qdev_get_parent_bus(DEVICE(xendev))); const char *type = object_get_typename(OBJECT(xendev)); - Error *local_err = NULL; if (xendev->frontend_id == DOMID_INVALID) { xendev->frontend_id = xen_domid; @@ -1248,9 +1245,9 @@ static void xen_device_realize(DeviceState *dev, Error **errp) goto unrealize; } - xendev->name = xendev_class->get_name(xendev, &local_err); - if (local_err) { - error_propagate_prepend(errp, local_err, + xendev->name = xendev_class->get_name(xendev, errp); + if (*errp) { + error_prepend(errp, "failed to get device name: "); goto unrealize; } @@ -1274,22 +1271,19 @@ static void xen_device_realize(DeviceState *dev, Error **errp) xendev->feature_grant_copy = (xengnttab_grant_copy(xendev->xgth, 0, NULL) == 0); - xen_device_backend_create(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_device_backend_create(xendev, errp); + if (*errp) { goto unrealize; } - xen_device_frontend_create(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xen_device_frontend_create(xendev, errp); + if (*errp) { goto unrealize; } if (xendev_class->realize) { - xendev_class->realize(xendev, &local_err); - if (local_err) { - error_propagate(errp, local_err); + xendev_class->realize(xendev, errp); + if (*errp) { goto unrealize; } } diff --git a/hw/xen/xen-host-pci-device.c b/hw/xen/xen-host-pci-device.c index 1b44dcafaf..02379c341c 100644 --- a/hw/xen/xen-host-pci-device.c +++ b/hw/xen/xen-host-pci-device.c @@ -333,8 +333,8 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain, uint8_t bus, uint8_t dev, uint8_t func, Error **errp) { + ERRP_AUTO_PROPAGATE(); unsigned int v; - Error *err = NULL; d->config_fd = -1; d->domain = domain; @@ -342,36 +342,36 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain, d->dev = dev; d->func = func; - xen_host_pci_config_open(d, &err); - if (err) { + xen_host_pci_config_open(d, errp); + if (*errp) { goto error; } - xen_host_pci_get_resource(d, &err); - if (err) { + xen_host_pci_get_resource(d, errp); + if (*errp) { goto error; } - xen_host_pci_get_hex_value(d, "vendor", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "vendor", &v, errp); + if (*errp) { goto error; } d->vendor_id = v; - xen_host_pci_get_hex_value(d, "device", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "device", &v, errp); + if (*errp) { goto error; } d->device_id = v; - xen_host_pci_get_dec_value(d, "irq", &v, &err); - if (err) { + xen_host_pci_get_dec_value(d, "irq", &v, errp); + if (*errp) { goto error; } d->irq = v; - xen_host_pci_get_hex_value(d, "class", &v, &err); - if (err) { + xen_host_pci_get_hex_value(d, "class", &v, errp); + if (*errp) { goto error; } d->class_code = v; @@ -381,7 +381,6 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain, return; error: - error_propagate(errp, err); if (d->config_fd >= 0) { close(d->config_fd); diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 8fbaf2eae9..4bf9353bcb 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -765,12 +765,12 @@ static void xen_pt_destroy(PCIDevice *d) { static void xen_pt_realize(PCIDevice *d, Error **errp) { + ERRP_AUTO_PROPAGATE(); XenPCIPassthroughState *s = XEN_PT_DEVICE(d); int i, rc = 0; uint8_t machine_irq = 0, scratch; uint16_t cmd = 0; int pirq = XEN_PT_UNASSIGNED_PIRQ; - Error *err = NULL; /* register real device */ XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d" @@ -781,10 +781,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) xen_host_pci_device_get(&s->real_device, s->hostaddr.domain, s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function, - &err); - if (err) { - error_append_hint(&err, "Failed to \"open\" the real pci device"); - error_propagate(errp, err); + errp); + if (*errp) { + error_append_hint(errp, "Failed to \"open\" the real pci device"); return; } @@ -811,11 +810,10 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) return; } - xen_pt_setup_vga(s, &s->real_device, &err); - if (err) { - error_append_hint(&err, "Setup VGA BIOS of passthrough" - " GFX failed"); - error_propagate(errp, err); + xen_pt_setup_vga(s, &s->real_device, errp); + if (*errp) { + error_append_hint(errp, "Setup VGA BIOS of passthrough" + " GFX failed"); xen_host_pci_device_put(&s->real_device); return; } @@ -828,10 +826,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp) xen_pt_register_regions(s, &cmd); /* reinitialize each config register to be emulated */ - xen_pt_config_init(s, &err); - if (err) { - error_append_hint(&err, "PCI Config space initialisation failed"); - error_propagate(errp, err); + xen_pt_config_init(s, errp); + if (*errp) { + error_append_hint(errp, "PCI Config space initialisation failed"); rc = -1; goto err_out; } diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 31ec5add1d..af3fbd1bfb 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -2008,8 +2008,8 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s, void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp) { + ERRP_AUTO_PROPAGATE(); int i, rc; - Error *err = NULL; QLIST_INIT(&s->reg_grps); @@ -2052,10 +2052,9 @@ void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp) reg_grp_offset, ®_grp_entry->size); if (rc < 0) { - error_setg(&err, "Failed to initialize %d/%zu, type = 0x%x," + error_setg(errp, "Failed to initialize %d/%zu, type = 0x%x," " rc: %d", i, ARRAY_SIZE(xen_pt_emu_reg_grps), xen_pt_emu_reg_grps[i].grp_type, rc); - error_propagate(errp, err); xen_pt_config_delete(s); return; } @@ -2068,13 +2067,14 @@ void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp) /* initialize capability register */ for (j = 0; regs->size != 0; j++, regs++) { - xen_pt_config_reg_init(s, reg_grp_entry, regs, &err); - if (err) { - error_append_hint(&err, "Failed to init register %d" - " offsets 0x%x in grp_type = 0x%x (%d/%zu)", j, - regs->offset, xen_pt_emu_reg_grps[i].grp_type, - i, ARRAY_SIZE(xen_pt_emu_reg_grps)); - error_propagate(errp, err); + xen_pt_config_reg_init(s, reg_grp_entry, regs, errp); + if (*errp) { + error_append_hint(errp, "Failed to init register %d" + " offsets 0x%x in grp_type = 0x%x (%d/%zu)", + j, + regs->offset, + xen_pt_emu_reg_grps[i].grp_type, + i, ARRAY_SIZE(xen_pt_emu_reg_grps)); xen_pt_config_delete(s); return; }