From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712143; cv=pass; d=zohomail.com; s=zohoarc; b=KBuo6WrfR1HNdmeVnSwoFZG4hSM55+7PWDKxUhf78RvcoVAIp3e9n+lCkbswJw7BnupDLzXXuCf9Y6T3PVjobIt47u0J0QXpaaHK7my/T49+4TXjwvI/KrMbdOMkm9uUVP9TWlFJpoL2knJvzzRpDQUMyXMbPjkoiL0aIW/p2fk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712143; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=f+eJbX2MZPPDkO/kDijUBqa41+ytN7yNNrsdw0gTcnY=; b=Ecmg+q2bFYoR7wpXm7wHCkAivPmVc9XteeVpmmPXh1DxIeZU7WPtQe7sC4IsoXhwY0sE/a6566UYpPjJSm9denpHFG3jc+ksxOtePgZlda6PCByK/tikSd5aDv4pRtjEUvZBLpNgN3pOzhkI5tCnYxsJ9LFShzzSZyqamcTvyuI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712142899509.2936231697821; Tue, 9 Jun 2020 07:15:42 -0700 (PDT) Received: from localhost ([::1]:46612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif2T-0000EN-Gz for importer@patchew.org; Tue, 09 Jun 2020 10:15:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0l-0006in-3v; Tue, 09 Jun 2020 10:13:55 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:27969 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0j-0007gx-PJ; Tue, 09 Jun 2020 10:13:54 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:48 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:48 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ud35Ws4E0XRb1EQga3L5lMyXaUvosNMkOwxk2CeJki3OsQ6A6XRZ3djZmyv9b1UiwOvFKGten+jDkBHS+AkNNBYGT6BmaZwb9kgErE2pS3+LPK7EXb3NlH7Kd44Ae64+w1S+tORc1PbzXEJGED9P3R7WBSdj1BZW5eXZNOgR64NGFglTGehUbuLwE1W2pJDREv5OfXdP7y3+gGnNtuu+Y2Si6ecLT5ulvmYYvOn10hNkOB3piLqfjTwyX4QtISVeUtknk+oI7fRllrsKZNmoxIxy+2nB0aG7+sKNr33NYHUWzzg0yNkp0NS1d2jgZODFUTzqQJeazTwu1DxlFUJtFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f+eJbX2MZPPDkO/kDijUBqa41+ytN7yNNrsdw0gTcnY=; b=m+31HcMbYnSazg1E8X5Ir0TWRh4oV+yMGrIl04EXjGw2CS5KKVhFcFKg9A/O8C+nPwSAF27CxJwlPLiaSXi+ObC2jIrLUkPONpGCofgp2elxXOGW6fYOiFMSEIlxSlehXoDFeb4hhKg7dXZN4iuxoH+bsMA/hEteiMmZAsJMyaX+/+RSj9vypLXLp3ti/A1ldXezfCNpztCePAeQqmHZvxy5HRzh6xKPD7UxksyvBidbsDRTJf+YM1bwI4UanfGEnrARUq4n+fsqq7cyPpdhCBeiSRYSpwg55Mp6bF5ZfoxO+tSGwFKDjF5BAXfrPULUWB71gv+2/Wjp2sSJ/++Avw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=f+eJbX2MZPPDkO/kDijUBqa41+ytN7yNNrsdw0gTcnY=; b=JlKqTSz3qXudxZCACObVjwfiED/3csVe5RDky+Lppap4R4zsCu+Jwjfk2ZuO2a2HDISwzVbgBU0JGTlRgngqnASC91x3p97ZMPw7m1qb+c5v3JddtLcVJA6n+ZgHlWDDqSlwvCjAct8idRlrtaOWk4upIEoKFJFnVY1fEt06b0s= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 1/7] block: return error-code from bdrv_invalidate_cache Date: Tue, 9 Jun 2020 17:13:23 +0300 Message-Id: <20200609141329.3945-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6c334a75-7d6f-437b-a98f-08d80c7f53b0 X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:489; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Btr7mcGfXPulhkL7L0Hg95xA69UcLkGAMs1E67uWBsk69NZLc0rZ9bYFg3w7coiG7E0J3GkWeog3JTSYKCi8vSsNosMLe7zx4ym8n34Az1inOYDN4eHUs42KyWbrEZajSz8hG6XPqvblG2pk3h8Kucw/uiuN9c0/o4xvoiCFVqOpt1Md300Yqz8bLfZ236dHmLBIuy/J+w0ZQmOCo6pWRUz70wlYkPI5mLR/12FJwCV9tMjA0O7vthe+1ahF7lQTbSNd8tsixBg2jRELwMwSOgjSi7VIaEKCvS14Ba+KtF6E+bjOgrcnsWZDwSUKNKcvyBAauJ02BFmVJ8N1SSZwLH7M5txW+Q6ipttwKOgInpbueN+hFmxgvDZMGsOTzx83 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: PxLfiMKOw93kf1ZZpSJ11j6I7di+cxF3JKCPfsf029wt/yr4WTQJRKsF+7JlT3nb4lcJLbCqZwljT/iEieAihz8kEsg/GwJEl/RaEHFOiUNkoQfswRrO9Bs0nxDiX8VwmgIMDTd/y0C43kMP0fEVg/qQdD3kmBO36bNE/o4m81d9phDUpIB8QH/II1BQml3WazRCLlZ+79dA5q4niAI+gnG9yWT0RX94HG5frkhv8XUWwaxEpJbkOnzBvq2DG1rBYtdBSgl+0bdxMEzV9UBuRkDD8F0lsu7sbpffoFUl3gymDl75Yd7WwqyFB+6cojLcIvjldke6Nbf7OTg5PUKmsgRtRKHQwMqj5oSECMSDgDeBp9wrKlXiZQFBLqhHGWa/1RrC5z0K074I2vmPYFhGmHkWKGAcykSIch9pV3gEScX684ebciDEZC/44AETizFB4FMcMXqYftNgVEJy3GnQxzjqPUpHGKtjxJbOTbJ4rlOTSeXuY3btb3PJ6+tNKWu8 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c334a75-7d6f-437b-a98f-08d80c7f53b0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:47.9104 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RpEaFPfGraMQPKL3rJIHZ1GgcA7WClYQxmMuYc5GnP49wbU32vsu9OfvLjDt96GIx1sHOo6pJj6B9Ngk6ZdVsohw4RsaoGoFQ9Bkxlp0LMw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:47 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" This is the only coroutine wrapper from block.c and block/io.c which doesn't return a value, so let's convert it to the common behavior, to simplify moving to generated coroutine wrappers in a further commit. Also, bdrv_invalidate_cache is a void function, returning error only through **errp parameter, which is considered to be bad practice, as it forces callers to define and propagate local_err variable, so conversion is good anyway. This patch leaves the conversion of .bdrv_co_invalidate_cache() driver callbacks and bdrv_invalidate_cache_all() for another day. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- include/block/block.h | 2 +- block.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 25e299605e..46965a7780 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -464,7 +464,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Invalidate any cached metadata used by image formats */ -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); +int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); =20 diff --git a/block.c b/block.c index 8416376c9b..b01551f21c 100644 --- a/block.c +++ b/block.c @@ -5643,8 +5643,8 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; @@ -5653,14 +5653,14 @@ static void coroutine_fn bdrv_co_invalidate_cache(B= lockDriverState *bs, BdrvDirtyBitmap *bm; =20 if (!bs->drv) { - return; + return -ENOMEDIUM; } =20 QLIST_FOREACH(child, &bs->children, next) { bdrv_co_invalidate_cache(child->bs, &local_err); if (local_err) { error_propagate(errp, local_err); - return; + return -EINVAL; } } =20 @@ -5684,7 +5684,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return ret; } bdrv_set_perm(bs, perm, shared_perm); =20 @@ -5693,7 +5693,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (local_err) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } =20 @@ -5705,7 +5705,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; error_setg_errno(errp, -ret, "Could not refresh total sector c= ount"); - return; + return ret; } } =20 @@ -5715,27 +5715,30 @@ static void coroutine_fn bdrv_co_invalidate_cache(B= lockDriverState *bs, if (local_err) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } } + + return 0; } =20 typedef struct InvalidateCacheCo { BlockDriverState *bs; Error **errp; bool done; + int ret; } InvalidateCacheCo; =20 static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) { InvalidateCacheCo *ico =3D opaque; - bdrv_co_invalidate_cache(ico->bs, ico->errp); + ico->ret =3D bdrv_co_invalidate_cache(ico->bs, ico->errp); ico->done =3D true; aio_wait_kick(); } =20 -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) +int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) { Coroutine *co; InvalidateCacheCo ico =3D { @@ -5752,22 +5755,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Er= ror **errp) bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !ico.done); } + + return ico.ret; } =20 void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; - Error *local_err =3D NULL; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(aio_context); - bdrv_invalidate_cache(bs, &local_err); + ret =3D bdrv_invalidate_cache(bs, errp); aio_context_release(aio_context); - if (local_err) { - error_propagate(errp, local_err); + if (ret < 0) { bdrv_next_cleanup(&it); return; } --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712141; cv=pass; d=zohomail.com; s=zohoarc; b=RLUSviLjakCi9W0V1Oaqdc5oRFERJrQUBnh/yssMK8Zl7tzu4TndGs4jfJ11i8Ngw1D1YhtsWPWCmYksQK8BYftvESx+gL2Wm5EON5UAXrSf/IRikcrYq5tCa/PA2g4/Cs1VnoJgMXx4RfZ0OmXKxyPQjXkf+VoyZ+p7ZSs3dHs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712141; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+P3eZo8WPmovaEVuviCSj6vzBDK+j0ShsQU3UDgtRyc=; b=OuSY32Dd6c3zA32ydpJcVwmik7N4QuL24lUWqEH8LwKu8WrPiuZBvO1BXe+Js08ekEiz/yXyF9MG0Pvyg1sBDYcjubh8PhOrg2VQF3LE2Ic++x3Pk+M+f0nmXuuv6NHCgsIdaO9ApOrRQKW7ndaCQ0v9ck857hpSmm3iaYp9p7k= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712141204455.1664153385425; Tue, 9 Jun 2020 07:15:41 -0700 (PDT) Received: from localhost ([::1]:46576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif2R-0000DX-Qd for importer@patchew.org; Tue, 09 Jun 2020 10:15:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0n-0006m6-5d; Tue, 09 Jun 2020 10:13:57 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:27969 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0l-0007gx-NZ; Tue, 09 Jun 2020 10:13:56 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:49 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:49 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N8IFxL2gqijsG4Pv6UJ2QVu06cjT72u2M9iR3aCWkIroRrxgpCYRLrIC7Y3qkiuTjbQNPxgt7q8/1NTh3Niy9YjPXEd1TLnNRffRLmpbn961iONW33BOLqJeklOoDY8hogFm3+bipJY8X1YSKGoNBa8MKFtcW8d6qGUmvHW+xwV2P+5DNOCQy1ybAmpC5CyihDCeQ+eJP28CvzBTSXKDSVIP5VL/ZURO21EGncOns+N2UUx2CJuuLlQsZ8bqqjtAIcso4NSIQwmi9MynvJHop1TBLbHxxw1PdelE/T7CRYo8NT+j+oI2x45KCquuWVgyfzehgzsb5MMiO4H6rffXYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+P3eZo8WPmovaEVuviCSj6vzBDK+j0ShsQU3UDgtRyc=; b=FFQng4LJ6iFlnqlbCzZPYcWND/zD6b4UCct6T9SkUVIjjm1uOu1yXKiodg0Us+/eocAJbmLFSQDfct7TjH8t3M2Y/s44TMuLNBeyFppLbIFMOYrJkMr+wiXCdxzWZBnTEsbzuMH3psladUPQsTM5PAFqy7sNJ+SS20EqsAECnrHlSnCNinlRhA9A3UOfC+hXL89WhiPzROWK36C4fndz9jfx1FCZgb9LthWt0BzmlVTIqI4+O49SeDmAPRzv+e0ivRddT9wQGYZgibHuleHXHfjYqhVh50AuqGxZC0/fy1atNkzRPHWvthOdSpYbn23QxSSqkJRi8oShxNDTPoMClw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+P3eZo8WPmovaEVuviCSj6vzBDK+j0ShsQU3UDgtRyc=; b=jnlzvYw48aDOqBDYYlnTM/rOq9P62NeOJbllP0syttaJT0JGQhRxdks3dRdv43X59ikwH5/Nf8v7X+IbRLyTfWJuAe0mhOpE9TvnAjrQPRAV95HV4n2zMRFg4DkW+NTGUvyj6sLFrNc3i3AUYjHYutouGCJp4qdB8hAh+hqO/K0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 2/7] block/io: refactor coroutine wrappers Date: Tue, 9 Jun 2020 17:13:24 +0300 Message-Id: <20200609141329.3945-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00798308-d24c-44b0-74c1-08d80c7f5446 X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:189; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pe2uHK+92iDA0FnAULw9Uoe57zhO636okwRSPFc1VKTBkV68klhNqOtrizHT8uLzYL3XwSZocAO7Y5uNaY0Vc86zQAMk2W565CziFut3nTalf6yYJWJZjXUkJKwhNeAOqITnOOc3//uD7gvj2pN4k0QYHdYljTwSHdua2yajgGDcXsZu9eK5uPSGx/NryuDyRfqZD3RSQFqhFlt6ll3JVl6m+7AgK2j0CeBAk0K6qyypBzsPqqovHIx3siiQuRs+gDvi7v9f+pe0KvOFfTC/Udr5HCUs6l9mksKss2nWpENMvVgfxYnKWWYuHGRU/EX0+h9NZORAQ5VizCX4Or/tnsYnu367ZyArOgPmfGBJoKZyeq1A4H1x0qoiFxAJzCge X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: AyA8H99OEGgYo5TgclMKZZqniJvGevUI/hJ63jVdVA39WK2cD/HS3Q3ZKPWumm++bIxBUMLZ6yT2g0rFJ2ddIFC62+zt7G8QgH8TdhowTgHUodrrYUQiLV0xLdVhZTTZPdVPagviUTmrKi74VTEapcv9VGbStMLo1PFaA6zb45YnbaAyuzvPm8Soj6QTxBbjOZzhMiB/dkdG4ASl0007qvUjwPnBSjCfUc55/VpbjKZ221pv7tn5a7tJLPyeVNTltX0sedKxonch2R6oWT7uXgkQZBp0ipNDIR7tFmzYmhdTCxjIw2A1Rdt0KH6u86ZDXjxZwD4u6inGbGaj+kohJALMqLOphhZ4IHbIoD2zREWCfSdDnVxdE5SDOgyw1mXEfgwpjl9NM5+IkvhafUZoV7wjRnpwf7PTeset72vKnq7KQiEUaAA0Ac3bSYoRS6l/60fsd085a5SeKIbnwohfT+YLjvD2Z/nYJg+UBIarZGw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00798308-d24c-44b0-74c1-08d80c7f5446 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:48.8791 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 27QNfNGRJAkWcm+WAK1J5irNjanmFiMLWhRO7OxL4GXguFomC32lkckzZ/P+FBOiMQ7uTJf1xtmXfDi+K2NNnlAyRRWcz/mdo60ypYjtmH0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:47 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Most of our coroutine wrappers already follow this convention: We have 'coroutine_fn bdrv_co_()' as the core function, and a wrapper 'bdrv_()' which does parameters packing and call bdrv_run_co(). The only outsiders are the bdrv_prwv_co and bdrv_common_block_status_above wrappers. Let's refactor them to behave as the others, it simplifies further conversion of coroutine wrappers. This patch adds indirection layer, but it will be compensated by further commit, which will drop bdrv_co_prwv together with is_write logic, to keep read and write patch separate. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index df8f2a98d4..af6cb839bf 100644 --- a/block/io.c +++ b/block/io.c @@ -933,27 +933,31 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 +static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) +{ + if (is_write) { + return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); + } else { + return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); + } +} + static int coroutine_fn bdrv_rw_co_entry(void *opaque) { RwCo *rwco =3D opaque; =20 - if (!rwco->is_write) { - return bdrv_co_preadv(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } else { - return bdrv_co_pwritev(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } + return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, + rwco->is_write, rwco->flags); } =20 /* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv_co(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +static int bdrv_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { RwCo rwco =3D { .child =3D child, @@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); =20 - return bdrv_prwv_co(child, offset, &qiov, true, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); } =20 /* @@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEM= UIOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, false, 0); + ret =3D bdrv_prwv(child, offset, qiov, false, 0); if (ret < 0) { return ret; } @@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, true, 0); + ret =3D bdrv_prwv(child, offset, qiov, true, 0); if (ret < 0) { return ret; } @@ -2463,14 +2466,15 @@ early_out: return ret; } =20 -static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) +static int coroutine_fn +bdrv_co_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BlockDriverState *p; int ret =3D 0; @@ -2508,10 +2512,10 @@ static int coroutine_fn bdrv_block_status_above_co_= entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; =20 - return bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->file); + return bdrv_co_common_block_status_above(data->bs, data->base, + data->want_zero, + data->offset, data->bytes, + data->pnum, data->map, data->= file); } =20 /* --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712295; cv=pass; d=zohomail.com; s=zohoarc; b=bsmbStkMFcDUAsQoBV8qsX92ttY1GRt/K73CVOaCk64amefkuTMyXJCyZ/WUrKfuGy2pTs5WHhDP2KL5j/nOU6K3vf+wxxK2yZNCmIp7s4EWD86XSVLvDn8Sc1tqLrYazacNHvYyBd18IRGRH/kzQhZUB39R0ZZOVecz1HNC/3U= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712295; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CdkEciUCSDw7LDQzG+bxUvcxlwX6Xi7xdsPRAuiFRuU=; b=BVNc+SFSA+buy1usDEXTylBmZbMQZ4xud1GZFswti079kZmd2Qgsk1iRkB/NTkb3l0BJcU9ww95GI6O+cqCi0cAA0kSyAZ4isu1bFYdj9RtThbR7axVaI3iC5ExMKqbhEGCOiuwJoB+sPk+tHwzzDWHBQmt5gLC/rDEq7LAKtFI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712295668875.9073712657946; Tue, 9 Jun 2020 07:18:15 -0700 (PDT) Received: from localhost ([::1]:54304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif4w-0003nh-7i for importer@patchew.org; Tue, 09 Jun 2020 10:18:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0p-0006py-0v; Tue, 09 Jun 2020 10:13:59 -0400 Received: from mail-am6eur05on2106.outbound.protection.outlook.com ([40.107.22.106]:18497 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0n-0007hk-P9; Tue, 09 Jun 2020 10:13:58 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:49 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:49 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lpXM/71rEKGea7cR4xaiZvEHD1cuj6jR3pqSI3E/3BlsZfBQEQxIk0oOnXO2Uc0nqqpFMutx0KJBQ0SPfxMKTcl3TIyLpi/eONpj+ve6Il9+SEkiSSPU6g8CcchI9cuv1i7LGoFe5BetUBlXLa29td/+imke+hfFm5mgwlc5mqbL+iTiayNxjNo5ArpR6BEnZHwBP8DKiXa3lUK3NvxJ+VKNWVWWqco8LzhG19/MB95A0PQQmvQDVLN13HBQpQNd/AAV1jL92ht60RJ1gOZwv2ti12//yzfLqG1doAZyPxoXN7xzV8BY1CoBv5ay+/UGF36vi4bvI0mJFS6ir+WmGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CdkEciUCSDw7LDQzG+bxUvcxlwX6Xi7xdsPRAuiFRuU=; b=i3O+x8yK0gJqwvhZiBLoOVKuPdd5o+bCq1xCaVBJV+BfXskleVL3VX9sAW8pXcXKFhs1zn5YUZwE2txu/mUqcaeIgCTj7sv+R5UhSJk2mqxLOcN8FT4iH7BBBaqpwFWxksIZtaRDgphXE2odriGCBgHUwn9WLu0l5Xhg6V4aRBCeqwufxYYtsM6usxcIYuzEaHB9R1V48xPl41r3hqDKhphrdhQfIet6pnLy+BsjNpCjl9Huz+k9kty4cmfblG3uuKcuERoDAWHzz8n7yrZ3e8LSpGJ2mCFvStnv4/Q1OO7+7VLznSLc83df+3FFo7gT0+I79GKfEWhDeBgmpaqb4w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CdkEciUCSDw7LDQzG+bxUvcxlwX6Xi7xdsPRAuiFRuU=; b=YwPF60hbBglXt7PwOShaUTLsMg5j8AejolDA4svSWqoS+JSGWBfW+o7Dto7W/8WdTIdMUS4t20RTzsnnc2enZill+tBVOammBtfs3+5s1RmHnvRa1tTURvMky7/OlKTLr4ZaqGJoGTltMVCtsnRVbF5yFJyRexPQuCIAp2lu9vg= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 3/7] block: declare some coroutine functions in block/coroutines.h Date: Tue, 9 Jun 2020 17:13:25 +0300 Message-Id: <20200609141329.3945-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c3322aa1-afe9-4525-d81b-08d80c7f54d7 X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MS54o889E5LWjnuPjTDPvWv11TFj5YPlE4sPu6+Z0FNuJCTgf8nquG02CnNIiSiJpfihnWWSymG5koJhhgpEY6yRq8DhZ4S9cAXfPXb+8vVUZP0ebCLLCvcT0vi3X2i0zi/3e1KUBZb025PUJak7m/JVIzLdz6NTLq3rjxAB2AeELtEZ5nOWv6vFb0wH5REvs6pfjhpqIPdIDwBujBennG+617lzZ6dJ6ZvjH1JWRoEWWYkhargvFgZgheg9qr9BdLVbUTSQHMKjvxdj5KESJrjBsBRvSlm6rbt3U0OkZIWVMmfG355ofPm3iEK0EJjIpahspCjcM85aCrf6Jp7vbloR/keGZB7oCR9N0HeniUPgJMj4O1KVA1k6ehG0DrHz X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: kSVn/fHtDrveNLNQXIVkol9haBF9POPmkW7tX94n29Z06nabb364BJ9pFR8nBzkz8QDsR2V569Mw9lqC8Mo8DX1EcOcKl7i2uhJgsIBMaIsKMGvLAWcicLqcak1pdj1uY5/3vvDrz6P6Vx9hFzZGq1O1avRLXHp2Dzek8FTueYSrEKZ8Il+bw0w1yRjlT6wiYUB1RKTUJUK9iy3RqI8kT/+MJdCII5dcL/py/HDvUWXc/xWRS/ux7H0O/3YGpEGwrMJy5+rRR7aVr0CHEaPr/SFS5Qka+X+I4jJ4BgamWFzQMFONvANIwCn8pOO7LhwxHY/lh3EnYfZmw6MYunxqQYCQ0gY3fSLcl3KzRp8Pgj3+vVlnvBFXRTYLTlsIHU3QYNuErOPTNObUQNNoDWzak8OtiR6j49zTlJ9lZ6oDEawksx8WjnlaYwQpnFFIRVTBBM8g7byXVJI66hTemgI4+irXpoEvxp7Gd5DMmEtPv7c= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3322aa1-afe9-4525-d81b-08d80c7f54d7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:49.8070 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZDx3QOU0eZ3TecDMGrw/GsFxu/1FlY9+hlyQFdxg8PRDjf+15rQTPBg1f7UAh2Yro7IdHG63kRuZWkUOy6GVI5Ftd8idcUqu1AFM/GmyDSw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.106; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:55 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to keep coroutine-wrappers code (structure-packing parameters, BDRV_POLL wrapper functions) in separate auto-generated files. So, we'll need a header with declaration of original _co_ functions, for those which are static now. As well, we'll need declarations for wrapper functions. Do these declarations now, as a preparation step. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/coroutines.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++ block.c | 8 +++--- block/io.c | 34 +++++++++++------------ 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 block/coroutines.h diff --git a/block/coroutines.h b/block/coroutines.h new file mode 100644 index 0000000000..9ce1730a09 --- /dev/null +++ b/block/coroutines.h @@ -0,0 +1,67 @@ +/* + * Block layer I/O functions + * + * Copyright (c) 2003 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_COROUTINES_INT_H +#define BLOCK_COROUTINES_INT_H + +#include "block/block_int.h" + +int coroutine_fn bdrv_co_check(BlockDriverState *bs, + BdrvCheckResult *res, BdrvCheckMode fix); +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp); + +int coroutine_fn +bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, + bool is_write, BdrvRequestFlags flags); +int +bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, + bool is_write, BdrvRequestFlags flags); + +int coroutine_fn +bdrv_co_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file); +int +bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file); + +int coroutine_fn +bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read); +int +bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read); + +#endif /* BLOCK_COROUTINES_INT_H */ diff --git a/block.c b/block.c index b01551f21c..2ca9267729 100644 --- a/block.c +++ b/block.c @@ -48,6 +48,7 @@ #include "qemu/timer.h" #include "qemu/cutils.h" #include "qemu/id.h" +#include "block/coroutines.h" =20 #ifdef CONFIG_BSD #include @@ -4625,8 +4626,8 @@ static void bdrv_delete(BlockDriverState *bs) * free of errors) or -errno when an internal error occurred. The results = of the * check are stored in res. */ -static int coroutine_fn bdrv_co_check(BlockDriverState *bs, - BdrvCheckResult *res, BdrvCheckMode = fix) +int coroutine_fn bdrv_co_check(BlockDriverState *bs, + BdrvCheckResult *res, BdrvCheckMode fix) { if (bs->drv =3D=3D NULL) { return -ENOMEDIUM; @@ -5643,8 +5644,7 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; diff --git a/block/io.c b/block/io.c index af6cb839bf..deb9ca8d82 100644 --- a/block/io.c +++ b/block/io.c @@ -29,6 +29,7 @@ #include "block/blockjob.h" #include "block/blockjob_int.h" #include "block/block_int.h" +#include "block/coroutines.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -933,9 +934,9 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 -static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { if (is_write) { return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); @@ -955,9 +956,9 @@ static int coroutine_fn bdrv_rw_co_entry(void *opaque) /* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +int bdrv_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { RwCo rwco =3D { .child =3D child, @@ -2466,7 +2467,7 @@ early_out: return ret; } =20 -static int coroutine_fn +int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -2523,12 +2524,12 @@ static int coroutine_fn bdrv_block_status_above_co_= entry(void *opaque) * * See bdrv_co_block_status_above() for details. */ -static int bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, int64_t offset, - int64_t bytes, int64_t *pnum, - int64_t *map, - BlockDriverState **file) +int bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, int64_t offset, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BdrvCoBlockStatusData data =3D { .bs =3D bs, @@ -2644,7 +2645,7 @@ typedef struct BdrvVmstateCo { bool is_read; } BdrvVmstateCo; =20 -static int coroutine_fn +int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { @@ -2676,9 +2677,8 @@ static int coroutine_fn bdrv_co_rw_vmstate_entry(void= *opaque) return bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); } =20 -static inline int -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read) { BdrvVmstateCo data =3D { .bs =3D bs, --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712301; cv=pass; d=zohomail.com; s=zohoarc; b=lN9i/wjyDEHYj5rymzrNSoMbpGLz9ZrlAdQ62yHydGnRKTdwCHupudOVHCM92tt4Ea4CcJqg9m+8knbUIDmNfQUVHj6UvpcAfwI2hCnlz15/uboehjR4jp5Wsn5rbtB143kMJ5H68rxKtOYpJ/LBv+R3wEvMiObdJY9ZbQCLCJk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712301; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kGeEa/tG+Uhdcvr3hUZQEhZ4NR9pDdo25ndUBd5AObc=; b=Z1Y7WMFnimRg4gzQAiGElm3DCdv1BGyAdtBS08OcX5JRTlbZ9gME8ic8RpxPHUZ8wnJQeudY5LhDufXKj7gS9DpoVSnKzdTbzA5EoVbe3LbjorSA77MlEcP0G0/1U0AsAMK3QoVC1P3TghgIPJwKanLEYS7AGRAZ4nQ28ZVeEBI= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712301302763.5634043994329; Tue, 9 Jun 2020 07:18:21 -0700 (PDT) Received: from localhost ([::1]:54494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif51-0003sW-Qv for importer@patchew.org; Tue, 09 Jun 2020 10:18:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0p-0006qf-FF; Tue, 09 Jun 2020 10:13:59 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:27969 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0n-0007gx-MO; Tue, 09 Jun 2020 10:13:59 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:50 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:50 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aeCOXhWiEq3HFKzIt8O8T34nrD1Zx70H7jh/WGZcrQBfVQchMcF/BBi7zZ1V9BNssMYuiv3T35raxoRyyKzIrGIO3o1xdlQfLppZeFpOrBO8RCWUTF1LiUplGw2nJG2ayEH+bfRv2SLWQCM9560WWFsye4NuAffvF3/xcY8hBPfhrEtvYXcWqGzatvnjtWAy7affZy0A4jeTY+gGxi0yHynce+mTzkAVb11t9hDoR1CAQW0UQMqAkGJejrTNUayQbkRlAW3zTkz84OL7XEMrA7HfOvk+yaPchhriqPo6crRnLEyCTrgnee+4qcWbAWwwDfCUweOfNXN9+vHyjNBUjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kGeEa/tG+Uhdcvr3hUZQEhZ4NR9pDdo25ndUBd5AObc=; b=IYYUeGoa2m7ITxIhvmLbw8Gf9p7vG7EM59fXkKSFt0jFym/fBliZHaPjdNOwVYoQ81swLVxZ7F78sBIMp/yEL0Mkpf7TTJZmfgxQqXd0Pks8Qsvun+/LF10N0fuEizLc4yC4IDz8SE0ZwYFUx0Qo70KOLB2wY9nG8761QlGw1moMGGx2WwGBwfnP/TB1QaQpwkefReFPdRT2DDw8D/n3IKu5ZGKZNpTKZ2p+7IJlK9EJsIvfpsfIYW2+0154aFCl6+ifciBWaTUN0q132gm955BE9Jr1Z/UnkSNGHzgvlS7XE63SNZGnysxs/HsnoQUlnZjM0LPn+34kiNV+OYR7Kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kGeEa/tG+Uhdcvr3hUZQEhZ4NR9pDdo25ndUBd5AObc=; b=WXkEr3s26sk+Fl/lxCZV4TFgNgG7xu4avpMh3k6ASaDvohSLS3FyFnYOYFv1kL5ebAy6EN6VBBTWd8fzWL16tx1Ik9t5vqLyutppKN19llhzNsVCZBYyyBqIOkUzEYbOLcOFAG+1OH6sy9tUsHlRGzRX25VwSKlOuObfVvgZkAY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 4/7] scripts: add coroutine-wrapper.py Date: Tue, 9 Jun 2020 17:13:26 +0300 Message-Id: <20200609141329.3945-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2bed8c52-e180-44df-8f9e-08d80c7f5567 X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:651; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c/L8d78OXgsVrisgeeeZkOue54BAOGIn0DSJYt/AYK6FG+qprywX1YJmxPBmVpN7tHl/3cUcKFHFl2u32oMDC4wJoZbfdEZfNvll9VUHl3yzYU+YuZNa7ipyGg4P8Ad6Xp86XkrJyBYCdwXKy5kkJrkxpWGHXwemz/Fs+9wVk7ave1jSOU+KZX/ZUWREQ2zMPqpGV5rn4a+FmxzMK3Ho/sGyvg3E3qAQOTHaiD5WqnXriJyKUoreYvHukvSDUrSHAElK95pmrNL8Rsta/lYnl7EX1/GBxVWEG+VcrpLanUfpzCGFR+x6yXX9s5JSeKNL64GiXwZAeTYaA9zaYQULQvqh7HnqFnewLLa6R+zZGRZvoVjUpDS9pS4rBSGnbixhcQzD4l5Q3h3ls3I7ELEMZ4JnNcLmrfXaZv3qZGd1INern8I90pOJ7mcVlyemPId3Lfogm2n4QazKh9mpqRV6s8ZLpozZPYRtSUfL4Mo7np8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(30864003)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: chyrnUu2MBUf8YFeCx2Qz6jaCkoYwunl9I6diZ7ZcjfiiJDZ4yZzTN5o5eAOiVfUIaOvo+udoMDamXpmhKR8+NgQ0PvSwwAdqKH8MwknTUjaevTDbgtYb0Vu0MkavvFRDNiJkMu063h5FkCMh3lMQNV0RJw9EdpEb5Euxac/ttqEfEazk7qlTFODGlnGgWhR/JlYv3ohQ9TlWorkBSEbDHzekIGr/fljzxiHBOOEruxcw5xkz8wcNQsQl9u2qs1HZ8wHtuIRWcmzGCYw70Pyc3Yneo0oevD3vW8O6cdpbKY+QddULYyxntdvSsSa2lKjGy7SjvsOwTCthTI/KHyUF4oGSODltWWaHYuZmv/1bawEpSJu6SgPSz0YPD1gOMZMTEb7NG3NBQ44YmKn8TwftTlBGmR4rApnAUIC5uwRQWDHi4ursYGR5B9SnklP8JzfxgLdb5fXSBKDTfxrcDVU2hguukWKI9vg+d7VUwKY4kM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bed8c52-e180-44df-8f9e-08d80c7f5567 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:50.7559 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zGs3LVJmvZmAhnzsybEkWm4y7Qp5KQjNbD8NSKiNF81Ok2FhS+tdKz+JFNBTAdJPKZ1xT+9ui4eX+0RsVY08dh3R2cffMdZ2H2z423bw1YA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:47 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We have a very frequent pattern of creating coroutine from function with several arguments: - create structure to pack parameters - create _entry function to call original function taking parameters from struct - do different magic to handle completion: set ret to NOT_DONE or EINPROGRESS, use separate bool for void functions - fill the struct and create coroutine from _entry function and this struct as a parameter - do coroutine enter and BDRV_POLL_WHILE loop Let's reduce code duplication by generating coroutine wrappers. This patch adds scripts/coroutine-wrapper.py together with some friends, which will generate functions with declared prototypes marked by 'generated_co_wrapper' specifier. The usage of new code generation is as follows: 1. define somewhere int coroutine_fn bdrv_co_NAME(...) {...} function 2. declare in some header file int generated_co_wrapper bdrv_NAME(...); function with same list of parameters. (you'll need to include "block/generated-co-wrapper.h" to get the specifier) 3. both declarations should be available through block/coroutines.h header. 4. add header with generated_co_wrapper declaration into COROUTINE_HEADERS list in Makefile Still, no function is now marked, this work is for the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- Makefile | 8 ++ block/block-gen.h | 55 +++++++++ include/block/generated-co-wrapper.h | 35 ++++++ block/Makefile.objs | 1 + scripts/coroutine-wrapper.py | 174 +++++++++++++++++++++++++++ 5 files changed, 273 insertions(+) create mode 100644 block/block-gen.h create mode 100644 include/block/generated-co-wrapper.h create mode 100755 scripts/coroutine-wrapper.py diff --git a/Makefile b/Makefile index d1af126ea1..517a29810f 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,14 @@ generated-files-y +=3D $(TRACE_SOURCES) generated-files-y +=3D $(BUILD_DIR)/trace-events-all generated-files-y +=3D .git-submodule-status =20 +generated-files-y +=3D block/block-gen.c + +COROUTINE_HEADERS =3D include/block/block.h block/coroutines.h +block/block-gen.c: $(COROUTINE_HEADERS) scripts/coroutine-wrapper.py + $(call quiet-command, \ + cat $(addprefix $(SRC_PATH)/,$(COROUTINE_HEADERS)) | \ + $(SRC_PATH)/scripts/coroutine-wrapper.py > $@,"GEN","$(TARGET_DIR)$@") + trace-group-name =3D $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g') =20 tracetool-y =3D $(SRC_PATH)/scripts/tracetool.py diff --git a/block/block-gen.h b/block/block-gen.h new file mode 100644 index 0000000000..482d06737d --- /dev/null +++ b/block/block-gen.h @@ -0,0 +1,55 @@ +/* + * Block coroutine wrapping core, used by auto-generated block/block-gen.c + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2020 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_BLOCK_GEN_H +#define BLOCK_BLOCK_GEN_H + +#include "block/block_int.h" + +/* This function is called at the end of generated coroutine entries. */ +static inline void bdrv_poll_co__on_exit(void) +{ + aio_wait_kick(); +} + +/* Base structure for argument packing structures */ +typedef struct BdrvPollCo { + BlockDriverState *bs; + bool in_progress; + int ret; + Coroutine *co; /* Keep pointer here for debugging */ +} BdrvPollCo; + +static inline int bdrv_poll_co(BdrvPollCo *s) +{ + assert(!qemu_in_coroutine()); + + bdrv_coroutine_enter(s->bs, s->co); + BDRV_POLL_WHILE(s->bs, s->in_progress); + + return s->ret; +} + +#endif /* BLOCK_BLOCK_GEN_H */ diff --git a/include/block/generated-co-wrapper.h b/include/block/generated= -co-wrapper.h new file mode 100644 index 0000000000..62c6e053ba --- /dev/null +++ b/include/block/generated-co-wrapper.h @@ -0,0 +1,35 @@ +/* + * Block layer I/O functions + * + * Copyright (c) 2020 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_GENERATED_CO_WRAPPER_H +#define BLOCK_GENERATED_CO_WRAPPER_H + +/* + * generated_co_wrapper + * Function specifier, which does nothing but marking functions to be + * generated by scripts/coroutine-wrapper.py + */ +#define generated_co_wrapper + +#endif /* BLOCK_GENERATED_CO_WRAPPER_H */ diff --git a/block/Makefile.objs b/block/Makefile.objs index 3635b6b4c1..05e4d033c1 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -45,6 +45,7 @@ block-obj-y +=3D crypto.o block-obj-y +=3D aio_task.o block-obj-y +=3D backup-top.o block-obj-y +=3D filter-compress.o +block-obj-y +=3D block-gen.o common-obj-y +=3D monitor/ =20 block-obj-y +=3D stream.o diff --git a/scripts/coroutine-wrapper.py b/scripts/coroutine-wrapper.py new file mode 100755 index 0000000000..dbe6fb97d9 --- /dev/null +++ b/scripts/coroutine-wrapper.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python3 +"""Generate coroutine wrappers for block subsystem. + +The program parses one or several concatenated c files from stdin, +searches for functions with 'generated_co_wrapper' specifier +and generates corresponding wrappers on stdout. + +Usage: cat FILE.[ch]... | coroutine-wrapper.py > generated-file.c + +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 . +""" + +import sys +import re +import subprocess +from typing import Iterator + + +def prettify(code: str) -> str: + """Prettify code using clang-format if available""" + + try: + style =3D '{IndentWidth: 4, BraceWrapping: {AfterFunction: true}, = ' \ + 'BreakBeforeBraces: Custom, SortIncludes: false, ' \ + 'MaxEmptyLinesToKeep: 2}' + p =3D subprocess.run(['clang-format', f'-style=3D{style}'], check= =3DTrue, + encoding=3D'utf-8', input=3Dcode, + stdout=3Dsubprocess.PIPE) + return p.stdout + except FileNotFoundError: + return code + + +def gen_header(): + copyright =3D re.sub('^.*Copyright', 'Copyright', __doc__, flags=3Dre.= DOTALL) + copyright =3D re.sub('^(?=3D.)', ' * ', copyright.strip(), flags=3Dre.= MULTILINE) + copyright =3D re.sub('^$', ' *', copyright, flags=3Dre.MULTILINE) + return f"""\ +/* + * File is generated by scripts/coroutine-wrapper.py + * +{copyright} + */ + +#include "qemu/osdep.h" +#include "block/coroutines.h" +#include "block/block-gen.h"\ +""" + + +class ParamDecl: + param_re =3D re.compile(r'(?P' + r'(?P.*[ *])' + r'(?P[a-z][a-z0-9_]*)' + r')') + + def __init__(self, param_decl: str) -> None: + m =3D self.param_re.match(param_decl.strip()) + if m is None: + raise ValueError(f'Wrong parameter declaration: "{param_decl}"= ') + self.decl =3D m.group('decl') + self.type =3D m.group('type') + self.name =3D m.group('name') + + +class FuncDecl: + def __init__(self, return_type: str, name: str, args: str) -> None: + self.return_type =3D return_type.strip() + self.name =3D name.strip() + self.args =3D [ParamDecl(arg.strip()) for arg in args.split(',')] + + def gen_list(self, format: str) -> str: + return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) + + def gen_block(self, format: str) -> str: + return '\n'.join(format.format_map(arg.__dict__) for arg in self.a= rgs) + + +# Match wrappers declared with a generated_co_wrapper mark +func_decl_re =3D re.compile(r'^int\s*generated_co_wrapper\s*' + r'(?P[a-z][a-z0-9_]*)' + r'\((?P[^)]*)\);$', re.MULTILINE) + + +def func_decl_iter(text: str) -> Iterator: + for m in func_decl_re.finditer(text): + yield FuncDecl(return_type=3D'int', + name=3Dm.group('wrapper_name'), + args=3Dm.group('args')) + + +def snake_to_camel(func_name: str) -> str: + """ + Convert underscore names like 'some_function_name' to camel-case like + 'SomeFunctionName' + """ + words =3D func_name.split('_') + words =3D [w[0].upper() + w[1:] for w in words] + return ''.join(words) + + +def gen_wrapper(func: FuncDecl) -> str: + assert func.name.startswith('bdrv_') + assert not func.name.startswith('bdrv_co_') + assert func.return_type =3D=3D 'int' + assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *'] + + name =3D 'bdrv_co_' + func.name[5:] + bs =3D 'bs' if func.args[0].type =3D=3D 'BlockDriverState *' else 'chi= ld->bs' + struct_name =3D snake_to_camel(name) + + return f"""\ +/* + * Wrappers for {name} + */ + +typedef struct {struct_name} {{ + BdrvPollCo poll_state; +{ func.gen_block(' {decl};') } +}} {struct_name}; + +static void coroutine_fn {name}_entry(void *opaque) +{{ + {struct_name} *s =3D opaque; + + s->poll_state.ret =3D {name}({ func.gen_list('s->{name}') }); + s->poll_state.in_progress =3D false; + + bdrv_poll_co__on_exit(); +}} + +int {func.name}({ func.gen_list('{decl}') }) +{{ + if (qemu_in_coroutine()) {{ + return {name}({ func.gen_list('{name}') }); + }} else {{ + {struct_name} s =3D {{ + .poll_state.bs =3D {bs}, + .poll_state.in_progress =3D true, + +{ func.gen_block(' .{name} =3D {name},') } + }}; + + s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); + + return bdrv_poll_co(&s.poll_state); + }} +}}""" + + +def gen_wrappers_file(input_code: str) -> str: + res =3D gen_header() + for func in func_decl_iter(input_code): + res +=3D '\n\n\n' + res +=3D gen_wrapper(func) + + return prettify(res) # prettify to wrap long lines + + +if __name__ =3D=3D '__main__': + print(gen_wrappers_file(sys.stdin.read())) --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712449; cv=pass; d=zohomail.com; s=zohoarc; b=d1dhNjp0cDUbHTuqjEl5zF7ebyz5Ud1BH6A+xM7vgqwjcdsdRPkI5wAKG7wdM/upEDC9Ps9lWKdqxQ/0vINb1b5HgdX9V+6E5Ci8zqG8VBfvHc0iX/CmpVhYuresSj0GEQodd7j2Jkg4gC5PMUVE/SEhTmw756zKilG76ydhrwM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712449; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RHNmPReNB/FFQ2Oj7AfM9sIBpQdZfZsnC0Nu7dHRlVk=; b=DoaOzComLnb0Gpju6yIHi/JB6Gu2k5e9BWkO5Hv9gGI6MgqlJq2MN5bf+IxVyfXFebAKvg8sCSxhARVG1P1r/Xe2L+Ovh1Znc0pgL2onrPYmu71k0aYz33gKlGK/0M4qh4xktdB6m3vxen6MxFNuELVtb+FFu9KUSMMdFzOqho0= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712449765245.9343867511053; Tue, 9 Jun 2020 07:20:49 -0700 (PDT) Received: from localhost ([::1]:32838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif7Q-0006dm-71 for importer@patchew.org; Tue, 09 Jun 2020 10:20:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0r-0006vA-9v; Tue, 09 Jun 2020 10:14:01 -0400 Received: from mail-am6eur05on2106.outbound.protection.outlook.com ([40.107.22.106]:18497 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0p-0007hk-LJ; Tue, 09 Jun 2020 10:14:00 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:51 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:51 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g1SvM8H+lbjvLv8+a2VkMD8DUjjhs97UBr3gxFIJvudd4dJ1/+veh9Snbu1+XZpAfkw2+LwaLIRIXwFDKlCPkrWTaPVfyw40jHpfbnt2n45/2ZXXl0KRj24T7OHsM3afzTMroULtszHU6QNysiFrrcV7Zsc56TCwj0SHzrHLsAscrQQLia7K29FjnjOUZKDLXckNvyB0Sm/ApDnA3xipZNgVkzG/nXV6RJh3XHz8F4fM6FySpYyX5yTne98reJ/8BL0lQ86liSV8RQcK6hEhJWeA0ATaV0hKUo8TLJfoXumOTkPzGf7cKtRZ7B4zHQA0ODOY+KBnqUlxPHL80m32Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RHNmPReNB/FFQ2Oj7AfM9sIBpQdZfZsnC0Nu7dHRlVk=; b=gDGUxpDi4sdteizN4IbtpRT2tSaDlvRVSMKN1aCXvGdepi30f/ytzeBFqf2dg4aRz0QVU1CRST0lP6fCzrdNLCg4mqe54WTaaW+nXMT2t8yT9Ab0+Q1fAjuFBvloPY847sQua6RUTc1dduFJjak7knGaMK+m+LwUjpaFtICUNq/gbEMPWevErV1X5v6y2y7VnHD8E5jHgaQwj0LurKlWZrwGdKjJzp4lrr5/TziUqKwAj53ia8Yhb/e/gNPI4uVm1WWE53QrJ2M5nau3Q3YVecZnVmX7h361TRLM5u7Y4QFHKdJXkplYwjeN7SAfI6iqTUSHeUs7yOF3Ap7k57y7ew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RHNmPReNB/FFQ2Oj7AfM9sIBpQdZfZsnC0Nu7dHRlVk=; b=F+2R1YwYqy/y12zZ6XfEdBxTdN9qEPu65tqIwwZcLB/UTCxSAtYoZW4B3vrsv8ssS8OpKP/qvS4CeT9WlxyX/sQzKxtBf+3jDSDr9OVZecj99tSowWhuDuhs+0ax1uQN6LBaL+vc+sm43Y42dzsTh2jGx/VG4h4COAGCpFKVB70= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 5/7] block: generate coroutine-wrapper code Date: Tue, 9 Jun 2020 17:13:27 +0300 Message-Id: <20200609141329.3945-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a12ca7f8-0f76-4b10-09a5-08d80c7f55f8 X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:79; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ltCw9Zx6i5MHBrHzghq9bfo/JosovHwY6/O98m/vzvk5TEegpzW36tqBN/RRsnHkFchFuP810guPIFzI2xdUTViTOyUuLAUyULLfKo14DouoZR3J2cok8EHm4k/sBDQ4Dyrs29NMf+wIa0D8HBTh0Eenl7rfWmLKIMeWP549hnU66u01/KWCBTZKyU09XBahTHlk9AW9BOvU3Dl1GcscEiG3u8oLJuYt9k7CjBH5jHhEKuMg/S0AFCKrz7n8c4TZUrAlcM6LyRdKQY2XkGPmCRs2mK6JAOV5oR3ZyKnNBpeVI59pAOJPhZRc0pO3MNhKGoz/j6/No9zaCKXSO1UdXJ0vLong4sFmuhI6cs+QE4eNo4V+00PEA+8YcU4zEpw5 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(30864003)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: qWkrsavfQt1Mc09PbJvIfUI7jDG9BWuAXctJfhiYZgUyxzIdK7UbDMgQWtIOB4yTJOc5akp+Yt4qSIS8L/aK9VBmLXEXLk9D6pCtZdhrJgMKkhD+eGPNTloOBAegqRFQWbvC0ezjVOoPO/UUIfUVMb3dHKWh+t487ohsm/0dshCKaZKVQ2RtwKERsk4dX/m+xiPLo6mLrndAUV9SlMXECjSn7E2bhs5obcJSYyMLriz4DvgSZ6/RVDj7mvZ7ztj6MT+NzFGpmAGna/t75VsBmPVf9c8mYph/uD56TIhOT3pDuFrCguxv6+a1ooArpaWZBN1LRx2CZkCadwudoawsvMo8rHnDB0RQ2I0ScH4LF1FxOQ+r6WdM2DGWZl8jE0hSngXj9T7hgmOIiUmCqlb10szp0sdsxxXHdlanjiKpWejHLfe/ICcHhuMIi8uPtVahoKXjBCwpiAZWWrNcvFsAnqt/Bq20m2c4Q2tSACs6IG0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a12ca7f8-0f76-4b10-09a5-08d80c7f55f8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:51.7346 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +5HgQH812Pn7QHxAxDE0fA4nm9V88qn4ujPH+J0tpbZYmRGTVAV/D2nwthHkrVG4mAtdc7c+rqxNl/75LdD195wKRvEtFFnhfL6NW0y7iZA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.106; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:55 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Use code generation implemented in previous commit to generated coroutine wrappers in block.c and block/io.c Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/coroutines.h | 7 +- include/block/block.h | 17 ++-- block.c | 73 --------------- block/io.c | 212 ------------------------------------------ 4 files changed, 15 insertions(+), 294 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 9ce1730a09..145a2d2645 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -26,6 +26,7 @@ #define BLOCK_COROUTINES_INT_H =20 #include "block/block_int.h" +#include "block/generated-co-wrapper.h" =20 int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); @@ -34,7 +35,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverStat= e *bs, Error **errp); int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); -int +int generated_co_wrapper bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); =20 @@ -47,7 +48,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file); -int +int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -60,7 +61,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); -int +int generated_co_wrapper bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); =20 diff --git a/include/block/block.h b/include/block/block.h index 46965a7780..46c8b7816e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -9,6 +9,7 @@ #include "block/dirty-bitmap.h" #include "block/blockjob.h" #include "qemu/hbitmap.h" +#include "block/generated-co-wrapper.h" =20 /* block.c */ typedef struct BlockDriver BlockDriver; @@ -398,8 +399,9 @@ void bdrv_refresh_filename(BlockDriverState *bs); int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, PreallocMode prealloc, BdrvRequestFlags = flags, Error **errp); -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp); +int generated_co_wrapper +bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); @@ -441,7 +443,8 @@ typedef enum { BDRV_FIX_ERRORS =3D 2, } BdrvCheckMode; =20 -int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode f= ix); +int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult = *res, + BdrvCheckMode fix); =20 /* The units of offset and total_work_size may be chosen arbitrarily by the * block driver; total_work_size may change during the course of the amend= ment @@ -464,12 +467,13 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Invalidate any cached metadata used by image formats */ -int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); +int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, + Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); =20 /* Ensure contents are flushed to disk. */ -int bdrv_flush(BlockDriverState *bs); +int generated_co_wrapper bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); int bdrv_flush_all(void); void bdrv_close_all(void); @@ -484,7 +488,8 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes); int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); diff --git a/block.c b/block.c index 2ca9267729..3046696f30 100644 --- a/block.c +++ b/block.c @@ -4640,43 +4640,6 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, return bs->drv->bdrv_co_check(bs, res, fix); } =20 -typedef struct CheckCo { - BlockDriverState *bs; - BdrvCheckResult *res; - BdrvCheckMode fix; - int ret; -} CheckCo; - -static void coroutine_fn bdrv_check_co_entry(void *opaque) -{ - CheckCo *cco =3D opaque; - cco->ret =3D bdrv_co_check(cco->bs, cco->res, cco->fix); - aio_wait_kick(); -} - -int bdrv_check(BlockDriverState *bs, - BdrvCheckResult *res, BdrvCheckMode fix) -{ - Coroutine *co; - CheckCo cco =3D { - .bs =3D bs, - .res =3D res, - .ret =3D -EINPROGRESS, - .fix =3D fix, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_check_co_entry(&cco); - } else { - co =3D qemu_coroutine_create(bdrv_check_co_entry, &cco); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, cco.ret =3D=3D -EINPROGRESS); - } - - return cco.ret; -} - /* * Return values: * 0 - success @@ -5723,42 +5686,6 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDrive= rState *bs, Error **errp) return 0; } =20 -typedef struct InvalidateCacheCo { - BlockDriverState *bs; - Error **errp; - bool done; - int ret; -} InvalidateCacheCo; - -static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) -{ - InvalidateCacheCo *ico =3D opaque; - ico->ret =3D bdrv_co_invalidate_cache(ico->bs, ico->errp); - ico->done =3D true; - aio_wait_kick(); -} - -int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) -{ - Coroutine *co; - InvalidateCacheCo ico =3D { - .bs =3D bs, - .done =3D false, - .errp =3D errp - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_invalidate_cache_co_entry(&ico); - } else { - co =3D qemu_coroutine_create(bdrv_invalidate_cache_co_entry, &ico); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, !ico.done); - } - - return ico.ret; -} - void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; diff --git a/block/io.c b/block/io.c index deb9ca8d82..36fbf9e1fa 100644 --- a/block/io.c +++ b/block/io.c @@ -890,50 +890,6 @@ static int bdrv_check_byte_request(BlockDriverState *b= s, int64_t offset, return 0; } =20 -typedef int coroutine_fn BdrvRequestEntry(void *opaque); -typedef struct BdrvRunCo { - BdrvRequestEntry *entry; - void *opaque; - int ret; - bool done; - Coroutine *co; /* Coroutine, running bdrv_run_co_entry, for debugging = */ -} BdrvRunCo; - -static void coroutine_fn bdrv_run_co_entry(void *opaque) -{ - BdrvRunCo *arg =3D opaque; - - arg->ret =3D arg->entry(arg->opaque); - arg->done =3D true; - aio_wait_kick(); -} - -static int bdrv_run_co(BlockDriverState *bs, BdrvRequestEntry *entry, - void *opaque) -{ - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - return entry(opaque); - } else { - BdrvRunCo s =3D { .entry =3D entry, .opaque =3D opaque }; - - s.co =3D qemu_coroutine_create(bdrv_run_co_entry, &s); - bdrv_coroutine_enter(bs, s.co); - - BDRV_POLL_WHILE(bs, !s.done); - - return s.ret; - } -} - -typedef struct RwCo { - BdrvChild *child; - int64_t offset; - QEMUIOVector *qiov; - bool is_write; - BdrvRequestFlags flags; -} RwCo; - int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags) @@ -945,32 +901,6 @@ int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_= t offset, } } =20 -static int coroutine_fn bdrv_rw_co_entry(void *opaque) -{ - RwCo *rwco =3D opaque; - - return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, - rwco->is_write, rwco->flags); -} - -/* - * Process a vectored synchronous request using coroutines - */ -int bdrv_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - RwCo rwco =3D { - .child =3D child, - .offset =3D offset, - .qiov =3D qiov, - .is_write =3D is_write, - .flags =3D flags, - }; - - return bdrv_run_co(child->bs, bdrv_rw_co_entry, &rwco); -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -2245,18 +2175,6 @@ int bdrv_flush_all(void) return result; } =20 - -typedef struct BdrvCoBlockStatusData { - BlockDriverState *bs; - BlockDriverState *base; - bool want_zero; - int64_t offset; - int64_t bytes; - int64_t *pnum; - int64_t *map; - BlockDriverState **file; -} BdrvCoBlockStatusData; - int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, bool want_zero, int64_t offset, @@ -2508,43 +2426,6 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, return ret; } =20 -/* Coroutine wrapper for bdrv_block_status_above() */ -static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque) -{ - BdrvCoBlockStatusData *data =3D opaque; - - return bdrv_co_common_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->= file); -} - -/* - * Synchronous wrapper around bdrv_co_block_status_above(). - * - * See bdrv_co_block_status_above() for details. - */ -int bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, int64_t offset, - int64_t bytes, int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - BdrvCoBlockStatusData data =3D { - .bs =3D bs, - .base =3D base, - .want_zero =3D want_zero, - .offset =3D offset, - .bytes =3D bytes, - .pnum =3D pnum, - .map =3D map, - .file =3D file, - }; - - return bdrv_run_co(bs, bdrv_block_status_above_co_entry, &data); -} - int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) @@ -2638,13 +2519,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 0; } =20 -typedef struct BdrvVmstateCo { - BlockDriverState *bs; - QEMUIOVector *qiov; - int64_t pos; - bool is_read; -} BdrvVmstateCo; - int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) @@ -2670,26 +2544,6 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVecto= r *qiov, int64_t pos, return ret; } =20 -static int coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque) -{ - BdrvVmstateCo *co =3D opaque; - - return bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); -} - -int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) -{ - BdrvVmstateCo data =3D { - .bs =3D bs, - .qiov =3D qiov, - .pos =3D pos, - .is_read =3D is_read, - }; - - return bdrv_run_co(bs, bdrv_co_rw_vmstate_entry, &data); -} - int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { @@ -2765,11 +2619,6 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ =20 -static int coroutine_fn bdrv_flush_co_entry(void *opaque) -{ - return bdrv_co_flush(opaque); -} - int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int current_gen; @@ -2882,24 +2731,6 @@ early_exit: return ret; } =20 -int bdrv_flush(BlockDriverState *bs) -{ - return bdrv_run_co(bs, bdrv_flush_co_entry, bs); -} - -typedef struct DiscardCo { - BdrvChild *child; - int64_t offset; - int64_t bytes; -} DiscardCo; - -static int coroutine_fn bdrv_pdiscard_co_entry(void *opaque) -{ - DiscardCo *rwco =3D opaque; - - return bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); -} - int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { @@ -3014,17 +2845,6 @@ out: return ret; } =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) -{ - DiscardCo rwco =3D { - .child =3D child, - .offset =3D offset, - .bytes =3D bytes, - }; - - return bdrv_run_co(child->bs, bdrv_pdiscard_co_entry, &rwco); -} - int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) { BlockDriver *drv =3D bs->drv; @@ -3422,35 +3242,3 @@ out: =20 return ret; } - -typedef struct TruncateCo { - BdrvChild *child; - int64_t offset; - bool exact; - PreallocMode prealloc; - BdrvRequestFlags flags; - Error **errp; -} TruncateCo; - -static int coroutine_fn bdrv_truncate_co_entry(void *opaque) -{ - TruncateCo *tco =3D opaque; - - return bdrv_co_truncate(tco->child, tco->offset, tco->exact, - tco->prealloc, tco->flags, tco->errp); -} - -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp) -{ - TruncateCo tco =3D { - .child =3D child, - .offset =3D offset, - .exact =3D exact, - .prealloc =3D prealloc, - .flags =3D flags, - .errp =3D errp, - }; - - return bdrv_run_co(child->bs, bdrv_truncate_co_entry, &tco); -} --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712605; cv=pass; d=zohomail.com; s=zohoarc; b=B4OFr+zuxeMMxlfvDprl9/QIcVSR9oYi+MBpNRXOAy6z+jomoRQZXqhVUp9LN6g1lVoYCuYEfpuBjTP74LwvrE+IHnQ+9iX/soGWEsH66jRuXdqS5cmf5tfAOHqXMpwasH6lgjzzV4MT0TIZAg6tyPEHY4EUXHYr38iWj8uKQTw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712605; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=P+d3F4A0xFO02lJNWxruw6tLeIUskt33CWkhSv3cj6Q=; b=GqMcmWBjAGbvUG1qqoSR0Vfg6uhZqPsiyTSJI8RFmYbDTo9SHuPVPzHTxn4TUnHW/kCNKihGOwCMewR0TLm9xHnaXYaPXBBTOZiMK11QmArgQ2FUEv9pITL7FhDYVrUj7a4lFvryEUFLDIKDHZ6G/uIxBrEaw+wQ/djJ5xtrxAY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712605566230.98831820207636; Tue, 9 Jun 2020 07:23:25 -0700 (PDT) Received: from localhost ([::1]:41202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif9w-0001j5-5Z for importer@patchew.org; Tue, 09 Jun 2020 10:23:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0r-0006vf-Gx; Tue, 09 Jun 2020 10:14:01 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:27969 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0q-0007gx-0Y; Tue, 09 Jun 2020 10:14:01 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:52 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:52 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K+urYbJB8V4je8x1nVtfsClZT3e0q4ImGZYhwUqFs/YdDdo4vem/GjbNqrz/VCtVCvb46NYdqQeqmp8qQDdIejN4rW01gMkoC4JTCkkT6mQNLcoeM1L9LiZBswDy4IwhXhrdDuuy8ONvhzZgR4880cU13kJQFou/zdYeIvWS3nor+z1fc9MJsTyTeVxdoRCmSeJDColbu4t72/xSGgl9RdlBYJq7jttqidvAdGNFNxcqqtDKArAKcdt+840PXzGx5kOJ0guYQOFcX+7N6wGtPyvEkugIdcNBJNo3gMHSGlQFa1XUUhNlgIKwnCPu1pxtgeFS2IpzIZtbdwI9Eah0kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P+d3F4A0xFO02lJNWxruw6tLeIUskt33CWkhSv3cj6Q=; b=ggK+EKRV8jqv+k7XZLYd5q2a6ucpzd7xgQwWi4biLuMX0QdBJqq0Q0illz1PE1DArZy8+1TeOGmjnp8HY8eOyMsa4NFSLOT/nrIT2ha6tJAiVYW5KE3bBVShXCPUMtQqbStGEZZscFrDmcUKcApHqqpKsxJmExjLjsoMm5403IizXn2dzE/GPIJy7UATbXWGEa5tcYbc9n0+Zoeilk6hscGFXM1u8HjoqxQ54X/1uOEIxZuFa4BGsZcp7t9ptz27tes3XvJm4llDv0+tZyPM4Wq1az9ZDL1+7nah6EC2wAKldoqbrjNElNGFBOiird1ZarCvf6bcntbbkFIcqkwsqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P+d3F4A0xFO02lJNWxruw6tLeIUskt33CWkhSv3cj6Q=; b=n2EPKhtpPlQKm/G3O1AfLBSZijhjyGNjBHu6VA9sBU9A1NIFVVSdgl5JnRJAS/qIDFEaGSzyf28hRdxDSVX51eEZ7BCgzQS+QgZSJ0aARTApv7Mrv0kAUf3458fM+2fUeNrADw1VGNFvcI8wVG6HTCvSO4kzSI1upkkryz4puXI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 6/7] block: drop bdrv_prwv Date: Tue, 9 Jun 2020 17:13:28 +0300 Message-Id: <20200609141329.3945-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 717670a4-2523-459f-0885-08d80c7f568a X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W8beSRdC6HsZa/9HEB/B8Kt+AqDb6gKdl+8r2JxzzB5jC9AUdYw58OvFLC6S7tpDMvkTurAzz+Gv7MJJCj1EY+VffT9biSVbBWQPf9PwJ70mxo+/9VFW/S7Ss2V+RaK8jdSoRwdXwJFRxBL9ac0LFCRpRriqf3UhNEM8oHjKtOMr2NQ8s83qNlr7igVF89zzoPUBaiFfdWryMamSe3QkG3t76CfbL1D9CTlf03zzdiu9DBUhiJJnpinANBXaM2Ary5kDfLrIlUSVGV+pg0L5M/WSYiZ4iX9b0rILh25uZ+G8csm+xKSTnLu+a9FoFGNYjHr8uR7Nsuq2zAdZELKdY0ZTt9jQaX9oLkqBMv3PetfWaADV9BuuHTnOi1X3Sy2N X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 9f1w7xYRVrptUME9JJNTIxIS8GFUFktEmjr7wUTrT4UEFFrvMQDjKi+HoSOdgsWKGGNw8TWk0WrQsbpEhj3xSLirCYShegvVW7qiUn0RoGynoKH3WoSIEaxTSs1q0OrcqLLuYnIehO+aBY5PDMPhWwh2cgNkMKXJ9nmuMy8wuLdClA2wX3Vu2kVFi6OXD9RHGsaHx4K51HaRkOmYMLAWNR+rewAH8fUvO66RJO3RPqxDkNsQGxjBz5aTpcQWAFNRenOBKUsX7w9ZVrkhCtz8v/ZxeqYs8MkhHVF6KaQ11K5viYKgb9WnIad+N/i18uobAkTJTKwJvIYtGpFiIls4FeLIFnSy/L+FNTMTGzpJYHKCwdPBa9Rjf8zlYMCVyJuyFqUt20OzIyw6rSOHo2NIn09rMnlrLtSm2xyzSikSTZ4WDhB1tXTmcDfMayJDQv6Lh+uV0t+1573I7eTMcwr/ZNO/UwT4ObUS7ymBjD5dpRw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 717670a4-2523-459f-0885-08d80c7f568a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:52.6615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AAY4dcROqw/zCJyhazbIVLd7+o+pqiHC57tF1yc0H+na4icaktVkf0Uhiv7qCZflu/qA5c4tM1yKbCv5WlTwodGbMGiLNWmBwBKAu6sh4RI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:47 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Now that we are not maintaining boilerplate code for coroutine wrappers, there is no more sense in keeping the extra indirection layer of bdrv_prwv(). Let's drop it and instead generate pure bdrv_preadv() and bdrv_pwritev(). Currently, bdrv_pwritev() and bdrv_preadv() are returning bytes on success, auto generated functions will instead return zero, as their _co_ prototype. Still, it's simple to make the conversion safe: the only external user of bdrv_pwritev() is test-bdrv-drain, and it is comfortable enough with bdrv_co_pwritev() instead. So prototypes are moved to local block/coroutines.h. Next, the only internal use is bdrv_pread() and bdrv_pwrite(), which are modified to return bytes on success. Of course, it would be great to convert bdrv_pread() and bdrv_pwrite() to return 0 on success. But this requires audit (and probably conversion) of all their users, let's leave it for another day refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/coroutines.h | 10 ++++----- include/block/block.h | 2 -- block/io.c | 49 ++++++++--------------------------------- tests/test-bdrv-drain.c | 2 +- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 145a2d2645..56c0be6f8f 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -32,12 +32,12 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp); =20 -int coroutine_fn -bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); int generated_co_wrapper -bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); +bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); +int generated_co_wrapper +bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); =20 int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index 46c8b7816e..dadb6e796f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -379,9 +379,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes); -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es); -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, const void *buf, int count); /* diff --git a/block/io.c b/block/io.c index 36fbf9e1fa..3060c7e6ed 100644 --- a/block/io.c +++ b/block/io.c @@ -890,23 +890,11 @@ static int bdrv_check_byte_request(BlockDriverState *= bs, int64_t offset, return 0; } =20 -int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - if (is_write) { - return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); - } else { - return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); - } -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); + return bdrv_pwritev(child, offset, bytes, NULL, + BDRV_REQ_ZERO_WRITE | flags); } =20 /* @@ -950,41 +938,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) } } =20 -/* return < 0 if error. See bdrv_pwrite() for the return codes */ -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret =3D bdrv_prwv(child, offset, qiov, false, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; -} - /* See bdrv_pwrite() for the return codes */ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; + ret =3D bdrv_preadv(child, offset, bytes, &qiov, 0); =20 - ret =3D bdrv_prwv(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; + return ret < 0 ? ret : bytes; } =20 /* Return no. of bytes on success or < 0 on error. Important errors are: @@ -995,13 +961,16 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) */ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_pwritev(child, offset, &qiov); + ret =3D bdrv_pwritev(child, offset, bytes, &qiov, 0); + + return ret < 0 ? ret : bytes; } =20 /* diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 1107271840..1595bbc92e 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1872,7 +1872,7 @@ static int coroutine_fn bdrv_replace_test_co_preadv(B= lockDriverState *bs, } s->io_co =3D NULL; =20 - ret =3D bdrv_preadv(bs->backing, offset, qiov); + ret =3D bdrv_co_preadv(bs->backing, offset, bytes, qiov, 0); s->has_read =3D true; =20 /* Wake up drain_co if it runs */ --=20 2.21.0 From nobody Fri May 17 22:25:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1591712157; cv=pass; d=zohomail.com; s=zohoarc; b=nSm0qDwsBK9uSOBiHl1WtLC8Rb5WLid0sqPj87YccMQ/tMHYJU5nw6LgCvjDJ1yzg2y60lnFIMlw30/IsKuAt2W28lFNAenqp83oeoeUJIE7HylFCpCBdqGy10PEzc2wznPKNCKuz/EhEEFZfZO3VYa7rAQDxSCObPswib2q0S0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591712157; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9xuWWArO7p4I0F+lEkAtacYWCf55HAJXFv7UbUiYUGk=; b=J5rpgUb4e0RbdNi6PBkfs6J6h3rQV3c5dflrImKLDHNgw2vHtoJA+FH7QLze55rqVppMoOjNxkXHM9aLzlpSICrvE6IURevbcp+PquFC12ulbIDWYmW8VKMgUFjerxeqyAjrRHR2yI8iOpdBbcgI8jZQMgL3s7baCu9F/RTBCU4= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591712157449190.922813407823; Tue, 9 Jun 2020 07:15:57 -0700 (PDT) Received: from localhost ([::1]:47338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jif2g-0000Xw-0C for importer@patchew.org; Tue, 09 Jun 2020 10:15:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54714) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0s-0006yN-Uc; Tue, 09 Jun 2020 10:14:02 -0400 Received: from mail-am6eur05on2106.outbound.protection.outlook.com ([40.107.22.106]:18497 helo=EUR05-AM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jif0r-0007hk-Sj; Tue, 09 Jun 2020 10:14:02 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Tue, 9 Jun 2020 14:13:53 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Tue, 9 Jun 2020 14:13:53 +0000 Received: from localhost.localdomain (185.215.60.180) by FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20 via Frontend Transport; Tue, 9 Jun 2020 14:13:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Or3vjzDLCt8BdMjYaXO76iyg5FXdESmIDymUjYFsaCYgCSVDJlG8b6fGwvgxSP9rLdw6b6O6tZJTm0wYNFsHXmLsNI90jjo3YUw8+rbjHqWsaU+730AmxTt1xCaGr7qUv4YS8WRQflM8wjGHMTRpL2HAoEi6vp7H0OUgiu6uQNHkCBJu8TWlGF2CasleavfnozOdKjujGYdo2tuNc3AnppiAsZiCTCyrR3C1nP9mUC7TfX2wbJATLjufwRABHgIVg4HAsiJ7Y22T+JUU91qv3JlrJws+p1LQ+kONRTg5LeaSSHvpwKy6HmhJKi+kQwGBGXNstu+DAPXloRNMHBNhPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9xuWWArO7p4I0F+lEkAtacYWCf55HAJXFv7UbUiYUGk=; b=at4WC/szIeICBVLpmBbWU2V0R+I9/ohISrda3+ND3U0Mc9dSMIt6VInQKXXcqKCm4xcAwmiahUmUhAxOo8QaSMquitAooBvSigTbzcbzyIePEoLI78by/oK0/lvX2H2ogGryF9wVpiiX0ShoZmuewNGaH3N8QueaDS679RO6WdY0XhC44sC5fnRVJCQb0E6D9fR8gF9ucCPizvaeNR/i0ZxqGl82SHX8uZDo5cIk6FoLmgUeB5TsIwsmeJFWYLA/cYugjQsDAl3daObFNMOZqzl4rqO8wdWRr3hGPG8C+sb/DAThM6VtcIKpjRYL/vzvliiKrDUndMm8TfHn8svOkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9xuWWArO7p4I0F+lEkAtacYWCf55HAJXFv7UbUiYUGk=; b=ZUFzjIhUHqFm+wVqZT5xJl4qFDXIObeci7dCxhfNFnKqoPS66PmTuK9vaMcLmbYIyLaEmImwT7Tsv4kv5zlyps6esSDLe81RgxdjNdgniy6LI3KiVttnXyNo3FY8yCw2Y4AgPOaVDCvGJi8ZFAruB9Y2m94jWpBM9pkLRQIUzp8= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v6 7/7] block/io: refactor save/load vmstate Date: Tue, 9 Jun 2020 17:13:29 +0300 Message-Id: <20200609141329.3945-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200609141329.3945-1-vsementsov@virtuozzo.com> References: <20200609141329.3945-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0002.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::12) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.180] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 206b2d25-aa5b-4f55-75b0-08d80c7f571e X-MS-TrafficTypeDiagnostic: AM7PR08MB5494: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:153; X-Forefront-PRVS: 042957ACD7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6A7nyRdgWmkC4x6O6SEbx59d9T/vdcJD+Gu97pR3ViQXSbeRvDps+Cg/+s8GCcjtNIvf1870iOIFVxNjBrDAPpn1my//wno9A64aNoS/LalU2FophLltZ7bSARSTTCIXtS+EBq7dldL39Y7b0G6m6ejyapPKKPVB9oIH2rk+w4UCReHRF/Ibh4bqqQ7n2TmJcU4W7QL8le57wVY1UkgRyjn3fosVqmIg2S1O3LD8cZhfyjNEC6eWZ3Viz5Qmrjs8+f+vzqx8gA1R4jng+vsAJpV4W5eb9igrTZwa/EB4m0eRTRDHpXM79t5blr5SFQK66kPW6nk07t5CWJd89fe9xZ7BkAEAz3ERE2i5BlaWf70pWxEu9dQofFhotPu5hW5y X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(366004)(376002)(136003)(396003)(39850400004)(346002)(2906002)(6512007)(8676002)(83380400001)(6506007)(16526019)(186003)(26005)(6486002)(478600001)(36756003)(69590400007)(6666004)(8936002)(52116002)(6916009)(66476007)(66946007)(5660300002)(66556008)(1076003)(86362001)(4326008)(2616005)(316002)(107886003)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 5HssCftwQJMb0AhKw8FVIl8bm00a0VlT2mRoN73xZsXhPa42JBFf/Pm6g1r1q5EDSKIxzZy+Cwbadj84hay/wouJ07juspi6S6guI86mwRTgN71gMCOAGxGyqX7TlYhQNt80rgBAQZY0+VztznlIomQB8s0mDjnIvZriAp98yxBEp+/cDX40S/T3dMCSIV2P4f1iQ8fO9tWEvUlszh0R9Mlsj+oIKClI/aCughPZ+vQI5zidrjC2mYwsxnsjcstiFSeanJfBBCfEJcqfTX1n128wFOrDcksQkLd5H/TOisfS9aCCCmgGf7KR7/U6fPRI3IO756sLQ5CWGQvzZ60JwXRK3vmz3VJ0No/KT730YBsz00N5BJuoB+IES9jkBvkZ10UDHj4rL6Nzbc9UJ1QGkaK+BG8uAmK74uiajWxe1lEbb7b32w4BCvgX6LbxnNPPUy40GZ3mogF9eNCi1eMMx7486Gc8apeCA2Dt9fgY5BU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 206b2d25-aa5b-4f55-75b0-08d80c7f571e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jun 2020 14:13:53.6034 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: prKhldKxicGN8fIfoRkaMRy3UxBz56fIXTQMueZKdxlgoeD2/uHHOUossPjbSsULnIfmbvuuHELG5+DNuvtEHuGCKCCK8B68Au1QuHXWmYY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5494 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.106; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 10:13:55 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/coroutines.h | 10 +++---- include/block/block.h | 6 ++-- block/io.c | 67 ++++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 56c0be6f8f..7e14fdeccf 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -58,11 +58,9 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); -int generated_co_wrapper -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); +int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); +int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); =20 #endif /* BLOCK_COROUTINES_INT_H */ diff --git a/include/block/block.h b/include/block/block.h index dadb6e796f..cc2edbeb65 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -568,8 +568,10 @@ int path_has_protocol(const char *path); int path_is_absolute(const char *path); char *path_combine(const char *base_path, const char *filename); =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos); +int generated_co_wrapper +bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper +bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size); =20 diff --git a/block/io.c b/block/io.c index 3060c7e6ed..83ffc7d390 100644 --- a/block/io.c +++ b/block/io.c @@ -2489,66 +2489,67 @@ int bdrv_is_allocated_above(BlockDriverState *top, } =20 int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { BlockDriver *drv =3D bs->drv; int ret =3D -ENOTSUP; =20 + if (!drv) { + return -ENOMEDIUM; + } + bdrv_inc_in_flight(bs); =20 - if (!drv) { - ret =3D -ENOMEDIUM; - } else if (drv->bdrv_load_vmstate) { - if (is_read) { - ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); - } else { - ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); - } + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); } else if (bs->file) { - ret =3D bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + ret =3D bdrv_co_readv_vmstate(bs->file->bs, qiov, pos); } =20 bdrv_dec_in_flight(bs); + return ret; } =20 -int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size) +int coroutine_fn +bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + BlockDriver *drv =3D bs->drv; + int ret =3D -ENOTSUP; =20 - ret =3D bdrv_writev_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; + if (!drv) { + return -ENOMEDIUM; } =20 - return size; -} + bdrv_inc_in_flight(bs); =20 -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos) -{ - return bdrv_rw_vmstate(bs, qiov, pos, false); + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); + } else if (bs->file) { + ret =3D bdrv_co_writev_vmstate(bs->file->bs, qiov, pos); + } + + bdrv_dec_in_flight(bs); + + return ret; } =20 -int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, +int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; - - ret =3D bdrv_readv_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } + int ret =3D bdrv_writev_vmstate(bs, &qiov, pos); =20 - return size; + return ret < 0 ? ret : size; } =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) +int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size) { - return bdrv_rw_vmstate(bs, qiov, pos, true); + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); + int ret =3D bdrv_readv_vmstate(bs, &qiov, pos); + + return ret < 0 ? ret : size; } =20 /**************************************************************/ --=20 2.21.0