[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:27:21 +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=7dHgs/1VLBXJ5Fid/0F/6cbHkJ0A+oW1xrqX9+A0GgQ=; b=WpVsW1S/kKhHgGTEzveH/WBQWziddYzWdBCW+5peeK2CMYzuM35ikhiL93qQisaU2sh5XUUpBGRi/TFqqx3OmGIe24yyfIzJAQbSDPUcgJl828BlV9USdpsDOoEeDZtHgttMYKmGI1gJsSt+V6kxWrCrBRnN8lSCWDpfiroaO+QmE16osB2eevjAkuP0qNTfCZo6bo3ZQRwiDwhweVFwoM8Ww9mA8MT5yPoo5QtVqHYpRPAG0NbaJNanr+SI0Duz8hOTcNB65u4JLwKXGhuJHAalGmP1VOd5oTVjmseyILk+5VEQB5HpwincSvcGZkpYEkN24oBog5tfK+cn6HqdlA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B83E+AQw1n8nLaPpws6ZVk2Dvv0JowLzEH6tW4QBIZHQO5bOyKoRkl9zce6LAfAcYeKNBnUqMBuqWKPapazajsM6mugFl46pUPnH27w2MyNgzfB2U64tU7/YQtksU04S+GWbxUwv7ua6jeuaCXw0Q2a/INcuYW1pZmbpSmGcHX0jgHrsfKIziwmv/KoIW40wdsUPJfmkSsIjxMNkqU8mSH3CYfS72OI5u+QFvQXzGlRrot81kEsbS6zPF3R+md3jI0xbLOthW81i6HkUhnZFc7n6i76TjivEJep1dTrNSJmAcZacixJJoHL5R1ayC6mgKhmUp43MFeS2JhA8RHsWLw==
- 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:27:33 +0000
- Ironport-sdr: 5meZAAXbPsZyMOd9RQOAURE7ue4N8I0GylPazNiN4F+IkU2Nf7CrEdUTmPOyFzJi7zfeggOiiu Gt5Od7xhy+yHk7m31eLzfrafTPyIE2+841Tdhjt9RuKfy1UwsAhsaJEc7TrPpyeonTG5OoNRbW jYwfp8qY1//btPd2uEMJY+wlNQ6hUZhFAaCgz+oVCXV8JG1R++3gaALgNG32rpHLVCAPpUvSm5 ZnyqhIjEF7MhfKsrin8SIf9C2tCW+9kugysfCU7OmxJSUh1jT50kH6wLdq3lVUWVW9JSAnaEIT sQI=
- 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:21, 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.
>
>> +
>> + 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.
And that also mean that you could remove one argument to bio_new(): combine op
and op_flags into "unsigned int opf"
>
>> +
>> + return bio;
>> +}
>>
>> #endif /* __LINUX_BIO_H */
>>
>
>
--
Damien Le Moal
Western Digital Research
|