blob: 4cb908305e5dab49638a9b3d6368f1b730aa5966 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Jeff Mahoney079b72b2013-11-01 13:06:57 -04002#ifndef _BTRFS_SYSFS_H_
3#define _BTRFS_SYSFS_H_
4
David Sterba1bae3092014-02-05 15:36:18 +01005/*
6 * Data exported through sysfs
7 */
8extern u64 btrfs_debugfs_test;
9
Jeff Mahoney079b72b2013-11-01 13:06:57 -040010enum btrfs_feature_set {
11 FEAT_COMPAT,
12 FEAT_COMPAT_RO,
13 FEAT_INCOMPAT,
14 FEAT_MAX
15};
16
17#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
18{ \
19 .attr = { .name = __stringify(_name), .mode = _mode }, \
20 .show = _show, \
21 .store = _store, \
22}
23
Anand Jain20ee0822014-07-30 20:04:09 +080024#define BTRFS_ATTR_RW(_name, _show, _store) \
Anand Jain98b3d382014-07-30 20:04:08 +080025 static struct kobj_attribute btrfs_attr_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080026 __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
Anand Jain98b3d382014-07-30 20:04:08 +080027
28#define BTRFS_ATTR(_name, _show) \
Anand Jain20ee0822014-07-30 20:04:09 +080029 static struct kobj_attribute btrfs_attr_##_name = \
30 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080031
Jeff Mahoney5ac1d202013-11-01 13:06:58 -040032#define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr)
33
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040034#define BTRFS_RAID_ATTR(_name, _show) \
Anand Jain98b3d382014-07-30 20:04:08 +080035 static struct kobj_attribute btrfs_raid_attr_##_name = \
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040036 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080037
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040038#define BTRFS_RAID_ATTR_PTR(_name) (&btrfs_raid_attr_##_name.attr)
39
40
Jeff Mahoney079b72b2013-11-01 13:06:57 -040041struct btrfs_feature_attr {
42 struct kobj_attribute kobj_attr;
43 enum btrfs_feature_set feature_set;
44 u64 feature_bit;
45};
46
47#define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \
48static struct btrfs_feature_attr btrfs_attr_##_name = { \
49 .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
Jeff Mahoneyba631942013-11-01 13:07:01 -040050 btrfs_feature_attr_show, \
51 btrfs_feature_attr_store), \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040052 .feature_set = _feature_set, \
53 .feature_bit = _prefix ##_## _feature_bit, \
54}
55#define BTRFS_FEAT_ATTR_PTR(_name) (&btrfs_attr_##_name.kobj_attr.attr)
56
57#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
58 BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
59#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
David Sterbaba2d0842016-01-20 19:07:04 +010060 BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
Jeff Mahoney079b72b2013-11-01 13:06:57 -040061#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
62 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
63
64/* convert from attribute */
David Sterba093adbc2015-02-24 19:40:41 +010065static inline struct btrfs_feature_attr *
66to_btrfs_feature_attr(struct kobj_attribute *a)
67{
68 return container_of(a, struct btrfs_feature_attr, kobj_attr);
69}
70
71static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
72{
73 return container_of(attr, struct kobj_attribute, attr);
74}
75
76static inline struct btrfs_feature_attr *
77attr_to_btrfs_feature_attr(struct attribute *attr)
78{
79 return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
80}
81
Jeff Mahoney3b02a682013-11-01 13:07:02 -040082char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
83extern const char * const btrfs_feature_set_names[3];
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040084extern struct kobj_type space_info_ktype;
85extern struct kobj_type btrfs_raid_ktype;
Anand Jaine3bd6972015-08-14 18:32:48 +080086int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain0d393762014-06-03 11:36:01 +080087 struct btrfs_device *one_device);
Anand Jain32576042015-08-14 18:32:49 +080088int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain99994cd2014-06-03 11:36:00 +080089 struct btrfs_device *one_device);
Anand Jain0c10e2d2015-03-10 06:38:35 +080090int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
91 struct kobject *parent);
Anand Jainef1a0da2015-03-10 06:38:36 +080092int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
Anand Jain1d1c1be2015-03-10 06:38:37 +080093void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
David Sterba444e7512016-01-21 18:50:40 +010094void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
95 u64 bit, enum btrfs_feature_set set);
96
Jeff Mahoney079b72b2013-11-01 13:06:57 -040097#endif /* _BTRFS_SYSFS_H_ */