From patchwork Mon Mar 12 10:16:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10275913 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 523B060467 for ; Mon, 12 Mar 2018 10:22:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5782F28C59 for ; Mon, 12 Mar 2018 10:22:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C5EA28CC0; Mon, 12 Mar 2018 10:22:05 +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=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, 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 C44B628C59 for ; Mon, 12 Mar 2018 10:22:04 +0000 (UTC) Received: from localhost ([::1]:57516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evKah-0006ij-T5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Mar 2018 06:22:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33640) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evKWK-0002mj-MQ for qemu-devel@nongnu.org; Mon, 12 Mar 2018 06:17:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evKWF-0006kt-Vk for qemu-devel@nongnu.org; Mon, 12 Mar 2018 06:17:32 -0400 Received: from mail-eopbgr10122.outbound.protection.outlook.com ([40.107.1.122]:49387 helo=EUR02-HE1-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 1evKWF-0006gT-I3; Mon, 12 Mar 2018 06:17:27 -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=r9LvqWXRgPVPvuZqEu7gWTtjBzQZ+cxb9k2bRV+leqQ=; b=iTO4z6dQsqn4DlFYCDjz9oP3LDz13q2NXWBTSs6Cy3XYUm3vUAtsBISNnhAWQf3rTLqbc1PKhmGHvZUHH4ueFy0r7mEy3vOSKjKPLHyHVUoIpX4sNnmnRPk1YFWaeYQOf+2w/hCVewqQ8w6I7E57ye44vD58Qt9HxLWsPYLNEYI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by DB6PR0801MB1991.eurprd08.prod.outlook.com (2603:10a6:4:76::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.567.14; Mon, 12 Mar 2018 10:17:24 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Mon, 12 Mar 2018 13:16:54 +0300 Message-Id: <1520849818-6915-6-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520849818-6915-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1520849818-6915-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR06CA0148.eurprd06.prod.outlook.com (2603:10a6:7:16::35) To DB6PR0801MB1991.eurprd08.prod.outlook.com (2603:10a6:4:76::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9f3c434-5635-4858-9b73-08d588027391 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:DB6PR0801MB1991; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1991; 3:0k9hzdmHZFlIfSjo+mq9sHYPuLPXQ+jLcnVBn79ZQWwQeOFg4MNbimx6/+g6vtpydZDKkIn/fKBHC4Rws8/2kS/L9ed5P4HRPx7otaCehA/kyLiy4UentIhtOYgpN8KxmU1jItRwnZeor5YxoIwIwuIQduuZ3Z/VIfqCC7SywwyPiLlR4AtepebbzkBSaOsmQlL4IL7ty4BCFUs5/0HTxOXwaAZYtSoA8jgZB/rxBnJ8sljws9h62MQLgPsBZr75; 25:Gh+DSRJHlh2xCCO5s/s0ou2XvrT8/Bjuhsq1a8+2/1kbihfJLHWaxAVk9S5T+jMpsijvS4TnFUlkrA5LO0XLKBOpBAmoTearhAX+Z6nQ/zdHRf0mMdwPDx+cLXj19+H74ccZo0oJfW44z1jUdL7iwoBSQFfj4mOLb+LC893kulywdFWUGo3UXo7zzwUMVBtThoByZ4LN8M6L6IQ/lC3FQroAQXyb95JZvzu5JlkBDiS82K6OtBQ+kIjX3B/DZzpO8FgNZNkCTmz8bXEsq22M158EOeOcnVnANLMqa4nsW0a5RKcH1oUIjCJE8zFZuw1UvNg26mkNjbkgTTCj2fVq5g==; 31:lx4KInCDGK/+vNkWxcwuysPr8lFGGt0jsfMsRQJ/QGpDegObd2i+yYP653h6bpGIijMgFtbzwj2z5K6nqFvwmx+1K0gMVO1VBBqeXNeDQO7PnnhQMfptaf02JEncodEid9tUfz4vHIK6lNGvAt2gFspcDYjLabnqsI76uguIJ0xo//H0gJ2ekidRBIXtBc4m+s2tVn+oruEAc3JBcIx3DJfF855VgeDNJ5NPFDrmb3E= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1991: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1991; 20:nCMA0DpNfACOwuL3CrkExLifXcng2b1EputhI27bzDlqBmjojBE3ORr9SlhAHlsU8pg7knpZ7l5lLffGDhnotS2xc8nBFfdnUWAXccW9w7oKIset/aFUaxuSLJ69Z3FD/JdbgI97BXcJn1EakF9V3E51Txt/mtvYXi/oY/sGsCm0xSBs+KNgvfCc9LWsxnqZ1PEsxSELXMIfpUiwWFJ3PLaFsec25Wo14j03mwxACt3IzN8fjOQvIBWJ8fznMsF2rgwcJCzWbeTSveabxv2j+Z2vA2wR58c37FlE5/vNV96uu5Bt022jawG1+BfeEREH207l18HVMuP5M4T2SUYQRMdv3HkTTXYlgsAzFwUy9iJKKvZGfPOx5Sl2MnBT/hyUdTHzW2Eo95nsdnSDF1c3T0RMRRtPlICHyU7q0Tuc+Gg7TxYCnn5rJCeSwUSz4Xcx+Gkqt8rOTuj8/BFxUwUIauRWxDGspeWWKsUHArWXpac0UgZXu1H+P2eaH7laLFun; 4:5ZJ67tBJYF4fIBfcbig4YJRmKSBReTkOyvFJ0J9czx9XrXu1mnjYtf0H8BkbrIrZfxjmprdRYHoT4IiQHJF0Wek6PutJakOCwDP1W1R5h5aO9b+BX/Bu1T803VW75icQQ79Ewq/YaBBanhXFgdovS28IVFN/V2O4z7v1jrDKZBKFjvn01i3Y/2EBJndNirwnt/Xu2BsVSsT4Thflbf+7RUKUPCVW+Lp+Z6kJzKAwQXRGPXePoev1pf1+4cjc5a9UYUu0EKEJCjW98y33/+MSMQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3002001)(93006095)(93001095)(10201501046)(3231220)(944501244)(52105095)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123558120)(6072148)(201708071742011); SRVR:DB6PR0801MB1991; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0801MB1991; X-Forefront-PRVS: 06098A2863 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39840400004)(366004)(346002)(39380400002)(376002)(396003)(199004)(189003)(47776003)(106356001)(4326008)(81166006)(16586007)(107886003)(8676002)(69596002)(6116002)(68736007)(3846002)(105586002)(50226002)(386003)(6506007)(81156014)(8936002)(55236004)(2906002)(36756003)(478600001)(2351001)(2361001)(25786009)(316002)(59450400001)(6486002)(53416004)(76176011)(97736004)(52116002)(51416003)(66066001)(48376002)(50466002)(6916009)(6666003)(6512007)(2950100002)(5660300001)(26005)(86362001)(53936002)(16526019)(7736002)(186003)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0801MB1991; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0801MB1991; 23:YGcUbST8YSDeWzxuWT+tf3iIDeYu7TCY3nAtF+2?= =?us-ascii?Q?AnnQOsbjQ0/SFOgHanXBfPHqlzYe3AsGCzUfl4T9N1TH6cap3EWYDTM4a1Rk?= =?us-ascii?Q?n0E0u9LvXn4Ooe0oGInb4Go1IR0Tg6OEfZIj7tOjMJJg/Pib3PxUc9Tt0FcW?= =?us-ascii?Q?RtTtee8vUD/MvKB5+EToddE2YlJ+hB1QoDwoazYxaLEpZUK0e/48YFDhgLH6?= =?us-ascii?Q?2e5hp/lbz5DnpreQJ6IGisTcoeu7mj3m6QsN72tEHsAMkeHfMYAtR+qsf4Nl?= =?us-ascii?Q?2yutGTtQoPrX+EzEqH223olaNKWNU8Zr9Ph6i/VxJi2qJkND5VWZ2GN5haKq?= =?us-ascii?Q?g+W/ftGNNHccpxnP+ge3XFXGc8jvtriyI/gxZGYeIdvo4dNe/Z3nKzO29gI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uAMGB3izlrUOERG04mdjIJrba5zYhYVPk1we43/EZhl6qXGzBFa+wTl8wj7uUQOyRYdH2M7BmHEzyXvsVTZMDW2/jFB5K SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1991; 20:gg54Jn5n2rGwx8mCziXiqPBLVAS/QLYJ3eDapiMlBSiO+phcvguVtOyHC1JRYDAy8Q82HJ8LKzHM32wnyVDIUtsTz1GJbncYAnfgqOGLywQaxexsRLxhuha8kRs/3zov7uFEh61dzeUt70qzegQThXoMhkQ0XLagtsnbE+cIVs4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 10:17:24.5371 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d9f3c434-5635-4858-9b73-08d588027391 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1991 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.1.122 Subject: [Qemu-devel] [PATCH v8 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 c4f2a07..5d74603 100644 --- a/block/io.c +++ b/block/io.c @@ -599,12 +599,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; @@ -630,11 +631,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; } } @@ -642,7 +646,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, @@ -1474,7 +1483,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); @@ -1498,8 +1507,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); @@ -1624,6 +1638,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. */