From 9b463a3a9ef9b6800359824c63c711e99edb4345 Mon Sep 17 00:00:00 2001 From: Coleman Kane Date: Tue, 13 Jul 2021 15:40:04 -0400 Subject: [PATCH] Compatibility update for 5.14 for blk_alloc_disk() In Linux 5.14, blk_alloc_queue is no longer exported, and its usage has been superseded by blk_alloc_disk, which returns a gendisk struct from which we can still retrieve the struct request_queue* that is needed in the one place where it is used. This also replaces the call to alloc_disk(minors), and minors is now set via struct member assignment. Signed-off-by: Coleman Kane --- config/kernel-blk-alloc-disk.m4 | 23 +++++++++++++++++++++++ config/kernel.m4 | 2 ++ module/os/linux/zfs/zvol_os.c | 15 +++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 config/kernel-blk-alloc-disk.m4 diff --git a/config/kernel-blk-alloc-disk.m4 b/config/kernel-blk-alloc-disk.m4 new file mode 100644 index 000000000000..ef013b66f2d5 --- /dev/null +++ b/config/kernel-blk-alloc-disk.m4 @@ -0,0 +1,23 @@ +dnl # +dnl # 5.14 API change +dnl # blk_alloc_queue deprecated in favor of blk_alloc_disk +dnl # +AC_DEFUN([ZFS_AC_KERNEL_SRC_BLK_ALLOC_DISK], [ + ZFS_LINUX_TEST_SRC([blk_alloc_disk], [ + #include + ], [ + struct gendisk *disk = NULL; + disk = blk_alloc_disk(0); + ]) +]) + +AC_DEFUN([ZFS_AC_KERNEL_BLK_ALLOC_DISK], [ + AC_MSG_CHECKING([whether blk_alloc_disk() is available]) + ZFS_LINUX_TEST_RESULT([blk_alloc_disk], [ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_BLK_ALLOC_DISK, 1, + [blk_alloc_disk() is available]) + ], [ + AC_MSG_RESULT(no) + ]) +]) diff --git a/config/kernel.m4 b/config/kernel.m4 index 7196e66ca28a..9df9e447bf0f 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -132,6 +132,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [ ZFS_AC_KERNEL_SRC_SIGNAL_STOP ZFS_AC_KERNEL_SRC_SIGINFO ZFS_AC_KERNEL_SRC_SET_SPECIAL_STATE + ZFS_AC_KERNEL_SRC_BLK_ALLOC_DISK AC_MSG_CHECKING([for available kernel interfaces]) ZFS_LINUX_TEST_COMPILE_ALL([kabi]) @@ -237,6 +238,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [ ZFS_AC_KERNEL_SIGNAL_STOP ZFS_AC_KERNEL_SIGINFO ZFS_AC_KERNEL_SET_SPECIAL_STATE + ZFS_AC_KERNEL_BLK_ALLOC_DISK ]) dnl # diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c index 741979f11af8..af9355686207 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -794,10 +794,19 @@ zvol_alloc(dev_t dev, const char *name) list_link_init(&zv->zv_next); mutex_init(&zv->zv_state_lock, NULL, MUTEX_DEFAULT, NULL); +#ifdef HAVE_BLK_ALLOC_DISK + zso->zvo_disk = blk_alloc_disk(NUMA_NO_NODE); + if (zso->zvo_disk == NULL) + goto out_kmem; + + zso->zvo_queue = zso->zvo_disk->queue; + zso->zvo_disk->minors = ZVOL_MINORS; +#else #ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS zso->zvo_queue = blk_alloc_queue(NUMA_NO_NODE); #else zso->zvo_queue = blk_generic_alloc_queue(zvol_request, NUMA_NO_NODE); +#endif #endif if (zso->zvo_queue == NULL) goto out_kmem; @@ -810,9 +819,11 @@ zvol_alloc(dev_t dev, const char *name) /* Disable write merging in favor of the ZIO pipeline. */ blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zso->zvo_queue); +#ifndef HAVE_BLK_ALLOC_DISK zso->zvo_disk = alloc_disk(ZVOL_MINORS); if (zso->zvo_disk == NULL) goto out_queue; +#endif zso->zvo_queue->queuedata = zv; zso->zvo_dev = dev; @@ -851,7 +862,11 @@ zvol_alloc(dev_t dev, const char *name) return (zv); out_queue: +#ifdef HAVE_BLK_ALLOC_DISK + blk_cleanup_disk(zso->zvo_disk); +#else blk_cleanup_queue(zso->zvo_queue); +#endif out_kmem: kmem_free(zso, sizeof (struct zvol_state_os)); kmem_free(zv, sizeof (zvol_state_t));