diff options
author | Eric Biggers <ebiggers@google.com> | 2019-05-20 12:29:52 -0400 |
---|---|---|
committer | Eric Biggers <ebiggers@google.com> | 2019-05-28 13:27:53 -0400 |
commit | 6e4b73bcd1519d50680d92ba74887c80c4e59140 (patch) | |
tree | 36dcd075033712f765fedf4340713b8f23122803 | |
parent | ec39a36867440995c9675b2800f5ddaeb51b024e (diff) |
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>
-rw-r--r-- | fs/ext4/page-io.c | 10 |
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, | |||
467 | 467 | ||
468 | bh = head = page_buffers(page); | 468 | bh = head = page_buffers(page); |
469 | 469 | ||
470 | /* | ||
471 | * If any blocks are being written to an encrypted file, encrypt them | ||
472 | * into a bounce page. For simplicity, just encrypt until the last | ||
473 | * block which might be needed. This may cause some unneeded blocks | ||
474 | * (e.g. holes) to be unnecessarily encrypted, but this is rare and | ||
475 | * can't happen in the common case of blocksize == PAGE_SIZE. | ||
476 | */ | ||
470 | if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) { | 477 | if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode) && nr_to_submit) { |
471 | gfp_t gfp_flags = GFP_NOFS; | 478 | gfp_t gfp_flags = GFP_NOFS; |
479 | unsigned int enc_bytes = round_up(len, i_blocksize(inode)); | ||
472 | 480 | ||
473 | retry_encrypt: | 481 | retry_encrypt: |
474 | bounce_page = fscrypt_encrypt_pagecache_blocks(page, PAGE_SIZE, | 482 | bounce_page = fscrypt_encrypt_pagecache_blocks(page, enc_bytes, |
475 | 0, gfp_flags); | 483 | 0, gfp_flags); |
476 | if (IS_ERR(bounce_page)) { | 484 | if (IS_ERR(bounce_page)) { |
477 | ret = PTR_ERR(bounce_page); | 485 | ret = PTR_ERR(bounce_page); |