Skip to contentSkip to conversation

scsi logging update: the real thing

PATCH In review Hannes Reinecke 7 participants 21 messages Jan 8, 2015 – Jan 14, 2015

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover scsi logging update: the real thing

Hi all,

this is the second part of my scsi logging update, covering CDB and sense code printing. With this patchset CDBs and sense code bytes will be formatted on a single line (where possible), and prefixed with the device and command tag.

To ensure CDBs and sense code bytes are not broken up during printk I've implemented a per-cpu buffer for formatting messages. One can allocate a chunk from the buffer using scsi_log_reserve_buffer() and return it via scsi_log_release_buffer(). Both function do an implicit preempt_disable() / preempt_enable() to ensure we're not scheduled away from that cpu whilst writing into the buffer.

With that I've been able to clean up constants.c to remove all the #ifdef CONFIG_SCSI_CONSTANTS statements. It'll now be compiled in conditionally if CONFIG_SCSI_CONSTANTS is set.

Thanks go to Stephen Rostedt who suffered my annoying questions during LPC.

Changes to v3:
- Update to scsi-for-3.20 tree
- Drop upstreamed patches

Changes to v2:
- Include reviews and suggestions from Robert Elliott

Hannes Reinecke (9):
scsi: Implement per-cpu logging buffer
scsi: log request tag for scmd_printk()
scsi: use external buffer for command logging
libata: use __scsi_format_command()
scsi: use per-cpu buffer for formatting sense
scsi: use per-cpu buffer for formatting scsi_print_result()
scsi: Conditionally compile in constants.c
scsi: Do not display buffer pointers in scsi_log_send()
scsi_error: do not display kernel pointer in message logs

 drivers/ata/libata-eh.c     |  17 +-
 drivers/scsi/Kconfig        |   4 +-
 drivers/scsi/Makefile       |   6 +-
 drivers/scsi/ch.c           |   6 +-
 drivers/scsi/constants.c    | 247 +---------------------
 drivers/scsi/scsi.c         |  11 +-
 drivers/scsi/scsi_error.c   |  49 ++---
 drivers/scsi/scsi_logging.c | 489 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/sd.c           |   7 +-
 drivers/scsi/sr_ioctl.c     |  13 +-
 drivers/scsi/ufs/ufshcd.c   |   6 +-
 drivers/xen/xen-scsiback.c  |   1 +
 include/scsi/scsi.h         |   3 +
 include/scsi/scsi_dbg.h     |  74 ++++++-
 include/scsi/scsi_device.h  |  21 +-
 15 files changed, 624 insertions(+), 330 deletions(-)
 create mode 100644 drivers/scsi/scsi_logging.c
Signature · 1 line
1.8.4.5
#4 lore raw

PATCH v4 3/9 scsi: use external buffer for command logging

Use an external buffer for __scsi_print_command() and move command logging over to use the per-cpu logging buffer. With that we can guarantee the command always will always be formatted in one line.
So we can even print out a variable length command correctly across several lines.
Finally rename __scsi_print_command() to __scsi_format_comment() to better reflect the functionality.

---
 drivers/scsi/ch.c           |   6 +-
 drivers/scsi/constants.c    |  74 +-----------------
 drivers/scsi/scsi_logging.c | 182 ++++++++++++++++++++++++++++++++++++++++----
 drivers/scsi/sr_ioctl.c     |  13 +++-
 include/scsi/scsi.h         |   3 +
 include/scsi/scsi_dbg.h     |   6 +-
 6 files changed, 192 insertions(+), 92 deletions(-)
drivers/scsi/ch.c +4 -2
index 6bac8a7..79e462f 100644
@@ -195,8 +195,10 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
  retry:
 	errno = 0;
 	if (debug) {
-		DPRINTK("command: ");
-		__scsi_print_command(cmd, cmd_len);
+		char logbuf[SCSI_LOG_BUFSIZE];
+
+		__scsi_format_command(logbuf, sizeof(logbuf), cmd, cmd_len);
+		DPRINTK("command: %s", logbuf);
 	}
 
 	result = scsi_execute_req(ch->device, cmd, direction, buffer,
drivers/scsi/constants.c +2 -72

92 lines not on this page · raw message

drivers/scsi/scsi_logging.c +168 -14

211 lines not on this page · raw message

drivers/scsi/sr_ioctl.c +10 -3
index fb929fa..e8deb9c 100644
@@ -188,6 +188,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
 	struct scsi_sense_hdr sshdr;
 	int result, err = 0, retries = 0;
 	struct request_sense *sense = cgc->sense;
+	char logbuf[SCSI_LOG_BUFSIZE];
 
 	SDev = cd->device;
 
@@ -257,14 +258,20 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
 				/* sense: Invalid command operation code */
 				err = -EDRIVE_CANT_DO_THIS;
 #ifdef DEBUG
-			__scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
+			__scsi_format_command(logbuf, sizeof(logbuf),
+					      cgc->cmd, CDROM_PACKET_SIZE);
+			sr_printk(KERN_INFO, cd,
+				  "CDROM (ioctl) invalid command: %s\n",
+				  logbuf);
 			scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
 #endif
 			break;
 		default:
+			__scsi_format_command(logbuf, sizeof(logbuf),
+					      cgc->cmd, CDROM_PACKET_SIZE);
 			sr_printk(KERN_ERR, cd,
-				  "CDROM (ioctl) error, command: ");
-			__scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
+				  "CDROM (ioctl) error, command: %s\n",
+				  logbuf);
 			scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
 			err = -EIO;
 		}
