blob: 648cedf9c06ec75c3e783d0d5e6f5b91ae1891d9 [file] [log] [blame]
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -07001/*
2 * sysfs.h - sysfs support declarations.
3 *
4 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
5 * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
18 */
19
20#ifndef _NILFS_SYSFS_H
21#define _NILFS_SYSFS_H
22
23#include <linux/sysfs.h>
24
25#define NILFS_ROOT_GROUP_NAME "nilfs2"
26
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -070027/*
28 * struct nilfs_sysfs_dev_subgroups - device subgroup kernel objects
29 * @sg_superblock_kobj: /sys/fs/<nilfs>/<device>/superblock
30 * @sg_superblock_kobj_unregister: completion state
Vyacheslav Dubeykoabc968d2014-08-08 14:20:44 -070031 * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor
32 * @sg_segctor_kobj_unregister: completion state
Vyacheslav Dubeykoa2ecb792014-08-08 14:20:50 -070033 * @sg_mounted_snapshots_kobj: /sys/fs/<nilfs>/<device>/mounted_snapshots
34 * @sg_mounted_snapshots_kobj_unregister: completion state
Vyacheslav Dubeyko02a0ba12014-08-08 14:20:48 -070035 * @sg_checkpoints_kobj: /sys/fs/<nilfs>/<device>/checkpoints
36 * @sg_checkpoints_kobj_unregister: completion state
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -070037 * @sg_segments_kobj: /sys/fs/<nilfs>/<device>/segments
38 * @sg_segments_kobj_unregister: completion state
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -070039 */
40struct nilfs_sysfs_dev_subgroups {
41 /* /sys/fs/<nilfs>/<device>/superblock */
42 struct kobject sg_superblock_kobj;
43 struct completion sg_superblock_kobj_unregister;
Vyacheslav Dubeykoabc968d2014-08-08 14:20:44 -070044
45 /* /sys/fs/<nilfs>/<device>/segctor */
46 struct kobject sg_segctor_kobj;
47 struct completion sg_segctor_kobj_unregister;
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -070048
Vyacheslav Dubeykoa2ecb792014-08-08 14:20:50 -070049 /* /sys/fs/<nilfs>/<device>/mounted_snapshots */
50 struct kobject sg_mounted_snapshots_kobj;
51 struct completion sg_mounted_snapshots_kobj_unregister;
52
Vyacheslav Dubeyko02a0ba12014-08-08 14:20:48 -070053 /* /sys/fs/<nilfs>/<device>/checkpoints */
54 struct kobject sg_checkpoints_kobj;
55 struct completion sg_checkpoints_kobj_unregister;
56
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -070057 /* /sys/fs/<nilfs>/<device>/segments */
58 struct kobject sg_segments_kobj;
59 struct completion sg_segments_kobj_unregister;
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -070060};
61
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -070062#define NILFS_COMMON_ATTR_STRUCT(name) \
63struct nilfs_##name##_attr { \
64 struct attribute attr; \
65 ssize_t (*show)(struct kobject *, struct attribute *, \
66 char *); \
67 ssize_t (*store)(struct kobject *, struct attribute *, \
68 const char *, size_t); \
Ryusuke Konishifacb9ec2016-05-23 16:23:28 -070069}
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -070070
71NILFS_COMMON_ATTR_STRUCT(feature);
72
Vyacheslav Dubeykoda7141f2014-08-08 14:20:39 -070073#define NILFS_DEV_ATTR_STRUCT(name) \
74struct nilfs_##name##_attr { \
75 struct attribute attr; \
76 ssize_t (*show)(struct nilfs_##name##_attr *, struct the_nilfs *, \
77 char *); \
78 ssize_t (*store)(struct nilfs_##name##_attr *, struct the_nilfs *, \
79 const char *, size_t); \
Ryusuke Konishifacb9ec2016-05-23 16:23:28 -070080}
Vyacheslav Dubeykoda7141f2014-08-08 14:20:39 -070081
82NILFS_DEV_ATTR_STRUCT(dev);
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -070083NILFS_DEV_ATTR_STRUCT(segments);
Vyacheslav Dubeykoa2ecb792014-08-08 14:20:50 -070084NILFS_DEV_ATTR_STRUCT(mounted_snapshots);
Vyacheslav Dubeyko02a0ba12014-08-08 14:20:48 -070085NILFS_DEV_ATTR_STRUCT(checkpoints);
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -070086NILFS_DEV_ATTR_STRUCT(superblock);
Vyacheslav Dubeykoabc968d2014-08-08 14:20:44 -070087NILFS_DEV_ATTR_STRUCT(segctor);
Vyacheslav Dubeykoda7141f2014-08-08 14:20:39 -070088
Vyacheslav Dubeykoa5a73322014-08-08 14:20:52 -070089#define NILFS_CP_ATTR_STRUCT(name) \
90struct nilfs_##name##_attr { \
91 struct attribute attr; \
92 ssize_t (*show)(struct nilfs_##name##_attr *, struct nilfs_root *, \
93 char *); \
94 ssize_t (*store)(struct nilfs_##name##_attr *, struct nilfs_root *, \
95 const char *, size_t); \
Ryusuke Konishifacb9ec2016-05-23 16:23:28 -070096}
Vyacheslav Dubeykoa5a73322014-08-08 14:20:52 -070097
98NILFS_CP_ATTR_STRUCT(snapshot);
99
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -0700100#define NILFS_ATTR(type, name, mode, show, store) \
101 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
102 __ATTR(name, mode, show, store)
103
104#define NILFS_INFO_ATTR(type, name) \
105 NILFS_ATTR(type, name, 0444, NULL, NULL)
106#define NILFS_RO_ATTR(type, name) \
107 NILFS_ATTR(type, name, 0444, nilfs_##type##_##name##_show, NULL)
108#define NILFS_RW_ATTR(type, name) \
109 NILFS_ATTR(type, name, 0644, \
110 nilfs_##type##_##name##_show, \
111 nilfs_##type##_##name##_store)
112
113#define NILFS_FEATURE_INFO_ATTR(name) \
114 NILFS_INFO_ATTR(feature, name)
115#define NILFS_FEATURE_RO_ATTR(name) \
116 NILFS_RO_ATTR(feature, name)
117#define NILFS_FEATURE_RW_ATTR(name) \
118 NILFS_RW_ATTR(feature, name)
119
Vyacheslav Dubeykoda7141f2014-08-08 14:20:39 -0700120#define NILFS_DEV_INFO_ATTR(name) \
121 NILFS_INFO_ATTR(dev, name)
122#define NILFS_DEV_RO_ATTR(name) \
123 NILFS_RO_ATTR(dev, name)
124#define NILFS_DEV_RW_ATTR(name) \
125 NILFS_RW_ATTR(dev, name)
126
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -0700127#define NILFS_SEGMENTS_RO_ATTR(name) \
128 NILFS_RO_ATTR(segments, name)
129#define NILFS_SEGMENTS_RW_ATTR(name) \
130 NILFS_RW_ATTR(segs_info, name)
131
Vyacheslav Dubeykoa2ecb792014-08-08 14:20:50 -0700132#define NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(name) \
133 NILFS_RO_ATTR(mounted_snapshots, name)
134
Vyacheslav Dubeyko02a0ba12014-08-08 14:20:48 -0700135#define NILFS_CHECKPOINTS_RO_ATTR(name) \
136 NILFS_RO_ATTR(checkpoints, name)
137#define NILFS_CHECKPOINTS_RW_ATTR(name) \
138 NILFS_RW_ATTR(checkpoints, name)
139
Vyacheslav Dubeykoa5a73322014-08-08 14:20:52 -0700140#define NILFS_SNAPSHOT_INFO_ATTR(name) \
141 NILFS_INFO_ATTR(snapshot, name)
142#define NILFS_SNAPSHOT_RO_ATTR(name) \
143 NILFS_RO_ATTR(snapshot, name)
144#define NILFS_SNAPSHOT_RW_ATTR(name) \
145 NILFS_RW_ATTR(snapshot, name)
146
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -0700147#define NILFS_SUPERBLOCK_RO_ATTR(name) \
148 NILFS_RO_ATTR(superblock, name)
149#define NILFS_SUPERBLOCK_RW_ATTR(name) \
150 NILFS_RW_ATTR(superblock, name)
151
Vyacheslav Dubeykoabc968d2014-08-08 14:20:44 -0700152#define NILFS_SEGCTOR_INFO_ATTR(name) \
153 NILFS_INFO_ATTR(segctor, name)
154#define NILFS_SEGCTOR_RO_ATTR(name) \
155 NILFS_RO_ATTR(segctor, name)
156#define NILFS_SEGCTOR_RW_ATTR(name) \
157 NILFS_RW_ATTR(segctor, name)
158
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -0700159#define NILFS_FEATURE_ATTR_LIST(name) \
160 (&nilfs_feature_attr_##name.attr)
Vyacheslav Dubeykoda7141f2014-08-08 14:20:39 -0700161#define NILFS_DEV_ATTR_LIST(name) \
162 (&nilfs_dev_attr_##name.attr)
Vyacheslav Dubeykoef43d5c2014-08-08 14:20:46 -0700163#define NILFS_SEGMENTS_ATTR_LIST(name) \
164 (&nilfs_segments_attr_##name.attr)
Vyacheslav Dubeykoa2ecb792014-08-08 14:20:50 -0700165#define NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(name) \
166 (&nilfs_mounted_snapshots_attr_##name.attr)
Vyacheslav Dubeyko02a0ba12014-08-08 14:20:48 -0700167#define NILFS_CHECKPOINTS_ATTR_LIST(name) \
168 (&nilfs_checkpoints_attr_##name.attr)
Vyacheslav Dubeykoa5a73322014-08-08 14:20:52 -0700169#define NILFS_SNAPSHOT_ATTR_LIST(name) \
170 (&nilfs_snapshot_attr_##name.attr)
Vyacheslav Dubeykocaa05d42014-08-08 14:20:42 -0700171#define NILFS_SUPERBLOCK_ATTR_LIST(name) \
172 (&nilfs_superblock_attr_##name.attr)
Vyacheslav Dubeykoabc968d2014-08-08 14:20:44 -0700173#define NILFS_SEGCTOR_ATTR_LIST(name) \
174 (&nilfs_segctor_attr_##name.attr)
Vyacheslav Dubeykoaebe17f2014-08-08 14:20:37 -0700175
176#endif /* _NILFS_SYSFS_H */