From patchwork Sat May 14 04:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kiselev, Oleg" X-Patchwork-Id: 1631040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=KEwYyqCH; dkim-atps=neutral Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L0XKk6qxPz9sBF for ; Sat, 14 May 2022 14:17:30 +1000 (AEST) Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4L0XKj21fkz4xXh for ; Sat, 14 May 2022 14:17:29 +1000 (AEST) Received: by gandalf.ozlabs.org (Postfix) id 4L0XKj1ykVz4xXn; Sat, 14 May 2022 14:17:29 +1000 (AEST) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazon201209 header.b=KEwYyqCH; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4L0XKj1n4nz4xXh for ; Sat, 14 May 2022 14:17:28 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231690AbiENERY (ORCPT ); Sat, 14 May 2022 00:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231629AbiENERW (ORCPT ); Sat, 14 May 2022 00:17:22 -0400 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B1DE2B09EB for ; Fri, 13 May 2022 21:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1652501840; x=1684037840; h=from:to:cc:subject:date:message-id:content-id: content-transfer-encoding:mime-version; bh=3S+E3MPtMhWz5GF6SctMTjlaW+Q8p3K4PJBYH1NzsNM=; b=KEwYyqCHPB3BSNwYf+9GYqeGUQvh2DTU5p41PQTVyThfIkYsSqVn/SQA Awu7N8MMXIB4e1gNY/MfJgpezOh9+nn5dFIktvLV17cl6R1hjebvtyHPN s1xqi6aEr5Zqb1NIlllFMtd6UNXZUYnfU+cyMS55w93REf+01FD6X+xYR Y=; X-IronPort-AV: E=Sophos;i="5.91,225,1647302400"; d="scan'208";a="88440285" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-7a21ed79.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP; 14 May 2022 04:17:19 +0000 Received: from EX13MTAUWB001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-7a21ed79.us-east-1.amazon.com (Postfix) with ESMTPS id 170B422156F; Sat, 14 May 2022 04:17:18 +0000 (UTC) Received: from EX13D23UWA003.ant.amazon.com (10.43.160.194) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 14 May 2022 04:17:09 +0000 Received: from EX13D23UWA003.ant.amazon.com (10.43.160.194) by EX13D23UWA003.ant.amazon.com (10.43.160.194) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 14 May 2022 04:17:09 +0000 Received: from EX13D23UWA003.ant.amazon.com ([10.43.160.194]) by EX13D23UWA003.ant.amazon.com ([10.43.160.194]) with mapi id 15.00.1497.033; Sat, 14 May 2022 04:17:09 +0000 From: "Kiselev, Oleg" To: "linux-ext4@vger.kernel.org" CC: Theodore Ts'o Subject: [PATCH] resize2fs: trim resize to cluster boundary Thread-Topic: [PATCH] resize2fs: trim resize to cluster boundary Thread-Index: AQHYZ0l6LEgGHOTRZECljY67fqyoJA== Date: Sat, 14 May 2022 04:17:09 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.43.160.203] Content-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch rounds down the size provided to resize2fs to the nearest cluster boundary for bigalloc filesystems. This is similar to the trimming already done for page boundary alignment. Aligning the size in the user space provides the right value feedback from the resize2fs command, which is a better user experience than trimming the size in the kernel. Signed-off-by: Oleg Kiselev --- resize/main.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.32.0 diff --git a/resize/main.c b/resize/main.c index bceaa1677e21..93a1d5a260e1 100644 --- a/resize/main.c +++ b/resize/main.c @@ -537,6 +537,12 @@ int main (int argc, char ** argv) goto errout; } } + + /* If using cluster allocations, trim down to a cluster boundary */ + if (ext2fs_has_feature_bigalloc(fs->super)) { + new_size &= ~((blk64_t)(1 << fs->cluster_ratio_bits) - 1); + } + new_group_desc_count = ext2fs_div64_ceil(new_size - fs->super->s_first_data_block, EXT2_BLOCKS_PER_GROUP(fs->super));