Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[linux-2.6-microblaze.git] / fs / ext4 / super.c
index 6900da9..450c918 100644 (file)
@@ -1211,6 +1211,9 @@ static void ext4_put_super(struct super_block *sb)
         */
        ext4_unregister_sysfs(sb);
 
+       if (___ratelimit(&ext4_mount_msg_ratelimit, "EXT4-fs unmount"))
+               ext4_msg(sb, KERN_INFO, "unmounting filesystem.");
+
        ext4_unregister_li_request(sb);
        ext4_quota_off_umount(sb);
 
@@ -1397,7 +1400,7 @@ static void ext4_destroy_inode(struct inode *inode)
 
 static void init_once(void *foo)
 {
-       struct ext4_inode_info *ei = (struct ext4_inode_info *) foo;
+       struct ext4_inode_info *ei = foo;
 
        INIT_LIST_HEAD(&ei->i_orphan);
        init_rwsem(&ei->xattr_sem);
@@ -1492,128 +1495,6 @@ static int ext4_nfs_commit_metadata(struct inode *inode)
        return ext4_write_inode(inode, &wbc);
 }
 
-#ifdef CONFIG_FS_ENCRYPTION
-static int ext4_get_context(struct inode *inode, void *ctx, size_t len)
-{
-       return ext4_xattr_get(inode, EXT4_XATTR_INDEX_ENCRYPTION,
-                                EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, ctx, len);
-}
-
-static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
-                                                       void *fs_data)
-{
-       handle_t *handle = fs_data;
-       int res, res2, credits, retries = 0;
-
-       /*
-        * Encrypting the root directory is not allowed because e2fsck expects
-        * lost+found to exist and be unencrypted, and encrypting the root
-        * directory would imply encrypting the lost+found directory as well as
-        * the filename "lost+found" itself.
-        */
-       if (inode->i_ino == EXT4_ROOT_INO)
-               return -EPERM;
-
-       if (WARN_ON_ONCE(IS_DAX(inode) && i_size_read(inode)))
-               return -EINVAL;
-
-       if (ext4_test_inode_flag(inode, EXT4_INODE_DAX))
-               return -EOPNOTSUPP;
-
-       res = ext4_convert_inline_data(inode);
-       if (res)
-               return res;
-
-       /*
-        * If a journal handle was specified, then the encryption context is
-        * being set on a new inode via inheritance and is part of a larger
-        * transaction to create the inode.  Otherwise the encryption context is
-        * being set on an existing inode in its own transaction.  Only in the
-        * latter case should the "retry on ENOSPC" logic be used.
-        */
-
-       if (handle) {
-               res = ext4_xattr_set_handle(handle, inode,
-                                           EXT4_XATTR_INDEX_ENCRYPTION,
-                                           EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
-                                           ctx, len, 0);
-               if (!res) {
-                       ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
-                       ext4_clear_inode_state(inode,
-                                       EXT4_STATE_MAY_INLINE_DATA);
-                       /*
-                        * Update inode->i_flags - S_ENCRYPTED will be enabled,
-                        * S_DAX may be disabled
-                        */
-                       ext4_set_inode_flags(inode, false);
-               }
-               return res;
-       }
-
-       res = dquot_initialize(inode);
-       if (res)
-               return res;
-retry:
-       res = ext4_xattr_set_credits(inode, len, false /* is_create */,
-                                    &credits);
-       if (res)
-               return res;
-
-       handle = ext4_journal_start(inode, EXT4_HT_MISC, credits);
-       if (IS_ERR(handle))
-               return PTR_ERR(handle);
-
-       res = ext4_xattr_set_handle(handle, inode, EXT4_XATTR_INDEX_ENCRYPTION,
-                                   EXT4_XATTR_NAME_ENCRYPTION_CONTEXT,
-                                   ctx, len, 0);
-       if (!res) {
-               ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
-               /*
-                * Update inode->i_flags - S_ENCRYPTED will be enabled,
-                * S_DAX may be disabled
-                */
-               ext4_set_inode_flags(inode, false);
-               res = ext4_mark_inode_dirty(handle, inode);
-               if (res)
-                       EXT4_ERROR_INODE(inode, "Failed to mark inode dirty");
-       }
-       res2 = ext4_journal_stop(handle);
-
-       if (res == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
-               goto retry;
-       if (!res)
-               res = res2;
-       return res;
-}
-
-static const union fscrypt_policy *ext4_get_dummy_policy(struct super_block *sb)
-{
-       return EXT4_SB(sb)->s_dummy_enc_policy.policy;
-}
-
-static bool ext4_has_stable_inodes(struct super_block *sb)
-{
-       return ext4_has_feature_stable_inodes(sb);
-}
-
-static void ext4_get_ino_and_lblk_bits(struct super_block *sb,
-                                      int *ino_bits_ret, int *lblk_bits_ret)
-{
-       *ino_bits_ret = 8 * sizeof(EXT4_SB(sb)->s_es->s_inodes_count);
-       *lblk_bits_ret = 8 * sizeof(ext4_lblk_t);
-}
-
-static const struct fscrypt_operations ext4_cryptops = {
-       .key_prefix             = "ext4:",
-       .get_context            = ext4_get_context,
-       .set_context            = ext4_set_context,
-       .get_dummy_policy       = ext4_get_dummy_policy,
-       .empty_dir              = ext4_empty_dir,
-       .has_stable_inodes      = ext4_has_stable_inodes,
-       .get_ino_and_lblk_bits  = ext4_get_ino_and_lblk_bits,
-};
-#endif
-
 #ifdef CONFIG_QUOTA
 static const char * const quotatypes[] = INITQFNAMES;
 #define QTYPE2NAME(t) (quotatypes[t])
@@ -1867,7 +1748,6 @@ static const struct fs_parameter_spec ext4_param_specs[] = {
 };
 
 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
-#define DEFAULT_MB_OPTIMIZE_SCAN       (-1)
 
 static const char deprecated_msg[] =
        "Mount option \"%s\" will be removed by %s\n"
@@ -1913,6 +1793,7 @@ static const struct mount_opts {
         MOPT_EXT4_ONLY | MOPT_CLEAR},
        {Opt_warn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_SET},
        {Opt_nowarn_on_error, EXT4_MOUNT_WARN_ON_ERROR, MOPT_CLEAR},
+       {Opt_commit, 0, MOPT_NO_EXT2},
        {Opt_nojournal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
         MOPT_EXT4_ONLY | MOPT_CLEAR},
        {Opt_journal_checksum, EXT4_MOUNT_JOURNAL_CHECKSUM,
@@ -2427,11 +2308,12 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
                ctx->spec |= EXT4_SPEC_DUMMY_ENCRYPTION;
                ctx->test_dummy_enc_arg = kmemdup_nul(param->string, param->size,
                                                      GFP_KERNEL);
+               return 0;
 #else
                ext4_msg(NULL, KERN_WARNING,
-                        "Test dummy encryption mount option ignored");
+                        "test_dummy_encryption option not supported");
+               return -EINVAL;
 #endif
-               return 0;
        case Opt_dax:
        case Opt_dax_type:
 #ifdef CONFIG_FS_DAX
@@ -2625,8 +2507,10 @@ parse_failed:
        ret = ext4_apply_options(fc, sb);
 
 out_free:
-       kfree(s_ctx);
-       kfree(fc);
+       if (fc) {
+               ext4_fc_free(fc);
+               kfree(fc);
+       }
        kfree(s_mount_opts);
        return ret;
 }
