]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: remove max_mirrors argument from write_all_supers()
authorFilipe Manana <fdmanana@suse.com>
Tue, 3 Feb 2026 19:45:14 +0000 (19:45 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 16:55:54 +0000 (18:55 +0200)
There's no need to pass max_mirrors to write_all_supers() since from the
given transaction handle we can infer if we are in a transaction commit
or fsync context, so we can determine how many mirrors we need to use.

So remove the max_mirror argument from write_all_supers() and stop
adjusting it in the callees write_dev_supers() and wait_dev_supers(),
simplifying them besides the parameter list for write_all_supers().

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/transaction.c
fs/btrfs/tree-log.c

index 89f5423f0366c45649e8619c8ad62d8cb9c18105..e4a2673ffeaa64486aad6e22cac031ca25b5722c 100644 (file)
@@ -3756,8 +3756,7 @@ static void btrfs_end_super_write(struct bio *bio)
  * Write superblock @sb to the @device. Do not wait for completion, all the
  * folios we use for writing are locked.
  *
- * Write @max_mirrors copies of the superblock, where 0 means default that fit
- * the expected device size at commit time. Note that max_mirrors must be
+ * Write @max_mirrors copies of the superblock. Note that max_mirrors must be
  * same for write and wait phases.
  *
  * Return number of errors when folio is not found or submission fails.
@@ -3773,9 +3772,6 @@ static int write_dev_supers(struct btrfs_device *device,
 
        atomic_set(&device->sb_write_errors, 0);
 
-       if (max_mirrors == 0)
-               max_mirrors = BTRFS_SUPER_MIRROR_MAX;
-
        for (i = 0; i < max_mirrors; i++) {
                struct folio *folio;
                struct bio *bio;
@@ -3860,9 +3856,6 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors)
        int ret;
        u64 bytenr;
 
-       if (max_mirrors == 0)
-               max_mirrors = BTRFS_SUPER_MIRROR_MAX;
-
        for (i = 0; i < max_mirrors; i++) {
                struct folio *folio;
 
@@ -4032,13 +4025,14 @@ int btrfs_get_num_tolerated_disk_barrier_failures(u64 flags)
        return min_tolerated;
 }
 
-int write_all_supers(struct btrfs_trans_handle *trans, int max_mirrors)
+int write_all_supers(struct btrfs_trans_handle *trans)
 {
        struct btrfs_fs_info *fs_info = trans->fs_info;
        struct list_head *head;
        struct btrfs_device *dev;
        struct btrfs_super_block *sb;
        struct btrfs_dev_item *dev_item;
+       int max_mirrors;
        int ret;
        int do_barriers;
        int max_errors;
@@ -4047,12 +4041,12 @@ int write_all_supers(struct btrfs_trans_handle *trans, int max_mirrors)
 
        do_barriers = !btrfs_test_opt(fs_info, NOBARRIER);
 
-       /*
-        * max_mirrors == 0 indicates we're from commit_transaction,
-        * not from fsync where the tree roots in fs_info have not
-        * been consistent on disk.
-        */
-       if (max_mirrors == 0) {
+       if (trans->transaction->state < TRANS_STATE_UNBLOCKED) {
+               /* We are called from fsync. */
+               max_mirrors = 1;
+       } else {
+               /* We are called from transaction commit. */
+               max_mirrors = BTRFS_SUPER_MIRROR_MAX;
                ret = backup_super_roots(fs_info);
                if (ret < 0)
                        return ret;
index 081a6860861c2b16988e44b6b3f9bde60e3be4e0..163f5114973a30c60460d753c7b143acbeed1943 100644 (file)
@@ -58,7 +58,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info);
 int btrfs_validate_super(const struct btrfs_fs_info *fs_info,
                         const struct btrfs_super_block *sb, int mirror_num);
 int btrfs_check_features(struct btrfs_fs_info *fs_info, bool is_rw_mount);
-int write_all_supers(struct btrfs_trans_handle *trans, int max_mirrors);
+int write_all_supers(struct btrfs_trans_handle *trans);
 int btrfs_commit_super(struct btrfs_fs_info *fs_info);
 struct btrfs_root *btrfs_read_tree_root(struct btrfs_root *tree_root,
                                        const struct btrfs_key *key);
index 8f24a025625ead9f0e668f07291d005feebab435..4c1fcf9a71a2456ddaad7a7de2e682195b84ef3d 100644 (file)
@@ -2573,7 +2573,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                goto scrub_continue;
        }
 
-       ret = write_all_supers(trans, 0);
+       ret = write_all_supers(trans);
        /*
         * the super is written, we can safely allow the tree-loggers
         * to go about their business
index 4f360ccf8380e2177cae5b114fb960e2beb976bc..304a4325e2e091fe7a7c33ee0509527af3fbbbd7 100644 (file)
@@ -3576,7 +3576,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
 
        btrfs_set_super_log_root(fs_info->super_for_commit, log_root_start);
        btrfs_set_super_log_root_level(fs_info->super_for_commit, log_root_level);
-       ret = write_all_supers(trans, 1);
+       ret = write_all_supers(trans);
        mutex_unlock(&fs_info->tree_log_mutex);
        if (unlikely(ret)) {
                btrfs_set_log_full_commit(trans);