[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 02/34] block: introduce and use bio_new
- To: linux-xfs@xxxxxxxxxxxxxxx, linux-fsdevel@xxxxxxxxxxxxxxx, dm-devel@xxxxxxxxxx, linux-block@xxxxxxxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx, drbd-dev@xxxxxxxxxxxxxxxx, xen-devel@xxxxxxxxxxxxxxxxxxxx, linux-nvme@xxxxxxxxxxxxxxxxxxx, linux-scsi@xxxxxxxxxxxxxxx, target-devel@xxxxxxxxxxxxxxx, linux-fscrypt@xxxxxxxxxxxxxxx, jfs-discussion@xxxxxxxxxxxxxxxxxxxxx, linux-nilfs@xxxxxxxxxxxxxxx, ocfs2-devel@xxxxxxxxxxxxxx, linux-pm@xxxxxxxxxxxxxxx, linux-mm@xxxxxxxxx
- From: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
- Date: Wed, 27 Jan 2021 23:11:01 -0800
- Cc: axboe@xxxxxxxxx, philipp.reisner@xxxxxxxxxx, lars.ellenberg@xxxxxxxxxx, konrad.wilk@xxxxxxxxxx, roger.pau@xxxxxxxxxx, minchan@xxxxxxxxxx, ngupta@xxxxxxxxxx, sergey.senozhatsky.work@xxxxxxxxx, agk@xxxxxxxxxx, snitzer@xxxxxxxxxx, hch@xxxxxx, sagi@xxxxxxxxxxx, chaitanya.kulkarni@xxxxxxx, martin.petersen@xxxxxxxxxx, viro@xxxxxxxxxxxxxxxxxx, tytso@xxxxxxx, jaegeuk@xxxxxxxxxx, ebiggers@xxxxxxxxxx, djwong@xxxxxxxxxx, shaggy@xxxxxxxxxx, konishi.ryusuke@xxxxxxxxx, mark@xxxxxxxxxx, jlbec@xxxxxxxxxxxx, joseph.qi@xxxxxxxxxxxxxxxxx, damien.lemoal@xxxxxxx, naohiro.aota@xxxxxxx, jth@xxxxxxxxxx, rjw@xxxxxxxxxxxxx, len.brown@xxxxxxxxx, pavel@xxxxxx, akpm@xxxxxxxxxxxxxxxxxxxx, hare@xxxxxxx, gustavoars@xxxxxxxxxx, tiwai@xxxxxxx, alex.shi@xxxxxxxxxxxxxxxxx, asml.silence@xxxxxxxxx, ming.lei@xxxxxxxxxx, tj@xxxxxxxxxx, osandov@xxxxxx, bvanassche@xxxxxxx, jefflexu@xxxxxxxxxxxxxxxxx
- Delivery-date: Thu, 28 Jan 2021 07:12:01 +0000
- Ironport-sdr: 8/dBKA7g/jbRzCZQg8lJkOc/yY6kSqYaDab+Qwamz43l63acYbyrw55KYd8E88hJ/2S18+xLDx 34HJ1ZzvJbk3iIqM0QLbkVgAV9xf2UGJW0IHCnpFfvc092M5n1y9oe8Yu5ZwMP68v3j4sl1GQD jNYRfiGszaTJeCGQ9wovfl8D5XqpGyxMM2MtP3LpRKmZP+c/8UQgUFCtYNhYNpDb6W9fPYCCRw pi4ninNiqvJ5LLJuvbsMg3pfVxNf3TeDidcPKBNI1f/Qv1spgjuryrUrAa3Dr5s4UuUn4ETXBO Ap4=
- Ironport-sdr: rfQpYOswVNFR2gS5xT3kk1zuVCn6nMX/nrwfivaz/wWQ5oqSiqcBR8y+LbTIOAR1VlKnfwdzCX pgmDoujWGwMsqy8TiKbKr0dZnxwwv7dIc0sgGlsLJkBXZ9WGw0zXPypvaKgWZTxDO8eslsgk6e EEZz3l8yfORjDN6QdKYDQhLJ8/F7XLcCEwJoxAMlQQlDK/cTN3ymDwF20i/2Ux7cobX4NoSCex W2lzL8X+PCJFxvxcVmVSIvT3UIr781Kl0DuO5kZ1Dg/0tSkr0w4SgUfWMLskjEJyF7nEMcj66F 4Q109esZwg0XsCE9Kisw6n8G
- Ironport-sdr: HYKG8+pmcZ9KZ4KZ0ijEvKFdi7W0dgGDXHFsWIaWNxW3zaOZulAuYVmKBU97gor6eDg6ylP5Ni 6/ahnxe6yM79ewZwsqKvrfMjvqQiAhLVOYCtlxS8Bh1Gz/vhwXPlVRnl4SwtLQD680yYKL86EL o3y724i0cbqHM9ChTIb0swq0MYuYoJx+iwqVjQ/XkVzNSKEtJ8uwRbdybmRUPVMHWHGtPAl98+ IjNd0sVxBZiY+I2eDgAQpiJ9r1dqmBNoZAqnfBCkqleNy/DSVZGKQaXDO89s0wR1FlZS/ZCSSd 5w0=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Wdcironportexception: Internal
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);
+
+ bio_set_dev(bio, bdev);
+ bio->bi_iter.bi_sector = sector;
+ bio_set_op_attrs(bio, op, op_flags);
+
+ return bio;
+}
#endif /* __LINUX_BIO_H */
--
2.22.1
|