Skip to content

Commit 2c18481

Browse files
behlendorftonyhutter
authored andcommitted
Linux 5.7 compat: blk_alloc_queue()
Commit torvalds/linux@3d745ea5 simplified the blk_alloc_queue() interface by updating it to take the request queue as an argument. Add a wrapper function which accepts the new arguments and internally uses the available interfaces. Other minor changes include increasing the Linux-Maximum to 5.6 now that 5.6 has been released. It was not bumped to 5.7 because this release has not yet been finalized and is still subject to change. Added local 'struct zvol_state_os *zso' variable to zvol_alloc. Reviewed-by: George Melikov <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #10181 Closes #10187
1 parent 85e11c9 commit 2c18481

File tree

4 files changed

+67
-33
lines changed

4 files changed

+67
-33
lines changed

META

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Release: 1
66
Release-Tags: relext
77
License: CDDL
88
Author: OpenZFS on Linux
9-
Linux-Maximum: 5.4
9+
Linux-Maximum: 5.6
1010
Linux-Minimum: 2.6.32

config/kernel-make-request-fn.m4

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,34 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_MAKE_REQUEST_FN], [
2525
],[
2626
blk_queue_make_request(NULL, &make_request);
2727
])
28+
ZFS_LINUX_TEST_SRC([blk_alloc_queue_request_fn], [
29+
#include <linux/blkdev.h>
30+
blk_qc_t make_request(struct request_queue *q,
31+
struct bio *bio) { return (BLK_QC_T_NONE); }
32+
],[
33+
struct request_queue *q __attribute__ ((unused));
34+
q = blk_alloc_queue(make_request, NUMA_NO_NODE);
35+
])
2836
])
2937

