[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200329174714.32416-2-chaitanya.kulkarni@wdc.com>
Date: Sun, 29 Mar 2020 10:47:11 -0700
From: Chaitanya Kulkarni <chaitanya.kulkarni@....com>
To: hch@....de, martin.petersen@...cle.com
Cc: darrick.wong@...cle.com, axboe@...nel.dk, tytso@....edu,
adilger.kernel@...ger.ca, ming.lei@...hat.com, jthumshirn@...e.de,
minwoo.im.dev@...il.com, chaitanya.kulkarni@....com,
damien.lemoal@....com, andrea.parri@...rulasolutions.com,
hare@...e.com, tj@...nel.org, hannes@...xchg.org,
khlebnikov@...dex-team.ru, ajay.joshi@....com, bvanassche@....org,
arnd@...db.de, houtao1@...wei.com, asml.silence@...il.com,
linux-block@...r.kernel.org, linux-ext4@...r.kernel.org
Subject: [PATCH 1/4] block: create payloadless issue bio helper
This is a prep-patch that creates a helper to submit payloadless bio
with all the required arguments. This is needed to avoid the code
repetition in blk-lib,c so that new payloadless ops can use it.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@....com>
---
block/blk-lib.c | 51 +++++++++++++++++++++++++++++--------------------
1 file changed, 30 insertions(+), 21 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 5f2c429d4378..8e53e393703c 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -209,13 +209,40 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
}
EXPORT_SYMBOL(blkdev_issue_write_same);
+static void __blkdev_issue_payloadless(struct block_device *bdev,
+ unsigned op, sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
+ struct bio **biop, unsigned bio_opf, unsigned int max_sectors)
+{
+ struct bio *bio = *biop;
+
+ while (nr_sects) {
+ bio = blk_next_bio(bio, 0, gfp_mask);
+ bio->bi_iter.bi_sector = sector;
+ bio_set_dev(bio, bdev);
+ bio->bi_opf = op;
+ bio->bi_opf |= bio_opf;
+
+ if (nr_sects > max_sectors) {
+ bio->bi_iter.bi_size = max_sectors << 9;
+ nr_sects -= max_sectors;
+ sector += max_sectors;
+ } else {
+ bio->bi_iter.bi_size = nr_sects << 9;
+ nr_sects = 0;
+ }
+ cond_resched();
+ }
+
+ *biop = bio;
+}
+
static int __blkdev_issue_write_zeroes(struct block_device *bdev,
sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
struct bio **biop, unsigned flags)
{
- struct bio *bio = *biop;
unsigned int max_write_zeroes_sectors;
struct request_queue *q = bdev_get_queue(bdev);
+ unsigned int unmap = (flags & BLKDEV_ZERO_NOUNMAP) ? REQ_NOUNMAP : 0;
if (!q)
return -ENXIO;
@@ -229,26 +256,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
if (max_write_zeroes_sectors == 0)
return -EOPNOTSUPP;
- while (nr_sects) {
- bio = blk_next_bio(bio, 0, gfp_mask);
- bio->bi_iter.bi_sector = sector;
- bio_set_dev(bio, bdev);
- bio->bi_opf = REQ_OP_WRITE_ZEROES;
- if (flags & BLKDEV_ZERO_NOUNMAP)
- bio->bi_opf |= REQ_NOUNMAP;
-
- if (nr_sects > max_write_zeroes_sectors) {
- bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;
- nr_sects -= max_write_zeroes_sectors;
- sector += max_write_zeroes_sectors;
- } else {
- bio->bi_iter.bi_size = nr_sects << 9;
- nr_sects = 0;
- }
- cond_resched();
- }
-
- *biop = bio;
+ __blkdev_issue_payloadless(bdev, REQ_OP_WRITE_ZEROES, sector, nr_sects,
+ gfp_mask, biop, unmap, max_write_zeroes_sectors);
return 0;
}
--
2.22.0
Powered by blists - more mailing lists