fs, fscrypt: add an S_ENCRYPTED inode flag
Introduce a flag S_ENCRYPTED which can be set in ->i_flags to indicate that the inode is encrypted using the fscrypt (fs/crypto/) mechanism. Checking this flag will give the same information that inode->i_sb->s_cop->is_encrypted(inode) currently does, but will be more efficient. This will be useful for adding higher-level helper functions for filesystems to use. For example we'll be able to replace this: if (ext4_encrypted_inode(inode)) { ret = fscrypt_get_encryption_info(inode); if (ret) return ret; if (!fscrypt_has_encryption_key(inode)) return -ENOKEY; } with this: ret = fscrypt_require_key(inode); if (ret) return ret; ... since we'll be able to retain the fast path for unencrypted files as a single flag check, using an inline function. This wasn't possible before because we'd have had to frequently call through the ->i_sb->s_cop->is_encrypted function pointer, even when the encryption support was disabled or not being used. Note: we don't define S_ENCRYPTED to 0 if CONFIG_FS_ENCRYPTION is disabled because we want to continue to return an error if an encrypted file is accessed without encryption support, rather than pretending that it is unencrypted. Reviewed-by: Chao Yu <yuchao0@huawei.com> Acked-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
1617929c3b
commit
685285b0b3
5 changed files with 17 additions and 4 deletions
|
@ -4374,8 +4374,11 @@ void ext4_set_inode_flags(struct inode *inode)
|
||||||
new_fl |= S_DIRSYNC;
|
new_fl |= S_DIRSYNC;
|
||||||
if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode))
|
if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode))
|
||||||
new_fl |= S_DAX;
|
new_fl |= S_DAX;
|
||||||
|
if (flags & EXT4_ENCRYPT_FL)
|
||||||
|
new_fl |= S_ENCRYPTED;
|
||||||
inode_set_flags(inode, new_fl,
|
inode_set_flags(inode, new_fl,
|
||||||
S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
|
S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX|
|
||||||
|
S_ENCRYPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
|
/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
|
||||||
|
|
|
@ -1130,7 +1130,8 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
|
||||||
ext4_clear_inode_state(inode,
|
ext4_clear_inode_state(inode,
|
||||||
EXT4_STATE_MAY_INLINE_DATA);
|
EXT4_STATE_MAY_INLINE_DATA);
|
||||||
/*
|
/*
|
||||||
* Update inode->i_flags - e.g. S_DAX may get disabled
|
* Update inode->i_flags - S_ENCRYPTED will be enabled,
|
||||||
|
* S_DAX may be disabled
|
||||||
*/
|
*/
|
||||||
ext4_set_inode_flags(inode);
|
ext4_set_inode_flags(inode);
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1152,10 @@ retry:
|
||||||
ctx, len, 0);
|
ctx, len, 0);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
|
ext4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);
|
||||||
/* Update inode->i_flags - e.g. S_DAX may get disabled */
|
/*
|
||||||
|
* Update inode->i_flags - S_ENCRYPTED will be enabled,
|
||||||
|
* S_DAX may be disabled
|
||||||
|
*/
|
||||||
ext4_set_inode_flags(inode);
|
ext4_set_inode_flags(inode);
|
||||||
res = ext4_mark_inode_dirty(handle, inode);
|
res = ext4_mark_inode_dirty(handle, inode);
|
||||||
if (res)
|
if (res)
|
||||||
|
|
|
@ -3094,6 +3094,7 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
#ifdef CONFIG_F2FS_FS_ENCRYPTION
|
||||||
file_set_encrypt(inode);
|
file_set_encrypt(inode);
|
||||||
|
inode->i_flags |= S_ENCRYPTED;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,11 @@ void f2fs_set_inode_flags(struct inode *inode)
|
||||||
new_fl |= S_NOATIME;
|
new_fl |= S_NOATIME;
|
||||||
if (flags & FS_DIRSYNC_FL)
|
if (flags & FS_DIRSYNC_FL)
|
||||||
new_fl |= S_DIRSYNC;
|
new_fl |= S_DIRSYNC;
|
||||||
|
if (f2fs_encrypted_inode(inode))
|
||||||
|
new_fl |= S_ENCRYPTED;
|
||||||
inode_set_flags(inode, new_fl,
|
inode_set_flags(inode, new_fl,
|
||||||
S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
|
S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|
|
||||||
|
S_ENCRYPTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri)
|
static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri)
|
||||||
|
|
|
@ -1843,6 +1843,7 @@ struct super_operations {
|
||||||
#else
|
#else
|
||||||
#define S_DAX 0 /* Make all the DAX code disappear */
|
#define S_DAX 0 /* Make all the DAX code disappear */
|
||||||
#endif
|
#endif
|
||||||
|
#define S_ENCRYPTED 16384 /* Encrypted file (using fs/crypto/) */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note that nosuid etc flags are inode-specific: setting some file-system
|
* Note that nosuid etc flags are inode-specific: setting some file-system
|
||||||
|
@ -1881,6 +1882,7 @@ struct super_operations {
|
||||||
#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
|
#define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
|
||||||
#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
|
#define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
|
||||||
#define IS_DAX(inode) ((inode)->i_flags & S_DAX)
|
#define IS_DAX(inode) ((inode)->i_flags & S_DAX)
|
||||||
|
#define IS_ENCRYPTED(inode) ((inode)->i_flags & S_ENCRYPTED)
|
||||||
|
|
||||||
#define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \
|
#define IS_WHITEOUT(inode) (S_ISCHR(inode->i_mode) && \
|
||||||
(inode)->i_rdev == WHITEOUT_DEV)
|
(inode)->i_rdev == WHITEOUT_DEV)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue