qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize
@ 2012-07-16 14:25 Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP Paolo Bonzini
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

This series adds support for block_resize to virtio-scsi.  Events
are reported via a new event type.  Patches to the spec are on the
list.

Paolo Bonzini (5):
  scsi-disk: removable hard disks support START/STOP
  scsi-disk: report resized disk via sense codes
  scsi: establish precedence levels for unit attention
  scsi: report parameter changes to HBA drivers
  virtio-scsi: report parameter change events

 hw/scsi-bus.c    |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/scsi-disk.c   |   21 +++++++++++------
 hw/scsi.h        |    5 ++++
 hw/virtio-scsi.c |   16 +++++++++++++
 trace-events     |    1 +
 5 files changed, 102 insertions(+), 8 deletions(-)

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP
  2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
@ 2012-07-16 14:25 ` Paolo Bonzini
  2012-07-23 16:44   ` Blue Swirl
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes Paolo Bonzini
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Support for START/STOP UNIT right now is limited to CD-ROMs.  This is wrong,
since removable hard disks (in the real world: SD card readers) also support
it in pretty much the same way.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-disk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index bcec66b..42bae3b 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1251,7 +1251,7 @@ static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     bool start = req->cmd.buf[4] & 1;
     bool loej = req->cmd.buf[4] & 2; /* load on start, eject on !start */
 
-    if (s->qdev.type == TYPE_ROM && loej) {
+    if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && loej) {
         if (!start && !s->tray_open && s->tray_locked) {
             scsi_check_condition(r,
                                  bdrv_is_inserted(s->qdev.conf.bs)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes
  2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP Paolo Bonzini
@ 2012-07-16 14:25 ` Paolo Bonzini
  2012-07-17 11:14   ` Kevin Wolf
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 3/5] scsi: establish precedence levels for unit attention Paolo Bonzini
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Linux will not use these, but a very similar mechanism will be used to
report the condition via virtio-scsi events.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-bus.c  |    5 +++++
 hw/scsi-disk.c |   15 +++++++++++----
 hw/scsi.h      |    2 ++
 3 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 8b961f2..2547c50 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -1161,6 +1161,11 @@ const struct SCSISense sense_code_LUN_FAILURE = {
     .key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01
 };
 
+/* Unit attention, Capacity data has changed */
+const struct SCSISense sense_code_CAPACITY_CHANGED = {
+    .key = UNIT_ATTENTION, .asc = 0x2a, .ascq = 0x09
+};
+
 /* Unit attention, Power on, reset or bus device reset occurred */
 const struct SCSISense sense_code_RESET = {
     .key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 42bae3b..0905446 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1863,6 +1863,13 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
+static void scsi_disk_resize_cb(void *opaque)
+{
+    SCSIDiskState *s = opaque;
+
+    scsi_device_set_ua(&s->qdev, SENSE_CODE(CAPACITY_CHANGED));
+}
+
 static void scsi_cd_change_media_cb(void *opaque, bool load)
 {
     SCSIDiskState *s = opaque;
@@ -1904,11 +1911,13 @@ static bool scsi_cd_is_medium_locked(void *opaque)
     return ((SCSIDiskState *)opaque)->tray_locked;
 }
 
-static const BlockDevOps scsi_cd_block_ops = {
+static const BlockDevOps scsi_disk_block_ops = {
     .change_media_cb = scsi_cd_change_media_cb,
     .eject_request_cb = scsi_cd_eject_request_cb,
     .is_tray_open = scsi_cd_is_tray_open,
     .is_medium_locked = scsi_cd_is_medium_locked,
+
+    .resize_cb = scsi_disk_resize_cb,
 };
 
 static void scsi_disk_unit_attention_reported(SCSIDevice *dev)
@@ -1956,9 +1965,7 @@ static int scsi_initfn(SCSIDevice *dev)
         return -1;
     }
 
-    if (s->features & (1 << SCSI_DISK_F_REMOVABLE)) {
-        bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s);
-    }
+    bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s);
     bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize);
 
     bdrv_iostatus_enable(s->qdev.conf.bs);
diff --git a/hw/scsi.h b/hw/scsi.h
index 47c3b9c..e901350 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -198,6 +198,8 @@ extern const struct SCSISense sense_code_IO_ERROR;
 extern const struct SCSISense sense_code_I_T_NEXUS_LOSS;
 /* Command aborted, Logical Unit failure */
 extern const struct SCSISense sense_code_LUN_FAILURE;
