From patchwork Wed Nov 1 15:43:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10036685 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 02AD9602B5 for ; Wed, 1 Nov 2017 15:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5D2D28C6E for ; Wed, 1 Nov 2017 15:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A852128610; Wed, 1 Nov 2017 15:55:33 +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 C5A6028610 for ; Wed, 1 Nov 2017 15:55:32 +0000 (UTC) Received: from localhost ([::1]:56421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vMZ-00086X-Lf for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 11:55:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vC9-00085U-GS for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vC5-0006cc-AD for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:45 -0400 Received: from mail-eopbgr40114.outbound.protection.outlook.com ([40.107.4.114]:24096 helo=EUR03-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 1e9vC5-0006bv-0j; Wed, 01 Nov 2017 11:44:41 -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=7JcE4p4DwXXVmBNAA/YOzIh9lH8VNMN2vfOeHy/El34=; b=CHzfnTk4poxzeFHwUIdIo5sONAsYu8/kl0MOte3TBkRwvCjFGFZP3OYd83LZAaDT6Mna8wiAsf1SZAK5eXG8E1TYyb1ZChJ6Z9nWlCTQ/kRPzu/H2CVMKV3lIrgUlWUSaKTD6x9kT4HLTLEqyCV0QzdBV2aOdDfX9bBXLScZXL4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Wed, 1 Nov 2017 15:44:38 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 18:43:57 +0300 Message-Id: <1509551048-129830-5-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR0501CA0017.eurprd05.prod.outlook.com (2603:10a6:800:92::27) To AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 44ade82a-ae49-4fa7-abce-08d5213f7655 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603199); SRVR:AM5PR0801MB1987; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 3:zll+keuL04t8bkVRf06lZ5CDMTcGa2Dd/ZRSQRUDAznLsE2zLh1gUn3Oef8/NOjG/ahWfHMCihuPSouGyeA8c4AWULxf45UdQjVtp6k1WJACGLtQ2ca/FTS7mOtVPE8eumjju3WcqNqnIptFa7oGwVYGK0aj07uMX/I8wCC77eDEOwVjR6Db0I5doK0i2nzg651wop8dyn9wDvQd0XVY2r3h04d7DFuL2zTQGuxerNNI2Dzq4SH1bVK4ulSOvHMc; 25:d/K18Ut6liRDifWh7WdsI2Ym26iIgyWsj6o20bSxb/6E4PlHSYE7ze+lyiQqMwPzttvE98wXCcDS8T58UfXtwg734NvItYzYKc//A7QAo6n8jFh14B0pJk760qvd9h0FRI81ycoocdNmdegG+h6H2ho3W2g+D+54oXJ5I0Kxh4MMJk3M/Slfjoo2JEM3Aavd2MRHSn+FSF+a2EbgN/gxjxD1h8UEBXdfB22fG6wleXU33KZQPUYR1fshhaCPX0kzSvGpwjriyq5DtP9q+iTzrOQHVQio5ThLR94OAQG5vNFVjRJkPmO+ZEddTvBs+oIK6ROJIGp4WeBjnhaTEkOjpQ==; 31:4zX1Zuvg+XKHnceSysZROWOZsmHU7BKYb+mS3WVTjajf1D+QFPykfy7FudSbhImAr9f5LsNr5j5GdypdZ+lQLgF59itxHVOsToahIUYUcFtMH+9Cs7fKbvEGEs3iL9baC5B57mnE/2XOukrOo/aQB9V7pcIN/IQZ07wln7TMLmnAAUcukzZ//CdGYavju6YmPtd+XfgerFzvfE7NOwSfZCIhlBJ7tNvpsPLX1efBjP8= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1987: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:cCPzFhZGSACMtCuAy5UpYrKGSwTHTA3ccNuRr1f7NvmVkp67gM5EEpZTt3eF/t9c/ymQogOMr8oZE3wTPSP65z8lZo+cfeZbNRrex7YCEqgoWuSRgiq52m/uAjv6PahnbQNGVYE843fphJ79gfL/qz4i/CCqYD9rQCqcQ2gOo1BEAwX3Twa8NlXYRO6REW3LPIjnLj4FN/dOV6fkWbRIcUfal1A9cS31dzFfpaZyv1Har7X1OdM3woLLWCmuKKulpZ9yMKatVw8ya17cu5X619NsrWP3to4QGAwXuZZHZuWDRsIoUsOtcxyYkAtQDSP6LJLxXq3ejRyZ4wglDJvzEzsUDr5x51VQtx5NwQIqGdNYfV/QJE4NN1ZIX1Q+DQIEfOlYHePgMUJ2YceIHEDS264PeNh1IW1Mw3xqWlPN2QY=; 4:53nl9+V7nvjfjiE+6Q3XQ0rP8uIYT7iDpbQC2ihU6VIoAf75dIcVse/7fDCRcxoqH7iNd2cR4gQh2kNyZnAoqe8QyBcE8KpprjHGVpOpb8uasP6FrET8AI1mZa3Ln9DmkoKEttbUUq5k/XO3P6vF/luXo826HQgeI5Xz0vbaznlVUcu06+ch502pv8V0ntEIczv9lVciI8In6Me7cXaINSvJ5kgGzbkkLyTXwP0DTcyXmuZapumertxzhPIkCqr/yHnqlL2IUztaS8k3sa3lMw== X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231020)(100000703101)(100105400095)(3002001)(6041248)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM5PR0801MB1987; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5PR0801MB1987; X-Forefront-PRVS: 0478C23FE0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(189002)(199003)(6666003)(16526018)(53936002)(107886003)(48376002)(86362001)(6916009)(2950100002)(3846002)(6116002)(101416001)(575784001)(50986999)(76176999)(106356001)(69596002)(5660300001)(25786009)(105586002)(316002)(53416004)(2351001)(16586007)(2361001)(33646002)(4326008)(5003940100001)(478600001)(66066001)(36756003)(50226002)(6512007)(47776003)(2906002)(8936002)(6506006)(97736004)(6486002)(68736007)(305945005)(50466002)(81166006)(81156014)(8676002)(189998001)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1987; 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; AM5PR0801MB1987; 23:By/pua4CFI1wUJIuZyy/FtKLS71rd+JZNN8gLjZ?= =?us-ascii?Q?R7SM6xFFRRIZvw8AxzJqDmRrPgktRiuZxqBPpBDebQlmsiR4gidzle+0DzTl?= =?us-ascii?Q?X04gaRmj60K37TJJ6QSY6xgFAp+3RmP92Dg+V8BH25snbufP8SD/nhpZe5e4?= =?us-ascii?Q?OwfPCqWzOYewsiFtXst2CdlJY7q1OqIEMk/8XjB1J/Wa75OhHnl26WiW39oM?= =?us-ascii?Q?PcqlsFLJlpK9SfgoF5MwPHOtmionn/Rfssw/8IaOVu51Uv313RoX8Xw5fPDf?= =?us-ascii?Q?5Lm05cAmao2wfNdNMwfdYKLTzejSsJy/IiSJWbNByCqzh8kDG9woga1bRnJJ?= =?us-ascii?Q?7R3afNnTl9fpqsQv9vvzJM9i4mA0RRHRlrwGLMaP2SWakvJ3fS+homsB0HbV?= =?us-ascii?Q?BiTZJF9cqJJ38+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6znggqihz1N3Y= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 15:44:38.6494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 44ade82a-ae49-4fa7-abce-08d5213f7655 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1987 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.114 Subject: [Qemu-devel] [PATCH v5 04/15] 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 --- block/io.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index 7506207..1e07a0b 100644 --- a/block/io.c +++ b/block/io.c @@ -535,7 +535,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; @@ -566,11 +567,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; } } @@ -1120,7 +1124,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) { @@ -1410,7 +1414,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); @@ -1514,7 +1521,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); @@ -1534,6 +1541,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. */ @@ -1552,7 +1563,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); @@ -1623,7 +1634,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) { @@ -1664,7 +1675,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);