Commit acbf054d authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: inject fault to kzalloc

This patch introduces f2fs_kzalloc based on f2fs_kmalloc in order to
support error injection for kzalloc().
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 979f492f
...@@ -793,7 +793,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi) ...@@ -793,7 +793,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
block_t cp_blk_no; block_t cp_blk_no;
int i; int i;
sbi->ckpt = kzalloc(cp_blks * blk_size, GFP_KERNEL); sbi->ckpt = f2fs_kzalloc(sbi, cp_blks * blk_size, GFP_KERNEL);
if (!sbi->ckpt) if (!sbi->ckpt)
return -ENOMEM; return -ENOMEM;
/* /*
......
...@@ -439,7 +439,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi) ...@@ -439,7 +439,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi)
struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
struct f2fs_stat_info *si; struct f2fs_stat_info *si;
si = kzalloc(sizeof(struct f2fs_stat_info), GFP_KERNEL); si = f2fs_kzalloc(sbi, sizeof(struct f2fs_stat_info), GFP_KERNEL);
if (!si) if (!si)
return -ENOMEM; return -ENOMEM;
......
...@@ -2422,6 +2422,12 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, ...@@ -2422,6 +2422,12 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
return kmalloc(size, flags); return kmalloc(size, flags);
} }
static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi,
size_t size, gfp_t flags)
{
return f2fs_kmalloc(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);
......
...@@ -533,7 +533,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -533,7 +533,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
struct qstr istr = QSTR_INIT(symname, len); struct qstr istr = QSTR_INIT(symname, len);
struct fscrypt_str ostr; struct fscrypt_str ostr;
sd = kzalloc(disk_link.len, GFP_NOFS); sd = f2fs_kzalloc(sbi, disk_link.len, GFP_NOFS);
if (!sd) { if (!sd) {
err = -ENOMEM; err = -ENOMEM;
goto err_out; goto err_out;
......
...@@ -2581,8 +2581,8 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) ...@@ -2581,8 +2581,8 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 +
F2FS_BLKSIZE - 1); F2FS_BLKSIZE - 1);
nm_i->nat_bits = kzalloc(nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, nm_i->nat_bits = f2fs_kzalloc(sbi,
GFP_KERNEL); nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL);
if (!nm_i->nat_bits) if (!nm_i->nat_bits)
return -ENOMEM; return -ENOMEM;
...@@ -2728,7 +2728,8 @@ int build_node_manager(struct f2fs_sb_info *sbi) ...@@ -2728,7 +2728,8 @@ int build_node_manager(struct f2fs_sb_info *sbi)
{ {
int err; int err;
sbi->nm_info = kzalloc(sizeof(struct f2fs_nm_info), GFP_KERNEL); sbi->nm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_nm_info),
GFP_KERNEL);
if (!sbi->nm_info) if (!sbi->nm_info)
return -ENOMEM; return -ENOMEM;
......
...@@ -657,7 +657,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi) ...@@ -657,7 +657,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi)
goto init_thread; goto init_thread;
} }
fcc = kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL); fcc = f2fs_kzalloc(sbi, sizeof(struct flush_cmd_control), GFP_KERNEL);
if (!fcc) if (!fcc)
return -ENOMEM; return -ENOMEM;
atomic_set(&fcc->issued_flush, 0); atomic_set(&fcc->issued_flush, 0);
...@@ -1737,7 +1737,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi) ...@@ -1737,7 +1737,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
goto init_thread; goto init_thread;
} }
dcc = kzalloc(sizeof(struct discard_cmd_control), GFP_KERNEL); dcc = f2fs_kzalloc(sbi, sizeof(struct discard_cmd_control), GFP_KERNEL);
if (!dcc) if (!dcc)
return -ENOMEM; return -ENOMEM;
...@@ -3338,7 +3338,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -3338,7 +3338,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
unsigned int bitmap_size; unsigned int bitmap_size;
/* allocate memory for SIT information */ /* allocate memory for SIT information */
sit_i = kzalloc(sizeof(struct sit_info), GFP_KERNEL); sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL);
if (!sit_i) if (!sit_i)
return -ENOMEM; return -ENOMEM;
...@@ -3356,29 +3356,30 @@ static int build_sit_info(struct f2fs_sb_info *sbi) ...@@ -3356,29 +3356,30 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
for (start = 0; start < MAIN_SEGS(sbi); start++) { for (start = 0; start < MAIN_SEGS(sbi); start++) {
sit_i->sentries[start].cur_valid_map sit_i->sentries[start].cur_valid_map
= kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
sit_i->sentries[start].ckpt_valid_map sit_i->sentries[start].ckpt_valid_map
= kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
if (!sit_i->sentries[start].cur_valid_map || if (!sit_i->sentries[start].cur_valid_map ||
!sit_i->sentries[start].ckpt_valid_map) !sit_i->sentries[start].ckpt_valid_map)
return -ENOMEM; return -ENOMEM;
#ifdef CONFIG_F2FS_CHECK_FS #ifdef CONFIG_F2FS_CHECK_FS
sit_i->sentries[start].cur_valid_map_mir sit_i->sentries[start].cur_valid_map_mir
= kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
if (!sit_i->sentries[start].cur_valid_map_mir) if (!sit_i->sentries[start].cur_valid_map_mir)
return -ENOMEM; return -ENOMEM;
#endif #endif
if (f2fs_discard_en(sbi)) { if (f2fs_discard_en(sbi)) {
sit_i->sentries[start].discard_map sit_i->sentries[start].discard_map
= kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE,
GFP_KERNEL);
if (!sit_i->sentries[start].discard_map) if (!sit_i->sentries[start].discard_map)
return -ENOMEM; return -ENOMEM;
} }
} }
sit_i->tmp_map = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
if (!sit_i->tmp_map) if (!sit_i->tmp_map)
return -ENOMEM; return -ENOMEM;
...@@ -3427,7 +3428,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi) ...@@ -3427,7 +3428,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)
unsigned int bitmap_size, sec_bitmap_size; unsigned int bitmap_size, sec_bitmap_size;
/* allocate memory for free segmap information */ /* allocate memory for free segmap information */
free_i = kzalloc(sizeof(struct free_segmap_info), GFP_KERNEL); free_i = f2fs_kzalloc(sbi, sizeof(struct free_segmap_info), GFP_KERNEL);
if (!free_i) if (!free_i)
return -ENOMEM; return -ENOMEM;
...@@ -3468,12 +3469,12 @@ static int build_curseg(struct f2fs_sb_info *sbi) ...@@ -3468,12 +3469,12 @@ static int build_curseg(struct f2fs_sb_info *sbi)
for (i = 0; i < NR_CURSEG_TYPE; i++) { for (i = 0; i < NR_CURSEG_TYPE; i++) {
mutex_init(&array[i].curseg_mutex); mutex_init(&array[i].curseg_mutex);
array[i].sum_blk = kzalloc(PAGE_SIZE, GFP_KERNEL); array[i].sum_blk = f2fs_kzalloc(sbi, PAGE_SIZE, GFP_KERNEL);
if (!array[i].sum_blk) if (!array[i].sum_blk)
return -ENOMEM; return -ENOMEM;
init_rwsem(&array[i].journal_rwsem); init_rwsem(&array[i].journal_rwsem);
array[i].journal = kzalloc(sizeof(struct f2fs_journal), array[i].journal = f2fs_kzalloc(sbi,
GFP_KERNEL); sizeof(struct f2fs_journal), GFP_KERNEL);
if (!array[i].journal) if (!array[i].journal)
return -ENOMEM; return -ENOMEM;
array[i].segno = NULL_SEGNO; array[i].segno = NULL_SEGNO;
...@@ -3631,7 +3632,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) ...@@ -3631,7 +3632,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi)
unsigned int bitmap_size, i; unsigned int bitmap_size, i;
/* allocate memory for dirty segments list information */ /* allocate memory for dirty segments list information */
dirty_i = kzalloc(sizeof(struct dirty_seglist_info), GFP_KERNEL); dirty_i = f2fs_kzalloc(sbi, sizeof(struct dirty_seglist_info),
GFP_KERNEL);
if (!dirty_i) if (!dirty_i)
return -ENOMEM; return -ENOMEM;
...@@ -3685,7 +3687,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi) ...@@ -3685,7 +3687,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
struct f2fs_sm_info *sm_info; struct f2fs_sm_info *sm_info;
int err; int err;
sm_info = kzalloc(sizeof(struct f2fs_sm_info), GFP_KERNEL); sm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_sm_info), GFP_KERNEL);
if (!sm_info) if (!sm_info)
return -ENOMEM; return -ENOMEM;
......
...@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, ...@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
if (!size && !inline_size) if (!size && !inline_size)
return -ENODATA; return -ENODATA;
txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode),
GFP_F2FS_ZERO); inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS);
if (!txattr_addr) if (!txattr_addr)
return -ENOMEM; return -ENOMEM;
...@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage, ...@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
void *txattr_addr; void *txattr_addr;
int err; int err;
txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode),
GFP_F2FS_ZERO); inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS);
if (!txattr_addr) if (!txattr_addr)
return -ENOMEM; return -ENOMEM;
......
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