Ryusuke Konishi | ae98043 | 2018-09-04 15:46:30 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 2 | /* |
| 3 | * sysfs.h - 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 | * |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 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 |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 22 | * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor |
| 23 | * @sg_segctor_kobj_unregister: completion state |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 24 | * @sg_mounted_snapshots_kobj: /sys/fs/<nilfs>/<device>/mounted_snapshots |
| 25 | * @sg_mounted_snapshots_kobj_unregister: completion state |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 26 | * @sg_checkpoints_kobj: /sys/fs/<nilfs>/<device>/checkpoints |
| 27 | * @sg_checkpoints_kobj_unregister: completion state |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 28 | * @sg_segments_kobj: /sys/fs/<nilfs>/<device>/segments |
| 29 | * @sg_segments_kobj_unregister: completion state |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 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; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 35 | |
| 36 | /* /sys/fs/<nilfs>/<device>/segctor */ |
| 37 | struct kobject sg_segctor_kobj; |
| 38 | struct completion sg_segctor_kobj_unregister; |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 39 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 40 | /* /sys/fs/<nilfs>/<device>/mounted_snapshots */ |
| 41 | struct kobject sg_mounted_snapshots_kobj; |
| 42 | struct completion sg_mounted_snapshots_kobj_unregister; |
| 43 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 44 | /* /sys/fs/<nilfs>/<device>/checkpoints */ |
| 45 | struct kobject sg_checkpoints_kobj; |
| 46 | struct completion sg_checkpoints_kobj_unregister; |
| 47 | |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 48 | /* /sys/fs/<nilfs>/<device>/segments */ |
| 49 | struct kobject sg_segments_kobj; |
| 50 | struct completion sg_segments_kobj_unregister; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 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); \ |
Ryusuke Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 60 | } |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 61 | |
| 62 | NILFS_COMMON_ATTR_STRUCT(feature); |
| 63 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 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); \ |
Ryusuke Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 71 | } |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 72 | |
| 73 | NILFS_DEV_ATTR_STRUCT(dev); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 74 | NILFS_DEV_ATTR_STRUCT(segments); |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 75 | NILFS_DEV_ATTR_STRUCT(mounted_snapshots); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 76 | NILFS_DEV_ATTR_STRUCT(checkpoints); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 77 | NILFS_DEV_ATTR_STRUCT(superblock); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 78 | NILFS_DEV_ATTR_STRUCT(segctor); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 79 | |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 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); \ |
Ryusuke Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 87 | } |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 88 | |
| 89 | NILFS_CP_ATTR_STRUCT(snapshot); |
| 90 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 123 | #define NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(name) \ |
| 124 | NILFS_RO_ATTR(mounted_snapshots, name) |
| 125 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 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 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 150 | #define NILFS_FEATURE_ATTR_LIST(name) \ |
| 151 | (&nilfs_feature_attr_##name.attr) |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 152 | #define NILFS_DEV_ATTR_LIST(name) \ |
| 153 | (&nilfs_dev_attr_##name.attr) |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 154 | #define NILFS_SEGMENTS_ATTR_LIST(name) \ |
| 155 | (&nilfs_segments_attr_##name.attr) |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 156 | #define NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(name) \ |
| 157 | (&nilfs_mounted_snapshots_attr_##name.attr) |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 158 | #define NILFS_CHECKPOINTS_ATTR_LIST(name) \ |
| 159 | (&nilfs_checkpoints_attr_##name.attr) |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 160 | #define NILFS_SNAPSHOT_ATTR_LIST(name) \ |
| 161 | (&nilfs_snapshot_attr_##name.attr) |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 162 | #define NILFS_SUPERBLOCK_ATTR_LIST(name) \ |
| 163 | (&nilfs_superblock_attr_##name.attr) |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 164 | #define NILFS_SEGCTOR_ATTR_LIST(name) \ |
| 165 | (&nilfs_segctor_attr_##name.attr) |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 166 | |
| 167 | #endif /* _NILFS_SYSFS_H */ |