Commit 7ecaa46c authored by Ryusuke Konishi's avatar Ryusuke Konishi

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: default avatarRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
parent bde4e696
...@@ -271,6 +271,7 @@ nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **); ...@@ -271,6 +271,7 @@ nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **);
extern int nilfs_store_magic_and_option(struct super_block *, extern int nilfs_store_magic_and_option(struct super_block *,
struct nilfs_super_block *, char *); struct nilfs_super_block *, char *);
extern int nilfs_commit_super(struct nilfs_sb_info *, int); extern int nilfs_commit_super(struct nilfs_sb_info *, int);
extern int nilfs_cleanup_super(struct nilfs_sb_info *);
extern int nilfs_attach_checkpoint(struct nilfs_sb_info *, __u64); extern int nilfs_attach_checkpoint(struct nilfs_sb_info *, __u64);
extern void nilfs_detach_checkpoint(struct nilfs_sb_info *); extern void nilfs_detach_checkpoint(struct nilfs_sb_info *);
......
...@@ -278,6 +278,24 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb) ...@@ -278,6 +278,24 @@ int nilfs_commit_super(struct nilfs_sb_info *sbi, int dupsb)
return nilfs_sync_super(sbi, dupsb); return nilfs_sync_super(sbi, dupsb);
} }
/**
* nilfs_cleanup_super() - write filesystem state for cleanup
* @sbi: nilfs_sb_info to be unmounted or degraded to read-only
*
* This function restores state flags in the on-disk super block.
* This will set "clean" flag (i.e. NILFS_VALID_FS) unless the
* filesystem was not clean previously.
*/
int nilfs_cleanup_super(struct nilfs_sb_info *sbi)
{
struct nilfs_super_block **sbp = sbi->s_nilfs->ns_sbp;
int ret;
sbp[0]->s_state = cpu_to_le16(sbi->s_nilfs->ns_mount_state);
ret = nilfs_commit_super(sbi, 1);
return ret;
}
static void nilfs_put_super(struct super_block *sb) static void nilfs_put_super(struct super_block *sb)
{ {
struct nilfs_sb_info *sbi = NILFS_SB(sb); struct nilfs_sb_info *sbi = NILFS_SB(sb);
...@@ -289,8 +307,7 @@ static void nilfs_put_super(struct super_block *sb) ...@@ -289,8 +307,7 @@ static void nilfs_put_super(struct super_block *sb)
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
down_write(&nilfs->ns_sem); down_write(&nilfs->ns_sem);
nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state); nilfs_cleanup_super(sbi);
nilfs_commit_super(sbi, 1);
up_write(&nilfs->ns_sem); up_write(&nilfs->ns_sem);
} }
down_write(&nilfs->ns_super_sem); down_write(&nilfs->ns_super_sem);
...@@ -819,7 +836,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent, ...@@ -819,7 +836,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
static int nilfs_remount(struct super_block *sb, int *flags, char *data) static int nilfs_remount(struct super_block *sb, int *flags, char *data)
{ {
struct nilfs_sb_info *sbi = NILFS_SB(sb); struct nilfs_sb_info *sbi = NILFS_SB(sb);
struct nilfs_super_block *sbp;
struct the_nilfs *nilfs = sbi->s_nilfs; struct the_nilfs *nilfs = sbi->s_nilfs;
unsigned long old_sb_flags; unsigned long old_sb_flags;
struct nilfs_mount_options old_opts; struct nilfs_mount_options old_opts;
...@@ -880,11 +896,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data) ...@@ -880,11 +896,7 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
* the RDONLY flag and then mark the partition as valid again. * the RDONLY flag and then mark the partition as valid again.
*/ */
down_write(&nilfs->ns_sem); down_write(&nilfs->ns_sem);
sbp = nilfs->ns_sbp[0]; nilfs_cleanup_super(sbi);
if (!(sbp->s_state & le16_to_cpu(NILFS_VALID_FS)) &&
(nilfs->ns_mount_state & NILFS_VALID_FS))
sbp->s_state = cpu_to_le16(nilfs->ns_mount_state);
nilfs_commit_super(sbi, 1);
up_write(&nilfs->ns_sem); up_write(&nilfs->ns_sem);
} else { } else {
/* /*
......
...@@ -324,9 +324,8 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi) ...@@ -324,9 +324,8 @@ int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
goto failed_unload; goto failed_unload;
down_write(&nilfs->ns_sem); down_write(&nilfs->ns_sem);
nilfs->ns_mount_state |= NILFS_VALID_FS; nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */
nilfs->ns_sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state); err = nilfs_cleanup_super(sbi);
err = nilfs_commit_super(sbi, 1);
up_write(&nilfs->ns_sem); up_write(&nilfs->ns_sem);
if (err) { if (err) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment