block: warn once for each partition in bio_check_ro()
authorYu Kuai <yukuai3@huawei.com>
Tue, 28 Nov 2023 12:30:27 +0000 (20:30 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 28 Nov 2023 19:11:08 +0000 (12:11 -0700)
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 <yukuai3@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20231128123027.971610-3-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-core.c
include/linux/blk_types.h

index fdf25b8d6e784f9904ee7892277acdb25430f3d3..2eca76ccf4ee017332ad37f708d6d2b8e5f50b74 100644 (file)
@@ -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);
        }
 }
 
index f7d40692dd9481e7cad3f95892c9053311f1edf0..b29ebd53417d79564617fccc762a56f2b569de63 100644 (file)
@@ -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