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 | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/block/bdev.c b/block/bdev.c index 42bcde62967e..b2b69cd82d66 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -776,6 +776,14 @@ static bool bdev_writes_blocked(struct block_device *bdev) return !!bdev->bd_mounters; }
+static bool bdev_lower_device_writes_blocked(struct block_device *bdev) +{ + if (bdev_allow_write_mounted & (1 << BLKDEV_DETECT_WRITING_PART0)) + return !!bdev->bd_holder; + else + return !!bdev->bd_holder && bdev->bd_holder != bd_may_claim; +} + static void bdev_block_writes(struct block_device *bdev) { bdev->bd_mounters++; @@ -839,6 +847,9 @@ static bool bdev_may_open(struct block_device *bdev, blk_mode_t mode) return bdev_may_conflict_open(bdev, OPEN_EXCLUSIVE); if (mode & BLK_OPEN_RESTRICT_WRITES && bdev_mount_blocked(bdev)) return bdev_may_conflict_open(bdev, OPEN_FOR_EXCLUSIVE); + if ((bdev_allow_write_mounted & (1 << BLKDEV_WRITE_MOUNTED_DUMP)) && + mode & BLK_OPEN_WRITE && bdev_lower_device_writes_blocked(bdev)) + blkdev_dump_conflict_opener(bdev, OPEN_EXCLUSIVE);
return true; }