Skip to content

Commit f5569fe

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: prepare for allowing DUP on zoned
Allow for a block-group to be placed on more than one physical zone. This is a preparation for allowing DUP profiles for meta-data on a zoned file-system. Signed-off-by: Johannes Thumshirn <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent ad48bff commit f5569fe

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

fs/btrfs/zoned.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,12 +1215,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
12151215
struct btrfs_device *device;
12161216
u64 logical = cache->start;
12171217
u64 length = cache->length;
1218-
u64 physical = 0;
12191218
int ret;
12201219
int i;
12211220
unsigned int nofs_flag;
12221221
u64 *alloc_offsets = NULL;
12231222
u64 *caps = NULL;
1223+
u64 *physical = NULL;
12241224
unsigned long *active = NULL;
12251225
u64 last_alloc = 0;
12261226
u32 num_sequential = 0, num_conventional = 0;
@@ -1264,6 +1264,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
12641264
goto out;
12651265
}
12661266

1267+
physical = kcalloc(map->num_stripes, sizeof(*physical), GFP_NOFS);
1268+
if (!physical) {
1269+
ret = -ENOMEM;
1270+
goto out;
1271+
}
1272+
12671273
active = bitmap_zalloc(map->num_stripes, GFP_NOFS);
12681274
if (!active) {
12691275
ret = -ENOMEM;
@@ -1277,14 +1283,14 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
12771283
int dev_replace_is_ongoing = 0;
12781284

12791285
device = map->stripes[i].dev;
1280-
physical = map->stripes[i].physical;
1286+
physical[i] = map->stripes[i].physical;
12811287

12821288
if (device->bdev == NULL) {
12831289
alloc_offsets[i] = WP_MISSING_DEV;
12841290
continue;
12851291
}
12861292

1287-
is_sequential = btrfs_dev_is_sequential(device, physical);
1293+
is_sequential = btrfs_dev_is_sequential(device, physical[i]);
12881294
if (is_sequential)
12891295
num_sequential++;
12901296
else
@@ -1299,21 +1305,21 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
12991305
* This zone will be used for allocation, so mark this zone
13001306
* non-empty.
13011307
*/
1302-
btrfs_dev_clear_zone_empty(device, physical);
1308+
btrfs_dev_clear_zone_empty(device, physical[i]);
13031309

13041310
down_read(&dev_replace->rwsem);
13051311
dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing(dev_replace);
13061312
if (dev_replace_is_ongoing && dev_replace->tgtdev != NULL)
1307-
btrfs_dev_clear_zone_empty(dev_replace->tgtdev, physical);
1313+
btrfs_dev_clear_zone_empty(dev_replace->tgtdev, physical[i]);
13081314
up_read(&dev_replace->rwsem);
13091315

13101316
/*
13111317
* The group is mapped to a sequential zone. Get the zone write
13121318
* pointer to determine the allocation offset within the zone.
13131319
*/
1314-
WARN_ON(!IS_ALIGNED(physical, fs_info->zone_size));
1320+
WARN_ON(!IS_ALIGNED(physical[i], fs_info->zone_size));
13151321
nofs_flag = memalloc_nofs_save();
1316-
ret = btrfs_get_dev_zone(device, physical, &zone);
1322+
ret = btrfs_get_dev_zone(device, physical[i], &zone);
13171323
memalloc_nofs_restore(nofs_flag);
13181324
if (ret == -EIO || ret == -EOPNOTSUPP) {
13191325
ret = 0;
@@ -1339,7 +1345,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
13391345
case BLK_ZONE_COND_READONLY:
13401346
btrfs_err(fs_info,
13411347
"zoned: offline/readonly zone %llu on device %s (devid %llu)",
1342-
physical >> device->zone_info->zone_size_shift,
1348+
physical[i] >> device->zone_info->zone_size_shift,
13431349
rcu_str_deref(device->name), device->devid);
13441350
alloc_offsets[i] = WP_MISSING_DEV;
13451351
break;
@@ -1404,7 +1410,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
14041410
if (alloc_offsets[0] == WP_MISSING_DEV) {
14051411
btrfs_err(fs_info,
14061412
"zoned: cannot recover write pointer for zone %llu",
1407-
physical);
1413+
physical[0]);
14081414
ret = -EIO;
14091415
goto out;
14101416
}
@@ -1465,6 +1471,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
14651471
cache->physical_map = NULL;
14661472
}
14671473
bitmap_free(active);
1474+
kfree(physical);
14681475
kfree(caps);
14691476
kfree(alloc_offsets);
14701477
free_extent_map(em);

0 commit comments

Comments
 (0)