提交 5ac1d209 编写于 作者: J Jeff Mahoney 提交者: Chris Mason

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: NJeff Mahoney <jeffm@suse.com>
Signed-off-by: NJosef Bacik <jbacik@fusionio.com>
Signed-off-by: NChris Mason <clm@fb.com>
上级 079b72bc
...@@ -3780,6 +3780,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ...@@ -3780,6 +3780,8 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans,
/* sysfs.c */ /* sysfs.c */
int btrfs_init_sysfs(void); int btrfs_init_sysfs(void);
void btrfs_exit_sysfs(void); void btrfs_exit_sysfs(void);
int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info);
void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info);
/* xattr.c */ /* xattr.c */
ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "rcu-string.h" #include "rcu-string.h"
#include "dev-replace.h" #include "dev-replace.h"
#include "raid56.h" #include "raid56.h"
#include "sysfs.h"
#ifdef CONFIG_X86 #ifdef CONFIG_X86
#include <asm/cpufeature.h> #include <asm/cpufeature.h>
...@@ -2743,6 +2744,12 @@ int open_ctree(struct super_block *sb, ...@@ -2743,6 +2744,12 @@ int open_ctree(struct super_block *sb,
btrfs_close_extra_devices(fs_info, fs_devices, 1); btrfs_close_extra_devices(fs_info, fs_devices, 1);
ret = btrfs_sysfs_add_one(fs_info);
if (ret) {
pr_err("btrfs: failed to init sysfs interface: %d\n", ret);
goto fail_block_groups;
}
ret = btrfs_init_space_info(fs_info); ret = btrfs_init_space_info(fs_info);
if (ret) { if (ret) {
printk(KERN_ERR "Failed to initial space info: %d\n", ret); printk(KERN_ERR "Failed to initial space info: %d\n", ret);
...@@ -3584,6 +3591,8 @@ int close_ctree(struct btrfs_root *root) ...@@ -3584,6 +3591,8 @@ int close_ctree(struct btrfs_root *root)
percpu_counter_sum(&fs_info->delalloc_bytes)); percpu_counter_sum(&fs_info->delalloc_bytes));
} }
btrfs_sysfs_remove_one(fs_info);
del_fs_roots(fs_info); del_fs_roots(fs_info);
btrfs_free_block_groups(fs_info); btrfs_free_block_groups(fs_info);
......
...@@ -28,6 +28,25 @@ ...@@ -28,6 +28,25 @@
#include "transaction.h" #include "transaction.h"
#include "sysfs.h" #include "sysfs.h"
static void btrfs_release_super_kobj(struct kobject *kobj);
static struct kobj_type btrfs_ktype = {
.sysfs_ops = &kobj_sysfs_ops,
.release = btrfs_release_super_kobj,
};
static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
{
if (kobj->ktype != &btrfs_ktype)
return NULL;
return container_of(kobj, struct btrfs_fs_info, super_kobj);
}
static void btrfs_release_super_kobj(struct kobject *kobj)
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);
complete(&fs_info->kobj_unregister);
}
static ssize_t btrfs_feature_attr_show(struct kobject *kobj, static ssize_t btrfs_feature_attr_show(struct kobject *kobj,
struct kobj_attribute *a, char *buf) struct kobj_attribute *a, char *buf)
{ {
...@@ -65,6 +84,23 @@ static const struct attribute_group btrfs_feature_attr_group = { ...@@ -65,6 +84,23 @@ static const struct attribute_group btrfs_feature_attr_group = {
/* /sys/fs/btrfs/ entry */ /* /sys/fs/btrfs/ entry */
static struct kset *btrfs_kset; static struct kset *btrfs_kset;
void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
{
kobject_del(&fs_info->super_kobj);
kobject_put(&fs_info->super_kobj);
wait_for_completion(&fs_info->kobj_unregister);
}
int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
{
int error;
init_completion(&fs_info->kobj_unregister);
error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL,
"%pU", fs_info->fsid);
return error;
}
int btrfs_init_sysfs(void) int btrfs_init_sysfs(void)
{ {
int ret; int ret;
......
...@@ -15,6 +15,13 @@ enum btrfs_feature_set { ...@@ -15,6 +15,13 @@ enum btrfs_feature_set {
.store = _store, \ .store = _store, \
} }
#define BTRFS_ATTR_RW(_name, _mode, _show, _store) \
static struct kobj_attribute btrfs_attr_##_name = \
__INIT_KOBJ_ATTR(_name, _mode, _show, _store)
#define BTRFS_ATTR(_name, _mode, _show) \
BTRFS_ATTR_RW(_name, _mode, _show, NULL)
#define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr)
struct btrfs_feature_attr { struct btrfs_feature_attr {
struct kobj_attribute kobj_attr; struct kobj_attribute kobj_attr;
enum btrfs_feature_set feature_set; enum btrfs_feature_set feature_set;
...@@ -40,4 +47,7 @@ static struct btrfs_feature_attr btrfs_attr_##_name = { \ ...@@ -40,4 +47,7 @@ static struct btrfs_feature_attr btrfs_attr_##_name = { \
/* convert from attribute */ /* convert from attribute */
#define to_btrfs_feature_attr(a) \ #define to_btrfs_feature_attr(a) \
container_of(a, struct btrfs_feature_attr, kobj_attr) container_of(a, struct btrfs_feature_attr, kobj_attr)
#define attr_to_btrfs_attr(a) container_of(a, struct kobj_attribute, attr)
#define attr_to_btrfs_feature_attr(a) \
to_btrfs_feature_attr(attr_to_btrfs_attr(a))
#endif /* _BTRFS_SYSFS_H_ */ #endif /* _BTRFS_SYSFS_H_ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册