Linux 5.19 compat: bdev_max_secure_erase_sectors()

Linux 5.19 commit torvalds/linux@44abff2c0 removed the
blk_queue_secure_erase() helper function.  The preferred
interface is to now use the bdev_max_secure_erase_sectors()
function to check for discard support.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #13515
This commit is contained in:
Brian Behlendorf 2022-05-27 18:20:04 +00:00
parent 9ce5eb18ef
commit 048301b6dc
3 changed files with 43 additions and 24 deletions

View File

@ -133,13 +133,20 @@ AC_DEFUN([ZFS_AC_KERNEL_BLK_QUEUE_DISCARD], [
]) ])
dnl # dnl #
dnl # 4.8 API, dnl # 5.19: bdev_max_secure_erase_sectors() available
dnl # blk_queue_secure_erase() dnl # 4.8: blk_queue_secure_erase() available
dnl # dnl # 2.6.36: blk_queue_secdiscard() available
dnl # 2.6.36 - 4.7 API,
dnl # blk_queue_secdiscard()
dnl # dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_BLK_QUEUE_SECURE_ERASE], [ AC_DEFUN([ZFS_AC_KERNEL_SRC_BLK_QUEUE_SECURE_ERASE], [
ZFS_LINUX_TEST_SRC([bdev_max_secure_erase_sectors], [
#include <linux/blkdev.h>
],[
struct block_device *bdev __attribute__ ((unused)) = NULL;
unsigned int error __attribute__ ((unused));
error = bdev_max_secure_erase_sectors(bdev);
])
ZFS_LINUX_TEST_SRC([blk_queue_secure_erase], [ ZFS_LINUX_TEST_SRC([blk_queue_secure_erase], [
#include <linux/blkdev.h> #include <linux/blkdev.h>
],[ ],[
@ -162,6 +169,14 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BLK_QUEUE_SECURE_ERASE], [
]) ])
AC_DEFUN([ZFS_AC_KERNEL_BLK_QUEUE_SECURE_ERASE], [ AC_DEFUN([ZFS_AC_KERNEL_BLK_QUEUE_SECURE_ERASE], [
AC_MSG_CHECKING([whether bdev_max_secure_erase_sectors() is available])
ZFS_LINUX_TEST_RESULT([bdev_max_secure_erase_sectors], [
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_BDEV_MAX_SECURE_ERASE_SECTORS, 1,
[bdev_max_secure_erase_sectors() is available])
],[
AC_MSG_RESULT(no)
AC_MSG_CHECKING([whether blk_queue_secure_erase() is available]) AC_MSG_CHECKING([whether blk_queue_secure_erase() is available])
ZFS_LINUX_TEST_RESULT([blk_queue_secure_erase], [ ZFS_LINUX_TEST_RESULT([blk_queue_secure_erase], [
AC_MSG_RESULT(yes) AC_MSG_RESULT(yes)
@ -179,6 +194,7 @@ AC_DEFUN([ZFS_AC_KERNEL_BLK_QUEUE_SECURE_ERASE], [
ZFS_LINUX_TEST_ERROR([blk_queue_secure_erase]) ZFS_LINUX_TEST_ERROR([blk_queue_secure_erase])
]) ])
]) ])
])
]) ])
dnl # dnl #

View File

@ -514,21 +514,26 @@ bdev_discard_supported(struct block_device *bdev)
} }
/* /*
* 5.19 API,
* bdev_max_secure_erase_sectors()
*
* 4.8 API, * 4.8 API,
* blk_queue_secure_erase() * blk_queue_secure_erase()
* *
* 2.6.36 - 4.7 API, * 2.6.36 - 4.7 API,
* blk_queue_secdiscard() * blk_queue_secdiscard()
*/ */
static inline int static inline boolean_t
blk_queue_discard_secure(struct request_queue *q) bdev_secure_discard_supported(struct block_device *bdev)
{ {
#if defined(HAVE_BLK_QUEUE_SECURE_ERASE) #if defined(HAVE_BDEV_MAX_SECURE_ERASE_SECTORS)
return (blk_queue_secure_erase(q)); return (!!bdev_max_secure_erase_sectors(bdev));
#elif defined(HAVE_BLK_QUEUE_SECURE_ERASE)
return (!!blk_queue_secure_erase(bdev_get_queue(bdev)));
#elif defined(HAVE_BLK_QUEUE_SECDISCARD) #elif defined(HAVE_BLK_QUEUE_SECDISCARD)
return (blk_queue_secdiscard(q)); return (!!blk_queue_secdiscard(bdev_get_queue(bdev)));
#else #else
return (0); #error "Unsupported kernel"
#endif #endif
} }

View File

@ -304,8 +304,6 @@ vdev_disk_open(vdev_t *v, uint64_t *psize, uint64_t *max_psize,
rw_exit(&vd->vd_lock); rw_exit(&vd->vd_lock);
} }
struct request_queue *q = bdev_get_queue(vd->vd_bdev);
/* Determine the physical block size */ /* Determine the physical block size */
int physical_block_size = bdev_physical_block_size(vd->vd_bdev); int physical_block_size = bdev_physical_block_size(vd->vd_bdev);
@ -319,10 +317,10 @@ vdev_disk_open(vdev_t *v, uint64_t *psize, uint64_t *max_psize,
v->vdev_has_trim = bdev_discard_supported(vd->vd_bdev); v->vdev_has_trim = bdev_discard_supported(vd->vd_bdev);
/* Set when device reports it supports secure TRIM. */ /* Set when device reports it supports secure TRIM. */
v->vdev_has_securetrim = !!blk_queue_discard_secure(q); v->vdev_has_securetrim = bdev_secure_discard_supported(vd->vd_bdev);
/* Inform the ZIO pipeline that we are non-rotational */ /* Inform the ZIO pipeline that we are non-rotational */
v->vdev_nonrot = blk_queue_nonrot(q); v->vdev_nonrot = blk_queue_nonrot(bdev_get_queue(vd->vd_bdev));
/* Physical volume size in bytes for the partition */ /* Physical volume size in bytes for the partition */
*psize = bdev_capacity(vd->vd_bdev); *psize = bdev_capacity(vd->vd_bdev);