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

Konstantin Khorenko khorenko at virtuozzo.com
Mon Jun 7 15:54:01 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.35
------>
commit d003edfe91e0e8d504e04a9d3cf8decfc1bf46b8
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Mon Jun 7 15:54:01 2021 +0300

    scsi: ratelimit messages about rejected I/O
    
    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>
    
    (cherry-picked from vz7 commit 734978dda643 ("scsi: ratelimit messages about
    rejected I/O"))
    
    https://jira.sw.ru/browse/PSBM-127849
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin 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 0002d2be2651..f34783ac8d41 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -1245,6 +1245,8 @@ 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(ratelimit, 5 * HZ, 10);
+
 	switch (sdev->sdev_state) {
 	case SDEV_OFFLINE:
 	case SDEV_TRANSPORT_OFFLINE:
@@ -1255,8 +1257,9 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
 		 */
 		if (!sdev->offline_already) {
 			sdev->offline_already = true;
-			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");
 		}
 		return BLK_STS_IOERR;
 	case SDEV_DEL:
@@ -1264,8 +1267,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");
 		return BLK_STS_IOERR;
 	case SDEV_BLOCK:
 	case SDEV_CREATED_BLOCK:


More information about the Devel mailing list