tune2fs: don't recover journal if device is busy.
PATCH 1/1 tune2fs: don't recover journal if device is busy.
tune2fs currently replays the journal if it needs
recovery and the filesystem isn't mounted.
The test for "is the filesystem mounted" isn't completely robust. Lustre makes use of ext4 filesystems in a way that they are mounted without being visible in /proc/mounts or similar.
This usage can easily be detected by attempting to open the device with O_EXCL. tune2fs already does this and the EXT2_MF_BUSY flag is set if open(O_EXCL) fails.
Several uses other than lustre mounts could cause O_EXCL to fail, but in any case it seems unwise to recover the journal when something else is keeping the device busy.
So add an extra test to avoid journal recovery when the device is busy. This fixes some problems with lustre usage.
--
Note: it seems wrong to recover the journal *after* making changes to the superblock - there is a good chance that recovering the journal will over-write those changes. This is what was happening that lead me to this problem. Shouldn't journal recovery happen *first*??
Thanks,
NeilBrown
--- misc/tune2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
misc/tune2fs.c +1 -1
@@ -3337,7 +3337,7 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" }#else /* Recover the journal if possible. */ -if ((open_flag &EXT2_FLAG_RW ) && !(mount_flags &EXT2_MF_MOUNTED ) && +if ((open_flag &EXT2_FLAG_RW ) && !(mount_flags & (EXT2_MF_BUSY |EXT2_MF_MOUNTED )) &&ext2fs_has_feature_journal_needs_recovery (fs->super)) {errcode_t err;
Signature · 1 line
2.14.0.rc0.dirty
_______________________________________________
lustre-devel mailing list [email protected]
http://lists.lustre.org/listinfo.cgi/lustre-devel-lustre.org
Quoted 17 lines · NeilBrown
tune2fs currently replays the journal if it needs
recovery and the filesystem isn't mounted.The test for "is the filesystem mounted" isn't completely robust. Lustre makes use of ext4 filesystems in a way that they are mounted without being visible in
/proc/mountsor similar.
This usage can easily be detected by attempting to open the device withO_EXCL. tune2fs already does this and theEXT2_MF_BUSYflag is set ifopen(O_EXCL)fails.
Several uses other than lustre mounts could causeO_EXCLto fail, but in any case it seems unwise to recover the journal when something else is keeping the device busy.So add an extra test to avoid journal recovery when the device is busy. This fixes some problems with lustre usage.
Quoted 8 lines
Signed-off-by NeilBrown <[email protected]>--
Note: it seems wrong to recover the journal *after* making changes to the superblock - there is a good chance that recovering the journal will over-write those changes. This is what was happening that lead me to this problem. Shouldn't journal recovery happen *first*??
Yes. Oops. :/
This whole hunk ought to move up to be right after ext2fs_check_if_mounted, I think.
As for this patch itself,
--D
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 32 lines · Theodore Ts'o
Quoted 10 lines · Darrick J. Wong
Quoted 5 lines
Note: it seems wrong to recover the journal *after* making changes to the superblock - there is a good chance that recovering the journal will over-write those changes. This is what was happening that lead me to this problem. Shouldn't journal recovery happen *first*??
Yes. Oops. :/
This whole hunk ought to move up to be right after
ext2fs_check_if_mounted, I think.After I did that, the test
t_replay_and_setstarted failing. The problem is that the test deliberately corrupts all of the inode and block bitmaps by writing bogus journal entries. When tune2fs replays the journal, it ends up smashing the inode and block bitmaps; but then when it tries to rewrite checksums, the fact that inode bitmap is completely zeroed out means all of the inode entries are also cleared
out. Oops!This normally isn't supposed to happen because
check_fsck_needed()is not supposed to allow us to do dangerous things that require rewriting checksums unless the file system is freshly checked.But the way the test was constructed the superblock's last mount time is still 0, since the file system was never mounted. By definition, though, if there is a journal to be replayed, the file system has been mounted, and hence must be checked. Once fixed I this to force
s_lastcheckto be always less thans_mtimeaafter replaying the journal, then thet_replay_and_settest would fail because it's not safe to run "tune2fs -O ^metadata_csum" without running e2fsck first.
Quoted 5 lines
So I'll change the test to set the file system label instead doing something more dangerous like clear the metadata checksum feature. Was there someone who really wanted to be able to execute "tune2fs -O ^metadata_csum" on a file system with a dirty journal w/o running e2fsck first?
No, I didn't have a specific user in mind. Frankly I doubt there will be very many people who want to turn *off* that feature, but for those who do so to a dirty fs we could replay the journal first.
(Though let's be honest, if you're going to tune2fs you really ought to e2fsck before just to make sure the fs is ok...)
--D
Quoted 2 lines
- Ted