Re: [f2fs-dev] [PATCH v8 10/12] f2fs: cache: support fault injection
From: Zhiguo Niu
Date: Wed Sep 16 2026 - 04:51:40 EST
Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@xxxxxxxxxxxxxxxxxxxxx>
于2026年9月16日周三 09:57写道:
>
> 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_KMALLOC
>
> Signed-off-by: Chao Yu <chao@xxxxxxxxxx>
Reviewed-by: Zhiguo Niu <zhiguo.niu@xxxxxxxxxx>
thanks!
> ---
> 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 3e6a198ef3b3..27624b6799a9 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