3038
AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [
3139
dnl #
32-
dnl # Legacy API
33-
dnl # make_request_fn returns int.
40+
dnl # Linux 5.7 API Change
41+
dnl # blk_alloc_queue() expects request function.
3442
dnl #
35-
AC_MSG_CHECKING([whether make_request_fn() returns int])
36-
ZFS_LINUX_TEST_RESULT([make_request_fn_int], [
43+
AC_MSG_CHECKING([whether blk_alloc_queue() expects request function])
44+
ZFS_LINUX_TEST_RESULT([blk_alloc_queue_request_fn], [
45+
AC_MSG_RESULT(yes)
46+
dnl # Checked as part of the blk_alloc_queue_request_fn test
47+
AC_MSG_CHECKING([whether make_request_fn() returns blk_qc_t])
3748
AC_MSG_RESULT(yes)
38-
AC_DEFINE(MAKE_REQUEST_FN_RET, int,
49+
AC_DEFINE(HAVE_BLK_ALLOC_QUEUE_REQUEST_FN, 1,
50+
[blk_alloc_queue() expects request function])
51+
AC_DEFINE(MAKE_REQUEST_FN_RET, blk_qc_t,
3952
[make_request_fn() return type])
40-
AC_DEFINE(HAVE_MAKE_REQUEST_FN_RET_INT, 1,
41-
[Noting that make_request_fn() returns int])
53+
AC_DEFINE(HAVE_MAKE_REQUEST_FN_RET_QC, 1,
54+
[Noting that make_request_fn() returns blk_qc_t])
4255
],[
43-
AC_MSG_RESULT(no)
44-
4556
dnl #
4657
dnl # Linux 3.2 API Change
4758
dnl # make_request_fn returns void.
@@ -55,7 +66,6 @@ AC_DEFUN([ZFS_AC_KERNEL_MAKE_REQUEST_FN], [
5566
[Noting that make_request_fn() returns void])
5667
],[
5768
AC_MSG_RESULT(no)
58-
5969
dnl #
6070
dnl # Linux 4.4 API Change
6171
dnl # make_request_fn returns blk_qc_t.

include/linux/blkdev_compat.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,4 +669,18 @@ blk_generic_end_io_acct(struct request_queue *q, int rw,
669669
#endif
670670
}
671671

672+
static inline struct request_queue *
673+
blk_generic_alloc_queue(make_request_fn make_request, int node_id)
674+
{
675+
#if defined(HAVE_BLK_ALLOC_QUEUE_REQUEST_FN)
676+
return (blk_alloc_queue(make_request, node_id));
677+
#else
678+
struct request_queue *q = blk_alloc_queue(GFP_KERNEL);
679+
if (q != NULL)
680+
blk_queue_make_request(q, make_request);
681+
682+
return (q);
683+
#endif
684+
}
685+
672686
#endif /* _ZFS_BLKDEV_H */

module/zfs/zvol.c

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ static struct ida zvol_ida;
113113
/*
114114
* The in-core state of each volume.
115115
*/
116+
struct zvol_state_os {
117+
struct gendisk *zvo_disk; /* generic disk */
118+
struct request_queue *zvo_queue; /* request queue */
119+
dataset_kstats_t zvo_kstat; /* zvol kstats */
120+
dev_t zvo_dev; /* device id */
121+
};
122+
116123
struct zvol_state {
117124
char zv_name[MAXNAMELEN]; /* name */
118125
uint64_t zv_volsize; /* advertised space */
@@ -134,6 +141,7 @@ struct zvol_state {
134141
kmutex_t zv_state_lock; /* protects zvol_state_t */
135142
atomic_t zv_suspend_ref; /* refcount for suspend */
136143
krwlock_t zv_suspend_lock; /* suspend lock */
144+
struct zvol_state_os *zv_zso; /* private platform state */
137145
};
138146

139147
typedef enum {
@@ -1686,6 +1694,7 @@ static zvol_state_t *
16861694
zvol_alloc(dev_t dev, const char *name)
16871695
{
16881696
zvol_state_t *zv;
1697+
struct zvol_state_os *zso;
16891698
uint64_t volmode;
16901699

16911700
if (dsl_prop_get_integer(name, "volmode", &volmode, NULL) != 0)
@@ -1698,39 +1707,39 @@ zvol_alloc(dev_t dev, const char *name)
16981707
return (NULL);
16991708

17001709
zv = kmem_zalloc(sizeof (zvol_state_t), KM_SLEEP);
1710+
zso = kmem_zalloc(sizeof (struct zvol_state_os), KM_SLEEP);
1711+
zv->zv_zso = zso;
17011712

17021713
list_link_init(&zv->zv_next);
1703-
17041714
mutex_init(&zv->zv_state_lock, NULL, MUTEX_DEFAULT, NULL);
17051715

1706-
zv->zv_queue = blk_alloc_queue(GFP_ATOMIC);
1707-
if (zv->zv_queue == NULL)
1716+
zso->zvo_queue = blk_generic_alloc_queue(zvol_request, NUMA_NO_NODE);
1717+
if (zso->zvo_queue == NULL)
17081718
goto out_kmem;
17091719

1710-
blk_queue_make_request(zv->zv_queue, zvol_request);
1711-
blk_queue_set_write_cache(zv->zv_queue, B_TRUE, B_TRUE);
1720+
blk_queue_set_write_cache(zso->zvo_queue, B_TRUE, B_TRUE);
17121721

17131722
/* Limit read-ahead to a single page to prevent over-prefetching. */
1714-
blk_queue_set_read_ahead(zv->zv_queue, 1);
1723+
blk_queue_set_read_ahead(zso->zvo_queue, 1);
17151724

17161725
/* Disable write merging in favor of the ZIO pipeline. */
1717-
blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zv->zv_queue);
1726+
blk_queue_flag_set(QUEUE_FLAG_NOMERGES, zso->zvo_queue);
17181727

1719-
zv->zv_disk = alloc_disk(ZVOL_MINORS);
1720-
if (zv->zv_disk == NULL)
1728+
zso->zvo_disk = alloc_disk(ZVOL_MINORS);
1729+
if (zso->zvo_disk == NULL)
17211730
goto out_queue;
17221731

1723-
zv->zv_queue->queuedata = zv;
1724-
zv->zv_dev = dev;
1732+
zso->zvo_queue->queuedata = zv;
1733+
zso->zvo_dev = dev;
17251734
zv->zv_open_count = 0;
17261735
strlcpy(zv->zv_name, name, MAXNAMELEN);
17271736

17281737
zfs_rangelock_init(&zv->zv_rangelock, NULL, NULL);
17291738
rw_init(&zv->zv_suspend_lock, NULL, RW_DEFAULT, NULL);
17301739

1731-
zv->zv_disk->major = zvol_major;
1740+
zso->zvo_disk->major = zvol_major;
17321741
#ifdef HAVE_BLOCK_DEVICE_OPERATIONS_CHECK_EVENTS
1733-
zv->zv_disk->events = DISK_EVENT_MEDIA_CHANGE;
1742+
zso->zvo_disk->events = DISK_EVENT_MEDIA_CHANGE;
17341743
#endif
17351744

17361745
if (volmode == ZFS_VOLMODE_DEV) {
@@ -1741,26 +1750,27 @@ zvol_alloc(dev_t dev, const char *name)
17411750
* and suppresses partition scanning (GENHD_FL_NO_PART_SCAN)
17421751
* setting gendisk->flags accordingly.
17431752
*/
1744-
zv->zv_disk->minors = 1;
1753+
zso->zvo_disk->minors = 1;
17451754
#if defined(GENHD_FL_EXT_DEVT)
1746-
zv->zv_disk->flags &= ~GENHD_FL_EXT_DEVT;
1755+
zso->zvo_disk->flags &= ~GENHD_FL_EXT_DEVT;
17471756
#endif
17481757
#if defined(GENHD_FL_NO_PART_SCAN)
1749-
zv->zv_disk->flags |= GENHD_FL_NO_PART_SCAN;
1758+
zso->zvo_disk->flags |= GENHD_FL_NO_PART_SCAN;
17501759
#endif
17511760
}
1752-
zv->zv_disk->first_minor = (dev & MINORMASK);
1753-
zv->zv_disk->fops = &zvol_ops;
1754-
zv->zv_disk->private_data = zv;
1755-
zv->zv_disk->queue = zv->zv_queue;
1756-
snprintf(zv->zv_disk->disk_name, DISK_NAME_LEN, "%s%d",
1761+
zso->zvo_disk->first_minor = (dev & MINORMASK);
1762+
zso->zvo_disk->fops = &zvol_ops;
1763+
zso->zvo_disk->private_data = zv;
1764+
zso->zvo_disk->queue = zso->zvo_queue;
1765+
snprintf(zso->zvo_disk->disk_name, DISK_NAME_LEN, "%s%d",
17571766
ZVOL_DEV_NAME, (dev & MINORMASK));
17581767

17591768
return (zv);
17601769

17611770
out_queue:
1762-
blk_cleanup_queue(zv->zv_queue);
1771+
blk_cleanup_queue(zso->zvo_queue);
17631772
out_kmem:
1773+
kmem_free(zso, sizeof (struct zvol_state_os));
17641774
kmem_free(zv, sizeof (zvol_state_t));
17651775

17661776
return (NULL);

0 commit comments

Comments
 (0)