提交 14eae9d6 编写于 作者: Z zhangyi (F) 提交者: Xie XiuQi

block: add info when opening an exclusive opened block device for write

euler inclusion
category: feature
bugzilla: 14367
CVE: NA
---------------------------

Currently, we don't have an easy way to figure out a corrupted file
system which has been writen data through the raw block device. 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: Nzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: NMiao Xie <miaoxie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 f3019115
...@@ -1624,13 +1624,13 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) ...@@ -1624,13 +1624,13 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
res = __blkdev_get(bdev, mode, 0); res = __blkdev_get(bdev, mode, 0);
mutex_lock(&bdev->bd_mutex);
spin_lock(&bdev_lock);
if (whole) { if (whole) {
struct gendisk *disk = whole->bd_disk; struct gendisk *disk = whole->bd_disk;
/* finish claiming */ /* finish claiming */
mutex_lock(&bdev->bd_mutex);
spin_lock(&bdev_lock);
if (!res) { if (!res) {
BUG_ON(!bd_may_claim(bdev, whole, holder)); BUG_ON(!bd_may_claim(bdev, whole, holder));
/* /*
...@@ -1667,6 +1667,22 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) ...@@ -1667,6 +1667,22 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
mutex_unlock(&bdev->bd_mutex); mutex_unlock(&bdev->bd_mutex);
bdput(whole); bdput(whole);
} else {
if (!res && (mode & FMODE_WRITE) && bdev->bd_holders) {
char name[BDEVNAME_SIZE];
/*
* Open an exclusive opened device for write may
* probability corrupt the device, such as a
* mounted file system, give a hint here.
*/
pr_info_ratelimited("VFS: Open an exclusive opened "
"block device for write %s [%d %s].\n",
bdevname(bdev, name), current->pid,
current->comm);
}
spin_unlock(&bdev_lock);
mutex_unlock(&bdev->bd_mutex);
} }
return res; return res;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册