scsi: introduce scsi_build_sense

Move more knowledge of sense data format out of hw/scsi/scsi-bus.c
for reusability.

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2017-08-22 09:42:59 +02:00
parent e5b5728cd3
commit a3760467c6
3 changed files with 14 additions and 7 deletions

View File

@ -818,13 +818,7 @@ void scsi_req_build_sense(SCSIRequest *req, SCSISense sense)
{ {
trace_scsi_req_build_sense(req->dev->id, req->lun, req->tag, trace_scsi_req_build_sense(req->dev->id, req->lun, req->tag,
sense.key, sense.asc, sense.ascq); sense.key, sense.asc, sense.ascq);
memset(req->sense, 0, 18); req->sense_len = scsi_build_sense(req->sense, sense);
req->sense[0] = 0x70;
req->sense[2] = sense.key;
req->sense[7] = 10;
req->sense[12] = sense.asc;
req->sense[13] = sense.ascq;
req->sense_len = 18;
} }
static void scsi_req_enqueue_internal(SCSIRequest *req) static void scsi_req_enqueue_internal(SCSIRequest *req)

View File

@ -30,6 +30,8 @@ typedef struct SCSISense {
uint8_t ascq; uint8_t ascq;
} SCSISense; } SCSISense;
int scsi_build_sense(uint8_t *buf, SCSISense sense);
/* /*
* Predefined sense codes * Predefined sense codes
*/ */

View File

@ -96,6 +96,17 @@ int scsi_cdb_length(uint8_t *buf)
return cdb_len; return cdb_len;
} }
int scsi_build_sense(uint8_t *buf, SCSISense sense)
{
memset(buf, 0, 18);
buf[0] = 0x70;
buf[2] = sense.key;
buf[7] = 10;
buf[12] = sense.asc;
buf[13] = sense.ascq;
return 18;
}
/* /*
* Predefined sense codes * Predefined sense codes
*/ */