+/* LUN not ready, Capacity data has changed */
+extern const struct SCSISense sense_code_CAPACITY_CHANGED;
 /* LUN not ready, Medium not present */
 extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM;
 /* Unit attention, Power on, reset or bus device reset occurred */
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 3/5] scsi: establish precedence levels for unit attention
  2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes Paolo Bonzini
@ 2012-07-16 14:25 ` Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 4/5] scsi: report parameter changes to HBA drivers Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 5/5] virtio-scsi: report parameter change events Paolo Bonzini
  4 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

When a device is resized, we will report a unit attention condition
for CAPACITY DATA HAS CHANGED.  However, we should ensure that this
condition does not override a more important unit attention condition.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-bus.c  |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/scsi-disk.c |    4 ++--
 hw/scsi.h      |    1 +
 trace-events   |    1 +
 4 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 2547c50..d5e1fb0 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -1530,6 +1530,55 @@ void scsi_req_abort(SCSIRequest *req, int status)
     scsi_req_unref(req);
 }
 
+static int scsi_ua_precedence(SCSISense sense)
+{
+    if (sense.key != UNIT_ATTENTION) {
+        return INT_MAX;
+    }
+    if (sense.asc == 0x29 && sense.ascq == 0x04) {
+        /* DEVICE INTERNAL RESET goes with POWER ON OCCURRED */
+        return 1;
+    } else if (sense.asc == 0x3F && sense.ascq == 0x01) {
+        /* MICROCODE HAS BEEN CHANGED goes with SCSI BUS RESET OCCURRED */
+        return 2;
+    } else if (sense.asc == 0x29 && (sense.ascq == 0x05 || sense.ascq == 0x06)) {
+        /* These two go with "all others". */
+        ;
+    } else if (sense.asc == 0x29 && sense.ascq <= 0x07) {
+        /* POWER ON, RESET OR BUS DEVICE RESET OCCURRED = 0
+         * POWER ON OCCURRED = 1
+         * SCSI BUS RESET OCCURRED = 2
+         * BUS DEVICE RESET FUNCTION OCCURRED = 3
+         * I_T NEXUS LOSS OCCURRED = 7
+         */
+        return sense.ascq;
+    } else if (sense.asc == 0x2F && sense.ascq == 0x01) {
+        /* COMMANDS CLEARED BY POWER LOSS NOTIFICATION  */
+        return 8;
+    }
+    return (sense.asc << 8) | sense.ascq;
+}
+
+void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense)
+{
+    int prec1, prec2;
+    if (sense.key != UNIT_ATTENTION) {
+        return;
+    }
+    trace_scsi_device_set_ua(sdev->id, sdev->lun, sense.key,
+                             sense.asc, sense.ascq);
+
+    /*
+     * Override a pre-existing unit attention condition, except for a more
+     * important reset condition.
+    */
+    prec1 = scsi_ua_precedence(sdev->unit_attention);
+    prec2 = scsi_ua_precedence(sense);
+    if (prec2 < prec1) {
+        sdev->unit_attention = sense;
+    }
+}
+
 void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)
 {
     SCSIRequest *req;
@@ -1538,7 +1587,8 @@ void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense)
         req = QTAILQ_FIRST(&sdev->requests);
         scsi_req_cancel(req);
     }
-    sdev->unit_attention = sense;
+
+    scsi_device_set_ua(sdev, sense);
 }
 
 static char *scsibus_get_dev_path(DeviceState *dev)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 0905446..fabd0bf 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1886,7 +1886,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);
+    scsi_device_set_ua(&s->qdev, SENSE_CODE(UNIT_ATTENTION_NO_MEDIUM));
     s->media_event = true;
     s->eject_request = false;
 }
@@ -1925,7 +1925,7 @@ static void scsi_disk_unit_attention_reported(SCSIDevice *dev)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
     if (s->media_changed) {
         s->media_changed = false;
-        s->qdev.unit_attention = SENSE_CODE(MEDIUM_CHANGED);
+        scsi_device_set_ua(&s->qdev, SENSE_CODE(MEDIUM_CHANGED));
     }
 }
 
diff --git a/hw/scsi.h b/hw/scsi.h
index e901350..4804be9 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -239,6 +239,7 @@ void scsi_req_abort(SCSIRequest *req, int status);
 void scsi_req_cancel(SCSIRequest *req);
 void scsi_req_retry(SCSIRequest *req);
 void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
+void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense);
 int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
 SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
 
diff --git a/trace-events b/trace-events
index 7baa42d..90e9c2a 100644
--- a/trace-events
+++ b/trace-events
@@ -393,6 +393,7 @@ scsi_req_parsed(int target, int lun, int tag, int cmd, int mode, int xfer) "targ
 scsi_req_parsed_lba(int target, int lun, int tag, int cmd, uint64_t lba) "target %d lun %d tag %d command %d lba %"PRIu64
 scsi_req_parse_bad(int target, int lun, int tag, int cmd) "target %d lun %d tag %d command %d"
 scsi_req_build_sense(int target, int lun, int tag, int key, int asc, int ascq) "target %d lun %d tag %d key %#02x asc %#02x ascq %#02x"
+scsi_device_set_ua(int target, int lun, int key, int asc, int ascq) "target %d lun %d key %#02x asc %#02x ascq %#02x"
 scsi_report_luns(int target, int lun, int tag) "target %d lun %d tag %d"
 scsi_inquiry(int target, int lun, int tag, int cdb1, int cdb2) "target %d lun %d tag %d page %#02x/%#02x"
 scsi_test_unit_ready(int target, int lun, int tag) "target %d lun %d tag %d"
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 4/5] scsi: report parameter changes to HBA drivers
  2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
                   ` (2 preceding siblings ...)
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 3/5] scsi: establish precedence levels for unit attention Paolo Bonzini
@ 2012-07-16 14:25 ` Paolo Bonzini
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 5/5] virtio-scsi: report parameter change events Paolo Bonzini
  4 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/scsi-bus.c  |   10 ++++++++++
 hw/scsi-disk.c |    2 +-
 hw/scsi.h      |    2 ++
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index d5e1fb0..77aa946 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -1072,6 +1072,16 @@ int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
     return 0;
 }
 
+void scsi_device_report_change(SCSIDevice *dev, SCSISense sense)
+{
+    SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
+
+    scsi_device_set_ua(dev, sense);
+    if (bus->info->change) {
+        bus->info->change(bus, dev, sense);
+    }
+}
+
 /*
  * Predefined sense codes
  */
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index fabd0bf..8351de5 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1867,7 +1867,7 @@ static void scsi_disk_resize_cb(void *opaque)
 {
     SCSIDiskState *s = opaque;
 
-    scsi_device_set_ua(&s->qdev, SENSE_CODE(CAPACITY_CHANGED));
+    scsi_device_report_change(&s->qdev, SENSE_CODE(CAPACITY_CHANGED));
 }
 
 static void scsi_cd_change_media_cb(void *opaque, bool load)
diff --git a/hw/scsi.h b/hw/scsi.h
index 4804be9..380bb89 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -132,6 +132,7 @@ struct SCSIBusInfo {
     void (*cancel)(SCSIRequest *req);
     void (*hotplug)(SCSIBus *bus, SCSIDevice *dev);
     void (*hot_unplug)(SCSIBus *bus, SCSIDevice *dev);
+    void (*change)(SCSIBus *bus, SCSIDevice *dev, SCSISense sense);
     QEMUSGList *(*get_sg_list)(SCSIRequest *req);
 
     void (*save_request)(QEMUFile *f, SCSIRequest *req);
@@ -240,6 +241,7 @@ void scsi_req_cancel(SCSIRequest *req);
 void scsi_req_retry(SCSIRequest *req);
 void scsi_device_purge_requests(SCSIDevice *sdev, SCSISense sense);
 void scsi_device_set_ua(SCSIDevice *sdev, SCSISense sense);
+void scsi_device_report_change(SCSIDevice *dev, SCSISense sense);
 int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fixed);
 SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lun);
 
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 5/5] virtio-scsi: report parameter change events
  2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
                   ` (3 preceding siblings ...)
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 4/5] scsi: report parameter changes to HBA drivers Paolo Bonzini
@ 2012-07-16 14:25 ` Paolo Bonzini
  4 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-16 14:25 UTC (permalink / raw)
  To: qemu-devel; +Cc: kvm

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/virtio-scsi.c |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c
index 83dbabd..80a47d7 100644
--- a/hw/virtio-scsi.c
+++ b/hw/virtio-scsi.c
@@ -27,6 +27,7 @@
 /* Feature Bits */
 #define VIRTIO_SCSI_F_INOUT                    0
 #define VIRTIO_SCSI_F_HOTPLUG                  1
+#define VIRTIO_SCSI_F_CHANGE                   2
 
 /* Response codes */
 #define VIRTIO_SCSI_S_OK                       0
@@ -63,6 +64,7 @@
 #define VIRTIO_SCSI_T_NO_EVENT                 0
 #define VIRTIO_SCSI_T_TRANSPORT_RESET          1
 #define VIRTIO_SCSI_T_ASYNC_NOTIFY             2
+#define VIRTIO_SCSI_T_PARAM_CHANGE             3
 
 /* Reasons for transport reset event */
 #define VIRTIO_SCSI_EVT_RESET_HARD             0
@@ -554,6 +556,7 @@ static uint32_t virtio_scsi_get_features(VirtIODevice *vdev,
                                          uint32_t requested_features)
 {
     requested_features |= (1UL << VIRTIO_SCSI_F_HOTPLUG);
+    requested_features |= (1UL << VIRTIO_SCSI_F_CHANGE);
     return requested_features;
 }
 
@@ -637,6 +640,18 @@ static void virtio_scsi_handle_event(VirtIODevice *vdev, VirtQueue *vq)
     }
 }
 
+static void virtio_scsi_change(SCSIBus *bus, SCSIDevice *dev, SCSISense sense)
+{
+    VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
+
+    if (((s->vdev.guest_features >> VIRTIO_SCSI_F_CHANGE) & 1) &&
+        (s->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK) &&
+        dev->type != TYPE_ROM) {
+        virtio_scsi_push_event(s, dev, VIRTIO_SCSI_T_PARAM_CHANGE,
+                               sense.asc | (sense.ascq << 8));
+    }
+}
+
 static void virtio_scsi_hotplug(SCSIBus *bus, SCSIDevice *dev)
 {
     VirtIOSCSI *s = container_of(bus, VirtIOSCSI, bus);
@@ -666,6 +681,7 @@ static struct SCSIBusInfo virtio_scsi_scsi_info = {
 
     .complete = virtio_scsi_command_complete,
     .cancel = virtio_scsi_request_cancelled,
+    .change = virtio_scsi_change,
     .hotplug = virtio_scsi_hotplug,
     .hot_unplug = virtio_scsi_hot_unplug,
     .get_sg_list = virtio_scsi_get_sg_list,
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes Paolo Bonzini
@ 2012-07-17 11:14   ` Kevin Wolf
  2012-07-17 11:15     ` Paolo Bonzini
  0 siblings, 1 reply; 10+ messages in thread
From: Kevin Wolf @ 2012-07-17 11:14 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, kvm

Am 16.07.2012 16:25, schrieb Paolo Bonzini:
> Linux will not use these, but a very similar mechanism will be used to
> report the condition via virtio-scsi events.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/scsi-bus.c  |    5 +++++
>  hw/scsi-disk.c |   15 +++++++++++----
>  hw/scsi.h      |    2 ++
>  3 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index 8b961f2..2547c50 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -1161,6 +1161,11 @@ const struct SCSISense sense_code_LUN_FAILURE = {
>      .key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01
>  };
>  
> +/* Unit attention, Capacity data has changed */
> +const struct SCSISense sense_code_CAPACITY_CHANGED = {
> +    .key = UNIT_ATTENTION, .asc = 0x2a, .ascq = 0x09
> +};
> +
>  /* Unit attention, Power on, reset or bus device reset occurred */
>  const struct SCSISense sense_code_RESET = {
>      .key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 42bae3b..0905446 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1863,6 +1863,13 @@ static void scsi_destroy(SCSIDevice *dev)
>      blockdev_mark_auto_del(s->qdev.conf.bs);
>  }
>  
> +static void scsi_disk_resize_cb(void *opaque)
> +{
> +    SCSIDiskState *s = opaque;
> +
> +    scsi_device_set_ua(&s->qdev, SENSE_CODE(CAPACITY_CHANGED));
> +}
> +
>  static void scsi_cd_change_media_cb(void *opaque, bool load)
>  {
>      SCSIDiskState *s = opaque;
> @@ -1904,11 +1911,13 @@ static bool scsi_cd_is_medium_locked(void *opaque)
>      return ((SCSIDiskState *)opaque)->tray_locked;
>  }
>  
> -static const BlockDevOps scsi_cd_block_ops = {
> +static const BlockDevOps scsi_disk_block_ops = {
>      .change_media_cb = scsi_cd_change_media_cb,
>      .eject_request_cb = scsi_cd_eject_request_cb,
>      .is_tray_open = scsi_cd_is_tray_open,
>      .is_medium_locked = scsi_cd_is_medium_locked,
> +
> +    .resize_cb = scsi_disk_resize_cb,
>  };
>  
>  static void scsi_disk_unit_attention_reported(SCSIDevice *dev)
> @@ -1956,9 +1965,7 @@ static int scsi_initfn(SCSIDevice *dev)
>          return -1;
>      }
>  
> -    if (s->features & (1 << SCSI_DISK_F_REMOVABLE)) {
> -        bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s);
> -    }
> +    bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s);

Are you aware of this code?

bool bdrv_dev_has_removable_media(BlockDriverState *bs)
{
    return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
}

This means that now all SCSI disks have removable media from the
monitor's point of view.

Kevin

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes
  2012-07-17 11:14   ` Kevin Wolf
