aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorVyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>2014-08-08 17:20:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:20 -0400
commitef43d5cd84b7d2ea09846de34e14be7d74be3e6f (patch)
tree67163715eb9012e931f9a7eefafe59a71ad20401 /fs
parentabc968dbf291955ac750ecf59e3baf2b529a8257 (diff)
nilfs2: add /sys/fs/nilfs2/<device>/segments group
This patch adds creation of /sys/fs/nilfs2/<device>/segments group. The segments group contains attributes that describe details about volume's segments: (1) segments_number - show number of segments on volume. (2) blocks_per_segment - show number of blocks in segment. (3) clean_segments - show count of clean segments. (4) dirty_segments - show count of dirty segments. Signed-off-by: Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> Cc: Vyacheslav Dubeyko <slava@dubeyko.com> Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Cc: Michael L. Semon <mlsemon35@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/nilfs2/sysfs.c99
-rw-r--r--fs/nilfs2/sysfs.h14
2 files changed, 112 insertions, 1 deletions
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index 61454a859e81..fe8e1411dc6a 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -112,6 +112,95 @@ void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
112} 112}
113 113
114/************************************************************************ 114/************************************************************************
115 * NILFS segments attrs *
116 ************************************************************************/
117
118static ssize_t
119nilfs_segments_segments_number_show(struct nilfs_segments_attr *attr,
120 struct the_nilfs *nilfs,
121 char *buf)
122{
123 return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_nsegments);
124}
125
126static ssize_t
127nilfs_segments_blocks_per_segment_show(struct nilfs_segments_attr *attr,
128 struct the_nilfs *nilfs,
129 char *buf)
130{
131 return snprintf(buf, PAGE_SIZE, "%lu\n", nilfs->ns_blocks_per_segment);
132}
133
134static ssize_t
135nilfs_segments_clean_segments_show(struct nilfs_segments_attr *attr,
136 struct the_nilfs *nilfs,
137 char *buf)
138{
139 unsigned long ncleansegs;
140
141 down_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
142 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
143 up_read(&NILFS_MDT(nilfs->ns_dat)->mi_sem);
144
145 return snprintf(buf, PAGE_SIZE, "%lu\n", ncleansegs);
146}
147
148static ssize_t
149nilfs_segments_dirty_segments_show(struct nilfs_segments_attr *attr,
150 struct the_nilfs *nilfs,
151 char *buf)
152{
153 struct nilfs_sustat sustat;
154 int err;
155
156 down_read(&nilfs->ns_segctor_sem);
157 err = nilfs_sufile_get_stat(nilfs->ns_sufile, &sustat);
158 up_read(&nilfs->ns_segctor_sem);
159 if (err < 0) {
160 printk(KERN_ERR "NILFS: unable to get segment stat: err=%d\n",
161 err);
162 return err;
163 }
164
165 return snprintf(buf, PAGE_SIZE, "%llu\n", sustat.ss_ndirtysegs);
166}
167
168static const char segments_readme_str[] =
169 "The segments group contains attributes that describe\n"
170 "details about volume's segments.\n\n"
171 "(1) segments_number\n\tshow number of segments on volume.\n\n"
172 "(2) blocks_per_segment\n\tshow number of blocks in segment.\n\n"
173 "(3) clean_segments\n\tshow count of clean segments.\n\n"
174 "(4) dirty_segments\n\tshow count of dirty segments.\n\n";
175
176static ssize_t
177nilfs_segments_README_show(struct nilfs_segments_attr *attr,
178 struct the_nilfs *nilfs,
179 char *buf)
180{
181 return snprintf(buf, PAGE_SIZE, segments_readme_str);
182}
183
184NILFS_SEGMENTS_RO_ATTR(segments_number);
185NILFS_SEGMENTS_RO_ATTR(blocks_per_segment);
186NILFS_SEGMENTS_RO_ATTR(clean_segments);
187NILFS_SEGMENTS_RO_ATTR(dirty_segments);
188NILFS_SEGMENTS_RO_ATTR(README);
189
190static struct attribute *nilfs_segments_attrs[] = {
191 NILFS_SEGMENTS_ATTR_LIST(segments_number),
192 NILFS_SEGMENTS_ATTR_LIST(blocks_per_segment),
193 NILFS_SEGMENTS_ATTR_LIST(clean_segments),
194 NILFS_SEGMENTS_ATTR_LIST(dirty_segments),
195 NILFS_SEGMENTS_ATTR_LIST(README),
196 NULL,
197};
198
199NILFS_DEV_INT_GROUP_OPS(segments, dev);
200NILFS_DEV_INT_GROUP_TYPE(segments, dev);
201NILFS_DEV_INT_GROUP_FNS(segments, dev);
202
203/************************************************************************
115 * NILFS segctor attrs * 204 * NILFS segctor attrs *
116 ************************************************************************/ 205 ************************************************************************/
117 206
@@ -664,10 +753,14 @@ int nilfs_sysfs_create_device_group(struct super_block *sb)
664 if (err) 753 if (err)
665 goto free_dev_subgroups; 754 goto free_dev_subgroups;
666 755
667 err = nilfs_sysfs_create_superblock_group(nilfs); 756 err = nilfs_sysfs_create_segments_group(nilfs);
668 if (err) 757 if (err)
669 goto cleanup_dev_kobject; 758 goto cleanup_dev_kobject;
670 759
760 err = nilfs_sysfs_create_superblock_group(nilfs);
761 if (err)
762 goto delete_segments_group;
763
671 err = nilfs_sysfs_create_segctor_group(nilfs); 764 err = nilfs_sysfs_create_segctor_group(nilfs);
672 if (err) 765 if (err)
673 goto delete_superblock_group; 766 goto delete_superblock_group;
@@ -677,6 +770,9 @@ int nilfs_sysfs_create_device_group(struct super_block *sb)
677delete_superblock_group: 770delete_superblock_group:
678 nilfs_sysfs_delete_superblock_group(nilfs); 771 nilfs_sysfs_delete_superblock_group(nilfs);
679 772
773delete_segments_group:
774 nilfs_sysfs_delete_segments_group(nilfs);
775
680cleanup_dev_kobject: 776cleanup_dev_kobject:
681 kobject_del(&nilfs->ns_dev_kobj); 777 kobject_del(&nilfs->ns_dev_kobj);
682 778
@@ -689,6 +785,7 @@ failed_create_device_group:
689 785
690void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs) 786void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
691{ 787{
788 nilfs_sysfs_delete_segments_group(nilfs);
692 nilfs_sysfs_delete_superblock_group(nilfs); 789 nilfs_sysfs_delete_superblock_group(nilfs);
693 nilfs_sysfs_delete_segctor_group(nilfs); 790 nilfs_sysfs_delete_segctor_group(nilfs);
694 kobject_del(&nilfs->ns_dev_kobj); 791 kobject_del(&nilfs->ns_dev_kobj);
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
index ad4d5bcc16f5..228bdd14f945 100644
--- a/fs/nilfs2/sysfs.h
+++ b/fs/nilfs2/sysfs.h
@@ -30,6 +30,8 @@
30 * @sg_superblock_kobj_unregister: completion state 30 * @sg_superblock_kobj_unregister: completion state
31 * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor 31 * @sg_segctor_kobj: /sys/fs/<nilfs>/<device>/segctor
32 * @sg_segctor_kobj_unregister: completion state 32 * @sg_segctor_kobj_unregister: completion state
33 * @sg_segments_kobj: /sys/fs/<nilfs>/<device>/segments
34 * @sg_segments_kobj_unregister: completion state
33 */ 35 */
34struct nilfs_sysfs_dev_subgroups { 36struct nilfs_sysfs_dev_subgroups {
35 /* /sys/fs/<nilfs>/<device>/superblock */ 37 /* /sys/fs/<nilfs>/<device>/superblock */
@@ -39,6 +41,10 @@ struct nilfs_sysfs_dev_subgroups {
39 /* /sys/fs/<nilfs>/<device>/segctor */ 41 /* /sys/fs/<nilfs>/<device>/segctor */
40 struct kobject sg_segctor_kobj; 42 struct kobject sg_segctor_kobj;
41 struct completion sg_segctor_kobj_unregister; 43 struct completion sg_segctor_kobj_unregister;
44
45 /* /sys/fs/<nilfs>/<device>/segments */
46 struct kobject sg_segments_kobj;
47 struct completion sg_segments_kobj_unregister;
42}; 48};
43 49
44#define NILFS_COMMON_ATTR_STRUCT(name) \ 50#define NILFS_COMMON_ATTR_STRUCT(name) \
@@ -62,6 +68,7 @@ struct nilfs_##name##_attr { \
62}; 68};
63 69
64NILFS_DEV_ATTR_STRUCT(dev); 70NILFS_DEV_ATTR_STRUCT(dev);
71NILFS_DEV_ATTR_STRUCT(segments);
65NILFS_DEV_ATTR_STRUCT(superblock); 72NILFS_DEV_ATTR_STRUCT(superblock);
66NILFS_DEV_ATTR_STRUCT(segctor); 73NILFS_DEV_ATTR_STRUCT(segctor);
67 74
@@ -92,6 +99,11 @@ NILFS_DEV_ATTR_STRUCT(segctor);
92#define NILFS_DEV_RW_ATTR(name) \ 99#define NILFS_DEV_RW_ATTR(name) \
93 NILFS_RW_ATTR(dev, name) 100 NILFS_RW_ATTR(dev, name)
94 101
102#define NILFS_SEGMENTS_RO_ATTR(name) \
103 NILFS_RO_ATTR(segments, name)
104#define NILFS_SEGMENTS_RW_ATTR(name) \
105 NILFS_RW_ATTR(segs_info, name)
106
95#define NILFS_SUPERBLOCK_RO_ATTR(name) \ 107#define NILFS_SUPERBLOCK_RO_ATTR(name) \
96 NILFS_RO_ATTR(superblock, name) 108 NILFS_RO_ATTR(superblock, name)
97#define NILFS_SUPERBLOCK_RW_ATTR(name) \ 109#define NILFS_SUPERBLOCK_RW_ATTR(name) \
@@ -108,6 +120,8 @@ NILFS_DEV_ATTR_STRUCT(segctor);
108 (&nilfs_feature_attr_##name.attr) 120 (&nilfs_feature_attr_##name.attr)
109#define NILFS_DEV_ATTR_LIST(name) \ 121#define NILFS_DEV_ATTR_LIST(name) \
110 (&nilfs_dev_attr_##name.attr) 122 (&nilfs_dev_attr_##name.attr)
123#define NILFS_SEGMENTS_ATTR_LIST(name) \
124 (&nilfs_segments_attr_##name.attr)
111#define NILFS_SUPERBLOCK_ATTR_LIST(name) \ 125#define NILFS_SUPERBLOCK_ATTR_LIST(name) \
112 (&nilfs_superblock_attr_##name.attr) 126 (&nilfs_superblock_attr_##name.attr)
113#define NILFS_SEGCTOR_ATTR_LIST(name) \ 127#define NILFS_SEGCTOR_ATTR_LIST(name) \