2 * sysfs.c - sysfs support implementation.
4 * Copyright (C) 2005-2014 Nippon Telegraph and Telephone Corporation.
5 * Copyright (C) 2014 HGST, Inc., a Western Digital Company.
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.
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.
17 * Written by Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>
20 #include <linux/kobject.h>
28 /* /sys/fs/<nilfs>/ */
29 static struct kset *nilfs_kset;
31 #define NILFS_SHOW_TIME(time_t_val, buf) ({ \
34 time_to_tm(time_t_val, 0, &res); \
35 res.tm_year += 1900; \
37 count = scnprintf(buf, PAGE_SIZE, \
38 "%ld-%.2d-%.2d %.2d:%.2d:%.2d\n", \
39 res.tm_year, res.tm_mon, res.tm_mday, \
40 res.tm_hour, res.tm_min, res.tm_sec);\
44 #define NILFS_DEV_INT_GROUP_OPS(name, parent_name) \
45 static ssize_t nilfs_##name##_attr_show(struct kobject *kobj, \
46 struct attribute *attr, char *buf) \
48 struct the_nilfs *nilfs = container_of(kobj->parent, \
50 ns_##parent_name##_kobj); \
51 struct nilfs_##name##_attr *a = container_of(attr, \
52 struct nilfs_##name##_attr, \
54 return a->show ? a->show(a, nilfs, buf) : 0; \
56 static ssize_t nilfs_##name##_attr_store(struct kobject *kobj, \
57 struct attribute *attr, \
58 const char *buf, size_t len) \
60 struct the_nilfs *nilfs = container_of(kobj->parent, \
62 ns_##parent_name##_kobj); \
63 struct nilfs_##name##_attr *a = container_of(attr, \
64 struct nilfs_##name##_attr, \
66 return a->store ? a->store(a, nilfs, buf, len) : 0; \
68 static const struct sysfs_ops nilfs_##name##_attr_ops = { \
69 .show = nilfs_##name##_attr_show, \
70 .store = nilfs_##name##_attr_store, \
73 #define NILFS_DEV_INT_GROUP_TYPE(name, parent_name) \
74 static void nilfs_##name##_attr_release(struct kobject *kobj) \
76 struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
77 struct the_nilfs *nilfs = container_of(kobj->parent, \
79 ns_##parent_name##_kobj); \
80 subgroups = nilfs->ns_##parent_name##_subgroups; \
81 complete(&subgroups->sg_##name##_kobj_unregister); \
83 static struct kobj_type nilfs_##name##_ktype = { \
84 .default_attrs = nilfs_##name##_attrs, \
85 .sysfs_ops = &nilfs_##name##_attr_ops, \
86 .release = nilfs_##name##_attr_release, \
89 #define NILFS_DEV_INT_GROUP_FNS(name, parent_name) \
90 int nilfs_sysfs_create_##name##_group(struct the_nilfs *nilfs) \
92 struct kobject *parent; \
93 struct kobject *kobj; \
94 struct completion *kobj_unregister; \
95 struct nilfs_sysfs_##parent_name##_subgroups *subgroups; \
97 subgroups = nilfs->ns_##parent_name##_subgroups; \
98 kobj = &subgroups->sg_##name##_kobj; \
99 kobj_unregister = &subgroups->sg_##name##_kobj_unregister; \
100 parent = &nilfs->ns_##parent_name##_kobj; \
101 kobj->kset = nilfs_kset; \
102 init_completion(kobj_unregister); \
103 err = kobject_init_and_add(kobj, &nilfs_##name##_ktype, parent, \
109 void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
111 kobject_del(&nilfs->ns_##parent_name##_subgroups->sg_##name##_kobj); \
114 /************************************************************************
115 * NILFS segctor attrs *
116 ************************************************************************/
119 nilfs_segctor_last_pseg_block_show(struct nilfs_segctor_attr *attr,
120 struct the_nilfs *nilfs,
125 spin_lock(&nilfs->ns_last_segment_lock);
126 last_pseg = nilfs->ns_last_pseg;
127 spin_unlock(&nilfs->ns_last_segment_lock);
129 return snprintf(buf, PAGE_SIZE, "%llu\n",
130 (unsigned long long)last_pseg);
134 nilfs_segctor_last_seg_sequence_show(struct nilfs_segctor_attr *attr,
135 struct the_nilfs *nilfs,
140 spin_lock(&nilfs->ns_last_segment_lock);
141 last_seq = nilfs->ns_last_seq;
142 spin_unlock(&nilfs->ns_last_segment_lock);
144 return snprintf(buf, PAGE_SIZE, "%llu\n", last_seq);
148 nilfs_segctor_last_seg_checkpoint_show(struct nilfs_segctor_attr *attr,
149 struct the_nilfs *nilfs,
154 spin_lock(&nilfs->ns_last_segment_lock);
155 last_cno = nilfs->ns_last_cno;
156 spin_unlock(&nilfs->ns_last_segment_lock);
158 return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
162 nilfs_segctor_current_seg_sequence_show(struct nilfs_segctor_attr *attr,
163 struct the_nilfs *nilfs,
168 down_read(&nilfs->ns_sem);
169 seg_seq = nilfs->ns_seg_seq;
170 up_read(&nilfs->ns_sem);
172 return snprintf(buf, PAGE_SIZE, "%llu\n", seg_seq);
176 nilfs_segctor_current_last_full_seg_show(struct nilfs_segctor_attr *attr,
177 struct the_nilfs *nilfs,
182 down_read(&nilfs->ns_sem);
183 segnum = nilfs->ns_segnum;
184 up_read(&nilfs->ns_sem);
186 return snprintf(buf, PAGE_SIZE, "%llu\n", segnum);
190 nilfs_segctor_next_full_seg_show(struct nilfs_segctor_attr *attr,
191 struct the_nilfs *nilfs,
196 down_read(&nilfs->ns_sem);
197 nextnum = nilfs->ns_nextnum;
198 up_read(&nilfs->ns_sem);
200 return snprintf(buf, PAGE_SIZE, "%llu\n", nextnum);
204 nilfs_segctor_next_pseg_offset_show(struct nilfs_segctor_attr *attr,
205 struct the_nilfs *nilfs,
208 unsigned long pseg_offset;
210 down_read(&nilfs->ns_sem);
211 pseg_offset = nilfs->ns_pseg_offset;
212 up_read(&nilfs->ns_sem);
214 return snprintf(buf, PAGE_SIZE, "%lu\n", pseg_offset);
218 nilfs_segctor_next_checkpoint_show(struct nilfs_segctor_attr *attr,
219 struct the_nilfs *nilfs,
224 down_read(&nilfs->ns_sem);
226 up_read(&nilfs->ns_sem);
228 return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
232 nilfs_segctor_last_seg_write_time_show(struct nilfs_segctor_attr *attr,
233 struct the_nilfs *nilfs,
238 down_read(&nilfs->ns_sem);
239 ctime = nilfs->ns_ctime;
240 up_read(&nilfs->ns_sem);
242 return NILFS_SHOW_TIME(ctime, buf);
246 nilfs_segctor_last_seg_write_time_secs_show(struct nilfs_segctor_attr *attr,
247 struct the_nilfs *nilfs,
252 down_read(&nilfs->ns_sem);
253 ctime = nilfs->ns_ctime;
254 up_read(&nilfs->ns_sem);
256 return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)ctime);
260 nilfs_segctor_last_nongc_write_time_show(struct nilfs_segctor_attr *attr,
261 struct the_nilfs *nilfs,
266 down_read(&nilfs->ns_sem);
267 nongc_ctime = nilfs->ns_nongc_ctime;
268 up_read(&nilfs->ns_sem);
270 return NILFS_SHOW_TIME(nongc_ctime, buf);
274 nilfs_segctor_last_nongc_write_time_secs_show(struct nilfs_segctor_attr *attr,
275 struct the_nilfs *nilfs,
280 down_read(&nilfs->ns_sem);
281 nongc_ctime = nilfs->ns_nongc_ctime;
282 up_read(&nilfs->ns_sem);
284 return snprintf(buf, PAGE_SIZE, "%llu\n",
285 (unsigned long long)nongc_ctime);
289 nilfs_segctor_dirty_data_blocks_count_show(struct nilfs_segctor_attr *attr,
290 struct the_nilfs *nilfs,
295 down_read(&nilfs->ns_sem);
296 ndirtyblks = atomic_read(&nilfs->ns_ndirtyblks);
297 up_read(&nilfs->ns_sem);
299 return snprintf(buf, PAGE_SIZE, "%u\n", ndirtyblks);
302 static const char segctor_readme_str[] =
303 "The segctor group contains attributes that describe\n"
304 "segctor thread activity details.\n\n"
305 "(1) last_pseg_block\n"
306 "\tshow start block number of the latest segment.\n\n"
307 "(2) last_seg_sequence\n"
308 "\tshow sequence value of the latest segment.\n\n"
309 "(3) last_seg_checkpoint\n"
310 "\tshow checkpoint number of the latest segment.\n\n"
311 "(4) current_seg_sequence\n\tshow segment sequence counter.\n\n"
312 "(5) current_last_full_seg\n"
313 "\tshow index number of the latest full segment.\n\n"
314 "(6) next_full_seg\n"
315 "\tshow index number of the full segment index to be used next.\n\n"
316 "(7) next_pseg_offset\n"
317 "\tshow offset of next partial segment in the current full segment.\n\n"
318 "(8) next_checkpoint\n\tshow next checkpoint number.\n\n"
319 "(9) last_seg_write_time\n"
320 "\tshow write time of the last segment in human-readable format.\n\n"
321 "(10) last_seg_write_time_secs\n"
322 "\tshow write time of the last segment in seconds.\n\n"
323 "(11) last_nongc_write_time\n"
324 "\tshow write time of the last segment not for cleaner operation "
325 "in human-readable format.\n\n"
326 "(12) last_nongc_write_time_secs\n"
327 "\tshow write time of the last segment not for cleaner operation "
329 "(13) dirty_data_blocks_count\n"
330 "\tshow number of dirty data blocks.\n\n";
333 nilfs_segctor_README_show(struct nilfs_segctor_attr *attr,
334 struct the_nilfs *nilfs, char *buf)
336 return snprintf(buf, PAGE_SIZE, segctor_readme_str);
339 NILFS_SEGCTOR_RO_ATTR(last_pseg_block);
340 NILFS_SEGCTOR_RO_ATTR(last_seg_sequence);
341 NILFS_SEGCTOR_RO_ATTR(last_seg_checkpoint);
342 NILFS_SEGCTOR_RO_ATTR(current_seg_sequence);
343 NILFS_SEGCTOR_RO_ATTR(current_last_full_seg);
344 NILFS_SEGCTOR_RO_ATTR(next_full_seg);
345 NILFS_SEGCTOR_RO_ATTR(next_pseg_offset);
346 NILFS_SEGCTOR_RO_ATTR(next_checkpoint);
347 NILFS_SEGCTOR_RO_ATTR(last_seg_write_time);
348 NILFS_SEGCTOR_RO_ATTR(last_seg_write_time_secs);
349 NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time);
350 NILFS_SEGCTOR_RO_ATTR(last_nongc_write_time_secs);
351 NILFS_SEGCTOR_RO_ATTR(dirty_data_blocks_count);
352 NILFS_SEGCTOR_RO_ATTR(README);
354 static struct attribute *nilfs_segctor_attrs[] = {
355 NILFS_SEGCTOR_ATTR_LIST(last_pseg_block),
356 NILFS_SEGCTOR_ATTR_LIST(last_seg_sequence),
357 NILFS_SEGCTOR_ATTR_LIST(last_seg_checkpoint),
358 NILFS_SEGCTOR_ATTR_LIST(current_seg_sequence),
359 NILFS_SEGCTOR_ATTR_LIST(current_last_full_seg),
360 NILFS_SEGCTOR_ATTR_LIST(next_full_seg),
361 NILFS_SEGCTOR_ATTR_LIST(next_pseg_offset),
362 NILFS_SEGCTOR_ATTR_LIST(next_checkpoint),
363 NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time),
364 NILFS_SEGCTOR_ATTR_LIST(last_seg_write_time_secs),
365 NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time),
366 NILFS_SEGCTOR_ATTR_LIST(last_nongc_write_time_secs),
367 NILFS_SEGCTOR_ATTR_LIST(dirty_data_blocks_count),
368 NILFS_SEGCTOR_ATTR_LIST(README),
372 NILFS_DEV_INT_GROUP_OPS(segctor, dev);
373 NILFS_DEV_INT_GROUP_TYPE(segctor, dev);
374 NILFS_DEV_INT_GROUP_FNS(segctor, dev);
376 /************************************************************************
377 * NILFS superblock attrs *
378 ************************************************************************/
381 nilfs_superblock_sb_write_time_show(struct nilfs_superblock_attr *attr,
382 struct the_nilfs *nilfs,
387 down_read(&nilfs->ns_sem);
388 sbwtime = nilfs->ns_sbwtime;
389 up_read(&nilfs->ns_sem);
391 return NILFS_SHOW_TIME(sbwtime, buf);
395 nilfs_superblock_sb_write_time_secs_show(struct nilfs_superblock_attr *attr,
396 struct the_nilfs *nilfs,
401 down_read(&nilfs->ns_sem);
402 sbwtime = nilfs->ns_sbwtime;
403 up_read(&nilfs->ns_sem);
405 return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)sbwtime);
409 nilfs_superblock_sb_write_count_show(struct nilfs_superblock_attr *attr,
410 struct the_nilfs *nilfs,
415 down_read(&nilfs->ns_sem);
416 sbwcount = nilfs->ns_sbwcount;
417 up_read(&nilfs->ns_sem);
419 return snprintf(buf, PAGE_SIZE, "%u\n", sbwcount);
423 nilfs_superblock_sb_update_frequency_show(struct nilfs_superblock_attr *attr,
424 struct the_nilfs *nilfs,
427 unsigned sb_update_freq;
429 down_read(&nilfs->ns_sem);
430 sb_update_freq = nilfs->ns_sb_update_freq;
431 up_read(&nilfs->ns_sem);
433 return snprintf(buf, PAGE_SIZE, "%u\n", sb_update_freq);
437 nilfs_superblock_sb_update_frequency_store(struct nilfs_superblock_attr *attr,
438 struct the_nilfs *nilfs,
439 const char *buf, size_t count)
444 err = kstrtouint(skip_spaces(buf), 0, &val);
446 printk(KERN_ERR "NILFS: unable to convert string: err=%d\n",
451 if (val < NILFS_SB_FREQ) {
453 printk(KERN_WARNING "NILFS: superblock update frequency cannot be lesser than 10 seconds\n");
456 down_write(&nilfs->ns_sem);
457 nilfs->ns_sb_update_freq = val;
458 up_write(&nilfs->ns_sem);
463 static const char sb_readme_str[] =
464 "The superblock group contains attributes that describe\n"
465 "superblock's details.\n\n"
466 "(1) sb_write_time\n\tshow previous write time of super block "
467 "in human-readable format.\n\n"
468 "(2) sb_write_time_secs\n\tshow previous write time of super block "
470 "(3) sb_write_count\n\tshow write count of super block.\n\n"
471 "(4) sb_update_frequency\n"
472 "\tshow/set interval of periodical update of superblock (in seconds).\n\n"
473 "\tYou can set preferable frequency of superblock update by command:\n\n"
474 "\t'echo <val> > /sys/fs/<nilfs>/<dev>/superblock/sb_update_frequency'\n";
477 nilfs_superblock_README_show(struct nilfs_superblock_attr *attr,
478 struct the_nilfs *nilfs, char *buf)
480 return snprintf(buf, PAGE_SIZE, sb_readme_str);
483 NILFS_SUPERBLOCK_RO_ATTR(sb_write_time);
484 NILFS_SUPERBLOCK_RO_ATTR(sb_write_time_secs);
485 NILFS_SUPERBLOCK_RO_ATTR(sb_write_count);
486 NILFS_SUPERBLOCK_RW_ATTR(sb_update_frequency);
487 NILFS_SUPERBLOCK_RO_ATTR(README);
489 static struct attribute *nilfs_superblock_attrs[] = {
490 NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time),
491 NILFS_SUPERBLOCK_ATTR_LIST(sb_write_time_secs),
492 NILFS_SUPERBLOCK_ATTR_LIST(sb_write_count),
493 NILFS_SUPERBLOCK_ATTR_LIST(sb_update_frequency),
494 NILFS_SUPERBLOCK_ATTR_LIST(README),
498 NILFS_DEV_INT_GROUP_OPS(superblock, dev);
499 NILFS_DEV_INT_GROUP_TYPE(superblock, dev);
500 NILFS_DEV_INT_GROUP_FNS(superblock, dev);
502 /************************************************************************
503 * NILFS device attrs *
504 ************************************************************************/
507 ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr,
508 struct the_nilfs *nilfs,
511 struct nilfs_super_block **sbp = nilfs->ns_sbp;
512 u32 major = le32_to_cpu(sbp[0]->s_rev_level);
513 u16 minor = le16_to_cpu(sbp[0]->s_minor_rev_level);
515 return snprintf(buf, PAGE_SIZE, "%d.%d\n", major, minor);
519 ssize_t nilfs_dev_blocksize_show(struct nilfs_dev_attr *attr,
520 struct the_nilfs *nilfs,
523 return snprintf(buf, PAGE_SIZE, "%u\n", nilfs->ns_blocksize);
527 ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr,
528 struct the_nilfs *nilfs,
531 struct nilfs_super_block **sbp = nilfs->ns_sbp;
532 u64 dev_size = le64_to_cpu(sbp[0]->s_dev_size);
534 return snprintf(buf, PAGE_SIZE, "%llu\n", dev_size);
538 ssize_t nilfs_dev_free_blocks_show(struct nilfs_dev_attr *attr,
539 struct the_nilfs *nilfs,
542 sector_t free_blocks = 0;
544 nilfs_count_free_blocks(nilfs, &free_blocks);
545 return snprintf(buf, PAGE_SIZE, "%llu\n",
546 (unsigned long long)free_blocks);
550 ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr,
551 struct the_nilfs *nilfs,
554 struct nilfs_super_block **sbp = nilfs->ns_sbp;
556 return snprintf(buf, PAGE_SIZE, "%pUb\n", sbp[0]->s_uuid);
560 ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr,
561 struct the_nilfs *nilfs,
564 struct nilfs_super_block **sbp = nilfs->ns_sbp;
566 return scnprintf(buf, sizeof(sbp[0]->s_volume_name), "%s\n",
567 sbp[0]->s_volume_name);
570 static const char dev_readme_str[] =
571 "The <device> group contains attributes that describe file system\n"
572 "partition's details.\n\n"
573 "(1) revision\n\tshow NILFS file system revision.\n\n"
574 "(2) blocksize\n\tshow volume block size in bytes.\n\n"
575 "(3) device_size\n\tshow volume size in bytes.\n\n"
576 "(4) free_blocks\n\tshow count of free blocks on volume.\n\n"
577 "(5) uuid\n\tshow volume's UUID.\n\n"
578 "(6) volume_name\n\tshow volume's name.\n\n";
580 static ssize_t nilfs_dev_README_show(struct nilfs_dev_attr *attr,
581 struct the_nilfs *nilfs,
584 return snprintf(buf, PAGE_SIZE, dev_readme_str);
587 NILFS_DEV_RO_ATTR(revision);
588 NILFS_DEV_RO_ATTR(blocksize);
589 NILFS_DEV_RO_ATTR(device_size);
590 NILFS_DEV_RO_ATTR(free_blocks);
591 NILFS_DEV_RO_ATTR(uuid);
592 NILFS_DEV_RO_ATTR(volume_name);
593 NILFS_DEV_RO_ATTR(README);
595 static struct attribute *nilfs_dev_attrs[] = {
596 NILFS_DEV_ATTR_LIST(revision),
597 NILFS_DEV_ATTR_LIST(blocksize),
598 NILFS_DEV_ATTR_LIST(device_size),
599 NILFS_DEV_ATTR_LIST(free_blocks),
600 NILFS_DEV_ATTR_LIST(uuid),
601 NILFS_DEV_ATTR_LIST(volume_name),
602 NILFS_DEV_ATTR_LIST(README),
606 static ssize_t nilfs_dev_attr_show(struct kobject *kobj,
607 struct attribute *attr, char *buf)
609 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
611 struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
614 return a->show ? a->show(a, nilfs, buf) : 0;
617 static ssize_t nilfs_dev_attr_store(struct kobject *kobj,
618 struct attribute *attr,
619 const char *buf, size_t len)
621 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
623 struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
626 return a->store ? a->store(a, nilfs, buf, len) : 0;
629 static void nilfs_dev_attr_release(struct kobject *kobj)
631 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
633 complete(&nilfs->ns_dev_kobj_unregister);
636 static const struct sysfs_ops nilfs_dev_attr_ops = {
637 .show = nilfs_dev_attr_show,
638 .store = nilfs_dev_attr_store,
641 static struct kobj_type nilfs_dev_ktype = {
642 .default_attrs = nilfs_dev_attrs,
643 .sysfs_ops = &nilfs_dev_attr_ops,
644 .release = nilfs_dev_attr_release,
647 int nilfs_sysfs_create_device_group(struct super_block *sb)
649 struct the_nilfs *nilfs = sb->s_fs_info;
650 size_t devgrp_size = sizeof(struct nilfs_sysfs_dev_subgroups);
653 nilfs->ns_dev_subgroups = kzalloc(devgrp_size, GFP_KERNEL);
654 if (unlikely(!nilfs->ns_dev_subgroups)) {
656 printk(KERN_ERR "NILFS: unable to allocate memory for device group\n");
657 goto failed_create_device_group;
660 nilfs->ns_dev_kobj.kset = nilfs_kset;
661 init_completion(&nilfs->ns_dev_kobj_unregister);
662 err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL,
665 goto free_dev_subgroups;
667 err = nilfs_sysfs_create_superblock_group(nilfs);
669 goto cleanup_dev_kobject;
671 err = nilfs_sysfs_create_segctor_group(nilfs);
673 goto delete_superblock_group;
677 delete_superblock_group:
678 nilfs_sysfs_delete_superblock_group(nilfs);
681 kobject_del(&nilfs->ns_dev_kobj);
684 kfree(nilfs->ns_dev_subgroups);
686 failed_create_device_group:
690 void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
692 nilfs_sysfs_delete_superblock_group(nilfs);
693 nilfs_sysfs_delete_segctor_group(nilfs);
694 kobject_del(&nilfs->ns_dev_kobj);
695 kfree(nilfs->ns_dev_subgroups);
698 /************************************************************************
699 * NILFS feature attrs *
700 ************************************************************************/
702 static ssize_t nilfs_feature_revision_show(struct kobject *kobj,
703 struct attribute *attr, char *buf)
705 return snprintf(buf, PAGE_SIZE, "%d.%d\n",
706 NILFS_CURRENT_REV, NILFS_MINOR_REV);
709 static const char features_readme_str[] =
710 "The features group contains attributes that describe NILFS file\n"
711 "system driver features.\n\n"
712 "(1) revision\n\tshow current revision of NILFS file system driver.\n";
714 static ssize_t nilfs_feature_README_show(struct kobject *kobj,
715 struct attribute *attr,
718 return snprintf(buf, PAGE_SIZE, features_readme_str);
721 NILFS_FEATURE_RO_ATTR(revision);
722 NILFS_FEATURE_RO_ATTR(README);
724 static struct attribute *nilfs_feature_attrs[] = {
725 NILFS_FEATURE_ATTR_LIST(revision),
726 NILFS_FEATURE_ATTR_LIST(README),
730 static const struct attribute_group nilfs_feature_attr_group = {
732 .attrs = nilfs_feature_attrs,
735 int __init nilfs_sysfs_init(void)
739 nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj);
742 printk(KERN_ERR "NILFS: unable to create sysfs entry: err %d\n",
744 goto failed_sysfs_init;
747 err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
749 printk(KERN_ERR "NILFS: unable to create feature group: err %d\n",
751 goto cleanup_sysfs_init;
757 kset_unregister(nilfs_kset);
763 void nilfs_sysfs_exit(void)
765 sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
766 kset_unregister(nilfs_kset);