Skip to content

Commit

Permalink
Use struct scsi_status more widely
Browse files Browse the repository at this point in the history
Change the type of the {status,msg,host,driver}_byte() argument and also
of the scsi_{host,driver}byte_string() argument from 'int' into 'struct
scsi_status'. Change the type of the second argument of
set_{status,msg,host,driver}_byte() from 'int' into the proper enumeration
type.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: John Garry <john.garry@huawei.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
  • Loading branch information
bvanassche committed Apr 12, 2021
1 parent e17a254 commit ead328d
Show file tree
Hide file tree
Showing 28 changed files with 216 additions and 193 deletions.
5 changes: 3 additions & 2 deletions block/bsg-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,16 @@ static int bsg_transport_fill_hdr(struct request *rq, struct sg_io_v4 *hdr,
static int bsg_transport_complete_rq(struct request *rq, struct sg_io_v4 *hdr)
{
struct bsg_job *job = blk_mq_rq_to_pdu(rq);
struct scsi_status job_result = { .combined = job->result };
int ret = 0;

/*
* The assignments below don't make much sense, but are kept for
* bug by bug backwards compatibility:
*/
hdr->device_status = job->result & 0xff;
hdr->transport_status = host_byte(job->result);
hdr->driver_status = driver_byte(job->result);
hdr->transport_status = host_byte(job_result);
hdr->driver_status = driver_byte(job_result);
hdr->info = 0;
if (hdr->device_status || hdr->transport_status || hdr->driver_status)
hdr->info |= SG_INFO_CHECK;
Expand Down
5 changes: 3 additions & 2 deletions drivers/scsi/ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,16 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
void *buffer, unsigned buflength,
enum dma_data_direction direction)
{
int errno, retries = 0, timeout, result;
int errno, retries = 0, timeout;
struct scsi_status result;
struct scsi_sense_hdr sshdr;

timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
? timeout_init : timeout_move;

retry:
errno = 0;
result = scsi_execute_req(ch->device, cmd, direction, buffer,
result.combined = scsi_execute_req(ch->device, cmd, direction, buffer,
buflength, &sshdr, timeout * HZ,
MAX_RETRIES, NULL);

Expand Down
4 changes: 2 additions & 2 deletions drivers/scsi/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ static const char * const driverbyte_table[]={
"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR",
"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};

const char *scsi_hostbyte_string(int result)
const char *scsi_hostbyte_string(struct scsi_status result)
{
const char *hb_string = NULL;
enum host_status hb = host_byte(result);
Expand All @@ -421,7 +421,7 @@ const char *scsi_hostbyte_string(int result)
}
EXPORT_SYMBOL(scsi_hostbyte_string);

const char *scsi_driverbyte_string(int result)
const char *scsi_driverbyte_string(struct scsi_status result)
{
const char *db_string = NULL;
enum driver_status db = driver_byte(result);
Expand Down
20 changes: 11 additions & 9 deletions drivers/scsi/device_handler/scsi_dh_alua.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
int len, k, off, bufflen = ALUA_RTPG_SIZE;
int group_id_old, state_old, pref_old, valid_states_old;
unsigned char *desc, *buff;
unsigned err, retval;
unsigned err;
struct scsi_status retval;
unsigned int tpg_desc_tbl_off;
unsigned char orig_transition_tmo;
unsigned long flags;
Expand All @@ -543,9 +544,10 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)

retry:
err = 0;
retval = submit_rtpg(sdev, buff, bufflen, &sense_hdr, pg->flags);
retval.combined = submit_rtpg(sdev, buff, bufflen, &sense_hdr,
pg->flags);

if (retval) {
if (retval.combined) {
/*
* Some (broken) implementations have a habit of returning
* an error during things like firmware update etc.
Expand All @@ -558,14 +560,14 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
if ((pg->valid_states & ~TPGS_SUPPORT_OPTIMIZED) == 0) {
sdev_printk(KERN_INFO, sdev,
"%s: ignoring rtpg result %d\n",
ALUA_DH_NAME, retval);
ALUA_DH_NAME, retval.combined);
kfree(buff);
return SCSI_DH_OK;
}
if (!scsi_sense_valid(&sense_hdr)) {
sdev_printk(KERN_INFO, sdev,
"%s: rtpg failed, result %d\n",
ALUA_DH_NAME, retval);
ALUA_DH_NAME, retval.combined);
kfree(buff);
if (driver_byte(retval) == DRIVER_ERROR)
return SCSI_DH_DEV_TEMP_BUSY;
Expand Down Expand Up @@ -759,7 +761,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg)
*/
static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg)
{
int retval;
struct scsi_status retval;
struct scsi_sense_hdr sense_hdr;

if (!(pg->tpgs & TPGS_MODE_EXPLICIT)) {
Expand Down Expand Up @@ -788,13 +790,13 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg)
ALUA_DH_NAME, pg->state);
return SCSI_DH_NOSYS;
}
retval = submit_stpg(sdev, pg->group_id, &sense_hdr);
retval.combined = submit_stpg(sdev, pg->group_id, &sense_hdr);

if (retval) {
if (retval.combined) {
if (!scsi_sense_valid(&sense_hdr)) {
sdev_printk(KERN_INFO, sdev,
"%s: stpg failed, result %d",
ALUA_DH_NAME, retval);
ALUA_DH_NAME, retval.combined);
if (driver_byte(retval) == DRIVER_ERROR)
return SCSI_DH_DEV_TEMP_BUSY;
} else {
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/megaraid/megaraid_sas_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,7 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)

/* Check for an mpio path and adjust behavior */
if (atomic_read(&instance->adprecovery) == MEGASAS_ADPRESET_SM_INFAULT) {
if (megasas_check_mpio_paths(instance, scmd) ==
if (megasas_check_mpio_paths(instance, scmd).combined ==
(DID_REQUEUE << 16)) {
return SCSI_MLQUEUE_HOST_BUSY;
} else {
Expand Down
8 changes: 4 additions & 4 deletions drivers/scsi/megaraid/megaraid_sas_fusion.c
Original file line number Diff line number Diff line change
Expand Up @@ -4837,18 +4837,18 @@ megasas_instance *megasas_get_peer_instance(struct megasas_instance *instance)
}

/* Check for a second path that is currently UP */
int megasas_check_mpio_paths(struct megasas_instance *instance,
struct scsi_status megasas_check_mpio_paths(struct megasas_instance *instance,
struct scsi_cmnd *scmd)
{
struct megasas_instance *peer_instance = NULL;
int retval = (DID_REQUEUE << 16);
struct scsi_status retval = { .combined = DID_REQUEUE << 16 };

if (instance->peerIsPresent) {
peer_instance = megasas_get_peer_instance(instance);
if ((peer_instance) &&
(atomic_read(&peer_instance->adprecovery) ==
MEGASAS_HBA_OPERATIONAL))
retval = (DID_NO_CONNECT << 16);
retval.combined = (DID_NO_CONNECT << 16);
}
return retval;
}
Expand Down Expand Up @@ -4959,7 +4959,7 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int reason)
MPI2_FUNCTION_SCSI_IO_REQUEST)
fpio_count++;

scmd_local->result.combined =
scmd_local->result =
megasas_check_mpio_paths(instance,
scmd_local);
if (instance->ldio_threshold &&
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/megaraid/megaraid_sas_fusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ u8 megasas_get_map_info(struct megasas_instance *instance);
int megasas_sync_map_info(struct megasas_instance *instance);
void megasas_release_fusion(struct megasas_instance *instance);
void megasas_reset_reply_desc(struct megasas_instance *instance);
int megasas_check_mpio_paths(struct megasas_instance *instance,
struct scsi_status megasas_check_mpio_paths(struct megasas_instance *instance,
struct scsi_cmnd *scmd);
void megasas_fusion_ocr_wq(struct work_struct *work);

Expand Down
2 changes: 2 additions & 0 deletions drivers/scsi/scsi_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,8 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd)
fallthrough;
case DID_SOFT_ERROR:
return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER);
default:
break;
}

if (status_byte(scmd->result) != CHECK_CONDITION)
Expand Down
12 changes: 6 additions & 6 deletions drivers/scsi/scsi_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ static int ioctl_probe(struct Scsi_Host *host, void __user *buffer)
static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
int timeout, int retries)
{
int result;
struct scsi_status result;
struct scsi_sense_hdr sshdr;

SCSI_LOG_IOCTL(1, sdev_printk(KERN_INFO, sdev,
"Trying ioctl with scsi command %d\n", *cmd));

result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
result.combined = scsi_execute_req(sdev, cmd, DMA_NONE, NULL, 0,
&sshdr, timeout, retries, NULL);

SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
"Ioctl returned 0x%x\n", result));
"Ioctl returned 0x%x\n", result.combined));

if (driver_byte(result) == DRIVER_SENSE &&
scsi_sense_valid(&sshdr)) {
Expand All @@ -121,22 +121,22 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
case UNIT_ATTENTION:
if (sdev->removable) {
sdev->changed = 1;
result = 0; /* This is no longer considered an error */
result.combined = 0; /* This is no longer considered an error */
break;
}
fallthrough; /* for non-removable media */
default:
sdev_printk(KERN_INFO, sdev,
"ioctl_internal_command return code = %x\n",
result);
result.combined);
scsi_print_sense_hdr(sdev, NULL, &sshdr);
break;
}
}

SCSI_LOG_IOCTL(2, sdev_printk(KERN_INFO, sdev,
"IOCTL Releasing command\n"));
return result;
return result.combined;
}

int scsi_set_medium_removal(struct scsi_device *sdev, char state)
Expand Down
33 changes: 19 additions & 14 deletions drivers/scsi/scsi_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,8 @@ static bool scsi_end_request(struct request *req, blk_status_t error,
* Translate a SCSI result code into a blk_status_t value. May reset the host
* byte of @cmd->result.
*/
static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)
static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd,
struct scsi_status result)
{
switch (host_byte(result)) {
case DID_OK:
Expand All @@ -627,7 +628,8 @@ static blk_status_t scsi_result_to_blk_status(struct scsi_cmnd *cmd, int result)
* to handle the case when a SCSI LLD sets result to
* DRIVER_SENSE << 24 without setting SAM_STAT_CHECK_CONDITION.
*/
if (scsi_status_is_good(result) && (result & ~0xff) == 0)
if (scsi_status_is_good(result) &&
(result.combined & ~0xff) == 0)
return BLK_STS_OK;
return BLK_STS_IOERR;
case DID_TRANSPORT_FAILFAST:
Expand Down Expand Up @@ -676,7 +678,8 @@ static bool scsi_cmd_runtime_exceeced(struct scsi_cmnd *cmd)
}

/* Helper for scsi_io_completion() when special action required. */
static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result)
static void scsi_io_completion_action(struct scsi_cmnd *cmd,
struct scsi_status result)
{
struct request_queue *q = cmd->device->request_queue;
struct request *req = cmd->request;
Expand Down Expand Up @@ -848,8 +851,8 @@ static void scsi_io_completion_action(struct scsi_cmnd *cmd, int result)
* new result that may suppress further error checking. Also modifies
* *blk_statp in some cases.
*/
static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
blk_status_t *blk_statp)
static struct scsi_status scsi_io_completion_nz_result(struct scsi_cmnd *cmd,
struct scsi_status result, blk_status_t *blk_statp)
{
bool sense_valid;
bool sense_current = true; /* false implies "deferred sense" */
Expand Down Expand Up @@ -898,7 +901,7 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
do_print = false;
if (do_print)
scsi_print_sense(cmd);
result = 0;
result.combined = 0;
/* for passthrough, *blk_statp may be set */
*blk_statp = BLK_STS_OK;
}
Expand All @@ -910,7 +913,7 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
* intermediate statuses (both obsolete in SAM-4) as good.
*/
if (status_byte(result) && scsi_status_is_good(result)) {
result = 0;
result.combined = 0;
*blk_statp = BLK_STS_OK;
}
return result;
Expand Down Expand Up @@ -940,12 +943,13 @@ static int scsi_io_completion_nz_result(struct scsi_cmnd *cmd, int result,
*/
void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
{
int result = cmd->result.combined;
struct scsi_status result = cmd->result;
struct request_queue *q = cmd->device->request_queue;
struct request *req = cmd->request;
blk_status_t blk_stat = BLK_STS_OK;

if (unlikely(result)) /* a nz result may or may not be an error */
/* a non-zero result may or may not be an error */
if (unlikely(result.combined))
result = scsi_io_completion_nz_result(cmd, result, &blk_stat);

if (unlikely(blk_rq_is_passthrough(req))) {
Expand Down Expand Up @@ -984,7 +988,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
* If there had been no error, but we have leftover bytes in the
* requeues just queue the command up again.
*/
if (likely(result == 0))
if (likely(result.combined == 0))
scsi_io_completion_reprep(cmd, q);
else
scsi_io_completion_action(cmd, result);
Expand Down Expand Up @@ -2147,7 +2151,8 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
unsigned char cmd[12];
int use_10_for_ms;
int header_length;
int result, retry_count = retries;
struct scsi_status result;
int retry_count = retries;
struct scsi_sense_hdr my_sshdr;

memset(data, 0, sizeof(*data));
Expand Down Expand Up @@ -2182,8 +2187,8 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,

memset(buffer, 0, len);

result = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer, len,
sshdr, timeout, retries, NULL);
result.combined = scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buffer,
len, sshdr, timeout, retries, NULL);

/* This code looks awful: what it's doing is making sure an
* ILLEGAL REQUEST sense return identifies the actual command
Expand Down Expand Up @@ -2235,7 +2240,7 @@ scsi_mode_sense(struct scsi_device *sdev, int dbd, int modepage,
goto retry;
}

return result;
return result.combined;
}
EXPORT_SYMBOL(scsi_mode_sense);

Expand Down
4 changes: 2 additions & 2 deletions drivers/scsi/scsi_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ void scsi_print_result(const struct scsi_cmnd *cmd, const char *msg,
char *logbuf;
size_t off, logbuf_len;
const char *mlret_string = scsi_mlreturn_string(disposition);
const char *hb_string = scsi_hostbyte_string(cmd->result.combined);
const char *db_string = scsi_driverbyte_string(cmd->result.combined);
const char *hb_string = scsi_hostbyte_string(cmd->result);
const char *db_string = scsi_driverbyte_string(cmd->result);
unsigned long cmd_age = (jiffies - cmd->jiffies_at_alloc) / HZ;

logbuf = scsi_log_reserve_buffer(&logbuf_len);
Expand Down

0 comments on commit ead328d

Please sign in to comment.