Skip to contentSkip to conversation

scsi_lib: avoid the "rejecting I/O to offline device" print storm

SCSI Chuansheng Liu 1 participant 1 message Oct 22, 2013 SCSI

lore
Share & tools
lore
#0 lore raw

When handling the scsi_request_fn(), when the sd offline happened, sometimes we will hit the print storm as below:

<3>[   95.365837] sd 0:0:0:0: rejecting I/O to offline device
<3>[   95.368633] sd 0:0:0:0: rejecting I/O to offline device
<3>[   95.369881] sd 0:0:0:0: rejecting I/O to offline device
<3>[   95.371088] sd 0:0:0:0: rejecting I/O to offline device
...
<3>[   99.026230] sd 0:0:0:0: rejecting I/O to offline device
<3>[   99.027196] sd 0:0:0:0: rejecting I/O to offline device
<3>[   99.028240] sd 0:0:0:0: rejecting I/O to offline device

In our case, the print last almost 4s, and it causes irq is disbled for 4s, bring system unstable.

Here we create sd_printk_ratelimited to replace it.

---
 drivers/scsi/scsi_lib.c    |    2 +-
 include/scsi/scsi_device.h |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
drivers/scsi/scsi_lib.c +1 -1
index d1549b7..7d8d476 100644
@@ -1570,7 +1570,7 @@ static void scsi_request_fn(struct request_queue *q)
 			break;
 
 		if (unlikely(!scsi_device_online(sdev))) {
-			sdev_printk(KERN_ERR, sdev,
+			sdev_printk_ratelimited(KERN_ERR, sdev,
 				    "rejecting I/O to offline device\n");
 			scsi_kill_request(req, q);
 			continue;
include/scsi/scsi_device.h +10 -0
index d65fbec..0d7d1be 100644
@@ -7,6 +7,7 @@
 #include <linux/blkdev.h>
 #include <scsi/scsi.h>
 #include <linux/atomic.h>
+#include <linux/ratelimit.h>
 
 struct device;
 struct request_queue;
@@ -235,6 +236,15 @@ struct scsi_dh_data {
 #define sdev_printk(prefix, sdev, fmt, a...)	\
 	dev_printk(prefix, &(sdev)->sdev_gendev, fmt, ##a)
 
+#define sdev_printk_ratelimited(prefix, sdev, fmt, a...)               \
+do {                                                                   \
+       static DEFINE_RATELIMIT_STATE(_rs,                              \
+                                       DEFAULT_RATELIMIT_INTERVAL,     \
+                                       DEFAULT_RATELIMIT_BURST);       \
+       if (__ratelimit(&_rs))                                          \
+               dev_printk(prefix, &(sdev)->sdev_gendev, fmt, ##a);     \
+} while (0)
+
 #define scmd_printk(prefix, scmd, fmt, a...)				\
         (scmd)->request->rq_disk ?					\
 	sdev_printk(prefix, (scmd)->device, "[%s] " fmt,		\
Signature · 1 line
1.7.9.5