Commit b07fbce6 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Paolo Bonzini

scsi-bus: correct responses for INQUIRY and REQUEST SENSE

According to SPC-3 INQUIRY and REQUEST SENSE should return GOOD
even on unsupported LUNS.
Signed-off-by: 's avatarHannes Reinecke <hare@suse.com>
Message-Id: <1503049022-14749-1-git-send-email-hare@suse.de>
Reported-by: 's avatarLaszlo Ersek <lersek@redhat.com>
Fixes: ded6ddc5
Cc: qemu-stable@nongnu.org
Signed-off-by: 's avatarPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: 's avatarHannes Reinecke <hare@suse.de>
parent 5c0919d0
......@@ -516,8 +516,10 @@ static size_t scsi_sense_len(SCSIRequest *req)
static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
{
SCSITargetReq *r = DO_UPCAST(SCSITargetReq, req, req);
int fixed_sense = (req->cmd.buf[1] & 1) == 0;
if (req->lun != 0) {
if (req->lun != 0 &&
buf[0] != INQUIRY && buf[0] != REQUEST_SENSE) {
scsi_req_build_sense(req, SENSE_CODE(LUN_NOT_SUPPORTED));
scsi_req_complete(req, CHECK_CONDITION);
return 0;
......@@ -535,9 +537,28 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf)
break;
case REQUEST_SENSE:
scsi_target_alloc_buf(&r->req, scsi_sense_len(req));
r->len = scsi_device_get_sense(r->req.dev, r->buf,
MIN(req->cmd.xfer, r->buf_len),
(req->cmd.buf[1] & 1) == 0);
if (req->lun != 0) {
const struct SCSISense sense = SENSE_CODE(LUN_NOT_SUPPORTED);
if (fixed_sense) {
r->buf[0] = 0x70;
r->buf[2] = sense.key;
r->buf[10] = 10;
r->buf[12] = sense.asc;
r->buf[13] = sense.ascq;
r->len = MIN(req->cmd.xfer, SCSI_SENSE_LEN);
} else {
r->buf[0] = 0x72;
r->buf[1] = sense.key;
r->buf[2] = sense.asc;
r->buf[3] = sense.ascq;
r->len = 8;
}
} else {
r->len = scsi_device_get_sense(r->req.dev, r->buf,
MIN(req->cmd.xfer, r->buf_len),
fixed_sense);
}
if (r->req.dev->sense_is_ua) {
scsi_device_unit_attention_reported(req->dev);
r->req.dev->sense_len = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment