Linux 6.18: block_device_operations->getgeo takes struct gendisk*

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
This commit is contained in:
Rob Norris 2025-09-12 10:23:28 +10:00 committed by Brian Behlendorf
parent 51ab0e2185
commit c1f1464525
2 changed files with 52 additions and 3 deletions

View File

@ -119,15 +119,49 @@ AC_DEFUN([ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_REVALIDATE_DISK], [
])
])
dnl #
dnl # 6.18 API change
dnl # block_device_operation->getgeo takes struct gendisk* as first arg
dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK], [
ZFS_LINUX_TEST_SRC([block_device_operations_getgeo_gendisk], [
#include <linux/blkdev.h>
static int blk_getgeo(struct gendisk *disk, struct hd_geometry *geo)
{
(void) disk, (void) geo;
return (0);
}
static const struct block_device_operations
bops __attribute__ ((unused)) = {
.getgeo = blk_getgeo,
};
], [], [])
])
AC_DEFUN([ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK], [
AC_MSG_CHECKING([whether bops->getgeo() takes gendisk as first arg])
ZFS_LINUX_TEST_RESULT([block_device_operations_getgeo_gendisk], [
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK], [1],
[Define if getgeo() in block_device_operations takes struct gendisk * as its first arg])
],[
AC_MSG_RESULT(no)
])
])
AC_DEFUN([ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS], [
ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_CHECK_EVENTS
ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_RELEASE_1ARG
ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_REVALIDATE_DISK
ZFS_AC_KERNEL_SRC_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK
])
AC_DEFUN([ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS], [
ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_CHECK_EVENTS
ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_RELEASE_VOID
ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_REVALIDATE_DISK
ZFS_AC_KERNEL_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK
])

View File

@ -1066,12 +1066,13 @@ zvol_os_clear_private(zvol_state_t *zv)
* tiny devices. For devices over 1 Mib a standard head and sector count
* is used to keep the cylinders count reasonable.
*/
static int
zvol_getgeo(struct block_device *bdev, struct hd_geometry *geo)
static inline int
zvol_getgeo_impl(struct gendisk *disk, struct hd_geometry *geo)
{
zvol_state_t *zv = bdev->bd_disk->private_data;
zvol_state_t *zv = disk->private_data;
sector_t sectors;
ASSERT3P(zv, !=, NULL);
ASSERT3U(zv->zv_open_count, >, 0);
sectors = get_capacity(zv->zv_zso->zvo_disk);
@ -1090,6 +1091,20 @@ zvol_getgeo(struct block_device *bdev, struct hd_geometry *geo)
return (0);
}
#ifdef HAVE_BLOCK_DEVICE_OPERATIONS_GETGEO_GENDISK
static int
zvol_getgeo(struct gendisk *disk, struct hd_geometry *geo)
{
return (zvol_getgeo_impl(disk, geo));
}
#else
static int
zvol_getgeo(struct block_device *bdev, struct hd_geometry *geo)
{
return (zvol_getgeo_impl(bdev->bd_disk, geo));
}
#endif
/*
* Why have two separate block_device_operations structs?
*