Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit be5d050a authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim
Browse files

f2fs: support bio allocation error injection



This patch adds to support bio allocation error injection to simulate
out-of-memory test scenario.

Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 710adf1c
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -172,7 +172,7 @@ static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
{
{
	struct bio *bio;
	struct bio *bio;


	bio = f2fs_bio_alloc(npages);
	bio = f2fs_bio_alloc(sbi, npages, true);


	f2fs_target_device(sbi, blk_addr, bio);
	f2fs_target_device(sbi, blk_addr, bio);
	bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
	bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
@@ -472,7 +472,7 @@ static struct bio *f2fs_grab_read_bio(struct inode *inode, block_t blkaddr,
		f2fs_wait_on_block_writeback(sbi, blkaddr);
		f2fs_wait_on_block_writeback(sbi, blkaddr);
	}
	}


	bio = bio_alloc(GFP_KERNEL, min_t(int, nr_pages, BIO_MAX_PAGES));
	bio = f2fs_bio_alloc(sbi, min_t(int, nr_pages, BIO_MAX_PAGES), false);
	if (!bio) {
	if (!bio) {
		if (ctx)
		if (ctx)
			fscrypt_release_ctx(ctx);
			fscrypt_release_ctx(ctx);
+17 −6
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ enum {
	FAULT_KMALLOC,
	FAULT_KMALLOC,
	FAULT_PAGE_ALLOC,
	FAULT_PAGE_ALLOC,
	FAULT_PAGE_GET,
	FAULT_PAGE_GET,
	FAULT_ALLOC_BIO,
	FAULT_ALLOC_NID,
	FAULT_ALLOC_NID,
	FAULT_ORPHAN,
	FAULT_ORPHAN,
	FAULT_BLOCK,
	FAULT_BLOCK,
@@ -1993,16 +1994,26 @@ static inline void *f2fs_kmem_cache_alloc(struct kmem_cache *cachep,
	return entry;
	return entry;
}
}


static inline struct bio *f2fs_bio_alloc(int npages)
static inline struct bio *f2fs_bio_alloc(struct f2fs_sb_info *sbi,
						int npages, bool no_fail)
{
{
	struct bio *bio;
	struct bio *bio;


	if (no_fail) {
		/* No failure on bio allocation */
		/* No failure on bio allocation */
		bio = bio_alloc(GFP_NOIO, npages);
		bio = bio_alloc(GFP_NOIO, npages);
		if (!bio)
		if (!bio)
			bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
			bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, npages);
		return bio;
		return bio;
	}
	}
#ifdef CONFIG_F2FS_FAULT_INJECTION
	if (time_to_inject(sbi, FAULT_ALLOC_BIO)) {
		f2fs_show_injection_info(FAULT_ALLOC_BIO);
		return NULL;
	}
#endif
	return bio_alloc(GFP_KERNEL, npages);
}


static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
static inline void f2fs_radix_tree_insert(struct radix_tree_root *root,
				unsigned long index, void *item)
				unsigned long index, void *item)
+3 −2
Original line number Original line Diff line number Diff line
@@ -511,7 +511,7 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi)
static int __submit_flush_wait(struct f2fs_sb_info *sbi,
static int __submit_flush_wait(struct f2fs_sb_info *sbi,
				struct block_device *bdev)
				struct block_device *bdev)
{
{
	struct bio *bio = f2fs_bio_alloc(0);
	struct bio *bio = f2fs_bio_alloc(sbi, 0, true);
	int ret;
	int ret;


	bio->bi_rw = REQ_OP_WRITE;
	bio->bi_rw = REQ_OP_WRITE;
@@ -943,7 +943,8 @@ static int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
			if (ret)
			if (ret)
				return ret;
				return ret;
		}
		}
		bio = f2fs_bio_alloc(1);

		bio = bio_alloc(GFP_NOIO | __GFP_NOFAIL, 1);
		bio->bi_iter.bi_sector = sector;
		bio->bi_iter.bi_sector = sector;
		bio->bi_bdev = bdev;
		bio->bi_bdev = bdev;
		bio_set_op_attrs(bio, op, 0);
		bio_set_op_attrs(bio, op, 0);
+1 −0
Original line number Original line Diff line number Diff line
@@ -48,6 +48,7 @@ char *fault_name[FAULT_MAX] = {
	[FAULT_KMALLOC]		= "kmalloc",
	[FAULT_KMALLOC]		= "kmalloc",
	[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_NID]	= "alloc nid",
	[FAULT_ALLOC_NID]	= "alloc nid",
	[FAULT_ORPHAN]		= "orphan",
	[FAULT_ORPHAN]		= "orphan",
	[FAULT_BLOCK]		= "no more block",
	[FAULT_BLOCK]		= "no more block",