diff options
author | Vyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com> | 2014-08-08 17:20:39 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-08 18:57:20 -0400 |
commit | da7141fb78db915680616e15677539fc8140cf53 (patch) | |
tree | fcec7b80ddf5bf6ff0b98b1ca7fa7610bf309432 /fs/nilfs2/sysfs.c | |
parent | aebe17f6844488ff0b824fbac28d9f342f7b078e (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/sysfs.c')
-rw-r--r-- | fs/nilfs2/sysfs.c | 168 |
1 files changed, 168 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 | |||
48 | static | ||
49 | ssize_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 | |||
60 | static | ||
61 | ssize_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 | |||
68 | static | ||
69 | ssize_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 | |||
79 | static | ||
80 | ssize_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 | |||
91 | static | ||
92 | ssize_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 | |||
101 | static | ||
102 | ssize_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 | |||
112 | static 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 | |||
122 | static 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 | |||
129 | NILFS_DEV_RO_ATTR(revision); | ||
130 | NILFS_DEV_RO_ATTR(blocksize); | ||
131 | NILFS_DEV_RO_ATTR(device_size); | ||
132 | NILFS_DEV_RO_ATTR(free_blocks); | ||
133 | NILFS_DEV_RO_ATTR(uuid); | ||
134 | NILFS_DEV_RO_ATTR(volume_name); | ||
135 | NILFS_DEV_RO_ATTR(README); | ||
136 | |||
137 | static 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 | |||
148 | static 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 | |||
159 | static 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 | |||
171 | static 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 | |||
178 | static const struct sysfs_ops nilfs_dev_attr_ops = { | ||
179 | .show = nilfs_dev_attr_show, | ||
180 | .store = nilfs_dev_attr_store, | ||
181 | }; | ||
182 | |||
183 | static 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 | |||
189 | int 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 | |||
203 | failed_create_device_group: | ||
204 | return err; | ||
205 | } | ||
206 | |||
207 | void 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 | ||