Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 1 | #ifndef _BTRFS_SYSFS_H_ |
| 2 | #define _BTRFS_SYSFS_H_ |
| 3 | |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 4 | /* |
| 5 | * Data exported through sysfs |
| 6 | */ |
| 7 | extern u64 btrfs_debugfs_test; |
| 8 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 9 | enum 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 Jain | 20ee082 | 2014-07-30 20:04:09 +0800 | [diff] [blame] | 23 | #define BTRFS_ATTR_RW(_name, _show, _store) \ |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 24 | static struct kobj_attribute btrfs_attr_##_name = \ |
Anand Jain | 20ee082 | 2014-07-30 20:04:09 +0800 | [diff] [blame] | 25 | __INIT_KOBJ_ATTR(_name, 0644, _show, _store) |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 26 | |
| 27 | #define BTRFS_ATTR(_name, _show) \ |
Anand Jain | 20ee082 | 2014-07-30 20:04:09 +0800 | [diff] [blame] | 28 | static struct kobj_attribute btrfs_attr_##_name = \ |
| 29 | __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 30 | |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 31 | #define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr) |
| 32 | |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 33 | #define BTRFS_RAID_ATTR(_name, _show) \ |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 34 | static struct kobj_attribute btrfs_raid_attr_##_name = \ |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 35 | __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 36 | |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 37 | #define BTRFS_RAID_ATTR_PTR(_name) (&btrfs_raid_attr_##_name.attr) |
| 38 | |
| 39 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 40 | struct 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) \ |
| 47 | static struct btrfs_feature_attr btrfs_attr_##_name = { \ |
| 48 | .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \ |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 49 | btrfs_feature_attr_show, \ |
| 50 | btrfs_feature_attr_store), \ |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 51 | .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) \ |
| 59 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT, feature) |
| 60 | #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \ |
| 61 | BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) |
| 62 | |
| 63 | /* convert from attribute */ |
David Sterba | 093adbc | 2015-02-24 19:40:41 +0100 | [diff] [blame] | 64 | static inline struct btrfs_feature_attr * |
| 65 | to_btrfs_feature_attr(struct kobj_attribute *a) |
| 66 | { |
| 67 | return container_of(a, struct btrfs_feature_attr, kobj_attr); |
| 68 | } |
| 69 | |
| 70 | static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr) |
| 71 | { |
| 72 | return container_of(attr, struct kobj_attribute, attr); |
| 73 | } |
| 74 | |
| 75 | static inline struct btrfs_feature_attr * |
| 76 | attr_to_btrfs_feature_attr(struct attribute *attr) |
| 77 | { |
| 78 | return to_btrfs_feature_attr(attr_to_btrfs_attr(attr)); |
| 79 | } |
| 80 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 81 | char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); |
| 82 | extern const char * const btrfs_feature_set_names[3]; |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 83 | extern struct kobj_type space_info_ktype; |
| 84 | extern struct kobj_type btrfs_raid_ktype; |
Anand Jain | 1ba4381 | 2015-03-10 06:38:33 +0800 | [diff] [blame] | 85 | int btrfs_kobj_add_device(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 0d39376 | 2014-06-03 11:36:01 +0800 | [diff] [blame] | 86 | struct btrfs_device *one_device); |
Anand Jain | 6c14a16 | 2015-03-10 06:38:34 +0800 | [diff] [blame] | 87 | int btrfs_kobj_rm_device(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 88 | struct btrfs_device *one_device); |
Anand Jain | 0c10e2d | 2015-03-10 06:38:35 +0800 | [diff] [blame] | 89 | int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs, |
| 90 | struct kobject *parent); |
Anand Jain | ef1a0da | 2015-03-10 06:38:36 +0800 | [diff] [blame] | 91 | int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs); |
Anand Jain | 1d1c1be | 2015-03-10 06:38:37 +0800 | [diff] [blame] | 92 | void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs); |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 93 | #endif /* _BTRFS_SYSFS_H_ */ |