mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
scsi: introduce scsi_sense_from_errno()
The new function is an extension of the switch statement in scsi-disk.c which also includes the errno cases only found in sg_io_sense_from_errno. This allows us to consolidate the errno handling. Extracted from a patch by Hannes Reinecke <hare@suse.de>. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
424740def9
commit
d7a84021db
3 changed files with 51 additions and 47 deletions
51
scsi/utils.c
51
scsi/utils.c
|
@ -565,21 +565,52 @@ const char *scsi_command_name(uint8_t cmd)
|
|||
return names[cmd];
|
||||
}
|
||||
|
||||
int scsi_sense_from_errno(int errno_value, SCSISense *sense)
|
||||
{
|
||||
switch (errno_value) {
|
||||
case 0:
|
||||
return GOOD;
|
||||
case EDOM:
|
||||
return TASK_SET_FULL;
|
||||
#ifdef CONFIG_LINUX
|
||||
/* These errno mapping are specific to Linux. For more information:
|
||||
* - scsi_decide_disposition in drivers/scsi/scsi_error.c
|
||||
* - scsi_result_to_blk_status in drivers/scsi/scsi_lib.c
|
||||
* - blk_errors[] in block/blk-core.c
|
||||
*/
|
||||
case EBADE:
|
||||
return RESERVATION_CONFLICT;
|
||||
case ENODATA:
|
||||
*sense = SENSE_CODE(READ_ERROR);
|
||||
return CHECK_CONDITION;
|
||||
case EREMOTEIO:
|
||||
*sense = SENSE_CODE(LUN_COMM_FAILURE);
|
||||
return CHECK_CONDITION;
|
||||
#endif
|
||||
case ENOMEDIUM:
|
||||
*sense = SENSE_CODE(NO_MEDIUM);
|
||||
return CHECK_CONDITION;
|
||||
case ENOMEM:
|
||||
*sense = SENSE_CODE(TARGET_FAILURE);
|
||||
return CHECK_CONDITION;
|
||||
case EINVAL:
|
||||
*sense = SENSE_CODE(INVALID_FIELD);
|
||||
return CHECK_CONDITION;
|
||||
case ENOSPC:
|
||||
*sense = SENSE_CODE(SPACE_ALLOC_FAILED);
|
||||
return CHECK_CONDITION;
|
||||
default:
|
||||
*sense = SENSE_CODE(IO_ERROR);
|
||||
return CHECK_CONDITION;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LINUX
|
||||
int sg_io_sense_from_errno(int errno_value, struct sg_io_hdr *io_hdr,
|
||||
SCSISense *sense)
|
||||
{
|
||||
if (errno_value != 0) {
|
||||
switch (errno_value) {
|
||||
case EDOM:
|
||||
return TASK_SET_FULL;
|
||||
case ENOMEM:
|
||||
*sense = SENSE_CODE(TARGET_FAILURE);
|
||||
return CHECK_CONDITION;
|
||||
default:
|
||||
*sense = SENSE_CODE(IO_ERROR);
|
||||
return CHECK_CONDITION;
|
||||
}
|
||||
return scsi_sense_from_errno(errno_value, sense);
|
||||
} else {
|
||||
if (io_hdr->host_status == SG_ERR_DID_NO_CONNECT ||
|
||||
io_hdr->host_status == SG_ERR_DID_BUS_BUSY ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue