[PATCH] scsi_lib: ratelimit printk in scsi_prep_state_check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]

  Powered by Linux