@@ -2898,115 +2898,6 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
28982898 return ret ;
28992899}
29002900
2901- int btrfs_update_block_group (struct btrfs_trans_handle * trans ,
2902- u64 bytenr , u64 num_bytes , int alloc )
2903- {
2904- struct btrfs_fs_info * info = trans -> fs_info ;
2905- struct btrfs_block_group_cache * cache = NULL ;
2906- u64 total = num_bytes ;
2907- u64 old_val ;
2908- u64 byte_in_group ;
2909- int factor ;
2910- int ret = 0 ;
2911-
2912- /* block accounting for super block */
2913- spin_lock (& info -> delalloc_root_lock );
2914- old_val = btrfs_super_bytes_used (info -> super_copy );
2915- if (alloc )
2916- old_val += num_bytes ;
2917- else
2918- old_val -= num_bytes ;
2919- btrfs_set_super_bytes_used (info -> super_copy , old_val );
2920- spin_unlock (& info -> delalloc_root_lock );
2921-
2922- while (total ) {
2923- cache = btrfs_lookup_block_group (info , bytenr );
2924- if (!cache ) {
2925- ret = - ENOENT ;
2926- break ;
2927- }
2928- factor = btrfs_bg_type_to_factor (cache -> flags );
2929-
2930- /*
2931- * If this block group has free space cache written out, we
2932- * need to make sure to load it if we are removing space. This
2933- * is because we need the unpinning stage to actually add the
2934- * space back to the block group, otherwise we will leak space.
2935- */
2936- if (!alloc && cache -> cached == BTRFS_CACHE_NO )
2937- btrfs_cache_block_group (cache , 1 );
2938-
2939- byte_in_group = bytenr - cache -> key .objectid ;
2940- WARN_ON (byte_in_group > cache -> key .offset );
2941-
2942- spin_lock (& cache -> space_info -> lock );
2943- spin_lock (& cache -> lock );
2944-
2945- if (btrfs_test_opt (info , SPACE_CACHE ) &&
2946- cache -> disk_cache_state < BTRFS_DC_CLEAR )
2947- cache -> disk_cache_state = BTRFS_DC_CLEAR ;
2948-
2949- old_val = btrfs_block_group_used (& cache -> item );
2950- num_bytes = min (total , cache -> key .offset - byte_in_group );
2951- if (alloc ) {
2952- old_val += num_bytes ;
2953- btrfs_set_block_group_used (& cache -> item , old_val );
2954- cache -> reserved -= num_bytes ;
2955- cache -> space_info -> bytes_reserved -= num_bytes ;
2956- cache -> space_info -> bytes_used += num_bytes ;
2957- cache -> space_info -> disk_used += num_bytes * factor ;
2958- spin_unlock (& cache -> lock );
2959- spin_unlock (& cache -> space_info -> lock );
2960- } else {
2961- old_val -= num_bytes ;
2962- btrfs_set_block_group_used (& cache -> item , old_val );
2963- cache -> pinned += num_bytes ;
2964- btrfs_space_info_update_bytes_pinned (info ,
2965- cache -> space_info , num_bytes );
2966- cache -> space_info -> bytes_used -= num_bytes ;
2967- cache -> space_info -> disk_used -= num_bytes * factor ;
2968- spin_unlock (& cache -> lock );
2969- spin_unlock (& cache -> space_info -> lock );
2970-
2971- trace_btrfs_space_reservation (info , "pinned" ,
2972- cache -> space_info -> flags ,
2973- num_bytes , 1 );
2974- percpu_counter_add_batch (& cache -> space_info -> total_bytes_pinned ,
2975- num_bytes ,
2976- BTRFS_TOTAL_BYTES_PINNED_BATCH );
2977- set_extent_dirty (info -> pinned_extents ,
2978- bytenr , bytenr + num_bytes - 1 ,
2979- GFP_NOFS | __GFP_NOFAIL );
2980- }
2981-
2982- spin_lock (& trans -> transaction -> dirty_bgs_lock );
2983- if (list_empty (& cache -> dirty_list )) {
2984- list_add_tail (& cache -> dirty_list ,
2985- & trans -> transaction -> dirty_bgs );
2986- trans -> delayed_ref_updates ++ ;
2987- btrfs_get_block_group (cache );
2988- }
2989- spin_unlock (& trans -> transaction -> dirty_bgs_lock );
2990-
2991- /*
2992- * No longer have used bytes in this block group, queue it for
2993- * deletion. We do this after adding the block group to the
2994- * dirty list to avoid races between cleaner kthread and space
2995- * cache writeout.
2996- */
2997- if (!alloc && old_val == 0 )
2998- btrfs_mark_bg_unused (cache );
2999-
3000- btrfs_put_block_group (cache );
3001- total -= num_bytes ;
3002- bytenr += num_bytes ;
3003- }
3004-
3005- /* Modified block groups are accounted for in the delayed_refs_rsv. */
3006- btrfs_update_delayed_refs_rsv (trans );
3007- return ret ;
3008- }
3009-
30102901static u64 first_logical_byte (struct btrfs_fs_info * fs_info , u64 search_start )
30112902{
30122903 struct btrfs_block_group_cache * cache ;
@@ -3187,70 +3078,6 @@ btrfs_inc_block_group_reservations(struct btrfs_block_group_cache *bg)
31873078 atomic_inc (& bg -> reservations );
31883079}
31893080
3190- /**
3191- * btrfs_add_reserved_bytes - update the block_group and space info counters
3192- * @cache: The cache we are manipulating
3193- * @ram_bytes: The number of bytes of file content, and will be same to
3194- * @num_bytes except for the compress path.
3195- * @num_bytes: The number of bytes in question
3196- * @delalloc: The blocks are allocated for the delalloc write
3197- *
3198- * This is called by the allocator when it reserves space. If this is a
3199- * reservation and the block group has become read only we cannot make the
3200- * reservation and return -EAGAIN, otherwise this function always succeeds.
3201- */
3202- int btrfs_add_reserved_bytes (struct btrfs_block_group_cache * cache ,
3203- u64 ram_bytes , u64 num_bytes , int delalloc )
3204- {
3205- struct btrfs_space_info * space_info = cache -> space_info ;
3206- int ret = 0 ;
3207-
3208- spin_lock (& space_info -> lock );
3209- spin_lock (& cache -> lock );
3210- if (cache -> ro ) {
3211- ret = - EAGAIN ;
3212- } else {
3213- cache -> reserved += num_bytes ;
3214- space_info -> bytes_reserved += num_bytes ;
3215- btrfs_space_info_update_bytes_may_use (cache -> fs_info ,
3216- space_info , - ram_bytes );
3217- if (delalloc )
3218- cache -> delalloc_bytes += num_bytes ;
3219- }
3220- spin_unlock (& cache -> lock );
3221- spin_unlock (& space_info -> lock );
3222- return ret ;
3223- }
3224-
3225- /**
3226- * btrfs_free_reserved_bytes - update the block_group and space info counters
3227- * @cache: The cache we are manipulating
3228- * @num_bytes: The number of bytes in question
3229- * @delalloc: The blocks are allocated for the delalloc write
3230- *
3231- * This is called by somebody who is freeing space that was never actually used
3232- * on disk. For example if you reserve some space for a new leaf in transaction
3233- * A and before transaction A commits you free that leaf, you call this with
3234- * reserve set to 0 in order to clear the reservation.
3235- */
3236- void btrfs_free_reserved_bytes (struct btrfs_block_group_cache * cache ,
3237- u64 num_bytes , int delalloc )
3238- {
3239- struct btrfs_space_info * space_info = cache -> space_info ;
3240-
3241- spin_lock (& space_info -> lock );
3242- spin_lock (& cache -> lock );
3243- if (cache -> ro )
3244- space_info -> bytes_readonly += num_bytes ;
3245- cache -> reserved -= num_bytes ;
3246- space_info -> bytes_reserved -= num_bytes ;
3247- space_info -> max_extent_size = 0 ;
3248-
3249- if (delalloc )
3250- cache -> delalloc_bytes -= num_bytes ;
3251- spin_unlock (& cache -> lock );
3252- spin_unlock (& space_info -> lock );
3253- }
32543081void btrfs_prepare_extent_commit (struct btrfs_fs_info * fs_info )
32553082{
32563083 struct btrfs_caching_control * next ;
0 commit comments