[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 02/34] block: introduce and use bio_new
- To: Chaitanya Kulkarni <Chaitanya.Kulkarni@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: Damien Le Moal <Damien.LeMoal@xxxxxxx>
- Date: Thu, 28 Jan 2021 07:21:42 +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=rZQ79VfW37oEjUPhbUXgVDt26btMTlh35TXahcKTIxw=; b=ewcyy+f5pm0Gvfuq66QLUzmljFfxV1XcSt+FlXT110bCllm3RqvEk+y6rdwmDmRsLuIdGvXsMnFhphdnjfxABcalxu6RrTkW7MnOnWh9EF/8L3nffa7eXXB95G3BRw9RE5QltDcCZ1vcJ9c2HoEAI4HaooQEfE5prpKhyIBJc+z2sT8ynyDdElAtc2TQJJC8yAuAd8n0jS7Wc+YTaNR4fwo2ziu1wBo7rB+4xYRJnj/90sIzgR+/oyqJ8hNKi14vk4mwaZnVXoctiOqF4V0CjyJ2prws95UPtxPw9I8GHkzSJXn0TdiFJJTWo1ZfduzHSE90W7Sesm7qKNrg2W5Wag==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XGvTFC0yVocA1hFeGOYvjQ+f/YSuD75Q/8tkuiyNxQkF23UxvMywneYGAln1lw8Xhs3qjQvWItdgd+CqdoCZOLpmuH4ptIfJkiKypbJOF8fjo6xly5kpeejMCcmb9TV+VYlceFyaNhO46nha82bqmy7/luCs/lrsoL/cArREno60UHuMizWsEmdy4Bxfq7LnJpERyi07H9ww2vM5jeFFQj0tMeAigkwO1DsWafJt0Fq839vVOSa6z1KrJTZS1iJDKKe3rPYdaA3pbji5icSyWi0MHi2Av8SuAEzbzvSxch0j+tb0kMkBwUJVhvH8tc9lyxzjLZbBWdlEFDj4KAQoSQ==
- 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 07:21:56 +0000
- Ironport-sdr: QEF+8TGngCqTGDYAfES0k7Iq8Lj8Z1j23hWw3M3LnFhL6QZih1XM5LZxSRsfTJXgpv5E1SblKM Bsu7V10JhP5TnAvBjYRtRxEqUPv2HJm33T5x70FdtpKeTam8Lku0k8SIl7hluBD5ij/As5Vw9s nKuDQlS8VQ8KHSrpBH6erXI92dE58YUlccMAgxKbmkG5Krj4uGkirZn5TulPgUw8Qky4rfx2PQ aWCuLtWfwtNgNSyX+xM2wVuWWfLlJn8a8AVx4NTLiKKss4UTZKw7CG5gC5hQr1D2fM05/SrZuv r5A=
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHW9UTnP+XqlvwCeEC+5iodtWSeNA==
- Thread-topic: [RFC PATCH 02/34] block: introduce and use bio_new
- Wdcipoutbound: EOP-TRUE
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.
> +
> + 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.
> +
> + return bio;
> +}
>
> #endif /* __LINUX_BIO_H */
>
--
Damien Le Moal
Western Digital Research
|