From patchwork Thu Jan 18 17:49:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10173757 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 3B9F46055D for ; Thu, 18 Jan 2018 17:51:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27EF4281E1 for ; Thu, 18 Jan 2018 17:51:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AAAA28408; Thu, 18 Jan 2018 17:51:09 +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 2EE37281E1 for ; Thu, 18 Jan 2018 17:51:07 +0000 (UTC) Received: from localhost ([::1]:44483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecELD-0005uU-7t for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Jan 2018 12:51:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52268) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecEJg-0004Mj-HX for qemu-devel@nongnu.org; Thu, 18 Jan 2018 12:49:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecEJd-0004HS-Es for qemu-devel@nongnu.org; Thu, 18 Jan 2018 12:49:32 -0500 Received: from mail-am5eur03on0716.outbound.protection.outlook.com ([2a01:111:f400:fe08::716]:42208 helo=EUR03-AM5-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 1ecEJd-0004Ce-5X; Thu, 18 Jan 2018 12:49:29 -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=+mhcy2SKFQOkThyHlH0r3qSgqwyIoO1NmnMfck57ymk=; b=J8a2bbCmGQNqLWO4KoNPsul4iOLHDr8EUiQdQybbq2f7Jzgw5ZnmfIEPFr3M0AYaSbyey0pMfX3DdA64fQALgsZHi87H+DbTnRWQnLF7q2whC74n74u9tm3uz0OcSlUHt+OcEy0g8ZjBAGhczzSZp3g8OLDH4D4tBNbIbTjzShI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by HE1PR0801MB1995.eurprd08.prod.outlook.com (2603:10a6:3:50::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 17:49:24 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 20:49:02 +0300 Message-Id: <1516297747-107232-5-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516297747-107232-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1516297747-107232-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0132.eurprd05.prod.outlook.com (2603:10a6:7:28::19) To HE1PR0801MB1995.eurprd08.prod.outlook.com (2603:10a6:3:50::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7203ff00-aa3a-49ea-0f82-08d55e9bd028 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:HE1PR0801MB1995; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 3:Ub3t05Tk4dTPGzQ7R93SGYuHPlS91YEBtX8AgVc3UHRfAbCizHUjbp/HADIdIpVVvxK4g+qWYE0j0hA7s9RDM72rR7lfTgQ2GVuRXP6Xdm9UiTyy/oh3QcOsj1qKXTkTJPq9W4Jl9GeVZg8SBRQM6byBqO+Q9Hca83szt9CcjFuvwo6WKm8yT8rn/v64inzZ5kncFIJaUL1pWUNZh36BOI8NnqjdjqB66IGr2AGCEMk0UCEZMbBpymc76XVcH5F6; 25:FUDtxlnqXqffpiDRhgO/E/YPwdPKekAHzQtrhmYA6b+B8FXPXFxd7uI+dkSL3dk1ZsCgVTaFtyLginzaAHzIOWTS4VAR6z4VFKe5PlrGUKW0zaXFFkDx7XTrrQyxa5AMCsSJfwgEDg4sZtqbW8OKWn+HIj9qfRt8x73Ji6n6oLVRfTWumSqXBUUWHzPaw63D7ypgg3t9bX/O7rPOGgDIZNkCUYLggx7OOsmv+hTlhbFag51ZEq9aRPYr2rf+TKowKHOUv4MkUZYSAw/Ky3ywIy0x6f0egysJu+lO6Frq6Wsz+onX4iNCLr1FkVotkJ7wuueiajXo0A1ZQPiKfc0LRg==; 31:V18RFNKrW3aDQFnygP27+uOimIvUfA8qrFXPZ5pBlOiXGU3Sl2XHKwlc21TJGlfsqxThxUW1qF8sxm9ynbdm7R3bmZuyxKTFseaT+WKi6Vm3lEp8q9CFbrUsSZVpOfTvRab1YiUargVZqP3MVDCs/cUm6Etcej65vuWe1EDTE3n/rGuXI8gCjhUf7ckus1M+36262qj80OMB7ZQHcHY68uDp5c9REFoRm9Jd6e5J37o= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1995: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 20:FvnY7UOWB5qfyNkK4ELojzNagdwdmqg0H+YIqsSatSrcICbGzJVu/yElSm6goqwo/l58ZZBKX6Rw1IhYatRDGivkkjpGoCaZMXyDcbvehgmPJcdWGHzIGzbx6k7pFS4SZ+Ly2aBms2NSWJT+I/jrjUiX4B8XqBQy448SA/xLzMGpt759VzU24usdg0vndbojLXdTTDEv0JeeIpJBx4QRvEm+AdlgEjsPFl/uYn1GiUUC0zkhgLqhr06JK8ZwijROQqnb0UuDwxKqfkv3Q4EwEv2ulvx93iw0yd4x9WcxYnuO+/nDYmxSUzCSIqNgVP85WcZXCq6Y6s1Z5cc+W4o+9DR+1G+qDWLTRHzImIPDWOFmoj2erqH5TxBAwGU4KyqgFUAJrq6dh+P+GTKhy31F0iTG2UVnmZ2/5GTPwR2mVgg=; 4:atew1ZEZfElBLMxFF0AJLK5vkkGD0F7pwYkKD9QUBMrgtY4MjmOfJKJiEC1qKbWlNyBLeY8bDiGmNUH7Yd5YPkOwBUFVUzpcVJ15UxlVaCBB/hMds5rQA28fz5F2wSIalHaqvNLFrmwmzohKhSeg/jltZ3SBJoWHTC2XfthQfRwvOMhIQFr9rqCcyt+FtTAvn/FYT2kt97CgrM9C6ODPjVTQsvdjOusOYifASqr1SRRO4UbqSQAy1KujXNUSSZc4uvkDVbHsAQBY4AXWtoPbhw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040495)(2401047)(8121501046)(5005006)(10201501046)(3231023)(2400065)(944501161)(3002001)(93006095)(93001095)(6041282)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:HE1PR0801MB1995; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:HE1PR0801MB1995; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(39850400004)(376002)(396003)(39380400002)(366004)(199004)(189003)(50226002)(6512007)(16586007)(316002)(2906002)(16526018)(53936002)(2351001)(6666003)(5660300001)(575784001)(66066001)(51416003)(6916009)(69596002)(59450400001)(7736002)(2950100002)(86362001)(2361001)(76176011)(478600001)(97736004)(107886003)(105586002)(50466002)(6116002)(47776003)(68736007)(52116002)(26005)(8676002)(6506007)(305945005)(3846002)(386003)(36756003)(81166006)(81156014)(53416004)(6486002)(8936002)(25786009)(106356001)(4326008)(48376002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0801MB1995; 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; HE1PR0801MB1995; 23:tM9DfpPGqDTMtZz6DYuMsx3dUQK+yf4YjitUA72?= =?us-ascii?Q?u2WL9T3XO6DrqewW2B1ZrlgzdcM82cbkKNvXWLIyB08mtt3SkAbtpLlqiePr?= =?us-ascii?Q?wqJDXg6D/3ixBnR5jOpRvDImH5is1G7/EZjgK61orX629biJlcDAgqH8/579?= =?us-ascii?Q?ZGINgiKFSUuAizuOdg2hr5ezJaIcIX653KR+m4+Ozi4YP925NIdmUvgCbn++?= =?us-ascii?Q?Sou6chJtpoWE8+dPq4P4nfkv4Hn8dEp08TdriB9+oZFEgen6cofn+KmBZ/L+?= =?us-ascii?Q?ULuUWwkbKYzpdrl/G4HzTEj1B/FHnQ9oRRqdJW1mCSYtg0tOEWxxBFhqNLyt?= =?us-ascii?Q?ldfVFx4ZO/msouTfGszbe0oSWTMcPf0+sz8Rl9bvWXMn5HUYhJSnpoJpcGmS?= =?us-ascii?Q?pUCB/bnwBjbe3AP8NpNjdFwPiqkho9gxbwTGDs1lzeaejcQuBiQ4dtHACfk7?= =?us-ascii?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NBYOE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 17:49:24.5052 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7203ff00-aa3a-49ea-0f82-08d55e9bd028 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1995 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe08::716 Subject: [Qemu-devel] [PATCH v7 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 Reviewed-by: Alberto Garcia --- 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);