diff options
Diffstat (limited to 'fs/btrfs/sysfs.c')
-rw-r--r-- | fs/btrfs/sysfs.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 115499cd6b79..50cb9f9cdbfd 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c | |||
@@ -4,6 +4,7 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <linux/sched.h> | 6 | #include <linux/sched.h> |
7 | #include <linux/sched/mm.h> | ||
7 | #include <linux/slab.h> | 8 | #include <linux/slab.h> |
8 | #include <linux/spinlock.h> | 9 | #include <linux/spinlock.h> |
9 | #include <linux/completion.h> | 10 | #include <linux/completion.h> |
@@ -749,6 +750,51 @@ static void init_feature_attrs(void) | |||
749 | } | 750 | } |
750 | } | 751 | } |
751 | 752 | ||
753 | /* | ||
754 | * Create a sysfs entry for a given block group type at path | ||
755 | * /sys/fs/btrfs/UUID/allocation/data/TYPE | ||
756 | */ | ||
757 | void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache) | ||
758 | { | ||
759 | struct btrfs_fs_info *fs_info = cache->fs_info; | ||
760 | struct btrfs_space_info *space_info = cache->space_info; | ||
761 | struct raid_kobject *rkobj; | ||
762 | const int index = btrfs_bg_flags_to_raid_index(cache->flags); | ||
763 | unsigned int nofs_flag; | ||
764 | int ret; | ||
765 | |||
766 | /* | ||
767 | * Setup a NOFS context because kobject_add(), deep in its call chain, | ||
768 | * does GFP_KERNEL allocations, and we are often called in a context | ||
769 | * where if reclaim is triggered we can deadlock (we are either holding | ||
770 | * a transaction handle or some lock required for a transaction | ||
771 | * commit). | ||
772 | */ | ||
773 | nofs_flag = memalloc_nofs_save(); | ||
774 | |||
775 | rkobj = kzalloc(sizeof(*rkobj), GFP_NOFS); | ||
776 | if (!rkobj) { | ||
777 | memalloc_nofs_restore(nofs_flag); | ||
778 | btrfs_warn(cache->fs_info, | ||
779 | "couldn't alloc memory for raid level kobject"); | ||
780 | return; | ||
781 | } | ||
782 | |||
783 | rkobj->flags = cache->flags; | ||
784 | kobject_init(&rkobj->kobj, &btrfs_raid_ktype); | ||
785 | ret = kobject_add(&rkobj->kobj, &space_info->kobj, "%s", | ||
786 | btrfs_bg_type_to_raid_name(rkobj->flags)); | ||
787 | memalloc_nofs_restore(nofs_flag); | ||
788 | if (ret) { | ||
789 | kobject_put(&rkobj->kobj); | ||
790 | btrfs_warn(fs_info, | ||
791 | "failed to add kobject for block cache, ignoring"); | ||
792 | return; | ||
793 | } | ||
794 | |||
795 | space_info->block_group_kobjs[index] = &rkobj->kobj; | ||
796 | } | ||
797 | |||
752 | /* when one_device is NULL, it removes all device links */ | 798 | /* when one_device is NULL, it removes all device links */ |
753 | 799 | ||
754 | int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, | 800 | int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, |