Whamcloud - gitweb
LU-16202 build: bio_alloc takes struct block_device 20/48820/9
authorShaun Tancheff <shaun.tancheff@hpe.com>
Mon, 14 Nov 2022 09:30:23 +0000 (03:30 -0600)
committerOleg Drokin <green@whamcloud.com>
Fri, 13 Jan 2023 07:21:35 +0000 (07:21 +0000)
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 <shaun.tancheff@hpe.com>
Signed-off-by: Jian Yu <yujian@whamcloud.com>
Change-Id: I060229b25785f46a9749fcdb18727af292a940ac
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/48820
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Petros Koutoupis <petros.koutoupis@hpe.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
libcfs/autoconf/lustre-libcfs.m4
libcfs/include/libcfs/linux/linux-fs.h
libcfs/libcfs/crypto/bio.c
lustre/include/lustre_compat.h
lustre/osd-ldiskfs/osd_internal.h
lustre/osd-ldiskfs/osd_io.c

index badfcf5..9b3e070 100644 (file)
@@ -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 <linux/bio.h>
+       ],[
+               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
 
 #
index 6ef6b07..8d25907 100644 (file)
@@ -84,4 +84,4 @@ static inline void mapping_clear_exiting(struct address_space *mapping)
 #endif
 }
 
-#endif
+#endif /* __LIBCFS_LINUX_CFS_FS_H__ */
index a0e96db..78b56cb 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 #include <linux/bio.h>
 #include <linux/namei.h>
+#include <lustre_compat.h>
 #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! */
index aca622a..b4efb01 100644 (file)
 #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
index a57cfe0..1ee407e 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/file.h>
 #include <ldiskfs/ldiskfs.h>
 #include <ldiskfs/ldiskfs_jbd2.h>
+#include <lustre_compat.h>
 
 /* LUSTRE_OSD_NAME */
 #include <obd.h>
@@ -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))
index a104ae7..366312b 100644 (file)
@@ -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) {