From 8a6aee1e1e1bffd41af691311895d9ca938daefe Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 19 Apr 2022 10:38:04 -0700 Subject: [PATCH] Linux 5.17 compat: GENHD_FL_EXT_DEVT / GENHD_FL_NO_PART_SCAN As of the 5.17 kernel the GENHD_FL_EXT_DEVT flag has been removed and the GENHD_FL_NO_PART_SCAN flag renamed GENHD_FL_NO_PART. Update zvol_alloc() to set GENHD_FL_NO_PART for the newer kernels which is sufficient. The behavior for prior kernels remains unchanged. 1ebe2e5f ("block: remove GENHD_FL_EXT_DEVT") 46e7eac6 ("block: rename GENHD_FL_NO_PART_SCAN to GENHD_FL_NO_PART") Reviewed-by: Tony Hutter Signed-off-by: Brian Behlendorf Closes #13294 Closes #13297 --- config/kernel-genhd-flags.m4 | 58 +++++++++++++++++++++++++++++++++++ config/kernel.m4 | 2 ++ module/os/linux/zfs/zvol_os.c | 21 +++++-------- 3 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 config/kernel-genhd-flags.m4 diff --git a/config/kernel-genhd-flags.m4 b/config/kernel-genhd-flags.m4 new file mode 100644 index 000000000000..af6a8a086bc9 --- /dev/null +++ b/config/kernel-genhd-flags.m4 @@ -0,0 +1,58 @@ +dnl # +dnl # 5.17 API change, +dnl # +dnl # GENHD_FL_EXT_DEVT flag removed +dnl # GENHD_FL_NO_PART_SCAN renamed GENHD_FL_NO_PART +dnl # +AC_DEFUN([ZFS_AC_KERNEL_SRC_GENHD_FLAGS], [ + + ZFS_LINUX_TEST_SRC([genhd_fl_ext_devt], [ + #include + ], [ + int flags __attribute__ ((unused)) = GENHD_FL_EXT_DEVT; + ]) + + ZFS_LINUX_TEST_SRC([genhd_fl_no_part], [ + #include + ], [ + int flags __attribute__ ((unused)) = GENHD_FL_NO_PART; + ]) + + ZFS_LINUX_TEST_SRC([genhd_fl_no_part_scan], [ + #include + ], [ + int flags __attribute__ ((unused)) = GENHD_FL_NO_PART_SCAN; + ]) +]) + +AC_DEFUN([ZFS_AC_KERNEL_GENHD_FLAGS], [ + + AC_MSG_CHECKING([whether GENHD_FL_EXT_DEVT flag is available]) + ZFS_LINUX_TEST_RESULT([genhd_fl_ext_devt], [ + AC_MSG_RESULT(yes) + AC_DEFINE(ZFS_GENHD_FL_EXT_DEVT, GENHD_FL_EXT_DEVT, + [GENHD_FL_EXT_DEVT flag is available]) + ], [ + AC_MSG_RESULT(no) + AC_DEFINE(ZFS_GENHD_FL_EXT_DEVT, 0, + [GENHD_FL_EXT_DEVT flag is not available]) + ]) + + AC_MSG_CHECKING([whether GENHD_FL_NO_PART flag is available]) + ZFS_LINUX_TEST_RESULT([genhd_fl_no_part], [ + AC_MSG_RESULT(yes) + AC_DEFINE(ZFS_GENHD_FL_NO_PART, GENHD_FL_NO_PART, + [GENHD_FL_NO_PART flag is available]) + ], [ + AC_MSG_RESULT(no) + + AC_MSG_CHECKING([whether GENHD_FL_NO_PART_SCAN flag is available]) + ZFS_LINUX_TEST_RESULT([genhd_fl_no_part_scan], [ + AC_MSG_RESULT(yes) + AC_DEFINE(ZFS_GENHD_FL_NO_PART, GENHD_FL_NO_PART_SCAN, + [GENHD_FL_NO_PART_SCAN flag is available]) + ], [ + ZFS_LINUX_TEST_ERROR([GENHD_FL_NO_PART|GENHD_FL_NO_PART_SCAN]) + ]) + ]) +]) diff --git a/config/kernel.m4 b/config/kernel.m4 index 3b6f93f6b023..771dc21787d4 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -61,6 +61,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_SRC], [ ZFS_AC_KERNEL_SRC_BIO ZFS_AC_KERNEL_SRC_BLKDEV ZFS_AC_KERNEL_SRC_BLK_QUEUE + ZFS_AC_KERNEL_SRC_GENHD_FLAGS ZFS_AC_KERNEL_SRC_REVALIDATE_DISK ZFS_AC_KERNEL_SRC_GET_DISK_RO ZFS_AC_KERNEL_SRC_GENERIC_READLINK_GLOBAL @@ -174,6 +175,7 @@ AC_DEFUN([ZFS_AC_KERNEL_TEST_RESULT], [ ZFS_AC_KERNEL_BIO ZFS_AC_KERNEL_BLKDEV ZFS_AC_KERNEL_BLK_QUEUE + ZFS_AC_KERNEL_GENHD_FLAGS ZFS_AC_KERNEL_REVALIDATE_DISK ZFS_AC_KERNEL_GET_DISK_RO ZFS_AC_KERNEL_GENERIC_READLINK_GLOBAL diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c index d30f01f4b0e2..4ebdf8331695 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -906,22 +906,17 @@ zvol_alloc(dev_t dev, const char *name) zso->zvo_disk->major = zvol_major; zso->zvo_disk->events = DISK_EVENT_MEDIA_CHANGE; + /* + * Setting ZFS_VOLMODE_DEV disables partitioning on ZVOL devices. + * This is accomplished by limiting the number of minors for the + * device to one and explicitly disabling partition scanning. + */ if (volmode == ZFS_VOLMODE_DEV) { - /* - * ZFS_VOLMODE_DEV disable partitioning on ZVOL devices: set - * gendisk->minors = 1 as noted in include/linux/blkdev.h. - * Also disable extended partition numbers (GENHD_FL_EXT_DEVT) - * and suppresses partition scanning (GENHD_FL_NO_PART_SCAN) - * setting gendisk->flags accordingly. - */ zso->zvo_disk->minors = 1; -#if defined(GENHD_FL_EXT_DEVT) - zso->zvo_disk->flags &= ~GENHD_FL_EXT_DEVT; -#endif -#if defined(GENHD_FL_NO_PART_SCAN) - zso->zvo_disk->flags |= GENHD_FL_NO_PART_SCAN; -#endif + zso->zvo_disk->flags &= ~ZFS_GENHD_FL_EXT_DEVT; + zso->zvo_disk->flags |= ZFS_GENHD_FL_NO_PART; } + zso->zvo_disk->first_minor = (dev & MINORMASK); zso->zvo_disk->fops = &zvol_ops; zso->zvo_disk->private_data = zv;