From patchwork Mon Apr 27 14:39:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 283902 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=-9.8 required=3.0 tests=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, 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 29880C55199 for ; Mon, 27 Apr 2020 14:41:17 +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 E820D20656 for ; Mon, 27 Apr 2020 14:41:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="YS9ow0G/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E820D20656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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]:48591 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4wd-0001ph-PZ for qemu-devel@archiver.kernel.org; Mon, 27 Apr 2020 10:41:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56842) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v4-00089L-AM for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v3-0007kR-Ri for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:38 -0400 Received: from mail-eopbgr40124.outbound.protection.outlook.com ([40.107.4.124]:49833 helo=EUR03-DB5-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 1jT4v1-0007iT-9D; Mon, 27 Apr 2020 10:39:35 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yx2DnubE9R6Rlt7g/9roIxuOhmC/icVy7glRoD9KcFZrqtb/nNz9DZK9hLQSJvNkDtzHuhg04pqsmvwY899cKCFSr0148PcSVeCbyDKCvN6a+Be3zTyNv2LoEsww4hWA4mWVvZN/os8NVg76NSaqIkC/RE73DJ3bVuA0PjuCindWlJmbGq9WYvC3r8wf6SNQkdNEpYbI+RLlE2quicNp8q7gOt24q6Bp9j/3+wqAjcLn1n0wYCvZ2jfoJxkd9mXyUz6rR04Qxc5UoBL4+5ahMaLIjChekLf1PIEzJ46ii4HquQu1/2LTVawssTSCsS1UROh0dNhrz7GtOi5boVDVGA== 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=+Tp/lNrp4pa6NXDHRAe0wN6lAiaVRIBuOBnYuWH7cs4=; b=nu1zKfZUlnNlt0euh6np8R/gTH0+yUbz8zN/tNw10qyd6WvshOliscp0jww8VxD17zuuEOzfOS1GCItN5OKnRrPqM81ClNl/LqTkuSNyHsTzrgPPuuzZDzRp9enJV+q26aL0JoHo8wciSluzw2rf+IoX6DsxuzyM7oFPdWOKjCzJDMZRK/V+xHD2UCpwbPHmwAybu6DRvVdo29NGfQFjNU3eqYfU/7mou8LG13L3ciztwzDQ5njWvcsgX3fwy0tBt0CNIhxq+invelz10oj5//SKIEa+MFohAMVLnraqWS1I5NrWHYlH51R0PTFVXnyHSiJZefXHUplwjz3HXJ3dZw== 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=+Tp/lNrp4pa6NXDHRAe0wN6lAiaVRIBuOBnYuWH7cs4=; b=YS9ow0G/RtWp+W7QANmuBdRvVm61I0G+rkbVGv9yUfoRXsje+QChu7y5NDm+HJ/urpxU4lI9HWK0Eazhx0nTYsRKNJnE5CIAOz80VTxxs37uzx34O8vhNiQgXu4AMeZDT9OVj9js36nOfOJj+oOXb24Viivopgq7zK7Y+JJfaKk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:33 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:33 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 3/9] block/io: move flush and pdiscard stuff down Date: Mon, 27 Apr 2020 17:39:01 +0300 Message-Id: <20200427143907.5710-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:32 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47d9a031-ffe9-41a5-1196-08d7eab8cce0 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:248; X-Forefront-PRVS: 0386B406AA 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)(396003)(376002)(136003)(346002)(366004)(39840400004)(478600001)(52116002)(6916009)(2616005)(956004)(4326008)(8676002)(36756003)(107886003)(6666004)(5660300002)(2906002)(316002)(66476007)(6486002)(66946007)(6512007)(8936002)(69590400007)(186003)(6506007)(66556008)(16526019)(26005)(86362001)(1076003)(81156014); DIR:OUT; SFP:1102; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Zz7KO/VoX7ZtrOij+B5VMurGtIXXRzIFDeqmkWwedfoUpqoMB7gDGylA2BHU3mn+p9evtNUz0qphe8Hpj9mjDEtpWZUsUWEKBLuryr8wsTxHC2we3a9nH23p1Gj9uW1sh2pHf+CDkccVJ7U2llQu9KWVJHXc12SqLEYniQrWSTQ8XY2wQ4/TtnR0y4kH+r4qYlJCFovj3wQxDhgwlM/QgZ8A9r4GuCgoVqe+9UPD/RE1fSG7+5UrJ4qMqkrw8tK9ruMnuYfiUyddGSoG4Fys5kBw+lTX/evpUDESWp1oajo9eIJlKlMHicGrPpWm6Lu0R6++DVwiGLbuRkRlkGKbDN2i8fSGiKmZ0aeST3x2iTS+YSx50lrVq2Asp1uKx2EcKqOgcwiVtK2TZw1pJsruXd02tZYcYXUSj3KXPHcJ34yNGAoU/GvmPAU3yczvxX/ycm1f5i5JDJLxHJATqcy2UrqrS5IoQvS2yJm4Cb7MT9PidLKEifp9oTO6B1cfdXQN X-MS-Exchange-AntiSpam-MessageData: hJNu7Muxmr5Ihve8CMMcUuZZxbEpNJsFLOXWFrMuH43gZFlztc/CCwLUIoA2itsev7HgR+1Za4zqGWvB2cwcvb1tYyyVmv9HzmrZLized5oRfLXi59/FdTZvCZ+BzRkMQ4lCtsDbs1Y3mQJgZF1+vPQxknI3KtO6NjkoU7WpJrufXZsvJr14TzyAx+wBVoXfb/tx9BH1lppRzxBIDt69KhWtLnjZbrpmbPwgBN9179Fsj6daAPZmfS2hph18m/k1WAiolWA44EPU9Gjee3DlOGdrpXuEIzZjr2bUZw96quIYx0sr+9S23Fs7lfcJtSvMKtRMiF7umfjdc1bSue98/HXCP5nbtxbqNNfpkrPzqyoT14cYkQiU5YrUKaYk4hueD82dC8HlkyeDTVdL8A2w9rpxrbrw+gH2BmttDXol8DGRWZTbJ64uD4agFNxtUUf4xkq7yXzWzvrDSPHzE3FYqlgdteroel3t0adzsDllu6XhQgAJG4HE8Dyv9RUciWksCSj+qFu2ikUx6620FyEXnFIEazERkF5wftCB0b4WylfZzpSNgtMhR60nu9VsATfY//moWXJ65bxwwKo5JvZLwLRcmrsIv3itrd75/wRayfT/ZmoOCLB01kvq8toLPrd+RlhisaJUpDeZGJG7M3teYnIdN6pR4X1YvMGZ2Wm2OFtwEnNkR8tUn2aw5ir5JcEDoxbnyIaUUMcJOYyc6W0Te5TFzXQgEH7wy7OU1oRu+DX4s9CixXlIbaJwmIM47INShFo6+6sZnboG2DYvvWkentSw+Sk8Y9YxeCE3oP1P1LM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47d9a031-ffe9-41a5-1196-08d7eab8cce0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:32.9667 (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: BCoDqRyiPGSE9CVzxTXuZsK2s+ce7FRkzaBGfhHZ5cijP4RRa+ejQ9/Khor/2Vmq74+3kl83cEL4edci31m4VvTzTjwaMUKOg3iyyjSRFaw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.4.124; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.4.124 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" bdrv_co_flush and bdrv_co_pdiscard will become static in further patch, move their usage down. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index 880871e691..1134f8144a 100644 --- a/block/io.c +++ b/block/io.c @@ -2827,20 +2827,6 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ -typedef struct FlushCo { - BlockDriverState *bs; - int ret; -} FlushCo; - - -static void coroutine_fn bdrv_flush_co_entry(void *opaque) -{ - FlushCo *rwco = opaque; - - rwco->ret = bdrv_co_flush(rwco->bs); - aio_wait_kick(); -} - int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int current_gen; @@ -2953,6 +2939,19 @@ early_exit: return ret; } +typedef struct FlushCo { + BlockDriverState *bs; + int ret; +} FlushCo; + +static void coroutine_fn bdrv_flush_co_entry(void *opaque) +{ + FlushCo *rwco = opaque; + + rwco->ret = bdrv_co_flush(rwco->bs); + aio_wait_kick(); +} + int bdrv_flush(BlockDriverState *bs) { Coroutine *co; @@ -2973,20 +2972,6 @@ int bdrv_flush(BlockDriverState *bs) return flush_co.ret; } -typedef struct DiscardCo { - BdrvChild *child; - int64_t offset; - int64_t bytes; - int ret; -} DiscardCo; -static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) -{ - DiscardCo *rwco = opaque; - - rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); - aio_wait_kick(); -} - int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { @@ -3101,6 +3086,21 @@ out: return ret; } +typedef struct DiscardCo { + BdrvChild *child; + int64_t offset; + int64_t bytes; + int ret; +} DiscardCo; + +static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) +{ + DiscardCo *rwco = opaque; + + rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); + aio_wait_kick(); +} + int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { Coroutine *co; From patchwork Mon Apr 27 14:39:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 283901 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=-9.8 required=3.0 tests=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, 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 93471C54FD0 for ; Mon, 27 Apr 2020 14:41:50 +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 460EE206D4 for ; Mon, 27 Apr 2020 14:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="iwZg8jsl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 460EE206D4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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]:48626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4xB-0002wo-3U for qemu-devel@archiver.kernel.org; Mon, 27 Apr 2020 10:41:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56920) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4vA-0008JW-Sd for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4vA-0007nQ-0l for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:44 -0400 Received: from mail-eopbgr40124.outbound.protection.outlook.com ([40.107.4.124]:49833 helo=EUR03-DB5-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 1jT4v3-0007iT-Hr; Mon, 27 Apr 2020 10:39:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eF0WTSh5le4p4snOOvR039P4MEcwy/gQhIKx+2IeRovTjBh2Olro6sjLv83Yk6AqQhxF6T856Zk5kmY25X6g8Mk/F32wO5HL0udLT+SPKslnjlnPabZU1xibBGuj41Z/Tn5SEv6rxZGeudIOBN+H781YQZATzK/S0CU7zxUEWR0HJJP+bQaJs0KisrZ7hE3rT31ZugXuNXXZDcBBpgawFDcVJljHGqFMdOHrTyaNlXlg/OFVtmhoArxivKqak607499OQrqcaLIYNOr0DgGL1BGvVUm+ITaAwnXj9ZKeTQr4qOsXLMKGmngRsPIUfOIm6K/QpP6ufQlXtTdUr/DPAw== 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=pBsTKOfdeaYxD8YTy5iDd2s7PklFJjA0Pe3Rsu7nlJk=; b=Jf8nDalLazGFEx6LZMzltdZe2dpkWP1cQ59Ky7uOUwno52/LPVxnxvAmIIz2j0+ncYMNMo+dNjngafed3jXbFzPTXvlkTjIpOc8rMVrXknCIss9SOfrhsrcWwtbiHu/EdIQCMJZuLkAYrkmU4nkSN/1rFdeUzgTi2wKWH4dv1FO8JWk3AqFF8jnyvrKkzpy/TTmt5/EAihWQ+k54rOrrVNfYESAbyXtDnXZ/3oiyYSBGooWYlyPMCbFdses9zUXABYhBCw1Wib0u+P9e3QfTPvBuiGlURM2gqTx3hIc7eWB8bLwnNPg1HZe6lcy9WAvfeyOG1dZCy2p2C+KyjziFLQ== 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=pBsTKOfdeaYxD8YTy5iDd2s7PklFJjA0Pe3Rsu7nlJk=; b=iwZg8jsl/JZxz9P6Znnu0bWasUiGbstZKZBlD2FFfPCHGiDE06loK7k9N4Z38KEscQp/JQiAs7/OsjzEGEcLZZ5W098T8hq/ld41XrdzsOCgKy4JnbNlD7DiERc9Vy50BRPk0WTesmKoBqbLdURWrx8t09f0GPWHXcW04IEo9lc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:34 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:34 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 5/9] block/io: expand in_flight inc/dec section: simple cases Date: Mon, 27 Apr 2020 17:39:03 +0300 Message-Id: <20200427143907.5710-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:33 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 311b4f26-27be-4f44-81b9-08d7eab8cdc8 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 0386B406AA 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)(396003)(376002)(136003)(346002)(366004)(39840400004)(478600001)(52116002)(6916009)(2616005)(956004)(4326008)(8676002)(36756003)(107886003)(6666004)(5660300002)(2906002)(316002)(30864003)(66476007)(6486002)(66946007)(6512007)(8936002)(69590400007)(186003)(6506007)(66556008)(16526019)(26005)(86362001)(1076003)(81156014); DIR:OUT; SFP:1102; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JjaVV/SafuzwFn2gtupZj/LT4+DtMT4iiBSn6R19hoFbUG27wO5cfqyoa5xcoMZrjkX2K/J1ZmPbfcCUdwPavwzBi/UVJ/h21EoMcYSyUBzF2rZzNgM5bYGXqJh18nOA2AW0WrBGev4r1paIRUGEYJpZDq2AFohFjSuAJxJHZ0U1h8i9RiRKjbxBo2nhjGdqybJDUPi4ip9JYwkBLQPV4nA4JN3kVnDW5n68gnI+bGuuj84u6BojqTbUMqbXBfHgfEP3DqlHxr/3ljLwu98SVE5KrV9BzBvRP78u2891GTPl53q1+pIsPf6qiGWV9L5j8qqzjbcbXdbO0lW9sLXje/6AMHR81VcgzbcIGuNok6ZZTe4jOrZm7Oei/lLk83Tv9G58qiYcnBtDKhI3kE0ktUmLXj8F9E00pZOKpXKOdu3xr9psU/2VglMk2j6tKWXf3E/TwD1XoKEpQlLyPFDvdMZURgVPz6inQC4t+d4Y+Xisou+TN+cVhsGICgZ10LzG X-MS-Exchange-AntiSpam-MessageData: gqdDZolIetGbHUpXdWKugFEWJRNn3uVFkowRC6FUmMiyrAC7swyuE0dxKnN7zdFTuzEZcv1xW/ZmKO5pC4aGvP8b3lkaOK4mc3UJWjhjMWd/SYiMaVSpEJMz3CPwV/yzu/w+/8q1CHorRe8P0xkS/Dumz0u1/xC8N/gCX0PxTK5nD1KQIjSUcM26Mzn/wLbs6EURPvPJVPpKsJaq0K58rgxTgrX2AanHEUSMTQ36BYPtp0816HtJ7GJFWSR/GU9iGORUwstGwGZJrra4x7AaGodROLPOjTC2D+YqNNNjaLSZQ18rh3a1YfsKhDRjZLONZy6IAtuUGQbfLk9wuAiz9fJLDCZ+Cn2UExclqNur3XTXdgarWOoMEhZk0aaXN39fs00wY55THHis3efGGC/oquarH27LOF7OvBps/fk8TsZ89cO1yOROnXiQsxlPww2NP94aOexsiuTy/58rC3tntq6hJmx51lIqauTocPD+2YvjThgCSJrZel6NKZDXUIC9RhCzVUXgjWc6tpPHe9cPWg+Nnqc9TNk++/duLEitD0ydFu8b2xOC+3CmG3oNIBhMFhpkMmb8wQptrQNukQD3phHIRHHJF5CcdNMkqXKHQejS+Tork+uKE/+ylzVBjDpMLENUtandSIUiv6F0OwvQ3dPsJ7teQupQExXY54z5Jco2+OdqKIdRy+OIJkxvrF87rzjeroDaQ+/Hsd84nA44Rp484QuzLjAtxgZn+0A73t1gyiYapIAM9nrTdWFavvLSpVwDdyd+JCl9I5MVFS7JjrsuDLSZfs24xTOhBgqetWw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 311b4f26-27be-4f44-81b9-08d7eab8cdc8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:34.5448 (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: nuLgl6vuN0VdaDA0Xqx10JSOktALFDyaFvHR/3OC8pF6SjuE3rjY7uG0KJyoAopcX+JazrrJ+FDnHt/KhjqXrj3xI79x8ZAA6ic+dyalB80= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.4.124; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.4.124 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It's safer to expand in_flight request to start before enter to coroutine in synchronous wrappers, due to the following (theoretical) problem: Consider write. It's possible, that qemu_coroutine_enter only schedules execution, assume such case. Then we may possibly have the following: 1. Somehow check that we are not in drained section in outer code. 2. Call bdrv_pwritev(), assuming that it will increase in_flight, which will protect us from starting drained section. 3. It calls bdrv_prwv_co() -> bdrv_coroutine_enter() (not yet increased in_flight). 4. Assume coroutine not yet actually entered, only scheduled, and we go to some code, which starts drained section (as in_flight is zero). 5. Scheduled coroutine starts, and blindly increases in_flight, and we are in drained section with in_flight request. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 161 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 124 insertions(+), 37 deletions(-) diff --git a/block/io.c b/block/io.c index 061f3f2590..a91d8c1e21 100644 --- a/block/io.c +++ b/block/io.c @@ -1511,7 +1511,8 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, return bdrv_co_preadv_part(child, offset, bytes, qiov, 0, flags); } -int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_preadv_part(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) @@ -1540,8 +1541,6 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, return 0; } - bdrv_inc_in_flight(bs); - /* Don't do copy-on-read if we read data before write operation */ if (atomic_read(&bs->copy_on_read)) { flags |= BDRV_REQ_COPY_ON_READ; @@ -1554,13 +1553,26 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, bs->bl.request_alignment, qiov, qiov_offset, flags); tracked_request_end(&req); - bdrv_dec_in_flight(bs); bdrv_padding_destroy(&pad); return ret; } +int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, + int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret = bdrv_do_preadv_part(child, offset, bytes, qiov, qiov_offset, flags); + bdrv_dec_in_flight(child->bs); + + return ret; +} + static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -1922,7 +1934,8 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, return bdrv_co_pwritev_part(child, offset, bytes, qiov, 0, flags); } -int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_pwritev_part(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) { @@ -1962,7 +1975,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, return 0; } - bdrv_inc_in_flight(bs); /* * Align write if necessary by performing a read-modify-write cycle. * Pad qiov with the read parts and be sure to have a tracked request not @@ -1987,7 +1999,19 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, out: tracked_request_end(&req); - bdrv_dec_in_flight(bs); + + return ret; +} + +int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret = bdrv_do_pwritev_part(child, offset, bytes, qiov, qiov_offset, flags); + bdrv_dec_in_flight(child->bs); return ret; } @@ -2014,17 +2038,18 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_rw_co_entry(void *opaque) { RwCo *rwco = opaque; if (!rwco->is_write) { - rwco->ret = bdrv_co_preadv(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, + rwco->ret = bdrv_do_preadv_part(rwco->child, rwco->offset, + rwco->qiov->size, rwco->qiov, 0, rwco->flags); } else { - rwco->ret = bdrv_co_pwritev(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, + rwco->ret = bdrv_do_pwritev_part(rwco->child, rwco->offset, + rwco->qiov->size, rwco->qiov, 0, rwco->flags); } aio_wait_kick(); @@ -2047,6 +2072,8 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset, .flags = flags, }; + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_rw_co_entry(&rwco); @@ -2055,6 +2082,9 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset, bdrv_coroutine_enter(child->bs, co); BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE); } + + bdrv_dec_in_flight(child->bs); + return rwco.ret; } @@ -2699,15 +2729,14 @@ typedef struct BdrvVmstateCo { int ret; } BdrvVmstateCo; +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, +bdrv_do_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { BlockDriver *drv = bs->drv; int ret = -ENOTSUP; - bdrv_inc_in_flight(bs); - if (!drv) { ret = -ENOMEDIUM; } else if (drv->bdrv_load_vmstate) { @@ -2717,17 +2746,19 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, ret = drv->bdrv_save_vmstate(bs, qiov, pos); } } else if (bs->file) { - ret = bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + bdrv_inc_in_flight(bs->file->bs); + ret = bdrv_do_rw_vmstate(bs->file->bs, qiov, pos, is_read); + bdrv_dec_in_flight(bs->file->bs); } - bdrv_dec_in_flight(bs); return ret; } +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque) { BdrvVmstateCo *co = opaque; - co->ret = bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); + co->ret = bdrv_do_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); aio_wait_kick(); } @@ -2735,8 +2766,12 @@ static inline int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { + int ret; + + bdrv_inc_in_flight(bs); + if (qemu_in_coroutine()) { - return bdrv_co_rw_vmstate(bs, qiov, pos, is_read); + ret = bdrv_do_rw_vmstate(bs, qiov, pos, is_read); } else { BdrvVmstateCo data = { .bs = bs, @@ -2749,8 +2784,12 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, data.ret == -EINPROGRESS); - return data.ret; + ret = data.ret; } + + bdrv_dec_in_flight(bs); + + return ret; } int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, @@ -2828,16 +2867,14 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ -int coroutine_fn bdrv_co_flush(BlockDriverState *bs) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_flush(BlockDriverState *bs) { int current_gen; - int ret = 0; - - bdrv_inc_in_flight(bs); + int ret; - if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || - bdrv_is_sg(bs)) { - goto early_exit; + if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || bdrv_is_sg(bs)) { + return 0; } qemu_co_mutex_lock(&bs->reqs_lock); @@ -2935,8 +2972,17 @@ out: qemu_co_queue_next(&bs->flush_queue); qemu_co_mutex_unlock(&bs->reqs_lock); -early_exit: + return ret; +} + +int coroutine_fn bdrv_co_flush(BlockDriverState *bs) +{ + int ret; + + bdrv_inc_in_flight(bs); + ret = bdrv_do_flush(bs); bdrv_dec_in_flight(bs); + return ret; } @@ -2945,11 +2991,12 @@ typedef struct FlushCo { int ret; } FlushCo; +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_flush_co_entry(void *opaque) { FlushCo *rwco = opaque; - rwco->ret = bdrv_co_flush(rwco->bs); + rwco->ret = bdrv_do_flush(rwco->bs); aio_wait_kick(); } @@ -2961,6 +3008,8 @@ int bdrv_flush(BlockDriverState *bs) .ret = NOT_DONE, }; + bdrv_inc_in_flight(bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_flush_co_entry(&flush_co); @@ -2970,11 +3019,14 @@ int bdrv_flush(BlockDriverState *bs) BDRV_POLL_WHILE(bs, flush_co.ret == NOT_DONE); } + bdrv_dec_in_flight(bs); + return flush_co.ret; } -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, - int64_t bytes) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes) { BdrvTrackedRequest req; int max_pdiscard, ret; @@ -3012,7 +3064,6 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, head = offset % align; tail = (offset + bytes) % align; - bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD); ret = bdrv_co_write_req_prepare(child, offset, bytes, &req, 0); @@ -3083,7 +3134,18 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, out: bdrv_co_write_req_finish(child, req.offset, req.bytes, &req, ret); tracked_request_end(&req); - bdrv_dec_in_flight(bs); + return ret; +} + +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, + int64_t offset, int64_t bytes) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret = bdrv_do_pdiscard(child, offset, bytes); + bdrv_dec_in_flight(child->bs); + return ret; } @@ -3094,11 +3156,12 @@ typedef struct DiscardCo { int ret; } DiscardCo; +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) { DiscardCo *rwco = opaque; - rwco->ret = bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); + rwco->ret = bdrv_do_pdiscard(rwco->child, rwco->offset, rwco->bytes); aio_wait_kick(); } @@ -3112,6 +3175,8 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) .ret = NOT_DONE, }; + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_pdiscard_co_entry(&rwco); @@ -3121,6 +3186,8 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) BDRV_POLL_WHILE(child->bs, rwco.ret == NOT_DONE); } + bdrv_dec_in_flight(child->bs); + return rwco.ret; } @@ -3411,9 +3478,12 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs) * If 'exact' is true, the file must be resized to exactly the given * 'offset'. Otherwise, it is sufficient for the node to be at least * 'offset' bytes in length. + * + * To be called between exactly one pair of bdrv_inc/dec_in_flight() */ -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, Error **errp) +static int coroutine_fn bdrv_do_truncate(BdrvChild *child, + int64_t offset, bool exact, + PreallocMode prealloc, Error **errp) { BlockDriverState *bs = child->bs; BlockDriver *drv = bs->drv; @@ -3444,7 +3514,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, new_bytes = 0; } - bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset - new_bytes, new_bytes, BDRV_TRACKED_TRUNCATE); @@ -3493,6 +3562,19 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, out: tracked_request_end(&req); + + return ret; +} + +int coroutine_fn bdrv_co_truncate(BdrvChild *child, + int64_t offset, bool exact, + PreallocMode prealloc, Error **errp) +{ + int ret; + BlockDriverState *bs = child->bs; + + bdrv_inc_in_flight(bs); + ret = bdrv_do_truncate(child, offset, exact, prealloc, errp); bdrv_dec_in_flight(bs); return ret; @@ -3507,10 +3589,11 @@ typedef struct TruncateCo { int ret; } TruncateCo; +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_truncate_co_entry(void *opaque) { TruncateCo *tco = opaque; - tco->ret = bdrv_co_truncate(tco->child, tco->offset, tco->exact, + tco->ret = bdrv_do_truncate(tco->child, tco->offset, tco->exact, tco->prealloc, tco->errp); aio_wait_kick(); } @@ -3528,6 +3611,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, .ret = NOT_DONE, }; + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_truncate_co_entry(&tco); @@ -3537,5 +3622,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, BDRV_POLL_WHILE(child->bs, tco.ret == NOT_DONE); } + bdrv_dec_in_flight(child->bs); + return tco.ret; } From patchwork Mon Apr 27 14:39:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 283898 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=-9.8 required=3.0 tests=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, 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 30C86C54FCB for ; Mon, 27 Apr 2020 14:49:21 +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 E901E206CD for ; Mon, 27 Apr 2020 14:49:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="S7XbetRU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E901E206CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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]:49164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT54S-0007ZA-2l for qemu-devel@archiver.kernel.org; Mon, 27 Apr 2020 10:49:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56902) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v9-0008HO-1O for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v8-0007ml-7O for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:42 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v4-0007iF-Da; Mon, 27 Apr 2020 10:39:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYvxb3xT8AbUoMmigwZ4YXcUdJJgWLnpqNu0A7EqP/IEKlLOaz1m7kFfKl5FGTQhhpT+sPu4kKXZYwfZNSbk51b1M6AzzkzKpNB9sKSXTecNBHj4F0LXo1JQE4vRA5F79eR5KwoFrvKZasb++J0VpLvFrDtvQGyPDFi/Rr3xw8dmiENQBSAgbUnXctkP6ImbTtUMrXCBoM7LvWQFW25Jq1ZJ/T1yyNLKOMZ1zfn7lcroyoMu0fAlW19KuGUVQ0T/+lZ900Au207qJR0y5T5jsjMbDZgk436QBz8OcEdUsCKWwIjUVPaBpnU3UicUbskrSRFCik5g5EBWzZs3qtU9BQ== 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=R/KHxXjLZZosLyhmJd8gaGFYJpbqdCga15U3mqAzN+o=; b=Vvu/Gs01zER1/uli+ongeCTLXTeTJsstA3oVH2cUqiVqkv4dE5Vjc5Pu/01k1xSbefvLTTX6daEmcjEK2TdUSYZ3PKp2zZLjXyNmrqWZ1hPdLEYJDdLH75O1nqJJRWBiyh1ebkx4qJiPUVMvDAEZ/adF++DDFQJkse6Wnwz5LZtwaFKy1W/mpesRC3HTM9o7yDt7nncx99sunhJUQz/WZiaf+2yndJSdxF95VOlGpXhtOMJ0fcWgag5VjiabwduLn1k0clIAijk3KP94gHR2HzhcjavU45vqhf0zttgS5lkPPaX8E4ZhhnAhpTeoqXiw7VvoMhm2sExolSRfr75RQw== 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=R/KHxXjLZZosLyhmJd8gaGFYJpbqdCga15U3mqAzN+o=; b=S7XbetRUj3YLAklZk6toOH1HeWDbvoVF9xtxDCLg7v+Dp3pcpvLJHfTbIFKVk0QZvddI2hLJhySL7LNKsOFhwCrYZZ/bPbhjbFJklIOy0/U6FR86A+y70ilPbh5JDmrjzSciUSSLnUEkd3E4zZJ8/vRoSnbq6te6JigIPqpiJDg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:36 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:36 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 7/9] block/io: add bdrv_do_pwrite_zeroes Date: Mon, 27 Apr 2020 17:39:05 +0300 Message-Id: <20200427143907.5710-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:35 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7eb6aeec-3804-4a4e-8719-08d7eab8ceb3 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u8FZb1i8zi50jL9zXrxZP4bUsmruYJSewcNOtLVDKVPbBa9WeYqs24kk4PGlazbwr1pxu9xvaRN49SOyrUMm/MMYA+ApBkHW48glbx8szulFp3iKMwvpU8lLB+4KPy//5pCj16JTy70tp6dR3RVEeUBHbmsUfWWRcIm7Q6UAu2RU/mQJ6pB3fWcv3hRF1yVZscLoiyVUcg53kBhlQ+dslaBR8xkqYNHyztif6hyDsSwE99UgnlypAAszaZLGRG/lpffuMw6hHtHltmVEAoHpDlmYDXRJxV11t5Vhl+M5h2eLq5pkWlcxMILHgkH48ayrdxKOazWmdeiC7ircfYkOEBGvGKikCgd0m2WVAiYZxZSKeYOF8fnXlv9qhO5H4z0VxjsbFxkJd2Pvc81+db4v6k3sy6Z3AKbyG5wLfKldI4BA1UNxoXpp7e1BvSJN/hqFZWb6kMo5DGl6z19w4sJTM/UsKMT0ocbP/uHSd8nuCtNE7LCcmkVszVwNWpkJAPm9 X-MS-Exchange-AntiSpam-MessageData: Os+RFQWs6a6HWHyucP5wmfxKpPhlMjtCaXdQac6g0PC4GBb178RlzsHbDQXTCHdKyL7PvZNLYeG/MNAl4FUnYsoCAFvmJCdhDMbEsTidw6PHKqqyENAR4GbYmzZ8SUrlboyAtij6Zv25TN80GavH18cxlUW3dZuKu/3A9mk2h84oh7IwC2wZukKPD/H/iJ7nUKotL5SZILhtVX9RSbzP4sqAxNLCl9oa1i2gxPNOJM+CQB8w7zm4ZaMjinMbsN1KLHxHjqhKXcG+wWAXqIi+myzC2HFsxBeLyC3+GJxDqshspLjq+SXkxzkrkBVHlWk5O/+jRtOrwFginTQj9kULsa02umNbKpbvZ1WIASmbCYFxGiZ+sijCyBr4BdVRIR392tWlKMvX9mrnF55OenXc9Q+FhIQdA/MvjxbhEuk5l7ONMsXhe71PBUeMgbeOOg3JkEC9UYcwuwu3zLXC75VAoLSpg/uhx7+G1j7Z5zeGgl6oZBQ2ImdEOrXPBNkFat+E4o8ox8qMd3gORWCCrLhsyTwQYLzJ9HmTzjrCds+cRVV655NFGJFDddy2j7leTV7P3T0cpMaDe0abA3KRVj9YVpzOjYbcBhJEq/vWsFHbLjbMth1aWM99p3b0NE6/OFD1+NnfS1P8RBRRr9QP24vFtKKQgCdrdsg1c3R/64RxUL23Vn4k6QHmQYeWDHTKk6pMXLQitMxAapNtD0r2Tb/EmmkkbXa2SamHjWNsQcU7oVpMaw2tW0VMJMF5BOPcP2gZIPr2JDKA9MQnBRtJe7+D5dPByXQQhqHlozBOD4SlE+U= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7eb6aeec-3804-4a4e-8719-08d7eab8ceb3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:36.0233 (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: yr45yQ912mG2mc991l6oMhT9QzIuSMh+oo4EGp0JvAbDtiLyKFkp5eYvXYRNgRzi+7ArNtF5KcL/s7KQYBOWVOx5abdddAnXZIGdFHhXqP8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 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/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We'll need a bdrv_co_pwrite_zeroes version without inc/dec in_flight to be used in further implementation of bdrv_make_zero. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/block/io.c b/block/io.c index 1cb6f433e5..e6a8ead46c 100644 --- a/block/io.c +++ b/block/io.c @@ -2016,8 +2016,10 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, return ret; } -int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, - int bytes, BdrvRequestFlags flags) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn +bdrv_do_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, + BdrvRequestFlags flags) { trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); @@ -2025,8 +2027,21 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, flags &= ~BDRV_REQ_MAY_UNMAP; } - return bdrv_co_pwritev(child, offset, bytes, NULL, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_do_pwritev_part(child, offset, bytes, NULL, 0, + BDRV_REQ_ZERO_WRITE | flags); +} + +int coroutine_fn +bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret = bdrv_do_pwrite_zeroes(child, offset, bytes, flags); + bdrv_dec_in_flight(child->bs); + + return ret; } typedef struct RwCo { From patchwork Mon Apr 27 14:39:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 283899 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=-9.8 required=3.0 tests=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, 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 A321EC54FD0 for ; Mon, 27 Apr 2020 14:47:24 +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 6E28720661 for ; Mon, 27 Apr 2020 14:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ZHj8Sg0D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E28720661 Authentication-Results: mail.kernel.org; dmarc=fail (p=none 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]:49018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT52Z-0004Xf-FE for qemu-devel@archiver.kernel.org; Mon, 27 Apr 2020 10:47:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56930) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4vH-0008Ux-5z for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4vG-0007o8-Ow for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:50 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v7-0007iF-7A; Mon, 27 Apr 2020 10:39:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CX060VwXV9NUZgzkd9ARvUT1XOMgkOcRwtwW6gbSOIm9wJ/QBczxx4nqJ+tTwXbC5a6IzniVx1JWp8R5mjpTKRVXTvnEwKnu9q19Lz+wi4yZ32XDOE2sPc1SJrvWqC2FjOisfuiFR5uX8PI7iprTX8PR1MFh6mlkYEY4OHq3e5Bo5lgIOkOF1RsIriLUQSoIV7nPa9On12+5aJdLoAA0VlekPPBJVZsyS2ZdTRn4nxoLAUpldAer4FUt59XVJYPyFXQr8ry51ogHXfCGaOEMBMCbkqJBtCAFTGZVwQVST9K9gpVd3aPwCoDjJC5ZydOIMbvPKFM6wCbHoxEW28WQTQ== 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=qhCI3mR5pgL/iYViE4V7hx6uZsZTQBrSjdHTZOX0Z4A=; b=YQT+AnsX8VGWVvRS1NqYiBQZaDJulWyVYwluM+tdNQjclrjkW+iEcpUmuDpCLSRGp6yIpIFI0m/flSk46h+T1Az+o8xTr62x7y0iMm03IXEScn0ZCcVs6OMJjzJzYZw8dqUC8A/4ej6fCpQlSYUmWgm2jrJ/Jk8iOg+npYjCi01eyIKW/nsw02YciltKAgs6o9hJaIAE1QGCn92Nrmnhv0BSdPW6M9RrJkkPatYTP6SaDaAPAi6n1WMwYlzF4UhdjdDDbcIx9pSMSh7G4oikxP0ufJy62ENT5a6Nj90vehKXodiM3W83+wmEB7JGsPCQkwLVICjw1xYCXrXiQQnxJQ== 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=qhCI3mR5pgL/iYViE4V7hx6uZsZTQBrSjdHTZOX0Z4A=; b=ZHj8Sg0Dnv4B4qN8LiLeNPRVisbFqUSb2h/z/t9yo6LiyxOLtR3xvlREnz6dMshkPKk/zfXmxcTm/cUPBawQyqKV+HfLE/t+pIxs8iz312IQu+azTieajqA+Cqxnsn9l0v9QjONSX41qNChvsFRJZA2MjFLuGSNRtKl/4jdkiAI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:37 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:37 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 9/9] block/io: expand in_flight inc/dec section: bdrv_make_zero Date: Mon, 27 Apr 2020 17:39:07 +0300 Message-Id: <20200427143907.5710-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:36 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b1b9897-6afe-48c7-449d-08d7eab8cf90 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GfUIeXB7MPLq/l6bYP1esF1UvzDwbKMUP1sIu73zk0W4SQTLbHujYK8mPBDDs/n7MgtCWE8kuRPz5eeBL4Lv71pzW7yFWqycpn1PVGZuhzuDIbAPLlzbpUKvPkTlzbRRjckZISCjxTh1AupX/DqnWB3C1i2Ng3UjIVPBNZkM3ktSUIBqKaZUfFe+9s0+7yw09n3uNIYoZU6xWFbNYOfQMgW0vE8GhUqcwHSx4Fuh18h8otthCMB483yb+zMG7E3e1jqz40tNvEmGB2fyQ+OhL7lkjYyiGckaik8yiVO2u0EYRrKJjVSEUmRFfSkQA+3PI5V9GRHm6yr61t151h7qiCttLk8tI4H+lrS0WJkqD6lZdYV6HXnOa4vnDsrUUHY2AtcMDxl7T5vaIplvrCFOA7P4Md0sFBW96bfvSykN8YA7pNl8Uh5wZGUZZcP9Tdq2vUXG6AdcaqxR0pC7nKtfC9fUxgUo3Sj4x8EWhfs+0Z6ne7c52lgoR/5ZUqSKMmlz X-MS-Exchange-AntiSpam-MessageData: /bq9qBvTjGt8cgaZpRk2MmKrx5dUa0qYqnqVFB7M+nX7axKJB+bHh1+XkZ8evEMB3Ueh9hnesol7uUxNiwOIie2ovZYg2jKgHG77hJ1obob2wgPGkGTnw9KtTg34pSSFcuLMedQoXf0Ks1yhZYtMH14Hajg+5SlKyyiLbp7BYBVMQWvcz0IPOEjTvi16IPB822E/xqFLxKVLdlx9gTiIyujfbMfzV5kUI2684tXfUTt31gl8PgCig4lXse1620y15WQEGR6c43WtlwuM20FjTiBtpc4hDxFWkn7MAWbBJA1TMQ3ow/RfyfQNltT2XuuWbTag+IXWki+utsDMqMFHrmzUbyGcJ15xMm2E3iZGuTA2nnrcROtQw8TXo2EYMAAbn2iFHLAi97nUiJ2/TmDEHvt1We3pNhe41eVn6WyUXgNk1sLBfHkBvTb1xKpUwgMYVGUK8l0w8kwg09ueah9JuX5kXviEjvFdoMhy1XIePfoX+/4JLi6YOjLBCZrur6bOAsPCM3HvyzPd20D3y666nDzVFPTQEZbc3tl2kCCWs7C+OuNN2ES8vTHUT9DvxSNt5rNfAsSWc3TgwuZLJF95Ytc7haemXiTgr97OQImKqYmC/77xwZ8U3EoIeOCWaX70vvQJHAeVdi3mRG6CeQb9v2mz5tXINKquAnp9wjrI3nQAYZn7AEeGW9PVip6nfi5+oM3JFiI8CUVTD/nqvw5BQ65zHscxEwi+2JKHHHH/U19tu0n6mp3uWVBOdYCr77WF5HwUEJ3jhKA8YOvvk7I/1OE14Y8EvBkEWQXFmUMyj2o= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b1b9897-6afe-48c7-449d-08d7eab8cf90 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:37.5436 (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: Gj9UX7klU47bQ9As2zCq1K29MHjf3FtlSkd6QrMsKgwGpe2Ase4pF1OtB9Y0JmMPmflW5uhE4K9am4kDnNFuzKOFYgdzpdlICWeS5749qFg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 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/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It's safer to expand in_flight request to start before enter to coroutine in synchronous wrappers and end after BDRV_POLL_WHILE loop. Note that qemu_coroutine_enter may only schedule the coroutine in some circumstances. bdrv_make_zero update includes refactoring: move the whole loop into coroutine, which has additional benefit of not create/enter new coroutine on each iteration. Signed-off-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 3bc0daec33..cd5374e6c7 100644 --- a/block/io.c +++ b/block/io.c @@ -2740,8 +2740,11 @@ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, * BDRV_REQ_FUA). * * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + * + * To be called between exactly one pair of bdrv_inc/dec_in_flight() */ -int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +static int coroutine_fn +bdrv_do_make_zero(BdrvChild *child, BdrvRequestFlags flags) { int ret; int64_t target_size, bytes, offset = 0; @@ -2757,7 +2760,8 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) if (bytes <= 0) { return 0; } - ret = bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); + ret = bdrv_co_block_status(bs, true, false, + offset, bytes, &bytes, NULL, NULL); if (ret < 0) { return ret; } @@ -2765,7 +2769,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) offset += bytes; continue; } - ret = bdrv_pwrite_zeroes(child, offset, bytes, flags); + ret = bdrv_do_pwrite_zeroes(child, offset, bytes, flags); if (ret < 0) { return ret; } @@ -2773,6 +2777,50 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) } } +typedef struct BdrvDoMakeZeroData { + BdrvChild *child; + BdrvRequestFlags flags; + int ret; + bool done; +} BdrvDoMakeZeroData; + +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static void coroutine_fn bdrv_make_zero_co_entry(void *opaque) +{ + BdrvDoMakeZeroData *data = opaque; + + data->ret = bdrv_do_make_zero(data->child, data->flags); + data->done = true; + aio_wait_kick(); +} + +int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + ret = bdrv_do_make_zero(child, flags); + } else { + BdrvDoMakeZeroData data = { + .child = child, + .flags = flags, + .done = false, + }; + Coroutine *co = qemu_coroutine_create(bdrv_make_zero_co_entry, &data); + + bdrv_coroutine_enter(child->bs, co); + BDRV_POLL_WHILE(child->bs, !data.done); + ret = data.ret; + } + + bdrv_dec_in_flight(child->bs); + + return ret; +} + typedef struct BdrvVmstateCo { BlockDriverState *bs; QEMUIOVector *qiov;