Skip to content

Commit b7281c8

Browse files
committed
Linux 5.11 compat: lookup_bdev()
The lookup_bdev() function has been updated to require a dev_t be passed as the second argument. This is actually pretty nice since the major number stored in the dev_t was the only part we were interested in. This allows to us avoid handling the bdev entirely. The vdev_lookup_bdev() wrapper was updated to emulate the behavior of the new lookup_bdev() for all supported kernels. Reviewed-by: Rafael Kitover <[email protected]> Reviewed-by: Coleman Kane <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #11387 Closes #11390
1 parent c347fac commit b7281c8

File tree

3 files changed

+74
-30
lines changed

3 files changed

+74
-30
lines changed

config/kernel-blkdev.m4

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,42 +154,69 @@ AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV], [
154154
])
155155

156156
dnl #
157-
dnl # 2.6.27, lookup_bdev() was exported.
158-
dnl # 4.4.0-6.21 - lookup_bdev() takes 2 arguments.
157+
dnl # 5.11 API, lookup_bdev() takes dev_t argument.
158+
dnl # 2.6.27 API, lookup_bdev() was first exported.
159+
dnl # 4.4.0-6.21 API, lookup_bdev() on Ubuntu takes mode argument.
159160
dnl #
160161
AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV], [
162+
ZFS_LINUX_TEST_SRC([lookup_bdev_devt], [
163+
#include <linux/blkdev.h>
164+
], [
165+
int error __attribute__ ((unused));
166+
const char path[] = "/example/path";
167+
dev_t dev;
168+
169+
error = lookup_bdev(path, &dev);
170+
])
171+
161172
ZFS_LINUX_TEST_SRC([lookup_bdev_1arg], [
162173
#include <linux/fs.h>
163174
#include <linux/blkdev.h>
164175
], [
165-
lookup_bdev(NULL);
176+
struct block_device *bdev __attribute__ ((unused));
177+
const char path[] = "/example/path";
178+
179+
bdev = lookup_bdev(path);
166180
])
167181
168-
ZFS_LINUX_TEST_SRC([lookup_bdev_2args], [
182+
ZFS_LINUX_TEST_SRC([lookup_bdev_mode], [
169183
#include <linux/fs.h>
170184
], [
171-
lookup_bdev(NULL, FMODE_READ);
185+
struct block_device *bdev __attribute__ ((unused));
186+
const char path[] = "/example/path";
187+
188+
bdev = lookup_bdev(path, FMODE_READ);
172189
])
173190
])
174191

175192
AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV], [
176-
AC_MSG_CHECKING([whether lookup_bdev() wants 1 arg])
177-
ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_1arg],
193+
AC_MSG_CHECKING([whether lookup_bdev() wants dev_t arg])
194+
ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_devt],
178195
[lookup_bdev], [fs/block_dev.c], [
179196
AC_MSG_RESULT(yes)
180-
AC_DEFINE(HAVE_1ARG_LOOKUP_BDEV, 1,
181-
[lookup_bdev() wants 1 arg])
197+
AC_DEFINE(HAVE_DEVT_LOOKUP_BDEV, 1,
198+
[lookup_bdev() wants dev_t arg])
182199
], [
183200
AC_MSG_RESULT(no)
184201
185-
AC_MSG_CHECKING([whether lookup_bdev() wants 2 args])
186-
ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_2args],
202+
AC_MSG_CHECKING([whether lookup_bdev() wants 1 arg])
203+
ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_1arg],
187204
[lookup_bdev], [fs/block_dev.c], [
188205
AC_MSG_RESULT(yes)
189-
AC_DEFINE(HAVE_2ARGS_LOOKUP_BDEV, 1,
190-
[lookup_bdev() wants 2 args])
206+
AC_DEFINE(HAVE_1ARG_LOOKUP_BDEV, 1,
207+
[lookup_bdev() wants 1 arg])
191208
], [
192-
ZFS_LINUX_TEST_ERROR([lookup_bdev()])
209+
AC_MSG_RESULT(no)
210+
211+
AC_MSG_CHECKING([whether lookup_bdev() wants mode arg])
212+
ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_mode],
213+
[lookup_bdev], [fs/block_dev.c], [
214+
AC_MSG_RESULT(yes)
215+
AC_DEFINE(HAVE_MODE_LOOKUP_BDEV, 1,
216+
[lookup_bdev() wants mode arg])
217+
], [
218+
ZFS_LINUX_TEST_ERROR([lookup_bdev()])
219+
])
193220
])
194221
])
195222
])

include/os/linux/kernel/linux/blkdev_compat.h

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,38 @@ zfs_check_media_change(struct block_device *bdev)
318318
*
319319
* 4.4.0-6.21 API change for Ubuntu
320320
* lookup_bdev() gained a second argument, FMODE_*, to check inode permissions.
321+
*
322+
* 5.11 API change
323+
* Changed to take a dev_t argument which is set on success and return a
324+
* non-zero error code on failure.
321325
*/
322-
#ifdef HAVE_1ARG_LOOKUP_BDEV
323-
#define vdev_lookup_bdev(path) lookup_bdev(path)
324-
#else
325-
#ifdef HAVE_2ARGS_LOOKUP_BDEV
326-
#define vdev_lookup_bdev(path) lookup_bdev(path, 0)
326+
static inline int
327+
vdev_lookup_bdev(const char *path, dev_t *dev)
328+
{
329+
#if defined(HAVE_DEVT_LOOKUP_BDEV)
330+
return (lookup_bdev(path, dev));
331+
#elif defined(HAVE_1ARG_LOOKUP_BDEV)
332+
struct block_device *bdev = lookup_bdev(path);
333+
if (IS_ERR(bdev))
334+
return (PTR_ERR(bdev));
335+
336+
*dev = bdev->bd_dev;
337+
bdput(bdev);
338+
339+
return (0);
340+
#elif defined(HAVE_MODE_LOOKUP_BDEV)
341+
struct block_device *bdev = lookup_bdev(path, FMODE_READ);
342+
if (IS_ERR(bdev))
343+
return (PTR_ERR(bdev));
344+
345+
*dev = bdev->bd_dev;
346+
bdput(bdev);
347+
348+
return (0);
327349
#else
328350
#error "Unsupported kernel"
329-
#endif /* HAVE_2ARGS_LOOKUP_BDEV */
330-
#endif /* HAVE_1ARG_LOOKUP_BDEV */
351+
#endif
352+
}
331353

332354
/*
333355
* Kernels without bio_set_op_attrs use bi_rw for the bio flags.

module/os/linux/zfs/zvol_os.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,14 @@ typedef struct zv_request {
6666
* Given a path, return TRUE if path is a ZVOL.
6767
*/
6868
static boolean_t
69-
zvol_is_zvol_impl(const char *device)
69+
zvol_is_zvol_impl(const char *path)
7070
{
71-
struct block_device *bdev;
72-
unsigned int major;
71+
dev_t dev = 0;
7372

74-
bdev = vdev_lookup_bdev(device);
75-
if (IS_ERR(bdev))
73+
if (vdev_lookup_bdev(path, &dev) != 0)
7674
return (B_FALSE);
7775

78-
major = MAJOR(bdev->bd_dev);
79-
bdput(bdev);
80-
81-
if (major == zvol_major)
76+
if (MAJOR(dev) == zvol_major)
8277
return (B_TRUE);
8378

8479
return (B_FALSE);

0 commit comments

Comments
 (0)