Skip to content

Commit 95617d6

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: cleanup, stop casting for extent_map->lookup everywhere
Overloading extent_map->bdev to struct map_lookup * might have started out as a means to an end, but it's a pattern that's used all over the place now. Let's get rid of the casting and just add a union instead. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a7ca422 commit 95617d6

6 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎fs/btrfs/dev-replace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ static void btrfs_dev_replace_update_device_in_mapping_tree(
614614
em = lookup_extent_mapping(em_tree, start, (u64)-1);
615615
if (!em)
616616
break;
617-
map = (struct map_lookup *)em->bdev;
617+
map = em->map_lookup;
618618
for (i = 0; i < map->num_stripes; i++)
619619
if (srcdev == map->stripes[i].dev)
620620
map->stripes[i].dev = tgtdev;

‎fs/btrfs/extent-tree.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10322,7 +10322,7 @@ btrfs_start_trans_remove_block_group(struct btrfs_fs_info *fs_info,
1032210322
* more device items and remove one chunk item), but this is done at
1032310323
* btrfs_remove_chunk() through a call to check_system_chunk().
1032410324
*/
10325-
map = (struct map_lookup *)em->bdev;
10325+
map = em->map_lookup;
1032610326
num_items = 3 + map->num_stripes;
1032710327
free_extent_map(em);
1032810328

‎fs/btrfs/extent_map.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void free_extent_map(struct extent_map *em)
7676
WARN_ON(extent_map_in_tree(em));
7777
WARN_ON(!list_empty(&em->list));
7878
if (test_bit(EXTENT_FLAG_FS_MAPPING, &em->flags))
79-
kfree(em->bdev);
79+
kfree(em->map_lookup);
8080
kmem_cache_free(extent_map_cache, em);
8181
}
8282
}

‎fs/btrfs/extent_map.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ struct extent_map {
3232
u64 block_len;
3333
u64 generation;
3434
unsigned long flags;
35-
struct block_device *bdev;
35+
union {
36+
struct block_device *bdev;
37+
38+
/*
39+
* used for chunk mappings
40+
* flags & EXTENT_FLAG_FS_MAPPING must be set
41+
*/
42+
struct map_lookup *map_lookup;
43+
};
3644
atomic_t refs;
3745
unsigned int compress_type;
3846
struct list_head list;

‎fs/btrfs/scrub.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3458,7 +3458,7 @@ static noinline_for_stack int scrub_chunk(struct scrub_ctx *sctx,
34583458
return ret;
34593459
}
34603460

3461-
map = (struct map_lookup *)em->bdev;
3461+
map = em->map_lookup;
34623462
if (em->start != chunk_offset)
34633463
goto out;
34643464

‎fs/btrfs/volumes.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ static int contains_pending_extent(struct btrfs_transaction *transaction,
11821182
struct map_lookup *map;
11831183
int i;
11841184

1185-
map = (struct map_lookup *)em->bdev;
1185+
map = em->map_lookup;
11861186
for (i = 0; i < map->num_stripes; i++) {
11871187
u64 end;
11881188

@@ -2754,7 +2754,7 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
27542754
free_extent_map(em);
27552755
return -EINVAL;
27562756
}
2757-
map = (struct map_lookup *)em->bdev;
2757+
map = em->map_lookup;
27582758
lock_chunks(root->fs_info->chunk_root);
27592759
check_system_chunk(trans, extent_root, map->type);
27602760
unlock_chunks(root->fs_info->chunk_root);
@@ -4718,7 +4718,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
47184718
goto error;
47194719
}
47204720
set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags);
4721-
em->bdev = (struct block_device *)map;
4721+
em->map_lookup = map;
47224722
em->start = start;
47234723
em->len = num_bytes;
47244724
em->block_start = 0;
@@ -4813,7 +4813,7 @@ int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans,
48134813
return -EINVAL;
48144814
}
48154815

4816-
map = (struct map_lookup *)em->bdev;
4816+
map = em->map_lookup;
48174817
item_size = btrfs_chunk_item_size(map->num_stripes);
48184818
stripe_size = em->orig_block_len;
48194819

@@ -4955,7 +4955,7 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset)
49554955
if (!em)
49564956
return 1;
49574957

4958-
map = (struct map_lookup *)em->bdev;
4958+
map = em->map_lookup;
49594959
for (i = 0; i < map->num_stripes; i++) {
49604960
if (map->stripes[i].dev->missing) {
49614961
miss_ndevs++;
@@ -5035,7 +5035,7 @@ int btrfs_num_copies(struct btrfs_fs_info *fs_info, u64 logical, u64 len)
50355035
return 1;
50365036
}
50375037

5038-
map = (struct map_lookup *)em->bdev;
5038+
map = em->map_lookup;
50395039
if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1))
50405040
ret = map->num_stripes;
50415041
else if (map->type & BTRFS_BLOCK_GROUP_RAID10)
@@ -5071,7 +5071,7 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root,
50715071
BUG_ON(!em);
50725072

50735073
BUG_ON(em->start > logical || em->start + em->len < logical);
5074-
map = (struct map_lookup *)em->bdev;
5074+
map = em->map_lookup;
50755075
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
50765076
len = map->stripe_len * nr_data_stripes(map);
50775077
free_extent_map(em);
@@ -5092,7 +5092,7 @@ int btrfs_is_parity_mirror(struct btrfs_mapping_tree *map_tree,
50925092
BUG_ON(!em);
50935093

50945094
BUG_ON(em->start > logical || em->start + em->len < logical);
5095-
map = (struct map_lookup *)em->bdev;
5095+
map = em->map_lookup;
50965096
if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK)
50975097
ret = 1;
50985098
free_extent_map(em);
@@ -5251,7 +5251,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
52515251
return -EINVAL;
52525252
}
52535253

5254-
map = (struct map_lookup *)em->bdev;
5254+
map = em->map_lookup;
52555255
offset = logical - em->start;
52565256

52575257
stripe_len = map->stripe_len;
@@ -5793,7 +5793,7 @@ int btrfs_rmap_block(struct btrfs_mapping_tree *map_tree,
57935793
free_extent_map(em);
57945794
return -EIO;
57955795
}
5796-
map = (struct map_lookup *)em->bdev;
5796+
map = em->map_lookup;
57975797

57985798
length = em->len;
57995799
rmap_len = map->stripe_len;
@@ -6229,7 +6229,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key,
62296229
}
62306230

62316231
set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags);
6232-
em->bdev = (struct block_device *)map;
6232+
em->map_lookup = map;
62336233
em->start = logical;
62346234
em->len = length;
62356235
em->orig_start = 0;
@@ -6920,7 +6920,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_root *root,
69206920
/* In order to kick the device replace finish process */
69216921
lock_chunks(root);
69226922
list_for_each_entry(em, &transaction->pending_chunks, list) {
6923-
map = (struct map_lookup *)em->bdev;
6923+
map = em->map_lookup;
69246924

69256925
for (i = 0; i < map->num_stripes; i++) {
69266926
dev = map->stripes[i].dev;

0 commit comments

Comments
 (0)