From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:34392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R62Dy-0005QY-RQ for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R62Ds-0005Qw-EN for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:06 -0400 Received: from mail-ww0-f53.google.com ([74.125.82.53]:40788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R62Ds-0005PR-4T for qemu-devel@nongnu.org; Tue, 20 Sep 2011 11:27:00 -0400 Received: by mail-ww0-f53.google.com with SMTP id 14so804349wwg.10 for ; Tue, 20 Sep 2011 08:26:59 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 20 Sep 2011 17:26:39 +0200 Message-Id: <1316532406-25340-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1316532406-25340-1-git-send-email-pbonzini@redhat.com> References: <1316532406-25340-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 05/12] scsi: notify the device when unit attention is reported List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Reporting media change events via unit attention sense codes requires a small state machine: first report "NO MEDIUM", then report "MEDIUM MAY HAVE CHANGED". Unfortunately there is no good hooking point for the device to notice that its pending unit attention condition has been reported. This patch reworks the generic machinery to add one. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 32 +++++++++++++++++++++++++++----- hw/scsi.h | 2 ++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index fc2f823..c190509 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -295,6 +295,13 @@ static int32_t scsi_target_send_command(SCSIRequest *req, uint8_t *buf) r->len = scsi_device_get_sense(r->req.dev, r->buf, MIN(req->cmd.xfer, sizeof r->buf), (req->cmd.buf[1] & 1) == 0); + if (r->req.dev->sense_is_ua) { + if (r->req.dev->info->unit_attention_reported) { + r->req.dev->info->unit_attention_reported(req->dev); + } + r->req.dev->sense_len = 0; + r->req.dev->sense_is_ua = false; + } break; default: scsi_req_build_sense(req, SENSE_CODE(LUN_NOT_SUPPORTED)); @@ -383,7 +390,13 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, (buf[0] != INQUIRY && buf[0] != REPORT_LUNS && buf[0] != GET_CONFIGURATION && - buf[0] != GET_EVENT_STATUS_NOTIFICATION)) { + buf[0] != GET_EVENT_STATUS_NOTIFICATION && + + /* + * If we already have a pending unit attention condition, + * report this one before triggering another one. + */ + !(buf[0] == REQUEST_SENSE && d->sense_is_ua))) { req = scsi_req_alloc(&reqops_unit_attention, d, tag, lun, hba_private); } else if (lun != d->lun || @@ -479,10 +492,15 @@ int scsi_req_get_sense(SCSIRequest *req, uint8_t *buf, int len) * * We assume UA_INTLCK_CTRL to be 00b for HBAs that support autosense, and * 10b for HBAs that do not support it (do not call scsi_req_get_sense). - * In the latter case, scsi_req_complete clears unit attention conditions - * after moving them to the device's sense buffer. + * Here we handle unit attention clearing for UA_INTLCK_CTRL == 00b. */ - scsi_clear_unit_attention(req); + if (req->dev->sense_is_ua) { + if (req->dev->info->unit_attention_reported) { + req->dev->info->unit_attention_reported(req->dev); + } + req->dev->sense_len = 0; + req->dev->sense_is_ua = false; + } return ret; } @@ -1082,8 +1100,12 @@ void scsi_req_complete(SCSIRequest *req, int status) if (req->sense_len) { memcpy(req->dev->sense, req->sense, req->sense_len); + req->dev->sense_len = req->sense_len; + req->dev->sense_is_ua = (req->ops == &reqops_unit_attention); + } else { + req->dev->sense_len = 0; + req->dev->sense_is_ua = false; } - req->dev->sense_len = req->sense_len; /* * Unit attention state is now stored in the device's sense buffer diff --git a/hw/scsi.h b/hw/scsi.h index e8dcabf..6d40b8e 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -62,6 +62,7 @@ struct SCSIDevice BlockConf conf; SCSIDeviceInfo *info; SCSISense unit_attention; + bool sense_is_ua; uint8_t sense[SCSI_SENSE_BUF_SIZE]; uint32_t sense_len; QTAILQ_HEAD(, SCSIRequest) requests; @@ -92,6 +93,7 @@ struct SCSIDeviceInfo { void (*destroy)(SCSIDevice *s); SCSIRequest *(*alloc_req)(SCSIDevice *s, uint32_t tag, uint32_t lun, void *hba_private); + void (*unit_attention_reported)(SCSIDevice *s); SCSIReqOps reqops; }; -- 1.7.6