Skip to contentSkip to conversation

f2fs: new mount API conversion

PATCH Applied Eric Sandeen 7 participants 60 messages Apr 24, 2025 – Jul 11, 2025 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#44 lore raw
In reply to Eric Sandeen

Hi all - it would be nice to get some review or feedback on this; seems that these patches tend to go stale fairly quickly as f2fs evolves. :)

Thanks,
-Eric

Quoted 71 lines · Eric Sandeen

V3:
- Rebase onto git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
dev branch
- Fix up some 0day robot warnings

This is a forward-port of Hongbo's original f2fs mount API conversion, posted last August at
https://lore.kernel.org/linux-f2fs-devel/[email protected]/

I had been trying to approach this with a little less complexity, but in the end I realized that Hongbo's approach (which follows the ext4 approach) was a good one, and I was not making any progrss myself. 😉

In addition to the forward-port, I have also fixed a couple bugs I found during testing, and some improvements / style choices as well. Hongbo and I have discussed most of this off-list already, so I'm presenting the net result here.

This does pass my typical testing which does a large number of random mounts/remounts with valid and invalid option sets, on f2fs filesystem images with various features in the on-disk superblock. (I was not able to test all of this completely, as some options or features require hardware I dn't have.)

Thanks,
-Eric

(A recap of Hongbo's original cover letter is below, edited slightly for this series:)

Since many filesystems have done the new mount API conversion, we introduce the new mount API conversion in f2fs.

The series can be applied on top of the current mainline tree and the work is based on the patches from Lukas Czerner (has done this in ext4[1]). His patch give me a lot of ideas.

Here is a high level description of the patchset:

1. Prepare the f2fs mount parameters required by the new mount API and use it for parsing, while still using the old API to get mount options string. Split the parameter parsing and validation of the parse_options helper into two separate helpers.

f2fs: Add fs parameter specifications for mount options
f2fs: move the option parser into handle_mount_opt

2. Remove the use of sb/sbi structure of f2fs from all the parsing code, because with the new mount API the parsing is going to be done before we even get the super block. In this part, we introduce f2fs_fs_context to hold the temporary options when parsing. For the simple options check, it has to be done during parsing by using f2fs_fs_context structure. For the check which needs sb/sbi, we do this during super block filling.

f2fs: Allow sbi to be NULL in f2fs_printk
f2fs: Add f2fs_fs_context to record the mount options
f2fs: separate the options parsing and options checking

3. Switch the f2fs to use the new mount API for mount and remount.

f2fs: introduce fs_context_operation structure
f2fs: switch to the new mount api

[1] https://lore.kernel.org/all/[email protected]/

maintainer
#45 lore raw
Quoted 3 lines · Eric Sandeen

Hi all - it would be nice to get some review or feedback on this; seems that these patches tend to go stale fairly quickly as f2fs evolves. :)

Thank you so much for the work! Let me queue this series into dev-test for tests. If I find any issue, let me ping to the thread. So, you don't need to worry about rebasing it. :)

Thanks,

Quoted 76 lines

Thanks,
-Eric

Quoted 71 lines · Eric Sandeen

V3:
- Rebase onto git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
dev branch
- Fix up some 0day robot warnings

This is a forward-port of Hongbo's original f2fs mount API conversion, posted last August at
https://lore.kernel.org/linux-f2fs-devel/[email protected]/

I had been trying to approach this with a little less complexity, but in the end I realized that Hongbo's approach (which follows the ext4 approach) was a good one, and I was not making any progrss myself. 😉

In addition to the forward-port, I have also fixed a couple bugs I found during testing, and some improvements / style choices as well. Hongbo and I have discussed most of this off-list already, so I'm presenting the net result here.

This does pass my typical testing which does a large number of random mounts/remounts with valid and invalid option sets, on f2fs filesystem images with various features in the on-disk superblock. (I was not able to test all of this completely, as some options or features require hardware I dn't have.)

Thanks,
-Eric

(A recap of Hongbo's original cover letter is below, edited slightly for this series:)

Since many filesystems have done the new mount API conversion, we introduce the new mount API conversion in f2fs.

The series can be applied on top of the current mainline tree and the work is based on the patches from Lukas Czerner (has done this in ext4[1]). His patch give me a lot of ideas.

Here is a high level description of the patchset:

1. Prepare the f2fs mount parameters required by the new mount API and use it for parsing, while still using the old API to get mount options string. Split the parameter parsing and validation of the parse_options helper into two separate helpers.

f2fs: Add fs parameter specifications for mount options
f2fs: move the option parser into handle_mount_opt

2. Remove the use of sb/sbi structure of f2fs from all the parsing code, because with the new mount API the parsing is going to be done before we even get the super block. In this part, we introduce f2fs_fs_context to hold the temporary options when parsing. For the simple options check, it has to be done during parsing by using f2fs_fs_context structure. For the check which needs sb/sbi, we do this during super block filling.

f2fs: Allow sbi to be NULL in f2fs_printk
f2fs: Add f2fs_fs_context to record the mount options
f2fs: separate the options parsing and options checking

3. Switch the f2fs to use the new mount API for mount and remount.

f2fs: introduce fs_context_operation structure
f2fs: switch to the new mount api

[1] https://lore.kernel.org/all/[email protected]/

#46 lore raw
Quoted 8 lines · Jaegeuk Kim
Quoted 3 lines · Eric Sandeen

Hi all - it would be nice to get some review or feedback on this; seems that these patches tend to go stale fairly quickly as f2fs evolves. :)

Thank you so much for the work! Let me queue this series into dev-test for tests. If I find any issue, let me ping to the thread. So, you don't need to worry about rebasing it. :)

Thank you for queuing it, and Hongbo for the original series. Please reach out if you encounter any problems.

-Eric

Quoted 6 lines

Thanks,

Quoted 4 lines

Thanks,
-Eric

Reviewed-by on the v3 series
#47 lore raw
In reply to Eric Sandeen
Quoted 62 lines · Eric Sandeen

V3:
- Rebase onto git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
dev branch
- Fix up some 0day robot warnings

This is a forward-port of Hongbo's original f2fs mount API conversion, posted last August at
https://lore.kernel.org/linux-f2fs-devel/[email protected]/

I had been trying to approach this with a little less complexity, but in the end I realized that Hongbo's approach (which follows the ext4 approach) was a good one, and I was not making any progrss myself. 😉

In addition to the forward-port, I have also fixed a couple bugs I found during testing, and some improvements / style choices as well. Hongbo and I have discussed most of this off-list already, so I'm presenting the net result here.

This does pass my typical testing which does a large number of random mounts/remounts with valid and invalid option sets, on f2fs filesystem images with various features in the on-disk superblock. (I was not able to test all of this completely, as some options or features require hardware I dn't have.)

Thanks,
-Eric

(A recap of Hongbo's original cover letter is below, edited slightly for this series:)

Since many filesystems have done the new mount API conversion, we introduce the new mount API conversion in f2fs.

The series can be applied on top of the current mainline tree and the work is based on the patches from Lukas Czerner (has done this in ext4[1]). His patch give me a lot of ideas.

Here is a high level description of the patchset:

1. Prepare the f2fs mount parameters required by the new mount API and use it for parsing, while still using the old API to get mount options string. Split the parameter parsing and validation of the parse_options helper into two separate helpers.

f2fs: Add fs parameter specifications for mount options
f2fs: move the option parser into handle_mount_opt

2. Remove the use of sb/sbi structure of f2fs from all the parsing code, because with the new mount API the parsing is going to be done before we even get the super block. In this part, we introduce f2fs_fs_context to hold the temporary options when parsing. For the simple options check, it has to be done during parsing by using f2fs_fs_context structure. For the check which needs sb/sbi, we do this during super block filling.

f2fs: Allow sbi to be NULL in f2fs_printk
f2fs: Add f2fs_fs_context to record the mount options
f2fs: separate the options parsing and options checking

Quoted 9 lines

3. Switch the f2fs to use the new mount API for mount and remount.

f2fs: introduce fs_context_operation structure
f2fs: switch to the new mount api

[1] https://lore.kernel.org/all/[email protected]/

The option parsing for f2fs is quite complex so obviously we need Hongbo to review

these as well (at least).

Apart from that all the mount API bits I expect to see are present and Eric notes

the option parsing complexity ends up being unavoidable so it looks good to me.

Ian

maintainer
#48 lore raw
In reply to Eric Sandeen

Hmm, I had to drop the series at the moment, since it seems needing more work to deal with default_options(), which breaks my device setup. For example, set_opt(sbi, READ_EXTENT_CACHE) in default_options is not propagating to the below logics. In this case, do we need ctx_set_opt() if user doesn't set?

Quoted 69 lines · Eric Sandeen

V3:
- Rebase onto git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs.git
dev branch
- Fix up some 0day robot warnings

This is a forward-port of Hongbo's original f2fs mount API conversion, posted last August at
https://lore.kernel.org/linux-f2fs-devel/[email protected]/

I had been trying to approach this with a little less complexity, but in the end I realized that Hongbo's approach (which follows the ext4 approach) was a good one, and I was not making any progrss myself. 😉

In addition to the forward-port, I have also fixed a couple bugs I found during testing, and some improvements / style choices as well. Hongbo and I have discussed most of this off-list already, so I'm presenting the net result here.

This does pass my typical testing which does a large number of random mounts/remounts with valid and invalid option sets, on f2fs filesystem images with various features in the on-disk superblock. (I was not able to test all of this completely, as some options or features require hardware I dn't have.)

Thanks,
-Eric

(A recap of Hongbo's original cover letter is below, edited slightly for this series:)

Since many filesystems have done the new mount API conversion, we introduce the new mount API conversion in f2fs.

The series can be applied on top of the current mainline tree and the work is based on the patches from Lukas Czerner (has done this in ext4[1]). His patch give me a lot of ideas.

Here is a high level description of the patchset:

1. Prepare the f2fs mount parameters required by the new mount API and use it for parsing, while still using the old API to get mount options string. Split the parameter parsing and validation of the parse_options helper into two separate helpers.

f2fs: Add fs parameter specifications for mount options
f2fs: move the option parser into handle_mount_opt

2. Remove the use of sb/sbi structure of f2fs from all the parsing code, because with the new mount API the parsing is going to be done before we even get the super block. In this part, we introduce f2fs_fs_context to hold the temporary options when parsing. For the simple options check, it has to be done during parsing by using f2fs_fs_context structure. For the check which needs sb/sbi, we do this during super block filling.

f2fs: Allow sbi to be NULL in f2fs_printk
f2fs: Add f2fs_fs_context to record the mount options
f2fs: separate the options parsing and options checking

3. Switch the f2fs to use the new mount API for mount and remount.

f2fs: introduce fs_context_operation structure
f2fs: switch to the new mount api

[1] https://lore.kernel.org/all/[email protected]/

#49 lore raw
Quoted 4 lines · Jaegeuk Kim

Hmm, I had to drop the series at the moment, since it seems needing more work to deal with default_options(), which breaks my device setup. For example, set_opt(sbi, READ_EXTENT_CACHE) in default_options is not propagating to the below logics. In this case, do we need ctx_set_opt() if user doesn't set?

Hm, can you describe the test or environment that fails for you? (I'm afraid that I may not have all the right hardware to test everything, so may have missed some cases)

However, from a quick test here, a loopback mount of an f2fs image file does set extent_cache properly, so maybe I don't understand the problem:

# mount -o loop f2fsfile.img mnt
# mount | grep -o extent_cache
extent_cache
#

I'm happy to try to look into it though. Maybe you can put the patches back on a temporary branch for me to pull and test?

Thanks,
- Eric

maintainer
#50 lore raw
Quoted 13 lines · Eric Sandeen
Quoted 4 lines · Jaegeuk Kim

Hmm, I had to drop the series at the moment, since it seems needing more work to deal with default_options(), which breaks my device setup. For example, set_opt(sbi, READ_EXTENT_CACHE) in default_options is not propagating to the below logics. In this case, do we need ctx_set_opt() if user doesn't set?

Hm, can you describe the test or environment that fails for you? (I'm afraid that I may not have all the right hardware to test everything, so may have missed some cases)

However, from a quick test here, a loopback mount of an f2fs image file does set extent_cache properly, so maybe I don't understand the problem:

Quoted 7 lines
# mount -o loop f2fsfile.img mnt
# mount | grep -o extent_cache
extent_cache
#

I'm happy to try to look into it though. Maybe you can put the patches back on a temporary branch for me to pull and test?

Thank you! I pushed here the last version.

https://github.com/jaegeuk/f2fs/commits/mount/

What about:

# mount -o loop,noextent_cache f2fsfile.img mnt

In this case, 1) ctx_clear_opt(), 2) set_opt() in default_options,
3) clear_opt since mask is set?

And, device_aliasing check is still failing, since it does not understand test_opt(). Probably it's the only case?

Quoted 4 lines

Thanks,
- Eric

#51 lore raw
Quoted 24 lines · Jaegeuk Kim
Quoted 13 lines · Eric Sandeen
Quoted 4 lines · Jaegeuk Kim

Hmm, I had to drop the series at the moment, since it seems needing more work to deal with default_options(), which breaks my device setup. For example, set_opt(sbi, READ_EXTENT_CACHE) in default_options is not propagating to the below logics. In this case, do we need ctx_set_opt() if user doesn't set?

Hm, can you describe the test or environment that fails for you? (I'm afraid that I may not have all the right hardware to test everything, so may have missed some cases)

However, from a quick test here, a loopback mount of an f2fs image file does set extent_cache properly, so maybe I don't understand the problem:

Quoted 7 lines
# mount -o loop f2fsfile.img mnt
# mount | grep -o extent_cache
extent_cache
#

I'm happy to try to look into it though. Maybe you can put the patches back on a temporary branch for me to pull and test?

Thank you! I pushed here the last version.

Quoted 7 lines

https://github.com/jaegeuk/f2fs/commits/mount/

What about:

# mount -o loop,noextent_cache f2fsfile.img mnt

In this case, 1) ctx_clear_opt(), 2) set_opt() in default_options,
3) clear_opt since mask is set?

Not sure what I'm missing, it seems to work properly here but I haven't pulled your (slightly) modified patches yet:

# mount -o loop,extent_cache f2fsfile.img mnt
# mount | grep -wo extent_cache
extent_cache
# umount mnt
# mount -o loop,noextent_cache f2fsfile.img mnt
# mount | grep -wo noextent_cache
noextent_cache
#

this looks right?

I'll check your tree tomorrow, though it doesn't sound like you made many changes.

Quoted 2 lines

And, device_aliasing check is still failing, since it does not understand test_opt(). Probably it's the only case?

I think you can blame me, not Hongbo on that one ;) - I will look into it.

-Eric

Quoted 5 lines
Quoted 4 lines

Thanks,
- Eric

#52 lore raw
Quoted 1 line · Eric Sandeen

On 5/6/25 8:23 PM, Jaegeuk Kim wrote:

...

Quoted 19 lines
Quoted 5 lines

What about:

# mount -o loop,noextent_cache f2fsfile.img mnt

In this case, 1) ctx_clear_opt(), 2) set_opt() in default_options,
3) clear_opt since mask is set?