@ 2012-07-17 11:15     ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-17 11:15 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel, kvm

Il 17/07/2012 13:14, Kevin Wolf ha scritto:
>> > -    if (s->features & (1 << SCSI_DISK_F_REMOVABLE)) {
>> > -        bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s);
>> > -    }
>> > +    bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s);
> Are you aware of this code?
> 
> bool bdrv_dev_has_removable_media(BlockDriverState *bs)
> {
>     return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
> }
> 
> This means that now all SCSI disks have removable media from the
> monitor's point of view.

I remembered there was something similar but I couldn't find it.  I'll
rework the patch to have two separate sets of dev_ops.

Thanks very much!

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP
  2012-07-16 14:25 ` [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP Paolo Bonzini
@ 2012-07-23 16:44   ` Blue Swirl
  2012-07-23 16:50     ` Paolo Bonzini
  0 siblings, 1 reply; 10+ messages in thread
From: Blue Swirl @ 2012-07-23 16:44 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, kvm

On Mon, Jul 16, 2012 at 2:25 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
> Support for START/STOP UNIT right now is limited to CD-ROMs.  This is wrong,
> since removable hard disks (in the real world: SD card readers) also support
> it in pretty much the same way.

I remember vaguely tuning a set of large SCSI hard disks
(non-removable) so that they all didn't start immediately at the same
time (which could have burned out the PSU) but only with START UNIT
command. I think Linux or maybe even the BIOS started the drives
(nicely in sequence) before accessing the drive.

>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  hw/scsi-disk.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index bcec66b..42bae3b 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1251,7 +1251,7 @@ static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>      bool start = req->cmd.buf[4] & 1;
>      bool loej = req->cmd.buf[4] & 2; /* load on start, eject on !start */
>
> -    if (s->qdev.type == TYPE_ROM && loej) {
> +    if ((s->features & (1 << SCSI_DISK_F_REMOVABLE)) && loej) {
>          if (!start && !s->tray_open && s->tray_locked) {
>              scsi_check_condition(r,
>                                   bdrv_is_inserted(s->qdev.conf.bs)
> --
> 1.7.10.4
>
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP
  2012-07-23 16:44   ` Blue Swirl
