ext4: remove useless s_dirt assignment
[firefly-linux-kernel-4.4.55.git] / fs / ext4 / super.c
index 7e3a319ec402806564b0a3b42cf8c09b34751eaa..150840a4af38a73c20923d85cca33795c5613e74 100644 (file)
@@ -376,7 +376,7 @@ void ext4_journal_abort_handle(const char *caller, unsigned int line,
        if (is_handle_aborted(handle))
                return;
 
-       printk(KERN_ERR "%s:%d: aborting transaction: %s in %s\n",
+       printk(KERN_ERR "EXT4-fs: %s:%d: aborting transaction: %s in %s\n",
               caller, line, errstr, err_fn);
 
        jbd2_journal_abort_handle(handle);
@@ -515,11 +515,16 @@ void ext4_error_inode(struct inode *inode, const char *function,
        va_start(args, fmt);
        vaf.fmt = fmt;
        vaf.va = &args;
-       printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
-              inode->i_sb->s_id, function, line, inode->i_ino);
        if (block)
-               printk(KERN_CONT "block %llu: ", block);
-       printk(KERN_CONT "comm %s: %pV\n", current->comm, &vaf);
+               printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
+                      "inode #%lu: block %llu: comm %s: %pV\n",
+                      inode->i_sb->s_id, function, line, inode->i_ino,
+                      block, current->comm, &vaf);
+       else
+               printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
+                      "inode #%lu: comm %s: %pV\n",
+                      inode->i_sb->s_id, function, line, inode->i_ino,
+                      current->comm, &vaf);
        va_end(args);
 
        ext4_handle_error(inode->i_sb);
