Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 2 | |
| 3 | #ifndef BTRFS_SYSFS_H |
| 4 | #define BTRFS_SYSFS_H |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 5 | |
| 6 | enum btrfs_feature_set { |
David Sterba | bbe339c | 2018-11-27 15:25:13 +0100 | [diff] [blame] | 7 | FEAT_COMPAT, |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 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 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 20 | #define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \ |
| 21 | static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ |
Anand Jain | 20ee082 | 2014-07-30 20:04:09 +0800 | [diff] [blame] | 22 | __INIT_KOBJ_ATTR(_name, 0644, _show, _store) |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 23 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 24 | #define BTRFS_ATTR(_prefix, _name, _show) \ |
| 25 | static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \ |
Anand Jain | 20ee082 | 2014-07-30 20:04:09 +0800 | [diff] [blame] | 26 | __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) |
Anand Jain | 98b3d38 | 2014-07-30 20:04:08 +0800 | [diff] [blame] | 27 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 28 | #define BTRFS_ATTR_PTR(_prefix, _name) \ |
| 29 | (&btrfs_attr_##_prefix##_##_name.attr) |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 30 | |
| 31 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 32 | struct btrfs_feature_attr { |
| 33 | struct kobj_attribute kobj_attr; |
| 34 | enum btrfs_feature_set feature_set; |
| 35 | u64 feature_bit; |
| 36 | }; |
| 37 | |
David Sterba | 8943910 | 2019-08-01 17:34:41 +0200 | [diff] [blame] | 38 | /* For raid type sysfs entries */ |
| 39 | struct raid_kobject { |
| 40 | u64 flags; |
| 41 | struct kobject kobj; |
| 42 | }; |
| 43 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 44 | #define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit) \ |
| 45 | static struct btrfs_feature_attr btrfs_attr_features_##_name = { \ |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 46 | .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \ |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 47 | btrfs_feature_attr_show, \ |
| 48 | btrfs_feature_attr_store), \ |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 49 | .feature_set = _feature_set, \ |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 50 | .feature_bit = _feature_prefix ##_## _feature_bit, \ |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 51 | } |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 52 | #define BTRFS_FEAT_ATTR_PTR(_name) \ |
| 53 | (&btrfs_attr_features_##_name.kobj_attr.attr) |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 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) \ |
David Sterba | ba2d084 | 2016-01-20 19:07:04 +0100 | [diff] [blame] | 58 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature) |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 59 | #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \ |
| 60 | BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) |
| 61 | |
| 62 | /* convert from attribute */ |
David Sterba | 093adbc | 2015-02-24 19:40:41 +0100 | [diff] [blame] | 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 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 80 | char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags); |
David Sterba | f10152b | 2019-08-01 19:07:55 +0200 | [diff] [blame] | 81 | const char * const btrfs_feature_set_name(enum btrfs_feature_set set); |
Anand Jain | e3bd697 | 2015-08-14 18:32:48 +0800 | [diff] [blame] | 82 | int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 0d39376 | 2014-06-03 11:36:01 +0800 | [diff] [blame] | 83 | struct btrfs_device *one_device); |
Anand Jain | 3257604 | 2015-08-14 18:32:49 +0800 | [diff] [blame] | 84 | int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 85 | struct btrfs_device *one_device); |
Anand Jain | 0c10e2d | 2015-03-10 06:38:35 +0800 | [diff] [blame] | 86 | int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs, |
| 87 | struct kobject *parent); |
Anand Jain | ef1a0da | 2015-03-10 06:38:36 +0800 | [diff] [blame] | 88 | int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs); |
Anand Jain | 1d1c1be | 2015-03-10 06:38:37 +0800 | [diff] [blame] | 89 | void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs); |
David Sterba | 444e751 | 2016-01-21 18:50:40 +0100 | [diff] [blame] | 90 | void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info, |
| 91 | u64 bit, enum btrfs_feature_set set); |
David Sterba | 5b28692 | 2019-08-01 18:50:16 +0200 | [diff] [blame] | 92 | void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action); |
David Sterba | 444e751 | 2016-01-21 18:50:40 +0100 | [diff] [blame] | 93 | |
David Sterba | 8943910 | 2019-08-01 17:34:41 +0200 | [diff] [blame] | 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); |
David Sterba | 32a9991 | 2019-08-01 17:49:55 +0200 | [diff] [blame] | 98 | void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache); |
David Sterba | b882327 | 2019-08-01 18:50:16 +0200 | [diff] [blame] | 99 | int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info, |
| 100 | struct btrfs_space_info *space_info); |
David Sterba | b5865ba | 2019-08-01 18:50:16 +0200 | [diff] [blame^] | 101 | void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info); |
David Sterba | 8943910 | 2019-08-01 17:34:41 +0200 | [diff] [blame] | 102 | |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 103 | #endif |