@@ -168,7 +168,7 @@ void btrfs_put_block_group(struct btrfs_block_group *cache)
168
168
cache );
169
169
170
170
kfree (cache -> free_space_ctl );
171
- kfree (cache -> physical_map );
171
+ btrfs_free_chunk_map (cache -> physical_map );
172
172
kfree (cache );
173
173
}
174
174
}
@@ -1047,7 +1047,7 @@ static int remove_block_group_item(struct btrfs_trans_handle *trans,
1047
1047
}
1048
1048
1049
1049
int btrfs_remove_block_group (struct btrfs_trans_handle * trans ,
1050
- u64 group_start , struct extent_map * em )
1050
+ struct btrfs_chunk_map * map )
1051
1051
{
1052
1052
struct btrfs_fs_info * fs_info = trans -> fs_info ;
1053
1053
struct btrfs_path * path ;
@@ -1059,10 +1059,10 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1059
1059
int index ;
1060
1060
int factor ;
1061
1061
struct btrfs_caching_control * caching_ctl = NULL ;
1062
- bool remove_em ;
1062
+ bool remove_map ;
1063
1063
bool remove_rsv = false;
1064
1064
1065
- block_group = btrfs_lookup_block_group (fs_info , group_start );
1065
+ block_group = btrfs_lookup_block_group (fs_info , map -> start );
1066
1066
BUG_ON (!block_group );
1067
1067
BUG_ON (!block_group -> ro );
1068
1068
@@ -1252,7 +1252,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1252
1252
* entries because we already removed them all when we called
1253
1253
* btrfs_remove_free_space_cache().
1254
1254
*
1255
- * And we must not remove the extent map from the fs_info->mapping_tree
1255
+ * And we must not remove the chunk map from the fs_info->mapping_tree
1256
1256
* to prevent the same logical address range and physical device space
1257
1257
* ranges from being reused for a new block group. This is needed to
1258
1258
* avoid races with trimming and scrub.
@@ -1268,19 +1268,11 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1268
1268
* in place until the extents have been discarded completely when
1269
1269
* the transaction commit has completed.
1270
1270
*/
1271
- remove_em = (atomic_read (& block_group -> frozen ) == 0 );
1271
+ remove_map = (atomic_read (& block_group -> frozen ) == 0 );
1272
1272
spin_unlock (& block_group -> lock );
1273
1273
1274
- if (remove_em ) {
1275
- struct extent_map_tree * em_tree ;
1276
-
1277
- em_tree = & fs_info -> mapping_tree ;
1278
- write_lock (& em_tree -> lock );
1279
- remove_extent_mapping (em_tree , em );
1280
- write_unlock (& em_tree -> lock );
1281
- /* once for the tree */
1282
- free_extent_map (em );
1283
- }
1274
+ if (remove_map )
1275
+ btrfs_remove_chunk_map (fs_info , map );
1284
1276
1285
1277
out :
1286
1278
/* Once for the lookup reference */
@@ -1295,16 +1287,12 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
1295
1287
struct btrfs_fs_info * fs_info , const u64 chunk_offset )
1296
1288
{
1297
1289
struct btrfs_root * root = btrfs_block_group_root (fs_info );
1298
- struct extent_map_tree * em_tree = & fs_info -> mapping_tree ;
1299
- struct extent_map * em ;
1300
- struct map_lookup * map ;
1290
+ struct btrfs_chunk_map * map ;
1301
1291
unsigned int num_items ;
1302
1292
1303
- read_lock (& em_tree -> lock );
1304
- em = lookup_extent_mapping (em_tree , chunk_offset , 1 );
1305
- read_unlock (& em_tree -> lock );
1306
- ASSERT (em != NULL );
1307
- ASSERT (em -> start == chunk_offset );
1293
+ map = btrfs_find_chunk_map (fs_info , chunk_offset , 1 );
1294
+ ASSERT (map != NULL );
1295
+ ASSERT (map -> start == chunk_offset );
1308
1296
1309
1297
/*
1310
1298
* We need to reserve 3 + N units from the metadata space info in order
@@ -1325,9 +1313,8 @@ struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
1325
1313
* more device items and remove one chunk item), but this is done at
1326
1314
* btrfs_remove_chunk() through a call to check_system_chunk().
1327
1315
*/
1328
- map = em -> map_lookup ;
1329
1316
num_items = 3 + map -> num_stripes ;
1330
- free_extent_map ( em );
1317
+ btrfs_free_chunk_map ( map );
1331
1318
1332
1319
return btrfs_start_transaction_fallback_global_rsv (root , num_items );
1333
1320
}
@@ -1928,8 +1915,7 @@ void btrfs_mark_bg_to_reclaim(struct btrfs_block_group *bg)
1928
1915
static int read_bg_from_eb (struct btrfs_fs_info * fs_info , struct btrfs_key * key ,
1929
1916
struct btrfs_path * path )
1930
1917
{
1931
- struct extent_map_tree * em_tree ;
1932
- struct extent_map * em ;
1918
+ struct btrfs_chunk_map * map ;
1933
1919
struct btrfs_block_group_item bg ;
1934
1920
struct extent_buffer * leaf ;
1935
1921
int slot ;
@@ -1939,40 +1925,37 @@ static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
1939
1925
slot = path -> slots [0 ];
1940
1926
leaf = path -> nodes [0 ];
1941
1927
1942
- em_tree = & fs_info -> mapping_tree ;
1943
- read_lock (& em_tree -> lock );
1944
- em = lookup_extent_mapping (em_tree , key -> objectid , key -> offset );
1945
- read_unlock (& em_tree -> lock );
1946
- if (!em ) {
1928
+ map = btrfs_find_chunk_map (fs_info , key -> objectid , key -> offset );
1929
+ if (!map ) {
1947
1930
btrfs_err (fs_info ,
1948
1931
"logical %llu len %llu found bg but no related chunk" ,
1949
1932
key -> objectid , key -> offset );
1950
1933
return - ENOENT ;
1951
1934
}
1952
1935
1953
- if (em -> start != key -> objectid || em -> len != key -> offset ) {
1936
+ if (map -> start != key -> objectid || map -> chunk_len != key -> offset ) {
1954
1937
btrfs_err (fs_info ,
1955
1938
"block group %llu len %llu mismatch with chunk %llu len %llu" ,
1956
- key -> objectid , key -> offset , em -> start , em -> len );
1939
+ key -> objectid , key -> offset , map -> start , map -> chunk_len );
1957
1940
ret = - EUCLEAN ;
1958
- goto out_free_em ;
1941
+ goto out_free_map ;
1959
1942
}
1960
1943
1961
1944
read_extent_buffer (leaf , & bg , btrfs_item_ptr_offset (leaf , slot ),
1962
1945
sizeof (bg ));
1963
1946
flags = btrfs_stack_block_group_flags (& bg ) &
1964
1947
BTRFS_BLOCK_GROUP_TYPE_MASK ;
1965
1948
1966
- if (flags != (em -> map_lookup -> type & BTRFS_BLOCK_GROUP_TYPE_MASK )) {
1949
+ if (flags != (map -> type & BTRFS_BLOCK_GROUP_TYPE_MASK )) {
1967
1950
btrfs_err (fs_info ,
1968
1951
"block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx" ,
1969
1952
key -> objectid , key -> offset , flags ,
1970
- (BTRFS_BLOCK_GROUP_TYPE_MASK & em -> map_lookup -> type ));
1953
+ (BTRFS_BLOCK_GROUP_TYPE_MASK & map -> type ));
1971
1954
ret = - EUCLEAN ;
1972
1955
}
1973
1956
1974
- out_free_em :
1975
- free_extent_map ( em );
1957
+ out_free_map :
1958
+ btrfs_free_chunk_map ( map );
1976
1959
return ret ;
1977
1960
}
1978
1961
@@ -2025,23 +2008,21 @@ static void set_avail_alloc_bits(struct btrfs_fs_info *fs_info, u64 flags)
2025
2008
int btrfs_rmap_block (struct btrfs_fs_info * fs_info , u64 chunk_start ,
2026
2009
u64 physical , u64 * * logical , int * naddrs , int * stripe_len )
2027
2010
{
2028
- struct extent_map * em ;
2029
- struct map_lookup * map ;
2011
+ struct btrfs_chunk_map * map ;
2030
2012
u64 * buf ;
2031
2013
u64 bytenr ;
2032
2014
u64 data_stripe_length ;
2033
2015
u64 io_stripe_size ;
2034
2016
int i , nr = 0 ;
2035
2017
int ret = 0 ;
2036
2018
2037
- em = btrfs_get_chunk_map (fs_info , chunk_start , 1 );
2038
- if (IS_ERR (em ))
2019
+ map = btrfs_get_chunk_map (fs_info , chunk_start , 1 );
2020
+ if (IS_ERR (map ))
2039
2021
return - EIO ;
2040
2022
2041
- map = em -> map_lookup ;
2042
- data_stripe_length = em -> orig_block_len ;
2023
+ data_stripe_length = map -> stripe_size ;
2043
2024
io_stripe_size = BTRFS_STRIPE_LEN ;
2044
- chunk_start = em -> start ;
2025
+ chunk_start = map -> start ;
2045
2026
2046
2027
/* For RAID5/6 adjust to a full IO stripe length */
2047
2028
if (map -> type & BTRFS_BLOCK_GROUP_RAID56_MASK )
@@ -2095,7 +2076,7 @@ int btrfs_rmap_block(struct btrfs_fs_info *fs_info, u64 chunk_start,
2095
2076
* naddrs = nr ;
2096
2077
* stripe_len = io_stripe_size ;
2097
2078
out :
2098
- free_extent_map ( em );
2079
+ btrfs_free_chunk_map ( map );
2099
2080
return ret ;
2100
2081
}
2101
2082
@@ -2200,49 +2181,47 @@ static struct btrfs_block_group *btrfs_create_block_group_cache(
2200
2181
*/
2201
2182
static int check_chunk_block_group_mappings (struct btrfs_fs_info * fs_info )
2202
2183
{
2203
- struct extent_map_tree * map_tree = & fs_info -> mapping_tree ;
2204
- struct extent_map * em ;
2205
- struct btrfs_block_group * bg ;
2206
2184
u64 start = 0 ;
2207
2185
int ret = 0 ;
2208
2186
2209
2187
while (1 ) {
2210
- read_lock (& map_tree -> lock );
2188
+ struct btrfs_chunk_map * map ;
2189
+ struct btrfs_block_group * bg ;
2190
+
2211
2191
/*
2212
- * lookup_extent_mapping will return the first extent map
2213
- * intersecting the range, so setting @len to 1 is enough to
2192
+ * btrfs_find_chunk_map() will return the first chunk map
2193
+ * intersecting the range, so setting @length to 1 is enough to
2214
2194
* get the first chunk.
2215
2195
*/
2216
- em = lookup_extent_mapping (map_tree , start , 1 );
2217
- read_unlock (& map_tree -> lock );
2218
- if (!em )
2196
+ map = btrfs_find_chunk_map (fs_info , start , 1 );
2197
+ if (!map )
2219
2198
break ;
2220
2199
2221
- bg = btrfs_lookup_block_group (fs_info , em -> start );
2200
+ bg = btrfs_lookup_block_group (fs_info , map -> start );
2222
2201
if (!bg ) {
2223
2202
btrfs_err (fs_info ,
2224
2203
"chunk start=%llu len=%llu doesn't have corresponding block group" ,
2225
- em -> start , em -> len );
2204
+ map -> start , map -> chunk_len );
2226
2205
ret = - EUCLEAN ;
2227
- free_extent_map ( em );
2206
+ btrfs_free_chunk_map ( map );
2228
2207
break ;
2229
2208
}
2230
- if (bg -> start != em -> start || bg -> length != em -> len ||
2209
+ if (bg -> start != map -> start || bg -> length != map -> chunk_len ||
2231
2210
(bg -> flags & BTRFS_BLOCK_GROUP_TYPE_MASK ) !=
2232
- (em -> map_lookup -> type & BTRFS_BLOCK_GROUP_TYPE_MASK )) {
2211
+ (map -> type & BTRFS_BLOCK_GROUP_TYPE_MASK )) {
2233
2212
btrfs_err (fs_info ,
2234
2213
"chunk start=%llu len=%llu flags=0x%llx doesn't match block group start=%llu len=%llu flags=0x%llx" ,
2235
- em -> start , em -> len ,
2236
- em -> map_lookup -> type & BTRFS_BLOCK_GROUP_TYPE_MASK ,
2214
+ map -> start , map -> chunk_len ,
2215
+ map -> type & BTRFS_BLOCK_GROUP_TYPE_MASK ,
2237
2216
bg -> start , bg -> length ,
2238
2217
bg -> flags & BTRFS_BLOCK_GROUP_TYPE_MASK );
2239
2218
ret = - EUCLEAN ;
2240
- free_extent_map ( em );
2219
+ btrfs_free_chunk_map ( map );
2241
2220
btrfs_put_block_group (bg );
2242
2221
break ;
2243
2222
}
2244
- start = em -> start + em -> len ;
2245
- free_extent_map ( em );
2223
+ start = map -> start + map -> chunk_len ;
2224
+ btrfs_free_chunk_map ( map );
2246
2225
btrfs_put_block_group (bg );
2247
2226
}
2248
2227
return ret ;
@@ -2370,28 +2349,25 @@ static int read_one_block_group(struct btrfs_fs_info *info,
2370
2349
2371
2350
static int fill_dummy_bgs (struct btrfs_fs_info * fs_info )
2372
2351
{
2373
- struct extent_map_tree * em_tree = & fs_info -> mapping_tree ;
2374
2352
struct rb_node * node ;
2375
2353
int ret = 0 ;
2376
2354
2377
- for (node = rb_first_cached (& em_tree -> map ); node ; node = rb_next (node )) {
2378
- struct extent_map * em ;
2379
- struct map_lookup * map ;
2355
+ for (node = rb_first_cached (& fs_info -> mapping_tree ); node ; node = rb_next (node )) {
2356
+ struct btrfs_chunk_map * map ;
2380
2357
struct btrfs_block_group * bg ;
2381
2358
2382
- em = rb_entry (node , struct extent_map , rb_node );
2383
- map = em -> map_lookup ;
2384
- bg = btrfs_create_block_group_cache (fs_info , em -> start );
2359
+ map = rb_entry (node , struct btrfs_chunk_map , rb_node );
2360
+ bg = btrfs_create_block_group_cache (fs_info , map -> start );
2385
2361
if (!bg ) {
2386
2362
ret = - ENOMEM ;
2387
2363
break ;
2388
2364
}
2389
2365
2390
2366
/* Fill dummy cache as FULL */
2391
- bg -> length = em -> len ;
2367
+ bg -> length = map -> chunk_len ;
2392
2368
bg -> flags = map -> type ;
2393
2369
bg -> cached = BTRFS_CACHE_FINISHED ;
2394
- bg -> used = em -> len ;
2370
+ bg -> used = map -> chunk_len ;
2395
2371
bg -> flags = map -> type ;
2396
2372
ret = btrfs_add_block_group_cache (fs_info , bg );
2397
2373
/*
@@ -2619,19 +2595,17 @@ static int insert_dev_extents(struct btrfs_trans_handle *trans,
2619
2595
{
2620
2596
struct btrfs_fs_info * fs_info = trans -> fs_info ;
2621
2597
struct btrfs_device * device ;
2622
- struct extent_map * em ;
2623
- struct map_lookup * map ;
2598
+ struct btrfs_chunk_map * map ;
2624
2599
u64 dev_offset ;
2625
2600
u64 stripe_size ;
2626
2601
int i ;
2627
2602
int ret = 0 ;
2628
2603
2629
- em = btrfs_get_chunk_map (fs_info , chunk_offset , chunk_size );
2630
- if (IS_ERR (em ))
2631
- return PTR_ERR (em );
2604
+ map = btrfs_get_chunk_map (fs_info , chunk_offset , chunk_size );
2605
+ if (IS_ERR (map ))
2606
+ return PTR_ERR (map );
2632
2607
2633
- map = em -> map_lookup ;
2634
- stripe_size = em -> orig_block_len ;
2608
+ stripe_size = map -> stripe_size ;
2635
2609
2636
2610
/*
2637
2611
* Take the device list mutex to prevent races with the final phase of
@@ -2654,7 +2628,7 @@ static int insert_dev_extents(struct btrfs_trans_handle *trans,
2654
2628
}
2655
2629
mutex_unlock (& fs_info -> fs_devices -> device_list_mutex );
2656
2630
2657
- free_extent_map ( em );
2631
+ btrfs_free_chunk_map ( map );
2658
2632
return ret ;
2659
2633
}
2660
2634
@@ -4407,8 +4381,6 @@ void btrfs_freeze_block_group(struct btrfs_block_group *cache)
4407
4381
void btrfs_unfreeze_block_group (struct btrfs_block_group * block_group )
4408
4382
{
4409
4383
struct btrfs_fs_info * fs_info = block_group -> fs_info ;
4410
- struct extent_map_tree * em_tree ;
4411
- struct extent_map * em ;
4412
4384
bool cleanup ;
4413
4385
4414
4386
spin_lock (& block_group -> lock );
@@ -4417,17 +4389,16 @@ void btrfs_unfreeze_block_group(struct btrfs_block_group *block_group)
4417
4389
spin_unlock (& block_group -> lock );
4418
4390
4419
4391
if (cleanup ) {
4420
- em_tree = & fs_info -> mapping_tree ;
4421
- write_lock (& em_tree -> lock );
4422
- em = lookup_extent_mapping (em_tree , block_group -> start ,
4423
- 1 );
4424
- BUG_ON (!em ); /* logic error, can't happen */
4425
- remove_extent_mapping (em_tree , em );
4426
- write_unlock (& em_tree -> lock );
4427
-
4428
- /* once for us and once for the tree */
4429
- free_extent_map (em );
4430
- free_extent_map (em );
4392
+ struct btrfs_chunk_map * map ;
4393
+
4394
+ map = btrfs_find_chunk_map (fs_info , block_group -> start , 1 );
4395
+ /* Logic error, can't happen. */
4396
+ ASSERT (map );
4397
+
4398
+ btrfs_remove_chunk_map (fs_info , map );
4399
+
4400
+ /* Once for our lookup reference. */
4401
+ btrfs_free_chunk_map (map );
4431
4402
4432
4403
/*
4433
4404
* We may have left one free space entry and other possible
0 commit comments