Skip to content

Commit 89d1d38

Browse files
committed
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 5223654 commit 89d1d38

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
@@ -762,7 +762,7 @@ static struct block_device_operations zvol_ops = {
762762
.getgeo = zvol_getgeo,
763763
.owner = THIS_MODULE,
764764
#ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS
765-
.submit_bio = zvol_submit_bio,
765+
.submit_bio = zvol_submit_bio,
766766
#endif
767767
};
768768

@@ -795,13 +795,40 @@ zvol_alloc(dev_t dev, const char *name)
795795
mutex_init(&zv->zv_state_lock, NULL, MUTEX_DEFAULT, NULL);
796796

797797
#ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS
798+
#ifdef HAVE_BLK_ALLOC_DISK
799+
zso->zvo_disk = blk_alloc_disk(NUMA_NO_NODE);
800+
if (zso->zvo_disk == NULL)
801+
goto out_kmem;
802+
803+
zso->zvo_disk->minors = ZVOL_MINORS;
804+
zso->zvo_queue = zso->zvo_disk->queue;
805+
#else
798806
zso->zvo_queue = blk_alloc_queue(NUMA_NO_NODE);
807+
if (zso->zvo_queue == NULL)
808+
goto out_kmem;
809+
810+
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
811+
if (zso->zvo_disk == NULL) {
812+
blk_cleanup_queue(zso->zvo_queue);
813+
goto out_kmem;
814+
}
815+
816+
zso->zvo_disk->queue = zso->zvo_queue;
817+
#endif /* HAVE_BLK_ALLOC_DISK */
799818
#else
800819
zso->zvo_queue = blk_generic_alloc_queue(zvol_request, NUMA_NO_NODE);
801-
#endif
802820
if (zso->zvo_queue == NULL)
803821
goto out_kmem;
804822

823+
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
824+
if (zso->zvo_disk == NULL) {
825+
blk_cleanup_queue(zso->zvo_queue);
826+
goto out_kmem;
827+
}
828+
829+
zso->zvo_disk->queue = zso->zvo_queue;
830+
#endif /* HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS */
831+
805832
blk_queue_set_write_cache(zso->zvo_queue, B_TRUE, B_TRUE);
806833

807834
/* Limit read-ahead to a single page to prevent over-prefetching. */
@@ -810,10 +837,6 @@ zvol_alloc(dev_t dev, const char *name)
810837
/* Disable write merging in favor of the ZIO pipeline. */
811838
blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zso->zvo_queue);
812839

813-
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
814-
if (zso->zvo_disk == NULL)
815-
goto out_queue;
816-
817840
zso->zvo_queue->queuedata = zv;
818841
zso->zvo_dev = dev;
819842
zv->zv_open_count = 0;
@@ -844,14 +867,11 @@ zvol_alloc(dev_t dev, const char *name)
844867
zso->zvo_disk->first_minor = (dev & MINORMASK);
845868
zso->zvo_disk->fops = &zvol_ops;
846869
zso->zvo_disk->private_data = zv;
847-
zso->zvo_disk->queue = zso->zvo_queue;
848870
snprintf(zso->zvo_disk->disk_name, DISK_NAME_LEN, "%s%d",
849871
ZVOL_DEV_NAME, (dev & MINORMASK));
850872

851873
return (zv);
852874

853-
out_queue:
854-
blk_cleanup_queue(zso->zvo_queue);
855875
out_kmem:
856876
kmem_free(zso, sizeof (struct zvol_state_os));
857877
kmem_free(zv, sizeof (zvol_state_t));
@@ -882,8 +902,13 @@ zvol_free(zvol_state_t *zv)
882902
zfs_rangelock_fini(&zv->zv_rangelock);
883903

884904
del_gendisk(zv->zv_zso->zvo_disk);
905+
#if defined(HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS) && \
906+
defined(HAVE_BLK_ALLOC_DISK)
907+
blk_cleanup_disk(zv->zv_zso->zvo_disk);
908+
#else
885909
blk_cleanup_queue(zv->zv_zso->zvo_queue);
886910
put_disk(zv->zv_zso->zvo_disk);
911+
#endif
887912

888913
ida_simple_remove(&zvol_ida,
889914
MINOR(zv->zv_zso->zvo_dev) >> ZVOL_MINOR_BITS);

0 commit comments

Comments
 (0)