* [PATCH] fscrypt: introduce fscrypt_needs_contents_encryption()
@ 2019-12-09 20:50 Eric Biggers
2020-01-03 16:59 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2019-12-09 20:50 UTC (permalink / raw)
To: linux-fscrypt; +Cc: linux-ext4, linux-f2fs-devel, linux-fsdevel
From: Eric Biggers <ebiggers@google.com>
Add a function fscrypt_needs_contents_encryption() which takes an inode
and returns true if it's an encrypted regular file and the kernel was
built with fscrypt support.
This will allow replacing duplicated checks of IS_ENCRYPTED() &&
S_ISREG() on the I/O paths in ext4 and f2fs, while also optimizing out
unneeded code when !CONFIG_FS_ENCRYPTION.
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
include/linux/fscrypt.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
index cb18b5fbcef92..2a29f56b1a1cb 100644
--- a/include/linux/fscrypt.h
+++ b/include/linux/fscrypt.h
@@ -72,6 +72,21 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode)
return READ_ONCE(inode->i_crypt_info) != NULL;
}
+/**
+ * fscrypt_needs_contents_encryption() - check whether an inode needs
+ * contents encryption
+ *
+ * Return: %true iff the inode is an encrypted regular file and the kernel was
+ * built with fscrypt support.
+ *
+ * If you need to know whether the encrypt bit is set even when the kernel was
+ * built without fscrypt support, you must use IS_ENCRYPTED() directly instead.
+ */
+static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
+{
+ return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
+}
+
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
{
return inode->i_sb->s_cop->dummy_context &&
@@ -269,6 +284,11 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode)
return false;
}
+static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
+{
+ return false;
+}
+
static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
{
return false;
--
2.24.0.393.g34dc348eaf-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] fscrypt: introduce fscrypt_needs_contents_encryption()
2019-12-09 20:50 [PATCH] fscrypt: introduce fscrypt_needs_contents_encryption() Eric Biggers
@ 2020-01-03 16:59 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2020-01-03 16:59 UTC (permalink / raw)
To: linux-fscrypt; +Cc: linux-ext4, linux-f2fs-devel, linux-fsdevel
On Mon, Dec 09, 2019 at 12:50:21PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> Add a function fscrypt_needs_contents_encryption() which takes an inode
> and returns true if it's an encrypted regular file and the kernel was
> built with fscrypt support.
>
> This will allow replacing duplicated checks of IS_ENCRYPTED() &&
> S_ISREG() on the I/O paths in ext4 and f2fs, while also optimizing out
> unneeded code when !CONFIG_FS_ENCRYPTION.
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> include/linux/fscrypt.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/include/linux/fscrypt.h b/include/linux/fscrypt.h
> index cb18b5fbcef92..2a29f56b1a1cb 100644
> --- a/include/linux/fscrypt.h
> +++ b/include/linux/fscrypt.h
> @@ -72,6 +72,21 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode)
> return READ_ONCE(inode->i_crypt_info) != NULL;
> }
>
> +/**
> + * fscrypt_needs_contents_encryption() - check whether an inode needs
> + * contents encryption
> + *
> + * Return: %true iff the inode is an encrypted regular file and the kernel was
> + * built with fscrypt support.
> + *
> + * If you need to know whether the encrypt bit is set even when the kernel was
> + * built without fscrypt support, you must use IS_ENCRYPTED() directly instead.
> + */
> +static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
> +{
> + return IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode);
> +}
> +
> static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
> {
> return inode->i_sb->s_cop->dummy_context &&
> @@ -269,6 +284,11 @@ static inline bool fscrypt_has_encryption_key(const struct inode *inode)
> return false;
> }
>
> +static inline bool fscrypt_needs_contents_encryption(const struct inode *inode)
> +{
> + return false;
> +}
> +
> static inline bool fscrypt_dummy_context_enabled(struct inode *inode)
> {
> return false;
> --
> 2.24.0.393.g34dc348eaf-goog
>
Applied to fscrypt.git#master for 5.6.
- Eric
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-03 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-09 20:50 [PATCH] fscrypt: introduce fscrypt_needs_contents_encryption() Eric Biggers
2020-01-03 16:59 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).