Skip to contentSkip to conversation

exfat: call sync_filesystem for read-only remount

PATCH Superseded Hyunchul Lee 2 participants 7 messages Jun 12, 2020 – Jun 15, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 exfat: call sync_filesystem for read-only remount

We need to commit dirty metadata and pages to disk before remounting exfat as read-only.

This fixes a failure in xfstests generic/452

---
 fs/exfat/super.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
fs/exfat/super.c +19 -0
index e650e65536f8..61c6cf240c19 100644
@@ -693,10 +693,29 @@ static void exfat_free(struct fs_context *fc)
 	}
 }
 
+static int exfat_reconfigure(struct fs_context *fc)
+{
+	struct super_block *sb = fc->root->d_sb;
+	int ret;
+	bool new_rdonly;
+
+	new_rdonly = fc->sb_flags & SB_RDONLY;
+	if (new_rdonly != sb_rdonly(sb)) {
+		if (new_rdonly) {
+			/* volume flag will be updated in exfat_sync_fs */
+			ret = sync_filesystem(sb);
+			if (ret < 0)
+				return ret;
+		}
+	}
+	return 0;
+}
+
 static const struct fs_context_operations exfat_context_ops = {
 	.parse_param	= exfat_parse_param,
 	.get_tree	= exfat_get_tree,
 	.free		= exfat_free,
+	.reconfigure	= exfat_reconfigure,
 };
 
 static int exfat_init_fs_context(struct fs_context *fc)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 exfat: allow to change some mount options for remount

Allow to change permission masks, allow_utime,
errors. But ignore other options.

---
 fs/exfat/super.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
fs/exfat/super.c +29 -11
index 61c6cf240c19..3c1d47289ba2 100644
@@ -696,9 +696,13 @@ static void exfat_free(struct fs_context *fc)
 static int exfat_reconfigure(struct fs_context *fc)
 {
 	struct super_block *sb = fc->root->d_sb;
+	struct exfat_sb_info *sbi = EXFAT_SB(sb);
+	struct exfat_mount_options *new_opts;
 	int ret;
 	bool new_rdonly;
 
+	new_opts = &((struct exfat_sb_info *)fc->s_fs_info)->options;
+
 	new_rdonly = fc->sb_flags & SB_RDONLY;
 	if (new_rdonly != sb_rdonly(sb)) {
 		if (new_rdonly) {
@@ -708,6 +712,12 @@ static int exfat_reconfigure(struct fs_context *fc)
 				return ret;
 		}
 	}
+
+	/* allow to change these options but ignore others */
+	sbi->options.fs_fmask = new_opts->fs_fmask;
+	sbi->options.fs_dmask = new_opts->fs_dmask;
+	sbi->options.allow_utime = new_opts->allow_utime;
+	sbi->options.errors = new_opts->errors;
 	return 0;
 }
 
@@ -726,17 +736,25 @@ static int exfat_init_fs_context(struct fs_context *fc)
 	if (!sbi)
 		return -ENOMEM;
 
-	mutex_init(&sbi->s_lock);
-	ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
-			DEFAULT_RATELIMIT_BURST);
-
-	sbi->options.fs_uid = current_uid();
-	sbi->options.fs_gid = current_gid();
-	sbi->options.fs_fmask = current->fs->umask;
-	sbi->options.fs_dmask = current->fs->umask;
-	sbi->options.allow_utime = -1;
-	sbi->options.iocharset = exfat_default_iocharset;
-	sbi->options.errors = EXFAT_ERRORS_RO;
+	if (fc->root) {
+		/* reconfiguration */
+		memcpy(&sbi->options, &EXFAT_SB(fc->root->d_sb)->options,
+			sizeof(struct exfat_mount_options));
+		sbi->options.iocharset = exfat_default_iocharset;
+	} else {
+		mutex_init(&sbi->s_lock);
+		ratelimit_state_init(&sbi->ratelimit,
+				DEFAULT_RATELIMIT_INTERVAL,
+				DEFAULT_RATELIMIT_BURST);
+
+		sbi->options.fs_uid = current_uid();
+		sbi->options.fs_gid = current_gid();
+		sbi->options.fs_fmask = current->fs->umask;
+		sbi->options.fs_dmask = current->fs->umask;
+		sbi->options.allow_utime = -1;
+		sbi->options.iocharset = exfat_default_iocharset;
+		sbi->options.errors = EXFAT_ERRORS_RO;
+	}
 
 	fc->s_fs_info = sbi;
 	fc->ops = &exfat_context_ops;
