Skip to contentSkip to conversation

SCSI: throttle SG_DXFER_TO_FROM_DEV warning message better

PATCH New Tejun Heo 1 participant 1 message Aug 17, 2007

Subsystems (2)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 SCSI: throttle SG_DXFER_TO_FROM_DEV warning message better

When a program continually issues SG_DXFER_TO_FROM_DEV commands, throttling via printk_ratelimit() isn't enough. If the drive is fast and the console is slow (e.g. vesafb), it can slow down the process quite a bit.

This patch makes sg remember last printed comm name and skip warning message if the name matches. This can protect most use cases.

---
 drivers/scsi/sg.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/scsi/sg.c +8 -2
index 85d3894..913408a 100644
@@ -605,8 +605,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
 	 * but is is possible that the app intended SG_DXFER_TO_DEV, because there
 	 * is a non-zero input_size, so emit a warning.
 	 */
-	if (hp->dxfer_direction == SG_DXFER_TO_FROM_DEV)
-		if (printk_ratelimit())
+	if (hp->dxfer_direction == SG_DXFER_TO_FROM_DEV) {
+		static char last_printed[TASK_COMM_LEN];
+
+		if (strcmp(last_printed, current->comm) && printk_ratelimit()) {
 			printk(KERN_WARNING
 			       "sg_write: data in/out %d/%d bytes for SCSI command 0x%x--"
 			       "guessing data in;\n" KERN_WARNING "   "
@@ -614,6 +616,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
 			       old_hdr.reply_len - (int)SZ_SG_HEADER,
 			       input_size, (unsigned int) cmnd[0],
 			       current->comm);
+
+			memcpy(last_printed, current->comm, TASK_COMM_LEN);
+		}
+	}
 	k = sg_common_write(sfp, srp, cmnd, sfp->timeout, blocking);
 	return (k < 0) ? k : count;
 }