All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes
@ 2011-08-03 13:07 Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 01/45] block: Attach non-qdev devices as well Markus Armbruster
                   ` (46 more replies)
  0 siblings, 47 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

This patch series looks bigger than it is.  All the patches are small
and hopefully easy to review.

Objectives:

* Push BlockDriverState members locked, tray_open, media_changed into
  device models, where they belong.

* BlockDriverState member removable is a confusing mess, replace it.

* Improve eject -f.

Also clean up minor messes as they get in the way.

It is based on Kevin's block branch f08df41b.

Part I: Preliminaries
PATCH 01-03: Work on block layer interface for device models

Part II: Move tray state to device models
PATCH 04-10 IDE tray open/closed
PATCH 11-12 SCSI tray open/closed
PATCH 13-14 block layer kill tray_open
PATCH 15-16 IDE & SCSI tray lock
PATCH 17-19 block layer kill locked
PATCH 20-24 IDE & SCSI tray bug fixes
PATCH 25-27 IDE & SCSI migrate tray state
PATCH 28-30 block layer & fdc media_changed

Part III: Replace removable
PATCH 31-34 clean up inappopriate uses of removable
PATCH 35-36 replace remaining users

Part IV: Miscellaneous
PATCH 37    cover tray open/closed in info block
PATCH 38-43 Reduce unclean use of block_int.h
PATCH 44-45 Improve eject -f

Naturally, I want all parts applied.  But I did my best to make
applying only a prefix workable, too.

Review invited from:

* Kevin, Christoph and Amit reviewed v1.

* Hannes commented on the SCSI stuff in v1.

* Luiz, the following patches affect QMP's query-block: PATCH 35
  `block: Clean up remaining users of "removable"' and PATCH 38
  `block: Show whether the guest ejected the medium in info block'.

* Juan, please review PATCH 26 `ide/atapi: Preserve tray state on
  migration', PATCH 27 `scsi-disk: Preserve tray state on migration',
  and PATCH 32 `savevm: Include writable devices with removable
  media'.

* Andrzej commented to v1 of PATCH 34 `spitz tosa: Simplify "drive is
  suitable for microdrive" test'.  It is unchanged.

* Stefano, you reviewed v1 of PATCH 35 (affects "-drive if=xen").
  Please have a look at new PATCH 33 `xen: Clean up
  pci_piix3_xen_ide_unplug()'s test for "not a CD"'.

Testing

* Both master and the block branch are broken for me by Avi's memory
  API work (Avi reproduced, and claims to have a fix), so for testing
  I had to rebase the block branch on an older master cde1a700 plus my
  dependencies: some Xen work e3745602..679f4f8b, and some nand work
  64de0e46..63efb1d9.

* Linux boots, both from HD and CD.

* For both IDE and SCSI:

  - info block reports tray state correctly

  - Guest locking the tray stops eject (without -f) and change

  - eject -f; change works even while tray is locked by guest

  - Physical tray state tracks the virtual one (file=/dev/sr0)

  - Reading /dev/sr0 with tray open behaves as before: IDE closes the
    tray and reads (matches bare metal), SCSI reports no medium

  - Tray state is migrated correctly (tested with savevm/loadvm)

* Guest still notices CD media change (IDE only, SCSI doesn't work
  before or after my patches because GESN isn't implemented)

* Migrating ide-cd to older version works when tray is closed and
  unlocked, else fails (tested with savevm/loadvm)

* Migrating scsi-cd to older version fails

* Linux detects fdc media change (from monitor)

* savevm and loadvm snapshot read/write floppy

* spitz and tosa initialize their microdrive as before (PATCH 34;
  tested with -S -M {spitz,tosa}, didn't actually try to boot)

Not tested:

* BlockDriver "host_floppy"

  Lack the hardware.  Like pretty much everybody not running a
  computer museum.  

  Is keeping BlockDriver "host_floppy" around still worth our while?

  If the answer is no, I'm happy to respin with PATCH 28-30 replaced
  by a single patch to remove it, and simplify block.c and hw/fdc.c.


v2:

* Rebased to block branch; non-trivial conflicts:
  - Old PATCH 01-02,06-09 already there, drop
  - `block: Attach non-qdev devices as well':
    - cover new pci_piix3_xen_ide_unplug()
    - hw/nand has been qdefivied, drop hunk
    - onenand_init() changed, rewrite hunk
  - pci_piix3_xen_ide_unplug() needs new PATCH 33.

* Drop old PATCH 18 `scsi-disk: Reject CD-specific SCSI commands to
  disks' because Hannes wants to do it differently, and it's not
  essential to this series.

* Christoph's advice:
  - Rework `ide: Update command code definitions as per ACS-2'
  - Add comment to `ide: Fix ATA command READ to set ATAPI signature
    for CD-ROM'
  - Squash `ide/atapi: Track tray open/close state' and `ide/atapi:
    Switch from BlockDriverState's tray_open to own'
  - Squash `ide/atapi: Track tray locked state' and `ide/atapi: Switch
    from BlockDriverState's locked to own tray_locked'
  - Squash `scsi-disk: Track tray locked state' and `scsi-disk: Switch
    from BlockDriverState's locked to own tray_locked'
  - Drop `block: Move BlockDriverAIOCB & friends from block_int.h to
    block.h'

* Luiz's advice:
  - Change query-block to always include "ejected" for removable
    devices.  Requires moving `block: Show whether the guest ejected
    the medium in info block', which causes a bunch of conflicts.

* A few cosmetic improvements


Markus Armbruster (45):
  block: Attach non-qdev devices as well
  block: Generalize change_cb() to BlockDevOps
  block: Split change_cb() into change_media_cb(), resize_cb()
  ide: Update command code definitions as per ACS-2 Table B.2
  ide: Clean up case label indentation in ide_exec_cmd()
  ide: Fix ATA command READ to set ATAPI signature for CD-ROM
  ide: Use a table to declare which drive kinds accept each command
  ide: Reject ATA commands specific to drive kinds
  ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  ide/atapi: Track tray open/close state
  scsi-disk: Factor out scsi_disk_emulate_start_stop()
  scsi-disk: Track tray open/close state
  block: Revert entanglement of bdrv_is_inserted() with tray status
  block: Drop tray status tracking, no longer used
  ide/atapi: Track tray locked state
  scsi-disk: Track tray locked state
  block: Leave enforcing tray lock to device models
  block: Drop medium lock tracking, ask device models instead
  block: Rename bdrv_set_locked() to bdrv_lock_medium()
  ide: Provide IDEDeviceInfo method exit()
  ide/atapi: Don't fail eject when tray is already open
  ide/atapi: Avoid physical/virtual tray state mismatch
  scsi-disk: Fix START_STOP to fail when it can't eject
  scsi-disk: Avoid physical/virtual tray state mismatch
  ide: Give vmstate structs internal linkage where possible
  ide/atapi: Preserve tray state on migration
  scsi-disk: Preserve tray state on migration
  block/raw: Fix to forward method bdrv_media_changed()
  block: Leave tracking media change to device models
  fdc: Make media change detection more robust
  block: Clean up bdrv_flush_all()
  savevm: Include writable devices with removable media
  xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD"
  spitz tosa: Simplify "drive is suitable for microdrive" test
  block: Clean up remaining users of "removable"
  block: Drop BlockDriverState member removable
  block: Show whether the guest ejected the medium in info block
  block: Move BlockConf & friends from block_int.h to block.h
  hw: Trim superfluous #include "block_int.h"
  block: Declare qemu_blockalign() in block.h, not block_int.h
  block: New bdrv_set_buffer_alignment()
  block: Reset buffer alignment on detach
  nbd: Clean up use of block_int.h
  block: New change_media_cb() parameter load
  ide/atapi scsi-disk: Make monitor eject -f, then change work

 block.c              |  195 +++++++++++++++++++++++++++-----------------------
 block.h              |   90 ++++++++++++++++++++---
 block/nbd.c          |    1 +
 block/raw-posix.c    |    8 +-
 block/raw.c          |   13 +++-
 block_int.h          |   54 ++-------------
 blockdev.c           |   15 ++---
 hw/fdc.c             |   48 ++++++-------
 hw/ide/atapi.c       |   58 +++++++--------
 hw/ide/cmd646.c      |    1 -
 hw/ide/core.c        |  196 ++++++++++++++++++++++++++++++++++++++------------
 hw/ide/ich.c         |    1 -
 hw/ide/internal.h    |  175 ++++++++++++++++++++++++---------------------
 hw/ide/isa.c         |    1 -
 hw/ide/macio.c       |    1 -
 hw/ide/microdrive.c  |    1 -
 hw/ide/mmio.c        |    1 -
 hw/ide/pci.c         |    1 -
 hw/ide/piix.c        |    7 +-
 hw/ide/qdev.c        |   30 ++++++++
 hw/ide/via.c         |    1 -
 hw/lsi53c895a.c      |    1 -
 hw/onenand.c         |    4 +-
 hw/pflash_cfi01.c    |    1 +
 hw/pflash_cfi02.c    |    1 +
 hw/qdev-properties.c |    6 +-
 hw/scsi-bus.c        |   10 +++
 hw/scsi-disk.c       |  111 ++++++++++++++++++++++++++---
 hw/scsi-generic.c    |    1 -
 hw/scsi.h            |    5 +-
 hw/sd.c              |   14 ++--
 hw/spitz.c           |   10 +--
 hw/tosa.c            |   10 +--
 hw/usb-msd.c         |    2 +-
 hw/virtio-blk.c      |   15 ++--
 hw/virtio.h          |    2 +-
 hw/xen_disk.c        |    1 +
 nbd.c                |    1 +
 nbd.h                |    2 -
 qmp-commands.hx      |    2 +
 savevm.c             |    4 +-
 trace-events         |    2 +-
 42 files changed, 690 insertions(+), 413 deletions(-)

-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 01/45] block: Attach non-qdev devices as well
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 02/45] block: Generalize change_cb() to BlockDevOps Markus Armbruster
                   ` (45 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

For now, this just protects against programming errors like having the
same drive back multiple non-qdev devices, or untimely bdrv_delete().
Later commits will add other interesting uses.

While there, rename BlockDriverState member peer to dev, bdrv_attach()
to bdrv_attach_dev(), bdrv_detach() to bdrv_detach_dev(), and
bdrv_get_attached() to bdrv_get_attached_dev().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c              |   29 ++++++++++++++++++++---------
 block.h              |    7 ++++---
 block_int.h          |    3 ++-
 blockdev.c           |    5 ++---
 hw/ide/core.c        |    1 +
 hw/ide/piix.c        |    4 ++--
 hw/onenand.c         |    4 +++-
 hw/pflash_cfi01.c    |    1 +
 hw/pflash_cfi02.c    |    1 +
 hw/qdev-properties.c |    6 +++---
 hw/sd.c              |    1 +
 hw/usb-msd.c         |    2 +-
 hw/xen_disk.c        |    1 +
 13 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/block.c b/block.c
index 4826fd8..10a39f1 100644
--- a/block.c
+++ b/block.c
@@ -728,7 +728,7 @@ void bdrv_make_anon(BlockDriverState *bs)
 
 void bdrv_delete(BlockDriverState *bs)
 {
-    assert(!bs->peer);
+    assert(!bs->dev);
 
     /* remove from list, if necessary */
     bdrv_make_anon(bs);
@@ -742,26 +742,37 @@ void bdrv_delete(BlockDriverState *bs)
     qemu_free(bs);
 }
 
-int bdrv_attach(BlockDriverState *bs, DeviceState *qdev)
+int bdrv_attach_dev(BlockDriverState *bs, void *dev)
+/* TODO change to DeviceState *dev when all users are qdevified */
 {
-    if (bs->peer) {
+    if (bs->dev) {
         return -EBUSY;
     }
-    bs->peer = qdev;
+    bs->dev = dev;
     return 0;
 }
 
-void bdrv_detach(BlockDriverState *bs, DeviceState *qdev)
+/* TODO qdevified devices don't use this, remove when devices are qdevified */
+void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev)
 {
-    assert(bs->peer == qdev);
-    bs->peer = NULL;
+    if (bdrv_attach_dev(bs, dev) < 0) {
+        abort();
+    }
+}
+
+void bdrv_detach_dev(BlockDriverState *bs, void *dev)
+/* TODO change to DeviceState *dev when all users are qdevified */
+{
+    assert(bs->dev == dev);
+    bs->dev = NULL;
     bs->change_cb = NULL;
     bs->change_opaque = NULL;
 }
 
-DeviceState *bdrv_get_attached(BlockDriverState *bs)
+/* TODO change to return DeviceState * when all users are qdevified */
+void *bdrv_get_attached_dev(BlockDriverState *bs)
 {
-    return bs->peer;
+    return bs->dev;
 }
 
 /*
diff --git a/block.h b/block.h
index a3bfaaf..a82b0cd 100644
--- a/block.h
+++ b/block.h
@@ -73,9 +73,10 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
               BlockDriver *drv);
 void bdrv_close(BlockDriverState *bs);
-int bdrv_attach(BlockDriverState *bs, DeviceState *qdev);
-void bdrv_detach(BlockDriverState *bs, DeviceState *qdev);
-DeviceState *bdrv_get_attached(BlockDriverState *bs);
+int bdrv_attach_dev(BlockDriverState *bs, void *dev);
+void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
+void bdrv_detach_dev(BlockDriverState *bs, void *dev);
+void *bdrv_get_attached_dev(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
diff --git a/block_int.h b/block_int.h
index f6d02b3..cf7b7e7 100644
--- a/block_int.h
+++ b/block_int.h
@@ -167,7 +167,8 @@ struct BlockDriverState {
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
-    DeviceState *peer;
+    void *dev;                  /* attached device model, if any */
+    /* TODO change to DeviceState when all users are qdevified */
 
     char filename[1024];
     char backing_file[1024]; /* if non zero, the image is a diff of
diff --git a/blockdev.c b/blockdev.c
index a25367a..40f061a 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -14,7 +14,6 @@
 #include "qemu-option.h"
 #include "qemu-config.h"
 #include "sysemu.h"
-#include "hw/qdev.h"
 #include "block_int.h"
 
 static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
@@ -747,12 +746,12 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
     bdrv_flush(bs);
     bdrv_close(bs);
 
-    /* if we have a device associated with this BlockDriverState (bs->peer)
+    /* if we have a device attached to this BlockDriverState
      * then we need to make the drive anonymous until the device
      * can be removed.  If this is a drive with no device backing
      * then we can just get rid of the block driver state right here.
      */
-    if (bs->peer) {
+    if (bdrv_get_attached_dev(bs)) {
         bdrv_make_anon(bs);
     } else {
         drive_uninit(drive_get_by_blockdev(bs));
diff --git a/hw/ide/core.c b/hw/ide/core.c
index d145b19..bcef8bc 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1865,6 +1865,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
                 error_report("Can't set up IDE drive %s", dinfo->id);
                 exit(1);
             }
+            bdrv_attach_dev_nofail(dinfo->bdrv, &bus->ifs[i]);
         } else {
             ide_reset(&bus->ifs[i]);
         }
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index f527dbd..00fb683 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -162,9 +162,9 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
         if (di != NULL && di->bdrv != NULL && !di->bdrv->removable) {
-            DeviceState *ds = bdrv_get_attached(di->bdrv);
+            DeviceState *ds = bdrv_get_attached_dev(di->bdrv);
             if (ds) {
-                bdrv_detach(di->bdrv, ds);
+                bdrv_detach_dev(di->bdrv, ds);
             }
             bdrv_close(di->bdrv);
             pci_ide->bus[di->bus].ifs[di->unit].bs = NULL;
diff --git a/hw/onenand.c b/hw/onenand.c
index b0cbebc..f2a5f5d 100644
--- a/hw/onenand.c
+++ b/hw/onenand.c
@@ -717,7 +717,9 @@ void *onenand_init(BlockDriverState *bdrv,
     s->iomemtype = cpu_register_io_memory(onenand_readfn,
                     onenand_writefn, s, DEVICE_NATIVE_ENDIAN);
     s->bdrv = bdrv;
-    if (!s->bdrv) {
+    if (s->bdrv) {
+        bdrv_attach_dev_nofail(s->bdrv, s);
+    } else {
         s->image = memset(qemu_malloc(size + (size >> 5)),
                         0xff, size + (size >> 5));
     }
diff --git a/hw/pflash_cfi01.c b/hw/pflash_cfi01.c
index 90fdc84..285e385 100644
--- a/hw/pflash_cfi01.c
+++ b/hw/pflash_cfi01.c
@@ -620,6 +620,7 @@ pflash_t *pflash_cfi01_register(target_phys_addr_t base, ram_addr_t off,
             qemu_free(pfl);
             return NULL;
         }
+        bdrv_attach_dev_nofail(pfl->bs, pfl);
     }
 #if 0 /* XXX: there should be a bit to set up read-only,
        *      the same way the hardware does (with WP pin).
diff --git a/hw/pflash_cfi02.c b/hw/pflash_cfi02.c
index 725cd1e..059824d 100644
--- a/hw/pflash_cfi02.c
+++ b/hw/pflash_cfi02.c
@@ -643,6 +643,7 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off,
             qemu_free(pfl);
             return NULL;
         }
+        bdrv_attach_dev_nofail(pfl->bs, pfl);
     }
 #if 0 /* XXX: there should be a bit to set up read-only,
        *      the same way the hardware does (with WP pin).
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index eff2d24..f06b317 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -312,7 +312,7 @@ static int parse_drive(DeviceState *dev, Property *prop, const char *str)
     bs = bdrv_find(str);
     if (bs == NULL)
         return -ENOENT;
-    if (bdrv_attach(bs, dev) < 0)
+    if (bdrv_attach_dev(bs, dev) < 0)
         return -EEXIST;
     *ptr = bs;
     return 0;
@@ -323,7 +323,7 @@ static void free_drive(DeviceState *dev, Property *prop)
     BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
 
     if (*ptr) {
-        bdrv_detach(*ptr, dev);
+        bdrv_detach_dev(*ptr, dev);
         blockdev_auto_del(*ptr);
     }
 }
@@ -678,7 +678,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *va
 {
     int res;
 
-    res = bdrv_attach(value, dev);
+    res = bdrv_attach_dev(value, dev);
     if (res < 0) {
         error_report("Can't attach drive %s to %s.%s: %s",
                      bdrv_get_device_name(value),
diff --git a/hw/sd.c b/hw/sd.c
index c2c80ab..8d42ee2 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -449,6 +449,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)
     sd->enable = 1;
     sd_reset(sd, bs);
     if (sd->bdrv) {
+        bdrv_attach_dev_nofail(sd->bdrv, sd);
         bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
     }
     return sd;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index cdeac58..3edc25c 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -523,7 +523,7 @@ static int usb_msd_initfn(USBDevice *dev)
      *
      * The hack is probably a bad idea.
      */
-    bdrv_detach(bs, &s->dev.qdev);
+    bdrv_detach_dev(bs, &s->dev.qdev);
     s->conf.bs = NULL;
 
     if (!s->serial) {
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index add815f..89fe824 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -692,6 +692,7 @@ static int blk_init(struct XenDevice *xendev)
         xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
         blkdev->bs = blkdev->dinfo->bdrv;
     }
+    bdrv_attach_dev_nofail(blkdev->bs, blkdev);
     blkdev->file_blk  = BLOCK_SIZE;
     blkdev->file_size = bdrv_getlength(blkdev->bs);
     if (blkdev->file_size < 0) {
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 02/45] block: Generalize change_cb() to BlockDevOps
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 01/45] block: Attach non-qdev devices as well Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 03/45] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
                   ` (44 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

So we can more easily add device model callbacks.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c         |   43 +++++++++++++++++++++----------------------
 block.h         |    9 ++++++---
 block_int.h     |    5 ++---
 hw/ide/core.c   |    6 +++++-
 hw/sd.c         |    6 +++++-
 hw/virtio-blk.c |    6 +++++-
 6 files changed, 44 insertions(+), 31 deletions(-)

diff --git a/block.c b/block.c
index 10a39f1..3aa1eb5 100644
--- a/block.c
+++ b/block.c
@@ -44,6 +44,7 @@
 #include <windows.h>
 #endif
 
+static void bdrv_dev_change_cb(BlockDriverState *bs, int reason);
 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque);
@@ -661,10 +662,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
     }
 
     if (!bdrv_key_required(bs)) {
-        /* call the change callback */
         bs->media_changed = 1;
-        if (bs->change_cb)
-            bs->change_cb(bs->change_opaque, CHANGE_MEDIA);
+        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
     }
 
     return 0;
@@ -700,10 +699,8 @@ void bdrv_close(BlockDriverState *bs)
             bdrv_close(bs->file);
         }
 
-        /* call the change callback */
         bs->media_changed = 1;
-        if (bs->change_cb)
-            bs->change_cb(bs->change_opaque, CHANGE_MEDIA);
+        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
     }
 }
 
@@ -765,8 +762,8 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev)
 {
     assert(bs->dev == dev);
     bs->dev = NULL;
-    bs->change_cb = NULL;
-    bs->change_opaque = NULL;
+    bs->dev_ops = NULL;
+    bs->dev_opaque = NULL;
 }
 
 /* TODO change to return DeviceState * when all users are qdevified */
@@ -775,6 +772,20 @@ void *bdrv_get_attached_dev(BlockDriverState *bs)
     return bs->dev;
 }
 
+void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
+                      void *opaque)
+{
+    bs->dev_ops = ops;
+    bs->dev_opaque = opaque;
+}
+
+static void bdrv_dev_change_cb(BlockDriverState *bs, int reason)
+{
+    if (bs->dev_ops && bs->dev_ops->change_cb) {
+        bs->dev_ops->change_cb(bs->dev_opaque, reason);
+    }
+}
+
 /*
  * Run consistency checks on an image
  *
@@ -1232,9 +1243,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
     ret = drv->bdrv_truncate(bs, offset);
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
-        if (bs->change_cb) {
-            bs->change_cb(bs->change_opaque, CHANGE_SIZE);
-        }
+        bdrv_dev_change_cb(bs, CHANGE_SIZE);
     }
     return ret;
 }
@@ -1572,15 +1581,6 @@ int bdrv_enable_write_cache(BlockDriverState *bs)
     return bs->enable_write_cache;
 }
 
-/* XXX: no longer used */
-void bdrv_set_change_cb(BlockDriverState *bs,
-                        void (*change_cb)(void *opaque, int reason),
-                        void *opaque)
-{
-    bs->change_cb = change_cb;
-    bs->change_opaque = opaque;
-}
-
 int bdrv_is_encrypted(BlockDriverState *bs)
 {
     if (bs->backing_hd && bs->backing_hd->encrypted)
@@ -1619,8 +1619,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
         bs->valid_key = 1;
         /* call the change callback now, we skipped it on open */
         bs->media_changed = 1;
-        if (bs->change_cb)
-            bs->change_cb(bs->change_opaque, CHANGE_MEDIA);
+        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
     }
     return ret;
 }
diff --git a/block.h b/block.h
index a82b0cd..6c55d4c 100644
--- a/block.h
+++ b/block.h
@@ -28,6 +28,10 @@ typedef struct QEMUSnapshotInfo {
     uint64_t vm_clock_nsec; /* VM clock relative to boot */
 } QEMUSnapshotInfo;
 
+typedef struct BlockDevOps {
+    void (*change_cb)(void *opaque, int reason);
+} BlockDevOps;
+
 #define BDRV_O_RDWR        0x0002
 #define BDRV_O_SNAPSHOT    0x0008 /* open the file read only and save writes in a snapshot */
 #define BDRV_O_NOCACHE     0x0020 /* do not use the host page cache */
@@ -77,6 +81,8 @@ int bdrv_attach_dev(BlockDriverState *bs, void *dev);
 void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev);
 void bdrv_detach_dev(BlockDriverState *bs, void *dev);
 void *bdrv_get_attached_dev(BlockDriverState *bs);
+void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
+                      void *opaque);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
@@ -192,9 +198,6 @@ int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
 int bdrv_eject(BlockDriverState *bs, int eject_flag);
-void bdrv_set_change_cb(BlockDriverState *bs,
-                        void (*change_cb)(void *opaque, int reason),
-                        void *opaque);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
 BlockDriverState *bdrv_find(const char *name);
 BlockDriverState *bdrv_next(BlockDriverState *bs);
diff --git a/block_int.h b/block_int.h
index cf7b7e7..48d6026 100644
--- a/block_int.h
+++ b/block_int.h
@@ -160,15 +160,14 @@ struct BlockDriverState {
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
-    /* event callback when inserting/removing */
-    void (*change_cb)(void *opaque, int reason);
-    void *change_opaque;
 
     BlockDriver *drv; /* NULL means no media */
     void *opaque;
 
     void *dev;                  /* attached device model, if any */
     /* TODO change to DeviceState when all users are qdevified */
+    const BlockDevOps *dev_ops;
+    void *dev_opaque;
 
     char filename[1024];
     char backing_file[1024]; /* if non zero, the image is a diff of
diff --git a/hw/ide/core.c b/hw/ide/core.c
index bcef8bc..773b7cf 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1717,6 +1717,10 @@ void ide_bus_reset(IDEBus *bus)
     bus->dma->ops->reset(bus->dma);
 }
 
+static const BlockDevOps ide_cd_block_ops = {
+    .change_cb = cdrom_change_cb,
+};
+
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
                    const char *version, const char *serial)
 {
@@ -1751,7 +1755,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
     s->smart_errors = 0;
     s->smart_selftest_count = 0;
     if (kind == IDE_CD) {
-        bdrv_set_change_cb(bs, cdrom_change_cb, s);
+        bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);
         bs->buffer_alignment = 2048;
     } else {
         if (!bdrv_is_inserted(s->bs)) {
diff --git a/hw/sd.c b/hw/sd.c
index 8d42ee2..d47b7a4 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -435,6 +435,10 @@ static void sd_cardchange(void *opaque, int reason)
     }
 }
 
+static const BlockDevOps sd_block_ops = {
+    .change_cb = sd_cardchange,
+};
+
 /* We do not model the chip select pin, so allow the board to select
    whether card should be in SSI or MMC/SD mode.  It is also up to the
    board to ensure that ssi transfers only occur when the chip select
@@ -450,7 +454,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)
     sd_reset(sd, bs);
     if (sd->bdrv) {
         bdrv_attach_dev_nofail(sd->bdrv, sd);
-        bdrv_set_change_cb(sd->bdrv, sd_cardchange, sd);
+        bdrv_set_dev_ops(sd->bdrv, &sd_block_ops, sd);
     }
     return sd;
 }
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 6471ac8..9e5ef88 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -536,6 +536,10 @@ static void virtio_blk_change_cb(void *opaque, int reason)
     }
 }
 
+static const BlockDevOps virtio_block_ops = {
+    .change_cb = virtio_blk_change_cb,
+};
+
 VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
                               char **serial)
 {
@@ -582,7 +586,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_removable(s->bs, 0);
-    bdrv_set_change_cb(s->bs, virtio_blk_change_cb, s);
+    bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
     s->bs->buffer_alignment = conf->logical_block_size;
 
     add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 03/45] block: Split change_cb() into change_media_cb(), resize_cb()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 01/45] block: Attach non-qdev devices as well Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 02/45] block: Generalize change_cb() to BlockDevOps Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 04/45] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
                   ` (43 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Multiplexing callbacks complicates matters needlessly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c         |   23 +++++++++++++++--------
 block.h         |   12 +++++++++++-
 block_int.h     |    3 ---
 hw/ide/core.c   |    8 ++------
 hw/sd.c         |    8 ++------
 hw/virtio-blk.c |    8 +++-----
 6 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/block.c b/block.c
index 3aa1eb5..17933c8 100644
--- a/block.c
+++ b/block.c
@@ -44,7 +44,7 @@
 #include <windows.h>
 #endif
 
-static void bdrv_dev_change_cb(BlockDriverState *bs, int reason);
+static void bdrv_dev_change_media_cb(BlockDriverState *bs);
 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque);
@@ -663,7 +663,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
 
     if (!bdrv_key_required(bs)) {
         bs->media_changed = 1;
-        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
+        bdrv_dev_change_media_cb(bs);
     }
 
     return 0;
@@ -700,7 +700,7 @@ void bdrv_close(BlockDriverState *bs)
         }
 
         bs->media_changed = 1;
-        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
+        bdrv_dev_change_media_cb(bs);
     }
 }
 
@@ -779,10 +779,17 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
     bs->dev_opaque = opaque;
 }
 
-static void bdrv_dev_change_cb(BlockDriverState *bs, int reason)
+static void bdrv_dev_change_media_cb(BlockDriverState *bs)
 {
-    if (bs->dev_ops && bs->dev_ops->change_cb) {
-        bs->dev_ops->change_cb(bs->dev_opaque, reason);
+    if (bs->dev_ops && bs->dev_ops->change_media_cb) {
+        bs->dev_ops->change_media_cb(bs->dev_opaque);
+    }
+}
+
+static void bdrv_dev_resize_cb(BlockDriverState *bs)
+{
+    if (bs->dev_ops && bs->dev_ops->resize_cb) {
+        bs->dev_ops->resize_cb(bs->dev_opaque);
     }
 }
 
@@ -1243,7 +1250,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset)
     ret = drv->bdrv_truncate(bs, offset);
     if (ret == 0) {
         ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS);
-        bdrv_dev_change_cb(bs, CHANGE_SIZE);
+        bdrv_dev_resize_cb(bs);
     }
     return ret;
 }
@@ -1619,7 +1626,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
         bs->valid_key = 1;
         /* call the change callback now, we skipped it on open */
         bs->media_changed = 1;
-        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
+        bdrv_dev_change_media_cb(bs);
     }
     return ret;
 }
diff --git a/block.h b/block.h
index 6c55d4c..3ff30c9 100644
--- a/block.h
+++ b/block.h
@@ -28,8 +28,18 @@ typedef struct QEMUSnapshotInfo {
     uint64_t vm_clock_nsec; /* VM clock relative to boot */
 } QEMUSnapshotInfo;
 
+/* Callbacks for block device models */
 typedef struct BlockDevOps {
-    void (*change_cb)(void *opaque, int reason);
+    /*
+     * Runs when virtual media changed (monitor commands eject, change)
+     * Beware: doesn't run when a host device's physical media
+     * changes.  Sure would be useful if it did.
+     */
+    void (*change_media_cb)(void *opaque);
+    /*
+     * Runs when the size changed (e.g. monitor command block_resize)
+     */
+    void (*resize_cb)(void *opaque);
 } BlockDevOps;
 
 #define BDRV_O_RDWR        0x0002
diff --git a/block_int.h b/block_int.h
index 48d6026..215f008 100644
--- a/block_int.h
+++ b/block_int.h
@@ -211,9 +211,6 @@ struct BlockDriverState {
     void *private;
 };
 
-#define CHANGE_MEDIA    0x01
-#define CHANGE_SIZE     0x02
-
 struct BlockDriverAIOCB {
     AIOPool *pool;
     BlockDriverState *bs;
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 773b7cf..ec043a3 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -758,15 +758,11 @@ static void ide_cfata_metadata_write(IDEState *s)
 }
 
 /* called when the inserted state of the media has changed */
-static void cdrom_change_cb(void *opaque, int reason)
+static void ide_cd_change_cb(void *opaque)
 {
     IDEState *s = opaque;
     uint64_t nb_sectors;
 
-    if (!(reason & CHANGE_MEDIA)) {
-        return;
-    }
-
     bdrv_get_geometry(s->bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
 
@@ -1718,7 +1714,7 @@ void ide_bus_reset(IDEBus *bus)
 }
 
 static const BlockDevOps ide_cd_block_ops = {
-    .change_cb = cdrom_change_cb,
+    .change_media_cb = ide_cd_change_cb,
 };
 
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
diff --git a/hw/sd.c b/hw/sd.c
index d47b7a4..24f4af8 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -420,14 +420,10 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
     sd->pwd_len = 0;
 }
 
