From: Li Lingfeng lilingfeng3@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I53Q6M CVE: NA
---------------------------
Commit 9a8887a9e69135c87d0748e589d7d31161d74d77 can't cover some special situations, so revert it and add a more complete one.
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 | 20 ++------------------ include/linux/fs.h | 1 - 2 files changed, 2 insertions(+), 19 deletions(-)
diff --git a/fs/block_dev.c b/fs/block_dev.c index 6ba91b97753f..4daa2998fbaf 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1666,8 +1666,6 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) bdev->bd_openers++; if (for_part) bdev->bd_part_count++; - if (mode & FMODE_WRITE) - bdev->bd_write_openers++; mutex_unlock(&bdev->bd_mutex); disk_unblock_events(disk); /* only one opener holds refs to the module and disk */ @@ -1715,7 +1713,6 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) { struct block_device *whole = NULL; int res; - char name[BDEVNAME_SIZE];
WARN_ON_ONCE((mode & FMODE_EXCL) && !holder);
@@ -1735,19 +1732,6 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) if (whole) { struct gendisk *disk = whole->bd_disk;
- /* - * Open an write opened block device exclusively, the - * writing process may probability corrupt the device, - * such as a mounted file system, give a hint here. - */ - if (!res && (bdev->bd_write_openers > - ((mode & FMODE_WRITE) ? 1 : 0)) && !bdev->bd_holders) { - pr_info_ratelimited("VFS: Open an write opened " - "block device exclusively %s [%d %s].\n", - bdevname(bdev, name), current->pid, - current->comm); - } - /* finish claiming */ if (!res) { BUG_ON(!bd_may_claim(bdev, whole, holder)); @@ -1787,6 +1771,8 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) 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 @@ -1934,8 +1920,6 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) sync_blockdev(bdev);
mutex_lock_nested(&bdev->bd_mutex, for_part); - if (mode & FMODE_WRITE) - bdev->bd_write_openers--; if (for_part) bdev->bd_part_count--;
diff --git a/include/linux/fs.h b/include/linux/fs.h index bcd2131ca06c..3892a5793c62 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -462,7 +462,6 @@ struct request_queue; struct block_device { dev_t bd_dev; /* not a kdev_t - it's a search key */ int bd_openers; - int bd_write_openers; struct inode * bd_inode; /* will die */ struct super_block * bd_super; struct mutex bd_mutex; /* open/close mutex */