From patchwork Thu Jan 18 17:49:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10173765 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 4C6A2602DC for ; Thu, 18 Jan 2018 17:54:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3994428047 for ; Thu, 18 Jan 2018 17:54:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E635283AD; Thu, 18 Jan 2018 17:54:01 +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 7DC0228047 for ; Thu, 18 Jan 2018 17:54:00 +0000 (UTC) Received: from localhost ([::1]:44517 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecENz-0008S0-Oc for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Jan 2018 12:53:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecEJg-0004Mi-Ge 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 1ecEJc-0004GQ-VV 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 1ecEJc-0004Ce-LA; Thu, 18 Jan 2018 12:49:28 -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=yBFMpInOPdYlJ4w7940vHgaPI05D8gSiQd6JttTBU8s=; b=AvoN5taOrNqry2drTJmnzK4/Un1mFZWFMkqQnL1WEAok8Za6a+gDnoy2tK9rpL5FSsKeHlltTEs+FD2tAtrpc7kuU2wZF/9ABKaBsMqy+DufTXve//P1qocHhOV57B0ij4sIbhZToIWF7QVerS6rSlC3O7gm7o3lDwMdr9WIfTY= 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:23 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 20:49:01 +0300 Message-Id: <1516297747-107232-4-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: 3749c493-db08-4420-75f5-08d55e9bcfcd 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:TpKsXc5Cx2AEzCpkmCuFr4rvDre4LY2f8Ivo3//O/YBEIw68vi7DNiziNAl3YZXtg6hZSerEMld9tdlxq3U+YeKTlwK/i5pTPfdCJBQOZUc3EGFoO2bYFpnX40oB4aTKgI3b1Mgn0RE727VWeDZwh3JA6vZvNOYomAHal6ZSoEVVayRnGi/oimJLBuiA/GcRfOVgUWZ8uPp2r+sgjeP9akWvTQxXHAflZNmfb81ZirztV30IlB3e/masBjzao62C; 25:iogC8+cqOd1IMV+ei8uyL3hAQJHN5T2FkU8+H2iW/50LI2rzSkY5c0dv6pp07JXnXkuMOUUgYszhSlFhvz6pbZwY8uRm8LaSkZqUpLlDugmoqqs9zKslyMWesE+97qA7FeOLV1lkual6u4BpGGmMjAwzDi/CZL84A+5OAaGD+1xmXh9GEnksjSIDeluXO9vO+cko3cGTqZ3d8hmxcQWZnicgY4B8wO3VsDqejw7FxVUejylkEpFdpvkekBnVLCBeu0wNbB4YV4boORnBQt5oacNc1kcV6gYm2lKJ5/cmi3v5T/eCw/R1uIPChqyotpPVVIRyWz8eGnEYKWiIUMRc+g==; 31:FIO3pWafxlrhToVzKODvHpXwTazve0Wx48cAYQWHzYx0pcUwO6hP9BeFOsmeg9K7RfTC7v02HjUffG/Qi5WjNTZqTnq5rv01EOhTcss5FOvmZoqJ7LYGQ/S1zt7iFGzUsgysrKzzdbwvA+Iyl6sxeXjav/TQT5IIJp1paLbGkW2l1kYL0WIopN9QCtlGD2vhfw35PMplxNsLbsh4NcLRG1rrzhD24kBLU4TB/6wURBo= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1995: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 20:Td/F/KDpj24KRJuLKas3fng4GTHm8VPXh9XJuUtUOKrKKsKWAOkbKtycuRtySeqVYLR2pO+DzXeN29ktr3dL5GhWp/hJvOpNtuQ+NXShcBhieGeqpwMpvikgpAxRtF2wh5/gMGomh73XqyJ0Y2zh9jhS4OmWV+FmQ70bad+ldsqYBuk8JYBL+iplx07yKQh3yVLf8qNU4N4Rzc3JsN8/rUjQzIeYd1iWbnf5cvKSWKCC2NkuY0ftScaxrmQVImg8fEoW1MSc+Dlorws8ykFWlAjgZvAwwLmjPabotxXFufHoY/ki9CuXRsewhJTBAkLHMul2GRU6TCRWn/2im2zVOaKVCAKHkYieCjO1YIkdkQrXdi5110XR1QhDSISBTxdJ7x3aCrCDey5NcBiHYeHd3piIP3E3rSkun+DzF+bw9zc=; 4:8e1hV19VDGwkxKTPlxiCW7QAelkOgpBZXWobg1l7K+Lt2jW2nJXOsLQL82dE52koodg35XcxX1oaFSX49CyQRCDKFY8nhX18IUcKEVBQBmbibraxMjYudDk1idSKNksbrRH15Tz+ZsnKx7GQJVFMd0jKdMMX1mIo1S5rM1+uxFTL2qxCzBvZSzZ08EbFzFVBYE+jJ3UvlyBq4oq68dJWfohiofDhZ4caQwNuleTLvtzTGq9TBfnZqZt4X9s3IPDS1p20+hnMG/5Asc6LNVoTfA== 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)(979002)(346002)(39850400004)(376002)(396003)(39380400002)(366004)(199004)(189003)(50226002)(6512007)(16586007)(316002)(2906002)(16526018)(53936002)(2351001)(6666003)(5660300001)(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)(969003)(989001)(999001)(1009001)(1019001); 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:Coq5EV0yd74cEwvOrjbuKD+qKGd/wDObBMevnoc?= =?us-ascii?Q?GVySmfGuUEvvgFoyw3SDuhv7W4QRywqU1/uOxACnkvgsEeXV7CvqXBOhCvQT?= =?us-ascii?Q?+un+Yu0zmaAD+I99a5Fp25zK4GlnnlpQ9/CAdgQ1ZLTeQSrndvlE0bVXIlRO?= =?us-ascii?Q?BYt+YfIvFZdhrCla/ThkN0ckowdpibgpND9BpJUO7tiuVmOVaA1TiUzEZbDe?= =?us-ascii?Q?HGSCqp4csbVW3X2h+KcrEVmD5VRtY2KuHb6b8VoO1P3oSjK7iJXctJ1eDZEr?= =?us-ascii?Q?ftm6YKkSoxVTikE+dto86Ldb+0439+dxCys8FMs79Z3Ll6uwkvC/48FgPIcc?= =?us-ascii?Q?vAv+KZFrBBuEW+6QrtBxg+Gy9SrNO5HrGO1VGHxYk81Uz702Kk7dWuTSny1S?= =?us-ascii?Q?+wtR+ftxEMyY7vI6cCKcsD5dEOPYD2FgPOgdaKTAoMexME0aPETpICtTtdbj?= =?us-ascii?Q?zsKYjz5yid5LCwJ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: 1; HE1PR0801MB1995; 6:IXnRuVQEsxBxqWYPNgXHaWWHKCcSDGamx1Fm3Fj0Q6cMW+dG11zIx5sIf/U5OOofbEYLde5mJViikTrqm7bNxFdXeAacitIuCJSjVdvzr+uLUyulZqRIuLMMdgycAcfDMXA3inIdIzTpoRJRgc87lFY9qu6NvehI46H4mYxoU7F/hooZtncl1uSwnCCk9s2gscd3qot9hbIB9WzXrRClBa60nSbLuVstPjb3T5xUHoxoL4yN/CvIczIuRJjPzNyXUxvG0qnLWwJIRv7EtYV7S/MZz3HwE1yF1EUA5vfDJ3sgBIMzfcXhQrikrNHTVo3o9N3LDVo6EnbJ+nAkePenXV+y56tQtmM+Wok4VoPGAwA=; 5:aUKwnBb8afA9uh/7+vKsidUcm2UOyCiJgUOGl6u7IKFgYuQhI38LzULPAPTtHy1sTGsTngod0ruVq5QuVLKfaYalckmLWV7TnkEZUQG8juJkX+H8dKA1MHvW2VJGlwsQTtYr/VEjaxKzybGpdUwloiMCskaUsWc8wYNqEV5NjUw=; 24:w41RpaIOQv4TIgFDpSulJHOXdLsNW7aWQpDogoMjDqHtdKhNageaoDtOcQT2lygT/LG3Yqb3RhDc35iltR9Vopc1irukcCF9UUdAurq5rbw=; 7:j9IiX9fGZZ+mfnR3jMF/K6e0ca7J4aMVxXumjyuH+c9KmT4k9s8kBNMj1mHqG2CI9ACHirw2spWvJIQo6YQtnnFgYLWspnoJb8ebhu37GNPr64qpn6xhqxjyoirBQGrprowKg4BddQb+EBJYYb/zUBlmqqtq4i8+tJ+L6ttVuE0TyAdPBblHSRMRvw5uXXmGQvAwNuDH+B9fejLRCLUHzLiRICiU4xjLJAMTxYoTNgoac3e+bSmrODLsU65iG4/1 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 20:SfcKTNeJHivHvG1InjAmlPBEt1YQg5SOg5Whh11qTQdfBh2YeumngtwazgiQNfEihvoMx6Bf/VLHJPSD7Q4yJTmf5Zf2lmQCXYaaccbiO7kJlwZVzToDX5zYVenFIXyove4zSohfvMWbpv9IGbvT02P9hAaL9sQFEFx5bkjdGEM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 17:49:23.9115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3749c493-db08-4420-75f5-08d55e9bcfcd 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 3/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 | 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 9b12774..3e31b89 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 29cafa4..b141710 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 7ea4023..cf2f84c 100644 --- a/block/io.c +++ b/block/io.c @@ -1424,7 +1424,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; @@ -1514,8 +1514,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; @@ -1593,6 +1593,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, @@ -1693,6 +1696,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. @@ -1822,6 +1828,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; }