blob: 611e103c174b5022aab807c7c102fef39e849282 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Sterba9888c342018-04-03 19:16:55 +02002
3#ifndef BTRFS_SYSFS_H
4#define BTRFS_SYSFS_H
Jeff Mahoney079b72b2013-11-01 13:06:57 -04005
David Sterba67715b22019-08-01 19:46:20 +02006#include <linux/kobject.h>
7
Jeff Mahoney079b72b2013-11-01 13:06:57 -04008enum btrfs_feature_set {
David Sterbabbe339c2018-11-27 15:25:13 +01009 FEAT_COMPAT,
Jeff Mahoney079b72b2013-11-01 13:06:57 -040010 FEAT_COMPAT_RO,
11 FEAT_INCOMPAT,
12 FEAT_MAX
13};
14
15#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
16{ \
17 .attr = { .name = __stringify(_name), .mode = _mode }, \
18 .show = _show, \
19 .store = _store, \
20}
21
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020022#define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \
23 static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080024 __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
Anand Jain98b3d382014-07-30 20:04:08 +080025
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020026#define BTRFS_ATTR(_prefix, _name, _show) \
27 static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080028 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080029
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020030#define BTRFS_ATTR_PTR(_prefix, _name) \
31 (&btrfs_attr_##_prefix##_##_name.attr)
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040032
33
Jeff Mahoney079b72b2013-11-01 13:06:57 -040034struct btrfs_feature_attr {
35 struct kobj_attribute kobj_attr;
36 enum btrfs_feature_set feature_set;
37 u64 feature_bit;
38};
39
David Sterba89439102019-08-01 17:34:41 +020040/* For raid type sysfs entries */
41struct raid_kobject {
42 u64 flags;
43 struct kobject kobj;
44};
45
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020046#define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit) \
47static struct btrfs_feature_attr btrfs_attr_features_##_name = { \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040048 .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, \
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020052 .feature_bit = _feature_prefix ##_## _feature_bit, \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040053}
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020054#define BTRFS_FEAT_ATTR_PTR(_name) \
55 (&btrfs_attr_features_##_name.kobj_attr.attr)
Jeff Mahoney079b72b2013-11-01 13:06:57 -040056
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);
David Sterbaf10152b2019-08-01 19:07:55 +020083const char * const btrfs_feature_set_name(enum btrfs_feature_set set);
Anand Jaine3bd6972015-08-14 18:32:48 +080084int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain0d393762014-06-03 11:36:01 +080085 struct btrfs_device *one_device);
Anand Jain32576042015-08-14 18:32:49 +080086int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain99994cd2014-06-03 11:36:00 +080087 struct btrfs_device *one_device);
Anand Jain0c10e2d2015-03-10 06:38:35 +080088int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
89 struct kobject *parent);
Anand Jainef1a0da2015-03-10 06:38:36 +080090int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
Anand Jain1d1c1be2015-03-10 06:38:37 +080091void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
David Sterbaf93c3992019-08-01 18:50:16 +020092void btrfs_sysfs_update_sprout_fsid(struct btrfs_fs_devices *fs_devices,
93 const u8 *fsid);
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);
David Sterba5b286922019-08-01 18:50:16 +020096void btrfs_kobject_uevent(struct block_device *bdev, enum kobject_action action);
David Sterba444e7512016-01-21 18:50:40 +010097
David Sterba89439102019-08-01 17:34:41 +020098int __init btrfs_init_sysfs(void);
99void __cold btrfs_exit_sysfs(void);
100int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info);
101void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info);
David Sterba32a99912019-08-01 17:49:55 +0200102void btrfs_sysfs_add_block_group_type(struct btrfs_block_group_cache *cache);
David Sterbab8823272019-08-01 18:50:16 +0200103int btrfs_sysfs_add_space_info_type(struct btrfs_fs_info *fs_info,
104 struct btrfs_space_info *space_info);
David Sterbab5865ba2019-08-01 18:50:16 +0200105void btrfs_sysfs_remove_space_info(struct btrfs_space_info *space_info);
David Sterba89439102019-08-01 17:34:41 +0200106
David Sterba9888c342018-04-03 19:16:55 +0200107#endif