From patchwork Mon Mar 12 10:16:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10275915 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 98BE76038F for ; Mon, 12 Mar 2018 10:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D66328C59 for ; Mon, 12 Mar 2018 10:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9238328CE3; Mon, 12 Mar 2018 10:22:16 +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 706B728C59 for ; Mon, 12 Mar 2018 10:22:15 +0000 (UTC) Received: from localhost ([::1]:57517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evKas-0006tk-Jx for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Mar 2018 06:22:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33621) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evKWI-0002k4-RR for qemu-devel@nongnu.org; Mon, 12 Mar 2018 06:17:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evKWD-0006fE-RA for qemu-devel@nongnu.org; Mon, 12 Mar 2018 06:17:30 -0400 Received: from mail-eopbgr10121.outbound.protection.outlook.com ([40.107.1.121]:6708 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 1evKWD-0006Rl-EC; Mon, 12 Mar 2018 06:17:25 -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=Zd5lIXT9vHRRGoO28Y5oWXO1nfYXS9LkUzK9M3y3U9c=; b=SHW+Y+gJIwZLI2o2jT3h7paA+uXxAuomRqiKlhghiTxhb5tghaysXZC9quCgiQaWyHBLcb0uijfLBU0iXpuPWYq3CAen1Ei4nJIsrklkKSIxZYnA6qlRsZ5E8jp3RHhZbbND3njDkfuqIJjdgiY5VGDLrCwyGIeJl7Wvz68iDHM= 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:23 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Mon, 12 Mar 2018 13:16:53 +0300 Message-Id: <1520849818-6915-5-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: efd787f0-8cf4-4df2-1894-08d5880272ed 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:oO1XvW3KCvJhcnH43KPiS5cg9GKb8qXJkQDfkX0jsmAaPmXOiVaUAiyllNe9xKvaqfyEC0cYVy1j7bcb8q6JM1LB9FwxjOpfp5hnARkfb1sHF9PBLJPXzuFRhIeb7Wz88eIBvpAlB42HojbbGQ2F1BHrhGaNGzeZzzF1lsh5JjJd4+QxoqNKSNJbVBjyBXOtfnLkq9ny4JyV6h4+WYAUTiuYBS9AtG+Opd9azpz1EMam8EDlaWe7E5kVWylepK+b; 25:zil+VChN5ayOerM37su6KuOSjLf4Krabft9NwQB07Pxpd4exZ+LjlbUzvSPppLnJvJzMcP3CUQ831xq9ds9mtflcCeJ+01Gq8y3Dgs2jnKXP4qf6R8AylW28Gwxwy0c45mMrKumTCeiy2R4BCwplBMViAUchL4OSZrJckEl7Zy0/xJRV0lSzlL53AQ03giIWr7/pes+Bsf1sYZgXp13AzUEmBXgvM3E5pi4xDQvP4AyJf81h+Feh/Xxp4G+FbNiT9qWYIdQTzGx2/4zvotZ0aywtSBpyoFmveerwHMVlUskCdoqeYngFoeGLp/RWyVbG/V5DCTAU6JrDGguSfyS89A==; 31:DkLs/+cKx8mC7BH+0HDhB4Ax+8qjcPJbl7tw3Tj24gKF61+0fxwjwJhEx86azRKVxnvZQd9Pgv4SK9tsiPSNFPVwHzV89GYb8nf4ukdlPXDVuLtIumK3RH05JAYSpedw9M8YELbEbGMSjaYpZp6KfzwIgzIKCmVuHzhkl8lvWRbbWDzRXHnoF5wOWQt8Ikl4WUv1JI0cwyv3qvVwcXP9e24RNdgruZ0+lQ6MXrdXFoU= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1991: X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1991; 20:kCA3C97HuJ2GS2EzIFQCxFtwmwAYI9oS8ThX4M5MLwRVcAsA3qmZntws4xzWM/79hFKvgvmDhgFlY4oBtKpHhmMmp7cp5EILqXD7QipmBLNiENwCEeLOPx8NBOReuOo7goKhByglrUFim4OLoLZtCt8a5dedEwYLOTa7Q4uTSyJFj0i6GT/5K/4TEk2fYf2NNg9n916cRy4f7wQfijzSx2vE2fuph8LFzqoLg0V6sUVX2w02YszjeFqlD4+0tJwI/0Nv7spskDZbp4CR56n3R2qI7G1ia6nnwOlsHWkv961HWSUr/Eyd2fIdhbrXkLkYhIn0IlETtGQ5kiz0V6Q/IvmILv10/Ws0VImtjv6iVN4pR4y1DnIoAaNuJz93F77hA0+9htp5PhrMSMblJzCAuZBDfvaAmiolzRx+Qn1GHK921hKDeJVblkacYvsVhy7z43dnanGxuZT1EsuYod3QJS5Q7QkosawN47kFRAqEihnaAN8zE0N8+pZPVePS2Xd/; 4:3iF8ML8oJbMIy4VpcJAJrGkvx1iKjy760TATLstxs6EeNsATva+Kh1u/N47aiIHkcgr++2dHS+i1m7NJmirhqOBKobL1oNmnjj783WUzby3wlch3d7pL2hpvtqltjlMjNcpdEcAoxNjYite0L4coLy6p3X3Zv6nNIEBiKvpryLZsqRJTl6qhcnmNq3I5Vrcr/Fh3ZQEnaqtyd0pLKrHnF8bqxmSAJJZC9nz9NM4axchl8xsa9ywsm5E+782DygIyIyUGAOryq+dFbsfNDPVj5A== 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:Akkn5YAf/4lrq0oH2kGcZSSY2N39TTRNAB8XjAv?= =?us-ascii?Q?dIPQEbKLLUHJUQRhfhQZHjDSrXOIZDZtxdPrX37f0d3QLvxy7uMojEy2TWkH?= =?us-ascii?Q?wV6e8GJXencXkx3MdjR1LmCGrpbhnM1h2FFMAfb8qZimLlgG2ch3bz5tGkix?= =?us-ascii?Q?RD1fdvwx7P+LjPlykwPmIJQd1AlRGlsD4/tNThzVk4sQefjQ0C5asRJ60D/C?= =?us-ascii?Q?EF8UoNCPC3tI6lyC4OuG0AQD4U+KpIPeyxfEFnpOeCPRDHLPmPWF5G2Ko7Qs?= =?us-ascii?Q?dARDhtYF5GYQjErnc7VSdliZ0jwjE9HGYt7vQ/bj/2F/Wc3lCJ/bZ3NZdQDq?= =?us-ascii?Q?+7kzPO5AD0ZjX+ukCwvgj48yMfVbdWe+WUDOF9pQvSayB9n3BYJ8gSbnexGU?= =?us-ascii?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MYZupiFIcqz5lKcqhS/82RwJ1d5Q2B2YkjYRb5sK1NXTk+e3ROhFhtWtrKehyWMA71umei9+UIZGciyh SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0801MB1991; 20:uTWbrvpWxceUoMrPY4zB7cYqwPySWnEjpqGYLwTu6tNLlbOGZyi7KYXUhGdCfZHdZACpw1x0oHPaojFgD+NUmPKiAnNXHx6/w6pIkE8l5fV3ndDWtyX4oVUgvWk6rY+A1Ipafm1HPolZaB9Pz8FZXZsPzPATS84zOcvw7NCGlEs= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Mar 2018 10:17:23.4589 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: efd787f0-8cf4-4df2-1894-08d5880272ed 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.121 Subject: [Qemu-devel] [PATCH v8 4/9] block: introduce BDRV_REQ_ALLOCATE flag 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 flag is supposed to indicate that the region of the disk image has to be sufficiently allocated so it reads as zeroes. The call with the flag set must return -ENOTSUP if allocation cannot be done efficiently. This has to be made sure of by both - the drivers that support the flag - and the common block layer (so it will not fall back to any slowpath (like writing zero buffers) in case the driver does not support the flag). Signed-off-by: Anton Nefedov Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- include/block/block.h | 8 +++++++- include/block/block_int.h | 2 +- block/io.c | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 8b6db95..9747632 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -53,9 +53,15 @@ typedef enum { BDRV_REQ_NO_SERIALISING = 0x8, BDRV_REQ_FUA = 0x10, BDRV_REQ_WRITE_COMPRESSED = 0x20, + /* The BDRV_REQ_ALLOCATE flag is used to indicate that the driver has to + * efficiently allocate the space so it reads as zeroes, or return an error. + * Must be used together with BDRV_REQ_ZERO_WRITE. + * Contradictory to BDRV_REQ_MAY_UNMAP so the two must not be used together. + */ + BDRV_REQ_ALLOCATE = 0x40, /* Mask of valid flags */ - BDRV_REQ_MASK = 0x3f, + BDRV_REQ_MASK = 0x7f, } BdrvRequestFlags; typedef struct BlockSizes { diff --git a/include/block/block_int.h b/include/block/block_int.h index 64a5700..9495e35 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -648,7 +648,7 @@ struct BlockDriverState { /* Flags honored during pwrite (so far: BDRV_REQ_FUA) */ unsigned int supported_write_flags; /* Flags honored during pwrite_zeroes (so far: BDRV_REQ_FUA, - * BDRV_REQ_MAY_UNMAP) */ + * BDRV_REQ_MAY_UNMAP, BDRV_REQ_ALLOCATE) */ unsigned int supported_zero_flags; /* the following member gives a name to every node on the bs graph. */ diff --git a/block/io.c b/block/io.c index 2b09c65..c4f2a07 100644 --- a/block/io.c +++ b/block/io.c @@ -1418,7 +1418,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, assert(!bs->supported_zero_flags); } - if (ret == -ENOTSUP) { + if (ret == -ENOTSUP && !(flags & BDRV_REQ_ALLOCATE)) { /* Fall back to bounce buffer if write zeroes is unsupported */ BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE; @@ -1511,7 +1511,9 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, !(flags & BDRV_REQ_ZERO_WRITE) && drv->bdrv_co_pwrite_zeroes && qemu_iovec_is_zero(qiov)) { flags |= BDRV_REQ_ZERO_WRITE; - if (bs->detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP) { + if (bs->detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && + !(flags & BDRV_REQ_ALLOCATE)) + { flags |= BDRV_REQ_MAY_UNMAP; } } @@ -1587,6 +1589,9 @@ static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, assert(flags & BDRV_REQ_ZERO_WRITE); if (head_padding_bytes || tail_padding_bytes) { + if (flags & BDRV_REQ_ALLOCATE) { + return -ENOTSUP; + } buf = qemu_blockalign(bs, align); iov = (struct iovec) { .iov_base = buf, @@ -1672,6 +1677,9 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, bool use_local_qiov = false; int ret; + assert(!((flags & BDRV_REQ_ALLOCATE) && (flags & BDRV_REQ_MAY_UNMAP))); + assert(!((flags & BDRV_REQ_ALLOCATE) && !(flags & BDRV_REQ_ZERO_WRITE))); + trace_bdrv_co_pwritev(child->bs, offset, bytes, flags); if (!bs->drv) { @@ -1816,6 +1824,12 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, { trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); + if ((flags & BDRV_REQ_ALLOCATE) && + !(child->bs->supported_zero_flags & BDRV_REQ_ALLOCATE)) + { + return -ENOTSUP; + } + if (!(child->bs->open_flags & BDRV_O_UNMAP)) { flags &= ~BDRV_REQ_MAY_UNMAP; }