Not sure what I'm missing, it seems to work properly here but I haven't pulled your (slightly) modified patches yet:

# mount -o loop,extent_cache f2fsfile.img mnt
# mount | grep -wo extent_cache
extent_cache
# umount mnt
# mount -o loop,noextent_cache f2fsfile.img mnt
# mount | grep -wo noextent_cache
noextent_cache
#
Quoted 4 lines

this looks right?

I'll check your tree tomorrow, though it doesn't sound like you made many changes.

Hmm, I checked tonight and I see the same (correct?) behavior in your tree.

Quoted 2 lines
Quoted 2 lines

And, device_aliasing check is still failing, since it does not understand test_opt(). Probably it's the only case?

Again, in your tree (I had to use a git version of f2fs-tools to make device aliasing work - maybe time for a release?) ;)

# mkfs.ext4 /dev/vdc
# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount -o noextent_cache /dev/vdb mnt
# dmesg | tail -n 1
[  581.924604] F2FS-fs (vdb): device aliasing requires extent cache
# mount -o extent_cache /dev/vdb mnt
# mount | grep -wo extent_cache
extent_cache
# 

Maybe you can show me exactly what's not working for you?

-Eric

maintainer
#53 lore raw
Quoted 37 lines · Eric Sandeen
Quoted 1 line · Eric Sandeen

