summaryrefslogtreecommitdiff
path: root/block/bdev.c
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2024-01-23 14:26:48 +0100
committerChristian Brauner <brauner@kernel.org>2024-02-25 12:05:28 +0100
commit321de651fa565dcf76c017b257bdf15ec7fff45d (patch)
tree347fdf9dfdc22b8bf68701a9fdaedb2d74a9dc1b /block/bdev.c
parent7c09a4ed6156c6cab6b951e027ca6ea24af454ba (diff)
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.org Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'block/bdev.c')
-rw-r--r--block/bdev.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/block/bdev.c b/block/bdev.c
index 4e4527c5df00..efecc9b97e1e 100644
--- a/block/bdev.c
+++ b/block/bdev.c
@@ -799,16 +799,21 @@ static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode)
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)
return;
+ bdev = file_bdev(bdev_file);
/* Yield exclusive or shared write access. */
- if (mode & BLK_OPEN_RESTRICT_WRITES)
- bdev_unblock_writes(bdev);
- else if (mode & BLK_OPEN_WRITE)
- bdev->bd_writers--;
+ if (mode & BLK_OPEN_WRITE) {
+ if (bdev_writes_blocked(bdev))
+ bdev_unblock_writes(bdev);
+ else
+ bdev->bd_writers--;
+ }
}
/**
@@ -1020,7 +1025,7 @@ void bdev_release(struct file *bdev_file)
sync_blockdev(bdev);
mutex_lock(&disk->open_mutex);
- bdev_yield_write_access(bdev, handle->mode);
+ bdev_yield_write_access(bdev_file, handle->mode);
if (handle->holder)
bd_end_claim(bdev, handle->holder);