From patchwork Fri Dec 17 16:46:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12685297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B6A71C433EF for ; Fri, 17 Dec 2021 16:51:03 +0000 (UTC) Received: from localhost ([::1]:53086 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myGRi-0007jR-NA for qemu-devel@archiver.kernel.org; Fri, 17 Dec 2021 11:51:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myGO0-0002gy-P9; Fri, 17 Dec 2021 11:47:12 -0500 Received: from [2a01:111:f400:7d00::707] (port=6433 helo=EUR05-VI1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myGNy-0008DM-MG; Fri, 17 Dec 2021 11:47:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RAcsuBIwSKLHH0xO4m+PdSgPfERN4gYl0f5AyfaZYmJA25m8rafZM99f6kCCtIwNGHLv+OlIsrTbSaKCLG488WAANJCdYkRMHZLc3iPfFLdTBtsv8IbBzakfs9XKLPu4TNKDeG9Tp4Gu2E6ueDHldS3BO7gBgGuXevR8t6Jh7FyRL+GgmzymGButGCDnAc5YCpO+A9uiE78ca3GClBI/rVXSKE+4/0C24xrjvK21Lc0JRuDiq6zkNx/Q3pF/EYgYuyMuDUavJe9fwNxH0kRrH4Wsc/v9jbGVn0oKDiR1rpJnLfXM/CIemDztrSxhNTfhy8AfdxUscXcwrCmeV/igFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=M3x+CA3xoAUw6+jkjktlDCfdR0tit9aImCsaojfiMMA=; b=j9oKtmdUfPtr+81uAkhPGhuLy60AjsSt4qRW2nGeahJkSE5IS9G8cKdzQjrcsLzffH4n0qWu6JmJvxbFdWz1HhIsfA/yjsjrMwMuciV9kP33OLOkYrNSWl5tnY4NvHfl0WqIy2rDyPWx39OwmM9moqsJ/13f8wwsNz06GCvEik/EjAQsjjsSJyEjPL98yFN5XFRO3/VBlMcVKzrMvx393Lv1TZFBCGRhH4KfCM8IBYwL7411uHmOD3OFYbY5yRP/oaiHvFlEhskYrreDm5yt6uMf/nnToa+xjcp8vrkxikG+7WN/W/ps6slO3Pg9eNzQ9DZvMmEsFpBjVhdfI6lhvQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M3x+CA3xoAUw6+jkjktlDCfdR0tit9aImCsaojfiMMA=; b=ruvvbIN6KSUBOzbfTkqXzqONfXWRzFxokUq5AQV1/jMcqBjGWtOLukd8H4+xL6+iNtsVA9dW8/tPNvk8q6cTm4TGLfwI3bPTsI6Qe076SDgUNZcucjcF9Ug8Gf2MgmSbQIOuZz0g2WANznD39jhoY7pUuEiIBGWm7nWb30sJHyU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM0PR08MB3362.eurprd08.prod.outlook.com (2603:10a6:208:dc::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.15; Fri, 17 Dec 2021 16:47:03 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::2078:5a2:1898:d83a]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::2078:5a2:1898:d83a%7]) with mapi id 15.20.4669.024; Fri, 17 Dec 2021 16:47:03 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, pl@kamp.de Subject: [PATCH v2 1/2] iotests: Test qemu-img convert of zeroed data cluster Date: Fri, 17 Dec 2021 17:46:53 +0100 Message-Id: <20211217164654.1184218-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211217164654.1184218-1-vsementsov@virtuozzo.com> References: <20211217164654.1184218-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0192.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::17) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS8PR04CA0192.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Fri, 17 Dec 2021 16:47:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f25e979-dfa7-4c6e-78c3-08d9c17cda60 X-MS-TrafficTypeDiagnostic: AM0PR08MB3362:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mm+qvIrm7OblS5jDNjy7hTqxbZjwMDJzo0GEitXTGu9HnhC2mHQ+Db5Yij93Arw+FdbNLfHwu6Dy+iX8FDr/oAgp+SGx9hUqs8aQDPPbIam2yLfZ4OFS2I+73E6tteqiw8HnIEO+A9h+bqitaPYZw3GeQmL6TleHk9SK2smf5FD2m6zo6YH77UHJVYN9JZ1eWZYTVUpUFJ5Q1p44rUjE75DyiNaZi8d1i7y65p6jEgRWGcGWXkyHuFNRb56SGwctM8Kn9LhZ4cRvxJNj0ogNkDJcxh+k3cHnewTWjnID8Ck4KaSTCon03a5cYjd1jg2I6n/Pm8JcilVm5fb+l2nzXWZfHO2KJhq8COwmKqRyv4r+C+hj8PXxr7noH6qwhfIcTtVMl1Vrh770etlmquwSvn18Std8wLlMZ26yk1CUZtCCo42OOWKDthmnKR6348qoq6sm3sQLFYLipf11szyj9vXkHyEaeIR92UahWY5u8UNd5GtuxwxDG161nAjmlRdnqNHM0PzBeMc40TaVRV7lVtvKyMs6KRHfE2uUUYZ3qkHvNX5Al8MUg59lOf6WNf6bLSe3Wzj5WeM66pWFC1xTk1Nx0Rv5rjq+8Ha2BrbwZEvVuZEsqVUHH6aeLzbZVZFamWjYFo5cthXhtUTFxOOmK36Sb1zvAnUk+KnM4o4wxnIDQuozx6wcRmOa7/SURYRRsY1VdElnFsgceUt5QUuQkkpetctSlwANNqO0RS+Qpx8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(86362001)(38100700002)(956004)(38350700002)(508600001)(2616005)(6486002)(6666004)(36756003)(8676002)(26005)(5660300002)(6506007)(186003)(8936002)(4326008)(52116002)(6916009)(1076003)(6512007)(2906002)(316002)(66556008)(83380400001)(66476007)(66946007)(21314003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wTbb5u7BdGFYEzTUd4iMoOmAeC5Srg8luOhPOlbWIOBmbFwGPso475yBbhEUEOx11zOx5F8HZG6aghe8SUJFV687+Krf4VYuU/T+dPnmey+d0/Ur73Md+XlRyLn1Y0knhpErloR8MzL9hB9M30SLytJAciWGWgUFEgQTHpcGP/XoriBTKwgS5B4LY66gq0WCvzdaHdriDXIIS9+QuGwGwMWZI8S7f1Sc+2kpRO4gvZO3vAjPhrYm9P5J0XcmGPSdZG0MZH77xYggXS6XKv3A7RXjNA5fTLQRiEhO0t25V4fZenZ3ylPBF8wCaZ18zYCCUvETCfX11JzZQMX81Ki10SHyHjUCPc0lz70m8IcSW3goBDasiyaR59SYFguEJjKC2nCedGqit3MuUuYAEXgQV+5RnTckpe8uwVPQjD9WEodYMm7nDP8J9ZDQdSDAeAtyKPc+pflN0huLOFkNycP2wSVFDM/JnF64pE0QzPObFpzeFcY4S5yK+ecqVt4bRDOTkwBdDHsRUQfjRyNoT5y16Ojg8XwN5lpzxjBlVCSoNHn71+K6a52iPvIztnAWPU1J3JJNZ+WbrxLAJ0jWlhxFuTif7gChNPEgemSo50BG7kkqnUsmsHV2kSJOIsNztFwZvmz4FhQkWxB9AnqzAJ3kbUaVUX2ZPiNlos6WIHVqJMvwuInmuG4eyE2PJYFau4PUI8p5GcDXkH/WOGD9Lzd9+Z67qUDA4s+KLwag8lfWUioEXWhE1mo7rZeNtfB76almFHcKc6o/9oI4R5UG8fcZH6Q3jGDQ7Y0XM3yKkq3/zw0cq7fLvmCysQXSmf1N91ViP2SaAQ0HIUmfHamvEHz1+PHzp3J26K1fUadGiYgaP0Zx9gr7aR7TN/z4QDeROHTL6cqHIYaQrsTAHpIf/xyzVrV2zaKZ9uF6iDFL7nFjTb9jhKWfh9uShjW+DKeTNuEtLwSA80ykiW7k1tccsxxSevDwLFMOgV38ghAutOdXynjs6RVX/f6znYyunKjnPpdbRIGDg60OcPtfCmAVEMZxxUsqXfGQPCs3WE9EPAYjtATfjumYY4HLDLM5wPgOnZoV0GzhVIrPr5iQIjeYFDMzwB8G7Xz1/M259mGS1t8pwDZC3YMznAp5NBL0sielNseoSWj5+ZlN52UfHkdqIthu95VQW51Snvf8IArQNut92uxRjTY1BCiOUTRCJPz72CM7gY15vdjppS/q2MEXGSl+C5h9y8lv2t8x6pSQVOsSUlhS00KiUgM/ynQewh8NfWZ1L/qLT2VSM+fOnspQDw1S0ZjqQU4H9ASxvceD+9dcItCixD6aUhYfmFReMdJIeT/0rGupaMV+O/ZJ6lm8xi8W/lUvDhyl+VVffiWlbMPZHIyGdBOXvAQdd2PN7uk0ibzPbUX859Xpa+iiR6TlGLrMDlxerDc5Z+HldYsHsKQHEBwSME3fKHeIlrgmv41nLPtQOcle9cSnFA0bjIwgZNRsB7c9ZP/l9d5IHV7z5X/wSWijA8qL81ep8CFIikTwHGIfaItynqk6BJbcXWY52SKItOOq5+dOcakrTEF5+XVL8Rfq9EVg2VBDMv45OM9/OnBJkyDGcdNhK7SwZfEDpA9rjyR8r/zdak/eQDB3j1Vup5ZdOqo0+7m8s08oADSFhD7kCzcj15zWgE2bufIfOar4zukU3gWqjZ/5e4CjQlgoru0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f25e979-dfa7-4c6e-78c3-08d9c17cda60 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2021 16:47:03.5448 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HL+Wga5r0a2uqDB2yCCvjappDjdAtjROB1Fwuty74GrKqYywuZSmx6dlEqST7+ETcRh+AWX3Sh5+6I60Sp/yW3Pe+mWxIdbNPmalT3bn+sE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3362 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a01:111:f400:7d00::707 (failed) Received-SPF: pass client-ip=2a01:111:f400:7d00::707; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Kevin Wolf This demonstrates what happens when the block status changes in sub-min_sparse granularity, but all of the parts are zeroed out. The alignment logic in is_allocated_sectors() prevents that the target image remains fully sparse as expected, but turns it into a data cluster of explicit zeros. Signed-off-by: Kevin Wolf Signed-off-by: Vladimir Sementsov-Ogievskiy --- tests/qemu-iotests/122 | 1 + tests/qemu-iotests/122.out | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122 index efb260d822..be0f6b79e5 100755 --- a/tests/qemu-iotests/122 +++ b/tests/qemu-iotests/122 @@ -251,6 +251,7 @@ $QEMU_IO -c "write -P 0 0 64k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_test $QEMU_IO -c "write 0 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir $QEMU_IO -c "write 8k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir $QEMU_IO -c "write 17k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir +$QEMU_IO -c "write -P 0 65k 1k" "$TEST_IMG" 2>&1 | _filter_qemu_io | _filter_testdir for min_sparse in 4k 8k; do echo diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out index 8fbdac2b39..69b8e8b803 100644 --- a/tests/qemu-iotests/122.out +++ b/tests/qemu-iotests/122.out @@ -192,6 +192,8 @@ wrote 1024/1024 bytes at offset 8192 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 1024/1024 bytes at offset 17408 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1024/1024 bytes at offset 66560 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) convert -S 4k [{ "start": 0, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, @@ -199,7 +201,9 @@ convert -S 4k { "start": 8192, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, { "start": 12288, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false}, { "start": 16384, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 20480, "length": 67088384, "depth": 0, "present": false, "zero": true, "data": false}] +{ "start": 20480, "length": 46080, "depth": 0, "present": false, "zero": true, "data": false}, +{ "start": 66560, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, +{ "start": 67584, "length": 67041280, "depth": 0, "present": false, "zero": true, "data": false}] convert -c -S 4k [{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true}, @@ -211,7 +215,9 @@ convert -c -S 4k convert -S 8k [{ "start": 0, "length": 24576, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 24576, "length": 67084288, "depth": 0, "present": false, "zero": true, "data": false}] +{ "start": 24576, "length": 41984, "depth": 0, "present": false, "zero": true, "data": false}, +{ "start": 66560, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, +{ "start": 67584, "length": 67041280, "depth": 0, "present": false, "zero": true, "data": false}] convert -c -S 8k [{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true}, From patchwork Fri Dec 17 16:46:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 12685291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF224C433EF for ; Fri, 17 Dec 2021 16:48:59 +0000 (UTC) Received: from localhost ([::1]:48234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1myGPi-0004Qv-JA for qemu-devel@archiver.kernel.org; Fri, 17 Dec 2021 11:48:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myGNy-0002ca-8P; Fri, 17 Dec 2021 11:47:10 -0500 Received: from mail-eopbgr40121.outbound.protection.outlook.com ([40.107.4.121]:35531 helo=EUR03-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1myGNv-0008DQ-Ob; Fri, 17 Dec 2021 11:47:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ldz8ljwymoppWl0NrZweeHLuSgrOOSyIx1p+ujlshWl3NM7kXqgy4mVD/0QJmpyaF8XE84vmv/B0lwmb+H0cSe8VGVbYFW7xgyE62V9/0l2nvVFKOKv3H4YKZBdYfLlcbKr/55Y8+UnWHWlPolJqzVHRnTFRAlt2fzhAcm/S4XkZbANUrpxmM4sMXx8c3J2M9XySMVMiavjp1gDWx6/MXK2pFwcnXC12U3WPlgcMu8hV1I4JV/2tD0Jbs3VemsExv5mwbZU+oyL1mJOPicDkBHf7FYidn1VX3fwZp2O95HOiCvDqbKxsdS/8ytU/L1gM3UVEewiXouXyQWH32jlRsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4miMG3Oab9hhFZOAYw1MKZFIkoUiB2FyO1PtzuUDtVg=; b=Jqe54PnAv8haSIxxZwshWgvwMECAtCM0Wkjvx6xv7xpi23AbTm6hsYM80sIC40yqFTNqOlPNHAxFejR2uaZ96s58LQwVYj4avjALk4GbO2gVap8SNh/4GfDOXIvBiv7U1MRz4ZqE3wzJoxhCf9y+QGhqoBbpPH3YPvdvF61IK/nKeLP4GBsiwu2VpeNXRm3I2aAYKzwWS4l6VC71B0SzBGPvV7saHOg+MPxG01Hg5AGCVju3b2c8qj9jUiUVDB6eG/h7+RStVBBoTVOrO7Cg3F3Eo4xgxcg/3RAR3QUD9/QtyxanrLIK/LZgXs+yae4QwcPVdjg9w+hYnqJKDFGl2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4miMG3Oab9hhFZOAYw1MKZFIkoUiB2FyO1PtzuUDtVg=; b=Q/txW1KyedLsEqVeZImvU6WLj81AHXnePiVvfXFJDz51zZNij7Jw+v2G/t1iAr10nsybnhZJVKPQi44mZXCAly+NQRcBT8bmm95PU2Mh6LNXiHGPL6EDDWuQQNkqENQb9j25LBuQDGfJYec51MY+C+nmpMah5QF6U4yFizpiIPs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=virtuozzo.com; Received: from AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) by AM0PR08MB3955.eurprd08.prod.outlook.com (2603:10a6:208:12d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4801.15; Fri, 17 Dec 2021 16:47:04 +0000 Received: from AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::2078:5a2:1898:d83a]) by AM9PR08MB6737.eurprd08.prod.outlook.com ([fe80::2078:5a2:1898:d83a%7]) with mapi id 15.20.4669.024; Fri, 17 Dec 2021 16:47:04 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, hreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, pl@kamp.de Subject: [PATCH v2 2/2] qemu-img: make is_allocated_sectors() more efficient Date: Fri, 17 Dec 2021 17:46:54 +0100 Message-Id: <20211217164654.1184218-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211217164654.1184218-1-vsementsov@virtuozzo.com> References: <20211217164654.1184218-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AS8PR04CA0192.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::17) To AM9PR08MB6737.eurprd08.prod.outlook.com (2603:10a6:20b:304::18) MIME-Version: 1.0 Received: from kvm.ch-qa.sw.ru (130.117.225.5) by AS8PR04CA0192.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Fri, 17 Dec 2021 16:47:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58d6fc3a-eb34-4a08-91de-08d9c17cdaa7 X-MS-TrafficTypeDiagnostic: AM0PR08MB3955:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d62JrLBVr6VHbfKym1A6KDOkmkvFnnoIxijIBQOpWULU8DgXBO7eq4VYn3PM73S9dyeTglUQJyC0bZDcm6np+h8qy5f8ggtzd8czMXTSt3LyNgQEI7+OcIOYP4QrnQtvQWHuDJcK6R5GVXKPG6V+oUBUX9wtG2YKTwq2AbDEkC/vOS/leHrxmotQohcT9V5obhmXSS6naK1Tj8Nq00/QZyF4o1jdfNGPGIpMrXlZCpnul3196HnEkhg9Holjm4KHdcjegdvjftX7ND2R7l7rMsIT/se3TmVBUw8pbCGpzT3hjsPsw1E0QqtIXdARDkzwA/houHroq7HKjr1jkGiqsJRfMP93pUMxKTE+y6wbvHPy7nUY2IHIHzG2gCOJFMm3j1Rp3OKUbgiwnK55gVv88ewDNH6J+4wh5KhAOIcdxE1dFswrmowMpBN8Gdxs5cr7ZGX9FAFwyVKwXddhKpeAlLYoNnp5nyNG9spu0VxnL8QNyjagI+SctxFIsNRqwd+UH67MUucf+Yf3bGSzQ/THbKozq7v/lOHyZ7CrylJ25aPnoJ1w2N0bJjbfnuP2OF37HPjVxyjYv7rX36Feago54GXyiFyWMnIKzKVzwajJEJ3Z8JB12kTFOfg4QWiIO3+K5Q/kxQgSN7NlHuwK9gDBXnOof/jPoVXwPcmgG6uo3NZpDmk1qGRIk4dGXg6xr+cQqlIRyPfkyT70YwB5lTWljQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR08MB6737.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(6486002)(36756003)(38350700002)(26005)(6916009)(38100700002)(8676002)(52116002)(6506007)(508600001)(8936002)(2906002)(5660300002)(316002)(186003)(86362001)(1076003)(6666004)(66476007)(2616005)(66556008)(66946007)(6512007)(83380400001)(956004)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rwFtZohm7ajjYMbmkHjqJhsLjKxba4CSl8dzvbvhKHHY65P0arnfbLfJlCRd8Cx4ToFooDhQKd2jk4AdOR/HlM7XFdsniogVMWAjq5B1JJsvNIXLjUeAiJDgDMPT6t4lLRgXZxiMns+oBADuDpV7DfZjSD9DNA311DL4l24KyovC4MTF1kSNFQTlT2FDcDB3XjkneUP0X3byjSbFwRW/a9TN7MgOaN7XoeDReMUQFcb12ihGQDhNtDk4ZUJt4CDZOJsLAxprd6hLfhhriP/X3NNUqbgiSY3/D1sxct+6KZTJmr/2M3ehlT43gsg6+Mi7lFF7ktyBNE7qK01/fEED9BDKoFAokesdkD5IZOGvnuoEM7eFtbei6LTMvKz5arsrnqwMoMeTuHax3TSWlutg4T3JPD3mA/7xoaYR7xuG9V7eG2LqIm1HA95fMs6w7dD17usr9CmIoNixtyVFHLgcFKQqohI9KLbghrFzODAS1rJgm1P10iO5bm/L70LNOAyyWa+YnNDzOoDLYwIFny/Cu5ERVldiFZoMlS3uVctsR/Qix2vvqz6B14ve/emaxOWCctNaXn9s9kty8VgUlMJx1uGwgxw0vj2cAbeE1Hyb+jfdNWEIYBGy7yMv38nQ3TS9bndmx85GzJ0+dy4aBLUdkWgG3DsdBIrl1B2/jzFWH5Pq/qn3XB1j4BCr86M8fXwQKjqXLmzCNcJ1JVxRVFCPVXIHYA9m6TogAewjUfVLINb2BWCrISy+El1pRrB2f7j0G8NIYzK6eCr/FAI1P6qjLmq8xTuqCHe0MiRT7/SfE2nWDsJYG1tuOEfoca5e5VpCwx/RzLHqNSielvhUzGp8FjXbeh8nnudz4WgLpBCLwVa/N3rBfMIEJF1S6xrGwCaa77Uki5ZKi1WcZcUq6VE+/ghOv+M/tGPbz58kv4itWsWDxtOPk/AVxAHzL+vb0cgcxcL116wW5yAM/Kr1moftExlZGeKTf5T9ZjocBTQXPE81m78eUEotlhwWp1hjQ/fQLu2UMRAdq6dRYYMbg7uuC87CPYf0l6uiNAVs9+3AiL53xLBi/srcBBH7RsiwAnOySwB8fYhhfxMg8CTUxWsSYp88A1ogDKw+qGGaKMY4d9ToFy+FmooJP4H3vM/VNJJVt0VMJYwxGPdE60Iq44IUSd5ir5qddCMHsg2Xj8stFyQXKLWmBvkE/Qtqf4uza36wLZ0vDyMhZpWq79G7tCN7rN8jBkVVPvg70ToDfKxhpf3fcNFcY4MhPBNX5G14YVT3cEGVQYymJ33EChRTk1xbxjdNWXP5yVbQIBKWaKYAJ7DrFMHHBOmq14JpCTbYywePS70UzBO8FL+Dc6LHxDkAra/XzxeNg7l0q7ALudGeaaU+RMY/1Y8oe6a8dJpV1lOi6tv6vY948jjJIbggWK8ngAxF7zANRYWOrRcj+H1W7zpDpC2rBrz9SpxibD3wVd+nccmayIP99BafWWVAxcpWGc86yaBDi3hFXEJN8j89b/UyBh/IqI1kbXjsB7EI2KbYCOE7kdpOH3aYfAATCqnJ/Zz6gKzxVrH8wOzsXFYhfGhOfu4rwBOQyXY6xhO+a7Ka82LFRwCWlGDBKRlFEsyER5BGpHDcNMQNubOLcdLBSLe6VubXyxSuKnrAQec86bdEqXXzySc8WEsqwpafxluhgguDxDKJ2Wy/5Cq7m5/6Py4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58d6fc3a-eb34-4a08-91de-08d9c17cdaa7 X-MS-Exchange-CrossTenant-AuthSource: AM9PR08MB6737.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2021 16:47:03.9699 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: EOpGZ5LjMikGNb/X+2SoYv4VpSsh1F8BfuWkTi3SkP+v0WeLc6LcifKZy40fQlfjPVlcT2A9bDcL2nMzIWlw1qu2fvWPVLE8bqm5O147z3g= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3955 Received-SPF: pass client-ip=40.107.4.121; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Consider the case when the whole buffer is zero and end is unaligned. If i <= tail, we return 1 and do one unaligned WRITE, RMW happens. If i > tail, we do on aligned WRITE_ZERO (or skip if target is zeroed) and again one unaligned WRITE, RMW happens. Let's do better: don't fragment the whole-zero buffer and report it as ZERO: in case of zeroed target we just do nothing and avoid RMW. If target is not zeroes, one unaligned WRITE_ZERO should not be much worse than one unaligned WRITE. Signed-off-by: Vladimir Sementsov-Ogievskiy --- qemu-img.c | 23 +++++++++++++++++++---- tests/qemu-iotests/122.out | 8 ++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index f036a1d428..d7ddfcc528 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1171,19 +1171,34 @@ static int is_allocated_sectors(const uint8_t *buf, int n, int *pnum, } } + if (i == n) { + /* + * The whole buf is the same. + * No reason to split it into chunks, so return now. + */ + *pnum = i; + return !is_zero; + } + tail = (sector_num + i) & (alignment - 1); if (tail) { if (is_zero && i <= tail) { - /* treat unallocated areas which only consist - * of a small tail as allocated. */ + /* + * For sure next sector after i is data, and it will rewrite this + * tail anyway due to RMW. So, let's just write data now. + */ is_zero = false; } if (!is_zero) { - /* align up end offset of allocated areas. */ + /* If possible, align up end offset of allocated areas. */ i += alignment - tail; i = MIN(i, n); } else { - /* align down end offset of zero areas. */ + /* + * For sure next sector after i is data, and it will rewrite this + * tail anyway due to RMW. Better is avoid RMW and write zeroes up + * to aligned bound. + */ i -= tail; } } diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out index 69b8e8b803..e18766e167 100644 --- a/tests/qemu-iotests/122.out +++ b/tests/qemu-iotests/122.out @@ -201,9 +201,7 @@ convert -S 4k { "start": 8192, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, { "start": 12288, "length": 4096, "depth": 0, "present": false, "zero": true, "data": false}, { "start": 16384, "length": 4096, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 20480, "length": 46080, "depth": 0, "present": false, "zero": true, "data": false}, -{ "start": 66560, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 67584, "length": 67041280, "depth": 0, "present": false, "zero": true, "data": false}] +{ "start": 20480, "length": 67088384, "depth": 0, "present": false, "zero": true, "data": false}] convert -c -S 4k [{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true}, @@ -215,9 +213,7 @@ convert -c -S 4k convert -S 8k [{ "start": 0, "length": 24576, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 24576, "length": 41984, "depth": 0, "present": false, "zero": true, "data": false}, -{ "start": 66560, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true, "offset": OFFSET}, -{ "start": 67584, "length": 67041280, "depth": 0, "present": false, "zero": true, "data": false}] +{ "start": 24576, "length": 67084288, "depth": 0, "present": false, "zero": true, "data": false}] convert -c -S 8k [{ "start": 0, "length": 1024, "depth": 0, "present": true, "zero": false, "data": true},