From patchwork Sat Aug 9 17:10:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 378780 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B3E141400D6 for ; Sun, 10 Aug 2014 03:10:34 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751977AbaHIRKc (ORCPT ); Sat, 9 Aug 2014 13:10:32 -0400 Received: from imap.thunk.org ([74.207.234.97]:52422 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752010AbaHIRK1 (ORCPT ); Sat, 9 Aug 2014 13:10:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=RJbwDlXlI2VDhfR+3nJ6e2KPKGL/ckINNXn5f5O01hk=; b=auREpy2xvaKYnN8NpZZfr9Ywbm9UHKRwC0Sz+PZ2Pp2rFSS66/mZYCwAxrZnU4UWtajyQr+9mYUslMlIGyQT1QHZZaLns5enUwzXQcrZqg+ogjjDI0qSfCDjxr6JxH4Vjq8n4Hu/jYqx+dnosksQ0tzw4W4seXDBsANkn+K/FhI=; Received: from root (helo=closure.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.80) (envelope-from ) id 1XGA9v-0006bE-MC; Sat, 09 Aug 2014 17:10:23 +0000 Received: by closure.thunk.org (Postfix, from userid 15806) id A90C2580DBD; Sat, 9 Aug 2014 13:10:22 -0400 (EDT) From: Theodore Ts'o To: Ext4 Developers List Cc: antymat+debian@chelmska.waw.pl, 756922@bugs.debian.org, Theodore Ts'o Subject: [PATCH 3/6] resize2fs: disable the meta_bg feature if necessary Date: Sat, 9 Aug 2014 13:10:17 -0400 Message-Id: <1407604220-2620-3-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1407604220-2620-1-git-send-email-tytso@mit.edu> References: <1407604220-2620-1-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When shrinking a file system, if the number block groups drops below the point where we started using the meta_bg layout, disable the meta_bg feature and set s_first_meta_bg to zero. This is necessary to avoid creating an invalid/corrupted file system after the shrink. Addresses-Debian-Bug: 756922 Reported-by: Marcin Wolcendorf Signed-off-by: Theodore Ts'o --- resize/resize2fs.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 9641b1e..b3755f6 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -489,6 +489,13 @@ retry: fs->super->s_reserved_gdt_blocks = new; } + if ((fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) && + (fs->super->s_first_meta_bg > fs->desc_blocks)) { + fs->super->s_feature_incompat &= + ~EXT2_FEATURE_INCOMPAT_META_BG; + fs->super->s_first_meta_bg = 0; + } + /* * Update the location of the backup superblocks if the * sparse_super2 feature is enabled. @@ -998,13 +1005,15 @@ static errcode_t blocks_to_move(ext2_resize_t rfs) ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); } - if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) { + if (old_fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) old_blocks = old_fs->super->s_first_meta_bg; + else + old_blocks = old_fs->desc_blocks + + old_fs->super->s_reserved_gdt_blocks; + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) new_blocks = fs->super->s_first_meta_bg; - } else { - old_blocks = old_fs->desc_blocks + old_fs->super->s_reserved_gdt_blocks; + else new_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; - } retval = reserve_sparse_super2_last_group(rfs, meta_bmap); if (retval)