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

Configure Feed

Select the types of activity you want to include in your feed.

scsi: core: Introduce enum scsi_disposition

Improve readability of the code in the SCSI core by introducing an
enumeration type for the values used internally that decide how to continue
processing a SCSI command. The eh_*_handler return values have not been
changed because that would involve modifying all SCSI drivers.

The output of the following command has been inspected to verify that no
out-of-range values are assigned to a variable of type enum
scsi_disposition:

KCFLAGS=-Wassign-enum make CC=clang W=1 drivers/scsi/

Link: https://lore.kernel.org/r/20210415220826.29438-6-bvanassche@acm.org
Cc: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Daniel Wagner <dwagner@suse.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Bart Van Assche and committed by
Martin K. Petersen
b8e162f9 280e91b0

+57 -51
+1 -1
drivers/ata/libata-eh.c
··· 1599 1599 } 1600 1600 1601 1601 if (qc->flags & ATA_QCFLAG_SENSE_VALID) { 1602 - int ret = scsi_check_sense(qc->scsicmd); 1602 + enum scsi_disposition ret = scsi_check_sense(qc->scsicmd); 1603 1603 /* 1604 1604 * SUCCESS here means that the sense code could be 1605 1605 * evaluated and should be passed to the upper layers
+2 -2
drivers/scsi/device_handler/scsi_dh_alua.c
··· 405 405 } 406 406 } 407 407 408 - static int alua_check_sense(struct scsi_device *sdev, 409 - struct scsi_sense_hdr *sense_hdr) 408 + static enum scsi_disposition alua_check_sense(struct scsi_device *sdev, 409 + struct scsi_sense_hdr *sense_hdr) 410 410 { 411 411 struct alua_dh_data *h = sdev->handler_data; 412 412 struct alua_port_group *pg;
+2 -2
drivers/scsi/device_handler/scsi_dh_emc.c
··· 280 280 return res; 281 281 } 282 282 283 - static int clariion_check_sense(struct scsi_device *sdev, 284 - struct scsi_sense_hdr *sense_hdr) 283 + static enum scsi_disposition clariion_check_sense(struct scsi_device *sdev, 284 + struct scsi_sense_hdr *sense_hdr) 285 285 { 286 286 switch (sense_hdr->sense_key) { 287 287 case NOT_READY:
+2 -2
drivers/scsi/device_handler/scsi_dh_rdac.c
··· 656 656 return BLK_STS_OK; 657 657 } 658 658 659 - static int rdac_check_sense(struct scsi_device *sdev, 660 - struct scsi_sense_hdr *sense_hdr) 659 + static enum scsi_disposition rdac_check_sense(struct scsi_device *sdev, 660 + struct scsi_sense_hdr *sense_hdr) 661 661 { 662 662 struct rdac_dh_data *h = sdev->handler_data; 663 663
+34 -30
drivers/scsi/scsi_error.c
··· 60 60 #define HOST_RESET_SETTLE_TIME (10) 61 61 62 62 static int scsi_eh_try_stu(struct scsi_cmnd *scmd); 63 - static int scsi_try_to_abort_cmd(struct scsi_host_template *, 64 - struct scsi_cmnd *); 63 + static enum scsi_disposition scsi_try_to_abort_cmd(struct scsi_host_template *, 64 + struct scsi_cmnd *); 65 65 66 66 void scsi_eh_wakeup(struct Scsi_Host *shost) 67 67 { ··· 151 151 struct scsi_cmnd *scmd = 152 152 container_of(work, struct scsi_cmnd, abort_work.work); 153 153 struct scsi_device *sdev = scmd->device; 154 - int rtn; 154 + enum scsi_disposition rtn; 155 155 156 156 if (scsi_host_eh_past_deadline(sdev->host)) { 157 157 SCSI_LOG_ERROR_RECOVERY(3, ··· 498 498 * When a deferred error is detected the current command has 499 499 * not been executed and needs retrying. 500 500 */ 501 - int scsi_check_sense(struct scsi_cmnd *scmd) 501 + enum scsi_disposition scsi_check_sense(struct scsi_cmnd *scmd) 502 502 { 503 503 struct scsi_device *sdev = scmd->device; 504 504 struct scsi_sense_hdr sshdr; ··· 512 512 return NEEDS_RETRY; 513 513 514 514 if (sdev->handler && sdev->handler->check_sense) { 515 - int rc; 515 + enum scsi_disposition rc; 516 516 517 517 rc = sdev->handler->check_sense(sdev, &sshdr); 518 518 if (rc != SCSI_RETURN_NOT_HANDLED) ··· 723 723 * don't allow for the possibility of retries here, and we are a lot 724 724 * more restrictive about what we consider acceptable. 725 725 */ 726 - static int scsi_eh_completed_normally(struct scsi_cmnd *scmd) 726 + static enum scsi_disposition scsi_eh_completed_normally(struct scsi_cmnd *scmd) 727 727 { 728 728 /* 729 729 * first check the host byte, to see if there is anything in there ··· 804 804 * scsi_try_host_reset - ask host adapter to reset itself 805 805 * @scmd: SCSI cmd to send host reset. 806 806 */ 807 - static int scsi_try_host_reset(struct scsi_cmnd *scmd) 807 + static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd) 808 808 { 809 809 unsigned long flags; 810 - int rtn; 810 + enum scsi_disposition rtn; 811 811 struct Scsi_Host *host = scmd->device->host; 812 812 struct scsi_host_template *hostt = host->hostt; 813 813 ··· 834 834 * scsi_try_bus_reset - ask host to perform a bus reset 835 835 * @scmd: SCSI cmd to send bus reset. 836 836 */ 837 - static int scsi_try_bus_reset(struct scsi_cmnd *scmd) 837 + static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd) 838 838 { 839 839 unsigned long flags; 840 - int rtn; 840 + enum scsi_disposition rtn; 841 841 struct Scsi_Host *host = scmd->device->host; 842 842 struct scsi_host_template *hostt = host->hostt; 843 843 ··· 876 876 * timer on it, and set the host back to a consistent state prior to 877 877 * returning. 878 878 */ 879 - static int scsi_try_target_reset(struct scsi_cmnd *scmd) 879 + static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd) 880 880 { 881 881 unsigned long flags; 882 - int rtn; 882 + enum scsi_disposition rtn; 883 883 struct Scsi_Host *host = scmd->device->host; 884 884 struct scsi_host_template *hostt = host->hostt; 885 885 ··· 907 907 * timer on it, and set the host back to a consistent state prior to 908 908 * returning. 909 909 */ 910 - static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd) 910 + static enum scsi_disposition scsi_try_bus_device_reset(struct scsi_cmnd *scmd) 911 911 { 912 - int rtn; 912 + enum scsi_disposition rtn; 913 913 struct scsi_host_template *hostt = scmd->device->host->hostt; 914 914 915 915 if (!hostt->eh_device_reset_handler) ··· 938 938 * if the device is temporarily unavailable (eg due to a 939 939 * link down on FibreChannel) 940 940 */ 941 - static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt, 942 - struct scsi_cmnd *scmd) 941 + static enum scsi_disposition 942 + scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) 943 943 { 944 944 if (!hostt->eh_abort_handler) 945 945 return FAILED; ··· 1072 1072 * Return value: 1073 1073 * SUCCESS or FAILED or NEEDS_RETRY 1074 1074 */ 1075 - static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd, 1076 - int cmnd_size, int timeout, unsigned sense_bytes) 1075 + static enum scsi_disposition scsi_send_eh_cmnd(struct scsi_cmnd *scmd, 1076 + unsigned char *cmnd, int cmnd_size, int timeout, unsigned sense_bytes) 1077 1077 { 1078 1078 struct scsi_device *sdev = scmd->device; 1079 1079 struct Scsi_Host *shost = sdev->host; ··· 1180 1180 * that we obtain it on our own. This function will *not* return until 1181 1181 * the command either times out, or it completes. 1182 1182 */ 1183 - static int scsi_request_sense(struct scsi_cmnd *scmd) 1183 + static enum scsi_disposition scsi_request_sense(struct scsi_cmnd *scmd) 1184 1184 { 1185 1185 return scsi_send_eh_cmnd(scmd, NULL, 0, scmd->device->eh_timeout, ~0); 1186 1186 } 1187 1187 1188 - static int scsi_eh_action(struct scsi_cmnd *scmd, int rtn) 1188 + static enum scsi_disposition 1189 + scsi_eh_action(struct scsi_cmnd *scmd, enum scsi_disposition rtn) 1189 1190 { 1190 1191 if (!blk_rq_is_passthrough(scmd->request)) { 1191 1192 struct scsi_driver *sdrv = scsi_cmd_to_driver(scmd); ··· 1239 1238 { 1240 1239 struct scsi_cmnd *scmd, *next; 1241 1240 struct Scsi_Host *shost; 1242 - int rtn; 1241 + enum scsi_disposition rtn; 1243 1242 1244 1243 /* 1245 1244 * If SCSI_EH_ABORT_SCHEDULED has been set, it is timeout IO, ··· 1317 1316 static int scsi_eh_tur(struct scsi_cmnd *scmd) 1318 1317 { 1319 1318 static unsigned char tur_command[6] = {TEST_UNIT_READY, 0, 0, 0, 0, 0}; 1320 - int retry_cnt = 1, rtn; 1319 + int retry_cnt = 1; 1320 + enum scsi_disposition rtn; 1321 1321 1322 1322 retry_tur: 1323 1323 rtn = scsi_send_eh_cmnd(scmd, tur_command, 6, ··· 1406 1404 static unsigned char stu_command[6] = {START_STOP, 0, 0, 0, 1, 0}; 1407 1405 1408 1406 if (scmd->device->allow_restart) { 1409 - int i, rtn = NEEDS_RETRY; 1407 + int i; 1408 + enum scsi_disposition rtn = NEEDS_RETRY; 1410 1409 1411 1410 for (i = 0; rtn == NEEDS_RETRY && i < 2; i++) 1412 1411 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, scmd->device->request_queue->rq_timeout, 0); ··· 1501 1498 { 1502 1499 struct scsi_cmnd *scmd, *bdr_scmd, *next; 1503 1500 struct scsi_device *sdev; 1504 - int rtn; 1501 + enum scsi_disposition rtn; 1505 1502 1506 1503 shost_for_each_device(sdev, shost) { 1507 1504 if (scsi_host_eh_past_deadline(shost)) { ··· 1568 1565 1569 1566 while (!list_empty(&tmp_list)) { 1570 1567 struct scsi_cmnd *next, *scmd; 1571 - int rtn; 1568 + enum scsi_disposition rtn; 1572 1569 unsigned int id; 1573 1570 1574 1571 if (scsi_host_eh_past_deadline(shost)) { ··· 1626 1623 struct scsi_cmnd *scmd, *chan_scmd, *next; 1627 1624 LIST_HEAD(check_list); 1628 1625 unsigned int channel; 1629 - int rtn; 1626 + enum scsi_disposition rtn; 1630 1627 1631 1628 /* 1632 1629 * we really want to loop over the various channels, and do this on ··· 1697 1694 { 1698 1695 struct scsi_cmnd *scmd, *next; 1699 1696 LIST_HEAD(check_list); 1700 - int rtn; 1697 + enum scsi_disposition rtn; 1701 1698 1702 1699 if (!list_empty(work_q)) { 1703 1700 scmd = list_entry(work_q->next, ··· 1803 1800 * doesn't require the error handler read (i.e. we don't need to 1804 1801 * abort/reset), this function should return SUCCESS. 1805 1802 */ 1806 - int scsi_decide_disposition(struct scsi_cmnd *scmd) 1803 + enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *scmd) 1807 1804 { 1808 - int rtn; 1805 + enum scsi_disposition rtn; 1809 1806 1810 1807 /* 1811 1808 * if the device is offline, then we clearly just pass the result back ··· 2368 2365 struct Scsi_Host *shost = dev->host; 2369 2366 struct request *rq; 2370 2367 unsigned long flags; 2371 - int error = 0, rtn, val; 2368 + int error = 0, val; 2369 + enum scsi_disposition rtn; 2372 2370 2373 2371 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) 2374 2372 return -EACCES;
+1 -1
drivers/scsi/scsi_lib.c
··· 1441 1441 static void scsi_complete(struct request *rq) 1442 1442 { 1443 1443 struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); 1444 - int disposition; 1444 + enum scsi_disposition disposition; 1445 1445 1446 1446 INIT_LIST_HEAD(&cmd->eh_entry); 1447 1447
+1 -1
drivers/scsi/scsi_priv.h
··· 74 74 extern void scmd_eh_abort_handler(struct work_struct *work); 75 75 extern enum blk_eh_timer_return scsi_times_out(struct request *req); 76 76 extern int scsi_error_handler(void *host); 77 - extern int scsi_decide_disposition(struct scsi_cmnd *cmd); 77 + extern enum scsi_disposition scsi_decide_disposition(struct scsi_cmnd *cmd); 78 78 extern void scsi_eh_wakeup(struct Scsi_Host *shost); 79 79 extern void scsi_eh_scmd_add(struct scsi_cmnd *); 80 80 void scsi_eh_ready_devs(struct Scsi_Host *shost,
+11 -10
include/scsi/scsi.h
··· 180 180 /* 181 181 * Internal return values. 182 182 */ 183 - 184 - #define NEEDS_RETRY 0x2001 185 - #define SUCCESS 0x2002 186 - #define FAILED 0x2003 187 - #define QUEUED 0x2004 188 - #define SOFT_ERROR 0x2005 189 - #define ADD_TO_MLQUEUE 0x2006 190 - #define TIMEOUT_ERROR 0x2007 191 - #define SCSI_RETURN_NOT_HANDLED 0x2008 192 - #define FAST_IO_FAIL 0x2009 183 + enum scsi_disposition { 184 + NEEDS_RETRY = 0x2001, 185 + SUCCESS = 0x2002, 186 + FAILED = 0x2003, 187 + QUEUED = 0x2004, 188 + SOFT_ERROR = 0x2005, 189 + ADD_TO_MLQUEUE = 0x2006, 190 + TIMEOUT_ERROR = 0x2007, 191 + SCSI_RETURN_NOT_HANDLED = 0x2008, 192 + FAST_IO_FAIL = 0x2009, 193 + }; 193 194 194 195 /* 195 196 * Midlevel queue return values.
+2 -1
include/scsi/scsi_dh.h
··· 52 52 /* Filled by the hardware handler */ 53 53 struct module *module; 54 54 const char *name; 55 - int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *); 55 + enum scsi_disposition (*check_sense)(struct scsi_device *, 56 + struct scsi_sense_hdr *); 56 57 int (*attach)(struct scsi_device *); 57 58 void (*detach)(struct scsi_device *); 58 59 int (*activate)(struct scsi_device *, activate_complete, void *);
+1 -1
include/scsi/scsi_eh.h
··· 17 17 extern int scsi_block_when_processing_errors(struct scsi_device *); 18 18 extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd, 19 19 struct scsi_sense_hdr *sshdr); 20 - extern int scsi_check_sense(struct scsi_cmnd *); 20 + extern enum scsi_disposition scsi_check_sense(struct scsi_cmnd *); 21 21 22 22 static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) 23 23 {