diff mbox series

[v2] btrfs: change BTRFS_MOUNT_* flags to 64bits

Message ID 0955d2c5675a7fe3146292aaa766755f22bcd94b.1720865683.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series [v2] btrfs: change BTRFS_MOUNT_* flags to 64bits | expand

Commit Message

Qu Wenruo July 13, 2024, 10:15 a.m. UTC
Currently the BTRFS_MOUNT_* flags is already reaching 32 bits, and with
the incoming new rescue options, we're going beyond the width of 32
bits.

This is going to cause problems as for quite some 32 bit systems,
1ULL << 32 would overflow the width of unsigned long.

Fix the problem by:

- Migrate all existing BTRFS_MOUNT_* flags to unsigned long long
- Migrate all mount option related variables to unsigned long long
  * btrfs_fs_info::mount_opt
  * btrfs_fs_context::mount_opt
  * mount_opt parameter of btrfs_check_options()
  * old_opts parameter of btrfs_remount_begin()
  * old_opts parameter of btrfs_remount_cleanup()
  * mount_opt parameter of btrfs_check_mountopts_zoned()
  * mount_opt and opt parameters of check_ro_option()

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
The current patch is still based on the latest for-next branch.

But during merge time I will move this before the new rescue options.

Changelog:
v2:
- Also fix the parameters of mount options
  Or 32bit systems would still fail to compile.
---
 fs/btrfs/fs.h    | 66 ++++++++++++++++++++++++------------------------
 fs/btrfs/super.c | 11 ++++----
 fs/btrfs/super.h |  3 ++-
 fs/btrfs/zoned.c |  3 ++-
 fs/btrfs/zoned.h |  5 ++--
 5 files changed, 46 insertions(+), 42 deletions(-)

Comments

David Sterba July 15, 2024, 12:31 p.m. UTC | #1
On Sat, Jul 13, 2024 at 07:45:08PM +0930, Qu Wenruo wrote:
> Currently the BTRFS_MOUNT_* flags is already reaching 32 bits, and with
> the incoming new rescue options, we're going beyond the width of 32
> bits.
> 
> This is going to cause problems as for quite some 32 bit systems,
> 1ULL << 32 would overflow the width of unsigned long.
> 
> Fix the problem by:
> 
> - Migrate all existing BTRFS_MOUNT_* flags to unsigned long long
> - Migrate all mount option related variables to unsigned long long
>   * btrfs_fs_info::mount_opt
>   * btrfs_fs_context::mount_opt
>   * mount_opt parameter of btrfs_check_options()
>   * old_opts parameter of btrfs_remount_begin()
>   * old_opts parameter of btrfs_remount_cleanup()
>   * mount_opt parameter of btrfs_check_mountopts_zoned()
>   * mount_opt and opt parameters of check_ro_option()
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> The current patch is still based on the latest for-next branch.
> 
> But during merge time I will move this before the new rescue options.

You konw you can't do that right? The branch for 6.11 can't be changed
anymore and it was late last week already. I've forked the changes at
8e7860543a94784d744c7ce34b7 so far it's still subset of for-next if you
change anything below that then it'll cause merge conflicts or would
need manual resolution in another way. Until rc1 it's probably safest to
just append to our for-next.
Qu Wenruo July 15, 2024, 10:11 p.m. UTC | #2
在 2024/7/15 22:01, David Sterba 写道:
> On Sat, Jul 13, 2024 at 07:45:08PM +0930, Qu Wenruo wrote:
>> Currently the BTRFS_MOUNT_* flags is already reaching 32 bits, and with
>> the incoming new rescue options, we're going beyond the width of 32
>> bits.
>>
>> This is going to cause problems as for quite some 32 bit systems,
>> 1ULL << 32 would overflow the width of unsigned long.
>>
>> Fix the problem by:
>>
>> - Migrate all existing BTRFS_MOUNT_* flags to unsigned long long
>> - Migrate all mount option related variables to unsigned long long
>>    * btrfs_fs_info::mount_opt
>>    * btrfs_fs_context::mount_opt
>>    * mount_opt parameter of btrfs_check_options()
>>    * old_opts parameter of btrfs_remount_begin()
>>    * old_opts parameter of btrfs_remount_cleanup()
>>    * mount_opt parameter of btrfs_check_mountopts_zoned()
>>    * mount_opt and opt parameters of check_ro_option()
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>> The current patch is still based on the latest for-next branch.
>>
>> But during merge time I will move this before the new rescue options.
>
> You konw you can't do that right? The branch for 6.11 can't be changed
> anymore and it was late last week already. I've forked the changes at
> 8e7860543a94784d744c7ce34b7 so far it's still subset of for-next if you
> change anything below that then it'll cause merge conflicts or would
> need manual resolution in another way. Until rc1 it's probably safest to
> just append to our for-next.
>

