]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: get rid of btrfs_read_dev_super()
authorQu Wenruo <wqu@suse.com>
Mon, 28 Apr 2025 00:46:19 +0000 (10:16 +0930)
committerDavid Sterba <dsterba@suse.com>
Thu, 15 May 2025 12:30:50 +0000 (14:30 +0200)
The function is introduced by commit a512bbf855ff ("Btrfs: superblock
duplication") at the beginning of btrfs.

It leaved a comment saying we'd need a special mount option to read all
super blocks, but it's never been implemented and there was not
need/request for it. The check/rescue tools are able to start from a
specific copy and use it as primary eventually.

This means btrfs_read_dev_super() is always reading the first super
block, making all the code finding the latest super block unnecessary.

Just remove that function and replace all call sites with
btrfs_read_disk_super(bdev, 0, false).

Signed-off-by: Qu Wenruo <wqu@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/volumes.c

index 1768618d8a604eb09a616e62666b734368c4c0a1..308e8f384ecbb4d8f65b1cf3c53f872981bdb947 100644 (file)
@@ -3317,7 +3317,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
        /*
         * Read super block and check the signature bytes only
         */
-       disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev);
+       disk_super = btrfs_read_disk_super(fs_devices->latest_dev->bdev, 0, false);
        if (IS_ERR(disk_super)) {
                ret = PTR_ERR(disk_super);
                goto fail_alloc;
@@ -3712,34 +3712,6 @@ static void btrfs_end_super_write(struct bio *bio)
        bio_put(bio);
 }
 
-struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev)
-{
-       struct btrfs_super_block *super, *latest = NULL;
-       int i;
-       u64 transid = 0;
-
-       /* we would like to check all the supers, but that would make
-        * a btrfs mount succeed after a mkfs from a different FS.
-        * So, we need to add a special mount option to scan for
-        * later supers, using BTRFS_SUPER_MIRROR_MAX instead
-        */
-       for (i = 0; i < 1; i++) {
-               super = btrfs_read_disk_super(bdev, i, false);
-               if (IS_ERR(super))
-                       continue;
-
-               if (!latest || btrfs_super_generation(super) > transid) {
-                       if (latest)
-                               btrfs_release_disk_super(super);
-
-                       latest = super;
-                       transid = btrfs_super_generation(super);
-               }
-       }
-
-       return super;
-}
-
 /*
  * Write superblock @sb to the @device. Do not wait for completion, all the
  * folios we use for writing are locked.
index 0ac9baf1215fed6425e04a1a275726364e242856..864a55a96226e7327028267d73d9396e54dcdede 100644 (file)
@@ -58,7 +58,6 @@ 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_fs_info *fs_info, int max_mirrors);
-struct btrfs_super_block *btrfs_read_dev_super(struct block_device *bdev);
 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 8478fb5ce44617b9346e27c98f9b367309358db2..db1c924a636b0330ac7f57b7a68aa68ca3330cfd 100644 (file)
@@ -493,7 +493,7 @@ btrfs_get_bdev_and_sb(const char *device_path, blk_mode_t flags, void *holder,
                }
        }
        invalidate_bdev(bdev);
-       *disk_super = btrfs_read_dev_super(bdev);
+       *disk_super = btrfs_read_disk_super(bdev, 0, false);
        if (IS_ERR(*disk_super)) {
                ret = PTR_ERR(*disk_super);
                fput(*bdev_file);