diff options
author | Coleman Kane <ckane@colemankane.org> | 2021-12-03 21:45:28 -0500 |
---|---|---|
committer | Tony Hutter <hutter2@llnl.gov> | 2021-12-07 13:14:23 -0800 |
commit | ea61e074132f9371c3d1932ed8e24767a087c80c (patch) | |
tree | 841b71f1e6e6e046197af1185330f89002a55f83 | |
parent | 9519fe1ff83016fdbf2ad7bcad0c7a16a8e73acc (diff) |
Linux 5.16: bio_set_dev is no longer a helper macro
This change adds a confiugre check to determine if bio_set_dev is a
helper macro or not. If not, then the attempt to override its internal
call to bio_associate_blkg(), with a macro definition to our own
version, is no longer possible, as the compiler won't use it when
compiling the new inline function replacement implemented in the header.
This change also creates a new vdev_bio_set_dev() function that performs
the same work, and also performs the work implemented in
vdev_bio_associate_blkg(), as it is the only thing calling that function
in our code. Our custom vdev_bio_associate_blkg() is now only compiled
if the bio_set_dev() is a macro in the Linux headers.
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Coleman Kane <ckane@colemankane.org>
Closes #12819
-rw-r--r-- | config/kernel-bio.m4 | 28 | ||||
-rw-r--r-- | module/os/linux/zfs/vdev_disk.c | 24 |
2 files changed, 52 insertions, 0 deletions
diff --git a/config/kernel-bio.m4 b/config/kernel-bio.m4 index 1d715b2de..df5e9de3b 100644 --- a/config/kernel-bio.m4 +++ b/config/kernel-bio.m4 @@ -191,6 +191,24 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BIO_SET_DEV], [ ], [], [ZFS_META_LICENSE]) ]) +dnl # +dnl # Linux 5.16 API +dnl # +dnl # bio_set_dev is no longer a helper macro and is now an inline function, +dnl # meaning that the function it calls internally can no longer be overridden +dnl # by our code +dnl # +AC_DEFUN([ZFS_AC_KERNEL_SRC_BIO_SET_DEV_MACRO], [ + ZFS_LINUX_TEST_SRC([bio_set_dev_macro], [ + #include <linux/bio.h> + #include <linux/fs.h> + ],[ + #ifndef bio_set_dev + #error Not a macro + #endif + ], [], [ZFS_META_LICENSE]) +]) + AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV], [ AC_MSG_CHECKING([whether bio_set_dev() is available]) ZFS_LINUX_TEST_RESULT([bio_set_dev], [ @@ -205,6 +223,15 @@ AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV], [ AC_DEFINE(HAVE_BIO_SET_DEV_GPL_ONLY, 1, [bio_set_dev() GPL-only]) ]) + + AC_MSG_CHECKING([whether bio_set_dev() is a macro]) + ZFS_LINUX_TEST_RESULT([bio_set_dev_macro], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_BIO_SET_DEV_MACRO, 1, + [bio_set_dev() is a macro]) + ],[ + AC_MSG_RESULT(no) + ]) ],[ AC_MSG_RESULT(no) ]) @@ -434,6 +461,7 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BIO], [ ZFS_AC_KERNEL_SRC_BLKG_TRYGET ZFS_AC_KERNEL_SRC_BIO_BDEV_DISK ZFS_AC_KERNEL_SRC_BDEV_SUBMIT_BIO_RETURNS_VOID + ZFS_AC_KERNEL_SRC_BIO_SET_DEV_MACRO ]) AC_DEFUN([ZFS_AC_KERNEL_BIO], [ diff --git a/module/os/linux/zfs/vdev_disk.c b/module/os/linux/zfs/vdev_disk.c index bcec4c6ba..0e884f426 100644 --- a/module/os/linux/zfs/vdev_disk.c +++ b/module/os/linux/zfs/vdev_disk.c @@ -493,6 +493,7 @@ vdev_blkg_tryget(struct blkcg_gq *blkg) #elif defined(HAVE_BLKG_TRYGET) #define vdev_blkg_tryget(bg) blkg_tryget(bg) #endif +#ifdef HAVE_BIO_SET_DEV_MACRO /* * The Linux 5.0 kernel updated the bio_set_dev() macro so it calls the * GPL-only bio_associate_blkg() symbol thus inadvertently converting @@ -514,7 +515,30 @@ vdev_bio_associate_blkg(struct bio *bio) if (q->root_blkg && vdev_blkg_tryget(q->root_blkg)) bio->bi_blkg = q->root_blkg; } + #define bio_associate_blkg vdev_bio_associate_blkg +#else +static inline void +vdev_bio_set_dev(struct bio *bio, struct block_device *bdev) +{ +#if defined(HAVE_BIO_BDEV_DISK) + struct request_queue *q = bdev->bd_disk->queue; +#else + struct request_queue *q = bio->bi_disk->queue; +#endif + bio_clear_flag(bio, BIO_REMAPPED); + if (bio->bi_bdev != bdev) + bio_clear_flag(bio, BIO_THROTTLED); + bio->bi_bdev = bdev; + + ASSERT3P(q, !=, NULL); + ASSERT3P(bio->bi_blkg, ==, NULL); + + if (q->root_blkg && vdev_blkg_tryget(q->root_blkg)) + bio->bi_blkg = q->root_blkg; +} +#define bio_set_dev vdev_bio_set_dev +#endif #endif #else /* |