From nobody Fri Nov 14 00:58:44 2025 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1583471821; cv=none; d=zohomail.com; s=zohoarc; b=CEg1CPkhfhvmuamqdCK2EvrbtTA5E4bhuLVEBY4TAweHCLJ5hG0dS+hFzGlPG4jdtHWVfjrBzz1WjSSXvZ/j1g6zu6IogpTev7xiv1wNbHzNZ7ZD8MKXwHaSehlmhhv27wmOu0ru8m+7rUW56j6pRH72POIIKUMAC/ommA7hfd8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583471821; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jvme3FaLlGZAV/Tb75VMxgw2M6WgXna3fhuI6OHzcSs=; b=DqZRX7SuD9BghtOkHzga14Tl/5p5LyiJX81PMjU1hFIB/NnIZOM0fNZqrd3/yssL9BzgPCjF84aHb81t+N2WgxH+mvtBFBd8p4rAfW1VIFtRJK72MQM0/M8WvkkzcRg33tMTf4XFXEFcGEOPWNa3gBeaOE7l3WpjZCRI/511n2M= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1583471821459914.5414064079089; Thu, 5 Mar 2020 21:17:01 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jA5LR-0005Vt-1E; Fri, 06 Mar 2020 05:16:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jA5LP-0005VW-NA for xen-devel@lists.xenproject.org; Fri, 06 Mar 2020 05:16:19 +0000 Received: from relay.sw.ru (unknown [185.231.240.75]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 959402ba-5f69-11ea-b74d-bc764e2007e4; Fri, 06 Mar 2020 05:16:08 +0000 (UTC) Received: from vovaso.qa.sw.ru ([10.94.3.0] helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1jA5Km-0001tg-7F; Fri, 06 Mar 2020 08:15:40 +0300 X-Inumbo-ID: 959402ba-5f69-11ea-b74d-bc764e2007e4 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Fri, 6 Mar 2020 08:15:28 +0300 Message-Id: <20200306051536.27803-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200306051536.27803-1-vsementsov@virtuozzo.com> References: <20200306051536.27803-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v8 02/10] 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: Kevin Wolf , vsementsov@virtuozzo.com, Laszlo Ersek , qemu-block@nongnu.org, Paul Durrant , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Christian Schoenebeck , Greg Kurz , armbru@redhat.com, Stefano Stabellini , Gerd Hoffmann , Stefan Hajnoczi , Anthony Perard , xen-devel@lists.xenproject.org, Max Reitz , Eric Blake , Michael Roth , Stefan Berger Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Script adds ERRP_AUTO_PROPAGATE macro invocation where appropriate and does corresponding changes in code (look for details in include/qapi/error.h) Usage example: spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \ blockdev-nbd.c qemu-nbd.c {block/nbd*,nbd/*,include/block/nbd*}.[hc] Signed-off-by: Vladimir Sementsov-Ogievskiy --- Cc: Eric Blake Cc: Kevin Wolf Cc: Max Reitz Cc: Greg Kurz Cc: Christian Schoenebeck Cc: Stefano Stabellini Cc: Anthony Perard Cc: Paul Durrant Cc: Stefan Hajnoczi Cc: "Philippe Mathieu-Daud=C3=A9" Cc: Laszlo Ersek Cc: Gerd Hoffmann Cc: Stefan Berger Cc: Markus Armbruster Cc: Michael Roth Cc: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org Cc: xen-devel@lists.xenproject.org include/qapi/error.h | 3 + scripts/coccinelle/auto-propagated-errp.cocci | 231 ++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci diff --git a/include/qapi/error.h b/include/qapi/error.h index bb9bcf02fb..fbfc6f1c0b 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -211,6 +211,9 @@ * } * ... * } + * + * For mass conversion use script + * scripts/coccinelle/auto-propagated-errp.cocci */ =20 #ifndef ERROR_H diff --git a/scripts/coccinelle/auto-propagated-errp.cocci b/scripts/coccin= elle/auto-propagated-errp.cocci new file mode 100644 index 0000000000..bff274bd6d --- /dev/null +++ b/scripts/coccinelle/auto-propagated-errp.cocci @@ -0,0 +1,231 @@ +// Use ERRP_AUTO_PROPAGATE (see include/qapi/error.h) +// +// Copyright (c) 2020 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 . +// +// Usage example: +// spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ +// --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff \ +// --max-width 80 blockdev-nbd.c qemu-nbd.c \ +// {block/nbd*,nbd/*,include/block/nbd*}.[hc] + +// Switch unusual (Error **) parameter names to errp +// (this is necessary to use ERRP_AUTO_PROPAGATE). +// +// Disable optional_qualifier to skip functions with "Error *const *errp" +// parameter. +// +// Skip functions with "assert(_errp && *_errp)" statement, as they have +// non generic semantics and may have unusual Error ** argument name for p= urpose +// (like nbd_iter_channel_error()). +// +// Skip util/error.c to not touch, for example, error_propagate and +// error_propagate_prepend(). +@ depends on !(file in "util/error.c") disable optional_qualifier@ +identifier fn; +identifier _errp !=3D errp; +@@ + + fn(..., +- Error **_errp ++ Error **errp + ,...) + { +( + ... when !=3D assert(_errp && *_errp) +& + <... +- _errp ++ errp + ...> +) + } + +// Add invocation of ERRP_AUTO_PROPAGATE to errp-functions where necessary +// +// Note, that without "when any" final "..." may not want to mach something +// matched by previous pattern, i.e. the rule will not match double +// error_prepend in control flow like in vfio_set_irq_signaling(). +// +// Note, "exists" says that we want apply rule even if it matches not on +// all possible control flows (otherwise, it will not match standard patte= rn +// when error_propagate() call is in if branch). +@ disable optional_qualifier exists@ +identifier fn, local_err, errp; +@@ + + fn(..., Error **errp, ...) + { ++ ERRP_AUTO_PROPAGATE(); + ... when !=3D ERRP_AUTO_PROPAGATE(); +( + error_append_hint(errp, ...); +| + error_prepend(errp, ...); +| + error_vprepend(errp, ...); +| + Error *local_err =3D NULL; + ... +( + error_propagate_prepend(errp, local_err, ...); +| + error_propagate(errp, local_err); +) +) + ... when any + } + + +// Match scenarios with propagation of local error to errp. +@rule1 disable optional_qualifier exists@ +identifier fn, local_err; +symbol errp; +@@ + + fn(..., Error **errp, ...) + { + ... + Error *local_err =3D NULL; + ... +( + error_propagate_prepend(errp, local_err, ...); +| + error_propagate(errp, local_err); +) + ... + } + +// Convert special case with goto in separate. +// We can probably merge this into the following hunk with help of ( | ) +// operator, but it significantly reduce performance on block.c parsing (o= r it +// hangs, I don't know) +// +// Note interesting thing: if we don't do it here, and try to fixup "out: = }" +// things later after all transformations (the rule will be the same, just +// without error_propagate() call), coccinelle fails to match this "out: }= ". +@@ +identifier rule1.fn, rule1.local_err, out; +symbol errp; +@@ + + fn(...) + { + <... +- goto out; ++ return; + ...> +- out: +- error_propagate(errp, local_err); + } + +// Convert most of local_err related staff. +// +// Note, that we update everything related to matched by rule1 function na= me +// and local_err name. We may match something not related to the pattern +// matched by rule1. For example, local_err may be defined with the same n= ame +// in different blocks inside one function, and in one block follow the +// propagation pattern and in other block doesn't. Or we may have several +// functions with the same name (for different configurations). +// +// Note also that errp-cleaning functions +// error_free_errp +// error_report_errp +// error_reportf_errp +// warn_report_errp +// warn_reportf_errp +// are not yet implemented. They must call corresponding Error* - freeing +// function and then set *errp to NULL, to avoid further propagation to +// original errp (consider ERRP_AUTO_PROPAGATE in use). +// For example, error_free_errp may look like this: +// +// void error_free_errp(Error **errp) +// { +// error_free(*errp); +// *errp =3D NULL; +// } +@ exists@ +identifier rule1.fn, rule1.local_err; +expression list args; +symbol errp; +@@ + + fn(...) + { + <... +( +- Error *local_err =3D NULL; +| + +// Convert error clearing functions +( +- error_free(local_err); ++ error_free_errp(errp); +| +- error_report_err(local_err); ++ error_report_errp(errp); +| +- error_reportf_err(local_err, args); ++ error_reportf_errp(errp, args); +| +- warn_report_err(local_err); ++ warn_report_errp(errp); +| +- warn_reportf_err(local_err, args); ++ warn_reportf_errp(errp, args); +) +?- local_err =3D NULL; + +| +- error_propagate_prepend(errp, local_err, args); ++ error_prepend(errp, args); +| +- error_propagate(errp, local_err); +| +- &local_err ++ errp +) + ...> + } + +// Convert remaining local_err usage. It should be different kinds of error +// checking in if operators. We can't merge this into previous hunk, as th= is +// conflicts with other substitutions in it (at least with "- local_err = =3D NULL"). +@@ +identifier rule1.fn, rule1.local_err; +symbol errp; +@@ + + fn(...) + { + <... +- local_err ++ *errp + ...> + } + +// Always use the same patter for checking error +@@ +identifier rule1.fn; +symbol errp; +@@ + + fn(...) + { + <... +- *errp !=3D NULL ++ *errp + ...> + } --=20 2.21.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel