aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2
diff options
context:
space:
mode:
authorVyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>2014-08-08 17:20:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:20 -0400
commitda7141fb78db915680616e15677539fc8140cf53 (patch)
treefcec7b80ddf5bf6ff0b98b1ca7fa7610bf309432 /fs/nilfs2
parentaebe17f6844488ff0b824fbac28d9f342f7b078e (diff)
nilfs2: add /sys/fs/nilfs2/<device> group
This patch adds creation of /sys/fs/nilfs2/<device> group. The <device> group contains attributes that describe file system partition's details: (1) revision - show NILFS file system revision. (2) blocksize - show volume block size in bytes. (3) device_size - show volume size in bytes. (4) free_blocks - show count of free blocks on volume. (5) uuid - show volume's UUID. (6) volume_name - show volume's name. 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/nilfs2')
-rw-r--r--fs/nilfs2/sysfs.c168
-rw-r--r--fs/nilfs2/sysfs.h20
-rw-r--r--fs/nilfs2/the_nilfs.h6
3 files changed, 194 insertions, 0 deletions
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index 41b8f7039657..780d0f5bbe88 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -42,6 +42,174 @@ static struct kset *nilfs_kset;
42}) 42})
43 43
44/************************************************************************ 44/************************************************************************
45 * NILFS device attrs *
46 ************************************************************************/
47
48static
49ssize_t nilfs_dev_revision_show(struct nilfs_dev_attr *attr,
50 struct the_nilfs *nilfs,
51 char *buf)
52{
53 struct nilfs_super_block **sbp = nilfs->ns_sbp;
54 u32 major = le32_to_cpu(sbp[0]->s_rev_level);
55 u16 minor = le16_to_cpu(sbp[0]->s_minor_rev_level);
56
57 return snprintf(buf, PAGE_SIZE, "%d.%d\n", major, minor);
58}
59
60static
61ssize_t nilfs_dev_blocksize_show(struct nilfs_dev_attr *attr,
62 struct the_nilfs *nilfs,
63 char *buf)
64{
65 return snprintf(buf, PAGE_SIZE, "%u\n", nilfs->ns_blocksize);
66}
67
68static
69ssize_t nilfs_dev_device_size_show(struct nilfs_dev_attr *attr,
70 struct the_nilfs *nilfs,
71 char *buf)
72{
73 struct nilfs_super_block **sbp = nilfs->ns_sbp;
74 u64 dev_size = le64_to_cpu(sbp[0]->s_dev_size);
75
76 return snprintf(buf, PAGE_SIZE, "%llu\n", dev_size);
77}
78
79static
80ssize_t nilfs_dev_free_blocks_show(struct nilfs_dev_attr *attr,
81 struct the_nilfs *nilfs,
82 char *buf)
83{
84 sector_t free_blocks = 0;
85
86 nilfs_count_free_blocks(nilfs, &free_blocks);
87 return snprintf(buf, PAGE_SIZE, "%llu\n",
88 (unsigned long long)free_blocks);
89}
90
91static
92ssize_t nilfs_dev_uuid_show(struct nilfs_dev_attr *attr,
93 struct the_nilfs *nilfs,
94 char *buf)
95{
96 struct nilfs_super_block **sbp = nilfs->ns_sbp;
97
98 return snprintf(buf, PAGE_SIZE, "%pUb\n", sbp[0]->s_uuid);
99}
100
101static
102ssize_t nilfs_dev_volume_name_show(struct nilfs_dev_attr *attr,
103 struct the_nilfs *nilfs,
104 char *buf)
105{
106 struct nilfs_super_block **sbp = nilfs->ns_sbp;
107
108 return scnprintf(buf, sizeof(sbp[0]->s_volume_name), "%s\n",
109 sbp[0]->s_volume_name);
110}
111
112static const char dev_readme_str[] =
113 "The <device> group contains attributes that describe file system\n"
114 "partition's details.\n\n"
115 "(1) revision\n\tshow NILFS file system revision.\n\n"
116 "(2) blocksize\n\tshow volume block size in bytes.\n\n"
117 "(3) device_size\n\tshow volume size in bytes.\n\n"
118 "(4) free_blocks\n\tshow count of free blocks on volume.\n\n"
119 "(5) uuid\n\tshow volume's UUID.\n\n"
120 "(6) volume_name\n\tshow volume's name.\n\n";
121
122static ssize_t nilfs_dev_README_show(struct nilfs_dev_attr *attr,
123 struct the_nilfs *nilfs,
124 char *buf)
125{
126 return snprintf(buf, PAGE_SIZE, dev_readme_str);
127}
128
129NILFS_DEV_RO_ATTR(revision);
130NILFS_DEV_RO_ATTR(blocksize);
131NILFS_DEV_RO_ATTR(device_size);
132NILFS_DEV_RO_ATTR(free_blocks);
133NILFS_DEV_RO_ATTR(uuid);
134NILFS_DEV_RO_ATTR(volume_name);
135NILFS_DEV_RO_ATTR(README);
136
137static struct attribute *nilfs_dev_attrs[] = {
138 NILFS_DEV_ATTR_LIST(revision),
139 NILFS_DEV_ATTR_LIST(blocksize),
140 NILFS_DEV_ATTR_LIST(device_size),
141 NILFS_DEV_ATTR_LIST(free_blocks),
142 NILFS_DEV_ATTR_LIST(uuid),
143 NILFS_DEV_ATTR_LIST(volume_name),
144 NILFS_DEV_ATTR_LIST(README),
145 NULL,
146};
147
148static ssize_t nilfs_dev_attr_show(struct kobject *kobj,
149 struct attribute *attr, char *buf)
150{
151 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
152 ns_dev_kobj);
153 struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
154 attr);
155
156 return a->show ? a->show(a, nilfs, buf) : 0;
157}
158
159static ssize_t nilfs_dev_attr_store(struct kobject *kobj,
160 struct attribute *attr,
161 const char *buf, size_t len)
162{
163 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
164 ns_dev_kobj);
165 struct nilfs_dev_attr *a = container_of(attr, struct nilfs_dev_attr,
166 attr);
167
168 return a->store ? a->store(a, nilfs, buf, len) : 0;
169}
170
171static void nilfs_dev_attr_release(struct kobject *kobj)
172{
173 struct the_nilfs *nilfs = container_of(kobj, struct the_nilfs,
174 ns_dev_kobj);
175 complete(&nilfs->ns_dev_kobj_unregister);
176}
177
178static const struct sysfs_ops nilfs_dev_attr_ops = {
179 .show = nilfs_dev_attr_show,
180 .store = nilfs_dev_attr_store,
181};
182
183static struct kobj_type nilfs_dev_ktype = {
184 .default_attrs = nilfs_dev_attrs,
185 .sysfs_ops = &nilfs_dev_attr_ops,
186 .release = nilfs_dev_attr_release,
187};
188
189int nilfs_sysfs_create_device_group(struct super_block *sb)
190{
191 struct the_nilfs *nilfs = sb->s_fs_info;
192 int err;
193
194 nilfs->ns_dev_kobj.kset = nilfs_kset;
195 init_completion(&nilfs->ns_dev_kobj_unregister);
196 err = kobject_init_and_add(&nilfs->ns_dev_kobj, &nilfs_dev_ktype, NULL,
197 "%s", sb->s_id);
198 if (err)
199 goto failed_create_device_group;
200
201 return 0;
202
203failed_create_device_group:
204 return err;
205}
206
207void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
208{
209 kobject_del(&nilfs->ns_dev_kobj);
210}
211
212/************************************************************************
45 * NILFS feature attrs * 213 * NILFS feature attrs *
46 ************************************************************************/ 214 ************************************************************************/
47 215
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
index 0aed24661052..2353b28c2796 100644
--- a/fs/nilfs2/sysfs.h
+++ b/fs/nilfs2/sysfs.h
@@ -35,6 +35,17 @@ struct nilfs_##name##_attr { \
35 35
36NILFS_COMMON_ATTR_STRUCT(feature); 36NILFS_COMMON_ATTR_STRUCT(feature);
37 37
38#define NILFS_DEV_ATTR_STRUCT(name) \
39struct nilfs_##name##_attr { \
40 struct attribute attr; \
41 ssize_t (*show)(struct nilfs_##name##_attr *, struct the_nilfs *, \
42 char *); \
43 ssize_t (*store)(struct nilfs_##name##_attr *, struct the_nilfs *, \
44 const char *, size_t); \
45};
46
47NILFS_DEV_ATTR_STRUCT(dev);
48
38#define NILFS_ATTR(type, name, mode, show, store) \ 49#define NILFS_ATTR(type, name, mode, show, store) \
39 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \ 50 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
40 __ATTR(name, mode, show, store) 51 __ATTR(name, mode, show, store)
@@ -55,7 +66,16 @@ NILFS_COMMON_ATTR_STRUCT(feature);
55#define NILFS_FEATURE_RW_ATTR(name) \ 66#define NILFS_FEATURE_RW_ATTR(name) \
56 NILFS_RW_ATTR(feature, name) 67 NILFS_RW_ATTR(feature, name)
57 68
69#define NILFS_DEV_INFO_ATTR(name) \
70 NILFS_INFO_ATTR(dev, name)
71#define NILFS_DEV_RO_ATTR(name) \
72 NILFS_RO_ATTR(dev, name)
73#define NILFS_DEV_RW_ATTR(name) \
74 NILFS_RW_ATTR(dev, name)
75
58#define NILFS_FEATURE_ATTR_LIST(name) \ 76#define NILFS_FEATURE_ATTR_LIST(name) \
59 (&nilfs_feature_attr_##name.attr) 77 (&nilfs_feature_attr_##name.attr)
78#define NILFS_DEV_ATTR_LIST(name) \
79 (&nilfs_dev_attr_##name.attr)
60 80
61#endif /* _NILFS_SYSFS_H */ 81#endif /* _NILFS_SYSFS_H */
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index de8cc53b4a5c..34bc7bd57b0b 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -95,6 +95,8 @@ enum {
95 * @ns_inode_size: size of on-disk inode 95 * @ns_inode_size: size of on-disk inode
96 * @ns_first_ino: first not-special inode number 96 * @ns_first_ino: first not-special inode number
97 * @ns_crc_seed: seed value of CRC32 calculation 97 * @ns_crc_seed: seed value of CRC32 calculation
98 * @ns_dev_kobj: /sys/fs/<nilfs>/<device>
99 * @ns_dev_kobj_unregister: completion state
98 */ 100 */
99struct the_nilfs { 101struct the_nilfs {
100 unsigned long ns_flags; 102 unsigned long ns_flags;
@@ -188,6 +190,10 @@ struct the_nilfs {
188 int ns_inode_size; 190 int ns_inode_size;
189 int ns_first_ino; 191 int ns_first_ino;
190 u32 ns_crc_seed; 192 u32 ns_crc_seed;
193
194 /* /sys/fs/<nilfs>/<device> */
195 struct kobject ns_dev_kobj;
196 struct completion ns_dev_kobj_unregister;
191}; 197};
192 198
193#define THE_NILFS_FNS(bit, name) \ 199#define THE_NILFS_FNS(bit, name) \