Signature · 1 line
2.17.1
#2 lore raw

RE: [PATCH 2/2] exfat: allow to change some mount options for remount

Quoted 24 lines

Allow to change permission masks, allow_utime, errors. But ignore other options.

---
 fs/exfat/super.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
fs/exfat/super.c +4 -0
@@ -696,9 +696,13 @@ static void exfat_free(struct fs_context *fc)  static int
 exfat_reconfigure(struct fs_context *fc)  {
 	struct super_block *sb = fc->root->d_sb;
+	struct exfat_sb_info *sbi = EXFAT_SB(sb);
+	struct exfat_mount_options *new_opts;
 	int ret;
 	bool new_rdonly;
 
+	new_opts = &((struct exfat_sb_info *)fc->s_fs_info)->options;
+
 	new_rdonly = fc->sb_flags & SB_RDONLY;
 	if (new_rdonly != sb_rdonly(sb)) {
 		if (new_rdonly) {

fs/exfat/super.c static int exfat_reconfigure(struct fs_context *fc) · line 720

Quoted 9 lines
fs/exfat/super.c +6 -0
@@ -708,6 +712,12 @@ static int exfat_reconfigure(struct fs_context *fc)
 				return ret;
 		}
 	}
+
+	/* allow to change these options but ignore others */
+	sbi->options.fs_fmask = new_opts->fs_fmask;
+	sbi->options.fs_dmask = new_opts->fs_dmask;
+	sbi->options.allow_utime = new_opts->allow_utime;
+	sbi->options.errors = new_opts->errors;

Is there any reason why you allow a few options on remount ?

Quoted 42 lines
fs/exfat/super.c +19 -12
 	return 0;
 }
 
@@ -726,17 +736,25 @@ static int exfat_init_fs_context(struct fs_context *fc)
 	if (!sbi)
 		return -ENOMEM;
 
-	mutex_init(&sbi->s_lock);
-	ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
-			DEFAULT_RATELIMIT_BURST);
-
-	sbi->options.fs_uid = current_uid();
-	sbi->options.fs_gid = current_gid();
-	sbi->options.fs_fmask = current->fs->umask;
-	sbi->options.fs_dmask = current->fs->umask;
-	sbi->options.allow_utime = -1;
-	sbi->options.iocharset = exfat_default_iocharset;
-	sbi->options.errors = EXFAT_ERRORS_RO;
+	if (fc->root) {
+		/* reconfiguration */
+		memcpy(&sbi->options, &EXFAT_SB(fc->root->d_sb)->options,
+			sizeof(struct exfat_mount_options));
+		sbi->options.iocharset = exfat_default_iocharset;
+	} else {
+		mutex_init(&sbi->s_lock);
+		ratelimit_state_init(&sbi->ratelimit,
+				DEFAULT_RATELIMIT_INTERVAL,
+				DEFAULT_RATELIMIT_BURST);
+
+		sbi->options.fs_uid = current_uid();
+		sbi->options.fs_gid = current_gid();
+		sbi->options.fs_fmask = current->fs->umask;
+		sbi->options.fs_dmask = current->fs->umask;
+		sbi->options.allow_utime = -1;
+		sbi->options.iocharset = exfat_default_iocharset;
+		sbi->options.errors = EXFAT_ERRORS_RO;
+	}
 
 	fc->s_fs_info = sbi;
 	fc->ops = &exfat_context_ops;
--

