tunnels: fix netns vs proto registration ordering
[safe/jmp/linux-2.6] / fs / nilfs2 / super.c
index ebbefb9..8173fae 100644 (file)
@@ -67,7 +67,6 @@ MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem "
                   "(NILFS)");
 MODULE_LICENSE("GPL");
 
-static void nilfs_write_super(struct super_block *sb);
 static int nilfs_remount(struct super_block *sb, int *flags, char *data);
 
 /**
@@ -313,9 +312,6 @@ static void nilfs_put_super(struct super_block *sb)
 
        lock_kernel();
 
-       if (sb->s_dirt)
-               nilfs_write_super(sb);
-
        nilfs_detach_segment_constructor(sbi);
 
        if (!(sb->s_flags & MS_RDONLY)) {
@@ -338,63 +334,21 @@ static void nilfs_put_super(struct super_block *sb)
        unlock_kernel();
 }
 
-/**
- * nilfs_write_super - write super block(s) of NILFS
- * @sb: super_block
- *
- * nilfs_write_super() gets a fs-dependent lock, writes super block(s), and
- * clears s_dirt.  This function is called in the section protected by
- * lock_super().
- *
- * The s_dirt flag is managed by each filesystem and we protect it by ns_sem
- * of the struct the_nilfs.  Lock order must be as follows:
- *
- *   1. lock_super()
- *   2.    down_write(&nilfs->ns_sem)
- *
- * Inside NILFS, locking ns_sem is enough to protect s_dirt and the buffer
- * of the super block (nilfs->ns_sbp[]).
- *
- * In most cases, VFS functions call lock_super() before calling these
- * methods.  So we must be careful not to bring on deadlocks when using
- * lock_super();  see generic_shutdown_super(), write_super(), and so on.
- *
- * Note that order of lock_kernel() and lock_super() depends on contexts
- * of VFS.  We should also note that lock_kernel() can be used in its
- * protective section and only the outermost one has an effect.
- */
-static void nilfs_write_super(struct super_block *sb)
+static int nilfs_sync_fs(struct super_block *sb, int wait)
 {
        struct nilfs_sb_info *sbi = NILFS_SB(sb);
        struct the_nilfs *nilfs = sbi->s_nilfs;
-
-       down_write(&nilfs->ns_sem);
-       if (!(sb->s_flags & MS_RDONLY)) {
-               struct nilfs_super_block **sbp = nilfs->ns_sbp;
-               u64 t = get_seconds();
-               int dupsb;
-
-               if (!nilfs_discontinued(nilfs) && t >= nilfs->ns_sbwtime[0] &&
-                   t < nilfs->ns_sbwtime[0] + NILFS_SB_FREQ) {
-                       up_write(&nilfs->ns_sem);
-                       return;
-               }
-               dupsb = sbp[1] && t > nilfs->ns_sbwtime[1] + NILFS_ALTSB_FREQ;
-               nilfs_commit_super(sbi, dupsb);
-       }
-       sb->s_dirt = 0;
-       up_write(&nilfs->ns_sem);
-}
-
-static int nilfs_sync_fs(struct super_block *sb, int wait)
-{
        int err = 0;
 
-       nilfs_write_super(sb);
-
        /* This function is called when super block should be written back */
        if (wait)
                err = nilfs_construct_segment(sb);
+
+       down_write(&nilfs->ns_sem);
+       if (sb->s_dirt)
+               nilfs_commit_super(sbi, 1);
+       up_write(&nilfs->ns_sem);
+
        return err;
 }
 
@@ -409,15 +363,10 @@ int nilfs_attach_checkpoint(struct nilfs_sb_info *sbi, __u64 cno)
        list_add(&sbi->s_list, &nilfs->ns_supers);
        up_write(&nilfs->ns_super_sem);
 
-       sbi->s_ifile = nilfs_mdt_new(
-               nilfs, sbi->s_super, NILFS_IFILE_INO, NILFS_IFILE_GFP);
+       sbi->s_ifile = nilfs_ifile_new(sbi, nilfs->ns_inode_size);
        if (!sbi->s_ifile)
                return -ENOMEM;
 
-       err = nilfs_palloc_init_blockgroup(sbi->s_ifile, nilfs->ns_inode_size);
-       if (unlikely(err))
-               goto failed;
-
        down_read(&nilfs->ns_segctor_sem);
        err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp,
                                          &bh_cp);
@@ -458,7 +407,6 @@ void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
 {
        struct the_nilfs *nilfs = sbi->s_nilfs;
 
-       nilfs_mdt_clear(sbi->s_ifile);
        nilfs_mdt_destroy(sbi->s_ifile);
        sbi->s_ifile = NULL;
        down_write(&nilfs->ns_super_sem);
@@ -466,22 +414,6 @@ void nilfs_detach_checkpoint(struct nilfs_sb_info *sbi)
        up_write(&nilfs->ns_super_sem);
 }
 
-static int nilfs_mark_recovery_complete(struct nilfs_sb_info *sbi)
-{
-       struct the_nilfs *nilfs = sbi->s_nilfs;
-       int err = 0;
-
-       down_write(&nilfs->ns_sem);
-       if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
-               nilfs->ns_mount_state |= NILFS_VALID_FS;
-               err = nilfs_commit_super(sbi, 1);
-               if (likely(!err))
-                       printk(KERN_INFO "NILFS: recovery complete.\n");
-       }
-       up_write(&nilfs->ns_sem);
-       return err;
-}
-
 static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
        struct super_block *sb = dentry->d_sb;
@@ -537,7 +469,7 @@ static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
        struct nilfs_sb_info *sbi = NILFS_SB(sb);
 
        if (!nilfs_test_opt(sbi, BARRIER))
-               seq_printf(seq, ",barrier=off");
+               seq_printf(seq, ",nobarrier");
        if (nilfs_test_opt(sbi, SNAPSHOT))
                seq_printf(seq, ",cp=%llu",
                           (unsigned long long int)sbi->s_snapshot_cno);
@@ -547,11 +479,13 @@ static int nilfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
                seq_printf(seq, ",errors=panic");
        if (nilfs_test_opt(sbi, STRICT_ORDER))
                seq_printf(seq, ",order=strict");
+       if (nilfs_test_opt(sbi, NORECOVERY))
+               seq_printf(seq, ",norecovery");
 
        return 0;
 }
 
