Skip to content

Commit 3039fad

Browse files
committed
Merge tag 'for-5.3-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux
Pull btrfs fixes from David Sterba: "Two fixes that popped up during testing: - fix for sysfs-related code that adds/removes block groups, warnings appear during several fstests in connection with sysfs updates in 5.3, the fix essentially replaces a workaround with scope NOFS and applies to 5.2-based branch too - add sanity check of trim range" * tag 'for-5.3-rc4-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: btrfs: trim: Check the range passed into to prevent overflow Btrfs: fix sysfs warning and missing raid sysfs directories
2 parents c332f3a + 07301df commit 3039fad

File tree

4 files changed

+35
-55
lines changed

4 files changed

+35
-55
lines changed

fs/btrfs/ctree.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ struct btrfs_dev_replace {
401401
struct raid_kobject {
402402
u64 flags;
403403
struct kobject kobj;
404-
struct list_head list;
405404
};
406405

407406
/*
@@ -915,8 +914,6 @@ struct btrfs_fs_info {
915914
u32 thread_pool_size;
916915

917916
struct kobject *space_info_kobj;
918-
struct list_head pending_raid_kobjs;
919-
spinlock_t pending_raid_kobjs_lock; /* uncontended */
920917

921918
u64 total_pinned;
922919

@@ -2698,7 +2695,6 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr);
26982695
int btrfs_make_block_group(struct btrfs_trans_handle *trans,
26992696
u64 bytes_used, u64 type, u64 chunk_offset,
27002697
u64 size);
2701-
void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info);
27022698
struct btrfs_trans_handle *btrfs_start_trans_remove_block_group(
27032699
struct btrfs_fs_info *fs_info,
27042700
const u64 chunk_offset);

fs/btrfs/disk-io.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,8 +2683,6 @@ int open_ctree(struct super_block *sb,
26832683
INIT_LIST_HEAD(&fs_info->delayed_iputs);
26842684
INIT_LIST_HEAD(&fs_info->delalloc_roots);
26852685
INIT_LIST_HEAD(&fs_info->caching_block_groups);
2686-
INIT_LIST_HEAD(&fs_info->pending_raid_kobjs);
2687-
spin_lock_init(&fs_info->pending_raid_kobjs_lock);
26882686
spin_lock_init(&fs_info->delalloc_root_lock);
26892687
spin_lock_init(&fs_info->trans_lock);
26902688
spin_lock_init(&fs_info->fs_roots_radix_lock);

fs/btrfs/extent-tree.c

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/sched.h>
7+
#include <linux/sched/mm.h>
78
#include <linux/sched/signal.h>
89
#include <linux/pagemap.h>
910
#include <linux/writeback.h>
@@ -7888,33 +7889,6 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info)
78887889
return 0;
78897890
}
78907891

7891-
/* link_block_group will queue up kobjects to add when we're reclaim-safe */
7892-
void btrfs_add_raid_kobjects(struct btrfs_fs_info *fs_info)
7893-
{
7894-
struct btrfs_space_info *space_info;
7895-
struct raid_kobject *rkobj;
7896-
LIST_HEAD(list);
7897-
int ret = 0;
7898-
7899-
spin_lock(&fs_info->pending_raid_kobjs_lock);
7900-
list_splice_init(&fs_info->pending_raid_kobjs, &list);
7901-
spin_unlock(&fs_info->pending_raid_kobjs_lock);
7902-
7903-
list_for_each_entry(rkobj, &list, list) {
7904-
space_info = btrfs_find_space_info(fs_info, rkobj->flags);
7905-
7906-
ret = kobject_add(&rkobj->kobj, &space_info->kobj,
7907-
"%s", btrfs_bg_type_to_raid_name(rkobj->flags));
7908-
if (ret) {
7909-
kobject_put(&rkobj->kobj);
7910-
break;
7911-
}
7912-
}
7913-
if (ret)
7914-
btrfs_warn(fs_info,
7915-
"failed to add kobject for block cache, ignoring");
7916-
}
7917-
79187892
static void link_block_group(struct btrfs_block_group_cache *cache)
79197893
{
79207894
struct btrfs_space_info *space_info = cache->space_info;
@@ -7929,18 +7903,36 @@ static void link_block_group(struct btrfs_block_group_cache *cache)
79297903
up_write(&space_info->groups_sem);
79307904

79317905
if (first) {
7932-
struct raid_kobject *rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS);
7906+
struct raid_kobject *rkobj;
7907+
unsigned int nofs_flag;
7908+
int ret;
7909+
7910+
/*
7911+
* Setup a NOFS context because kobject_add(), deep in its call
7912+
* chain, does GFP_KERNEL allocations, and we are often called
7913+
* in a context where if reclaim is triggered we can deadlock
7914+
* (we are either holding a transaction handle or some lock
7915+
* required for a transaction commit).
7916+
*/
7917+
nofs_flag = memalloc_nofs_save();
7918+
rkobj = kzalloc(sizeof(*rkobj), GFP_KERNEL);
79337919
if (!rkobj) {
7920+
memalloc_nofs_restore(nofs_flag);
79347921
btrfs_warn(cache->fs_info,
79357922
"couldn't alloc memory for raid level kobject");
79367923
return;
79377924
}
79387925
rkobj->flags = cache->flags;
79397926
kobject_init(&rkobj->kobj, &btrfs_raid_ktype);
7940-
7941-
spin_lock(&fs_info->pending_raid_kobjs_lock);
7942-
list_add_tail(&rkobj->list, &fs_info->pending_raid_kobjs);
7943-
spin_unlock(&fs_info->pending_raid_kobjs_lock);
7927+
ret = kobject_add(&rkobj->kobj, &space_info->kobj, "%s",
7928+
btrfs_bg_type_to_raid_name(rkobj->flags));
7929+
memalloc_nofs_restore(nofs_flag);
7930+
if (ret) {
7931+
kobject_put(&rkobj->kobj);
7932+
btrfs_warn(fs_info,
7933+
"failed to add kobject for block cache, ignoring");
7934+
return;
7935+
}
79447936
space_info->block_group_kobjs[index] = &rkobj->kobj;
79457937
}
79467938
}
@@ -8206,7 +8198,6 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
82068198
inc_block_group_ro(cache, 1);
82078199
}
82088200

8209-
btrfs_add_raid_kobjects(info);
82108201
btrfs_init_global_block_rsv(info);
82118202
ret = check_chunk_block_group_mappings(info);
82128203
error:
@@ -8975,6 +8966,7 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
89758966
struct btrfs_device *device;
89768967
struct list_head *devices;
89778968
u64 group_trimmed;
8969+
u64 range_end = U64_MAX;
89788970
u64 start;
89798971
u64 end;
89808972
u64 trimmed = 0;
@@ -8984,16 +8976,23 @@ int btrfs_trim_fs(struct btrfs_fs_info *fs_info, struct fstrim_range *range)
89848976
int dev_ret = 0;
89858977
int ret = 0;
89868978

8979+
/*
8980+
* Check range overflow if range->len is set.
8981+
* The default range->len is U64_MAX.
8982+
*/
8983+
if (range->len != U64_MAX &&
8984+
check_add_overflow(range->start, range->len, &range_end))
8985+
return -EINVAL;
8986+
89878987
cache = btrfs_lookup_first_block_group(fs_info, range->start);
89888988
for (; cache; cache = next_block_group(cache)) {
8989-
if (cache->key.objectid >= (range->start + range->len)) {
8989+
if (cache->key.objectid >= range_end) {
89908990
btrfs_put_block_group(cache);
89918991
break;
89928992
}
89938993

89948994
start = max(range->start, cache->key.objectid);
8995-
end = min(range->start + range->len,
8996-
cache->key.objectid + cache->key.offset);
8995+
end = min(range_end, cache->key.objectid + cache->key.offset);
89978996

89988997
if (end - start >= range->minlen) {
89998998
if (!block_group_cache_done(cache)) {

fs/btrfs/volumes.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,16 +3087,6 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
30873087
if (ret)
30883088
return ret;
30893089

3090-
/*
3091-
* We add the kobjects here (and after forcing data chunk creation)
3092-
* since relocation is the only place we'll create chunks of a new
3093-
* type at runtime. The only place where we'll remove the last
3094-
* chunk of a type is the call immediately below this one. Even
3095-
* so, we're protected against races with the cleaner thread since
3096-
* we're covered by the delete_unused_bgs_mutex.
3097-
*/
3098-
btrfs_add_raid_kobjects(fs_info);
3099-
31003090
trans = btrfs_start_trans_remove_block_group(root->fs_info,
31013091
chunk_offset);
31023092
if (IS_ERR(trans)) {
@@ -3223,9 +3213,6 @@ static int btrfs_may_alloc_data_chunk(struct btrfs_fs_info *fs_info,
32233213
btrfs_end_transaction(trans);
32243214
if (ret < 0)
32253215
return ret;
3226-
3227-
btrfs_add_raid_kobjects(fs_info);
3228-
32293216
return 1;
32303217
}
32313218
}

0 commit comments

Comments
 (0)