2.17.1

#3 lore raw

Re: [PATCH 2/2] exfat: allow to change some mount options for remount

2020년 6월 15일 (월) 오전 9:18, Namjae Jeon <[email protected]>님이 작성:

Quoted 19 lines
Quoted 19 lines

Allow to change permission masks, allow_utime, errors. But ignore other options.

---
 fs/exfat/super.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
fs/exfat/super.c +2 -0
@@ -696,9 +696,13 @@ static void exfat_free(struct fs_context *fc)  static int
 exfat_reconfigure(struct fs_context *fc)  {
      struct super_block *sb = fc->root->d_sb;
+     struct exfat_sb_info *sbi = EXFAT_SB(sb);
+     struct exfat_mount_options *new_opts;
      int ret;
      bool new_rdonly;
 
Quoted 16 lines
Quoted 6 lines
fs/exfat/super.c +2 -0
+     new_opts = &((struct exfat_sb_info *)fc->s_fs_info)->options;
+
      new_rdonly = fc->sb_flags & SB_RDONLY;
      if (new_rdonly != sb_rdonly(sb)) {
              if (new_rdonly) {

fs/exfat/super.c static int exfat_reconfigure(struct fs_context *fc) · line 720

Quoted 9 lines
fs/exfat/super.c +6 -0
@@ -708,6 +712,12 @@ static int exfat_reconfigure(struct fs_context *fc)
                              return ret;
              }
      }
+
+     /* allow to change these options but ignore others */
+     sbi->options.fs_fmask = new_opts->fs_fmask;
+     sbi->options.fs_dmask = new_opts->fs_dmask;
+     sbi->options.allow_utime = new_opts->allow_utime;
+     sbi->options.errors = new_opts->errors;

Is there any reason why you allow a few options on remount ?

while exfat is remounted, inodes are not reclaimed. So I think changing fs_uid, fs_gid, or time_offset is not impossible. And I am not sure changing the iocharset is safe.

I am curious about your opinion.

Thanks.

Quoted 44 lines
Quoted 42 lines
fs/exfat/super.c +19 -12
      return 0;
 }
 
@@ -726,17 +736,25 @@ static int exfat_init_fs_context(struct fs_context *fc)
      if (!sbi)
              return -ENOMEM;
 
-     mutex_init(&sbi->s_lock);
-     ratelimit_state_init(&sbi->ratelimit, DEFAULT_RATELIMIT_INTERVAL,
-                     DEFAULT_RATELIMIT_BURST);
-
-     sbi->options.fs_uid = current_uid();
-     sbi->options.fs_gid = current_gid();
-     sbi->options.fs_fmask = current->fs->umask;
-     sbi->options.fs_dmask = current->fs->umask;
-     sbi->options.allow_utime = -1;
-     sbi->options.iocharset = exfat_default_iocharset;
-     sbi->options.errors = EXFAT_ERRORS_RO;
+     if (fc->root) {
+             /* reconfiguration */
+             memcpy(&sbi->options, &EXFAT_SB(fc->root->d_sb)->options,
+                     sizeof(struct exfat_mount_options));
+             sbi->options.iocharset = exfat_default_iocharset;
+     } else {
+             mutex_init(&sbi->s_lock);
+             ratelimit_state_init(&sbi->ratelimit,
+                             DEFAULT_RATELIMIT_INTERVAL,
+                             DEFAULT_RATELIMIT_BURST);
+
+             sbi->options.fs_uid = current_uid();
+             sbi->options.fs_gid = current_gid();
+             sbi->options.fs_fmask = current->fs->umask;
+             sbi->options.fs_dmask = current->fs->umask;
+             sbi->options.allow_utime = -1;
+             sbi->options.iocharset = exfat_default_iocharset;
+             sbi->options.errors = EXFAT_ERRORS_RO;
+     }
 
      fc->s_fs_info = sbi;
      fc->ops = &exfat_context_ops;
--

2.17.1

#4 lore raw
In reply to Hyunchul Lee

