block: fix and cleanup bio_check_ro
authorChristoph Hellwig <hch@lst.de>
Fri, 4 Mar 2022 18:00:56 +0000 (19:00 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 1 Feb 2023 07:27:30 +0000 (08:27 +0100)
commit 57e95e4670d1126c103305bcf34a9442f49f6d6a upstream.

Don't use a WARN_ON when printing a potentially user triggered
condition.  Also don't print the partno when the block device name
already includes it, and use the %pg specifier to simplify printing
the block device name.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://lore.kernel.org/r/20220304180105.409765-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
block/blk-core.c

index 13e1fca..ed6271d 100644 (file)
@@ -698,14 +698,10 @@ static inline bool should_fail_request(struct block_device *part,
 static inline bool bio_check_ro(struct bio *bio)
 {
        if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
-               char b[BDEVNAME_SIZE];
-
                if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
                        return false;
-
-               WARN_ONCE(1,
-                      "Trying to write to read-only block-device %s (partno %d)\n",
-                       bio_devname(bio, b), bio->bi_bdev->bd_partno);
+               pr_warn("Trying to write to read-only block-device %pg\n",
+                       bio->bi_bdev);
                /* Older lvm-tools actually trigger this */
                return false;
        }