-static void sd_cardchange(void *opaque, int reason)
+static void sd_cardchange(void *opaque)
 {
     SDState *sd = opaque;
 
-    if (!(reason & CHANGE_MEDIA)) {
-        return;
-    }
-
     qemu_set_irq(sd->inserted_cb, bdrv_is_inserted(sd->bdrv));
     if (bdrv_is_inserted(sd->bdrv)) {
         sd_reset(sd, sd->bdrv);
@@ -436,7 +432,7 @@ static void sd_cardchange(void *opaque, int reason)
 }
 
 static const BlockDevOps sd_block_ops = {
-    .change_cb = sd_cardchange,
+    .change_media_cb = sd_cardchange,
 };
 
 /* We do not model the chip select pin, so allow the board to select
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 9e5ef88..dc0b692 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -527,17 +527,15 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
     return 0;
 }
 
-static void virtio_blk_change_cb(void *opaque, int reason)
+static void virtio_blk_resize(void *opaque)
 {
     VirtIOBlock *s = opaque;
 
-    if (reason & CHANGE_SIZE) {
-        virtio_notify_config(&s->vdev);
-    }
+    virtio_notify_config(&s->vdev);
 }
 
 static const BlockDevOps virtio_block_ops = {
-    .change_cb = virtio_blk_change_cb,
+    .resize_cb = virtio_blk_resize,
 };
 
 VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 04/45] ide: Update command code definitions as per ACS-2 Table B.2
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (2 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 03/45] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 05/45] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
                   ` (42 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Drop WIN_SRST, it has the same value as WIN_DEVICE_RESET.

Drop unused WIN_RESTORE, it has the same value as WIN_RECAL.

Drop codes that are not implemented and long obsolete: WIN_READ_LONG,
WIN_READ_LONG_ONCE, WIN_WRITE_LONG, WIN_WRITE_LONG_ONCE, WIN_FORMAT
(all obsolete since ATA4), WIN_ACKMEDIACHANGE, WIN_POSTBOOT,
WIN_PREBOOT (obsolete since ATA3), WIN_WRITE_SAME (obsolete since
ATA3, code reused for something else in ACS2), WIN_IDENTIFY_DMA
(obsolete since ATA4).

Drop codes that are not implemented and vendor-specific:
EXABYTE_ENABLE_NEST, DISABLE_SEAGATE.

Drop WIN_INIT, it isn't implemented, its value used to be reserved,
and is used for something else since ATA8.

CFA_IDLEIMMEDIATE isn't specific to CFATA.  ACS-2 shows it as a
defined command in ATA-1, -2 and -3.  Rename to WIN_IDLEIMMEDIATE2.

Mark vendor specific, retired, and obsolete codes.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c     |    4 +-
 hw/ide/internal.h |  171 ++++++++++++++++++++++++++++-------------------------
 2 files changed, 92 insertions(+), 83 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index ec043a3..88ee768 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1104,7 +1104,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
     case WIN_STANDBYNOW1:
     case WIN_STANDBYNOW2:
     case WIN_IDLEIMMEDIATE:
-    case CFA_IDLEIMMEDIATE:
+    case WIN_IDLEIMMEDIATE2:
     case WIN_SETIDLE1:
     case WIN_SETIDLE2:
     case WIN_SLEEPNOW1:
@@ -1143,7 +1143,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
                           */
         ide_set_irq(s->bus);
         break;
-    case WIN_SRST:
+    case WIN_DEVICE_RESET:
         if (s->drive_kind != IDE_CD)
             goto abort_cmd;
         ide_set_signature(s);
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 02e805f..46e84fa 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -55,111 +55,120 @@ typedef struct IDEDMAOps IDEDMAOps;
 #define IDE_CMD_RESET           0x04
 #define IDE_CMD_DISABLE_IRQ     0x02
 
-/* ATA/ATAPI Commands pre T13 Spec */
+/* ACS-2 T13/2015-D Table B.2 Command codes */
 #define WIN_NOP				0x00
-/*
- *	0x01->0x02 Reserved
- */
+/* reserved                             0x01..0x02 */
 #define CFA_REQ_EXT_ERROR_CODE		0x03 /* CFA Request Extended Error Code */
-/*
- *      0x04->0x05 Reserved
- */
+/* reserved                             0x04..0x05 */
 #define WIN_DSM                         0x06
-/*
- *      0x07 Reserved
- */
-#define WIN_SRST			0x08 /* ATAPI soft reset command */
+/* reserved                             0x07 */
 #define WIN_DEVICE_RESET		0x08
-/*
- *	0x09->0x0F Reserved
- */
-#define WIN_RECAL			0x10
-#define WIN_RESTORE			WIN_RECAL
-/*
- *	0x10->0x1F Reserved
- */
+/* reserved                             0x09..0x0a */
+/* REQUEST SENSE DATA EXT               0x0B */
+/* reserved                             0x0C..0x0F */
+#define WIN_RECAL                       0x10 /* obsolete since ATA4 */
+/* obsolete since ATA3, retired in ATA4 0x11..0x1F */
 #define WIN_READ			0x20 /* 28-Bit */
-#define WIN_READ_ONCE			0x21 /* 28-Bit without retries */
-#define WIN_READ_LONG			0x22 /* 28-Bit */
-#define WIN_READ_LONG_ONCE		0x23 /* 28-Bit without retries */
+#define WIN_READ_ONCE                   0x21 /* 28-Bit w/o retries, obsolete since ATA5 */
+/* obsolete since ATA4                  0x22..0x23 */
 #define WIN_READ_EXT			0x24 /* 48-Bit */
 #define WIN_READDMA_EXT			0x25 /* 48-Bit */
-#define WIN_READDMA_QUEUED_EXT		0x26 /* 48-Bit */
+#define WIN_READDMA_QUEUED_EXT          0x26 /* 48-Bit, obsolete since ACS2 */
 #define WIN_READ_NATIVE_MAX_EXT		0x27 /* 48-Bit */
-/*
- *	0x28
- */
+/* reserved                             0x28 */
 #define WIN_MULTREAD_EXT		0x29 /* 48-Bit */
-/*
- *	0x2A->0x2F Reserved
- */
+/* READ STREAM DMA EXT                  0x2A */
+/* READ STREAM EXT                      0x2B */
+/* reserved                             0x2C..0x2E */
+/* READ LOG EXT                         0x2F */
 #define WIN_WRITE			0x30 /* 28-Bit */
-#define WIN_WRITE_ONCE			0x31 /* 28-Bit without retries */
-#define WIN_WRITE_LONG			0x32 /* 28-Bit */
-#define WIN_WRITE_LONG_ONCE		0x33 /* 28-Bit without retries */
+#define WIN_WRITE_ONCE                  0x31 /* 28-Bit w/o retries, obsolete since ATA5 */
+/* obsolete since ATA4                  0x32..0x33 */
 #define WIN_WRITE_EXT			0x34 /* 48-Bit */
 #define WIN_WRITEDMA_EXT		0x35 /* 48-Bit */
 #define WIN_WRITEDMA_QUEUED_EXT		0x36 /* 48-Bit */
+#define WIN_SET_MAX_EXT                 0x37 /* 48-Bit, obsolete since ACS2 */
 #define WIN_SET_MAX_EXT			0x37 /* 48-Bit */
 #define CFA_WRITE_SECT_WO_ERASE		0x38 /* CFA Write Sectors without erase */
 #define WIN_MULTWRITE_EXT		0x39 /* 48-Bit */
-/*
- *	0x3A->0x3B Reserved
- */
-#define WIN_WRITE_VERIFY		0x3C /* 28-Bit */
-/*
- *	0x3D->0x3F Reserved
- */
+/* WRITE STREAM DMA EXT                 0x3A */
+/* WRITE STREAM EXT                     0x3B */
+#define WIN_WRITE_VERIFY                0x3C /* 28-Bit, obsolete since ATA4 */
+/* WRITE DMA FUA EXT                    0x3D */
+/* obsolete since ACS2                  0x3E */
+/* WRITE LOG EXT                        0x3F */
 #define WIN_VERIFY			0x40 /* 28-Bit - Read Verify Sectors */
-#define WIN_VERIFY_ONCE			0x41 /* 28-Bit - without retries */
+#define WIN_VERIFY_ONCE                 0x41 /* 28-Bit - w/o retries, obsolete since ATA5 */
 #define WIN_VERIFY_EXT			0x42 /* 48-Bit */
-/*
- *	0x43->0x4F Reserved
- */
-#define WIN_FORMAT			0x50
-/*
- *	0x51->0x5F Reserved
- */
-#define WIN_INIT			0x60
-/*
- *	0x61->0x5F Reserved
- */
-#define WIN_SEEK			0x70 /* 0x70-0x7F Reserved */
+/* reserved                             0x43..0x44 */
+/* WRITE UNCORRECTABLE EXT              0x45 */
+/* reserved                             0x46 */
+/* READ LOG DMA EXT                     0x47 */
+/* reserved                             0x48..0x4F */
+/* obsolete since ATA4                  0x50 */
+/* CONFIGURE STREAM                     0x51 */
+/* reserved                             0x52..0x56 */
+/* WRITE LOG DMA EXT                    0x57 */
+/* reserved                             0x58..0x5A */
+/* TRUSTED NON DATA                     0x5B */
+/* TRUSTED RECEIVE                      0x5C */
+/* TRUSTED RECEIVE DMA                  0x5D */
+/* TRUSTED SEND                         0x5E */
+/* TRUSTED SEND DMA                     0x5F */
+/* READ FPDMA QUEUED                    0x60 */
+/* WRITE FPDMA QUEUED                   0x61 */
+/* reserved                             0x62->0x6F */
+#define WIN_SEEK                        0x70 /* obsolete since ATA7 */
+/* reserved                             0x71-0x7F */
+/* vendor specific                      0x80-0x86 */
 #define CFA_TRANSLATE_SECTOR		0x87 /* CFA Translate Sector */
+/* vendor specific                      0x88-0x8F */
 #define WIN_DIAGNOSE			0x90
-#define WIN_SPECIFY			0x91 /* set drive geometry translation */
+#define WIN_SPECIFY                     0x91 /* set drive geometry translation, obsolete since ATA6 */
 #define WIN_DOWNLOAD_MICROCODE		0x92
-#define WIN_STANDBYNOW2			0x94
-#define CFA_IDLEIMMEDIATE		0x95 /* force drive to become "ready" */
-#define WIN_STANDBY2			0x96
-#define WIN_SETIDLE2			0x97
-#define WIN_CHECKPOWERMODE2		0x98
-#define WIN_SLEEPNOW2			0x99
-/*
- *	0x9A VENDOR
- */
+/* DOWNLOAD MICROCODE DMA               0x93 */
+#define WIN_STANDBYNOW2                 0x94 /* retired in ATA4 */
+#define WIN_IDLEIMMEDIATE2              0x95 /* force drive to become "ready", retired in ATA4 */
+#define WIN_STANDBY2                    0x96 /* retired in ATA4 */
+#define WIN_SETIDLE2                    0x97 /* retired in ATA4 */
+#define WIN_CHECKPOWERMODE2             0x98 /* retired in ATA4 */
+#define WIN_SLEEPNOW2                   0x99 /* retired in ATA4 */
+/* vendor specific                      0x9A */
+/* reserved                             0x9B..0x9F */
 #define WIN_PACKETCMD			0xA0 /* Send a packet command. */
 #define WIN_PIDENTIFY			0xA1 /* identify ATAPI device	*/
-#define WIN_QUEUED_SERVICE		0xA2
+#define WIN_QUEUED_SERVICE              0xA2 /* obsolete since ACS2 */
+/* reserved                             0xA3..0xAF */
 #define WIN_SMART			0xB0 /* self-monitoring and reporting */
+/* Device Configuration Overlay         0xB1 */
+/* reserved                             0xB2..0xB3 */
+/* Sanitize Device                      0xB4 */
+/* reserved                             0xB5 */
+/* NV Cache                             0xB6 */
+/* reserved for CFA                     0xB7..0xBB */
 #define CFA_ACCESS_METADATA_STORAGE	0xB8
+/* reserved                             0xBC..0xBF */
 #define CFA_ERASE_SECTORS       	0xC0 /* microdrives implement as NOP */
+/* vendor specific                      0xC1..0xC3 */
 #define WIN_MULTREAD			0xC4 /* read sectors using multiple mode*/
 #define WIN_MULTWRITE			0xC5 /* write sectors using multiple mode */
 #define WIN_SETMULT			0xC6 /* enable/disable multiple mode */
-#define WIN_READDMA_QUEUED		0xC7 /* read sectors using Queued DMA transfers */
+#define WIN_READDMA_QUEUED              0xC7 /* read sectors using Queued DMA transfers, obsolete since ACS2 */
 #define WIN_READDMA			0xC8 /* read sectors using DMA transfers */
-#define WIN_READDMA_ONCE		0xC9 /* 28-Bit - without retries */
+#define WIN_READDMA_ONCE                0xC9 /* 28-Bit - w/o retries, obsolete since ATA5 */
 #define WIN_WRITEDMA			0xCA /* write sectors using DMA transfers */
-#define WIN_WRITEDMA_ONCE		0xCB /* 28-Bit - without retries */
-#define WIN_WRITEDMA_QUEUED		0xCC /* write sectors using Queued DMA transfers */
+#define WIN_WRITEDMA_ONCE               0xCB /* 28-Bit - w/o retries, obsolete since ATA5 */
+#define WIN_WRITEDMA_QUEUED		0xCC /* write sectors using Queued DMA transfers, obsolete since ACS2 */
 #define CFA_WRITE_MULTI_WO_ERASE	0xCD /* CFA Write multiple without erase */
-#define WIN_GETMEDIASTATUS		0xDA
-#define WIN_ACKMEDIACHANGE		0xDB /* ATA-1, ATA-2 vendor */
-#define WIN_POSTBOOT			0xDC
-#define WIN_PREBOOT			0xDD
-#define WIN_DOORLOCK			0xDE /* lock door on removable drives */
-#define WIN_DOORUNLOCK			0xDF /* unlock door on removable drives */
+/* WRITE MULTIPLE FUA EXT               0xCE */
+/* reserved                             0xCF..0xDO */
+/* CHECK MEDIA CARD TYPE                0xD1 */
+/* reserved for media card pass through 0xD2..0xD4 */
+/* reserved                             0xD5..0xD9 */
+#define WIN_GETMEDIASTATUS              0xDA /* obsolete since ATA8 */
+/* obsolete since ATA3, retired in ATA4 0xDB..0xDD */
+#define WIN_DOORLOCK                    0xDE /* lock door on removable drives, obsolete since ATA8 */
+#define WIN_DOORUNLOCK                  0xDF /* unlock door on removable drives, obsolete since ATA8 */
 #define WIN_STANDBYNOW1			0xE0
 #define WIN_IDLEIMMEDIATE		0xE1 /* force drive to become "ready" */
 #define WIN_STANDBY             	0xE2 /* Set device in Standby Mode */
@@ -169,25 +178,25 @@ typedef struct IDEDMAOps IDEDMAOps;
 #define WIN_SLEEPNOW1			0xE6
 #define WIN_FLUSH_CACHE			0xE7
 #define WIN_WRITE_BUFFER		0xE8 /* force write only 1 sector */
-#define WIN_WRITE_SAME			0xE9 /* read ata-2 to use */
-	/* SET_FEATURES 0x22 or 0xDD */
+/* READ BUFFER DMA                      0xE9 */
 #define WIN_FLUSH_CACHE_EXT		0xEA /* 48-Bit */
+/* WRITE BUFFER DMA                     0xEB */
 #define WIN_IDENTIFY			0xEC /* ask drive to identify itself	*/
-#define WIN_MEDIAEJECT			0xED
-#define WIN_IDENTIFY_DMA		0xEE /* same as WIN_IDENTIFY, but DMA */
+#define WIN_MEDIAEJECT                  0xED /* obsolete since ATA8 */
+/* obsolete since ATA4                  0xEE */
 #define WIN_SETFEATURES			0xEF /* set special drive features */
-#define EXABYTE_ENABLE_NEST		0xF0
-#define IBM_SENSE_CONDITION		0xF0 /* measure disk temperature */
+#define IBM_SENSE_CONDITION             0xF0 /* measure disk temperature, vendor specific */
 #define WIN_SECURITY_SET_PASS		0xF1
 #define WIN_SECURITY_UNLOCK		0xF2
 #define WIN_SECURITY_ERASE_PREPARE	0xF3
 #define WIN_SECURITY_ERASE_UNIT		0xF4
 #define WIN_SECURITY_FREEZE_LOCK	0xF5
-#define CFA_WEAR_LEVEL			0xF5 /* microdrives implement as NOP */
+#define CFA_WEAR_LEVEL                  0xF5 /* microdrives implement as NOP; not specified in T13! */
 #define WIN_SECURITY_DISABLE		0xF6
+/* vendor specific                      0xF7 */
 #define WIN_READ_NATIVE_MAX		0xF8 /* return the native maximum address */
 #define WIN_SET_MAX			0xF9
-#define DISABLE_SEAGATE			0xFB
+/* vendor specific                      0xFA..0xFF */
 
 /* set to 1 set disable mult support */
 #define MAX_MULT_SECTORS 16
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 05/45] ide: Clean up case label indentation in ide_exec_cmd()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (3 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 04/45] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 06/45] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
                   ` (41 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 88ee768..fa50692 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -954,7 +954,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         s->status = READY_STAT | SEEK_STAT;
         ide_set_irq(s->bus);
         break;
-	case WIN_READ_EXT:
+    case WIN_READ_EXT:
 	lba48 = 1;
     case WIN_READ:
     case WIN_READ_ONCE:
@@ -964,7 +964,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         s->req_nb_sectors = 1;
         ide_sector_read(s);
         break;
-	case WIN_WRITE_EXT:
+    case WIN_WRITE_EXT:
 	lba48 = 1;
     case WIN_WRITE:
     case WIN_WRITE_ONCE:
@@ -977,7 +977,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
         s->media_changed = 1;
         break;
-	case WIN_MULTREAD_EXT:
+    case WIN_MULTREAD_EXT:
 	lba48 = 1;
     case WIN_MULTREAD:
         if (!s->mult_sectors)
@@ -1002,7 +1002,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
         s->media_changed = 1;
         break;
-	case WIN_READDMA_EXT:
+    case WIN_READDMA_EXT:
 	lba48 = 1;
     case WIN_READDMA:
     case WIN_READDMA_ONCE:
@@ -1011,7 +1011,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	ide_cmd_lba48_transform(s, lba48);
         ide_sector_start_dma(s, IDE_DMA_READ);
         break;
-	case WIN_WRITEDMA_EXT:
+    case WIN_WRITEDMA_EXT:
 	lba48 = 1;
     case WIN_WRITEDMA:
     case WIN_WRITEDMA_ONCE:
@@ -1236,7 +1236,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
 
-	case WIN_SMART:
+    case WIN_SMART:
 	if (s->drive_kind == IDE_CD)
 		goto abort_cmd;
 	if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 06/45] ide: Fix ATA command READ to set ATAPI signature for CD-ROM
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (4 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 05/45] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
                   ` (40 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Must set the ATAPI device signature, see ATA4 8.27.5.2 Outputs for
PACKET Command feature set devices, and ACS-2 7.36.6 Outputs for
PACKET feature set devices.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index fa50692..1c4dc2f 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -958,8 +958,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	lba48 = 1;
     case WIN_READ:
     case WIN_READ_ONCE:
-        if (!s->bs)
+        if (s->drive_kind == IDE_CD) {
+            ide_set_signature(s); /* odd, but ATA4 8.27.5.2 requires it */
             goto abort_cmd;
+        }
 	ide_cmd_lba48_transform(s, lba48);
         s->req_nb_sectors = 1;
         ide_sector_read(s);
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (5 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 06/45] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 16:53   ` Blue Swirl
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 08/45] ide: Reject ATA commands specific to drive kinds Markus Armbruster
                   ` (39 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

No functional change.

It would be nice to have handler functions in the table, like commit
e1a064f9 did for ATAPI.  Left for another day.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |  104 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 79 insertions(+), 25 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 1c4dc2f..a25c175 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     }
 }
 
+#define HD_OK (1u << IDE_HD)
+#define CD_OK (1u << IDE_CD)
+#define CFA_OK (1u << IDE_CFATA)
+#define HD_CFA_OK (HD_OK | CFA_OK)
+#define ALL_OK (HD_OK | CD_OK | CFA_OK)
+
+/* See ACS-2 T13/2015-D Table B.2 Command codes */
+uint8_t ide_cmd_table[0x100] = {
+    /* NOP not implemented, mandatory for CD */
+    [CFA_REQ_EXT_ERROR_CODE]            = CFA_OK,
+    [WIN_DSM]                           = ALL_OK,
+    [WIN_DEVICE_RESET]                  = CD_OK,
+    [WIN_RECAL]                         = ALL_OK,
+    [WIN_READ]                          = ALL_OK,
+    [WIN_READ_ONCE]                     = ALL_OK,
+    [WIN_READ_EXT]                      = ALL_OK,
+    [WIN_READDMA_EXT]                   = ALL_OK,
+    [WIN_READ_NATIVE_MAX_EXT]           = ALL_OK,
+    [WIN_MULTREAD_EXT]                  = ALL_OK,
+    [WIN_WRITE]                         = ALL_OK,
+    [WIN_WRITE_ONCE]                    = ALL_OK,
+    [WIN_WRITE_EXT]                     = ALL_OK,
+    [WIN_WRITEDMA_EXT]                  = ALL_OK,
+    [CFA_WRITE_SECT_WO_ERASE]           = ALL_OK,
+    [WIN_MULTWRITE_EXT]                 = ALL_OK,
+    [WIN_WRITE_VERIFY]                  = ALL_OK,
+    [WIN_VERIFY]                        = ALL_OK,
+    [WIN_VERIFY_ONCE]                   = ALL_OK,
+    [WIN_VERIFY_EXT]                    = ALL_OK,
+    [WIN_SEEK]                          = HD_CFA_OK,
+    [CFA_TRANSLATE_SECTOR]              = CFA_OK,
+    [WIN_DIAGNOSE]                      = ALL_OK,
+    [WIN_SPECIFY]                       = ALL_OK,
+    [WIN_STANDBYNOW2]                   = ALL_OK,
+    [WIN_IDLEIMMEDIATE2]                = ALL_OK,
+    [WIN_STANDBY2]                      = ALL_OK,
+    [WIN_SETIDLE2]                      = ALL_OK,
+    [WIN_CHECKPOWERMODE2]               = ALL_OK,
+    [WIN_SLEEPNOW2]                     = ALL_OK,
+    [WIN_PACKETCMD]                     = CD_OK,
+    [WIN_PIDENTIFY]                     = CD_OK,
+    [WIN_SMART]                         = HD_CFA_OK,
+    [CFA_ACCESS_METADATA_STORAGE]       = CFA_OK,
+    [CFA_ERASE_SECTORS]                 = CFA_OK,
+    [WIN_MULTREAD]                      = ALL_OK,
+    [WIN_MULTWRITE]                     = ALL_OK,
+    [WIN_SETMULT]                       = ALL_OK,
+    [WIN_READDMA]                       = ALL_OK,
+    [WIN_READDMA_ONCE]                  = ALL_OK,
+    [WIN_WRITEDMA]                      = ALL_OK,
+    [WIN_WRITEDMA_ONCE]                 = ALL_OK,
+    [CFA_WRITE_MULTI_WO_ERASE]          = ALL_OK,
+    [WIN_STANDBYNOW1]                   = ALL_OK,
+    [WIN_IDLEIMMEDIATE]                 = ALL_OK,
+    [WIN_STANDBY]                       = ALL_OK,
+    [WIN_SETIDLE1]                      = ALL_OK,
+    [WIN_CHECKPOWERMODE1]               = ALL_OK,
+    [WIN_SLEEPNOW1]                     = ALL_OK,
+    [WIN_FLUSH_CACHE]                   = ALL_OK,
+    [WIN_FLUSH_CACHE_EXT]               = ALL_OK,
+    [WIN_IDENTIFY]                      = ALL_OK,
+    [WIN_SETFEATURES]                   = ALL_OK,
+    [IBM_SENSE_CONDITION]               = CFA_OK,
+    [CFA_WEAR_LEVEL]                    = CFA_OK,
+    [WIN_READ_NATIVE_MAX]               = ALL_OK,
+};
+
+static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
+{
+    return cmd <= 0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind));
+}
 
 void ide_exec_cmd(IDEBus *bus, uint32_t val)
 {
@@ -895,6 +966,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
     if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
         return;
 
+    if (!ide_cmd_permitted(s, val)) {
+        goto abort_cmd;
+    }
+
     switch(val) {
     case WIN_DSM:
         switch (s->feature) {
@@ -1115,21 +1190,15 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case WIN_SEEK:
-        if(s->drive_kind == IDE_CD)
-            goto abort_cmd;
         /* XXX: Check that seek is within bounds */
         s->status = READY_STAT | SEEK_STAT;
         ide_set_irq(s->bus);
         break;
         /* ATAPI commands */
     case WIN_PIDENTIFY:
-        if (s->drive_kind == IDE_CD) {
-            ide_atapi_identify(s);
-            s->status = READY_STAT | SEEK_STAT;
-            ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
-        } else {
-            ide_abort_command(s);
-        }
+        ide_atapi_identify(s);
+        s->status = READY_STAT | SEEK_STAT;
+        ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
         ide_set_irq(s->bus);
         break;
     case WIN_DIAGNOSE:
@@ -1146,15 +1215,11 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case WIN_DEVICE_RESET:
-        if (s->drive_kind != IDE_CD)
-            goto abort_cmd;
         ide_set_signature(s);
         s->status = 0x00; /* NOTE: READY is _not_ set */
         s->error = 0x01;
         break;
     case WIN_PACKETCMD:
-        if (s->drive_kind != IDE_CD)
-            goto abort_cmd;
         /* overlapping commands not supported */
         if (s->feature & 0x02)
             goto abort_cmd;
@@ -1166,16 +1231,12 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         break;
     /* CF-ATA commands */
     case CFA_REQ_EXT_ERROR_CODE:
-        if (s->drive_kind != IDE_CFATA)
-            goto abort_cmd;
         s->error = 0x09;    /* miscellaneous error */
         s->status = READY_STAT | SEEK_STAT;
         ide_set_irq(s->bus);
         break;
     case CFA_ERASE_SECTORS:
     case CFA_WEAR_LEVEL:
-        if (s->drive_kind != IDE_CFATA)
-            goto abort_cmd;
         if (val == CFA_WEAR_LEVEL)
             s->nsector = 0;
         if (val == CFA_ERASE_SECTORS)
@@ -1185,8 +1246,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case CFA_TRANSLATE_SECTOR:
-        if (s->drive_kind != IDE_CFATA)
-            goto abort_cmd;
         s->error = 0x00;
         s->status = READY_STAT | SEEK_STAT;
         memset(s->io_buffer, 0, 0x200);
@@ -1205,8 +1264,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case CFA_ACCESS_METADATA_STORAGE:
-        if (s->drive_kind != IDE_CFATA)
-            goto abort_cmd;
         switch (s->feature) {
         case 0x02:	/* Inquiry Metadata Storage */
             ide_cfata_metadata_inquiry(s);
@@ -1225,8 +1282,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case IBM_SENSE_CONDITION:
-        if (s->drive_kind != IDE_CFATA)
-            goto abort_cmd;
         switch (s->feature) {
         case 0x01:  /* sense temperature in device */
             s->nsector = 0x50;      /* +20 C */
@@ -1239,8 +1294,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
         break;
 
     case WIN_SMART:
-	if (s->drive_kind == IDE_CD)
-		goto abort_cmd;
 	if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
 		goto abort_cmd;
 	if (!s->smart_enabled && s->feature != SMART_ENABLE)
@@ -1395,6 +1448,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	}
 	break;
     default:
+        /* should not be reachable */
     abort_cmd:
         ide_abort_command(s);
         ide_set_irq(s->bus);
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 08/45] ide: Reject ATA commands specific to drive kinds
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (6 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
                   ` (38 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

ACS-2 Table B.2 explicitly prohibits ATAPI devices from implementing
WIN_RECAL, WIN_READ_EXT, WIN_READDMA_EXT, WIN_READ_NATIVE_MAX,
WIN_MULTREAD_EXT, WIN_WRITE, WIN_WRITE_ONCE, WIN_WRITE_EXT,
WIN_WRITEDMA_EXT, WIN_MULTWRITE_EXT, WIN_WRITE_VERIFY, WIN_VERIFY,
WIN_VERIFY_ONCE, WIN_VERIFY_EXT, WIN_SPECIFY, WIN_MULTREAD,
WIN_MULTWRITE, WIN_SETMULT, WIN_READDMA, WIN_READDMA_ONCE,
WIN_WRITEDMA, WIN_WRITEDMA_ONCE, WIN_FLUSH_CACHE_EXT.  Restrict them
to IDE_HD and IDE_CFATA.

Same for CFA_WRITE_SECT_WO_ERASE, CFA_WRITE_MULTI_WO_ERASE.  Restrict
them to IDE_CFATA, like the other CFA_ commands.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |   50 +++++++++++++++++++++++++-------------------------
 1 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index a25c175..3c46176 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -888,27 +888,27 @@ uint8_t ide_cmd_table[0x100] = {
     [CFA_REQ_EXT_ERROR_CODE]            = CFA_OK,
     [WIN_DSM]                           = ALL_OK,
     [WIN_DEVICE_RESET]                  = CD_OK,
-    [WIN_RECAL]                         = ALL_OK,
+    [WIN_RECAL]                         = HD_CFA_OK,
     [WIN_READ]                          = ALL_OK,
     [WIN_READ_ONCE]                     = ALL_OK,
-    [WIN_READ_EXT]                      = ALL_OK,
-    [WIN_READDMA_EXT]                   = ALL_OK,
-    [WIN_READ_NATIVE_MAX_EXT]           = ALL_OK,
-    [WIN_MULTREAD_EXT]                  = ALL_OK,
-    [WIN_WRITE]                         = ALL_OK,
-    [WIN_WRITE_ONCE]                    = ALL_OK,
-    [WIN_WRITE_EXT]                     = ALL_OK,
-    [WIN_WRITEDMA_EXT]                  = ALL_OK,
-    [CFA_WRITE_SECT_WO_ERASE]           = ALL_OK,
-    [WIN_MULTWRITE_EXT]                 = ALL_OK,
-    [WIN_WRITE_VERIFY]                  = ALL_OK,
-    [WIN_VERIFY]                        = ALL_OK,
-    [WIN_VERIFY_ONCE]                   = ALL_OK,
-    [WIN_VERIFY_EXT]                    = ALL_OK,
+    [WIN_READ_EXT]                      = HD_CFA_OK,
+    [WIN_READDMA_EXT]                   = HD_CFA_OK,
+    [WIN_READ_NATIVE_MAX_EXT]           = HD_CFA_OK,
+    [WIN_MULTREAD_EXT]                  = HD_CFA_OK,
+    [WIN_WRITE]                         = HD_CFA_OK,
+    [WIN_WRITE_ONCE]                    = HD_CFA_OK,
+    [WIN_WRITE_EXT]                     = HD_CFA_OK,
+    [WIN_WRITEDMA_EXT]                  = HD_CFA_OK,
+    [CFA_WRITE_SECT_WO_ERASE]           = CFA_OK,
+    [WIN_MULTWRITE_EXT]                 = HD_CFA_OK,
+    [WIN_WRITE_VERIFY]                  = HD_CFA_OK,
+    [WIN_VERIFY]                        = HD_CFA_OK,
+    [WIN_VERIFY_ONCE]                   = HD_CFA_OK,
+    [WIN_VERIFY_EXT]                    = HD_CFA_OK,
     [WIN_SEEK]                          = HD_CFA_OK,
     [CFA_TRANSLATE_SECTOR]              = CFA_OK,
     [WIN_DIAGNOSE]                      = ALL_OK,
-    [WIN_SPECIFY]                       = ALL_OK,
+    [WIN_SPECIFY]                       = HD_CFA_OK,
     [WIN_STANDBYNOW2]                   = ALL_OK,
     [WIN_IDLEIMMEDIATE2]                = ALL_OK,
     [WIN_STANDBY2]                      = ALL_OK,
@@ -920,14 +920,14 @@ uint8_t ide_cmd_table[0x100] = {
     [WIN_SMART]                         = HD_CFA_OK,
     [CFA_ACCESS_METADATA_STORAGE]       = CFA_OK,
     [CFA_ERASE_SECTORS]                 = CFA_OK,
-    [WIN_MULTREAD]                      = ALL_OK,
-    [WIN_MULTWRITE]                     = ALL_OK,
-    [WIN_SETMULT]                       = ALL_OK,
-    [WIN_READDMA]                       = ALL_OK,
-    [WIN_READDMA_ONCE]                  = ALL_OK,
-    [WIN_WRITEDMA]                      = ALL_OK,
-    [WIN_WRITEDMA_ONCE]                 = ALL_OK,
-    [CFA_WRITE_MULTI_WO_ERASE]          = ALL_OK,
+    [WIN_MULTREAD]                      = HD_CFA_OK,
+    [WIN_MULTWRITE]                     = HD_CFA_OK,
+    [WIN_SETMULT]                       = HD_CFA_OK,
+    [WIN_READDMA]                       = HD_CFA_OK,
+    [WIN_READDMA_ONCE]                  = HD_CFA_OK,
+    [WIN_WRITEDMA]                      = HD_CFA_OK,
+    [WIN_WRITEDMA_ONCE]                 = HD_CFA_OK,
+    [CFA_WRITE_MULTI_WO_ERASE]          = CFA_OK,
     [WIN_STANDBYNOW1]                   = ALL_OK,
     [WIN_IDLEIMMEDIATE]                 = ALL_OK,
     [WIN_STANDBY]                       = ALL_OK,
@@ -935,7 +935,7 @@ uint8_t ide_cmd_table[0x100] = {
     [WIN_CHECKPOWERMODE1]               = ALL_OK,
     [WIN_SLEEPNOW1]                     = ALL_OK,
     [WIN_FLUSH_CACHE]                   = ALL_OK,
-    [WIN_FLUSH_CACHE_EXT]               = ALL_OK,
+    [WIN_FLUSH_CACHE_EXT]               = HD_CFA_OK,
     [WIN_IDENTIFY]                      = ALL_OK,
     [WIN_SETFEATURES]                   = ALL_OK,
     [IBM_SENSE_CONDITION]               = CFA_OK,
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (7 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 08/45] ide: Reject ATA commands specific to drive kinds Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-09-02 10:20   ` Kevin Wolf
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state Markus Armbruster
                   ` (37 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

"eject" is misleading; it means "eject" when start is clear, but
"load" when start is set.  Rename to loej, because that's how MMC-5
calls it, in section 6.40.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/atapi.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index fe2fb0b..17fbef8 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -892,11 +892,11 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
 
 static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
 {
-    int start, eject, sense, err = 0;
-    start = buf[4] & 1;
-    eject = (buf[4] >> 1) & 1;
+    int sense, err = 0;
+    bool start = buf[4] & 1;
+    bool loej = buf[4] & 2;
 
-    if (eject) {
+    if (loej) {
         err = bdrv_eject(s->bs, !start);
     }
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (8 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-09-02 10:23   ` Kevin Wolf
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
                   ` (36 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

We already track it in BlockDriverState since commit 4be9762a.  As
discussed in that commit's message, we should track it in the device
device models instead, because it's device state.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/atapi.c    |    6 +++++-
 hw/ide/internal.h |    1 +
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 17fbef8..96f7c31 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,
     uint8_t event_code, media_status;
 
     media_status = 0;
-    if (s->bs->tray_open) {
+    if (s->tray_open) {
         media_status = MS_TRAY_OPEN;
     } else if (bdrv_is_inserted(s->bs)) {
         media_status = MS_MEDIA_PRESENT;
@@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
         ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
         break;
     }
+
+    if (loej && !err) {
+        s->tray_open = !start;
+    }
 }
 
 static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 46e84fa..cd8e977 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -442,6 +442,7 @@ struct IDEState {
     struct unreported_events events;
     uint8_t sense_key;
     uint8_t asc;
+    bool tray_open;
     uint8_t cdrom_changed;
     int packet_transfer_size;
     int elementary_transfer_size;
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (9 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-04  6:12   ` Hannes Reinecke
  2011-09-02 10:26   ` Kevin Wolf
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state Markus Armbruster
                   ` (35 subsequent siblings)
  46 siblings, 2 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index fa198f9..d549cb7 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
     return toclen;
 }
 
+static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
+{
+    SCSIRequest *req = &r->req;
+    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
+    bool start = req->cmd.buf[4] & 1;
+    bool loej = req->cmd.buf[4] & 2;
+
+    if (s->qdev.type == TYPE_ROM && loej) {
+        bdrv_eject(s->bs, !start);
+    }
+}
+
 static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
 {
     SCSIRequest *req = &r->req;
@@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
             goto illegal_request;
         break;
     case START_STOP:
-        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
-            /* load/eject medium */
-            bdrv_eject(s->bs, !(req->cmd.buf[4] & 1));
-        }
+        scsi_disk_emulate_start_stop(r);
         break;
     case ALLOW_MEDIUM_REMOVAL:
         bdrv_set_locked(s->bs, req->cmd.buf[4] & 1);
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (10 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-04  6:13   ` Hannes Reinecke
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 13/45] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
                   ` (34 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

We already track it in BlockDriverState since commit 4be9762a.  As
discussed in that commit's message, we should track it in the device
device models instead, because it's device state.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index d549cb7..2d5e157 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -72,6 +72,7 @@ struct SCSIDiskState
     char *version;
     char *serial;
     SCSISense sense;
+    bool tray_open;
 };
 
 static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
@@ -829,6 +830,7 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
 
     if (s->qdev.type == TYPE_ROM && loej) {
         bdrv_eject(s->bs, !start);
+        s->tray_open = !start;
     }
 }
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 13/45] block: Revert entanglement of bdrv_is_inserted() with tray status
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (11 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 14/45] block: Drop tray status tracking, no longer used Markus Armbruster
                   ` (33 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Commit 4be9762a changed bdrv_is_inserted() to fail when the tray is
open.  Unfortunately, there are two different kinds of users, with
conflicting needs.

1. Device models using bdrv_eject(), currently ide-cd and scsi-cd.
They expect bdrv_is_inserted() to reflect the tray status.  Commit
4be9762a makes them happy.

2. Code that wants to know whether a BlockDriverState has media, such
as find_image_format(), bdrv_flush_all().  Commit 4be9762a makes them
unhappy.  In particular, it breaks flush on VM stop for media ejected
by the guest.

Revert the change to bdrv_is_inserted().  Check the tray status in the
device models instead.

Note on IDE: Since only ATAPI devices have a tray, and they don't
accept ATA commands since the recent commit "ide: Reject ATA commands
specific to drive kinds", checking in atapi.c suffices.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c        |    7 +++----
 hw/ide/atapi.c |   15 ++++++++-------
 hw/scsi-disk.c |   10 ++++++++--
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/block.c b/block.c
index 17933c8..257aec8 100644
--- a/block.c
+++ b/block.c
@@ -2986,13 +2986,12 @@ static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs)
 int bdrv_is_inserted(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
-    int ret;
+
     if (!drv)
         return 0;
     if (!drv->bdrv_is_inserted)
-        return !bs->tray_open;
-    ret = drv->bdrv_is_inserted(bs);
-    return ret;
+        return 1;
+    return drv->bdrv_is_inserted(bs);
 }
 
 /**
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 96f7c31..08e1a7a 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -73,7 +73,7 @@ static void lba_to_msf(uint8_t *buf, int lba)
 
 static inline int media_present(IDEState *s)
 {
-    return (s->nb_sectors > 0);
+    return !s->tray_open && s->nb_sectors > 0;
 }
 
 /* XXX: DVDs that could fit on a CD will be reported as a CD */
@@ -1066,20 +1066,21 @@ static const struct {
     [ 0x03 ] = { cmd_request_sense,                 ALLOW_UA },
     [ 0x12 ] = { cmd_inquiry,                       ALLOW_UA },
     [ 0x1a ] = { cmd_mode_sense, /* (6) */          0 },
-    [ 0x1b ] = { cmd_start_stop_unit,               0 },
+    [ 0x1b ] = { cmd_start_stop_unit,               0 }, /* [1] */
     [ 0x1e ] = { cmd_prevent_allow_medium_removal,  0 },
     [ 0x25 ] = { cmd_read_cdvd_capacity,            CHECK_READY },
-    [ 0x28 ] = { cmd_read, /* (10) */               0 },
+    [ 0x28 ] = { cmd_read, /* (10) */               CHECK_READY },
     [ 0x2b ] = { cmd_seek,                          CHECK_READY },
     [ 0x43 ] = { cmd_read_toc_pma_atip,             CHECK_READY },
     [ 0x46 ] = { cmd_get_configuration,             ALLOW_UA },
     [ 0x4a ] = { cmd_get_event_status_notification, ALLOW_UA },
     [ 0x5a ] = { cmd_mode_sense, /* (10) */         0 },
-    [ 0xa8 ] = { cmd_read, /* (12) */               0 },
-    [ 0xad ] = { cmd_read_dvd_structure,            0 },
+    [ 0xa8 ] = { cmd_read, /* (12) */               CHECK_READY },
+    [ 0xad ] = { cmd_read_dvd_structure,            CHECK_READY },
     [ 0xbb ] = { cmd_set_speed,                     0 },
     [ 0xbd ] = { cmd_mechanism_status,              0 },
-    [ 0xbe ] = { cmd_read_cd,                       0 },
+    [ 0xbe ] = { cmd_read_cd,                       CHECK_READY },
+    /* [1] handler detects and reports not ready condition itself */
 };
 
 void ide_atapi_cmd(IDEState *s)
@@ -1115,7 +1116,7 @@ void ide_atapi_cmd(IDEState *s)
      * GET_EVENT_STATUS_NOTIFICATION to detect such tray open/close
      * states rely on this behavior.
      */
-    if (bdrv_is_inserted(s->bs) && s->cdrom_changed) {
+    if (!s->tray_open && bdrv_is_inserted(s->bs) && s->cdrom_changed) {
         ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
 
         s->cdrom_changed = 0;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 2d5e157..db72b86 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -186,6 +186,9 @@ static void scsi_read_data(SCSIRequest *req)
     if (n > SCSI_DMA_BUF_SIZE / 512)
         n = SCSI_DMA_BUF_SIZE / 512;
 
+    if (s->tray_open) {
+        scsi_read_complete(r, -ENOMEDIUM);
+    }
     r->iov.iov_len = n * 512;
     qemu_iovec_init_external(&r->qiov, &r->iov, 1);
     r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->qiov, n,
@@ -284,6 +287,9 @@ static void scsi_write_data(SCSIRequest *req)
 
     n = r->iov.iov_len / 512;
     if (n) {
+        if (s->tray_open) {
+            scsi_write_complete(r, -ENOMEDIUM);
+        }
         qemu_iovec_init_external(&r->qiov, &r->iov, 1);
         r->req.aiocb = bdrv_aio_writev(s->bs, r->sector, &r->qiov, n,
                                    scsi_write_complete, r);
@@ -844,7 +850,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
 
     switch (req->cmd.buf[0]) {
     case TEST_UNIT_READY:
-        if (!bdrv_is_inserted(s->bs))
+        if (s->tray_open || !bdrv_is_inserted(s->bs))
             goto not_ready;
         break;
     case REQUEST_SENSE:
@@ -987,7 +993,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
     return buflen;
 
 not_ready:
-    if (!bdrv_is_inserted(s->bs)) {
+    if (s->tray_open || !bdrv_is_inserted(s->bs)) {
         scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(NO_MEDIUM));
     } else {
         scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(LUN_NOT_READY));
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 14/45] block: Drop tray status tracking, no longer used
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (12 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 13/45] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state Markus Armbruster
                   ` (32 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Commit 4be9762a is now completely redone.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c     |    1 -
 block_int.h |    1 -
 2 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 257aec8..737cdc9 100644
--- a/block.c
+++ b/block.c
@@ -3027,7 +3027,6 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag)
     if (drv && drv->bdrv_eject) {
         drv->bdrv_eject(bs, eject_flag);
     }
-    bs->tray_open = eject_flag;
     return 0;
 }
 
diff --git a/block_int.h b/block_int.h
index 215f008..e0824ce 100644
--- a/block_int.h
+++ b/block_int.h
@@ -156,7 +156,6 @@ struct BlockDriverState {
     int open_flags; /* flags used to open the file, re-used for re-open */
     int removable; /* if true, the media can be removed */
     int locked;    /* if true, the media cannot temporarily be ejected */
-    int tray_open; /* if true, the virtual tray is open */
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (13 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 14/45] block: Drop tray status tracking, no longer used Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-09-02 11:02   ` Kevin Wolf
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 16/45] scsi-disk: " Markus Armbruster
                   ` (31 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

We already track it in BlockDriverState.  Just like tray open/close
state, we should track it in the device models instead, because it's
device state.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/atapi.c    |    4 +++-
 hw/ide/internal.h |    1 +
 2 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 08e1a7a..237657f 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
             buf[12] = 0x71;
             buf[13] = 3 << 5;
             buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
-            if (bdrv_is_locked(s->bs))
+            if (s->tray_locked) {
                 buf[6] |= 1 << 1;
+            }
             buf[15] = 0x00;
             cpu_to_ube16(&buf[16], 706);
             buf[18] = 0;
@@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
 
 static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
 {
+    s->tray_locked = buf[4] & 1;
     bdrv_set_locked(s->bs, buf[4] & 1);
     ide_atapi_cmd_ok(s);
 }
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index cd8e977..3e56b45 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -443,6 +443,7 @@ struct IDEState {
     uint8_t sense_key;
     uint8_t asc;
     bool tray_open;
+    bool tray_locked;
     uint8_t cdrom_changed;
     int packet_transfer_size;
     int elementary_transfer_size;
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (14 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-04  6:14   ` Hannes Reinecke
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 17/45] block: Leave enforcing tray lock to device models Markus Armbruster
                   ` (30 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

We already track it in BlockDriverState.  Just like tray open/close
state, we should track it in the device models instead, because it's
device state.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index db72b86..8ca69f2 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -73,6 +73,7 @@ struct SCSIDiskState
     char *serial;
     SCSISense sense;
     bool tray_open;
+    bool tray_locked;
 };
 
 static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
@@ -678,7 +679,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p,
         p[5] = 0xff; /* CD DA, DA accurate, RW supported,
                         RW corrected, C2 errors, ISRC,
                         UPC, Bar code */
-        p[6] = 0x2d | (bdrv_is_locked(s->bs)? 2 : 0);
+        p[6] = 0x2d | (s->tray_locked ? 2 : 0);
         /* Locking supported, jumper present, eject, tray */
         p[7] = 0; /* no volume & mute control, no
                      changer */
@@ -896,6 +897,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
         scsi_disk_emulate_start_stop(r);
         break;
     case ALLOW_MEDIUM_REMOVAL:
+        s->tray_locked = req->cmd.buf[4] & 1;
         bdrv_set_locked(s->bs, req->cmd.buf[4] & 1);
         break;
     case READ_CAPACITY_10:
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 17/45] block: Leave enforcing tray lock to device models
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (15 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 16/45] scsi-disk: " Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 18/45] block: Drop medium lock tracking, ask device models instead Markus Armbruster
                   ` (29 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

The device model knows best when to accept the guest's eject command.
No need to detour through the block layer.

bdrv_eject() can't fail anymore.  Make it void.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c        |    7 +------
 block.h        |    2 +-
 hw/ide/atapi.c |   29 +++++++++--------------------
 hw/scsi-disk.c |    3 +++
 4 files changed, 14 insertions(+), 27 deletions(-)

diff --git a/block.c b/block.c
index 737cdc9..73e0fd4 100644
--- a/block.c
+++ b/block.c
@@ -3016,18 +3016,13 @@ int bdrv_media_changed(BlockDriverState *bs)
 /**
  * If eject_flag is TRUE, eject the media. Otherwise, close the tray
  */
-int bdrv_eject(BlockDriverState *bs, int eject_flag)
+void bdrv_eject(BlockDriverState *bs, int eject_flag)
 {
     BlockDriver *drv = bs->drv;
 
-    if (eject_flag && bs->locked) {
-        return -EBUSY;
-    }
-
     if (drv && drv->bdrv_eject) {
         drv->bdrv_eject(bs, eject_flag);
     }
-    return 0;
 }
 
 int bdrv_is_locked(BlockDriverState *bs)
diff --git a/block.h b/block.h
index 3ff30c9..3f33c8e 100644
--- a/block.h
+++ b/block.h
@@ -207,7 +207,7 @@ int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
 int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
-int bdrv_eject(BlockDriverState *bs, int eject_flag);
+void bdrv_eject(BlockDriverState *bs, int eject_flag);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
 BlockDriverState *bdrv_find(const char *name);
 BlockDriverState *bdrv_next(BlockDriverState *bs);
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 237657f..6cb8f0e 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -894,33 +894,22 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
 
 static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
 {
-    int sense, err = 0;
+    int sense;
     bool start = buf[4] & 1;
     bool loej = buf[4] & 2;
 
     if (loej) {
-        err = bdrv_eject(s->bs, !start);
-    }
-
-    switch (err) {
-    case 0:
-        ide_atapi_cmd_ok(s);
-        break;
-    case -EBUSY:
-        sense = SENSE_NOT_READY;
-        if (bdrv_is_inserted(s->bs)) {
-            sense = SENSE_ILLEGAL_REQUEST;
+        if (!start && s->tray_locked) {
+            sense = bdrv_is_inserted(s->bs)
+                ? SENSE_NOT_READY : SENSE_ILLEGAL_REQUEST;
+            ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
+            return;
         }
-        ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
-        break;
-    default:
-        ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
-        break;
-    }
-
-    if (loej && !err) {
+        bdrv_eject(s->bs, !start);
         s->tray_open = !start;
     }
+
+    ide_atapi_cmd_ok(s);
 }
 
 static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 8ca69f2..d22a211 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -836,6 +836,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     bool loej = req->cmd.buf[4] & 2;
 
     if (s->qdev.type == TYPE_ROM && loej) {
+        if (!start && s->tray_locked) {
+            return;
+        }
         bdrv_eject(s->bs, !start);
         s->tray_open = !start;
     }
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 18/45] block: Drop medium lock tracking, ask device models instead
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (16 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 17/45] block: Leave enforcing tray lock to device models Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
                   ` (28 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Requires new BlockDevOps member is_medium_locked().  Implement for IDE
and SCSI CD-ROMs.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c        |   16 +++++++++-------
 block.h        |    8 +++++++-
 block_int.h    |    1 -
 blockdev.c     |    2 +-
 hw/ide/core.c  |    6 ++++++
 hw/scsi-disk.c |   10 ++++++++++
 6 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/block.c b/block.c
index 73e0fd4..3a8a4e6 100644
--- a/block.c
+++ b/block.c
@@ -793,6 +793,14 @@ static void bdrv_dev_resize_cb(BlockDriverState *bs)
     }
 }
 
+bool bdrv_dev_is_medium_locked(BlockDriverState *bs)
+{
+    if (bs->dev_ops && bs->dev_ops->is_medium_locked) {
+        return bs->dev_ops->is_medium_locked(bs->dev_opaque);
+    }
+    return false;
+}
+
 /*
  * Run consistency checks on an image
  *
@@ -1854,7 +1862,7 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
         bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
                                     "'removable': %i, 'locked': %i }",
                                     bs->device_name, bs->removable,
-                                    bs->locked);
+                                    bdrv_dev_is_medium_locked(bs));
 
         if (bs->drv) {
             QObject *obj;
@@ -3025,11 +3033,6 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
     }
 }
 
-int bdrv_is_locked(BlockDriverState *bs)
-{
-    return bs->locked;
-}
-
 /**
  * Lock or unlock the media (if it is locked, the user won't be able
  * to eject it manually).
@@ -3040,7 +3043,6 @@ void bdrv_set_locked(BlockDriverState *bs, int locked)
 
     trace_bdrv_set_locked(bs, locked);
 
-    bs->locked = locked;
     if (drv && drv->bdrv_set_locked) {
         drv->bdrv_set_locked(bs, locked);
     }
diff --git a/block.h b/block.h
index 3f33c8e..37d9048 100644
--- a/block.h
+++ b/block.h
@@ -37,6 +37,12 @@ typedef struct BlockDevOps {
      */
     void (*change_media_cb)(void *opaque);
     /*
+     * Is the virtual medium locked into the device?
+     * Device models should implement this only when device has such a
+     * lock.
+     */
+    bool (*is_medium_locked)(void *opaque);
+    /*
      * Runs when the size changed (e.g. monitor command block_resize)
      */
     void (*resize_cb)(void *opaque);
@@ -93,6 +99,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);
 void *bdrv_get_attached_dev(BlockDriverState *bs);
 void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
                       void *opaque);
+bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
 int bdrv_write(BlockDriverState *bs, int64_t sector_num,
@@ -205,7 +212,6 @@ int bdrv_is_sg(BlockDriverState *bs);
 int bdrv_enable_write_cache(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
-int bdrv_is_locked(BlockDriverState *bs);
 void bdrv_set_locked(BlockDriverState *bs, int locked);
 void bdrv_eject(BlockDriverState *bs, int eject_flag);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
diff --git a/block_int.h b/block_int.h
index e0824ce..9eff892 100644
--- a/block_int.h
+++ b/block_int.h
@@ -155,7 +155,6 @@ struct BlockDriverState {
     int keep_read_only; /* if true, the media was requested to stay read only */
     int open_flags; /* flags used to open the file, re-used for re-open */
     int removable; /* if true, the media can be removed */
-    int locked;    /* if true, the media cannot temporarily be ejected */
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
diff --git a/blockdev.c b/blockdev.c
index 40f061a..bb1f8c4 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -649,7 +649,7 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
         qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
         return -1;
     }
-    if (!force && bdrv_is_locked(bs)) {
+    if (!force && bdrv_dev_is_medium_locked(bs)) {
         qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
         return -1;
     }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 3c46176..5bcc857 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1769,8 +1769,14 @@ void ide_bus_reset(IDEBus *bus)
     bus->dma->ops->reset(bus->dma);
 }
 
+static bool ide_cd_is_medium_locked(void *opaque)
+{
+    return ((IDEState *)opaque)->tray_locked;
+}
+
 static const BlockDevOps ide_cd_block_ops = {
     .change_media_cb = ide_cd_change_cb,
+    .is_medium_locked = ide_cd_is_medium_locked,
 };
 
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index d22a211..6f5ec0d 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1201,6 +1201,15 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
+static bool scsi_cd_is_medium_locked(void *opaque)
+{
+    return ((SCSIDiskState *)opaque)->tray_locked;
+}
+
+static const BlockDevOps scsi_cd_block_ops = {
+    .is_medium_locked = scsi_cd_is_medium_locked,
+};
+
 static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
@@ -1235,6 +1244,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
     }
 
     if (scsi_type == TYPE_ROM) {
+        bdrv_set_dev_ops(s->bs, &scsi_cd_block_ops, s);
         s->qdev.blocksize = 2048;
     } else if (scsi_type == TYPE_DISK) {
         s->qdev.blocksize = s->qdev.conf.logical_block_size;
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (17 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 18/45] block: Drop medium lock tracking, ask device models instead Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-09-02 11:30   ` Kevin Wolf
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
                   ` (27 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c           |    8 ++++----
 block.h           |    2 +-
 block/raw-posix.c |    8 ++++----
 block/raw.c       |    6 +++---
 block_int.h       |    2 +-
 hw/ide/atapi.c    |    2 +-
 hw/scsi-disk.c    |    2 +-
 trace-events      |    2 +-
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/block.c b/block.c
index 3a8a4e6..10c1b1a 100644
--- a/block.c
+++ b/block.c
@@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
  * Lock or unlock the media (if it is locked, the user won't be able
  * to eject it manually).
  */
-void bdrv_set_locked(BlockDriverState *bs, int locked)
+void bdrv_lock_medium(BlockDriverState *bs, int locked)
 {
     BlockDriver *drv = bs->drv;
 
-    trace_bdrv_set_locked(bs, locked);
+    trace_bdrv_lock_medium(bs, locked);
 
-    if (drv && drv->bdrv_set_locked) {
-        drv->bdrv_set_locked(bs, locked);
+    if (drv && drv->bdrv_lock_medium) {
+        drv->bdrv_lock_medium(bs, locked);
     }
 }
 
diff --git a/block.h b/block.h
index 37d9048..4a6b957 100644
--- a/block.h
+++ b/block.h
@@ -212,7 +212,7 @@ int bdrv_is_sg(BlockDriverState *bs);
 int bdrv_enable_write_cache(BlockDriverState *bs);
 int bdrv_is_inserted(BlockDriverState *bs);
 int bdrv_media_changed(BlockDriverState *bs);
-void bdrv_set_locked(BlockDriverState *bs, int locked);
+void bdrv_lock_medium(BlockDriverState *bs, int locked);
 void bdrv_eject(BlockDriverState *bs, int eject_flag);
 void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
 BlockDriverState *bdrv_find(const char *name);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index c5c9944..b429baf 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1358,7 +1358,7 @@ static void cdrom_eject(BlockDriverState *bs, int eject_flag)
     }
 }
 
-static void cdrom_set_locked(BlockDriverState *bs, int locked)
+static void cdrom_lock_medium(BlockDriverState *bs, int locked)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1396,7 +1396,7 @@ static BlockDriver bdrv_host_cdrom = {
     /* removable device support */
     .bdrv_is_inserted   = cdrom_is_inserted,
     .bdrv_eject         = cdrom_eject,
-    .bdrv_set_locked    = cdrom_set_locked,
+    .bdrv_lock_medium   = cdrom_lock_medium,
 
     /* generic scsi device */
     .bdrv_ioctl         = hdev_ioctl,
@@ -1477,7 +1477,7 @@ static void cdrom_eject(BlockDriverState *bs, int eject_flag)
     cdrom_reopen(bs);
 }
 
-static void cdrom_set_locked(BlockDriverState *bs, int locked)
+static void cdrom_lock_medium(BlockDriverState *bs, int locked)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1517,7 +1517,7 @@ static BlockDriver bdrv_host_cdrom = {
     /* removable device support */
     .bdrv_is_inserted   = cdrom_is_inserted,
     .bdrv_eject         = cdrom_eject,
-    .bdrv_set_locked    = cdrom_set_locked,
+    .bdrv_lock_medium   = cdrom_lock_medium,
 };
 #endif /* __FreeBSD__ */
 
diff --git a/block/raw.c b/block/raw.c
index cb6203e..fa74ef1 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -80,9 +80,9 @@ static void raw_eject(BlockDriverState *bs, int eject_flag)
     bdrv_eject(bs->file, eject_flag);
 }
 
-static void raw_set_locked(BlockDriverState *bs, int locked)
+static void raw_lock_medium(BlockDriverState *bs, int locked)
 {
-    bdrv_set_locked(bs->file, locked);
+    bdrv_lock_medium(bs->file, locked);
 }
 
 static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
@@ -138,7 +138,7 @@ static BlockDriver bdrv_raw = {
 
     .bdrv_is_inserted   = raw_is_inserted,
     .bdrv_eject         = raw_eject,
-    .bdrv_set_locked    = raw_set_locked,
+    .bdrv_lock_medium   = raw_lock_medium,
     .bdrv_ioctl         = raw_ioctl,
     .bdrv_aio_ioctl     = raw_aio_ioctl,
 
diff --git a/block_int.h b/block_int.h
index 9eff892..eb7f46d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -119,7 +119,7 @@ struct BlockDriver {
     int (*bdrv_is_inserted)(BlockDriverState *bs);
     int (*bdrv_media_changed)(BlockDriverState *bs);
     void (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
-    void (*bdrv_set_locked)(BlockDriverState *bs, int locked);
+    void (*bdrv_lock_medium)(BlockDriverState *bs, int locked);
 
     /* to control generic scsi devices */
     int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 6cb8f0e..1be6cbf 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -822,7 +822,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
 static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
 {
     s->tray_locked = buf[4] & 1;
-    bdrv_set_locked(s->bs, buf[4] & 1);
+    bdrv_lock_medium(s->bs, buf[4] & 1);
     ide_atapi_cmd_ok(s);
 }
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 6f5ec0d..79d7737 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -901,7 +901,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
         break;
     case ALLOW_MEDIUM_REMOVAL:
         s->tray_locked = req->cmd.buf[4] & 1;
-        bdrv_set_locked(s->bs, req->cmd.buf[4] & 1);
+        bdrv_lock_medium(s->bs, req->cmd.buf[4] & 1);
         break;
     case READ_CAPACITY_10:
         /* The normal LEN field for this command is zero.  */
diff --git a/trace-events b/trace-events
index 19d31e3..f113042 100644
--- a/trace-events
+++ b/trace-events
@@ -65,7 +65,7 @@ disable bdrv_aio_multiwrite_latefail(void *mcb, int i) "mcb %p i %d"
 disable bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p"
 disable bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
 disable bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p"
-disable bdrv_set_locked(void *bs, int locked) "bs %p locked %d"
+disable bdrv_lock_medium(void *bs, int locked) "bs %p locked %d"
 disable bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
 disable bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d"
 disable bdrv_co_io(int is_write, void *acb) "is_write %d acb %p"
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (18 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
@ 2011-08-03 13:07 ` Markus Armbruster
  2011-08-04 17:48   ` Luiz Capitulino
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 21/45] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
                   ` (26 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/internal.h |    1 +
 hw/ide/qdev.c     |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 3e56b45..0b0b8a7 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);
 struct IDEDeviceInfo {
     DeviceInfo qdev;
     ide_qdev_initfn init;
+    ide_qdev_initfn exit;
 };
 
 #define BM_STATUS_DMAING 0x01
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 6bd8d20..3b7b306 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -91,9 +91,21 @@ err:
     return -1;
 }
 
+static int ide_qdev_exit(DeviceState *qdev)
+{
+    IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev);
+    IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, qdev->info);
+
+    if (info->exit) {
+        return info->exit(dev);
+    }
+    return 0;
+}
+
 static void ide_qdev_register(IDEDeviceInfo *info)
 {
     info->qdev.init = ide_qdev_init;
+    info->qdev.exit = ide_qdev_exit;
     info->qdev.bus_info = &ide_bus_info;
     qdev_register(&info->qdev);
 }
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 21/45] ide/atapi: Don't fail eject when tray is already open
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (19 preceding siblings ...)
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
                   ` (25 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

MMC-5 6.40.2.6 specifies that START STOP UNIT succeeds when the drive
already has the requested state.  cmd_start_stop_unit() fails when
asked to eject while the tray is open and locked.  Fix that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/atapi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 1be6cbf..9f384c8 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -899,7 +899,7 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
     bool loej = buf[4] & 2;
 
     if (loej) {
-        if (!start && s->tray_locked) {
+        if (!start && !s->tray_open && s->tray_locked) {
             sense = bdrv_is_inserted(s->bs)
                 ? SENSE_NOT_READY : SENSE_ILLEGAL_REQUEST;
             ide_atapi_cmd_error(s, sense, ASC_MEDIA_REMOVAL_PREVENTED);
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (20 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 21/45] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-09-02 12:07   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
                   ` (24 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

When ide-cd is backed by a physical drive, we want the physical tray
match the virtual one.  To that end, we call bdrv_eject() on guest's
load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
But we don't set the initial state on device model init.  Fix that.

While there, also unlock on device model exit.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |    4 ++++
 hw/ide/qdev.c |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 5bcc857..d8b1d43 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
 
     ide_reset(s);
     bdrv_set_removable(bs, s->drive_kind == IDE_CD);
+    if (s->drive_kind == IDE_CD) {
+        bdrv_lock_medium(bs, s->tray_locked);
+        bdrv_eject(bs, s->tray_open);
+    }
     return 0;
 }
 
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 3b7b306..bc2f426 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)
     return ide_dev_initfn(dev, IDE_CD);
 }
 
+static int ide_cd_exitfn(IDEDevice *dev)
+{
+    bdrv_lock_medium(dev->conf.bs, 0);
+    return 0;
+}
+
 static int ide_drive_initfn(IDEDevice *dev)
 {
     DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
@@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)
     return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
 }
 
+static int ide_drive_exitfn(IDEDevice *dev)
+{
+    DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
+
+    if (dinfo->media_cd) {
+        return ide_cd_exitfn(dev);
+    }
+    return 0;
+}
+
 #define DEFINE_IDE_DEV_PROPERTIES()                     \
     DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),        \
     DEFINE_PROP_STRING("ver",  IDEDrive, dev.version),  \
@@ -211,6 +227,7 @@ static IDEDeviceInfo ide_dev_info[] = {
         .qdev.desc    = "virtual IDE CD-ROM",
         .qdev.size    = sizeof(IDEDrive),
         .init         = ide_cd_initfn,
+        .exit         = ide_cd_exitfn,
         .qdev.props   = (Property[]) {
             DEFINE_IDE_DEV_PROPERTIES(),
             DEFINE_PROP_END_OF_LIST(),
@@ -221,6 +238,7 @@ static IDEDeviceInfo ide_dev_info[] = {
         .qdev.desc    = "virtual IDE disk or CD-ROM (legacy)",
         .qdev.size    = sizeof(IDEDrive),
         .init         = ide_drive_initfn,
+        .exit         = ide_drive_exitfn,
         .qdev.props   = (Property[]) {
             DEFINE_IDE_DEV_PROPERTIES(),
             DEFINE_PROP_END_OF_LIST(),
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (21 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04  6:20   ` Hannes Reinecke
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
                   ` (23 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Don't fail when tray is already open.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-bus.c  |   10 ++++++++++
 hw/scsi-disk.c |   15 +++++++++++----
 hw/scsi.h      |    4 ++++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 0b0344c..1c5fe7f 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = {
     .key = NOT_READY, .asc = 0x3a, .ascq = 0x00
 };
 
+/* LUN not ready, medium removal prevented */
+const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = {
+    .key = NOT_READY, .asc = 0x53, .ascq = 0x00
+};
+
 /* Hardware error, internal target failure */
 const struct SCSISense sense_code_TARGET_FAILURE = {
     .key = HARDWARE_ERROR, .asc = 0x44, .ascq = 0x00
@@ -466,6 +471,11 @@ const struct SCSISense sense_code_LUN_NOT_SUPPORTED = {
     .key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00
 };
 
+/* Illegal request, medium removal prevented */
+const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL = {
+    .key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x00
+};
+
 /* Command aborted, I/O process terminated */
 const struct SCSISense sense_code_IO_ERROR = {
     .key = ABORTED_COMMAND, .asc = 0x00, .ascq = 0x06
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 79d7737..19a1843 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -828,7 +828,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
     return toclen;
 }
 
-static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
+static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
 {
     SCSIRequest *req = &r->req;
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
@@ -836,12 +836,17 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     bool loej = req->cmd.buf[4] & 2;
 
     if (s->qdev.type == TYPE_ROM && loej) {
-        if (!start && s->tray_locked) {
-            return;
+        if (!start && !s->tray_open && s->tray_locked) {
+            scsi_command_complete(r, CHECK_CONDITION,
+                                  bdrv_is_inserted(s->bs)
+                                  ? SENSE_CODE(MEDIUM_REMOVAL_PREVENTED_ILL)
+                                  : SENSE_CODE(MEDIUM_REMOVAL_PREVENTED_NR));
+            return -1;
         }
         bdrv_eject(s->bs, !start);
         s->tray_open = !start;
     }
+    return 0;
 }
 
 static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
@@ -897,7 +902,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
             goto illegal_request;
         break;
     case START_STOP:
-        scsi_disk_emulate_start_stop(r);
+        if (scsi_disk_emulate_start_stop(r) < 0) {
+            return -1;
+        }
         break;
     case ALLOW_MEDIUM_REMOVAL:
         s->tray_locked = req->cmd.buf[4] & 1;
diff --git a/hw/scsi.h b/hw/scsi.h
index 6b15bbc..63442c6 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -118,6 +118,8 @@ extern const struct SCSISense sense_code_NO_SENSE;
 extern const struct SCSISense sense_code_LUN_NOT_READY;
 /* LUN not ready, Medium not present */
 extern const struct SCSISense sense_code_NO_MEDIUM;
+/* LUN not readt, medium removal prevented */
+extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR;
 /* Hardware error, internal target failure */
 extern const struct SCSISense sense_code_TARGET_FAILURE;
 /* Illegal request, invalid command operation code */
@@ -128,6 +130,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
 extern const struct SCSISense sense_code_INVALID_FIELD;
 /* Illegal request, LUN not supported */
 extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
+/* Illegal request, medium removal prevented */
+extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL;
 /* Command aborted, I/O process terminated */
 extern const struct SCSISense sense_code_IO_ERROR;
 /* Command aborted, I_T Nexus loss occurred */
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (22 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04  6:21   ` Hannes Reinecke
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 25/45] ide: Give vmstate structs internal linkage where possible Markus Armbruster
                   ` (22 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

When scsi-cd is backed by a physical drive, we want the physical tray
match the virtual one.  To that end, we call bdrv_eject() on guest's
load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
But we don't set the initial state on device model init.  Fix that.

While there, also unlock on device model exit.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 19a1843..f223de6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1205,6 +1205,9 @@ static void scsi_destroy(SCSIDevice *dev)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
 
     scsi_device_purge_requests(&s->qdev);
+    if (s->qdev.type == TYPE_ROM) {
+        bdrv_lock_medium(s->qdev.conf.bs, 0);
+    }
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
@@ -1265,6 +1268,10 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
     s->qdev.type = scsi_type;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
     bdrv_set_removable(s->bs, scsi_type == TYPE_ROM);
+    if (scsi_type == TYPE_ROM) {
+        bdrv_lock_medium(s->bs, s->tray_locked);
+        bdrv_eject(s->bs, s->tray_open);
+    }
     add_boot_device_path(s->qdev.conf.bootindex, &dev->qdev, ",0");
     return 0;
 }
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 25/45] ide: Give vmstate structs internal linkage where possible
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (23 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration Markus Armbruster
                   ` (21 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index d8b1d43..cbda0c2 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2051,7 +2051,7 @@ static bool ide_error_needed(void *opaque)
 }
 
 /* Fields for GET_EVENT_STATUS_NOTIFICATION ATAPI command */
-const VMStateDescription vmstate_ide_atapi_gesn_state = {
+static const VMStateDescription vmstate_ide_atapi_gesn_state = {
     .name ="ide_drive/atapi/gesn_state",
     .version_id = 1,
     .minimum_version_id = 1,
@@ -2063,7 +2063,7 @@ const VMStateDescription vmstate_ide_atapi_gesn_state = {
     }
 };
 
-const VMStateDescription vmstate_ide_drive_pio_state = {
+static const VMStateDescription vmstate_ide_drive_pio_state = {
     .name = "ide_drive/pio_state",
     .version_id = 1,
     .minimum_version_id = 1,
@@ -2125,7 +2125,7 @@ const VMStateDescription vmstate_ide_drive = {
     }
 };
 
-const VMStateDescription vmstate_ide_error_status = {
+static const VMStateDescription vmstate_ide_error_status = {
     .name ="ide_bus/error",
     .version_id = 1,
     .minimum_version_id = 1,
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (24 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 25/45] ide: Give vmstate structs internal linkage where possible Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-09-02 12:20   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 27/45] scsi-disk: " Markus Armbruster
                   ` (20 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Use a subsection, so that migration to older version still works,
provided the tray is closed and unlocked.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index cbda0c2..22a2dc7 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2036,6 +2036,22 @@ static bool ide_drive_pio_state_needed(void *opaque)
         || (s->bus->error_status & BM_STATUS_PIO_RETRY);
 }
 
+static int ide_tray_state_post_load(void *opaque, int version_id)
+{
+    IDEState *s = opaque;
+
+    bdrv_eject(s->bs, s->tray_open);
+    bdrv_lock_medium(s->bs, s->tray_locked);
+    return 0;
+}
+
+static bool ide_tray_state_needed(void *opaque)
+{
+    IDEState *s = opaque;
+
+    return s->tray_open || s->tray_locked;
+}
+
 static bool ide_atapi_gesn_needed(void *opaque)
 {
     IDEState *s = opaque;
@@ -2063,6 +2079,19 @@ static const VMStateDescription vmstate_ide_atapi_gesn_state = {
     }
 };
 
+static const VMStateDescription vmstate_ide_tray_state = {
+    .name = "ide_drive/tray_state",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .post_load = ide_tray_state_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(tray_open, IDEState),
+        VMSTATE_BOOL(tray_locked, IDEState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const VMStateDescription vmstate_ide_drive_pio_state = {
     .name = "ide_drive/pio_state",
     .version_id = 1,
@@ -2117,6 +2146,9 @@ const VMStateDescription vmstate_ide_drive = {
             .vmsd = &vmstate_ide_drive_pio_state,
             .needed = ide_drive_pio_state_needed,
         }, {
+            .vmsd = &vmstate_ide_tray_state,
+            .needed = ide_tray_state_needed,
+        }, {
             .vmsd = &vmstate_ide_atapi_gesn_state,
             .needed = ide_atapi_gesn_needed,
         }, {
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (25 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04  6:23   ` Hannes Reinecke
  2011-09-02 12:25   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 28/45] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
                   ` (19 subsequent siblings)
  46 siblings, 2 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
versions.  We normally use subsections to avoid that.  Not possible
here, because we don't have a section to begin with.  Too bad.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/scsi-disk.c |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index f223de6..04e0a77 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     return scsi_initfn(dev, scsi_type);
 }
 
+static int scsi_cd_post_load(void *opaque, int version_id)
+{
+    SCSIDiskState *s = opaque;
+
+    bdrv_eject(s->bs, s->tray_open);
+    bdrv_lock_medium(s->bs, s->tray_locked);
+    return 0;
+}
+
+static const VMStateDescription vmstate_scsi_cd = {
+    .name = "scsi-cd",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .post_load = scsi_cd_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(tray_open, SCSIDiskState),
+        VMSTATE_BOOL(tray_locked, SCSIDiskState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static const VMStateDescription vmstate_scsi_disk = {
+    .name = "scsi-disk",
+    .version_id = 0,
+    .minimum_version_id = 0,
+    .post_load = scsi_cd_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_BOOL(tray_open, SCSIDiskState),
+        VMSTATE_BOOL(tray_locked, SCSIDiskState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 #define DEFINE_SCSI_DISK_PROPERTIES()                           \
     DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),          \
     DEFINE_PROP_STRING("ver",  SCSIDiskState, version),         \
@@ -1333,6 +1366,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI CD-ROM",
         .qdev.size    = sizeof(SCSIDiskState),
+        .qdev.vmsd    = &vmstate_scsi_cd,
         .qdev.reset   = scsi_disk_reset,
         .init         = scsi_cd_initfn,
         .destroy      = scsi_destroy,
@@ -1353,6 +1387,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
         .qdev.fw_name = "disk",
         .qdev.desc    = "virtual SCSI disk or CD-ROM (legacy)",
         .qdev.size    = sizeof(SCSIDiskState),
+        .qdev.vmsd    = &vmstate_scsi_disk,
         .qdev.reset   = scsi_disk_reset,
         .init         = scsi_disk_initfn,
         .destroy      = scsi_destroy,
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 28/45] block/raw: Fix to forward method bdrv_media_changed()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (26 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 27/45] scsi-disk: " Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 29/45] block: Leave tracking media change to device models Markus Armbruster
                   ` (18 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Block driver "raw" forwards most methods to the underlying block
driver.  However, it doesn't implement method bdrv_media_changed().
Makes bdrv_media_changed() always return -ENOTSUP.

I believe -fda /dev/fd0 gives you raw over host_floppy, and disk
change detection (fdc register 7 bit 7) is broken.  Testing my theory
requires a computer museum, though.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/raw.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/block/raw.c b/block/raw.c
index fa74ef1..934f439 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -75,6 +75,11 @@ static int raw_is_inserted(BlockDriverState *bs)
     return bdrv_is_inserted(bs->file);
 }
 
+static int raw_media_changed(BlockDriverState *bs)
+{
+    return bdrv_media_changed(bs->file);
+}
+
 static void raw_eject(BlockDriverState *bs, int eject_flag)
 {
     bdrv_eject(bs->file, eject_flag);
@@ -137,8 +142,10 @@ static BlockDriver bdrv_raw = {
     .bdrv_discard       = raw_discard,
 
     .bdrv_is_inserted   = raw_is_inserted,
+    .bdrv_media_changed = raw_media_changed,
     .bdrv_eject         = raw_eject,
     .bdrv_lock_medium   = raw_lock_medium,
+
     .bdrv_ioctl         = raw_ioctl,
     .bdrv_aio_ioctl     = raw_aio_ioctl,
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 29/45] block: Leave tracking media change to device models
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (27 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 28/45] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 30/45] fdc: Make media change detection more robust Markus Armbruster
                   ` (17 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

hw/fdc.c is the only one that cares.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c     |   20 ++++++--------------
 block_int.h |    1 -
 hw/fdc.c    |   40 ++++++++++++++++++----------------------
 3 files changed, 24 insertions(+), 37 deletions(-)

diff --git a/block.c b/block.c
index 10c1b1a..f4f320e 100644
--- a/block.c
+++ b/block.c
@@ -662,7 +662,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
     }
 
     if (!bdrv_key_required(bs)) {
-        bs->media_changed = 1;
         bdrv_dev_change_media_cb(bs);
     }
 
@@ -699,7 +698,6 @@ void bdrv_close(BlockDriverState *bs)
             bdrv_close(bs->file);
         }
 
-        bs->media_changed = 1;
         bdrv_dev_change_media_cb(bs);
     }
 }
@@ -1633,7 +1631,6 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
     } else if (!bs->valid_key) {
         bs->valid_key = 1;
         /* call the change callback now, we skipped it on open */
-        bs->media_changed = 1;
         bdrv_dev_change_media_cb(bs);
     }
     return ret;
@@ -3003,22 +3000,17 @@ int bdrv_is_inserted(BlockDriverState *bs)
 }
 
 /**
- * Return TRUE if the media changed since the last call to this
- * function. It is currently only used for floppy disks
+ * Return whether the media changed since the last call to this
+ * function, or -ENOTSUP if we don't know.  Most drivers don't know.
  */
 int bdrv_media_changed(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
-    int ret;
 
-    if (!drv || !drv->bdrv_media_changed)
-        ret = -ENOTSUP;
-    else
-        ret = drv->bdrv_media_changed(bs);
-    if (ret == -ENOTSUP)
-        ret = bs->media_changed;
-    bs->media_changed = 0;
-    return ret;
+    if (drv && drv->bdrv_media_changed) {
+        return drv->bdrv_media_changed(bs);
+    }
+    return -ENOTSUP;
 }
 
 /**
diff --git a/block_int.h b/block_int.h
index eb7f46d..a271a07 100644
--- a/block_int.h
+++ b/block_int.h
@@ -172,7 +172,6 @@ struct BlockDriverState {
                                 this file image */
     char backing_format[16]; /* if non-zero and backing_file exists */
     int is_temporary;
-    int media_changed;
 
     BlockDriverState *backing_hd;
     BlockDriverState *file;
diff --git a/hw/fdc.c b/hw/fdc.c
index edf0360..a2d8aae 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -535,30 +535,11 @@ static CPUWriteMemoryFunc * const fdctrl_mem_write_strict[3] = {
     NULL,
 };
 
-static void fdrive_media_changed_pre_save(void *opaque)
-{
-    FDrive *drive = opaque;
-
-    drive->media_changed = drive->bs->media_changed;
-}
-
-static int fdrive_media_changed_post_load(void *opaque, int version_id)
-{
-    FDrive *drive = opaque;
-
-    if (drive->bs != NULL) {
-        drive->bs->media_changed = drive->media_changed;
-    }
-
-    /* User ejected the floppy when drive->bs == NULL */
-    return 0;
-}
-
 static bool fdrive_media_changed_needed(void *opaque)
 {
     FDrive *drive = opaque;
 
-    return (drive->bs != NULL && drive->bs->media_changed != 1);
+    return (drive->bs != NULL && drive->media_changed != 1);
 }
 
 static const VMStateDescription vmstate_fdrive_media_changed = {
@@ -566,8 +547,6 @@ static const VMStateDescription vmstate_fdrive_media_changed = {
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
-    .pre_save = fdrive_media_changed_pre_save,
-    .post_load = fdrive_media_changed_post_load,
     .fields      = (VMStateField[]) {
         VMSTATE_UINT8(media_changed, FDrive),
         VMSTATE_END_OF_LIST()
@@ -920,6 +899,10 @@ static int fdctrl_media_changed(FDrive *drv)
     if (!drv->bs)
         return 0;
     ret = bdrv_media_changed(drv->bs);
+    if (ret < 0) {
+        ret = drv->media_changed;
+    }
+    drv->media_changed = 0;
     if (ret) {
         fd_revalidate(drv);
     }
@@ -1791,6 +1774,17 @@ static void fdctrl_result_timer(void *opaque)
     fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
 }
 
+static void fdctrl_change_cb(void *opaque)
+{
+    FDrive *drive = opaque;
+
+    drive->media_changed = 1;
+}
+
+static const BlockDevOps fdctrl_block_ops = {
+    .change_media_cb = fdctrl_change_cb,
+};
+
 /* Init functions */
 static int fdctrl_connect_drives(FDCtrl *fdctrl)
 {
@@ -1814,7 +1808,9 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)
         fd_init(drive);
         fd_revalidate(drive);
         if (drive->bs) {
+            drive->media_changed = 1;
             bdrv_set_removable(drive->bs, 1);
+            bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive);
         }
     }
     return 0;
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 30/45] fdc: Make media change detection more robust
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (28 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 29/45] block: Leave tracking media change to device models Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 31/45] block: Clean up bdrv_flush_all() Markus Armbruster
                   ` (16 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

fdctrl_change_cb() gets called on a virtual media change via monitor.
It would be nice if host device block drivers called it on physical
media change, but they don't.

bdrv_media_changed() lets you poll for media change, but it returns
"don't know" except with block driver "host_floppy".

FDrive member media_changed gets set on device initialization and by
fdctrl_change_cb(), and cleared by fdctrl_media_changed().  Thus, it's
set on first entry to fdctrl_media_changed() since device
initialization or virtual media change.

fdctrl_media_changed() ignores media_changed unless
bdrv_media_changed() returns "don't know".  If we change media via
monitor (setting media_changed), and the new media's block driver
returns 0, we lose.  Fortunately, "host_floppy" always returns 1 on
first call.  Brittle.  Clean it up not to rely on it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/fdc.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index a2d8aae..6854e15 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -898,11 +898,15 @@ static int fdctrl_media_changed(FDrive *drv)
 
     if (!drv->bs)
         return 0;
-    ret = bdrv_media_changed(drv->bs);
-    if (ret < 0) {
-        ret = drv->media_changed;
+    if (drv->media_changed) {
+        drv->media_changed = 0;
+        ret = 1;
+    } else {
+        ret = bdrv_media_changed(drv->bs);
+        if (ret < 0) {
+            ret = 0;            /* we don't know, assume no */
+        }
     }
-    drv->media_changed = 0;
     if (ret) {
         fd_revalidate(drv);
     }
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 31/45] block: Clean up bdrv_flush_all()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (29 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 30/45] fdc: Make media change detection more robust Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 32/45] savevm: Include writable devices with removable media Markus Armbruster
                   ` (15 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Change (!bdrv_is_removable(bs) || bdrv_is_inserted(bs)) to just
bdrv_is_inserted().  Rationale:

    The value of bdrv_is_removable(bs) matters only when
    bdrv_is_inserted(bs) is false.

    bdrv_is_inserted(bs) is true when bs is open (bs->drv != NULL) and
    not an empty host drive (CD-ROM or floppy).

    Therefore, bdrv_is_removable(bs) matters only when:

    1. bs is not open
       old: may call bdrv_flush(bs), which does nothing
       new: won't call

    2. bs is an empty host drive
       old: may call bdrv_flush(bs), which calls driver method
            raw_flush(), which calls fdatasync() or equivalent, which
            can't do anything useful while the drive is empty
       new: won't call

Result is bs->drv && !bdrv_is_read_only(bs) && bdrv_is_inserted(bs).
bdrv_is_inserted(bs) implies bs->drv.  Drop the redundant test.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index f4f320e..1ff42b5 100644
--- a/block.c
+++ b/block.c
@@ -1721,8 +1721,7 @@ void bdrv_flush_all(void)
     BlockDriverState *bs;
 
     QTAILQ_FOREACH(bs, &bdrv_states, list) {
-        if (bs->drv && !bdrv_is_read_only(bs) &&
-            (!bdrv_is_removable(bs) || bdrv_is_inserted(bs))) {
+        if (!bdrv_is_read_only(bs) && bdrv_is_inserted(bs)) {
             bdrv_flush(bs);
         }
     }
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 32/45] savevm: Include writable devices with removable media
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (30 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 31/45] block: Clean up bdrv_flush_all() Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 33/45] xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD" Markus Armbruster
                   ` (14 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

savevm and loadvm silently ignore block devices with removable media,
such as floppies and SD cards.  Rolling back a VM to a previous
checkpoint will *not* roll back writes to block devices with removable
media.

Moreover, bdrv_is_removable() is a confused mess, and wrong in at
least one case: it considers "-drive if=xen,media=cdrom -M xenpv"
removable.  It'll be cleaned up later in this series.

Read-only block devices are also ignored, but that's okay.

Fix by ignoring only read-only block devices and empty block devices.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c  |    2 +-
 savevm.c |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index 1ff42b5..b3a5ee7 100644
--- a/block.c
+++ b/block.c
@@ -2047,7 +2047,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event)
 int bdrv_can_snapshot(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
-    if (!drv || bdrv_is_removable(bs) || bdrv_is_read_only(bs)) {
+    if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
         return 0;
     }
 
diff --git a/savevm.c b/savevm.c
index 7801aa7..839712e 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1914,7 +1914,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
 
-        if (bdrv_is_removable(bs) || bdrv_is_read_only(bs)) {
+        if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
             continue;
         }
 
@@ -2034,7 +2034,7 @@ int load_vmstate(const char *name)
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
 
-        if (bdrv_is_removable(bs) || bdrv_is_read_only(bs)) {
+        if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) {
             continue;
         }
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 33/45] xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD"
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (31 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 32/45] savevm: Include writable devices with removable media Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 34/45] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
                   ` (13 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

pci_piix3_xen_ide_unplug() unplugs only disks, not CD-ROMs.  It peeks
into the DriveInfo's BlockDriverState to distinguish between the two.
Unclean; use DriveInfo member media_cd, like xen_config_dev_blk().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/piix.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 00fb683..0430c1e 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -27,7 +27,6 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "sysemu.h"
 #include "dma.h"
 
@@ -161,7 +160,7 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)
 
     for (; i < 3; i++) {
         di = drive_get_by_index(IF_IDE, i);
-        if (di != NULL && di->bdrv != NULL && !di->bdrv->removable) {
+        if (di != NULL && !di->media_cd) {
             DeviceState *ds = bdrv_get_attached_dev(di->bdrv);
             if (ds) {
                 bdrv_detach_dev(di->bdrv, ds);
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 34/45] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (32 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 33/45] xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD" Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable" Markus Armbruster
                   ` (12 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

We try the drive defined with -drive if=ide,index=0 (or equivalent
sugar).  We use it only if (dinfo && bdrv_is_inserted(dinfo->bdrv) &&
!bdrv_is_removable(dinfo->bdrv)).  This is a convoluted way to test
for "drive media can't be removed".

The only way to create such a drive with -drive if=ide is media=cdrom.
And that sets dinfo->media_cd, so just test that.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/spitz.c |   10 +++-------
 hw/tosa.c  |   10 +++-------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/hw/spitz.c b/hw/spitz.c
index c05b5f7..0adae59 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -708,17 +708,13 @@ static void spitz_ssp_attach(PXA2xxState *cpu)
 static void spitz_microdrive_attach(PXA2xxState *cpu, int slot)
 {
     PCMCIACardState *md;
-    BlockDriverState *bs;
     DriveInfo *dinfo;
 
     dinfo = drive_get(IF_IDE, 0, 0);
-    if (!dinfo)
+    if (!dinfo || dinfo->media_cd)
         return;
-    bs = dinfo->bdrv;
-    if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
-        pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
-    }
+    md = dscm1xxxx_init(dinfo);
+    pxa2xx_pcmcia_attach(cpu->pcmcia[slot], md);
 }
 
 /* Wm8750 and Max7310 on I2C */
diff --git a/hw/tosa.c b/hw/tosa.c
index a7967a2..7b407f4 100644
--- a/hw/tosa.c
+++ b/hw/tosa.c
@@ -51,17 +51,13 @@
 static void tosa_microdrive_attach(PXA2xxState *cpu)
 {
     PCMCIACardState *md;
-    BlockDriverState *bs;
     DriveInfo *dinfo;
 
     dinfo = drive_get(IF_IDE, 0, 0);
-    if (!dinfo)
+    if (!dinfo || dinfo->media_cd)
         return;
-    bs = dinfo->bdrv;
-    if (bdrv_is_inserted(bs) && !bdrv_is_removable(bs)) {
-        md = dscm1xxxx_init(dinfo);
-        pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
-    }
+    md = dscm1xxxx_init(dinfo);
+    pxa2xx_pcmcia_attach(cpu->pcmcia[0], md);
 }
 
 static void tosa_out_switch(void *opaque, int line, int level)
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable"
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (33 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 34/45] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04 17:58   ` Luiz Capitulino
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 36/45] block: Drop BlockDriverState member removable Markus Armbruster
                   ` (11 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

BlockDriverState member removable is a confused mess.  It is true when
an ide-cd, scsi-cd or floppy qdev is attached, or when the
BlockDriverState was created with -drive if={floppy,sd} or -drive
if={ide,scsi,xen,none},media=cdrom ("created removable"), except when
an ide-hd, scsi-hd, scsi-generic or virtio-blk qdev is attached.

Three users remain:

1. eject_device(), via bdrv_is_removable() uses it to determine
   whether a block device can eject media.

2. bdrv_info() is monitor command "info block".  QMP documentation
   says "true if the device is removable, false otherwise".  From the
   monitor user's point of view, the only sensible interpretation of
   "is removable" is "can eject media with monitor commands eject and
   change".

A block device can eject media unless a device is attached that
doesn't support it.  Switch the two users over to new
bdrv_dev_has_removable_media() that returns exactly that.

3. bdrv_getlength() uses to suppress its length cache when media can
   change (see commit 46a4e4e6).  Media change is either monitor
   command change (updates the length cache), monitor command eject
   (doesn't update the length cache, easily fixable), or physical
   media change (invalidates length cache, not so easily fixable).

I'm refraining from improving anything here, because this series is
long enough already.  Instead, I simply switch it over to
bdrv_dev_has_removable_media() as well.

This changes the behavior of the length cache and of monitor commands
eject and change in two cases:

a. drive not created removable, no device attached

   The commit makes the drive removable, and defeats the length cache.

   Example: -drive if=none

b. drive created removable, but the attached drive is non-removable,
   and doesn't call bdrv_set_removable(..., 0) (most devices don't)

   The commit makes the drive non-removable, and enables the length
   cache.

   Example: -drive if=xen,media=cdrom -M xenpv

   The other non-removable devices that don't call
   bdrv_set_removable() can't currently use a drive created removable,
   either because they aren't qdevified, or because they lack a drive
   property.  Won't stay that way.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c        |   18 +++++++++++-------
 block.h        |    3 ++-
 blockdev.c     |    2 +-
 hw/scsi-disk.c |    5 +++++
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/block.c b/block.c
index b3a5ee7..87a3ef3 100644
--- a/block.c
+++ b/block.c
@@ -775,6 +775,9 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
 {
     bs->dev_ops = ops;
     bs->dev_opaque = opaque;
+    if (bdrv_dev_has_removable_media(bs) && bs == bs_snapshots) {
+        bs_snapshots = NULL;
+    }
 }
 
 static void bdrv_dev_change_media_cb(BlockDriverState *bs)
@@ -784,6 +787,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
     }
 }
 
+bool bdrv_dev_has_removable_media(BlockDriverState *bs)
+{
+    return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
+}
+
 static void bdrv_dev_resize_cb(BlockDriverState *bs)
 {
     if (bs->dev_ops && bs->dev_ops->resize_cb) {
@@ -1289,7 +1297,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)
     if (!drv)
         return -ENOMEDIUM;
 
-    if (bs->growable || bs->removable) {
+    if (bs->growable || bdrv_dev_has_removable_media(bs)) {
         if (drv->bdrv_getlength) {
             return drv->bdrv_getlength(bs);
         }
@@ -1574,11 +1582,6 @@ void bdrv_set_removable(BlockDriverState *bs, int removable)
     }
 }
 
-int bdrv_is_removable(BlockDriverState *bs)
-{
-    return bs->removable;
-}
-
 int bdrv_is_read_only(BlockDriverState *bs)
 {
     return bs->read_only;
@@ -1857,7 +1860,8 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
 
         bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
                                     "'removable': %i, 'locked': %i }",
-                                    bs->device_name, bs->removable,
+                                    bs->device_name,
+                                    bdrv_dev_has_removable_media(bs),
                                     bdrv_dev_is_medium_locked(bs));
 
         if (bs->drv) {
diff --git a/block.h b/block.h
index 4a6b957..fd8f1d1 100644
--- a/block.h
+++ b/block.h
@@ -34,6 +34,7 @@ typedef struct BlockDevOps {
      * Runs when virtual media changed (monitor commands eject, change)
      * Beware: doesn't run when a host device's physical media
      * changes.  Sure would be useful if it did.
+     * Device models with removable media must implement this callback.
      */
     void (*change_media_cb)(void *opaque);
     /*
@@ -99,6 +100,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);
 void *bdrv_get_attached_dev(BlockDriverState *bs);
 void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
                       void *opaque);
+bool bdrv_dev_has_removable_media(BlockDriverState *bs);
 bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
@@ -206,7 +208,6 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
                        BlockErrorAction on_write_error);
 BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
 void bdrv_set_removable(BlockDriverState *bs, int removable);
-int bdrv_is_removable(BlockDriverState *bs);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_sg(BlockDriverState *bs);
 int bdrv_enable_write_cache(BlockDriverState *bs);
diff --git a/blockdev.c b/blockdev.c
index bb1f8c4..bcddfc0 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -645,7 +645,7 @@ out:
 
 static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
 {
-    if (!bdrv_is_removable(bs)) {
+    if (!bdrv_dev_has_removable_media(bs)) {
         qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
         return -1;
     }
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 04e0a77..a30063a 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1211,12 +1211,17 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
+static void scsi_cd_change_media_cb(void *opaque)
+{
+}
+
 static bool scsi_cd_is_medium_locked(void *opaque)
 {
     return ((SCSIDiskState *)opaque)->tray_locked;
 }
 
 static const BlockDevOps scsi_cd_block_ops = {
+    .change_media_cb = scsi_cd_change_media_cb,
     .is_medium_locked = scsi_cd_is_medium_locked,
 };
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 36/45] block: Drop BlockDriverState member removable
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (34 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable" Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block Markus Armbruster
                   ` (10 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

It's a confused mess (see previous commit).  No users remain.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c           |    8 --------
 block.h           |    1 -
 block_int.h       |    1 -
 blockdev.c        |    5 -----
 hw/fdc.c          |    1 -
 hw/ide/core.c     |    1 -
 hw/scsi-disk.c    |    1 -
 hw/scsi-generic.c |    1 -
 hw/virtio-blk.c   |    1 -
 9 files changed, 0 insertions(+), 20 deletions(-)

diff --git a/block.c b/block.c
index 87a3ef3..b488b21 100644
--- a/block.c
+++ b/block.c
@@ -1574,14 +1574,6 @@ BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read)
     return is_read ? bs->on_read_error : bs->on_write_error;
 }
 
-void bdrv_set_removable(BlockDriverState *bs, int removable)
-{
-    bs->removable = removable;
-    if (removable && bs == bs_snapshots) {
-        bs_snapshots = NULL;
-    }
-}
-
 int bdrv_is_read_only(BlockDriverState *bs)
 {
     return bs->read_only;
diff --git a/block.h b/block.h
index fd8f1d1..6b11be5 100644
--- a/block.h
+++ b/block.h
@@ -207,7 +207,6 @@ int bdrv_get_translation_hint(BlockDriverState *bs);
 void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
                        BlockErrorAction on_write_error);
 BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
-void bdrv_set_removable(BlockDriverState *bs, int removable);
 int bdrv_is_read_only(BlockDriverState *bs);
 int bdrv_is_sg(BlockDriverState *bs);
 int bdrv_enable_write_cache(BlockDriverState *bs);
diff --git a/block_int.h b/block_int.h
index a271a07..9dad1c0 100644
--- a/block_int.h
+++ b/block_int.h
@@ -154,7 +154,6 @@ struct BlockDriverState {
     int read_only; /* if true, the media is read only */
     int keep_read_only; /* if true, the media was requested to stay read only */
     int open_flags; /* flags used to open the file, re-used for re-open */
-    int removable; /* if true, the media can be removed */
     int encrypted; /* if true, the media is encrypted */
     int valid_key; /* if true, a valid encryption key has been set */
     int sg;        /* if true, the device is a /dev/sg* */
diff --git a/blockdev.c b/blockdev.c
index bcddfc0..6d921ea 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -482,17 +482,12 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
             }
 	    break;
 	case MEDIA_CDROM:
-            bdrv_set_removable(dinfo->bdrv, 1);
             dinfo->media_cd = 1;
 	    break;
 	}
         break;
     case IF_SD:
-        /* FIXME: This isn't really a floppy, but it's a reasonable
-           approximation.  */
     case IF_FLOPPY:
-        bdrv_set_removable(dinfo->bdrv, 1);
-        break;
     case IF_PFLASH:
     case IF_MTD:
         break;
diff --git a/hw/fdc.c b/hw/fdc.c
index 6854e15..debcd89 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1813,7 +1813,6 @@ static int fdctrl_connect_drives(FDCtrl *fdctrl)
         fd_revalidate(drive);
         if (drive->bs) {
             drive->media_changed = 1;
-            bdrv_set_removable(drive->bs, 1);
             bdrv_set_dev_ops(drive->bs, &fdctrl_block_ops, drive);
         }
     }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 22a2dc7..c82d8a1 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1838,7 +1838,6 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
     }
 
     ide_reset(s);
-    bdrv_set_removable(bs, s->drive_kind == IDE_CD);
     if (s->drive_kind == IDE_CD) {
         bdrv_lock_medium(bs, s->tray_locked);
         bdrv_eject(bs, s->tray_open);
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a30063a..a7a70bd 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1272,7 +1272,6 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
 
     s->qdev.type = scsi_type;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-    bdrv_set_removable(s->bs, scsi_type == TYPE_ROM);
     if (scsi_type == TYPE_ROM) {
         bdrv_lock_medium(s->bs, s->tray_locked);
         bdrv_eject(s->bs, s->tray_open);
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index 7b0026e..8cbbdc9 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -534,7 +534,6 @@ static int scsi_generic_initfn(SCSIDevice *dev)
     DPRINTF("block size %d\n", s->qdev.blocksize);
     s->driver_status = 0;
     memset(s->sensebuf, 0, sizeof(s->sensebuf));
-    bdrv_set_removable(s->bs, 0);
     return 0;
 }
 
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index dc0b692..4ed1975 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -583,7 +583,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     s->qdev = dev;
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
-    bdrv_set_removable(s->bs, 0);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
     s->bs->buffer_alignment = conf->logical_block_size;
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (35 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 36/45] block: Drop BlockDriverState member removable Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04 18:05   ` Luiz Capitulino
  2011-09-02 13:04   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 38/45] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
                   ` (9 subsequent siblings)
  46 siblings, 2 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Need to ask the device, so this requires new BlockDevOps member
is_medium_ejected().

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c         |   17 +++++++++++++++--
 block.h         |    6 ++++++
 hw/ide/core.c   |    6 ++++++
 hw/scsi-disk.c  |    6 ++++++
 qmp-commands.hx |    2 ++
 5 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index b488b21..fed0c16 100644
--- a/block.c
+++ b/block.c
@@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs)
     return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
 }
 
+bool bdrv_dev_is_medium_ejected(BlockDriverState *bs)
+{
+    if (bs->dev_ops && bs->dev_ops->is_medium_ejected) {
+        return bs->dev_ops->is_medium_ejected(bs->dev_opaque);
+    }
+    return false;
+}
+
 static void bdrv_dev_resize_cb(BlockDriverState *bs)
 {
     if (bs->dev_ops && bs->dev_ops->resize_cb) {
@@ -1813,8 +1821,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque)
 
     if (qdict_get_bool(bs_dict, "removable")) {
         monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
+        monitor_printf(mon, " ejected=%d", qdict_get_bool(bs_dict, "ejected"));
     }
-
     if (qdict_haskey(bs_dict, "inserted")) {
         QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
 
@@ -1849,16 +1857,21 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
 
     QTAILQ_FOREACH(bs, &bdrv_states, list) {
         QObject *bs_obj;
+        QDict *bs_dict;
 
         bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
                                     "'removable': %i, 'locked': %i }",
                                     bs->device_name,
                                     bdrv_dev_has_removable_media(bs),
                                     bdrv_dev_is_medium_locked(bs));
+        bs_dict = qobject_to_qdict(bs_obj);
 
+        if (bdrv_dev_has_removable_media(bs)) {
+            qdict_put(bs_dict, "ejected",
+                      qbool_from_int(bdrv_dev_is_medium_ejected(bs)));
+        }
         if (bs->drv) {
             QObject *obj;
-            QDict *bs_dict = qobject_to_qdict(bs_obj);
 
             obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
                                      "'encrypted': %i }",
diff --git a/block.h b/block.h
index 6b11be5..fdb7680 100644
--- a/block.h
+++ b/block.h
@@ -38,6 +38,11 @@ typedef struct BlockDevOps {
      */
     void (*change_media_cb)(void *opaque);
     /*
+     * Is medium ejected from the device?
+     * Device models calling bdrv_eject() should implement this.
+     */
+    bool (*is_medium_ejected)(void *opaque);
+    /*
      * Is the virtual medium locked into the device?
      * Device models should implement this only when device has such a
      * lock.
@@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs);
 void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
                       void *opaque);
 bool bdrv_dev_has_removable_media(BlockDriverState *bs);
+bool bdrv_dev_is_medium_ejected(BlockDriverState *bs);
 bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
               uint8_t *buf, int nb_sectors);
diff --git a/hw/ide/core.c b/hw/ide/core.c
index c82d8a1..47dd81c 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1769,6 +1769,11 @@ void ide_bus_reset(IDEBus *bus)
     bus->dma->ops->reset(bus->dma);
 }
 
+static bool ide_cd_medium_ejected(void *opaque)
+{
+    return ((IDEState *)opaque)->tray_open;
+}
+
 static bool ide_cd_is_medium_locked(void *opaque)
 {
     return ((IDEState *)opaque)->tray_locked;
@@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque)
 
 static const BlockDevOps ide_cd_block_ops = {
     .change_media_cb = ide_cd_change_cb,
+    .is_medium_ejected = ide_cd_medium_ejected,
     .is_medium_locked = ide_cd_is_medium_locked,
 };
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a7a70bd..3ebcee4 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque)
 {
 }
 
+static bool scsi_cd_is_medium_ejected(void *opaque)
+{
+    return ((SCSIDiskState *)opaque)->tray_open;
+}
+
 static bool scsi_cd_is_medium_locked(void *opaque)
 {
     return ((SCSIDiskState *)opaque)->tray_locked;
@@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque)
 
 static const BlockDevOps scsi_cd_block_ops = {
     .change_media_cb = scsi_cd_change_media_cb,
+    .is_medium_ejected = scsi_cd_is_medium_ejected,
     .is_medium_locked = scsi_cd_is_medium_locked,
 };
 
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 03f67da..b0447f1 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1131,6 +1131,8 @@ Each json-object contain the following:
          - Possible values: "unknown"
 - "removable": true if the device is removable, false otherwise (json-bool)
 - "locked": true if the device is locked, false otherwise (json-bool)
+- "ejected": only present if removable, true if the device ejected its
+             media (json-bool)
 - "inserted": only present if the device is inserted, it is a json-object
    containing the following:
          - "file": device file name (json-string)
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 38/45] block: Move BlockConf & friends from block_int.h to block.h
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (36 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 39/45] hw: Trim superfluous #include "block_int.h" Markus Armbruster
                   ` (8 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

It's convenience stuff for block device models, so block.h isn't the
ideal home either, but better than block_int.h.

Permits moving some #include "block_int.h" from device model .h into
.c.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.h           |   38 ++++++++++++++++++++++++++++++++++++++
 block_int.h       |   35 -----------------------------------
 hw/ide/core.c     |    1 +
 hw/ide/internal.h |    1 -
 hw/scsi-disk.c    |    1 +
 hw/scsi.h         |    1 -
 hw/virtio-blk.c   |    1 +
 hw/virtio.h       |    2 +-
 8 files changed, 42 insertions(+), 38 deletions(-)

diff --git a/block.h b/block.h
index fdb7680..a8aca5f 100644
--- a/block.h
+++ b/block.h
@@ -331,4 +331,42 @@ typedef enum {
 #define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
 void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
 
+
+/* Convenience for block device models */
+
+typedef struct BlockConf {
+    BlockDriverState *bs;
+    uint16_t physical_block_size;
+    uint16_t logical_block_size;
+    uint16_t min_io_size;
+    uint32_t opt_io_size;
+    int32_t bootindex;
+    uint32_t discard_granularity;
+} BlockConf;
+
+static inline unsigned int get_physical_block_exp(BlockConf *conf)
+{
+    unsigned int exp = 0, size;
+
+    for (size = conf->physical_block_size;
+        size > conf->logical_block_size;
+        size >>= 1) {
+        exp++;
+    }
+
+    return exp;
+}
+
+#define DEFINE_BLOCK_PROPERTIES(_state, _conf)                          \
+    DEFINE_PROP_DRIVE("drive", _state, _conf.bs),                       \
+    DEFINE_PROP_UINT16("logical_block_size", _state,                    \
+                       _conf.logical_block_size, 512),                  \
+    DEFINE_PROP_UINT16("physical_block_size", _state,                   \
+                       _conf.physical_block_size, 512),                 \
+    DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
+    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
+    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1),        \
+    DEFINE_PROP_UINT32("discard_granularity", _state, \
+                       _conf.discard_granularity, 0)
+
 #endif
diff --git a/block_int.h b/block_int.h
index 9dad1c0..e5385ba 100644
--- a/block_int.h
+++ b/block_int.h
@@ -227,39 +227,4 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size);
 int is_windows_drive(const char *filename);
 #endif
 
-typedef struct BlockConf {
-    BlockDriverState *bs;
-    uint16_t physical_block_size;
-    uint16_t logical_block_size;
-    uint16_t min_io_size;
-    uint32_t opt_io_size;
-    int32_t bootindex;
-    uint32_t discard_granularity;
-} BlockConf;
-
-static inline unsigned int get_physical_block_exp(BlockConf *conf)
-{
-    unsigned int exp = 0, size;
-
-    for (size = conf->physical_block_size;
-        size > conf->logical_block_size;
-        size >>= 1) {
-        exp++;
-    }
-
-    return exp;
-}
-
-#define DEFINE_BLOCK_PROPERTIES(_state, _conf)                          \
-    DEFINE_PROP_DRIVE("drive", _state, _conf.bs),                       \
-    DEFINE_PROP_UINT16("logical_block_size", _state,                    \
-                       _conf.logical_block_size, 512),                  \
-    DEFINE_PROP_UINT16("physical_block_size", _state,                   \
-                       _conf.physical_block_size, 512),                 \
-    DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0),  \
-    DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0),    \
-    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1),        \
-    DEFINE_PROP_UINT32("discard_granularity", _state, \
-                       _conf.discard_granularity, 0)
-
 #endif /* BLOCK_INT_H */
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 47dd81c..24e10b2 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -30,6 +30,7 @@
 #include "sysemu.h"
 #include "dma.h"
 #include "blockdev.h"
+#include "block_int.h"
 
 #include <hw/ide/internal.h>
 
diff --git a/hw/ide/internal.h b/hw/ide/internal.h
index 0b0b8a7..f16e671 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -7,7 +7,6 @@
  * non-internal declarations are in hw/ide.h
  */
 #include <hw/ide.h>
-#include "block_int.h"
 #include "iorange.h"
 #include "dma.h"
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 3ebcee4..5159e5d 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -37,6 +37,7 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #include "scsi-defs.h"
 #include "sysemu.h"
 #include "blockdev.h"
+#include "block_int.h"
 
 #define SCSI_DMA_BUF_SIZE    131072
 #define SCSI_MAX_INQUIRY_LEN 256
diff --git a/hw/scsi.h b/hw/scsi.h
index 63442c6..943216e 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -3,7 +3,6 @@
 
 #include "qdev.h"
 #include "block.h"
-#include "block_int.h"
 
 #define MAX_SCSI_DEVS	255
 
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 4ed1975..a517150 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -15,6 +15,7 @@
 #include "qemu-error.h"
 #include "trace.h"
 #include "blockdev.h"
+#include "block_int.h"
 #include "virtio-blk.h"
 #ifdef __linux__
 # include <scsi/sg.h>
diff --git a/hw/virtio.h b/hw/virtio.h
index 0fd0bb0..fd9967d 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -18,7 +18,7 @@
 #include "net.h"
 #include "qdev.h"
 #include "sysemu.h"
-#include "block_int.h"
+#include "block.h"
 #include "event_notifier.h"
 #ifdef CONFIG_LINUX
 #include "9p.h"
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 39/45] hw: Trim superfluous #include "block_int.h"
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (37 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 38/45] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
                   ` (7 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Including it in device models is unclean, including it without a
reason adds insult to injury.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/fdc.c            |    1 -
 hw/ide/cmd646.c     |    1 -
 hw/ide/ich.c        |    1 -
 hw/ide/isa.c        |    1 -
 hw/ide/macio.c      |    1 -
 hw/ide/microdrive.c |    1 -
 hw/ide/mmio.c       |    1 -
 hw/ide/pci.c        |    1 -
 hw/ide/via.c        |    1 -
 hw/lsi53c895a.c     |    1 -
 10 files changed, 0 insertions(+), 10 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index debcd89..e8da6a9 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -36,7 +36,6 @@
 #include "qdev-addr.h"
 #include "blockdev.h"
 #include "sysemu.h"
-#include "block_int.h"
 
 /********************************************************/
 /* debug Floppy devices */
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index 56302b5..79ceca0 100644
--- a/hw/ide/cmd646.c
+++ b/hw/ide/cmd646.c
@@ -27,7 +27,6 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "sysemu.h"
 #include "dma.h"
 
diff --git a/hw/ide/ich.c b/hw/ide/ich.c
index d241ea8..3e758e9 100644
--- a/hw/ide/ich.c
+++ b/hw/ide/ich.c
@@ -66,7 +66,6 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/pci.h>
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 4ac7453..28b69d2 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -26,7 +26,6 @@
 #include <hw/pc.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/internal.h>
diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index 7daeb31..e92c330 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -26,7 +26,6 @@
 #include <hw/ppc_mac.h>
 #include <hw/mac_dbdma.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/internal.h>
diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 9fbbf0e..61a6034 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -26,7 +26,6 @@
 #include <hw/pc.h>
 #include <hw/pcmcia.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/internal.h>
diff --git a/hw/ide/mmio.c b/hw/ide/mmio.c
index 10f6f40..d6bb5e3 100644
--- a/hw/ide/mmio.c
+++ b/hw/ide/mmio.c
@@ -24,7 +24,6 @@
  */
 #include <hw/hw.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/internal.h>
diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index 9f3050a..a5371f4 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -27,7 +27,6 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "dma.h"
 
 #include <hw/ide/pci.h>
diff --git a/hw/ide/via.c b/hw/ide/via.c
index 3474c37..3c131f6 100644
--- a/hw/ide/via.c
+++ b/hw/ide/via.c
@@ -28,7 +28,6 @@
 #include <hw/pci.h>
 #include <hw/isa.h>
 #include "block.h"
-#include "block_int.h"
 #include "sysemu.h"
 #include "dma.h"
 
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index e9904c4..9f76e7d 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -15,7 +15,6 @@
 #include "hw.h"
 #include "pci.h"
 #include "scsi.h"
-#include "block_int.h"
 
 //#define DEBUG_LSI
 //#define DEBUG_LSI_REG
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (38 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 39/45] hw: Trim superfluous #include "block_int.h" Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04 18:10   ` Luiz Capitulino
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment() Markus Armbruster
                   ` (6 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Device models should be able to use it without an unclean include of
block_int.h.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.h     |    2 ++
 block_int.h |    2 --
 hw/sd.c     |    1 -
 3 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/block.h b/block.h
index a8aca5f..3dfd2a4 100644
--- a/block.h
+++ b/block.h
@@ -269,6 +269,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
                     const char *base_filename, const char *base_fmt,
                     char *options, uint64_t img_size, int flags);
 
+void *qemu_blockalign(BlockDriverState *bs, size_t size);
+
 #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
 
 void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
diff --git a/block_int.h b/block_int.h
index e5385ba..9a59784 100644
--- a/block_int.h
+++ b/block_int.h
@@ -221,8 +221,6 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
                    BlockDriverCompletionFunc *cb, void *opaque);
 void qemu_aio_release(void *p);
 
-void *qemu_blockalign(BlockDriverState *bs, size_t size);
-
 #ifdef _WIN32
 int is_windows_drive(const char *filename);
 #endif
diff --git a/hw/sd.c b/hw/sd.c
index 24f4af8..3bcfe6a 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -31,7 +31,6 @@
 
 #include "hw.h"
 #include "block.h"
-#include "block_int.h"
 #include "sd.h"
 
 //#define DEBUG_SD 1
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (39 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-09-02 13:13   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach Markus Armbruster
                   ` (5 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

Device models should be able to set it without an unclean include of
block_int.h.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c         |    6 ++++--
 block.h         |    1 +
 hw/ide/core.c   |    2 +-
 hw/scsi-disk.c  |    2 +-
 hw/virtio-blk.c |    3 +--
 5 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/block.c b/block.c
index fed0c16..67d9429 100644
--- a/block.c
+++ b/block.c
@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
     bs->encrypted = 0;
     bs->valid_key = 0;
     bs->open_flags = flags;
-    /* buffer_alignment defaulted to 512, drivers can change this value */
     bs->buffer_alignment = 512;
 
     pstrcpy(bs->filename, sizeof(bs->filename), filename);
@@ -3070,7 +3069,10 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
     return NULL;
 }
 
-
+void bdrv_set_buffer_alignment(BlockDriverState *bs, int align)
+{
+    bs->buffer_alignment = align;
+}
 
 void *qemu_blockalign(BlockDriverState *bs, size_t size)
 {
diff --git a/block.h b/block.h
index 3dfd2a4..3885208 100644
--- a/block.h
+++ b/block.h
@@ -269,6 +269,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
                     const char *base_filename, const char *base_fmt,
                     char *options, uint64_t img_size, int flags);
 
+void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
 void *qemu_blockalign(BlockDriverState *bs, size_t size);
 
 #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 24e10b2..bd59016 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1821,7 +1821,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
     s->smart_selftest_count = 0;
     if (kind == IDE_CD) {
         bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);
-        bs->buffer_alignment = 2048;
+        bdrv_set_buffer_alignment(bs, 2048);
     } else {
         if (!bdrv_is_inserted(s->bs)) {
             error_report("Device needs media, but drive is empty");
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 5159e5d..71d6408 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1275,7 +1275,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
         return -1;
     }
     s->cluster_size = s->qdev.blocksize / 512;
-    s->bs->buffer_alignment = s->qdev.blocksize;
+    bdrv_set_buffer_alignment(s->bs, s->qdev.blocksize);
 
     s->qdev.type = scsi_type;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index a517150..811d709 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -15,7 +15,6 @@
 #include "qemu-error.h"
 #include "trace.h"
 #include "blockdev.h"
-#include "block_int.h"
 #include "virtio-blk.h"
 #ifdef __linux__
 # include <scsi/sg.h>
@@ -585,7 +584,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
     register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
                     virtio_blk_save, virtio_blk_load, s);
     bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
-    s->bs->buffer_alignment = conf->logical_block_size;
+    bdrv_set_buffer_alignment(s->bs, conf->logical_block_size);
 
     add_boot_device_path(conf->bootindex, dev, "/disk@0,0");
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (40 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment() Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-09-02 13:20   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 43/45] nbd: Clean up use of block_int.h Markus Armbruster
                   ` (4 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

BlockDriverState member buffer_alignment is initially 512.  The device
model may set them, with bdrv_set_buffer_alignment().  If the device
model gets detached (hot unplug), the device's alignment is left
behind.  Only okay because device hot unplug automatically destroys
the BlockDriverState.  But that's a questionable feature, best not to
rely on it.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 67d9429..b0e54ef 100644
--- a/block.c
+++ b/block.c
@@ -761,6 +761,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev)
     bs->dev = NULL;
     bs->dev_ops = NULL;
     bs->dev_opaque = NULL;
+    bs->buffer_alignment = 512;
 }
 
 /* TODO change to return DeviceState * when all users are qdevified */
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 43/45] nbd: Clean up use of block_int.h
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (41 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load Markus Armbruster
                   ` (3 subsequent siblings)
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch


Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block/nbd.c |    1 +
 nbd.c       |    1 +
 nbd.h       |    2 --
 3 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/block/nbd.c b/block/nbd.c
index 7a52f62..2e365ac 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -28,6 +28,7 @@
 
 #include "qemu-common.h"
 #include "nbd.h"
+#include "block_int.h"
 #include "module.h"
 #include "qemu_socket.h"
 
diff --git a/nbd.c b/nbd.c
index e7a585d..6d81cfb 100644
--- a/nbd.c
+++ b/nbd.c
@@ -17,6 +17,7 @@
  */
 
 #include "nbd.h"
+#include "block.h"
 
 #include <errno.h>
 #include <string.h>
diff --git a/nbd.h b/nbd.h
index b38d0d0..5f87a7d 100644
--- a/nbd.h
+++ b/nbd.h
@@ -23,8 +23,6 @@
 
 #include <qemu-common.h>
 
-#include "block_int.h"
-
 struct nbd_request {
     uint32_t magic;
     uint32_t type;
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (42 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 43/45] nbd: Clean up use of block_int.h Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-09-02 13:26   ` Kevin Wolf
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 45/45] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
                   ` (2 subsequent siblings)
  46 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

To let device models distinguish between eject and load.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c        |   12 ++++++------
 block.h        |    3 ++-
 hw/fdc.c       |    2 +-
 hw/ide/core.c  |    2 +-
 hw/scsi-disk.c |    2 +-
 hw/sd.c        |    2 +-
 6 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/block.c b/block.c
index b0e54ef..1bd67dd 100644
--- a/block.c
+++ b/block.c
@@ -44,7 +44,7 @@
 #include <windows.h>
 #endif
 
-static void bdrv_dev_change_media_cb(BlockDriverState *bs);
+static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
 static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
         int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
         BlockDriverCompletionFunc *cb, void *opaque);
@@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
     }
 
     if (!bdrv_key_required(bs)) {
-        bdrv_dev_change_media_cb(bs);
+        bdrv_dev_change_media_cb(bs, true);
     }
 
     return 0;
@@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)
             bdrv_close(bs->file);
         }
 
