hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8S3GW CVE: NA
---------------------------
Introduce bd_mounters to record the num of mount. The count of bd_writers and bd_mounters can have other uses and they doesn't block writes when bdev_allow_write_mounted is not set, so remove the restriction for counting them.
Signed-off-by: Li Lingfeng lilingfeng3@huawei.com --- block/bdev.c | 19 +++++++++---------- include/linux/blk_types.h | 1 + 2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c index dd39c26c44ad..715428eb6621 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -735,17 +735,22 @@ void blkdev_put_no_open(struct block_device *bdev)
static bool bdev_writes_blocked(struct block_device *bdev) { - return bdev->bd_writers == -1; + return !!bdev->bd_mounters; }
static void bdev_block_writes(struct block_device *bdev) { - bdev->bd_writers = -1; + bdev->bd_mounters++; }
static void bdev_unblock_writes(struct block_device *bdev) { - bdev->bd_writers = 0; + bdev->bd_mounters--; +} + +static bool bdev_mount_blocked(struct block_device *bdev) +{ + return bdev->bd_writers > 0; }
static bool bdev_may_open(struct block_device *bdev, blk_mode_t mode) @@ -755,16 +760,13 @@ static bool bdev_may_open(struct block_device *bdev, blk_mode_t mode) /* Writes blocked? */ if (mode & BLK_OPEN_WRITE && bdev_writes_blocked(bdev)) return false; - if (mode & BLK_OPEN_RESTRICT_WRITES && bdev->bd_writers > 0) + if (mode & BLK_OPEN_RESTRICT_WRITES && bdev_mount_blocked(bdev)) return false; return true; }
static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode) { - if (bdev_allow_write_mounted) - return; - /* Claim exclusive or shared write access. */ if (mode & BLK_OPEN_RESTRICT_WRITES) bdev_block_writes(bdev); @@ -774,9 +776,6 @@ static void bdev_claim_write_access(struct block_device *bdev, blk_mode_t mode)
static void bdev_yield_write_access(struct block_device *bdev, blk_mode_t mode) { - if (bdev_allow_write_mounted) - return; - /* Yield exclusive or shared write access. */ if (mode & BLK_OPEN_RESTRICT_WRITES) bdev_unblock_writes(bdev); diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index 262ae789726b..0e1e429d3f74 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -70,6 +70,7 @@ struct block_device { bool bd_make_it_fail; #endif int bd_writers; + int bd_mounters; /* * keep this out-of-line as it's both big and not needed in the fast * path