Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: merge __scsi_execute into scsi_execute

All but one caller want the decoded sense header, so offer the existing
__scsi_execute helper as the public scsi_execute API to simply the
callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Christoph Hellwig and committed by
Martin K. Petersen
76aaf87b 3949e2f0

+46 -74
+4 -8
drivers/ata/libata-scsi.c
··· 600 600 u8 args[4], *argbuf = NULL, *sensebuf = NULL; 601 601 int argsize = 0; 602 602 enum dma_data_direction data_dir; 603 + struct scsi_sense_hdr sshdr; 603 604 int cmd_result; 604 605 605 606 if (arg == NULL) ··· 649 648 /* Good values for timeout and retries? Values below 650 649 from scsi_ioctl_send_command() for default case... */ 651 650 cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, 652 - sensebuf, (10*HZ), 5, 0, NULL); 651 + sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); 653 652 654 653 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ 655 654 u8 *desc = sensebuf + 8; ··· 658 657 /* If we set cc then ATA pass-through will cause a 659 658 * check condition even if no error. Filter that. */ 660 659 if (cmd_result & SAM_STAT_CHECK_CONDITION) { 661 - struct scsi_sense_hdr sshdr; 662 - scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, 663 - &sshdr); 664 660 if (sshdr.sense_key == RECOVERED_ERROR && 665 661 sshdr.asc == 0 && sshdr.ascq == 0x1d) 666 662 cmd_result &= ~SAM_STAT_CHECK_CONDITION; ··· 705 707 int rc = 0; 706 708 u8 scsi_cmd[MAX_COMMAND_SIZE]; 707 709 u8 args[7], *sensebuf = NULL; 710 + struct scsi_sense_hdr sshdr; 708 711 int cmd_result; 709 712 710 713 if (arg == NULL) ··· 733 734 /* Good values for timeout and retries? Values below 734 735 from scsi_ioctl_send_command() for default case... */ 735 736 cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, 736 - sensebuf, (10*HZ), 5, 0, NULL); 737 + sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); 737 738 738 739 if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ 739 740 u8 *desc = sensebuf + 8; ··· 742 743 /* If we set cc then ATA pass-through will cause a 743 744 * check condition even if no error. Filter that. */ 744 745 if (cmd_result & SAM_STAT_CHECK_CONDITION) { 745 - struct scsi_sense_hdr sshdr; 746 - scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, 747 - &sshdr); 748 746 if (sshdr.sense_key == RECOVERED_ERROR && 749 747 sshdr.asc == 0 && sshdr.ascq == 0x1d) 750 748 cmd_result &= ~SAM_STAT_CHECK_CONDITION;
+3 -5
drivers/scsi/cxlflash/superpipe.c
··· 305 305 struct cxlflash_cfg *cfg = shost_priv(sdev->host); 306 306 struct device *dev = &cfg->dev->dev; 307 307 struct glun_info *gli = lli->parent; 308 + struct scsi_sense_hdr sshdr; 308 309 u8 *cmd_buf = NULL; 309 310 u8 *scsi_cmd = NULL; 310 311 u8 *sense_buf = NULL; ··· 333 332 /* Drop the ioctl read semahpore across lengthy call */ 334 333 up_read(&cfg->ioctl_rwsem); 335 334 result = scsi_execute(sdev, scsi_cmd, DMA_FROM_DEVICE, cmd_buf, 336 - CMD_BUFSIZE, sense_buf, to, CMD_RETRIES, 0, NULL); 335 + CMD_BUFSIZE, sense_buf, &sshdr, to, CMD_RETRIES, 336 + 0, 0, NULL); 337 337 down_read(&cfg->ioctl_rwsem); 338 338 rc = check_state(cfg); 339 339 if (rc) { ··· 347 345 if (driver_byte(result) == DRIVER_SENSE) { 348 346 result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ 349 347 if (result & SAM_STAT_CHECK_CONDITION) { 350 - struct scsi_sense_hdr sshdr; 351 - 352 - scsi_normalize_sense(sense_buf, SCSI_SENSE_BUFFERSIZE, 353 - &sshdr); 354 348 switch (sshdr.sense_key) { 355 349 case NO_SENSE: 356 350 case RECOVERED_ERROR:
+2 -2
drivers/scsi/cxlflash/vlun.c
··· 453 453 /* Drop the ioctl read semahpore across lengthy call */ 454 454 up_read(&cfg->ioctl_rwsem); 455 455 result = scsi_execute(sdev, scsi_cmd, DMA_TO_DEVICE, cmd_buf, 456 - CMD_BUFSIZE, sense_buf, to, CMD_RETRIES, 457 - 0, NULL); 456 + CMD_BUFSIZE, sense_buf, NULL, to, 457 + CMD_RETRIES, 0, 0, NULL); 458 458 down_read(&cfg->ioctl_rwsem); 459 459 rc = check_state(cfg); 460 460 if (rc) {
+21 -27
drivers/scsi/scsi_lib.c
··· 213 213 __scsi_queue_insert(cmd, reason, 1); 214 214 } 215 215 216 - static int __scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 216 + 217 + /** 218 + * scsi_execute - insert request and wait for the result 219 + * @sdev: scsi device 220 + * @cmd: scsi command 221 + * @data_direction: data direction 222 + * @buffer: data buffer 223 + * @bufflen: len of buffer 224 + * @sense: optional sense buffer 225 + * @sshdr: optional decoded sense header 226 + * @timeout: request timeout in seconds 227 + * @retries: number of times to retry request 228 + * @flags: flags for ->cmd_flags 229 + * @rq_flags: flags for ->rq_flags 230 + * @resid: optional residual length 231 + * 232 + * returns the req->errors value which is the scsi_cmnd result 233 + * field. 234 + */ 235 + int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 217 236 int data_direction, void *buffer, unsigned bufflen, 218 237 unsigned char *sense, struct scsi_sense_hdr *sshdr, 219 238 int timeout, int retries, u64 flags, req_flags_t rq_flags, ··· 287 268 288 269 return ret; 289 270 } 290 - 291 - /** 292 - * scsi_execute - insert request and wait for the result 293 - * @sdev: scsi device 294 - * @cmd: scsi command 295 - * @data_direction: data direction 296 - * @buffer: data buffer 297 - * @bufflen: len of buffer 298 - * @sense: optional sense buffer 299 - * @timeout: request timeout in seconds 300 - * @retries: number of times to retry request 301 - * @flags: or into request flags; 302 - * @resid: optional residual length 303 - * 304 - * returns the req->errors value which is the scsi_cmnd result 305 - * field. 306 - */ 307 - int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 308 - int data_direction, void *buffer, unsigned bufflen, 309 - unsigned char *sense, int timeout, int retries, u64 flags, 310 - int *resid) 311 - { 312 - return __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, sense, 313 - NULL, timeout, retries, flags, 0, resid); 314 - } 315 271 EXPORT_SYMBOL(scsi_execute); 316 272 317 273 int scsi_execute_req_flags(struct scsi_device *sdev, const unsigned char *cmd, ··· 294 300 struct scsi_sense_hdr *sshdr, int timeout, int retries, 295 301 int *resid, u64 flags, req_flags_t rq_flags) 296 302 { 297 - return __scsi_execute(sdev, cmd, data_direction, buffer, bufflen, 303 + return scsi_execute(sdev, cmd, data_direction, buffer, bufflen, 298 304 NULL, sshdr, timeout, retries, flags, rq_flags, 299 305 resid); 300 306 }
+10 -14
drivers/scsi/scsi_transport_spi.c
··· 123 123 { 124 124 int i, result; 125 125 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 126 + struct scsi_sense_hdr sshdr_tmp; 127 + 128 + if (!sshdr) 129 + sshdr = &sshdr_tmp; 126 130 127 131 for(i = 0; i < DV_RETRIES; i++) { 128 - result = scsi_execute(sdev, cmd, dir, buffer, bufflen, 129 - sense, DV_TIMEOUT, /* retries */ 1, 132 + result = scsi_execute(sdev, cmd, dir, buffer, bufflen, sense, 133 + sshdr, DV_TIMEOUT, /* retries */ 1, 130 134 REQ_FAILFAST_DEV | 131 135 REQ_FAILFAST_TRANSPORT | 132 136 REQ_FAILFAST_DRIVER, 133 - NULL); 134 - if (driver_byte(result) & DRIVER_SENSE) { 135 - struct scsi_sense_hdr sshdr_tmp; 136 - if (!sshdr) 137 - sshdr = &sshdr_tmp; 138 - 139 - if (scsi_normalize_sense(sense, SCSI_SENSE_BUFFERSIZE, 140 - sshdr) 141 - && sshdr->sense_key == UNIT_ATTENTION) 142 - continue; 143 - } 144 - break; 137 + 0, NULL); 138 + if (!(driver_byte(result) & DRIVER_SENSE) || 139 + sshdr->sense_key != UNIT_ATTENTION) 140 + break; 145 141 } 146 142 return result; 147 143 }
+3 -16
drivers/scsi/sr_ioctl.c
··· 187 187 struct scsi_device *SDev; 188 188 struct scsi_sense_hdr sshdr; 189 189 int result, err = 0, retries = 0; 190 - struct request_sense *sense = cgc->sense; 191 190 192 191 SDev = cd->device; 193 - 194 - if (!sense) { 195 - sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); 196 - if (!sense) { 197 - err = -ENOMEM; 198 - goto out; 199 - } 200 - } 201 192 202 193 retry: 203 194 if (!scsi_block_when_processing_errors(SDev)) { ··· 196 205 goto out; 197 206 } 198 207 199 - memset(sense, 0, sizeof(*sense)); 200 208 result = scsi_execute(SDev, cgc->cmd, cgc->data_direction, 201 - cgc->buffer, cgc->buflen, (char *)sense, 202 - cgc->timeout, IOCTL_RETRIES, 0, NULL); 203 - 204 - scsi_normalize_sense((char *)sense, sizeof(*sense), &sshdr); 209 + cgc->buffer, cgc->buflen, 210 + (unsigned char *)cgc->sense, &sshdr, 211 + cgc->timeout, IOCTL_RETRIES, 0, 0, NULL); 205 212 206 213 /* Minimal error checking. Ignore cases we know about, and report the rest. */ 207 214 if (driver_byte(result) != 0) { ··· 250 261 251 262 /* Wake up a process waiting for device */ 252 263 out: 253 - if (!cgc->sense) 254 - kfree(sense); 255 264 cgc->stat = err; 256 265 return err; 257 266 }
+3 -2
include/scsi/scsi_device.h
··· 410 410 extern void scsi_sanitize_inquiry_string(unsigned char *s, int len); 411 411 extern int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 412 412 int data_direction, void *buffer, unsigned bufflen, 413 - unsigned char *sense, int timeout, int retries, 414 - u64 flags, int *resid); 413 + unsigned char *sense, struct scsi_sense_hdr *sshdr, 414 + int timeout, int retries, u64 flags, 415 + req_flags_t rq_flags, int *resid); 415 416 extern int scsi_execute_req_flags(struct scsi_device *sdev, 416 417 const unsigned char *cmd, int data_direction, void *buffer, 417 418 unsigned bufflen, struct scsi_sense_hdr *sshdr, int timeout,