]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9888c340 DS |
2 | |
3 | #ifndef BTRFS_SYSFS_H | |
4 | #define BTRFS_SYSFS_H | |
079b72bc JM |
5 | |
6 | enum btrfs_feature_set { | |
bbe339cc | 7 | FEAT_COMPAT, |
079b72bc JM |
8 | FEAT_COMPAT_RO, |
9 | FEAT_INCOMPAT, | |
10 | FEAT_MAX | |
11 | }; | |
12 | ||
13 | #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ | |
14 | { \ | |
15 | .attr = { .name = __stringify(_name), .mode = _mode }, \ | |
16 | .show = _show, \ | |
17 | .store = _store, \ | |
18 | } | |
19 | ||
a969f4cc HK |
20 | #define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \ |
21 | static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ | |
20ee0825 | 22 | __INIT_KOBJ_ATTR(_name, 0644, _show, _store) |
98b3d389 | 23 | |
a969f4cc HK |
24 | #define BTRFS_ATTR(_prefix, _name, _show) \ |
25 | static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ | |
20ee0825 | 26 | __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) |
98b3d389 | 27 | |
a969f4cc HK |
28 | #define BTRFS_ATTR_PTR(_prefix, _name) \ |
29 | (&btrfs_attr_##_prefix##_##_name.attr) | |
6ab0a202 JM |
30 | |
31 | ||
079b72bc JM |
32 | struct btrfs_feature_attr { |
33 | struct kobj_attribute kobj_attr; | |
34 | enum btrfs_feature_set feature_set; | |
35 | u64 feature_bit; | |
36 | }; | |
37 | ||
89439109 DS |
38 | /* For raid type sysfs entries */ |
39 | struct raid_kobject { | |
40 | u64 flags; | |
41 | struct kobject kobj; | |
42 | }; | |
43 | ||
a969f4cc HK |
44 | #define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit) \ |
45 | static struct btrfs_feature_attr btrfs_attr_features_##_name = { \ | |
079b72bc | 46 | .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \ |
ba631941 JM |
47 | btrfs_feature_attr_show, \ |
48 | btrfs_feature_attr_store), \ | |
079b72bc | 49 | .feature_set = _feature_set, \ |
a969f4cc | 50 | .feature_bit = _feature_prefix ##_## _feature_bit, \ |
079b72bc | 51 | } |
a969f4cc HK |
52 | #define BTRFS_FEAT_ATTR_PTR(_name) \ |
53 | (&btrfs_attr_features_##_name.kobj_attr.attr) | |
079b72bc JM |
54 | |
55 | #define BTRFS_FEAT_ATTR_COMPAT(name, feature) \ | |
56 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature) | |
57 | #define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \ | |
ba2d0840 | 58 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature) |
079b72bc JM |
59 | #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \ |
60 | BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) | |
61 | ||
62 | /* convert from attribute */ | |
093adbce DS |
63 | static inline struct btrfs_feature_attr * |
64 | to_btrfs_feature_attr(struct kobj_attribute *a) | |
65 | { | |
66 | return container_of(a, struct btrfs_feature_attr, kobj_attr); | |
67 | } | |
68 | ||
69 | static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr) | |
70 | { | |
71 | return container_of(attr, struct kobj_attribute, attr); | |
72 | } | |
73 | ||
74 | static inline struct btrfs_feature_attr * | |
75 | attr_to_btrfs_feature_attr(struct attribute *attr) | |
76 | { | |
77 | return to_btrfs_feature_attr(attr_to_btrfs_attr(attr)); | |
78 | } | |
79 | ||
3b02a68a | 80 | char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); |
6c52157f | 81 | extern const char * const btrfs_feature_set_names[FEAT_MAX]; |
6ab0a202 | 82 | extern struct kobj_type space_info_ktype; |
e3bd6973 | 83 | int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices, |
0d39376a | 84 | struct btrfs_device *one_device); |
32576040 | 85 | int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, |
99994cde | 86 | struct btrfs_device *one_device); |
0c10e2d4 AJ |
87 | int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs, |
88 | struct kobject *parent); | |
ef1a0daa | 89 | int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs); |
1d1c1be3 | 90 | void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs); |
444e7516 DS |
91 | void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info, |
92 | u64 bit, enum btrfs_feature_set set); | |
93 | ||
89439109 DS |
94 | int __init btrfs_init_sysfs(void); |
95 | void __cold btrfs_exit_sysfs(void); | |
96 | int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info); | |
97 | void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info); | |
32a9991f | 98 | void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache); |
89439109 | 99 | |
9888c340 | 100 | #endif |