mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 10:13:56 -06:00
scsi: introduce sg_io_sense_from_errno
Move more knowledge of SG_IO out of hw/scsi/scsi-generic.c, for reusability. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
a3760467c6
commit
1ead6b4e24
3 changed files with 46 additions and 34 deletions
35
scsi/utils.c
35
scsi/utils.c
|
@ -501,3 +501,38 @@ const char *scsi_command_name(uint8_t cmd)
|
|||
}
|
||||
return names[cmd];
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
} else {
|
||||
if (io_hdr->host_status == SG_ERR_DID_NO_CONNECT ||
|
||||
io_hdr->host_status == SG_ERR_DID_BUS_BUSY ||
|
||||
io_hdr->host_status == SG_ERR_DID_TIME_OUT ||
|
||||
(io_hdr->driver_status & SG_ERR_DRIVER_TIMEOUT)) {
|
||||
return BUSY;
|
||||
} else if (io_hdr->host_status) {
|
||||
*sense = SENSE_CODE(I_T_NEXUS_LOSS);
|
||||
return CHECK_CONDITION;
|
||||
} else if (io_hdr->status) {
|
||||
return io_hdr->status;
|
||||
} else if (io_hdr->driver_status & SG_ERR_DRIVER_SENSE) {
|
||||
return CHECK_CONDITION;
|
||||
} else {
|
||||
return GOOD;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue