From patchwork Wed Dec 11 01:23:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 299716 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 148532C030E for ; Wed, 11 Dec 2013 12:23:41 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751954Ab3LKBXk (ORCPT ); Tue, 10 Dec 2013 20:23:40 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:43394 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584Ab3LKBXk (ORCPT ); Tue, 10 Dec 2013 20:23:40 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id rBB1Nbwm010269 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Dec 2013 01:23:38 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBB1Napw025635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Dec 2013 01:23:37 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id rBB1Nas3024778; Wed, 11 Dec 2013 01:23:36 GMT Received: from localhost (/10.145.179.107) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 Dec 2013 17:23:36 -0800 Subject: [PATCH 47/74] resize2fs: during shrink, don't free in-use bg data clusters To: tytso@mit.edu, darrick.wong@oracle.com From: "Darrick J. Wong" Cc: linux-ext4@vger.kernel.org Date: Tue, 10 Dec 2013 17:23:33 -0800 Message-ID: <20131211012333.30655.80931.stgit@birch.djwong.org> In-Reply-To: <20131211011813.30655.39624.stgit@birch.djwong.org> References: <20131211011813.30655.39624.stgit@birch.djwong.org> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When freeing a group's metadata blocks, be careful not to free clusters belonging to other groups! Signed-off-by: Darrick J. Wong --- resize/resize2fs.c | 78 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 29 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/resize/resize2fs.c b/resize/resize2fs.c index ff5e6a2..49fe986 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -270,40 +270,60 @@ static void fix_uninit_block_bitmaps(ext2_filsys fs) * release them in the new filesystem data structure, and mark them as * reserved so the old inode table blocks don't get overwritten. */ -static void free_gdp_blocks(ext2_filsys fs, - ext2fs_block_bitmap reserve_blocks, - ext2_filsys old_fs, - dgrp_t group) +static errcode_t free_gdp_blocks(ext2_filsys fs, + ext2fs_block_bitmap reserve_blocks, + ext2_filsys old_fs, + dgrp_t group, dgrp_t count) { blk64_t blk; int j; + dgrp_t i; + ext2fs_block_bitmap bg_map = NULL; + errcode_t retval = 0; - blk = ext2fs_block_bitmap_loc(old_fs, group); - if (blk && - (blk < ext2fs_blocks_count(fs->super))) { - ext2fs_block_alloc_stats2(fs, blk, -1); - ext2fs_mark_block_bitmap2(reserve_blocks, blk); - } + /* If bigalloc, don't free metadata living in the same cluster */ + if (EXT2FS_CLUSTER_RATIO(fs) > 1) { + retval = ext2fs_allocate_block_bitmap(fs, "bgdata", &bg_map); + if (retval) + goto out; - blk = ext2fs_inode_bitmap_loc(old_fs, group); - if (blk && - (blk < ext2fs_blocks_count(fs->super))) { - ext2fs_block_alloc_stats2(fs, blk, -1); - ext2fs_mark_block_bitmap2(reserve_blocks, blk); + retval = mark_table_blocks(fs, bg_map); + if (retval) + goto out; } - blk = ext2fs_inode_table_loc(old_fs, group); - if (blk == 0 || - (blk >= ext2fs_blocks_count(fs->super))) - return; + for (i = group; i < group + count; i++) { + blk = ext2fs_block_bitmap_loc(old_fs, i); + if (blk && + (blk < ext2fs_blocks_count(fs->super)) && + !(bg_map && ext2fs_test_block_bitmap2(bg_map, blk))) { + ext2fs_block_alloc_stats2(fs, blk, -1); + ext2fs_mark_block_bitmap2(reserve_blocks, blk); + } - for (j = 0; - j < fs->inode_blocks_per_group; j++, blk++) { - if (blk >= ext2fs_blocks_count(fs->super)) - break; - ext2fs_block_alloc_stats2(fs, blk, -1); - ext2fs_mark_block_bitmap2(reserve_blocks, blk); + blk = ext2fs_inode_bitmap_loc(old_fs, i); + if (blk && + (blk < ext2fs_blocks_count(fs->super)) && + !(bg_map && ext2fs_test_block_bitmap2(bg_map, blk))) { + ext2fs_block_alloc_stats2(fs, blk, -1); + ext2fs_mark_block_bitmap2(reserve_blocks, blk); + } + + blk = ext2fs_inode_table_loc(old_fs, i); + for (j = 0; + j < fs->inode_blocks_per_group; j++, blk++) { + if (blk >= ext2fs_blocks_count(fs->super) || + (bg_map && ext2fs_test_block_bitmap2(bg_map, blk))) + continue; + ext2fs_block_alloc_stats2(fs, blk, -1); + ext2fs_mark_block_bitmap2(reserve_blocks, blk); + } } + +out: + if (bg_map) + ext2fs_free_block_bitmap(bg_map); + return retval; } /* @@ -467,10 +487,10 @@ retry: * Check the block groups that we are chopping off * and free any blocks associated with their metadata */ - for (i = fs->group_desc_count; - i < old_fs->group_desc_count; i++) - free_gdp_blocks(fs, reserve_blocks, old_fs, i); - retval = 0; + retval = free_gdp_blocks(fs, reserve_blocks, old_fs, + fs->group_desc_count, + old_fs->group_desc_count - + fs->group_desc_count); goto errout; }