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>
This commit is contained in:
Christian Brauner 2024-01-23 14:26:48 +01:00
parent 7c09a4ed61
commit 321de651fa
No known key found for this signature in database
GPG Key ID: 91C61BC06578DCA2
1 changed files with 11 additions and 6 deletions

View File

@ -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);