diff options
author | Chao Yu <yuchao0@huawei.com> | 2017-11-30 06:28:17 -0500 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2018-01-02 22:27:29 -0500 |
commit | acbf054d537d7efddc232e6c11a15d4be0507fd6 (patch) | |
tree | a77c055e6a007f298a12dcbe59b6b294adc89929 | |
parent | 979f492fe387e88a0c97566853ebb615f19a3221 (diff) |
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: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r-- | fs/f2fs/checkpoint.c | 2 | ||||
-rw-r--r-- | fs/f2fs/debug.c | 2 | ||||
-rw-r--r-- | fs/f2fs/f2fs.h | 6 | ||||
-rw-r--r-- | fs/f2fs/namei.c | 2 | ||||
-rw-r--r-- | fs/f2fs/node.c | 7 | ||||
-rw-r--r-- | fs/f2fs/segment.c | 30 | ||||
-rw-r--r-- | fs/f2fs/xattr.c | 8 |
7 files changed, 33 insertions, 24 deletions
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4aa69bc1c70a..097eadc82432 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c | |||
@@ -793,7 +793,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi) | |||
793 | block_t cp_blk_no; | 793 | block_t cp_blk_no; |
794 | int i; | 794 | int i; |
795 | 795 | ||
796 | sbi->ckpt = kzalloc(cp_blks * blk_size, GFP_KERNEL); | 796 | sbi->ckpt = f2fs_kzalloc(sbi, cp_blks * blk_size, GFP_KERNEL); |
797 | if (!sbi->ckpt) | 797 | if (!sbi->ckpt) |
798 | return -ENOMEM; | 798 | return -ENOMEM; |
799 | /* | 799 | /* |
diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 674f9bbe98d9..a66107b5cfff 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c | |||
@@ -439,7 +439,7 @@ int f2fs_build_stats(struct f2fs_sb_info *sbi) | |||
439 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); | 439 | struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); |
440 | struct f2fs_stat_info *si; | 440 | struct f2fs_stat_info *si; |
441 | 441 | ||
442 | si = kzalloc(sizeof(struct f2fs_stat_info), GFP_KERNEL); | 442 | si = f2fs_kzalloc(sbi, sizeof(struct f2fs_stat_info), GFP_KERNEL); |
443 | if (!si) | 443 | if (!si) |
444 | return -ENOMEM; | 444 | return -ENOMEM; |
445 | 445 | ||
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f3b46197b282..3f3d062c349e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h | |||
@@ -2422,6 +2422,12 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi, | |||
2422 | return kmalloc(size, flags); | 2422 | return kmalloc(size, flags); |
2423 | } | 2423 | } |
2424 | 2424 | ||
2425 | static inline void *f2fs_kzalloc(struct f2fs_sb_info *sbi, | ||
2426 | size_t size, gfp_t flags) | ||
2427 | { | ||
2428 | return f2fs_kmalloc(sbi, size, flags | __GFP_ZERO); | ||
2429 | } | ||
2430 | |||
2425 | static inline int get_extra_isize(struct inode *inode) | 2431 | static inline int get_extra_isize(struct inode *inode) |
2426 | { | 2432 | { |
2427 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); | 2433 | return F2FS_I(inode)->i_extra_isize / sizeof(__le32); |
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index bbb3fc1e2bef..e3a0f4f65851 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c | |||
@@ -533,7 +533,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, | |||
533 | struct qstr istr = QSTR_INIT(symname, len); | 533 | struct qstr istr = QSTR_INIT(symname, len); |
534 | struct fscrypt_str ostr; | 534 | struct fscrypt_str ostr; |
535 | 535 | ||
536 | sd = kzalloc(disk_link.len, GFP_NOFS); | 536 | sd = f2fs_kzalloc(sbi, disk_link.len, GFP_NOFS); |
537 | if (!sd) { | 537 | if (!sd) { |
538 | err = -ENOMEM; | 538 | err = -ENOMEM; |
539 | goto err_out; | 539 | goto err_out; |
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index fe99723bb5b6..f3ab3a917d13 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c | |||
@@ -2581,8 +2581,8 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) | |||
2581 | 2581 | ||
2582 | nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + | 2582 | nm_i->nat_bits_blocks = F2FS_BYTES_TO_BLK((nat_bits_bytes << 1) + 8 + |
2583 | F2FS_BLKSIZE - 1); | 2583 | F2FS_BLKSIZE - 1); |
2584 | nm_i->nat_bits = kzalloc(nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, | 2584 | nm_i->nat_bits = f2fs_kzalloc(sbi, |
2585 | GFP_KERNEL); | 2585 | nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL); |
2586 | if (!nm_i->nat_bits) | 2586 | if (!nm_i->nat_bits) |
2587 | return -ENOMEM; | 2587 | return -ENOMEM; |
2588 | 2588 | ||
@@ -2728,7 +2728,8 @@ int build_node_manager(struct f2fs_sb_info *sbi) | |||
2728 | { | 2728 | { |
2729 | int err; | 2729 | int err; |
2730 | 2730 | ||
2731 | sbi->nm_info = kzalloc(sizeof(struct f2fs_nm_info), GFP_KERNEL); | 2731 | sbi->nm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_nm_info), |
2732 | GFP_KERNEL); | ||
2732 | if (!sbi->nm_info) | 2733 | if (!sbi->nm_info) |
2733 | return -ENOMEM; | 2734 | return -ENOMEM; |
2734 | 2735 | ||
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index c117e0913f2a..51307f9d2cb0 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c | |||
@@ -657,7 +657,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi) | |||
657 | goto init_thread; | 657 | goto init_thread; |
658 | } | 658 | } |
659 | 659 | ||
660 | fcc = kzalloc(sizeof(struct flush_cmd_control), GFP_KERNEL); | 660 | fcc = f2fs_kzalloc(sbi, sizeof(struct flush_cmd_control), GFP_KERNEL); |
661 | if (!fcc) | 661 | if (!fcc) |
662 | return -ENOMEM; | 662 | return -ENOMEM; |
663 | atomic_set(&fcc->issued_flush, 0); | 663 | atomic_set(&fcc->issued_flush, 0); |
@@ -1737,7 +1737,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi) | |||
1737 | goto init_thread; | 1737 | goto init_thread; |
1738 | } | 1738 | } |
1739 | 1739 | ||
1740 | dcc = kzalloc(sizeof(struct discard_cmd_control), GFP_KERNEL); | 1740 | dcc = f2fs_kzalloc(sbi, sizeof(struct discard_cmd_control), GFP_KERNEL); |
1741 | if (!dcc) | 1741 | if (!dcc) |
1742 | return -ENOMEM; | 1742 | return -ENOMEM; |
1743 | 1743 | ||
@@ -3338,7 +3338,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) | |||
3338 | unsigned int bitmap_size; | 3338 | unsigned int bitmap_size; |
3339 | 3339 | ||
3340 | /* allocate memory for SIT information */ | 3340 | /* allocate memory for SIT information */ |
3341 | sit_i = kzalloc(sizeof(struct sit_info), GFP_KERNEL); | 3341 | sit_i = f2fs_kzalloc(sbi, sizeof(struct sit_info), GFP_KERNEL); |
3342 | if (!sit_i) | 3342 | if (!sit_i) |
3343 | return -ENOMEM; | 3343 | return -ENOMEM; |
3344 | 3344 | ||
@@ -3356,29 +3356,30 @@ static int build_sit_info(struct f2fs_sb_info *sbi) | |||
3356 | 3356 | ||
3357 | for (start = 0; start < MAIN_SEGS(sbi); start++) { | 3357 | for (start = 0; start < MAIN_SEGS(sbi); start++) { |
3358 | sit_i->sentries[start].cur_valid_map | 3358 | sit_i->sentries[start].cur_valid_map |
3359 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3359 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3360 | sit_i->sentries[start].ckpt_valid_map | 3360 | sit_i->sentries[start].ckpt_valid_map |
3361 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3361 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3362 | if (!sit_i->sentries[start].cur_valid_map || | 3362 | if (!sit_i->sentries[start].cur_valid_map || |
3363 | !sit_i->sentries[start].ckpt_valid_map) | 3363 | !sit_i->sentries[start].ckpt_valid_map) |
3364 | return -ENOMEM; | 3364 | return -ENOMEM; |
3365 | 3365 | ||
3366 | #ifdef CONFIG_F2FS_CHECK_FS | 3366 | #ifdef CONFIG_F2FS_CHECK_FS |
3367 | sit_i->sentries[start].cur_valid_map_mir | 3367 | sit_i->sentries[start].cur_valid_map_mir |
3368 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3368 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3369 | if (!sit_i->sentries[start].cur_valid_map_mir) | 3369 | if (!sit_i->sentries[start].cur_valid_map_mir) |
3370 | return -ENOMEM; | 3370 | return -ENOMEM; |
3371 | #endif | 3371 | #endif |
3372 | 3372 | ||
3373 | if (f2fs_discard_en(sbi)) { | 3373 | if (f2fs_discard_en(sbi)) { |
3374 | sit_i->sentries[start].discard_map | 3374 | sit_i->sentries[start].discard_map |
3375 | = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3375 | = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, |
3376 | GFP_KERNEL); | ||
3376 | if (!sit_i->sentries[start].discard_map) | 3377 | if (!sit_i->sentries[start].discard_map) |
3377 | return -ENOMEM; | 3378 | return -ENOMEM; |
3378 | } | 3379 | } |
3379 | } | 3380 | } |
3380 | 3381 | ||
3381 | sit_i->tmp_map = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); | 3382 | sit_i->tmp_map = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL); |
3382 | if (!sit_i->tmp_map) | 3383 | if (!sit_i->tmp_map) |
3383 | return -ENOMEM; | 3384 | return -ENOMEM; |
3384 | 3385 | ||
@@ -3427,7 +3428,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi) | |||
3427 | unsigned int bitmap_size, sec_bitmap_size; | 3428 | unsigned int bitmap_size, sec_bitmap_size; |
3428 | 3429 | ||
3429 | /* allocate memory for free segmap information */ | 3430 | /* allocate memory for free segmap information */ |
3430 | free_i = kzalloc(sizeof(struct free_segmap_info), GFP_KERNEL); | 3431 | free_i = f2fs_kzalloc(sbi, sizeof(struct free_segmap_info), GFP_KERNEL); |
3431 | if (!free_i) | 3432 | if (!free_i) |
3432 | return -ENOMEM; | 3433 | return -ENOMEM; |
3433 | 3434 | ||
@@ -3468,12 +3469,12 @@ static int build_curseg(struct f2fs_sb_info *sbi) | |||
3468 | 3469 | ||
3469 | for (i = 0; i < NR_CURSEG_TYPE; i++) { | 3470 | for (i = 0; i < NR_CURSEG_TYPE; i++) { |
3470 | mutex_init(&array[i].curseg_mutex); | 3471 | mutex_init(&array[i].curseg_mutex); |
3471 | array[i].sum_blk = kzalloc(PAGE_SIZE, GFP_KERNEL); | 3472 | array[i].sum_blk = f2fs_kzalloc(sbi, PAGE_SIZE, GFP_KERNEL); |
3472 | if (!array[i].sum_blk) | 3473 | if (!array[i].sum_blk) |
3473 | return -ENOMEM; | 3474 | return -ENOMEM; |
3474 | init_rwsem(&array[i].journal_rwsem); | 3475 | init_rwsem(&array[i].journal_rwsem); |
3475 | array[i].journal = kzalloc(sizeof(struct f2fs_journal), | 3476 | array[i].journal = f2fs_kzalloc(sbi, |
3476 | GFP_KERNEL); | 3477 | sizeof(struct f2fs_journal), GFP_KERNEL); |
3477 | if (!array[i].journal) | 3478 | if (!array[i].journal) |
3478 | return -ENOMEM; | 3479 | return -ENOMEM; |
3479 | array[i].segno = NULL_SEGNO; | 3480 | array[i].segno = NULL_SEGNO; |
@@ -3631,7 +3632,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi) | |||
3631 | unsigned int bitmap_size, i; | 3632 | unsigned int bitmap_size, i; |
3632 | 3633 | ||
3633 | /* allocate memory for dirty segments list information */ | 3634 | /* allocate memory for dirty segments list information */ |
3634 | dirty_i = kzalloc(sizeof(struct dirty_seglist_info), GFP_KERNEL); | 3635 | dirty_i = f2fs_kzalloc(sbi, sizeof(struct dirty_seglist_info), |
3636 | GFP_KERNEL); | ||
3635 | if (!dirty_i) | 3637 | if (!dirty_i) |
3636 | return -ENOMEM; | 3638 | return -ENOMEM; |
3637 | 3639 | ||
@@ -3685,7 +3687,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi) | |||
3685 | struct f2fs_sm_info *sm_info; | 3687 | struct f2fs_sm_info *sm_info; |
3686 | int err; | 3688 | int err; |
3687 | 3689 | ||
3688 | sm_info = kzalloc(sizeof(struct f2fs_sm_info), GFP_KERNEL); | 3690 | sm_info = f2fs_kzalloc(sbi, sizeof(struct f2fs_sm_info), GFP_KERNEL); |
3689 | if (!sm_info) | 3691 | if (!sm_info) |
3690 | return -ENOMEM; | 3692 | return -ENOMEM; |
3691 | 3693 | ||
diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index ec8961ef8cac..5e2b905cc0c4 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c | |||
@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, | |||
298 | if (!size && !inline_size) | 298 | if (!size && !inline_size) |
299 | return -ENODATA; | 299 | return -ENODATA; |
300 | 300 | ||
301 | txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, | 301 | txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), |
302 | GFP_F2FS_ZERO); | 302 | inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); |
303 | if (!txattr_addr) | 303 | if (!txattr_addr) |
304 | return -ENOMEM; | 304 | return -ENOMEM; |
305 | 305 | ||
@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage, | |||
351 | void *txattr_addr; | 351 | void *txattr_addr; |
352 | int err; | 352 | int err; |
353 | 353 | ||
354 | txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE, | 354 | txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode), |
355 | GFP_F2FS_ZERO); | 355 | inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS); |
356 | if (!txattr_addr) | 356 | if (!txattr_addr) |
357 | return -ENOMEM; | 357 | return -ENOMEM; |
358 | 358 | ||