Hi Hyunchul,

Quoted 3 lines

We need to commit dirty metadata and pages to disk before remounting exfat as read-only.

This fixes a failure in xfstests generic/452

Could you please elaborate more the reason why generic/452 in xfstests failed ?

Quoted 10 lines
---
 fs/exfat/super.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 698

Quoted 6 lines
fs/exfat/super.c +3 -0
@@ -693,10 +693,29 @@ static void exfat_free(struct fs_context *fc)
 	}
 }
 
+static int exfat_reconfigure(struct fs_context *fc) {
+	struct super_block *sb = fc->root->d_sb;
+	int ret;

int ret = 0;

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 703

Quoted 4 lines
fs/exfat/super.c +4 -0
+	bool new_rdonly;
+
+	new_rdonly = fc->sb_flags & SB_RDONLY;
+	if (new_rdonly != sb_rdonly(sb)) {

If you modify it like this, would not we need new_rdonly?

        if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb))

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 708

Quoted 5 lines
fs/exfat/super.c +5 -0
+		if (new_rdonly) {
+			/* volume flag will be updated in exfat_sync_fs */
+			ret = sync_filesystem(sb);
+			if (ret < 0)
+				return ret;

I think that this ret check can be removed by using return ret; below ?

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 711

Quoted 3 lines
fs/exfat/super.c +3 -0
+		}
+	}
+	return 0;

return ret;

Quoted 12 lines
fs/exfat/super.c +3 -1
+}
+
 static const struct fs_context_operations exfat_context_ops = {
 	.parse_param	= exfat_parse_param,
 	.get_tree	= exfat_get_tree,
 	.free		= exfat_free,
+	.reconfigure	= exfat_reconfigure,
 };
 
 static int exfat_init_fs_context(struct fs_context *fc)
--

2.17.1

#5 lore raw

Hi Namjae,

2020년 6월 15일 (월) 오전 9:14, Namjae Jeon <[email protected]>님이 작성:

Quoted 6 lines

Hi Hyunchul,

Quoted 3 lines

We need to commit dirty metadata and pages to disk before remounting exfat as read-only.

This fixes a failure in xfstests generic/452

Could you please elaborate more the reason why generic/452 in xfstests failed ?

xfstests generic/452 does the following.
cp /bin/ls <exfat>/
mount -o remount,ro <exfat>

the <exfat>/ls file is corrupted, because while exfat is remounted as read-only, exfat doesn't have a chance to commit metadata and vfs invalidates page caches in a block device.

I will put this explanation in a commit message.

Quoted 17 lines
Quoted 10 lines
---
 fs/exfat/super.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 698

Quoted 6 lines
fs/exfat/super.c +3 -0
@@ -693,10 +693,29 @@ static void exfat_free(struct fs_context *fc)
      }
 }
 
+static int exfat_reconfigure(struct fs_context *fc) {
+     struct super_block *sb = fc->root->d_sb;
+     int ret;

int ret = 0;

Quoted 7 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 703

Quoted 4 lines
fs/exfat/super.c +4 -0
+     bool new_rdonly;
+
+     new_rdonly = fc->sb_flags & SB_RDONLY;
+     if (new_rdonly != sb_rdonly(sb)) {

If you modify it like this, would not we need new_rdonly?

        if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb))

This condition means that mount options are changed from "rw" to "ro", or "ro" to "rw".

Quoted 1 line

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 704

Quoted 1 line
fs/exfat/super.c +1 -0
+             if (new_rdonly) {

And this condition means these options are changed from "rw" to "ro". It seems better to change two conditions to the one you suggested, or remove those. because sync_filesystem returns 0 when the filesystem is mounted as read-only.

Quoted 5 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 708

Quoted 4 lines
fs/exfat/super.c +4 -0
+                     /* volume flag will be updated in exfat_sync_fs */
+                     ret = sync_filesystem(sb);
+                     if (ret < 0)
+                             return ret;

I think that this ret check can be removed by using return ret; below ?

Okay, I will apply this.
Thank you for your comments!

Quoted 18 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 711

Quoted 3 lines
fs/exfat/super.c +3 -0
+             }
+     }
+     return 0;

