hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8S3GW CVE: NA
---------------------------
Introduce bd_mounted to record the state of mount. The count of bd_writers and bd_mounted can have other uses and they doesn't block writes when bdev_allow_write_mounted is not set, so remove the restriction for recording them.
Signed-off-by: Li Lingfeng lilingfeng3@huawei.com --- block/bdev.c | 19 +++++++++---------- include/linux/blk_types.h | 3 +++ 2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/block/bdev.c b/block/bdev.c index dd39c26c44ad..b031c91efa0d 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_mounted; }
static void bdev_block_writes(struct block_device *bdev) { - bdev->bd_writers = -1; + bdev->bd_mounted = true; }
static void bdev_unblock_writes(struct block_device *bdev) { - bdev->bd_writers = 0; + bdev->bd_mounted = false; +} + +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..f571b45eba19 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -69,6 +69,9 @@ struct block_device { #ifdef CONFIG_FAIL_MAKE_REQUEST bool bd_make_it_fail; #endif + /* State of mounting */ + bool bd_mounted; + /* The counter of write opened */ int bd_writers; /* * keep this out-of-line as it's both big and not needed in the fast