Message ID | 20210128071133.60335-1-chaitanya.kulkarni@wdc.com |
---|---|
Headers | show |
Series | block: introduce bio_new() | expand |
On 2021/01/28 16:15, Chaitanya Kulkarni wrote: > Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> > --- > fs/zonefs/super.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c > index ab68e27bb322..620d67965a22 100644 > --- a/fs/zonefs/super.c > +++ b/fs/zonefs/super.c > @@ -661,6 +661,7 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = { > > static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) > { > + unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; I do not see the point of adding this variable since it is used only for the bio_new() call. Pass the op value directly. > struct inode *inode = file_inode(iocb->ki_filp); > struct zonefs_inode_info *zi = ZONEFS_I(inode); > struct block_device *bdev = inode->i_sb->s_bdev; > @@ -678,15 +679,12 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter *from) > if (!nr_pages) > return 0; > > - bio = bio_alloc(GFP_NOFS, nr_pages); > + bio = bio_new(bdev, zi->i_zsector, op, 0, GFP_NOFS, nr_pages); > if (!bio) > return -ENOMEM; > > - bio_set_dev(bio, bdev); > - bio->bi_iter.bi_sector = zi->i_zsector; > bio->bi_write_hint = iocb->ki_hint; > bio->bi_ioprio = iocb->ki_ioprio; > - bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE; > if (iocb->ki_flags & IOCB_DSYNC) > bio->bi_opf |= REQ_FUA; > >
On Thu, Jan 28, 2021 at 8:21 AM Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> wrote: > Please explain in the changelog why making this change is a good idea. > Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> > --- > kernel/power/swap.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/kernel/power/swap.c b/kernel/power/swap.c > index c73f2e295167..e92e36c053a6 100644 > --- a/kernel/power/swap.c > +++ b/kernel/power/swap.c > @@ -271,13 +271,12 @@ static int hib_submit_io(int op, int op_flags, pgoff_t page_off, void *addr, > struct hib_bio_batch *hb) > { > struct page *page = virt_to_page(addr); > + sector_t sect = page_off * (PAGE_SIZE >> 9); > struct bio *bio; > int error = 0; > > - bio = bio_alloc(GFP_NOIO | __GFP_HIGH, 1); > - bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9); > - bio_set_dev(bio, hib_resume_bdev); > - bio_set_op_attrs(bio, op, op_flags); > + bio = bio_new(hib_resume_bdev, sect, op, op_flags, 1, > + GFP_NOIO | __GFP_HIGH); > > if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { > pr_err("Adding page to bio failed at %llu\n", > -- > 2.22.1 >
You probably don't need 4 patches to fs/jfs/. These can be combined into a single patch. Dave On 1/28/21 1:11 AM, Chaitanya Kulkarni wrote: > Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> > --- > fs/jfs/jfs_logmgr.c | 7 ++----- > 1 file changed, 2 insertions(+), 5 deletions(-) > > diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c > index 9330eff210e0..4481f3e33a3f 100644 > --- a/fs/jfs/jfs_logmgr.c > +++ b/fs/jfs/jfs_logmgr.c > @@ -1979,17 +1979,14 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp) > > bp->l_flag |= lbmREAD; > > - bio = bio_alloc(GFP_NOFS, 1); > - > - bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9); > - bio_set_dev(bio, log->bdev); > + bio = bio_new(log->bdev, bp->l_blkno << (log->l2bsize - 9), > + REQ_OP_READ, 0, 1, GFP_NOFS); > > bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset); > BUG_ON(bio->bi_iter.bi_size != LOGPSIZE); > > bio->bi_end_io = lbmIODone; > bio->bi_private = bp; > - bio->bi_opf = REQ_OP_READ; > /*check if journaling to disk has been disabled*/ > if (log->no_integrity) { > bio->bi_iter.bi_size = 0; >
FYI your email is completely unreadable to those not using html. I can't tell what you wrote and what Damien wrote. On Thu, Jan 28, 2021 at 08:33:10AM +0000, Chaitanya Kulkarni wrote: > 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@wdc.com><mailto:chaitanya.kulkarni@wdc.com> > --- > 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. > _______________________________________________ > Ocfs2-devel mailing list > Ocfs2-devel@oss.oracle.com > https://oss.oracle.com/mailman/listinfo/ocfs2-devel