Skip to content

Commit

Permalink
Compatibility update for 5.14 for blk_alloc_disk()
Browse files Browse the repository at this point in the history
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 <ckane@colemankane.org>
  • Loading branch information
ckane committed Jul 13, 2021
1 parent 1325434 commit 9b463a3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions config/kernel-blk-alloc-disk.m4
Original file line number Diff line number Diff line change
@@ -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 <linux/genhd.h>
], [
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)
])
])
2 changes: 2 additions & 0 deletions config/kernel.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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 #
Expand Down
15 changes: 15 additions & 0 deletions module/os/linux/zfs/zvol_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9b463a3

Please sign in to comment.