diff mbox series

scsi_lib: ratelimit printk in scsi_prep_state_check

Message ID ed19f704-ed33-66dc-ff37-2f686b66dbd6@gmx.net (mailing list archive)
State Deferred
Headers show
Series scsi_lib: ratelimit printk in scsi_prep_state_check | expand

Commit Message

Arne Jansen Dec. 10, 2019, 2:21 p.m. UTC
scsi_prep_state_check is called with the queue_lock held, called from
scsi_internal_device_unblock.
The same lock is also acquired in softirq context from scsi_end_request.
If the output overwhelms the serial console, the machine effectively
comes to a halt, even triggering a hardware watchdog.

This patch ratelimits the output.

Signed-off-by: Arne Jansen <sensille@gmx.net>
---
  drivers/scsi/scsi_lib.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)

         case SDEV_TRANSPORT_OFFLINE:
@@ -1240,16 +1244,18 @@ scsi_prep_state_check(struct scsi_device *sdev,
struct request *req)
                  * commands.  The device must be brought online
                  * before trying any recovery commands.
                  */
-               sdev_printk(KERN_ERR, sdev,
-                           "rejecting I/O to offline device\n");
+               if (__ratelimit(&_rs))
+                       sdev_printk(KERN_ERR, sdev,
+                                   "rejecting I/O to offline device\n");
                 return BLK_STS_IOERR;
         case SDEV_DEL:
                 /*
                  * If the device is fully deleted, we refuse to
                  * process any commands as well.
                  */
-               sdev_printk(KERN_ERR, sdev,
-                           "rejecting I/O to dead device\n");
+               if (__ratelimit(&_rs))
+                       sdev_printk(KERN_ERR, sdev,
+                                   "rejecting I/O to dead device\n");
                 return BLK_STS_IOERR;
         case SDEV_BLOCK:
         case SDEV_CREATED_BLOCK:
--
2.11.0
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 3e7a45d0daca..33432108d6aa 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1232,6 +1232,10 @@  static blk_status_t scsi_setup_cmnd(struct
scsi_device *sdev,
  static blk_status_t
  scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
  {
+       static DEFINE_RATELIMIT_STATE(_rs,
+               DEFAULT_RATELIMIT_INTERVAL,
+               DEFAULT_RATELIMIT_BURST);
+
         switch (sdev->sdev_state) {
         case SDEV_OFFLINE: