
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8S3GW CVE: NA --------------------------- Filesystem on logic devices may be corrupted when writing to a block device which is used to create logic devices, so show info to indicate this risk behavior. Signed-off-by: Li Lingfeng <lilingfeng3@huawei.com> --- block/bdev.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index 050a5cc5d4c2..b555deef0d76 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -818,6 +818,22 @@ static void bdev_unblock_mount(struct block_device *bdev) bdev->bd_disk->write_open_partitions--; } +static void bdev_write_exclusive_dump(struct block_device *bdev, void *holder, + const struct blk_holder_ops *hops) +{ + bool may_claim; + + if (!bdev_write_mounted_opt(WRITE_MOUNTED_DUMP)) + return; + + mutex_lock(&bdev_lock); + may_claim = bd_may_claim(bdev, holder, hops); + mutex_unlock(&bdev_lock); + + if (!may_claim) + blkdev_dump_conflict_opener(bdev, OPEN_EXCLUSIVE); +} + static bool bdev_may_open(struct block_device *bdev, blk_mode_t mode) { if (bdev_write_mounted_opt(ALLOW_WRITE_MOUNTED) && @@ -919,6 +935,9 @@ struct bdev_handle *bdev_open_by_dev(dev_t dev, blk_mode_t mode, void *holder, disk_block_events(disk); + if (mode & BLK_OPEN_WRITE) + bdev_write_exclusive_dump(bdev, holder, hops); + mutex_lock(&disk->open_mutex); ret = -ENXIO; if (!disk_live(disk)) -- 2.31.1