mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
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:
parent
7c09a4ed61
commit
321de651fa
13
block/bdev.c
13
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)
|
||||
if (mode & BLK_OPEN_WRITE) {
|
||||
if (bdev_writes_blocked(bdev))
|
||||
bdev_unblock_writes(bdev);
|
||||
else if (mode & BLK_OPEN_WRITE)
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user