Skip to content

Commit 36d50b6

Browse files
behlendorftonyhutter
authored andcommitted
Linux 5.14 compat: 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. Reviewed-by: Tony Nguyen <[email protected]> Reviewed-by: Olaf Faaland <[email protected]> Reviewed-by: Coleman Kane <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #12362 Closes #12409
1 parent 0c4f86b commit 36d50b6

File tree

2 files changed

+54
-9
lines changed

2 files changed

+54
-9
lines changed

config/kernel-make-request-fn.m4

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN], [
4242
struct block_device_operations o;
4343
o.submit_bio = NULL;
4444
])
45+
46+
ZFS_LINUX_TEST_SRC([blk_alloc_disk], [
47+
#include <linux/blkdev.h>
48+
],[
49+
struct gendisk *disk __attribute__ ((unused));
50+
disk = blk_alloc_disk(NUMA_NO_NODE);
51+
])
4552
])
4653

4754
AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [
@@ -56,6 +63,19 @@ AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [
5663
5764
AC_DEFINE(HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS, 1,
5865
[submit_bio is member of struct block_device_operations])
66+
67+
dnl #
68+
dnl # Linux 5.14 API Change:
69+
dnl # blk_alloc_queue() + alloc_disk() combo replaced by
70+
dnl # a single call to blk_alloc_disk().
71+
dnl #
72+
AC_MSG_CHECKING([whether blk_alloc_disk() exists])
73+
ZFS_LINUX_TEST_RESULT([blk_alloc_disk], [
74+
AC_MSG_RESULT(yes)
75+
AC_DEFINE([HAVE_BLK_ALLOC_DISK], 1, [blk_alloc_disk() exists])
76+
], [
77+
AC_MSG_RESULT(no)
78+
])
5979
],[
6080
AC_MSG_RESULT(no)
6181

module/os/linux/zfs/zvol_os.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static struct block_device_operations zvol_ops = {
727727
.getgeo = zvol_getgeo,
728728
.owner = THIS_MODULE,
729729
#ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS
730-
.submit_bio = zvol_submit_bio,
730+
.submit_bio = zvol_submit_bio,
731731
#endif
732732
};
733733

@@ -760,13 +760,40 @@ zvol_alloc(dev_t dev, const char *name)
760760
mutex_init(&zv->zv_state_lock, NULL, MUTEX_DEFAULT, NULL);
761761

762762
#ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS
763+
#ifdef HAVE_BLK_ALLOC_DISK
764+
zso->zvo_disk = blk_alloc_disk(NUMA_NO_NODE);
765+
if (zso->zvo_disk == NULL)
766+
goto out_kmem;
767+
768+
zso->zvo_disk->minors = ZVOL_MINORS;
769+
zso->zvo_queue = zso->zvo_disk->queue;
770+
#else
763771
zso->zvo_queue = blk_alloc_queue(NUMA_NO_NODE);
772+
if (zso->zvo_queue == NULL)
773+
goto out_kmem;
774+
775+
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
776+
if (zso->zvo_disk == NULL) {
777+
blk_cleanup_queue(zso->zvo_queue);
778+
goto out_kmem;
779+
}
780+
781+
zso->zvo_disk->queue = zso->zvo_queue;
782+
#endif /* HAVE_BLK_ALLOC_DISK */
764783
#else
765784
zso->zvo_queue = blk_generic_alloc_queue(zvol_request, NUMA_NO_NODE);
766-
#endif
767785
if (zso->zvo_queue == NULL)
768786
goto out_kmem;
769787

788+
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
789+
if (zso->zvo_disk == NULL) {
790+
blk_cleanup_queue(zso->zvo_queue);
791+
goto out_kmem;
792+
}
793+
794+
zso->zvo_disk->queue = zso->zvo_queue;
795+
#endif /* HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS */
796+
770797
blk_queue_set_write_cache(zso->zvo_queue, B_TRUE, B_TRUE);
771798

772799
/* Limit read-ahead to a single page to prevent over-prefetching. */
@@ -775,10 +802,6 @@ zvol_alloc(dev_t dev, const char *name)
775802
/* Disable write merging in favor of the ZIO pipeline. */
776803
blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zso->zvo_queue);
777804

778-
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
779-
if (zso->zvo_disk == NULL)
780-
goto out_queue;
781-
782805
zso->zvo_queue->queuedata = zv;
783806
zso->zvo_dev = dev;
784807
zv->zv_open_count = 0;
@@ -809,14 +832,11 @@ zvol_alloc(dev_t dev, const char *name)
809832
zso->zvo_disk->first_minor = (dev & MINORMASK);
810833
zso->zvo_disk->fops = &zvol_ops;
811834
zso->zvo_disk->private_data = zv;
812-
zso->zvo_disk->queue = zso->zvo_queue;
813835
snprintf(zso->zvo_disk->disk_name, DISK_NAME_LEN, "%s%d",
814836
ZVOL_DEV_NAME, (dev & MINORMASK));
815837

816838
return (zv);
817839

818-
out_queue:
819-
blk_cleanup_queue(zso->zvo_queue);
820840
out_kmem:
821841
kmem_free(zso, sizeof (struct zvol_state_os));
822842
kmem_free(zv, sizeof (zvol_state_t));
@@ -847,8 +867,13 @@ zvol_free(zvol_state_t *zv)
847867
zfs_rangelock_fini(&zv->zv_rangelock);
848868

849869
del_gendisk(zv->zv_zso->zvo_disk);
870+
#if defined(HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS) && \
871+
defined(HAVE_BLK_ALLOC_DISK)
872+
blk_cleanup_disk(zv->zv_zso->zvo_disk);
873+
#else
850874
blk_cleanup_queue(zv->zv_zso->zvo_queue);
851875
put_disk(zv->zv_zso->zvo_disk);
876+
#endif
852877

853878
ida_simple_remove(&zvol_ida,
854879
MINOR(zv->zv_zso->zvo_dev) >> ZVOL_MINOR_BITS);

0 commit comments

Comments
 (0)