return ret;

Quoted 12 lines
fs/exfat/super.c +3 -1
+}
+
 static const struct fs_context_operations exfat_context_ops = {
      .parse_param    = exfat_parse_param,
      .get_tree       = exfat_get_tree,
      .free           = exfat_free,
+     .reconfigure    = exfat_reconfigure,
 };
 
 static int exfat_init_fs_context(struct fs_context *fc)
--

2.17.1

#6 lore raw
Quoted 8 lines

Hi Namjae,

2020년 6월 15일 (월) 오전 9:14, Namjae Jeon <[email protected]>님이 작성:

Quoted 5 lines

Hi Hyunchul,

Quoted 3 lines

We need to commit dirty metadata and pages to disk before remounting exfat as read-only.

This fixes a failure in xfstests generic/452

Quoted 8 lines
Quoted 1 line

Could you please elaborate more the reason why generic/452 in xfstests failed ?

xfstests generic/452 does the following.
cp /bin/ls <exfat>/
mount -o remount,ro <exfat>

the <exfat>/ls file is corrupted, because while exfat is remounted as read-only, exfat doesn't have a chance to commit metadata and vfs invalidates page caches in a block device.

Got it.

Quoted 2 lines

I will put this explanation in a commit message.

Good.

Quoted 26 lines
Quoted 19 lines
Quoted 12 lines
---
 fs/exfat/super.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
fs/exfat/super.c index renamed from fs/exfat/super.c +0 -0

e650e65536f8..61c6cf240c19 100644

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 698

Quoted 6 lines
fs/exfat/super.c +3 -0
@@ -693,10 +693,29 @@ static void exfat_free(struct fs_context *fc)
      }
 }
 
+static int exfat_reconfigure(struct fs_context *fc) {
+     struct super_block *sb = fc->root->d_sb;
+     int ret;

int ret = 0;

Quoted 7 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 703

Quoted 4 lines
fs/exfat/super.c +4 -0
+     bool new_rdonly;
+
+     new_rdonly = fc->sb_flags & SB_RDONLY;
+     if (new_rdonly != sb_rdonly(sb)) {

If you modify it like this, would not we need new_rdonly?

        if (fc->sb_flags & SB_RDONLY && !sb_rdonly(sb))
Quoted 7 lines

This condition means that mount options are changed from "rw" to "ro", or "ro" to "rw".

Quoted 1 line

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 704

Quoted 1 line
fs/exfat/super.c +1 -0
+             if (new_rdonly) {

And this condition means these options are changed from "rw" to "ro".
It seems better to change two conditions to the one you suggested, or remove those. because sync_filesystem returns 0 when the filesystem is mounted as read-only.

The latter would be fine.

Quoted 9 lines
Quoted 6 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 708

Quoted 5 lines
fs/exfat/super.c +4 -0
+                     /* volume flag will be updated in exfat_sync_fs */
+                     ret = sync_filesystem(sb);
+                     if (ret < 0)
+                             return ret;

I think that this ret check can be removed by using return ret; below ?

Okay, I will apply this.
Thank you for your comments!

Thanks for your patch!

Quoted 20 lines
Quoted 20 lines

fs/exfat/super.c static void exfat_free(struct fs_context *fc) · line 711

Quoted 5 lines
fs/exfat/super.c +3 -0
+             }
+     }
+     return 0;

return ret;

Quoted 12 lines
fs/exfat/super.c +3 -1
+}
+
 static const struct fs_context_operations exfat_context_ops = {
      .parse_param    = exfat_parse_param,
      .get_tree       = exfat_get_tree,
      .free           = exfat_free,
+     .reconfigure    = exfat_reconfigure,
 };
 
 static int exfat_init_fs_context(struct fs_context *fc)
--

2.17.1