@ 2012-07-23 16:50     ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2012-07-23 16:50 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel, kvm

Il 23/07/2012 18:44, Blue Swirl ha scritto:
>> > Support for START/STOP UNIT right now is limited to CD-ROMs.  This is wrong,
>> > since removable hard disks (in the real world: SD card readers) also support
>> > it in pretty much the same way.
> I remember vaguely tuning a set of large SCSI hard disks
> (non-removable) so that they all didn't start immediately at the same
> time (which could have burned out the PSU) but only with START UNIT
> command. I think Linux or maybe even the BIOS started the drives
> (nicely in sequence) before accessing the drive.

Yes, all disks do start/stop.  Removable disks support load and eject in
addition.  I'll fix the commit message.

Paolo

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-07-23 16:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-16 14:25 [Qemu-devel] [PATCH 0/5] virtio-scsi: support block_resize Paolo Bonzini
2012-07-16 14:25 ` [Qemu-devel] [PATCH 1/5] scsi-disk: removable hard disks support START/STOP Paolo Bonzini
2012-07-23 16:44   ` Blue Swirl
2012-07-23 16:50     ` Paolo Bonzini
2012-07-16 14:25 ` [Qemu-devel] [PATCH 2/5] scsi-disk: report resized disk via sense codes Paolo Bonzini
2012-07-17 11:14   ` Kevin Wolf
2012-07-17 11:15     ` Paolo Bonzini
2012-07-16 14:25 ` [Qemu-devel] [PATCH 3/5] scsi: establish precedence levels for unit attention Paolo Bonzini
2012-07-16 14:25 ` [Qemu-devel] [PATCH 4/5] scsi: report parameter changes to HBA drivers Paolo Bonzini
2012-07-16 14:25 ` [Qemu-devel] [PATCH 5/5] virtio-scsi: report parameter change events Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).