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

Konstantin Khorenko khorenko at virtuozzo.com
Fri Dec 27 19:25:14 MSK 2019


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 at virtuozzo.com>
---
 drivers/scsi/scsi_lib.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

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



More information about the Devel mailing list