From patchwork Fri Dec 30 11:00:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongqiang Yang X-Patchwork-Id: 133663 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 84E8FB6FAF for ; Sat, 31 Dec 2011 01:41:42 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751332Ab1L3Oll (ORCPT ); Fri, 30 Dec 2011 09:41:41 -0500 Received: from mail-iy0-f174.google.com ([209.85.210.174]:41000 "EHLO mail-iy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750877Ab1L3Olk (ORCPT ); Fri, 30 Dec 2011 09:41:40 -0500 Received: by mail-iy0-f174.google.com with SMTP id h11so25397943iae.19 for ; Fri, 30 Dec 2011 06:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=sONBSGp82dhrf3sTNb1HsS4unduc0S/O8qIbQj8yXpw=; b=OsF30gaLOn1nQzMUL1axlRClr4hP2Vi/03x1VEnYHDO/CMK8PRTirbjCRucscjwmmK 1sr7IuCJfqxqy6W4iBprKRVBSXHLEzA/r99iHiTShrbFhQ2wuT//uPHj81ot8lpQqYTT h7FvEcCykmxNDrEOl3s3e9bs/dTbQdaiZKEEM= Received: by 10.42.168.202 with SMTP id x10mr40996143icy.4.1325256100358; Fri, 30 Dec 2011 06:41:40 -0800 (PST) Received: from localhost.localdomain ([159.226.43.42]) by mx.google.com with ESMTPS id aq5sm86161462igc.5.2011.12.30.06.41.38 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Dec 2011 06:41:39 -0800 (PST) From: Yongqiang Yang To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Yongqiang Yang Subject: [PATCH V6 RESEND 03/15] ext4: add a function which sets up a new group desc Date: Fri, 30 Dec 2011 19:00:00 +0800 Message-Id: <1325242812-27005-4-git-send-email-xiaoqiangnk@gmail.com> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1325242812-27005-1-git-send-email-xiaoqiangnk@gmail.com> References: <1325242812-27005-1-git-send-email-xiaoqiangnk@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Yongqiang Yang This patch adds a function named ext4_setup_new_desc() which sets up a new group descriptor and whose code is copied from ext4_group_add(). The function will be used by new resize implementation. Signed-off-by: Yongqiang Yang Signed-off-by: "Theodore Ts'o" --- fs/ext4/resize.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 55 insertions(+), 0 deletions(-) diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c index 9a5486e..a50eab3 100644 --- a/fs/ext4/resize.c +++ b/fs/ext4/resize.c @@ -777,6 +777,61 @@ out: return err; } +/* + * ext4_setup_new_desc() sets up group descriptors specified by @input. + * + * @handle: journal handle + * @sb: super block + */ +static int ext4_setup_new_desc(handle_t *handle, struct super_block *sb, + struct ext4_new_group_data *input) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + ext4_group_t group; + struct ext4_group_desc *gdp; + struct buffer_head *gdb_bh; + int gdb_off, gdb_num, err = 0; + + group = input->group; + + gdb_off = group % EXT4_DESC_PER_BLOCK(sb); + gdb_num = group / EXT4_DESC_PER_BLOCK(sb); + + /* + * get_write_access() has been called on gdb_bh by ext4_add_new_desc(). + */ + gdb_bh = sbi->s_group_desc[gdb_num]; + /* Update group descriptor block for new group */ + gdp = (struct ext4_group_desc *)((char *)gdb_bh->b_data + + gdb_off * EXT4_DESC_SIZE(sb)); + + memset(gdp, 0, EXT4_DESC_SIZE(sb)); + /* LV FIXME */ + memset(gdp, 0, EXT4_DESC_SIZE(sb)); + ext4_block_bitmap_set(sb, gdp, input->block_bitmap); /* LV FIXME */ + ext4_inode_bitmap_set(sb, gdp, input->inode_bitmap); /* LV FIXME */ + ext4_inode_table_set(sb, gdp, input->inode_table); /* LV FIXME */ + ext4_free_group_clusters_set(sb, gdp, + EXT4_B2C(sbi, input->free_blocks_count)); + ext4_free_inodes_set(sb, gdp, EXT4_INODES_PER_GROUP(sb)); + gdp->bg_flags = cpu_to_le16(EXT4_BG_INODE_ZEROED); + gdp->bg_checksum = ext4_group_desc_csum(sbi, input->group, gdp); + + err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh); + if (unlikely(err)) { + ext4_std_error(sb, err); + return err; + } + + /* + * We can allocate memory for mb_alloc based on the new group + * descriptor + */ + err = ext4_mb_add_groupinfo(sb, group, gdp); + + return err; +} + /* Add group descriptor data to an existing or new group descriptor block. * Ensure we handle all possible error conditions _before_ we start modifying * the filesystem, because we cannot abort the transaction and not have it