Skip to content

Commit 64de76c

Browse files
committed
Merge tag 'for-6.5-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: - fix accounting of global block reserve size when block group tree is enabled - the async discard has been enabled in 6.2 unconditionally, but for zoned mode it does not make that much sense to do it asynchronously as the zones are reset as needed - error handling and proper error value propagation fixes * tag 'for-6.5-rc3-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: check for commit error at btrfs_attach_transaction_barrier() btrfs: check if the transaction was aborted at btrfs_wait_for_commit() btrfs: remove BUG_ON()'s in add_new_free_space() btrfs: account block group tree when calculating global reserve size btrfs: zoned: do not enable async discard
2 parents 379e667 + b28ff3a commit 64de76c

File tree

7 files changed

+75
-29
lines changed

7 files changed

+75
-29
lines changed

fs/btrfs/block-group.c

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,16 @@ static void fragment_free_space(struct btrfs_block_group *block_group)
499499
* used yet since their free space will be released as soon as the transaction
500500
* commits.
501501
*/
502-
u64 add_new_free_space(struct btrfs_block_group *block_group, u64 start, u64 end)
502+
int add_new_free_space(struct btrfs_block_group *block_group, u64 start, u64 end,
503+
u64 *total_added_ret)
503504
{
504505
struct btrfs_fs_info *info = block_group->fs_info;
505-
u64 extent_start, extent_end, size, total_added = 0;
506+
u64 extent_start, extent_end, size;
506507
int ret;
507508

509+
if (total_added_ret)
510+
*total_added_ret = 0;
511+
508512
while (start < end) {
509513
ret = find_first_extent_bit(&info->excluded_extents, start,
510514
&extent_start, &extent_end,
@@ -517,10 +521,12 @@ u64 add_new_free_space(struct btrfs_block_group *block_group, u64 start, u64 end
517521
start = extent_end + 1;
518522
} else if (extent_start > start && extent_start < end) {
519523
size = extent_start - start;
520-
total_added += size;
521524
ret = btrfs_add_free_space_async_trimmed(block_group,
522525
start, size);
523-
BUG_ON(ret); /* -ENOMEM or logic error */
526+
if (ret)
527+
return ret;
528+
if (total_added_ret)
529+
*total_added_ret += size;
524530
start = extent_end + 1;
525531
} else {
526532
break;
@@ -529,13 +535,15 @@ u64 add_new_free_space(struct btrfs_block_group *block_group, u64 start, u64 end
529535

530536
if (start < end) {
531537
size = end - start;
532-
total_added += size;
533538
ret = btrfs_add_free_space_async_trimmed(block_group, start,
534539
size);
535-
BUG_ON(ret); /* -ENOMEM or logic error */
540+
if (ret)
541+
return ret;
542+
if (total_added_ret)
543+
*total_added_ret += size;
536544
}
537545

538-
return total_added;
546+
return 0;
539547
}
540548

541549
/*
@@ -779,8 +787,13 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
779787

780788
if (key.type == BTRFS_EXTENT_ITEM_KEY ||
781789
key.type == BTRFS_METADATA_ITEM_KEY) {
782-
total_found += add_new_free_space(block_group, last,
783-
key.objectid);
790+
u64 space_added;
791+
792+
ret = add_new_free_space(block_group, last, key.objectid,
793+
&space_added);
794+
if (ret)
795+
goto out;
796+
total_found += space_added;
784797
if (key.type == BTRFS_METADATA_ITEM_KEY)
785798
last = key.objectid +
786799
fs_info->nodesize;
@@ -795,11 +808,10 @@ static int load_extent_tree_free(struct btrfs_caching_control *caching_ctl)
795808
}
796809
path->slots[0]++;
797810
}
798-
ret = 0;
799-
800-
total_found += add_new_free_space(block_group, last,
801-
block_group->start + block_group->length);
802811

812+
ret = add_new_free_space(block_group, last,
813+
block_group->start + block_group->length,
814+
NULL);
803815
out:
804816
btrfs_free_path(path);
805817
return ret;
@@ -2294,9 +2306,11 @@ static int read_one_block_group(struct btrfs_fs_info *info,
22942306
btrfs_free_excluded_extents(cache);
22952307
} else if (cache->used == 0) {
22962308
cache->cached = BTRFS_CACHE_FINISHED;
2297-
add_new_free_space(cache, cache->start,
2298-
cache->start + cache->length);
2309+
ret = add_new_free_space(cache, cache->start,
2310+
cache->start + cache->length, NULL);
22992311
btrfs_free_excluded_extents(cache);
2312+
if (ret)
2313+
goto error;
23002314
}
23012315

23022316
ret = btrfs_add_block_group_cache(info, cache);
@@ -2740,9 +2754,12 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
27402754
return ERR_PTR(ret);
27412755
}
27422756

2743-
add_new_free_space(cache, chunk_offset, chunk_offset + size);
2744-
2757+
ret = add_new_free_space(cache, chunk_offset, chunk_offset + size, NULL);
27452758
btrfs_free_excluded_extents(cache);
2759+
if (ret) {
2760+
btrfs_put_block_group(cache);
2761+
return ERR_PTR(ret);
2762+
}
27462763

27472764
/*
27482765
* Ensure the corresponding space_info object is created and

fs/btrfs/block-group.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,8 @@ int btrfs_cache_block_group(struct btrfs_block_group *cache, bool wait);
289289
void btrfs_put_caching_control(struct btrfs_caching_control *ctl);
290290
struct btrfs_caching_control *btrfs_get_caching_control(
291291
struct btrfs_block_group *cache);
292-
u64 add_new_free_space(struct btrfs_block_group *block_group,
293-
u64 start, u64 end);
292+
int add_new_free_space(struct btrfs_block_group *block_group,
293+
u64 start, u64 end, u64 *total_added_ret);
294294
struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
295295
struct btrfs_fs_info *fs_info,
296296
const u64 chunk_offset);

fs/btrfs/block-rsv.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,11 @@ void btrfs_update_global_block_rsv(struct btrfs_fs_info *fs_info)
349349
}
350350
read_unlock(&fs_info->global_root_lock);
351351

352+
if (btrfs_fs_compat_ro(fs_info, BLOCK_GROUP_TREE)) {
353+
num_bytes += btrfs_root_used(&fs_info->block_group_root->root_item);
354+
min_items++;
355+
}
356+
352357
/*
353358
* But we also want to reserve enough space so we can do the fallback
354359
* global reserve for an unlink, which is an additional

fs/btrfs/disk-io.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3438,11 +3438,16 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
34383438
* For devices supporting discard turn on discard=async automatically,
34393439
* unless it's already set or disabled. This could be turned off by
34403440
* nodiscard for the same mount.
3441+
*
3442+
* The zoned mode piggy backs on the discard functionality for
3443+
* resetting a zone. There is no reason to delay the zone reset as it is
3444+
* fast enough. So, do not enable async discard for zoned mode.
34413445
*/
34423446
if (!(btrfs_test_opt(fs_info, DISCARD_SYNC) ||
34433447
btrfs_test_opt(fs_info, DISCARD_ASYNC) ||
34443448
btrfs_test_opt(fs_info, NODISCARD)) &&
3445-
fs_info->fs_devices->discardable) {
3449+
fs_info->fs_devices->discardable &&
3450+
!btrfs_is_zoned(fs_info)) {
34463451
btrfs_set_and_info(fs_info, DISCARD_ASYNC,
34473452
"auto enabling async discard");
34483453
}

fs/btrfs/free-space-tree.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,13 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
15151515
if (prev_bit == 0 && bit == 1) {
15161516
extent_start = offset;
15171517
} else if (prev_bit == 1 && bit == 0) {
1518-
total_found += add_new_free_space(block_group,
1519-
extent_start,
1520-
offset);
1518+
u64 space_added;
1519+
1520+
ret = add_new_free_space(block_group, extent_start,
1521+
offset, &space_added);
1522+
if (ret)
1523+
goto out;
1524+
total_found += space_added;
15211525
if (total_found > CACHING_CTL_WAKE_UP) {
15221526
total_found = 0;
15231527
wake_up(&caching_ctl->wait);
@@ -1529,8 +1533,9 @@ static int load_free_space_bitmaps(struct btrfs_caching_control *caching_ctl,
15291533
}
15301534
}
15311535
if (prev_bit == 1) {
1532-
total_found += add_new_free_space(block_group, extent_start,
1533-
end);
1536+
ret = add_new_free_space(block_group, extent_start, end, NULL);
1537+
if (ret)
1538+
goto out;
15341539
extent_count++;
15351540
}
15361541

@@ -1569,6 +1574,8 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
15691574
end = block_group->start + block_group->length;
15701575

15711576
while (1) {
1577+
u64 space_added;
1578+
15721579
ret = btrfs_next_item(root, path);
15731580
if (ret < 0)
15741581
goto out;
@@ -1583,8 +1590,11 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
15831590
ASSERT(key.type == BTRFS_FREE_SPACE_EXTENT_KEY);
15841591
ASSERT(key.objectid < end && key.objectid + key.offset <= end);
15851592

1586-
total_found += add_new_free_space(block_group, key.objectid,
1587-
key.objectid + key.offset);
1593+
ret = add_new_free_space(block_group, key.objectid,
1594+
key.objectid + key.offset, &space_added);
1595+
if (ret)
1596+
goto out;
1597+
total_found += space_added;
15881598
if (total_found > CACHING_CTL_WAKE_UP) {
15891599
total_found = 0;
15901600
wake_up(&caching_ctl->wait);

fs/btrfs/transaction.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,13 @@ btrfs_attach_transaction_barrier(struct btrfs_root *root)
826826

827827
trans = start_transaction(root, 0, TRANS_ATTACH,
828828
BTRFS_RESERVE_NO_FLUSH, true);
829-
if (trans == ERR_PTR(-ENOENT))
830-
btrfs_wait_for_commit(root->fs_info, 0);
829+
if (trans == ERR_PTR(-ENOENT)) {
830+
int ret;
831+
832+
ret = btrfs_wait_for_commit(root->fs_info, 0);
833+
if (ret)
834+
return ERR_PTR(ret);
835+
}
831836

832837
return trans;
833838
}
@@ -931,6 +936,7 @@ int btrfs_wait_for_commit(struct btrfs_fs_info *fs_info, u64 transid)
931936
}
932937

933938
wait_for_commit(cur_trans, TRANS_STATE_COMPLETED);
939+
ret = cur_trans->aborted;
934940
btrfs_put_transaction(cur_trans);
935941
out:
936942
return ret;

fs/btrfs/zoned.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ int btrfs_check_mountopts_zoned(struct btrfs_fs_info *info)
805805
return -EINVAL;
806806
}
807807

808+
btrfs_clear_and_info(info, DISCARD_ASYNC,
809+
"zoned: async discard ignored and disabled for zoned mode");
810+
808811
return 0;
809812
}
810813

0 commit comments

Comments
 (0)