On 5/6/25 8:23 PM, Jaegeuk Kim wrote:

...

Quoted 19 lines
Quoted 5 lines

What about:

# mount -o loop,noextent_cache f2fsfile.img mnt

In this case, 1) ctx_clear_opt(), 2) set_opt() in default_options,
3) clear_opt since mask is set?

Not sure what I'm missing, it seems to work properly here but I haven't pulled your (slightly) modified patches yet:

# mount -o loop,extent_cache f2fsfile.img mnt
# mount | grep -wo extent_cache
extent_cache
# umount mnt
# mount -o loop,noextent_cache f2fsfile.img mnt
# mount | grep -wo noextent_cache
noextent_cache
#
Quoted 4 lines

this looks right?

I'll check your tree tomorrow, though it doesn't sound like you made many changes.

Hmm, I checked tonight and I see the same (correct?) behavior in your tree.

Quoted 2 lines
Quoted 2 lines

And, device_aliasing check is still failing, since it does not understand test_opt(). Probably it's the only case?

Again, in your tree (I had to use a git version of f2fs-tools to make device aliasing work - maybe time for a release?) ;)

Quoted 9 lines
# mkfs.ext4 /dev/vdc
# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount -o noextent_cache /dev/vdb mnt
# dmesg | tail -n 1
[  581.924604] F2FS-fs (vdb): device aliasing requires extent cache
# mount -o extent_cache /dev/vdb mnt
# mount | grep -wo extent_cache
extent_cache
# 

