Commit 5f7136db authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Jens Axboe
Browse files

block: Add bio_max_segs



It's often inconvenient to use BIO_MAX_PAGES due to min() requiring the
sign to be the same.  Introduce bio_max_segs() and change BIO_MAX_PAGES to
be unsigned to make it easier for the users.

Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 94d4bffd
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -150,9 +150,7 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
	bmd->is_our_pages = !map_data;
	bmd->is_null_mapped = (map_data && map_data->null_mapped);

	nr_pages = DIV_ROUND_UP(offset + len, PAGE_SIZE);
	if (nr_pages > BIO_MAX_PAGES)
		nr_pages = BIO_MAX_PAGES;
	nr_pages = bio_max_segs(DIV_ROUND_UP(offset + len, PAGE_SIZE));

	ret = -ENOMEM;
	bio = bio_kmalloc(gfp_mask, nr_pages);
+1 −3
Original line number Diff line number Diff line
@@ -1326,9 +1326,7 @@ static int dispatch_rw_block_io(struct xen_blkif_ring *ring,
				     pages[i]->page,
				     seg[i].nsec << 9,
				     seg[i].offset) == 0)) {

			int nr_iovecs = min_t(int, (nseg-i), BIO_MAX_PAGES);
			bio = bio_alloc(GFP_KERNEL, nr_iovecs);
			bio = bio_alloc(GFP_KERNEL, bio_max_segs(nseg - i));
			if (unlikely(bio == NULL))
				goto fail_put_bio;

+2 −2
Original line number Diff line number Diff line
@@ -341,8 +341,8 @@ static void do_region(int op, int op_flags, unsigned region,
			num_bvecs = 1;
			break;
		default:
			num_bvecs = min_t(int, BIO_MAX_PAGES,
					  dm_sector_div_up(remaining, (PAGE_SIZE >> SECTOR_SHIFT)));
			num_bvecs = bio_max_segs(dm_sector_div_up(remaining,
						(PAGE_SIZE >> SECTOR_SHIFT)));
		}

		bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, &io->client->bios);
+5 −5
Original line number Diff line number Diff line
@@ -264,15 +264,14 @@ static int write_inline_data(struct log_writes_c *lc, void *entry,
			     size_t entrylen, void *data, size_t datalen,
			     sector_t sector)
{
	int num_pages, bio_pages, pg_datalen, pg_sectorlen, i;
	int bio_pages, pg_datalen, pg_sectorlen, i;
	struct page *page;
	struct bio *bio;
	size_t ret;
	void *ptr;

	while (datalen) {
		num_pages = ALIGN(datalen, PAGE_SIZE) >> PAGE_SHIFT;
		bio_pages = min(num_pages, BIO_MAX_PAGES);
		bio_pages = bio_max_segs(DIV_ROUND_UP(datalen, PAGE_SIZE));

		atomic_inc(&lc->io_blocks);

@@ -364,7 +363,7 @@ static int log_one_block(struct log_writes_c *lc,
		goto out;

	atomic_inc(&lc->io_blocks);
	bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt, BIO_MAX_PAGES));
	bio = bio_alloc(GFP_KERNEL, bio_max_segs(block->vec_cnt));
	if (!bio) {
		DMERR("Couldn't alloc log bio");
		goto error;
@@ -386,7 +385,8 @@ static int log_one_block(struct log_writes_c *lc,
		if (ret != block->vecs[i].bv_len) {
			atomic_inc(&lc->io_blocks);
			submit_bio(bio);
			bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt - i, BIO_MAX_PAGES));
			bio = bio_alloc(GFP_KERNEL,
					bio_max_segs(block->vec_cnt - i));
			if (!bio) {
				DMERR("Couldn't alloc log bio");
				goto error;
+4 −4
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ static int nvmet_bdev_alloc_bip(struct nvmet_req *req, struct bio *bio,
	}

	bip = bio_integrity_alloc(bio, GFP_NOIO,
		min_t(unsigned int, req->metadata_sg_cnt, BIO_MAX_PAGES));
					bio_max_segs(req->metadata_sg_cnt));
	if (IS_ERR(bip)) {
		pr_err("Unable to allocate bio_integrity_payload\n");
		return PTR_ERR(bip);
@@ -225,7 +225,7 @@ static int nvmet_bdev_alloc_bip(struct nvmet_req *req, struct bio *bio,

static void nvmet_bdev_execute_rw(struct nvmet_req *req)
{
	int sg_cnt = req->sg_cnt;
	unsigned int sg_cnt = req->sg_cnt;
	struct bio *bio;
	struct scatterlist *sg;
	struct blk_plug plug;
@@ -262,7 +262,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
		bio = &req->b.inline_bio;
		bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
	} else {
		bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
		bio = bio_alloc(GFP_KERNEL, bio_max_segs(sg_cnt));
	}
	bio_set_dev(bio, req->ns->bdev);
	bio->bi_iter.bi_sector = sector;
@@ -289,7 +289,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
				}
			}

			bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
			bio = bio_alloc(GFP_KERNEL, bio_max_segs(sg_cnt));
			bio_set_dev(bio, req->ns->bdev);
			bio->bi_iter.bi_sector = sector;
			bio->bi_opf = op;
Loading