From patchwork Tue Sep 15 16:44:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 273679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 471F1C43461 for ; Tue, 15 Sep 2020 16:51:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BFF5120809 for ; Tue, 15 Sep 2020 16:51:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="S6hJvgfI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFF5120809 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIEB6-0001Dx-R7 for qemu-devel@archiver.kernel.org; Tue, 15 Sep 2020 12:51:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4U-0000LR-HD; Tue, 15 Sep 2020 12:44:46 -0400 Received: from mail-eopbgr00131.outbound.protection.outlook.com ([40.107.0.131]:27107 helo=EUR02-AM5-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 1kIE4Q-0007he-T7; Tue, 15 Sep 2020 12:44:46 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k2UdzEKdil8twx5D4EGQKa3yjoVDZhEvg3EWBsnwiuodFxWulmG3VJRceLlK2zcgUecS0ZrXIRREXLjuBSkRzimq3iymgaiJzNS+fVOizIxW5mmRHz7dPxxUTM1vWEnOWOdXp0PrweLMMJg1CHLuT8J1AUes3ViYg4d4OVFayr1KQ8QDLEap/pE85jqW7Eo3ANHUHVPeUqrLWYbslse3kuYQ4QRo1ZtkxjZVXAhCItwTmzQYETNy2dUzDJc+gtN2Ke63P2wJ3iZHlCmRGru4yRoH7puVU9Nkc4TihIeAMesbZzJn7zVei98oHNM7CDvdIukir/1EA5vPQ+EJ0aSDmg== 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=m3Mfjs6F23/Apaan2wyhFR9NH3ancKVhc8mxe6uHokQ=; b=Rt8w+GUD/oqtKzX88VyUXzcYNySoD95MB4sW3xeG9ROAO0WG2Rf1dcfbKlZ6RMPab/AGwNS4AciPTJyX6d0noXV23PQti34OdiY8gwxpEs0qm68zUTW36SAH9DJuKaDMS3ipg/x6go1SNsaYpNyJkwdn+tnL6rePPoaxEfadMz8EOQW4NFTL0EH8X50sdOlO59WhDGwCwJXWXcIImyOzAhXYOAkYJStIAe8472/xuq0BooDGtHRBFNqCajzpgA9yBxzw1P08V+ORkDlBptNdCkwIdGBFPyw5NAoncaij6UPQZ+FbNgwkCukMPV5sfjo/e+8XWP0qnt+dfSO1mmbAFA== 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=m3Mfjs6F23/Apaan2wyhFR9NH3ancKVhc8mxe6uHokQ=; b=S6hJvgfIh//SE3IB4tO1lBaSod5WQ3jlyUsDzn+FogiqR57Y7fUyK+1CRMijN85tlg+Se62ZZyzjWcijirQW4LbydtoWZNFszx/kttDT0LFgrTSV9l39nNe2+wkzm07oXZf0MEAnAFhKg4gtxy0kZ2AWXn5we0Y417Y6V7qw6OY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:29 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:29 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 6/7] block: drop bdrv_prwv Date: Tue, 15 Sep 2020 19:44:10 +0300 Message-Id: <20200915164411.20590-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:28 +0000 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff160562-6e63-49a4-4f5b-08d859969d2f X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V0q4UdXYE3oPvibPknG4ZNNDVFv9esasRcKtsNMoUPt3SIw1bl+j8Z5T+aw6IvmwmVVR1Wkh7SGCUdiav4knXRJUb1w5fgD1qrG2MSbAjroXS0V2HtH9vZ3wws5fM85UB/v6ha7Tr3NE+x1Wf+0ZcOZJ+QRTHeWTyWTwdRsugArZEYV6HfkA86k5TJeRMh3sd8OloXGTwIyCPe5YjT/myXROZpHr/WmnO7brTgB9d6Qk1QZc3i8dshU7Ke2VMqeqJ7PGIGfDrH9aRyRExAfB5My1qlRepN2SNFVv4+MD3aFinbPIxwy4jb3eyKTd72kqzfTl8wrdDi2sQAfi85JI/soqC7wUZoCqjRMOEm8H54E= 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; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 9dO+RLJDlVlEpCBco0edIt9QyCiWehCJFPgLiD1dxXXKwfwYuvhAnLQgaZTT11WAUsPqNIDj4xFrwHk7NHuZeJ7hc7jkFUc4mZya3xQuxAil1pPm1oLAKePDPh5GyvRoT4pRj3VvnMHmIsEC5gP+zW+CdChDnPAknlq8k5dkVP5takpd3bmFMRoxiNrMqKIxAgwc3qOwv9m8CQ87IlaiZEyIGfqwgoxpvr6Q8EdqXa3QBxFvYoqHfpq/BCctF0vbG/Kyuxhy5m8ipykkW4W6NsGTOtyXU7LeN9GSCz4i9uio+Hvf9j4eE7pHuyZT3KEW3wGuR/E4c0Qm7OA3SwDLcw5X9pDiGOp/IEvJAgEXswTJtMV43tXatV3uqPOM78I4jh6mA5smDNIY+BBK2ROj92lT7PKlW09eyMaorDiHh4c3Z13kgRPl1rDy2KEsl12fyS2wKucRUfiOsSMWKA+Klbntquxm23tuHMjPxGRrE1t1x2aCTz5+AXfTCp43L80v5PTfjqdOqITmlpCwspsjvVYEGR+DtD1wL3o7ZHN11DXzAxlxcfGxTCSyFMdK5O7KjRgfpnRWIZ5hooKRyqkbSYny+SnlBQAGIqCUzM7S0nRtfcVDugSZ3cVNpDuom9rgcFoOHuDVBfKuUV/pHy+x2Q== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff160562-6e63-49a4-4f5b-08d859969d2f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:29.1707 (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: S63iejeq6VLKDea5kKjYbs6nCiPeZ21dMh7bIh85fCckRmRHFBZk6I1VDyE3xl3yQYwpphnUwabVIfdduWNl0nImCBR8T59xgifw0E4gpXA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 Received-SPF: pass client-ip=40.107.0.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:35 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 autolearn=ham autolearn_force=no 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: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- 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 c62b3a2697..6c63a819c9 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -31,12 +31,12 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); -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); int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index d8fb02fa2a..b8b4c177de 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -383,9 +383,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 bytes); -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 5270d68d72..68d7d9cf80 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; } -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 = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | flags); + return bdrv_pwritev(child, offset, bytes, NULL, + BDRV_REQ_ZERO_WRITE | flags); } /* @@ -950,41 +938,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) } } -/* return < 0 if error. See bdrv_pwrite() for the return codes */ -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret = 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 = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); if (bytes < 0) { return -EINVAL; } - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; + ret = bdrv_preadv(child, offset, bytes, &qiov, 0); - ret = bdrv_prwv(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; + return ret < 0 ? ret : bytes; } /* 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, QEMUIOVector *qiov) */ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes) { + int ret; QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); if (bytes < 0) { return -EINVAL; } - return bdrv_pwritev(child, offset, &qiov); + ret = bdrv_pwritev(child, offset, bytes, &qiov, 0); + + return ret < 0 ? ret : bytes; } /* 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(BlockDriverState *bs, } s->io_co = NULL; - ret = bdrv_preadv(bs->backing, offset, qiov); + ret = bdrv_co_preadv(bs->backing, offset, bytes, qiov, 0); s->has_read = true; /* Wake up drain_co if it runs */