@@ -3693,7 +3693,8 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3693
3693
found -> disk_total += total_bytes * factor ;
3694
3694
found -> bytes_used += bytes_used ;
3695
3695
found -> disk_used += bytes_used * factor ;
3696
- found -> full = 0 ;
3696
+ if (total_bytes > 0 )
3697
+ found -> full = 0 ;
3697
3698
spin_unlock (& found -> lock );
3698
3699
* space_info = found ;
3699
3700
return 0 ;
@@ -3721,7 +3722,10 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags,
3721
3722
found -> bytes_reserved = 0 ;
3722
3723
found -> bytes_readonly = 0 ;
3723
3724
found -> bytes_may_use = 0 ;
3724
- found -> full = 0 ;
3725
+ if (total_bytes > 0 )
3726
+ found -> full = 0 ;
3727
+ else
3728
+ found -> full = 1 ;
3725
3729
found -> force_alloc = CHUNK_ALLOC_NO_FORCE ;
3726
3730
found -> chunk_alloc = 0 ;
3727
3731
found -> flush = 0 ;
@@ -9562,13 +9566,30 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
9562
9566
9563
9567
free_excluded_extents (root , cache );
9564
9568
9569
+ /*
9570
+ * Call to ensure the corresponding space_info object is created and
9571
+ * assigned to our block group, but don't update its counters just yet.
9572
+ * We want our bg to be added to the rbtree with its ->space_info set.
9573
+ */
9574
+ ret = update_space_info (root -> fs_info , cache -> flags , 0 , 0 ,
9575
+ & cache -> space_info );
9576
+ if (ret ) {
9577
+ btrfs_remove_free_space_cache (cache );
9578
+ btrfs_put_block_group (cache );
9579
+ return ret ;
9580
+ }
9581
+
9565
9582
ret = btrfs_add_block_group_cache (root -> fs_info , cache );
9566
9583
if (ret ) {
9567
9584
btrfs_remove_free_space_cache (cache );
9568
9585
btrfs_put_block_group (cache );
9569
9586
return ret ;
9570
9587
}
9571
9588
9589
+ /*
9590
+ * Now that our block group has its ->space_info set and is inserted in
9591
+ * the rbtree, update the space info's counters.
9592
+ */
9572
9593
ret = update_space_info (root -> fs_info , cache -> flags , size , bytes_used ,
9573
9594
& cache -> space_info );
9574
9595
if (ret ) {
0 commit comments