From patchwork Tue Jan 16 13:04:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10166819 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 D872660325 for ; Tue, 16 Jan 2018 13:10:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA06328470 for ; Tue, 16 Jan 2018 13:10:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA91828488; Tue, 16 Jan 2018 13:10:28 +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 2AF7428470 for ; Tue, 16 Jan 2018 13:10:28 +0000 (UTC) Received: from localhost ([::1]:35196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebR0V-00079J-CP for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Jan 2018 08:10:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebQvM-0002dn-PE for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebQvI-0006UQ-L4 for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:08 -0500 Received: from mail-ve1eur01on0099.outbound.protection.outlook.com ([104.47.1.99]:39168 helo=EUR01-VE1-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 1ebQvH-0006T2-Vs; Tue, 16 Jan 2018 08:05:04 -0500 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=PKdTX4sH7WEVE8AJufEh15xi1Ekk6ZM3z7G18fKIWqI=; b=IdJkzYdq64us8gIYyMEHO2LUO/9au49Qg7rWxiQjWv280e7PZkE2qBv6qj0+PXya7DyCmgNvu1dZ5nClqiwD3IMWxjGjdr0PqWq0cc+8bexJJkKryVUfN+6anXfT+IelfnvOEqPszC7xz9ffKaZA2VVY6Be+3TvHjBz4hp+6R9A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Tue, 16 Jan 2018 13:05:01 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 16:04:25 +0300 Message-Id: <1516107870-8110-5-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P190CA0006.EURP190.PROD.OUTLOOK.COM (2603:10a6:3:bc::16) To VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e8be0279-9a98-4f66-b22f-08d55ce1c14a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB2000; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 3:jk13QZCF6apfEZjbypW5nVBq4HOhnYZvCl5LkJ/ekyOjz0oGULmtSrSsy2Oa4x8z3CZUIE5Bs6P1qLq/WxGvc+IyTB2H3izYgBNP72LjGu/Zfk8mjQg/tI3h+0vkOW/CrOd/MO9dIj4vAjMoNiVIfWJMFxfyCIDHYmccGXGnnA8nmipDT54NAv3p7sUhiMpb3HrTndCKBQwIJ6q1/yZilt2mfVeS+oe32wuNu0Xi1WHsZmTM7pnV/8PwwmtapYAD; 25:NV3uedAUnnGpNwrjICczMt9w0aLks4EGcjC946zDkUYuzUeoTxGDVWioVNo9ckGdHl+vZnqcK9P8gvnI4joKUJk+balIYwbbJNUSxCL1MdZ/vajUR1K7fiTv19DMCbprBNke7bh5pCS109kqOnxDZZGErTfrjRFa0jg7pf0gAqUmEfjAk8bXbOHqEIbo94H3cLVpG0uPdF075O20YHoKZVvNoV2XC7FslKM/0QlJlgz8Qfcofv1HwRrHLt7MK/bqpKcTJnYRpVSSBCDcfxhI+LDdJTaRlNg+6qAJtOAhMF8VmvXGBphwJWruURLRAvrrRpjBcFdH1v1qebub9NZjHw==; 31:dIO2PbQfNhmXFGMoTcPdeS5RniVCRtXrAYza6myS2YSHg78bEmzXxFktyELDW+kuuFYvbkBSpV3CbnKt9RJYkT3kG1ljRRiSernwKWokKNfQGFOzNcGA9zBN0lI8O4muqMGc5cfr555MTGSqVeWbrXQE2RaGavHJ2S4IiL7CmHqe1XEXEMxZjpOSOkkQCYLhV3qrhpU5y2ji8qU2x95YyXXlVifEE3y9ydmjttSxoiM= X-MS-TrafficTypeDiagnostic: VI1PR0801MB2000: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:Pp8HHZaxeWBDC04L95Wbr1u+mlddOl1P5/AoqGFdrQWVxKBmKf3hbsLwN1B4CEv2a6a/JqGSabQb6yqUXIdcqmPJrQb9DRKJ3tRn8jzcZReDvI+cGSbubtX46BpM865pPzqOCThHQUxTIGXOp4Ba2fwOY9NvtDzC1KgPlU2SUaf5DoZ5spM0id+bUm8dldmb+GATOOuUro5y8y0F2AOYtD/BSuwGxhsg1vNj+3jQAW2qFhghWaYifNSy2Zk2N/PjkQPMbCWZipOdxhj6mLDOP7jviWyW/Nfn9NHcFTYvHYkkr5Z1cSJQ0T3eMo3uZ0A09gfK3JOwoKKt1nPQcR58PCpiFmqGlT0glEJabMvypJTQLibs0R23TrKqd3YGIUrrwdtmYhbyf/0r3n8Ci1mSx73v7LohncV0sfs4vaHa6Ks=; 4:9Y4XWIg+rqxCor6zsxVFqAtFjpjJOwivGsZ5dZRUE+jPB/RF6iCGqgMP+PnDDBGclo7Tg3urbZcw9da9Gj3PWwIUppnsAT9uO86PZs53qXc3Tqzh88usdmHmQkCeizMXjo8/0hyba02PydVJW6CRgu0oOCjNiOZQ+oUmtxhU+GOp5mhrf/pBAx8yT+4QU1QZc1aRdHx/d6sSjog3ilY46GF+lYvS88DTEiVFU7KcPSXosiU/qqcyWgfiM6DcH/SYOULdFUhFJHx1dp+7ncAsFA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231023)(944501161)(10201501046)(6041268)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR0801MB2000; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0801MB2000; X-Forefront-PRVS: 0554B1F54F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(396003)(366004)(39380400002)(376002)(39840400004)(189003)(199004)(105586002)(2906002)(48376002)(6916009)(2950100002)(5660300001)(53416004)(66066001)(6512007)(53936002)(26005)(50466002)(47776003)(16526018)(6666003)(2351001)(478600001)(36756003)(106356001)(2361001)(69596002)(51416003)(305945005)(68736007)(4326008)(8936002)(81166006)(386003)(52116002)(3846002)(25786009)(8676002)(81156014)(59450400001)(6486002)(50226002)(76176011)(6116002)(6506007)(97736004)(316002)(16586007)(86362001)(575784001)(107886003)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB2000; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A: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; VI1PR0801MB2000; 23:z7X0TyeoGwXq4yRQe5K8WJ6UQWkzHulGFMv5gUi?= =?us-ascii?Q?NNPcVJxNxg3cSm16hqb9Mk4sAiSYNT9orCzvjFANxwjEzRHRVTQkHnQlqoNQ?= =?us-ascii?Q?+14qs0PfVTVo4/4f4uY20MMC/AYGmNewUq2hI1U/8yUIA1JO9jo6SGXb9jkz?= =?us-ascii?Q?lfEd/aO5JGMgKlYKMxqFprVdk7LYVpgasSDcgLuLO0kJUd57i1m0tAjvZlz2?= =?us-ascii?Q?CqI4fmsgsw8c6p23BvaX/JlMlj0y64oBIM49AZJqsA3bjFWevzZgeXzDF+xi?= =?us-ascii?Q?Z8ArHEirpUwMWhuxxXmRj1GKukwMDpAooVwZhZUQiSYRhbUDjBwvIxYNzu4c?= =?us-ascii?Q?iXlZFO9fhOxQ4BRr7Aa7RczCabOcKvuWeUvXP6IeCU1ukvKF8YlXTNaVng36?= =?us-ascii?Q?u64aGqx3rqQ4M4JGDa0yOjYLeqpAkeaCp+YxSMeSxatNU8AoVTMeOr7HBVo0?= =?us-ascii?Q?7OjRowzHypv2nmDl417LsK7VwhJ55gpKXYJ1RdnIIBrf3XtsFWmhtbQAHh5W?= =?us-ascii?Q?o6kecvzDa5dkxeS1dy3FASC+C9srrelkX4b3Yjwj+RyKHjZa5sKSBkjnwj+1?= =?us-ascii?Q?9vPS4KMvEYzdtzELQYTBDlXGifn8ZdAcSlN3/UIkrFW5hXKHgoAsMiMk4BIK?= =?us-ascii?Q?VFc2tqPBGs6737vDwfVb43shiWoXScEPDe+qOhxKYVj8Kps8rHmilVwgTsx0?= =?us-ascii?Q?wYaHfHhqQ/V4y8WaKLHllwDlLPZktYEyPYr3KfAwvjgQDHp6gsmX5+KHh+OF?= =?us-ascii?Q?LUaS0vKnzOIYLCtvmaSB11Crl+Idi8RZiOO/QYJ8EXooh6f0ApiWhdMxmex8?= =?us-ascii?Q?2maM9F/vUGd2KAiMeFH//v96JcDxvAx1Yfbj/OXIZpLfVBGbET838BFE1GRZ?= =?us-ascii?Q?zKYTrRdWmOLazWPWzDHMYzWKOJiMmkLSzdbbmCFGlq2eckdy8am4L2xuST53?= =?us-ascii?Q?xBPU1FBBnGClY9rWIV9SNM//mWHJe9pMjgohreBNplfDPYDBgPKXKLK2Ryps?= =?us-ascii?Q?C/6dv0I8NEwowPvee8Wj2GbgDRr24cEKzIY52XNOl9pIEDjll8Qsl3WIsXQn?= =?us-ascii?Q?ERIq/FhWi22K3ZMIirfMcMhpVbGgfTTSn4tFYCaULOioDd6QXOjLzas4FOjY?= =?us-ascii?Q?HhFkexzEy1pBl921K0xL7y8pICHtkzD5fP6WbUhK81xmk18m0PdnoAISUJKR?= =?us-ascii?Q?2fFNn28aJdQg4Jxcx1cngcHsg8rYue86bEhSJhmHAOq9tqUpA5Ug6lxbFeA?= =?us-ascii?Q?=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 6:muk4wbaoxyqgzMcgE1JAmEdKlE9/JGC9tDWTpH4RxwNGyTvLKfzaTK83KgWavuhTGnbsLdRHIlymciWIU2jaPVvu7pQN3ZKNxUa5fBrxs47wfmVihKNAv49Dfu4BqXotnJ8YeAYB0bVJ/MNPcqMdJ1aScvWpC8pBnrqHJDQ3SNZIbrsTfY44pKH6lRx+AueKZ2jC+Vy0+PIg2ssUGHtopzFva24np39OH3CokS/K+v00K/k6gumDJUM9h3uhlMAbr+czKCMs09QgVPIRGjBCrzkMMUyseiUntw5zh4oRLkHg8M8YI5kUC6pigfY7qqMPeB/HqyTLvTPCOtXF7wl3THeYeRJhSOKaldde+RkMnYM=; 5:csHbeEbHw0sDYhDgoRnhAW4wNrzkux+jyCgg2KGkEJ4B8+pyauKo6G/4em5HIVL0taheWLrNyosnorrtly+1oVatdwNP3+6T/vamn0Hu1pRlStGJ+QMmkZldtRUr4EN6JWSmsqTevfmjGl+Bbyem+E3rGteFSuGg0HI87MBfERM=; 24:gH2glx6FyNNIE1lvzi+Bgf7T+Mzac9IekpXsEuC6f/zhKovRs4aG/pPFOR/eNSAcJDdD5u0Z/YkewDHUYuBzoy6DohvZ+5P35btEarNL57o=; 7:vn/0w/Qbvd6SnQoFeEhMERwhyXuOFKs0UwcuSQdazMLb3vNaQR/9zZnZE9QYOLj6xT1GqITYkiMKVGkdeKgYl4aDMQeaxzAwDCE5sAtWpZ0JbpuhnS865W8aFjwyYCaumYZb1iiIiU8WNiS3EKFNcEdMzz7A5rbHGMSrPZo3OsNScpcrhVJwNwiOpRtFymFv7hKAVb/daO9ZrqRWdNfWh3uXMQ2EqoxTVW8qJ8OR7RAcCC0AVnTfq5f4l8Uj4/6L SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:qz4694HVZo8M9EAvYSZly74DSv27n87LT9J9Oj7/3ixe8k2wv53po4JPPqTh+6zDRWmTJjWpIKB2E/TAUp7ZZ5Qc6UoMELrHQEvoKE7rOcit2AmMJw9nAlRwu8/jrUl/bo9GJFeABmaue9P+UuCabijuUgw0MQoalTKjc/wRLJc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2018 13:05:01.6056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e8be0279-9a98-4f66-b22f-08d55ce1c14a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2000 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.99 Subject: [Qemu-devel] [PATCH v6 4/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: Eric Blake --- block/io.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index cf2f84c..4b0d34f 100644 --- a/block/io.c +++ b/block/io.c @@ -605,7 +605,8 @@ void bdrv_dec_in_flight(BlockDriverState *bs) bdrv_wakeup(bs); } -static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self) +static bool coroutine_fn wait_serialising_requests(BdrvTrackedRequest *self, + bool nowait) { BlockDriverState *bs = self->bs; BdrvTrackedRequest *req; @@ -636,11 +637,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) { + waited = true; + if (nowait) { + break; + } self->waiting_for = req; qemu_co_queue_wait(&req->wait_queue, &bs->reqs_lock); self->waiting_for = NULL; retry = true; - waited = true; break; } } @@ -1206,7 +1210,7 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, } if (!(flags & BDRV_REQ_NO_SERIALISING)) { - wait_serialising_requests(req); + wait_serialising_requests(req, false); } if (flags & BDRV_REQ_COPY_ON_READ) { @@ -1504,7 +1508,10 @@ 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); + waited = wait_serialising_requests(req, flags & BDRV_REQ_ALLOCATE); + if (waited && flags & BDRV_REQ_ALLOCATE) { + return -EAGAIN; + } assert(!waited || !req->serialising); assert(req->overlap_offset <= offset); assert(offset + bytes <= req->overlap_offset + req->overlap_bytes); @@ -1608,7 +1615,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, /* RMW the unaligned part before head. */ mark_request_serialising(req, align); - wait_serialising_requests(req); + wait_serialising_requests(req, false); bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD); ret = bdrv_aligned_preadv(child, req, offset & ~(align - 1), align, align, &local_qiov, 0); @@ -1628,6 +1635,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. */ @@ -1646,7 +1657,7 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, assert(align == tail_padding_bytes + bytes); /* RMW the unaligned part after tail. */ mark_request_serialising(req, align); - wait_serialising_requests(req); + wait_serialising_requests(req, false); bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); ret = bdrv_aligned_preadv(child, req, offset, align, align, &local_qiov, 0); @@ -1717,7 +1728,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, struct iovec head_iov; mark_request_serialising(&req, align); - wait_serialising_requests(&req); + wait_serialising_requests(&req, false); head_buf = qemu_blockalign(bs, align); head_iov = (struct iovec) { @@ -1758,7 +1769,7 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, bool waited; mark_request_serialising(&req, align); - waited = wait_serialising_requests(&req); + waited = wait_serialising_requests(&req, false); assert(!waited || !use_local_qiov); tail_buf = qemu_blockalign(bs, align);