From 5c4ec382a76c7c0d6b218fcab5a1c2e035012158 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 16 Jan 2019 10:39:19 -0800 Subject: [PATCH] Linux 5.0 compat: Fix bio_set_dev() The Linux 5.0 kernel updated the bio_set_dev() macro so it calls the GPL-only bio_associate_blkg() symbol thus inadvertently converting the entire macro. Provide a minimal version which always assigns the request queue's root_blkg to the bio. Reviewed-by: Brian Behlendorf Signed-off-by: Brian Behlendorf Closes #8287 --- config/kernel-bio_set_dev.m4 | 35 +++++++++++++++++++++++++++++++++-- module/zfs/vdev_disk.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/config/kernel-bio_set_dev.m4 b/config/kernel-bio_set_dev.m4 index 6be873c56..71d47a893 100644 --- a/config/kernel-bio_set_dev.m4 +++ b/config/kernel-bio_set_dev.m4 @@ -1,10 +1,10 @@ dnl # dnl # Linux 4.14 API, dnl # -dnl # The bio_set_dev() helper was introduced as part of the transition +dnl # The bio_set_dev() helper macro was introduced as part of the transition dnl # to have struct gendisk in struct bio. dnl # -AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV], [ +AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV_MACRO], [ AC_MSG_CHECKING([whether bio_set_dev() exists]) ZFS_LINUX_TRY_COMPILE([ #include @@ -20,3 +20,34 @@ AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV], [ AC_MSG_RESULT(no) ]) ]) + +dnl # +dnl # Linux 5.0 API, +dnl # +dnl # The bio_set_dev() helper macro was updated to internally depend on +dnl # bio_associate_blkg() symbol which is exported GPL-only. +dnl # +AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV_GPL_ONLY], [ + AC_MSG_CHECKING([whether bio_set_dev() is GPL-only]) + ZFS_LINUX_TRY_COMPILE([ + #include + #include + #include + MODULE_LICENSE("$ZFS_META_LICENSE"); + ],[ + struct block_device *bdev = NULL; + struct bio *bio = NULL; + bio_set_dev(bio, bdev); + ],[ + AC_MSG_RESULT(no) + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_BIO_SET_DEV_GPL_ONLY, 1, + [bio_set_dev() GPL-only]) + ]) +]) + +AC_DEFUN([ZFS_AC_KERNEL_BIO_SET_DEV], [ + ZFS_AC_KERNEL_BIO_SET_DEV_MACRO + ZFS_AC_KERNEL_BIO_SET_DEV_GPL_ONLY +]) diff --git a/module/zfs/vdev_disk.c b/module/zfs/vdev_disk.c index 1a570e821..cf011bf9c 100644 --- a/module/zfs/vdev_disk.c +++ b/module/zfs/vdev_disk.c @@ -502,13 +502,38 @@ vdev_submit_bio_impl(struct bio *bio) #endif } -#ifndef HAVE_BIO_SET_DEV +#ifdef HAVE_BIO_SET_DEV +#if defined(CONFIG_BLK_CGROUP) && defined(HAVE_BIO_SET_DEV_GPL_ONLY) +/* + * The Linux 5.0 kernel updated the bio_set_dev() macro so it calls the + * GPL-only bio_associate_blkg() symbol thus inadvertently converting + * the entire macro. Provide a minimal version which always assigns the + * request queue's root_blkg to the bio. + */ +static inline void +vdev_bio_associate_blkg(struct bio *bio) +{ + struct request_queue *q = bio->bi_disk->queue; + + ASSERT3P(q, !=, NULL); + ASSERT3P(q->root_blkg, !=, NULL); + ASSERT3P(bio->bi_blkg, ==, NULL); + + if (blkg_tryget(q->root_blkg)) + bio->bi_blkg = q->root_blkg; +} +#define bio_associate_blkg vdev_bio_associate_blkg +#endif +#else +/* + * Provide a bio_set_dev() helper macro for pre-Linux 4.14 kernels. + */ static inline void bio_set_dev(struct bio *bio, struct block_device *bdev) { bio->bi_bdev = bdev; } -#endif /* !HAVE_BIO_SET_DEV */ +#endif /* HAVE_BIO_SET_DEV */ static inline void vdev_submit_bio(struct bio *bio) -- 2.40.0