mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 03:35:32 -04:00
f2fs: Remove fs-layer file contents en/decryption code
Now that fscrypt's file contents en/decryption is always implemented using blk-crypto when the filesystem is block-based, the fs-layer en/decryption code in f2fs is unused code. Remove it. Note that the struct f2fs_io_info field encrypted_page is kept because it is still used by the garbage collection path to relocate encrypted blocks using raw meta pages from META_MAPPING. Link: https://patch.msgid.link/20260713023708.9245-11-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
@@ -1286,8 +1286,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
|
||||
.compressed_page = NULL,
|
||||
.io_type = io_type,
|
||||
.io_wbc = wbc,
|
||||
.encrypted = fscrypt_inode_uses_fs_layer_crypto(cc->inode) ?
|
||||
1 : 0,
|
||||
};
|
||||
struct folio *folio;
|
||||
struct dnode_of_data dn;
|
||||
@@ -1361,14 +1359,6 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
|
||||
|
||||
/* wait for GCed page writeback via META_MAPPING */
|
||||
f2fs_wait_on_block_writeback(inode, fio.old_blkaddr);
|
||||
|
||||
if (fio.encrypted) {
|
||||
fio.page = cc->rpages[i + 1];
|
||||
err = f2fs_encrypt_one_page(&fio);
|
||||
if (err)
|
||||
goto out_destroy_crypt;
|
||||
cc->cpages[i] = fio.encrypted_page;
|
||||
}
|
||||
}
|
||||
|
||||
set_cluster_writeback(cc);
|
||||
@@ -1406,21 +1396,15 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
|
||||
|
||||
f2fs_bug_on(fio.sbi, blkaddr == NULL_ADDR);
|
||||
|
||||
if (fio.encrypted)
|
||||
fio.encrypted_page = cc->cpages[i - 1];
|
||||
else
|
||||
fio.compressed_page = cc->cpages[i - 1];
|
||||
fio.compressed_page = cc->cpages[i - 1];
|
||||
|
||||
cc->cpages[i - 1] = NULL;
|
||||
fio.submitted = 0;
|
||||
f2fs_outplace_write_data(&dn, &fio);
|
||||
if (unlikely(!fio.submitted)) {
|
||||
cancel_cluster_writeback(cc, cic, i);
|
||||
|
||||
/* To call fscrypt_finalize_bounce_page */
|
||||
i = cc->valid_nr_cpages;
|
||||
*submitted = 0;
|
||||
goto out_destroy_crypt;
|
||||
goto out_free_page_array;
|
||||
}
|
||||
(*submitted)++;
|
||||
unlock_continue:
|
||||
@@ -1452,17 +1436,8 @@ static int f2fs_write_compressed_pages(struct compress_ctx *cc,
|
||||
f2fs_destroy_compress_ctx(cc, false);
|
||||
return 0;
|
||||
|
||||
out_destroy_crypt:
|
||||
out_free_page_array:
|
||||
page_array_free(sbi, cic->rpages, cc->cluster_size);
|
||||
|
||||
if (!fio.encrypted)
|
||||
goto out_put_cic;
|
||||
|
||||
for (--i; i >= 0; i--) {
|
||||
if (!cc->cpages[i])
|
||||
continue;
|
||||
fscrypt_finalize_bounce_page(&cc->cpages[i]);
|
||||
}
|
||||
out_put_cic:
|
||||
kmem_cache_free(cic_entry_slab, cic);
|
||||
out_put_dnode:
|
||||
|
||||
@@ -65,9 +65,6 @@ bool f2fs_is_cp_guaranteed(const struct folio *folio)
|
||||
struct inode *inode;
|
||||
struct f2fs_sb_info *sbi;
|
||||
|
||||
if (fscrypt_is_bounce_folio(folio))
|
||||
return folio_test_f2fs_gcing(fscrypt_pagecache_folio(folio));
|
||||
|
||||
inode = mapping->host;
|
||||
sbi = F2FS_I_SB(inode);
|
||||
|
||||
@@ -101,11 +98,6 @@ static enum count_type __read_io_type(struct folio *folio)
|
||||
|
||||
/* postprocessing steps for read bios */
|
||||
enum bio_post_read_step {
|
||||
#ifdef CONFIG_FS_ENCRYPTION
|
||||
STEP_DECRYPT = BIT(0),
|
||||
#else
|
||||
STEP_DECRYPT = 0, /* compile out the decryption-related code */
|
||||
#endif
|
||||
#ifdef CONFIG_F2FS_FS_COMPRESSION
|
||||
STEP_DECOMPRESS = BIT(1),
|
||||
#else
|
||||
@@ -301,11 +293,6 @@ static void f2fs_post_read_work(struct work_struct *work)
|
||||
container_of(work, struct bio_post_read_ctx, work);
|
||||
struct bio *bio = ctx->bio;
|
||||
|
||||
if ((ctx->enabled_steps & STEP_DECRYPT) && !fscrypt_decrypt_bio(bio)) {
|
||||
f2fs_finish_read_bio(bio, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx->enabled_steps & STEP_DECOMPRESS)
|
||||
f2fs_handle_step_decompress(ctx, true);
|
||||
|
||||
@@ -329,18 +316,11 @@ static void f2fs_read_end_io(struct bio *bio)
|
||||
return;
|
||||
}
|
||||
|
||||
if (ctx) {
|
||||
unsigned int enabled_steps = ctx->enabled_steps &
|
||||
(STEP_DECRYPT | STEP_DECOMPRESS);
|
||||
|
||||
/*
|
||||
* If we have only decompression step between decompression and
|
||||
* decrypt, we don't need post processing for this.
|
||||
*/
|
||||
if (enabled_steps == STEP_DECOMPRESS &&
|
||||
!f2fs_low_mem_mode(sbi)) {
|
||||
if (ctx && (ctx->enabled_steps & STEP_DECOMPRESS)) {
|
||||
if (!f2fs_low_mem_mode(sbi)) {
|
||||
/* Decompress inline. */
|
||||
f2fs_handle_step_decompress(ctx, intask);
|
||||
} else if (enabled_steps) {
|
||||
} else {
|
||||
INIT_WORK(&ctx->work, f2fs_post_read_work);
|
||||
queue_work(ctx->sbi->wq, &ctx->work);
|
||||
return;
|
||||
@@ -362,13 +342,6 @@ static void f2fs_write_end_bio(struct bio *bio)
|
||||
struct folio *folio = fi.folio;
|
||||
enum count_type type;
|
||||
|
||||
if (fscrypt_is_bounce_folio(folio)) {
|
||||
struct folio *io_folio = folio;
|
||||
|
||||
folio = fscrypt_pagecache_folio(io_folio);
|
||||
fscrypt_free_bounce_page(&io_folio->page);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_F2FS_FS_COMPRESSION
|
||||
if (f2fs_is_compressed_page(folio)) {
|
||||
f2fs_compress_write_end_io(bio, folio);
|
||||
@@ -614,11 +587,6 @@ static bool __has_merged_page(struct bio *bio, struct inode *inode,
|
||||
bio_for_each_folio_all(fi, bio) {
|
||||
struct folio *target = fi.folio;
|
||||
|
||||
if (fscrypt_is_bounce_folio(target)) {
|
||||
target = fscrypt_pagecache_folio(target);
|
||||
if (IS_ERR(target))
|
||||
continue;
|
||||
}
|
||||
if (f2fs_is_compressed_page(target)) {
|
||||
target = f2fs_compress_control_folio(target);
|
||||
if (IS_ERR(target))
|
||||
@@ -1161,9 +1129,6 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode,
|
||||
f2fs_set_bio_crypt_ctx(bio, inode, first_idx, NULL, GFP_NOFS);
|
||||
bio->bi_end_io = f2fs_read_end_io;
|
||||
|
||||
if (fscrypt_inode_uses_fs_layer_crypto(inode))
|
||||
post_read_steps |= STEP_DECRYPT;
|
||||
|
||||
if (vi)
|
||||
post_read_steps |= STEP_VERITY;
|
||||
|
||||
@@ -2852,35 +2817,6 @@ static void f2fs_readahead(struct readahead_control *rac)
|
||||
f2fs_mpage_readpages(inode, vi, rac, NULL);
|
||||
}
|
||||
|
||||
int f2fs_encrypt_one_page(struct f2fs_io_info *fio)
|
||||
{
|
||||
struct inode *inode = fio_inode(fio);
|
||||
struct folio *mfolio;
|
||||
struct page *page;
|
||||
|
||||
if (!f2fs_encrypted_file(inode))
|
||||
return 0;
|
||||
|
||||
page = fio->compressed_page ? fio->compressed_page : fio->page;
|
||||
|
||||
if (fscrypt_inode_uses_inline_crypto(inode))
|
||||
return 0;
|
||||
|
||||
fio->encrypted_page = fscrypt_encrypt_pagecache_blocks(page_folio(page),
|
||||
PAGE_SIZE, 0, GFP_NOFS);
|
||||
if (IS_ERR(fio->encrypted_page))
|
||||
return PTR_ERR(fio->encrypted_page);
|
||||
|
||||
mfolio = filemap_lock_folio(META_MAPPING(fio->sbi), fio->old_blkaddr);
|
||||
if (!IS_ERR(mfolio)) {
|
||||
if (folio_test_uptodate(mfolio))
|
||||
memcpy(folio_address(mfolio),
|
||||
page_address(fio->encrypted_page), PAGE_SIZE);
|
||||
f2fs_folio_put(mfolio, true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool check_inplace_update_policy(struct inode *inode,
|
||||
struct f2fs_io_info *fio)
|
||||
{
|
||||
@@ -3053,22 +2989,15 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
||||
if (ipu_force ||
|
||||
(__is_valid_data_blkaddr(fio->old_blkaddr) &&
|
||||
need_inplace_update(fio))) {
|
||||
err = f2fs_encrypt_one_page(fio);
|
||||
if (err)
|
||||
goto out_writepage;
|
||||
|
||||
folio_start_writeback(folio);
|
||||
f2fs_put_dnode(&dn);
|
||||
if (fio->need_lock == LOCK_REQ)
|
||||
f2fs_unlock_op(fio->sbi, &lc);
|
||||
err = f2fs_inplace_write_data(fio);
|
||||
if (err) {
|
||||
if (fscrypt_inode_uses_fs_layer_crypto(inode))
|
||||
fscrypt_finalize_bounce_page(&fio->encrypted_page);
|
||||
if (err)
|
||||
folio_end_writeback(folio);
|
||||
} else {
|
||||
else
|
||||
set_inode_flag(inode, FI_UPDATE_WRITE);
|
||||
}
|
||||
trace_f2fs_do_write_data_page(folio, IPU);
|
||||
return err;
|
||||
}
|
||||
@@ -3087,10 +3016,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
|
||||
|
||||
fio->version = ni.version;
|
||||
|
||||
err = f2fs_encrypt_one_page(fio);
|
||||
if (err)
|
||||
goto out_writepage;
|
||||
|
||||
folio_start_writeback(folio);
|
||||
|
||||
if (fio->compr_blocks && fio->old_blkaddr == COMPRESS_ADDR)
|
||||
@@ -4602,9 +4527,9 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length,
|
||||
iomap->offset = F2FS_BLK_TO_BYTES(map.m_lblk);
|
||||
|
||||
/*
|
||||
* When inline encryption is enabled, sometimes I/O to an encrypted file
|
||||
* has to be broken up to guarantee DUN contiguity. Handle this by
|
||||
* limiting the length of the mapping returned.
|
||||
* Sometimes I/O to an encrypted file has to be broken up to guarantee
|
||||
* DUN contiguity. Handle this by limiting the length of the mapping
|
||||
* returned.
|
||||
*/
|
||||
map.m_len = fscrypt_limit_io_blocks(inode, map.m_lblk, map.m_len);
|
||||
|
||||
|
||||
@@ -1364,7 +1364,6 @@ struct f2fs_io_info {
|
||||
unsigned int submitted:1; /* indicate IO submission */
|
||||
unsigned int in_list:1; /* indicate fio is in io_list */
|
||||
unsigned int is_por:1; /* indicate IO is from recovery or not */
|
||||
unsigned int encrypted:1; /* indicate file is encrypted */
|
||||
unsigned int meta_gc:1; /* require meta inode GC */
|
||||
enum iostat_type io_type; /* io type */
|
||||
struct writeback_control *io_wbc; /* writeback control */
|
||||
@@ -4199,7 +4198,6 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio);
|
||||
int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, int flag);
|
||||
int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||
u64 start, u64 len);
|
||||
int f2fs_encrypt_one_page(struct f2fs_io_info *fio);
|
||||
bool f2fs_should_update_inplace(struct inode *inode, struct f2fs_io_info *fio);
|
||||
bool f2fs_should_update_outplace(struct inode *inode, struct f2fs_io_info *fio);
|
||||
int f2fs_write_single_data_page(struct folio *folio, int *submitted,
|
||||
|
||||
@@ -3986,8 +3986,6 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
|
||||
"%s Failed to allocate data block, ino:%u, index:%lu, type:%d, old_blkaddr:0x%x, new_blkaddr:0x%x, err:%d",
|
||||
__func__, fio->ino, folio->index, type,
|
||||
fio->old_blkaddr, fio->new_blkaddr, err);
|
||||
if (fscrypt_inode_uses_fs_layer_crypto(folio->mapping->host))
|
||||
fscrypt_finalize_bounce_page(&fio->encrypted_page);
|
||||
folio_end_writeback(folio);
|
||||
if (f2fs_in_warm_node_list(folio))
|
||||
f2fs_del_fsync_node_entry(fio->sbi, folio);
|
||||
|
||||
@@ -3776,7 +3776,6 @@ static const struct fscrypt_operations f2fs_cryptops = {
|
||||
.inode_info_offs = (int)offsetof(struct f2fs_inode_info, i_crypt_info) -
|
||||
(int)offsetof(struct f2fs_inode_info, vfs_inode),
|
||||
.is_block_based = 1,
|
||||
.needs_bounce_pages = 1,
|
||||
.has_32bit_inodes = 1,
|
||||
.supports_subblock_data_units = 1,
|
||||
.legacy_key_prefix = "f2fs:",
|
||||
|
||||
Reference in New Issue
Block a user