From patchwork Tue Jul 31 11:48:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Liu X-Patchwork-Id: 174248 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 3EE7E2C0083 for ; Tue, 31 Jul 2012 21:40:49 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756028Ab2GaLkr (ORCPT ); Tue, 31 Jul 2012 07:40:47 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:35285 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756042Ab2GaLko (ORCPT ); Tue, 31 Jul 2012 07:40:44 -0400 Received: by mail-pb0-f46.google.com with SMTP id rp8so11540445pbb.19 for ; Tue, 31 Jul 2012 04:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Vax+FFAH7g9441wVdVKis3wGISczCWk9f2NudB6UeXQ=; b=sczZUtJN0BYpbXNLi690sfhRUrBEf6iu3Q+qdLZel8hNSvEtsERK80M89yO0pPqJdr wCIHm8QuQn9ZZjy/ZSqQFjMzuoNeZJU3Hm7law62VhXi1Zx2zp/wPd9gRPcEPJu7NvCW +v1fyqAwIuxLxn3xzxRf/xWspBbK4rkZXgmuvb91zh0VShy65piUU3Qw1c6XvxeDBdQa t2WNe7fMUTf8gnMRw7zAx6Z4XB3Iod0Gpg60km2cNVfxMoZ6XmYk2y7HVcl6MlP+Mx+m tMHlGhMwWjUUufYZdxAAHILEL8AOTVsvu87YthSvEXnPY8ZXnFhm2hrg9yD5QltzYFQZ TRCA== Received: by 10.68.223.164 with SMTP id qv4mr43074414pbc.20.1343734843964; Tue, 31 Jul 2012 04:40:43 -0700 (PDT) Received: from localhost.localdomain ([182.92.247.2]) by mx.google.com with ESMTPS id oo6sm135950pbc.22.2012.07.31.04.40.42 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 31 Jul 2012 04:40:43 -0700 (PDT) From: Zheng Liu To: linux-ext4@vger.kernel.org Cc: Zheng Liu Subject: [PATCH 31/36 v4] e2fsck: make pass1 support inline data Date: Tue, 31 Jul 2012 19:48:24 +0800 Message-Id: <1343735309-30579-32-git-send-email-wenqing.lz@taobao.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1343735309-30579-1-git-send-email-wenqing.lz@taobao.com> References: <1343735309-30579-1-git-send-email-wenqing.lz@taobao.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Zheng Liu Signed-off-by: Zheng Liu --- e2fsck/pass1.c | 76 ++++++++++++++++++++++++++++++++++++++++++----- e2fsck/pass1b.c | 5 ++- lib/ext2fs/dblist_dir.c | 8 ++++- 3 files changed, 77 insertions(+), 12 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index fee0dc6..f1bf828 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -221,12 +221,37 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino, if (len == fs->blocksize) return 0; } else { - if (inode->i_size >= sizeof(inode->i_block)) - return 0; + if (inode->i_flags & EXT4_INLINE_DATA_FL) { + struct ext2_inode_large *large_inode; + struct inline_data idata; + void *inline_start; + int inline_data_size; + errcode_t retval; + + inline_data_size = ext2fs_inline_data_size(fs, ino); + if (inode->i_size != inline_data_size) + return 0; - len = strnlen((char *)inode->i_block, sizeof(inode->i_block)); - if (len == sizeof(inode->i_block)) - return 0; + large_inode = (struct ext2_inode_large *)inode; + + ext2fs_iget_extra_inode(fs, large_inode, &idata); + if (idata.inline_off == EXT4_MIN_INLINE_DATA_SIZE) + return 0; + inline_start = ext2fs_get_inline_xattr_pos(large_inode, + &idata); + len = strnlen((char *)inline_start, + idata.inline_size - EXT4_MIN_INLINE_DATA_SIZE); + if (len != idata.inline_size - EXT4_MIN_INLINE_DATA_SIZE) + return 0; + len += EXT4_MIN_INLINE_DATA_SIZE; + } else { + if (inode->i_size >= sizeof(inode->i_block)) + return 0; + + len = strnlen((char *)inode->i_block, sizeof(inode->i_block)); + if (len == sizeof(inode->i_block)) + return 0; + } } if (len != inode->i_size) return 0; @@ -304,6 +329,14 @@ static void check_ea_in_inode(e2fsck_t ctx, struct problem_context *pctx) goto fix; } + /* + * not do the following checks for inline_data because + * other checks ensure that the content of inline data + * is correct. + */ + if (strncmp(EXT2_EXT_ATTR_NAME(entry), "data", 4) == 0) + goto next; + /* attribute len eats this space */ remain -= EXT2_EXT_ATTR_SIZE(entry->e_name_len); @@ -331,6 +364,7 @@ static void check_ea_in_inode(e2fsck_t ctx, struct problem_context *pctx) goto fix; } +next: remain -= entry->e_value_size; entry = EXT2_EXT_ATTR_NEXT(entry); @@ -1203,7 +1237,8 @@ void e2fsck_pass1(e2fsck_t ctx) ctx->fs_sockets_count++; } else mark_inode_bad(ctx, ino); - if (!(inode->i_flags & EXT4_EXTENTS_FL)) { + if (!(inode->i_flags & EXT4_EXTENTS_FL) && + !(inode->i_flags & EXT4_INLINE_DATA_FL)) { if (inode->i_block[EXT2_IND_BLOCK]) ctx->fs_ind_count++; if (inode->i_block[EXT2_DIND_BLOCK]) @@ -1212,6 +1247,7 @@ void e2fsck_pass1(e2fsck_t ctx) ctx->fs_tind_count++; } if (!(inode->i_flags & EXT4_EXTENTS_FL) && + !(inode->i_flags & EXT4_INLINE_DATA_FL) && (inode->i_block[EXT2_IND_BLOCK] || inode->i_block[EXT2_DIND_BLOCK] || inode->i_block[EXT2_TIND_BLOCK] || @@ -2089,6 +2125,22 @@ static void check_blocks_extents(e2fsck_t ctx, struct problem_context *pctx, ext2fs_extent_free(ehandle); } +static void check_blocks_inline_data(e2fsck_t ctx, struct problem_context *pctx, + struct process_block_struct *pb) +{ + if (pb->is_dir) { + pctx->errcode = ext2fs_add_dir_block2(ctx->fs->dblist, + pb->ino, 0, 0); + if (pctx->errcode) { + pctx->blk = 0; + pctx->num = 0; + fix_problem(ctx, PR_1_ADD_DBLOCK, pctx); + /* Should never get here */ + ctx->flags |= E2F_FLAG_ABORT; + } + } +} + /* * This subroutine is called on each inode to account for all of the * blocks used by that inode. @@ -2103,6 +2155,7 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, int bad_size = 0; int dirty_inode = 0; int extent_fs; + int inlinedata_fs; __u64 size; pb.ino = ino; @@ -2126,6 +2179,8 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, extent_fs = (ctx->fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS); + inlinedata_fs = (ctx->fs->super->s_feature_incompat & + EXT4_FEATURE_INCOMPAT_INLINE_DATA); if (inode->i_flags & EXT2_COMPRBLK_FL) { if (fs->super->s_feature_incompat & @@ -2149,6 +2204,8 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, if (ext2fs_inode_has_valid_blocks2(fs, inode)) { if (extent_fs && (inode->i_flags & EXT4_EXTENTS_FL)) check_blocks_extents(ctx, pctx, &pb); + else if (inlinedata_fs && (inode->i_flags & EXT4_INLINE_DATA_FL)) + check_blocks_inline_data(ctx, pctx, &pb); else { pctx->errcode = ext2fs_block_iterate3(fs, ino, pb.is_dir ? BLOCK_FLAG_HOLE : 0, @@ -2191,7 +2248,8 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, } } - if (!pb.num_blocks && pb.is_dir) { + if (!pb.num_blocks && pb.is_dir && + !(inode->i_flags & EXT4_INLINE_DATA_FL)) { if (fix_problem(ctx, PR_1_ZERO_LENGTH_DIR, pctx)) { e2fsck_clear_inode(ctx, ino, inode, 0, "check_blocks"); ctx->fs_directory_count--; @@ -2217,7 +2275,9 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, #endif if (pb.is_dir) { int nblock = inode->i_size >> EXT2_BLOCK_SIZE_BITS(fs->super); - if (inode->i_size & (fs->blocksize - 1)) + if (inode->i_flags & EXT4_INLINE_DATA_FL) + ; + else if (inode->i_size & (fs->blocksize - 1)) bad_size = 5; else if (nblock > (pb.last_block + 1)) bad_size = 1; diff --git a/e2fsck/pass1b.c b/e2fsck/pass1b.c index 05cbd10..6918fcc 100644 --- a/e2fsck/pass1b.c +++ b/e2fsck/pass1b.c @@ -315,8 +315,9 @@ static void pass1b(e2fsck_t ctx, char *block_buf) pb.inode = &inode; pb.cur_cluster = ~0; - if (ext2fs_inode_has_valid_blocks2(fs, &inode) || - (ino == EXT2_BAD_INO)) + if ((ext2fs_inode_has_valid_blocks2(fs, &inode) || + (ino == EXT2_BAD_INO)) && + !(inode.i_flags & EXT4_INLINE_DATA_FL)) pctx.errcode = ext2fs_block_iterate3(fs, ino, BLOCK_FLAG_READ_ONLY, block_buf, process_pass1b_block, &pb); diff --git a/lib/ext2fs/dblist_dir.c b/lib/ext2fs/dblist_dir.c index d4d5111..cc54d7a 100644 --- a/lib/ext2fs/dblist_dir.c +++ b/lib/ext2fs/dblist_dir.c @@ -72,8 +72,12 @@ static int db_dir_proc(ext2_filsys fs, struct ext2_db_entry2 *db_info, ctx->dir = db_info->ino; ctx->errcode = 0; - ret = ext2fs_process_dir_block(fs, &db_info->blk, - db_info->blockcnt, 0, 0, priv_data); + if (ext2fs_has_inline_data(fs, ctx->dir)) + ret = ext2fs_inline_data_iterate2(fs, ctx->dir, 0, NULL, + ctx->func, ctx->priv_data); + else + ret = ext2fs_process_dir_block(fs, &db_info->blk, + db_info->blockcnt, 0, 0, priv_data); if ((ret & BLOCK_ABORT) && !ctx->errcode) return DBLIST_ABORT; return 0;