Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1 | /* |
| 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 Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 27 | /* |
| 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 Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 31 | * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor |
| 32 | * @sg_segctor_kobj_unregister: completion state |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 33 | * @sg_mounted_snapshots_kobj: /sys/fs/<nilfs>/<device>/mounted_snapshots |
| 34 | * @sg_mounted_snapshots_kobj_unregister: completion state |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 35 | * @sg_checkpoints_kobj: /sys/fs/<nilfs>/<device>/checkpoints |
| 36 | * @sg_checkpoints_kobj_unregister: completion state |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 37 | * @sg_segments_kobj: /sys/fs/<nilfs>/<device>/segments |
| 38 | * @sg_segments_kobj_unregister: completion state |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 39 | */ |
| 40 | struct nilfs_sysfs_dev_subgroups { |
| 41 | /* /sys/fs/<nilfs>/<device>/superblock */ |
| 42 | struct kobject sg_superblock_kobj; |
| 43 | struct completion sg_superblock_kobj_unregister; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 44 | |
| 45 | /* /sys/fs/<nilfs>/<device>/segctor */ |
| 46 | struct kobject sg_segctor_kobj; |
| 47 | struct completion sg_segctor_kobj_unregister; |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 48 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 49 | /* /sys/fs/<nilfs>/<device>/mounted_snapshots */ |
| 50 | struct kobject sg_mounted_snapshots_kobj; |
| 51 | struct completion sg_mounted_snapshots_kobj_unregister; |
| 52 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 53 | /* /sys/fs/<nilfs>/<device>/checkpoints */ |
| 54 | struct kobject sg_checkpoints_kobj; |
| 55 | struct completion sg_checkpoints_kobj_unregister; |
| 56 | |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 57 | /* /sys/fs/<nilfs>/<device>/segments */ |
| 58 | struct kobject sg_segments_kobj; |
| 59 | struct completion sg_segments_kobj_unregister; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 62 | #define NILFS_COMMON_ATTR_STRUCT(name) \ |
| 63 | struct 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 Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 69 | } |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 70 | |
| 71 | NILFS_COMMON_ATTR_STRUCT(feature); |
| 72 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 73 | #define NILFS_DEV_ATTR_STRUCT(name) \ |
| 74 | struct 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 Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 80 | } |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 81 | |
| 82 | NILFS_DEV_ATTR_STRUCT(dev); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 83 | NILFS_DEV_ATTR_STRUCT(segments); |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 84 | NILFS_DEV_ATTR_STRUCT(mounted_snapshots); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 85 | NILFS_DEV_ATTR_STRUCT(checkpoints); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 86 | NILFS_DEV_ATTR_STRUCT(superblock); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 87 | NILFS_DEV_ATTR_STRUCT(segctor); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 88 | |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 89 | #define NILFS_CP_ATTR_STRUCT(name) \ |
| 90 | struct 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 Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 96 | } |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 97 | |
| 98 | NILFS_CP_ATTR_STRUCT(snapshot); |
| 99 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 100 | #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 Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 120 | #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 Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 127 | #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 Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 132 | #define NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(name) \ |
| 133 | NILFS_RO_ATTR(mounted_snapshots, name) |
| 134 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 135 | #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 Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 140 | #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 Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 147 | #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 Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 152 | #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 Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 159 | #define NILFS_FEATURE_ATTR_LIST(name) \ |
| 160 | (&nilfs_feature_attr_##name.attr) |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 161 | #define NILFS_DEV_ATTR_LIST(name) \ |
| 162 | (&nilfs_dev_attr_##name.attr) |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 163 | #define NILFS_SEGMENTS_ATTR_LIST(name) \ |
| 164 | (&nilfs_segments_attr_##name.attr) |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 165 | #define NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(name) \ |
| 166 | (&nilfs_mounted_snapshots_attr_##name.attr) |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 167 | #define NILFS_CHECKPOINTS_ATTR_LIST(name) \ |
| 168 | (&nilfs_checkpoints_attr_##name.attr) |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 169 | #define NILFS_SNAPSHOT_ATTR_LIST(name) \ |
| 170 | (&nilfs_snapshot_attr_##name.attr) |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 171 | #define NILFS_SUPERBLOCK_ATTR_LIST(name) \ |
| 172 | (&nilfs_superblock_attr_##name.attr) |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 173 | #define NILFS_SEGCTOR_ATTR_LIST(name) \ |
| 174 | (&nilfs_segctor_attr_##name.attr) |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 175 | |
| 176 | #endif /* _NILFS_SYSFS_H */ |