I guess it's impossible to drop all the new rescue mount option patches
from 6.11 queue?

If still possible, I'd prefer to drop them first instead of hugely
breaking 32bit systems.

Thanks,
Qu
Qu Wenruo July 15, 2024, 10:41 p.m. UTC | #3
在 2024/7/16 07:41, Qu Wenruo 写道:
>
>
> 在 2024/7/15 22:01, David Sterba 写道:
>> On Sat, Jul 13, 2024 at 07:45:08PM +0930, Qu Wenruo wrote:
>>> Currently the BTRFS_MOUNT_* flags is already reaching 32 bits, and with
>>> the incoming new rescue options, we're going beyond the width of 32
>>> bits.
>>>
>>> This is going to cause problems as for quite some 32 bit systems,
>>> 1ULL << 32 would overflow the width of unsigned long.
>>>
>>> Fix the problem by:
>>>
>>> - Migrate all existing BTRFS_MOUNT_* flags to unsigned long long
>>> - Migrate all mount option related variables to unsigned long long
>>>    * btrfs_fs_info::mount_opt
>>>    * btrfs_fs_context::mount_opt
>>>    * mount_opt parameter of btrfs_check_options()
>>>    * old_opts parameter of btrfs_remount_begin()
>>>    * old_opts parameter of btrfs_remount_cleanup()
>>>    * mount_opt parameter of btrfs_check_mountopts_zoned()
>>>    * mount_opt and opt parameters of check_ro_option()
>>>
>>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>>> ---
>>> The current patch is still based on the latest for-next branch.
>>>
>>> But during merge time I will move this before the new rescue options.
>>
>> You konw you can't do that right? The branch for 6.11 can't be changed
>> anymore and it was late last week already. I've forked the changes at
>> 8e7860543a94784d744c7ce34b7 so far it's still subset of for-next if you
>> change anything below that then it'll cause merge conflicts or would
>> need manual resolution in another way. Until rc1 it's probably safest to
>> just append to our for-next.
>>
>
> I guess it's impossible to drop all the new rescue mount option patches
> from 6.11 queue?

My bad, just see the git pull, so it's not possible anymore.

Then I just hope the patch can be merged as a bug fixes sooner, or we're
going to be flooded by tons of compiling failures.