I meant:

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt

It's supposed to be successful, since extent_cache is enabled by default.

Quoted 4 lines

Maybe you can show me exactly what's not working for you?

-Eric

#54 lore raw
Quoted 6 lines · Jaegeuk Kim

I meant:

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt

It's supposed to be successful, since extent_cache is enabled by default.

I'm sorry, clearly I was too sleepy last night. This fixes it for me.

We have to test the mask to see if the option was explisitly set (either extent_cache or noextent_cache) at mount time.

If it was not specified at all, it will be set by the default f'n and remain in the sbi, and it will pass this consistency check.

fs/f2fs/super.c +2 -1
index d89b9ede221e..e178796ce9a7 100644
@@ -1412,7 +1414,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
-			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
+			 !ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
 	}
maintainer
#55 lore raw
Quoted 22 lines · Eric Sandeen
Quoted 6 lines · Jaegeuk Kim

I meant:

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt

It's supposed to be successful, since extent_cache is enabled by default.

I'm sorry, clearly I was too sleepy last night. This fixes it for me.

We have to test the mask to see if the option was explisitly set (either extent_cache or noextent_cache) at mount time.

If it was not specified at all, it will be set by the default f'n and remain in the sbi, and it will pass this consistency check.

fs/f2fs/super.c +0 -0
index d89b9ede221e..e178796ce9a7 100644

