Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions block/bdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,11 +860,6 @@ void blkdev_put_no_open(struct block_device *bdev)
put_device(&bdev->bd_device);
}

static bool bdev_writes_blocked(struct block_device *bdev)
{
return bdev->bd_writers < 0;
}

static void bdev_block_writes(struct block_device *bdev)
{
bdev->bd_writers--;
Expand Down
16 changes: 16 additions & 0 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,22 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
goto out_unlock;
}

#ifndef CONFIG_BLK_DEV_WRITE_MOUNTED
/*
* Changing lo_offset or shrinking lo_sizelimit on a mounted
* device is equivalent to modifying the block device contents.
* Block this if writes to the device are blocked.
*/
if ((lo->lo_offset != info->lo_offset ||
(info->lo_sizelimit &&
(lo->lo_sizelimit == 0 ||
info->lo_sizelimit < lo->lo_sizelimit))) &&
bdev_writes_blocked(lo->lo_device)) {
err = -EBUSY;
goto out_unlock;
}
#endif

if (lo->lo_offset != info->lo_offset ||
lo->lo_sizelimit != info->lo_sizelimit) {
size_changed = true;
Expand Down
5 changes: 5 additions & 0 deletions include/linux/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ struct block_device {
#define bdev_whole(_bdev) \
((_bdev)->bd_disk->part0)

static inline bool bdev_writes_blocked(struct block_device *bdev)
{
return bdev->bd_writers < 0;
}

#define dev_to_bdev(device) \
container_of((device), struct block_device, bd_device)

Expand Down