aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVyacheslav Dubeyko <Vyacheslav.Dubeyko@hgst.com>2014-08-08 17:20:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:21 -0400
commita5a7332a291b55beb0863b119816d12ffc04dfb0 (patch)
tree4c217b1629b4f6931e68dcc9abf790f0fa682119
parenta2ecb791a9d6e71a2d37d66034475a92ebc7e02c (diff)
nilfs2: add /sys/fs/nilfs2/<device>/mounted_snapshots/<snapshot> group
This patch adds creation of <snapshot> group for every mounted snapshot in /sys/fs/nilfs2/<device>/mounted_snapshots group. The group contains details about mounted snapshot: (1) inodes_count - show number of inodes for snapshot. (2) blocks_count - show number of blocks for snapshot. 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>
-rw-r--r--Documentation/ABI/testing/sysfs-fs-nilfs219
-rw-r--r--fs/nilfs2/sysfs.c118
-rw-r--r--fs/nilfs2/sysfs.h20
-rw-r--r--fs/nilfs2/the_nilfs.h6
4 files changed, 163 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-nilfs2 b/Documentation/ABI/testing/sysfs-fs-nilfs2
index 29dbc8f8bcbd..304ba84a973a 100644
--- a/Documentation/ABI/testing/sysfs-fs-nilfs2
+++ b/Documentation/ABI/testing/sysfs-fs-nilfs2
@@ -248,3 +248,22 @@ Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
248Description: 248Description:
249 Describe content of /sys/fs/nilfs2/<device>/mounted_snapshots 249 Describe content of /sys/fs/nilfs2/<device>/mounted_snapshots
250 group. 250 group.
251
252What: /sys/fs/nilfs2/<device>/mounted_snapshots/<id>/inodes_count
253Date: April 2014
254Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
255Description:
256 Show number of inodes for snapshot.
257
258What: /sys/fs/nilfs2/<device>/mounted_snapshots/<id>/blocks_count
259Date: April 2014
260Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
261Description:
262 Show number of blocks for snapshot.
263
264What: /sys/fs/nilfs2/<device>/mounted_snapshots/<id>/README
265Date: April 2014
266Contact: "Vyacheslav Dubeyko" <slava@dubeyko.com>
267Description:
268 Describe attributes of /sys/fs/nilfs2/<device>/mounted_snapshots/<id>
269 group.
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index fc0c961d486a..0f6148c8121a 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -112,6 +112,124 @@ void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
112} 112}
113 113
114/************************************************************************ 114/************************************************************************
115 * NILFS snapshot attrs *
116 ************************************************************************/
117
118static ssize_t
119nilfs_snapshot_inodes_count_show(struct nilfs_snapshot_attr *attr,
120 struct nilfs_root *root, char *buf)
121{
122 return snprintf(buf, PAGE_SIZE, "%llu\n",
123 (unsigned long long)atomic64_read(&root->inodes_count));
124}
125
126static ssize_t
127nilfs_snapshot_blocks_count_show(struct nilfs_snapshot_attr *attr,
128 struct nilfs_root *root, char *buf)
129{
130 return snprintf(buf, PAGE_SIZE, "%llu\n",
131 (unsigned long long)atomic64_read(&root->blocks_count));
132}
133
134static const char snapshot_readme_str[] =
135 "The group contains details about mounted snapshot.\n\n"
136 "(1) inodes_count\n\tshow number of inodes for snapshot.\n\n"
137 "(2) blocks_count\n\tshow number of blocks for snapshot.\n\n";
138
139static ssize_t
140nilfs_snapshot_README_show(struct nilfs_snapshot_attr *attr,
141 struct nilfs_root *root, char *buf)
142{
143 return snprintf(buf, PAGE_SIZE, snapshot_readme_str);
144}
145
146NILFS_SNAPSHOT_RO_ATTR(inodes_count);
147NILFS_SNAPSHOT_RO_ATTR(blocks_count);
148NILFS_SNAPSHOT_RO_ATTR(README);
149
150static struct attribute *nilfs_snapshot_attrs[] = {
151 NILFS_SNAPSHOT_ATTR_LIST(inodes_count),
152 NILFS_SNAPSHOT_ATTR_LIST(blocks_count),
153 NILFS_SNAPSHOT_ATTR_LIST(README),
154 NULL,
155};
156
157static ssize_t nilfs_snapshot_attr_show(struct kobject *kobj,
158 struct attribute *attr, char *buf)
159{
160 struct nilfs_root *root =
161 container_of(kobj, struct nilfs_root, snapshot_kobj);
162 struct nilfs_snapshot_attr *a =
163 container_of(attr, struct nilfs_snapshot_attr, attr);
164
165 return a->show ? a->show(a, root, buf) : 0;
166}
167
168static ssize_t nilfs_snapshot_attr_store(struct kobject *kobj,
169 struct attribute *attr,
170 const char *buf, size_t len)
171{
172 struct nilfs_root *root =
173 container_of(kobj, struct nilfs_root, snapshot_kobj);
174 struct nilfs_snapshot_attr *a =
175 container_of(attr, struct nilfs_snapshot_attr, attr);
176
177 return a->store ? a->store(a, root, buf, len) : 0;
178}
179
180static void nilfs_snapshot_attr_release(struct kobject *kobj)
181{
182 struct nilfs_root *root = container_of(kobj, struct nilfs_root,
183 snapshot_kobj);
184 complete(&root->snapshot_kobj_unregister);
185}
186
187static const struct sysfs_ops nilfs_snapshot_attr_ops = {
188 .show = nilfs_snapshot_attr_show,
189 .store = nilfs_snapshot_attr_store,
190};
191
192static struct kobj_type nilfs_snapshot_ktype = {
193 .default_attrs = nilfs_snapshot_attrs,
194 .sysfs_ops = &nilfs_snapshot_attr_ops,
195 .release = nilfs_snapshot_attr_release,
196};
197
198int nilfs_sysfs_create_snapshot_group(struct nilfs_root *root)
199{
200 struct the_nilfs *nilfs;
201 struct kobject *parent;
202 int err;
203
204 nilfs = root->nilfs;
205 parent = &nilfs->ns_dev_subgroups->sg_mounted_snapshots_kobj;
206 root->snapshot_kobj.kset = nilfs_kset;
207 init_completion(&root->snapshot_kobj_unregister);
208
209 if (root->cno == NILFS_CPTREE_CURRENT_CNO) {
210 err = kobject_init_and_add(&root->snapshot_kobj,
211 &nilfs_snapshot_ktype,
212 &nilfs->ns_dev_kobj,
213 "current_checkpoint");
214 } else {
215 err = kobject_init_and_add(&root->snapshot_kobj,
216 &nilfs_snapshot_ktype,
217 parent,
218 "%llu", root->cno);
219 }
220
221 if (err)
222 return err;
223
224 return 0;
225}
226
227void nilfs_sysfs_delete_snapshot_group(struct nilfs_root *root)
228{
229 kobject_del(&root->snapshot_kobj);
230}
231
232/************************************************************************
115 * NILFS mounted snapshots attrs * 233 * NILFS mounted snapshots attrs *
116 ************************************************************************/ 234 ************************************************************************/
117 235
diff --git a/fs/nilfs2/sysfs.h b/fs/nilfs2/sysfs.h
index 4e84e230e9dd..677e3a1a8370 100644
--- a/fs/nilfs2/sysfs.h
+++ b/fs/nilfs2/sysfs.h
@@ -86,6 +86,17 @@ NILFS_DEV_ATTR_STRUCT(checkpoints);
86NILFS_DEV_ATTR_STRUCT(superblock); 86NILFS_DEV_ATTR_STRUCT(superblock);
87NILFS_DEV_ATTR_STRUCT(segctor); 87NILFS_DEV_ATTR_STRUCT(segctor);
88 88
89#define NILFS_CP_ATTR_STRUCT(name) \
90struct nilfs_##name##_attr { \
91 struct attribute attr; \
92 ssize_t (*show)(struct nilfs_##name##_attr *, struct nilfs_root *, \
93 char *); \
94 ssize_t (*store)(struct nilfs_##name##_attr *, struct nilfs_root *, \
95 const char *, size_t); \
96};
97
98NILFS_CP_ATTR_STRUCT(snapshot);
99
89#define NILFS_ATTR(type, name, mode, show, store) \ 100#define NILFS_ATTR(type, name, mode, show, store) \
90 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \ 101 static struct nilfs_##type##_attr nilfs_##type##_attr_##name = \
91 __ATTR(name, mode, show, store) 102 __ATTR(name, mode, show, store)
@@ -126,6 +137,13 @@ NILFS_DEV_ATTR_STRUCT(segctor);
126#define NILFS_CHECKPOINTS_RW_ATTR(name) \ 137#define NILFS_CHECKPOINTS_RW_ATTR(name) \
127 NILFS_RW_ATTR(checkpoints, name) 138 NILFS_RW_ATTR(checkpoints, name)
128 139
140#define NILFS_SNAPSHOT_INFO_ATTR(name) \
141 NILFS_INFO_ATTR(snapshot, name)
142#define NILFS_SNAPSHOT_RO_ATTR(name) \
143 NILFS_RO_ATTR(snapshot, name)
144#define NILFS_SNAPSHOT_RW_ATTR(name) \
145 NILFS_RW_ATTR(snapshot, name)
146
129#define NILFS_SUPERBLOCK_RO_ATTR(name) \ 147#define NILFS_SUPERBLOCK_RO_ATTR(name) \
130 NILFS_RO_ATTR(superblock, name) 148 NILFS_RO_ATTR(superblock, name)
131#define NILFS_SUPERBLOCK_RW_ATTR(name) \ 149#define NILFS_SUPERBLOCK_RW_ATTR(name) \
@@ -148,6 +166,8 @@ NILFS_DEV_ATTR_STRUCT(segctor);
148 (&nilfs_mounted_snapshots_attr_##name.attr) 166 (&nilfs_mounted_snapshots_attr_##name.attr)
149#define NILFS_CHECKPOINTS_ATTR_LIST(name) \ 167#define NILFS_CHECKPOINTS_ATTR_LIST(name) \
150 (&nilfs_checkpoints_attr_##name.attr) 168 (&nilfs_checkpoints_attr_##name.attr)
169#define NILFS_SNAPSHOT_ATTR_LIST(name) \
170 (&nilfs_snapshot_attr_##name.attr)
151#define NILFS_SUPERBLOCK_ATTR_LIST(name) \ 171#define NILFS_SUPERBLOCK_ATTR_LIST(name) \
152 (&nilfs_superblock_attr_##name.attr) 172 (&nilfs_superblock_attr_##name.attr)
153#define NILFS_SEGCTOR_ATTR_LIST(name) \ 173#define NILFS_SEGCTOR_ATTR_LIST(name) \
diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h
index 7fe822307f98..d01ead1bea9a 100644
--- a/fs/nilfs2/the_nilfs.h
+++ b/fs/nilfs2/the_nilfs.h
@@ -243,6 +243,8 @@ THE_NILFS_FNS(SB_DIRTY, sb_dirty)
243 * @ifile: inode file 243 * @ifile: inode file
244 * @inodes_count: number of inodes 244 * @inodes_count: number of inodes
245 * @blocks_count: number of blocks 245 * @blocks_count: number of blocks
246 * @snapshot_kobj: /sys/fs/<nilfs>/<device>/mounted_snapshots/<snapshot>
247 * @snapshot_kobj_unregister: completion state for kernel object
246 */ 248 */
247struct nilfs_root { 249struct nilfs_root {
248 __u64 cno; 250 __u64 cno;
@@ -254,6 +256,10 @@ struct nilfs_root {
254 256
255 atomic64_t inodes_count; 257 atomic64_t inodes_count;
256 atomic64_t blocks_count; 258 atomic64_t blocks_count;
259
260 /* /sys/fs/<nilfs>/<device>/mounted_snapshots/<snapshot> */
261 struct kobject snapshot_kobj;
262 struct completion snapshot_kobj_unregister;
257}; 263};
258 264
259/* Special checkpoint number */ 265/* Special checkpoint number */