[RFC PATCH 17/19] btrfs: don't allow direct IO of encrypted extents

From: Mark Harmstone
Date: Tue Jan 08 2019 - 20:27:58 EST


Signed-off-by: Mark Harmstone <mark@xxxxxxxxxxxxx>
---
fs/btrfs/inode.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index f8bc7174f7e3..8f58f492abc8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -7945,6 +7945,17 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
goto unlock_err;
}

+ /*
+ * Fallback to buffered IO if we have an encrypted inode,
+ * as we would need to change what's in memory.
+ */
+ if ((create && inode_need_encrypt(inode)) ||
+ test_bit(EXTENT_FLAG_ENCRYPTED, &em->flags)) {
+ free_extent_map(em);
+ ret = -ENOTBLK;
+ goto unlock_err;
+ }
+
if (create) {
ret = btrfs_get_blocks_direct_write(&em, bh_result, inode,
dio_data, start, len);
--
2.19.2