aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2
diff options
context:
space:
mode:
authorVyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>2014-08-08 17:20:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:20 -0400
commitaebe17f6844488ff0b824fbac28d9f342f7b078e (patch)
treec0573e1c431e8c11d6056eb05ba7a410aa036601 /fs/nilfs2
parent834b46c37a2900bc90b5f1c5a11815be5a025445 (diff)
nilfs2: add /sys/fs/nilfs2/features group
This patchset implements creation of sysfs groups and attributes with the purpose to show NILFS2 volume details, internal state of the driver and to manage internal state of NILFS2 driver. Sysfs is a virtual file system that exports information about devices and drivers from the kernel device model to user space, and is also used for configuration. NILFS2 is a complex file system that has segctor thread, GC thread, checkpoint/snapshot model and so on. Sysfs namespace provides native and easy way for: (1) getting info and statistics about volume state; (2) getting info and configuration of internal subsystems (segctor thread); (3) snapshots management. Suggested patchset provides basis for managing segctor thread behaviour and manipulation by snapshots. Currently, it informs only about segctor thread's internal parameters and about mounted snapshots. But sysfs interface can provide easy and simple way for deep management of segctor thread and snapshots. This patchset provides opportunity to manage interval of periodical update of superblock (in seconds). Default value is 10 seconds. Now a user can increase this value by means of nilfs2/<device>/superblock/sb_update_frequency attribute in the case of necessity. Also the patchset provides opportunity to get information easily about key volumes's parameters (free blocks, superblock write count, superblock update frequency, latest segment info, dirty data blocks count, count of clean segments, count of dirty segments and so on) in real time manner. Such information can be used in scripts for subtle management of filesystem. Implemented functionality creates such groups: (1) /sys/fs/nilfs2 - root group (2) /sys/fs/nilfs2/features - group contains attributes that describe NILFS file system driver features (3) /sys/fs/nilfs2/<device> - group contains attributes that describe file system partition's details (4) /sys/fs/nilfs2/<device>/superblock - group contains attributes that describe superblock's details (5) /sys/fs/nilfs2/<device>/segctor - group contains attributes that describe segctor thread activity details (6) /sys/fs/nilfs2/<device>/segments - group contains attributes that describe details about volume's segments (7) /sys/fs/nilfs2/<device>/checkpoints - group contains attributes that describe details about volume's checkpoints (8) /sys/fs/nilfs2/<device>/mounted_snapshots - group contains group for every mounted snapshot (9) /sys/fs/nilfs2/<device>/mounted_snapshots/<snapshot> - group contains details about mounted snapshot This patch (of 9): This patch adds code of creation /sys/fs/nilfs2 group and /sys/fs/nilfs2/features group. The features group contains attributes that describe NILFS file system driver features: (1) revision - show current revision of NILFS file system driver. There are two formats of timestamp output - seconds and human-readable format. Every showed timestamp has two sysfs files (time-<xxx> and time-<xxx>-secs). One sysfs file (time-<xxx>) shows time in human-readable format. Another sysfs file (time-<xxx>-secs) shows time in seconds. It was reported by Michael Semon that timestamp output in human-readable format should be changed from "2014-4-12 14:5:38" to "2014-04-12 14:05:38". Second version of the patch fixes this issue. Reported-by: Michael L. Semon <mlsemon35@gmail.com> Signed-off-by: Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> Cc: Vyacheslav Dubeyko <slava@dubeyko.com> Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/nilfs2')
-rw-r--r--fs/nilfs2/sysfs.c113
-rw-r--r--fs/nilfs2/sysfs.h61
2 files changed, 174 insertions, 0 deletions
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
new file mode 100644
index 000000000000..41b8f7039657
--- /dev/null
+++ b/fs/nilfs2/sysfs.c
@@ -0,0 +1,113 @@
1/*
2 * sysfs.c - sysfs support implementation.
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#include <linux/kobject.h>
21
22#include "nilfs.h"
23#include "mdt.h"
24#include "sufile.h"
25#include "cpfile.h"
26#include "sysfs.h"
27
28/* /sys/fs/<nilfs>/ */
29static struct kset *nilfs_kset;
30
31#define NILFS_SHOW_TIME(time_t_val, buf) ({ \
32 struct tm res; \
33 int count = 0; \
34 time_to_tm(time_t_val, 0, &res); \
35 res.tm_year += 1900; \
36 res.tm_mon += 1; \
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);\
41 count; \
42})
43
44/************************************************************************
45 * NILFS feature attrs *
46 ************************************************************************/
47
48static ssize_t nilfs_feature_revision_show(struct kobject *kobj,
49 struct attribute *attr, char *buf)
50{
51 return snprintf(buf, PAGE_SIZE, "%d.%d\n",
52 NILFS_CURRENT_REV, NILFS_MINOR_REV);
53}
54
55static const char features_readme_str[] =
56 "The features group contains attributes that describe NILFS file\n"
57 "system driver features.\n\n"
58 "(1) revision\n\tshow current revision of NILFS file system driver.\n";
59
60static ssize_t nilfs_feature_README_show(struct kobject *kobj,
61 struct attribute *attr,
62 char *buf)
63{
64 return snprintf(buf, PAGE_SIZE, features_readme_str);
65}
66
67NILFS_FEATURE_RO_ATTR(revision);
68NILFS_FEATURE_RO_ATTR(README);
69
70static struct attribute *nilfs_feature_attrs[] = {
71 NILFS_FEATURE_ATTR_LIST(revision),
72 NILFS_FEATURE_ATTR_LIST(README),
73 NULL,
74};
75
76static const struct attribute_group nilfs_feature_attr_group = {
77 .name = "features",
78 .attrs = nilfs_feature_attrs,
79};
80
81int __init nilfs_sysfs_init(void)
82{
83 int err;
84
85 nilfs_kset = kset_create_and_add(NILFS_ROOT_GROUP_NAME, NULL, fs_kobj);
86 if (!nilfs_kset) {
87 err = -ENOMEM;
88 printk(KERN_ERR "NILFS: unable to create sysfs entry: err %d\n",
89 err);
90 goto failed_sysfs_init;
91 }
92
93 err = sysfs_create_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
94 if (unlikely(err)) {
95 printk(KERN_ERR "NILFS: unable to create feature group: err %d\n",
96 err);
97 goto cleanup_sysfs_init;
98 }
99
100 return 0;
101
102cleanup_sysfs_init:
103 kset_unregister(nilfs_kset);
104
105failed_sysfs_init:
106 return err;
107}
108
109void nilfs_sysfs_exit(void)
110{
111 sysfs_remove_group(&nilfs_kset->kobj, &nilfs_feature_attr_group);
112 kset_unregister(nilfs_kset);
113}
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
new file mode 100644
index 000000000000..0aed24661052
--- /dev/null
+++ b/fs/nilfs2/sysfs.h
@@ -0,0 +1,61 @@
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
27#define NILFS_COMMON_ATTR_STRUCT(name) \
28struct nilfs_##name##_attr { \
29 struct attribute attr; \
30 ssize_t (*show)(struct kobject *, struct attribute *, \
31 char *); \
32 ssize_t (*store)(struct kobject *, struct attribute *, \
33 const char *, size_t); \
34};
35
36NILFS_COMMON_ATTR_STRUCT(feature);
37
38#define NILFS_ATTR(type, name, mode, show, store) \
39 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
40 __ATTR(name, mode, show, store)
41
42#define NILFS_INFO_ATTR(type, name) \
43 NILFS_ATTR(type, name, 0444, NULL, NULL)
44#define NILFS_RO_ATTR(type, name) \
45 NILFS_ATTR(type, name, 0444, nilfs_##type##_##name##_show, NULL)
46#define NILFS_RW_ATTR(type, name) \
47 NILFS_ATTR(type, name, 0644, \
48 nilfs_##type##_##name##_show, \
49 nilfs_##type##_##name##_store)
50
51#define NILFS_FEATURE_INFO_ATTR(name) \
52 NILFS_INFO_ATTR(feature, name)
53#define NILFS_FEATURE_RO_ATTR(name) \
54 NILFS_RO_ATTR(feature, name)
55#define NILFS_FEATURE_RW_ATTR(name) \
56 NILFS_RW_ATTR(feature, name)
57
58#define NILFS_FEATURE_ATTR_LIST(name) \
59 (&nilfs_feature_attr_##name.attr)
60
61#endif /* _NILFS_SYSFS_H */