|
|
e427d2 |
From fb4a6ed596f6a9f6b1c6d3d9307ef8259d988c04 Mon Sep 17 00:00:00 2001
|
|
|
e427d2 |
From: Jan Kara <jack@suse.cz>
|
|
|
e427d2 |
Date: Thu, 13 Feb 2020 11:16:02 +0100
|
|
|
e427d2 |
Subject: [PATCH 06/46] tune2fs: update dir checksums when clearing dir_index
|
|
|
e427d2 |
feature
|
|
|
e427d2 |
Content-Type: text/plain
|
|
|
e427d2 |
|
|
|
e427d2 |
When clearing dir_index feature while metadata_csum is enabled, we have
|
|
|
e427d2 |
to rewrite checksums of all indexed directories to update checksums of
|
|
|
e427d2 |
internal tree nodes.
|
|
|
e427d2 |
|
|
|
e427d2 |
Signed-off-by: Jan Kara <jack@suse.cz>
|
|
|
e427d2 |
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
|
|
|
e427d2 |
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
|
|
|
e427d2 |
---
|
|
|
e427d2 |
misc/tune2fs.c | 143 ++++++++++++++++++++++++++++++++-----------------
|
|
|
e427d2 |
1 file changed, 95 insertions(+), 48 deletions(-)
|
|
|
e427d2 |
|
|
|
e427d2 |
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
|
|
|
e427d2 |
index 39cf8587..a7a779b8 100644
|
|
|
e427d2 |
--- a/misc/tune2fs.c
|
|
|
e427d2 |
+++ b/misc/tune2fs.c
|
|
|
e427d2 |
@@ -504,7 +504,8 @@ struct rewrite_dir_context {
|
|
|
e427d2 |
char *buf;
|
|
|
e427d2 |
errcode_t errcode;
|
|
|
e427d2 |
ext2_ino_t dir;
|
|
|
e427d2 |
- int is_htree;
|
|
|
e427d2 |
+ int is_htree:1;
|
|
|
e427d2 |
+ int clear_htree:1;
|
|
|
e427d2 |
};
|
|
|
e427d2 |
|
|
|
e427d2 |
static int rewrite_dir_block(ext2_filsys fs,
|
|
|
e427d2 |
@@ -523,8 +524,13 @@ static int rewrite_dir_block(ext2_filsys fs,
|
|
|
e427d2 |
if (ctx->errcode)
|
|
|
e427d2 |
return BLOCK_ABORT;
|
|
|
e427d2 |
|
|
|
e427d2 |
- /* if htree node... */
|
|
|
e427d2 |
- if (ctx->is_htree)
|
|
|
e427d2 |
+ /*
|
|
|
e427d2 |
+ * if htree node... Note that if we are clearing htree structures from
|
|
|
e427d2 |
+ * the directory, we treat the htree internal block as an ordinary leaf.
|
|
|
e427d2 |
+ * The code below will do the right thing and make space for checksum
|
|
|
e427d2 |
+ * there.
|
|
|
e427d2 |
+ */
|
|
|
e427d2 |
+ if (ctx->is_htree && !ctx->clear_htree)
|
|
|
e427d2 |
ext2fs_get_dx_countlimit(fs, (struct ext2_dir_entry *)ctx->buf,
|
|
|
e427d2 |
&dcl, &dcl_offset);
|
|
|
e427d2 |
if (dcl) {
|
|
|
e427d2 |
@@ -653,7 +659,8 @@ static errcode_t rewrite_directory(ext2_filsys fs, ext2_ino_t dir,
|
|
|
e427d2 |
if (retval)
|
|
|
e427d2 |
return retval;
|
|
|
e427d2 |
|
|
|
e427d2 |
- ctx.is_htree = (inode->i_flags & EXT2_INDEX_FL);
|
|
|
e427d2 |
+ ctx.is_htree = !!(inode->i_flags & EXT2_INDEX_FL);
|
|
|
e427d2 |
+ ctx.clear_htree = !ext2fs_has_feature_dir_index(fs->super);
|
|
|
e427d2 |
ctx.dir = dir;
|
|
|
e427d2 |
ctx.errcode = 0;
|
|
|
e427d2 |
retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY |
|
|
|
e427d2 |
@@ -664,6 +671,13 @@ static errcode_t rewrite_directory(ext2_filsys fs, ext2_ino_t dir,
|
|
|
e427d2 |
if (retval)
|
|
|
e427d2 |
return retval;
|
|
|
e427d2 |
|
|
|
e427d2 |
+ if (ctx.is_htree && ctx.clear_htree) {
|
|
|
e427d2 |
+ inode->i_flags &= ~EXT2_INDEX_FL;
|
|
|
e427d2 |
+ retval = ext2fs_write_inode(fs, dir, inode);
|
|
|
e427d2 |
+ if (retval)
|
|
|
e427d2 |
+ return retval;
|
|
|
e427d2 |
+ }
|
|
|
e427d2 |
+
|
|
|
e427d2 |
return ctx.errcode;
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
@@ -818,28 +832,67 @@ static void rewrite_one_inode(struct rewrite_context *ctx, ext2_ino_t ino,
|
|
|
e427d2 |
fatal_err(retval, "while rewriting extended attribute");
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
-/*
|
|
|
e427d2 |
- * Forcibly set checksums in all inodes.
|
|
|
e427d2 |
- */
|
|
|
e427d2 |
-static void rewrite_inodes(ext2_filsys fs)
|
|
|
e427d2 |
+#define REWRITE_EA_FL 0x01 /* Rewrite EA inodes */
|
|
|
e427d2 |
+#define REWRITE_DIR_FL 0x02 /* Rewrite directories */
|
|
|
e427d2 |
+#define REWRITE_NONDIR_FL 0x04 /* Rewrite other inodes */
|
|
|
e427d2 |
+#define REWRITE_ALL (REWRITE_EA_FL | REWRITE_DIR_FL | REWRITE_NONDIR_FL)
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+static void rewrite_inodes_pass(struct rewrite_context *ctx, unsigned int flags)
|
|
|
e427d2 |
{
|
|
|
e427d2 |
ext2_inode_scan scan;
|
|
|
e427d2 |
errcode_t retval;
|
|
|
e427d2 |
ext2_ino_t ino;
|
|
|
e427d2 |
struct ext2_inode *inode;
|
|
|
e427d2 |
- int pass;
|
|
|
e427d2 |
+ int rewrite;
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+ retval = ext2fs_get_mem(ctx->inode_size, &inode;;
|
|
|
e427d2 |
+ if (retval)
|
|
|
e427d2 |
+ fatal_err(retval, "while allocating memory");
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+ retval = ext2fs_open_inode_scan(ctx->fs, 0, &scan;;
|
|
|
e427d2 |
+ if (retval)
|
|
|
e427d2 |
+ fatal_err(retval, "while opening inode scan");
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+ do {
|
|
|
e427d2 |
+ retval = ext2fs_get_next_inode_full(scan, &ino, inode,
|
|
|
e427d2 |
+ ctx->inode_size);
|
|
|
e427d2 |
+ if (retval)
|
|
|
e427d2 |
+ fatal_err(retval, "while getting next inode");
|
|
|
e427d2 |
+ if (!ino)
|
|
|
e427d2 |
+ break;
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+ rewrite = 0;
|
|
|
e427d2 |
+ if (inode->i_flags & EXT4_EA_INODE_FL) {
|
|
|
e427d2 |
+ if (flags & REWRITE_EA_FL)
|
|
|
e427d2 |
+ rewrite = 1;
|
|
|
e427d2 |
+ } else if (LINUX_S_ISDIR(inode->i_mode)) {
|
|
|
e427d2 |
+ if (flags & REWRITE_DIR_FL)
|
|
|
e427d2 |
+ rewrite = 1;
|
|
|
e427d2 |
+ } else {
|
|
|
e427d2 |
+ if (flags & REWRITE_NONDIR_FL)
|
|
|
e427d2 |
+ rewrite = 1;
|
|
|
e427d2 |
+ }
|
|
|
e427d2 |
+ if (rewrite)
|
|
|
e427d2 |
+ rewrite_one_inode(ctx, ino, inode);
|
|
|
e427d2 |
+ } while (ino);
|
|
|
e427d2 |
+ ext2fs_close_inode_scan(scan);
|
|
|
e427d2 |
+ ext2fs_free_mem(&inode;;
|
|
|
e427d2 |
+}
|
|
|
e427d2 |
+
|
|
|
e427d2 |
+/*
|
|
|
e427d2 |
+ * Forcibly rewrite checksums in inodes specified by 'flags'
|
|
|
e427d2 |
+ */
|
|
|
e427d2 |
+static void rewrite_inodes(ext2_filsys fs, unsigned int flags)
|
|
|
e427d2 |
+{
|
|
|
e427d2 |
struct rewrite_context ctx = {
|
|
|
e427d2 |
.fs = fs,
|
|
|
e427d2 |
.inode_size = EXT2_INODE_SIZE(fs->super),
|
|
|
e427d2 |
};
|
|
|
e427d2 |
+ errcode_t retval;
|
|
|
e427d2 |
|
|
|
e427d2 |
if (fs->super->s_creator_os == EXT2_OS_HURD)
|
|
|
e427d2 |
return;
|
|
|
e427d2 |
|
|
|
e427d2 |
- retval = ext2fs_get_mem(ctx.inode_size, &inode;;
|
|
|
e427d2 |
- if (retval)
|
|
|
e427d2 |
- fatal_err(retval, "while allocating memory");
|
|
|
e427d2 |
-
|
|
|
e427d2 |
retval = ext2fs_get_memzero(ctx.inode_size, &ctx.zero_inode);
|
|
|
e427d2 |
if (retval)
|
|
|
e427d2 |
fatal_err(retval, "while allocating memory");
|
|
|
e427d2 |
@@ -858,39 +911,16 @@ static void rewrite_inodes(ext2_filsys fs)
|
|
|
e427d2 |
*
|
|
|
e427d2 |
* pass 2: go over other inodes to update their checksums.
|
|
|
e427d2 |
*/
|
|
|
e427d2 |
- if (ext2fs_has_feature_ea_inode(fs->super))
|
|
|
e427d2 |
- pass = 1;
|
|
|
e427d2 |
- else
|
|
|
e427d2 |
- pass = 2;
|
|
|
e427d2 |
- for (;pass <= 2; pass++) {
|
|
|
e427d2 |
- retval = ext2fs_open_inode_scan(fs, 0, &scan;;
|
|
|
e427d2 |
- if (retval)
|
|
|
e427d2 |
- fatal_err(retval, "while opening inode scan");
|
|
|
e427d2 |
-
|
|
|
e427d2 |
- do {
|
|
|
e427d2 |
- retval = ext2fs_get_next_inode_full(scan, &ino, inode,
|
|
|
e427d2 |
- ctx.inode_size);
|
|
|
e427d2 |
- if (retval)
|
|
|
e427d2 |
- fatal_err(retval, "while getting next inode");
|
|
|
e427d2 |
- if (!ino)
|
|
|
e427d2 |
- break;
|
|
|
e427d2 |
-
|
|
|
e427d2 |
- if (((pass == 1) &&
|
|
|
e427d2 |
- (inode->i_flags & EXT4_EA_INODE_FL)) ||
|
|
|
e427d2 |
- ((pass == 2) &&
|
|
|
e427d2 |
- !(inode->i_flags & EXT4_EA_INODE_FL)))
|
|
|
e427d2 |
- rewrite_one_inode(&ctx, ino, inode);
|
|
|
e427d2 |
- } while (ino);
|
|
|
e427d2 |
-
|
|
|
e427d2 |
- ext2fs_close_inode_scan(scan);
|
|
|
e427d2 |
- }
|
|
|
e427d2 |
+ if (ext2fs_has_feature_ea_inode(fs->super) && (flags & REWRITE_EA_FL))
|
|
|
e427d2 |
+ rewrite_inodes_pass(&ctx, REWRITE_EA_FL);
|
|
|
e427d2 |
+ flags &= ~REWRITE_EA_FL;
|
|
|
e427d2 |
+ rewrite_inodes_pass(&ctx, flags);
|
|
|
e427d2 |
|
|
|
e427d2 |
ext2fs_free_mem(&ctx.zero_inode);
|
|
|
e427d2 |
ext2fs_free_mem(&ctx.ea_buf);
|
|
|
e427d2 |
- ext2fs_free_mem(&inode;;
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
-static void rewrite_metadata_checksums(ext2_filsys fs)
|
|
|
e427d2 |
+static void rewrite_metadata_checksums(ext2_filsys fs, unsigned int flags)
|
|
|
e427d2 |
{
|
|
|
e427d2 |
errcode_t retval;
|
|
|
e427d2 |
dgrp_t i;
|
|
|
e427d2 |
@@ -902,7 +932,7 @@ static void rewrite_metadata_checksums(ext2_filsys fs)
|
|
|
e427d2 |
retval = ext2fs_read_bitmaps(fs);
|
|
|
e427d2 |
if (retval)
|
|
|
e427d2 |
fatal_err(retval, "while reading bitmaps");
|
|
|
e427d2 |
- rewrite_inodes(fs);
|
|
|
e427d2 |
+ rewrite_inodes(fs, flags);
|
|
|
e427d2 |
ext2fs_mark_ib_dirty(fs);
|
|
|
e427d2 |
ext2fs_mark_bb_dirty(fs);
|
|
|
e427d2 |
ext2fs_mmp_update2(fs, 1);
|
|
|
e427d2 |
@@ -1201,6 +1231,23 @@ mmp_error:
|
|
|
e427d2 |
uuid_generate((unsigned char *) sb->s_hash_seed);
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
+ if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX) &&
|
|
|
e427d2 |
+ ext2fs_has_feature_metadata_csum(sb)) {
|
|
|
e427d2 |
+ check_fsck_needed(fs,
|
|
|
e427d2 |
+ _("Disabling directory index on filesystem with "
|
|
|
e427d2 |
+ "checksums could take some time."));
|
|
|
e427d2 |
+ if (mount_flags & EXT2_MF_MOUNTED) {
|
|
|
e427d2 |
+ fputs(_("Cannot disable dir_index on a mounted "
|
|
|
e427d2 |
+ "filesystem!\n"), stderr);
|
|
|
e427d2 |
+ exit(1);
|
|
|
e427d2 |
+ }
|
|
|
e427d2 |
+ /*
|
|
|
e427d2 |
+ * Clearing dir_index on checksummed filesystem requires
|
|
|
e427d2 |
+ * rewriting all directories to update checksums.
|
|
|
e427d2 |
+ */
|
|
|
e427d2 |
+ rewrite_checksums |= REWRITE_DIR_FL;
|
|
|
e427d2 |
+ }
|
|
|
e427d2 |
+
|
|
|
e427d2 |
if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
|
|
|
e427d2 |
if (ext2fs_check_desc(fs)) {
|
|
|
e427d2 |
fputs(_("Clearing the flex_bg flag would "
|
|
|
e427d2 |
@@ -1244,7 +1291,7 @@ mmp_error:
|
|
|
e427d2 |
"The larger fields afforded by this feature "
|
|
|
e427d2 |
"enable full-strength checksumming. "
|
|
|
e427d2 |
"Run resize2fs -b to rectify.\n"));
|
|
|
e427d2 |
- rewrite_checksums = 1;
|
|
|
e427d2 |
+ rewrite_checksums = REWRITE_ALL;
|
|
|
e427d2 |
/* metadata_csum supersedes uninit_bg */
|
|
|
e427d2 |
ext2fs_clear_feature_gdt_csum(fs->super);
|
|
|
e427d2 |
|
|
|
e427d2 |
@@ -1272,7 +1319,7 @@ mmp_error:
|
|
|
e427d2 |
"filesystem!\n"), stderr);
|
|
|
e427d2 |
exit(1);
|
|
|
e427d2 |
}
|
|
|
e427d2 |
- rewrite_checksums = 1;
|
|
|
e427d2 |
+ rewrite_checksums = REWRITE_ALL;
|
|
|
e427d2 |
|
|
|
e427d2 |
/* Enable uninit_bg unless the user expressly turned it off */
|
|
|
e427d2 |
memcpy(test_features, old_features, sizeof(test_features));
|
|
|
e427d2 |
@@ -1454,7 +1501,7 @@ mmp_error:
|
|
|
e427d2 |
}
|
|
|
e427d2 |
check_fsck_needed(fs, _("Recalculating checksums "
|
|
|
e427d2 |
"could take some time."));
|
|
|
e427d2 |
- rewrite_checksums = 1;
|
|
|
e427d2 |
+ rewrite_checksums = REWRITE_ALL;
|
|
|
e427d2 |
}
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
@@ -3191,7 +3238,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
|
|
|
e427d2 |
check_fsck_needed(fs,
|
|
|
e427d2 |
_("Setting the UUID on this "
|
|
|
e427d2 |
"filesystem could take some time."));
|
|
|
e427d2 |
- rewrite_checksums = 1;
|
|
|
e427d2 |
+ rewrite_checksums = REWRITE_ALL;
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
if (ext2fs_has_group_desc_csum(fs)) {
|
|
|
e427d2 |
@@ -3302,7 +3349,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
|
|
|
e427d2 |
if (retval == 0) {
|
|
|
e427d2 |
printf(_("Setting inode size %lu\n"),
|
|
|
e427d2 |
new_inode_size);
|
|
|
e427d2 |
- rewrite_checksums = 1;
|
|
|
e427d2 |
+ rewrite_checksums = REWRITE_ALL;
|
|
|
e427d2 |
} else {
|
|
|
e427d2 |
printf("%s", _("Failed to change inode size\n"));
|
|
|
e427d2 |
rc = 1;
|
|
|
e427d2 |
@@ -3311,7 +3358,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
|
|
|
e427d2 |
}
|
|
|
e427d2 |
|
|
|
e427d2 |
if (rewrite_checksums)
|
|
|
e427d2 |
- rewrite_metadata_checksums(fs);
|
|
|
e427d2 |
+ rewrite_metadata_checksums(fs, rewrite_checksums);
|
|
|
e427d2 |
|
|
|
e427d2 |
if (l_flag)
|
|
|
e427d2 |
list_super(sb);
|
|
|
e427d2 |
--
|
|
|
e427d2 |
2.35.1
|
|
|
e427d2 |
|