-static struct super_operations nilfs_sops = {
+static const struct super_operations nilfs_sops = {
        .alloc_inode    = nilfs_alloc_inode,
        .destroy_inode  = nilfs_destroy_inode,
        .dirty_inode    = nilfs_dirty_inode,
@@ -560,7 +494,7 @@ static struct super_operations nilfs_sops = {
        /* .drop_inode    = nilfs_drop_inode, */
        .delete_inode   = nilfs_delete_inode,
        .put_super      = nilfs_put_super,
-       .write_super    = nilfs_write_super,
+       /* .write_super    = nilfs_write_super, */
        .sync_fs        = nilfs_sync_fs,
        /* .write_super_lockfs */
        /* .unlockfs */
@@ -607,7 +541,7 @@ nilfs_fh_to_parent(struct super_block *sb, struct fid *fid, int fh_len,
                                    nilfs_nfs_get_inode);
 }
 
-static struct export_operations nilfs_export_ops = {
+static const struct export_operations nilfs_export_ops = {
        .fh_to_dentry = nilfs_fh_to_dentry,
        .fh_to_parent = nilfs_fh_to_parent,
        .get_parent = nilfs_get_parent,
@@ -615,7 +549,7 @@ static struct export_operations nilfs_export_ops = {
 
 enum {
        Opt_err_cont, Opt_err_panic, Opt_err_ro,
-       Opt_barrier, Opt_snapshot, Opt_order,
+       Opt_nobarrier, Opt_snapshot, Opt_order, Opt_norecovery,
        Opt_err,
 };
 
@@ -623,25 +557,13 @@ static match_table_t tokens = {
        {Opt_err_cont, "errors=continue"},
        {Opt_err_panic, "errors=panic"},
        {Opt_err_ro, "errors=remount-ro"},
-       {Opt_barrier, "barrier=%s"},
+       {Opt_nobarrier, "nobarrier"},
        {Opt_snapshot, "cp=%u"},
        {Opt_order, "order=%s"},
+       {Opt_norecovery, "norecovery"},
        {Opt_err, NULL}
 };
 
-static int match_bool(substring_t *s, int *result)
-{
-       int len = s->to - s->from;
-
-       if (strncmp(s->from, "on", len) == 0)
-               *result = 1;
-       else if (strncmp(s->from, "off", len) == 0)
-               *result = 0;
-       else
-               return 1;
-       return 0;
-}
-
 static int parse_options(char *options, struct super_block *sb)
 {
        struct nilfs_sb_info *sbi = NILFS_SB(sb);
@@ -659,13 +581,8 @@ static int parse_options(char *options, struct super_block *sb)
 
                token = match_token(p, tokens, args);
                switch (token) {
-               case Opt_barrier:
-                       if (match_bool(&args[0], &option))
-                               return 0;
-                       if (option)
-                               nilfs_set_opt(sbi, BARRIER);
-                       else
-                               nilfs_clear_opt(sbi, BARRIER);
+               case Opt_nobarrier:
+                       nilfs_clear_opt(sbi, BARRIER);
                        break;
                case Opt_order:
                        if (strcmp(args[0].from, "relaxed") == 0)
@@ -694,6 +611,9 @@ static int parse_options(char *options, struct super_block *sb)
                        sbi->s_snapshot_cno = option;
                        nilfs_set_opt(sbi, SNAPSHOT);
                        break;
+               case Opt_norecovery:
+                       nilfs_set_opt(sbi, NORECOVERY);
+                       break;
                default:
                        printk(KERN_ERR
                               "NILFS: Unrecognized mount option \"%s\"\n", p);
@@ -719,9 +639,7 @@ static int nilfs_setup_super(struct nilfs_sb_info *sbi)
        int mnt_count = le16_to_cpu(sbp->s_mnt_count);
 
        /* nilfs->sem must be locked by the caller. */
-       if (!(nilfs->ns_mount_state & NILFS_VALID_FS)) {
-               printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
-       } else if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
+       if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
                printk(KERN_WARNING
                       "NILFS warning: mounting fs with errors\n");
 #if 0
@@ -829,19 +747,23 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
        sb->s_root = NULL;
        sb->s_time_gran = 1;
 
-       if (!nilfs_loaded(nilfs)) {
-               err = load_nilfs(nilfs, sbi);
-               if (err)
-                       goto failed_sbi;
-       }
+       err = load_nilfs(nilfs, sbi);
+       if (err)
+               goto failed_sbi;
+
        cno = nilfs_last_cno(nilfs);
 
        if (sb->s_flags & MS_RDONLY) {
                if (nilfs_test_opt(sbi, SNAPSHOT)) {
+                       down_read(&nilfs->ns_segctor_sem);
                        err = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile,
                                                       sbi->s_snapshot_cno);
-                       if (err < 0)
+                       up_read(&nilfs->ns_segctor_sem);
+                       if (err < 0) {
+                               if (err == -ENOENT)
+                                       err = -EINVAL;
                                goto failed_sbi;
+                       }
                        if (!err) {
                                printk(KERN_ERR
                                       "NILFS: The specified checkpoint is "
@@ -896,12 +818,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
                up_write(&nilfs->ns_sem);
        }
 
-       err = nilfs_mark_recovery_complete(sbi);
-       if (unlikely(err)) {
-               printk(KERN_ERR "NILFS: recovery failed.\n");
-               goto failed_root;
-       }
-
        down_write(&nilfs->ns_super_sem);
        if (!nilfs_test_opt(sbi, SNAPSHOT))
                nilfs->ns_current = sbi;
@@ -909,10 +825,6 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent,
 
        return 0;
 
- failed_root:
-       dput(sb->s_root);
-       sb->s_root = NULL;
-
  failed_segctor:
        nilfs_detach_segment_constructor(sbi);
 
@@ -957,6 +869,14 @@ static int nilfs_remount(struct super_block *sb, int *flags, char *data)
                goto restore_opts;
        }
 
+       if (!nilfs_valid_fs(nilfs)) {
+               printk(KERN_WARNING "NILFS (device %s): couldn't "
+                      "remount because the filesystem is in an "
+                      "incomplete recovery state.\n", sb->s_id);
+               err = -EINVAL;
+               goto restore_opts;
+       }
+
        if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
                goto out;
        if (*flags & MS_RDONLY) {
@@ -1149,10 +1069,6 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
         */
        sd.sbi = nilfs_find_sbinfo(nilfs, !(flags & MS_RDONLY), sd.cno);
 
-       if (!sd.cno)
-               /* trying to get the latest checkpoint.  */
-               sd.cno = nilfs_last_cno(nilfs);
-
        /*
         * Get super block instance holding the nilfs_sb_info struct.
         * A new instance is allocated if no existing mount is present or
@@ -1202,8 +1118,7 @@ nilfs_get_sb(struct file_system_type *fs_type, int flags,
        /* Abandoning the newly allocated superblock */
        mutex_unlock(&nilfs->ns_mount_mutex);
        put_nilfs(nilfs);
-       up_write(&s->s_umount);
-       deactivate_super(s);
+       deactivate_locked_super(s);
        /*
         * deactivate_super() invokes close_bdev_exclusive().
         * We must finish all post-cleaning before this call;