From patchwork Fri Oct 18 12:50:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 1179351 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46vm9k3PBhz9sPJ for ; Fri, 18 Oct 2019 23:51:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727993AbfJRMvF (ORCPT ); Fri, 18 Oct 2019 08:51:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:40366 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726875AbfJRMvE (ORCPT ); Fri, 18 Oct 2019 08:51:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5AE07B3B6; Fri, 18 Oct 2019 12:51:03 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id ED5CA1E4851; Fri, 18 Oct 2019 14:51:02 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Jan Kara Subject: [PATCH] resize2fs: Make minimum size estimates more reliable for mounted fs Date: Fri, 18 Oct 2019 14:50:59 +0200 Message-Id: <20191018125059.2446-1-jack@suse.cz> X-Mailer: git-send-email 2.16.4 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Currently, the estimate of minimum filesystem size is using free blocks counter in the superblock. The counter generally doesn't get updated while the filesystem is mounted and thus the estimate is very unreliable for a mounted filesystem. For some usecases such as automated partitioning proposal to the user it is desirable that the estimate of minimum filesystem size is reasonably accurate even for a mounted filesystem. So use group descriptor counters of free blocks for the estimate of minimum filesystem size. These get updated together with block being allocated and so the resulting estimate is more accurate. Signed-off-by: Jan Kara --- resize/resize2fs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/resize/resize2fs.c b/resize/resize2fs.c index c2e10471bfd1..8a3d08db19f3 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -2926,11 +2926,11 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) fs->super->s_reserved_gdt_blocks; /* calculate how many blocks are needed for data */ - data_needed = ext2fs_blocks_count(fs->super) - - ext2fs_free_blocks_count(fs->super); - - for (grp = 0; grp < fs->group_desc_count; grp++) + data_needed = ext2fs_blocks_count(fs->super); + for (grp = 0; grp < fs->group_desc_count; grp++) { data_needed -= calc_group_overhead(fs, grp, old_desc_blocks); + data_needed -= ext2fs_bg_free_blocks_count(fs, grp); + } #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) printf("fs requires %llu data blocks.\n", data_needed);