blob: d7da1a4c2f6c12d04a8f29e4d8f503943058d46d [file] [log] [blame]
Jeff Mahoney079b72b2013-11-01 13:06:57 -04001#ifndef _BTRFS_SYSFS_H_
2#define _BTRFS_SYSFS_H_
3
David Sterba1bae3092014-02-05 15:36:18 +01004/*
5 * Data exported through sysfs
6 */
7extern u64 btrfs_debugfs_test;
8
Jeff Mahoney079b72b2013-11-01 13:06:57 -04009enum btrfs_feature_set {
10 FEAT_COMPAT,
11 FEAT_COMPAT_RO,
12 FEAT_INCOMPAT,
13 FEAT_MAX
14};
15
16#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
17{ \
18 .attr = { .name = __stringify(_name), .mode = _mode }, \
19 .show = _show, \
20 .store = _store, \
21}
22
Anand Jain20ee0822014-07-30 20:04:09 +080023#define BTRFS_ATTR_RW(_name, _show, _store) \
Anand Jain98b3d382014-07-30 20:04:08 +080024 static struct kobj_attribute btrfs_attr_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080025 __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
Anand Jain98b3d382014-07-30 20:04:08 +080026
27#define BTRFS_ATTR(_name, _show) \
Anand Jain20ee0822014-07-30 20:04:09 +080028 static struct kobj_attribute btrfs_attr_##_name = \
29 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080030
Jeff Mahoney5ac1d202013-11-01 13:06:58 -040031#define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr)
32
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040033#define BTRFS_RAID_ATTR(_name, _show) \
Anand Jain98b3d382014-07-30 20:04:08 +080034 static struct kobj_attribute btrfs_raid_attr_##_name = \
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040035 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080036
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040037#define BTRFS_RAID_ATTR_PTR(_name) (&btrfs_raid_attr_##_name.attr)
38
39
Jeff Mahoney079b72b2013-11-01 13:06:57 -040040struct btrfs_feature_attr {
41 struct kobj_attribute kobj_attr;
42 enum btrfs_feature_set feature_set;
43 u64 feature_bit;
44};
45
46#define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \
47static struct btrfs_feature_attr btrfs_attr_##_name = { \
48 .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
Jeff Mahoneyba631942013-11-01 13:07:01 -040049 btrfs_feature_attr_show, \
50 btrfs_feature_attr_store), \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040051 .feature_set = _feature_set, \
52 .feature_bit = _prefix ##_## _feature_bit, \
53}
54#define BTRFS_FEAT_ATTR_PTR(_name) (&btrfs_attr_##_name.kobj_attr.attr)
55
56#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
57 BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
58#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
David Sterbaba2d0842016-01-20 19:07:04 +010059 BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
Jeff Mahoney079b72b2013-11-01 13:06:57 -040060#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
61 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
62
63/* convert from attribute */
David Sterba093adbc2015-02-24 19:40:41 +010064static inline struct btrfs_feature_attr *
65to_btrfs_feature_attr(struct kobj_attribute *a)
66{
67 return container_of(a, struct btrfs_feature_attr, kobj_attr);
68}
69
70static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
71{
72 return container_of(attr, struct kobj_attribute, attr);
73}
74
75static inline struct btrfs_feature_attr *
76attr_to_btrfs_feature_attr(struct attribute *attr)
77{
78 return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
79}
80
Jeff Mahoney3b02a682013-11-01 13:07:02 -040081char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
82extern const char * const btrfs_feature_set_names[3];
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040083extern struct kobj_type space_info_ktype;
84extern struct kobj_type btrfs_raid_ktype;
Anand Jaine3bd6972015-08-14 18:32:48 +080085int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain0d393762014-06-03 11:36:01 +080086 struct btrfs_device *one_device);
Anand Jain32576042015-08-14 18:32:49 +080087int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain99994cd2014-06-03 11:36:00 +080088 struct btrfs_device *one_device);
Anand Jain0c10e2d2015-03-10 06:38:35 +080089int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
90 struct kobject *parent);
Anand Jainef1a0da2015-03-10 06:38:36 +080091int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
Anand Jain1d1c1be2015-03-10 06:38:37 +080092void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
David Sterba444e7512016-01-21 18:50:40 +010093void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
94 u64 bit, enum btrfs_feature_set set);
95
Jeff Mahoney079b72b2013-11-01 13:06:57 -040096#endif /* _BTRFS_SYSFS_H_ */