-        bdrv_dev_change_media_cb(bs);
+        bdrv_dev_change_media_cb(bs, false);
     }
 }
 
@@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
     }
 }
 
-static void bdrv_dev_change_media_cb(BlockDriverState *bs)
+static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
 {
     if (bs->dev_ops && bs->dev_ops->change_media_cb) {
-        bs->dev_ops->change_media_cb(bs->dev_opaque);
+        bs->dev_ops->change_media_cb(bs->dev_opaque, load);
     }
 }
 
@@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
     } else if (!bs->valid_key) {
         bs->valid_key = 1;
         /* call the change callback now, we skipped it on open */
-        bdrv_dev_change_media_cb(bs);
+        bdrv_dev_change_media_cb(bs, 1);
     }
     return ret;
 }
diff --git a/block.h b/block.h
index 3885208..3fe0357 100644
--- a/block.h
+++ b/block.h
@@ -32,11 +32,12 @@ typedef struct QEMUSnapshotInfo {
 typedef struct BlockDevOps {
     /*
      * Runs when virtual media changed (monitor commands eject, change)
+     * Argument load is true on load and false on eject.
      * Beware: doesn't run when a host device's physical media
      * changes.  Sure would be useful if it did.
      * Device models with removable media must implement this callback.
      */
-    void (*change_media_cb)(void *opaque);
+    void (*change_media_cb)(void *opaque, bool load);
     /*
      * Is medium ejected from the device?
      * Device models calling bdrv_eject() should implement this.
diff --git a/hw/fdc.c b/hw/fdc.c
index e8da6a9..1f084ce 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1777,7 +1777,7 @@ static void fdctrl_result_timer(void *opaque)
     fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00);
 }
 
-static void fdctrl_change_cb(void *opaque)
+static void fdctrl_change_cb(void *opaque, bool load)
 {
     FDrive *drive = opaque;
 
diff --git a/hw/ide/core.c b/hw/ide/core.c
index bd59016..832fdda 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -759,7 +759,7 @@ static void ide_cfata_metadata_write(IDEState *s)
 }
 
 /* called when the inserted state of the media has changed */
-static void ide_cd_change_cb(void *opaque)
+static void ide_cd_change_cb(void *opaque, bool load)
 {
     IDEState *s = opaque;
     uint64_t nb_sectors;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 71d6408..aa90ede 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1212,7 +1212,7 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
-static void scsi_cd_change_media_cb(void *opaque)
+static void scsi_cd_change_media_cb(void *opaque, bool load)
 {
 }
 
diff --git a/hw/sd.c b/hw/sd.c
index 3bcfe6a..e756996 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -419,7 +419,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv)
     sd->pwd_len = 0;
 }
 
-static void sd_cardchange(void *opaque)
+static void sd_cardchange(void *opaque, bool load)
 {
     SDState *sd = opaque;
 
-- 
1.7.6

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

* [Qemu-devel] [PATCH v2 45/45] ide/atapi scsi-disk: Make monitor eject -f, then change work
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (43 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load Markus Armbruster
@ 2011-08-03 13:08 ` Markus Armbruster
  2011-08-04 15:54 ` [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Avi Kivity
  2011-09-02 13:37 ` Kevin Wolf
  46 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, stefano.stabellini, lcapitulino, hare, amit.shah, hch

change fails while the tray is locked by the guest.  eject -f forces
it open and removes any media.  Unfortunately, the tray closes again
instantly.  Since the lock remains as it is, there is no way to insert
another medium unless the guest voluntarily unlocks.

Fix by leaving the tray open after monitor eject.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 blockdev.c     |    3 ++-
 hw/ide/core.c  |    1 +
 hw/scsi-disk.c |    1 +
 3 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/blockdev.c b/blockdev.c
index 6d921ea..6e4f1df 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -644,7 +644,8 @@ static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
         qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
         return -1;
     }
-    if (!force && bdrv_dev_is_medium_locked(bs)) {
+    if (!force && !bdrv_dev_is_medium_ejected(bs)
+        && bdrv_dev_is_medium_locked(bs)) {
         qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
         return -1;
     }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 832fdda..e3d596d 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -764,6 +764,7 @@ static void ide_cd_change_cb(void *opaque, bool load)
     IDEState *s = opaque;
     uint64_t nb_sectors;
 
+    s->tray_open = !load;
     bdrv_get_geometry(s->bs, &nb_sectors);
     s->nb_sectors = nb_sectors;
 
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index aa90ede..cb2b9e2 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1214,6 +1214,7 @@ static void scsi_destroy(SCSIDevice *dev)
 
 static void scsi_cd_change_media_cb(void *opaque, bool load)
 {
+    ((SCSIDiskState *)opaque)->tray_open = !load;
 }
 
 static bool scsi_cd_is_medium_ejected(void *opaque)
-- 
1.7.6

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

* Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
@ 2011-08-03 16:53   ` Blue Swirl
  2011-08-03 17:15     ` Markus Armbruster
  2011-09-02 10:08     ` Kevin Wolf
  0 siblings, 2 replies; 105+ messages in thread
From: Blue Swirl @ 2011-08-03 16:53 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, quintela, qemu-devel, lcapitulino,
	hare, amit.shah, hch

On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster <armbru@redhat.com> wrote:
> No functional change.
>
> It would be nice to have handler functions in the table, like commit
> e1a064f9 did for ATAPI.  Left for another day.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/core.c |  104 +++++++++++++++++++++++++++++++++++++++++++--------------
>  1 files changed, 79 insertions(+), 25 deletions(-)
>
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 1c4dc2f..a25c175 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>     }
>  }
>
> +#define HD_OK (1u << IDE_HD)
> +#define CD_OK (1u << IDE_CD)
> +#define CFA_OK (1u << IDE_CFATA)
> +#define HD_CFA_OK (HD_OK | CFA_OK)
> +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
> +
> +/* See ACS-2 T13/2015-D Table B.2 Command codes */
> +uint8_t ide_cmd_table[0x100] = {

Missing 'static'.

> +    /* NOP not implemented, mandatory for CD */
> +    [CFA_REQ_EXT_ERROR_CODE]            = CFA_OK,
> +    [WIN_DSM]                           = ALL_OK,
> +    [WIN_DEVICE_RESET]                  = CD_OK,
> +    [WIN_RECAL]                         = ALL_OK,
> +    [WIN_READ]                          = ALL_OK,
> +    [WIN_READ_ONCE]                     = ALL_OK,
> +    [WIN_READ_EXT]                      = ALL_OK,
> +    [WIN_READDMA_EXT]                   = ALL_OK,
> +    [WIN_READ_NATIVE_MAX_EXT]           = ALL_OK,
> +    [WIN_MULTREAD_EXT]                  = ALL_OK,
> +    [WIN_WRITE]                         = ALL_OK,
> +    [WIN_WRITE_ONCE]                    = ALL_OK,
> +    [WIN_WRITE_EXT]                     = ALL_OK,
> +    [WIN_WRITEDMA_EXT]                  = ALL_OK,
> +    [CFA_WRITE_SECT_WO_ERASE]           = ALL_OK,
> +    [WIN_MULTWRITE_EXT]                 = ALL_OK,
> +    [WIN_WRITE_VERIFY]                  = ALL_OK,
> +    [WIN_VERIFY]                        = ALL_OK,
> +    [WIN_VERIFY_ONCE]                   = ALL_OK,
> +    [WIN_VERIFY_EXT]                    = ALL_OK,
> +    [WIN_SEEK]                          = HD_CFA_OK,
> +    [CFA_TRANSLATE_SECTOR]              = CFA_OK,
> +    [WIN_DIAGNOSE]                      = ALL_OK,
> +    [WIN_SPECIFY]                       = ALL_OK,
> +    [WIN_STANDBYNOW2]                   = ALL_OK,
> +    [WIN_IDLEIMMEDIATE2]                = ALL_OK,
> +    [WIN_STANDBY2]                      = ALL_OK,
> +    [WIN_SETIDLE2]                      = ALL_OK,
> +    [WIN_CHECKPOWERMODE2]               = ALL_OK,
> +    [WIN_SLEEPNOW2]                     = ALL_OK,
> +    [WIN_PACKETCMD]                     = CD_OK,
> +    [WIN_PIDENTIFY]                     = CD_OK,
> +    [WIN_SMART]                         = HD_CFA_OK,
> +    [CFA_ACCESS_METADATA_STORAGE]       = CFA_OK,
> +    [CFA_ERASE_SECTORS]                 = CFA_OK,
> +    [WIN_MULTREAD]                      = ALL_OK,
> +    [WIN_MULTWRITE]                     = ALL_OK,
> +    [WIN_SETMULT]                       = ALL_OK,
> +    [WIN_READDMA]                       = ALL_OK,
> +    [WIN_READDMA_ONCE]                  = ALL_OK,
> +    [WIN_WRITEDMA]                      = ALL_OK,
> +    [WIN_WRITEDMA_ONCE]                 = ALL_OK,
> +    [CFA_WRITE_MULTI_WO_ERASE]          = ALL_OK,
> +    [WIN_STANDBYNOW1]                   = ALL_OK,
> +    [WIN_IDLEIMMEDIATE]                 = ALL_OK,
> +    [WIN_STANDBY]                       = ALL_OK,
> +    [WIN_SETIDLE1]                      = ALL_OK,
> +    [WIN_CHECKPOWERMODE1]               = ALL_OK,
> +    [WIN_SLEEPNOW1]                     = ALL_OK,
> +    [WIN_FLUSH_CACHE]                   = ALL_OK,
> +    [WIN_FLUSH_CACHE_EXT]               = ALL_OK,
> +    [WIN_IDENTIFY]                      = ALL_OK,
> +    [WIN_SETFEATURES]                   = ALL_OK,
> +    [IBM_SENSE_CONDITION]               = CFA_OK,
> +    [CFA_WEAR_LEVEL]                    = CFA_OK,
> +    [WIN_READ_NATIVE_MAX]               = ALL_OK,
> +};
> +
> +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
> +{
> +    return cmd <= 0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind));
> +}
>
>  void ide_exec_cmd(IDEBus *bus, uint32_t val)
>  {
> @@ -895,6 +966,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>     if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
>         return;
>
> +    if (!ide_cmd_permitted(s, val)) {
> +        goto abort_cmd;
> +    }
> +
>     switch(val) {
>     case WIN_DSM:
>         switch (s->feature) {
> @@ -1115,21 +1190,15 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         ide_set_irq(s->bus);
>         break;
>     case WIN_SEEK:
> -        if(s->drive_kind == IDE_CD)
> -            goto abort_cmd;
>         /* XXX: Check that seek is within bounds */
>         s->status = READY_STAT | SEEK_STAT;
>         ide_set_irq(s->bus);
>         break;
>         /* ATAPI commands */
>     case WIN_PIDENTIFY:
> -        if (s->drive_kind == IDE_CD) {
> -            ide_atapi_identify(s);
> -            s->status = READY_STAT | SEEK_STAT;
> -            ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
> -        } else {
> -            ide_abort_command(s);
> -        }
> +        ide_atapi_identify(s);
> +        s->status = READY_STAT | SEEK_STAT;
> +        ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
>         ide_set_irq(s->bus);
>         break;
>     case WIN_DIAGNOSE:
> @@ -1146,15 +1215,11 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         ide_set_irq(s->bus);
>         break;
>     case WIN_DEVICE_RESET:
> -        if (s->drive_kind != IDE_CD)
> -            goto abort_cmd;
>         ide_set_signature(s);
>         s->status = 0x00; /* NOTE: READY is _not_ set */
>         s->error = 0x01;
>         break;
>     case WIN_PACKETCMD:
> -        if (s->drive_kind != IDE_CD)
> -            goto abort_cmd;
>         /* overlapping commands not supported */
>         if (s->feature & 0x02)
>             goto abort_cmd;
> @@ -1166,16 +1231,12 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         break;
>     /* CF-ATA commands */
>     case CFA_REQ_EXT_ERROR_CODE:
> -        if (s->drive_kind != IDE_CFATA)
> -            goto abort_cmd;
>         s->error = 0x09;    /* miscellaneous error */
>         s->status = READY_STAT | SEEK_STAT;
>         ide_set_irq(s->bus);
>         break;
>     case CFA_ERASE_SECTORS:
>     case CFA_WEAR_LEVEL:
> -        if (s->drive_kind != IDE_CFATA)
> -            goto abort_cmd;
>         if (val == CFA_WEAR_LEVEL)
>             s->nsector = 0;
>         if (val == CFA_ERASE_SECTORS)
> @@ -1185,8 +1246,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         ide_set_irq(s->bus);
>         break;
>     case CFA_TRANSLATE_SECTOR:
> -        if (s->drive_kind != IDE_CFATA)
> -            goto abort_cmd;
>         s->error = 0x00;
>         s->status = READY_STAT | SEEK_STAT;
>         memset(s->io_buffer, 0, 0x200);
> @@ -1205,8 +1264,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         ide_set_irq(s->bus);
>         break;
>     case CFA_ACCESS_METADATA_STORAGE:
> -        if (s->drive_kind != IDE_CFATA)
> -            goto abort_cmd;
>         switch (s->feature) {
>         case 0x02:     /* Inquiry Metadata Storage */
>             ide_cfata_metadata_inquiry(s);
> @@ -1225,8 +1282,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         ide_set_irq(s->bus);
>         break;
>     case IBM_SENSE_CONDITION:
> -        if (s->drive_kind != IDE_CFATA)
> -            goto abort_cmd;
>         switch (s->feature) {
>         case 0x01:  /* sense temperature in device */
>             s->nsector = 0x50;      /* +20 C */
> @@ -1239,8 +1294,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>         break;
>
>     case WIN_SMART:
> -       if (s->drive_kind == IDE_CD)
> -               goto abort_cmd;
>        if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
>                goto abort_cmd;
>        if (!s->smart_enabled && s->feature != SMART_ENABLE)
> @@ -1395,6 +1448,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
>        }
>        break;
>     default:
> +        /* should not be reachable */
>     abort_cmd:
>         ide_abort_command(s);
>         ide_set_irq(s->bus);
> --
> 1.7.6
>
>
>

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

* Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
  2011-08-03 16:53   ` Blue Swirl
@ 2011-08-03 17:15     ` Markus Armbruster
  2011-09-02 10:08     ` Kevin Wolf
  1 sibling, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-03 17:15 UTC (permalink / raw)
  To: Blue Swirl
  Cc: kwolf, stefano.stabellini, quintela, qemu-devel, lcapitulino,
	hare, amit.shah, hch

Blue Swirl <blauwirbel@gmail.com> writes:

> On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster <armbru@redhat.com> wrote:
>> No functional change.
>>
>> It would be nice to have handler functions in the table, like commit
>> e1a064f9 did for ATAPI.  Left for another day.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/core.c |  104 +++++++++++++++++++++++++++++++++++++++++++--------------
>>  1 files changed, 79 insertions(+), 25 deletions(-)
>>
>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>> index 1c4dc2f..a25c175 100644
>> --- a/hw/ide/core.c
>> +++ b/hw/ide/core.c
>> @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>>     }
>>  }
>>
>> +#define HD_OK (1u << IDE_HD)
>> +#define CD_OK (1u << IDE_CD)
>> +#define CFA_OK (1u << IDE_CFATA)
>> +#define HD_CFA_OK (HD_OK | CFA_OK)
>> +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
>> +
>> +/* See ACS-2 T13/2015-D Table B.2 Command codes */
>> +uint8_t ide_cmd_table[0x100] = {
>
> Missing 'static'.

Thanks, will fix.

[...]

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

* Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
@ 2011-08-04  6:12   ` Hannes Reinecke
  2011-09-02 10:26   ` Kevin Wolf
  1 sibling, 0 replies; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:12 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:07 PM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |   17 +++++++++++++----
>   1 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index fa198f9..d549cb7 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>       return toclen;
>   }
>
> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> +{
> +    SCSIRequest *req =&r->req;
> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
> +    bool start = req->cmd.buf[4]&  1;
> +    bool loej = req->cmd.buf[4]&  2;
> +
> +    if (s->qdev.type == TYPE_ROM&&  loej) {
> +        bdrv_eject(s->bs, !start);
> +    }
> +}
> +
>   static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>   {
>       SCSIRequest *req =&r->req;
> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>               goto illegal_request;
>           break;
>       case START_STOP:
> -        if (s->qdev.type == TYPE_ROM&&  (req->cmd.buf[4]&  2)) {
> -            /* load/eject medium */
> -            bdrv_eject(s->bs, !(req->cmd.buf[4]&  1));
> -        }
> +        scsi_disk_emulate_start_stop(r);
>           break;
>       case ALLOW_MEDIUM_REMOVAL:
>           bdrv_set_locked(s->bs, req->cmd.buf[4]&  1);

Acked-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state Markus Armbruster
@ 2011-08-04  6:13   ` Hannes Reinecke
  0 siblings, 0 replies; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:13 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:07 PM, Markus Armbruster wrote:
> We already track it in BlockDriverState since commit 4be9762a.  As
> discussed in that commit's message, we should track it in the device
> device models instead, because it's device state.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index d549cb7..2d5e157 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -72,6 +72,7 @@ struct SCSIDiskState
>       char *version;
>       char *serial;
>       SCSISense sense;
> +    bool tray_open;
>   };
>
>   static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
> @@ -829,6 +830,7 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>
>       if (s->qdev.type == TYPE_ROM&&  loej) {
>           bdrv_eject(s->bs, !start);
> +        s->tray_open = !start;
>       }
>   }
>
Acked-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 16/45] scsi-disk: " Markus Armbruster
@ 2011-08-04  6:14   ` Hannes Reinecke
  2011-08-04  6:39     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:07 PM, Markus Armbruster wrote:
> We already track it in BlockDriverState.  Just like tray open/close
> state, we should track it in the device models instead, because it's
> device state.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |    4 +++-
>   1 files changed, 3 insertions(+), 1 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index db72b86..8ca69f2 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -73,6 +73,7 @@ struct SCSIDiskState
>       char *serial;
>       SCSISense sense;
>       bool tray_open;
> +    bool tray_locked;
>   };
>
Hmm. Shouldn't we use a more generic 'flags' here and have bits for 
the individual tray states?
Feels like a waste to have individual values here.

>   static int scsi_handle_rw_error(SCSIDiskReq *r, int error, int type);
> @@ -678,7 +679,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p,
>           p[5] = 0xff; /* CD DA, DA accurate, RW supported,
>                           RW corrected, C2 errors, ISRC,
>                           UPC, Bar code */
> -        p[6] = 0x2d | (bdrv_is_locked(s->bs)? 2 : 0);
> +        p[6] = 0x2d | (s->tray_locked ? 2 : 0);
>           /* Locking supported, jumper present, eject, tray */
>           p[7] = 0; /* no volume&  mute control, no
>                        changer */
> @@ -896,6 +897,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>           scsi_disk_emulate_start_stop(r);
>           break;
>       case ALLOW_MEDIUM_REMOVAL:
> +        s->tray_locked = req->cmd.buf[4]&  1;
>           bdrv_set_locked(s->bs, req->cmd.buf[4]&  1);
>           break;
>       case READ_CAPACITY_10:

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
@ 2011-08-04  6:20   ` Hannes Reinecke
  2011-08-04  6:48     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:08 PM, Markus Armbruster wrote:
> Don't fail when tray is already open.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-bus.c  |   10 ++++++++++
>   hw/scsi-disk.c |   15 +++++++++++----
>   hw/scsi.h      |    4 ++++
>   3 files changed, 25 insertions(+), 4 deletions(-)
>
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index 0b0344c..1c5fe7f 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = {
>       .key = NOT_READY, .asc = 0x3a, .ascq = 0x00
>   };
>
> +/* LUN not ready, medium removal prevented */
> +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = {
> +    .key = NOT_READY, .asc = 0x53, .ascq = 0x00
> +};
> +
I would prefer to have the naming reversed,
eg NOT_READY_REMOVAL_PREVENTED
>   /* Hardware error, internal target failure */
>   const struct SCSISense sense_code_TARGET_FAILURE = {
>       .key = HARDWARE_ERROR, .asc = 0x44, .ascq = 0x00
> @@ -466,6 +471,11 @@ const struct SCSISense sense_code_LUN_NOT_SUPPORTED = {
>       .key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00
>   };
>
> +/* Illegal request, medium removal prevented */
> +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL = {
> +    .key = ILLEGAL_REQUEST, .asc = 0x53, .ascq = 0x00
> +};
> +
Same here: ILLEGAL_REQ_REMOVAL_PREVENTED

>   /* Command aborted, I/O process terminated */
>   const struct SCSISense sense_code_IO_ERROR = {
>       .key = ABORTED_COMMAND, .asc = 0x00, .ascq = 0x06
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 79d7737..19a1843 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -828,7 +828,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>       return toclen;
>   }
>
> -static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> +static int scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>   {
>       SCSIRequest *req =&r->req;
>       SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
> @@ -836,12 +836,17 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>       bool loej = req->cmd.buf[4]&  2;
>
>       if (s->qdev.type == TYPE_ROM&&  loej) {
> -        if (!start&&  s->tray_locked) {
> -            return;
> +        if (!start&&  !s->tray_open&&  s->tray_locked) {
> +            scsi_command_complete(r, CHECK_CONDITION,
> +                                  bdrv_is_inserted(s->bs)
> +                                  ? SENSE_CODE(MEDIUM_REMOVAL_PREVENTED_ILL)
> +                                  : SENSE_CODE(MEDIUM_REMOVAL_PREVENTED_NR));
> +            return -1;
>           }
>           bdrv_eject(s->bs, !start);
>           s->tray_open = !start;
>       }
> +    return 0;
>   }
>
>   static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
> @@ -897,7 +902,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>               goto illegal_request;
>           break;
>       case START_STOP:
> -        scsi_disk_emulate_start_stop(r);
> +        if (scsi_disk_emulate_start_stop(r)<  0) {
> +            return -1;
> +        }
>           break;
>       case ALLOW_MEDIUM_REMOVAL:
>           s->tray_locked = req->cmd.buf[4]&  1;
> diff --git a/hw/scsi.h b/hw/scsi.h
> index 6b15bbc..63442c6 100644
> --- a/hw/scsi.h
> +++ b/hw/scsi.h
> @@ -118,6 +118,8 @@ extern const struct SCSISense sense_code_NO_SENSE;
>   extern const struct SCSISense sense_code_LUN_NOT_READY;
>   /* LUN not ready, Medium not present */
>   extern const struct SCSISense sense_code_NO_MEDIUM;
> +/* LUN not readt, medium removal prevented */
> +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR;
LUN not ready.
Naming see above.

>   /* Hardware error, internal target failure */
>   extern const struct SCSISense sense_code_TARGET_FAILURE;
>   /* Illegal request, invalid command operation code */
> @@ -128,6 +130,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;
>   extern const struct SCSISense sense_code_INVALID_FIELD;
>   /* Illegal request, LUN not supported */
>   extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED;
> +/* Illegal request, medium removal prevented */
> +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL;
See above.
>   /* Command aborted, I/O process terminated */
>   extern const struct SCSISense sense_code_IO_ERROR;
>   /* Command aborted, I_T Nexus loss occurred */

Other than that it's okay.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-08-04  6:21   ` Hannes Reinecke
  0 siblings, 0 replies; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:21 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:08 PM, Markus Armbruster wrote:
> When scsi-cd is backed by a physical drive, we want the physical tray
> match the virtual one.  To that end, we call bdrv_eject() on guest's
> load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
> But we don't set the initial state on device model init.  Fix that.
>
> While there, also unlock on device model exit.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |    7 +++++++
>   1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 19a1843..f223de6 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1205,6 +1205,9 @@ static void scsi_destroy(SCSIDevice *dev)
>       SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
>
>       scsi_device_purge_requests(&s->qdev);
> +    if (s->qdev.type == TYPE_ROM) {
> +        bdrv_lock_medium(s->qdev.conf.bs, 0);
> +    }
>       blockdev_mark_auto_del(s->qdev.conf.bs);
>   }
>
> @@ -1265,6 +1268,10 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
>       s->qdev.type = scsi_type;
>       qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
>       bdrv_set_removable(s->bs, scsi_type == TYPE_ROM);
> +    if (scsi_type == TYPE_ROM) {
> +        bdrv_lock_medium(s->bs, s->tray_locked);
> +        bdrv_eject(s->bs, s->tray_open);
> +    }
>       add_boot_device_path(s->qdev.conf.bootindex,&dev->qdev, ",0");
>       return 0;
>   }
We could go not into metaphysical arguments that we're exposing the 
host state to the guest here. But I guess that would be taking 
things too far :-)

