Skip to content

Commit 722985e

Browse files
committed
Merge tag 'for-5.18-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "A few more code and warning fixes. There's one feature ioctl removal patch slated for 5.18 that did not make it to the main pull request. It's just a one-liner and the ioctl has a v2 that's in use for a long time, no point to postpone it to 5.19. Late update: - remove balance v1 ioctl, superseded by v2 in 2012 Fixes: - add back cgroup attribution for compressed writes - add super block write start/end annotations to asynchronous balance - fix root reference count on an error handling path - in zoned mode, activate zone at the chunk allocation time to avoid ENOSPC due to timing issues - fix delayed allocation accounting for direct IO Warning fixes: - simplify assertion condition in zoned check - remove an unused variable" * tag 'for-5.18-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: fix btrfs_submit_compressed_write cgroup attribution btrfs: fix root ref counts in error handling in btrfs_get_root_ref btrfs: zoned: activate block group only for extent allocation btrfs: return allocated block group from do_chunk_alloc() btrfs: mark resumed async balance as writing btrfs: remove support of balance v1 ioctl btrfs: release correct delalloc amount in direct IO write path btrfs: remove unused variable in btrfs_{start,write}_dirty_block_groups() btrfs: zoned: remove redundant condition in btrfs_run_delalloc_range
2 parents ec9c57a + acee08a commit 722985e

8 files changed

Lines changed: 49 additions & 23 deletions

File tree

fs/btrfs/block-group.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,12 +2503,6 @@ struct btrfs_block_group *btrfs_make_block_group(struct btrfs_trans_handle *tran
25032503
return ERR_PTR(ret);
25042504
}
25052505

2506-
/*
2507-
* New block group is likely to be used soon. Try to activate it now.
2508-
* Failure is OK for now.
2509-
*/
2510-
btrfs_zone_activate(cache);
2511-
25122506
ret = exclude_super_stripes(cache);
25132507
if (ret) {
25142508
/* We may have excluded something, so call this just in case */
@@ -2946,7 +2940,6 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
29462940
struct btrfs_path *path = NULL;
29472941
LIST_HEAD(dirty);
29482942
struct list_head *io = &cur_trans->io_bgs;
2949-
int num_started = 0;
29502943
int loops = 0;
29512944

29522945
spin_lock(&cur_trans->dirty_bgs_lock);
@@ -3012,7 +3005,6 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
30123005
cache->io_ctl.inode = NULL;
30133006
ret = btrfs_write_out_cache(trans, cache, path);
30143007
if (ret == 0 && cache->io_ctl.inode) {
3015-
num_started++;
30163008
should_put = 0;
30173009

30183010
/*
@@ -3113,7 +3105,6 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
31133105
int should_put;
31143106
struct btrfs_path *path;
31153107
struct list_head *io = &cur_trans->io_bgs;
3116-
int num_started = 0;
31173108

31183109
path = btrfs_alloc_path();
31193110
if (!path)
@@ -3171,7 +3162,6 @@ int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans)
31713162
cache->io_ctl.inode = NULL;
31723163
ret = btrfs_write_out_cache(trans, cache, path);
31733164
if (ret == 0 && cache->io_ctl.inode) {
3174-
num_started++;
31753165
should_put = 0;
31763166
list_add_tail(&cache->io_list, io);
31773167
} else {
@@ -3455,7 +3445,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, u64 type)
34553445
return btrfs_chunk_alloc(trans, alloc_flags, CHUNK_ALLOC_FORCE);
34563446
}
34573447

3458-
static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
3448+
static struct btrfs_block_group *do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
34593449
{
34603450
struct btrfs_block_group *bg;
34613451
int ret;
@@ -3542,7 +3532,11 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags)
35423532
out:
35433533
btrfs_trans_release_chunk_metadata(trans);
35443534

3545-
return ret;
3535+
if (ret)
3536+
return ERR_PTR(ret);
3537+
3538+
btrfs_get_block_group(bg);
3539+
return bg;
35463540
}
35473541

35483542
/*
@@ -3657,10 +3651,17 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
36573651
{
36583652
struct btrfs_fs_info *fs_info = trans->fs_info;
36593653
struct btrfs_space_info *space_info;
3654+
struct btrfs_block_group *ret_bg;
36603655
bool wait_for_alloc = false;
36613656
bool should_alloc = false;
3657+
bool from_extent_allocation = false;
36623658
int ret = 0;
36633659

3660+
if (force == CHUNK_ALLOC_FORCE_FOR_EXTENT) {
3661+
from_extent_allocation = true;
3662+
force = CHUNK_ALLOC_FORCE;
3663+
}
3664+
36643665
/* Don't re-enter if we're already allocating a chunk */
36653666
if (trans->allocating_chunk)
36663667
return -ENOSPC;
@@ -3750,9 +3751,22 @@ int btrfs_chunk_alloc(struct btrfs_trans_handle *trans, u64 flags,
37503751
force_metadata_allocation(fs_info);
37513752
}
37523753

3753-
ret = do_chunk_alloc(trans, flags);
3754+
ret_bg = do_chunk_alloc(trans, flags);
37543755
trans->allocating_chunk = false;
37553756

3757+
if (IS_ERR(ret_bg)) {
3758+
ret = PTR_ERR(ret_bg);
3759+
} else if (from_extent_allocation) {
3760+
/*
3761+
* New block group is likely to be used soon. Try to activate
3762+
* it now. Failure is OK for now.
3763+
*/
3764+
btrfs_zone_activate(ret_bg);
3765+
}
3766+
3767+
if (!ret)
3768+
btrfs_put_block_group(ret_bg);
3769+
37563770
spin_lock(&space_info->lock);
37573771
if (ret < 0) {
37583772
if (ret == -ENOSPC)

fs/btrfs/block-group.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ enum btrfs_discard_state {
3535
* the FS with empty chunks
3636
*
3737
* CHUNK_ALLOC_FORCE means it must try to allocate one
38+
*
39+
* CHUNK_ALLOC_FORCE_FOR_EXTENT like CHUNK_ALLOC_FORCE but called from
40+
* find_free_extent() that also activaes the zone
3841
*/
3942
enum btrfs_chunk_alloc_enum {
4043
CHUNK_ALLOC_NO_FORCE,
4144
CHUNK_ALLOC_LIMITED,
4245
CHUNK_ALLOC_FORCE,
46+
CHUNK_ALLOC_FORCE_FOR_EXTENT,
4347
};
4448

4549
struct btrfs_caching_control {

fs/btrfs/compression.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
537537
cb->orig_bio = NULL;
538538
cb->nr_pages = nr_pages;
539539

540+
if (blkcg_css)
541+
kthread_associate_blkcg(blkcg_css);
542+
540543
while (cur_disk_bytenr < disk_start + compressed_len) {
541544
u64 offset = cur_disk_bytenr - disk_start;
542545
unsigned int index = offset >> PAGE_SHIFT;
@@ -555,6 +558,8 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
555558
bio = NULL;
556559
goto finish_cb;
557560
}
561+
if (blkcg_css)
562+
bio->bi_opf |= REQ_CGROUP_PUNT;
558563
}
559564
/*
560565
* We should never reach next_stripe_start start as we will
@@ -612,6 +617,9 @@ blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start,
612617
return 0;
613618

614619
finish_cb:
620+
if (blkcg_css)
621+
kthread_associate_blkcg(NULL);
622+
615623
if (bio) {
616624
bio->bi_status = ret;
617625
bio_endio(bio);

fs/btrfs/disk-io.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,9 +1850,10 @@ static struct btrfs_root *btrfs_get_root_ref(struct btrfs_fs_info *fs_info,
18501850

18511851
ret = btrfs_insert_fs_root(fs_info, root);
18521852
if (ret) {
1853-
btrfs_put_root(root);
1854-
if (ret == -EEXIST)
1853+
if (ret == -EEXIST) {
1854+
btrfs_put_root(root);
18551855
goto again;
1856+
}
18561857
goto fail;
18571858
}
18581859
return root;

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4082,7 +4082,7 @@ static int find_free_extent_update_loop(struct btrfs_fs_info *fs_info,
40824082
}
40834083

40844084
ret = btrfs_chunk_alloc(trans, ffe_ctl->flags,
4085-
CHUNK_ALLOC_FORCE);
4085+
CHUNK_ALLOC_FORCE_FOR_EXTENT);
40864086

40874087
/* Do not bail out on ENOSPC since we can do more. */
40884088
if (ret == -ENOSPC)

fs/btrfs/inode.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,8 +2016,7 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
20162016
* to use run_delalloc_nocow() here, like for regular
20172017
* preallocated inodes.
20182018
*/
2019-
ASSERT(!zoned ||
2020-
(zoned && btrfs_is_data_reloc_root(inode->root)));
2019+
ASSERT(!zoned || btrfs_is_data_reloc_root(inode->root));
20212020
ret = run_delalloc_nocow(inode, locked_page, start, end,
20222021
page_started, nr_written);
20232022
} else if (!inode_can_compress(inode) ||
@@ -7444,6 +7443,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
74447443
u64 block_start, orig_start, orig_block_len, ram_bytes;
74457444
bool can_nocow = false;
74467445
bool space_reserved = false;
7446+
u64 prev_len;
74477447
int ret = 0;
74487448

74497449
/*
@@ -7471,6 +7471,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
74717471
can_nocow = true;
74727472
}
74737473

7474+
prev_len = len;
74747475
if (can_nocow) {
74757476
struct extent_map *em2;
74767477

@@ -7500,8 +7501,6 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
75007501
goto out;
75017502
}
75027503
} else {
7503-
const u64 prev_len = len;
7504-
75057504
/* Our caller expects us to free the input extent map. */
75067505
free_extent_map(em);
75077506
*map = NULL;
@@ -7532,7 +7531,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
75327531
* We have created our ordered extent, so we can now release our reservation
75337532
* for an outstanding extent.
75347533
*/
7535-
btrfs_delalloc_release_extents(BTRFS_I(inode), len);
7534+
btrfs_delalloc_release_extents(BTRFS_I(inode), prev_len);
75367535

75377536
/*
75387537
* Need to update the i_size under the extent lock so buffered

fs/btrfs/ioctl.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5456,8 +5456,6 @@ long btrfs_ioctl(struct file *file, unsigned int
54565456
return btrfs_ioctl_fs_info(fs_info, argp);
54575457
case BTRFS_IOC_DEV_INFO:
54585458
return btrfs_ioctl_dev_info(fs_info, argp);
5459-
case BTRFS_IOC_BALANCE:
5460-
return btrfs_ioctl_balance(file, NULL);
54615459
case BTRFS_IOC_TREE_SEARCH:
54625460
return btrfs_ioctl_tree_search(inode, argp);
54635461
case BTRFS_IOC_TREE_SEARCH_V2:

fs/btrfs/volumes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,10 +4430,12 @@ static int balance_kthread(void *data)
44304430
struct btrfs_fs_info *fs_info = data;
44314431
int ret = 0;
44324432

4433+
sb_start_write(fs_info->sb);
44334434
mutex_lock(&fs_info->balance_mutex);
44344435
if (fs_info->balance_ctl)
44354436
ret = btrfs_balance(fs_info, fs_info->balance_ctl, NULL);
44364437
mutex_unlock(&fs_info->balance_mutex);
4438+
sb_end_write(fs_info->sb);
44374439

44384440
return ret;
44394441
}

0 commit comments

Comments
 (0)