e2fsck: fix checks done for mounted vs. read-only
PATCH 1/1 e2fsck: fix checks done for mounted vs. read-only
Currently, if e2fsck is run without the "-n" flag (i.e. it might modify the filesystem), there is no guarantee that it will open the filesystem with the EXCLUSIVE flag (i.e. O_EXCL) to prevent the block device from being checked (in most cases this means mounted, but it could also be an MD/LVM member device).
Conversely, if e2fsck is run with "-n" (i.e. read-only), and /etc/mtab or /proc/mounts does not report the block device as mounted then e2fsck thinks the filesystem is unmounted. In this case, e2fsck incorrectly sets the EXCLUSIVE flag, which causes the check to fail, even though e2fsck is running read-only.
To fix this, do not open with EXCLUSIVE if it is a read-only check, and always open with EXCLUSIVE if the filesystem might be changed. This also prevents filesystem mounts while e2fsck is running.
Also refuse allow e2fsck to run at all if the filesystem is BUSY. The e2fsck check_mount() was checking for MOUNTED, but not BUSY, and it should refuse to run outright if the block device is BUSY. The previous MOUNTED heuristics pre-date the O_EXCL reservation by the kernel, so there could be uncertainty due to stale /etc/mtab data, but with newer kernels a busy device should never be modified.
--- e2fsck/unix.c | 17 +++++++++-------- 1 files changed, 9 insertions(+), 8 deletions(-)
e2fsck/unix.c +9 -8
@@ -219,7 +219,7 @@ static void check_mount(e2fsck_t ctx)* filesystem and it's mounted read-only, and we're not doing * a read/write check, then everything's fine. */ -if ((!(ctx->mount_flags &EXT2_MF_MOUNTED )) || +if ((!(ctx->mount_flags & (EXT2_MF_MOUNTED |EXT2_MF_BUSY ))) || ((ctx->mount_flags &EXT2_MF_ISROOT ) && (ctx->mount_flags &EXT2_MF_READONLY ) && !(ctx->options &E2F_OPT_WRITECHECK )))
@@ -227,13 +227,16 @@ static void check_mount(e2fsck_t ctx)if ((ctx->options &E2F_OPT_READONLY ) && !(ctx->options &E2F_OPT_WRITECHECK )) { -log_out (ctx,_ ("Warning! %s is mounted.\n" ), - ctx->filesystem_name); +log_out (ctx,_ ("Warning! %s is %s.\n" ), + ctx->filesystem_name, + ctx->mount_flags &EXT2_MF_MOUNTED ? +"mounted" :"in use" );return ; } -log_out (ctx,_ ("%s is mounted. " ), ctx->filesystem_name); -if (!ctx->interactive) +log_out (ctx,_ ("%s is %s.\n" ), ctx->filesystem_name, + ctx->mount_flags &EXT2_MF_MOUNTED ?"mounted" :"in use" ); +if (!ctx->interactive || ctx->mount_flags &EXT2_MF_BUSY )fatal_error (ctx,_ ("Cannot continue, aborting.\n\n" ));puts ("\007\007\007\007" ); log_out(ctx, _("\n\nWARNING!!! "
@@ -1219,9 +1222,7 @@ restart:if (!old_bitmaps) flags |=EXT2_FLAG_64BITS ;if ((ctx->options &E2F_OPT_READONLY ) ==0 ) - flags |=EXT2_FLAG_RW ; -if ((ctx->mount_flags &EXT2_MF_MOUNTED ) ==0 ) - flags |=EXT2_FLAG_EXCLUSIVE ; + flags |=EXT2_FLAG_RW |EXT2_FLAG_EXCLUSIVE ; retval =try_open_fs (ctx, flags, io_ptr, &fs);
Signature · 1 line
1.7.3.4
Ted Ts'o
AppliedQuoted 16 lines · Andreas Dilger
Currently, if e2fsck is run without the "-n" flag (i.e. it might modify the filesystem), there is no guarantee that it will open the filesystem with the EXCLUSIVE flag (i.e.
O_EXCL) to prevent the block device from being checked (in most cases this means mounted, but it could also be an MD/LVM member device).Conversely, if e2fsck is run with "-n" (i.e. read-only), and
/etc/mtabor/proc/mountsdoes not report the block device as mounted then e2fsck thinks the filesystem is unmounted. In this case, e2fsck incorrectly sets the EXCLUSIVE flag, which causes the check to fail, even though e2fsck is running read-only.To fix this, do not open with EXCLUSIVE if it is a read-only check, and always open with EXCLUSIVE if the filesystem might be changed. This also prevents filesystem mounts while e2fsck is running.
Quoted 8 lines
Also refuse allow e2fsck to run at all if the filesystem is BUSY. The e2fsck
check_mount()was checking for MOUNTED, but not BUSY, and it should refuse to run outright if the block device is BUSY. The previous MOUNTED heuristics pre-date theO_EXCLreservation by the kernel, so there could be uncertainty due to stale/etc/mtabdata, but with newer kernels a busy device should never be modified.Signed-off-by Andreas Dilger <[email protected]>
Thanks, applied.
- Ted
Quoted 24 lines · Ted Ts'o
Quoted 23 lines · Andreas Dilger
Currently, if e2fsck is run without the "-n" flag (i.e. it might modify the filesystem), there is no guarantee that it will open the filesystem with the EXCLUSIVE flag (i.e.
O_EXCL) to prevent the block device from being checked (in most cases this means mounted, but it could also be an MD/LVM member device).Conversely, if e2fsck is run with "-n" (i.e. read-only), and
/etc/mtabor/proc/mountsdoes not report the block device as mounted then e2fsck thinks the filesystem is unmounted. In this case, e2fsck incorrectly sets the EXCLUSIVE flag, which causes the check to fail, even though e2fsck is running read-only.To fix this, do not open with EXCLUSIVE if it is a read-only check, and always open with EXCLUSIVE if the filesystem might be changed. This also prevents filesystem mounts while e2fsck is running.
Also refuse allow e2fsck to run at all if the filesystem is BUSY. The e2fsck
check_mount()was checking for MOUNTED, but not BUSY, and it should refuse to run outright if the block device is BUSY. The previous MOUNTED heuristics pre-date theO_EXCLreservation by the kernel, so there could be uncertainty due to stale/etc/mtabdata, but with newer kernels a busy device should never be modified.
Quoted 3 lines
Quoted 1 line
Signed-off-by Andreas Dilger <[email protected]>Thanks, applied.
In late-breaking news, this change prevents checking the root filesystem at mount time, because the device is BUSY, and all filesystem-modifying checks use O_EXCL...
This was not a problem with our original patch, but I had changed it in discussion with Eric to prevent people from shooting themselves in the foot when bypassing "The filesystem is mounted. Do you really want to continue (y/n)?" questions and corrupting their filesystem. The revised patch tested correctly on mounted and unmounted regular filesystems, but breaks for the root fs.
Please revert this patch, and I'll come up with a better one.
Cheers, Andreas
--
Andreas Dilger Whamcloud, Inc.
Principal Lustre Engineer http://www.whamcloud.com/
PATCH 1/1 e2fsck: allow checking on mounted root filesystem
In reply to Andreas DilgerCommit 732e26b98e5c79a4298dbe341f43b54b354bb241 added checks to prevent e2fsck from being run in filesystem-modifying mode against a mounted or otherwise busy device, due to several bug reports of users doing this even with the verbose warnings in check_mount().
However, it also prevented e2fsck from checking a mounted root filesystem, which will prevent the node from booting. Once again allow e2fsck to run against the mounted root filesystem.
--- e2fsck/unix.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
e2fsck/unix.c +5 -2
@@ -1221,8 +1221,11 @@ restart: &old_bitmaps);if (!old_bitmaps) flags |=EXT2_FLAG_64BITS ; -if ((ctx->options &E2F_OPT_READONLY ) ==0 ) - flags |=EXT2_FLAG_RW |EXT2_FLAG_EXCLUSIVE ; +if ((ctx->options &E2F_OPT_READONLY ) ==0 ) { + flags |=EXT2_FLAG_RW ; +if (!(ctx->mount_flags &EXT2_MF_ISROOT )) + flags |=EXT2_FLAG_EXCLUSIVE ; + } retval =try_open_fs (ctx, flags, io_ptr, &fs);
Signature · 1 line
1.7.3.4
PATCH 1/1 e2fsck: allow checking on mounted root fs (v2)
Commit 732e26b98e5c79a4298dbe341f43b54b354bb241 added checks to prevent e2fsck from being run in filesystem-modifying mode against a mounted or otherwise busy device, due to several bug reports of users doing this even with the verbose warnings in check_mount().
However, it also prevented e2fsck from checking a mounted root filesystem, which will prevent the node from booting. Once again allow e2fsck to run against the mounted root filesystem if it is also mounted read-only at the time.
--- e2fsck/unix.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
e2fsck/unix.c +6 -2
@@ -1221,8 +1221,12 @@ restart: &old_bitmaps);if (!old_bitmaps) flags |=EXT2_FLAG_64BITS ; -if ((ctx->options &E2F_OPT_READONLY ) ==0 ) - flags |=EXT2_FLAG_RW |EXT2_FLAG_EXCLUSIVE ; +if ((ctx->options &E2F_OPT_READONLY ) ==0 ) { + flags |=EXT2_FLAG_RW ; +if (!(ctx->mount_flags &EXT2_MF_ISROOT && + ctx->mount_flags &EXT2_MF_READONLY )) + flags |=EXT2_FLAG_EXCLUSIVE ; + } retval =try_open_fs (ctx, flags, io_ptr, &fs);
Signature · 1 line
1.7.3.4
Re: [PATCH] e2fsck: allow checking on mounted root filesystem
In reply to Andreas DilgerQuoted 19 lines · Andreas Dilger
Commit
732e26b98e5c79a4298dbe341f43b54b354bb241added checks to prevent e2fsck from being run in filesystem-modifying mode against a mounted or otherwise busy device, due to several bug reports of users doing this even with the verbose warnings incheck_mount().However, it also prevented e2fsck from checking a mounted root filesystem, which will prevent the node from booting. Once again allow e2fsck to run against the mounted root filesystem.
Signed-off-by Andreas Dilger <[email protected]>---
e2fsck/unix.c| 7 +++++--1 files changed, 5 insertions(+), 2 deletions(-)e2fsck/unix.c +0
-0
e2fsck/unix.c restart: · line 1228
Quoted 10 lines
e2fsck/unix.c +5
-2@@ -1221,8 +1221,11 @@ restart: &old_bitmaps);if (!old_bitmaps) flags |=EXT2_FLAG_64BITS ; -if ((ctx->options &E2F_OPT_READONLY ) ==0 ) - flags |=EXT2_FLAG_RW |EXT2_FLAG_EXCLUSIVE ; +if ((ctx->options &E2F_OPT_READONLY ) ==0 ) { + flags |=EXT2_FLAG_RW ; +if (!(ctx->mount_flags &EXT2_MF_ISROOT )) + flags |=EXT2_FLAG_EXCLUSIVE ; + }
This should further exclude root filesystems that are not mounted read-only. Another patch on the way.
Cheers, Andreas
--
Andreas Dilger Whamcloud, Inc.
Principal Lustre Engineer http://www.whamcloud.com/
Ted Ts'o
AppliedRe: [PATCH] e2fsck: allow checking on mounted root fs (v2)
In reply to Andreas DilgerQuoted 11 lines · Andreas Dilger
Commit
732e26b98e5c79a4298dbe341f43b54b354bb241added checks to prevent e2fsck from being run in filesystem-modifying mode against a mounted or otherwise busy device, due to several bug reports of users doing this even with the verbose warnings incheck_mount().However, it also prevented e2fsck from checking a mounted root filesystem, which will prevent the node from booting. Once again allow e2fsck to run against the mounted root filesystem if it is also mounted read-only at the time.
Signed-off-by Andreas Dilger <[email protected]>
Thanks, applied.
- Ted