All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: guarantee already started handles to successfully finish while ro remounting
@ 2016-05-02  0:50 Daeho Jeong
  2016-05-05 13:45 ` Jan Kara
  2016-05-05 15:44 ` Theodore Ts'o
  0 siblings, 2 replies; 11+ messages in thread
From: Daeho Jeong @ 2016-05-02  0:50 UTC (permalink / raw)
  To: tytso, linux-ext4; +Cc: Daeho Jeong, Kitae Lee

We check whether a new handle can be started through
ext4_journal_check_start() and the function refuses to start the handle
when the filesystem is mounted with read-only. But now, when we remount
the filesystem with read-only option, already started handles are
allowed to be written on disk, but the subsequent metadata modification
using the handles are refused by ext4_journal_check_start().

As an example, in ext4_evict_inode(), i_size can be set to 0 using
a successfully started handle, but, when we remount the filesystem
with read-only option at that time, the subsequent ext4_truncate()
will be failed and the filesystem integrity will be damaged.

Therefore, we need to permit the metadata modification using already
started handles to be proceeded, even if s_flags of the filesystem is
set to MS_RDONLY.

Kitae found the problem and suggested the solution.

Signed-off-by: Kitae Lee <kitae87.lee@samsung.com>
Signed-off-by: Daeho Jeong <daeho.jeong@samsung.com>
---
 fs/ext4/ext4_jbd2.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index e770c1ee..3b59e11 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -43,7 +43,7 @@ static int ext4_journal_check_start(struct super_block *sb)
 	journal_t *journal;
 
 	might_sleep();
-	if (sb->s_flags & MS_RDONLY)
+	if (sb->s_flags & MS_RDONLY && ext4_journal_current_handle() == NULL)
 		return -EROFS;
 	WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
 	journal = EXT4_SB(sb)->s_journal;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* Re: [PATCH] ext4: guarantee already started handles to successfully finish while ro remounting
@ 2016-05-06  5:35 Daeho Jeong
  0 siblings, 0 replies; 11+ messages in thread
From: Daeho Jeong @ 2016-05-06  5:35 UTC (permalink / raw)
  To: Jan Kara
  Cc: tytso, linux-ext4, 정대호, 이기태

> So can you share a reproducer for this issue? Because my initial thinking
> is that checks during remount should fail the remount with EBUSY if there
> is any modification outstanding... If they don't we have a racy remount and
> fs-freezing code, which is a bug.

Hi Jan,

Sorry to make you confused. My patch description was little wrong.
I meant only the emergency read-only remount case, not the normal read-only
remount case. Android is currently using emergency ro remount for the device
shutdown procedure.

We can easily reproduce this problem, but we didn't make a TC for xfstest yet.
If we did that, I will let you know.

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] ext4: guarantee already started handles to successfully finish while ro remounting
@ 2016-05-06  6:01 Daeho Jeong
  2016-05-06 13:00 ` Theodore Ts'o
  0 siblings, 1 reply; 11+ messages in thread
From: Daeho Jeong @ 2016-05-06  6:01 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: jack, linux-ext4, 이기태

> Hmm, I'm not really comfortable with putting this hack in, since this
> is papering over the real problem, which is that Android is trying to
> use the emergency remount read-only sysrq option and this is
> fundamentally unsafe.  I'm not sure what else could break if it is
> situation normal that there is active processes busily writing to the
> file system and sysrq-u followed by reboot is the normal way the
> Android kernel does a reboot.

> A much better solution would be to change the Android userspace to
> call the FIFREEZE ioctl on each mounted file system, and then call for
> a reboot.

I agree with you. I know that current Android shutdown procedure is
not a safe way. But, without this patch, "even not in Android system",
when we trigger the emergency read-only remount while evicting inodes,
i_size of the inode becomes zero and the inode is not in orphan list,
but blocks of the inode are still allocated to the inode, because
ext4_truncate() will fail while stating the handle which was already started
by ext4_evict_inode(). This causes the filesystem inconsistency and
we will encounter an ext4 kernel panic in the next boot by this problem.

I think that this kind of filesystem crash can occur anywhere that
the same journal handle is repeatly used. During an atomic filesystem
operation, a part of the operation will succeed and the other one will fail.

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] ext4: guarantee already started handles to successfully finish while ro remounting
@ 2016-05-07 13:05 Daeho Jeong
  2016-05-07 17:47 ` Theodore Ts'o
  0 siblings, 1 reply; 11+ messages in thread
From: Daeho Jeong @ 2016-05-07 13:05 UTC (permalink / raw)
  To: Theodore Ts'o
  Cc: jack, linux-ext4, 정대호, 이기태

> The real problem here is that we want emergency unmount to be
> completely safe, butting MS_RDONLY randomly isn't safe against file
> system corruption.  The idea is you do this only when you have no
> other choice, and the consequences would be worse --- and where you
> would be prepared to do a file system consistency check afterwards.

> We can either fix Android userspace, or we could add a per-file system
> callback which tries (as much as possible) to make an emergency
> unmount safe.  In this particular case, it would probably involve
> setting the "file system is corrupt flag" to force a file system
> consistency check at the next reboot.  Because if you use emergency
> unmount, all bets are off, and there may be other problems....

Actually, we had executed power on/off test repeatedly with 10 Android
devices for a month. But, during the test, just this problem only happened
repeatedly, even if it occurred very rarely. So we had concluded that we
had to fix this problem certainly.

However, I can see the point now. Android have misused the emergency
ro-remount and the filesystem crash by emergency ro-remount is not an issue.
I can understand the purpose of the emergency ro-remount.

I heard that the next version of Android will do full scan of ext4 filesystems
using e2fsck every boot-up, so the existing problem will be naturally resolved,
even if it might not be the right solution.

Thank you for your valuable comments.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-05-09  8:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02  0:50 [PATCH] ext4: guarantee already started handles to successfully finish while ro remounting Daeho Jeong
2016-05-05 13:45 ` Jan Kara
2016-05-05 15:44 ` Theodore Ts'o
2016-05-06  5:35 Daeho Jeong
2016-05-06  6:01 Daeho Jeong
2016-05-06 13:00 ` Theodore Ts'o
2016-05-06 20:01   ` Andreas Dilger
2016-05-06 23:36     ` tytso
2016-05-09  8:40       ` Jan Kara
2016-05-07 13:05 Daeho Jeong
2016-05-07 17:47 ` Theodore Ts'o

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.