[rh7] scsi: ratelimit messages about rejected I/O

Submitted by Konstantin Khorenko on Dec. 27, 2019, 4:25 p.m.

Details

Message ID 20191227162514.31016-1-khorenko@virtuozzo.com
State New
Series "scsi: ratelimit messages about rejected I/O"
Headers show

Commit Message

Konstantin Khorenko Dec. 27, 2019, 4:25 p.m.
Don't flood logs with messages like
"sd 1:0:0:0: rejecting I/O to offline device".

On one hand this flooding is not useful for investigations,
on anothre hand it can make serial console to feed up.

https://jira.sw.ru/browse/PSBM-100118

Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 drivers/scsi/scsi_lib.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index c36e326f46a72..0db8a47be93c0 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1219,6 +1219,8 @@  static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req)
 static int
 scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
 {
+	static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 10);
+
 	int ret = BLKPREP_OK;
 
 	/*
@@ -1234,8 +1236,9 @@  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(&ratelimit))
+				sdev_printk(KERN_ERR, sdev,
+					"rejecting I/O to offline device\n");
 			ret = BLKPREP_KILL;
 			break;
 		case SDEV_DEL:
@@ -1243,8 +1246,9 @@  scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
 			 * 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(&ratelimit))
+				sdev_printk(KERN_ERR, sdev,
+					"rejecting I/O to dead device\n");
 			ret = BLKPREP_KILL;
 			break;
 		case SDEV_QUIESCE: