aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2019-05-20 09:29:52 -0700
committerEric Biggers <ebiggers@google.com>2019-05-28 10:27:53 -0700
commit6e4b73bcd1519d50680d92ba74887c80c4e59140 (patch)
tree36dcd075033712f765fedf4340713b8f23122803 /fs/ext4
parentext4: decrypt only the needed block in __ext4_block_zero_page_range() (diff)
downloadlinux-dev-6e4b73bcd1519d50680d92ba74887c80c4e59140.tar.xz
linux-dev-6e4b73bcd1519d50680d92ba74887c80c4e59140.zip
ext4: encrypt only up to last block in ext4_bio_write_page()
As an optimization, don't encrypt blocks fully beyond i_size, since those definitely won't need to be written out. Also add a comment. This is in preparation for allowing encryption on ext4 filesystems with blocksize != PAGE_SIZE. This is based on work by Chandan Rajendra. Reviewed-by: Chandan Rajendra <chandan@linux.ibm.com> Signed-off-by: Eric Biggers <ebiggers@google.com>
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/page-io.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 40ee33df5764..a18a47a2a1d1 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -467,11 +467,19 @@ int ext4_bio_write_page(struct ext4_io_submit *io,
bh = head = page_buffers(page);
+ /*
+ * If any blocks are being written to an encrypted file, encrypt them
+ * into a bounce page. For simplicity, just encrypt until the last
+ * block which might be needed. This may cause some unneeded blocks
+ * (e.g. holes) to be unnecessarily encrypted, but this is rare and
+ * can't happen in the common case of blocksize == PAGE_SIZE.
+ */
if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) {
gfp_t gfp_flags = GFP_NOFS;
+ unsigned int enc_bytes = round_up(len, i_blocksize(inode));
retry_encrypt:
- bounce_page = fscrypt_encrypt_pagecache_blocks(page, PAGE_SIZE,
+ bounce_page = fscrypt_encrypt_pagecache_blocks(page, enc_bytes,
0, gfp_flags);
if (IS_ERR(bounce_page)) {
ret = PTR_ERR(bounce_page);