@@ -541,15 +546,21 @@ void ext4_error_file(struct file *file, const char *function,
        path = d_path(&(file->f_path), pathname, sizeof(pathname));
        if (IS_ERR(path))
                path = "(unknown)";
-       printk(KERN_CRIT
-              "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
-              inode->i_sb->s_id, function, line, inode->i_ino);
-       if (block)
-               printk(KERN_CONT "block %llu: ", block);
        va_start(args, fmt);
        vaf.fmt = fmt;
        vaf.va = &args;
-       printk(KERN_CONT "comm %s: path %s: %pV\n", current->comm, path, &vaf);
+       if (block)
+               printk(KERN_CRIT
+                      "EXT4-fs error (device %s): %s:%d: inode #%lu: "
+                      "block %llu: comm %s: path %s: %pV\n",
+                      inode->i_sb->s_id, function, line, inode->i_ino,
+                      block, current->comm, path, &vaf);
+       else
+               printk(KERN_CRIT
+                      "EXT4-fs error (device %s): %s:%d: inode #%lu: "
+                      "comm %s: path %s: %pV\n",
+                      inode->i_sb->s_id, function, line, inode->i_ino,
+                      current->comm, path, &vaf);
        va_end(args);
 
        ext4_handle_error(inode->i_sb);
@@ -825,9 +836,6 @@ static void ext4_put_super(struct super_block *sb)
        destroy_workqueue(sbi->dio_unwritten_wq);
 
        lock_super(sb);
-       if (sb->s_dirt)
-               ext4_commit_super(sb, 1);
-
        if (sbi->s_journal) {
                err = jbd2_journal_destroy(sbi->s_journal);
                sbi->s_journal = NULL;
@@ -844,9 +852,12 @@ static void ext4_put_super(struct super_block *sb)
        if (!(sb->s_flags & MS_RDONLY)) {
                EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
                es->s_state = cpu_to_le16(sbi->s_mount_state);
-               ext4_commit_super(sb, 1);
        }
+       if (sb->s_dirt || !(sb->s_flags & MS_RDONLY))
+               ext4_commit_super(sb, 1);
+
        if (sbi->s_proc) {
+               remove_proc_entry("options", sbi->s_proc);
                remove_proc_entry(sb->s_id, ext4_proc_root);
        }
        kobject_del(&sbi->s_kobj);
@@ -1198,8 +1209,8 @@ static const match_table_t tokens = {
        {Opt_nouser_xattr, "nouser_xattr"},
        {Opt_acl, "acl"},
        {Opt_noacl, "noacl"},
-       {Opt_noload, "noload"},
        {Opt_noload, "norecovery"},
+       {Opt_noload, "noload"},
        {Opt_removed, "nobh"},
        {Opt_removed, "bh"},
        {Opt_commit, "commit=%u"},
@@ -1248,6 +1259,11 @@ static const match_table_t tokens = {
        {Opt_init_itable, "init_itable=%u"},
        {Opt_init_itable, "init_itable"},
        {Opt_noinit_itable, "noinit_itable"},
+       {Opt_removed, "check=none"},    /* mount option from ext2/3 */
+       {Opt_removed, "nocheck"},       /* mount option from ext2/3 */
+       {Opt_removed, "reservation"},   /* mount option from ext2/3 */
+       {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
+       {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
        {Opt_err, NULL},
 };
 
@@ -1437,6 +1453,10 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
        if (args->from && match_int(args, &arg))
                return -1;
        switch (token) {
+       case Opt_noacl:
+       case Opt_nouser_xattr:
+               ext4_msg(sb, KERN_WARNING, deprecated_msg, opt, "3.5");
+               break;
        case Opt_sb:
                return 1;       /* handled by get_sb_block() */
        case Opt_removed:
@@ -1668,143 +1688,123 @@ static inline void ext4_show_quota_options(struct seq_file *seq,
 #endif
 }
 
+static const char *token2str(int token)
+{
+       static const struct match_token *t;
+
+       for (t = tokens; t->token != Opt_err; t++)
+               if (t->token == token && !strchr(t->pattern, '='))
+                       break;
+       return t->pattern;
+}
+
 /*
  * Show an option if
  *  - it's set to a non-default value OR
  *  - if the per-sb default is different from the global default
  */
-static int ext4_show_options(struct seq_file *seq, struct dentry *root)
+static int _ext4_show_options(struct seq_file *seq, struct super_block *sb,
+                             int nodefs)
 {
-       int def_errors;
-       unsigned long def_mount_opts;
-       struct super_block *sb = root->d_sb;
        struct ext4_sb_info *sbi = EXT4_SB(sb);
        struct ext4_super_block *es = sbi->s_es;
+       int def_errors, def_mount_opt = nodefs ? 0 : sbi->s_def_mount_opt;
+       const struct mount_opts *m;
+       char sep = nodefs ? '\n' : ',';
 
-       def_mount_opts = le32_to_cpu(es->s_default_mount_opts);
-       def_errors     = le16_to_cpu(es->s_errors);
+#define SEQ_OPTS_PUTS(str) seq_printf(seq, "%c" str, sep)
+#define SEQ_OPTS_PRINT(str, arg) seq_printf(seq, "%c" str, sep, arg)
 
        if (sbi->s_sb_block != 1)
-               seq_printf(seq, ",sb=%llu", sbi->s_sb_block);
-       if (test_opt(sb, MINIX_DF))
-               seq_puts(seq, ",minixdf");
-       if (test_opt(sb, GRPID) && !(def_mount_opts & EXT4_DEFM_BSDGROUPS))
-               seq_puts(seq, ",grpid");
-       if (!test_opt(sb, GRPID) && (def_mount_opts & EXT4_DEFM_BSDGROUPS))
-               seq_puts(seq, ",nogrpid");
-       if (sbi->s_resuid != EXT4_DEF_RESUID ||
-           le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID) {
-               seq_printf(seq, ",resuid=%u", sbi->s_resuid);
-       }
-       if (sbi->s_resgid != EXT4_DEF_RESGID ||
-           le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {
-               seq_printf(seq, ",resgid=%u", sbi->s_resgid);
-       }
-       if (test_opt(sb, ERRORS_RO)) {
-               if (def_errors == EXT4_ERRORS_PANIC ||
-                   def_errors == EXT4_ERRORS_CONTINUE) {
-                       seq_puts(seq, ",errors=remount-ro");
-               }
-       }
+               SEQ_OPTS_PRINT("sb=%llu", sbi->s_sb_block);
+
+       for (m = ext4_mount_opts; m->token != Opt_err; m++) {
+               int want_set = m->flags & MOPT_SET;
+               if (((m->flags & (MOPT_SET|MOPT_CLEAR)) == 0) ||
+                   (m->flags & MOPT_CLEAR_ERR))
+                       continue;
+               if (!(m->mount_opt & (sbi->s_mount_opt ^ def_mount_opt)))
+                       continue; /* skip if same as the default */
+               if ((want_set &&
+                    (sbi->s_mount_opt & m->mount_opt) != m->mount_opt) ||
+                   (!want_set && (sbi->s_mount_opt & m->mount_opt)))
+                       continue; /* select Opt_noFoo vs Opt_Foo */
+               SEQ_OPTS_PRINT("%s", token2str(m->token));
+       }
+
+       if (nodefs || sbi->s_resuid != EXT4_DEF_RESUID ||
+           le16_to_cpu(es->s_def_resuid) != EXT4_DEF_RESUID)
+               SEQ_OPTS_PRINT("resuid=%u", sbi->s_resuid);
+       if (nodefs || sbi->s_resgid != EXT4_DEF_RESGID ||
+           le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID)
+               SEQ_OPTS_PRINT("resgid=%u", sbi->s_resgid);
+       def_errors = nodefs ? -1 : le16_to_cpu(es->s_errors);
+       if (test_opt(sb, ERRORS_RO) && def_errors != EXT4_ERRORS_RO)
+               SEQ_OPTS_PUTS("errors=remount-ro");
        if (test_opt(sb, ERRORS_CONT) && def_errors != EXT4_ERRORS_CONTINUE)
-               seq_puts(seq, ",errors=continue");
+               SEQ_OPTS_PUTS("errors=continue");
        if (test_opt(sb, ERRORS_PANIC) && def_errors != EXT4_ERRORS_PANIC)
-               seq_puts(seq, ",errors=panic");
-       if (test_opt(sb, NO_UID32) && !(def_mount_opts & EXT4_DEFM_UID16))
-               seq_puts(seq, ",nouid32");
-       if (test_opt(sb, DEBUG) && !(def_mount_opts & EXT4_DEFM_DEBUG))
-               seq_puts(seq, ",debug");
-#ifdef CONFIG_EXT4_FS_XATTR
-       if (test_opt(sb, XATTR_USER))
-               seq_puts(seq, ",user_xattr");
-       if (!test_opt(sb, XATTR_USER))
-               seq_puts(seq, ",nouser_xattr");
-#endif
-#ifdef CONFIG_EXT4_FS_POSIX_ACL
-       if (test_opt(sb, POSIX_ACL) && !(def_mount_opts & EXT4_DEFM_ACL))
-               seq_puts(seq, ",acl");
-       if (!test_opt(sb, POSIX_ACL) && (def_mount_opts & EXT4_DEFM_ACL))
-               seq_puts(seq, ",noacl");
-#endif
-       if (sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ) {
-               seq_printf(seq, ",commit=%u",
-                          (unsigned) (sbi->s_commit_interval / HZ));
-       }
-       if (sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME) {
-               seq_printf(seq, ",min_batch_time=%u",
-                          (unsigned) sbi->s_min_batch_time);
-       }
-       if (sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME) {
-               seq_printf(seq, ",max_batch_time=%u",
-                          (unsigned) sbi->s_max_batch_time);
-       }
-
-       /*
-        * We're changing the default of barrier mount option, so
-        * let's always display its mount state so it's clear what its
-        * status is.
-        */
-       seq_puts(seq, ",barrier=");
-       seq_puts(seq, test_opt(sb, BARRIER) ? "1" : "0");
-       if (test_opt(sb, JOURNAL_ASYNC_COMMIT))
-               seq_puts(seq, ",journal_async_commit");
-       else if (test_opt(sb, JOURNAL_CHECKSUM))
-               seq_puts(seq, ",journal_checksum");
+               SEQ_OPTS_PUTS("errors=panic");
+       if (nodefs || sbi->s_commit_interval != JBD2_DEFAULT_MAX_COMMIT_AGE*HZ)
+               SEQ_OPTS_PRINT("commit=%lu", sbi->s_commit_interval / HZ);
+       if (nodefs || sbi->s_min_batch_time != EXT4_DEF_MIN_BATCH_TIME)
+               SEQ_OPTS_PRINT("min_batch_time=%u", sbi->s_min_batch_time);
+       if (nodefs || sbi->s_max_batch_time != EXT4_DEF_MAX_BATCH_TIME)
+               SEQ_OPTS_PRINT("max_batch_time=%u", sbi->s_max_batch_time);
        if (sb->s_flags & MS_I_VERSION)
-               seq_puts(seq, ",i_version");
-       if (!test_opt(sb, DELALLOC) &&
-           !(def_mount_opts & EXT4_DEFM_NODELALLOC))
-               seq_puts(seq, ",nodelalloc");
-
-       if (!test_opt(sb, MBLK_IO_SUBMIT))
-               seq_puts(seq, ",nomblk_io_submit");
-       if (sbi->s_stripe)
-               seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
-       /*
-        * journal mode get enabled in different ways
-        * So just print the value even if we didn't specify it
-        */
-       if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
-               seq_puts(seq, ",data=journal");
-       else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
-               seq_puts(seq, ",data=ordered");
-       else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
-               seq_puts(seq, ",data=writeback");
-
-       if (sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
-               seq_printf(seq, ",inode_readahead_blks=%u",
-                          sbi->s_inode_readahead_blks);
-
-       if (test_opt(sb, DATA_ERR_ABORT))
-               seq_puts(seq, ",data_err=abort");
-
-       if (test_opt(sb, NO_AUTO_DA_ALLOC))
-               seq_puts(seq, ",noauto_da_alloc");
-
-       if (test_opt(sb, DISCARD) && !(def_mount_opts & EXT4_DEFM_DISCARD))
-               seq_puts(seq, ",discard");
+               SEQ_OPTS_PUTS("i_version");
+       if (nodefs || sbi->s_stripe)
+               SEQ_OPTS_PRINT("stripe=%lu", sbi->s_stripe);
+       if (EXT4_MOUNT_DATA_FLAGS & (sbi->s_mount_opt ^ def_mount_opt)) {
+               if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA)
+                       SEQ_OPTS_PUTS("data=journal");
+               else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_ORDERED_DATA)
+                       SEQ_OPTS_PUTS("data=ordered");
+               else if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)
+                       SEQ_OPTS_PUTS("data=writeback");
+       }
+       if (nodefs ||
+           sbi->s_inode_readahead_blks != EXT4_DEF_INODE_READAHEAD_BLKS)
+               SEQ_OPTS_PRINT("inode_readahead_blks=%u",
+                              sbi->s_inode_readahead_blks);
 
-       if (test_opt(sb, NOLOAD))
-               seq_puts(seq, ",norecovery");
+       if (nodefs || (test_opt(sb, INIT_INODE_TABLE) &&
+                      (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)))
+               SEQ_OPTS_PRINT("init_itable=%u", sbi->s_li_wait_mult);
 
-       if (test_opt(sb, DIOREAD_NOLOCK))
-               seq_puts(seq, ",dioread_nolock");
+       ext4_show_quota_options(seq, sb);
+       return 0;
+}
 
-       if (test_opt(sb, BLOCK_VALIDITY) &&
-           !(def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY))
-               seq_puts(seq, ",block_validity");
+static int ext4_show_options(struct seq_file *seq, struct dentry *root)
+{
+       return _ext4_show_options(seq, root->d_sb, 0);
+}
 
-       if (!test_opt(sb, INIT_INODE_TABLE))
-               seq_puts(seq, ",noinit_itable");
-       else if (sbi->s_li_wait_mult != EXT4_DEF_LI_WAIT_MULT)
-               seq_printf(seq, ",init_itable=%u",
-                          (unsigned) sbi->s_li_wait_mult);
+static int options_seq_show(struct seq_file *seq, void *offset)
+{
+       struct super_block *sb = seq->private;
+       int rc;
 
-       ext4_show_quota_options(seq, sb);
+       seq_puts(seq, (sb->s_flags & MS_RDONLY) ? "ro" : "rw");
+       rc = _ext4_show_options(seq, sb, 1);
+       seq_puts(seq, "\n");
+       return rc;
+}
 
-       return 0;
+static int options_open_fs(struct inode *inode, struct file *file)
+{
+       return single_open(file, options_seq_show, PDE(inode)->data);
 }
 
+static const struct file_operations ext4_seq_options_fops = {
+       .owner = THIS_MODULE,
+       .open = options_open_fs,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
                            int read_only)
 {
@@ -2808,7 +2808,7 @@ static int ext4_run_lazyinit_thread(void)
                ext4_clear_request_list();
                kfree(ext4_li_info);
                ext4_li_info = NULL;
-               printk(KERN_CRIT "EXT4: error %d creating inode table "
+               printk(KERN_CRIT "EXT4-fs: error %d creating inode table "
                                 "initialization thread\n",
                                 err);
                return err;
@@ -3105,6 +3105,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
                         "failed to parse options in superblock: %s",
                         sbi->s_es->s_mount_opts);
        }
+       sbi->s_def_mount_opt = sbi->s_mount_opt;
        if (!parse_options((char *) data, sb, &journal_devnum,
                           &journal_ioprio, 0))
                goto failed_mount;
@@ -3276,7 +3277,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 #else
                es->s_flags |= cpu_to_le32(EXT2_FLAGS_SIGNED_HASH);
 #endif
-               sb->s_dirt = 1;
        }
 
        /* Handle clustersize */
@@ -3400,6 +3400,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
        if (ext4_proc_root)
                sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
 
+       if (sbi->s_proc)
+               proc_create_data("options", S_IRUGO, sbi->s_proc,
+                                &ext4_seq_options_fops, sb);
+
        bgl_lock_init(sbi->s_blockgroup_lock);
 
        for (i = 0; i < db_count; i++) {
@@ -3724,6 +3728,7 @@ failed_mount2:
        ext4_kvfree(sbi->s_group_desc);
 failed_mount:
        if (sbi->s_proc) {
+               remove_proc_entry("options", sbi->s_proc);
                remove_proc_entry(sb->s_id, ext4_proc_root);
        }
 #ifdef CONFIG_QUOTA