diff mbox series

[4/5] ext4: support direct I/O with fscrypt using blk-crypto

Message ID 20200709194751.2579207-5-satyat@google.com
State Superseded
Headers show
Series add support for direct I/O with fscrypt using blk-crypto | expand

Commit Message

Satya Tangirala July 9, 2020, 7:47 p.m. UTC
From: Eric Biggers <ebiggers@google.com>

Wire up ext4 with fscrypt direct I/O support.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Satya Tangirala <satyat@google.com>
---
 fs/ext4/file.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Eric Biggers July 9, 2020, 10:30 p.m. UTC | #1
On Thu, Jul 09, 2020 at 07:47:50PM +0000, Satya Tangirala wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> Wire up ext4 with fscrypt direct I/O support.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> Signed-off-by: Satya Tangirala <satyat@google.com>

This commit message could use some more details.  I think it should clarify that
the direct I/O support is limited to cases where the filesystem has been mounted
with '-o inlinecrypt' and CONFIG_BLK_INLINE_ENCRYPTION has been enabled, along
with CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK if hardware support isn't present.

As-is, it sounds a bit over-promising.

Likewise for f2fs.

We need to properly document this too.  At the very least, in the fscrypt patch,
Documentation/filesystems/fscrypt.rst needs to be updated because it currently
says "Direct I/O is not supported on encrypted files."

fscrypt.rst could also use some information about inline encryption.  Currently
inline encryption for fscrypt is only documented in the ext4 and f2fs
documentation in the context of the inlinecrypt mount option.  (Though, this
suggestion applies even without direct I/O support.)

- Eric
diff mbox series

Patch

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 2a01e31a032c..d534f72675d9 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -36,9 +36,11 @@ 
 #include "acl.h"
 #include "truncate.h"
 
-static bool ext4_dio_supported(struct inode *inode)
+static bool ext4_dio_supported(struct kiocb *iocb, struct iov_iter *iter)
 {
-	if (IS_ENABLED(CONFIG_FS_ENCRYPTION) && IS_ENCRYPTED(inode))
+	struct inode *inode = file_inode(iocb->ki_filp);
+
+	if (!fscrypt_dio_supported(iocb, iter))
 		return false;
 	if (fsverity_active(inode))
 		return false;
@@ -61,7 +63,7 @@  static ssize_t ext4_dio_read_iter(struct kiocb *iocb, struct iov_iter *to)
 		inode_lock_shared(inode);
 	}
 
-	if (!ext4_dio_supported(inode)) {
+	if (!ext4_dio_supported(iocb, to)) {
 		inode_unlock_shared(inode);
 		/*
 		 * Fallback to buffered I/O if the operation being performed on
@@ -490,7 +492,7 @@  static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 	/* Fallback to buffered I/O if the inode does not support direct I/O. */
-	if (!ext4_dio_supported(inode)) {
+	if (!ext4_dio_supported(iocb, from)) {
 		if (ilock_shared)
 			inode_unlock_shared(inode);
 		else