Skip to content

Commit ad80142

Browse files
committed
Merge tag 'for-5.6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull more btrfs updates from David Sterba: "Fixes that arrived after the merge window freeze, mostly stable material. - fix race in tree-mod-log element tracking - fix bio flushing inside extent writepages - fix assertion when in-memory tracking of discarded extents finds an empty tree (eg. after adding a new device) - update logic of temporary read-only block groups to take into account overcommit - fix some fixup worker corner cases: - page could not go through proper COW cycle and the dirty status is lost due to page migration - deadlock if delayed allocation is performed under page lock - fix send emitting invalid clones within the same file - fix statfs reporting 0 free space when global block reserve size is larger than remaining free space but there is still space for new chunks" * tag 'for-5.6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: do not zero f_bavail if we have available space Btrfs: send, fix emission of invalid clone operations within the same file btrfs: do not do delalloc reservation under page lock btrfs: drop the -EBUSY case in __extent_writepage_io Btrfs: keep pages dirty when using btrfs_writepage_fixup_worker btrfs: take overcommit into account in inc_block_group_ro btrfs: fix force usage in inc_block_group_ro btrfs: Correctly handle empty trees in find_first_clear_extent_bit btrfs: flush write bio if we loop in extent_write_cache_pages Btrfs: fix race between adding and putting tree mod seq elements and nodes
2 parents e17ac02 + d55966c commit ad80142

File tree

13 files changed

+193
-83
lines changed

13 files changed

+193
-83
lines changed

fs/btrfs/block-group.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,6 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
11911191
{
11921192
struct btrfs_space_info *sinfo = cache->space_info;
11931193
u64 num_bytes;
1194-
u64 sinfo_used;
11951194
int ret = -ENOSPC;
11961195

11971196
spin_lock(&sinfo->lock);
@@ -1205,29 +1204,45 @@ static int inc_block_group_ro(struct btrfs_block_group *cache, int force)
12051204

12061205
num_bytes = cache->length - cache->reserved - cache->pinned -
12071206
cache->bytes_super - cache->used;
1208-
sinfo_used = btrfs_space_info_used(sinfo, true);
12091207

12101208
/*
1211-
* sinfo_used + num_bytes should always <= sinfo->total_bytes.
1212-
*
1213-
* Here we make sure if we mark this bg RO, we still have enough
1214-
* free space as buffer.
1209+
* Data never overcommits, even in mixed mode, so do just the straight
1210+
* check of left over space in how much we have allocated.
12151211
*/
1216-
if (sinfo_used + num_bytes <= sinfo->total_bytes) {
1212+
if (force) {
1213+
ret = 0;
1214+
} else if (sinfo->flags & BTRFS_BLOCK_GROUP_DATA) {
1215+
u64 sinfo_used = btrfs_space_info_used(sinfo, true);
1216+
1217+
/*
1218+
* Here we make sure if we mark this bg RO, we still have enough
1219+
* free space as buffer.
1220+
*/
1221+
if (sinfo_used + num_bytes <= sinfo->total_bytes)
1222+
ret = 0;
1223+
} else {
1224+
/*
1225+
* We overcommit metadata, so we need to do the
1226+
* btrfs_can_overcommit check here, and we need to pass in
1227+
* BTRFS_RESERVE_NO_FLUSH to give ourselves the most amount of
1228+
* leeway to allow us to mark this block group as read only.
1229+
*/
1230+
if (btrfs_can_overcommit(cache->fs_info, sinfo, num_bytes,
1231+
BTRFS_RESERVE_NO_FLUSH))
1232+
ret = 0;
1233+
}
1234+
1235+
if (!ret) {
12171236
sinfo->bytes_readonly += num_bytes;
12181237
cache->ro++;
12191238
list_add_tail(&cache->ro_list, &sinfo->ro_bgs);
1220-
ret = 0;
12211239
}
12221240
out:
12231241
spin_unlock(&cache->lock);
12241242
spin_unlock(&sinfo->lock);
12251243
if (ret == -ENOSPC && btrfs_test_opt(cache->fs_info, ENOSPC_DEBUG)) {
12261244
btrfs_info(cache->fs_info,
12271245
"unable to make block group %llu ro", cache->start);
1228-
btrfs_info(cache->fs_info,
1229-
"sinfo_used=%llu bg_num_bytes=%llu",
1230-
sinfo_used, num_bytes);
12311246
btrfs_dump_space_info(cache->fs_info, cache->space_info, 0, 0);
12321247
}
12331248
return ret;
@@ -2225,7 +2240,7 @@ int btrfs_inc_block_group_ro(struct btrfs_block_group *cache,
22252240
}
22262241
}
22272242

2228-
ret = inc_block_group_ro(cache, !do_chunk_alloc);
2243+
ret = inc_block_group_ro(cache, 0);
22292244
if (!do_chunk_alloc)
22302245
goto unlock_out;
22312246
if (!ret)

fs/btrfs/ctree.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,10 @@ u64 btrfs_get_tree_mod_seq(struct btrfs_fs_info *fs_info,
326326
struct seq_list *elem)
327327
{
328328
write_lock(&fs_info->tree_mod_log_lock);
329-
spin_lock(&fs_info->tree_mod_seq_lock);
330329
if (!elem->seq) {
331330
elem->seq = btrfs_inc_tree_mod_seq(fs_info);
332331
list_add_tail(&elem->list, &fs_info->tree_mod_seq_list);
333332
}
334-
spin_unlock(&fs_info->tree_mod_seq_lock);
335333
write_unlock(&fs_info->tree_mod_log_lock);
336334

337335
return elem->seq;
@@ -351,7 +349,7 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
351349
if (!seq_putting)
352350
return;
353351

354-
spin_lock(&fs_info->tree_mod_seq_lock);
352+
write_lock(&fs_info->tree_mod_log_lock);
355353
list_del(&elem->list);
356354
elem->seq = 0;
357355

@@ -362,19 +360,17 @@ void btrfs_put_tree_mod_seq(struct btrfs_fs_info *fs_info,
362360
* blocker with lower sequence number exists, we
363361
* cannot remove anything from the log
364362
*/
365-
spin_unlock(&fs_info->tree_mod_seq_lock);
363+
write_unlock(&fs_info->tree_mod_log_lock);
366364
return;
367365
}
368366
min_seq = cur_elem->seq;
369367
}
370368
}
371-
spin_unlock(&fs_info->tree_mod_seq_lock);
372369

373370
/*
374371
* anything that's lower than the lowest existing (read: blocked)
375372
* sequence number can be removed from the tree.
376373
*/
377-
write_lock(&fs_info->tree_mod_log_lock);
378374
tm_root = &fs_info->tree_mod_log;
379375
for (node = rb_first(tm_root); node; node = next) {
380376
next = rb_next(node);

fs/btrfs/ctree.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,12 @@ struct btrfs_fs_info {
714714
atomic_t nr_delayed_iputs;
715715
wait_queue_head_t delayed_iputs_wait;
716716

717-
/* this protects tree_mod_seq_list */
718-
spinlock_t tree_mod_seq_lock;
719717
atomic64_t tree_mod_seq;
720-
struct list_head tree_mod_seq_list;
721718

722-
/* this protects tree_mod_log */
719+
/* this protects tree_mod_log and tree_mod_seq_list */
723720
rwlock_t tree_mod_log_lock;
724721
struct rb_root tree_mod_log;
722+
struct list_head tree_mod_seq_list;
725723

726724
atomic_t async_delalloc_pages;
727725

fs/btrfs/delayed-ref.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,15 @@ void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans,
492492
if (head->is_data)
493493
return;
494494

495-
spin_lock(&fs_info->tree_mod_seq_lock);
495+
read_lock(&fs_info->tree_mod_log_lock);
496496
if (!list_empty(&fs_info->tree_mod_seq_list)) {
497497
struct seq_list *elem;
498498

499499
elem = list_first_entry(&fs_info->tree_mod_seq_list,
500500
struct seq_list, list);
501501
seq = elem->seq;
502502
}
503-
spin_unlock(&fs_info->tree_mod_seq_lock);
503+
read_unlock(&fs_info->tree_mod_log_lock);
504504

505505
again:
506506
for (node = rb_first_cached(&head->ref_tree); node;
@@ -518,7 +518,7 @@ int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq)
518518
struct seq_list *elem;
519519
int ret = 0;
520520

521-
spin_lock(&fs_info->tree_mod_seq_lock);
521+
read_lock(&fs_info->tree_mod_log_lock);
522522
if (!list_empty(&fs_info->tree_mod_seq_list)) {
523523
elem = list_first_entry(&fs_info->tree_mod_seq_list,
524524
struct seq_list, list);
@@ -531,7 +531,7 @@ int btrfs_check_delayed_seq(struct btrfs_fs_info *fs_info, u64 seq)
531531
}
532532
}
533533

534-
spin_unlock(&fs_info->tree_mod_seq_lock);
534+
read_unlock(&fs_info->tree_mod_log_lock);
535535
return ret;
536536
}
537537

fs/btrfs/disk-io.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,6 @@ int __cold open_ctree(struct super_block *sb,
26972697
spin_lock_init(&fs_info->fs_roots_radix_lock);
26982698
spin_lock_init(&fs_info->delayed_iput_lock);
26992699
spin_lock_init(&fs_info->defrag_inodes_lock);
2700-
spin_lock_init(&fs_info->tree_mod_seq_lock);
27012700
spin_lock_init(&fs_info->super_lock);
27022701
spin_lock_init(&fs_info->buffer_lock);
27032702
spin_lock_init(&fs_info->unused_bgs_lock);

fs/btrfs/extent_io.c

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,21 +1593,25 @@ void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
15931593
/* Find first extent with bits cleared */
15941594
while (1) {
15951595
node = __etree_search(tree, start, &next, &prev, NULL, NULL);
1596-
if (!node) {
1596+
if (!node && !next && !prev) {
1597+
/*
1598+
* Tree is completely empty, send full range and let
1599+
* caller deal with it
1600+
*/
1601+
*start_ret = 0;
1602+
*end_ret = -1;
1603+
goto out;
1604+
} else if (!node && !next) {
1605+
/*
1606+
* We are past the last allocated chunk, set start at
1607+
* the end of the last extent.
1608+
*/
1609+
state = rb_entry(prev, struct extent_state, rb_node);
1610+
*start_ret = state->end + 1;
1611+
*end_ret = -1;
1612+
goto out;
1613+
} else if (!node) {
15971614
node = next;
1598-
if (!node) {
1599-
/*
1600-
* We are past the last allocated chunk,
1601-
* set start at the end of the last extent. The
1602-
* device alloc tree should never be empty so
1603-
* prev is always set.
1604-
*/
1605-
ASSERT(prev);
1606-
state = rb_entry(prev, struct extent_state, rb_node);
1607-
*start_ret = state->end + 1;
1608-
*end_ret = -1;
1609-
goto out;
1610-
}
16111615
}
16121616
/*
16131617
* At this point 'node' either contains 'start' or start is
@@ -3438,11 +3442,7 @@ static noinline_for_stack int __extent_writepage_io(struct inode *inode,
34383442
ret = btrfs_writepage_cow_fixup(page, start, page_end);
34393443
if (ret) {
34403444
/* Fixup worker will requeue */
3441-
if (ret == -EBUSY)
3442-
wbc->pages_skipped++;
3443-
else
3444-
redirty_page_for_writepage(wbc, page);
3445-
3445+
redirty_page_for_writepage(wbc, page);
34463446
update_nr_written(wbc, nr_written);
34473447
unlock_page(page);
34483448
return 1;
@@ -4166,7 +4166,16 @@ static int extent_write_cache_pages(struct address_space *mapping,
41664166
*/
41674167
scanned = 1;
41684168
index = 0;
4169-
goto retry;
4169+
4170+
/*
4171+
* If we're looping we could run into a page that is locked by a
4172+
* writer and that writer could be waiting on writeback for a
4173+
* page in our current bio, and thus deadlock, so flush the
4174+
* write bio here.
4175+
*/
4176+
ret = flush_write_bio(epd);
4177+
if (!ret)
4178+
goto retry;
41704179
}
41714180

41724181
if (wbc->range_cyclic || (wbc->nr_to_write > 0 && range_whole))

0 commit comments

Comments
 (0)