From: "Darrick J. Wong" <djwong@us.ibm.com>
To: Andreas Dilger <adilger.kernel@dilger.ca>,
Theodore Tso <tytso@mit.edu>,
"Darrick J. Wong" <djwong@us.ibm.com>
Cc: Sunil Mushran <sunil.mushran@oracle.com>,
Amir Goldstein <amir73il@gmail.com>,
Andi Kleen <andi@firstfloor.org>, Mingming Cao <cmm@us.ibm.com>,
Joel Becker <jlbec@evilplan.org>,
linux-ext4@vger.kernel.org, Coly Li <colyli@gmail.com>
Subject: [PATCH 24/54] e2fsck: Verify htree root/node checksums
Date: Tue, 06 Mar 2012 15:59:58 -0800 [thread overview]
Message-ID: <20120306235958.11945.55905.stgit@elm3b70.beaverton.ibm.com> (raw)
In-Reply-To: <20120306235720.11945.30629.stgit@elm3b70.beaverton.ibm.com>
Check htree internal node checksums. If broken, ask user to clear the htree
index and recreate it later.
Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
---
e2fsck/e2fsck.h | 2 ++
e2fsck/pass2.c | 34 +++++++++++++++++++++++++++++-----
e2fsck/problem.c | 10 ++++++++++
e2fsck/problem.h | 6 ++++++
e2fsck/rehash.c | 41 +++++++++++++++++++++++++++++++++++++++--
5 files changed, 86 insertions(+), 7 deletions(-)
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index ed8b0c7..c6dab54 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -483,6 +483,8 @@ extern void region_free(region_t region);
extern int region_allocate(region_t region, region_addr_t start, int n);
/* rehash.c */
+void e2fsck_rehash_dir_later(e2fsck_t ctx, ext2_ino_t ino);
+int e2fsck_dir_will_be_rehashed(e2fsck_t ctx, ext2_ino_t ino);
errcode_t e2fsck_rehash_dir(e2fsck_t ctx, ext2_ino_t ino);
void e2fsck_rehash_directories(e2fsck_t ctx);
diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 882950d..e4a06f3 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -527,7 +527,7 @@ static void parse_int_node(ext2_filsys fs,
struct ext2_db_entry2 *db,
struct check_dir_struct *cd,
struct dx_dir_info *dx_dir,
- char *block_buf)
+ char *block_buf, int failed_csum)
{
struct ext2_dx_root_info *root;
struct ext2_dx_entry *ent;
@@ -538,6 +538,7 @@ static void parse_int_node(ext2_filsys fs,
ext2_dirhash_t min_hash = 0xffffffff;
ext2_dirhash_t max_hash = 0;
ext2_dirhash_t hash = 0, prev_hash;
+ int csum_size = 0;
if (db->blockcnt == 0) {
root = (struct ext2_dx_root_info *) (block_buf + 24);
@@ -552,9 +553,22 @@ static void parse_int_node(ext2_filsys fs,
#endif
ent = (struct ext2_dx_entry *) (block_buf + 24 + root->info_length);
+
+ if (failed_csum &&
+ (e2fsck_dir_will_be_rehashed(cd->ctx, cd->pctx.ino) ||
+ fix_problem(cd->ctx, PR_2_HTREE_ROOT_CSUM_INVALID,
+ &cd->pctx)))
+ goto clear_and_exit;
} else {
ent = (struct ext2_dx_entry *) (block_buf+8);
+
+ if (failed_csum &&
+ (e2fsck_dir_will_be_rehashed(cd->ctx, cd->pctx.ino) ||
+ fix_problem(cd->ctx, PR_2_HTREE_NODE_CSUM_INVALID,
+ &cd->pctx)))
+ goto clear_and_exit;
}
+
limit = (struct ext2_dx_countlimit *) ent;
#ifdef DX_DEBUG
@@ -565,8 +579,12 @@ static void parse_int_node(ext2_filsys fs,
#endif
count = ext2fs_le16_to_cpu(limit->count);
- expect_limit = (fs->blocksize - ((char *) ent - block_buf)) /
- sizeof(struct ext2_dx_entry);
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ csum_size = sizeof(struct ext2_dx_tail);
+ expect_limit = (fs->blocksize -
+ (csum_size + ((char *) ent - block_buf))) /
+ sizeof(struct ext2_dx_entry);
if (ext2fs_le16_to_cpu(limit->limit) != expect_limit) {
cd->pctx.num = ext2fs_le16_to_cpu(limit->limit);
if (fix_problem(cd->ctx, PR_2_HTREE_BAD_LIMIT, &cd->pctx))
@@ -632,6 +650,7 @@ static void parse_int_node(ext2_filsys fs,
clear_and_exit:
clear_htree(cd->ctx, cd->pctx.ino);
dx_dir->numblocks = 0;
+ e2fsck_rehash_dir_later(cd->ctx, cd->pctx.ino);
}
#endif /* ENABLE_HTREE */
@@ -734,6 +753,7 @@ static int check_dir_block(ext2_filsys fs,
struct problem_context pctx;
int dups_found = 0;
int ret;
+ int dx_csum_size = 0;
cd = (struct check_dir_struct *) priv_data;
buf = cd->buf;
@@ -745,6 +765,10 @@ static int check_dir_block(ext2_filsys fs,
if (ctx->progress && (ctx->progress)(ctx, 2, cd->count++, cd->max))
return DIRENT_ABORT;
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ dx_csum_size = sizeof(struct ext2_dx_tail);
+
/*
* Make sure the inode is still in use (could have been
* deleted in the duplicate/bad blocks pass.
@@ -834,7 +858,7 @@ static int check_dir_block(ext2_filsys fs,
(rec_len == fs->blocksize) &&
(dirent->name_len == 0) &&
(ext2fs_le16_to_cpu(limit->limit) ==
- ((fs->blocksize-8) /
+ ((fs->blocksize - (8 + dx_csum_size)) /
sizeof(struct ext2_dx_entry))))
dx_db->type = DX_DIRBLOCK_NODE;
}
@@ -1121,7 +1145,7 @@ out_htree:
cd->pctx.dir = cd->pctx.ino;
if ((dx_db->type == DX_DIRBLOCK_ROOT) ||
(dx_db->type == DX_DIRBLOCK_NODE))
- parse_int_node(fs, db, cd, dx_dir, buf);
+ parse_int_node(fs, db, cd, dx_dir, buf, 0);
}
#endif /* ENABLE_HTREE */
if (offset != fs->blocksize) {
diff --git a/e2fsck/problem.c b/e2fsck/problem.c
index 6ceee11..25db675 100644
--- a/e2fsck/problem.c
+++ b/e2fsck/problem.c
@@ -1383,6 +1383,16 @@ static struct e2fsck_problem problem_table[] = {
N_("i_file_acl_hi @F %N, @s zero.\n"),
PROMPT_CLEAR, PR_PREEN_OK },
+ /* htree root node fails checksum */
+ { PR_2_HTREE_ROOT_CSUM_INVALID,
+ N_("@p @h %d: root node fails checksum\n"),
+ PROMPT_CLEAR_HTREE, PR_PREEN_OK },
+
+ /* htree internal node fails checksum */
+ { PR_2_HTREE_NODE_CSUM_INVALID,
+ N_("@p @h %d: internal node fails checksum\n"),
+ PROMPT_CLEAR_HTREE, PR_PREEN_OK },
+
/* Pass 3 errors */
/* Pass 3: Checking directory connectivity */
diff --git a/e2fsck/problem.h b/e2fsck/problem.h
index 2adb4b9..5cf80fb 100644
--- a/e2fsck/problem.h
+++ b/e2fsck/problem.h
@@ -827,6 +827,12 @@ struct problem_context {
/* i_file_acl_hi should be zero */
#define PR_2_I_FILE_ACL_HI_ZERO 0x020048
+/* htree root node fails checksum */
+#define PR_2_HTREE_ROOT_CSUM_INVALID 0x020049
+
+/* htree node fails checksum */
+#define PR_2_HTREE_NODE_CSUM_INVALID 0x02004A
+
/*
* Pass 3 errors
*/
diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index 15993b3..610b3bf 100644
--- a/e2fsck/rehash.c
+++ b/e2fsck/rehash.c
@@ -52,6 +52,25 @@
#include "e2fsck.h"
#include "problem.h"
+/* Schedule a dir to be rebuilt during pass 3A. */
+void e2fsck_rehash_dir_later(e2fsck_t ctx, ext2_ino_t ino)
+{
+ if (!ctx->dirs_to_hash)
+ ext2fs_u32_list_create(&ctx->dirs_to_hash, 50);
+ if (ctx->dirs_to_hash)
+ ext2fs_u32_list_add(ctx->dirs_to_hash, ino);
+}
+
+/* Ask if a dir will be rebuilt during pass 3A. */
+int e2fsck_dir_will_be_rehashed(e2fsck_t ctx, ext2_ino_t ino)
+{
+ if (ctx->options & E2F_OPT_COMPRESS_DIRS)
+ return 1;
+ if (!ctx->dirs_to_hash)
+ return 0;
+ return ext2fs_u32_list_test(ctx->dirs_to_hash, ino);
+}
+
struct fill_dir_struct {
char *buf;
struct ext2_inode *inode;
@@ -495,6 +514,7 @@ static struct ext2_dx_root_info *set_root_node(ext2_filsys fs, char *buf,
struct ext2_dx_root_info *root;
struct ext2_dx_countlimit *limits;
int filetype = 0;
+ int csum_size = 0;
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_FILETYPE)
filetype = EXT2_FT_DIR << 8;
@@ -519,8 +539,13 @@ static struct ext2_dx_root_info *set_root_node(ext2_filsys fs, char *buf,
root->indirect_levels = 0;
root->unused_flags = 0;
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ csum_size = sizeof(struct ext2_dx_tail);
+
limits = (struct ext2_dx_countlimit *) (buf+32);
- limits->limit = (fs->blocksize - 32) / sizeof(struct ext2_dx_entry);
+ limits->limit = (fs->blocksize - (32 + csum_size)) /
+ sizeof(struct ext2_dx_entry);
limits->count = 0;
return root;
@@ -531,14 +556,20 @@ static struct ext2_dx_entry *set_int_node(ext2_filsys fs, char *buf)
{
struct ext2_dir_entry *dir;
struct ext2_dx_countlimit *limits;
+ int csum_size = 0;
memset(buf, 0, fs->blocksize);
dir = (struct ext2_dir_entry *) buf;
dir->inode = 0;
(void) ext2fs_set_rec_len(fs, fs->blocksize, dir);
+ if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ csum_size = sizeof(struct ext2_dx_tail);
+
limits = (struct ext2_dx_countlimit *) (buf+8);
- limits->limit = (fs->blocksize - 8) / sizeof(struct ext2_dx_entry);
+ limits->limit = (fs->blocksize - (8 + csum_size)) /
+ sizeof(struct ext2_dx_entry);
limits->count = 0;
return (struct ext2_dx_entry *) limits;
@@ -865,8 +896,14 @@ void e2fsck_rehash_directories(e2fsck_t ctx)
if (!ext2fs_u32_list_iterate(iter, &ino))
break;
}
+#if 0
+ /*
+ * lost+found must not be excluded from cleanups or else
+ * checksum errors won't get fixed.
+ */
if (ino == ctx->lost_and_found)
continue;
+#endif
pctx.dir = ino;
if (first) {
fix_problem(ctx, PR_3A_PASS_HEADER, &pctx);
next prev parent reply other threads:[~2012-03-07 0:01 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-06 23:57 [PATCH v3 00/54] e2fsprogs: Add metadata checksumming Darrick J. Wong
2012-03-06 23:57 ` [PATCH 01/54] libext2fs: Read and write full size inodes Darrick J. Wong
2012-03-09 23:36 ` Ted Ts'o
2012-03-12 22:23 ` Darrick J. Wong
2012-03-12 22:53 ` Ted Ts'o
2012-03-06 23:57 ` [PATCH 02/54] libext2fs: Change ext4 on-disk layout to support metadata checksumming Darrick J. Wong
2012-03-09 22:04 ` Ted Ts'o
2012-03-12 22:24 ` Darrick J. Wong
2012-03-06 23:57 ` [PATCH 03/54] debugfs: Optionally ignore bad checksums Darrick J. Wong
2012-03-06 23:57 ` [PATCH 04/54] libext2fs: Precompute FS UUID checksum seed Darrick J. Wong
2012-03-06 23:57 ` [PATCH 05/54] libext2fs: Add inode checksum support Darrick J. Wong
2012-03-06 23:57 ` [PATCH 06/54] debugfs: Dump inode checksum when appropriate Darrick J. Wong
2012-03-06 23:58 ` [PATCH 07/54] tune2fs: Add inode checksum support Darrick J. Wong
2012-03-06 23:58 ` [PATCH 08/54] e2fsck: Verify and correct inode checksums Darrick J. Wong
2012-03-10 5:09 ` Ted Ts'o
2012-03-12 22:49 ` Darrick J. Wong
2012-03-06 23:58 ` [PATCH 09/54] mke2fs: Allow metadata checksums to be turned on at mkfs time Darrick J. Wong
2012-03-06 23:58 ` [PATCH 10/54] libext2fs: Create the inode bitmap checksum Darrick J. Wong
2012-03-06 23:58 ` [PATCH 11/54] tune2fs: Rewrite inode bitmap checksums Darrick J. Wong
2012-03-06 23:58 ` [PATCH 12/54] dumpe2fs: Display inode bitmap checksum Darrick J. Wong
2012-03-06 23:58 ` [PATCH 13/54] e2fsck: Verify " Darrick J. Wong
2012-03-10 5:46 ` Ted Ts'o
2012-03-11 2:11 ` Ted Ts'o
2012-03-12 21:25 ` Darrick J. Wong
2012-03-12 22:30 ` Darrick J. Wong
2012-03-13 0:32 ` [PATCH v3.1 " Darrick J. Wong
2012-03-06 23:58 ` [PATCH 14/54] libext2fs: Create the block " Darrick J. Wong
2012-03-06 23:58 ` [PATCH 15/54] dumpe2fs: Display " Darrick J. Wong
2012-03-06 23:59 ` [PATCH 16/54] e2fsck: Verify " Darrick J. Wong
2012-03-13 0:33 ` [PATCH v3.1 " Darrick J. Wong
2012-03-06 23:59 ` [PATCH 17/54] e2fsck: Don't verify bitmap checksums Darrick J. Wong
2012-03-06 23:59 ` [PATCH 18/54] tune2fs: Rewrite block " Darrick J. Wong
2012-03-06 23:59 ` [PATCH 19/54] libext2fs: Verify and calculate extent tree block checksums Darrick J. Wong
2012-03-06 23:59 ` [PATCH 20/54] tune2fs: Enable extent tree checksums Darrick J. Wong
2012-03-06 23:59 ` [PATCH 21/54] e2fsck: Verify extent tree blocks and clear the bad ones Darrick J. Wong
2012-03-06 23:59 ` [PATCH 22/54] debugfs: Print htree internal node checksums Darrick J. Wong
2012-03-06 23:59 ` [PATCH 23/54] libext2fs: Add dx_root/dx_node checksum calculation and verification helpers Darrick J. Wong
2012-03-06 23:59 ` Darrick J. Wong [this message]
2012-03-13 0:35 ` [PATCH v3.1 24/54] e2fsck: Verify htree root/node checksums Darrick J. Wong
2012-03-07 0:00 ` [PATCH 25/54] libext2fs: Introduce dir_entry_tail to provide checksums for directory leaf nodes Darrick J. Wong
2012-03-07 0:00 ` [PATCH 26/54] e2fsck: Check directory leaf block checksums Darrick J. Wong
2012-03-07 0:00 ` [PATCH 27/54] tune2fs: Rebuild and checksum directories when toggling metadata_csum or changing UUID Darrick J. Wong
2012-03-07 0:00 ` [PATCH 28/54] libext2fs: Verify and calculate extended attribute block checksums Darrick J. Wong
2012-03-07 0:00 ` [PATCH 29/54] e2fsck: Check " Darrick J. Wong
2012-03-10 5:22 ` Ted Ts'o
2012-03-12 22:43 ` Darrick J. Wong
2012-03-07 0:00 ` [PATCH 30/54] tune2fs: Rewrite " Darrick J. Wong
2012-03-07 0:00 ` [PATCH 31/54] libext2fs: Calculate and verify superblock checksums Darrick J. Wong
2012-03-07 0:00 ` [PATCH 32/54] e2fsck: Handle superblock checksum errors gracefully Darrick J. Wong
2012-03-07 0:01 ` [PATCH 33/54] libext2fs: Record the checksum algorithm in use in the superblock Darrick J. Wong
2012-03-07 0:01 ` [PATCH 34/54] tune2fs: Store checksum algorithm type in superblock Darrick J. Wong
2012-03-07 0:01 ` [PATCH 35/54] mke2fs: Record the checksum algorithm in use in the superblock Darrick J. Wong
2012-03-07 0:01 ` [PATCH 36/54] libext2fs: Block group checksum should use metadata_csum algorithm Darrick J. Wong
2012-03-07 0:01 ` [PATCH 37/54] e2fsck: Ensure block group checksum uses " Darrick J. Wong
2012-03-13 0:38 ` [PATCH v3.1 " Darrick J. Wong
2012-03-07 0:01 ` [PATCH 38/54] tune2fs: Rewrite block group checksums when changing checksumming feature flags Darrick J. Wong
2012-03-07 0:02 ` [PATCH 39/54] mke2fs: Write new group descriptors with the appropriate checksum Darrick J. Wong
2012-03-07 0:02 ` [PATCH 40/54] mke2fs: Warn if not enabling all the features that metadata_csum wants Darrick J. Wong
2012-03-07 0:02 ` [PATCH 41/54] libext2fs: Add checksum to MMP block Darrick J. Wong
2012-03-07 0:02 ` [PATCH 42/54] e2fsck: Verify and correct MMP checksum problems Darrick J. Wong
2012-03-07 0:02 ` [PATCH 43/54] tune2fs: Force MMP update when changing metadata_csum flag Darrick J. Wong
2012-03-07 0:02 ` [PATCH 44/54] libext2fs: Change on-disk journal layout to support metadata checksumming Darrick J. Wong
2012-03-07 0:02 ` [PATCH 45/54] libext2fs: Dump feature flags for jbd2 v2 checksums Darrick J. Wong
2012-03-07 0:02 ` [PATCH 46/54] e2fsck: Check journal superblock checksum prior to recovery Darrick J. Wong
2012-03-07 0:02 ` [PATCH 47/54] e2fsck: Check revoke block checksum during recovery Darrick J. Wong
2012-03-07 0:03 ` [PATCH 48/54] e2fsck: Check descriptor block checksum when recovering journal Darrick J. Wong
2012-03-07 0:03 ` [PATCH 49/54] e2fsck: Check commit block checksum during recovery Darrick J. Wong
2012-03-07 0:03 ` [PATCH 50/54] e2fsck: Verify data block checksums when recovering journal Darrick J. Wong
2012-03-07 0:03 ` [PATCH 51/54] libext2fs: Enable support for the metadata checksumming feature Darrick J. Wong
2012-03-07 0:03 ` [PATCH 52/54] libext2fs: Bring the CRC32c implementation up to date with the kernel implementation Darrick J. Wong
2012-03-07 0:03 ` [PATCH 53/54] e2fsck: Refactor crc32_be code Darrick J. Wong
2012-03-07 0:03 ` [PATCH 54/54] mke2fs: Enable metadata_csum on ext4dev filesystems Darrick J. Wong
2012-03-09 22:37 ` [PATCH v3 00/54] e2fsprogs: Add metadata checksumming Ted Ts'o
2012-03-13 0:41 ` Darrick J. Wong
2012-03-13 4:04 ` Andreas Dilger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120306235958.11945.55905.stgit@elm3b70.beaverton.ibm.com \
--to=djwong@us.ibm.com \
--cc=adilger.kernel@dilger.ca \
--cc=amir73il@gmail.com \
--cc=andi@firstfloor.org \
--cc=cmm@us.ibm.com \
--cc=colyli@gmail.com \
--cc=jlbec@evilplan.org \
--cc=linux-ext4@vger.kernel.org \
--cc=sunil.mushran@oracle.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).