From: Shaun Tancheff Date: Mon, 14 Nov 2022 09:30:23 +0000 (-0600) Subject: LU-16202 build: bio_alloc takes struct block_device X-Git-Tag: 2.15.54~109 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=737737562e463d3608b4b6f044b2e170a3fd80e7;hp=61c3b3a9bb848e256845462ffd79b15565cd23ad;p=fs%2Flustre-release.git LU-16202 build: bio_alloc takes struct block_device Linux commit v5.17-rc2-21-g07888c665b40 block: pass a block_device and opf to bio_alloc Create a compatible bio_alloc wrapper to handle the change in arguments and behavior. HPE-bug-id: LUS-11267 Test-Parameters: trivial Signed-off-by: Shaun Tancheff Signed-off-by: Jian Yu Change-Id: I060229b25785f46a9749fcdb18727af292a940ac Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48820 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin Reviewed-by: Petros Koutoupis Reviewed-by: Andreas Dilger --- diff --git a/libcfs/autoconf/lustre-libcfs.m4 b/libcfs/autoconf/lustre-libcfs.m4 index badfcf5..9b3e070 100644 --- a/libcfs/autoconf/lustre-libcfs.m4 +++ b/libcfs/autoconf/lustre-libcfs.m4 @@ -2007,6 +2007,28 @@ pde_data, [ ]) # LIBCFS_PDE_DATA_EXISTS # +# LIBCFS_BIO_ALLOC_WITH_BDEV +# +# Linux commit v5.17-rc2-21-g07888c665b40 +# block: pass a block_device and opf to bio_alloc +# +AC_DEFUN([LIBCFS_BIO_ALLOC_WITH_BDEV],[ +LB_CHECK_COMPILE([does bio_alloc() takes a struct block_device], +bio_alloc_with_bdev, [ + #include + ],[ + struct block_device *bdev = NULL; + unsigned short nr_vecs = 1; + gfp_t gfp = GFP_KERNEL; + struct bio *bio = bio_alloc(bdev, nr_vecs, REQ_OP_WRITE, gfp); + (void) bio; + ],[ + AC_DEFINE(HAVE_BIO_ALLOC_WITH_BDEV, 1, + [bio_alloc() takes a struct block_device]) + ]) +]) # LIBCFS_BIO_ALLOC_WITH_BDEV + +# # LIBCFS_PROG_LINUX # # LibCFS linux kernel checks @@ -2157,6 +2179,7 @@ LIBCFS_PARAM_SET_UINT_MINMAX LIBCFS_LINUX_BLK_INTEGRITY_HEADER # 5.17 LIBCFS_PDE_DATA_EXISTS +LIBCFS_BIO_ALLOC_WITH_BDEV ]) # LIBCFS_PROG_LINUX # diff --git a/libcfs/include/libcfs/linux/linux-fs.h b/libcfs/include/libcfs/linux/linux-fs.h index 6ef6b07..8d25907 100644 --- a/libcfs/include/libcfs/linux/linux-fs.h +++ b/libcfs/include/libcfs/linux/linux-fs.h @@ -84,4 +84,4 @@ static inline void mapping_clear_exiting(struct address_space *mapping) #endif } -#endif +#endif /* __LIBCFS_LINUX_CFS_FS_H__ */ diff --git a/libcfs/libcfs/crypto/bio.c b/libcfs/libcfs/crypto/bio.c index a0e96db..78b56cb 100644 --- a/libcfs/libcfs/crypto/bio.c +++ b/libcfs/libcfs/crypto/bio.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "llcrypt_private.h" static void __llcrypt_decrypt_bio(struct bio *bio, bool done) @@ -96,14 +97,13 @@ int llcrypt_zeroout_range(const struct inode *inode, pgoff_t lblk, if (err) goto errout; - bio = bio_alloc(GFP_NOWAIT, 1); + bio = cfs_bio_alloc(inode->i_sb->s_bdev, 1, REQ_OP_WRITE, + GFP_NOWAIT); if (!bio) { err = -ENOMEM; goto errout; } - bio_set_dev(bio, inode->i_sb->s_bdev); bio->bi_iter.bi_sector = pblk << (blockbits - 9); - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); ret = bio_add_page(bio, ciphertext_page, blocksize, 0); if (WARN_ON(ret != blocksize)) { /* should never happen! */ diff --git a/lustre/include/lustre_compat.h b/lustre/include/lustre_compat.h index aca622a..b4efb01 100644 --- a/lustre/include/lustre_compat.h +++ b/lustre/include/lustre_compat.h @@ -71,6 +71,40 @@ #define bio_start_sector(bio) (bio->bi_sector) #endif +#ifdef HAVE_BI_BDEV +# define bio_get_dev(bio) ((bio)->bi_bdev) +# define bio_get_disk(bio) (bio_get_dev(bio)->bd_disk) +# define bio_get_queue(bio) bdev_get_queue(bio_get_dev(bio)) + +# ifndef HAVE_BIO_SET_DEV +# define bio_set_dev(bio, bdev) (bio_get_dev(bio) = (bdev)) +# endif +#else +# define bio_get_disk(bio) ((bio)->bi_disk) +# define bio_get_queue(bio) (bio_get_disk(bio)->queue) +#endif + +#ifndef HAVE_BI_OPF +#define bi_opf bi_rw +#endif + +static inline struct bio *cfs_bio_alloc(struct block_device *bdev, + unsigned short nr_vecs, + __u32 op, gfp_t gfp_mask) +{ + struct bio *bio; +#ifdef HAVE_BIO_ALLOC_WITH_BDEV + bio = bio_alloc(bdev, nr_vecs, op, gfp_mask); +#else + bio = bio_alloc(gfp_mask, nr_vecs); + if (bio) { + bio_set_dev(bio, bdev); + bio->bi_opf = op; + } +#endif /* HAVE_BIO_ALLOC_WITH_BDEV */ + return bio; +} + #ifndef HAVE_DENTRY_D_CHILD #define d_child d_u.d_child #endif diff --git a/lustre/osd-ldiskfs/osd_internal.h b/lustre/osd-ldiskfs/osd_internal.h index a57cfe0..1ee407e 100644 --- a/lustre/osd-ldiskfs/osd_internal.h +++ b/lustre/osd-ldiskfs/osd_internal.h @@ -52,6 +52,7 @@ #include #include #include +#include /* LUSTRE_OSD_NAME */ #include @@ -1498,19 +1499,6 @@ static inline struct buffer_head *__ldiskfs_bread(handle_t *handle, bool bio_integrity_enabled(struct bio *bio); #endif -#ifdef HAVE_BI_BDEV -# define bio_get_dev(bio) ((bio)->bi_bdev) -# define bio_get_disk(bio) (bio_get_dev(bio)->bd_disk) -# define bio_get_queue(bio) bdev_get_queue(bio_get_dev(bio)) - -# ifndef HAVE_BIO_SET_DEV -# define bio_set_dev(bio, bdev) (bio_get_dev(bio) = (bdev)) -# endif -#else -# define bio_get_disk(bio) ((bio)->bi_disk) -# define bio_get_queue(bio) (bio_get_disk(bio)->queue) -#endif - #ifdef HAVE_EXT4_JOURNAL_GET_WRITE_ACCESS_4ARGS # define osd_ldiskfs_journal_get_write_access(handle, sb, bh, flags) \ ldiskfs_journal_get_write_access((handle), (sb), (bh), (flags)) @@ -1615,10 +1603,6 @@ void osd_execute_truncate(struct osd_object *obj); #define __bi_cnt bi_cnt #endif -#ifndef HAVE_BI_OPF -#define bi_opf bi_rw -#endif - #ifndef HAVE_CLEAN_BDEV_ALIASES #define clean_bdev_aliases(bdev, block, len) \ unmap_underlying_metadata((bdev), (block)) diff --git a/lustre/osd-ldiskfs/osd_io.c b/lustre/osd-ldiskfs/osd_io.c index a104ae7..366312b 100644 --- a/lustre/osd-ldiskfs/osd_io.c +++ b/lustre/osd-ldiskfs/osd_io.c @@ -612,21 +612,21 @@ static int osd_do_bio(struct osd_device *osd, struct inode *inode, bio_start_page_idx = page_idx; /* allocate new bio */ - bio = bio_alloc(GFP_NOIO, min_t(unsigned short, - BIO_MAX_VECS, - (block_idx_end - block_idx + - blocks_left_page - 1))); - if (bio == NULL) { + bio = cfs_bio_alloc(bdev, + min_t(unsigned short, BIO_MAX_VECS, + (block_idx_end - block_idx + + blocks_left_page - 1)), + iobuf->dr_rw ? REQ_OP_WRITE + : REQ_OP_READ, + GFP_NOIO); + if (!bio) { CERROR("Can't allocate bio %u pages\n", block_idx_end - block_idx + blocks_left_page - 1); rc = -ENOMEM; goto out; } - - bio_set_dev(bio, bdev); bio_set_sector(bio, sector); - bio->bi_opf = iobuf->dr_rw ? WRITE : READ; rc = osd_bio_init(bio, iobuf, integrity_enabled, bio_start_page_idx, &bio_private); if (rc) {