sysfs.h 3.2 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4

#ifndef BTRFS_SYSFS_H
#define BTRFS_SYSFS_H
5 6

enum btrfs_feature_set {
7
	FEAT_COMPAT,
8 9 10 11 12 13 14 15 16 17 18 19
	FEAT_COMPAT_RO,
	FEAT_INCOMPAT,
	FEAT_MAX
};

#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store)			\
{									\
	.attr	= { .name = __stringify(_name), .mode = _mode },	\
	.show	= _show,						\
	.store	= _store,						\
}

20 21
#define BTRFS_ATTR_RW(_prefix, _name, _show, _store)			\
	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
22
			__INIT_KOBJ_ATTR(_name, 0644, _show, _store)
23

24 25
#define BTRFS_ATTR(_prefix, _name, _show)				\
	static struct kobj_attribute btrfs_attr_##_prefix##_##_name =	\
26
			__INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
27

28 29
#define BTRFS_ATTR_PTR(_prefix, _name)					\
	(&btrfs_attr_##_prefix##_##_name.attr)
30 31


32 33 34 35 36 37
struct btrfs_feature_attr {
	struct kobj_attribute kobj_attr;
	enum btrfs_feature_set feature_set;
	u64 feature_bit;
};

38 39 40 41 42 43
/* For raid type sysfs entries */
struct raid_kobject {
	u64 flags;
	struct kobject kobj;
};

44 45
#define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit)  \
static struct btrfs_feature_attr btrfs_attr_features_##_name = {	     \
46
	.kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO,			     \
47 48
				      btrfs_feature_attr_show,		     \
				      btrfs_feature_attr_store),	     \
49
	.feature_set	= _feature_set,					     \
50
	.feature_bit	= _feature_prefix ##_## _feature_bit,		     \
51
}
52 53
#define BTRFS_FEAT_ATTR_PTR(_name)					     \
	(&btrfs_attr_features_##_name.kobj_attr.attr)
54 55 56 57

#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
	BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
58
	BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
59 60 61 62
#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
	BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)

/* convert from attribute */
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
static inline struct btrfs_feature_attr *
to_btrfs_feature_attr(struct kobj_attribute *a)
{
	return container_of(a, struct btrfs_feature_attr, kobj_attr);
}

static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
{
	return container_of(attr, struct kobj_attribute, attr);
}

static inline struct btrfs_feature_attr *
attr_to_btrfs_feature_attr(struct attribute *attr)
{
	return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
}

80
char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
81
extern const char * const btrfs_feature_set_names[FEAT_MAX];
82 83
extern struct kobj_type space_info_ktype;
extern struct kobj_type btrfs_raid_ktype;
84
int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
85
		struct btrfs_device *one_device);
86
int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
87
                struct btrfs_device *one_device);
88 89
int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
				struct kobject *parent);
90
int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
91
void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
92 93 94
void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
		u64 bit, enum btrfs_feature_set set);

95 96 97 98 99
int __init btrfs_init_sysfs(void);
void __cold btrfs_exit_sysfs(void);
int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);

100
#endif