Skip to contentSkip to conversation

convert sd to scsi_execute_req (and update the scsi_execute_req API)

PATCH New James Bottomley 1 participant 1 message Jun 11, 2005 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert sd to scsi_execute_req (and update the scsi_execute_req API)

This one removes struct scsi_request entirely from sd. In the process, I noticed we have no callers of scsi_wait_req who don't immediately normalise the sense, so I updated the API to make it take a struct scsi_sense_hdr instead of simply a big sense buffer.

James

drivers/scsi/constants.c +26 -22
@@ -1155,6 +1155,31 @@ scsi_show_extd_sense(unsigned char asc, 
 	}
 }
 
+void
+scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr)
+{
+	const char *sense_txt;
+	/* An example of deferred is when an earlier write to disk cache
+	 * succeeded, but now the disk discovers that it cannot write the
+	 * data to the magnetic media.
+	 */
+	const char *error = scsi_sense_is_deferred(sshdr) ? 
+		"<<DEFERRED>>" : "Current";
+	printk(KERN_INFO "%s: %s", name, error);
+	if (sshdr->response_code >= 0x72)
+		printk(" [descriptor]");
+
+	sense_txt = scsi_sense_key_string(sshdr->sense_key);
+	if (sense_txt)
+		printk(": sense key: %s\n", sense_txt);
+	else
+		printk(": sense key=0x%x\n", sshdr->sense_key);
+	printk(KERN_INFO "    ");
+	scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
+	printk("\n");
+}
+EXPORT_SYMBOL(scsi_print_sense_hdr);
+
 /* Print sense information */
 void
 __scsi_print_sense(const char *name, const unsigned char *sense_buffer,
@@ -1162,8 +1187,6 @@ __scsi_print_sense(const char *name, con
 {
 	int k, num, res;
 	unsigned int info;
-	const char *error;
-	const char *sense_txt;
 	struct scsi_sense_hdr ssh;
     
 	res = scsi_normalize_sense(sense_buffer, sense_len, &ssh);
@@ -1181,26 +1204,7 @@ __scsi_print_sense(const char *name, con
 		printk("\n");
 		return;
 	}
-
-	/* An example of deferred is when an earlier write to disk cache
-	 * succeeded, but now the disk discovers that it cannot write the
-	 * data to the magnetic media.
-	 */
-	error = scsi_sense_is_deferred(&ssh) ? 
-			"<<DEFERRED>>" : "Current";
-	printk(KERN_INFO "%s: %s", name, error);
-	if (ssh.response_code >= 0x72)
-		printk(" [descriptor]");
-
-	sense_txt = scsi_sense_key_string(ssh.sense_key);
-	if (sense_txt)
-		printk(": sense key: %s\n", sense_txt);
-	else
-		printk(": sense key=0x%x\n", ssh.sense_key);
-	printk(KERN_INFO "    ");
-	scsi_show_extd_sense(ssh.asc, ssh.ascq);
-	printk("\n");
-
+	scsi_print_sense_hdr(name, &ssh);
 	if (ssh.response_code < 0x72) {
 		/* only decode extras for "fixed" format now */
 		char buff[80];
drivers/scsi/scsi_ioctl.c +6 -9
@@ -90,19 +90,16 @@ static int ioctl_internal_command(struct
 {
 	int result;
 	struct scsi_sense_hdr sshdr;
-	char sense[SCSI_SENSE_BUFFERSIZE];
 
 	SCSI_LOG_IOCTL(1, printk("Trying ioctl with scsi command %d\n", *cmd));
 
-
-	memset(sense, 0, sizeof(*sense));
 	result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
-				  sense, timeout, retries);
+				  &sshdr, timeout, retries);
 
 	SCSI_LOG_IOCTL(2, printk("Ioctl returned  0x%x\n", result));
 
 	if ((driver_byte(result) & DRIVER_SENSE) &&
-	    (scsi_normalize_sense(sense, sizeof(*sense), &sshdr))) {
+	    (scsi_sense_valid(&sshdr))) {
 		switch (sshdr.sense_key) {
 		case ILLEGAL_REQUEST:
 			if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
@@ -132,7 +129,7 @@ static int ioctl_internal_command(struct
 			       sdev->id,
 			       sdev->lun,
 			       result);
-			__scsi_print_sense("   ", sense, sizeof(*sense));
+			scsi_print_sense_hdr("   ", &sshdr);
 			break;
 		}
 	}
@@ -315,9 +312,9 @@ int scsi_ioctl_send_command(struct scsi_
 		break;
 	}
 
-	result = scsi_execute_req(sdev, cmd, data_direction, buf, needed,
-				  sense, timeout, retries);
-				  
+	result = scsi_execute(sdev, cmd, data_direction, buf, needed,
+			      sense, timeout, retries, 0);
+
 	/* 
 	 * If there was an error condition, pass the info back to the user. 
 	 */
drivers/scsi/scsi_lib.c +39 -28

136 lines not on this page · raw message

drivers/scsi/scsi_scan.c +4 -9
@@ -432,7 +432,6 @@ void scsi_target_reap(struct scsi_target
 static int scsi_probe_lun(struct scsi_device *sdev, char *inq_result,
 			  int result_len, int *bflags)
 {
-	char sense[SCSI_SENSE_BUFFERSIZE];
 	unsigned char scsi_cmd[MAX_COMMAND_SIZE];
 	int first_inquiry_len, try_inquiry_len, next_inquiry_len;
 	int response_len = 0;
@@ -460,11 +459,10 @@ static int scsi_probe_lun(struct scsi_de
 		scsi_cmd[0] = INQUIRY;
 		scsi_cmd[4] = (unsigned char) try_inquiry_len;
 
-		memset(sense, 0, sizeof(sense));
 		memset(inq_result, 0, try_inquiry_len);
 
 		result = scsi_execute_req(sdev,  scsi_cmd, DMA_FROM_DEVICE,
-					  inq_result, try_inquiry_len, sense,
+					  inq_result, try_inquiry_len, &sshdr,
 					  HZ / 2 + HZ * scsi_inq_timeout, 3);
 
 		SCSI_LOG_SCAN_BUS(3, printk(KERN_INFO "scsi scan: INQUIRY %s "
@@ -479,8 +477,7 @@ static int scsi_probe_lun(struct scsi_de
 			 * but many buggy devices do so anyway. 
 			 */
 			if ((driver_byte(result) & DRIVER_SENSE) &&
-			    scsi_normalize_sense(sense, sizeof(sense),
-						 &sshdr)) {
+			    scsi_sense_valid(&sshdr)) {
 				if ((sshdr.sense_key == UNIT_ATTENTION) &&
 				    ((sshdr.asc == 0x28) ||
 				     (sshdr.asc == 0x29)) &&
@@ -1010,7 +1007,6 @@ static int scsi_report_lun_scan(struct s
 				int rescan)
 {
 	char devname[64];
-	char sense[SCSI_SENSE_BUFFERSIZE];
 	unsigned char scsi_cmd[MAX_COMMAND_SIZE];
 	unsigned int length;
 	unsigned int lun;
@@ -1087,9 +1083,8 @@ static int scsi_report_lun_scan(struct s
 				" REPORT LUNS to %s (try %d)\n", devname,
 				retries));
 
-		memset(sense, 0, sizeof(sense));
 		result = scsi_execute_req(sdev, scsi_cmd, DMA_FROM_DEVICE,
-					  lun_data, length, sense,
+					  lun_data, length, &sshdr,
 					  SCSI_TIMEOUT + 4 * HZ, 3);
 
 		SCSI_LOG_SCAN_BUS(3, printk (KERN_INFO "scsi scan: REPORT LUNS"
@@ -1097,7 +1092,7 @@ static int scsi_report_lun_scan(struct s
 				?  "failed" : "successful", retries, result));
 		if (result == 0)
 			break;
-		else if (scsi_normalize_sense(sense, sizeof(sense), &sshdr)) {
+		else if (scsi_sense_valid(&sshdr)) {
 			if (sshdr.sense_key != UNIT_ATTENTION)
 				break;
 		}
drivers/scsi/sd.c +64 -96

377 lines not on this page · raw message

include/scsi/scsi_dbg.h +2 -0
@@ -3,8 +3,10 @@
 
 struct scsi_cmnd;
 struct scsi_request;
+struct scsi_sense_hdr;
 
 extern void scsi_print_command(struct scsi_cmnd *);
+extern void scsi_print_sense_hdr(const char *, struct scsi_sense_hdr *);
 extern void __scsi_print_command(unsigned char *);
 extern void scsi_print_sense(const char *, struct scsi_cmnd *);
 extern void scsi_print_req_sense(const char *, struct scsi_request *);
include/scsi/scsi_device.h +5 -9
@@ -8,6 +8,7 @@
 
 struct request_queue;
 struct scsi_cmnd;
+struct scsi_sense_hdr;
 
 struct scsi_mode_data {
 	__u32	length;
@@ -236,7 +237,7 @@ extern int scsi_set_medium_removal(struc
 extern int scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
 			   unsigned char *buffer, int len, int timeout,
 			   int retries, struct scsi_mode_data *data,
-			   char *sense);
+			   struct scsi_sense_hdr *);
 extern int scsi_test_unit_ready(struct scsi_device *sdev, int timeout,
 				int retries);
 extern int scsi_device_set_state(struct scsi_device *sdev,
@@ -258,15 +259,10 @@ extern int scsi_execute(struct scsi_devi
 			int data_direction, void *buffer, unsigned bufflen,
 			unsigned char *sense, int timeout, int retries,
 			int flag);
+extern int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
+			    int data_direction, void *buffer, unsigned bufflen,
+			    struct scsi_sense_hdr *, int timeout, int retries);
 
-static inline int
-scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd,
-		 int data_direction, void *buffer, unsigned bufflen,
-		 unsigned char *sense, int timeout, int retries)
-{
-	return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense,
-			    timeout, retries, 0);
-}
 static inline int scsi_device_online(struct scsi_device *sdev)
 {
 	return sdev->sdev_state != SDEV_OFFLINE;