[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 02/34] block: introduce and use bio_new
- To: Damien Le Moal <Damien.LeMoal@xxxxxxx>, "linux-xfs@xxxxxxxxxxxxxxx" <linux-xfs@xxxxxxxxxxxxxxx>, "linux-fsdevel@xxxxxxxxxxxxxxx" <linux-fsdevel@xxxxxxxxxxxxxxx>, "dm-devel@xxxxxxxxxx" <dm-devel@xxxxxxxxxx>, "linux-block@xxxxxxxxxxxxxxx" <linux-block@xxxxxxxxxxxxxxx>, "linux-kernel@xxxxxxxxxxxxxxx" <linux-kernel@xxxxxxxxxxxxxxx>, "drbd-dev@xxxxxxxxxxxxxxxx" <drbd-dev@xxxxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "linux-nvme@xxxxxxxxxxxxxxxxxxx" <linux-nvme@xxxxxxxxxxxxxxxxxxx>, "linux-scsi@xxxxxxxxxxxxxxx" <linux-scsi@xxxxxxxxxxxxxxx>, "target-devel@xxxxxxxxxxxxxxx" <target-devel@xxxxxxxxxxxxxxx>, "linux-fscrypt@xxxxxxxxxxxxxxx" <linux-fscrypt@xxxxxxxxxxxxxxx>, "jfs-discussion@xxxxxxxxxxxxxxxxxxxxx" <jfs-discussion@xxxxxxxxxxxxxxxxxxxxx>, "linux-nilfs@xxxxxxxxxxxxxxx" <linux-nilfs@xxxxxxxxxxxxxxx>, "ocfs2-devel@xxxxxxxxxxxxxx" <ocfs2-devel@xxxxxxxxxxxxxx>, "linux-pm@xxxxxxxxxxxxxxx" <linux-pm@xxxxxxxxxxxxxxx>, "linux-mm@xxxxxxxxx" <linux-mm@xxxxxxxxx>
- From: Chaitanya Kulkarni <Chaitanya.Kulkarni@xxxxxxx>
- Date: Thu, 28 Jan 2021 08:33:10 +0000
- Accept-language: en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=27WeiOixIPFPDfcazPu+NAilOtkMrK3W6qpnHMGnQ1I=; b=FK2i/EYO+dF56oSGse5NIEFHXnMEL4keuM661ULHd+CX3xaYRei3nU7oDIVp2LTbX3b8kMvSsOvoyoSn+xfZgNUqUy2tmPsQ8BQCkOswm9K8OymjLHQPUrtF4uOsdSM1EA4C0Hiwhh7+i13fyE2jXeTf5xgyWC+JQ7GLT4EDdBn81pXiubDjPSSdjIeNVlopW72HwMZys8hvkv+9hCsedjbMsayrLPLecuskgbGIZhcyljyK+NqBvsXddCsUQ2NSuArge92XsaQFZ0lqWTN1tBtt+j3t2Pyp3+6U/vwb83C50zFKv1XHOn5yP998iiYzX+hV0+S5lXwbsITlMSTVrg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YO/k4BCIgcd1faF6SBTDTzgpHjATKHzbXQDvi0kOEWycpaDnIAznCQ4ZZnngZX+hST6Iwg1kETCNbTUh8R9mshBgxhaysyByHSa8QXYZtbzzfT7gEtxLy0yJ+MHv2SkFOGfKAPx2u1Fd/XDYKMzUxatGdQN+KXpCJA5sb7ECir/05Z5N77u+Qg9Jk9vYXXgekfzmJayW2+ei6MFvlOSsQWpQhJ57at1OfK3d7CZ5y58dHcjFR1Kn5qqj4bOIX27klmefmSOYXyK9Z2z2/pPV9rZkZoyrAEi3KpTDlZke2RPJ3nUGErX24sHARwdvp4Tu7rWn2QnLqqBAYD0mqt/J8A==
- Authentication-results: wdc.com; dkim=none (message not signed) header.d=none;wdc.com; dmarc=none action=none header.from=wdc.com;
- Cc: "axboe@xxxxxxxxx" <axboe@xxxxxxxxx>, "philipp.reisner@xxxxxxxxxx" <philipp.reisner@xxxxxxxxxx>, "lars.ellenberg@xxxxxxxxxx" <lars.ellenberg@xxxxxxxxxx>, "konrad.wilk@xxxxxxxxxx" <konrad.wilk@xxxxxxxxxx>, "roger.pau@xxxxxxxxxx" <roger.pau@xxxxxxxxxx>, "minchan@xxxxxxxxxx" <minchan@xxxxxxxxxx>, "ngupta@xxxxxxxxxx" <ngupta@xxxxxxxxxx>, "sergey.senozhatsky.work@xxxxxxxxx" <sergey.senozhatsky.work@xxxxxxxxx>, "agk@xxxxxxxxxx" <agk@xxxxxxxxxx>, "snitzer@xxxxxxxxxx" <snitzer@xxxxxxxxxx>, "hch@xxxxxx" <hch@xxxxxx>, "sagi@xxxxxxxxxxx" <sagi@xxxxxxxxxxx>, "martin.petersen@xxxxxxxxxx" <martin.petersen@xxxxxxxxxx>, "viro@xxxxxxxxxxxxxxxxxx" <viro@xxxxxxxxxxxxxxxxxx>, "tytso@xxxxxxx" <tytso@xxxxxxx>, "jaegeuk@xxxxxxxxxx" <jaegeuk@xxxxxxxxxx>, "ebiggers@xxxxxxxxxx" <ebiggers@xxxxxxxxxx>, "djwong@xxxxxxxxxx" <djwong@xxxxxxxxxx>, "shaggy@xxxxxxxxxx" <shaggy@xxxxxxxxxx>, "konishi.ryusuke@xxxxxxxxx" <konishi.ryusuke@xxxxxxxxx>, "mark@xxxxxxxxxx" <mark@xxxxxxxxxx>, "jlbec@xxxxxxxxxxxx" <jlbec@xxxxxxxxxxxx>, "joseph.qi@xxxxxxxxxxxxxxxxx" <joseph.qi@xxxxxxxxxxxxxxxxx>, Naohiro Aota <Naohiro.Aota@xxxxxxx>, "jth@xxxxxxxxxx" <jth@xxxxxxxxxx>, "rjw@xxxxxxxxxxxxx" <rjw@xxxxxxxxxxxxx>, "len.brown@xxxxxxxxx" <len.brown@xxxxxxxxx>, "pavel@xxxxxx" <pavel@xxxxxx>, "akpm@xxxxxxxxxxxxxxxxxxxx" <akpm@xxxxxxxxxxxxxxxxxxxx>, "hare@xxxxxxx" <hare@xxxxxxx>, "gustavoars@xxxxxxxxxx" <gustavoars@xxxxxxxxxx>, "tiwai@xxxxxxx" <tiwai@xxxxxxx>, "alex.shi@xxxxxxxxxxxxxxxxx" <alex.shi@xxxxxxxxxxxxxxxxx>, "asml.silence@xxxxxxxxx" <asml.silence@xxxxxxxxx>, "ming.lei@xxxxxxxxxx" <ming.lei@xxxxxxxxxx>, "tj@xxxxxxxxxx" <tj@xxxxxxxxxx>, "osandov@xxxxxx" <osandov@xxxxxx>, "bvanassche@xxxxxxx" <bvanassche@xxxxxxx>, "jefflexu@xxxxxxxxxxxxxxxxx" <jefflexu@xxxxxxxxxxxxxxxxx>
- Delivery-date: Thu, 28 Jan 2021 08:33:22 +0000
- Ironport-sdr: w5opH1owjt5Lo+2wpqvthrCHUfi3DzYxGCpnBQreSkEDUDsMf7F+YFx55pLwTaPP9PNR7ejXkA iSR+m2lKwVNewOcICTKInfjZrlB0rasI/uRstfJhqvklCDneuwpV+AyeRN1UtTQsWi3p0wOZ5p NtRp9nobCYtjluwC9rgqlMTVRAr3YTDKNFwq0JnYGNhlwe8uciFKMFMA+HSlphgfBPZi2864Hg oUXTFClDbTYFMBIWbqyOYRv8WpvASVVAA6SmH+8ZEWqZyIRKACecwbZpVnZ0jn0vwCMZb72oFn ZMw=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHW9UTnc64/mAmIvESrRLPcPpiQkQ==
- Thread-topic: [RFC PATCH 02/34] block: introduce and use bio_new
- Wdcipoutbound: EOP-TRUE
On 1/27/21 11:21 PM, Damien Le Moal wrote:
On 2021/01/28 16:12, Chaitanya Kulkarni wrote:
Introduce bio_new() helper and use it in blk-lib.c to allocate and
initialize various non-optional or semi-optional members of the bio
along with bio allocation done with bio_alloc(). Here we also calmp the
max_bvecs for bio with BIO_MAX_PAGES before we pass to bio_alloc().
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
---
block/blk-lib.c | 6 +-----
include/linux/bio.h | 25 +++++++++++++++++++++++++
2 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/block/blk-lib.c b/block/blk-lib.c
index fb486a0bdb58..ec29415f00dd 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -14,17 +14,13 @@ struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
sector_t sect, unsigned op, unsigned opf,
unsigned int nr_pages, gfp_t gfp)
{
- struct bio *new = bio_alloc(gfp, nr_pages);
+ struct bio *new = bio_new(bdev, sect, op, opf, gfp, nr_pages);
if (bio) {
bio_chain(bio, new);
submit_bio(bio);
}
- new->bi_iter.bi_sector = sect;
- bio_set_dev(new, bdev);
- bio_set_op_attrs(new, op, opf);
-
return new;
}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index c74857cf1252..2a09ba100546 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -826,5 +826,30 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
if (!is_sync_kiocb(kiocb))
bio->bi_opf |= REQ_NOWAIT;
}
+/**
+ * bio_new - allcate and initialize new bio
+ * @bdev: blockdev to issue discard for
+ * @sector: start sector
+ * @op: REQ_OP_XXX from enum req_opf
+ * @op_flags: REQ_XXX from enum req_flag_bits
+ * @max_bvecs: maximum bvec to be allocated for this bio
+ * @gfp_mask: memory allocation flags (for bio_alloc)
+ *
+ * Description:
+ * Allocates, initializes common members, and returns a new bio.
+ */
+static inline struct bio *bio_new(struct block_device *bdev, sector_t sector,
+ unsigned int op, unsigned int op_flags,
+ unsigned int max_bvecs, gfp_t gfp_mask)
+{
+ unsigned nr_bvec = clamp_t(unsigned int, max_bvecs, 0, BIO_MAX_PAGES);
+ struct bio *bio = bio_alloc(gfp_mask, nr_bvec);
I think that depending on the gfp_mask passed, bio can be NULL. So this should
be checked.
true, I'll add that check.
+
+ bio_set_dev(bio, bdev);
+ bio->bi_iter.bi_sector = sector;
+ bio_set_op_attrs(bio, op, op_flags);
This function is obsolete. Open code this.
true, will do.
+
+ return bio;
+}
#endif /* __LINUX_BIO_H */
Thanks for the comments Damien.
|