f2fs: inject fault to kzalloc
authorChao Yu <yuchao0@huawei.com>
Thu, 30 Nov 2017 11:28:17 +0000 (19:28 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 3 Jan 2018 03:27:29 +0000 (19:27 -0800)
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>
fs/f2fs/checkpoint.c
fs/f2fs/debug.c
fs/f2fs/f2fs.h
fs/f2fs/namei.c
fs/f2fs/node.c
fs/f2fs/segment.c
fs/f2fs/xattr.c

index 4aa69bc..097eadc 100644 (file)
@@ -793,7 +793,7 @@ int get_valid_checkpoint(struct f2fs_sb_info *sbi)
        block_t cp_blk_no;
        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)
                return -ENOMEM;
        /*
index 674f9bb..a66107b 100644 (file)
@@ -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_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)
                return -ENOMEM;
 
index f3b4619..3f3d062 100644 (file)
@@ -2422,6 +2422,12 @@ static inline void *f2fs_kmalloc(struct f2fs_sb_info *sbi,
        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)
 {
        return F2FS_I(inode)->i_extra_isize / sizeof(__le32);
index bbb3fc1..e3a0f4f 100644 (file)
@@ -533,7 +533,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
                struct qstr istr = QSTR_INIT(symname, len);
                struct fscrypt_str ostr;
 
-               sd = kzalloc(disk_link.len, GFP_NOFS);
+               sd = f2fs_kzalloc(sbi, disk_link.len, GFP_NOFS);
                if (!sd) {
                        err = -ENOMEM;
                        goto err_out;
index fe99723..f3ab3a9 100644 (file)
@@ -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 +
                                                F2FS_BLKSIZE - 1);
-       nm_i->nat_bits = kzalloc(nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS,
-                                               GFP_KERNEL);
+       nm_i->nat_bits = f2fs_kzalloc(sbi,
+                       nm_i->nat_bits_blocks << F2FS_BLKSIZE_BITS, GFP_KERNEL);
        if (!nm_i->nat_bits)
                return -ENOMEM;
 
@@ -2728,7 +2728,8 @@ int build_node_manager(struct f2fs_sb_info *sbi)
 {
        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)
                return -ENOMEM;
 
index c117e09..51307f9 100644 (file)
@@ -657,7 +657,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi)
                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)
                return -ENOMEM;
        atomic_set(&fcc->issued_flush, 0);
@@ -1737,7 +1737,7 @@ static int create_discard_cmd_control(struct f2fs_sb_info *sbi)
                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)
                return -ENOMEM;
 
@@ -3338,7 +3338,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
        unsigned int bitmap_size;
 
        /* 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)
                return -ENOMEM;
 
@@ -3356,29 +3356,30 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
 
        for (start = 0; start < MAIN_SEGS(sbi); start++) {
                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
-                       = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
+                       = f2fs_kzalloc(sbi, SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
                if (!sit_i->sentries[start].cur_valid_map ||
                                !sit_i->sentries[start].ckpt_valid_map)
                        return -ENOMEM;
 
 #ifdef CONFIG_F2FS_CHECK_FS
                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)
                        return -ENOMEM;
 #endif
 
                if (f2fs_discard_en(sbi)) {
                        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)
                                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)
                return -ENOMEM;
 
@@ -3427,7 +3428,7 @@ static int build_free_segmap(struct f2fs_sb_info *sbi)
        unsigned int bitmap_size, sec_bitmap_size;
 
        /* 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)
                return -ENOMEM;
 
@@ -3468,12 +3469,12 @@ static int build_curseg(struct f2fs_sb_info *sbi)
 
        for (i = 0; i < NR_CURSEG_TYPE; i++) {
                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)
                        return -ENOMEM;
                init_rwsem(&array[i].journal_rwsem);
-               array[i].journal = kzalloc(sizeof(struct f2fs_journal),
-                                                       GFP_KERNEL);
+               array[i].journal = f2fs_kzalloc(sbi,
+                               sizeof(struct f2fs_journal), GFP_KERNEL);
                if (!array[i].journal)
                        return -ENOMEM;
                array[i].segno = NULL_SEGNO;
@@ -3631,7 +3632,8 @@ static int build_dirty_segmap(struct f2fs_sb_info *sbi)
        unsigned int bitmap_size, i;
 
        /* 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)
                return -ENOMEM;
 
@@ -3685,7 +3687,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
        struct f2fs_sm_info *sm_info;
        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)
                return -ENOMEM;
 
index ec8961e..5e2b905 100644 (file)
@@ -298,8 +298,8 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage,
        if (!size && !inline_size)
                return -ENODATA;
 
-       txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE,
-                                                       GFP_F2FS_ZERO);
+       txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode),
+                       inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS);
        if (!txattr_addr)
                return -ENOMEM;
 
@@ -351,8 +351,8 @@ static int read_all_xattrs(struct inode *inode, struct page *ipage,
        void *txattr_addr;
        int err;
 
-       txattr_addr = kzalloc(inline_size + size + XATTR_PADDING_SIZE,
-                                                       GFP_F2FS_ZERO);
+       txattr_addr = f2fs_kzalloc(F2FS_I_SB(inode),
+                       inline_size + size + XATTR_PADDING_SIZE, GFP_NOFS);
        if (!txattr_addr)
                return -ENOMEM;