Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jeff Mahoney and committed by
David Sterba
95617d69 a7ca4225

+25 -17
+1 -1
fs/btrfs/dev-replace.c
··· 614 614 em = lookup_extent_mapping(em_tree, start, (u64)-1); 615 615 if (!em) 616 616 break; 617 - map = (struct map_lookup *)em->bdev; 617 + map = em->map_lookup; 618 618 for (i = 0; i < map->num_stripes; i++) 619 619 if (srcdev == map->stripes[i].dev) 620 620 map->stripes[i].dev = tgtdev;
+1 -1
fs/btrfs/extent-tree.c
··· 10322 10322 * more device items and remove one chunk item), but this is done at 10323 10323 * btrfs_remove_chunk() through a call to check_system_chunk(). 10324 10324 */ 10325 - map = (struct map_lookup *)em->bdev; 10325 + map = em->map_lookup; 10326 10326 num_items = 3 + map->num_stripes; 10327 10327 free_extent_map(em); 10328 10328
+1 -1
fs/btrfs/extent_map.c
··· 76 76 WARN_ON(extent_map_in_tree(em)); 77 77 WARN_ON(!list_empty(&em->list)); 78 78 if (test_bit(EXTENT_FLAG_FS_MAPPING, &em->flags)) 79 - kfree(em->bdev); 79 + kfree(em->map_lookup); 80 80 kmem_cache_free(extent_map_cache, em); 81 81 } 82 82 }
+9 -1
fs/btrfs/extent_map.h
··· 32 32 u64 block_len; 33 33 u64 generation; 34 34 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 + }; 36 44 atomic_t refs; 37 45 unsigned int compress_type; 38 46 struct list_head list;
+1 -1
fs/btrfs/scrub.c
··· 3458 3458 return ret; 3459 3459 } 3460 3460 3461 - map = (struct map_lookup *)em->bdev; 3461 + map = em->map_lookup; 3462 3462 if (em->start != chunk_offset) 3463 3463 goto out; 3464 3464
+12 -12
fs/btrfs/volumes.c
··· 1182 1182 struct map_lookup *map; 1183 1183 int i; 1184 1184 1185 - map = (struct map_lookup *)em->bdev; 1185 + map = em->map_lookup; 1186 1186 for (i = 0; i < map->num_stripes; i++) { 1187 1187 u64 end; 1188 1188 ··· 2754 2754 free_extent_map(em); 2755 2755 return -EINVAL; 2756 2756 } 2757 - map = (struct map_lookup *)em->bdev; 2757 + map = em->map_lookup; 2758 2758 lock_chunks(root->fs_info->chunk_root); 2759 2759 check_system_chunk(trans, extent_root, map->type); 2760 2760 unlock_chunks(root->fs_info->chunk_root); ··· 4718 4718 goto error; 4719 4719 } 4720 4720 set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags); 4721 - em->bdev = (struct block_device *)map; 4721 + em->map_lookup = map; 4722 4722 em->start = start; 4723 4723 em->len = num_bytes; 4724 4724 em->block_start = 0; ··· 4813 4813 return -EINVAL; 4814 4814 } 4815 4815 4816 - map = (struct map_lookup *)em->bdev; 4816 + map = em->map_lookup; 4817 4817 item_size = btrfs_chunk_item_size(map->num_stripes); 4818 4818 stripe_size = em->orig_block_len; 4819 4819 ··· 4955 4955 if (!em) 4956 4956 return 1; 4957 4957 4958 - map = (struct map_lookup *)em->bdev; 4958 + map = em->map_lookup; 4959 4959 for (i = 0; i < map->num_stripes; i++) { 4960 4960 if (map->stripes[i].dev->missing) { 4961 4961 miss_ndevs++; ··· 5035 5035 return 1; 5036 5036 } 5037 5037 5038 - map = (struct map_lookup *)em->bdev; 5038 + map = em->map_lookup; 5039 5039 if (map->type & (BTRFS_BLOCK_GROUP_DUP | BTRFS_BLOCK_GROUP_RAID1)) 5040 5040 ret = map->num_stripes; 5041 5041 else if (map->type & BTRFS_BLOCK_GROUP_RAID10) ··· 5071 5071 BUG_ON(!em); 5072 5072 5073 5073 BUG_ON(em->start > logical || em->start + em->len < logical); 5074 - map = (struct map_lookup *)em->bdev; 5074 + map = em->map_lookup; 5075 5075 if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) 5076 5076 len = map->stripe_len * nr_data_stripes(map); 5077 5077 free_extent_map(em); ··· 5092 5092 BUG_ON(!em); 5093 5093 5094 5094 BUG_ON(em->start > logical || em->start + em->len < logical); 5095 - map = (struct map_lookup *)em->bdev; 5095 + map = em->map_lookup; 5096 5096 if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) 5097 5097 ret = 1; 5098 5098 free_extent_map(em); ··· 5251 5251 return -EINVAL; 5252 5252 } 5253 5253 5254 - map = (struct map_lookup *)em->bdev; 5254 + map = em->map_lookup; 5255 5255 offset = logical - em->start; 5256 5256 5257 5257 stripe_len = map->stripe_len; ··· 5793 5793 free_extent_map(em); 5794 5794 return -EIO; 5795 5795 } 5796 - map = (struct map_lookup *)em->bdev; 5796 + map = em->map_lookup; 5797 5797 5798 5798 length = em->len; 5799 5799 rmap_len = map->stripe_len; ··· 6229 6229 } 6230 6230 6231 6231 set_bit(EXTENT_FLAG_FS_MAPPING, &em->flags); 6232 - em->bdev = (struct block_device *)map; 6232 + em->map_lookup = map; 6233 6233 em->start = logical; 6234 6234 em->len = length; 6235 6235 em->orig_start = 0; ··· 6920 6920 /* In order to kick the device replace finish process */ 6921 6921 lock_chunks(root); 6922 6922 list_for_each_entry(em, &transaction->pending_chunks, list) { 6923 - map = (struct map_lookup *)em->bdev; 6923 + map = em->map_lookup; 6924 6924 6925 6925 for (i = 0; i < map->num_stripes; i++) { 6926 6926 dev = map->stripes[i].dev;