From patchwork Tue Jan 16 13:04:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10166811 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 2CDF060325 for ; Tue, 16 Jan 2018 13:06:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1DE3228446 for ; Tue, 16 Jan 2018 13:06:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E90628474; Tue, 16 Jan 2018 13:06:50 +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 1098E28446 for ; Tue, 16 Jan 2018 13:06:47 +0000 (UTC) Received: from localhost ([::1]:35111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebQww-0003yx-QA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Jan 2018 08:06:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebQvM-0002dD-4W for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebQvH-0006Tm-QW for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:08 -0500 Received: from mail-ve1eur01on0099.outbound.protection.outlook.com ([104.47.1.99]:39168 helo=EUR01-VE1-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 1ebQvH-0006T2-AD; Tue, 16 Jan 2018 08:05:03 -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=XYMqFE+C4N6qzOZVxEN6xBLYj144mD84WMjC5J0sLpnP027xBzEO/0Ihmm/mhULHhcimQUGGE3bHQWwUyv9Kd6bdbZlT6+qhVbnglB1jEa7ehfvwEMPLNIRx80D5UD9ENSFCnqna1yjiAgSPjVOFknSG77pxr5j1B5sXQclSaoU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Tue, 16 Jan 2018 13:05:00 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 16:04:24 +0300 Message-Id: <1516107870-8110-4-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P190CA0006.EURP190.PROD.OUTLOOK.COM (2603:10a6:3:bc::16) To VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 337079e4-9c4a-4d9f-1b59-08d55ce1c0b2 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB2000; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 3:DcTta+oGjcAsATPbes6FSB0o3qz3QxYz96kuBGHReIqoI/LIcw3oTwTCeCjn1kFZa6UmEIvCm1X5zYyU3BUooplSo0jI8tU3bT77Nj8AC5/v1Qcumm9+sDZl6WxbKy4OtqWVRdLzHTqSqUR0D+TNOQW3A7tNm38nD/CSfWSNCN/fQ0YHjSr6ZiIcS3xE8sjD5QNwInWHo9wR9BHy5emPBBpwYzUSo7STpKoXGtiIsJcSQmRJe5XhGDLF6SWzrtcU; 25:OIgSlqCaYf9Wj9luGDMtCwIj1WmeuZw7vH9YXHjuCGvPqXQ1+SEb++wP4zVVG/t8BXxh8IeHu0Oh58cav7O4mMJetWLLFmS0LGeD54OdV/eVKru5rv4KHmQk4aPS79uv1jnlGYAmbM3inVW4ay5eeUz3XoDLJcqedTUxh4wXdL+kGM4820iVcHBZq725CuzGm8bYwEVVNa8g+qWua790oa9eFL3loUnRS1rl1BlOIgyQCWghCpriqKOy4rhZslAQAuTIYKgm/eGoaNMtMdKxhSiqs0BtlmyxJUHjESEN36L5GVfOC0x/4pLexqtkCkZVczFO6umncCJhFzxHG0n2wA==; 31:yjIF5JyZyz8JDaULgA9ebPU9/qD/BLhTBX+q/MZna19e7PRBp/suQRu1YO/buq5J4/Fr53L1+llxPAY5w81wHYiwOWtQ+y0cQzHgCvDfxfacLE3wVU/cw6ADQnkl6KIjofAUG7jVTugrAugQnhR1sFXujbBy7wfascyCA4+doitQjZjJSD/R0sXcx2T2frfTSCUVMIdGVPjp7BmZMx6ekbP+K+FjkfqGui9XCYBEMrw= X-MS-TrafficTypeDiagnostic: VI1PR0801MB2000: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:+t7ZxCjT/EpsCdLuHsi2CoVkwPPegZWVrSYMRM2Xw7aqBl4wrZEogkwkN70QlafSGypv8lRgi10sO73Utp9y+kIKd6hbpEYwMoatbelUAp4v4hd5YplmpA1uTZPN3OULUtw6mc7LA2yHoowy6LlZv1+uXulli59UuhW3niYxJ4dqYPk4R+tk1xQd6BzgS+MRh7vFkAoOjEYbYcmym0fzBY3Q3RnAInJ0nDrqCPqN0ZcJMpD6GaQHFC+cIFjHCuV689SBxBACNFFY9ZBiwP/KuKWmQGAoPhw1mdOXJda4/IRejcVLLZnSfzHiDLPjaFN8DYsCbqplG3FmcKY8WuVi+HOu+abxJEjHPZX+Z+VzSJGuFInUSCXJBkAOQ4lWIMOl2pOQk2uL10I1mWj//y2ZT0oVAybtoR5chEOgF9nQ4lg=; 4:L9EcoPPmUfEhEtm6YyKZIpHsxaVQMcJ3PQbwiefcyE0skJVmJahYWWHlb4eXqe0sz59HMur9E2tloJc6aaDd3x1AYYUXKwMf4hV8ajwDnYtEcT2mFISQpvulZ7mH6Olu+domMJp7ApZWW1MQU4nooaYTkP8AUm4p/CFZWZdgXZkxJfQGthIpuKoZmqAjFgX47ktbfK0726ZxV9vXFnHqfsyi7b3pniui49ILBiqxrjNxvf3JgBFOEiGSYzZ6tJgKtDeMOTlpc8CFw2XOXY2ehA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231023)(944501161)(10201501046)(6041268)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR0801MB2000; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0801MB2000; X-Forefront-PRVS: 0554B1F54F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(396003)(366004)(39380400002)(376002)(39840400004)(189003)(199004)(105586002)(2906002)(48376002)(6916009)(2950100002)(5660300001)(53416004)(66066001)(6512007)(53936002)(26005)(50466002)(47776003)(16526018)(6666003)(2351001)(478600001)(36756003)(106356001)(2361001)(69596002)(51416003)(305945005)(68736007)(4326008)(8936002)(81166006)(386003)(52116002)(3846002)(25786009)(8676002)(81156014)(59450400001)(6486002)(50226002)(76176011)(6116002)(6506007)(97736004)(316002)(16586007)(86362001)(107886003)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB2000; 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; VI1PR0801MB2000; 23:GM2znBX25GY8dOpCtX7bMGipZRiimmTD9A9vJBT?= =?us-ascii?Q?rXJNzCzkmD6+4ae/xOMcW6uNb+eYA+eadOoFzNkgmUY0AU4m+McFP0pBbOU+?= =?us-ascii?Q?kSM8rXa9KlaL//wVr1/hCu6ESIq8NwlcyvnslQRyFBd3wxgFO/l2CaebJ8u7?= =?us-ascii?Q?1C+XaLFdM2BHwt8QhVFSp+ckh639bG57bjuOPP3N8Wmpt1175XgCvDui+r1B?= =?us-ascii?Q?TDpj6CtryQO2CivsQm2O6nBsZrHFfU1PllETXYNW45e8p7OkhOoiM7YfXtXc?= =?us-ascii?Q?4GCsmgfchr5Gj3U35aycaBTKtaN9YlKlk4O2ECqysQhg4sGE/ngXp7rnhAzN?= =?us-ascii?Q?+qmJA7urJOFKwQMgP2iKlE4xlRoSFTdXZ3RQpW5Fm/Nq0MNz8nNchRXMjRrD?= =?us-ascii?Q?mK95LNJwbHoyEmMp185BaEodQ2y/JhkbdrA3nhi02CxsG6XCeirpZlPKUpfu?= =?us-ascii?Q?VdaZZrgNqm9fH5Zvsx61NTt5Y/ICd2WPIBJ/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tz40uJKqnomVPH0isn2V710254EjA+VqC+lySM6aFyvDJfvCaRiXEiONcIC04TgjE9GYFO/BoLaKEOuYqR8qMysrFL+mZbFUJsbTNqlapIzAp2OLRPMwVwZd+YwWHAojdpZ5YVimAITo311L34XnkAVmfNyDE7nDbH+lL2Z3p+k7UM0daKJ8a2GgGRPkYGwu2w+Wt0vExYqkqPwB8hphwZXNzSryN0=; 5:Ss+JN/TDh6dSHA8ak5VMybYqSjt2hz1ouR2Yrt5SiHEsIhzv1P1J0bX6X+AnxsfKz2GBcYjbrpvepNIh7IdmHAmYqZdmYEC29Gm+k7G+mtoF8wrpOrVvBdvVW3KsEsL10vqdfi/VA6EO+TFn0H5VLvDPcTGlcCxTPgzky5VTrPo=; 24:sQIoW5rQC2zWFVNqVnTjYHKRYVJrPsw4a3bQjn/huWbhWSxxotdYQh7S0r+nOgghFhjLvGlPjO+qojMXZGHQI0ExhloILd7qq7dfknsz4pQ=; 7:4RnU2qSJnkZeX4FHCEGT4lKR6Tobo6MA/FD7Syr7FmxVozN353NeswfFtvs+HlXceZJRfrRl4qwop8fYZa2qJRvHOXnQmbK65q1z6Lo3h81xJc067IOETYHJo7+xH5mlmOAVHwH46hbj7m28a0ZLMv/JzV8596v9gIoUrtMgv4wd777NjkCULSY7wJqL9oiYzOOfE2iLUZjRep+ycm2UrWtkmKxWXsLmLkqdZ8FPRzNs+CC5gwLRSWmYw9edhg0T SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:1yzleaDTITHhaqCBRk7s2Wkhy9GQ88XZmGX+TDUngbnl2wNhy4n82IGuiUrmYodMJOJc7J0Z2SU6F+gXeDV1dXsoYzb3h9gSLLA5cP8RqdYGKjAan3eSZh9OFtYQIyuSO5lHnQ0nFsNeipt1dllbpwCFVvhadQj+z6FGyMF4OQM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2018 13:05:00.6056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 337079e4-9c4a-4d9f-1b59-08d55ce1c0b2 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2000 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.99 Subject: [Qemu-devel] [PATCH v6 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; }