@@ -1215,12 +1215,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1215
1215
struct btrfs_device * device ;
1216
1216
u64 logical = cache -> start ;
1217
1217
u64 length = cache -> length ;
1218
- u64 physical = 0 ;
1219
1218
int ret ;
1220
1219
int i ;
1221
1220
unsigned int nofs_flag ;
1222
1221
u64 * alloc_offsets = NULL ;
1223
1222
u64 * caps = NULL ;
1223
+ u64 * physical = NULL ;
1224
1224
unsigned long * active = NULL ;
1225
1225
u64 last_alloc = 0 ;
1226
1226
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)
1264
1264
goto out ;
1265
1265
}
1266
1266
1267
+ physical = kcalloc (map -> num_stripes , sizeof (* physical ), GFP_NOFS );
1268
+ if (!physical ) {
1269
+ ret = - ENOMEM ;
1270
+ goto out ;
1271
+ }
1272
+
1267
1273
active = bitmap_zalloc (map -> num_stripes , GFP_NOFS );
1268
1274
if (!active ) {
1269
1275
ret = - ENOMEM ;
@@ -1277,14 +1283,14 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1277
1283
int dev_replace_is_ongoing = 0 ;
1278
1284
1279
1285
device = map -> stripes [i ].dev ;
1280
- physical = map -> stripes [i ].physical ;
1286
+ physical [ i ] = map -> stripes [i ].physical ;
1281
1287
1282
1288
if (device -> bdev == NULL ) {
1283
1289
alloc_offsets [i ] = WP_MISSING_DEV ;
1284
1290
continue ;
1285
1291
}
1286
1292
1287
- is_sequential = btrfs_dev_is_sequential (device , physical );
1293
+ is_sequential = btrfs_dev_is_sequential (device , physical [ i ] );
1288
1294
if (is_sequential )
1289
1295
num_sequential ++ ;
1290
1296
else
@@ -1299,21 +1305,21 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1299
1305
* This zone will be used for allocation, so mark this zone
1300
1306
* non-empty.
1301
1307
*/
1302
- btrfs_dev_clear_zone_empty (device , physical );
1308
+ btrfs_dev_clear_zone_empty (device , physical [ i ] );
1303
1309
1304
1310
down_read (& dev_replace -> rwsem );
1305
1311
dev_replace_is_ongoing = btrfs_dev_replace_is_ongoing (dev_replace );
1306
1312
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 ] );
1308
1314
up_read (& dev_replace -> rwsem );
1309
1315
1310
1316
/*
1311
1317
* The group is mapped to a sequential zone. Get the zone write
1312
1318
* pointer to determine the allocation offset within the zone.
1313
1319
*/
1314
- WARN_ON (!IS_ALIGNED (physical , fs_info -> zone_size ));
1320
+ WARN_ON (!IS_ALIGNED (physical [ i ] , fs_info -> zone_size ));
1315
1321
nofs_flag = memalloc_nofs_save ();
1316
- ret = btrfs_get_dev_zone (device , physical , & zone );
1322
+ ret = btrfs_get_dev_zone (device , physical [ i ] , & zone );
1317
1323
memalloc_nofs_restore (nofs_flag );
1318
1324
if (ret == - EIO || ret == - EOPNOTSUPP ) {
1319
1325
ret = 0 ;
@@ -1339,7 +1345,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1339
1345
case BLK_ZONE_COND_READONLY :
1340
1346
btrfs_err (fs_info ,
1341
1347
"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 ,
1343
1349
rcu_str_deref (device -> name ), device -> devid );
1344
1350
alloc_offsets [i ] = WP_MISSING_DEV ;
1345
1351
break ;
@@ -1404,7 +1410,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1404
1410
if (alloc_offsets [0 ] == WP_MISSING_DEV ) {
1405
1411
btrfs_err (fs_info ,
1406
1412
"zoned: cannot recover write pointer for zone %llu" ,
1407
- physical );
1413
+ physical [ 0 ] );
1408
1414
ret = - EIO ;
1409
1415
goto out ;
1410
1416
}
@@ -1465,6 +1471,7 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)
1465
1471
cache -> physical_map = NULL ;
1466
1472
}
1467
1473
bitmap_free (active );
1474
+ kfree (physical );
1468
1475
kfree (caps );
1469
1476
kfree (alloc_offsets );
1470
1477
free_extent_map (em );
0 commit comments