fs/f2fs/super.c static int f2fs_check_opt_consistency(struct fs_context *fc, · line 1421

Quoted 9 lines
fs/f2fs/super.c +2 -1
@@ -1412,7 +1414,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
-			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
+			 !ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
 	}

I think that will cover the user-given options only, but we'd better check the final options as well. Can we apply like this?

---
 fs/f2fs/super.c | 50 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 17 deletions(-)
fs/f2fs/super.c +33 -17
index d89b9ede221e..270a9bf9773d 100644
@@ -1412,6 +1412,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
 			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
@@ -1657,6 +1658,29 @@ static void f2fs_apply_options(struct fs_context *fc, struct super_block *sb)
 	f2fs_apply_quota_options(fc, sb);
 }
 
+static int f2fs_sanity_check_options(struct f2fs_sb_info *sbi)
+{
+	if (f2fs_sb_has_device_alias(sbi) &&
+	    !test_opt(sbi, READ_EXTENT_CACHE)) {
+		f2fs_err(sbi, "device aliasing requires extent cache");
+		return -EINVAL;
+	}
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (f2fs_sb_has_blkzoned(sbi) &&
+	    sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+#endif
+	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
+		f2fs_warn(sbi, "LFS is not compatible with IPU");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static struct inode *f2fs_alloc_inode(struct super_block *sb)
 {
 	struct f2fs_inode_info *fi;
@@ -2616,21 +2640,15 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	default_options(sbi, true);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto restore_opts;
 
 	f2fs_apply_options(fc, sb);
 
-#ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) &&
-		sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-		f2fs_err(sbi,
-			"zoned: max open zones %u is too small, need at least %u open zones",
-				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-		err = -EINVAL;
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
 		goto restore_opts;
-	}
-#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -2663,12 +2681,6 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		}
 	}
 #endif
-	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
-		err = -EINVAL;
-		f2fs_warn(sbi, "LFS is not compatible with IPU");
-		goto restore_opts;
-	}
-
 	/* disallow enable atgc dynamically */
 	if (no_atgc == !!test_opt(sbi, ATGC)) {
 		err = -EINVAL;
@@ -4808,11 +4820,15 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	default_options(sbi, false);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto free_sb_buf;
 
 	f2fs_apply_options(fc, sb);
 
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
+		goto free_options;
+
 	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
Signature · 1 line
2.49.0.1015.ga840276032-goog
#56 lore raw
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Eric Sandeen
Quoted 6 lines · Jaegeuk Kim

I meant:

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt

It's supposed to be successful, since extent_cache is enabled by default.

I'm sorry, clearly I was too sleepy last night. This fixes it for me.

We have to test the mask to see if the option was explisitly set (either extent_cache or noextent_cache) at mount time.

If it was not specified at all, it will be set by the default f'n and remain in the sbi, and it will pass this consistency check.

fs/f2fs/super.c +0 -0
index d89b9ede221e..e178796ce9a7 100644
@@ -1412,7 +1414,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
Quoted 10 lines

fs/f2fs/super.c static int f2fs_check_opt_consistency(struct fs_context *fc,

Quoted 7 lines
fs/f2fs/super.c +2 -1
 	if (f2fs_sb_has_device_alias(sbi) &&
-			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
+			 !ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
 	}

I think that will cover the user-given options only, but we'd better check the final options as well. Can we apply like this?

I'm sorry, I'm not sure I understand what situation this additional changes will cover...

It looks like this adds the f2fs_sanity_check_options() to the remount path to explicitly (re-)check a few things.

But as far as I can tell, at least for the extent cache, remount is handled properly already (with the hunk above):

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt
# mount -o remount,noextent_cache mnt
mount: /root/mnt: mount point not mounted or bad option.
       dmesg(1) may have more information after failed mount system call.
# dmesg | tail -n 1
[60012.364941] F2FS-fs (vdb): device aliasing requires extent cache
#

I haven't tested with i.e. blkzoned devices though, is there a testcase that fails for you?

Thanks,
-Eric

Quoted 102 lines
---
 fs/f2fs/super.c | 50 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 17 deletions(-)
fs/f2fs/super.c +33 -17
index d89b9ede221e..270a9bf9773d 100644
@@ -1412,6 +1412,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
 			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
@@ -1657,6 +1658,29 @@ static void f2fs_apply_options(struct fs_context *fc, struct super_block *sb)
 	f2fs_apply_quota_options(fc, sb);
 }
 
+static int f2fs_sanity_check_options(struct f2fs_sb_info *sbi)
+{
+	if (f2fs_sb_has_device_alias(sbi) &&
+	    !test_opt(sbi, READ_EXTENT_CACHE)) {
+		f2fs_err(sbi, "device aliasing requires extent cache");
+		return -EINVAL;
+	}
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (f2fs_sb_has_blkzoned(sbi) &&
+	    sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+#endif
+	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
+		f2fs_warn(sbi, "LFS is not compatible with IPU");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static struct inode *f2fs_alloc_inode(struct super_block *sb)
 {
 	struct f2fs_inode_info *fi;
@@ -2616,21 +2640,15 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	default_options(sbi, true);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto restore_opts;
 
 	f2fs_apply_options(fc, sb);
 
-#ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) &&
-		sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-		f2fs_err(sbi,
-			"zoned: max open zones %u is too small, need at least %u open zones",
-				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-		err = -EINVAL;
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
 		goto restore_opts;
-	}
-#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -2663,12 +2681,6 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		}
 	}
 #endif
-	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
-		err = -EINVAL;
-		f2fs_warn(sbi, "LFS is not compatible with IPU");
-		goto restore_opts;
-	}
-
 	/* disallow enable atgc dynamically */
 	if (no_atgc == !!test_opt(sbi, ATGC)) {
 		err = -EINVAL;
@@ -4808,11 +4820,15 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	default_options(sbi, false);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto free_sb_buf;
 
 	f2fs_apply_options(fc, sb);
 
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
+		goto free_options;
+
 	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
maintainer
#57 lore raw
Quoted 55 lines · Eric Sandeen
Quoted 25 lines · Jaegeuk Kim
Quoted 24 lines · Eric Sandeen
Quoted 6 lines · Jaegeuk Kim

I meant:

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt

It's supposed to be successful, since extent_cache is enabled by default.

I'm sorry, clearly I was too sleepy last night. This fixes it for me.

We have to test the mask to see if the option was explisitly set (either extent_cache or noextent_cache) at mount time.

If it was not specified at all, it will be set by the default f'n and remain in the sbi, and it will pass this consistency check.

fs/f2fs/super.c +0 -0
index d89b9ede221e..e178796ce9a7 100644
@@ -1412,7 +1414,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
Quoted 10 lines

fs/f2fs/super.c static int f2fs_check_opt_consistency(struct fs_context *fc,

Quoted 7 lines
fs/f2fs/super.c +2 -1
 	if (f2fs_sb_has_device_alias(sbi) &&
-			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
+			 !ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
 	}

I think that will cover the user-given options only, but we'd better check the final options as well. Can we apply like this?

I'm sorry, I'm not sure I understand what situation this additional changes will cover...

It looks like this adds the f2fs_sanity_check_options() to the remount path to explicitly (re-)check a few things.

But as far as I can tell, at least for the extent cache, remount is handled properly already (with the hunk above):

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt
# mount -o remount,noextent_cache mnt
mount: /root/mnt: mount point not mounted or bad option.
       dmesg(1) may have more information after failed mount system call.
# dmesg | tail -n 1
[60012.364941] F2FS-fs (vdb): device aliasing requires extent cache
#
Quoted 2 lines

I haven't tested with i.e. blkzoned devices though, is there a testcase that fails for you?

I'm worrying about any missing case to check options enabled by default_options. For example, in the case of device_aliasing, we rely on enabling extent_cache by default_options, which was not caught by f2fs_check_opt_consistency.

I was thinking that we'd need a post sanity check.

Quoted 106 lines

Thanks,
-Eric

Quoted 102 lines
---
 fs/f2fs/super.c | 50 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 17 deletions(-)
fs/f2fs/super.c +33 -17
index d89b9ede221e..270a9bf9773d 100644
@@ -1412,6 +1412,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
 			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
@@ -1657,6 +1658,29 @@ static void f2fs_apply_options(struct fs_context *fc, struct super_block *sb)
 	f2fs_apply_quota_options(fc, sb);
 }
 
+static int f2fs_sanity_check_options(struct f2fs_sb_info *sbi)
+{
+	if (f2fs_sb_has_device_alias(sbi) &&
+	    !test_opt(sbi, READ_EXTENT_CACHE)) {
+		f2fs_err(sbi, "device aliasing requires extent cache");
+		return -EINVAL;
+	}
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (f2fs_sb_has_blkzoned(sbi) &&
+	    sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+#endif
+	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
+		f2fs_warn(sbi, "LFS is not compatible with IPU");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static struct inode *f2fs_alloc_inode(struct super_block *sb)
 {
 	struct f2fs_inode_info *fi;
@@ -2616,21 +2640,15 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	default_options(sbi, true);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto restore_opts;
 
 	f2fs_apply_options(fc, sb);
 
-#ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) &&
-		sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-		f2fs_err(sbi,
-			"zoned: max open zones %u is too small, need at least %u open zones",
-				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-		err = -EINVAL;
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
 		goto restore_opts;
-	}
-#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -2663,12 +2681,6 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		}
 	}
 #endif
-	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
-		err = -EINVAL;
-		f2fs_warn(sbi, "LFS is not compatible with IPU");
-		goto restore_opts;
-	}
-
 	/* disallow enable atgc dynamically */
 	if (no_atgc == !!test_opt(sbi, ATGC)) {
 		err = -EINVAL;
@@ -4808,11 +4820,15 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	default_options(sbi, false);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto free_sb_buf;
 
 	f2fs_apply_options(fc, sb);
 
+	err = f2fs_sanity_check_options(sbi);
+	if (err)
+		goto free_options;
+
 	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
#58 lore raw
Quoted 12 lines · Jaegeuk Kim
Quoted 12 lines

But as far as I can tell, at least for the extent cache, remount is handled properly already (with the hunk above):

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt
# mount -o remount,noextent_cache mnt
mount: /root/mnt: mount point not mounted or bad option.
       dmesg(1) may have more information after failed mount system call.
# dmesg | tail -n 1
[60012.364941] F2FS-fs (vdb): device aliasing requires extent cache
#
Quoted 7 lines
Quoted 2 lines

I haven't tested with i.e. blkzoned devices though, is there a testcase that fails for you?

I'm worrying about any missing case to check options enabled by default_options. For example, in the case of device_aliasing, we rely on enabling extent_cache by default_options, which was not caught by f2fs_check_opt_consistency.

I was thinking that we'd need a post sanity check.

I see. If you want a "belt and suspenders" approach and it works for you, no argument from me :)

-Eric

maintainer
#59 lore raw
Quoted 15 lines · Eric Sandeen
Quoted 14 lines · Jaegeuk Kim
Quoted 14 lines

But as far as I can tell, at least for the extent cache, remount is handled properly already (with the hunk above):

# mkfs/mkfs.f2fs -c /dev/[email protected] /dev/vdb
# mount /dev/vdb mnt
# mount -o remount,noextent_cache mnt
mount: /root/mnt: mount point not mounted or bad option.
       dmesg(1) may have more information after failed mount system call.
# dmesg | tail -n 1
[60012.364941] F2FS-fs (vdb): device aliasing requires extent cache
#

I haven't tested with i.e. blkzoned devices though, is there a testcase that fails for you?

Quoted 8 lines
Quoted 5 lines

I'm worrying about any missing case to check options enabled by default_options. For example, in the case of device_aliasing, we rely on enabling extent_cache by default_options, which was not caught by f2fs_check_opt_consistency.

I was thinking that we'd need a post sanity check.

I see. If you want a "belt and suspenders" approach and it works for you, no argument from me :)

Thanks. :)

I just found that I had to check it's from remount or not. And, this change does not break my setup having a specific options. Let me queue the series back and wait for further review from Chao.

---
 fs/f2fs/super.c | 54 +++++++++++++++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 17 deletions(-)
fs/f2fs/super.c +37 -17
index d89b9ede221e..0ee783224953 100644
@@ -1412,6 +1412,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc,
 	}
 
 	if (f2fs_sb_has_device_alias(sbi) &&
+			(ctx->opt_mask & F2FS_MOUNT_READ_EXTENT_CACHE) &&
 			!ctx_test_opt(ctx, F2FS_MOUNT_READ_EXTENT_CACHE)) {
 		f2fs_err(sbi, "device aliasing requires extent cache");
 		return -EINVAL;
@@ -1657,6 +1658,33 @@ static void f2fs_apply_options(struct fs_context *fc, struct super_block *sb)
 	f2fs_apply_quota_options(fc, sb);
 }
 
+static int f2fs_sanity_check_options(struct f2fs_sb_info *sbi, bool remount)
+{
+	if (f2fs_sb_has_device_alias(sbi) &&
+	    !test_opt(sbi, READ_EXTENT_CACHE)) {
+		f2fs_err(sbi, "device aliasing requires extent cache");
+		return -EINVAL;
+	}
+
+	if (!remount)
+		return 0;
+
+#ifdef CONFIG_BLK_DEV_ZONED
+	if (f2fs_sb_has_blkzoned(sbi) &&
+	    sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
+		f2fs_err(sbi,
+			"zoned: max open zones %u is too small, need at least %u open zones",
+				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
+		return -EINVAL;
+	}
+#endif
+	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
+		f2fs_warn(sbi, "LFS is not compatible with IPU");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static struct inode *f2fs_alloc_inode(struct super_block *sb)
 {
 	struct f2fs_inode_info *fi;
@@ -2616,21 +2644,15 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 	default_options(sbi, true);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto restore_opts;
 
 	f2fs_apply_options(fc, sb);
 
-#ifdef CONFIG_BLK_DEV_ZONED
-	if (f2fs_sb_has_blkzoned(sbi) &&
-		sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) {
-		f2fs_err(sbi,
-			"zoned: max open zones %u is too small, need at least %u open zones",
-				 sbi->max_open_zones, F2FS_OPTION(sbi).active_logs);
-		err = -EINVAL;
+	err = f2fs_sanity_check_options(sbi, true);
+	if (err)
 		goto restore_opts;
-	}
-#endif
+
 	/* flush outstanding errors before changing fs state */
 	flush_work(&sbi->s_error_work);
 
@@ -2663,12 +2685,6 @@ static int __f2fs_remount(struct fs_context *fc, struct super_block *sb)
 		}
 	}
 #endif
-	if (f2fs_lfs_mode(sbi) && !IS_F2FS_IPU_DISABLE(sbi)) {
-		err = -EINVAL;
-		f2fs_warn(sbi, "LFS is not compatible with IPU");
-		goto restore_opts;
-	}
-
 	/* disallow enable atgc dynamically */
 	if (no_atgc == !!test_opt(sbi, ATGC)) {
 		err = -EINVAL;
@@ -4808,11 +4824,15 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
 	default_options(sbi, false);
 
 	err = f2fs_check_opt_consistency(fc, sb);
-	if (err < 0)
+	if (err)
 		goto free_sb_buf;
 
 	f2fs_apply_options(fc, sb);
 
+	err = f2fs_sanity_check_options(sbi, false);
+	if (err)
+		goto free_options;
+
 	sb->s_maxbytes = max_file_blocks(NULL) <<
 				le32_to_cpu(raw_super->log_blocksize);
 	sb->s_max_links = F2FS_LINK_MAX;
Signature · 1 line
2.49.0.1015.ga840276032-goog