From patchwork Tue May 8 14:58:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10386331 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 195E86037F for ; Tue, 8 May 2018 15:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07CB728DD8 for ; Tue, 8 May 2018 15:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0B3928DFC; Tue, 8 May 2018 15:08:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 50B4928DD8 for ; Tue, 8 May 2018 15:08:10 +0000 (UTC) Received: from localhost ([::1]:51704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG4Dp-0000FT-Js for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 May 2018 11:08:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fG44l-0000I9-4x for qemu-devel@nongnu.org; Tue, 08 May 2018 10:58:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fG44h-0001Ye-0k for qemu-devel@nongnu.org; Tue, 08 May 2018 10:58:47 -0400 Received: from mail-db5eur01on0136.outbound.protection.outlook.com ([104.47.2.136]:52463 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fG44g-0001Xd-NF; Tue, 08 May 2018 10:58:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=zgzXLFFDB8YgjFnPayKJuVoYray8OagaCmTsbmRSVkQ=; b=Us4UPkoQx/sIFtUFbK7oUy0fYH+TY6K2MLhpQHc4E5qspcqdRRy/LIQgrmQAZwHCUafsbUBOUFWDgLlS7mRltx5A4skM5PamFrlBrFsv0pNSA/sWcFMuZUZc3Yk1qUr294dXqZYd3gt0mXkIeVqn8xZ4QjIel60jgaS3PsKQZNM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM0PR08MB3347.eurprd08.prod.outlook.com (2603:10a6:208:5f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.755.16; Tue, 8 May 2018 14:58:40 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 8 May 2018 17:58:12 +0300 Message-Id: <1525791496-125188-6-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525791496-125188-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1525791496-125188-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR07CA0020.eurprd07.prod.outlook.com (2603:10a6:6:2d::30) To AM0PR08MB3347.eurprd08.prod.outlook.com (2603:10a6:208:5f::20) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3347; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3347; 3:Pq9GD4BhgI75X+yR3HNt7uxYTrlkGrEIYLUEqyfEv6q92qP37DzxPQoZyS5DqHR5NU5wJEEOKWXLTqB9f1y5R+pnwgUv3NcwUeiFUzF6bjXjK2imR1fUThlMU4pR8AmzdezLLc4ftZlrpO7dlCEOqdSTJOcuGLg4ZrO/WGBnqsIJWFhh8WYzsQ2sNMMYl9lKG7+yoDatoSYY+YO34x2qjw0X4f22iWPENbNFDixGZmKFa5JhPPP2EbUC5UzfVqKY; 25:iQQ04OVcVTxwg9Vo1LBjtvTdbH2s3ZT65+3NGi6ZBzqXiQD5MBjr5/Y8/9G5F1ZbdH5CfU6tM/47YfAkiQSG8RwPsXjq/S09DsXOxeocSTSVWvFaMS/LcLLdQpU7zCjHXeMTbP2vOpmCnxs+iA9f89IXf42RDExiRTUDzwvVqpt2krPsd1LzgB4MqP1rYDGdt3RDPkxz2Q+QfCf4Eeex3peHpaif+8+GSQLFtoOwXIddY7N2oD/mOyhrBVuB5ot6JDwyinQhPT8WVYMrdgnWnLCf4L0zYnPLy2jQkulSqrRkuHZMAy9lK3CZbSMoSgO4BwG6S9JNZGD2OGXPFiqelg==; 31:T14pr26Uw/rp0jUiRBXG63Y60n1guvf+h+kZlvU9uqBEkqbl6REiL/1Av/mg90k/RvJSLHaybZjNY1+h1v+Ka2KVr1dzLQGkThzveNnwLzvBvW1lpfDY1818ChCLXVwB2U0ticZfEvy15/1/EY4UZ+8HoqGAUDK4m/GmwuY4xPtToxP9WVq6kxqOMQYdgJlWssR3TrGcFQpTENNdvPf9xFmqbwNP3DB4548vU0O92fI= X-MS-TrafficTypeDiagnostic: AM0PR08MB3347: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3347; 20:Kdy4UMwEhgMZeb+6ENbyrt1LKtL7sN9HzUSB/pUHAQg4S8YZH31yyp3X16WIleSaaf3aveUMaw/x1jtoEDgcfVxPAj8HqbIh5mLE/OAbSpBmeUm7uMUjjXiQmeZgx4oTd8neOMcPe+VdgppBHiGgSVbdArP7X1Z0NaVRZvVazyc3wfuV03n4qGsjQao8Q4H7MoM8L13ho56UvABnwMNY7CF+JR42fCJtXW42XvEmzm7BY5UrdgQAqRqJKdgZrhNVD1lYcsdcsYu+k7Kpsv+6qy/BjB4RZy0PXZ5vlAFDuFCPTUWQnmhaMwo1zTPTL1Q9ayZpQi8lwGjkRkhw94uxh13tzR64T4LLbrDTzMykIUOgoZx2CQXWyvxVJztZCn7nIQy6BpbIsZ/GgpWydI8G5SFVjV+tgHkn9twqon3hYw64M/xeMM+/OBZXs5FEimlPhkijoNVtOcgdq8xy1rmzst5YC8tLAC+LKFh9ZzHtzl6Z/FaDFp0tIO18LG8qwGZn; 4:HkT22RgrjFelasAT7FburnTngl+jiPvmLOdCzLXM+3silI6XQs4uNPxgcm9bNvO0HirnQBusd+uXl1PlHBZCy4LJFtIdMPp88eksidB3CphpOCWsSgz7w2lCOVss5MhZByFPd9Ev1eiwkakRjbeihiSPVQTLl/TLLuCGOgSoRIKqFMC+oh2DyjTCYQEFeotVMmZUCLlrshkdZM7k6vjUaYw4IChNROmgeJIUyaWEQee4lWEwBkwcvQsJDdwgCUITrivvJGDjb+RHmEFClyvPJQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231254)(944501410)(52105095)(3002001)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011); SRVR:AM0PR08MB3347; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3347; X-Forefront-PRVS: 0666E15D35 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39850400004)(366004)(376002)(396003)(346002)(39380400002)(199004)(189003)(5660300001)(6486002)(81156014)(8676002)(81166006)(97736004)(2361001)(6116002)(3846002)(2351001)(446003)(2616005)(44832011)(16586007)(956004)(486006)(316002)(305945005)(476003)(86362001)(11346002)(25786009)(68736007)(6916009)(6666003)(36756003)(69596002)(51416003)(66066001)(47776003)(386003)(6506007)(52116002)(8936002)(26005)(53416004)(55236004)(76176011)(105586002)(186003)(106356001)(16526019)(107886003)(53936002)(4326008)(7736002)(50226002)(50466002)(59450400001)(48376002)(478600001)(6512007)(2906002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3347; H:xantnef-ws.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3347; 23:raxm6i1dkhKmkcjSqeh8ZFIWxah7MfsAB58mfTxgU?= =?us-ascii?Q?jkXYH9SBZmYcHhwOVJiEejgy/390bLzhcxDYDrbglGwRwYOgtTa0LNb7YKVy?= =?us-ascii?Q?6C0/tQsqowZikXVc1mTVQMx45a4IwVc3RaCYB4/c8TxFiJeQuhdT4W6IqIol?= =?us-ascii?Q?A4MENtwbnIMxogcyR56EsvfiZzwRL995KlPRMeOcmpzX/8HYFiQBCOQdLoRb?= =?us-ascii?Q?4SdxUlVnVcauthKqDM/YtRVxkzhg67dmOjdtkpIaSkAwdKTE1/C1HjmgiWkn?= =?us-ascii?Q?SvDmSIY1wqQAe9wv5C6FMITpkzt55iXAEVMLTXfnkSVOg2nlXVGEd90r3gg8?= =?us-ascii?Q?fTeTCCTana+wJM9As4UJhRH6rkokJcnwWUxbGIqKU6ujwtGebCwFDnfOlLg3?= =?us-ascii?Q?siSJJE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frdx8DkrJU1jnvzfagt5IrMUas= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3347; 7:YzMpoi4csRmH4nY9eK0qYuvCC1RjPEmHPlPRQUxZYCBHqZ0nSLsiQbHBO+DSHyCoLTyRYq7fWScK1Y5yGp6oHl5q8c0Tk2JwFTu+lhiWkT5SE89AcVfW+DIi/EOJVMCbZCHg9b+ib56RjERxSB6M2tWEvC/l7gHb1guG779wQsDSf6OW/F4/dg8bIeG2d0xhBRgqv1VmGcc8icIk+sZ367VwA+iSQw2TT9dappMK/F7A2C51MemRJxrhx/NyfRQk; 20:YUM2jRFcDdaavf4atgX01szeN7p53IaGQS7QA0OhYhL2X52CBx97n4xW3J9R6Ly26Qqm5ZBaY+sWlyp7q9GRhgFeZvjVmAcA+q9KizULMaLfsdYWIs/myLsHQhCkgy2uiSYxhB8KTy54ldosSoEU1PlO5QOkZRMcnKLcKvUvVM0= X-MS-Office365-Filtering-Correlation-Id: a2acffaa-12e4-445e-6ea8-08d5b4f42fb9 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2018 14:58:40.0682 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a2acffaa-12e4-445e-6ea8-08d5b4f42fb9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3347 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.136 Subject: [Qemu-devel] [PATCH v9 5/9] block: treat BDRV_REQ_ALLOCATE as serialising X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Anton Nefedov , berto@igalia.com, den@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The idea is that ALLOCATE requests may overlap with other requests. Reuse the existing block layer infrastructure for serialising requests. Use the following approach: - mark ALLOCATE serialising, so subsequent requests to the area wait - ALLOCATE request itself must never wait if another request is in flight already. Return EAGAIN, let the caller reconsider. Signed-off-by: Anton Nefedov Reviewed-by: Alberto Garcia --- block/io.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/block/io.c b/block/io.c index 660702a..a2fb69a 100644 --- a/block/io.c +++ b/block/io.c @@ -598,12 +598,13 @@ void bdrv_dec_in_flight(BlockDriverState *bs) bdrv_wakeup(bs); } -static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) +static bool coroutine_fn find_or_wait_serialising_requests( + BdrvTrackedRequest *self, bool wait) { BlockDriverState *bs = self->bs; BdrvTrackedRequest *req; bool retry; - bool waited = false; + bool found = false; if (!atomic_read(&bs->serialising_in_flight)) { return false; @@ -629,11 +630,14 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) * will wait for us as soon as it wakes up, then just go on * (instead of producing a deadlock in the former case). */ if (!req->waiting_for) { + found = true; + if (!wait) { + break; + } self->waiting_for = req; qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock); self->waiting_for = NULL; retry = true; - waited = true; break; } } @@ -641,7 +645,12 @@ static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) qemu_co_mutex_unlock(&bs->reqs_lock); } while (retry); - return waited; + return found; +} + +static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) +{ + return find_or_wait_serialising_requests(self, true); } static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset, @@ -1473,7 +1482,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, { BlockDriverState *bs = child->bs; BlockDriver *drv = bs->drv; - bool waited; + bool found; int ret; int64_t end_sector = DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SIZE); @@ -1497,8 +1506,13 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, max_transfer = QEMU_ALIGN_DOWN(MIN_NON_ZERO(bs->bl.max_transfer, INT_MAX), align); - waited = wait_serialising_requests(req); - assert(!waited || !req->serialising); + found = find_or_wait_serialising_requests(req, + !(flags & BDRV_REQ_ALLOCATE)); + if (found && (flags & BDRV_REQ_ALLOCATE)) { + return -EAGAIN; + } + + assert(!found || !req->serialising); assert(req->overlap_offset <= offset); assert(offset + bytes <= req->overlap_offset + req->overlap_bytes); assert(child->perm & BLK_PERM_WRITE); @@ -1623,6 +1637,10 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, bytes -= zero_bytes; } + if (flags & BDRV_REQ_ALLOCATE) { + mark_request_serialising(req, align); + } + assert(!bytes || (offset & (align - 1)) == 0); if (bytes >= align) { /* Write the aligned part in the middle. */