Commit 06d779b8 authored by Li Lingfeng's avatar Li Lingfeng
Browse files

block: Record writing and mounting regardless of whether bdev_allow_write_mounted is set

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: default avatarLi Lingfeng <lilingfeng3@huawei.com>
parent ea6de9f6
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -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);
+3 −0
Original line number Diff line number Diff line
@@ -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