Skip to content

Commit 5ac1d20

Browse files
jeffmahoneyChris Mason
authored andcommitted
btrfs: publish per-super attributes in sysfs
This patch adds per-super attributes to sysfs. It doesn't publish any attributes yet, but does the proper lifetime handling as well as the basic infrastructure to add new attributes. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 079b72b commit 5ac1d20

4 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎fs/btrfs/ctree.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3780,6 +3780,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
37803780
/* sysfs.c */
37813781
int btrfs_init_sysfs(void);
37823782
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);
37833785

37843786
/* xattr.c */
37853787
ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);

‎fs/btrfs/disk-io.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "rcu-string.h"
4949
#include "dev-replace.h"
5050
#include "raid56.h"
51+
#include "sysfs.h"
5152

5253
#ifdef CONFIG_X86
5354
#include <asm/cpufeature.h>
@@ -2743,6 +2744,12 @@ int open_ctree(struct super_block *sb,
27432744

27442745
btrfs_close_extra_devices(fs_info, fs_devices, 1);
27452746

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+
27462753
ret = btrfs_init_space_info(fs_info);
27472754
if (ret) {
27482755
printk(KERN_ERR "Failed to initial space info: %d\n", ret);
@@ -3584,6 +3591,8 @@ int close_ctree(struct btrfs_root *root)
35843591
percpu_counter_sum(&fs_info->delalloc_bytes));
35853592
}
35863593

3594+
btrfs_sysfs_remove_one(fs_info);
3595+
35873596
del_fs_roots(fs_info);
35883597

35893598
btrfs_free_block_groups(fs_info);

‎fs/btrfs/sysfs.c‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@
2828
#include "transaction.h"
2929
#include "sysfs.h"
3030

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+
3150
static ssize_t btrfs_feature_attr_show(struct kobject *kobj,
3251
struct kobj_attribute *a, char *buf)
3352
{
@@ -65,6 +84,23 @@ static const struct attribute_group btrfs_feature_attr_group = {
6584
/* /sys/fs/btrfs/ entry */
6685
static struct kset *btrfs_kset;
6786

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+
68104
int btrfs_init_sysfs(void)
69105
{
70106
int ret;

‎fs/btrfs/sysfs.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ enum btrfs_feature_set {
1515
.store = _store, \
1616
}
1717

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+
1825
struct btrfs_feature_attr {
1926
struct kobj_attribute kobj_attr;
2027
enum btrfs_feature_set feature_set;
@@ -40,4 +47,7 @@ static struct btrfs_feature_attr btrfs_attr_##_name = { \
4047
/* convert from attribute */
4148
#define to_btrfs_feature_attr(a) \
4249
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))
4353
#endif /* _BTRFS_SYSFS_H_ */

0 commit comments

Comments
 (0)