Skip to contentSkip to conversation

tune2fs: warn if the filesystem journal is dirty

PATCH In review Andreas Dilger 2 participants 2 messages Sep 12, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tune2fs: warn if the filesystem journal is dirty

From: Jim Garlick <[email protected]>

Running tune2fs on a filesystem with an unrecovered journal can cause the tune2fs settings changes in the superblock to be reverted when the journal is replayed if it contains an uncommitted copy of the superblock. Print a warning if this is detected so that the user isn't surprised if it happens.

---
 misc/tune2fs.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
misc/tune2fs.c +12 -0
index b65dab9..e5ec8a4 100644
@@ -2395,6 +2395,7 @@ retry_open:
 		ext2fs_mark_super_dirty(fs);
 		printf(_("Setting stripe width to %d\n"), stripe_width);
 	}
+
 	if (ext_mount_opts) {
 		strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
 			sizeof(fs->super->s_mount_opts));
@@ -2404,6 +2405,17 @@ retry_open:
 		       ext_mount_opts);
 		free(ext_mount_opts);
 	}
+
+	/* Warn if file system needs recovery and it is opened for writing. */
+	if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
+	    (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
+	    (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER)) {
+		fprintf(stderr,
+			_("Warning: needs_recovery flag is set. You may wish\n"
+			  "replay the journal then rerun this command, or any\n"
+			  "changes may be overwritten by journal recovery.\n"));
+	}
+
 	free(device_name);
 	remove_error_table(&et_ext2_error_table);
 
Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 29 lines · Andreas Dilger

From: Jim Garlick <[email protected]>

Running tune2fs on a filesystem with an unrecovered journal can cause the tune2fs settings changes in the superblock to be reverted when the journal is replayed if it contains an uncommitted copy of the superblock. Print a warning if this is detected so that the user isn't surprised if it happens.

---
 misc/tune2fs.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
misc/tune2fs.c +1 -0
index b65dab9..e5ec8a4 100644
@@ -2395,6 +2395,7 @@ retry_open:
 		ext2fs_mark_super_dirty(fs);
 		printf(_("Setting stripe width to %d\n"), stripe_width);
 	}
+
 	if (ext_mount_opts) {
 		strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
 			sizeof(fs->super->s_mount_opts));
@@ -2404,6 +2405,17 @@ retry_open:
 		       ext_mount_opts);
 		free(ext_mount_opts);

misc/tune2fs.c retry_open: · line 2416

Quoted 10 lines
misc/tune2fs.c +9 -0
 	}
+
+	/* Warn if file system needs recovery and it is opened for writing. */
+	if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
+	    (sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
+	    (sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER)) {
+		fprintf(stderr,
+			_("Warning: needs_recovery flag is set. You may wish\n"
+			  "replay the journal then rerun this command, or any\n"
+			  "changes may be overwritten by journal recovery.\n"));

At a bare minimum this ought to be "You may wish *to* replay...", but I suggest:

"You should replay the journal and then rerun this command because it is possible that your changes will be overwritten by the journal recovery."

Otherwise looks fine to me.

--D

Quoted 12 lines
misc/tune2fs.c +2 -0
+	}
+
 	free(device_name);
 	remove_error_table(&et_ext2_error_table);
 
Signature · 6 lines
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html