Message ID | 570D5D02.3030807@sandisk.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 04/12/2016 10:39 PM, Bart Van Assche wrote: > Move the code for adding one or more zero pages into a new function. > This patch does not change any functionality. > > Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com> > Reviewed-by: Christoph Hellwig <hch@lst.de> > Cc: Jan Kara <jack@suse.cz> > Cc: Mike Snitzer <snitzer@redhat.com> > Cc: Martin K. Petersen <martin.petersen@oracle.com> > Cc: Dmitry Monakhov <dmonakhov@openvz.org> > Cc: Darrick J. Wong <darrick.wong@oracle.com> > Cc: Sagi Grimberg <sagi@grimberg.me> > --- > block/blk-lib.c | 30 +++++++++++++++++++----------- > 1 file changed, 19 insertions(+), 11 deletions(-) > > diff --git a/block/blk-lib.c b/block/blk-lib.c > index 2f4c6b2..9a93ca4 100644 > --- a/block/blk-lib.c > +++ b/block/blk-lib.c > @@ -219,6 +219,22 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, > } > EXPORT_SYMBOL(blkdev_issue_write_same); > > +static void bio_add_zero_pages(struct bio *bio, sector_t nr_sects) > +{ > + unsigned int sz; > + int ret; > + > + /* Avoid that bi_size overflows */ > + nr_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9); > + > + for (; nr_sects != 0; nr_sects -= ret >> 9) { > + sz = min_t(unsigned int, PAGE_SIZE >> 9, nr_sects) << 9; > + ret = bio_add_page(bio, ZERO_PAGE(0), sz, 0); > + if (ret < sz) > + break; > + } > +} > + > /** > * blkdev_issue_zeroout - generate number of zero filed write bios > * @bdev: blockdev to issue > @@ -236,7 +252,6 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, > int ret; > struct bio *bio; > struct bio_batch bb; > - unsigned int sz; > DECLARE_COMPLETION_ONSTACK(wait); > > atomic_set(&bb.done, 1); > @@ -256,16 +271,9 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, > bio->bi_bdev = bdev; > bio->bi_end_io = bio_batch_end_io; > bio->bi_private = &bb; > - > - while (nr_sects != 0) { > - sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects); > - ret = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0); > - nr_sects -= ret >> 9; > - sector += ret >> 9; > - if (ret < (sz << 9)) > - break; > - } > - ret = 0; > + bio_add_zero_pages(bio, nr_sects); > + nr_sects -= bio->bi_iter.bi_size >> 9; > + sector += bio->bi_iter.bi_size >> 9; > atomic_inc(&bb.done); > submit_bio(WRITE, bio); > } > Makes one wonder whether we should have a 'size_to_sector' and 'sector_to_size' macro ... Reviewed-by: Hannes Reinecke <hare@suse.com> Cheers, Hannes
diff --git a/block/blk-lib.c b/block/blk-lib.c index 2f4c6b2..9a93ca4 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -219,6 +219,22 @@ int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, } EXPORT_SYMBOL(blkdev_issue_write_same); +static void bio_add_zero_pages(struct bio *bio, sector_t nr_sects) +{ + unsigned int sz; + int ret; + + /* Avoid that bi_size overflows */ + nr_sects = min_t(sector_t, nr_sects, UINT_MAX >> 9); + + for (; nr_sects != 0; nr_sects -= ret >> 9) { + sz = min_t(unsigned int, PAGE_SIZE >> 9, nr_sects) << 9; + ret = bio_add_page(bio, ZERO_PAGE(0), sz, 0); + if (ret < sz) + break; + } +} + /** * blkdev_issue_zeroout - generate number of zero filed write bios * @bdev: blockdev to issue @@ -236,7 +252,6 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, int ret; struct bio *bio; struct bio_batch bb; - unsigned int sz; DECLARE_COMPLETION_ONSTACK(wait); atomic_set(&bb.done, 1); @@ -256,16 +271,9 @@ static int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, bio->bi_bdev = bdev; bio->bi_end_io = bio_batch_end_io; bio->bi_private = &bb; - - while (nr_sects != 0) { - sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects); - ret = bio_add_page(bio, ZERO_PAGE(0), sz << 9, 0); - nr_sects -= ret >> 9; - sector += ret >> 9; - if (ret < (sz << 9)) - break; - } - ret = 0; + bio_add_zero_pages(bio, nr_sects); + nr_sects -= bio->bi_iter.bi_size >> 9; + sector += bio->bi_iter.bi_size >> 9; atomic_inc(&bb.done); submit_bio(WRITE, bio); }