Skip to content

Commit dafc340

Browse files
naotakdave
authored andcommitted
btrfs: zoned: introduce physical_map to btrfs_block_group
We will use a block group's physical location to track active zones and finish fully written zones in the following commits. Since the zone activation is done in the extent allocation context which already holding the tree locks, we can't query the chunk tree for the physical locations. So, copy the location info into a block group and use it for activation. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent ea6f8dd commit dafc340

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

fs/btrfs/block-group.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void btrfs_put_block_group(struct btrfs_block_group *cache)
144144
*/
145145
WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root));
146146
kfree(cache->free_space_ctl);
147+
kfree(cache->physical_map);
147148
kfree(cache);
148149
}
149150
}

fs/btrfs/block-group.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct btrfs_block_group {
204204
u64 zone_unusable;
205205
u64 zone_capacity;
206206
u64 meta_write_pointer;
207+
struct map_lookup *physical_map;
207208
};
208209

209210
static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group)

fs/btrfs/zoned.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,18 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
11581158

11591159
map = em->map_lookup;
11601160

1161+
cache->physical_map = kmalloc(map_lookup_size(map->num_stripes), GFP_NOFS);
1162+
if (!cache->physical_map) {
1163+
ret = -ENOMEM;
1164+
goto out;
1165+
}
1166+
1167+
memcpy(cache->physical_map, map, map_lookup_size(map->num_stripes));
1168+
11611169
alloc_offsets = kcalloc(map->num_stripes, sizeof(*alloc_offsets), GFP_NOFS);
11621170
if (!alloc_offsets) {
1163-
free_extent_map(em);
1164-
return -ENOMEM;
1171+
ret = -ENOMEM;
1172+
goto out;
11651173
}
11661174

11671175
caps = kcalloc(map->num_stripes, sizeof(*caps), GFP_NOFS);
@@ -1344,6 +1352,10 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
13441352
if (!ret)
13451353
cache->meta_write_pointer = cache->alloc_offset + cache->start;
13461354

1355+
if (ret) {
1356+
kfree(cache->physical_map);
1357+
cache->physical_map = NULL;
1358+
}
13471359
kfree(caps);
13481360
kfree(alloc_offsets);
13491361
free_extent_map(em);

0 commit comments

Comments
 (0)