|
28 | 28 | #include "transaction.h" |
29 | 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 | 50 | static ssize_t btrfs_feature_attr_show(struct kobject *kobj, |
32 | 51 | struct kobj_attribute *a, char *buf) |
33 | 52 | { |
@@ -65,6 +84,23 @@ static const struct attribute_group btrfs_feature_attr_group = { |
65 | 84 | /* /sys/fs/btrfs/ entry */ |
66 | 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 | 104 | int btrfs_init_sysfs(void) |
69 | 105 | { |
70 | 106 | int ret; |
|
0 commit comments