linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arne Jansen <sensille@gmx.net>
To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: jejb@linux.ibm.com, martin.petersen@oracle.com
Subject: [PATCH] scsi_lib: ratelimit printk in scsi_prep_state_check
Date: Tue, 10 Dec 2019 15:21:07 +0100	[thread overview]
Message-ID: <ed19f704-ed33-66dc-ff37-2f686b66dbd6@gmx.net> (raw)

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(-)

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:
         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

                 reply	other threads:[~2019-12-10 14:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ed19f704-ed33-66dc-ff37-2f686b66dbd6@gmx.net \
    --to=sensille@gmx.net \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).