aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nilfs2/sysfs.c')
-rw-r--r--fs/nilfs2/sysfs.c123
1 files changed, 122 insertions, 1 deletions
diff --git a/fs/nilfs2/sysfs.c b/fs/nilfs2/sysfs.c
index fe8e1411dc6a..5cc735fcc1d5 100644
--- a/fs/nilfs2/sysfs.c
+++ b/fs/nilfs2/sysfs.c
@@ -112,6 +112,119 @@ void nilfs_sysfs_delete_##name##_group(struct the_nilfs *nilfs) \
112} 112}
113 113
114/************************************************************************ 114/************************************************************************
115 * NILFS checkpoints attrs *
116 ************************************************************************/
117
118static ssize_t
119nilfs_checkpoints_checkpoints_number_show(struct nilfs_checkpoints_attr *attr,
120 struct the_nilfs *nilfs,
121 char *buf)
122{
123 __u64 ncheckpoints;
124 struct nilfs_cpstat cpstat;
125 int err;
126
127 down_read(&nilfs->ns_segctor_sem);
128 err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
129 up_read(&nilfs->ns_segctor_sem);
130 if (err < 0) {
131 printk(KERN_ERR "NILFS: unable to get checkpoint stat: err=%d\n",
132 err);
133 return err;
134 }
135
136 ncheckpoints = cpstat.cs_ncps;
137
138 return snprintf(buf, PAGE_SIZE, "%llu\n", ncheckpoints);
139}
140
141static ssize_t
142nilfs_checkpoints_snapshots_number_show(struct nilfs_checkpoints_attr *attr,
143 struct the_nilfs *nilfs,
144 char *buf)
145{
146 __u64 nsnapshots;
147 struct nilfs_cpstat cpstat;
148 int err;
149
150 down_read(&nilfs->ns_segctor_sem);
151 err = nilfs_cpfile_get_stat(nilfs->ns_cpfile, &cpstat);
152 up_read(&nilfs->ns_segctor_sem);
153 if (err < 0) {
154 printk(KERN_ERR "NILFS: unable to get checkpoint stat: err=%d\n",
155 err);
156 return err;
157 }
158
159 nsnapshots = cpstat.cs_nsss;
160
161 return snprintf(buf, PAGE_SIZE, "%llu\n", nsnapshots);
162}
163
164static ssize_t
165nilfs_checkpoints_last_seg_checkpoint_show(struct nilfs_checkpoints_attr *attr,
166 struct the_nilfs *nilfs,
167 char *buf)
168{
169 __u64 last_cno;
170
171 spin_lock(&nilfs->ns_last_segment_lock);
172 last_cno = nilfs->ns_last_cno;
173 spin_unlock(&nilfs->ns_last_segment_lock);
174
175 return snprintf(buf, PAGE_SIZE, "%llu\n", last_cno);
176}
177
178static ssize_t
179nilfs_checkpoints_next_checkpoint_show(struct nilfs_checkpoints_attr *attr,
180 struct the_nilfs *nilfs,
181 char *buf)
182{
183 __u64 cno;
184
185 down_read(&nilfs->ns_sem);
186 cno = nilfs->ns_cno;
187 up_read(&nilfs->ns_sem);
188
189 return snprintf(buf, PAGE_SIZE, "%llu\n", cno);
190}
191
192static const char checkpoints_readme_str[] =
193 "The checkpoints group contains attributes that describe\n"
194 "details about volume's checkpoints.\n\n"
195 "(1) checkpoints_number\n\tshow number of checkpoints on volume.\n\n"
196 "(2) snapshots_number\n\tshow number of snapshots on volume.\n\n"
197 "(3) last_seg_checkpoint\n"
198 "\tshow checkpoint number of the latest segment.\n\n"
199 "(4) next_checkpoint\n\tshow next checkpoint number.\n\n";
200
201static ssize_t
202nilfs_checkpoints_README_show(struct nilfs_checkpoints_attr *attr,
203 struct the_nilfs *nilfs, char *buf)
204{
205 return snprintf(buf, PAGE_SIZE, checkpoints_readme_str);
206}
207
208NILFS_CHECKPOINTS_RO_ATTR(checkpoints_number);
209NILFS_CHECKPOINTS_RO_ATTR(snapshots_number);
210NILFS_CHECKPOINTS_RO_ATTR(last_seg_checkpoint);
211NILFS_CHECKPOINTS_RO_ATTR(next_checkpoint);
212NILFS_CHECKPOINTS_RO_ATTR(README);
213
214static struct attribute *nilfs_checkpoints_attrs[] = {
215 NILFS_CHECKPOINTS_ATTR_LIST(checkpoints_number),
216 NILFS_CHECKPOINTS_ATTR_LIST(snapshots_number),
217 NILFS_CHECKPOINTS_ATTR_LIST(last_seg_checkpoint),
218 NILFS_CHECKPOINTS_ATTR_LIST(next_checkpoint),
219 NILFS_CHECKPOINTS_ATTR_LIST(README),
220 NULL,
221};
222
223NILFS_DEV_INT_GROUP_OPS(checkpoints, dev);
224NILFS_DEV_INT_GROUP_TYPE(checkpoints, dev);
225NILFS_DEV_INT_GROUP_FNS(checkpoints, dev);
226
227/************************************************************************
115 * NILFS segments attrs * 228 * NILFS segments attrs *
116 ************************************************************************/ 229 ************************************************************************/
117 230
@@ -753,10 +866,14 @@ int nilfs_sysfs_create_device_group(struct super_block *sb)
753 if (err) 866 if (err)
754 goto free_dev_subgroups; 867 goto free_dev_subgroups;
755 868
756 err = nilfs_sysfs_create_segments_group(nilfs); 869 err = nilfs_sysfs_create_checkpoints_group(nilfs);
757 if (err) 870 if (err)
758 goto cleanup_dev_kobject; 871 goto cleanup_dev_kobject;
759 872
873 err = nilfs_sysfs_create_segments_group(nilfs);
874 if (err)
875 goto delete_checkpoints_group;
876
760 err = nilfs_sysfs_create_superblock_group(nilfs); 877 err = nilfs_sysfs_create_superblock_group(nilfs);
761 if (err) 878 if (err)
762 goto delete_segments_group; 879 goto delete_segments_group;
@@ -773,6 +890,9 @@ delete_superblock_group:
773delete_segments_group: 890delete_segments_group:
774 nilfs_sysfs_delete_segments_group(nilfs); 891 nilfs_sysfs_delete_segments_group(nilfs);
775 892
893delete_checkpoints_group:
894 nilfs_sysfs_delete_checkpoints_group(nilfs);
895
776cleanup_dev_kobject: 896cleanup_dev_kobject:
777 kobject_del(&nilfs->ns_dev_kobj); 897 kobject_del(&nilfs->ns_dev_kobj);
778 898
@@ -785,6 +905,7 @@ failed_create_device_group:
785 905
786void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs) 906void nilfs_sysfs_delete_device_group(struct the_nilfs *nilfs)
787{ 907{
908 nilfs_sysfs_delete_checkpoints_group(nilfs);
788 nilfs_sysfs_delete_segments_group(nilfs); 909 nilfs_sysfs_delete_segments_group(nilfs);
789 nilfs_sysfs_delete_superblock_group(nilfs); 910 nilfs_sysfs_delete_superblock_group(nilfs);
790 nilfs_sysfs_delete_segctor_group(nilfs); 911 nilfs_sysfs_delete_segctor_group(nilfs);