@ -317,6 +317,35 @@ static struct bio *__bio_alloc(struct f2fs_io_info *fio, int npages)
return bio ;
}
static int f2fs_set_bio_crypt_ctx ( struct bio * bio , const struct inode * inode ,
pgoff_t first_idx ,
const struct f2fs_io_info * fio ,
gfp_t gfp_mask )
{
/*
* The f2fs garbage collector sets - > encrypted_page when it wants to
* read / write raw data without encryption .
*/
if ( fio & & fio - > encrypted_page )
return 0 ;
return fscrypt_set_bio_crypt_ctx ( bio , inode , first_idx , gfp_mask ) ;
}
static bool f2fs_crypt_mergeable_bio ( struct bio * bio , const struct inode * inode ,
pgoff_t next_idx ,
const struct f2fs_io_info * fio )
{
/*
* The f2fs garbage collector sets - > encrypted_page when it wants to
* read / write raw data without encryption .
*/
if ( fio & & fio - > encrypted_page )
return true ;
return fscrypt_mergeable_bio ( bio , inode , next_idx ) ;
}
static inline void __submit_bio ( struct f2fs_sb_info * sbi ,
struct bio * bio , enum page_type type )
{
@ -514,6 +543,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
struct bio * bio ;
struct page * page = fio - > encrypted_page ?
fio - > encrypted_page : fio - > page ;
int err ;
if ( ! f2fs_is_valid_blkaddr ( fio - > sbi , fio - > new_blkaddr ,
fio - > is_por ? META_POR : ( __is_meta_io ( fio ) ?
@ -526,6 +556,13 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
/* Allocate a new bio */
bio = __bio_alloc ( fio , 1 ) ;
err = f2fs_set_bio_crypt_ctx ( bio , fio - > page - > mapping - > host ,
fio - > page - > index , fio , GFP_NOIO ) ;
if ( err ) {
bio_put ( bio ) ;
return err ;
}
if ( bio_add_page ( bio , page , PAGE_SIZE , 0 ) < PAGE_SIZE ) {
bio_put ( bio ) ;
return - EFAULT ;
@ -716,12 +753,17 @@ int f2fs_merge_page_bio(struct f2fs_io_info *fio)
trace_f2fs_submit_page_bio ( page , fio ) ;
f2fs_trace_ios ( fio , 0 ) ;
if ( bio & & ! page_is_mergeable ( fio - > sbi , bio , * fio - > last_block ,
fio - > new_blkaddr ) )
if ( bio & & ( ! page_is_mergeable ( fio - > sbi , bio , * fio - > last_block ,
fio - > new_blkaddr ) | |
! f2fs_crypt_mergeable_bio ( bio , fio - > page - > mapping - > host ,
fio - > page - > index , fio ) ) )
f2fs_submit_merged_ipu_write ( fio - > sbi , & bio , NULL ) ;
alloc_new :
if ( ! bio ) {
bio = __bio_alloc ( fio , BIO_MAX_PAGES ) ;
f2fs_set_bio_crypt_ctx ( bio , fio - > page - > mapping - > host ,
fio - > page - > index , fio ,
GFP_NOIO | __GFP_NOFAIL ) ;
bio_set_op_attrs ( bio , fio - > op , fio - > op_flags ) ;
add_bio_entry ( fio - > sbi , bio , page , fio - > temp ) ;
@ -773,8 +815,11 @@ next:
inc_page_count ( sbi , WB_DATA_TYPE ( bio_page ) ) ;
if ( io - > bio & & ! io_is_mergeable ( sbi , io - > bio , io , fio ,
io - > last_block_in_bio , fio - > new_blkaddr ) )
if ( io - > bio & &
( ! io_is_mergeable ( sbi , io - > bio , io , fio , io - > last_block_in_bio ,
fio - > new_blkaddr ) | |
! f2fs_crypt_mergeable_bio ( io - > bio , fio - > page - > mapping - > host ,
fio - > page - > index , fio ) ) )
__submit_merged_bio ( io ) ;
alloc_new :
if ( io - > bio = = NULL ) {
@ -786,6 +831,9 @@ alloc_new:
goto skip ;
}
io - > bio = __bio_alloc ( fio , BIO_MAX_PAGES ) ;
f2fs_set_bio_crypt_ctx ( io - > bio , fio - > page - > mapping - > host ,
fio - > page - > index , fio ,
GFP_NOIO | __GFP_NOFAIL ) ;
io - > fio = * fio ;
}
@ -825,15 +873,23 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
struct bio * bio ;
struct bio_post_read_ctx * ctx ;
unsigned int post_read_steps = 0 ;
int err ;
bio = f2fs_bio_alloc ( sbi , min_t ( int , nr_pages , BIO_MAX_PAGES ) , false ) ;
if ( ! bio )
return ERR_PTR ( - ENOMEM ) ;
err = f2fs_set_bio_crypt_ctx ( bio , inode , first_idx , NULL , GFP_NOFS ) ;
if ( err ) {
bio_put ( bio ) ;
return ERR_PTR ( err ) ;
}
f2fs_target_device ( sbi , blkaddr , bio ) ;
bio - > bi_end_io = f2fs_read_end_io ;
bio_set_op_attrs ( bio , REQ_OP_READ , op_flag ) ;
if ( f2fs_encrypted_file ( inode ) )
if ( fscrypt_inode_uses_fs_layer_crypto ( inode ) )
post_read_steps | = 1 < < STEP_DECRYPT ;
if ( f2fs_need_verity ( inode , first_idx ) )
@ -1870,8 +1926,9 @@ zero_out:
* This page will go to BIO . Do we need to send this
* BIO off first ?
*/
if ( bio & & ! page_is_mergeable ( F2FS_I_SB ( inode ) , bio ,
* last_block_in_bio , block_nr ) ) {
if ( bio & & ( ! page_is_mergeable ( F2FS_I_SB ( inode ) , bio ,
* last_block_in_bio , block_nr ) | |
! f2fs_crypt_mergeable_bio ( bio , inode , page - > index , NULL ) ) ) {
submit_and_realloc :
__f2fs_submit_read_bio ( F2FS_I_SB ( inode ) , bio , DATA ) ;
bio = NULL ;
@ -2011,6 +2068,9 @@ static int encrypt_one_page(struct f2fs_io_info *fio)
/* wait for GCed page writeback via META_MAPPING */
f2fs_wait_on_block_writeback ( inode , fio - > old_blkaddr ) ;
if ( fscrypt_inode_uses_inline_crypto ( inode ) )
return 0 ;
retry_encrypt :
fio - > encrypted_page = fscrypt_encrypt_pagecache_blocks ( fio - > page ,
PAGE_SIZE , 0 ,
@ -2185,7 +2245,7 @@ got_it:
f2fs_unlock_op ( fio - > sbi ) ;
err = f2fs_inplace_write_data ( fio ) ;
if ( err ) {
if ( f2fs_encrypted_file ( inode ) )
if ( fscrypt_inode_uses_fs_layer_crypto ( inode ) )
fscrypt_finalize_bounce_page ( & fio - > encrypted_page ) ;
if ( PageWriteback ( page ) )
end_page_writeback ( page ) ;