From patchwork Wed Nov 1 15:43:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10036673 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 A6392602B5 for ; Wed, 1 Nov 2017 15:52:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6F7E28C39 for ; Wed, 1 Nov 2017 15:52:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BBB228C9E; Wed, 1 Nov 2017 15:52:02 +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 7ACED28C9A for ; Wed, 1 Nov 2017 15:52:01 +0000 (UTC) Received: from localhost ([::1]:56402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vJA-0004n0-HS for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 11:52:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vCA-00086u-I9 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 1e9vC4-0006cF-Kq for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:46 -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 1e9vC4-0006bv-9o; Wed, 01 Nov 2017 11:44:40 -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=eN8aH1LjCf2PZgDh6jKK8nWx7j6xlchfn2rIjy0a1Rc=; b=LOxDY3P7TmHUL25KWXF2LIx1BRwINfyA0mptf7c40RxoBjZrR/jnX+83NK67B5OxBv9l/CdOUhlpYAVT2vVgsvdGgVNTjg0ULnwiX7Lu1DJCrdeSpJeeo9PDcnsGO3FdxrIr8PMkid904NGSwiafE3YfnRVHAYn0auSS/0TeT9c= 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:37 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 18:43:56 +0300 Message-Id: <1509551048-129830-4-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: 78c4d8e0-f269-4910-9fd6-08d5213f75a7 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603199); SRVR:AM5PR0801MB1987; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 3:c795vxK998/DJkK7PkCYIsnrucMkOjK730ohMIpMmL1MK5+Rwo60bZZNbsb+isYEqBqGs6NND8ujqXK1Z3gMpx/L8WxGcL0W4Awj+PrUuM0vFmwE0MPOilElb96RAym7H3fw30QjxAMTE37oFF5LHakludMRT/ERFpnNA+/RnkVcOJ1VySma08eK/PcLJMx8rRlT7JnsmDRPfyUfh8m5vPmqUH0xfNoke83cQUORmSX6QIwM9JO+Gigmm+fXglcJ; 25:IR/yeAidyKx6cNfOevwAgk2/33jmk7PC6kVJweiVW66t2A3BlbbglH5BbYeBIWx6Nru7tskUwACIhMCN/D4gmHP4vzFYjS8Ak4tzErAldHpPU3cuDqkvlo5+snLNwyblgfntGWsKdFZGNRXKsOv68edXHdQ8EMOKtdM0zjW5wOdVMGXxQjchE31OmkgKYzJKtKltiMKC8x5nEgXoPsGTGibdoBDESTXucXSQJVd0VFizTZnzbfbPvki6Ym9e+0bQKwGTXf6PhndXH+CpiFZzJFr+4BVFI1k4A0qM1eNU2G6KLy7f8CfNdHczCPa+IHBeMcGSFDJZsrulSLFJ7+XXzQ==; 31:yXybWSWBr3BhKP43hF2WUwiYII4zeTuTneW60Y3V4Wu9c9p8w9+HbJ5khPNBUI9md3IPzDb+Cq0N/RXXMiE51yV2erABkl0+g7ScVa+KIaZ0U2uUVSoRlMZSwLHJhOOLNKWo1NuA1+hh+3e8hnWTQ9DRR7ByQhJEHvMadX6cZdvaN4XtBmDx5Wu5SPqMGJV+99Y4JYtm01imyjI+6Bjbie7td/QDC8zbqSFKLaoWxL4= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1987: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:Ks2NUUq8txxR1hNblWAy1wmrAI1VzdSmFleaPXIqKa2w4M73V2H/M5MmUiRcQuF9wEVEWQlthp3eh8KrTkCxcYdjpyB+2DGL8/MlkjMJA65lFggRlKcPYIMyMI+/ml4iHTMkHU1XS/PQCMnDGHep4HEn0piYHuzW9SsLKZV0kgZ2bMGyDBUmA1HZiCKBNpmVuFKxiR9kAfBEYdxcadrelNM5wDwNb7DaadT+1gHfEyz9RvuhzUy5qAA4eDXXfugnsgq4+CP/KzTIYeQGNF0cLOTfvi2bIB1A7ORr1oWa52npPrISuI9Mch/XQxyOPoXYPe4nu4MQK8WtK5tkyObKpkWVNr6eLwssKrZ3nPCDkl/lrtEEl13QXeQ+e/qrseCGEyg74+oHf2s9e/dRsq4+ZySi4O1lOZxl+WCXLVi77Rg=; 4:DlNm11X/6KuVbSL8GdrJFoQcrCJO8OiY3tsPFQWhHksjo2age1nMBPCZLLofB9l47Ky7MUk27wW6k/3up6YQWNkh5Rsk9+ENYE57Q0Cl77eTKeo8vjU5U2n9gvxe3wKFC0WidtfBH1ZvpbX0MPS7QbipVIf3Yo4vDcBaAVGSTOvEt55+iqbDM2vSHzxVwiZ177ljik2DJbJa9l8mdR83FXPaiUoQGCfGiwQDn8pQuNxaQBweE/Y0BNaCOcg79O5zRIy2yz9/RMN+/tU7KzL0OA== 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)(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:LlvbIdt8NqGDuT3ojJDgnahmZpmYeU7Cq8UhB+a?= =?us-ascii?Q?Vbga5QAF00AkpVEJZyAY65SpAxTdvz5ufEdz5bJMLMKr8j51Jqexh2BLIKVG?= =?us-ascii?Q?TgaQi/dw/3jmKAr8ET3/ViDslNji7l22IBeIkbljIWKMhEYqhLGQHE2CLCuo?= =?us-ascii?Q?t/bsl6fOi1vG01VRQRkOLPn1Xq1NLcFdpZZpHm4m3Z+oqgqF7Zl9G2kzlyVp?= =?us-ascii?Q?FMx+QkhOAKbf7Edy2fzYOcXxSkz2XrKwCh8ZbZm2bIKycmlfVZS4vCcVKOhw?= =?us-ascii?Q?rRNznjdOr3B2TGQU28d1QM7tzs4jWRY6oJm6k6tTy8v+jP+6LxK6RefIHGMr?= =?us-ascii?Q?ksB4TQrIYuOJiq+QwC3PLR1nVjbYkXvRPFgX+dDirDsAesO3VT5Cyf6OwfzZ?= =?us-ascii?Q?dTenApO5RhDmBwrB+B7VDz2dNZTCnwnMgg9oj5FK9hXqatX+J1SEGKkK2oAR?= =?us-ascii?Q?MG0iFBAOGyAVJVRuR21VmZk+/Ozd25WSO36xpYifCkVmxbtr2XA57c4EgN/4?= =?us-ascii?Q?yb3dsagGC77VulJin+MoCVZj1fwvJt+x/Fia+cCSciTeK0ULghVybvoL5pFc?= =?us-ascii?Q?4xGFtye8Z2OrMDR0Ew1TYFdoedQYBHQ3ChNJpxxA0V1POAH3jSwURSGUpZeL?= =?us-ascii?Q?1SzfACxrRDHo23XVLN4MgnidMGM7xLu73YYCclWxu7RR0EvBi4MCALYb+ekP?= =?us-ascii?Q?uFz8BEjfToc5MomKmgW76uQjki0RKxKvCdCgBXd362wkC7/FbymA9ulAy5qx?= =?us-ascii?Q?AbLN2xS2z/POGBC51TOVBzMEsWbweSTsoJo2bMuZUe5C5We1fR3FNyODOal3?= =?us-ascii?Q?23QCXfmYGpyIbezqgtJA4oazINVAK8dCKMkstLso8xSMNBlKvTbKafj+X1a4?= =?us-ascii?Q?SG+33KM1jLyVxT4nT3wcQU+ovtnKNoGeBLODaFe4LKe6HXf6wZFmpJ7Xnx5T?= =?us-ascii?Q?dR3YTJcWgA4FTCv/TRQ3kv3jB9+yWj/pElKudiexcSsGL0Sx6oDQXKEJK7dv?= =?us-ascii?Q?vNbjrnRrQOgztQyDopvI2kK43oNFW8vtxi2ChxaMku2gKVpDclX/hkOORRAH?= =?us-ascii?Q?+R8QE6SSHfxkkZcJracXJ7bZfPQOpyuUraINMHLoHiO5agtMWwy+P69ReQqm?= =?us-ascii?Q?UI7d+03YPxtUWZA1faVqa3m2yMxrSsUxp8GPAON83FdHiM+bFtGCOSA=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 6:iimWQtdXxeVYUq1n7Boeh3cwgGSWubQ1R6UsqVVHrlajjDMlWsCt8yb7h9+p2WFAix69SRpYsTEZgv/Hsw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XQkKHlTm0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 15:44:37.5087 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 78c4d8e0-f269-4910-9fd6-08d5213f75a7 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 03/15] 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 | 6 +++++- include/block/block_int.h | 2 +- block/io.c | 20 +++++++++++++++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index fbc21da..a291db9 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -65,9 +65,13 @@ 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. + */ + 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 a548277..3799f5f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -632,7 +632,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 3d5ef2c..7506207 100644 --- a/block/io.c +++ b/block/io.c @@ -1334,7 +1334,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; @@ -1420,8 +1420,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, ret = notifier_with_return_list_notify(&bs->before_write_notifiers, req); if (!ret && bs->detect_zeroes != BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF && - !(flags & BDRV_REQ_ZERO_WRITE) && drv->bdrv_co_pwrite_zeroes && - qemu_iovec_is_zero(qiov)) { + !(flags & BDRV_REQ_ZERO_WRITE) && !(flags & BDRV_REQ_ALLOCATE) && + drv->bdrv_co_pwrite_zeroes && qemu_iovec_is_zero(qiov)) { flags |= BDRV_REQ_ZERO_WRITE; if (bs->detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP) { flags |= BDRV_REQ_MAY_UNMAP; @@ -1499,6 +1499,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, @@ -1599,6 +1602,9 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, return ret; } + /* allocation request with qiov provided doesn't make much sense */ + assert(!(qiov && (flags & BDRV_REQ_ALLOCATE))); + bdrv_inc_in_flight(bs); /* * Align write if necessary by performing a read-modify-write cycle. @@ -1728,6 +1734,14 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, { trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); + assert(!((flags & BDRV_REQ_MAY_UNMAP) && (flags & BDRV_REQ_ALLOCATE))); + + 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; }