From patchwork Thu Jun 1 15:14:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9759863 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 DE7CE60390 for ; Thu, 1 Jun 2017 15:23:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC177284F8 for ; Thu, 1 Jun 2017 15:23:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0D46284FF; Thu, 1 Jun 2017 15:23:06 +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 E47F9284F8 for ; Thu, 1 Jun 2017 15:22:55 +0000 (UTC) Received: from localhost ([::1]:45208 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRw6-0005hD-Nx for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Jun 2017 11:22:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRob-0000E9-1W for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRoX-0004fR-Q7 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:09 -0400 Received: from mail-eopbgr40095.outbound.protection.outlook.com ([40.107.4.95]:11349 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 1dGRoX-0004et-AD for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:05 -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=Ci8/9tP+OpplEg4I2wk7E3XYS7L/ebNRQ9iG6EMSOe4=; b=BoP5w2NixNR4SE2wyxVJZoUGEvvJvsaIvvtz/huAXNNG1Tje34EUyv6UU23RG8C7xusElmoah42/AvwvQ7iuhcYPP/3x0uzY7ENam7fRRH5IdWFXHYvflczDB8g6+ATZ819DcMaUrwp/3z/bx2S6dvfTPDlzMB9VDsu+WIlf9Dw= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Thu, 1 Jun 2017 15:15:02 +0000 From: Anton Nefedov To: Date: Thu, 1 Jun 2017 18:14:23 +0300 Message-ID: <1496330073-51338-6-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496330073-51338-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1496330073-51338-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0005.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::15) To VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0801MB1999: X-MS-Office365-Filtering-Correlation-Id: 096044d2-95ba-4ed3-f664-08d4a900fa77 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR0801MB1999; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 3:qY0qLMxa89VWal9sSMRmENm6mlb/PEu93xHzmIRxN+6dsm06wT+XdcWZP+xoXtpvp1JZIKmX9k/dJvnqU++hVKsuwO6hQowyBDkfaxEwgvvsF9cXLSJxQxgBKgESMh3NhTCpVEYwYng9+zfEDrsJCojoNZQbvwAVnDD4k4Firf6HVdGyW9oDNMyG078szi46wJ8ZOy873lV/2T5x9sQa24V3lMY7SBnxDVmkMYE8oyzUu7ueDck5k6CSmVx9LHEInidiMOZHUoX6efoa7ykYuAG6b5hW+ylo/0JJU1YqUylsJi+lSIwAcEEMKli95NVW0nCBg6UDZjUPUXxBO7PWIQ==; 25:evATzKen1f5T+XBk83PWfDzzuMrt+HOPlSyN/UW1ygNrAapvuj3eJtexcFzYWe1AEzzAl4gI4syCf+8Sk5H6boOZY9vOwwQudPVtK107JztbzehgoGLA+8haZFo8Kh848dbUjBjt10AAfjLaGKXFfKXze6niABH8ubDfi8lKzoqvLM2w9jRb+jPr2+PBxQyYwnEPdLlPk6mttw2Ou40tfw7xxwHRJuInYatey0AEtIy4S+L1spoo8BXg4TvttZfOGjXFkVjRnr5+eyWtQj0qA1SOy0aYFcVbzn+VzuRniZ9NeaUEdQYBlY+zamDNuYPlG55Bqeftrn0u9fWi0sJt0D8RcjHlrZS0FhSwEBiTQXShzMxxb8f4GmHugVO0x/uk8r+YujtTJ5NZPe4ZIxTQWREDNlHaGA7csEY6cy2Wdj2/GrRYPmQQW6Y+iDJy6nZgxH7lp2ESJhbKvSnKy2nPJwGnhhPmTvI6BHTMVRQzi/w= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 31:lUam7DcUPgIMhFa89VSBAW4/fBhoGPH46u7pYdGLvYasrhT6kHL2o2KiG+fTis4AgC9zEgBoStQCGWz3ccKK8cCYgAOTDnS8fWnaUIMwvuhe2VXu/PHB6UPLJUIb28VKTd3aMydaZsM4quOiA+JrQ0hsviQPQsiWSL7L/ZqIq4ZxC3a+00cePVKjCgm1vwmD3rKW+GmjbIkLn9s+iMgyJ7rvyTAbJitDwc+II/whsAU=; 20:G2dwba8eHb644tZ8aImvW/0n86KVhA5z5ZPqNniR29Jhm8shLKeEXfwoll1CBBtC3lBTI1dUAkFTjlLa1vua5mPnLpcLfEo16J4zd8ujuihHo17Co2Ag2YQ8gIy1chaAsQkM8IclgaCwv86H5SyNs0qnPC+T1CTGTSemJ0vQzVSaRP0JCViOecr3effXTM+R57NBJLUkco7EkmHlA5pY2/LaWInrXNUlSuRqIVSAShX1QblfLWDiONQRJvAb5AYse4U3iYS0hSQVKm0Kp6M6N3PPOtZ8t9dG/ZoQvnHvDG13LbWsyJfQe5Bf6gkRfpzNEs1Sh/USwwppvzKFKY7CX2WDpUk43ZrNQaJy46s8pX3STNRmp9CdDJPaeIddpSWeBPssdll+fLa6INHPzE2lf8mGdATi3/F1NPit5r88HJc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(20161123560025)(20161123558100)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0801MB1999; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0801MB1999; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1999; 4:eRFcF4axrfAzo10P2BQdcjmgoCufFfvJsLp7+r7f?= =?us-ascii?Q?DKUa2r0ZrBVVB58gsyI5z0IA21pd3lqP2Bo+63k4lJXpaPxJXyySCWhAYmUw?= =?us-ascii?Q?1tSUVw+JFGCk1Rrijnna7NH0TEa5Pl5u4DENPAJ/vB/9KwgDOsTFIA4u5X8W?= =?us-ascii?Q?/iqg94JUxFE0QDW0r3MW2KLhxvkiiOs9uRu9vZOuEH6IQQXyWBvykFJ2my/m?= =?us-ascii?Q?1yY+spm6t+mmVLHmtfNiJPHFwQTI0o/iTDnkVdZrCoKlLVeWLeRkgcpxun/h?= =?us-ascii?Q?J5rbiK4H4WLkMY+C7YUelj5hnkB0wu5vHAzEEa6qo3YXuvYbY+8rXK2THEip?= =?us-ascii?Q?5xUdb0ijl3pHODu9lIyLqtXJcbXY28kpzTP7Xxi95gmVcsloPmkA0EcXop+A?= =?us-ascii?Q?ZfD8konFkECww9NvHZV0LIzWUOsJ2PJLa3zadTRJHC1O7o/WWVAEm0NHc5E2?= =?us-ascii?Q?Zbqj2y7Pja5015KUOQG27v7ZEr++g7VE1DwR0YXwH15lJkV/LUw6UFtvSO/r?= =?us-ascii?Q?/gp3ryS9FjLNd0l8iO4oqrvVF+gdagf8k59QgCiIqvyhLEmHs4TbQyu0/WBt?= =?us-ascii?Q?QtjdcnmN0wrvW84vOFjGwxPFu39OR/YJV0tJTF4B3m/fhdPfvLnReJ4hO6AQ?= =?us-ascii?Q?DyrY23kv4vX5YCsG2zNfdhyuz7VMHzR4KpipUMRsdrMldUif11VBXgMLC5UC?= =?us-ascii?Q?9zEesFKol02CCow8EKgkxedfZK8p/SKSZ2awsefqEmGcPiGr0yjqCjkYmwCS?= =?us-ascii?Q?jFzvhmvad2hF32TriUJ1Mv8hVdsNBV3k6gTZ6ZxXsRir5I4Et3hDpHA2trZ9?= =?us-ascii?Q?DMleHcxw633hrgNHErIvb+rPAlDFuQRiNdlwbVyA6nnsQdQ0oUMmEIg8tTRS?= =?us-ascii?Q?RzsYiWOkoiy/aRmwhkO7k+kkRjlxtOGVSUeELgaEtaFeEnI5+DKJj3S+N0pw?= =?us-ascii?Q?oL3wj9n2KZzdY+I/CFXJcvQfVr2t54g+6HZleOGAA89EkFYjtZ/bZR493WLD?= =?us-ascii?Q?p280eDcjdcx1LsR6XjEuwnavxq1DFA2Rie+X/8T6XJ+5QR7Zna+UMVbcKy9v?= =?us-ascii?Q?uZC1utsCO/YDo/lBgxsFVLzPwFgJ2sT5tO8qIC+80MpDdcu5bF4lkvx9H4WQ?= =?us-ascii?Q?0onnwUCV6giUB41N5wyi+v6bSAXYa83d?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39830400002)(39450400003)(39400400002)(6916009)(6666003)(6486002)(7736002)(478600001)(5660300001)(305945005)(54906002)(53936002)(4326008)(6512007)(6506006)(2950100002)(110136004)(107886003)(3846002)(50226002)(8676002)(66066001)(42186005)(81166006)(38730400002)(25786009)(6116002)(76176999)(50986999)(47776003)(86362001)(5003940100001)(2906002)(2351001)(36756003)(48376002)(50466002)(33646002)(575784001)(53416004)(189998001)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1999; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1999; 23:v8zpNhQ0Ll+STfCwGdv9uhLiaxz9H9faOeJCOgE?= =?us-ascii?Q?Ec/f+RR2xFAgpyixBNLOpoRbOgNw9Qi8CeVkwSsnoZEwrlJPggFQF1NpQwcZ?= =?us-ascii?Q?0oLx6tVR6x+O4k3CCg+UkHuSpjhwMcGsQz0uSQ/jAKJRpwTTxE9q+e18wqff?= =?us-ascii?Q?vZ5i2XMXuZFxoCVh9+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TrR2ydP/Wwv6XS6HM5yG3KDMnMaIkbzpJ15LqQbF0HaKuFIKbPgMOu5xewvgOS/p/re4ZdLtpwz2XkIN0FFEiM4GL5JHGI2WSwbRyaWOg4CBspU6PQ50cVDyqKd; 24:tbsHVIXZy2jQ68IP9DEdGUxVKklhgVhuHrVsWdNLeHRjviwsEVQwXMbMo8JJGbM2l9AT+vlzAiJ/RZsxF3yNIsjmSLpneqn6eBJcOmMNAOA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 7:iZKfII8l6+IV2cNHCa5fjBlqjCNx7PpsL+x8JI7PmslBVv3JS3mDQOO7ffptMI3o4dW07lORdHygJ4smw7Qf4FMpsAjnjUcGA45IOe4moOx+Y6jjPz7GxdAB2rnON7GhRkvEJQcW6mjZY8zN0+k60t8FgUF8L+FX/f4AnfvaloOgzPokB+I3NjDkEIpUscepvOcGLWlQ7GjMQNLNPj9jXAj11Nw9NOJ/cEAiixm9kxT1cyMrPu1oTnLQbyf16tsyVtHPWPKx4QQOnNL8Eq9ZkBWEamJE2YWzMsSNXXuyUHWcI7cgGMU4/c8QabsGyOkSlGeCHGwi1ijOXvDg3WPLCA==; 20:aa17aq3Q5PTvF7ODyjyuMSqnp/7ediVluu1XuixtNJiZ195XUsJgbHwOXHbgqpQMtXj9tc2vH17cgQntNsVZeJRcdpW16qXG0KIF3lQIy797+3dygaRU4nc6kNedg2sZ44pQ97WWGoN9EjE4agQ/HmmMuyT4BRtEjAhuSCJgqaI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 15:15:02.4592 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1999 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.95 Subject: [Qemu-devel] [PATCH v2 05/15] qcow2: do not COW the empty areas 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 , den@virtuozzo.com, mreitz@redhat.com, "Denis V . Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP If COW area of the newly allocated cluster is zeroes, there is no reason to write zero sectors in perform_cow() again now as whole clusters are zeroed out in single chunks by handle_alloc_space(). Introduce QCowL2Meta field "reduced", since the existing fields (offset and nb_bytes) still has to keep other write requests from simultaneous writing in the area iotest 060: write to the discarded cluster does not trigger COW anymore. so, break on write_aio event instead, will work for the test (but write won't fail anymore, so update reference output) iotest 066: cluster-alignment areas that were not really COWed are now detected as zeroes, hence the initial write has to be exactly the same size for the maps to match performance tests: === qemu-io, results in seconds to complete (less is better) random write 4k to empty image, no backing HDD 64k cluster 128M over 128M image: 160 -> 160 ( x1 ) 128M over 2G image: 86 -> 84 ( x1 ) 128M over 8G image: 40 -> 29 ( x1.4 ) 1M cluster 32M over 8G image: 58 -> 23 ( x2.5 ) SSD 64k cluster 2G over 2G image: 71 -> 38 ( x1.9 ) 512M over 8G image: 85 -> 8 ( x10.6 ) 1M cluster 128M over 32G image: 314 -> 2 ( x157 ) - improvement grows bigger the bigger the cluster size, - first data portions to the fresh image benefit the most (more chance to hit an unallocated cluster) - SSD improvement is close to the IO length reduction rate (e.g. writing only 4k instead of 64k) gives theoretical x16 and practical x10 improvement) fio tests over xfs, empty image (cluster 64k), no backing, first megabytes of random writes: randwrite 4k, size=8g: HDD (io_size=128m) : 730 -> 1050 IOPS ( x1.45) SSD (io_size=512m) : 1500 -> 7000 IOPS ( x4.7 ) random writes io_size==image_size: randwrite 4k, size=2g io_size=2g: HDD : 200 IOPS (no difference) SSD : 7500 -> 9500 IOPS ( x1.3 ) sequential write: seqwrite 4k, size=4g, iodepth=4 SSD : 7000 -> 18000 IOPS ( x2.6 ) - numbers are similar to qemu-io tests, slightly less improvement (damped by fs?) Signed-off-by: Anton Nefedov Signed-off-by: Denis V. Lunev --- block/qcow2-cluster.c | 4 +++- block/qcow2.c | 32 ++++++++++++++++++++++++++++++-- block/qcow2.h | 4 ++++ tests/qemu-iotests/060 | 2 +- tests/qemu-iotests/060.out | 3 ++- tests/qemu-iotests/066 | 2 +- tests/qemu-iotests/066.out | 4 ++-- 7 files changed, 43 insertions(+), 8 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index d779ea1..ba8ce76 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -758,7 +758,7 @@ static int perform_cow(BlockDriverState *bs, QCowL2Meta *m, Qcow2COWRegion *r) BDRVQcow2State *s = bs->opaque; int ret; - if (r->nb_bytes == 0) { + if (r->nb_bytes == 0 || r->reduced) { return 0; } @@ -1267,10 +1267,12 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, .cow_start = { .offset = 0, .nb_bytes = offset_into_cluster(s, guest_offset), + .reduced = false, }, .cow_end = { .offset = nb_bytes, .nb_bytes = avail_bytes - nb_bytes, + .reduced = false, }, }; qemu_co_queue_init(&(*m)->dependent_requests); diff --git a/block/qcow2.c b/block/qcow2.c index cd5efba..067bb87 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -64,6 +64,9 @@ typedef struct { #define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA #define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 +static bool is_zero_sectors(BlockDriverState *bs, int64_t start, + uint32_t count); + static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename) { const QCowHeader *cow_header = (const void *)buf; @@ -1575,10 +1578,30 @@ fail: return ret; } +static void handle_cow_reduce(BlockDriverState *bs, QCowL2Meta *m) +{ + if (bs->encrypted) { + return; + } + if (!m->cow_start.reduced && m->cow_start.nb_bytes != 0 && + is_zero_sectors(bs, + (m->offset + m->cow_start.offset) >> BDRV_SECTOR_BITS, + m->cow_start.nb_bytes >> BDRV_SECTOR_BITS)) { + m->cow_start.reduced = true; + } + if (!m->cow_end.reduced && m->cow_end.nb_bytes != 0 && + is_zero_sectors(bs, + (m->offset + m->cow_end.offset) >> BDRV_SECTOR_BITS, + m->cow_end.nb_bytes >> BDRV_SECTOR_BITS)) { + m->cow_end.reduced = true; + } +} + static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) { BDRVQcow2State *s = bs->opaque; QCowL2Meta *m; + int ret; for (m = l2meta; m != NULL; m = m->next) { uint64_t bytes = m->nb_clusters << s->cluster_bits; @@ -1588,8 +1611,13 @@ static void handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) } /* try to alloc host space in one chunk for better locality */ - bdrv_co_pwrite_zeroes(bs->file, m->alloc_offset, bytes, - BDRV_REQ_ALLOCATE); + ret = bdrv_co_pwrite_zeroes(bs->file, m->alloc_offset, bytes, + BDRV_REQ_ALLOCATE); + if (ret != 0) { + continue; + } + + handle_cow_reduce(bs, m); } } diff --git a/block/qcow2.h b/block/qcow2.h index 1801dc3..ba15c08 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -305,6 +305,10 @@ typedef struct Qcow2COWRegion { /** Number of bytes to copy */ int nb_bytes; + + /** The region is filled with zeroes and does not require COW + */ + bool reduced; } Qcow2COWRegion; /** diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060 index 8e95c45..3a0f096 100755 --- a/tests/qemu-iotests/060 +++ b/tests/qemu-iotests/060 @@ -160,7 +160,7 @@ poke_file "$TEST_IMG" '131084' "\x00\x00" # 0x2000c # any unallocated cluster, leading to an attempt to overwrite the second L2 # table. Finally, resume the COW write and see it fail (but not crash). echo "open -o file.driver=blkdebug $TEST_IMG -break cow_read 0 +break write_aio 0 aio_write 0k 1k wait_break 0 write 64k 64k diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 3bc1461..d057aa1 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -107,7 +107,8 @@ qcow2: Marking image as corrupt: Preventing invalid write on metadata (overlaps blkdebug: Suspended request '0' write failed: Input/output error blkdebug: Resuming request '0' -aio_write failed: No medium found +wrote 1024/1024 bytes at offset 0 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) === Testing unallocated image header === diff --git a/tests/qemu-iotests/066 b/tests/qemu-iotests/066 index 8638217..3c216a1 100755 --- a/tests/qemu-iotests/066 +++ b/tests/qemu-iotests/066 @@ -71,7 +71,7 @@ echo _make_test_img $IMG_SIZE # Create data clusters (not aligned to an L2 table) -$QEMU_IO -c 'write -P 42 1M 256k' "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "write -P 42 $(((1024 + 32) * 1024)) 192k" "$TEST_IMG" | _filter_qemu_io orig_map=$($QEMU_IMG map --output=json "$TEST_IMG") # Convert the data clusters to preallocated zero clusters diff --git a/tests/qemu-iotests/066.out b/tests/qemu-iotests/066.out index 3d9da9b..093431e 100644 --- a/tests/qemu-iotests/066.out +++ b/tests/qemu-iotests/066.out @@ -19,8 +19,8 @@ Offset Length Mapped to File === Writing to preallocated zero clusters === Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67109376 -wrote 262144/262144 bytes at offset 1048576 -256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 196608/196608 bytes at offset 1081344 +192 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 262144/262144 bytes at offset 1048576 256 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 196608/196608 bytes at offset 1081344