Commit 628b3d14 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: inject fault to kvmalloc

This patch supports to inject fault into kvmalloc/kvzalloc.
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent acbf054d
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#ifdef CONFIG_F2FS_FAULT_INJECTION #ifdef CONFIG_F2FS_FAULT_INJECTION
enum { enum {
FAULT_KMALLOC, FAULT_KMALLOC,
FAULT_KVMALLOC,
FAULT_PAGE_ALLOC, FAULT_PAGE_ALLOC,
FAULT_PAGE_GET, FAULT_PAGE_GET,
FAULT_ALLOC_BIO, FAULT_ALLOC_BIO,
...@@ -2428,6 +2429,24 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, ...@@ -2428,6 +2429,24 @@ static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO);
} }
static inline void *f2fs_kvmalloc(struct f2fs_sb_info *sbi,
size_t size, gfp_t flags)
{
#ifdef CONFIG_F2FS_FAULT_INJECTION
if (time_to_inject(sbi, FAULT_KVMALLOC)) {
f2fs_show_injection_info(FAULT_KVMALLOC);
return NULL;
}
#endif
return kvmalloc(size, flags);
}
static inline void *f2fs_kvzalloc(struct f2fs_sb_info *sbi,
size_t size, gfp_t flags)
{
return f2fs_kvmalloc(sbi, size, flags | __GFP_ZERO);
}
static inline int get_extra_isize(struct inode *inode) static inline int get_extra_isize(struct inode *inode)
{ {
return F2FS_I(inode)->i_extra_isize / sizeof(__le32); return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
......
...@@ -1098,11 +1098,13 @@ static int __exchange_data_block(struct inode *src_inode, ...@@ -1098,11 +1098,13 @@ static int __exchange_data_block(struct inode *src_inode,
while (len) { while (len) {
olen = min((pgoff_t)4 * ADDRS_PER_BLOCK, len); olen = min((pgoff_t)4 * ADDRS_PER_BLOCK, len);
src_blkaddr = kvzalloc(sizeof(block_t) * olen, GFP_KERNEL); src_blkaddr = f2fs_kvzalloc(F2FS_I_SB(src_inode),
sizeof(block_t) * olen, GFP_KERNEL);
if (!src_blkaddr) if (!src_blkaddr)
return -ENOMEM; return -ENOMEM;
do_replace = kvzalloc(sizeof(int) * olen, GFP_KERNEL); do_replace = f2fs_kvzalloc(F2FS_I_SB(src_inode),
sizeof(int) * olen, GFP_KERNEL);
if (!do_replace) { if (!do_replace) {
kvfree(src_blkaddr); kvfree(src_blkaddr);
return -ENOMEM; return -ENOMEM;
......
...@@ -2707,17 +2707,17 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi) ...@@ -2707,17 +2707,17 @@ static int init_free_nid_cache(struct f2fs_sb_info *sbi)
{ {
struct f2fs_nm_info *nm_i = NM_I(sbi); struct f2fs_nm_info *nm_i = NM_I(sbi);
nm_i->free_nid_bitmap = kvzalloc(nm_i->nat_blocks * nm_i->free_nid_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks *
NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL); NAT_ENTRY_BITMAP_SIZE, GFP_KERNEL);
if (!nm_i->free_nid_bitmap) if (!nm_i->free_nid_bitmap)
return -ENOMEM; return -ENOMEM;
nm_i->nat_block_bitmap = kvzalloc(nm_i->nat_blocks / 8, nm_i->nat_block_bitmap = f2fs_kvzalloc(sbi, nm_i->nat_blocks / 8,
GFP_KERNEL); GFP_KERNEL);
if (!nm_i->nat_block_bitmap) if (!nm_i->nat_block_bitmap)
return -ENOMEM; return -ENOMEM;
nm_i->free_nid_count = kvzalloc(nm_i->nat_blocks * nm_i->free_nid_count = f2fs_kvzalloc(sbi, nm_i->nat_blocks *
sizeof(unsigned short), GFP_KERNEL); sizeof(unsigned short), GFP_KERNEL);
if (!nm_i->free_nid_count) if (!nm_i->free_nid_count)
return -ENOMEM; return -ENOMEM;
......
...@@ -3344,13 +3344,14 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -3344,13 +3344,14 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
SM_I(sbi)->sit_info = sit_i; SM_I(sbi)->sit_info = sit_i;
sit_i->sentries = kvzalloc(MAIN_SEGS(sbi) * sit_i->sentries = f2fs_kvzalloc(sbi, MAIN_SEGS(sbi) *
sizeof(struct seg_entry), GFP_KERNEL); sizeof(struct seg_entry), GFP_KERNEL);
if (!sit_i->sentries) if (!sit_i->sentries)
return -ENOMEM; return -ENOMEM;
bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
sit_i->dirty_sentries_bitmap = kvzalloc(bitmap_size, GFP_KERNEL); sit_i->dirty_sentries_bitmap = f2fs_kvzalloc(sbi, bitmap_size,
GFP_KERNEL);
if (!sit_i->dirty_sentries_bitmap) if (!sit_i->dirty_sentries_bitmap)
return -ENOMEM; return -ENOMEM;
...@@ -3384,7 +3385,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -3384,7 +3385,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
return -ENOMEM; return -ENOMEM;
if (sbi->segs_per_sec > 1) { if (sbi->segs_per_sec > 1) {
sit_i->sec_entries = kvzalloc(MAIN_SECS(sbi) * sit_i->sec_entries = f2fs_kvzalloc(sbi, MAIN_SECS(sbi) *
sizeof(struct sec_entry), GFP_KERNEL); sizeof(struct sec_entry), GFP_KERNEL);
if (!sit_i->sec_entries) if (!sit_i->sec_entries)
return -ENOMEM; return -ENOMEM;
...@@ -3435,12 +3436,12 @@ static int build_free_segmap(struct f2fs_sb_info *sbi) ...@@ -3435,12 +3436,12 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)
SM_I(sbi)->free_info = free_i; SM_I(sbi)->free_info = free_i;
bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
free_i->free_segmap = kvmalloc(bitmap_size, GFP_KERNEL); free_i->free_segmap = f2fs_kvmalloc(sbi, bitmap_size, GFP_KERNEL);
if (!free_i->free_segmap) if (!free_i->free_segmap)
return -ENOMEM; return -ENOMEM;
sec_bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); sec_bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi));
free_i->free_secmap = kvmalloc(sec_bitmap_size, GFP_KERNEL); free_i->free_secmap = f2fs_kvmalloc(sbi, sec_bitmap_size, GFP_KERNEL);
if (!free_i->free_secmap) if (!free_i->free_secmap)
return -ENOMEM; return -ENOMEM;
...@@ -3620,7 +3621,7 @@ static int init_victim_secmap(struct f2fs_sb_info *sbi) ...@@ -3620,7 +3621,7 @@ static int init_victim_secmap(struct f2fs_sb_info *sbi)
struct dirty_seglist_info *dirty_i = DIRTY_I(sbi); struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi)); unsigned int bitmap_size = f2fs_bitmap_size(MAIN_SECS(sbi));
dirty_i->victim_secmap = kvzalloc(bitmap_size, GFP_KERNEL); dirty_i->victim_secmap = f2fs_kvzalloc(sbi, bitmap_size, GFP_KERNEL);
if (!dirty_i->victim_secmap) if (!dirty_i->victim_secmap)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
...@@ -3643,7 +3644,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) ...@@ -3643,7 +3644,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi)
bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi)); bitmap_size = f2fs_bitmap_size(MAIN_SEGS(sbi));
for (i = 0; i < NR_DIRTY_TYPE; i++) { for (i = 0; i < NR_DIRTY_TYPE; i++) {
dirty_i->dirty_segmap[i] = kvzalloc(bitmap_size, GFP_KERNEL); dirty_i->dirty_segmap[i] = f2fs_kvzalloc(sbi, bitmap_size,
GFP_KERNEL);
if (!dirty_i->dirty_segmap[i]) if (!dirty_i->dirty_segmap[i])
return -ENOMEM; return -ENOMEM;
} }
......
...@@ -43,6 +43,7 @@ static struct kmem_cache *f2fs_inode_cachep; ...@@ -43,6 +43,7 @@ static struct kmem_cache *f2fs_inode_cachep;
char *fault_name[FAULT_MAX] = { char *fault_name[FAULT_MAX] = {
[FAULT_KMALLOC] = "kmalloc", [FAULT_KMALLOC] = "kmalloc",
[FAULT_KVMALLOC] = "kvmalloc",
[FAULT_PAGE_ALLOC] = "page alloc", [FAULT_PAGE_ALLOC] = "page alloc",
[FAULT_PAGE_GET] = "page get", [FAULT_PAGE_GET] = "page get",
[FAULT_ALLOC_BIO] = "alloc bio", [FAULT_ALLOC_BIO] = "alloc bio",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment