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 | /* |
Ryusuke Konishi | 94ee1d9 | 2021-11-08 18:35:01 -0800 | [diff] [blame] | 3 | * Sysfs support implementation. |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 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 | #include <linux/kobject.h> |
| 12 | |
| 13 | #include "nilfs.h" |
| 14 | #include "mdt.h" |
| 15 | #include "sufile.h" |
| 16 | #include "cpfile.h" |
| 17 | #include "sysfs.h" |
| 18 | |
| 19 | /* /sys/fs/<nilfs>/ */ |
| 20 | static struct kset *nilfs_kset; |
| 21 | |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 22 | #define NILFS_DEV_INT_GROUP_OPS(name, parent_name) \ |
| 23 | static ssize_t nilfs_##name##_attr_show(struct kobject *kobj, \ |
| 24 | struct attribute *attr, char *buf) \ |
| 25 | { \ |
| 26 | struct the_nilfs *nilfs = container_of(kobj->parent, \ |
| 27 | struct the_nilfs, \ |
| 28 | ns_##parent_name##_kobj); \ |
| 29 | struct nilfs_##name##_attr *a = container_of(attr, \ |
| 30 | struct nilfs_##name##_attr, \ |
| 31 | attr); \ |
| 32 | return a->show ? a->show(a, nilfs, buf) : 0; \ |
| 33 | } \ |
| 34 | static ssize_t nilfs_##name##_attr_store(struct kobject *kobj, \ |
| 35 | struct attribute *attr, \ |
| 36 | const char *buf, size_t len) \ |
| 37 | { \ |
| 38 | struct the_nilfs *nilfs = container_of(kobj->parent, \ |
| 39 | struct the_nilfs, \ |
| 40 | ns_##parent_name##_kobj); \ |
| 41 | struct nilfs_##name##_attr *a = container_of(attr, \ |
| 42 | struct nilfs_##name##_attr, \ |
| 43 | attr); \ |
| 44 | return a->store ? a->store(a, nilfs, buf, len) : 0; \ |
| 45 | } \ |
| 46 | static const struct sysfs_ops nilfs_##name##_attr_ops = { \ |
| 47 | .show = nilfs_##name##_attr_show, \ |
| 48 | .store = nilfs_##name##_attr_store, \ |
Ryusuke Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 49 | } |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 50 | |
| 51 | #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \ |
| 52 | static void nilfs_##name##_attr_release(struct kobject *kobj) \ |
| 53 | { \ |
Nanyong Sun | dbc6e7d4 | 2021-09-07 20:00:12 -0700 | [diff] [blame] | 54 | struct nilfs_sysfs_##parent_name##_subgroups *subgroups = container_of(kobj, \ |
| 55 | struct nilfs_sysfs_##parent_name##_subgroups, \ |
| 56 | sg_##name##_kobj); \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 57 | complete(&subgroups->sg_##name##_kobj_unregister); \ |
| 58 | } \ |
| 59 | static struct kobj_type nilfs_##name##_ktype = { \ |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 60 | .default_groups = nilfs_##name##_groups, \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 61 | .sysfs_ops = &nilfs_##name##_attr_ops, \ |
| 62 | .release = nilfs_##name##_attr_release, \ |
Ryusuke Konishi | facb9ec | 2016-05-23 16:23:28 -0700 | [diff] [blame] | 63 | } |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 64 | |
| 65 | #define NILFS_DEV_INT_GROUP_FNS(name, parent_name) \ |
Vyacheslav Dubeyko | dd70edb | 2014-08-08 14:20:55 -0700 | [diff] [blame] | 66 | static int nilfs_sysfs_create_##name##_group(struct the_nilfs *nilfs) \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 67 | { \ |
| 68 | struct kobject *parent; \ |
| 69 | struct kobject *kobj; \ |
| 70 | struct completion *kobj_unregister; \ |
| 71 | struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \ |
| 72 | int err; \ |
| 73 | subgroups = nilfs->ns_##parent_name##_subgroups; \ |
| 74 | kobj = &subgroups->sg_##name##_kobj; \ |
| 75 | kobj_unregister = &subgroups->sg_##name##_kobj_unregister; \ |
| 76 | parent = &nilfs->ns_##parent_name##_kobj; \ |
| 77 | kobj->kset = nilfs_kset; \ |
| 78 | init_completion(kobj_unregister); \ |
| 79 | err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \ |
| 80 | #name); \ |
| 81 | if (err) \ |
Nanyong Sun | 24f8cb1 | 2021-09-07 20:00:15 -0700 | [diff] [blame] | 82 | kobject_put(kobj); \ |
| 83 | return err; \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 84 | } \ |
Vyacheslav Dubeyko | dd70edb | 2014-08-08 14:20:55 -0700 | [diff] [blame] | 85 | static void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 86 | { \ |
Nanyong Sun | a3e1812 | 2021-09-07 20:00:18 -0700 | [diff] [blame] | 87 | kobject_put(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /************************************************************************ |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 91 | * NILFS snapshot attrs * |
| 92 | ************************************************************************/ |
| 93 | |
| 94 | static ssize_t |
| 95 | nilfs_snapshot_inodes_count_show(struct nilfs_snapshot_attr *attr, |
| 96 | struct nilfs_root *root, char *buf) |
| 97 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 98 | return sysfs_emit(buf, "%llu\n", |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 99 | (unsigned long long)atomic64_read(&root->inodes_count)); |
| 100 | } |
| 101 | |
| 102 | static ssize_t |
| 103 | nilfs_snapshot_blocks_count_show(struct nilfs_snapshot_attr *attr, |
| 104 | struct nilfs_root *root, char *buf) |
| 105 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 106 | return sysfs_emit(buf, "%llu\n", |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 107 | (unsigned long long)atomic64_read(&root->blocks_count)); |
| 108 | } |
| 109 | |
| 110 | static const char snapshot_readme_str[] = |
| 111 | "The group contains details about mounted snapshot.\n\n" |
| 112 | "(1) inodes_count\n\tshow number of inodes for snapshot.\n\n" |
| 113 | "(2) blocks_count\n\tshow number of blocks for snapshot.\n\n"; |
| 114 | |
| 115 | static ssize_t |
| 116 | nilfs_snapshot_README_show(struct nilfs_snapshot_attr *attr, |
| 117 | struct nilfs_root *root, char *buf) |
| 118 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 119 | return sysfs_emit(buf, snapshot_readme_str); |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | NILFS_SNAPSHOT_RO_ATTR(inodes_count); |
| 123 | NILFS_SNAPSHOT_RO_ATTR(blocks_count); |
| 124 | NILFS_SNAPSHOT_RO_ATTR(README); |
| 125 | |
| 126 | static struct attribute *nilfs_snapshot_attrs[] = { |
| 127 | NILFS_SNAPSHOT_ATTR_LIST(inodes_count), |
| 128 | NILFS_SNAPSHOT_ATTR_LIST(blocks_count), |
| 129 | NILFS_SNAPSHOT_ATTR_LIST(README), |
| 130 | NULL, |
| 131 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 132 | ATTRIBUTE_GROUPS(nilfs_snapshot); |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 133 | |
| 134 | static ssize_t nilfs_snapshot_attr_show(struct kobject *kobj, |
| 135 | struct attribute *attr, char *buf) |
| 136 | { |
| 137 | struct nilfs_root *root = |
| 138 | container_of(kobj, struct nilfs_root, snapshot_kobj); |
| 139 | struct nilfs_snapshot_attr *a = |
| 140 | container_of(attr, struct nilfs_snapshot_attr, attr); |
| 141 | |
| 142 | return a->show ? a->show(a, root, buf) : 0; |
| 143 | } |
| 144 | |
| 145 | static ssize_t nilfs_snapshot_attr_store(struct kobject *kobj, |
| 146 | struct attribute *attr, |
| 147 | const char *buf, size_t len) |
| 148 | { |
| 149 | struct nilfs_root *root = |
| 150 | container_of(kobj, struct nilfs_root, snapshot_kobj); |
| 151 | struct nilfs_snapshot_attr *a = |
| 152 | container_of(attr, struct nilfs_snapshot_attr, attr); |
| 153 | |
| 154 | return a->store ? a->store(a, root, buf, len) : 0; |
| 155 | } |
| 156 | |
| 157 | static void nilfs_snapshot_attr_release(struct kobject *kobj) |
| 158 | { |
| 159 | struct nilfs_root *root = container_of(kobj, struct nilfs_root, |
| 160 | snapshot_kobj); |
| 161 | complete(&root->snapshot_kobj_unregister); |
| 162 | } |
| 163 | |
| 164 | static const struct sysfs_ops nilfs_snapshot_attr_ops = { |
| 165 | .show = nilfs_snapshot_attr_show, |
| 166 | .store = nilfs_snapshot_attr_store, |
| 167 | }; |
| 168 | |
| 169 | static struct kobj_type nilfs_snapshot_ktype = { |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 170 | .default_groups = nilfs_snapshot_groups, |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 171 | .sysfs_ops = &nilfs_snapshot_attr_ops, |
| 172 | .release = nilfs_snapshot_attr_release, |
| 173 | }; |
| 174 | |
| 175 | int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root) |
| 176 | { |
| 177 | struct the_nilfs *nilfs; |
| 178 | struct kobject *parent; |
| 179 | int err; |
| 180 | |
| 181 | nilfs = root->nilfs; |
| 182 | parent = &nilfs->ns_dev_subgroups->sg_mounted_snapshots_kobj; |
| 183 | root->snapshot_kobj.kset = nilfs_kset; |
| 184 | init_completion(&root->snapshot_kobj_unregister); |
| 185 | |
| 186 | if (root->cno == NILFS_CPTREE_CURRENT_CNO) { |
| 187 | err = kobject_init_and_add(&root->snapshot_kobj, |
| 188 | &nilfs_snapshot_ktype, |
| 189 | &nilfs->ns_dev_kobj, |
| 190 | "current_checkpoint"); |
| 191 | } else { |
| 192 | err = kobject_init_and_add(&root->snapshot_kobj, |
| 193 | &nilfs_snapshot_ktype, |
| 194 | parent, |
| 195 | "%llu", root->cno); |
| 196 | } |
| 197 | |
| 198 | if (err) |
Nanyong Sun | b2fe39c | 2021-09-07 20:00:21 -0700 | [diff] [blame] | 199 | kobject_put(&root->snapshot_kobj); |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 200 | |
Nanyong Sun | b2fe39c | 2021-09-07 20:00:21 -0700 | [diff] [blame] | 201 | return err; |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root) |
| 205 | { |
Nanyong Sun | 17243e1 | 2021-09-07 20:00:23 -0700 | [diff] [blame] | 206 | kobject_put(&root->snapshot_kobj); |
Vyacheslav Dubeyko | a5a7332 | 2014-08-08 14:20:52 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /************************************************************************ |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 210 | * NILFS mounted snapshots attrs * |
| 211 | ************************************************************************/ |
| 212 | |
| 213 | static const char mounted_snapshots_readme_str[] = |
| 214 | "The mounted_snapshots group contains group for\n" |
| 215 | "every mounted snapshot.\n"; |
| 216 | |
| 217 | static ssize_t |
| 218 | nilfs_mounted_snapshots_README_show(struct nilfs_mounted_snapshots_attr *attr, |
| 219 | struct the_nilfs *nilfs, char *buf) |
| 220 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 221 | return sysfs_emit(buf, mounted_snapshots_readme_str); |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | NILFS_MOUNTED_SNAPSHOTS_RO_ATTR(README); |
| 225 | |
| 226 | static struct attribute *nilfs_mounted_snapshots_attrs[] = { |
| 227 | NILFS_MOUNTED_SNAPSHOTS_ATTR_LIST(README), |
| 228 | NULL, |
| 229 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 230 | ATTRIBUTE_GROUPS(nilfs_mounted_snapshots); |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 231 | |
| 232 | NILFS_DEV_INT_GROUP_OPS(mounted_snapshots, dev); |
| 233 | NILFS_DEV_INT_GROUP_TYPE(mounted_snapshots, dev); |
| 234 | NILFS_DEV_INT_GROUP_FNS(mounted_snapshots, dev); |
| 235 | |
| 236 | /************************************************************************ |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 237 | * NILFS checkpoints attrs * |
| 238 | ************************************************************************/ |
| 239 | |
| 240 | static ssize_t |
| 241 | nilfs_checkpoints_checkpoints_number_show(struct nilfs_checkpoints_attr *attr, |
| 242 | struct the_nilfs *nilfs, |
| 243 | char *buf) |
| 244 | { |
| 245 | __u64 ncheckpoints; |
| 246 | struct nilfs_cpstat cpstat; |
| 247 | int err; |
| 248 | |
| 249 | down_read(&nilfs->ns_segctor_sem); |
| 250 | err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat); |
| 251 | up_read(&nilfs->ns_segctor_sem); |
| 252 | if (err < 0) { |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 253 | nilfs_err(nilfs->ns_sb, "unable to get checkpoint stat: err=%d", |
| 254 | err); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 255 | return err; |
| 256 | } |
| 257 | |
| 258 | ncheckpoints = cpstat.cs_ncps; |
| 259 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 260 | return sysfs_emit(buf, "%llu\n", ncheckpoints); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static ssize_t |
| 264 | nilfs_checkpoints_snapshots_number_show(struct nilfs_checkpoints_attr *attr, |
| 265 | struct the_nilfs *nilfs, |
| 266 | char *buf) |
| 267 | { |
| 268 | __u64 nsnapshots; |
| 269 | struct nilfs_cpstat cpstat; |
| 270 | int err; |
| 271 | |
| 272 | down_read(&nilfs->ns_segctor_sem); |
| 273 | err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat); |
| 274 | up_read(&nilfs->ns_segctor_sem); |
| 275 | if (err < 0) { |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 276 | nilfs_err(nilfs->ns_sb, "unable to get checkpoint stat: err=%d", |
| 277 | err); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 278 | return err; |
| 279 | } |
| 280 | |
| 281 | nsnapshots = cpstat.cs_nsss; |
| 282 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 283 | return sysfs_emit(buf, "%llu\n", nsnapshots); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static ssize_t |
| 287 | nilfs_checkpoints_last_seg_checkpoint_show(struct nilfs_checkpoints_attr *attr, |
| 288 | struct the_nilfs *nilfs, |
| 289 | char *buf) |
| 290 | { |
| 291 | __u64 last_cno; |
| 292 | |
| 293 | spin_lock(&nilfs->ns_last_segment_lock); |
| 294 | last_cno = nilfs->ns_last_cno; |
| 295 | spin_unlock(&nilfs->ns_last_segment_lock); |
| 296 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 297 | return sysfs_emit(buf, "%llu\n", last_cno); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static ssize_t |
| 301 | nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr, |
| 302 | struct the_nilfs *nilfs, |
| 303 | char *buf) |
| 304 | { |
| 305 | __u64 cno; |
| 306 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 307 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 308 | cno = nilfs->ns_cno; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 309 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 310 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 311 | return sysfs_emit(buf, "%llu\n", cno); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static const char checkpoints_readme_str[] = |
| 315 | "The checkpoints group contains attributes that describe\n" |
| 316 | "details about volume's checkpoints.\n\n" |
| 317 | "(1) checkpoints_number\n\tshow number of checkpoints on volume.\n\n" |
| 318 | "(2) snapshots_number\n\tshow number of snapshots on volume.\n\n" |
| 319 | "(3) last_seg_checkpoint\n" |
| 320 | "\tshow checkpoint number of the latest segment.\n\n" |
| 321 | "(4) next_checkpoint\n\tshow next checkpoint number.\n\n"; |
| 322 | |
| 323 | static ssize_t |
| 324 | nilfs_checkpoints_README_show(struct nilfs_checkpoints_attr *attr, |
| 325 | struct the_nilfs *nilfs, char *buf) |
| 326 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 327 | return sysfs_emit(buf, checkpoints_readme_str); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | NILFS_CHECKPOINTS_RO_ATTR(checkpoints_number); |
| 331 | NILFS_CHECKPOINTS_RO_ATTR(snapshots_number); |
| 332 | NILFS_CHECKPOINTS_RO_ATTR(last_seg_checkpoint); |
| 333 | NILFS_CHECKPOINTS_RO_ATTR(next_checkpoint); |
| 334 | NILFS_CHECKPOINTS_RO_ATTR(README); |
| 335 | |
| 336 | static struct attribute *nilfs_checkpoints_attrs[] = { |
| 337 | NILFS_CHECKPOINTS_ATTR_LIST(checkpoints_number), |
| 338 | NILFS_CHECKPOINTS_ATTR_LIST(snapshots_number), |
| 339 | NILFS_CHECKPOINTS_ATTR_LIST(last_seg_checkpoint), |
| 340 | NILFS_CHECKPOINTS_ATTR_LIST(next_checkpoint), |
| 341 | NILFS_CHECKPOINTS_ATTR_LIST(README), |
| 342 | NULL, |
| 343 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 344 | ATTRIBUTE_GROUPS(nilfs_checkpoints); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 345 | |
| 346 | NILFS_DEV_INT_GROUP_OPS(checkpoints, dev); |
| 347 | NILFS_DEV_INT_GROUP_TYPE(checkpoints, dev); |
| 348 | NILFS_DEV_INT_GROUP_FNS(checkpoints, dev); |
| 349 | |
| 350 | /************************************************************************ |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 351 | * NILFS segments attrs * |
| 352 | ************************************************************************/ |
| 353 | |
| 354 | static ssize_t |
| 355 | nilfs_segments_segments_number_show(struct nilfs_segments_attr *attr, |
| 356 | struct the_nilfs *nilfs, |
| 357 | char *buf) |
| 358 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 359 | return sysfs_emit(buf, "%lu\n", nilfs->ns_nsegments); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | static ssize_t |
| 363 | nilfs_segments_blocks_per_segment_show(struct nilfs_segments_attr *attr, |
| 364 | struct the_nilfs *nilfs, |
| 365 | char *buf) |
| 366 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 367 | return sysfs_emit(buf, "%lu\n", nilfs->ns_blocks_per_segment); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static ssize_t |
| 371 | nilfs_segments_clean_segments_show(struct nilfs_segments_attr *attr, |
| 372 | struct the_nilfs *nilfs, |
| 373 | char *buf) |
| 374 | { |
| 375 | unsigned long ncleansegs; |
| 376 | |
| 377 | down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); |
| 378 | ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile); |
| 379 | up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem); |
| 380 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 381 | return sysfs_emit(buf, "%lu\n", ncleansegs); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static ssize_t |
| 385 | nilfs_segments_dirty_segments_show(struct nilfs_segments_attr *attr, |
| 386 | struct the_nilfs *nilfs, |
| 387 | char *buf) |
| 388 | { |
| 389 | struct nilfs_sustat sustat; |
| 390 | int err; |
| 391 | |
| 392 | down_read(&nilfs->ns_segctor_sem); |
| 393 | err = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat); |
| 394 | up_read(&nilfs->ns_segctor_sem); |
| 395 | if (err < 0) { |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 396 | nilfs_err(nilfs->ns_sb, "unable to get segment stat: err=%d", |
| 397 | err); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 398 | return err; |
| 399 | } |
| 400 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 401 | return sysfs_emit(buf, "%llu\n", sustat.ss_ndirtysegs); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static const char segments_readme_str[] = |
| 405 | "The segments group contains attributes that describe\n" |
| 406 | "details about volume's segments.\n\n" |
| 407 | "(1) segments_number\n\tshow number of segments on volume.\n\n" |
| 408 | "(2) blocks_per_segment\n\tshow number of blocks in segment.\n\n" |
| 409 | "(3) clean_segments\n\tshow count of clean segments.\n\n" |
| 410 | "(4) dirty_segments\n\tshow count of dirty segments.\n\n"; |
| 411 | |
| 412 | static ssize_t |
| 413 | nilfs_segments_README_show(struct nilfs_segments_attr *attr, |
| 414 | struct the_nilfs *nilfs, |
| 415 | char *buf) |
| 416 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 417 | return sysfs_emit(buf, segments_readme_str); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | NILFS_SEGMENTS_RO_ATTR(segments_number); |
| 421 | NILFS_SEGMENTS_RO_ATTR(blocks_per_segment); |
| 422 | NILFS_SEGMENTS_RO_ATTR(clean_segments); |
| 423 | NILFS_SEGMENTS_RO_ATTR(dirty_segments); |
| 424 | NILFS_SEGMENTS_RO_ATTR(README); |
| 425 | |
| 426 | static struct attribute *nilfs_segments_attrs[] = { |
| 427 | NILFS_SEGMENTS_ATTR_LIST(segments_number), |
| 428 | NILFS_SEGMENTS_ATTR_LIST(blocks_per_segment), |
| 429 | NILFS_SEGMENTS_ATTR_LIST(clean_segments), |
| 430 | NILFS_SEGMENTS_ATTR_LIST(dirty_segments), |
| 431 | NILFS_SEGMENTS_ATTR_LIST(README), |
| 432 | NULL, |
| 433 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 434 | ATTRIBUTE_GROUPS(nilfs_segments); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 435 | |
| 436 | NILFS_DEV_INT_GROUP_OPS(segments, dev); |
| 437 | NILFS_DEV_INT_GROUP_TYPE(segments, dev); |
| 438 | NILFS_DEV_INT_GROUP_FNS(segments, dev); |
| 439 | |
| 440 | /************************************************************************ |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 441 | * NILFS segctor attrs * |
| 442 | ************************************************************************/ |
| 443 | |
| 444 | static ssize_t |
| 445 | nilfs_segctor_last_pseg_block_show(struct nilfs_segctor_attr *attr, |
| 446 | struct the_nilfs *nilfs, |
| 447 | char *buf) |
| 448 | { |
| 449 | sector_t last_pseg; |
| 450 | |
| 451 | spin_lock(&nilfs->ns_last_segment_lock); |
| 452 | last_pseg = nilfs->ns_last_pseg; |
| 453 | spin_unlock(&nilfs->ns_last_segment_lock); |
| 454 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 455 | return sysfs_emit(buf, "%llu\n", |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 456 | (unsigned long long)last_pseg); |
| 457 | } |
| 458 | |
| 459 | static ssize_t |
| 460 | nilfs_segctor_last_seg_sequence_show(struct nilfs_segctor_attr *attr, |
| 461 | struct the_nilfs *nilfs, |
| 462 | char *buf) |
| 463 | { |
| 464 | u64 last_seq; |
| 465 | |
| 466 | spin_lock(&nilfs->ns_last_segment_lock); |
| 467 | last_seq = nilfs->ns_last_seq; |
| 468 | spin_unlock(&nilfs->ns_last_segment_lock); |
| 469 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 470 | return sysfs_emit(buf, "%llu\n", last_seq); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static ssize_t |
| 474 | nilfs_segctor_last_seg_checkpoint_show(struct nilfs_segctor_attr *attr, |
| 475 | struct the_nilfs *nilfs, |
| 476 | char *buf) |
| 477 | { |
| 478 | __u64 last_cno; |
| 479 | |
| 480 | spin_lock(&nilfs->ns_last_segment_lock); |
| 481 | last_cno = nilfs->ns_last_cno; |
| 482 | spin_unlock(&nilfs->ns_last_segment_lock); |
| 483 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 484 | return sysfs_emit(buf, "%llu\n", last_cno); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static ssize_t |
| 488 | nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr, |
| 489 | struct the_nilfs *nilfs, |
| 490 | char *buf) |
| 491 | { |
| 492 | u64 seg_seq; |
| 493 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 494 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 495 | seg_seq = nilfs->ns_seg_seq; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 496 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 497 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 498 | return sysfs_emit(buf, "%llu\n", seg_seq); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | static ssize_t |
| 502 | nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr, |
| 503 | struct the_nilfs *nilfs, |
| 504 | char *buf) |
| 505 | { |
| 506 | __u64 segnum; |
| 507 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 508 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 509 | segnum = nilfs->ns_segnum; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 510 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 511 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 512 | return sysfs_emit(buf, "%llu\n", segnum); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | static ssize_t |
| 516 | nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr, |
| 517 | struct the_nilfs *nilfs, |
| 518 | char *buf) |
| 519 | { |
| 520 | __u64 nextnum; |
| 521 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 522 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 523 | nextnum = nilfs->ns_nextnum; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 524 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 525 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 526 | return sysfs_emit(buf, "%llu\n", nextnum); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static ssize_t |
| 530 | nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr, |
| 531 | struct the_nilfs *nilfs, |
| 532 | char *buf) |
| 533 | { |
| 534 | unsigned long pseg_offset; |
| 535 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 536 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 537 | pseg_offset = nilfs->ns_pseg_offset; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 538 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 539 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 540 | return sysfs_emit(buf, "%lu\n", pseg_offset); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static ssize_t |
| 544 | nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr, |
| 545 | struct the_nilfs *nilfs, |
| 546 | char *buf) |
| 547 | { |
| 548 | __u64 cno; |
| 549 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 550 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 551 | cno = nilfs->ns_cno; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 552 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 553 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 554 | return sysfs_emit(buf, "%llu\n", cno); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static ssize_t |
| 558 | nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr, |
| 559 | struct the_nilfs *nilfs, |
| 560 | char *buf) |
| 561 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 562 | time64_t ctime; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 563 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 564 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 565 | ctime = nilfs->ns_ctime; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 566 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 567 | |
Andy Shevchenko | 776797f | 2021-05-11 18:39:57 +0300 | [diff] [blame] | 568 | return sysfs_emit(buf, "%ptTs\n", &ctime); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static ssize_t |
| 572 | nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr, |
| 573 | struct the_nilfs *nilfs, |
| 574 | char *buf) |
| 575 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 576 | time64_t ctime; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 577 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 578 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 579 | ctime = nilfs->ns_ctime; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 580 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 581 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 582 | return sysfs_emit(buf, "%llu\n", ctime); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static ssize_t |
| 586 | nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr, |
| 587 | struct the_nilfs *nilfs, |
| 588 | char *buf) |
| 589 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 590 | time64_t nongc_ctime; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 591 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 592 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 593 | nongc_ctime = nilfs->ns_nongc_ctime; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 594 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 595 | |
Andy Shevchenko | 776797f | 2021-05-11 18:39:57 +0300 | [diff] [blame] | 596 | return sysfs_emit(buf, "%ptTs\n", &nongc_ctime); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | static ssize_t |
| 600 | nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr, |
| 601 | struct the_nilfs *nilfs, |
| 602 | char *buf) |
| 603 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 604 | time64_t nongc_ctime; |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 605 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 606 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 607 | nongc_ctime = nilfs->ns_nongc_ctime; |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 608 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 609 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 610 | return sysfs_emit(buf, "%llu\n", nongc_ctime); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | static ssize_t |
| 614 | nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr, |
| 615 | struct the_nilfs *nilfs, |
| 616 | char *buf) |
| 617 | { |
| 618 | u32 ndirtyblks; |
| 619 | |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 620 | down_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 621 | ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks); |
Ryusuke Konishi | ad980c9 | 2016-08-02 14:05:25 -0700 | [diff] [blame] | 622 | up_read(&nilfs->ns_segctor_sem); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 623 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 624 | return sysfs_emit(buf, "%u\n", ndirtyblks); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | static const char segctor_readme_str[] = |
| 628 | "The segctor group contains attributes that describe\n" |
| 629 | "segctor thread activity details.\n\n" |
| 630 | "(1) last_pseg_block\n" |
| 631 | "\tshow start block number of the latest segment.\n\n" |
| 632 | "(2) last_seg_sequence\n" |
| 633 | "\tshow sequence value of the latest segment.\n\n" |
| 634 | "(3) last_seg_checkpoint\n" |
| 635 | "\tshow checkpoint number of the latest segment.\n\n" |
| 636 | "(4) current_seg_sequence\n\tshow segment sequence counter.\n\n" |
| 637 | "(5) current_last_full_seg\n" |
| 638 | "\tshow index number of the latest full segment.\n\n" |
| 639 | "(6) next_full_seg\n" |
| 640 | "\tshow index number of the full segment index to be used next.\n\n" |
| 641 | "(7) next_pseg_offset\n" |
| 642 | "\tshow offset of next partial segment in the current full segment.\n\n" |
| 643 | "(8) next_checkpoint\n\tshow next checkpoint number.\n\n" |
| 644 | "(9) last_seg_write_time\n" |
| 645 | "\tshow write time of the last segment in human-readable format.\n\n" |
| 646 | "(10) last_seg_write_time_secs\n" |
| 647 | "\tshow write time of the last segment in seconds.\n\n" |
| 648 | "(11) last_nongc_write_time\n" |
| 649 | "\tshow write time of the last segment not for cleaner operation " |
| 650 | "in human-readable format.\n\n" |
| 651 | "(12) last_nongc_write_time_secs\n" |
| 652 | "\tshow write time of the last segment not for cleaner operation " |
| 653 | "in seconds.\n\n" |
| 654 | "(13) dirty_data_blocks_count\n" |
| 655 | "\tshow number of dirty data blocks.\n\n"; |
| 656 | |
| 657 | static ssize_t |
| 658 | nilfs_segctor_README_show(struct nilfs_segctor_attr *attr, |
| 659 | struct the_nilfs *nilfs, char *buf) |
| 660 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 661 | return sysfs_emit(buf, segctor_readme_str); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | NILFS_SEGCTOR_RO_ATTR(last_pseg_block); |
| 665 | NILFS_SEGCTOR_RO_ATTR(last_seg_sequence); |
| 666 | NILFS_SEGCTOR_RO_ATTR(last_seg_checkpoint); |
| 667 | NILFS_SEGCTOR_RO_ATTR(current_seg_sequence); |
| 668 | NILFS_SEGCTOR_RO_ATTR(current_last_full_seg); |
| 669 | NILFS_SEGCTOR_RO_ATTR(next_full_seg); |
| 670 | NILFS_SEGCTOR_RO_ATTR(next_pseg_offset); |
| 671 | NILFS_SEGCTOR_RO_ATTR(next_checkpoint); |
| 672 | NILFS_SEGCTOR_RO_ATTR(last_seg_write_time); |
| 673 | NILFS_SEGCTOR_RO_ATTR(last_seg_write_time_secs); |
| 674 | NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time); |
| 675 | NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time_secs); |
| 676 | NILFS_SEGCTOR_RO_ATTR(dirty_data_blocks_count); |
| 677 | NILFS_SEGCTOR_RO_ATTR(README); |
| 678 | |
| 679 | static struct attribute *nilfs_segctor_attrs[] = { |
| 680 | NILFS_SEGCTOR_ATTR_LIST(last_pseg_block), |
| 681 | NILFS_SEGCTOR_ATTR_LIST(last_seg_sequence), |
| 682 | NILFS_SEGCTOR_ATTR_LIST(last_seg_checkpoint), |
| 683 | NILFS_SEGCTOR_ATTR_LIST(current_seg_sequence), |
| 684 | NILFS_SEGCTOR_ATTR_LIST(current_last_full_seg), |
| 685 | NILFS_SEGCTOR_ATTR_LIST(next_full_seg), |
| 686 | NILFS_SEGCTOR_ATTR_LIST(next_pseg_offset), |
| 687 | NILFS_SEGCTOR_ATTR_LIST(next_checkpoint), |
| 688 | NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time), |
| 689 | NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time_secs), |
| 690 | NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time), |
| 691 | NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time_secs), |
| 692 | NILFS_SEGCTOR_ATTR_LIST(dirty_data_blocks_count), |
| 693 | NILFS_SEGCTOR_ATTR_LIST(README), |
| 694 | NULL, |
| 695 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 696 | ATTRIBUTE_GROUPS(nilfs_segctor); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 697 | |
| 698 | NILFS_DEV_INT_GROUP_OPS(segctor, dev); |
| 699 | NILFS_DEV_INT_GROUP_TYPE(segctor, dev); |
| 700 | NILFS_DEV_INT_GROUP_FNS(segctor, dev); |
| 701 | |
| 702 | /************************************************************************ |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 703 | * NILFS superblock attrs * |
| 704 | ************************************************************************/ |
| 705 | |
| 706 | static ssize_t |
| 707 | nilfs_superblock_sb_write_time_show(struct nilfs_superblock_attr *attr, |
| 708 | struct the_nilfs *nilfs, |
| 709 | char *buf) |
| 710 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 711 | time64_t sbwtime; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 712 | |
| 713 | down_read(&nilfs->ns_sem); |
| 714 | sbwtime = nilfs->ns_sbwtime; |
| 715 | up_read(&nilfs->ns_sem); |
| 716 | |
Andy Shevchenko | 776797f | 2021-05-11 18:39:57 +0300 | [diff] [blame] | 717 | return sysfs_emit(buf, "%ptTs\n", &sbwtime); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static ssize_t |
| 721 | nilfs_superblock_sb_write_time_secs_show(struct nilfs_superblock_attr *attr, |
| 722 | struct the_nilfs *nilfs, |
| 723 | char *buf) |
| 724 | { |
Arnd Bergmann | fb04b91 | 2018-02-06 15:39:21 -0800 | [diff] [blame] | 725 | time64_t sbwtime; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 726 | |
| 727 | down_read(&nilfs->ns_sem); |
| 728 | sbwtime = nilfs->ns_sbwtime; |
| 729 | up_read(&nilfs->ns_sem); |
| 730 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 731 | return sysfs_emit(buf, "%llu\n", sbwtime); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | static ssize_t |
| 735 | nilfs_superblock_sb_write_count_show(struct nilfs_superblock_attr *attr, |
| 736 | struct the_nilfs *nilfs, |
| 737 | char *buf) |
| 738 | { |
Ryusuke Konishi | 0c6c44c | 2016-05-23 16:23:39 -0700 | [diff] [blame] | 739 | unsigned int sbwcount; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 740 | |
| 741 | down_read(&nilfs->ns_sem); |
| 742 | sbwcount = nilfs->ns_sbwcount; |
| 743 | up_read(&nilfs->ns_sem); |
| 744 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 745 | return sysfs_emit(buf, "%u\n", sbwcount); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static ssize_t |
| 749 | nilfs_superblock_sb_update_frequency_show(struct nilfs_superblock_attr *attr, |
| 750 | struct the_nilfs *nilfs, |
| 751 | char *buf) |
| 752 | { |
Ryusuke Konishi | 0c6c44c | 2016-05-23 16:23:39 -0700 | [diff] [blame] | 753 | unsigned int sb_update_freq; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 754 | |
| 755 | down_read(&nilfs->ns_sem); |
| 756 | sb_update_freq = nilfs->ns_sb_update_freq; |
| 757 | up_read(&nilfs->ns_sem); |
| 758 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 759 | return sysfs_emit(buf, "%u\n", sb_update_freq); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | static ssize_t |
| 763 | nilfs_superblock_sb_update_frequency_store(struct nilfs_superblock_attr *attr, |
| 764 | struct the_nilfs *nilfs, |
| 765 | const char *buf, size_t count) |
| 766 | { |
Ryusuke Konishi | 0c6c44c | 2016-05-23 16:23:39 -0700 | [diff] [blame] | 767 | unsigned int val; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 768 | int err; |
| 769 | |
| 770 | err = kstrtouint(skip_spaces(buf), 0, &val); |
| 771 | if (err) { |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 772 | nilfs_err(nilfs->ns_sb, "unable to convert string: err=%d", |
| 773 | err); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 774 | return err; |
| 775 | } |
| 776 | |
| 777 | if (val < NILFS_SB_FREQ) { |
| 778 | val = NILFS_SB_FREQ; |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 779 | nilfs_warn(nilfs->ns_sb, |
| 780 | "superblock update frequency cannot be lesser than 10 seconds"); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | down_write(&nilfs->ns_sem); |
| 784 | nilfs->ns_sb_update_freq = val; |
| 785 | up_write(&nilfs->ns_sem); |
| 786 | |
| 787 | return count; |
| 788 | } |
| 789 | |
| 790 | static const char sb_readme_str[] = |
| 791 | "The superblock group contains attributes that describe\n" |
| 792 | "superblock's details.\n\n" |
| 793 | "(1) sb_write_time\n\tshow previous write time of super block " |
| 794 | "in human-readable format.\n\n" |
| 795 | "(2) sb_write_time_secs\n\tshow previous write time of super block " |
| 796 | "in seconds.\n\n" |
| 797 | "(3) sb_write_count\n\tshow write count of super block.\n\n" |
| 798 | "(4) sb_update_frequency\n" |
| 799 | "\tshow/set interval of periodical update of superblock (in seconds).\n\n" |
| 800 | "\tYou can set preferable frequency of superblock update by command:\n\n" |
| 801 | "\t'echo <val> > /sys/fs/<nilfs>/<dev>/superblock/sb_update_frequency'\n"; |
| 802 | |
| 803 | static ssize_t |
| 804 | nilfs_superblock_README_show(struct nilfs_superblock_attr *attr, |
| 805 | struct the_nilfs *nilfs, char *buf) |
| 806 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 807 | return sysfs_emit(buf, sb_readme_str); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | NILFS_SUPERBLOCK_RO_ATTR(sb_write_time); |
| 811 | NILFS_SUPERBLOCK_RO_ATTR(sb_write_time_secs); |
| 812 | NILFS_SUPERBLOCK_RO_ATTR(sb_write_count); |
| 813 | NILFS_SUPERBLOCK_RW_ATTR(sb_update_frequency); |
| 814 | NILFS_SUPERBLOCK_RO_ATTR(README); |
| 815 | |
| 816 | static struct attribute *nilfs_superblock_attrs[] = { |
| 817 | NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time), |
| 818 | NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time_secs), |
| 819 | NILFS_SUPERBLOCK_ATTR_LIST(sb_write_count), |
| 820 | NILFS_SUPERBLOCK_ATTR_LIST(sb_update_frequency), |
| 821 | NILFS_SUPERBLOCK_ATTR_LIST(README), |
| 822 | NULL, |
| 823 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 824 | ATTRIBUTE_GROUPS(nilfs_superblock); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 825 | |
| 826 | NILFS_DEV_INT_GROUP_OPS(superblock, dev); |
| 827 | NILFS_DEV_INT_GROUP_TYPE(superblock, dev); |
| 828 | NILFS_DEV_INT_GROUP_FNS(superblock, dev); |
| 829 | |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 830 | /************************************************************************ |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 831 | * NILFS device attrs * |
| 832 | ************************************************************************/ |
| 833 | |
| 834 | static |
| 835 | ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr, |
| 836 | struct the_nilfs *nilfs, |
| 837 | char *buf) |
| 838 | { |
| 839 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
| 840 | u32 major = le32_to_cpu(sbp[0]->s_rev_level); |
| 841 | u16 minor = le16_to_cpu(sbp[0]->s_minor_rev_level); |
| 842 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 843 | return sysfs_emit(buf, "%d.%d\n", major, minor); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static |
| 847 | ssize_t nilfs_dev_blocksize_show(struct nilfs_dev_attr *attr, |
| 848 | struct the_nilfs *nilfs, |
| 849 | char *buf) |
| 850 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 851 | return sysfs_emit(buf, "%u\n", nilfs->ns_blocksize); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static |
| 855 | ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr, |
| 856 | struct the_nilfs *nilfs, |
| 857 | char *buf) |
| 858 | { |
| 859 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
| 860 | u64 dev_size = le64_to_cpu(sbp[0]->s_dev_size); |
| 861 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 862 | return sysfs_emit(buf, "%llu\n", dev_size); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static |
| 866 | ssize_t nilfs_dev_free_blocks_show(struct nilfs_dev_attr *attr, |
| 867 | struct the_nilfs *nilfs, |
| 868 | char *buf) |
| 869 | { |
| 870 | sector_t free_blocks = 0; |
| 871 | |
| 872 | nilfs_count_free_blocks(nilfs, &free_blocks); |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 873 | return sysfs_emit(buf, "%llu\n", |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 874 | (unsigned long long)free_blocks); |
| 875 | } |
| 876 | |
| 877 | static |
| 878 | ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr, |
| 879 | struct the_nilfs *nilfs, |
| 880 | char *buf) |
| 881 | { |
| 882 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
| 883 | |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 884 | return sysfs_emit(buf, "%pUb\n", sbp[0]->s_uuid); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static |
| 888 | ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr, |
| 889 | struct the_nilfs *nilfs, |
| 890 | char *buf) |
| 891 | { |
| 892 | struct nilfs_super_block **sbp = nilfs->ns_sbp; |
| 893 | |
| 894 | return scnprintf(buf, sizeof(sbp[0]->s_volume_name), "%s\n", |
| 895 | sbp[0]->s_volume_name); |
| 896 | } |
| 897 | |
| 898 | static const char dev_readme_str[] = |
| 899 | "The <device> group contains attributes that describe file system\n" |
| 900 | "partition's details.\n\n" |
| 901 | "(1) revision\n\tshow NILFS file system revision.\n\n" |
| 902 | "(2) blocksize\n\tshow volume block size in bytes.\n\n" |
| 903 | "(3) device_size\n\tshow volume size in bytes.\n\n" |
| 904 | "(4) free_blocks\n\tshow count of free blocks on volume.\n\n" |
| 905 | "(5) uuid\n\tshow volume's UUID.\n\n" |
| 906 | "(6) volume_name\n\tshow volume's name.\n\n"; |
| 907 | |
| 908 | static ssize_t nilfs_dev_README_show(struct nilfs_dev_attr *attr, |
| 909 | struct the_nilfs *nilfs, |
| 910 | char *buf) |
| 911 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 912 | return sysfs_emit(buf, dev_readme_str); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | NILFS_DEV_RO_ATTR(revision); |
| 916 | NILFS_DEV_RO_ATTR(blocksize); |
| 917 | NILFS_DEV_RO_ATTR(device_size); |
| 918 | NILFS_DEV_RO_ATTR(free_blocks); |
| 919 | NILFS_DEV_RO_ATTR(uuid); |
| 920 | NILFS_DEV_RO_ATTR(volume_name); |
| 921 | NILFS_DEV_RO_ATTR(README); |
| 922 | |
| 923 | static struct attribute *nilfs_dev_attrs[] = { |
| 924 | NILFS_DEV_ATTR_LIST(revision), |
| 925 | NILFS_DEV_ATTR_LIST(blocksize), |
| 926 | NILFS_DEV_ATTR_LIST(device_size), |
| 927 | NILFS_DEV_ATTR_LIST(free_blocks), |
| 928 | NILFS_DEV_ATTR_LIST(uuid), |
| 929 | NILFS_DEV_ATTR_LIST(volume_name), |
| 930 | NILFS_DEV_ATTR_LIST(README), |
| 931 | NULL, |
| 932 | }; |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 933 | ATTRIBUTE_GROUPS(nilfs_dev); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 934 | |
| 935 | static ssize_t nilfs_dev_attr_show(struct kobject *kobj, |
| 936 | struct attribute *attr, char *buf) |
| 937 | { |
| 938 | struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs, |
| 939 | ns_dev_kobj); |
| 940 | struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr, |
| 941 | attr); |
| 942 | |
| 943 | return a->show ? a->show(a, nilfs, buf) : 0; |
| 944 | } |
| 945 | |
| 946 | static ssize_t nilfs_dev_attr_store(struct kobject *kobj, |
| 947 | struct attribute *attr, |
| 948 | const char *buf, size_t len) |
| 949 | { |
| 950 | struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs, |
| 951 | ns_dev_kobj); |
| 952 | struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr, |
| 953 | attr); |
| 954 | |
| 955 | return a->store ? a->store(a, nilfs, buf, len) : 0; |
| 956 | } |
| 957 | |
| 958 | static void nilfs_dev_attr_release(struct kobject *kobj) |
| 959 | { |
| 960 | struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs, |
| 961 | ns_dev_kobj); |
| 962 | complete(&nilfs->ns_dev_kobj_unregister); |
| 963 | } |
| 964 | |
| 965 | static const struct sysfs_ops nilfs_dev_attr_ops = { |
| 966 | .show = nilfs_dev_attr_show, |
| 967 | .store = nilfs_dev_attr_store, |
| 968 | }; |
| 969 | |
| 970 | static struct kobj_type nilfs_dev_ktype = { |
Greg Kroah-Hartman | a6b9a61 | 2021-12-28 15:42:52 +0100 | [diff] [blame] | 971 | .default_groups = nilfs_dev_groups, |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 972 | .sysfs_ops = &nilfs_dev_attr_ops, |
| 973 | .release = nilfs_dev_attr_release, |
| 974 | }; |
| 975 | |
| 976 | int nilfs_sysfs_create_device_group(struct super_block *sb) |
| 977 | { |
| 978 | struct the_nilfs *nilfs = sb->s_fs_info; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 979 | size_t devgrp_size = sizeof(struct nilfs_sysfs_dev_subgroups); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 980 | int err; |
| 981 | |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 982 | nilfs->ns_dev_subgroups = kzalloc(devgrp_size, GFP_KERNEL); |
| 983 | if (unlikely(!nilfs->ns_dev_subgroups)) { |
| 984 | err = -ENOMEM; |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 985 | nilfs_err(sb, "unable to allocate memory for device group"); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 986 | goto failed_create_device_group; |
| 987 | } |
| 988 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 989 | nilfs->ns_dev_kobj.kset = nilfs_kset; |
| 990 | init_completion(&nilfs->ns_dev_kobj_unregister); |
| 991 | err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL, |
| 992 | "%s", sb->s_id); |
| 993 | if (err) |
Nanyong Sun | 5f5dec0 | 2021-09-07 20:00:09 -0700 | [diff] [blame] | 994 | goto cleanup_dev_kobject; |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 995 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 996 | err = nilfs_sysfs_create_mounted_snapshots_group(nilfs); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 997 | if (err) |
| 998 | goto cleanup_dev_kobject; |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 999 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 1000 | err = nilfs_sysfs_create_checkpoints_group(nilfs); |
| 1001 | if (err) |
| 1002 | goto delete_mounted_snapshots_group; |
| 1003 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 1004 | err = nilfs_sysfs_create_segments_group(nilfs); |
| 1005 | if (err) |
| 1006 | goto delete_checkpoints_group; |
| 1007 | |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 1008 | err = nilfs_sysfs_create_superblock_group(nilfs); |
| 1009 | if (err) |
| 1010 | goto delete_segments_group; |
| 1011 | |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 1012 | err = nilfs_sysfs_create_segctor_group(nilfs); |
| 1013 | if (err) |
| 1014 | goto delete_superblock_group; |
| 1015 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 1016 | return 0; |
| 1017 | |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 1018 | delete_superblock_group: |
| 1019 | nilfs_sysfs_delete_superblock_group(nilfs); |
| 1020 | |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 1021 | delete_segments_group: |
| 1022 | nilfs_sysfs_delete_segments_group(nilfs); |
| 1023 | |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 1024 | delete_checkpoints_group: |
| 1025 | nilfs_sysfs_delete_checkpoints_group(nilfs); |
| 1026 | |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 1027 | delete_mounted_snapshots_group: |
| 1028 | nilfs_sysfs_delete_mounted_snapshots_group(nilfs); |
| 1029 | |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 1030 | cleanup_dev_kobject: |
Nanyong Sun | 5f5dec0 | 2021-09-07 20:00:09 -0700 | [diff] [blame] | 1031 | kobject_put(&nilfs->ns_dev_kobj); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 1032 | kfree(nilfs->ns_dev_subgroups); |
| 1033 | |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 1034 | failed_create_device_group: |
| 1035 | return err; |
| 1036 | } |
| 1037 | |
| 1038 | void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs) |
| 1039 | { |
Vyacheslav Dubeyko | a2ecb79 | 2014-08-08 14:20:50 -0700 | [diff] [blame] | 1040 | nilfs_sysfs_delete_mounted_snapshots_group(nilfs); |
Vyacheslav Dubeyko | 02a0ba1 | 2014-08-08 14:20:48 -0700 | [diff] [blame] | 1041 | nilfs_sysfs_delete_checkpoints_group(nilfs); |
Vyacheslav Dubeyko | ef43d5c | 2014-08-08 14:20:46 -0700 | [diff] [blame] | 1042 | nilfs_sysfs_delete_segments_group(nilfs); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 1043 | nilfs_sysfs_delete_superblock_group(nilfs); |
Vyacheslav Dubeyko | abc968d | 2014-08-08 14:20:44 -0700 | [diff] [blame] | 1044 | nilfs_sysfs_delete_segctor_group(nilfs); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 1045 | kobject_del(&nilfs->ns_dev_kobj); |
Pavel Skripkin | 8fd0c1b | 2021-06-24 18:39:33 -0700 | [diff] [blame] | 1046 | kobject_put(&nilfs->ns_dev_kobj); |
Vyacheslav Dubeyko | caa05d4 | 2014-08-08 14:20:42 -0700 | [diff] [blame] | 1047 | kfree(nilfs->ns_dev_subgroups); |
Vyacheslav Dubeyko | da7141f | 2014-08-08 14:20:39 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | /************************************************************************ |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1051 | * NILFS feature attrs * |
| 1052 | ************************************************************************/ |
| 1053 | |
| 1054 | static ssize_t nilfs_feature_revision_show(struct kobject *kobj, |
| 1055 | struct attribute *attr, char *buf) |
| 1056 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 1057 | return sysfs_emit(buf, "%d.%d\n", |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1058 | NILFS_CURRENT_REV, NILFS_MINOR_REV); |
| 1059 | } |
| 1060 | |
| 1061 | static const char features_readme_str[] = |
| 1062 | "The features group contains attributes that describe NILFS file\n" |
| 1063 | "system driver features.\n\n" |
| 1064 | "(1) revision\n\tshow current revision of NILFS file system driver.\n"; |
| 1065 | |
| 1066 | static ssize_t nilfs_feature_README_show(struct kobject *kobj, |
| 1067 | struct attribute *attr, |
| 1068 | char *buf) |
| 1069 | { |
Qing Wang | 3bcd6c5 | 2021-11-08 18:34:58 -0800 | [diff] [blame] | 1070 | return sysfs_emit(buf, features_readme_str); |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | NILFS_FEATURE_RO_ATTR(revision); |
| 1074 | NILFS_FEATURE_RO_ATTR(README); |
| 1075 | |
| 1076 | static struct attribute *nilfs_feature_attrs[] = { |
| 1077 | NILFS_FEATURE_ATTR_LIST(revision), |
| 1078 | NILFS_FEATURE_ATTR_LIST(README), |
| 1079 | NULL, |
| 1080 | }; |
| 1081 | |
| 1082 | static const struct attribute_group nilfs_feature_attr_group = { |
| 1083 | .name = "features", |
| 1084 | .attrs = nilfs_feature_attrs, |
| 1085 | }; |
| 1086 | |
| 1087 | int __init nilfs_sysfs_init(void) |
| 1088 | { |
| 1089 | int err; |
| 1090 | |
| 1091 | nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj); |
| 1092 | if (!nilfs_kset) { |
| 1093 | err = -ENOMEM; |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 1094 | nilfs_err(NULL, "unable to create sysfs entry: err=%d", err); |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1095 | goto failed_sysfs_init; |
| 1096 | } |
| 1097 | |
| 1098 | err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group); |
| 1099 | if (unlikely(err)) { |
Joe Perches | a1d0747 | 2020-08-11 18:35:49 -0700 | [diff] [blame] | 1100 | nilfs_err(NULL, "unable to create feature group: err=%d", err); |
Vyacheslav Dubeyko | aebe17f | 2014-08-08 14:20:37 -0700 | [diff] [blame] | 1101 | goto cleanup_sysfs_init; |
| 1102 | } |
| 1103 | |
| 1104 | return 0; |
| 1105 | |
| 1106 | cleanup_sysfs_init: |
| 1107 | kset_unregister(nilfs_kset); |
| 1108 | |
| 1109 | failed_sysfs_init: |
| 1110 | return err; |
| 1111 | } |
| 1112 | |
| 1113 | void nilfs_sysfs_exit(void) |
| 1114 | { |
| 1115 | sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group); |
| 1116 | kset_unregister(nilfs_kset); |
| 1117 | } |