Acked-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 27/45] scsi-disk: " Markus Armbruster
@ 2011-08-04  6:23   ` Hannes Reinecke
  2011-08-04  6:45     ` Paolo Bonzini
  2011-08-04  9:57     ` Kevin Wolf
  2011-09-02 12:25   ` Kevin Wolf
  1 sibling, 2 replies; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:23 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/03/2011 03:08 PM, Markus Armbruster wrote:
> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
> versions.  We normally use subsections to avoid that.  Not possible
> here, because we don't have a section to begin with.  Too bad.
>
> Signed-off-by: Markus Armbruster<armbru@redhat.com>
> ---
>   hw/scsi-disk.c |   35 +++++++++++++++++++++++++++++++++++
>   1 files changed, 35 insertions(+), 0 deletions(-)
>
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index f223de6..04e0a77 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)
>       return scsi_initfn(dev, scsi_type);
>   }
>
> +static int scsi_cd_post_load(void *opaque, int version_id)
> +{
> +    SCSIDiskState *s = opaque;
> +
> +    bdrv_eject(s->bs, s->tray_open);
> +    bdrv_lock_medium(s->bs, s->tray_locked);
> +    return 0;
> +}
> +
> +static const VMStateDescription vmstate_scsi_cd = {
> +    .name = "scsi-cd",
> +    .version_id = 0,
> +    .minimum_version_id = 0,
> +    .post_load = scsi_cd_post_load,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_BOOL(tray_open, SCSIDiskState),
> +        VMSTATE_BOOL(tray_locked, SCSIDiskState),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +static const VMStateDescription vmstate_scsi_disk = {
> +    .name = "scsi-disk",
> +    .version_id = 0,
> +    .minimum_version_id = 0,
> +    .post_load = scsi_cd_post_load,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_BOOL(tray_open, SCSIDiskState),
> +        VMSTATE_BOOL(tray_locked, SCSIDiskState),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
And again; if we had just one 'flags' value we would have to save 
only one variable. And wouldn't need to touch this one for future 
states.

>   #define DEFINE_SCSI_DISK_PROPERTIES()                           \
>       DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf),          \
>       DEFINE_PROP_STRING("ver",  SCSIDiskState, version),         \
> @@ -1333,6 +1366,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
>           .qdev.fw_name = "disk",
>           .qdev.desc    = "virtual SCSI CD-ROM",
>           .qdev.size    = sizeof(SCSIDiskState),
> +        .qdev.vmsd    =&vmstate_scsi_cd,
>           .qdev.reset   = scsi_disk_reset,
>           .init         = scsi_cd_initfn,
>           .destroy      = scsi_destroy,
> @@ -1353,6 +1387,7 @@ static SCSIDeviceInfo scsi_disk_info[] = {
>           .qdev.fw_name = "disk",
>           .qdev.desc    = "virtual SCSI disk or CD-ROM (legacy)",
>           .qdev.size    = sizeof(SCSIDiskState),
> +        .qdev.vmsd    =&vmstate_scsi_disk,
>           .qdev.reset   = scsi_disk_reset,
>           .init         = scsi_disk_initfn,
>           .destroy      = scsi_destroy,

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-04  6:14   ` Hannes Reinecke
@ 2011-08-04  6:39     ` Markus Armbruster
  2011-08-04  6:46       ` Hannes Reinecke
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-04  6:39 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

Hannes Reinecke <hare@suse.de> writes:

> On 08/03/2011 03:07 PM, Markus Armbruster wrote:
>> We already track it in BlockDriverState.  Just like tray open/close
>> state, we should track it in the device models instead, because it's
>> device state.
>>
>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>> ---
>>   hw/scsi-disk.c |    4 +++-
>>   1 files changed, 3 insertions(+), 1 deletions(-)
>>
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index db72b86..8ca69f2 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -73,6 +73,7 @@ struct SCSIDiskState
>>       char *serial;
>>       SCSISense sense;
>>       bool tray_open;
>> +    bool tray_locked;
>>   };
>>
> Hmm. Shouldn't we use a more generic 'flags' here and have bits for
> the individual tray states?
> Feels like a waste to have individual values here.

On my system, struct SCSIDiskState is 248 bytes before my series (5
bytes of padding at the end), and 248 bytes after (3 bytes padding).  We
use one per disk.

I dare say switching to flags won't make a noticable difference in
memory use ;)

The bool members are easy to read and hard to screw up.

Flags can be nicer when you manipulate several of them together.

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-08-04  6:23   ` Hannes Reinecke
@ 2011-08-04  6:45     ` Paolo Bonzini
  2011-08-04  9:57     ` Kevin Wolf
  1 sibling, 0 replies; 105+ messages in thread
From: Paolo Bonzini @ 2011-08-04  6:45 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kwolf, stefano.stabellini, Markus Armbruster, quintela,
	qemu-devel, lcapitulino, amit.shah, hch

On 08/04/2011 08:23 AM, Hannes Reinecke wrote:
> On 08/03/2011 03:08 PM, Markus Armbruster wrote:
>> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
>> versions. We normally use subsections to avoid that. Not possible
>> here, because we don't have a section to begin with. Too bad.
>>
>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>> ---
>> hw/scsi-disk.c | 35 +++++++++++++++++++++++++++++++++++
>> 1 files changed, 35 insertions(+), 0 deletions(-)
>>
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index f223de6..04e0a77 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)
>> return scsi_initfn(dev, scsi_type);
>> }
>>
>> +static int scsi_cd_post_load(void *opaque, int version_id)
>> +{
>> + SCSIDiskState *s = opaque;
>> +
>> + bdrv_eject(s->bs, s->tray_open);
>> + bdrv_lock_medium(s->bs, s->tray_locked);
>> + return 0;
>> +}
>> +
>> +static const VMStateDescription vmstate_scsi_cd = {
>> + .name = "scsi-cd",
>> + .version_id = 0,
>> + .minimum_version_id = 0,
>> + .post_load = scsi_cd_post_load,
>> + .fields = (VMStateField[]) {
>> + VMSTATE_BOOL(tray_open, SCSIDiskState),
>> + VMSTATE_BOOL(tray_locked, SCSIDiskState),
>> + VMSTATE_END_OF_LIST()
>> + }
>> +};
>> +
>> +static const VMStateDescription vmstate_scsi_disk = {
>> + .name = "scsi-disk",
>> + .version_id = 0,
>> + .minimum_version_id = 0,
>> + .post_load = scsi_cd_post_load,
>> + .fields = (VMStateField[]) {
>> + VMSTATE_BOOL(tray_open, SCSIDiskState),
>> + VMSTATE_BOOL(tray_locked, SCSIDiskState),
>> + VMSTATE_END_OF_LIST()
>> + }
>> +};
>> +
> And again; if we had just one 'flags' value we would have to save only
> one variable. And wouldn't need to touch this one for future states.

