Re: [f2fs-dev] [PATCH v7 10/12] f2fs: cache: support fault injection

From: Chao Yu

Date: Mon Sep 14 2026 - 22:25:37 EST


On 9/14/26 17:35, Zhiguo Niu wrote:
Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx>
于2026年9月12日周六 07:28写道:

From: Chao Yu <chao@xxxxxxxxxx>

This patch adds fault injection support for metadata cache allocations
to improve error-path test coverage.
- it integrates entry allocations with FAULT_KALLOC
FAULT_KALLOC -> FAULT_KMALLOC?

Will fix.

Thanks,


Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
---
fs/f2fs/cache.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/fs/f2fs/cache.c b/fs/f2fs/cache.c
index 7260c157654b..dcab0f321730 100644
--- a/fs/f2fs/cache.c
+++ b/fs/f2fs/cache.c
@@ -154,23 +154,27 @@ static struct f2fs_cached_block *f2fs_create_cache(
struct f2fs_cached_block_list *cache,
unsigned long index, bool nofail)
{
+ struct f2fs_sb_info *sbi = cache->sbi;
struct f2fs_cached_block *entry;
unsigned int flags = GFP_NOFS;

if (index == ULONG_MAX)
return ERR_PTR(-ERANGE);

- if (nofail)
+ if (nofail) {
flags |= __GFP_NOFAIL;
-
- entry = kzalloc_obj(*entry, flags);
- if (!entry)
- return ERR_PTR(-ENOMEM);
-
- entry->data = kmalloc(cache->sbi->blocksize, flags);
- if (!entry->data) {
- kfree(entry);
- return ERR_PTR(-ENOMEM);
+ entry = kzalloc_obj(*entry, flags);
+ entry->data = kmalloc(sbi->blocksize, flags);
+ } else {
+ entry = f2fs_kzalloc(sbi, sizeof(*entry), flags);
+ if (!entry)
+ return ERR_PTR(-ENOMEM);
+
+ entry->data = f2fs_kmalloc(sbi, sbi->blocksize, flags);
+ if (!entry->data) {
+ kfree(entry);
+ return ERR_PTR(-ENOMEM);
+ }
}

entry->index = index;
--
2.49.0



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