2023-11-28 12:31:32

by Yu Kuai

[permalink] [raw]
Subject: [PATCH v4 2/2] block: warn once for each partition in bio_check_ro()

From: Yu Kuai <[email protected]>

Commit 1b0a151c10a6 ("blk-core: use pr_warn_ratelimited() in
bio_check_ro()") fix message storm by limit the rate, however, there
will still be lots of message in the long term. Fix it better by warn
once for each partition.

Signed-off-by: Yu Kuai <[email protected]>
---
block/blk-core.c | 14 +++++++++++---
include/linux/blk_types.h | 1 +
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index fdf25b8d6e78..2eca76ccf4ee 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -501,9 +501,17 @@ static inline void bio_check_ro(struct bio *bio)
if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
return;
- pr_warn_ratelimited("Trying to write to read-only block-device %pg\n",
- bio->bi_bdev);
- /* Older lvm-tools actually trigger this */
+
+ if (bio->bi_bdev->bd_ro_warned)
+ return;
+
+ bio->bi_bdev->bd_ro_warned = true;
+ /*
+ * Use ioctl to set underlying disk of raid/dm to read-only
+ * will trigger this.
+ */
+ pr_warn("Trying to write to read-only block-device %pg\n",
+ bio->bi_bdev);
}
}

diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index f7d40692dd94..b29ebd53417d 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -70,6 +70,7 @@ struct block_device {
#ifdef CONFIG_FAIL_MAKE_REQUEST
bool bd_make_it_fail;
#endif
+ bool bd_ro_warned;
/*
* keep this out-of-line as it's both big and not needed in the fast
* path
--
2.39.2


2023-11-28 13:00:33

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] block: warn once for each partition in bio_check_ro()

On Tue, Nov 28, 2023 at 08:30:27PM +0800, Yu Kuai wrote:
> From: Yu Kuai <[email protected]>
>
> Commit 1b0a151c10a6 ("blk-core: use pr_warn_ratelimited() in
> bio_check_ro()") fix message storm by limit the rate, however, there
> will still be lots of message in the long term. Fix it better by warn
> once for each partition.

The new field is in the same dword alignment as bd_make_it_fail and
could in theory corrupt it, at least on alpha. I guess we're fine,
because if you enable CONFIG_FAIL_MAKE_REQUEST on alpha you're asking
for this. I still hope we can clean up these non-atomic bools and
replace them with bitops soon.

Signed-off-by: Christoph Hellwig <[email protected]>

2023-11-29 01:14:14

by Yu Kuai

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] block: warn once for each partition in bio_check_ro()

Hi,

?? 2023/11/28 21:00, Christoph Hellwig ะด??:
> On Tue, Nov 28, 2023 at 08:30:27PM +0800, Yu Kuai wrote:
>> From: Yu Kuai <[email protected]>
>>
>> Commit 1b0a151c10a6 ("blk-core: use pr_warn_ratelimited() in
>> bio_check_ro()") fix message storm by limit the rate, however, there
>> will still be lots of message in the long term. Fix it better by warn
>> once for each partition.
>
> The new field is in the same dword alignment as bd_make_it_fail and
> could in theory corrupt it, at least on alpha. I guess we're fine,
> because if you enable CONFIG_FAIL_MAKE_REQUEST on alpha you're asking
> for this. I still hope we can clean up these non-atomic bools and
> replace them with bitops soon.

Yes, I'm working on this, and thanks for the review!

Kuai
>
> Signed-off-by: Christoph Hellwig <[email protected]>
> .
>