Agreed, but we have time until 0.16 to fix this.  I plan to migrate more 
stuff (unit attention state, for one), I'll take care of this too.

Paolo

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

* Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-04  6:39     ` Markus Armbruster
@ 2011-08-04  6:46       ` Hannes Reinecke
  2011-08-04  7:25         ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  6:46 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/04/2011 08:39 AM, Markus Armbruster wrote:
> Hannes Reinecke<hare@suse.de>  writes:
>
>> On 08/03/2011 03:07 PM, Markus Armbruster wrote:
>>> We already track it in BlockDriverState.  Just like tray open/close
>>> state, we should track it in the device models instead, because it's
>>> device state.
>>>
>>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>>> ---
>>>    hw/scsi-disk.c |    4 +++-
>>>    1 files changed, 3 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>>> index db72b86..8ca69f2 100644
>>> --- a/hw/scsi-disk.c
>>> +++ b/hw/scsi-disk.c
>>> @@ -73,6 +73,7 @@ struct SCSIDiskState
>>>        char *serial;
>>>        SCSISense sense;
>>>        bool tray_open;
>>> +    bool tray_locked;
>>>    };
>>>
>> Hmm. Shouldn't we use a more generic 'flags' here and have bits for
>> the individual tray states?
>> Feels like a waste to have individual values here.
>
> On my system, struct SCSIDiskState is 248 bytes before my series (5
> bytes of padding at the end), and 248 bytes after (3 bytes padding).  We
> use one per disk.
>
> I dare say switching to flags won't make a noticable difference in
> memory use ;)
>
> The bool members are easy to read and hard to screw up.
>
> Flags can be nicer when you manipulate several of them together.

Well, but this just proves my point.
Each 'bool' variable takes up one byte, of which only one bit is 
used. Which qualifies as a waste of space.
But if that's okay with everyone and the general consensus on how to 
code flags in qemu, I'll shut up.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject
  2011-08-04  6:20   ` Hannes Reinecke
@ 2011-08-04  6:48     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-04  6:48 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

Hannes Reinecke <hare@suse.de> writes:

> On 08/03/2011 03:08 PM, Markus Armbruster wrote:
>> Don't fail when tray is already open.
>>
>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>> ---
>>   hw/scsi-bus.c  |   10 ++++++++++
>>   hw/scsi-disk.c |   15 +++++++++++----
>>   hw/scsi.h      |    4 ++++
>>   3 files changed, 25 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
>> index 0b0344c..1c5fe7f 100644
>> --- a/hw/scsi-bus.c
>> +++ b/hw/scsi-bus.c
>> @@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = {
>>       .key = NOT_READY, .asc = 0x3a, .ascq = 0x00
>>   };
>>
>> +/* LUN not ready, medium removal prevented */
>> +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = {
>> +    .key = NOT_READY, .asc = 0x53, .ascq = 0x00
>> +};
>> +
> I would prefer to have the naming reversed,
> eg NOT_READY_REMOVAL_PREVENTED

I don't care, so I'll do it your way :)

More of the same below, plus typos, all noted, thanks!

By the way, I hate having to define a struct SCSISense in another file
(and make up a name for it!) just to report sense.  And I hate the silly
macro trickery to mask the long names even more.

To make sense of

        scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(NO_MEDIUM));

I have to look up SENSE_CODE() in scsi.h:

    #define SENSE_CODE(x) sense_code_ ## x

which leads me to scsi-bus.c:

    /* LUN not ready, Medium not present */
    const struct SCSISense sense_code_NO_MEDIUM = {
        .key = NOT_READY, .asc = 0x3a, .ascq = 0x00
    };

Compare to IDE:

    ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);

[...]

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

* Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-04  6:46       ` Hannes Reinecke
@ 2011-08-04  7:25         ` Markus Armbruster
  2011-08-04  7:30           ` Hannes Reinecke
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-04  7:25 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

Hannes Reinecke <hare@suse.de> writes:

> On 08/04/2011 08:39 AM, Markus Armbruster wrote:
>> Hannes Reinecke<hare@suse.de>  writes:
>>
>>> On 08/03/2011 03:07 PM, Markus Armbruster wrote:
>>>> We already track it in BlockDriverState.  Just like tray open/close
>>>> state, we should track it in the device models instead, because it's
>>>> device state.
>>>>
>>>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>>>> ---
>>>>    hw/scsi-disk.c |    4 +++-
>>>>    1 files changed, 3 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>>>> index db72b86..8ca69f2 100644
>>>> --- a/hw/scsi-disk.c
>>>> +++ b/hw/scsi-disk.c
>>>> @@ -73,6 +73,7 @@ struct SCSIDiskState
>>>>        char *serial;
>>>>        SCSISense sense;
>>>>        bool tray_open;
>>>> +    bool tray_locked;
>>>>    };
>>>>
>>> Hmm. Shouldn't we use a more generic 'flags' here and have bits for
>>> the individual tray states?
>>> Feels like a waste to have individual values here.
>>
>> On my system, struct SCSIDiskState is 248 bytes before my series (5
>> bytes of padding at the end), and 248 bytes after (3 bytes padding).  We
>> use one per disk.
>>
>> I dare say switching to flags won't make a noticable difference in
>> memory use ;)
>>
>> The bool members are easy to read and hard to screw up.
>>
>> Flags can be nicer when you manipulate several of them together.
>
> Well, but this just proves my point.
> Each 'bool' variable takes up one byte, of which only one bit is
> used. Which qualifies as a waste of space.

A few data bytes per SCSI disk are a drop in the ocean.

Plus they're offset by the flags data word and the extra code bytes you
need to extract the bits.

> But if that's okay with everyone and the general consensus on how to
> code flags in qemu, I'll shut up.

It's a big series, and respinning it is work.  Can we sort such things
in followup patches?

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

* Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
  2011-08-04  7:25         ` Markus Armbruster
@ 2011-08-04  7:30           ` Hannes Reinecke
  0 siblings, 0 replies; 105+ messages in thread
From: Hannes Reinecke @ 2011-08-04  7:30 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, lcapitulino,
	amit.shah, hch

On 08/04/2011 09:25 AM, Markus Armbruster wrote:
> Hannes Reinecke<hare@suse.de>  writes:
>
>> On 08/04/2011 08:39 AM, Markus Armbruster wrote:
>>> Hannes Reinecke<hare@suse.de>   writes:
>>>
>>>> On 08/03/2011 03:07 PM, Markus Armbruster wrote:
>>>>> We already track it in BlockDriverState.  Just like tray open/close
>>>>> state, we should track it in the device models instead, because it's
>>>>> device state.
>>>>>
>>>>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>>>>> ---
>>>>>     hw/scsi-disk.c |    4 +++-
>>>>>     1 files changed, 3 insertions(+), 1 deletions(-)
>>>>>
>>>>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>>>>> index db72b86..8ca69f2 100644
>>>>> --- a/hw/scsi-disk.c
>>>>> +++ b/hw/scsi-disk.c
>>>>> @@ -73,6 +73,7 @@ struct SCSIDiskState
>>>>>         char *serial;
>>>>>         SCSISense sense;
>>>>>         bool tray_open;
>>>>> +    bool tray_locked;
>>>>>     };
>>>>>
>>>> Hmm. Shouldn't we use a more generic 'flags' here and have bits for
>>>> the individual tray states?
>>>> Feels like a waste to have individual values here.
>>>
>>> On my system, struct SCSIDiskState is 248 bytes before my series (5
>>> bytes of padding at the end), and 248 bytes after (3 bytes padding).  We
>>> use one per disk.
>>>
>>> I dare say switching to flags won't make a noticable difference in
>>> memory use ;)
>>>
>>> The bool members are easy to read and hard to screw up.
>>>
>>> Flags can be nicer when you manipulate several of them together.
>>
>> Well, but this just proves my point.
>> Each 'bool' variable takes up one byte, of which only one bit is
>> used. Which qualifies as a waste of space.
>
> A few data bytes per SCSI disk are a drop in the ocean.
>
> Plus they're offset by the flags data word and the extra code bytes you
> need to extract the bits.
>
>> But if that's okay with everyone and the general consensus on how to
>> code flags in qemu, I'll shut up.
>
> It's a big series, and respinning it is work.  Can we sort such things
> in followup patches?
As said, it's a minor point.
And as it's only a byte you are correct about a drop in the ocean.
And Paolo promised to keep it up in a further patch series. So I'll 
retract my objection.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke		      zSeries & Storage
hare@suse.de			      +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-08-04  6:23   ` Hannes Reinecke
  2011-08-04  6:45     ` Paolo Bonzini
@ 2011-08-04  9:57     ` Kevin Wolf
  1 sibling, 0 replies; 105+ messages in thread
From: Kevin Wolf @ 2011-08-04  9:57 UTC (permalink / raw)
  To: Hannes Reinecke
  Cc: quintela, qemu-devel, stefano.stabellini, Markus Armbruster,
	lcapitulino, amit.shah, hch

Am 04.08.2011 08:23, schrieb Hannes Reinecke:
> On 08/03/2011 03:08 PM, Markus Armbruster wrote:
>> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
>> versions.  We normally use subsections to avoid that.  Not possible
>> here, because we don't have a section to begin with.  Too bad.
>>
>> Signed-off-by: Markus Armbruster<armbru@redhat.com>
>> ---
>>   hw/scsi-disk.c |   35 +++++++++++++++++++++++++++++++++++
>>   1 files changed, 35 insertions(+), 0 deletions(-)
>>
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index f223de6..04e0a77 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)
>>       return scsi_initfn(dev, scsi_type);
>>   }
>>
>> +static int scsi_cd_post_load(void *opaque, int version_id)
>> +{
>> +    SCSIDiskState *s = opaque;
>> +
>> +    bdrv_eject(s->bs, s->tray_open);
>> +    bdrv_lock_medium(s->bs, s->tray_locked);
>> +    return 0;
>> +}
>> +
>> +static const VMStateDescription vmstate_scsi_cd = {
>> +    .name = "scsi-cd",
>> +    .version_id = 0,
>> +    .minimum_version_id = 0,
>> +    .post_load = scsi_cd_post_load,
>> +    .fields = (VMStateField[]) {
>> +        VMSTATE_BOOL(tray_open, SCSIDiskState),
>> +        VMSTATE_BOOL(tray_locked, SCSIDiskState),
>> +        VMSTATE_END_OF_LIST()
>> +    }
>> +};
>> +
>> +static const VMStateDescription vmstate_scsi_disk = {
>> +    .name = "scsi-disk",
>> +    .version_id = 0,
>> +    .minimum_version_id = 0,
>> +    .post_load = scsi_cd_post_load,
>> +    .fields = (VMStateField[]) {
>> +        VMSTATE_BOOL(tray_open, SCSIDiskState),
>> +        VMSTATE_BOOL(tray_locked, SCSIDiskState),
>> +        VMSTATE_END_OF_LIST()
>> +    }
>> +};
>> +
> And again; if we had just one 'flags' value we would have to save 
> only one variable. And wouldn't need to touch this one for future 
> states.

I think the policy is that you need to add a subsection anyway, even if
you just add a flag to an existing field.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (44 preceding siblings ...)
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 45/45] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
@ 2011-08-04 15:54 ` Avi Kivity
  2011-09-02 13:37 ` Kevin Wolf
  46 siblings, 0 replies; 105+ messages in thread
From: Avi Kivity @ 2011-08-04 15:54 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, quintela, qemu-devel, lcapitulino,
	hare, amit.shah, hch

On 08/03/2011 04:07 PM, Markus Armbruster wrote:
> * Both master and the block branch are broken for me by Avi's memory
>    API work (Avi reproduced, and claims to have a fix), so for testing
>    I had to rebase the block branch on an older master cde1a700 plus my
>    dependencies: some Xen work e3745602..679f4f8b, and some nand work
>    64de0e46..63efb1d9.

The problem is that the old-style 440FX PAM dislikes the new-style 
memory registration.  The fix is the conversion of 440FX to the memory 
API, which will arrive with the third batch of my patchset.

-- 
error compiling committee.c: too many arguments to function

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

* Re: [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit()
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
@ 2011-08-04 17:48   ` Luiz Capitulino
  2011-08-05  7:13     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Luiz Capitulino @ 2011-08-04 17:48 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

On Wed,  3 Aug 2011 15:07:59 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/internal.h |    1 +
>  hw/ide/qdev.c     |   12 ++++++++++++
>  2 files changed, 13 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
> index 3e56b45..0b0b8a7 100644
> --- a/hw/ide/internal.h
> +++ b/hw/ide/internal.h
> @@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);
>  struct IDEDeviceInfo {
>      DeviceInfo qdev;
>      ide_qdev_initfn init;
> +    ide_qdev_initfn exit;
>  };
>  
>  #define BM_STATUS_DMAING 0x01
> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
> index 6bd8d20..3b7b306 100644
> --- a/hw/ide/qdev.c
> +++ b/hw/ide/qdev.c
> @@ -91,9 +91,21 @@ err:
>      return -1;
>  }
>  
> +static int ide_qdev_exit(DeviceState *qdev)
> +{
> +    IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev);
> +    IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, qdev->info);
> +
> +    if (info->exit) {
> +        return info->exit(dev);
> +    }
> +    return 0;

return info->exit ? info->exit(dev) : 0;

> +}
> +
>  static void ide_qdev_register(IDEDeviceInfo *info)
>  {
>      info->qdev.init = ide_qdev_init;
> +    info->qdev.exit = ide_qdev_exit;
>      info->qdev.bus_info = &ide_bus_info;
>      qdev_register(&info->qdev);
>  }

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