@@ -2786,12 +2670,44 @@ err_jquota_specified:
 #endif
 }
 
+static int ext4_check_test_dummy_encryption(const struct fs_context *fc,
+                                           struct super_block *sb)
+{
+#ifdef CONFIG_FS_ENCRYPTION
+       const struct ext4_fs_context *ctx = fc->fs_private;
+       const struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+       if (!(ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION))
+               return 0;
+
+       if (!ext4_has_feature_encrypt(sb)) {
+               ext4_msg(NULL, KERN_WARNING,
+                        "test_dummy_encryption requires encrypt feature");
+               return -EINVAL;
+       }
+       /*
+        * This mount option is just for testing, and it's not worthwhile to
+        * implement the extra complexity (e.g. RCU protection) that would be
+        * needed to allow it to be set or changed during remount.  We do allow
+        * it to be specified during remount, but only if there is no change.
+        */
+       if (fc->purpose == FS_CONTEXT_FOR_RECONFIGURE &&
+           !sbi->s_dummy_enc_policy.policy) {
+               ext4_msg(NULL, KERN_WARNING,
+                        "Can't set test_dummy_encryption on remount");
+               return -EINVAL;
+       }
+#endif /* CONFIG_FS_ENCRYPTION */
+       return 0;
+}
+
 static int ext4_check_opt_consistency(struct fs_context *fc,
                                      struct super_block *sb)
 {
        struct ext4_fs_context *ctx = fc->fs_private;
        struct ext4_sb_info *sbi = fc->s_fs_info;
        int is_remount = fc->purpose == FS_CONTEXT_FOR_RECONFIGURE;
+       int err;
 
        if ((ctx->opt_flags & MOPT_NO_EXT2) && IS_EXT2_SB(sb)) {
                ext4_msg(NULL, KERN_ERR,
@@ -2821,20 +2737,9 @@ static int ext4_check_opt_consistency(struct fs_context *fc,
                                 "for blocksize < PAGE_SIZE");
        }
 
-#ifdef CONFIG_FS_ENCRYPTION
-       /*
-        * This mount option is just for testing, and it's not worthwhile to
-        * implement the extra complexity (e.g. RCU protection) that would be
-        * needed to allow it to be set or changed during remount.  We do allow
-        * it to be specified during remount, but only if there is no change.
-        */
-       if ((ctx->spec & EXT4_SPEC_DUMMY_ENCRYPTION) &&
-           is_remount && !sbi->s_dummy_enc_policy.policy) {
-               ext4_msg(NULL, KERN_WARNING,
-                        "Can't set test_dummy_encryption on remount");
-               return -1;
-       }
-#endif
+       err = ext4_check_test_dummy_encryption(fc, sb);
+       if (err)
+               return err;
 
        if ((ctx->spec & EXT4_SPEC_DATAJ) && is_remount) {
                if (!sbi->s_journal) {
@@ -3837,7 +3742,7 @@ static struct task_struct *ext4_lazyinit_task;
  */
 static int ext4_lazyinit_thread(void *arg)
 {
-       struct ext4_lazy_init *eli = (struct ext4_lazy_init *)arg;
+       struct ext4_lazy_init *eli = arg;
        struct list_head *pos, *n;
        struct ext4_li_request *elr;
        unsigned long next_wakeup, cur;
@@ -4409,7 +4314,8 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
        int silent = fc->sb_flags & SB_SILENT;
 
        /* Set defaults for the variables that will be set during parsing */
-       ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
+       if (!(ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO))
+               ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
 
        sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
        sbi->s_sectors_written_start =
@@ -4886,7 +4792,7 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
                                        sbi->s_inodes_per_block;
        sbi->s_desc_per_block = blocksize / EXT4_DESC_SIZE(sb);
        sbi->s_sbh = bh;
-       sbi->s_mount_state = le16_to_cpu(es->s_state);
+       sbi->s_mount_state = le16_to_cpu(es->s_state) & ~EXT4_FC_REPLAY;
        sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
        sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
 
@@ -5279,12 +5185,6 @@ no_journal:
                goto failed_mount_wq;
        }
 
-       if (DUMMY_ENCRYPTION_ENABLED(sbi) && !sb_rdonly(sb) &&
-           !ext4_has_feature_encrypt(sb)) {
-               ext4_set_feature_encrypt(sb);
-               ext4_commit_super(sb);
-       }
-
        /*
         * Get the # of file system overhead blocks from the
         * superblock if present.
@@ -6272,7 +6172,6 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
        char *to_free[EXT4_MAXQUOTAS];
 #endif
 
-       ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
 
        /* Store the original options */
        old_sb_flags = sb->s_flags;
@@ -6298,9 +6197,14 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
                } else
                        old_opts.s_qf_names[i] = NULL;
 #endif
-       if (sbi->s_journal && sbi->s_journal->j_task->io_context)
-               ctx->journal_ioprio =
-                       sbi->s_journal->j_task->io_context->ioprio;
+       if (!(ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO)) {
+               if (sbi->s_journal && sbi->s_journal->j_task->io_context)
+                       ctx->journal_ioprio =
+                               sbi->s_journal->j_task->io_context->ioprio;
+               else
+                       ctx->journal_ioprio = DEFAULT_JOURNAL_IOPRIO;
+
+       }
 
        ext4_apply_options(fc, sb);
 
@@ -6441,7 +6345,8 @@ static int __ext4_remount(struct fs_context *fc, struct super_block *sb)
                                if (err)
                                        goto restore_opts;
                        }
-                       sbi->s_mount_state = le16_to_cpu(es->s_state);
+                       sbi->s_mount_state = (le16_to_cpu(es->s_state) &
+                                             ~EXT4_FC_REPLAY);
 
                        err = ext4_setup_super(sb, es, 0);
                        if (err)