Skip to content

Commit

Permalink
Add blk_mode_is_open_write() to test FMODE_WRITE / BLK_OPEN_WRITE
Browse files Browse the repository at this point in the history
The wrapper function is now used for testing using the appropriate
method for the kernel, whether the open mode is writeable or not.

Signed-off-by: Coleman Kane <[email protected]>
  • Loading branch information
ckane committed Jul 30, 2023
1 parent 40e11da commit 5379a40
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 6 additions & 0 deletions include/os/linux/kernel/linux/blkdev_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ vdev_lookup_bdev(const char *path, dev_t *dev)
#endif
}

#if defined(HAVE_BLK_MODE_T)
#define blk_mode_is_open_write(flag) ((flag) & BLK_OPEN_WRITE)
#else
#define blk_mode_is_open_write(flag) ((flag) & FMODE_WRITE)
#endif

/*
* Kernels without bio_set_op_attrs use bi_rw for the bio flags.
*/
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ zfs_open(struct inode *ip, int mode, int flag, cred_t *cr)
return (error);

/* Honor ZFS_APPENDONLY file attribute */
if ((mode & FMODE_WRITE) && (zp->z_pflags & ZFS_APPENDONLY) &&
if (blk_mode_is_open_write(mode) && (zp->z_pflags & ZFS_APPENDONLY) &&
((flag & O_APPEND) == 0)) {
zfs_exit(zfsvfs, FTAG);
return (SET_ERROR(EPERM));
Expand Down
2 changes: 1 addition & 1 deletion module/os/linux/zfs/zpl_ctldir.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
static int
zpl_common_open(struct inode *ip, struct file *filp)
{
if (filp->f_mode & FMODE_WRITE)
if (blk_mode_is_open_write(filp->f_mode))
return (-EACCES);

return (generic_file_open(ip, filp));
Expand Down
13 changes: 3 additions & 10 deletions module/os/linux/zfs/zvol_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,22 +777,15 @@ zvol_open(struct block_device *bdev, fmode_t flag)
}
}

#ifdef HAVE_BLK_MODE_T
error = -zvol_first_open(zv, !(flag & BLK_OPEN_WRITE));
#else
error = -zvol_first_open(zv, !(flag & FMODE_WRITE));
#endif
error = -zvol_first_open(zv, !(blk_mode_is_open_write(flag)));

if (drop_namespace)
mutex_exit(&spa_namespace_lock);
}

if (error == 0) {
#ifdef HAVE_BLK_MODE_T
if ((flag & BLK_OPEN_WRITE) && (zv->zv_flags & ZVOL_RDONLY)) {
#else
if ((flag & FMODE_WRITE) && (zv->zv_flags & ZVOL_RDONLY)) {
#endif
if ((blk_mode_is_open_write(flag)) &&
(zv->zv_flags & ZVOL_RDONLY)) {
if (zv->zv_open_count == 0)
zvol_last_close(zv);

Expand Down

0 comments on commit 5379a40

Please sign in to comment.