add patch use-swap-in-memswap
[ext4-patch-queue.git] / clean-up-superblock-encryption-mode-fields
blob2071b44be122bafd95c7dd347af2729b0af26e1a
1 ext4: clean up superblock encryption mode fields
3 The superblock fields s_file_encryption_mode and s_dir_encryption_mode
4 are vestigal, so remove them as a cleanup.  While we're at it, allow
5 file systems with both encryption and inline_data enabled at the same
6 time to work correctly.  We can't have encrypted inodes with inline
7 data, but there's no reason to prohibit unencrypted inodes from using
8 the inline data feature.
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/ext4/crypto_policy.c |  9 +++++++--
13  fs/ext4/ext4.h          |  6 ------
14  fs/ext4/ialloc.c        | 19 -------------------
15  fs/ext4/super.c         |  5 -----
16  4 files changed, 7 insertions(+), 32 deletions(-)
18 diff --git a/fs/ext4/crypto_policy.c b/fs/ext4/crypto_policy.c
19 index 370d3aa..683391f 100644
20 --- a/fs/ext4/crypto_policy.c
21 +++ b/fs/ext4/crypto_policy.c
22 @@ -51,6 +51,10 @@ static int ext4_create_encryption_context_from_policy(
23         struct ext4_encryption_context ctx;
24         int res = 0;
26 +       res = ext4_convert_inline_data(inode);
27 +       if (res)
28 +               return res;
30         ctx.format = EXT4_ENCRYPTION_CONTEXT_FORMAT_V1;
31         memcpy(ctx.master_key_descriptor, policy->master_key_descriptor,
32                EXT4_KEY_DESCRIPTOR_SIZE);
33 @@ -199,8 +203,9 @@ int ext4_inherit_context(struct inode *parent, struct inode *child)
34         res = ext4_xattr_set(child, EXT4_XATTR_INDEX_ENCRYPTION,
35                              EXT4_XATTR_NAME_ENCRYPTION_CONTEXT, &ctx,
36                              sizeof(ctx), 0);
37 -       if (!res)
38 +       if (!res) {
39                 ext4_set_inode_flag(child, EXT4_INODE_ENCRYPT);
40 +               ext4_clear_inode_state(child, EXT4_STATE_MAY_INLINE_DATA);
41 +       }
42         return res;
44  }
45 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
46 index 6dd3f51..4b589fe 100644
47 --- a/fs/ext4/ext4.h
48 +++ b/fs/ext4/ext4.h
49 @@ -1374,12 +1374,6 @@ struct ext4_sb_info {
50         struct ratelimit_state s_err_ratelimit_state;
51         struct ratelimit_state s_warning_ratelimit_state;
52         struct ratelimit_state s_msg_ratelimit_state;
54 -#ifdef CONFIG_EXT4_FS_ENCRYPTION
55 -       /* Encryption */
56 -       uint32_t s_file_encryption_mode;
57 -       uint32_t s_dir_encryption_mode;
58 -#endif
59  };
61  static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
62 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
63 index 2cf18a2..8fa00d3 100644
64 --- a/fs/ext4/ialloc.c
65 +++ b/fs/ext4/ialloc.c
66 @@ -1034,28 +1034,9 @@ got:
67         ext4_set_inode_state(inode, EXT4_STATE_NEW);
69         ei->i_extra_isize = EXT4_SB(sb)->s_want_extra_isize;
70 -#ifdef CONFIG_EXT4_FS_ENCRYPTION
71 -       if ((sbi->s_file_encryption_mode == EXT4_ENCRYPTION_MODE_INVALID) &&
72 -           (sbi->s_dir_encryption_mode == EXT4_ENCRYPTION_MODE_INVALID)) {
73 -               ei->i_inline_off = 0;
74 -               if (EXT4_HAS_INCOMPAT_FEATURE(sb,
75 -                       EXT4_FEATURE_INCOMPAT_INLINE_DATA))
76 -                       ext4_set_inode_state(inode,
77 -                       EXT4_STATE_MAY_INLINE_DATA);
78 -       } else {
79 -               /* Inline data and encryption are incompatible
80 -                * We turn off inline data since encryption is enabled */
81 -               ei->i_inline_off = 1;
82 -               if (EXT4_HAS_INCOMPAT_FEATURE(sb,
83 -                       EXT4_FEATURE_INCOMPAT_INLINE_DATA))
84 -                       ext4_clear_inode_state(inode,
85 -                       EXT4_STATE_MAY_INLINE_DATA);
86 -       }
87 -#else
88         ei->i_inline_off = 0;
89         if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_INLINE_DATA))
90                 ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
91 -#endif
92         ret = inode;
93         err = dquot_alloc_inode(inode);
94         if (err)
95 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
96 index c0df4f7..4ac5df5 100644
97 --- a/fs/ext4/super.c
98 +++ b/fs/ext4/super.c
99 @@ -3450,11 +3450,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
100         if (sb->s_bdev->bd_part)
101                 sbi->s_sectors_written_start =
102                         part_stat_read(sb->s_bdev->bd_part, sectors[1]);
103 -#ifdef CONFIG_EXT4_FS_ENCRYPTION
104 -       /* Modes of operations for file and directory encryption. */
105 -       sbi->s_file_encryption_mode = EXT4_ENCRYPTION_MODE_AES_256_XTS;
106 -       sbi->s_dir_encryption_mode = EXT4_ENCRYPTION_MODE_INVALID;
107 -#endif
109         /* Cleanup superblock name */
110         for (cp = sb->s_id; (cp = strchr(cp, '/'));)