aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-06-28 04:49:29 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-07-22 21:02:10 -0400
commit7ecaa46cfea453238a369b3019739d50ff5d7c37 (patch)
treec69911a31c3a2cd4966979de2d34764e08471f2a
parentbde4e696e4a527c3cc579ed77e4844d11ca17e12 (diff)
nilfs2: add nilfs_cleanup_super
This function write out filesystem state to super blocks in order to share the same cleanup work. This is a preparation for making super block writeback alternately. Cc: Jiro SEKIBA <jir@unicus.jp> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
-rw-r--r--fs/nilfs2/nilfs.h1
-rw-r--r--fs/nilfs2/super.c28
-rw-r--r--fs/nilfs2/the_nilfs.c5
3 files changed, 23 insertions, 11 deletions
diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h
index 47d6d7928122..469541711a1f 100644
--- a/fs/nilfs2/nilfs.h
+++ b/fs/nilfs2/nilfs.h
@@ -271,6 +271,7 @@ nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **);
271extern int nilfs_store_magic_and_option(struct super_block *, 271extern int nilfs_store_magic_and_option(struct super_block *,
272 struct nilfs_super_block *, char *); 272 struct nilfs_super_block *, char *);
273extern int nilfs_commit_super(struct nilfs_sb_info *, int); 273extern int nilfs_commit_super(struct nilfs_sb_info *, int);
274extern int nilfs_cleanup_super(struct nilfs_sb_info *);
274extern int nilfs_attach_checkpoint(struct nilfs_sb_info *, __u64); 275extern int nilfs_attach_checkpoint(struct nilfs_sb_info *, __u64);
275extern void nilfs_detach_checkpoint(struct nilfs_sb_info *); 276extern void nilfs_detach_checkpoint(struct nilfs_sb_info *);
276 277
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 39b28cf3cf8e..f23a31b04e14 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -278,6 +278,24 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb)
278 return nilfs_sync_super(sbi, dupsb); 278 return nilfs_sync_super(sbi, dupsb);
279} 279}
280 280
281/**
282 * nilfs_cleanup_super() - write filesystem state for cleanup
283 * @sbi: nilfs_sb_info to be unmounted or degraded to read-only
284 *
285 * This function restores state flags in the on-disk super block.
286 * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the
287 * filesystem was not clean previously.
288 */
289int nilfs_cleanup_super(struct nilfs_sb_info *sbi)
290{
291 struct nilfs_super_block **sbp = sbi->s_nilfs->ns_sbp;
292 int ret;
293
294 sbp[0]->s_state = cpu_to_le16(sbi->s_nilfs->ns_mount_state);
295 ret = nilfs_commit_super(sbi, 1);
296 return ret;
297}
298
281static void nilfs_put_super(struct super_block *sb) 299static void nilfs_put_super(struct super_block *sb)
282{ 300{
283 struct nilfs_sb_info *sbi = NILFS_SB(sb); 301 struct nilfs_sb_info *sbi = NILFS_SB(sb);
@@ -289,8 +307,7 @@ static void nilfs_put_super(struct super_block *sb)
289 307
290 if (!(sb->s_flags & MS_RDONLY)) { 308 if (!(sb->s_flags & MS_RDONLY)) {
291 down_write(&nilfs->ns_sem); 309 down_write(&nilfs->ns_sem);
292 nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state); 310 nilfs_cleanup_super(sbi);
293 nilfs_commit_super(sbi, 1);
294 up_write(&nilfs->ns_sem); 311 up_write(&nilfs->ns_sem);
295 } 312 }
296 down_write(&nilfs->ns_super_sem); 313 down_write(&nilfs->ns_super_sem);
@@ -819,7 +836,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
819static int nilfs_remount(struct super_block *sb, int *flags, char *data) 836static int nilfs_remount(struct super_block *sb, int *flags, char *data)
820{ 837{
821 struct nilfs_sb_info *sbi = NILFS_SB(sb); 838 struct nilfs_sb_info *sbi = NILFS_SB(sb);
822 struct nilfs_super_block *sbp;
823 struct the_nilfs *nilfs = sbi->s_nilfs; 839 struct the_nilfs *nilfs = sbi->s_nilfs;
824 unsigned long old_sb_flags; 840 unsigned long old_sb_flags;
825 struct nilfs_mount_options old_opts; 841 struct nilfs_mount_options old_opts;
@@ -880,11 +896,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
880 * the RDONLY flag and then mark the partition as valid again. 896 * the RDONLY flag and then mark the partition as valid again.
881 */ 897 */
882 down_write(&nilfs->ns_sem); 898 down_write(&nilfs->ns_sem);
883 sbp = nilfs->ns_sbp[0]; 899 nilfs_cleanup_super(sbi);
884 if (!(sbp->s_state & le16_to_cpu(NILFS_VALID_FS)) &&
885 (nilfs->ns_mount_state & NILFS_VALID_FS))
886 sbp->s_state = cpu_to_le16(nilfs->ns_mount_state);
887 nilfs_commit_super(sbi, 1);
888 up_write(&nilfs->ns_sem); 900 up_write(&nilfs->ns_sem);
889 } else { 901 } else {
890 /* 902 /*
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 4a9e8a059638..ed58053b6f68 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -324,9 +324,8 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
324 goto failed_unload; 324 goto failed_unload;
325 325
326 down_write(&nilfs->ns_sem); 326 down_write(&nilfs->ns_sem);
327 nilfs->ns_mount_state |= NILFS_VALID_FS; 327 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */
328 nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state); 328 err = nilfs_cleanup_super(sbi);
329 err = nilfs_commit_super(sbi, 1);
330 up_write(&nilfs->ns_sem); 329 up_write(&nilfs->ns_sem);
331 330
332 if (err) { 331 if (err) {