Commit f25391eb authored by Lukas Czerner's avatar Lukas Czerner Committed by Theodore Ts'o

ext4: handle option set by mount flags correctly

Currently there is a problem with mount options that can be both set by
vfs using mount flags or by a string parsing in ext4.

i_version/iversion options gets lost after remount, for example

$ mount -o i_version /dev/pmem0 /mnt
$ grep pmem0 /proc/self/mountinfo | grep i_version
310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,seclabel,i_version
$ mount -o remount,ro /mnt
$ grep pmem0 /proc/self/mountinfo | grep i_version

nolazytime gets ignored by ext4 on remount, for example

$ mount -o lazytime /dev/pmem0 /mnt
$ grep pmem0 /proc/self/mountinfo | grep lazytime
310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,lazytime,seclabel
$ mount -o remount,nolazytime /mnt
$ grep pmem0 /proc/self/mountinfo | grep lazytime
310 95 259:0 / /mnt rw,relatime shared:163 - ext4 /dev/pmem0 rw,lazytime,seclabel

Fix it by applying the SB_LAZYTIME and SB_I_VERSION flags from *flags to
s_flags before we parse the option and use the resulting state of the
same flags in *flags at the end of successful remount.
Signed-off-by: default avatarLukas Czerner <lczerner@redhat.com>
Reviewed-by: default avatarRitesh Harjani <riteshh@linux.ibm.com>
Link: https://lore.kernel.org/r/20200723150526.19931-1-lczerner@redhat.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 60ed633f
...@@ -5512,7 +5512,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) ...@@ -5512,7 +5512,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
{ {
struct ext4_super_block *es; struct ext4_super_block *es;
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
unsigned long old_sb_flags; unsigned long old_sb_flags, vfs_flags;
struct ext4_mount_options old_opts; struct ext4_mount_options old_opts;
int enable_quota = 0; int enable_quota = 0;
ext4_group_t g; ext4_group_t g;
...@@ -5555,6 +5555,14 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) ...@@ -5555,6 +5555,14 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
if (sbi->s_journal && sbi->s_journal->j_task->io_context) if (sbi->s_journal && sbi->s_journal->j_task->io_context)
journal_ioprio = sbi->s_journal->j_task->io_context->ioprio; journal_ioprio = sbi->s_journal->j_task->io_context->ioprio;
/*
* Some options can be enabled by ext4 and/or by VFS mount flag
* either way we need to make sure it matches in both *flags and
* s_flags. Copy those selected flags from *flags to s_flags
*/
vfs_flags = SB_LAZYTIME | SB_I_VERSION;
sb->s_flags = (sb->s_flags & ~vfs_flags) | (*flags & vfs_flags);
if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) { if (!parse_options(data, sb, NULL, &journal_ioprio, 1)) {
err = -EINVAL; err = -EINVAL;
goto restore_opts; goto restore_opts;
...@@ -5608,9 +5616,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) ...@@ -5608,9 +5616,6 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
set_task_ioprio(sbi->s_journal->j_task, journal_ioprio); set_task_ioprio(sbi->s_journal->j_task, journal_ioprio);
} }
if (*flags & SB_LAZYTIME)
sb->s_flags |= SB_LAZYTIME;
if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) { if ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) { if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) {
err = -EROFS; err = -EROFS;
...@@ -5758,7 +5763,13 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) ...@@ -5758,7 +5763,13 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
} }
#endif #endif
*flags = (*flags & ~SB_LAZYTIME) | (sb->s_flags & SB_LAZYTIME); /*
* Some options can be enabled by ext4 and/or by VFS mount flag
* either way we need to make sure it matches in both *flags and
* s_flags. Copy those selected flags from s_flags to *flags
*/
*flags = (*flags & ~vfs_flags) | (sb->s_flags & vfs_flags);
ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data); ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
kfree(orig_data); kfree(orig_data);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment