diff options
-rw-r--r-- | fs/btrfs/ctree.h | 2 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 9 | ||||
-rw-r--r-- | fs/btrfs/sysfs.c | 36 | ||||
-rw-r--r-- | fs/btrfs/sysfs.h | 10 |
4 files changed, 57 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 498452ebfd37..c5c888fbf033 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -3780,6 +3780,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, | |||
3780 | /* sysfs.c */ | 3780 | /* sysfs.c */ |
3781 | int btrfs_init_sysfs(void); | 3781 | int btrfs_init_sysfs(void); |
3782 | void btrfs_exit_sysfs(void); | 3782 | void btrfs_exit_sysfs(void); |
3783 | int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info); | ||
3784 | void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info); | ||
3783 | 3785 | ||
3784 | /* xattr.c */ | 3786 | /* xattr.c */ |
3785 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | 3787 | ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 435ef132b800..81f3433fe4fd 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -48,6 +48,7 @@ | |||
48 | #include "rcu-string.h" | 48 | #include "rcu-string.h" |
49 | #include "dev-replace.h" | 49 | #include "dev-replace.h" |
50 | #include "raid56.h" | 50 | #include "raid56.h" |
51 | #include "sysfs.h" | ||
51 | 52 | ||
52 | #ifdef CONFIG_X86 | 53 | #ifdef CONFIG_X86 |
53 | #include <asm/cpufeature.h> | 54 | #include <asm/cpufeature.h> |
@@ -2743,6 +2744,12 @@ retry_root_backup: | |||
2743 | 2744 | ||
2744 | btrfs_close_extra_devices(fs_info, fs_devices, 1); | 2745 | btrfs_close_extra_devices(fs_info, fs_devices, 1); |
2745 | 2746 | ||
2747 | ret = btrfs_sysfs_add_one(fs_info); | ||
2748 | if (ret) { | ||
2749 | pr_err("btrfs: failed to init sysfs interface: %d\n", ret); | ||
2750 | goto fail_block_groups; | ||
2751 | } | ||
2752 | |||
2746 | ret = btrfs_init_space_info(fs_info); | 2753 | ret = btrfs_init_space_info(fs_info); |
2747 | if (ret) { | 2754 | if (ret) { |
2748 | printk(KERN_ERR "Failed to initial space info: %d\n", ret); | 2755 | printk(KERN_ERR "Failed to initial space info: %d\n", ret); |
@@ -3584,6 +3591,8 @@ int close_ctree(struct btrfs_root *root) | |||
3584 | percpu_counter_sum(&fs_info->delalloc_bytes)); | 3591 | percpu_counter_sum(&fs_info->delalloc_bytes)); |
3585 | } | 3592 | } |
3586 | 3593 | ||
3594 | btrfs_sysfs_remove_one(fs_info); | ||
3595 | |||
3587 | del_fs_roots(fs_info); | 3596 | del_fs_roots(fs_info); |
3588 | 3597 | ||
3589 | btrfs_free_block_groups(fs_info); | 3598 | btrfs_free_block_groups(fs_info); |
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index 9e217b581903..79be4a187af9 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c | |||
@@ -28,6 +28,25 @@ | |||
28 | #include "transaction.h" | 28 | #include "transaction.h" |
29 | #include "sysfs.h" | 29 | #include "sysfs.h" |
30 | 30 | ||
31 | static void btrfs_release_super_kobj(struct kobject *kobj); | ||
32 | static struct kobj_type btrfs_ktype = { | ||
33 | .sysfs_ops = &kobj_sysfs_ops, | ||
34 | .release = btrfs_release_super_kobj, | ||
35 | }; | ||
36 | |||
37 | static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj) | ||
38 | { | ||
39 | if (kobj->ktype != &btrfs_ktype) | ||
40 | return NULL; | ||
41 | return container_of(kobj, struct btrfs_fs_info, super_kobj); | ||
42 | } | ||
43 | |||
44 | static void btrfs_release_super_kobj(struct kobject *kobj) | ||
45 | { | ||
46 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); | ||
47 | complete(&fs_info->kobj_unregister); | ||
48 | } | ||
49 | |||
31 | static ssize_t btrfs_feature_attr_show(struct kobject *kobj, | 50 | static ssize_t btrfs_feature_attr_show(struct kobject *kobj, |
32 | struct kobj_attribute *a, char *buf) | 51 | struct kobj_attribute *a, char *buf) |
33 | { | 52 | { |
@@ -65,6 +84,23 @@ static const struct attribute_group btrfs_feature_attr_group = { | |||
65 | /* /sys/fs/btrfs/ entry */ | 84 | /* /sys/fs/btrfs/ entry */ |
66 | static struct kset *btrfs_kset; | 85 | static struct kset *btrfs_kset; |
67 | 86 | ||
87 | void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info) | ||
88 | { | ||
89 | kobject_del(&fs_info->super_kobj); | ||
90 | kobject_put(&fs_info->super_kobj); | ||
91 | wait_for_completion(&fs_info->kobj_unregister); | ||
92 | } | ||
93 | |||
94 | int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info) | ||
95 | { | ||
96 | int error; | ||
97 | |||
98 | init_completion(&fs_info->kobj_unregister); | ||
99 | error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL, | ||
100 | "%pU", fs_info->fsid); | ||
101 | return error; | ||
102 | } | ||
103 | |||
68 | int btrfs_init_sysfs(void) | 104 | int btrfs_init_sysfs(void) |
69 | { | 105 | { |
70 | int ret; | 106 | int ret; |
diff --git a/fs/btrfs/sysfs.h b/fs/btrfs/sysfs.h index 863e031ed1c1..d7c61bdf04ba 100644 --- a/fs/btrfs/sysfs.h +++ b/fs/btrfs/sysfs.h | |||
@@ -15,6 +15,13 @@ enum btrfs_feature_set { | |||
15 | .store = _store, \ | 15 | .store = _store, \ |
16 | } | 16 | } |
17 | 17 | ||
18 | #define BTRFS_ATTR_RW(_name, _mode, _show, _store) \ | ||
19 | static struct kobj_attribute btrfs_attr_##_name = \ | ||
20 | __INIT_KOBJ_ATTR(_name, _mode, _show, _store) | ||
21 | #define BTRFS_ATTR(_name, _mode, _show) \ | ||
22 | BTRFS_ATTR_RW(_name, _mode, _show, NULL) | ||
23 | #define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr) | ||
24 | |||
18 | struct btrfs_feature_attr { | 25 | struct btrfs_feature_attr { |
19 | struct kobj_attribute kobj_attr; | 26 | struct kobj_attribute kobj_attr; |
20 | enum btrfs_feature_set feature_set; | 27 | enum btrfs_feature_set feature_set; |
@@ -40,4 +47,7 @@ static struct btrfs_feature_attr btrfs_attr_##_name = { \ | |||
40 | /* convert from attribute */ | 47 | /* convert from attribute */ |
41 | #define to_btrfs_feature_attr(a) \ | 48 | #define to_btrfs_feature_attr(a) \ |
42 | container_of(a, struct btrfs_feature_attr, kobj_attr) | 49 | container_of(a, struct btrfs_feature_attr, kobj_attr) |
50 | #define attr_to_btrfs_attr(a) container_of(a, struct kobj_attribute, attr) | ||
51 | #define attr_to_btrfs_feature_attr(a) \ | ||
52 | to_btrfs_feature_attr(attr_to_btrfs_attr(a)) | ||
43 | #endif /* _BTRFS_SYSFS_H_ */ | 53 | #endif /* _BTRFS_SYSFS_H_ */ |