From 23f2b51d8b3d7734718eb2f9b109cb9090f1484e Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sat, 2 Dec 2017 12:19:39 +0100 Subject: [PATCH 13/36] scsi-bus: correct responses for INQUIRY and REQUEST SENSE RH-Author: Paolo Bonzini Message-id: <20171202121953.13317-4-pbonzini@redhat.com> Patchwork-id: 78085 O-Subject: [RHEL7.4 qemu-kvm-rhev PATCH 03/17] scsi-bus: correct responses for INQUIRY and REQUEST SENSE Bugzilla: 1464908 RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Dr. David Alan Gilbert RH-Acked-by: John Snow From: Hannes Reinecke According to SPC-3 INQUIRY and REQUEST SENSE should return GOOD even on unsupported LUNS. Signed-off-by: Hannes Reinecke Message-Id: <1503049022-14749-1-git-send-email-hare@suse.de> Reported-by: Laszlo Ersek Fixes: ded6ddc5a7b95217557fa360913d1213e12d4a6d Cc: qemu-stable@nongnu.org Signed-off-by: Hannes Reinecke Signed-off-by: Paolo Bonzini (cherry picked from commit b07fbce6349c7b84642e7ed56c7a1ac3c1caca61) Signed-off-by: Miroslav Rezanina --- hw/scsi/scsi-bus.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index 404686a..55aa5a7 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -524,8 +524,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; @@ -543,9 +545,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; -- 1.8.3.1