Skip to content

Commit aabb7e6

Browse files
robntonyhutter
authored andcommitted
Linux 6.9 compat: bdev handles are now struct file
bdev_open_by_path() is replaced by bdev_file_open_by_path(), which returns a plain old struct file*. Release function is gone entirely; the regular file release function fput() will take care of the bdev specifics. Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes #16027 Closes #16033
1 parent 6efea26 commit aabb7e6

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

config/kernel-blkdev.m4

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_OPEN_BY_PATH], [
5454
])
5555
])
5656

57+
dnl #
58+
dnl # 6.9.x API change
59+
dnl # bdev_file_open_by_path() replaced bdev_open_by_path(),
60+
dnl # and returns struct file*
61+
dnl #
62+
AC_DEFUN([ZFS_AC_KERNEL_SRC_BDEV_FILE_OPEN_BY_PATH], [
63+
ZFS_LINUX_TEST_SRC([bdev_file_open_by_path], [
64+
#include <linux/fs.h>
65+
#include <linux/blkdev.h>
66+
], [
67+
struct file *file __attribute__ ((unused)) = NULL;
68+
const char *path = "path";
69+
fmode_t mode = 0;
70+
void *holder = NULL;
71+
struct blk_holder_ops h;
72+
73+
file = bdev_file_open_by_path(path, mode, holder, &h);
74+
])
75+
])
76+
5777
AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH], [
5878
AC_MSG_CHECKING([whether blkdev_get_by_path() exists and takes 3 args])
5979
ZFS_LINUX_TEST_RESULT([blkdev_get_by_path], [
@@ -73,7 +93,16 @@ AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH], [
7393
[bdev_open_by_path() exists])
7494
AC_MSG_RESULT(yes)
7595
], [
76-
ZFS_LINUX_TEST_ERROR([blkdev_get_by_path()])
96+
AC_MSG_RESULT(no)
97+
AC_MSG_CHECKING([whether bdev_file_open_by_path() exists])
98+
ZFS_LINUX_TEST_RESULT([bdev_file_open_by_path], [
99+
AC_DEFINE(HAVE_BDEV_FILE_OPEN_BY_PATH, 1,
100+
[bdev_file_open_by_path() exists])
101+
AC_MSG_RESULT(yes)
102+
], [
103+
AC_MSG_RESULT(no)
104+
ZFS_LINUX_TEST_ERROR([blkdev_get_by_path()])
105+
])
77106
])
78107
])
79108
])
@@ -149,10 +178,19 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_RELEASE], [
149178
])
150179
])
151180

181+
dnl #
182+
dnl # 6.9.x API change
183+
dnl #
184+
dnl # bdev_release() now private, but because bdev_file_open_by_path() returns
185+
dnl # struct file*, we can just use fput(). So the blkdev_put test no longer
186+
dnl # fails if not found.
187+
dnl #
188+
152189
AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_PUT], [
153190
AC_MSG_CHECKING([whether blkdev_put() exists])
154191
ZFS_LINUX_TEST_RESULT([blkdev_put], [
155192
AC_MSG_RESULT(yes)
193+
AC_DEFINE(HAVE_BLKDEV_PUT, 1, [blkdev_put() exists])
156194
], [
157195
AC_MSG_RESULT(no)
158196
AC_MSG_CHECKING([whether blkdev_put() accepts void* as arg 2])
@@ -168,7 +206,7 @@ AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_PUT], [
168206
AC_DEFINE(HAVE_BDEV_RELEASE, 1,
169207
[bdev_release() exists])
170208
], [
171-
ZFS_LINUX_TEST_ERROR([blkdev_put()])
209+
AC_MSG_RESULT(no)
172210
])
173211
])
174212
])
@@ -621,6 +659,7 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV], [
621659
ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH
622660
ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH_4ARG
623661
ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_OPEN_BY_PATH
662+
ZFS_AC_KERNEL_SRC_BDEV_FILE_OPEN_BY_PATH
624663
ZFS_AC_KERNEL_SRC_BLKDEV_PUT
625664
ZFS_AC_KERNEL_SRC_BLKDEV_PUT_HOLDER
626665
ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_RELEASE

module/os/linux/zfs/vdev_disk.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@
4444
/*
4545
* Linux 6.8.x uses a bdev_handle as an instance/refcount for an underlying
4646
* block_device. Since it carries the block_device inside, its convenient to
47-
* just use the handle as a proxy. For pre-6.8, we just emulate this with
48-
* a cast, since we don't need any of the other fields inside the handle.
47+
* just use the handle as a proxy.
48+
*
49+
* Linux 6.9.x uses a file for the same purpose.
50+
*
51+
* For pre-6.8, we just emulate this with a cast, since we don't need any of
52+
* the other fields inside the handle.
4953
*/
50-
#ifdef HAVE_BDEV_OPEN_BY_PATH
54+
#if defined(HAVE_BDEV_OPEN_BY_PATH)
5155
typedef struct bdev_handle zfs_bdev_handle_t;
5256
#define BDH_BDEV(bdh) ((bdh)->bdev)
5357
#define BDH_IS_ERR(bdh) (IS_ERR(bdh))
5458
#define BDH_PTR_ERR(bdh) (PTR_ERR(bdh))
5559
#define BDH_ERR_PTR(err) (ERR_PTR(err))
60+
#elif defined(HAVE_BDEV_FILE_OPEN_BY_PATH)
61+
typedef struct file zfs_bdev_handle_t;
62+
#define BDH_BDEV(bdh) (file_bdev(bdh))
63+
#define BDH_IS_ERR(bdh) (IS_ERR(bdh))
64+
#define BDH_PTR_ERR(bdh) (PTR_ERR(bdh))
65+
#define BDH_ERR_PTR(err) (ERR_PTR(err))
5666
#else
5767
typedef void zfs_bdev_handle_t;
5868
#define BDH_BDEV(bdh) ((struct block_device *)bdh)
@@ -239,7 +249,9 @@ vdev_blkdev_get_by_path(const char *path, spa_mode_t smode, void *holder)
239249
{
240250
vdev_bdev_mode_t bmode = vdev_bdev_mode(smode);
241251

242-
#if defined(HAVE_BDEV_OPEN_BY_PATH)
252+
#if defined(HAVE_BDEV_FILE_OPEN_BY_PATH)
253+
return (bdev_file_open_by_path(path, bmode, holder, NULL));
254+
#elif defined(HAVE_BDEV_OPEN_BY_PATH)
243255
return (bdev_open_by_path(path, bmode, holder, NULL));
244256
#elif defined(HAVE_BLKDEV_GET_BY_PATH_4ARG)
245257
return (blkdev_get_by_path(path, bmode, holder, NULL));
@@ -255,8 +267,10 @@ vdev_blkdev_put(zfs_bdev_handle_t *bdh, spa_mode_t smode, void *holder)
255267
return (bdev_release(bdh));
256268
#elif defined(HAVE_BLKDEV_PUT_HOLDER)
257269
return (blkdev_put(BDH_BDEV(bdh), holder));
258-
#else
270+
#elif defined(HAVE_BLKDEV_PUT)
259271
return (blkdev_put(BDH_BDEV(bdh), vdev_bdev_mode(smode)));
272+
#else
273+
fput(bdh);
260274
#endif
261275
}
262276

0 commit comments

Comments
 (0)