include/scsi/scsi.h +3 -0
index 8a7f8ad..d0a66aa 100644
@@ -195,6 +195,9 @@ enum scsi_timeouts {
 #define	ATA_16		      0x85	/* 16-byte pass-thru */
 #define	ATA_12		      0xa1	/* 12-byte pass-thru */
 
+/* Vendor specific CDBs start here */
+#define VENDOR_SPECIFIC_CDB 0xc0
+
 /*
  *	SCSI command lengths
  */
include/scsi/scsi_dbg.h +5 -1
index 7982795..c7ed7b8 100644
@@ -5,8 +5,12 @@ struct scsi_cmnd;
 struct scsi_device;
 struct scsi_sense_hdr;
 
+#define SCSI_LOG_BUFSIZE 128
+
+extern bool scsi_opcode_sa_name(int, int, const char **, const char **);
 extern void scsi_print_command(struct scsi_cmnd *);
-extern void __scsi_print_command(const unsigned char *, size_t);
+extern size_t __scsi_format_command(char *, size_t,
+				   const unsigned char *, size_t);
 extern void scsi_show_extd_sense(const struct scsi_device *, const char *,
 				 unsigned char, unsigned char);
 extern void scsi_show_sense_hdr(const struct scsi_device *, const char *,
Signature · 1 line
1.8.4.5
#11 lore raw

PATCH v4 7/9 scsi: Conditionally compile in constants.c

In reply to Hannes Reinecke

Instead of having constants.c littered with ifdef statements we should be moving dummy functions into the header and condintionally compile in constants.c if selected. And update the Kconfig description to reflect the actual size difference.

---
 drivers/scsi/Kconfig       |  4 +--
 drivers/scsi/Makefile      |  4 +--
 drivers/scsi/constants.c   | 44 ------------------------------
 drivers/xen/xen-scsiback.c |  1 +
 include/scsi/scsi_dbg.h    | 68 +++++++++++++++++++++++++++++++++++++++++++---
 5 files changed, 69 insertions(+), 52 deletions(-)
drivers/scsi/Kconfig +2 -2
index 9c92f41..b021bcb 100644
@@ -201,12 +201,12 @@ config SCSI_ENCLOSURE
 	  certain enclosure conditions to be reported and is not required.
 
 config SCSI_CONSTANTS
-	bool "Verbose SCSI error reporting (kernel size +=12K)"
+	bool "Verbose SCSI error reporting (kernel size +=75K)"
 	depends on SCSI
 	help
 	  The error messages regarding your SCSI hardware will be easier to
 	  understand if you say Y here; it will enlarge your kernel by about
-	  12 KB. If in doubt, say Y.
+	  75 KB. If in doubt, say Y.
 
 config SCSI_LOGGING
 	bool "SCSI logging facility"
drivers/scsi/Makefile +2 -2
index 447c2d2..dee160a 100644
@@ -159,9 +159,9 @@ obj-$(CONFIG_SCSI_OSD_INITIATOR) += osd/
 
 # This goes last, so that "real" scsi devices probe earlier
 obj-$(CONFIG_SCSI_DEBUG)	+= scsi_debug.o
-
-scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o constants.o \
+scsi_mod-y			+= scsi.o hosts.o scsi_ioctl.o \
 				   scsicam.o scsi_error.o scsi_lib.o
+scsi_mod-$(CONFIG_SCSI_CONSTANTS) += constants.o
 scsi_mod-$(CONFIG_SCSI_DMA)	+= scsi_lib_dma.o
 scsi_mod-y			+= scsi_scan.o scsi_sysfs.o scsi_devinfo.o
 scsi_mod-$(CONFIG_SCSI_NETLINK)	+= scsi_netlink.o
drivers/scsi/constants.c +0 -44

138 lines not on this page · raw message

drivers/xen/xen-scsiback.c +1 -0
index e999496e..471ab06 100644
@@ -47,6 +47,7 @@
 
 #include <generated/utsrelease.h>
 
+#include <scsi/scsi.h>
 #include <scsi/scsi_dbg.h>
 #include <scsi/scsi_eh.h>
 #include <scsi/scsi_tcq.h>
include/scsi/scsi_dbg.h +64 -4

82 lines not on this page · raw message

Signature · 1 line
1.8.4.5
#12 lore raw

PATCH v4 8/9 scsi: Do not display buffer pointers in scsi_log_send()

In reply to Hannes Reinecke

scsi_log_send() would display buffer pointer for higher logging levels. This is not only of questionable value but also exposes kernel pointer to userspace, which is discouraged in some setups. So drop this message altogether.

---
 drivers/scsi/scsi.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
drivers/scsi/scsi.c +1 -8
index 7f028cb..08c90a7 100644
@@ -531,7 +531,7 @@ void scsi_log_send(struct scsi_cmnd *cmd)
 	 *
 	 * 3: same as 2
 	 *
-	 * 4: same as 3 plus dump extra junk
+	 * 4: same as 3
 	 */
 	if (unlikely(scsi_logging_level)) {
 		level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
@@ -540,13 +540,6 @@ void scsi_log_send(struct scsi_cmnd *cmd)
 			scmd_printk(KERN_INFO, cmd,
 				    "Send: scmd 0x%p\n", cmd);
 			scsi_print_command(cmd);
-			if (level > 3) {
-				printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
-				       " queuecommand 0x%p\n",
-					scsi_sglist(cmd), scsi_bufflen(cmd),
-					cmd->device->host->hostt->queuecommand);
-
-			}
 		}
 	}
 }
Signature · 1 line
1.8.4.5
#13 lore raw

PATCH v4 9/9 scsi_error: do not display kernel pointer in message logs

In reply to Hannes Reinecke

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

---
 drivers/scsi/scsi_error.c | 49 +++++++++++++++++++----------------------------
 1 file changed, 20 insertions(+), 29 deletions(-)
