Skip to content

Commit 5722dce

Browse files
ckanetonyhutter
authored andcommitted
Linux 5.12 update: bio_max_segs() replaces BIO_MAX_PAGES
The BIO_MAX_PAGES macro is being retired in favor of a bio_max_segs() function that implements the typical MIN(x,y) logic used throughout the kernel for bounding the allocation, and also the new implementation is intended to be signed-safe (which the former was not). Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Coleman Kane <[email protected]> Closes #11765 (cherry picked from commit ffd6978) Signed-off-by: Jonathon Fernyhough <[email protected]>
1 parent 91d5ac8 commit 5722dce

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

config/kernel-bio_max_segs.m4

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
dnl #
2+
dnl # 5.12 API change removes BIO_MAX_PAGES in favor of bio_max_segs()
3+
dnl # which will handle the logic of setting the upper-bound to a
4+
dnl # BIO_MAX_PAGES, internally.
5+
dnl #
6+
AC_DEFUN([ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS], [
7+
ZFS_LINUX_TEST_SRC([bio_max_segs], [
8+
#include <linux/bio.h>
9+
],[
10+
bio_max_segs(1);
11+
])
12+
])
13+
14+
AC_DEFUN([ZFS_AC_KERNEL_BIO_MAX_SEGS], [
15+
AC_MSG_CHECKING([whether bio_max_segs() exists])
16+
ZFS_LINUX_TEST_RESULT([bio_max_segs], [
17+
AC_MSG_RESULT(yes)
18+
19+
AC_DEFINE([HAVE_BIO_MAX_SEGS], 1, [bio_max_segs() is implemented])
20+
],[
21+
AC_MSG_RESULT(no)
22+
])
23+
])

config/kernel.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [
127127
ZFS_AC_KERNEL_SRC_GENERIC_FILLATTR_USERNS
128128
ZFS_AC_KERNEL_SRC_MKNOD
129129
ZFS_AC_KERNEL_SRC_SYMLINK
130+
ZFS_AC_KERNEL_SRC_BIO_MAX_SEGS
130131
131132
AC_MSG_CHECKING([for available kernel interfaces])
132133
ZFS_LINUX_TEST_COMPILE_ALL([kabi])
@@ -227,6 +228,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [
227228
ZFS_AC_KERNEL_GENERIC_FILLATTR_USERNS
228229
ZFS_AC_KERNEL_MKNOD
229230
ZFS_AC_KERNEL_SYMLINK
231+
ZFS_AC_KERNEL_BIO_MAX_SEGS
230232
])
231233

232234
dnl #

module/os/linux/zfs/vdev_disk.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,14 @@ __vdev_disk_physio(struct block_device *bdev, zio_t *zio,
593593
}
594594

595595
/* bio_alloc() with __GFP_WAIT never returns NULL */
596+
#ifdef HAVE_BIO_MAX_SEGS
597+
dr->dr_bio[i] = bio_alloc(GFP_NOIO, bio_max_segs(
598+
abd_nr_pages_off(zio->io_abd, bio_size, abd_offset)));
599+
#else
596600
dr->dr_bio[i] = bio_alloc(GFP_NOIO,
597601
MIN(abd_nr_pages_off(zio->io_abd, bio_size, abd_offset),
598602
BIO_MAX_PAGES));
603+
#endif
599604
if (unlikely(dr->dr_bio[i] == NULL)) {
600605
vdev_disk_dio_free(dr);
601606
return (SET_ERROR(ENOMEM));

0 commit comments

Comments
 (0)