@@ -558,14 +558,15 @@ u64 add_new_free_space(struct btrfs_block_group *block_group, u64 start, u64 end
558
558
static int sample_block_group_extent_item (struct btrfs_caching_control * caching_ctl ,
559
559
struct btrfs_block_group * block_group ,
560
560
int index , int max_index ,
561
- struct btrfs_key * key )
561
+ struct btrfs_key * found_key )
562
562
{
563
563
struct btrfs_fs_info * fs_info = block_group -> fs_info ;
564
564
struct btrfs_root * extent_root ;
565
- int ret = 0 ;
566
565
u64 search_offset ;
567
566
u64 search_end = block_group -> start + block_group -> length ;
568
567
struct btrfs_path * path ;
568
+ struct btrfs_key search_key ;
569
+ int ret = 0 ;
569
570
570
571
ASSERT (index >= 0 );
571
572
ASSERT (index <= max_index );
@@ -585,37 +586,24 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
585
586
path -> reada = READA_FORWARD ;
586
587
587
588
search_offset = index * div_u64 (block_group -> length , max_index );
588
- key -> objectid = block_group -> start + search_offset ;
589
- key -> type = BTRFS_EXTENT_ITEM_KEY ;
590
- key -> offset = 0 ;
589
+ search_key . objectid = block_group -> start + search_offset ;
590
+ search_key . type = BTRFS_EXTENT_ITEM_KEY ;
591
+ search_key . offset = 0 ;
591
592
592
- while (1 ) {
593
- ret = btrfs_search_forward (extent_root , key , path , 0 );
594
- if (ret != 0 )
595
- goto out ;
593
+ btrfs_for_each_slot (extent_root , & search_key , found_key , path , ret ) {
596
594
/* Success; sampled an extent item in the block group */
597
- if (key -> type == BTRFS_EXTENT_ITEM_KEY &&
598
- key -> objectid >= block_group -> start &&
599
- key -> objectid + key -> offset <= search_end )
600
- goto out ;
595
+ if (found_key -> type == BTRFS_EXTENT_ITEM_KEY &&
596
+ found_key -> objectid >= block_group -> start &&
597
+ found_key -> objectid + found_key -> offset <= search_end )
598
+ break ;
601
599
602
600
/* We can't possibly find a valid extent item anymore */
603
- if (key -> objectid >= search_end ) {
601
+ if (found_key -> objectid >= search_end ) {
604
602
ret = 1 ;
605
603
break ;
606
604
}
607
- if (key -> type < BTRFS_EXTENT_ITEM_KEY )
608
- key -> type = BTRFS_EXTENT_ITEM_KEY ;
609
- else
610
- key -> objectid ++ ;
611
- btrfs_release_path (path );
612
- up_read (& fs_info -> commit_root_sem );
613
- mutex_unlock (& caching_ctl -> mutex );
614
- cond_resched ();
615
- mutex_lock (& caching_ctl -> mutex );
616
- down_read (& fs_info -> commit_root_sem );
617
605
}
618
- out :
606
+
619
607
lockdep_assert_held (& caching_ctl -> mutex );
620
608
lockdep_assert_held_read (& fs_info -> commit_root_sem );
621
609
btrfs_free_path (path );
@@ -659,6 +647,7 @@ static int sample_block_group_extent_item(struct btrfs_caching_control *caching_
659
647
static int load_block_group_size_class (struct btrfs_caching_control * caching_ctl ,
660
648
struct btrfs_block_group * block_group )
661
649
{
650
+ struct btrfs_fs_info * fs_info = block_group -> fs_info ;
662
651
struct btrfs_key key ;
663
652
int i ;
664
653
u64 min_size = block_group -> length ;
@@ -668,6 +657,8 @@ static int load_block_group_size_class(struct btrfs_caching_control *caching_ctl
668
657
if (!btrfs_block_group_should_use_size_class (block_group ))
669
658
return 0 ;
670
659
660
+ lockdep_assert_held (& caching_ctl -> mutex );
661
+ lockdep_assert_held_read (& fs_info -> commit_root_sem );
671
662
for (i = 0 ; i < 5 ; ++ i ) {
672
663
ret = sample_block_group_extent_item (caching_ctl , block_group , i , 5 , & key );
673
664
if (ret < 0 )
@@ -682,7 +673,6 @@ static int load_block_group_size_class(struct btrfs_caching_control *caching_ctl
682
673
block_group -> size_class = size_class ;
683
674
spin_unlock (& block_group -> lock );
684
675
}
685
-
686
676
out :
687
677
return ret ;
688
678
}
0 commit comments