Skip to content

Commit de37aa5

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Remove fsid/metadata_fsid fields from btrfs_info
Currently btrfs_fs_info structure contains a copy of the fsid/metadata_uuid fields. Same values are also contained in the btrfs_fs_devices structure which fs_info has a reference to. Let's reduce duplication by removing the fields from fs_info and always refer to the ones in fs_devices. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 56f20f4 commit de37aa5

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

fs/btrfs/check-integrity.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ static int btrfsic_test_for_metadata(struct btrfsic_state *state,
17201720
num_pages = state->metablock_size >> PAGE_SHIFT;
17211721
h = (struct btrfs_header *)datav[0];
17221722

1723-
if (memcmp(h->fsid, fs_info->fsid, BTRFS_FSID_SIZE))
1723+
if (memcmp(h->fsid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE))
17241724
return 1;
17251725

17261726
for (i = 0; i < num_pages; i++) {

fs/btrfs/ctree.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "transaction.h"
1313
#include "print-tree.h"
1414
#include "locking.h"
15+
#include "volumes.h"
1516

1617
static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
1718
*root, struct btrfs_path *path, int level);
@@ -224,7 +225,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
224225
else
225226
btrfs_set_header_owner(cow, new_root_objectid);
226227

227-
write_extent_buffer_fsid(cow, fs_info->metadata_fsid);
228+
write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
228229

229230
WARN_ON(btrfs_header_generation(buf) > trans->transid);
230231
if (new_root_objectid == BTRFS_TREE_RELOC_OBJECTID)
@@ -1050,7 +1051,7 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
10501051
else
10511052
btrfs_set_header_owner(cow, root->root_key.objectid);
10521053

1053-
write_extent_buffer_fsid(cow, fs_info->metadata_fsid);
1054+
write_extent_buffer_fsid(cow, fs_info->fs_devices->metadata_uuid);
10541055

10551056
ret = update_ref_for_cow(trans, root, buf, cow, &last_ref);
10561057
if (ret) {

fs/btrfs/ctree.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,6 @@ bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
773773
#define BTRFS_FS_BALANCE_RUNNING 18
774774

775775
struct btrfs_fs_info {
776-
/* User-visible fs UUID */
777-
u8 fsid[BTRFS_FSID_SIZE];
778-
/* UUID written to btree blocks */
779-
u8 metadata_fsid[BTRFS_FSID_SIZE];
780776
u8 chunk_tree_uuid[BTRFS_UUID_SIZE];
781777
unsigned long flags;
782778
struct btrfs_root *extent_root;

fs/btrfs/disk-io.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static int csum_dirty_buffer(struct btrfs_fs_info *fs_info, struct page *page)
542542
if (WARN_ON(!PageUptodate(page)))
543543
return -EUCLEAN;
544544

545-
ASSERT(memcmp_extent_buffer(eb, fs_info->metadata_fsid,
545+
ASSERT(memcmp_extent_buffer(eb, fs_info->fs_devices->metadata_uuid,
546546
btrfs_header_fsid(), BTRFS_FSID_SIZE) == 0);
547547

548548
return csum_tree_block(fs_info, eb, 0);
@@ -2456,11 +2456,11 @@ static int validate_super(struct btrfs_fs_info *fs_info,
24562456
ret = -EINVAL;
24572457
}
24582458

2459-
if (memcmp(fs_info->metadata_fsid, sb->dev_item.fsid,
2459+
if (memcmp(fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid,
24602460
BTRFS_FSID_SIZE) != 0) {
24612461
btrfs_err(fs_info,
24622462
"dev_item UUID does not match metadata fsid: %pU != %pU",
2463-
fs_info->metadata_fsid, sb->dev_item.fsid);
2463+
fs_info->fs_devices->metadata_uuid, sb->dev_item.fsid);
24642464
ret = -EINVAL;
24652465
}
24662466

@@ -2803,14 +2803,16 @@ int open_ctree(struct super_block *sb,
28032803
sizeof(*fs_info->super_for_commit));
28042804
brelse(bh);
28052805

2806-
memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE);
2806+
ASSERT(!memcmp(fs_info->fs_devices->fsid, fs_info->super_copy->fsid,
2807+
BTRFS_FSID_SIZE));
2808+
28072809
if (btrfs_fs_incompat(fs_info, METADATA_UUID)) {
2808-
memcpy(fs_info->metadata_fsid,
2809-
fs_info->super_copy->metadata_uuid, BTRFS_FSID_SIZE);
2810-
} else {
2811-
memcpy(fs_info->metadata_fsid, fs_info->fsid, BTRFS_FSID_SIZE);
2810+
ASSERT(!memcmp(fs_info->fs_devices->metadata_uuid,
2811+
fs_info->super_copy->metadata_uuid,
2812+
BTRFS_FSID_SIZE));
28122813
}
28132814

2815+
28142816
ret = btrfs_validate_mount_super(fs_info);
28152817
if (ret) {
28162818
btrfs_err(fs_info, "superblock contains fatal errors");
@@ -2930,7 +2932,7 @@ int open_ctree(struct super_block *sb,
29302932

29312933
sb->s_blocksize = sectorsize;
29322934
sb->s_blocksize_bits = blksize_bits(sectorsize);
2933-
memcpy(&sb->s_uuid, fs_info->fsid, BTRFS_FSID_SIZE);
2935+
memcpy(&sb->s_uuid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE);
29342936

29352937
mutex_lock(&fs_info->chunk_mutex);
29362938
ret = btrfs_read_sys_array(fs_info);

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8312,7 +8312,7 @@ btrfs_init_new_buffer(struct btrfs_trans_handle *trans, struct btrfs_root *root,
83128312
btrfs_set_header_generation(buf, trans->transid);
83138313
btrfs_set_header_backref_rev(buf, BTRFS_MIXED_BACKREF_REV);
83148314
btrfs_set_header_owner(buf, owner);
8315-
write_extent_buffer_fsid(buf, fs_info->metadata_fsid);
8315+
write_extent_buffer_fsid(buf, fs_info->fs_devices->metadata_uuid);
83168316
write_extent_buffer_chunk_tree_uuid(buf, fs_info->chunk_tree_uuid);
83178317
if (root->root_key.objectid == BTRFS_TREE_LOG_OBJECTID) {
83188318
buf->log_index = root->log_transid % 2;

fs/btrfs/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3150,7 +3150,7 @@ static long btrfs_ioctl_fs_info(struct btrfs_fs_info *fs_info,
31503150
}
31513151
rcu_read_unlock();
31523152

3153-
memcpy(&fi_args->fsid, fs_info->fsid, sizeof(fi_args->fsid));
3153+
memcpy(&fi_args->fsid, fs_devices->fsid, sizeof(fi_args->fsid));
31543154
fi_args->nodesize = fs_info->nodesize;
31553155
fi_args->sectorsize = fs_info->sectorsize;
31563156
fi_args->clone_alignment = fs_info->sectorsize;

fs/btrfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2090,7 +2090,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
20902090
u64 total_free_data = 0;
20912091
u64 total_free_meta = 0;
20922092
int bits = dentry->d_sb->s_blocksize_bits;
2093-
__be32 *fsid = (__be32 *)fs_info->fsid;
2093+
__be32 *fsid = (__be32 *)fs_info->fs_devices->fsid;
20942094
unsigned factor = 1;
20952095
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
20962096
int ret;

fs/btrfs/volumes.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,8 +1780,8 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
17801780
ptr = btrfs_device_uuid(dev_item);
17811781
write_extent_buffer(leaf, device->uuid, ptr, BTRFS_UUID_SIZE);
17821782
ptr = btrfs_device_fsid(dev_item);
1783-
write_extent_buffer(leaf, trans->fs_info->metadata_fsid, ptr,
1784-
BTRFS_FSID_SIZE);
1783+
write_extent_buffer(leaf, trans->fs_info->fs_devices->metadata_uuid,
1784+
ptr, BTRFS_FSID_SIZE);
17851785
btrfs_mark_buffer_dirty(leaf);
17861786

17871787
ret = 0;
@@ -2324,9 +2324,7 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
23242324
fs_devices->seed = seed_devices;
23252325

23262326
generate_random_uuid(fs_devices->fsid);
2327-
memcpy(fs_info->fsid, fs_devices->fsid, BTRFS_FSID_SIZE);
23282327
memcpy(fs_devices->metadata_uuid, fs_devices->fsid, BTRFS_FSID_SIZE);
2329-
memcpy(fs_info->metadata_fsid, fs_devices->fsid, BTRFS_FSID_SIZE);
23302328
memcpy(disk_super->fsid, fs_devices->fsid, BTRFS_FSID_SIZE);
23312329
mutex_unlock(&fs_devices->device_list_mutex);
23322330

@@ -2568,7 +2566,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
25682566
* so rename the fsid on the sysfs
25692567
*/
25702568
snprintf(fsid_buf, BTRFS_UUID_UNPARSED_SIZE, "%pU",
2571-
fs_info->fsid);
2569+
fs_info->fs_devices->fsid);
25722570
if (kobject_rename(&fs_devices->fsid_kobj, fsid_buf))
25732571
btrfs_warn(fs_info,
25742572
"sysfs: failed to create fsid for sprout");
@@ -6722,7 +6720,7 @@ static int read_one_dev(struct btrfs_fs_info *fs_info,
67226720
read_extent_buffer(leaf, fs_uuid, btrfs_device_fsid(dev_item),
67236721
BTRFS_FSID_SIZE);
67246722

6725-
if (memcmp(fs_uuid, fs_info->metadata_fsid, BTRFS_FSID_SIZE)) {
6723+
if (memcmp(fs_uuid, fs_devices->metadata_uuid, BTRFS_FSID_SIZE)) {
67266724
fs_devices = open_seed_devices(fs_info, fs_uuid);
67276725
if (IS_ERR(fs_devices))
67286726
return PTR_ERR(fs_devices);

include/trace/events/btrfs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ TRACE_DEFINE_ENUM(COMMIT_TRANS);
9292
#define TP_STRUCT__entry_fsid __array(u8, fsid, BTRFS_FSID_SIZE)
9393

9494
#define TP_fast_assign_fsid(fs_info) \
95-
memcpy(__entry->fsid, fs_info->fsid, BTRFS_FSID_SIZE)
95+
memcpy(__entry->fsid, fs_info->fs_devices->fsid, BTRFS_FSID_SIZE)
9696

9797
#define TP_STRUCT__entry_btrfs(args...) \
9898
TP_STRUCT__entry( \

0 commit comments

Comments
 (0)