drivers/scsi/scsi_error.c +20 -29
index e42fff6..10ffa21 100644
@@ -124,41 +124,37 @@ scmd_eh_abort_handler(struct work_struct *work)
 	if (scsi_host_eh_past_deadline(sdev->host)) {
 		SCSI_LOG_ERROR_RECOVERY(3,
 			scmd_printk(KERN_INFO, scmd,
-				    "scmd %p eh timeout, not aborting\n",
-				    scmd));
+				    "eh timeout, not aborting\n"));
 	} else {
 		SCSI_LOG_ERROR_RECOVERY(3,
 			scmd_printk(KERN_INFO, scmd,
-				    "aborting command %p\n", scmd));
+				    "aborting command\n"));
 		rtn = scsi_try_to_abort_cmd(sdev->host->hostt, scmd);
 		if (rtn == SUCCESS) {
 			set_host_byte(scmd, DID_TIME_OUT);
 			if (scsi_host_eh_past_deadline(sdev->host)) {
 				SCSI_LOG_ERROR_RECOVERY(3,
 					scmd_printk(KERN_INFO, scmd,
-						    "scmd %p eh timeout, "
-						    "not retrying aborted "
-						    "command\n", scmd));
+						    "eh timeout, not retrying "
+						    "aborted command\n"));
 			} else if (!scsi_noretry_cmd(scmd) &&
 			    (++scmd->retries <= scmd->allowed)) {
 				SCSI_LOG_ERROR_RECOVERY(3,
 					scmd_printk(KERN_WARNING, scmd,
-						    "scmd %p retry "
-						    "aborted command\n", scmd));
+						    "retry aborted command\n"));
 				scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
 				return;
 			} else {
 				SCSI_LOG_ERROR_RECOVERY(3,
 					scmd_printk(KERN_WARNING, scmd,
-						    "scmd %p finish "
-						    "aborted command\n", scmd));
+						    "finish aborted command\n"));
 				scsi_finish_command(scmd);
 				return;
 			}
 		} else {
 			SCSI_LOG_ERROR_RECOVERY(3,
 				scmd_printk(KERN_INFO, scmd,
-					    "scmd %p abort %s\n", scmd,
+					    "cmd abort %s\n",
 					    (rtn == FAST_IO_FAIL) ?
 					    "not send" : "failed"));
 		}
@@ -167,8 +163,7 @@ scmd_eh_abort_handler(struct work_struct *work)
 	if (!scsi_eh_scmd_add(scmd, 0)) {
 		SCSI_LOG_ERROR_RECOVERY(3,
 			scmd_printk(KERN_WARNING, scmd,
-				    "scmd %p terminate "
-				    "aborted command\n", scmd));
+				    "terminate aborted command\n"));
 		set_host_byte(scmd, DID_TIME_OUT);
 		scsi_finish_command(scmd);
 	}
@@ -194,7 +189,7 @@ scsi_abort_command(struct scsi_cmnd *scmd)
 		scmd->eh_eflags &= ~SCSI_EH_ABORT_SCHEDULED;
 		SCSI_LOG_ERROR_RECOVERY(3,
 			scmd_printk(KERN_INFO, scmd,
-				    "scmd %p previous abort failed\n", scmd));
+				    "previous abort failed\n"));
 		BUG_ON(delayed_work_pending(&scmd->abort_work));
 		return FAILED;
 	}
@@ -208,8 +203,7 @@ scsi_abort_command(struct scsi_cmnd *scmd)
 		spin_unlock_irqrestore(shost->host_lock, flags);
 		SCSI_LOG_ERROR_RECOVERY(3,
 			scmd_printk(KERN_INFO, scmd,
-				    "scmd %p not aborting, host in recovery\n",
-				    scmd));
+				    "not aborting, host in recovery\n"));
 		return FAILED;
 	}
 
@@ -219,8 +213,7 @@ scsi_abort_command(struct scsi_cmnd *scmd)
 
 	scmd->eh_eflags |= SCSI_EH_ABORT_SCHEDULED;
 	SCSI_LOG_ERROR_RECOVERY(3,
-		scmd_printk(KERN_INFO, scmd,
-			    "scmd %p abort scheduled\n", scmd));
+		scmd_printk(KERN_INFO, scmd, "abort scheduled\n"));
 	queue_delayed_work(shost->tmf_work_q, &scmd->abort_work, HZ / 100);
 	return SUCCESS;
 }
@@ -737,8 +730,7 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
 	struct completion *eh_action;
 
 	SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
-			"%s scmd: %p result: %x\n",
-			__func__, scmd, scmd->result));
+			"%s result: %x\n", __func__, scmd->result));
 
 	eh_action = scmd->device->host->eh_action;
 	if (eh_action)
@@ -1052,8 +1044,8 @@ retry:
 	scsi_log_completion(scmd, rtn);
 
 	SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