* Re: [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable"
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable" Markus Armbruster
@ 2011-08-04 17:58   ` Luiz Capitulino
  0 siblings, 0 replies; 105+ messages in thread
From: Luiz Capitulino @ 2011-08-04 17:58 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

On Wed,  3 Aug 2011 15:08:14 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> BlockDriverState member removable is a confused mess.  It is true when
> an ide-cd, scsi-cd or floppy qdev is attached, or when the
> BlockDriverState was created with -drive if={floppy,sd} or -drive
> if={ide,scsi,xen,none},media=cdrom ("created removable"), except when
> an ide-hd, scsi-hd, scsi-generic or virtio-blk qdev is attached.
> 
> Three users remain:
> 
> 1. eject_device(), via bdrv_is_removable() uses it to determine
>    whether a block device can eject media.
> 
> 2. bdrv_info() is monitor command "info block".  QMP documentation
>    says "true if the device is removable, false otherwise".  From the
>    monitor user's point of view, the only sensible interpretation of
>    "is removable" is "can eject media with monitor commands eject and
>    change".
> 
> A block device can eject media unless a device is attached that
> doesn't support it.  Switch the two users over to new
> bdrv_dev_has_removable_media() that returns exactly that.
> 
> 3. bdrv_getlength() uses to suppress its length cache when media can
>    change (see commit 46a4e4e6).  Media change is either monitor
>    command change (updates the length cache), monitor command eject
>    (doesn't update the length cache, easily fixable), or physical
>    media change (invalidates length cache, not so easily fixable).
> 
> I'm refraining from improving anything here, because this series is
> long enough already.  Instead, I simply switch it over to
> bdrv_dev_has_removable_media() as well.
> 
> This changes the behavior of the length cache and of monitor commands
> eject and change in two cases:
> 
> a. drive not created removable, no device attached
> 
>    The commit makes the drive removable, and defeats the length cache.
> 
>    Example: -drive if=none
> 
> b. drive created removable, but the attached drive is non-removable,
>    and doesn't call bdrv_set_removable(..., 0) (most devices don't)
> 
>    The commit makes the drive non-removable, and enables the length
>    cache.
> 
>    Example: -drive if=xen,media=cdrom -M xenpv
> 
>    The other non-removable devices that don't call
>    bdrv_set_removable() can't currently use a drive created removable,
>    either because they aren't qdevified, or because they lack a drive
>    property.  Won't stay that way.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good to me.

> ---
>  block.c        |   18 +++++++++++-------
>  block.h        |    3 ++-
>  blockdev.c     |    2 +-
>  hw/scsi-disk.c |    5 +++++
>  4 files changed, 19 insertions(+), 9 deletions(-)
> 
> diff --git a/block.c b/block.c
> index b3a5ee7..87a3ef3 100644
> --- a/block.c
> +++ b/block.c
> @@ -775,6 +775,9 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
>  {
>      bs->dev_ops = ops;
>      bs->dev_opaque = opaque;
> +    if (bdrv_dev_has_removable_media(bs) && bs == bs_snapshots) {
> +        bs_snapshots = NULL;
> +    }
>  }
>  
>  static void bdrv_dev_change_media_cb(BlockDriverState *bs)
> @@ -784,6 +787,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
>      }
>  }
>  
> +bool bdrv_dev_has_removable_media(BlockDriverState *bs)
> +{
> +    return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
> +}
> +
>  static void bdrv_dev_resize_cb(BlockDriverState *bs)
>  {
>      if (bs->dev_ops && bs->dev_ops->resize_cb) {
> @@ -1289,7 +1297,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)
>      if (!drv)
>          return -ENOMEDIUM;
>  
> -    if (bs->growable || bs->removable) {
> +    if (bs->growable || bdrv_dev_has_removable_media(bs)) {
>          if (drv->bdrv_getlength) {
>              return drv->bdrv_getlength(bs);
>          }
> @@ -1574,11 +1582,6 @@ void bdrv_set_removable(BlockDriverState *bs, int removable)
>      }
>  }
>  
> -int bdrv_is_removable(BlockDriverState *bs)
> -{
> -    return bs->removable;
> -}
> -
>  int bdrv_is_read_only(BlockDriverState *bs)
>  {
>      return bs->read_only;
> @@ -1857,7 +1860,8 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
>  
>          bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
>                                      "'removable': %i, 'locked': %i }",
> -                                    bs->device_name, bs->removable,
> +                                    bs->device_name,
> +                                    bdrv_dev_has_removable_media(bs),
>                                      bdrv_dev_is_medium_locked(bs));
>  
>          if (bs->drv) {
> diff --git a/block.h b/block.h
> index 4a6b957..fd8f1d1 100644
> --- a/block.h
> +++ b/block.h
> @@ -34,6 +34,7 @@ typedef struct BlockDevOps {
>       * Runs when virtual media changed (monitor commands eject, change)
>       * Beware: doesn't run when a host device's physical media
>       * changes.  Sure would be useful if it did.
> +     * Device models with removable media must implement this callback.
>       */
>      void (*change_media_cb)(void *opaque);
>      /*
> @@ -99,6 +100,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);
>  void *bdrv_get_attached_dev(BlockDriverState *bs);
>  void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
>                        void *opaque);
> +bool bdrv_dev_has_removable_media(BlockDriverState *bs);
>  bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
>  int bdrv_read(BlockDriverState *bs, int64_t sector_num,
>                uint8_t *buf, int nb_sectors);
> @@ -206,7 +208,6 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
>                         BlockErrorAction on_write_error);
>  BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
>  void bdrv_set_removable(BlockDriverState *bs, int removable);
> -int bdrv_is_removable(BlockDriverState *bs);
>  int bdrv_is_read_only(BlockDriverState *bs);
>  int bdrv_is_sg(BlockDriverState *bs);
>  int bdrv_enable_write_cache(BlockDriverState *bs);
> diff --git a/blockdev.c b/blockdev.c
> index bb1f8c4..bcddfc0 100644
> --- a/blockdev.c
> +++ b/blockdev.c
> @@ -645,7 +645,7 @@ out:
>  
>  static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
>  {
> -    if (!bdrv_is_removable(bs)) {
> +    if (!bdrv_dev_has_removable_media(bs)) {
>          qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
>          return -1;
>      }
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 04e0a77..a30063a 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1211,12 +1211,17 @@ static void scsi_destroy(SCSIDevice *dev)
>      blockdev_mark_auto_del(s->qdev.conf.bs);
>  }
>  
> +static void scsi_cd_change_media_cb(void *opaque)
> +{
> +}
> +
>  static bool scsi_cd_is_medium_locked(void *opaque)
>  {
>      return ((SCSIDiskState *)opaque)->tray_locked;
>  }
>  
>  static const BlockDevOps scsi_cd_block_ops = {
> +    .change_media_cb = scsi_cd_change_media_cb,
>      .is_medium_locked = scsi_cd_is_medium_locked,
>  };
>  

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

* Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block Markus Armbruster
@ 2011-08-04 18:05   ` Luiz Capitulino
  2011-09-02 13:04   ` Kevin Wolf
  1 sibling, 0 replies; 105+ messages in thread
From: Luiz Capitulino @ 2011-08-04 18:05 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

On Wed,  3 Aug 2011 15:08:16 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Need to ask the device, so this requires new BlockDevOps member
> is_medium_ejected().
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good to me.

> ---
>  block.c         |   17 +++++++++++++++--
>  block.h         |    6 ++++++
>  hw/ide/core.c   |    6 ++++++
>  hw/scsi-disk.c  |    6 ++++++
>  qmp-commands.hx |    2 ++
>  5 files changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/block.c b/block.c
> index b488b21..fed0c16 100644
> --- a/block.c
> +++ b/block.c
> @@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs)
>      return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb);
>  }
>  
> +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs)
> +{
> +    if (bs->dev_ops && bs->dev_ops->is_medium_ejected) {
> +        return bs->dev_ops->is_medium_ejected(bs->dev_opaque);
> +    }
> +    return false;
> +}
> +
>  static void bdrv_dev_resize_cb(BlockDriverState *bs)
>  {
>      if (bs->dev_ops && bs->dev_ops->resize_cb) {
> @@ -1813,8 +1821,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque)
>  
>      if (qdict_get_bool(bs_dict, "removable")) {
>          monitor_printf(mon, " locked=%d", qdict_get_bool(bs_dict, "locked"));
> +        monitor_printf(mon, " ejected=%d", qdict_get_bool(bs_dict, "ejected"));
>      }
> -
>      if (qdict_haskey(bs_dict, "inserted")) {
>          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
>  
> @@ -1849,16 +1857,21 @@ void bdrv_info(Monitor *mon, QObject **ret_data)
>  
>      QTAILQ_FOREACH(bs, &bdrv_states, list) {
>          QObject *bs_obj;
> +        QDict *bs_dict;
>  
>          bs_obj = qobject_from_jsonf("{ 'device': %s, 'type': 'unknown', "
>                                      "'removable': %i, 'locked': %i }",
>                                      bs->device_name,
>                                      bdrv_dev_has_removable_media(bs),
>                                      bdrv_dev_is_medium_locked(bs));
> +        bs_dict = qobject_to_qdict(bs_obj);
>  
> +        if (bdrv_dev_has_removable_media(bs)) {
> +            qdict_put(bs_dict, "ejected",
> +                      qbool_from_int(bdrv_dev_is_medium_ejected(bs)));
> +        }
>          if (bs->drv) {
>              QObject *obj;
> -            QDict *bs_dict = qobject_to_qdict(bs_obj);
>  
>              obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, "
>                                       "'encrypted': %i }",
> diff --git a/block.h b/block.h
> index 6b11be5..fdb7680 100644
> --- a/block.h
> +++ b/block.h
> @@ -38,6 +38,11 @@ typedef struct BlockDevOps {
>       */
>      void (*change_media_cb)(void *opaque);
>      /*
> +     * Is medium ejected from the device?
> +     * Device models calling bdrv_eject() should implement this.
> +     */
> +    bool (*is_medium_ejected)(void *opaque);
> +    /*
>       * Is the virtual medium locked into the device?
>       * Device models should implement this only when device has such a
>       * lock.
> @@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs);
>  void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
>                        void *opaque);
>  bool bdrv_dev_has_removable_media(BlockDriverState *bs);
> +bool bdrv_dev_is_medium_ejected(BlockDriverState *bs);
>  bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
>  int bdrv_read(BlockDriverState *bs, int64_t sector_num,
>                uint8_t *buf, int nb_sectors);
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index c82d8a1..47dd81c 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -1769,6 +1769,11 @@ void ide_bus_reset(IDEBus *bus)
>      bus->dma->ops->reset(bus->dma);
>  }
>  
> +static bool ide_cd_medium_ejected(void *opaque)
> +{
> +    return ((IDEState *)opaque)->tray_open;
> +}
> +
>  static bool ide_cd_is_medium_locked(void *opaque)
>  {
>      return ((IDEState *)opaque)->tray_locked;
> @@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque)
>  
>  static const BlockDevOps ide_cd_block_ops = {
>      .change_media_cb = ide_cd_change_cb,
> +    .is_medium_ejected = ide_cd_medium_ejected,
>      .is_medium_locked = ide_cd_is_medium_locked,
>  };
>  
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index a7a70bd..3ebcee4 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque)
>  {
>  }
>  
> +static bool scsi_cd_is_medium_ejected(void *opaque)
> +{
> +    return ((SCSIDiskState *)opaque)->tray_open;
> +}
> +
>  static bool scsi_cd_is_medium_locked(void *opaque)
>  {
>      return ((SCSIDiskState *)opaque)->tray_locked;
> @@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque)
>  
>  static const BlockDevOps scsi_cd_block_ops = {
>      .change_media_cb = scsi_cd_change_media_cb,
> +    .is_medium_ejected = scsi_cd_is_medium_ejected,
>      .is_medium_locked = scsi_cd_is_medium_locked,
>  };
>  
> diff --git a/qmp-commands.hx b/qmp-commands.hx
> index 03f67da..b0447f1 100644
> --- a/qmp-commands.hx
> +++ b/qmp-commands.hx
> @@ -1131,6 +1131,8 @@ Each json-object contain the following:
>           - Possible values: "unknown"
>  - "removable": true if the device is removable, false otherwise (json-bool)
>  - "locked": true if the device is locked, false otherwise (json-bool)
> +- "ejected": only present if removable, true if the device ejected its
> +             media (json-bool)
>  - "inserted": only present if the device is inserted, it is a json-object
>     containing the following:
>           - "file": device file name (json-string)

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

* Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
@ 2011-08-04 18:10   ` Luiz Capitulino
  2011-08-04 18:22     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Luiz Capitulino @ 2011-08-04 18:10 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

On Wed,  3 Aug 2011 15:08:19 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Device models should be able to use it without an unclean include of
> block_int.h.

Nitpick: I'd do the prototype move after patch 38/45 and include the
block_int.h removal in the patch you're trimming block_int.h includes.

> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block.h     |    2 ++
>  block_int.h |    2 --
>  hw/sd.c     |    1 -
>  3 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/block.h b/block.h
> index a8aca5f..3dfd2a4 100644
> --- a/block.h
> +++ b/block.h
> @@ -269,6 +269,8 @@ int bdrv_img_create(const char *filename, const char *fmt,
>                      const char *base_filename, const char *base_fmt,
>                      char *options, uint64_t img_size, int flags);
>  
> +void *qemu_blockalign(BlockDriverState *bs, size_t size);
> +
>  #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
>  
>  void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable);
> diff --git a/block_int.h b/block_int.h
> index e5385ba..9a59784 100644
> --- a/block_int.h
> +++ b/block_int.h
> @@ -221,8 +221,6 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
>                     BlockDriverCompletionFunc *cb, void *opaque);
>  void qemu_aio_release(void *p);
>  
> -void *qemu_blockalign(BlockDriverState *bs, size_t size);
> -
>  #ifdef _WIN32
>  int is_windows_drive(const char *filename);
>  #endif
> diff --git a/hw/sd.c b/hw/sd.c
> index 24f4af8..3bcfe6a 100644
> --- a/hw/sd.c
> +++ b/hw/sd.c
> @@ -31,7 +31,6 @@
>  
>  #include "hw.h"
>  #include "block.h"
> -#include "block_int.h"
>  #include "sd.h"
>  
>  //#define DEBUG_SD 1

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

* Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-08-04 18:10   ` Luiz Capitulino
@ 2011-08-04 18:22     ` Markus Armbruster
  2011-08-04 18:28       ` Luiz Capitulino
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-08-04 18:22 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Wed,  3 Aug 2011 15:08:19 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> Device models should be able to use it without an unclean include of
>> block_int.h.
>
> Nitpick: I'd do the prototype move after patch 38/45 and include the
> block_int.h removal in the patch you're trimming block_int.h includes.

Care to explain why?

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

* Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-08-04 18:22     ` Markus Armbruster
@ 2011-08-04 18:28       ` Luiz Capitulino
  0 siblings, 0 replies; 105+ messages in thread
From: Luiz Capitulino @ 2011-08-04 18:28 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

On Thu, 04 Aug 2011 20:22:15 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Wed,  3 Aug 2011 15:08:19 +0200
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> Device models should be able to use it without an unclean include of
> >> block_int.h.
> >
> > Nitpick: I'd do the prototype move after patch 38/45 and include the
> > block_int.h removal in the patch you're trimming block_int.h includes.
> 
> Care to explain why?

Seems more logical to me to solve the dependencies one by one and then
drop the includes in one shot. Maybe could even be done in a different
series.

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

* Re: [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit()
  2011-08-04 17:48   ` Luiz Capitulino
@ 2011-08-05  7:13     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-08-05  7:13 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: kwolf, quintela, stefano.stabellini, qemu-devel, hare, amit.shah, hch

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Wed,  3 Aug 2011 15:07:59 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/internal.h |    1 +
>>  hw/ide/qdev.c     |   12 ++++++++++++
>>  2 files changed, 13 insertions(+), 0 deletions(-)
>> 
>> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
>> index 3e56b45..0b0b8a7 100644
>> --- a/hw/ide/internal.h
>> +++ b/hw/ide/internal.h
>> @@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);
>>  struct IDEDeviceInfo {
>>      DeviceInfo qdev;
>>      ide_qdev_initfn init;
>> +    ide_qdev_initfn exit;
>>  };
>>  
>>  #define BM_STATUS_DMAING 0x01
>> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
>> index 6bd8d20..3b7b306 100644
>> --- a/hw/ide/qdev.c
>> +++ b/hw/ide/qdev.c
>> @@ -91,9 +91,21 @@ err:
>>      return -1;
>>  }
>>  
>> +static int ide_qdev_exit(DeviceState *qdev)
>> +{
>> +    IDEDevice *dev = DO_UPCAST(IDEDevice, qdev, qdev);
>> +    IDEDeviceInfo *info = DO_UPCAST(IDEDeviceInfo, qdev, qdev->info);
>> +
>> +    if (info->exit) {
>> +        return info->exit(dev);
>> +    }
>> +    return 0;
>
> return info->exit ? info->exit(dev) : 0;

Matter of taste.  I'll consider it when I respin.

>
>> +}
>> +
>>  static void ide_qdev_register(IDEDeviceInfo *info)
>>  {
>>      info->qdev.init = ide_qdev_init;
>> +    info->qdev.exit = ide_qdev_exit;
>>      info->qdev.bus_info = &ide_bus_info;
>>      qdev_register(&info->qdev);
>>  }

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

* Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
  2011-08-03 16:53   ` Blue Swirl
  2011-08-03 17:15     ` Markus Armbruster
@ 2011-09-02 10:08     ` Kevin Wolf
  2011-09-02 14:43       ` Markus Armbruster
  1 sibling, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 10:08 UTC (permalink / raw)
  To: Blue Swirl
  Cc: quintela, qemu-devel, stefano.stabellini, Markus Armbruster,
	lcapitulino, hare, amit.shah, hch

Am 03.08.2011 18:53, schrieb Blue Swirl:
> On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster <armbru@redhat.com> wrote:
>> No functional change.
>>
>> It would be nice to have handler functions in the table, like commit
>> e1a064f9 did for ATAPI.  Left for another day.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/core.c |  104 +++++++++++++++++++++++++++++++++++++++++++--------------
>>  1 files changed, 79 insertions(+), 25 deletions(-)
>>
>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>> index 1c4dc2f..a25c175 100644
>> --- a/hw/ide/core.c
>> +++ b/hw/ide/core.c
>> @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>>     }
>>  }
>>
>> +#define HD_OK (1u << IDE_HD)
>> +#define CD_OK (1u << IDE_CD)
>> +#define CFA_OK (1u << IDE_CFATA)
>> +#define HD_CFA_OK (HD_OK | CFA_OK)
>> +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
>> +
>> +/* See ACS-2 T13/2015-D Table B.2 Command codes */
>> +uint8_t ide_cmd_table[0x100] = {
> 
> Missing 'static'.

And const, while we're at it.

>> +    /* NOP not implemented, mandatory for CD */
>> +    [CFA_REQ_EXT_ERROR_CODE]            = CFA_OK,
>> +    [WIN_DSM]                           = ALL_OK,
>> +    [WIN_DEVICE_RESET]                  = CD_OK,
>> +    [WIN_RECAL]                         = ALL_OK,
>> +    [WIN_READ]                          = ALL_OK,
>> +    [WIN_READ_ONCE]                     = ALL_OK,
>> +    [WIN_READ_EXT]                      = ALL_OK,
>> +    [WIN_READDMA_EXT]                   = ALL_OK,
>> +    [WIN_READ_NATIVE_MAX_EXT]           = ALL_OK,
>> +    [WIN_MULTREAD_EXT]                  = ALL_OK,
>> +    [WIN_WRITE]                         = ALL_OK,
>> +    [WIN_WRITE_ONCE]                    = ALL_OK,
>> +    [WIN_WRITE_EXT]                     = ALL_OK,
>> +    [WIN_WRITEDMA_EXT]                  = ALL_OK,
>> +    [CFA_WRITE_SECT_WO_ERASE]           = ALL_OK,
>> +    [WIN_MULTWRITE_EXT]                 = ALL_OK,
>> +    [WIN_WRITE_VERIFY]                  = ALL_OK,
>> +    [WIN_VERIFY]                        = ALL_OK,
>> +    [WIN_VERIFY_ONCE]                   = ALL_OK,
>> +    [WIN_VERIFY_EXT]                    = ALL_OK,
>> +    [WIN_SEEK]                          = HD_CFA_OK,
>> +    [CFA_TRANSLATE_SECTOR]              = CFA_OK,
>> +    [WIN_DIAGNOSE]                      = ALL_OK,
>> +    [WIN_SPECIFY]                       = ALL_OK,
>> +    [WIN_STANDBYNOW2]                   = ALL_OK,
>> +    [WIN_IDLEIMMEDIATE2]                = ALL_OK,
>> +    [WIN_STANDBY2]                      = ALL_OK,
>> +    [WIN_SETIDLE2]                      = ALL_OK,
>> +    [WIN_CHECKPOWERMODE2]               = ALL_OK,
>> +    [WIN_SLEEPNOW2]                     = ALL_OK,
>> +    [WIN_PACKETCMD]                     = CD_OK,
>> +    [WIN_PIDENTIFY]                     = CD_OK,
>> +    [WIN_SMART]                         = HD_CFA_OK,
>> +    [CFA_ACCESS_METADATA_STORAGE]       = CFA_OK,
>> +    [CFA_ERASE_SECTORS]                 = CFA_OK,
>> +    [WIN_MULTREAD]                      = ALL_OK,
>> +    [WIN_MULTWRITE]                     = ALL_OK,
>> +    [WIN_SETMULT]                       = ALL_OK,
>> +    [WIN_READDMA]                       = ALL_OK,
>> +    [WIN_READDMA_ONCE]                  = ALL_OK,
>> +    [WIN_WRITEDMA]                      = ALL_OK,
>> +    [WIN_WRITEDMA_ONCE]                 = ALL_OK,
>> +    [CFA_WRITE_MULTI_WO_ERASE]          = ALL_OK,
>> +    [WIN_STANDBYNOW1]                   = ALL_OK,
>> +    [WIN_IDLEIMMEDIATE]                 = ALL_OK,
>> +    [WIN_STANDBY]                       = ALL_OK,
>> +    [WIN_SETIDLE1]                      = ALL_OK,
>> +    [WIN_CHECKPOWERMODE1]               = ALL_OK,
>> +    [WIN_SLEEPNOW1]                     = ALL_OK,
>> +    [WIN_FLUSH_CACHE]                   = ALL_OK,
>> +    [WIN_FLUSH_CACHE_EXT]               = ALL_OK,
>> +    [WIN_IDENTIFY]                      = ALL_OK,
>> +    [WIN_SETFEATURES]                   = ALL_OK,
>> +    [IBM_SENSE_CONDITION]               = CFA_OK,
>> +    [CFA_WEAR_LEVEL]                    = CFA_OK,
>> +    [WIN_READ_NATIVE_MAX]               = ALL_OK,
>> +};
>> +
>> +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
>> +{
>> +    return cmd <= 0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind));
>> +}

Doesn't cmd < ARRAY_SIZE(ide_cmd_table) better describe what you want?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
@ 2011-09-02 10:20   ` Kevin Wolf
  2011-09-02 14:47     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 10:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> "eject" is misleading; it means "eject" when start is clear, but
> "load" when start is set.  Rename to loej, because that's how MMC-5
> calls it, in section 6.40.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/atapi.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
> index fe2fb0b..17fbef8 100644
> --- a/hw/ide/atapi.c
> +++ b/hw/ide/atapi.c
> @@ -892,11 +892,11 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
>  
>  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
>  {
> -    int start, eject, sense, err = 0;
> -    start = buf[4] & 1;
> -    eject = (buf[4] >> 1) & 1;
> +    int sense, err = 0;
> +    bool start = buf[4] & 1;
> +    bool loej = buf[4] & 2;
>  
> -    if (eject) {
> +    if (loej) {
>          err = bdrv_eject(s->bs, !start);
>      }
>  

"eject" has the advantage that I immediately know that it's something to
do with the tray. "loej" on the other hand is a sequence of four random
characters. Maybe add a comment?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state Markus Armbruster
@ 2011-09-02 10:23   ` Kevin Wolf
  2011-09-02 14:51     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 10:23 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> We already track it in BlockDriverState since commit 4be9762a.  As
> discussed in that commit's message, we should track it in the device
> device models instead, because it's device state.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/atapi.c    |    6 +++++-
>  hw/ide/internal.h |    1 +
>  2 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
> index 17fbef8..96f7c31 100644
> --- a/hw/ide/atapi.c
> +++ b/hw/ide/atapi.c
> @@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,
>      uint8_t event_code, media_status;
>  
>      media_status = 0;
> -    if (s->bs->tray_open) {
> +    if (s->tray_open) {
>          media_status = MS_TRAY_OPEN;
>      } else if (bdrv_is_inserted(s->bs)) {
>          media_status = MS_MEDIA_PRESENT;
> @@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
>          ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
>          break;
>      }
> +
> +    if (loej && !err) {
> +        s->tray_open = !start;
> +    }
>  }
>  
>  static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
> index 46e84fa..cd8e977 100644
> --- a/hw/ide/internal.h
> +++ b/hw/ide/internal.h
> @@ -442,6 +442,7 @@ struct IDEState {
>      struct unreported_events events;
>      uint8_t sense_key;
>      uint8_t asc;
> +    bool tray_open;
>      uint8_t cdrom_changed;
>      int packet_transfer_size;
>      int elementary_transfer_size;

Probably needs to be migrated.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
  2011-08-04  6:12   ` Hannes Reinecke
@ 2011-09-02 10:26   ` Kevin Wolf
  2011-09-02 14:55     ` Markus Armbruster
  1 sibling, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 10:26 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/scsi-disk.c |   17 +++++++++++++----
>  1 files changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index fa198f9..d549cb7 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>      return toclen;
>  }
>  
> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> +{
> +    SCSIRequest *req = &r->req;
> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
> +    bool start = req->cmd.buf[4] & 1;
> +    bool loej = req->cmd.buf[4] & 2;
> +
> +    if (s->qdev.type == TYPE_ROM && loej) {
> +        bdrv_eject(s->bs, !start);
> +    }
> +}
> +
>  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>  {
>      SCSIRequest *req = &r->req;
> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>              goto illegal_request;
>          break;
>      case START_STOP:
> -        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
> -            /* load/eject medium */

So here we actually had the comment before. Can we retain it?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state Markus Armbruster
@ 2011-09-02 11:02   ` Kevin Wolf
  2011-09-02 14:56     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 11:02 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> We already track it in BlockDriverState.  Just like tray open/close
> state, we should track it in the device models instead, because it's
> device state.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/atapi.c    |    4 +++-
>  hw/ide/internal.h |    1 +
>  2 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
> index 08e1a7a..237657f 100644
> --- a/hw/ide/atapi.c
> +++ b/hw/ide/atapi.c
> @@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
>              buf[12] = 0x71;
>              buf[13] = 3 << 5;
>              buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
> -            if (bdrv_is_locked(s->bs))
> +            if (s->tray_locked) {
>                  buf[6] |= 1 << 1;
> +            }
>              buf[15] = 0x00;
>              cpu_to_ube16(&buf[16], 706);
>              buf[18] = 0;
> @@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
>  
>  static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
>  {
> +    s->tray_locked = buf[4] & 1;
>      bdrv_set_locked(s->bs, buf[4] & 1);
>      ide_atapi_cmd_ok(s);
>  }
> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
> index cd8e977..3e56b45 100644
> --- a/hw/ide/internal.h
> +++ b/hw/ide/internal.h
> @@ -443,6 +443,7 @@ struct IDEState {
>      uint8_t sense_key;
>      uint8_t asc;
>      bool tray_open;
> +    bool tray_locked;
>      uint8_t cdrom_changed;
>      int packet_transfer_size;
>      int elementary_transfer_size;

Same as tray open/close status: Needs to be migrated.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()
  2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
@ 2011-09-02 11:30   ` Kevin Wolf
  2011-09-02 14:58     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 11:30 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block.c           |    8 ++++----
>  block.h           |    2 +-
>  block/raw-posix.c |    8 ++++----
>  block/raw.c       |    6 +++---
>  block_int.h       |    2 +-
>  hw/ide/atapi.c    |    2 +-
>  hw/scsi-disk.c    |    2 +-
>  trace-events      |    2 +-
>  8 files changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 3a8a4e6..10c1b1a 100644
> --- a/block.c
> +++ b/block.c
> @@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
>   * Lock or unlock the media (if it is locked, the user won't be able
>   * to eject it manually).
>   */
> -void bdrv_set_locked(BlockDriverState *bs, int locked)
> +void bdrv_lock_medium(BlockDriverState *bs, int locked)

Make locked a bool while we're changing the signature everywhere?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-09-02 12:07   ` Kevin Wolf
  2011-09-02 15:19     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 12:07 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> When ide-cd is backed by a physical drive, we want the physical tray
> match the virtual one.  To that end, we call bdrv_eject() on guest's
> load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
> But we don't set the initial state on device model init.  Fix that.
> 
> While there, also unlock on device model exit.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/core.c |    4 ++++
>  hw/ide/qdev.c |   18 ++++++++++++++++++
>  2 files changed, 22 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 5bcc857..d8b1d43 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
>  
>      ide_reset(s);
>      bdrv_set_removable(bs, s->drive_kind == IDE_CD);
> +    if (s->drive_kind == IDE_CD) {
> +        bdrv_lock_medium(bs, s->tray_locked);
> +        bdrv_eject(bs, s->tray_open);
> +    }
>      return 0;
>  }
>  
> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
> index 3b7b306..bc2f426 100644
> --- a/hw/ide/qdev.c
> +++ b/hw/ide/qdev.c
> @@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)
>      return ide_dev_initfn(dev, IDE_CD);
>  }
>  
> +static int ide_cd_exitfn(IDEDevice *dev)
> +{
> +    bdrv_lock_medium(dev->conf.bs, 0);
> +    return 0;
> +}
> +
>  static int ide_drive_initfn(IDEDevice *dev)
>  {
>      DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
> @@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)
>      return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
>  }
>  
> +static int ide_drive_exitfn(IDEDevice *dev)
> +{
> +    DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
> +
> +    if (dinfo->media_cd) {
> +        return ide_cd_exitfn(dev);
> +    }

Is dinfo->media_cd guaranteed to be the same as s->drive_kind? I
wouldn't have expected this to be true at least since the introduction
of ide-hd/cd.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration Markus Armbruster
@ 2011-09-02 12:20   ` Kevin Wolf
  2011-09-02 12:35     ` Paolo Bonzini
  2011-09-02 15:20     ` Markus Armbruster
  0 siblings, 2 replies; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 12:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, Paolo Bonzini, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> Use a subsection, so that migration to older version still works,
> provided the tray is closed and unlocked.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Ah, here is the migration part. The state wasn't migrated before, so not
doing it in patch 10 doesn't break anything. I would still prefer to add
migration in the same patch that adds the fields.

You could just move the subsection itself and keep the post_load part
here if it doesn't fit naturally in one of the other patches of the series.

On another note, have our subsections been fixed meanwhile? If not,
increasing the version number instead might be the right choice. Paolo?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 27/45] scsi-disk: " Markus Armbruster
  2011-08-04  6:23   ` Hannes Reinecke
@ 2011-09-02 12:25   ` Kevin Wolf
  2011-09-02 15:35     ` Markus Armbruster
  1 sibling, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 12:25 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
> versions.  We normally use subsections to avoid that.  Not possible
> here, because we don't have a section to begin with.  Too bad.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

A more logical approach would be to add migration support to SCSI first.
I guess adding .unmigratable = 1 makes more sense at the moment.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-09-02 12:20   ` Kevin Wolf
@ 2011-09-02 12:35     ` Paolo Bonzini
  2011-09-02 15:22       ` Markus Armbruster
  2011-09-02 15:20     ` Markus Armbruster
  1 sibling, 1 reply; 105+ messages in thread
From: Paolo Bonzini @ 2011-09-02 12:35 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: quintela, qemu-devel, stefano.stabellini, Markus Armbruster,
	lcapitulino, hare, amit.shah, hch

On 09/02/2011 02:20 PM, Kevin Wolf wrote:
> Ah, here is the migration part. The state wasn't migrated before, so not
> doing it in patch 10 doesn't break anything. I would still prefer to add
> migration in the same patch that adds the fields.
>
> You could just move the subsection itself and keep the post_load part
> here if it doesn't fit naturally in one of the other patches of the series.
>
> On another note, have our subsections been fixed meanwhile? If not,
> increasing the version number instead might be the right choice. Paolo?

No, they haven't, but there's hope they will before 1.0.

Paolo

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

* Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block Markus Armbruster
  2011-08-04 18:05   ` Luiz Capitulino
@ 2011-09-02 13:04   ` Kevin Wolf
  2011-09-02 15:29     ` Markus Armbruster
  1 sibling, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 13:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> Need to ask the device, so this requires new BlockDevOps member
> is_medium_ejected().
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

I find the name confusing. "medium is ejected" seems to mean "tray is
open". It isn't obvious that "tray is closed, but no medium is inserted"
is not "medium is ejected".

Why not call it tray_open like in the devices?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment() Markus Armbruster
@ 2011-09-02 13:13   ` Kevin Wolf
  2011-09-02 15:30     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 13:13 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> Device models should be able to set it without an unclean include of
> block_int.h.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block.c         |    6 ++++--
>  block.h         |    1 +
>  hw/ide/core.c   |    2 +-
>  hw/scsi-disk.c  |    2 +-
>  hw/virtio-blk.c |    3 +--
>  5 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/block.c b/block.c
> index fed0c16..67d9429 100644
> --- a/block.c
> +++ b/block.c
> @@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
>      bs->encrypted = 0;
>      bs->valid_key = 0;
>      bs->open_flags = flags;
> -    /* buffer_alignment defaulted to 512, drivers can change this value */
>      bs->buffer_alignment = 512;

This comment is still right.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach Markus Armbruster
@ 2011-09-02 13:20   ` Kevin Wolf
  2011-09-02 15:32     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 13:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> BlockDriverState member buffer_alignment is initially 512.  The device
> model may set them, with bdrv_set_buffer_alignment().  If the device
> model gets detached (hot unplug), the device's alignment is left
> behind.  Only okay because device hot unplug automatically destroys
> the BlockDriverState.  But that's a questionable feature, best not to
> rely on it.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Hm, I'm not sure about this... Maybe instead of doing it on open and
detach, which is a strange combination, the right thing would be to do
it on attach?

Kevin

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

* Re: [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load
  2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load Markus Armbruster
@ 2011-09-02 13:26   ` Kevin Wolf
  2011-09-02 15:33     ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 13:26 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:08, schrieb Markus Armbruster:
> To let device models distinguish between eject and load.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  block.c        |   12 ++++++------
>  block.h        |    3 ++-
>  hw/fdc.c       |    2 +-
>  hw/ide/core.c  |    2 +-
>  hw/scsi-disk.c |    2 +-
>  hw/sd.c        |    2 +-
>  6 files changed, 12 insertions(+), 11 deletions(-)
> 
> diff --git a/block.c b/block.c
> index b0e54ef..1bd67dd 100644
> --- a/block.c
> +++ b/block.c
> @@ -44,7 +44,7 @@
>  #include <windows.h>
>  #endif
>  
> -static void bdrv_dev_change_media_cb(BlockDriverState *bs);
> +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
>  static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
>          int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
>          BlockDriverCompletionFunc *cb, void *opaque);
> @@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
>      }
>  
>      if (!bdrv_key_required(bs)) {
> -        bdrv_dev_change_media_cb(bs);
> +        bdrv_dev_change_media_cb(bs, true);
>      }
>  
>      return 0;
> @@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)
>              bdrv_close(bs->file);
>          }
>  
> -        bdrv_dev_change_media_cb(bs);
> +        bdrv_dev_change_media_cb(bs, false);
>      }
>  }
>  
> @@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
>      }
>  }
>  
> -static void bdrv_dev_change_media_cb(BlockDriverState *bs)
> +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
>  {
>      if (bs->dev_ops && bs->dev_ops->change_media_cb) {
> -        bs->dev_ops->change_media_cb(bs->dev_opaque);
> +        bs->dev_ops->change_media_cb(bs->dev_opaque, load);
>      }
>  }
>  
> @@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
>      } else if (!bs->valid_key) {
>          bs->valid_key = 1;
>          /* call the change callback now, we skipped it on open */
> -        bdrv_dev_change_media_cb(bs);
> +        bdrv_dev_change_media_cb(bs, 1);

s/1/true/

Kevin

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

* Re: [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes
  2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
                   ` (45 preceding siblings ...)
  2011-08-04 15:54 ` [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Avi Kivity
@ 2011-09-02 13:37 ` Kevin Wolf
  46 siblings, 0 replies; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 13:37 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 03.08.2011 15:07, schrieb Markus Armbruster:
> This patch series looks bigger than it is.  All the patches are small
> and hopefully easy to review.
> 
> Objectives:
> 
> * Push BlockDriverState members locked, tray_open, media_changed into
>   device models, where they belong.
> 
> * BlockDriverState member removable is a confusing mess, replace it.
> 
> * Improve eject -f.
> 
> Also clean up minor messes as they get in the way.
> 
> It is based on Kevin's block branch f08df41b.
> 
> Part I: Preliminaries
> PATCH 01-03: Work on block layer interface for device models
> 
> Part II: Move tray state to device models
> PATCH 04-10 IDE tray open/closed
> PATCH 11-12 SCSI tray open/closed
> PATCH 13-14 block layer kill tray_open
> PATCH 15-16 IDE & SCSI tray lock
> PATCH 17-19 block layer kill locked
> PATCH 20-24 IDE & SCSI tray bug fixes
> PATCH 25-27 IDE & SCSI migrate tray state
> PATCH 28-30 block layer & fdc media_changed
> 
> Part III: Replace removable
> PATCH 31-34 clean up inappopriate uses of removable
> PATCH 35-36 replace remaining users
> 
> Part IV: Miscellaneous
> PATCH 37    cover tray open/closed in info block
> PATCH 38-43 Reduce unclean use of block_int.h
> PATCH 44-45 Improve eject -f
> 
> Naturally, I want all parts applied.  But I did my best to make
> applying only a prefix workable, too.

Thanks, applied some patches to the block branch. Waiting for v3 for the
rest.

I didn't pick them only from the start of the series, but considered any
patch that looked good and didn't seem to depend on other patches. This
means that some patches may be applied in a different order now, but I'm
relatively sure that it doesn't break things.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
  2011-09-02 10:08     ` Kevin Wolf
@ 2011-09-02 14:43       ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:43 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino,
	Blue Swirl, hare, amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 18:53, schrieb Blue Swirl:
>> On Wed, Aug 3, 2011 at 1:07 PM, Markus Armbruster <armbru@redhat.com> wrote:
>>> No functional change.
>>>
>>> It would be nice to have handler functions in the table, like commit
>>> e1a064f9 did for ATAPI.  Left for another day.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  hw/ide/core.c |  104 +++++++++++++++++++++++++++++++++++++++++++--------------
>>>  1 files changed, 79 insertions(+), 25 deletions(-)
>>>
>>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>>> index 1c4dc2f..a25c175 100644
>>> --- a/hw/ide/core.c
>>> +++ b/hw/ide/core.c
>>> @@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>>>     }
>>>  }
>>>
>>> +#define HD_OK (1u << IDE_HD)
>>> +#define CD_OK (1u << IDE_CD)
>>> +#define CFA_OK (1u << IDE_CFATA)
>>> +#define HD_CFA_OK (HD_OK | CFA_OK)
>>> +#define ALL_OK (HD_OK | CD_OK | CFA_OK)
>>> +
>>> +/* See ACS-2 T13/2015-D Table B.2 Command codes */
>>> +uint8_t ide_cmd_table[0x100] = {
>> 
>> Missing 'static'.
>
> And const, while we're at it.

Yes.

>>> +    /* NOP not implemented, mandatory for CD */
>>> +    [CFA_REQ_EXT_ERROR_CODE]            = CFA_OK,
>>> +    [WIN_DSM]                           = ALL_OK,
>>> +    [WIN_DEVICE_RESET]                  = CD_OK,
>>> +    [WIN_RECAL]                         = ALL_OK,
>>> +    [WIN_READ]                          = ALL_OK,
>>> +    [WIN_READ_ONCE]                     = ALL_OK,
>>> +    [WIN_READ_EXT]                      = ALL_OK,
>>> +    [WIN_READDMA_EXT]                   = ALL_OK,
>>> +    [WIN_READ_NATIVE_MAX_EXT]           = ALL_OK,
>>> +    [WIN_MULTREAD_EXT]                  = ALL_OK,
>>> +    [WIN_WRITE]                         = ALL_OK,
>>> +    [WIN_WRITE_ONCE]                    = ALL_OK,
>>> +    [WIN_WRITE_EXT]                     = ALL_OK,
>>> +    [WIN_WRITEDMA_EXT]                  = ALL_OK,
>>> +    [CFA_WRITE_SECT_WO_ERASE]           = ALL_OK,
>>> +    [WIN_MULTWRITE_EXT]                 = ALL_OK,
>>> +    [WIN_WRITE_VERIFY]                  = ALL_OK,
>>> +    [WIN_VERIFY]                        = ALL_OK,
>>> +    [WIN_VERIFY_ONCE]                   = ALL_OK,
>>> +    [WIN_VERIFY_EXT]                    = ALL_OK,
>>> +    [WIN_SEEK]                          = HD_CFA_OK,
>>> +    [CFA_TRANSLATE_SECTOR]              = CFA_OK,
>>> +    [WIN_DIAGNOSE]                      = ALL_OK,
>>> +    [WIN_SPECIFY]                       = ALL_OK,
>>> +    [WIN_STANDBYNOW2]                   = ALL_OK,
>>> +    [WIN_IDLEIMMEDIATE2]                = ALL_OK,
>>> +    [WIN_STANDBY2]                      = ALL_OK,
>>> +    [WIN_SETIDLE2]                      = ALL_OK,
>>> +    [WIN_CHECKPOWERMODE2]               = ALL_OK,
>>> +    [WIN_SLEEPNOW2]                     = ALL_OK,
>>> +    [WIN_PACKETCMD]                     = CD_OK,
>>> +    [WIN_PIDENTIFY]                     = CD_OK,
>>> +    [WIN_SMART]                         = HD_CFA_OK,
>>> +    [CFA_ACCESS_METADATA_STORAGE]       = CFA_OK,
>>> +    [CFA_ERASE_SECTORS]                 = CFA_OK,
>>> +    [WIN_MULTREAD]                      = ALL_OK,
>>> +    [WIN_MULTWRITE]                     = ALL_OK,
>>> +    [WIN_SETMULT]                       = ALL_OK,
>>> +    [WIN_READDMA]                       = ALL_OK,
>>> +    [WIN_READDMA_ONCE]                  = ALL_OK,
>>> +    [WIN_WRITEDMA]                      = ALL_OK,
>>> +    [WIN_WRITEDMA_ONCE]                 = ALL_OK,
>>> +    [CFA_WRITE_MULTI_WO_ERASE]          = ALL_OK,
>>> +    [WIN_STANDBYNOW1]                   = ALL_OK,
>>> +    [WIN_IDLEIMMEDIATE]                 = ALL_OK,
>>> +    [WIN_STANDBY]                       = ALL_OK,
>>> +    [WIN_SETIDLE1]                      = ALL_OK,
>>> +    [WIN_CHECKPOWERMODE1]               = ALL_OK,
>>> +    [WIN_SLEEPNOW1]                     = ALL_OK,
>>> +    [WIN_FLUSH_CACHE]                   = ALL_OK,
>>> +    [WIN_FLUSH_CACHE_EXT]               = ALL_OK,
>>> +    [WIN_IDENTIFY]                      = ALL_OK,
>>> +    [WIN_SETFEATURES]                   = ALL_OK,
>>> +    [IBM_SENSE_CONDITION]               = CFA_OK,
>>> +    [CFA_WEAR_LEVEL]                    = CFA_OK,
>>> +    [WIN_READ_NATIVE_MAX]               = ALL_OK,
>>> +};
>>> +
>>> +static bool ide_cmd_permitted(IDEState *s, uint32_t cmd)
>>> +{
>>> +    return cmd <= 0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind));
>>> +}
>
> Doesn't cmd < ARRAY_SIZE(ide_cmd_table) better describe what you want?

Since I touch this patch anyway, I'll do this your way.

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

* Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  2011-09-02 10:20   ` Kevin Wolf
@ 2011-09-02 14:47     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:47 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> "eject" is misleading; it means "eject" when start is clear, but
>> "load" when start is set.  Rename to loej, because that's how MMC-5
>> calls it, in section 6.40.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/atapi.c |    8 ++++----
>>  1 files changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
>> index fe2fb0b..17fbef8 100644
>> --- a/hw/ide/atapi.c
>> +++ b/hw/ide/atapi.c
>> @@ -892,11 +892,11 @@ static void cmd_seek(IDEState *s, uint8_t* buf)
>>  
>>  static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
>>  {
>> -    int start, eject, sense, err = 0;
>> -    start = buf[4] & 1;
>> -    eject = (buf[4] >> 1) & 1;
>> +    int sense, err = 0;
>> +    bool start = buf[4] & 1;
>> +    bool loej = buf[4] & 2;
>>  
>> -    if (eject) {
>> +    if (loej) {
>>          err = bdrv_eject(s->bs, !start);
>>      }
>>  
>
> "eject" has the advantage that I immediately know that it's something to
> do with the tray. "loej" on the other hand is a sequence of four random
> characters. Maybe add a comment?

The name "loej" comes from MMC-5.  I can add a comment to its
definition.

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

* Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state
  2011-09-02 10:23   ` Kevin Wolf
@ 2011-09-02 14:51     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:51 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> We already track it in BlockDriverState since commit 4be9762a.  As
>> discussed in that commit's message, we should track it in the device
>> device models instead, because it's device state.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/atapi.c    |    6 +++++-
>>  hw/ide/internal.h |    1 +
>>  2 files changed, 6 insertions(+), 1 deletions(-)
>> 
>> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
>> index 17fbef8..96f7c31 100644
>> --- a/hw/ide/atapi.c
>> +++ b/hw/ide/atapi.c
>> @@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,
>>      uint8_t event_code, media_status;
>>  
>>      media_status = 0;
>> -    if (s->bs->tray_open) {
>> +    if (s->tray_open) {
>>          media_status = MS_TRAY_OPEN;
>>      } else if (bdrv_is_inserted(s->bs)) {
>>          media_status = MS_MEDIA_PRESENT;
>> @@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)
>>          ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
>>          break;
>>      }
>> +
>> +    if (loej && !err) {
>> +        s->tray_open = !start;
>> +    }
>>  }
>>  
>>  static void cmd_mechanism_status(IDEState *s, uint8_t* buf)
>> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
>> index 46e84fa..cd8e977 100644
>> --- a/hw/ide/internal.h
>> +++ b/hw/ide/internal.h
>> @@ -442,6 +442,7 @@ struct IDEState {
>>      struct unreported_events events;
>>      uint8_t sense_key;
>>      uint8_t asc;
>> +    bool tray_open;
>>      uint8_t cdrom_changed;
>>      int packet_transfer_size;
>>      int elementary_transfer_size;
>
> Probably needs to be migrated.

Correct, but I chose to fix that separately, in PATCH 27/45.  Note that
this patch neither breaks nor fixes anything.  It just prepares the
ground for fixes.

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

* Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-09-02 10:26   ` Kevin Wolf
@ 2011-09-02 14:55     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:55 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/scsi-disk.c |   17 +++++++++++++----
>>  1 files changed, 13 insertions(+), 4 deletions(-)
>> 
>> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
>> index fa198f9..d549cb7 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)
>>      return toclen;
>>  }
>>  
>> +static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>> +{
>> +    SCSIRequest *req = &r->req;
>> +    SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
>> +    bool start = req->cmd.buf[4] & 1;
>> +    bool loej = req->cmd.buf[4] & 2;
>> +
>> +    if (s->qdev.type == TYPE_ROM && loej) {
>> +        bdrv_eject(s->bs, !start);
>> +    }
>> +}
>> +
>>  static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>>  {
>>      SCSIRequest *req = &r->req;
>> @@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
>>              goto illegal_request;
>>          break;
>>      case START_STOP:
>> -        if (s->qdev.type == TYPE_ROM && (req->cmd.buf[4] & 2)) {
>> -            /* load/eject medium */
>
> So here we actually had the comment before. Can we retain it?

We never had it in atapi.c, actually.

The fact that my scsi_disk_emulate_command() is very similar to
atapi.c's cmd_start_stop_unit() is no accident.  Whatever comment I'll
add to atapi.c, I'll add here, too.

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

* Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state
  2011-09-02 11:02   ` Kevin Wolf
@ 2011-09-02 14:56     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:56 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> We already track it in BlockDriverState.  Just like tray open/close
>> state, we should track it in the device models instead, because it's
>> device state.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/atapi.c    |    4 +++-
>>  hw/ide/internal.h |    1 +
>>  2 files changed, 4 insertions(+), 1 deletions(-)
>> 
>> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
>> index 08e1a7a..237657f 100644
>> --- a/hw/ide/atapi.c
>> +++ b/hw/ide/atapi.c
>> @@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf)
>>              buf[12] = 0x71;
>>              buf[13] = 3 << 5;
>>              buf[14] = (1 << 0) | (1 << 3) | (1 << 5);
>> -            if (bdrv_is_locked(s->bs))
>> +            if (s->tray_locked) {
>>                  buf[6] |= 1 << 1;
>> +            }
>>              buf[15] = 0x00;
>>              cpu_to_ube16(&buf[16], 706);
>>              buf[18] = 0;
>> @@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)
>>  
>>  static void cmd_prevent_allow_medium_removal(IDEState *s, uint8_t* buf)
>>  {
>> +    s->tray_locked = buf[4] & 1;
>>      bdrv_set_locked(s->bs, buf[4] & 1);
>>      ide_atapi_cmd_ok(s);
>>  }
>> diff --git a/hw/ide/internal.h b/hw/ide/internal.h
>> index cd8e977..3e56b45 100644
>> --- a/hw/ide/internal.h
>> +++ b/hw/ide/internal.h
>> @@ -443,6 +443,7 @@ struct IDEState {
>>      uint8_t sense_key;
>>      uint8_t asc;
>>      bool tray_open;
>> +    bool tray_locked;
>>      uint8_t cdrom_changed;
>>      int packet_transfer_size;
>>      int elementary_transfer_size;
>
> Same as tray open/close status: Needs to be migrated.

Correct, but I chose to fix that separately, in PATCH 26/45.  Note that
this patch neither breaks nor fixes anything.  It just prepares the
ground for fixes.

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

* Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()
  2011-09-02 11:30   ` Kevin Wolf
@ 2011-09-02 14:58     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 14:58 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:07, schrieb Markus Armbruster:
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  block.c           |    8 ++++----
>>  block.h           |    2 +-
>>  block/raw-posix.c |    8 ++++----
>>  block/raw.c       |    6 +++---
>>  block_int.h       |    2 +-
>>  hw/ide/atapi.c    |    2 +-
>>  hw/scsi-disk.c    |    2 +-
>>  trace-events      |    2 +-
>>  8 files changed, 16 insertions(+), 16 deletions(-)
>> 
>> diff --git a/block.c b/block.c
>> index 3a8a4e6..10c1b1a 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)
>>   * Lock or unlock the media (if it is locked, the user won't be able
>>   * to eject it manually).
>>   */
>> -void bdrv_set_locked(BlockDriverState *bs, int locked)
>> +void bdrv_lock_medium(BlockDriverState *bs, int locked)
>
> Make locked a bool while we're changing the signature everywhere?

Good idea.

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

* Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-09-02 12:07   ` Kevin Wolf
@ 2011-09-02 15:19     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:19 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> When ide-cd is backed by a physical drive, we want the physical tray
>> match the virtual one.  To that end, we call bdrv_eject() on guest's
>> load/eject, and bdrv_lock_medium() on guest's prevent/allow removal.
>> But we don't set the initial state on device model init.  Fix that.
>> 
>> While there, also unlock on device model exit.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  hw/ide/core.c |    4 ++++
>>  hw/ide/qdev.c |   18 ++++++++++++++++++
>>  2 files changed, 22 insertions(+), 0 deletions(-)
>> 
>> diff --git a/hw/ide/core.c b/hw/ide/core.c
>> index 5bcc857..d8b1d43 100644
>> --- a/hw/ide/core.c
>> +++ b/hw/ide/core.c
>> @@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
>>  
>>      ide_reset(s);
>>      bdrv_set_removable(bs, s->drive_kind == IDE_CD);
>> +    if (s->drive_kind == IDE_CD) {
>> +        bdrv_lock_medium(bs, s->tray_locked);
>> +        bdrv_eject(bs, s->tray_open);
>> +    }
>>      return 0;
>>  }
>>  
>> diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
>> index 3b7b306..bc2f426 100644
>> --- a/hw/ide/qdev.c
>> +++ b/hw/ide/qdev.c
>> @@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)
>>      return ide_dev_initfn(dev, IDE_CD);
>>  }
>>  
>> +static int ide_cd_exitfn(IDEDevice *dev)
>> +{
>> +    bdrv_lock_medium(dev->conf.bs, 0);
>> +    return 0;
>> +}
>> +
>>  static int ide_drive_initfn(IDEDevice *dev)
>>  {
>>      DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
>> @@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)
>>      return ide_dev_initfn(dev, dinfo->media_cd ? IDE_CD : IDE_HD);
>>  }
>>  
>> +static int ide_drive_exitfn(IDEDevice *dev)
>> +{
>> +    DriveInfo *dinfo = drive_get_by_blockdev(dev->conf.bs);
>> +
>> +    if (dinfo->media_cd) {
>> +        return ide_cd_exitfn(dev);
>> +    }
>
> Is dinfo->media_cd guaranteed to be the same as s->drive_kind? I
> wouldn't have expected this to be true at least since the introduction
> of ide-hd/cd.

I'm afraid you're right.  Now I need to find a way from IDEDevice to
IDEState.  These IDE data structures are sick...

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-09-02 12:20   ` Kevin Wolf
  2011-09-02 12:35     ` Paolo Bonzini
@ 2011-09-02 15:20     ` Markus Armbruster
  2011-09-02 15:59       ` Kevin Wolf
  1 sibling, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:20 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, Paolo Bonzini, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> Use a subsection, so that migration to older version still works,
>> provided the tray is closed and unlocked.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> Ah, here is the migration part. The state wasn't migrated before, so not
> doing it in patch 10 doesn't break anything. I would still prefer to add
> migration in the same patch that adds the fields.
>
> You could just move the subsection itself and keep the post_load part
> here if it doesn't fit naturally in one of the other patches of the series.

I don't get this part, I'm afraid.

> On another note, have our subsections been fixed meanwhile? If not,
> increasing the version number instead might be the right choice. Paolo?
>
> Kevin

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-09-02 12:35     ` Paolo Bonzini
@ 2011-09-02 15:22       ` Markus Armbruster
  2011-09-02 15:25         ` Paolo Bonzini
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Kevin Wolf, stefano.stabellini, quintela, qemu-devel,
	lcapitulino, hare, amit.shah, hch

Paolo Bonzini <pbonzini@redhat.com> writes:

> On 09/02/2011 02:20 PM, Kevin Wolf wrote:
>> Ah, here is the migration part. The state wasn't migrated before, so not
>> doing it in patch 10 doesn't break anything. I would still prefer to add
>> migration in the same patch that adds the fields.
>>
>> You could just move the subsection itself and keep the post_load part
>> here if it doesn't fit naturally in one of the other patches of the series.
>>
>> On another note, have our subsections been fixed meanwhile? If not,
>> increasing the version number instead might be the right choice. Paolo?
>
> No, they haven't, but there's hope they will before 1.0.

Use a subsection here anyway?  Or should I throw up my hands and bump
the version number?

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-09-02 15:22       ` Markus Armbruster
@ 2011-09-02 15:25         ` Paolo Bonzini
  0 siblings, 0 replies; 105+ messages in thread
From: Paolo Bonzini @ 2011-09-02 15:25 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Kevin Wolf, stefano.stabellini, quintela, qemu-devel,
	lcapitulino, hare, amit.shah, hch

On 09/02/2011 05:22 PM, Markus Armbruster wrote:
>>> >>  On another note, have our subsections been fixed meanwhile? If not,
>>> >>  increasing the version number instead might be the right choice. Paolo?
>> >
>> >  No, they haven't, but there's hope they will before 1.0.
> Use a subsection here anyway?  Or should I throw up my hands and bump
> the version number?

Yes, I'd use a subsection for ide/atapi (not for SCSI of course).

Paolo

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

* Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
  2011-09-02 13:04   ` Kevin Wolf
@ 2011-09-02 15:29     ` Markus Armbruster
  2011-09-02 16:22       ` Kevin Wolf
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:29 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> Need to ask the device, so this requires new BlockDevOps member
>> is_medium_ejected().
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> I find the name confusing. "medium is ejected" seems to mean "tray is
> open". It isn't obvious that "tray is closed, but no medium is inserted"
> is not "medium is ejected".
>
> Why not call it tray_open like in the devices?

Not all all devices with removable media have trays.  I'll rename it
anyway.  We'll figure out how to handle devices without trays when we
add one.

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

* Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
  2011-09-02 13:13   ` Kevin Wolf
@ 2011-09-02 15:30     ` Markus Armbruster
  2011-09-02 16:25       ` Kevin Wolf
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:30 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> Device models should be able to set it without an unclean include of
>> block_int.h.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  block.c         |    6 ++++--
>>  block.h         |    1 +
>>  hw/ide/core.c   |    2 +-
>>  hw/scsi-disk.c  |    2 +-
>>  hw/virtio-blk.c |    3 +--
>>  5 files changed, 8 insertions(+), 6 deletions(-)
>> 
>> diff --git a/block.c b/block.c
>> index fed0c16..67d9429 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
>>      bs->encrypted = 0;
>>      bs->valid_key = 0;
>>      bs->open_flags = flags;
>> -    /* buffer_alignment defaulted to 512, drivers can change this value */
>>      bs->buffer_alignment = 512;
>
> This comment is still right.

It's also next to useless.  I hate comments paraphrasing the code :)

I'll keep it if you insist.

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

* Re: [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach
  2011-09-02 13:20   ` Kevin Wolf
@ 2011-09-02 15:32     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:32 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> BlockDriverState member buffer_alignment is initially 512.  The device
>> model may set them, with bdrv_set_buffer_alignment().  If the device
>> model gets detached (hot unplug), the device's alignment is left
>> behind.  Only okay because device hot unplug automatically destroys
>> the BlockDriverState.  But that's a questionable feature, best not to
>> rely on it.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> Hm, I'm not sure about this... Maybe instead of doing it on open and
> detach, which is a strange combination, the right thing would be to do
> it on attach?

Maybe.  My readiness to rearrange code for neatness declines a bit
beyond PATCH#30 or so ;)

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

* Re: [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load
  2011-09-02 13:26   ` Kevin Wolf
@ 2011-09-02 15:33     ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:33 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> To let device models distinguish between eject and load.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  block.c        |   12 ++++++------
>>  block.h        |    3 ++-
>>  hw/fdc.c       |    2 +-
>>  hw/ide/core.c  |    2 +-
>>  hw/scsi-disk.c |    2 +-
>>  hw/sd.c        |    2 +-
>>  6 files changed, 12 insertions(+), 11 deletions(-)
>> 
>> diff --git a/block.c b/block.c
>> index b0e54ef..1bd67dd 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -44,7 +44,7 @@
>>  #include <windows.h>
>>  #endif
>>  
>> -static void bdrv_dev_change_media_cb(BlockDriverState *bs);
>> +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load);
>>  static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs,
>>          int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
>>          BlockDriverCompletionFunc *cb, void *opaque);
>> @@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
>>      }
>>  
>>      if (!bdrv_key_required(bs)) {
>> -        bdrv_dev_change_media_cb(bs);
>> +        bdrv_dev_change_media_cb(bs, true);
>>      }
>>  
>>      return 0;
>> @@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)
>>              bdrv_close(bs->file);
>>          }
>>  
>> -        bdrv_dev_change_media_cb(bs);
>> +        bdrv_dev_change_media_cb(bs, false);
>>      }
>>  }
>>  
>> @@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
>>      }
>>  }
>>  
>> -static void bdrv_dev_change_media_cb(BlockDriverState *bs)
>> +static void bdrv_dev_change_media_cb(BlockDriverState *bs, bool load)
>>  {
>>      if (bs->dev_ops && bs->dev_ops->change_media_cb) {
>> -        bs->dev_ops->change_media_cb(bs->dev_opaque);
>> +        bs->dev_ops->change_media_cb(bs->dev_opaque, load);
>>      }
>>  }
>>  
>> @@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key)
>>      } else if (!bs->valid_key) {
>>          bs->valid_key = 1;
>>          /* call the change callback now, we skipped it on open */
>> -        bdrv_dev_change_media_cb(bs);
>> +        bdrv_dev_change_media_cb(bs, 1);
>
> s/1/true/

Thanks, will fix.

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-09-02 12:25   ` Kevin Wolf
@ 2011-09-02 15:35     ` Markus Armbruster
  2011-09-02 16:18       ` Kevin Wolf
  0 siblings, 1 reply; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 15:35 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
>> versions.  We normally use subsections to avoid that.  Not possible
>> here, because we don't have a section to begin with.  Too bad.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> A more logical approach would be to add migration support to SCSI first.

Isn't that what I do?

> I guess adding .unmigratable = 1 makes more sense at the moment.

Why?

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

* Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
  2011-09-02 15:20     ` Markus Armbruster
@ 2011-09-02 15:59       ` Kevin Wolf
  0 siblings, 0 replies; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 15:59 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, Paolo Bonzini, hch

Am 02.09.2011 17:20, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>> Use a subsection, so that migration to older version still works,
>>> provided the tray is closed and unlocked.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>
>> Ah, here is the migration part. The state wasn't migrated before, so not
>> doing it in patch 10 doesn't break anything. I would still prefer to add
>> migration in the same patch that adds the fields.
>>
>> You could just move the subsection itself and keep the post_load part
>> here if it doesn't fit naturally in one of the other patches of the series.
> 
> I don't get this part, I'm afraid.

I was afraid that you can't merge all of this patch into patch 10
because the post_load functions depends on later patches. So I suggested
that you just add the subsection definition itself to patch 10 and keep
the addition of post_load as patch 26.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-09-02 15:35     ` Markus Armbruster
@ 2011-09-02 16:18       ` Kevin Wolf
  2011-09-02 16:45         ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 16:18 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 02.09.2011 17:35, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
>>> versions.  We normally use subsections to avoid that.  Not possible
>>> here, because we don't have a section to begin with.  Too bad.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>
>> A more logical approach would be to add migration support to SCSI first.
> 
> Isn't that what I do?
> 
>> I guess adding .unmigratable = 1 makes more sense at the moment.
> 
> Why?

Hm, you mean that we can successfully migrate SCSI today?

SCSIDiskState doesn't seem to directly have anything variable that must
be migrated. I think SCSIDevice does have fields that need to be
migrated (unit_attention, sense and the request list). I'm not sure what
other state scsi-bus involves, but unless the SCSI controllers can
restore all of it, it should have a VMState, too.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
  2011-09-02 15:29     ` Markus Armbruster
@ 2011-09-02 16:22       ` Kevin Wolf
  0 siblings, 0 replies; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 16:22 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 02.09.2011 17:29, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>> Need to ask the device, so this requires new BlockDevOps member
>>> is_medium_ejected().
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>
>> I find the name confusing. "medium is ejected" seems to mean "tray is
>> open". It isn't obvious that "tray is closed, but no medium is inserted"
>> is not "medium is ejected".
>>
>> Why not call it tray_open like in the devices?
> 
> Not all all devices with removable media have trays.  I'll rename it
> anyway.  We'll figure out how to handle devices without trays when we
> add one.

Then you need to clarify the intended semantics. For devices without a
tray it's completely unclear to me what it means. The example for such a
device that we have today is floppy.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
  2011-09-02 15:30     ` Markus Armbruster
@ 2011-09-02 16:25       ` Kevin Wolf
  2011-09-02 16:53         ` Markus Armbruster
  0 siblings, 1 reply; 105+ messages in thread
From: Kevin Wolf @ 2011-09-02 16:25 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: stefano.stabellini, quintela, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Am 02.09.2011 17:30, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>> Device models should be able to set it without an unclean include of
>>> block_int.h.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  block.c         |    6 ++++--
>>>  block.h         |    1 +
>>>  hw/ide/core.c   |    2 +-
>>>  hw/scsi-disk.c  |    2 +-
>>>  hw/virtio-blk.c |    3 +--
>>>  5 files changed, 8 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/block.c b/block.c
>>> index fed0c16..67d9429 100644
>>> --- a/block.c
>>> +++ b/block.c
>>> @@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
>>>      bs->encrypted = 0;
>>>      bs->valid_key = 0;
>>>      bs->open_flags = flags;
>>> -    /* buffer_alignment defaulted to 512, drivers can change this value */
>>>      bs->buffer_alignment = 512;
>>
>> This comment is still right.
> 
> It's also next to useless.  I hate comments paraphrasing the code :)
> 
> I'll keep it if you insist.

The information that the comment gives isn't that we set it to 512, but
that this is only a default and "drivers" (should be "devices", I think)
are expected to change it.

Kevin

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

* Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
  2011-09-02 16:18       ` Kevin Wolf
@ 2011-09-02 16:45         ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 16:45 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 02.09.2011 17:35, schrieb Markus Armbruster:
>> Kevin Wolf <kwolf@redhat.com> writes:
>> 
>>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>>> Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older
>>>> versions.  We normally use subsections to avoid that.  Not possible
>>>> here, because we don't have a section to begin with.  Too bad.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>
>>> A more logical approach would be to add migration support to SCSI first.
>> 
>> Isn't that what I do?
>> 
>>> I guess adding .unmigratable = 1 makes more sense at the moment.
>> 
>> Why?
>
> Hm, you mean that we can successfully migrate SCSI today?
>
> SCSIDiskState doesn't seem to directly have anything variable that must
> be migrated. I think SCSIDevice does have fields that need to be
> migrated (unit_attention, sense and the request list). I'm not sure what
> other state scsi-bus involves, but unless the SCSI controllers can
> restore all of it, it should have a VMState, too.

Easiest solution is to just drop my patch then.

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

* Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
  2011-09-02 16:25       ` Kevin Wolf
@ 2011-09-02 16:53         ` Markus Armbruster
  0 siblings, 0 replies; 105+ messages in thread
From: Markus Armbruster @ 2011-09-02 16:53 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: quintela, stefano.stabellini, qemu-devel, lcapitulino, hare,
	amit.shah, hch

Kevin Wolf <kwolf@redhat.com> writes:

> Am 02.09.2011 17:30, schrieb Markus Armbruster:
>> Kevin Wolf <kwolf@redhat.com> writes:
>> 
>>> Am 03.08.2011 15:08, schrieb Markus Armbruster:
>>>> Device models should be able to set it without an unclean include of
>>>> block_int.h.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> ---
>>>>  block.c         |    6 ++++--
>>>>  block.h         |    1 +
>>>>  hw/ide/core.c   |    2 +-
>>>>  hw/scsi-disk.c  |    2 +-
>>>>  hw/virtio-blk.c |    3 +--
>>>>  5 files changed, 8 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/block.c b/block.c
>>>> index fed0c16..67d9429 100644
>>>> --- a/block.c
>>>> +++ b/block.c
>>>> @@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
>>>>      bs->encrypted = 0;
>>>>      bs->valid_key = 0;
>>>>      bs->open_flags = flags;
>>>> -    /* buffer_alignment defaulted to 512, drivers can change this value */
>>>>      bs->buffer_alignment = 512;
>>>
>>> This comment is still right.
>> 
>> It's also next to useless.  I hate comments paraphrasing the code :)
>> 
>> I'll keep it if you insist.
>
> The information that the comment gives isn't that we set it to 512, but
> that this is only a default and "drivers" (should be "devices", I think)
> are expected to change it.

Devices can and do change any number of default values set up here, and
documenting that just for buffer_alignment is useless at best,
misleading at worst.

Nevertheless, I'll keep it if you insist.

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

end of thread, other threads:[~2011-09-02 16:54 UTC | newest]

Thread overview: 105+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03 13:07 [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 01/45] block: Attach non-qdev devices as well Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 02/45] block: Generalize change_cb() to BlockDevOps Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 03/45] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 04/45] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 05/45] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 06/45] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
2011-08-03 16:53   ` Blue Swirl
2011-08-03 17:15     ` Markus Armbruster
2011-09-02 10:08     ` Kevin Wolf
2011-09-02 14:43       ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 08/45] ide: Reject ATA commands specific to drive kinds Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
2011-09-02 10:20   ` Kevin Wolf
2011-09-02 14:47     ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state Markus Armbruster
2011-09-02 10:23   ` Kevin Wolf
2011-09-02 14:51     ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
2011-08-04  6:12   ` Hannes Reinecke
2011-09-02 10:26   ` Kevin Wolf
2011-09-02 14:55     ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state Markus Armbruster
2011-08-04  6:13   ` Hannes Reinecke
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 13/45] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 14/45] block: Drop tray status tracking, no longer used Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state Markus Armbruster
2011-09-02 11:02   ` Kevin Wolf
2011-09-02 14:56     ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 16/45] scsi-disk: " Markus Armbruster
2011-08-04  6:14   ` Hannes Reinecke
2011-08-04  6:39     ` Markus Armbruster
2011-08-04  6:46       ` Hannes Reinecke
2011-08-04  7:25         ` Markus Armbruster
2011-08-04  7:30           ` Hannes Reinecke
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 17/45] block: Leave enforcing tray lock to device models Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 18/45] block: Drop medium lock tracking, ask device models instead Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
2011-09-02 11:30   ` Kevin Wolf
2011-09-02 14:58     ` Markus Armbruster
2011-08-03 13:07 ` [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
2011-08-04 17:48   ` Luiz Capitulino
2011-08-05  7:13     ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 21/45] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
2011-09-02 12:07   ` Kevin Wolf
2011-09-02 15:19     ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
2011-08-04  6:20   ` Hannes Reinecke
2011-08-04  6:48     ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
2011-08-04  6:21   ` Hannes Reinecke
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 25/45] ide: Give vmstate structs internal linkage where possible Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration Markus Armbruster
2011-09-02 12:20   ` Kevin Wolf
2011-09-02 12:35     ` Paolo Bonzini
2011-09-02 15:22       ` Markus Armbruster
2011-09-02 15:25         ` Paolo Bonzini
2011-09-02 15:20     ` Markus Armbruster
2011-09-02 15:59       ` Kevin Wolf
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 27/45] scsi-disk: " Markus Armbruster
2011-08-04  6:23   ` Hannes Reinecke
2011-08-04  6:45     ` Paolo Bonzini
2011-08-04  9:57     ` Kevin Wolf
2011-09-02 12:25   ` Kevin Wolf
2011-09-02 15:35     ` Markus Armbruster
2011-09-02 16:18       ` Kevin Wolf
2011-09-02 16:45         ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 28/45] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 29/45] block: Leave tracking media change to device models Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 30/45] fdc: Make media change detection more robust Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 31/45] block: Clean up bdrv_flush_all() Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 32/45] savevm: Include writable devices with removable media Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 33/45] xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD" Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 34/45] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable" Markus Armbruster
2011-08-04 17:58   ` Luiz Capitulino
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 36/45] block: Drop BlockDriverState member removable Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block Markus Armbruster
2011-08-04 18:05   ` Luiz Capitulino
2011-09-02 13:04   ` Kevin Wolf
2011-09-02 15:29     ` Markus Armbruster
2011-09-02 16:22       ` Kevin Wolf
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 38/45] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 39/45] hw: Trim superfluous #include "block_int.h" Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
2011-08-04 18:10   ` Luiz Capitulino
2011-08-04 18:22     ` Markus Armbruster
2011-08-04 18:28       ` Luiz Capitulino
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment() Markus Armbruster
2011-09-02 13:13   ` Kevin Wolf
2011-09-02 15:30     ` Markus Armbruster
2011-09-02 16:25       ` Kevin Wolf
2011-09-02 16:53         ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach Markus Armbruster
2011-09-02 13:20   ` Kevin Wolf
2011-09-02 15:32     ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 43/45] nbd: Clean up use of block_int.h Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load Markus Armbruster
2011-09-02 13:26   ` Kevin Wolf
2011-09-02 15:33     ` Markus Armbruster
2011-08-03 13:08 ` [Qemu-devel] [PATCH v2 45/45] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
2011-08-04 15:54 ` [Qemu-devel] [PATCH v2 00/45] Block layer cleanup & fixes Avi Kivity
2011-09-02 13:37 ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.