From: Li Lingfeng lilingfeng3@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I53Q6M CVE: NA
--------------------------------
Just like open a write opend block device exclusively, open an exclusive opened block device for write may also lead to potential data corruption. This patch add an info message when opening an exclusive opened block device for write to hint the potential data corruption.
Note that there are some legal cases such as file system or device mapper online resize, so this message is just a hint and isn't always mean that a risky written happens.
Signed-off-by: Li Lingfeng lilingfeng3@huawei.com Reviewed-by: Zhihao Cheng chengzhihao1@huawei.com Reviewed-by: Yang Erkun yangerkun@huawei.com Reviewed-by: Hou Tao houtao1@huawei.com Signed-off-by: Yongqiang Liu liuyongqiang13@huawei.com --- fs/block_dev.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/fs/block_dev.c b/fs/block_dev.c index 6adb17cc7dbb..b4bb16d79d78 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1820,6 +1820,18 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
mutex_unlock(&bdev->bd_mutex); bdput(whole); + } else if (!res && (mode & FMODE_WRITE)) { + spin_lock(&bdev_lock); + /* + * Open an exclusive opened device for write may + * probability corrupt the device, such as a + * mounted file system, give a hint here. + */ + if (bdev->bd_holders || + ((bdev->bd_contains->bd_holder != NULL) && (bdev->bd_contains->bd_holder != bd_may_claim))) + blkdev_dump_conflict_opener(bdev, + "VFS: Open an exclusive opened block device for write"); + spin_unlock(&bdev_lock); }
if (res)