Commit 321de651 authored by Christian Brauner's avatar Christian Brauner

block: don't rely on BLK_OPEN_RESTRICT_WRITES when yielding write access

Make it possible to detected a block device that was opened with
restricted write access based only on BLK_OPEN_WRITE and
bdev->bd_writers < 0 so we won't have to claim another FMODE_* flag.

Link: https://lore.kernel.org/r/20240123-vfs-bdev-file-v2-31-adbd023e19cc@kernel.orgSigned-off-by: default avatarChristian Brauner <brauner@kernel.org>
parent 7c09a4ed
...@@ -799,16 +799,21 @@ static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode) ...@@ -799,16 +799,21 @@ static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode)
bdev->bd_writers++; bdev->bd_writers++;
} }
static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode) static void bdev_yield_write_access(struct file *bdev_file, blk_mode_t mode)
{ {
struct block_device *bdev;
if (bdev_allow_write_mounted) if (bdev_allow_write_mounted)
return; return;
bdev = file_bdev(bdev_file);
/* Yield exclusive or shared write access. */ /* Yield exclusive or shared write access. */
if (mode & BLK_OPEN_RESTRICT_WRITES) if (mode & BLK_OPEN_WRITE) {
if (bdev_writes_blocked(bdev))
bdev_unblock_writes(bdev); bdev_unblock_writes(bdev);
else if (mode & BLK_OPEN_WRITE) else
bdev->bd_writers--; bdev->bd_writers--;
}
} }
/** /**
...@@ -1020,7 +1025,7 @@ void bdev_release(struct file *bdev_file) ...@@ -1020,7 +1025,7 @@ void bdev_release(struct file *bdev_file)
sync_blockdev(bdev); sync_blockdev(bdev);
mutex_lock(&disk->open_mutex); mutex_lock(&disk->open_mutex);
bdev_yield_write_access(bdev, handle->mode); bdev_yield_write_access(bdev_file, handle->mode);
if (handle->holder) if (handle->holder)
bd_end_claim(bdev, handle->holder); bd_end_claim(bdev, handle->holder);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment