blob: 40716b357c1d516193958479ea28702b0014003b [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 Sterba1bae3092014-02-05 15:36:18 +01006/*
7 * Data exported through sysfs
8 */
9extern u64 btrfs_debugfs_test;
10
Jeff Mahoney079b72b2013-11-01 13:06:57 -040011enum btrfs_feature_set {
David Sterbabbe339c2018-11-27 15:25:13 +010012 FEAT_COMPAT,
Jeff Mahoney079b72b2013-11-01 13:06:57 -040013 FEAT_COMPAT_RO,
14 FEAT_INCOMPAT,
15 FEAT_MAX
16};
17
18#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
19{ \
20 .attr = { .name = __stringify(_name), .mode = _mode }, \
21 .show = _show, \
22 .store = _store, \
23}
24
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020025#define BTRFS_ATTR_RW(_prefix, _name, _show, _store) \
26 static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080027 __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
Anand Jain98b3d382014-07-30 20:04:08 +080028
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020029#define BTRFS_ATTR(_prefix, _name, _show) \
30 static struct kobj_attribute btrfs_attr_##_prefix##_##_name = \
Anand Jain20ee0822014-07-30 20:04:09 +080031 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
Anand Jain98b3d382014-07-30 20:04:08 +080032
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020033#define BTRFS_ATTR_PTR(_prefix, _name) \
34 (&btrfs_attr_##_prefix##_##_name.attr)
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040035
36
Jeff Mahoney079b72b2013-11-01 13:06:57 -040037struct btrfs_feature_attr {
38 struct kobj_attribute kobj_attr;
39 enum btrfs_feature_set feature_set;
40 u64 feature_bit;
41};
42
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020043#define BTRFS_FEAT_ATTR(_name, _feature_set, _feature_prefix, _feature_bit) \
44static struct btrfs_feature_attr btrfs_attr_features_##_name = { \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040045 .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
Jeff Mahoneyba631942013-11-01 13:07:01 -040046 btrfs_feature_attr_show, \
47 btrfs_feature_attr_store), \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040048 .feature_set = _feature_set, \
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020049 .feature_bit = _feature_prefix ##_## _feature_bit, \
Jeff Mahoney079b72b2013-11-01 13:06:57 -040050}
Hans van Kranenburga969f4c2017-10-08 22:30:58 +020051#define BTRFS_FEAT_ATTR_PTR(_name) \
52 (&btrfs_attr_features_##_name.kobj_attr.attr)
Jeff Mahoney079b72b2013-11-01 13:06:57 -040053
54#define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
55 BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
56#define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
David Sterbaba2d0842016-01-20 19:07:04 +010057 BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
Jeff Mahoney079b72b2013-11-01 13:06:57 -040058#define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
59 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
60
61/* convert from attribute */
David Sterba093adbc2015-02-24 19:40:41 +010062static inline struct btrfs_feature_attr *
63to_btrfs_feature_attr(struct kobj_attribute *a)
64{
65 return container_of(a, struct btrfs_feature_attr, kobj_attr);
66}
67
68static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
69{
70 return container_of(attr, struct kobj_attribute, attr);
71}
72
73static inline struct btrfs_feature_attr *
74attr_to_btrfs_feature_attr(struct attribute *attr)
75{
76 return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
77}
78
Jeff Mahoney3b02a682013-11-01 13:07:02 -040079char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
Tomohiro Misono6c521572018-05-16 17:09:26 +090080extern const char * const btrfs_feature_set_names[FEAT_MAX];
Jeff Mahoney6ab0a202013-11-01 13:07:04 -040081extern struct kobj_type space_info_ktype;
82extern struct kobj_type btrfs_raid_ktype;
Anand Jaine3bd6972015-08-14 18:32:48 +080083int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain0d393762014-06-03 11:36:01 +080084 struct btrfs_device *one_device);
Anand Jain32576042015-08-14 18:32:49 +080085int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
Anand Jain99994cd2014-06-03 11:36:00 +080086 struct btrfs_device *one_device);
Anand Jain0c10e2d2015-03-10 06:38:35 +080087int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
88 struct kobject *parent);
Anand Jainef1a0da2015-03-10 06:38:36 +080089int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
Anand Jain1d1c1be2015-03-10 06:38:37 +080090void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
David Sterba444e7512016-01-21 18:50:40 +010091void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
92 u64 bit, enum btrfs_feature_set set);
93
David Sterba9888c342018-04-03 19:16:55 +020094#endif