]>
Commit | Line | Data |
---|---|---|
bed78fc0 JR |
1 | From 1b06b03a7be88f4565c2c3114b8d3f2dc9f9408a Mon Sep 17 00:00:00 2001 |
2 | From: Brian Behlendorf <behlendorf1@llnl.gov> | |
3 | Date: Fri, 23 Jul 2021 15:28:03 -0700 | |
4 | Subject: [PATCH] Linux 5.14 compat: blk_alloc_disk() | |
5 | ||
6 | In Linux 5.14, blk_alloc_queue is no longer exported, and its usage | |
7 | has been superseded by blk_alloc_disk, which returns a gendisk struct | |
8 | from which we can still retrieve the struct request_queue* that is | |
9 | needed in the one place where it is used. This also replaces the call | |
10 | to alloc_disk(minors), and minors is now set via struct member | |
11 | assignment. | |
12 | ||
13 | Reviewed-by: Tony Nguyen <tony.nguyen@delphix.com> | |
14 | Reviewed-by: Olaf Faaland <faaland1@llnl.gov> | |
15 | Reviewed-by: Coleman Kane <ckane@colemankane.org> | |
16 | Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> | |
17 | Closes #12362 | |
18 | Closes #12409 | |
19 | --- | |
20 | config/kernel-make-request-fn.m4 | 20 +++++++++++++++ | |
21 | module/os/linux/zfs/zvol_os.c | 43 +++++++++++++++++++++++++------- | |
22 | 2 files changed, 54 insertions(+), 9 deletions(-) | |
23 | ||
24 | diff --git a/config/kernel-make-request-fn.m4 b/config/kernel-make-request-fn.m4 | |
25 | index 290ef6b8da7..86b202a7a27 100644 | |
26 | --- a/config/kernel-make-request-fn.m4 | |
27 | +++ b/config/kernel-make-request-fn.m4 | |
28 | @@ -42,6 +42,13 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN], [ | |
29 | struct block_device_operations o; | |
30 | o.submit_bio = NULL; | |
31 | ]) | |
32 | + | |
33 | + ZFS_LINUX_TEST_SRC([blk_alloc_disk], [ | |
34 | + #include <linux/blkdev.h> | |
35 | + ],[ | |
36 | + struct gendisk *disk __attribute__ ((unused)); | |
37 | + disk = blk_alloc_disk(NUMA_NO_NODE); | |
38 | + ]) | |
39 | ]) | |
40 | ||
41 | AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [ | |
42 | @@ -56,6 +63,19 @@ AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [ | |
43 | ||
44 | AC_DEFINE(HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS, 1, | |
45 | [submit_bio is member of struct block_device_operations]) | |
46 | + | |
47 | + dnl # | |
48 | + dnl # Linux 5.14 API Change: | |
49 | + dnl # blk_alloc_queue() + alloc_disk() combo replaced by | |
50 | + dnl # a single call to blk_alloc_disk(). | |
51 | + dnl # | |
52 | + AC_MSG_CHECKING([whether blk_alloc_disk() exists]) | |
53 | + ZFS_LINUX_TEST_RESULT([blk_alloc_disk], [ | |
54 | + AC_MSG_RESULT(yes) | |
55 | + AC_DEFINE([HAVE_BLK_ALLOC_DISK], 1, [blk_alloc_disk() exists]) | |
56 | + ], [ | |
57 | + AC_MSG_RESULT(no) | |
58 | + ]) | |
59 | ],[ | |
60 | AC_MSG_RESULT(no) | |
61 | ||
62 | diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c | |
63 | index 741979f11af..8b29d73a3e0 100644 | |
64 | --- a/module/os/linux/zfs/zvol_os.c | |
65 | +++ b/module/os/linux/zfs/zvol_os.c | |
66 | @@ -762,7 +762,7 @@ static struct block_device_operations zvol_ops = { | |
67 | .getgeo = zvol_getgeo, | |
68 | .owner = THIS_MODULE, | |
69 | #ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS | |
70 | - .submit_bio = zvol_submit_bio, | |
71 | + .submit_bio = zvol_submit_bio, | |
72 | #endif | |
73 | }; | |
74 | ||
75 | @@ -795,13 +795,40 @@ zvol_alloc(dev_t dev, const char *name) | |
76 | mutex_init(&zv->zv_state_lock, NULL, MUTEX_DEFAULT, NULL); | |
77 | ||
78 | #ifdef HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS | |
79 | +#ifdef HAVE_BLK_ALLOC_DISK | |
80 | + zso->zvo_disk = blk_alloc_disk(NUMA_NO_NODE); | |
81 | + if (zso->zvo_disk == NULL) | |
82 | + goto out_kmem; | |
83 | + | |
84 | + zso->zvo_disk->minors = ZVOL_MINORS; | |
85 | + zso->zvo_queue = zso->zvo_disk->queue; | |
86 | +#else | |
87 | zso->zvo_queue = blk_alloc_queue(NUMA_NO_NODE); | |
88 | + if (zso->zvo_queue == NULL) | |
89 | + goto out_kmem; | |
90 | + | |
91 | + zso->zvo_disk = alloc_disk(ZVOL_MINORS); | |
92 | + if (zso->zvo_disk == NULL) { | |
93 | + blk_cleanup_queue(zso->zvo_queue); | |
94 | + goto out_kmem; | |
95 | + } | |
96 | + | |
97 | + zso->zvo_disk->queue = zso->zvo_queue; | |
98 | +#endif /* HAVE_BLK_ALLOC_DISK */ | |
99 | #else | |
100 | zso->zvo_queue = blk_generic_alloc_queue(zvol_request, NUMA_NO_NODE); | |
101 | -#endif | |
102 | if (zso->zvo_queue == NULL) | |
103 | goto out_kmem; | |
104 | ||
105 | + zso->zvo_disk = alloc_disk(ZVOL_MINORS); | |
106 | + if (zso->zvo_disk == NULL) { | |
107 | + blk_cleanup_queue(zso->zvo_queue); | |
108 | + goto out_kmem; | |
109 | + } | |
110 | + | |
111 | + zso->zvo_disk->queue = zso->zvo_queue; | |
112 | +#endif /* HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS */ | |
113 | + | |
114 | blk_queue_set_write_cache(zso->zvo_queue, B_TRUE, B_TRUE); | |
115 | ||
116 | /* Limit read-ahead to a single page to prevent over-prefetching. */ | |
117 | @@ -810,10 +837,6 @@ zvol_alloc(dev_t dev, const char *name) | |
118 | /* Disable write merging in favor of the ZIO pipeline. */ | |
119 | blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zso->zvo_queue); | |
120 | ||
121 | - zso->zvo_disk = alloc_disk(ZVOL_MINORS); | |
122 | - if (zso->zvo_disk == NULL) | |
123 | - goto out_queue; | |
124 | - | |
125 | zso->zvo_queue->queuedata = zv; | |
126 | zso->zvo_dev = dev; | |
127 | zv->zv_open_count = 0; | |
128 | @@ -844,14 +867,11 @@ zvol_alloc(dev_t dev, const char *name) | |
129 | zso->zvo_disk->first_minor = (dev & MINORMASK); | |
130 | zso->zvo_disk->fops = &zvol_ops; | |
131 | zso->zvo_disk->private_data = zv; | |
132 | - zso->zvo_disk->queue = zso->zvo_queue; | |
133 | snprintf(zso->zvo_disk->disk_name, DISK_NAME_LEN, "%s%d", | |
134 | ZVOL_DEV_NAME, (dev & MINORMASK)); | |
135 | ||
136 | return (zv); | |
137 | ||
138 | -out_queue: | |
139 | - blk_cleanup_queue(zso->zvo_queue); | |
140 | out_kmem: | |
141 | kmem_free(zso, sizeof (struct zvol_state_os)); | |
142 | kmem_free(zv, sizeof (zvol_state_t)); | |
143 | @@ -882,8 +902,13 @@ zvol_free(zvol_state_t *zv) | |
144 | zfs_rangelock_fini(&zv->zv_rangelock); | |
145 | ||
146 | del_gendisk(zv->zv_zso->zvo_disk); | |
147 | +#if defined(HAVE_SUBMIT_BIO_IN_BLOCK_DEVICE_OPERATIONS) && \ | |
148 | + defined(HAVE_BLK_ALLOC_DISK) | |
149 | + blk_cleanup_disk(zv->zv_zso->zvo_disk); | |
150 | +#else | |
151 | blk_cleanup_queue(zv->zv_zso->zvo_queue); | |
152 | put_disk(zv->zv_zso->zvo_disk); | |
153 | +#endif | |
154 | ||
155 | ida_simple_remove(&zvol_ida, | |
156 | MINOR(zv->zv_zso->zvo_dev) >> ZVOL_MINOR_BITS); |