Thanks,
Qu
>
> If still possible, I'd prefer to drop them first instead of hugely
> breaking 32bit systems.
>
> Thanks,
> Qu
>
David Sterba July 16, 2024, 12:14 a.m. UTC | #4
On Tue, Jul 16, 2024 at 08:11:00AM +0930, Qu Wenruo wrote:
> 
> 
> 在 2024/7/16 07:41, Qu Wenruo 写道:
> >
> >
> > 在 2024/7/15 22:01, David Sterba 写道:
> >> On Sat, Jul 13, 2024 at 07:45:08PM +0930, Qu Wenruo wrote:
> >>> Currently the BTRFS_MOUNT_* flags is already reaching 32 bits, and with
> >>> the incoming new rescue options, we're going beyond the width of 32
> >>> bits.
> >>>
> >>> This is going to cause problems as for quite some 32 bit systems,
> >>> 1ULL << 32 would overflow the width of unsigned long.
> >>>
> >>> Fix the problem by:
> >>>
> >>> - Migrate all existing BTRFS_MOUNT_* flags to unsigned long long
> >>> - Migrate all mount option related variables to unsigned long long
> >>>    * btrfs_fs_info::mount_opt
> >>>    * btrfs_fs_context::mount_opt
> >>>    * mount_opt parameter of btrfs_check_options()
> >>>    * old_opts parameter of btrfs_remount_begin()
> >>>    * old_opts parameter of btrfs_remount_cleanup()
> >>>    * mount_opt parameter of btrfs_check_mountopts_zoned()
> >>>    * mount_opt and opt parameters of check_ro_option()
> >>>
> >>> Signed-off-by: Qu Wenruo <wqu@suse.com>
> >>> ---
> >>> The current patch is still based on the latest for-next branch.
> >>>
> >>> But during merge time I will move this before the new rescue options.
> >>
> >> You konw you can't do that right? The branch for 6.11 can't be changed
> >> anymore and it was late last week already. I've forked the changes at
> >> 8e7860543a94784d744c7ce34b7 so far it's still subset of for-next if you
> >> change anything below that then it'll cause merge conflicts or would
> >> need manual resolution in another way. Until rc1 it's probably safest to
> >> just append to our for-next.
> >>
> >
> > I guess it's impossible to drop all the new rescue mount option patches
> > from 6.11 queue?
> 
> My bad, just see the git pull, so it's not possible anymore.
> 
> Then I just hope the patch can be merged as a bug fixes sooner, or we're
> going to be flooded by tons of compiling failures.

Yes a fixup is possible of course.
diff mbox series

Patch

diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h
index e911e0a838a2..103f0b3813b2 100644
--- a/fs/btrfs/fs.h
+++ b/fs/btrfs/fs.h
@@ -195,38 +195,38 @@  enum {
  * Note: don't forget to add new options to btrfs_show_options()
  */
 enum {
-	BTRFS_MOUNT_NODATASUM			= (1UL << 0),
-	BTRFS_MOUNT_NODATACOW			= (1UL << 1),
-	BTRFS_MOUNT_NOBARRIER			= (1UL << 2),
-	BTRFS_MOUNT_SSD				= (1UL << 3),
-	BTRFS_MOUNT_DEGRADED			= (1UL << 4),
-	BTRFS_MOUNT_COMPRESS			= (1UL << 5),
-	BTRFS_MOUNT_NOTREELOG   		= (1UL << 6),
-	BTRFS_MOUNT_FLUSHONCOMMIT		= (1UL << 7),
-	BTRFS_MOUNT_SSD_SPREAD			= (1UL << 8),
-	BTRFS_MOUNT_NOSSD			= (1UL << 9),
-	BTRFS_MOUNT_DISCARD_SYNC		= (1UL << 10),
-	BTRFS_MOUNT_FORCE_COMPRESS      	= (1UL << 11),
-	BTRFS_MOUNT_SPACE_CACHE			= (1UL << 12),
-	BTRFS_MOUNT_CLEAR_CACHE			= (1UL << 13),
-	BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED	= (1UL << 14),
-	BTRFS_MOUNT_ENOSPC_DEBUG		= (1UL << 15),
-	BTRFS_MOUNT_AUTO_DEFRAG			= (1UL << 16),
-	BTRFS_MOUNT_USEBACKUPROOT		= (1UL << 17),
-	BTRFS_MOUNT_SKIP_BALANCE		= (1UL << 18),
-	BTRFS_MOUNT_PANIC_ON_FATAL_ERROR	= (1UL << 19),
-	BTRFS_MOUNT_RESCAN_UUID_TREE		= (1UL << 20),
-	BTRFS_MOUNT_FRAGMENT_DATA		= (1UL << 21),
-	BTRFS_MOUNT_FRAGMENT_METADATA		= (1UL << 22),
-	BTRFS_MOUNT_FREE_SPACE_TREE		= (1UL << 23),
-	BTRFS_MOUNT_NOLOGREPLAY			= (1UL << 24),
-	BTRFS_MOUNT_REF_VERIFY			= (1UL << 25),
-	BTRFS_MOUNT_DISCARD_ASYNC		= (1UL << 26),
-	BTRFS_MOUNT_IGNOREBADROOTS		= (1UL << 27),
-	BTRFS_MOUNT_IGNOREDATACSUMS		= (1UL << 28),
-	BTRFS_MOUNT_NODISCARD			= (1UL << 29),
-	BTRFS_MOUNT_NOSPACECACHE		= (1UL << 30),
-	BTRFS_MOUNT_IGNOREMETACSUMS		= (1UL << 31),
+	BTRFS_MOUNT_NODATASUM			= (1ULL << 0),
+	BTRFS_MOUNT_NODATACOW			= (1ULL << 1),
+	BTRFS_MOUNT_NOBARRIER			= (1ULL << 2),
+	BTRFS_MOUNT_SSD				= (1ULL << 3),
+	BTRFS_MOUNT_DEGRADED			= (1ULL << 4),
+	BTRFS_MOUNT_COMPRESS			= (1ULL << 5),
+	BTRFS_MOUNT_NOTREELOG			= (1ULL << 6),
+	BTRFS_MOUNT_FLUSHONCOMMIT		= (1ULL << 7),
+	BTRFS_MOUNT_SSD_SPREAD			= (1ULL << 8),
+	BTRFS_MOUNT_NOSSD			= (1ULL << 9),
+	BTRFS_MOUNT_DISCARD_SYNC		= (1ULL << 10),
+	BTRFS_MOUNT_FORCE_COMPRESS		= (1ULL << 11),
+	BTRFS_MOUNT_SPACE_CACHE			= (1ULL << 12),
+	BTRFS_MOUNT_CLEAR_CACHE			= (1ULL << 13),
+	BTRFS_MOUNT_USER_SUBVOL_RM_ALLOWED	= (1ULL << 14),
+	BTRFS_MOUNT_ENOSPC_DEBUG		= (1ULL << 15),
+	BTRFS_MOUNT_AUTO_DEFRAG			= (1ULL << 16),
+	BTRFS_MOUNT_USEBACKUPROOT		= (1ULL << 17),
+	BTRFS_MOUNT_SKIP_BALANCE		= (1ULL << 18),
+	BTRFS_MOUNT_PANIC_ON_FATAL_ERROR	= (1ULL << 19),
+	BTRFS_MOUNT_RESCAN_UUID_TREE		= (1ULL << 20),
+	BTRFS_MOUNT_FRAGMENT_DATA		= (1ULL << 21),
+	BTRFS_MOUNT_FRAGMENT_METADATA		= (1ULL << 22),
+	BTRFS_MOUNT_FREE_SPACE_TREE		= (1ULL << 23),
+	BTRFS_MOUNT_NOLOGREPLAY			= (1ULL << 24),
+	BTRFS_MOUNT_REF_VERIFY			= (1ULL << 25),
+	BTRFS_MOUNT_DISCARD_ASYNC		= (1ULL << 26),
+	BTRFS_MOUNT_IGNOREBADROOTS		= (1ULL << 27),
+	BTRFS_MOUNT_IGNOREDATACSUMS		= (1ULL << 28),
+	BTRFS_MOUNT_NODISCARD			= (1ULL << 29),
+	BTRFS_MOUNT_NOSPACECACHE		= (1ULL << 30),
+	BTRFS_MOUNT_IGNOREMETACSUMS		= (1ULL << 31),
 	BTRFS_MOUNT_IGNORESUPERFLAGS		= (1ULL << 32),
 };
 
@@ -481,7 +481,7 @@  struct btrfs_fs_info {
 	 * required instead of the faster short fsync log commits
 	 */
 	u64 last_trans_log_full_commit;
-	unsigned long mount_opt;
+	unsigned long long mount_opt;
 
 	unsigned long compress_type:4;
 	unsigned int compress_level;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 0eda8c21d861..08d33cb372fb 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -82,7 +82,7 @@  struct btrfs_fs_context {
 	u32 commit_interval;
 	u32 metadata_ratio;
 	u32 thread_pool_size;
-	unsigned long mount_opt;
+	unsigned long long mount_opt;
 	unsigned long compress_type:4;
 	unsigned int compress_level;
 	refcount_t refs;
@@ -642,7 +642,7 @@  static void btrfs_clear_oneshot_options(struct btrfs_fs_info *fs_info)
 }
 
 static bool check_ro_option(const struct btrfs_fs_info *fs_info,
-			    unsigned long mount_opt, unsigned long opt,
+			    unsigned long long mount_opt, unsigned long long opt,
 			    const char *opt_name)
 {
 	if (mount_opt & opt) {
@@ -653,7 +653,8 @@  static bool check_ro_option(const struct btrfs_fs_info *fs_info,
 	return false;
 }
 
-bool btrfs_check_options(const struct btrfs_fs_info *info, unsigned long *mount_opt,
+bool btrfs_check_options(const struct btrfs_fs_info *info,
+			 unsigned long long *mount_opt,
 			 unsigned long flags)
 {
 	bool ret = true;
@@ -1231,7 +1232,7 @@  static void btrfs_resize_thread_pool(struct btrfs_fs_info *fs_info,
 }
 
 static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
-				       unsigned long old_opts, int flags)
+				       unsigned long long old_opts, int flags)
 {
 	if (btrfs_raw_test_opt(old_opts, AUTO_DEFRAG) &&
 	    (!btrfs_raw_test_opt(fs_info->mount_opt, AUTO_DEFRAG) ||
@@ -1245,7 +1246,7 @@  static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
 }
 
 static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
-					 unsigned long old_opts)
+					 unsigned long long old_opts)
 {
 	const bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE);
 
diff --git a/fs/btrfs/super.h b/fs/btrfs/super.h
index d2b8ebb46bc6..d80a86acfbbe 100644
--- a/fs/btrfs/super.h
+++ b/fs/btrfs/super.h
@@ -10,7 +10,8 @@ 
 struct super_block;
 struct btrfs_fs_info;
 
-bool btrfs_check_options(const struct btrfs_fs_info *info, unsigned long *mount_opt,
+bool btrfs_check_options(const struct btrfs_fs_info *info,
+			 unsigned long long *mount_opt,
 			 unsigned long flags);
 int btrfs_sync_fs(struct super_block *sb, int wait);
 char *btrfs_get_subvol_name_from_objectid(struct btrfs_fs_info *fs_info,
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index df7733044f7e..66f63e82af79 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -767,7 +767,8 @@  int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info)
 	return 0;
 }
 
-int btrfs_check_mountopts_zoned(const struct btrfs_fs_info *info, unsigned long *mount_opt)
+int btrfs_check_mountopts_zoned(const struct btrfs_fs_info *info,
+				unsigned long long *mount_opt)
 {
 	if (!btrfs_is_zoned(info))
 		return 0;
diff --git a/fs/btrfs/zoned.h b/fs/btrfs/zoned.h
index d66d00c08001..30b2e48a1cec 100644
--- a/fs/btrfs/zoned.h
+++ b/fs/btrfs/zoned.h
@@ -58,7 +58,8 @@  int btrfs_get_dev_zone_info(struct btrfs_device *device, bool populate_cache);
 void btrfs_destroy_dev_zone_info(struct btrfs_device *device);
 struct btrfs_zoned_device_info *btrfs_clone_dev_zone_info(struct btrfs_device *orig_dev);
 int btrfs_check_zoned_mode(struct btrfs_fs_info *fs_info);
-int btrfs_check_mountopts_zoned(const struct btrfs_fs_info *info, unsigned long *mount_opt);
+int btrfs_check_mountopts_zoned(const struct btrfs_fs_info *info,
+				unsigned long long *mount_opt);
 int btrfs_sb_log_location_bdev(struct block_device *bdev, int mirror, int rw,
 			       u64 *bytenr_ret);
 int btrfs_sb_log_location(struct btrfs_device *device, int mirror, int rw,
@@ -130,7 +131,7 @@  static inline int btrfs_check_zoned_mode(const struct btrfs_fs_info *fs_info)
 }
 
 static inline int btrfs_check_mountopts_zoned(const struct btrfs_fs_info *info,
-					      unsigned long *mount_opt)
+					      unsigned long long *mount_opt)
 {
 	return 0;
 }