Re: [f2fs-dev] [PATCH 13/13] ext4: encrypt only up to last block in ext4_bio_write_page()

2019-05-06 Thread Chandan Rajendra
On Thursday, May 2, 2019 4:15:15 AM IST Eric Biggers wrote:
> From: Eric Biggers 
> 
> 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.
>

Looks good to me,

Reviewed-by: Chandan Rajendra 

-- 
chandan





___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


[f2fs-dev] [PATCH 13/13] ext4: encrypt only up to last block in ext4_bio_write_page()

2019-05-01 Thread Eric Biggers
From: Eric Biggers 

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.

Signed-off-by: Eric Biggers 
---
 fs/ext4/page-io.c | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/page-io.c b/fs/ext4/page-io.c
index 457ddf051608f..ab843ad89df2f 100644
--- a/fs/ext4/page-io.c
+++ b/fs/ext4/page-io.c
@@ -468,11 +468,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);
-- 
2.21.0.593.g511ec345e18-goog



___
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel