@@ -2863,7 +2863,7 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
2863
2863
* This function always allocates a used segment(from dirty seglist) by SSR
2864
2864
* manner, so it should recover the existing segment information of valid blocks
2865
2865
*/
2866
- static void change_curseg (struct f2fs_sb_info * sbi , int type )
2866
+ static int change_curseg (struct f2fs_sb_info * sbi , int type )
2867
2867
{
2868
2868
struct dirty_seglist_info * dirty_i = DIRTY_I (sbi );
2869
2869
struct curseg_info * curseg = CURSEG_I (sbi , type );
@@ -2888,60 +2888,65 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)
2888
2888
if (IS_ERR (sum_page )) {
2889
2889
/* GC won't be able to use stale summary pages by cp_error */
2890
2890
memset (curseg -> sum_blk , 0 , SUM_ENTRY_SIZE );
2891
- return ;
2891
+ return PTR_ERR ( sum_page ) ;
2892
2892
}
2893
2893
sum_node = (struct f2fs_summary_block * )page_address (sum_page );
2894
2894
memcpy (curseg -> sum_blk , sum_node , SUM_ENTRY_SIZE );
2895
2895
f2fs_put_page (sum_page , 1 );
2896
+ return 0 ;
2896
2897
}
2897
2898
2898
2899
static int get_ssr_segment (struct f2fs_sb_info * sbi , int type ,
2899
2900
int alloc_mode , unsigned long long age );
2900
2901
2901
- static void get_atssr_segment (struct f2fs_sb_info * sbi , int type ,
2902
+ static int get_atssr_segment (struct f2fs_sb_info * sbi , int type ,
2902
2903
int target_type , int alloc_mode ,
2903
2904
unsigned long long age )
2904
2905
{
2905
2906
struct curseg_info * curseg = CURSEG_I (sbi , type );
2907
+ int ret = 0 ;
2906
2908
2907
2909
curseg -> seg_type = target_type ;
2908
2910
2909
2911
if (get_ssr_segment (sbi , type , alloc_mode , age )) {
2910
2912
struct seg_entry * se = get_seg_entry (sbi , curseg -> next_segno );
2911
2913
2912
2914
curseg -> seg_type = se -> type ;
2913
- change_curseg (sbi , type );
2915
+ ret = change_curseg (sbi , type );
2914
2916
} else {
2915
2917
/* allocate cold segment by default */
2916
2918
curseg -> seg_type = CURSEG_COLD_DATA ;
2917
- new_curseg (sbi , type , true);
2919
+ ret = new_curseg (sbi , type , true);
2918
2920
}
2919
2921
stat_inc_seg_type (sbi , curseg );
2922
+ return ret ;
2920
2923
}
2921
2924
2922
- static void __f2fs_init_atgc_curseg (struct f2fs_sb_info * sbi )
2925
+ static int __f2fs_init_atgc_curseg (struct f2fs_sb_info * sbi )
2923
2926
{
2924
2927
struct curseg_info * curseg = CURSEG_I (sbi , CURSEG_ALL_DATA_ATGC );
2928
+ int ret = 0 ;
2925
2929
2926
2930
if (!sbi -> am .atgc_enabled )
2927
- return ;
2931
+ return 0 ;
2928
2932
2929
2933
f2fs_down_read (& SM_I (sbi )-> curseg_lock );
2930
2934
2931
2935
mutex_lock (& curseg -> curseg_mutex );
2932
2936
down_write (& SIT_I (sbi )-> sentry_lock );
2933
2937
2934
- get_atssr_segment (sbi , CURSEG_ALL_DATA_ATGC , CURSEG_COLD_DATA , SSR , 0 );
2938
+ ret = get_atssr_segment (sbi , CURSEG_ALL_DATA_ATGC ,
2939
+ CURSEG_COLD_DATA , SSR , 0 );
2935
2940
2936
2941
up_write (& SIT_I (sbi )-> sentry_lock );
2937
2942
mutex_unlock (& curseg -> curseg_mutex );
2938
2943
2939
2944
f2fs_up_read (& SM_I (sbi )-> curseg_lock );
2940
-
2945
+ return ret ;
2941
2946
}
2942
- void f2fs_init_inmem_curseg (struct f2fs_sb_info * sbi )
2947
+ int f2fs_init_inmem_curseg (struct f2fs_sb_info * sbi )
2943
2948
{
2944
- __f2fs_init_atgc_curseg (sbi );
2949
+ return __f2fs_init_atgc_curseg (sbi );
2945
2950
}
2946
2951
2947
2952
static void __f2fs_save_inmem_curseg (struct f2fs_sb_info * sbi , int type )
@@ -3069,11 +3074,12 @@ static bool need_new_seg(struct f2fs_sb_info *sbi, int type)
3069
3074
return false;
3070
3075
}
3071
3076
3072
- void f2fs_allocate_segment_for_resize (struct f2fs_sb_info * sbi , int type ,
3077
+ int f2fs_allocate_segment_for_resize (struct f2fs_sb_info * sbi , int type ,
3073
3078
unsigned int start , unsigned int end )
3074
3079
{
3075
3080
struct curseg_info * curseg = CURSEG_I (sbi , type );
3076
3081
unsigned int segno ;
3082
+ int ret = 0 ;
3077
3083
3078
3084
f2fs_down_read (& SM_I (sbi )-> curseg_lock );
3079
3085
mutex_lock (& curseg -> curseg_mutex );
@@ -3084,9 +3090,9 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
3084
3090
goto unlock ;
3085
3091
3086
3092
if (f2fs_need_SSR (sbi ) && get_ssr_segment (sbi , type , SSR , 0 ))
3087
- change_curseg (sbi , type );
3093
+ ret = change_curseg (sbi , type );
3088
3094
else
3089
- new_curseg (sbi , type , true);
3095
+ ret = new_curseg (sbi , type , true);
3090
3096
3091
3097
stat_inc_seg_type (sbi , curseg );
3092
3098
@@ -3100,6 +3106,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type,
3100
3106
3101
3107
mutex_unlock (& curseg -> curseg_mutex );
3102
3108
f2fs_up_read (& SM_I (sbi )-> curseg_lock );
3109
+ return ret ;
3103
3110
}
3104
3111
3105
3112
static int __allocate_new_segment (struct f2fs_sb_info * sbi , int type ,
@@ -3486,14 +3493,17 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
3486
3493
bool from_gc = (type == CURSEG_ALL_DATA_ATGC );
3487
3494
struct seg_entry * se = NULL ;
3488
3495
bool segment_full = false;
3496
+ int ret = 0 ;
3489
3497
3490
3498
f2fs_down_read (& SM_I (sbi )-> curseg_lock );
3491
3499
3492
3500
mutex_lock (& curseg -> curseg_mutex );
3493
3501
down_write (& sit_i -> sentry_lock );
3494
3502
3495
- if (curseg -> segno == NULL_SEGNO )
3503
+ if (curseg -> segno == NULL_SEGNO ) {
3504
+ ret = - ENOSPC ;
3496
3505
goto out_err ;
3506
+ }
3497
3507
3498
3508
if (from_gc ) {
3499
3509
f2fs_bug_on (sbi , GET_SEGNO (sbi , old_blkaddr ) == NULL_SEGNO );
@@ -3546,17 +3556,17 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
3546
3556
}
3547
3557
3548
3558
if (from_gc ) {
3549
- get_atssr_segment (sbi , type , se -> type ,
3559
+ ret = get_atssr_segment (sbi , type , se -> type ,
3550
3560
AT_SSR , se -> mtime );
3551
3561
} else {
3552
3562
if (need_new_seg (sbi , type ))
3553
- new_curseg (sbi , type , false);
3563
+ ret = new_curseg (sbi , type , false);
3554
3564
else
3555
- change_curseg (sbi , type );
3565
+ ret = change_curseg (sbi , type );
3556
3566
stat_inc_seg_type (sbi , curseg );
3557
3567
}
3558
3568
3559
- if (curseg -> segno == NULL_SEGNO )
3569
+ if (ret )
3560
3570
goto out_err ;
3561
3571
}
3562
3572
@@ -3599,7 +3609,7 @@ int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
3599
3609
up_write (& sit_i -> sentry_lock );
3600
3610
mutex_unlock (& curseg -> curseg_mutex );
3601
3611
f2fs_up_read (& SM_I (sbi )-> curseg_lock );
3602
- return - ENOSPC ;
3612
+ return ret ;
3603
3613
3604
3614
}
3605
3615
@@ -3828,7 +3838,8 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
3828
3838
/* change the current segment */
3829
3839
if (segno != curseg -> segno ) {
3830
3840
curseg -> next_segno = segno ;
3831
- change_curseg (sbi , type );
3841
+ if (change_curseg (sbi , type ))
3842
+ goto out_unlock ;
3832
3843
}
3833
3844
3834
3845
curseg -> next_blkoff = GET_BLKOFF_FROM_SEG0 (sbi , new_blkaddr );
@@ -3854,12 +3865,14 @@ void f2fs_do_replace_block(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
3854
3865
if (recover_curseg ) {
3855
3866
if (old_cursegno != curseg -> segno ) {
3856
3867
curseg -> next_segno = old_cursegno ;
3857
- change_curseg (sbi , type );
3868
+ if (change_curseg (sbi , type ))
3869
+ goto out_unlock ;
3858
3870
}
3859
3871
curseg -> next_blkoff = old_blkoff ;
3860
3872
curseg -> alloc_type = old_alloc_type ;
3861
3873
}
3862
3874
3875
+ out_unlock :
3863
3876
up_write (& sit_i -> sentry_lock );
3864
3877
mutex_unlock (& curseg -> curseg_mutex );
3865
3878
f2fs_up_write (& SM_I (sbi )-> curseg_lock );
0 commit comments