xref: /linux/fs/nilfs2/sysfs.h (revision 3f0a50f345f78183f6e9b39c2f45ca5dcaa511ca)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Sysfs support declarations.
4  *
5  * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
6  * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
7  *
8  * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
9  */
10 
11 #ifndef _NILFS_SYSFS_H
12 #define _NILFS_SYSFS_H
13 
14 #include <linux/sysfs.h>
15 
16 #define NILFS_ROOT_GROUP_NAME	"nilfs2"
17 
18 /*
19  * struct nilfs_sysfs_dev_subgroups - device subgroup kernel objects
20  * @sg_superblock_kobj: /sys/fs/<nilfs>/<device>/superblock
21  * @sg_superblock_kobj_unregister: completion state
22  * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor
23  * @sg_segctor_kobj_unregister: completion state
24  * @sg_mounted_snapshots_kobj: /sys/fs/<nilfs>/<device>/mounted_snapshots
25  * @sg_mounted_snapshots_kobj_unregister: completion state
26  * @sg_checkpoints_kobj: /sys/fs/<nilfs>/<device>/checkpoints
27  * @sg_checkpoints_kobj_unregister: completion state
28  * @sg_segments_kobj: /sys/fs/<nilfs>/<device>/segments
29  * @sg_segments_kobj_unregister: completion state
30  */
31 struct nilfs_sysfs_dev_subgroups {
32 	/* /sys/fs/<nilfs>/<device>/superblock */
33 	struct kobject sg_superblock_kobj;
34 	struct completion sg_superblock_kobj_unregister;
35 
36 	/* /sys/fs/<nilfs>/<device>/segctor */
37 	struct kobject sg_segctor_kobj;
38 	struct completion sg_segctor_kobj_unregister;
39 
40 	/* /sys/fs/<nilfs>/<device>/mounted_snapshots */
41 	struct kobject sg_mounted_snapshots_kobj;
42 	struct completion sg_mounted_snapshots_kobj_unregister;
43 
44 	/* /sys/fs/<nilfs>/<device>/checkpoints */
45 	struct kobject sg_checkpoints_kobj;
46 	struct completion sg_checkpoints_kobj_unregister;
47 
48 	/* /sys/fs/<nilfs>/<device>/segments */
49 	struct kobject sg_segments_kobj;
50 	struct completion sg_segments_kobj_unregister;
51 };
52 
53 #define NILFS_COMMON_ATTR_STRUCT(name) \
54 struct nilfs_##name##_attr { \
55 	struct attribute attr; \
56 	ssize_t (*show)(struct kobject *, struct attribute *, \
57 			char *); \
58 	ssize_t (*store)(struct kobject *, struct attribute *, \
59 			 const char *, size_t); \
60 }
61 
62 NILFS_COMMON_ATTR_STRUCT(feature);
63 
64 #define NILFS_DEV_ATTR_STRUCT(name) \
65 struct nilfs_##name##_attr { \
66 	struct attribute attr; \
67 	ssize_t (*show)(struct nilfs_##name##_attr *, struct the_nilfs *, \
68 			char *); \
69 	ssize_t (*store)(struct nilfs_##name##_attr *, struct the_nilfs *, \
70 			 const char *, size_t); \
71 }
72 
73 NILFS_DEV_ATTR_STRUCT(dev);
74 NILFS_DEV_ATTR_STRUCT(segments);
75 NILFS_DEV_ATTR_STRUCT(mounted_snapshots);
76 NILFS_DEV_ATTR_STRUCT(checkpoints);
77 NILFS_DEV_ATTR_STRUCT(superblock);
78 NILFS_DEV_ATTR_STRUCT(segctor);
79 
80 #define NILFS_CP_ATTR_STRUCT(name) \
81 struct nilfs_##name##_attr { \
82 	struct attribute attr; \
83 	ssize_t (*show)(struct nilfs_##name##_attr *, struct nilfs_root *, \
84 			char *); \
85 	ssize_t (*store)(struct nilfs_##name##_attr *, struct nilfs_root *, \
86 			 const char *, size_t); \
87 }
88 
89 NILFS_CP_ATTR_STRUCT(snapshot);
90 
91 #define NILFS_ATTR(type, name, mode, show, store) \
92 	static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
93 		__ATTR(name, mode, show, store)
94 
95 #define NILFS_INFO_ATTR(type, name) \
96 	NILFS_ATTR(type, name, 0444, NULL, NULL)
97 #define NILFS_RO_ATTR(type, name) \
98 	NILFS_ATTR(type, name, 0444, nilfs_##type##_##name##_show, NULL)
99 #define NILFS_RW_ATTR(type, name) \
100 	NILFS_ATTR(type, name, 0644, \
101 		    nilfs_##type##_##name##_show, \
102 		    nilfs_##type##_##name##_store)
103 
104 #define NILFS_FEATURE_INFO_ATTR(name) \
105 	NILFS_INFO_ATTR(feature, name)
106 #define NILFS_FEATURE_RO_ATTR(name) \
107 	NILFS_RO_ATTR(feature, name)
108 #define NILFS_FEATURE_RW_ATTR(name) \
109 	NILFS_RW_ATTR(feature, name)
110 
111 #define NILFS_DEV_INFO_ATTR(name) \
112 	NILFS_INFO_ATTR(dev, name)
113 #define NILFS_DEV_RO_ATTR(name) \
114 	NILFS_RO_ATTR(dev, name)
115 #define NILFS_DEV_RW_ATTR(name) \
116 	NILFS_RW_ATTR(dev, name)
117 
118 #define NILFS_SEGMENTS_RO_ATTR(name) \
119 	NILFS_RO_ATTR(segments, name)
120 #define NILFS_SEGMENTS_RW_ATTR(name) \
121 	NILFS_RW_ATTR(segs_info, name)
122 
123 #define NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(name) \
124 	NILFS_RO_ATTR(mounted_snapshots, name)
125 
126 #define NILFS_CHECKPOINTS_RO_ATTR(name) \
127 	NILFS_RO_ATTR(checkpoints, name)
128 #define NILFS_CHECKPOINTS_RW_ATTR(name) \
129 	NILFS_RW_ATTR(checkpoints, name)
130 
131 #define NILFS_SNAPSHOT_INFO_ATTR(name) \
132 	NILFS_INFO_ATTR(snapshot, name)
133 #define NILFS_SNAPSHOT_RO_ATTR(name) \
134 	NILFS_RO_ATTR(snapshot, name)
135 #define NILFS_SNAPSHOT_RW_ATTR(name) \
136 	NILFS_RW_ATTR(snapshot, name)
137 
138 #define NILFS_SUPERBLOCK_RO_ATTR(name) \
139 	NILFS_RO_ATTR(superblock, name)
140 #define NILFS_SUPERBLOCK_RW_ATTR(name) \
141 	NILFS_RW_ATTR(superblock, name)
142 
143 #define NILFS_SEGCTOR_INFO_ATTR(name) \
144 	NILFS_INFO_ATTR(segctor, name)
145 #define NILFS_SEGCTOR_RO_ATTR(name) \
146 	NILFS_RO_ATTR(segctor, name)
147 #define NILFS_SEGCTOR_RW_ATTR(name) \
148 	NILFS_RW_ATTR(segctor, name)
149 
150 #define NILFS_FEATURE_ATTR_LIST(name) \
151 	(&nilfs_feature_attr_##name.attr)
152 #define NILFS_DEV_ATTR_LIST(name) \
153 	(&nilfs_dev_attr_##name.attr)
154 #define NILFS_SEGMENTS_ATTR_LIST(name) \
155 	(&nilfs_segments_attr_##name.attr)
156 #define NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(name) \
157 	(&nilfs_mounted_snapshots_attr_##name.attr)
158 #define NILFS_CHECKPOINTS_ATTR_LIST(name) \
159 	(&nilfs_checkpoints_attr_##name.attr)
160 #define NILFS_SNAPSHOT_ATTR_LIST(name) \
161 	(&nilfs_snapshot_attr_##name.attr)
162 #define NILFS_SUPERBLOCK_ATTR_LIST(name) \
163 	(&nilfs_superblock_attr_##name.attr)
164 #define NILFS_SEGCTOR_ATTR_LIST(name) \
165 	(&nilfs_segctor_attr_##name.attr)
166 
167 #endif /* _NILFS_SYSFS_H */
168