Linux 6.5 compat: check BLK_OPEN_EXCL is defined

On some systems we already have blkdev_get_by_path() with 4 args
but still the old FMODE_EXCL and not BLK_OPEN_EXCL defined.
The vdev_bdev_mode() function was added to handle this case
but there was no generic way to specify exclusive access.

Reviewed-by: Brian Atkinson <batkinson@lanl.gov>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #15692
(cherry picked from commit d530d5d8a5)
This commit is contained in:
Brian Behlendorf 2023-12-21 11:22:56 -08:00 committed by Tony Hutter
parent 5f465d1515
commit a9dc1166b6
1 changed files with 12 additions and 6 deletions

View File

@ -79,7 +79,7 @@ static blk_mode_t
#else #else
static fmode_t static fmode_t
#endif #endif
vdev_bdev_mode(spa_mode_t spa_mode) vdev_bdev_mode(spa_mode_t spa_mode, boolean_t exclusive)
{ {
#ifdef HAVE_BLK_MODE_T #ifdef HAVE_BLK_MODE_T
blk_mode_t mode = 0; blk_mode_t mode = 0;
@ -89,6 +89,9 @@ vdev_bdev_mode(spa_mode_t spa_mode)
if (spa_mode & SPA_MODE_WRITE) if (spa_mode & SPA_MODE_WRITE)
mode |= BLK_OPEN_WRITE; mode |= BLK_OPEN_WRITE;
if (exclusive)
mode |= BLK_OPEN_EXCL;
#else #else
fmode_t mode = 0; fmode_t mode = 0;
@ -97,6 +100,9 @@ vdev_bdev_mode(spa_mode_t spa_mode)
if (spa_mode & SPA_MODE_WRITE) if (spa_mode & SPA_MODE_WRITE)
mode |= FMODE_WRITE; mode |= FMODE_WRITE;
if (exclusive)
mode |= FMODE_EXCL;
#endif #endif
return (mode); return (mode);
@ -219,10 +225,10 @@ vdev_blkdev_get_by_path(const char *path, spa_mode_t mode, void *holder,
{ {
#ifdef HAVE_BLKDEV_GET_BY_PATH_4ARG #ifdef HAVE_BLKDEV_GET_BY_PATH_4ARG
return (blkdev_get_by_path(path, return (blkdev_get_by_path(path,
vdev_bdev_mode(mode) | BLK_OPEN_EXCL, holder, hops)); vdev_bdev_mode(mode, B_TRUE), holder, hops));
#else #else
return (blkdev_get_by_path(path, return (blkdev_get_by_path(path,
vdev_bdev_mode(mode) | FMODE_EXCL, holder)); vdev_bdev_mode(mode, B_TRUE), holder));
#endif #endif
} }
@ -232,7 +238,7 @@ vdev_blkdev_put(struct block_device *bdev, spa_mode_t mode, void *holder)
#ifdef HAVE_BLKDEV_PUT_HOLDER #ifdef HAVE_BLKDEV_PUT_HOLDER
return (blkdev_put(bdev, holder)); return (blkdev_put(bdev, holder));
#else #else
return (blkdev_put(bdev, vdev_bdev_mode(mode) | FMODE_EXCL)); return (blkdev_put(bdev, vdev_bdev_mode(mode, B_TRUE)));
#endif #endif
} }
@ -242,9 +248,9 @@ vdev_disk_open(vdev_t *v, uint64_t *psize, uint64_t *max_psize,
{ {
struct block_device *bdev; struct block_device *bdev;
#ifdef HAVE_BLK_MODE_T #ifdef HAVE_BLK_MODE_T
blk_mode_t mode = vdev_bdev_mode(spa_mode(v->vdev_spa)); blk_mode_t mode = vdev_bdev_mode(spa_mode(v->vdev_spa), B_FALSE);
#else #else
fmode_t mode = vdev_bdev_mode(spa_mode(v->vdev_spa)); fmode_t mode = vdev_bdev_mode(spa_mode(v->vdev_spa), B_FALSE);
#endif #endif
hrtime_t timeout = MSEC2NSEC(zfs_vdev_open_timeout_ms); hrtime_t timeout = MSEC2NSEC(zfs_vdev_open_timeout_ms);
vdev_disk_t *vd; vdev_disk_t *vd;