-			"%s: scmd: %p, timeleft: %ld\n",
-			__func__, scmd, timeleft));
+			"%s timeleft: %ld\n",
+			__func__, timeleft));
 
 	/*
 	 * If there is time left scsi_eh_done got called, and we will examine
@@ -1192,8 +1184,7 @@ int scsi_eh_get_sense(struct list_head *work_q,
 			continue;
 
 		SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
-			"sense requested for %p result %x\n",
-			scmd, scmd->result));
+			"sense requested, result %x\n", scmd->result));
 		SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
 
 		rtn = scsi_decide_disposition(scmd);
@@ -1235,7 +1226,7 @@ retry_tur:
 				scmd->device->eh_timeout, 0);
 
 	SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
-		"%s: scmd %p rtn %x\n", __func__, scmd, rtn));
+		"%s return: %x\n", __func__, rtn));
 
 	switch (rtn) {
 	case NEEDS_RETRY:
@@ -2092,8 +2083,8 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
 		    (++scmd->retries <= scmd->allowed)) {
 			SCSI_LOG_ERROR_RECOVERY(3,
 				scmd_printk(KERN_INFO, scmd,
-					     "%s: flush retry cmd: %p\n",
-					     current->comm, scmd));
+					     "%s: flush retry cmd\n",
+					     current->comm));
 				scsi_queue_insert(scmd, SCSI_MLQUEUE_EH_RETRY);
 		} else {
 			/*
@@ -2105,8 +2096,8 @@ void scsi_eh_flush_done_q(struct list_head *done_q)
 				scmd->result |= (DRIVER_TIMEOUT << 24);
 			SCSI_LOG_ERROR_RECOVERY(3,
 				scmd_printk(KERN_INFO, scmd,
-					     "%s: flush finish cmd: %p\n",
-					     current->comm, scmd));
+					     "%s: flush finish cmd\n",
+					     current->comm));
 			scsi_finish_command(scmd);
 		}
 	}
Signature · 1 line
1.8.4.5
#1 lore raw

PATCH v4 1/9 scsi: Implement per-cpu logging buffer

In reply to Hannes Reinecke

Implement a per-cpu buffer for formatting messages to avoid line break up under high load.
This patch implements scmd_printk() and sdev_prefix_printk() using the per-cpu buffer and makes sdev_printk() a wrapper for sdev_prefix_printk().

---
 drivers/scsi/Makefile       |   2 +-
 drivers/scsi/scsi_logging.c | 124 ++++++++++++++++++++++++++++++++++++++++++++
 include/scsi/scsi_device.h  |  21 +++-----
 3 files changed, 133 insertions(+), 14 deletions(-)
 create mode 100644 drivers/scsi/scsi_logging.c
drivers/scsi/Makefile +1 -1
index 58158f1..447c2d2 100644
@@ -167,7 +167,7 @@ scsi_mod-y			+= scsi_scan.o scsi_sysfs.o scsi_devinfo.o
 scsi_mod-$(CONFIG_SCSI_NETLINK)	+= scsi_netlink.o
 scsi_mod-$(CONFIG_SYSCTL)	+= scsi_sysctl.o
 scsi_mod-$(CONFIG_SCSI_PROC_FS)	+= scsi_proc.o
-scsi_mod-y			+= scsi_trace.o
+scsi_mod-y			+= scsi_trace.o scsi_logging.o
 scsi_mod-$(CONFIG_PM)		+= scsi_pm.o
 
 hv_storvsc-y			:= storvsc_drv.o
drivers/scsi/scsi_logging.c new file +124 -0

124 lines not on this page · raw message

include/scsi/scsi_device.h +8 -13
index 3a4edd1..d1aad4d 100644
@@ -230,9 +230,6 @@ struct scsi_dh_data {
 #define transport_class_to_sdev(class_dev) \
 	to_scsi_device(class_dev->parent)
 
-#define sdev_printk(prefix, sdev, fmt, a...)	\
-	dev_printk(prefix, &(sdev)->sdev_gendev, fmt, ##a)
-
 #define sdev_dbg(sdev, fmt, a...) \
 	dev_dbg(&(sdev)->sdev_gendev, fmt, ##a)
 
@@ -240,16 +237,14 @@ struct scsi_dh_data {
  * like scmd_printk, but the device name is passed in
  * as a string pointer
  */
