[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION |
Date: |
Mon, 31 Oct 2011 14:30:05 +0100 |
From: Paolo Bonzini <address@hidden>
This adds support for media change notification via the GET EVENT STATUS
NOTIFICATION command, used by Linux versions 2.6.38 and newer.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
hw/scsi-disk.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 8f8a94d..dd2b605 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -72,6 +72,7 @@ struct SCSIDiskState
uint32_t removable;
uint64_t max_lba;
bool media_changed;
+ bool media_event;
QEMUBH *bh;
char *version;
char *serial;
@@ -687,11 +688,58 @@ fail:
return -1;
}
-static int scsi_get_event_status_notification(SCSIDiskState *s,
- SCSIDiskReq *r, uint8_t *outbuf)
+static int scsi_event_status_media(SCSIDiskState *s, uint8_t *outbuf)
{
- scsi_check_condition(r, SENSE_CODE(INVALID_OPCODE));
- return -1;
+ uint8_t event_code, media_status;
+
+ media_status = 0;
+ if (s->tray_open) {
+ media_status = MS_TRAY_OPEN;
+ } else if (bdrv_is_inserted(s->bs)) {
+ media_status = MS_MEDIA_PRESENT;
+ }
+
+ /* Event notification descriptor */
+ event_code = MEC_NO_CHANGE;
+ if (media_status != MS_TRAY_OPEN && s->media_event) {
+ event_code = MEC_NEW_MEDIA;
+ s->media_event = false;
+ }
+
+ outbuf[0] = event_code;
+ outbuf[1] = media_status;
+
+ /* These fields are reserved, just clear them. */
+ outbuf[2] = 0;
+ outbuf[3] = 0;
+ return 4;
+}
+
+static int scsi_get_event_status_notification(SCSIDiskState *s, SCSIDiskReq *r,
+ uint8_t *outbuf)
+{
+ int size;
+ uint8_t *buf = r->req.cmd.buf;
+ uint8_t notification_class_request = buf[4];
+ if (s->qdev.type != TYPE_ROM) {
+ return -1;
+ }
+ if ((buf[1] & 1) == 0) {
+ /* asynchronous */
+ return -1;
+ }
+
+ size = 4;
+ outbuf[0] = outbuf[1] = 0;
+ outbuf[3] = 1 << GESN_MEDIA; /* supported events */
+ if (notification_class_request & (1 << GESN_MEDIA)) {
+ outbuf[2] = GESN_MEDIA;
+ size += scsi_event_status_media(s, &outbuf[size]);
+ } else {
+ outbuf[2] = 0x80;
+ }
+ stw_be_p(outbuf, size - 4);
+ return size;
}
static int scsi_get_configuration(SCSIDiskState *s, uint8_t *outbuf)
@@ -1442,6 +1490,7 @@ static void scsi_cd_change_media_cb(void *opaque, bool
load)
s->media_changed = load;
s->tray_open = !load;
s->qdev.unit_attention = SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM);
+ s->media_event = true;
}
static bool scsi_cd_is_tray_open(void *opaque)
--
1.7.6.4
- [Qemu-devel] [PATCH 44/55] scsi-disk: do not duplicate BlockDriverState member, (continued)
- [Qemu-devel] [PATCH 44/55] scsi-disk: do not duplicate BlockDriverState member, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 46/55] scsi-disk: small clean up to INQUIRY, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 47/55] scsi: move max_lba to SCSIDevice, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 50/55] scsi: pass cdb to alloc_req, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 49/55] scsi: export scsi_generic_reqops, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 52/55] scsi-disk: bump SCSIRequest reference count until aio completion runs, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 51/55] scsi: do not call transfer_data after canceling a request, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 36/55] scsi: add channel to addressing, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 21/55] atapi: cleanup/fix mode sense results, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 20/55] atapi: move GESN definitions to scsi-defs.h, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 30/55] scsi-disk: report media changed via GET EVENT STATUS NOTIFICATION,
Kevin Wolf <=
- [Qemu-devel] [PATCH 23/55] scsi-disk: report media changed via unit attention sense codes, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 42/55] scsi-generic: look at host status, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 48/55] scsi: make reqops const, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 53/55] scsi-generic: bump SCSIRequest reference count until aio completion runs, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 27/55] atapi/scsi-disk: make mode page values coherent between the two, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 28/55] scsi-disk: support DVD profile in GET CONFIGURATION, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 54/55] scsi: push request restart to SCSIDevice, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 29/55] scsi-disk: support READ DVD STRUCTURE, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 25/55] scsi-disk: add stubs for more MMC commands, Kevin Wolf, 2011/10/31
- [Qemu-devel] [PATCH 43/55] scsi-generic: snoop READ CAPACITY commands to get block size, Kevin Wolf, 2011/10/31