-#define sdev_prefix_printk(l, sdev, p, fmt, a...)			\
-	(p) ?								\
-	sdev_printk(l, sdev, "[%s] " fmt, p, ##a) :			\
-	sdev_printk(l, sdev, fmt, ##a)
-
-#define scmd_printk(prefix, scmd, fmt, a...)				\
-        (scmd)->request->rq_disk ?					\
-	sdev_printk(prefix, (scmd)->device, "[%s] " fmt,		\
-		    (scmd)->request->rq_disk->disk_name, ##a) :		\
-	sdev_printk(prefix, (scmd)->device, fmt, ##a)
+extern int sdev_prefix_printk(const char *, const struct scsi_device *,
+			      const char *, const char *, ...);
+
+#define sdev_printk(l, sdev, fmt, a...)				\
+	sdev_prefix_printk(l, sdev, NULL, fmt, ##a)
+
+extern int scmd_printk(const char *, const struct scsi_cmnd *,
+		       const char *, ...);
 
 #define scmd_dbg(scmd, fmt, a...)					   \
 	do {								   \
Signature · 1 line
1.8.4.5
#3 lore raw

PATCH v4 2/9 scsi: log request tag for scmd_printk()

In reply to Hannes Reinecke

The request tag provides a concise identification of a SCSI command, so we should be printing that out for scmd_printk().

---
 drivers/scsi/scsi_logging.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/scsi/scsi_logging.c +4 -0
index 09d65de..4d20132 100644
@@ -114,6 +114,10 @@ int scmd_printk(const char *level, const struct scsi_cmnd *scmd,
 	if (disk)
 		off += scnprintf(logbuf + off, logbuf_len - off,
 				 "[%s] ", disk->disk_name);
+
+	if (scmd->request->tag >= 0)
+		off += scnprintf(logbuf + off, logbuf_len - off,
+				 "tag#%d ", scmd->request->tag);
 	va_start(args, fmt);
 	off += vscnprintf(logbuf + off, logbuf_len - off, fmt, args);
 	va_end(args);
Signature · 1 line
1.8.4.5
#8 lore raw

PATCH v4 4/9 libata: use __scsi_format_command()

In reply to Hannes Reinecke

libata already uses an internal buffer, so we should be using __scsi_format_command() here.

---
 drivers/ata/libata-eh.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/ata/libata-eh.c +7 -10
index 3dbec89..9179f11 100644
@@ -2482,6 +2482,7 @@ static void ata_eh_link_report(struct ata_link *link)
 		struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
 		struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
 		const u8 *cdb = qc->cdb;
+		size_t cdb_len = qc->dev->cdb_len;
 		char data_buf[20] = "";
 		char cdb_buf[70] = "";
 
@@ -2509,16 +2510,12 @@ static void ata_eh_link_report(struct ata_link *link)
 		}
 
 		if (ata_is_atapi(qc->tf.protocol)) {
-			if (qc->scsicmd)
-				scsi_print_command(qc->scsicmd);
-			else
-				snprintf(cdb_buf, sizeof(cdb_buf),
-				 "cdb %02x %02x %02x %02x %02x %02x %02x %02x  "
-				 "%02x %02x %02x %02x %02x %02x %02x %02x\n         ",
-				 cdb[0], cdb[1], cdb[2], cdb[3],
-				 cdb[4], cdb[5], cdb[6], cdb[7],
-				 cdb[8], cdb[9], cdb[10], cdb[11],
-				 cdb[12], cdb[13], cdb[14], cdb[15]);
+			if (qc->scsicmd) {
+				cdb = qc->scsicmd->cmnd;
+				cdb_len = qc->scsicmd->cmd_len;
+			}
+			__scsi_format_command(cdb_buf, sizeof(cdb_buf),
+					      cdb, cdb_len);
 		} else {
 			const char *descr = ata_get_cmd_descript(cmd->command);
 			if (descr)
Signature · 1 line
1.8.4.5
#9 lore raw

PATCH v4 5/9 scsi: use per-cpu buffer for formatting sense

In reply to Hannes Reinecke

Convert sense buffer logging to use the per-cpu buffer to avoid line breakup.

---
 drivers/scsi/constants.c    | 107 ----------------------------
 drivers/scsi/scsi_logging.c | 166 +++++++++++++++++++++++++++++++++++++++++---
 drivers/scsi/sd.c           |   7 +-
 drivers/scsi/ufs/ufshcd.c   |   6 +-
 4 files changed, 161 insertions(+), 125 deletions(-)
drivers/scsi/constants.c +0 -107
index 7792960..a23ef75 100644
@@ -1246,113 +1246,6 @@ scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
 }
 EXPORT_SYMBOL(scsi_extd_sense_format);
 
-void
-scsi_show_extd_sense(const struct scsi_device *sdev, const char *name,
-		     unsigned char asc, unsigned char ascq)
-{
-	const char *extd_sense_fmt = NULL;
-	const char *extd_sense_str = scsi_extd_sense_format(asc, ascq,
-							    &extd_sense_fmt);
-
-	if (extd_sense_str) {
-		if (extd_sense_fmt)
-			sdev_prefix_printk(KERN_INFO, sdev, name,
-					   "Add. Sense: %s (%s%x)",
-					   extd_sense_str, extd_sense_fmt,
-					   ascq);
-		else
-			sdev_prefix_printk(KERN_INFO, sdev, name,
-					   "Add. Sense: %s", extd_sense_str);
-
-	} else {
-		sdev_prefix_printk(KERN_INFO, sdev, name,
-				   "%sASC=0x%x %sASCQ=0x%x\n",
-				   asc >= 0x80 ? "<<vendor>> " : "", asc,
-				   ascq >= 0x80 ? "<<vendor>> " : "", ascq);
-	}
-}
-EXPORT_SYMBOL(scsi_show_extd_sense);
-
-void
-scsi_show_sense_hdr(const struct scsi_device *sdev, const char *name,
-		    const struct scsi_sense_hdr *sshdr)
-{
-	const char *sense_txt;
-
-	sense_txt = scsi_sense_key_string(sshdr->sense_key);
-	if (sense_txt)
-		sdev_prefix_printk(KERN_INFO, sdev, name,
-				   "Sense Key : %s [%s]%s\n", sense_txt,
-				   scsi_sense_is_deferred(sshdr) ?
-				   "deferred" : "current",
-				   sshdr->response_code >= 0x72 ?
-				   " [descriptor]" : "");
-	else
-		sdev_prefix_printk(KERN_INFO, sdev, name,
-				   "Sense Key : 0x%x [%s]%s", sshdr->sense_key,
-				   scsi_sense_is_deferred(sshdr) ?
-				   "deferred" : "current",
-				   sshdr->response_code >= 0x72 ?
-				   " [descriptor]" : "");
-}
-EXPORT_SYMBOL(scsi_show_sense_hdr);
-
-/*
- * Print normalized SCSI sense header with a prefix.
- */
-void
-scsi_print_sense_hdr(const struct scsi_device *sdev, const char *name,
-		     const struct scsi_sense_hdr *sshdr)
-{
-	scsi_show_sense_hdr(sdev, name, sshdr);
-	scsi_show_extd_sense(sdev, name, sshdr->asc, sshdr->ascq);
-}
-EXPORT_SYMBOL(scsi_print_sense_hdr);
-
-static void
-scsi_dump_sense_buffer(const unsigned char *sense_buffer, int sense_len)
-{
-	int k, num;
-
-	num = (sense_len < 32) ? sense_len : 32;
-	printk("Unrecognized sense data (in hex):");
-	for (k = 0; k < num; ++k) {
-		if (0 == (k % 16)) {
-			printk("\n");
-			printk(KERN_INFO "        ");
-		}
-		printk("%02x ", sense_buffer[k]);
-	}
-	printk("\n");
-	return;
-}
-
-/* Normalize and print sense buffer with name prefix */
-void __scsi_print_sense(const struct scsi_device *sdev, const char *name,
-			const unsigned char *sense_buffer, int sense_len)
-{
-	struct scsi_sense_hdr sshdr;
-
-	if (!scsi_normalize_sense(sense_buffer, sense_len, &sshdr)) {
-		scsi_dump_sense_buffer(sense_buffer, sense_len);
-		return;
-	}
-	scsi_show_sense_hdr(sdev, name, &sshdr);
-	scsi_show_extd_sense(sdev, name, sshdr.asc, sshdr.ascq);
-}
-EXPORT_SYMBOL(__scsi_print_sense);
-
-/* Normalize and print sense buffer in SCSI command */
-void scsi_print_sense(const struct scsi_cmnd *cmd)
-{
-	struct gendisk *disk = cmd->request->rq_disk;
-	const char *disk_name = disk ? disk->disk_name : NULL;
-
-	__scsi_print_sense(cmd->device, disk_name, cmd->sense_buffer,
-			   SCSI_SENSE_BUFFERSIZE);
-}
-EXPORT_SYMBOL(scsi_print_sense);
-
 #ifdef CONFIG_SCSI_CONSTANTS
 
 static const char * const hostbyte_table[]={
drivers/scsi/scsi_logging.c +157 -9

209 lines not on this page · raw message

drivers/scsi/sd.c +2 -5
index 3995169..ebf35cb6 100644
@@ -3318,11 +3318,8 @@ module_exit(exit_sd);
 static void sd_print_sense_hdr(struct scsi_disk *sdkp,
 			       struct scsi_sense_hdr *sshdr)
 {
-	scsi_show_sense_hdr(sdkp->device,
-			    sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr);
-	scsi_show_extd_sense(sdkp->device,
-			     sdkp->disk ? sdkp->disk->disk_name : NULL,
-			     sshdr->asc, sshdr->ascq);
+	scsi_print_sense_hdr(sdkp->device,
+			     sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr);
 }
 
 static void sd_print_result(const struct scsi_disk *sdkp, const char *msg,
drivers/scsi/ufs/ufshcd.c +2 -4
index 2e4614b..5d60a86 100644
@@ -4714,10 +4714,8 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
 		sdev_printk(KERN_WARNING, sdp,
 			    "START_STOP failed for power mode: %d, result %x\n",
 			    pwr_mode, ret);
-		if (driver_byte(ret) & DRIVER_SENSE) {
-			scsi_show_sense_hdr(sdp, NULL, &sshdr);
-			scsi_show_extd_sense(sdp, NULL, sshdr.asc, sshdr.ascq);
-		}
+		if (driver_byte(ret) & DRIVER_SENSE)
+			scsi_print_sense_hdr(sdp, NULL, &sshdr);
 	}
 
 	if (!ret)
Signature · 1 line
1.8.4.5
#10 lore raw

PATCH v4 6/9 scsi: use per-cpu buffer for formatting scsi_print_result()

In reply to Hannes Reinecke

Convert scsi_print_result() to use the per-cpu buffer for decoding the command result and disposition.

---
 drivers/scsi/constants.c    | 22 -----------------
 drivers/scsi/scsi.c         |  2 +-
 drivers/scsi/scsi_logging.c | 59 +++++++++++++++++++++++++++++++++++++++++++++
 include/scsi/scsi_dbg.h     |  2 +-
 4 files changed, 61 insertions(+), 24 deletions(-)
drivers/scsi/constants.c +0 -22
index a23ef75..956fbdd 100644
@@ -1316,25 +1316,3 @@ const char *scsi_mlreturn_string(int result)
 	return NULL;
 }
 EXPORT_SYMBOL(scsi_mlreturn_string);
-
-void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
-{
-	const char *mlret_string = scsi_mlreturn_string(disposition);
-	const char *hb_string = scsi_hostbyte_string(cmd->result);
-	const char *db_string = scsi_driverbyte_string(cmd->result);
-
-	if (hb_string || db_string)
-		scmd_printk(KERN_INFO, cmd,
-			    "%s%s Result: hostbyte=%s driverbyte=%s",
-			    msg ? msg : "",
-			    mlret_string ? mlret_string : "UNKNOWN",
-			    hb_string ? hb_string : "invalid",
-			    db_string ? db_string : "invalid");
-	else
-		scmd_printk(KERN_INFO, cmd,
-			    "%s%s Result: hostbyte=0x%02x driverbyte=0x%02x",
-			    msg ? msg : "",
-			    mlret_string ? mlret_string : "UNKNOWN",
-			    host_byte(cmd->result), driver_byte(cmd->result));
-}
-EXPORT_SYMBOL(scsi_print_result);
drivers/scsi/scsi.c +1 -1
index e028854..7f028cb 100644
@@ -572,7 +572,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
 				       SCSI_LOG_MLCOMPLETE_BITS);
 		if (((level > 0) && (cmd->result || disposition != SUCCESS)) ||
 		    (level > 1)) {
-			scsi_print_result(cmd, "Done: ", disposition);
+			scsi_print_result(cmd, "Done", disposition);
 			scsi_print_command(cmd);
 			if (status_byte(cmd->result) & CHECK_CONDITION)
 				scsi_print_sense(cmd);
drivers/scsi/scsi_logging.c +59 -0

62 lines not on this page · raw message

include/scsi/scsi_dbg.h +1 -1
index c7ed7b8..365b674 100644
@@ -21,7 +21,7 @@ extern void scsi_print_sense(const struct scsi_cmnd *);
 extern void __scsi_print_sense(const struct scsi_device *, const char *name,
 			       const unsigned char *sense_buffer,
 			       int sense_len);
-extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
+extern void scsi_print_result(const struct scsi_cmnd *, const char *, int);
 extern const char *scsi_hostbyte_string(int);
 extern const char *scsi_driverbyte_string(int);
 extern const char *scsi_mlreturn_string(int);
Signature · 1 line
1.8.4.5
Reviewed-by on v4 9/9
#14 lore raw

RE: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

In reply to Hannes Reinecke
Quoted 28 lines

-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Hannes Reinecke
Sent: Thursday, January 08, 2015 12:44 AM
To: James Bottomley
Cc: Christoph Hellwig; [email protected]; Hannes Reinecke
Subject: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

---
 drivers/scsi/scsi_error.c | 49 +++++++++++++++++++---------------------
-------
 1 file changed, 20 insertions(+), 29 deletions(-)
drivers/scsi/scsi_error.c +0 -0
index e42fff6..10ffa21 100644
@@ -124,41 +124,37 @@ scmd_eh_abort_handler(struct work_struct *work)

...

drivers/scsi/scsi_error.c scmd_eh_abort_handler(struct work_struct *work) · line 139

Quoted 7 lines
drivers/scsi/scsi_error.c +2 -3
 				SCSI_LOG_ERROR_RECOVERY(3,
 					scmd_printk(KERN_INFO, scmd,
-						    "scmd %p eh timeout, "
-						    "not retrying aborted "
-						    "command\n", scmd));
+						    "eh timeout, not retrying "
+						    "aborted command\n"));

checkpatch allows/encourages keeping strings on one line even when they go past the 80th column. So, I recommend joining those two lines.

#15 lore raw

Re: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

Quoted 29 lines · Robert (Server Storage)
Quoted 28 lines

-----Original Message-----
From: [email protected] [mailto:linux-scsi- [email protected]] On Behalf Of Hannes Reinecke
Sent: Thursday, January 08, 2015 12:44 AM
To: James Bottomley
Cc: Christoph Hellwig; [email protected]; Hannes Reinecke
Subject: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

---
  drivers/scsi/scsi_error.c | 49 +++++++++++++++++++---------------------
-------
  1 file changed, 20 insertions(+), 29 deletions(-)
drivers/scsi/scsi_error.c +0 -0
index e42fff6..10ffa21 100644
@@ -124,41 +124,37 @@ scmd_eh_abort_handler(struct work_struct *work)

...

Quoted 11 lines

drivers/scsi/scsi_error.c scmd_eh_abort_handler(struct work_struct *work) · line 139

Quoted 7 lines

SCSI_LOG_ERROR_RECOVERY(3,
scmd_printk(KERN_INFO, scmd,

drivers/scsi/scsi_error.c +2 -3
-						    "scmd %p eh timeout, "
-						    "not retrying aborted "
-						    "command\n", scmd));
+						    "eh timeout, not retrying "
+						    "aborted command\n"));

checkpatch allows/encourages keeping strings on one line even when they go past the 80th column. So, I recommend joining those two lines.

Which in turn conflicts with cleanfile which is another kernel supplied utility. So I would suggest checkpatch should back off with that particular warning (and several other of its nags). Also new code (say a complete new function) should be treated differently compared to a patch (e.g. the 2 lines shown above) on existing code.

I use cleanfile in the user space since it warns of lines greater than 79 characters and trims trailing spaces (whitespaces ?) from the end of a line. And I would never use checkpatch in the user space since the coherence of the resulting source is much more important than the route to get there :-)

Doug Gilbert

#16 lore raw

Re: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

In reply to Hannes Reinecke
Quoted 6 lines · Hannes Reinecke

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

I'd actually be sad to see this go -- I have found it useful in the past when debugging crash dumps from customer sites to be able to look in the kernel messages and see that a particular scsi_cmnd had been aborted just before the crash (and then later completed).

-Ewan

#17 lore raw

Re: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

Quoted 8 lines · Ewan Milne
Quoted 6 lines · Hannes Reinecke

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

Quoted 6 lines

I'd actually be sad to see this go -- I have found it useful in the past when debugging crash dumps from customer sites to be able to look in the kernel messages and see that a particular scsi_cmnd had been aborted just before the crash (and then later completed).

But that's precisely why we've prefixed the scmd messages with the tag number; with that you'll be able to extract the same information.

And now that hch separated out the block layer tagging from SCSI-2 TCQ we should have the tag number available for any command, not just those from drivers which use TCQ.

Let me know if that isn't the case; this patch indeed only makes sense if the tag number is always available.

Cheers,

Hannes

Signature · 9 lines
Dr. Hannes Reinecke		               zSeries & Storage
[email protected]			               +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw

Re: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

Quoted 18 lines · Hannes Reinecke
Quoted 8 lines · Ewan Milne
Quoted 6 lines · Hannes Reinecke

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

Quoted 6 lines

I'd actually be sad to see this go -- I have found it useful in the past when debugging crash dumps from customer sites to be able to look in the kernel messages and see that a particular scsi_cmnd had been aborted just before the crash (and then later completed).

But that's precisely why we've prefixed the scmd messages with the tag number; with that you'll be able to extract the same information.

Quoted 6 lines

And now that hch separated out the block layer tagging from SCSI-2 TCQ we should have the tag number available for any command, not just those from drivers which use TCQ.

Let me know if that isn't the case; this patch indeed only makes sense if the tag number is always available.

Ah, yes, I think you may be right -- I ran into this when debugging some double completion panics, so my concern is whether the tag field remains valid after it completes the first time. I'll check.

-Ewan

Reviewed-by
#19 lore raw

Re: [PATCH 9/9] scsi_error: do not display kernel pointer in message logs

Quoted 23 lines · Ewan Milne
Quoted 22 lines · Hannes Reinecke
Quoted 8 lines · Ewan Milne
Quoted 6 lines · Hannes Reinecke

It is not good practice to display the kernel pointer in any message logs, and it doesn't display any additional information. And as we know have block-layer assigned tags we can use them to differentiate the messages.
So remove any pointer references from the displayed messages.

Quoted 6 lines

I'd actually be sad to see this go -- I have found it useful in the past when debugging crash dumps from customer sites to be able to look in the kernel messages and see that a particular scsi_cmnd had been aborted just before the crash (and then later completed).

But that's precisely why we've prefixed the scmd messages with the tag number; with that you'll be able to extract the same information.

And now that hch separated out the block layer tagging from SCSI-2 TCQ we should have the tag number available for any command, not just those from drivers which use TCQ.

Quoted 6 lines
Quoted 2 lines

Let me know if that isn't the case; this patch indeed only makes sense if the tag number is always available.

Ah, yes, I think you may be right -- I ran into this when debugging some double completion panics, so my concern is whether the tag field remains valid after it completes the first time. I'll check.

Looks like if the scmd completes twice, the req could be getting reused, so scmd->request->tag might be different. However, for crash analysis, scmd->tag gets a copy of the request tag so that would be good enough to match up with an earlier logged abort message.

#2 lore raw

Re: [PATCH 1/9] scsi: Implement per-cpu logging buffer

In reply to Hannes Reinecke

include/scsi/scsi_device.h struct scsi_dh_data { · line 250

Quoted 12 lines · Hannes Reinecke
include/scsi/scsi_device.h +8 -1
-	sdev_printk(prefix, (scmd)->device, fmt, ##a)
+extern int sdev_prefix_printk(const char *, const struct scsi_device *,
+			      const char *, const char *, ...);
+
+#define sdev_printk(l, sdev, fmt, a...)				\
+	sdev_prefix_printk(l, sdev, NULL, fmt, ##a)
+
+extern int scmd_printk(const char *, const struct scsi_cmnd *,
+		       const char *, ...);
 
 #define scmd_dbg(scmd, fmt, a...)					   \
 	do {								   \

These new prototypes need to be printf format checked, otherwise you lose us some type checking that gcc was doing:

extern __printf(4, 5)
int sdev_prefix_printk(const char *, const struct scsi_device *,

		      const char *, const char *, ...);

James

#5 lore raw

Re: [PATCH 3/9] scsi: use external buffer for command logging

In reply to Hannes Reinecke
Quoted 28 lines · Hannes Reinecke

Use an external buffer for __scsi_print_command() and move command logging over to use the per-cpu logging buffer. With that we can guarantee the command always will always be formatted in one line.
So we can even print out a variable length command correctly across several lines.
Finally rename __scsi_print_command() to __scsi_format_comment() to better reflect the functionality.

---
 drivers/scsi/ch.c           |   6 +-
 drivers/scsi/constants.c    |  74 +-----------------
 drivers/scsi/scsi_logging.c | 182 ++++++++++++++++++++++++++++++++++++++++----
 drivers/scsi/sr_ioctl.c     |  13 +++-
 include/scsi/scsi.h         |   3 +
 include/scsi/scsi_dbg.h     |   6 +-
 6 files changed, 192 insertions(+), 92 deletions(-)
drivers/scsi/ch.c +0 -0
index 6bac8a7..79e462f 100644

drivers/scsi/ch.c ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, · line 201

Quoted 9 lines
drivers/scsi/ch.c +4 -2
@@ -195,8 +195,10 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
  retry:
 	errno = 0;
 	if (debug) {
-		DPRINTK("command: ");
-		__scsi_print_command(cmd, cmd_len);
+		char logbuf[SCSI_LOG_BUFSIZE];
+
+		__scsi_format_command(logbuf, sizeof(logbuf), cmd, cmd_len);
+		DPRINTK("command: %s", logbuf);

I really hate using an on-stack buffer here ... we're pretty deep in the call chain already.

Since it's just required for printing a "command: " prefix, why not just use scsi_print_command()?

drivers/scsi/sr_ioctl.c int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) · line 191

Quoted 9 lines
drivers/scsi/sr_ioctl.c +1 -0
index fb929fa..e8deb9c 100644
@@ -188,6 +188,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
        struct scsi_sense_hdr sshdr;
        int result, err = 0, retries = 0;
        struct request_sense *sense = cgc->sense;
+       char logbuf[SCSI_LOG_BUFSIZE];

Same issue here.

drivers/scsi/sr_ioctl.c int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) · line 265

Quoted 12 lines
drivers/scsi/sr_ioctl.c +5 -1
        SDev = cd->device;
 
@@ -257,14 +258,20 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
                                /* sense: Invalid command operation code */
                                err = -EDRIVE_CANT_DO_THIS;
 #ifdef DEBUG
-                       __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
+                       __scsi_format_command(logbuf, sizeof(logbuf),
+                                             cgc->cmd, CDROM_PACKET_SIZE);
+                       sr_printk(KERN_INFO, cd,
+                                 "CDROM (ioctl) invalid command: %s\n",
+                                 logbuf);

Looks like scsi_print_command() will work here too.

drivers/scsi/sr_ioctl.c int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) · line 274

Quoted 11 lines
drivers/scsi/sr_ioctl.c +4 -2
                        scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
 #endif
                        break;
                default:
+                       __scsi_format_command(logbuf, sizeof(logbuf),
+                                             cgc->cmd, CDROM_PACKET_SIZE);
                        sr_printk(KERN_ERR, cd,
-                                 "CDROM (ioctl) error, command: ");
-                       __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
+                                 "CDROM (ioctl) error, command: %s\n",
+                                 logbuf);

And realistically here (with the appropriate sdev_print()'s preceding).

drivers/scsi/sr_ioctl.c int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc) · line 277

Quoted 3 lines
drivers/scsi/sr_ioctl.c +0 -0
                        scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
                        err = -EIO;
                }

James

#6 lore raw

Re: [PATCH 3/9] scsi: use external buffer for command logging

Quoted 5 lines · James Bottomley

I really hate using an on-stack buffer here ... we're pretty deep in the call chain already.

Since it's just required for printing a "command: " prefix, why not just use scsi_print_command()?

Both the ch and sr callers are not really a problem in terms of stack usage, as they are directly in file operations of character or block devices, so the whole FS/MM stack stack problem isn't an issue.

But using higher level functions might still be useful here.

#7 lore raw

Re: [PATCH 3/9] scsi: use external buffer for command logging

Quoted 10 lines · On Wed, 2015-01-14 at 10:36 +0100, [email protected] wrote:
Quoted 5 lines · James Bottomley

I really hate using an on-stack buffer here ... we're pretty deep in the call chain already.

Since it's just required for printing a "command: " prefix, why not just use scsi_print_command()?

Both the ch and sr callers are not really a problem in terms of stack usage, as they are directly in file operations of character or block devices, so the whole FS/MM stack stack problem isn't an issue.

Trying to calculate minutely how much additional overhead there is isn't really the point. The point is we can just use a different function that doesn't consume the on stack buffer, so we should, just as a matter of best practise. I agree it would have been a more finely balanced problem if we definitely needed the allocation

Quoted 1 line

But using higher level functions might still be useful here.

James