All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
@ 2011-07-20 16:23 Markus Armbruster
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f Markus Armbruster
                   ` (57 more replies)
  0 siblings, 58 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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.

Part I: Preliminaries
PATCH 01-09: Assorted block layer fixes and cleanup

Part II: Move tray state to device models
PATCH 10-18: IDE tray open/closed
PATCH 19-22: SCSI tray open/closed
PATCH 23-25: block layer kill tray_open
PATCH 26-27: IDE tray lock
PATCH 28-29: SCSI tray lock
PATCH 30-32: block layer kill locked
PATCH 33-35: IDE & SCSI synchronize physical tray on init
PATCH 36-38: IDE & SCSI migrate tray state
PATCH 39-41: block layer & fdc media_changed

Part III: Replace removable
PATCH 42-44 clean up inappopriate uses of removable
PATCH 45-46 replace remaining users

Part IV: Reduce unclean use of block_int.h
PATCH 47-53

PART V: Improve eject -f
PATCH 54-55

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

Review invited from:

* Kevin, of course.

* Amit, you might be interested in the ATAPI stuff.

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

* Juan, please review PATCH 37 "ide/atapi: Preserve tray state on
  migration", PATCH 38 "scsi-disk: Preserve tray state on migration",
  and PATCH 43 "savevm: Include writable devices with removable
  media".

* Dimitry, have a look at PATCH 44 "spitz tosa: Simplify "drive is
  suitable for microdrive" test".

* Stefano, have a look at PATCH 45, it affects "-drive if=xen".

Testing

* 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 44;
  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 39-41 replaced
  by a single patch to remove it, and simplify block.c and hw/fdc.c.


Markus Armbruster (55):
  blockdev: Make eject fail for non-removable drives even with -f
  block: Reset device model callbacks on detach
  block: Attach non-qdev devices as well
  block: Generalize change_cb() to BlockDevOps
  block: Split change_cb() into change_media_cb(), resize_cb()
  block/raw-win32: Drop disabled code for removable host devices
  block: Make BlockDriver method bdrv_set_locked() return void
  block: Make BlockDriver method bdrv_eject() return void
  block: Don't let locked flag prevent medium load
  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
  ide/atapi: Switch from BlockDriverState's tray_open to own
  scsi-disk: Reject CD-specific SCSI commands to disks
  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
  block: Show whether the guest ejected the medium in info block
  ide/atapi: Track tray locked state
  ide/atapi: Switch from BlockDriverState's locked to own tray_locked
  scsi-disk: Track tray locked state
  scsi-disk: Switch from BlockDriverState's locked to own tray_locked
  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
  spitz tosa: Simplify "drive is suitable for microdrive" test
  block: Clean up remaining users of "removable"
  block: Drop BlockDriverState member removable
  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
  block: Move BlockDriverAIOCB & friends from block_int.h to block.h
  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              |  205 ++++++++++++++++++++++++++------------------------
 block.h              |  104 +++++++++++++++++++++++---
 block/nbd.c          |    1 +
 block/raw-posix.c    |   30 +++-----
 block/raw-win32.c    |   35 ---------
 block/raw.c          |   18 +++--
 block_int.h          |   74 ++-----------------
 blockdev.c           |   28 +++-----
 hw/fdc.c             |   48 ++++++------
 hw/ide/atapi.c       |   58 +++++++--------
 hw/ide/cmd646.c      |    1 -
 hw/ide/core.c        |  195 ++++++++++++++++++++++++++++++++++++-----------
 hw/ide/ich.c         |    1 -
 hw/ide/internal.h    |  199 +++++++++++++++++++++++++-----------------------
 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        |    1 -
 hw/ide/qdev.c        |   30 +++++++
 hw/ide/via.c         |    1 -
 hw/lsi53c895a.c      |    1 -
 hw/nand.c            |    4 +-
 hw/onenand.c         |    6 +-
 hw/pflash_cfi01.c    |    1 +
 hw/pflash_cfi02.c    |    1 +
 hw/qdev-properties.c |    6 +-
 hw/scsi-bus.c        |   10 +++
 hw/scsi-disk.c       |  175 ++++++++++++++++++++++++++++++++++++++++---
 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      |    1 +
 savevm.c             |    4 +-
 trace-events         |    2 +-
 44 files changed, 792 insertions(+), 516 deletions(-)

-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:27   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 02/55] block: Reset device model callbacks on detach Markus Armbruster
                   ` (56 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Ejecting hard disk platters can only end in tears.

If you need to revoke access to an image, use drive_del, not eject -f.

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

diff --git a/blockdev.c b/blockdev.c
index a97a801..fcab8da 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -646,16 +646,13 @@ out:
 
 static int eject_device(Monitor *mon, BlockDriverState *bs, int force)
 {
-    if (!force) {
-        if (!bdrv_is_removable(bs)) {
-            qerror_report(QERR_DEVICE_NOT_REMOVABLE,
-                           bdrv_get_device_name(bs));
-            return -1;
-        }
-        if (bdrv_is_locked(bs)) {
-            qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
-            return -1;
-        }
+    if (!bdrv_is_removable(bs)) {
+        qerror_report(QERR_DEVICE_NOT_REMOVABLE, bdrv_get_device_name(bs));
+        return -1;
+    }
+    if (!force && bdrv_is_locked(bs)) {
+        qerror_report(QERR_DEVICE_LOCKED, bdrv_get_device_name(bs));
+        return -1;
     }
     bdrv_close(bs);
     return 0;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 02/55] block: Reset device model callbacks on detach
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:27   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 03/55] block: Attach non-qdev devices as well Markus Armbruster
                   ` (55 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

BlockDriverState members change_cb and change_opaque are initially
null.  The device model may set them, with bdrv_set_change_cb().  If
the device model gets detached (hot unplug), they're left dangling.
Only safe 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 |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/block.c b/block.c
index 24a25d5..c49a825 100644
--- a/block.c
+++ b/block.c
@@ -730,6 +730,8 @@ void bdrv_detach(BlockDriverState *bs, DeviceState *qdev)
 {
     assert(bs->peer == qdev);
     bs->peer = NULL;
+    bs->change_cb = NULL;
+    bs->change_opaque = NULL;
 }
 
 DeviceState *bdrv_get_attached(BlockDriverState *bs)
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 03/55] block: Attach non-qdev devices as well
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f Markus Armbruster
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 02/55] block: Reset device model callbacks on detach Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 04/55] block: Generalize change_cb() to BlockDevOps Markus Armbruster
                   ` (54 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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/nand.c            |    4 +++-
 hw/onenand.c         |    6 ++++--
 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, 44 insertions(+), 23 deletions(-)

diff --git a/block.c b/block.c
index c49a825..1429028 100644
--- a/block.c
+++ b/block.c
@@ -703,7 +703,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);
@@ -717,26 +717,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 859d1d9..8d8172c 100644
--- a/block.h
+++ b/block.h
@@ -72,9 +72,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 1e265d2..1a23d8a 100644
--- a/block_int.h
+++ b/block_int.h
@@ -159,7 +159,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 fcab8da..13a9b41 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/nand.c b/hw/nand.c
index 37e51d7..242cc02 100644
--- a/hw/nand.c
+++ b/hw/nand.c
@@ -463,8 +463,10 @@ NANDFlashState *nand_init(int manf_id, int chip_id)
 
     s = (NANDFlashState *) qemu_mallocz(sizeof(NANDFlashState));
     dinfo = drive_get(IF_MTD, 0, 0);
-    if (dinfo)
+    if (dinfo) {
         s->bdrv = dinfo->bdrv;
+        bdrv_attach_dev_nofail(s->bdrv, s);
+    }
     s->manf_id = manf_id;
     s->chip_id = chip_id;
     s->size = nand_flash_ids[s->chip_id].size << 20;
diff --git a/hw/onenand.c b/hw/onenand.c
index 71c1ab4..8382a6f 100644
--- a/hw/onenand.c
+++ b/hw/onenand.c
@@ -632,11 +632,13 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq)
     s->density_mask = (id & (1 << 11)) ? (1 << (6 + ((id >> 12) & 7))) : 0;
     s->iomemtype = cpu_register_io_memory(onenand_readfn,
                     onenand_writefn, s, DEVICE_NATIVE_ENDIAN);
-    if (!dinfo)
+    if (!dinfo) {
         s->image = memset(qemu_malloc(size + (size >> 5)),
                         0xff, size + (size >> 5));
-    else
+    } else {
         s->bdrv = dinfo->bdrv;
+        bdrv_attach_dev_nofail(s->bdrv, s);
+    }
     s->otp = memset(qemu_malloc((64 + 2) << PAGE_SHIFT),
                     0xff, (64 + 2) << PAGE_SHIFT);
     s->ram = qemu_ram_alloc(NULL, "onenand.ram", 0xc000 << s->shift);
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 cedfb20..3fdd5b0 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -451,6 +451,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 86582cc..8a82204 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -530,7 +530,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 0c298af..7d4144c 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -682,6 +682,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.2.3

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

* [Qemu-devel] [PATCH 04/55] block: Generalize change_cb() to BlockDevOps
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (2 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 03/55] block: Attach non-qdev devices as well Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:30   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 05/55] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
                   ` (53 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 1429028..2a1f7af 100644
--- a/block.c
+++ b/block.c
@@ -43,6 +43,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);
@@ -636,10 +637,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;
@@ -675,10 +674,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);
     }
 }
 
@@ -740,8 +737,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 */
@@ -750,6 +747,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
  *
@@ -1152,9 +1163,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;
 }
@@ -1473,15 +1482,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)
@@ -1520,8 +1520,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 8d8172c..623c488 100644
--- a/block.h
+++ b/block.h
@@ -27,6 +27,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 */
@@ -76,6 +80,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,
@@ -188,9 +194,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 1a23d8a..e2fa254 100644
--- a/block_int.h
+++ b/block_int.h
@@ -152,15 +152,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 3fdd5b0..94cea3d 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -437,6 +437,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
@@ -452,7 +456,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.2.3

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

* [Qemu-devel] [PATCH 05/55] block: Split change_cb() into change_media_cb(), resize_cb()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (3 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 04/55] block: Generalize change_cb() to BlockDevOps Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:31   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 06/55] block/raw-win32: Drop disabled code for removable host devices Markus Armbruster
                   ` (52 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 2a1f7af..fab766a 100644
--- a/block.c
+++ b/block.c
@@ -43,7 +43,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);
@@ -638,7 +638,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;
@@ -675,7 +675,7 @@ void bdrv_close(BlockDriverState *bs)
         }
 
         bs->media_changed = 1;
-        bdrv_dev_change_cb(bs, CHANGE_MEDIA);
+        bdrv_dev_change_media_cb(bs);
     }
 }
 
@@ -754,10 +754,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);
     }
 }
 
@@ -1163,7 +1170,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;
 }
@@ -1520,7 +1527,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 623c488..89f75e3 100644
--- a/block.h
+++ b/block.h
@@ -27,8 +27,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 e2fa254..f5d67c1 100644
--- a/block_int.h
+++ b/block_int.h
@@ -203,9 +203,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 94cea3d..4dc9047 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -422,14 +422,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);
@@ -438,7 +434,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.2.3

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

* [Qemu-devel] [PATCH 06/55] block/raw-win32: Drop disabled code for removable host devices
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (4 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 05/55] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:32   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void Markus Armbruster
                   ` (51 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

It's been disabled since the start (commit 19cb3738, Aug 2006), and
has been untouched except for spelling fixes and such.  I don't feel
like dragging it along any further.

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

diff --git a/block/raw-win32.c b/block/raw-win32.c
index 56bd719..17cc540 100644
--- a/block/raw-win32.c
+++ b/block/raw-win32.c
@@ -366,41 +366,6 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
     return 0;
 }
 
-#if 0
-/***********************************************/
-/* removable device additional commands */
-
-static int raw_is_inserted(BlockDriverState *bs)
-{
-    return 1;
-}
-
-static int raw_media_changed(BlockDriverState *bs)
-{
-    return -ENOTSUP;
-}
-
-static int raw_eject(BlockDriverState *bs, int eject_flag)
-{
-    DWORD ret_count;
-
-    if (s->type == FTYPE_FILE)
-        return -ENOTSUP;
-    if (eject_flag) {
-        DeviceIoControl(s->hfile, IOCTL_STORAGE_EJECT_MEDIA,
-                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
-    } else {
-        DeviceIoControl(s->hfile, IOCTL_STORAGE_LOAD_MEDIA,
-                        NULL, 0, NULL, 0, &lpBytesReturned, NULL);
-    }
-}
-
-static int raw_set_locked(BlockDriverState *bs, int locked)
-{
-    return -ENOTSUP;
-}
-#endif
-
 static int hdev_has_zero_init(BlockDriverState *bs)
 {
     return 0;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (5 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 06/55] block/raw-win32: Drop disabled code for removable host devices Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
       [not found]   ` <20110721111134.787a83af@doriath>
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() " Markus Armbruster
                   ` (50 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

The only caller is bdrv_set_locked(), and it ignores the value.

Callees always return 0, except for FreeBSD's cdrom_set_locked(),
which returns -ENOTSUP when the device is in a terminally wedged
state.

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

diff --git a/block/raw-posix.c b/block/raw-posix.c
index 34b64aa..14f8f62 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1346,7 +1346,7 @@ static int cdrom_eject(BlockDriverState *bs, int eject_flag)
     return 0;
 }
 
-static int cdrom_set_locked(BlockDriverState *bs, int locked)
+static void cdrom_set_locked(BlockDriverState *bs, int locked)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1357,8 +1357,6 @@ static int cdrom_set_locked(BlockDriverState *bs, int locked)
          */
         /* perror("CDROM_LOCKDOOR"); */
     }
-
-    return 0;
 }
 
 static BlockDriver bdrv_host_cdrom = {
@@ -1467,12 +1465,12 @@ static int cdrom_eject(BlockDriverState *bs, int eject_flag)
     return 0;
 }
 
-static int cdrom_set_locked(BlockDriverState *bs, int locked)
+static void cdrom_set_locked(BlockDriverState *bs, int locked)
 {
     BDRVRawState *s = bs->opaque;
 
     if (s->fd < 0)
-        return -ENOTSUP;
+        return;
     if (ioctl(s->fd, (locked ? CDIOCPREVENT : CDIOCALLOW)) < 0) {
         /*
          * Note: an error can happen if the distribution automatically
@@ -1480,8 +1478,6 @@ static int cdrom_set_locked(BlockDriverState *bs, int locked)
          */
         /* perror("CDROM_LOCKDOOR"); */
     }
-
-    return 0;
 }
 
 static BlockDriver bdrv_host_cdrom = {
diff --git a/block/raw.c b/block/raw.c
index b0f72d6..1398a9c 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -80,10 +80,9 @@ static int raw_eject(BlockDriverState *bs, int eject_flag)
     return bdrv_eject(bs->file, eject_flag);
 }
 
-static int raw_set_locked(BlockDriverState *bs, int locked)
+static void raw_set_locked(BlockDriverState *bs, int locked)
 {
     bdrv_set_locked(bs->file, locked);
-    return 0;
 }
 
 static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf)
diff --git a/block_int.h b/block_int.h
index f5d67c1..69cf222 100644
--- a/block_int.h
+++ b/block_int.h
@@ -111,7 +111,7 @@ struct BlockDriver {
     int (*bdrv_is_inserted)(BlockDriverState *bs);
     int (*bdrv_media_changed)(BlockDriverState *bs);
     int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
-    int (*bdrv_set_locked)(BlockDriverState *bs, int locked);
+    void (*bdrv_set_locked)(BlockDriverState *bs, int locked);
 
     /* to control generic scsi devices */
     int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf);
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() return void
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (6 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-22 14:41   ` Kevin Wolf
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load Markus Armbruster
                   ` (49 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Callees always return 0, except for FreeBSD's cdrom_eject(), which
returns -ENOTSUP when the device is in a terminally wedged state.

The only caller is bdrv_eject(), and it maps -ENOTSUP to 0 since
commit 4be9762a.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 block.c           |   17 ++++-------------
 block/raw-posix.c |   16 +++++-----------
 block/raw.c       |    4 ++--
 block_int.h       |    2 +-
 4 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/block.c b/block.c
index fab766a..594bcab 100644
--- a/block.c
+++ b/block.c
@@ -2768,25 +2768,16 @@ int bdrv_media_changed(BlockDriverState *bs)
 int bdrv_eject(BlockDriverState *bs, int eject_flag)
 {
     BlockDriver *drv = bs->drv;
-    int ret;
 
     if (bs->locked) {
         return -EBUSY;
     }
 
-    if (!drv || !drv->bdrv_eject) {
-        ret = -ENOTSUP;
-    } else {
-        ret = drv->bdrv_eject(bs, eject_flag);
-    }
-    if (ret == -ENOTSUP) {
-        ret = 0;
+    if (drv && drv->bdrv_eject) {
+        drv->bdrv_eject(bs, eject_flag);
     }
-    if (ret >= 0) {
-        bs->tray_open = eject_flag;
-    }
-
-    return ret;
+    bs->tray_open = eject_flag;
+    return 0;
 }
 
 int bdrv_is_locked(BlockDriverState *bs)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 14f8f62..e8a2fc2 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1239,7 +1239,7 @@ static int floppy_media_changed(BlockDriverState *bs)
     return ret;
 }
 
-static int floppy_eject(BlockDriverState *bs, int eject_flag)
+static void floppy_eject(BlockDriverState *bs, int eject_flag)
 {
     BDRVRawState *s = bs->opaque;
     int fd;
@@ -1254,8 +1254,6 @@ static int floppy_eject(BlockDriverState *bs, int eject_flag)
             perror("FDEJECT");
         close(fd);
     }
-
-    return 0;
 }
 
 static BlockDriver bdrv_host_floppy = {
@@ -1331,7 +1329,7 @@ static int cdrom_is_inserted(BlockDriverState *bs)
     return 0;
 }
 
-static int cdrom_eject(BlockDriverState *bs, int eject_flag)
+static void cdrom_eject(BlockDriverState *bs, int eject_flag)
 {
     BDRVRawState *s = bs->opaque;
 
@@ -1342,8 +1340,6 @@ static int cdrom_eject(BlockDriverState *bs, int eject_flag)
         if (ioctl(s->fd, CDROMCLOSETRAY, NULL) < 0)
             perror("CDROMEJECT");
     }
-
-    return 0;
 }
 
 static void cdrom_set_locked(BlockDriverState *bs, int locked)
@@ -1443,12 +1439,12 @@ static int cdrom_is_inserted(BlockDriverState *bs)
     return raw_getlength(bs) > 0;
 }
 
-static int cdrom_eject(BlockDriverState *bs, int eject_flag)
+static void cdrom_eject(BlockDriverState *bs, int eject_flag)
 {
     BDRVRawState *s = bs->opaque;
 
     if (s->fd < 0)
-        return -ENOTSUP;
+        return;
 
     (void) ioctl(s->fd, CDIOCALLOW);
 
@@ -1460,9 +1456,7 @@ static int cdrom_eject(BlockDriverState *bs, int eject_flag)
             perror("CDIOCCLOSE");
     }
 
-    if (cdrom_reopen(bs) < 0)
-        return -ENOTSUP;
-    return 0;
+    cdrom_reopen(bs);
 }
 
 static void cdrom_set_locked(BlockDriverState *bs, int locked)
diff --git a/block/raw.c b/block/raw.c
index 1398a9c..cb6203e 100644
--- a/block/raw.c
+++ b/block/raw.c
@@ -75,9 +75,9 @@ static int raw_is_inserted(BlockDriverState *bs)
     return bdrv_is_inserted(bs->file);
 }
 
-static int raw_eject(BlockDriverState *bs, int eject_flag)
+static void raw_eject(BlockDriverState *bs, int eject_flag)
 {
-    return bdrv_eject(bs->file, eject_flag);
+    bdrv_eject(bs->file, eject_flag);
 }
 
 static void raw_set_locked(BlockDriverState *bs, int locked)
diff --git a/block_int.h b/block_int.h
index 69cf222..2d9edcf 100644
--- a/block_int.h
+++ b/block_int.h
@@ -110,7 +110,7 @@ struct BlockDriver {
     /* removable device specific */
     int (*bdrv_is_inserted)(BlockDriverState *bs);
     int (*bdrv_media_changed)(BlockDriverState *bs);
-    int (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
+    void (*bdrv_eject)(BlockDriverState *bs, int eject_flag);
     void (*bdrv_set_locked)(BlockDriverState *bs, int locked);
 
     /* to control generic scsi devices */
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (7 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() " Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-22 14:51   ` Kevin Wolf
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
                   ` (48 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Commit aea2a33c made bdrv_eject() obey the locked flag.  Correct for
medium eject (eject_flag set), incorrect for medium load (eject_flag
clear).  See MMC-5 Table 341 "Actions for Lock/Unlock/Eject".

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

diff --git a/block.c b/block.c
index 594bcab..6727274 100644
--- a/block.c
+++ b/block.c
@@ -2769,7 +2769,7 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag)
 {
     BlockDriver *drv = bs->drv;
 
-    if (bs->locked) {
+    if (eject_flag && bs->locked) {
         return -EBUSY;
     }
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (8 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:34   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 11/55] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
                   ` (47 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Drop WIN_SRST, it has same value as WIN_DEVICE_RESET.

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.

Turn unused macros into comments.  Mark vendor specific, retired,
obsolete.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/core.c     |    4 +-
 hw/ide/internal.h |  195 +++++++++++++++++++++++++++-------------------------
 2 files changed, 103 insertions(+), 96 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..1f807d4 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -55,139 +55,146 @@ typedef struct IDEDMAOps IDEDMAOps;
 #define IDE_CMD_RESET           0x04
 #define IDE_CMD_DISABLE_IRQ     0x02
 
-/* ATA/ATAPI Commands pre T13 Spec */
-#define WIN_NOP				0x00
-/*
- *	0x01->0x02 Reserved
- */
+/* ACS-2 T13/2015-D Table B.2 Command codes */
+/* NOP                                  0x00 */
+/* 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 */
+/* obsolete since ACS2                  0x26 */
 #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                  0x36 */
+/* SET MAX ADDRESS EXT                  0x37 */
 #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_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
- */
+#define WIN_SPECIFY                     0x91 /* set drive geometry translation, obsolete since ATA6 */
+/* DOWNLOAD MICROCODE                   0x92 */
+/* 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
+/* obsolete since ACS2                  0xA2 */
+/* 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 */
+/* obsolete since ACS2                  0xC7 */
 #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 */
+/* obsolete since ACS2                  0xCC */
 #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 */
+/* obsolete since ATA8                  0xDA */
+/* obsolete since ATA3, retired in ATA4 0xDB..0xDD */
+/* obsolete since ATA8                  0xDE..0xDF */
 #define WIN_STANDBYNOW1			0xE0
 #define WIN_IDLEIMMEDIATE		0xE1 /* force drive to become "ready" */
 #define WIN_STANDBY             	0xE2 /* Set device in Standby Mode */
 #define WIN_SETIDLE1			0xE3
-#define WIN_READ_BUFFER			0xE4 /* force read only 1 sector */
+/* READ BUFFER                          0xE4 */
 #define WIN_CHECKPOWERMODE1		0xE5
 #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 */
+/* WRITE BUFFER                         0xE8 */
+/* 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 */
+/* obsolete since ATA8                  0xED */
+/* 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 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 WIN_SECURITY_DISABLE		0xF6
+#define IBM_SENSE_CONDITION             0xF0 /* measure disk temperature, vendor specific */
+/* SECURITY SET PASS                    0xF1 */
+/* SECURITY UNLOCK                      0xF2 */
+/* SECURITY ERASE PREPARE               0xF3 */
+/* SECURITY ERASE UNIT                  0xF4 */
+/* SECURITY FREEZE LOCK                 0xF5 */
+#define CFA_WEAR_LEVEL                  0xF5 /* microdrives implement as NOP; not specified in T13! */
+/* 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
+/* SET MAX ADDRESS                      0xF9 */
+/* vendor specific                      0xFA..0xFF */
 
 /* set to 1 set disable mult support */
 #define MAX_MULT_SECTORS 16
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 11/55] ide: Clean up case label indentation in ide_exec_cmd()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (9 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-25 12:34   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
                   ` (46 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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.2.3

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

* [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (10 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 11/55] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 11:57   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
                   ` (45 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Must set the ATAPI device signature, see 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..f96ebf2 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);
             goto abort_cmd;
+        }
 	ide_cmd_lba48_transform(s, lba48);
         s->req_nb_sectors = 1;
         ide_sector_read(s);
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (11 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 11:58   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds Markus Armbruster
                   ` (44 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 f96ebf2..d1f7489 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.2.3

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

* [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (12 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 11:58   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
                   ` (43 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 d1f7489..c8cfd67 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.2.3

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

* [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (13 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 11:59   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state Markus Armbruster
                   ` (42 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

"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.2.3

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

* [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (14 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 11:59   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own Markus Armbruster
                   ` (41 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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    |    4 ++++
 hw/ide/internal.h |    1 +
 2 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 17fbef8..fee567b 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -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 1f807d4..5cf95c0 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -440,6 +440,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.2.3

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

* [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (15 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:00   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks Markus Armbruster
                   ` (40 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 fee567b..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;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (16 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:02   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
                   ` (39 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

Use a table to declare which drive kinds accept each command.

Limit READ_CAPACITY, READ_TOC, GET_CONFIGURATION to SCSI_CD, as per
SPC-4.

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/scsi-disk.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 62 insertions(+), 1 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a8c7372..c4643d0 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -991,6 +991,59 @@ illegal_request:
     return -1;
 }
 
+#define HD_OK (1u << SCSI_HD)
+#define CD_OK (1u << SCSI_CD)
+#define ALL_OK (HD_OK | CD_OK)
+
+/* See SPC-4 T10/1731-D Table D.2 Operation codes */
+uint8_t scsi_cmd_table[0x100] = {
+    [TEST_UNIT_READY]           = ALL_OK,
+    [REZERO_UNIT]               = ALL_OK,
+    [REQUEST_SENSE]             = ALL_OK,
+    /* FORMAT_UNIT not implemented, SPC-4 mandatory for HD */
+    [READ_6]                    = ALL_OK,
+    [WRITE_6]                   = ALL_OK,
+    [SEEK_6]                    = ALL_OK,
+    [INQUIRY]                   = ALL_OK,
+    [MODE_SELECT]               = ALL_OK,
+    [RESERVE]                   = ALL_OK,
+    [RELEASE]                   = ALL_OK,
+    [MODE_SENSE]                = ALL_OK,
+    [START_STOP]                = ALL_OK,
+    /* SEND DIAGNOSTIC not implemented, SPC-4 mandatory for HD */
+    [ALLOW_MEDIUM_REMOVAL]      = ALL_OK,
+    [READ_CAPACITY]             = CD_OK,
+    [READ_10]                   = ALL_OK,
+    [WRITE_10]                  = ALL_OK,
+    [SEEK_10]                   = ALL_OK,
+    [WRITE_VERIFY]              = ALL_OK,
+    [VERIFY]                    = ALL_OK,
+    [SYNCHRONIZE_CACHE]         = ALL_OK,
+    [READ_TOC]                  = CD_OK,
+    [GET_CONFIGURATION]         = CD_OK,
+    /* GET EVENT STATUS NOTIFICATION not implemented, SPC-4 mandatory for CD */
+    [MODE_SELECT_10]            = ALL_OK,
+    [RESERVE_10]                = ALL_OK,
+    [RELEASE_10]                = ALL_OK,
+    [MODE_SENSE_10]             = ALL_OK,
+    [READ_16]                   = ALL_OK,
+    [WRITE_16]                  = ALL_OK,
+    [WRITE_VERIFY_16]           = ALL_OK,
+    /* VERIFY(16) not implemented, WRITE_VERIFY(16) is, odd */
+    [WRITE_SAME_16]             = ALL_OK,
+    [SERVICE_ACTION_IN]         = ALL_OK,
+    [REPORT_LUNS]               = ALL_OK,
+    [READ_12]                   = ALL_OK,
+    [WRITE_12]                  = ALL_OK,
+    [WRITE_VERIFY_12]           = ALL_OK,
+    /* VERIFY(12) not implemented, WRITE_VERIFY(12) is, odd */
+};
+
+static bool scsi_cmd_permitted(SCSIDiskState *s, uint8_t cmd)
+{
+    return scsi_cmd_table[cmd] & (1u << s->drive_kind);
+}
+
 /* Execute a scsi command.  Returns the length of the data expected by the
    command.  This will be Positive for data transfers from the device
    (eg. disk reads), negative for transfers to the device (eg. disk writes),
@@ -1033,6 +1086,13 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
             return 0;
         }
     }
+
+    if (!scsi_cmd_permitted(s, command)) {
+        DPRINTF("SCSI command (%2.2x) not valid for device\n", command);
+        scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(INVALID_OPCODE));
+        return 0;
+    }
+
     switch (command) {
     case TEST_UNIT_READY:
     case REQUEST_SENSE:
@@ -1137,7 +1197,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
 
         break;
     default:
-        DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]);
+        /* should not be reachable */
+        BADF("Unknown SCSI command (%2.2x)\n", buf[0]);
         scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(INVALID_OPCODE));
         return 0;
     fail:
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (17 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:03   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state Markus Armbruster
                   ` (38 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 c4643d0..544ecef 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -817,6 +817,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->drive_kind == SCSI_CD && loej) {
+        bdrv_eject(s->bs, !start);
+    }
+}
+
 static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
 {
     SCSIRequest *req = &r->req;
@@ -870,10 +882,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
             goto illegal_request;
         break;
     case START_STOP:
-        if (s->drive_kind == SCSI_CD && (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.2.3

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

* [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (18 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:03   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
                   ` (37 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 544ecef..fc36327 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -74,6 +74,7 @@ struct SCSIDiskState
     char *version;
     char *serial;
     SCSISense sense;
+    bool tray_open;
     SCSIDriveKind drive_kind;
 };
 
@@ -826,6 +827,7 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
 
     if (s->drive_kind == SCSI_CD && loej) {
         bdrv_eject(s->bs, !start);
+        s->tray_open = !start;
     }
 }
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (19 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:10   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used Markus Armbruster
                   ` (36 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 |   12 +++++++++---
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/block.c b/block.c
index 6727274..2b1eb4d 100644
--- a/block.c
+++ b/block.c
@@ -2734,13 +2734,12 @@ void qemu_aio_release(void *p)
 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 fc36327..207a868 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -189,6 +189,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,
@@ -287,6 +290,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);
@@ -841,7 +847,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:
@@ -978,7 +984,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)
         break;
     case REZERO_UNIT:
         DPRINTF("Rezero Unit\n");
-        if (!bdrv_is_inserted(s->bs)) {
+        if (s->tray_open || !bdrv_is_inserted(s->bs)) {
             goto not_ready;
         }
         break;
@@ -990,7 +996,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.2.3

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

* [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (20 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:11   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block Markus Armbruster
                   ` (35 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 2b1eb4d..ba24bf1 100644
--- a/block.c
+++ b/block.c
@@ -2775,7 +2775,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 2d9edcf..b142dee 100644
--- a/block_int.h
+++ b/block_int.h
@@ -148,7 +148,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.2.3

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

* [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (21 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
       [not found]   ` <20110721112232.28405a1c@doriath>
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state Markus Armbruster
                   ` (34 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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

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

diff --git a/block.c b/block.c
index ba24bf1..6759066 100644
--- a/block.c
+++ b/block.c
@@ -761,6 +761,14 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
     }
 }
 
+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) {
@@ -1712,7 +1720,9 @@ 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"));
     }
-
+    if (qdict_get_try_bool(bs_dict, "ejected", false)) {
+        monitor_printf(mon, " ejected");
+    }
     if (qdict_haskey(bs_dict, "inserted")) {
         QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
 
@@ -1747,15 +1757,19 @@ 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, bs->removable,
                                     bs->locked);
+        bs_dict = qobject_to_qdict(bs_obj);
 
+        if (bdrv_dev_is_medium_ejected(bs)) {
+            qdict_put(bs_dict, "ejected", qbool_from_int(1));
+        }
         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 89f75e3..65a0115 100644
--- a/block.h
+++ b/block.h
@@ -36,6 +36,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);
+    /*
      * Runs when the size changed (e.g. monitor command block_resize)
      */
     void (*resize_cb)(void *opaque);
@@ -92,6 +97,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_ejected(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/hw/ide/core.c b/hw/ide/core.c
index c8cfd67..b07a4d7 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_medium_ejected(void *opaque)
+{
+    return ((IDEState *)opaque)->tray_open;
+}
+
 static const BlockDevOps ide_cd_block_ops = {
     .change_media_cb = ide_cd_change_cb,
+    .is_medium_ejected = ide_cd_medium_ejected,
 };
 
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 207a868..ff52d87 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1261,6 +1261,15 @@ static void scsi_destroy(SCSIDevice *dev)
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
+static bool scsi_cd_is_medium_ejected(void *opaque)
+{
+    return ((SCSIDiskState *)opaque)->tray_open;
+}
+
+static const BlockDevOps scsi_cd_block_ops = {
+    .is_medium_ejected = scsi_cd_is_medium_ejected,
+};
+
 static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
 {
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
@@ -1294,6 +1303,7 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
     }
 
     if (kind == SCSI_CD) {
+        bdrv_set_dev_ops(s->bs, &scsi_cd_block_ops, s);
         s->qdev.blocksize = 2048;
     } else {
         s->qdev.blocksize = s->qdev.conf.logical_block_size;
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 92c5c3a..cc5d30f 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -1070,6 +1070,7 @@ 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": present and 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.2.3

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

* [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (22 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:13   ` Christoph Hellwig
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
                   ` (33 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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    |    1 +
 hw/ide/internal.h |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 08e1a7a..8634e6b 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -820,6 +820,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 5cf95c0..12f80de 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -441,6 +441,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.2.3

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

* [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (23 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state Markus Armbruster
@ 2011-07-20 16:23 ` Markus Armbruster
  2011-07-26 12:14   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state Markus Armbruster
                   ` (32 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:23 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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

diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 8634e6b..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;
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (24 preceding siblings ...)
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:14   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
                   ` (31 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index ff52d87..a220426 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -75,6 +75,7 @@ struct SCSIDiskState
     char *serial;
     SCSISense sense;
     bool tray_open;
+    bool tray_locked;
     SCSIDriveKind drive_kind;
 };
 
@@ -893,6 +894,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:
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (25 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:14   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 28/55] block: Leave enforcing tray lock to device models Markus Armbruster
                   ` (30 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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

diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a220426..aac63b6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -676,7 +676,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 */
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 28/55] block: Leave enforcing tray lock to device models
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (26 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
       [not found]   ` <20110721113051.4ea99b04@doriath>
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 29/55] block: Drop medium lock tracking, ask device models instead Markus Armbruster
                   ` (29 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 6759066..70928af 100644
--- a/block.c
+++ b/block.c
@@ -2778,18 +2778,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 65a0115..7cc7919 100644
--- a/block.h
+++ b/block.h
@@ -209,7 +209,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 aac63b6..a4ed499 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -833,6 +833,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     bool loej = req->cmd.buf[4] & 2;
 
     if (s->drive_kind == SCSI_CD && loej) {
+        if (!start && s->tray_locked) {
+            return;
+        }
         bdrv_eject(s->bs, !start);
         s->tray_open = !start;
     }
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 29/55] block: Drop medium lock tracking, ask device models instead
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (27 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 28/55] block: Leave enforcing tray lock to device models Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 30/55] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
                   ` (28 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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        |    7 ++++++-
 block_int.h    |    1 -
 blockdev.c     |    2 +-
 hw/ide/core.c  |    6 ++++++
 hw/scsi-disk.c |    6 ++++++
 6 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/block.c b/block.c
index 70928af..af9bbb2 100644
--- a/block.c
+++ b/block.c
@@ -776,6 +776,14 @@ static void bdrv_dev_resize_cb(BlockDriverState *bs)
     }
 }
 
+int 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 0;
+}
+
 /*
  * Run consistency checks on an image
  *
@@ -1762,7 +1770,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));
         bs_dict = qobject_to_qdict(bs_obj);
 
         if (bdrv_dev_is_medium_ejected(bs)) {
@@ -2787,11 +2795,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).
@@ -2802,7 +2805,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 7cc7919..f2f8dad 100644
--- a/block.h
+++ b/block.h
@@ -41,6 +41,11 @@ typedef struct BlockDevOps {
      */
     bool (*is_medium_ejected)(void *opaque);
     /*
+     * Is the virtual medium locked into the device?
+     * Null means device doesn't have 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);
@@ -98,6 +103,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs);
 void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops,
                       void *opaque);
 bool bdrv_dev_is_medium_ejected(BlockDriverState *bs);
+int 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,
@@ -207,7 +213,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 b142dee..a049f1a 100644
--- a/block_int.h
+++ b/block_int.h
@@ -147,7 +147,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 13a9b41..4c58128 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 b07a4d7..35beb93 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1774,9 +1774,15 @@ 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;
+}
+
 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,
 };
 
 int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index a4ed499..f804739 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1271,8 +1271,14 @@ 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;
+}
+
 static const BlockDevOps scsi_cd_block_ops = {
     .is_medium_ejected = scsi_cd_is_medium_ejected,
+    .is_medium_locked = scsi_cd_is_medium_locked,
 };
 
 static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 30/55] block: Rename bdrv_set_locked() to bdrv_lock_medium()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (28 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 29/55] block: Drop medium lock tracking, ask device models instead Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
                   ` (27 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 af9bbb2..c12f037 100644
--- a/block.c
+++ b/block.c
@@ -2799,14 +2799,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 f2f8dad..b034d51 100644
--- a/block.h
+++ b/block.h
@@ -213,7 +213,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 e8a2fc2..c18778f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1342,7 +1342,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;
 
@@ -1378,7 +1378,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,
@@ -1459,7 +1459,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;
 
@@ -1497,7 +1497,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 a049f1a..7d49a6e 100644
--- a/block_int.h
+++ b/block_int.h
@@ -111,7 +111,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 f804739..97f6d41 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -898,7 +898,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:
         /* The normal LEN field for this command is zero.  */
diff --git a/trace-events b/trace-events
index bebf612..9be7242 100644
--- a/trace-events
+++ b/trace-events
@@ -54,7 +54,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"
 
 # hw/virtio-blk.c
 disable virtio_blk_req_complete(void *req, int status) "req %p status %d"
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (29 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 30/55] block: Rename bdrv_set_locked() to bdrv_lock_medium() Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:16   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
                   ` (26 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 12f80de..df8887a 100644
--- a/hw/ide/internal.h
+++ b/hw/ide/internal.h
@@ -527,6 +527,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 d9b8f24..97ccbe8 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -87,9 +87,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.2.3

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

* [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (30 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:16   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
                   ` (25 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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.2.3

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

* [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (31 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:17   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
                   ` (24 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 35beb93..1c84b68 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1845,6 +1845,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 97ccbe8..50188a9 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -178,6 +178,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);
@@ -185,6 +191,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_PROP_UINT32("unit", IDEDrive, dev.unit, -1), \
     DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf),        \
@@ -208,6 +224,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(),
@@ -218,6 +235,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.2.3

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

* [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (32 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:17   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
                   ` (23 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 ad6a730..169a022 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -440,6 +440,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
@@ -465,6 +470,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 97f6d41..b9de4df 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -825,7 +825,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);
@@ -833,12 +833,17 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
     bool loej = req->cmd.buf[4] & 2;
 
     if (s->drive_kind == SCSI_CD && 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)
@@ -894,7 +899,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 c1dca35..f6b6bc1 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -116,6 +116,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 */
@@ -126,6 +128,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.2.3

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

* [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (33 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:17   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 36/55] ide: Give vmstate structs internal linkage where possible Markus Armbruster
                   ` (22 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 b9de4df..553d8c6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1270,6 +1270,9 @@ static void scsi_destroy(SCSIDevice *dev)
     SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
 
     scsi_device_purge_requests(&s->qdev);
+    if (s->drive_kind == SCSI_CD) {
+        bdrv_lock_medium(s->qdev.conf.bs, 0);
+    }
     blockdev_mark_auto_del(s->qdev.conf.bs);
 }
 
@@ -1332,6 +1335,10 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
     s->qdev.type = TYPE_DISK;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
     bdrv_set_removable(s->bs, kind == SCSI_CD);
+    if (kind == SCSI_CD) {
+        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.2.3

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

* [Qemu-devel] [PATCH 36/55] ide: Give vmstate structs internal linkage where possible
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (34 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 37/55] ide/atapi: Preserve tray state on migration Markus Armbruster
                   ` (21 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 1c84b68..709645e 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2057,7 +2057,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,
@@ -2069,7 +2069,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,
@@ -2131,7 +2131,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.2.3

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

* [Qemu-devel] [PATCH 37/55] ide/atapi: Preserve tray state on migration
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (35 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 36/55] ide: Give vmstate structs internal linkage where possible Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 38/55] scsi-disk: " Markus Armbruster
                   ` (20 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 709645e..90ad497 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -2042,6 +2042,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;
@@ -2069,6 +2085,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,
@@ -2123,6 +2152,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.2.3

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

* [Qemu-devel] [PATCH 38/55] scsi-disk: Preserve tray state on migration
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (36 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 37/55] ide/atapi: Preserve tray state on migration Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
                   ` (19 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 553d8c6..ad63814 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1368,6 +1368,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)
     return scsi_initfn(dev, kind);
 }
 
+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),         \
@@ -1400,6 +1433,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,
@@ -1420,6 +1454,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.2.3

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

* [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (37 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 38/55] scsi-disk: " Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:18   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models Markus Armbruster
                   ` (18 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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.2.3

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

* [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (38 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:19   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 41/55] fdc: Make media change detection more robust Markus Armbruster
                   ` (17 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 c12f037..2225be5 100644
--- a/block.c
+++ b/block.c
@@ -637,7 +637,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);
     }
 
@@ -674,7 +673,6 @@ void bdrv_close(BlockDriverState *bs)
             bdrv_close(bs->file);
         }
 
-        bs->media_changed = 1;
         bdrv_dev_change_media_cb(bs);
     }
 }
@@ -1542,7 +1540,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;
@@ -2765,22 +2762,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 7d49a6e..d8688b8 100644
--- a/block_int.h
+++ b/block_int.h
@@ -164,7 +164,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.2.3

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

* [Qemu-devel] [PATCH 41/55] fdc: Make media change detection more robust
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (39 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all() Markus Armbruster
                   ` (16 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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.2.3

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

* [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (40 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 41/55] fdc: Make media change detection more robust Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 12:19   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 43/55] savevm: Include writable devices with removable media Markus Armbruster
                   ` (15 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 2225be5..f233062 100644
--- a/block.c
+++ b/block.c
@@ -1626,8 +1626,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.2.3

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

* [Qemu-devel] [PATCH 43/55] savevm: Include writable devices with removable media
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (41 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all() Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
                   ` (14 subsequent siblings)
  57 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 f233062..9591c8a 100644
--- a/block.c
+++ b/block.c
@@ -1958,7 +1958,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 8139bc7..1f03987 100644
--- a/savevm.c
+++ b/savevm.c
@@ -1913,7 +1913,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;
         }
 
@@ -2033,7 +2033,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.2.3

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

* [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (42 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 43/55] savevm: Include writable devices with removable media Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-30  2:24   ` andrzej zaborowski
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable" Markus Armbruster
                   ` (13 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 006f7a9..c743ae0 100644
--- a/hw/spitz.c
+++ b/hw/spitz.c
@@ -706,17 +706,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.2.3

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

* [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable"
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (43 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-21 17:33   ` Luiz Capitulino
  2011-07-26 13:03   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 46/55] block: Drop BlockDriverState member removable Markus Armbruster
                   ` (12 subsequent siblings)
  57 siblings, 2 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 9591c8a..b394f17 100644
--- a/block.c
+++ b/block.c
@@ -750,6 +750,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)
@@ -759,6 +762,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
     }
 }
 
+int 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) {
@@ -1198,7 +1206,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);
         }
@@ -1483,11 +1491,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;
@@ -1765,7 +1768,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));
         bs_dict = qobject_to_qdict(bs_obj);
 
diff --git a/block.h b/block.h
index b034d51..f6fa3d0 100644
--- a/block.h
+++ b/block.h
@@ -33,6 +33,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);
     /*
@@ -102,6 +103,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);
+int bdrv_dev_has_removable_media(BlockDriverState *bs);
 bool bdrv_dev_is_medium_ejected(BlockDriverState *bs);
 int bdrv_dev_is_medium_locked(BlockDriverState *bs);
 int bdrv_read(BlockDriverState *bs, int64_t sector_num,
@@ -207,7 +209,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 4c58128..06a82d3 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 ad63814..ae194c5 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1276,6 +1276,10 @@ 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_ejected(void *opaque)
 {
     return ((SCSIDiskState *)opaque)->tray_open;
@@ -1287,6 +1291,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,
 };
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 46/55] block: Drop BlockDriverState member removable
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (44 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable" Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:03   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 47/55] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
                   ` (11 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 b394f17..925861f 100644
--- a/block.c
+++ b/block.c
@@ -1483,14 +1483,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 f6fa3d0..b56dae6 100644
--- a/block.h
+++ b/block.h
@@ -208,7 +208,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 d8688b8..4bc91cb 100644
--- a/block_int.h
+++ b/block_int.h
@@ -146,7 +146,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 06a82d3..9284afd 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 90ad497..2bde2b8 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1844,7 +1844,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 ae194c5..f36f529 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1339,7 +1339,6 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
 
     s->qdev.type = TYPE_DISK;
     qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);
-    bdrv_set_removable(s->bs, kind == SCSI_CD);
     if (kind == SCSI_CD) {
         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 8e59c7e..24ca9ff 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -533,7 +533,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.2.3

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

* [Qemu-devel] [PATCH 47/55] block: Move BlockConf & friends from block_int.h to block.h
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (45 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 46/55] block: Drop BlockDriverState member removable Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:04   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 48/55] hw: Trim superfluous #include "block_int.h" Markus Armbruster
                   ` (10 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 b56dae6..b6eaaba 100644
--- a/block.h
+++ b/block.h
@@ -326,4 +326,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 4bc91cb..7e74d01 100644
--- a/block_int.h
+++ b/block_int.h
@@ -219,39 +219,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 2bde2b8..7301108 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 df8887a..d467b04 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 f36f529..9d6968c 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 f6b6bc1..aa3aeff 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.2.3

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

* [Qemu-devel] [PATCH 48/55] hw: Trim superfluous #include "block_int.h"
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (46 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 47/55] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:04   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
                   ` (9 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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/piix.c       |    1 -
 hw/ide/via.c        |    1 -
 hw/lsi53c895a.c     |    1 -
 11 files changed, 0 insertions(+), 11 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 054e073..6f8c175 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/piix.c b/hw/ide/piix.c
index 84f72b0..a0bef42 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"
 
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 940b43a..0930519 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.2.3

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

* [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (47 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 48/55] hw: Trim superfluous #include "block_int.h" Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:05   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 50/55] block: New bdrv_set_buffer_alignment() Markus Armbruster
                   ` (8 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 b6eaaba..8f52abb 100644
--- a/block.h
+++ b/block.h
@@ -264,6 +264,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 7e74d01..768c842 100644
--- a/block_int.h
+++ b/block_int.h
@@ -213,8 +213,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 4dc9047..fdd87b0 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.2.3

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

* [Qemu-devel] [PATCH 50/55] block: New bdrv_set_buffer_alignment()
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (48 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:06   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 51/55] block: Reset buffer alignment on detach Markus Armbruster
                   ` (7 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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  |    3 +--
 hw/virtio-blk.c |    3 +--
 5 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/block.c b/block.c
index 925861f..e9b911b 100644
--- a/block.c
+++ b/block.c
@@ -428,7 +428,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);
@@ -2819,7 +2818,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 8f52abb..c596b4c 100644
--- a/block.h
+++ b/block.h
@@ -264,6 +264,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 7301108..bfa1162 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 9d6968c..1bfdfdd 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -37,7 +37,6 @@ 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
@@ -1336,7 +1335,7 @@ static int scsi_initfn(SCSIDevice *dev, SCSIDriveKind kind)
         s->qdev.blocksize = s->qdev.conf.logical_block_size;
     }
     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 = TYPE_DISK;
     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.2.3

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

* [Qemu-devel] [PATCH 51/55] block: Reset buffer alignment on detach
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (49 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 50/55] block: New bdrv_set_buffer_alignment() Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:06   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h Markus Armbruster
                   ` (6 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 e9b911b..b94864c 100644
--- a/block.c
+++ b/block.c
@@ -736,6 +736,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.2.3

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

* [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (50 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 51/55] block: Reset buffer alignment on detach Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:07   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 53/55] nbd: Clean up use of block_int.h Markus Armbruster
                   ` (5 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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

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

diff --git a/block.h b/block.h
index c596b4c..be5ed0a 100644
--- a/block.h
+++ b/block.h
@@ -140,8 +140,23 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res);
 /* async block I/O */
 typedef struct BlockDriverAIOCB BlockDriverAIOCB;
 typedef void BlockDriverCompletionFunc(void *opaque, int ret);
+typedef struct AIOPool {
+    void (*cancel)(BlockDriverAIOCB *acb);
+    int aiocb_size;
+    BlockDriverAIOCB *free_aiocb;
+} AIOPool;
+struct BlockDriverAIOCB {
+    AIOPool *pool;
+    BlockDriverState *bs;
+    BlockDriverCompletionFunc *cb;
+    void *opaque;
+    BlockDriverAIOCB *next;
+};
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
                                      int sector_num);
+void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
+                   BlockDriverCompletionFunc *cb, void *opaque);
+void qemu_aio_release(void *p);
 BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
                                  QEMUIOVector *iov, int nb_sectors,
                                  BlockDriverCompletionFunc *cb, void *opaque);
diff --git a/block_int.h b/block_int.h
index 768c842..9f1121d 100644
--- a/block_int.h
+++ b/block_int.h
@@ -40,12 +40,6 @@
 #define BLOCK_OPT_TABLE_SIZE    "table_size"
 #define BLOCK_OPT_PREALLOC      "preallocation"
 
-typedef struct AIOPool {
-    void (*cancel)(BlockDriverAIOCB *acb);
-    int aiocb_size;
-    BlockDriverAIOCB *free_aiocb;
-} AIOPool;
-
 struct BlockDriver {
     const char *format_name;
     int instance_size;
@@ -199,20 +193,8 @@ struct BlockDriverState {
     void *private;
 };
 
-struct BlockDriverAIOCB {
-    AIOPool *pool;
-    BlockDriverState *bs;
-    BlockDriverCompletionFunc *cb;
-    void *opaque;
-    BlockDriverAIOCB *next;
-};
-
 void get_tmp_filename(char *filename, int size);
 
-void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
-                   BlockDriverCompletionFunc *cb, void *opaque);
-void qemu_aio_release(void *p);
-
 #ifdef _WIN32
 int is_windows_drive(const char *filename);
 #endif
diff --git a/hw/ide/core.c b/hw/ide/core.c
index bfa1162..cac3518 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -30,7 +30,6 @@
 #include "sysemu.h"
 #include "dma.h"
 #include "blockdev.h"
-#include "block_int.h"
 
 #include <hw/ide/internal.h>
 
-- 
1.7.2.3

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

* [Qemu-devel] [PATCH 53/55] nbd: Clean up use of block_int.h
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (51 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:07   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 54/55] block: New change_media_cb() parameter load Markus Armbruster
                   ` (4 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah


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 0dcd86b..c40100d 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.2.3

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

* [Qemu-devel] [PATCH 54/55] block: New change_media_cb() parameter load
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (52 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 53/55] nbd: Clean up use of block_int.h Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:08   ` Christoph Hellwig
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 55/55] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
                   ` (3 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 b94864c..53a433a 100644
--- a/block.c
+++ b/block.c
@@ -43,7 +43,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);
@@ -636,7 +636,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;
@@ -672,7 +672,7 @@ void bdrv_close(BlockDriverState *bs)
             bdrv_close(bs->file);
         }
 
-        bdrv_dev_change_media_cb(bs);
+        bdrv_dev_change_media_cb(bs, false);
     }
 }
 
@@ -755,10 +755,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);
     }
 }
 
@@ -1535,7 +1535,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 be5ed0a..c99de24 100644
--- a/block.h
+++ b/block.h
@@ -31,11 +31,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 cac3518..05ed7e9 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -758,7 +758,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 1bfdfdd..4f28e9c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1276,7 +1276,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 fdd87b0..31b83de 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -421,7 +421,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.2.3

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

* [Qemu-devel] [PATCH 55/55] ide/atapi scsi-disk: Make monitor eject -f, then change work
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (53 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 54/55] block: New change_media_cb() parameter load Markus Armbruster
@ 2011-07-20 16:24 ` Markus Armbruster
  2011-07-26 13:08   ` Christoph Hellwig
  2011-07-23  3:15 ` [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Amit Shah
                   ` (2 subsequent siblings)
  57 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-20 16:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, lcapitulino, amit.shah

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 9284afd..197f57f 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 05ed7e9..77eef58 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -763,6 +763,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 4f28e9c..3d245fe 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -1278,6 +1278,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.2.3

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

* Re: [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void
       [not found]   ` <20110721111134.787a83af@doriath>
@ 2011-07-21 15:07     ` Markus Armbruster
  2011-07-21 16:34       ` Luiz Capitulino
  2011-07-22 14:36       ` Kevin Wolf
  0 siblings, 2 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-21 15:07 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Wed, 20 Jul 2011 18:23:41 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> The only caller is bdrv_set_locked(), and it ignores the value.
>> 
>> Callees always return 0, except for FreeBSD's cdrom_set_locked(),
>> which returns -ENOTSUP when the device is in a terminally wedged
>> state.
>
> The fact that we're ignoring ioctl() failures caught my attention. Is it
> because the state we store in bs->locked is what really matters?
>
> Otherwise the right thing to do would be to propagate the error and
> change callers to handle it.

The only caller is bdrv_set_locked().  Which can't handle it, so it
would have to pass it on.

The purpose of bdrv_set_locked() is to synchronize the physical lock (if
any) with the virtual lock.  Worst that can happen is the physical lock
fails to track the virtual one.

bdrv_set_locked()'s callers are device models: ide-cd and scsi-cd.  Each
one calls it in four places (with all my patches applied):

* Device init: can return failure.  Failure makes QEMU refuse to start
  (-device cold plug), or hot plug fail (device_add).

* Device exit: can't return failure.

* Device post migration: can return failure, makes migration fail.
  Given the choice, I figure I'd pick an incorrect physical tray lock
  over a failed migration.

* Guest PREVENT ALLOW MEDIUM REMOVAL: can send error reply to guest.
  Recommended errors according to MMC-5 are "unit attention errors" (not
  a good match), "CDB or parameter list validation errors" (worse) and
  "hardware failures" (no good choices there either).

I doubt adding the error handling is worth our while, but feel free to
send patches.

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

* Re: [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block
       [not found]   ` <20110721112232.28405a1c@doriath>
@ 2011-07-21 15:08     ` Markus Armbruster
  2011-07-21 16:38       ` Luiz Capitulino
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-21 15:08 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Wed, 20 Jul 2011 18:23:57 +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>
>> ---
>>  block.c         |   18 ++++++++++++++++--
>>  block.h         |    6 ++++++
>>  hw/ide/core.c   |    6 ++++++
>>  hw/scsi-disk.c  |   10 ++++++++++
>>  qmp-commands.hx |    1 +
>>  5 files changed, 39 insertions(+), 2 deletions(-)
>> 
>> diff --git a/block.c b/block.c
>> index ba24bf1..6759066 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -761,6 +761,14 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
>>      }
>>  }
>>  
>> +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) {
>> @@ -1712,7 +1720,9 @@ 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"));
>>      }
>> -
>> +    if (qdict_get_try_bool(bs_dict, "ejected", false)) {
>> +        monitor_printf(mon, " ejected");
>> +    }
>>      if (qdict_haskey(bs_dict, "inserted")) {
>>          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
>>  
>> @@ -1747,15 +1757,19 @@ 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, bs->removable,
>>                                      bs->locked);
>> +        bs_dict = qobject_to_qdict(bs_obj);
>>  
>> +        if (bdrv_dev_is_medium_ejected(bs)) {
>> +            qdict_put(bs_dict, "ejected", qbool_from_int(1));
>> +        }
>
> I'd expect 'ejected' to be always present. It's a bool afterall, so it's
> either true or false.
>
> But I see that "ejected=false" might not be ideal. What about calling it
> "inserted" then?

"inserted=true" for disks looks odd to me, but whatever floats your boat
:)

> Also misses QMP documentation.

Last patch hunk.

>>          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/qmp-commands.hx b/qmp-commands.hx
>> index 92c5c3a..cc5d30f 100644
>> --- a/qmp-commands.hx
>> +++ b/qmp-commands.hx
>> @@ -1070,6 +1070,7 @@ 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": present and 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] 145+ messages in thread

* Re: [Qemu-devel] [PATCH 28/55] block: Leave enforcing tray lock to device models
       [not found]   ` <20110721113051.4ea99b04@doriath>
@ 2011-07-21 15:16     ` Markus Armbruster
  2011-07-21 16:40       ` Luiz Capitulino
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-21 15:16 UTC (permalink / raw)
  To: Luiz Capitulino
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Wed, 20 Jul 2011 18:24:02 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> 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.
>
> But we're supposed to return an error to the user/client if we're unable
> to eject, aren't we?

Same story as for bdrv_set_locked() [PATCH 07/55]: the purpose is to
synchronize the physical tray with the virtual one.  Errors would have
to be propagated up into device model init, post migration and guest
START STOP UNIT.  What error to report to the guest?  Hardware failure?

As with bdrv_set_locked(), I'm not removing any error handling.  I don't
add any either.  The series is long enough...

> (one more question below)

Where?

>> 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 6759066..70928af 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -2778,18 +2778,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 65a0115..7cc7919 100644
>> --- a/block.h
>> +++ b/block.h
>> @@ -209,7 +209,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 aac63b6..a4ed499 100644
>> --- a/hw/scsi-disk.c
>> +++ b/hw/scsi-disk.c
>> @@ -833,6 +833,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
>>      bool loej = req->cmd.buf[4] & 2;
>>  
>>      if (s->drive_kind == SCSI_CD && loej) {
>> +        if (!start && s->tray_locked) {
>> +            return;
>> +        }
>>          bdrv_eject(s->bs, !start);
>>          s->tray_open = !start;
>>      }

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

* Re: [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void
  2011-07-21 15:07     ` Markus Armbruster
@ 2011-07-21 16:34       ` Luiz Capitulino
  2011-07-22 14:36       ` Kevin Wolf
  1 sibling, 0 replies; 145+ messages in thread
From: Luiz Capitulino @ 2011-07-21 16:34 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

On Thu, 21 Jul 2011 17:07:17 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Wed, 20 Jul 2011 18:23:41 +0200
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> The only caller is bdrv_set_locked(), and it ignores the value.
> >> 
> >> Callees always return 0, except for FreeBSD's cdrom_set_locked(),
> >> which returns -ENOTSUP when the device is in a terminally wedged
> >> state.
> >
> > The fact that we're ignoring ioctl() failures caught my attention. Is it
> > because the state we store in bs->locked is what really matters?
> >
> > Otherwise the right thing to do would be to propagate the error and
> > change callers to handle it.
> 
> The only caller is bdrv_set_locked().  Which can't handle it, so it
> would have to pass it on.
> 
> The purpose of bdrv_set_locked() is to synchronize the physical lock (if
> any) with the virtual lock.  Worst that can happen is the physical lock
> fails to track the virtual one.
> 
> bdrv_set_locked()'s callers are device models: ide-cd and scsi-cd.  Each
> one calls it in four places (with all my patches applied):
> 
> * Device init: can return failure.  Failure makes QEMU refuse to start
>   (-device cold plug), or hot plug fail (device_add).
> 
> * Device exit: can't return failure.
> 
> * Device post migration: can return failure, makes migration fail.
>   Given the choice, I figure I'd pick an incorrect physical tray lock
>   over a failed migration.
> 
> * Guest PREVENT ALLOW MEDIUM REMOVAL: can send error reply to guest.
>   Recommended errors according to MMC-5 are "unit attention errors" (not
>   a good match), "CDB or parameter list validation errors" (worse) and
>   "hardware failures" (no good choices there either).
> 
> I doubt adding the error handling is worth our while, but feel free to
> send patches.

I can't tell if the problems you mention above (physical lock out of sync
with the virtual one and the post migration) will turn out to be real
issues. If they do, we'll have to fix it.

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

* Re: [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block
  2011-07-21 15:08     ` Markus Armbruster
@ 2011-07-21 16:38       ` Luiz Capitulino
  2011-07-21 17:30         ` Luiz Capitulino
  0 siblings, 1 reply; 145+ messages in thread
From: Luiz Capitulino @ 2011-07-21 16:38 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

On Thu, 21 Jul 2011 17:08:56 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Wed, 20 Jul 2011 18:23:57 +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>
> >> ---
> >>  block.c         |   18 ++++++++++++++++--
> >>  block.h         |    6 ++++++
> >>  hw/ide/core.c   |    6 ++++++
> >>  hw/scsi-disk.c  |   10 ++++++++++
> >>  qmp-commands.hx |    1 +
> >>  5 files changed, 39 insertions(+), 2 deletions(-)
> >> 
> >> diff --git a/block.c b/block.c
> >> index ba24bf1..6759066 100644
> >> --- a/block.c
> >> +++ b/block.c
> >> @@ -761,6 +761,14 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
> >>      }
> >>  }
> >>  
> >> +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) {
> >> @@ -1712,7 +1720,9 @@ 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"));
> >>      }
> >> -
> >> +    if (qdict_get_try_bool(bs_dict, "ejected", false)) {
> >> +        monitor_printf(mon, " ejected");
> >> +    }
> >>      if (qdict_haskey(bs_dict, "inserted")) {
> >>          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
> >>  
> >> @@ -1747,15 +1757,19 @@ 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, bs->removable,
> >>                                      bs->locked);
> >> +        bs_dict = qobject_to_qdict(bs_obj);
> >>  
> >> +        if (bdrv_dev_is_medium_ejected(bs)) {
> >> +            qdict_put(bs_dict, "ejected", qbool_from_int(1));
> >> +        }
> >
> > I'd expect 'ejected' to be always present. It's a bool afterall, so it's
> > either true or false.
> >
> > But I see that "ejected=false" might not be ideal. What about calling it
> > "inserted" then?
> 
> "inserted=true" for disks looks odd to me, but whatever floats your boat
> :)

I meant always present for removable media. Maybe "media-inserted" is even
better.

> 
> > Also misses QMP documentation.
> 
> Last patch hunk.

Ah, thanks, missed it.

> 
> >>          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/qmp-commands.hx b/qmp-commands.hx
> >> index 92c5c3a..cc5d30f 100644
> >> --- a/qmp-commands.hx
> >> +++ b/qmp-commands.hx
> >> @@ -1070,6 +1070,7 @@ 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": present and 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] 145+ messages in thread

* Re: [Qemu-devel] [PATCH 28/55] block: Leave enforcing tray lock to device models
  2011-07-21 15:16     ` Markus Armbruster
@ 2011-07-21 16:40       ` Luiz Capitulino
  0 siblings, 0 replies; 145+ messages in thread
From: Luiz Capitulino @ 2011-07-21 16:40 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

On Thu, 21 Jul 2011 17:16:13 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Wed, 20 Jul 2011 18:24:02 +0200
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> 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.
> >
> > But we're supposed to return an error to the user/client if we're unable
> > to eject, aren't we?
> 
> Same story as for bdrv_set_locked() [PATCH 07/55]: the purpose is to
> synchronize the physical tray with the virtual one.  Errors would have
> to be propagated up into device model init, post migration and guest
> START STOP UNIT.  What error to report to the guest?  Hardware failure?
> 
> As with bdrv_set_locked(), I'm not removing any error handling.  I don't
> add any either.  The series is long enough...

I see.

> 
> > (one more question below)
> 
> Where?

This was to check if you'd find it where it's hidden.


Kidding :) The question I had was answered by a later patch, but I forgot
to remove the comment.

> 
> >> 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 6759066..70928af 100644
> >> --- a/block.c
> >> +++ b/block.c
> >> @@ -2778,18 +2778,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 65a0115..7cc7919 100644
> >> --- a/block.h
> >> +++ b/block.h
> >> @@ -209,7 +209,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 aac63b6..a4ed499 100644
> >> --- a/hw/scsi-disk.c
> >> +++ b/hw/scsi-disk.c
> >> @@ -833,6 +833,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)
> >>      bool loej = req->cmd.buf[4] & 2;
> >>  
> >>      if (s->drive_kind == SCSI_CD && loej) {
> >> +        if (!start && s->tray_locked) {
> >> +            return;
> >> +        }
> >>          bdrv_eject(s->bs, !start);
> >>          s->tray_open = !start;
> >>      }
> 

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

* Re: [Qemu-devel] [PATCH 23/55] block: Show whether the guest ejected the medium in info block
  2011-07-21 16:38       ` Luiz Capitulino
@ 2011-07-21 17:30         ` Luiz Capitulino
  0 siblings, 0 replies; 145+ messages in thread
From: Luiz Capitulino @ 2011-07-21 17:30 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

On Thu, 21 Jul 2011 13:38:46 -0300
Luiz Capitulino <lcapitulino@redhat.com> wrote:

> On Thu, 21 Jul 2011 17:08:56 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
> 
> > Luiz Capitulino <lcapitulino@redhat.com> writes:
> > 
> > > On Wed, 20 Jul 2011 18:23:57 +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>
> > >> ---
> > >>  block.c         |   18 ++++++++++++++++--
> > >>  block.h         |    6 ++++++
> > >>  hw/ide/core.c   |    6 ++++++
> > >>  hw/scsi-disk.c  |   10 ++++++++++
> > >>  qmp-commands.hx |    1 +
> > >>  5 files changed, 39 insertions(+), 2 deletions(-)
> > >> 
> > >> diff --git a/block.c b/block.c
> > >> index ba24bf1..6759066 100644
> > >> --- a/block.c
> > >> +++ b/block.c
> > >> @@ -761,6 +761,14 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
> > >>      }
> > >>  }
> > >>  
> > >> +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) {
> > >> @@ -1712,7 +1720,9 @@ 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"));
> > >>      }
> > >> -
> > >> +    if (qdict_get_try_bool(bs_dict, "ejected", false)) {
> > >> +        monitor_printf(mon, " ejected");
> > >> +    }
> > >>      if (qdict_haskey(bs_dict, "inserted")) {
> > >>          QDict *qdict = qobject_to_qdict(qdict_get(bs_dict, "inserted"));
> > >>  
> > >> @@ -1747,15 +1757,19 @@ 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, bs->removable,
> > >>                                      bs->locked);
> > >> +        bs_dict = qobject_to_qdict(bs_obj);
> > >>  
> > >> +        if (bdrv_dev_is_medium_ejected(bs)) {
> > >> +            qdict_put(bs_dict, "ejected", qbool_from_int(1));
> > >> +        }
> > >
> > > I'd expect 'ejected' to be always present. It's a bool afterall, so it's
> > > either true or false.
> > >
> > > But I see that "ejected=false" might not be ideal. What about calling it
> > > "inserted" then?
> > 
> > "inserted=true" for disks looks odd to me, but whatever floats your boat
> > :)
> 
> I meant always present for removable media. Maybe "media-inserted" is even
> better.

Given we already have a 'inserted' key, we could call it "media-ejected" which
is always present for devices that support it.

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

* Re: [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable"
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable" Markus Armbruster
@ 2011-07-21 17:33   ` Luiz Capitulino
  2011-07-26 13:03   ` Christoph Hellwig
  1 sibling, 0 replies; 145+ messages in thread
From: Luiz Capitulino @ 2011-07-21 17:33 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel, amit.shah

On Wed, 20 Jul 2011 18:24:19 +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 9591c8a..b394f17 100644
> --- a/block.c
> +++ b/block.c
> @@ -750,6 +750,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)
> @@ -759,6 +762,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs)
>      }
>  }
>  
> +int 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) {
> @@ -1198,7 +1206,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);
>          }
> @@ -1483,11 +1491,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;
> @@ -1765,7 +1768,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));
>          bs_dict = qobject_to_qdict(bs_obj);
>  
> diff --git a/block.h b/block.h
> index b034d51..f6fa3d0 100644
> --- a/block.h
> +++ b/block.h
> @@ -33,6 +33,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);
>      /*
> @@ -102,6 +103,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);
> +int bdrv_dev_has_removable_media(BlockDriverState *bs);
>  bool bdrv_dev_is_medium_ejected(BlockDriverState *bs);
>  int bdrv_dev_is_medium_locked(BlockDriverState *bs);
>  int bdrv_read(BlockDriverState *bs, int64_t sector_num,
> @@ -207,7 +209,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 4c58128..06a82d3 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 ad63814..ae194c5 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1276,6 +1276,10 @@ 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_ejected(void *opaque)
>  {
>      return ((SCSIDiskState *)opaque)->tray_open;
> @@ -1287,6 +1291,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,
>  };

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

* Re: [Qemu-devel] [PATCH 07/55] block: Make BlockDriver method bdrv_set_locked() return void
  2011-07-21 15:07     ` Markus Armbruster
  2011-07-21 16:34       ` Luiz Capitulino
@ 2011-07-22 14:36       ` Kevin Wolf
  1 sibling, 0 replies; 145+ messages in thread
From: Kevin Wolf @ 2011-07-22 14:36 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	Luiz Capitulino, amit.shah

Am 21.07.2011 17:07, schrieb Markus Armbruster:
> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
>> On Wed, 20 Jul 2011 18:23:41 +0200
>> Markus Armbruster <armbru@redhat.com> wrote:
>>
>>> The only caller is bdrv_set_locked(), and it ignores the value.
>>>
>>> Callees always return 0, except for FreeBSD's cdrom_set_locked(),
>>> which returns -ENOTSUP when the device is in a terminally wedged
>>> state.
>>
>> The fact that we're ignoring ioctl() failures caught my attention. Is it
>> because the state we store in bs->locked is what really matters?
>>
>> Otherwise the right thing to do would be to propagate the error and
>> change callers to handle it.
> 
> The only caller is bdrv_set_locked().  Which can't handle it, so it
> would have to pass it on.
> 
> The purpose of bdrv_set_locked() is to synchronize the physical lock (if
> any) with the virtual lock.  Worst that can happen is the physical lock
> fails to track the virtual one.
> 
> bdrv_set_locked()'s callers are device models: ide-cd and scsi-cd.  Each
> one calls it in four places (with all my patches applied):
> 
> * Device init: can return failure.  Failure makes QEMU refuse to start
>   (-device cold plug), or hot plug fail (device_add).
> 
> * Device exit: can't return failure.
> 
> * Device post migration: can return failure, makes migration fail.
>   Given the choice, I figure I'd pick an incorrect physical tray lock
>   over a failed migration.
> 
> * Guest PREVENT ALLOW MEDIUM REMOVAL: can send error reply to guest.
>   Recommended errors according to MMC-5 are "unit attention errors" (not
>   a good match), "CDB or parameter list validation errors" (worse) and
>   "hardware failures" (no good choices there either).
> 
> I doubt adding the error handling is worth our while, but feel free to
> send patches.

I agree with Luiz that it feels a bit strange to remove one of the rare
places in qemu that actually return errors, but if you say that the
callers can't handle it anyway, well... We can always add it back if we
find a device that could make use of it.

Kevin

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

* Re: [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() return void
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() " Markus Armbruster
@ 2011-07-22 14:41   ` Kevin Wolf
  2011-07-22 15:04     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Kevin Wolf @ 2011-07-22 14:41 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Am 20.07.2011 18:23, schrieb Markus Armbruster:
> Callees always return 0, except for FreeBSD's cdrom_eject(), which
> returns -ENOTSUP when the device is in a terminally wedged state.
> 
> The only caller is bdrv_eject(), and it maps -ENOTSUP to 0 since
> commit 4be9762a.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

What about failed ioctls? Currently we only print an error message but
still return 0. Is this the right behaviour? Could callers make use of
an error return here or would we end up like with bdrv_set_locked()
where we can't really communicate the error to the guest?

Kevin

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

* Re: [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load Markus Armbruster
@ 2011-07-22 14:51   ` Kevin Wolf
  2011-07-22 15:33     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Kevin Wolf @ 2011-07-22 14:51 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Am 20.07.2011 18:23, schrieb Markus Armbruster:
> Commit aea2a33c made bdrv_eject() obey the locked flag.  Correct for
> medium eject (eject_flag set), incorrect for medium load (eject_flag
> clear).  See MMC-5 Table 341 "Actions for Lock/Unlock/Eject".
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

SCSI doesn't really matter here, this is about host state. The comment
for bdrv_set_locked only talks about eject, so it's probably right anyway.

Kevin

> ---
>  block.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 594bcab..6727274 100644
> --- a/block.c
> +++ b/block.c
> @@ -2769,7 +2769,7 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag)
>  {
>      BlockDriver *drv = bs->drv;
>  
> -    if (bs->locked) {
> +    if (eject_flag && bs->locked) {
>          return -EBUSY;
>      }
>  

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

* Re: [Qemu-devel] [PATCH 08/55] block: Make BlockDriver method bdrv_eject() return void
  2011-07-22 14:41   ` Kevin Wolf
@ 2011-07-22 15:04     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-22 15:04 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Kevin Wolf <kwolf@redhat.com> writes:

> Am 20.07.2011 18:23, schrieb Markus Armbruster:
>> Callees always return 0, except for FreeBSD's cdrom_eject(), which
>> returns -ENOTSUP when the device is in a terminally wedged state.
>> 
>> The only caller is bdrv_eject(), and it maps -ENOTSUP to 0 since
>> commit 4be9762a.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> What about failed ioctls? Currently we only print an error message but
> still return 0. Is this the right behaviour? Could callers make use of
> an error return here or would we end up like with bdrv_set_locked()
> where we can't really communicate the error to the guest?

Note that I'm not removing any error handling.  I don't add any either.
The series is long enough...

bdrv_eject()'s purpose is similar to bdrv_set_locked()'s: synchronize
the physical tray to the virtual one.  Unsurprisingly, our error
handling options are also similar.

All bdrv_eject() can do with errors from the BlockDriver method is pass
them on.

At this point in the series, bdrv_eject() still returns an error of its
own: -EBUSY when bs->locked.  28/55 moves that check into callers.

bdrv_eject()'s callers are device models: ide-cd and scsi-cd.  Each one
calls it in three places (with all my patches applied):

* Device init: can return failure.  Failure makes QEMU refuse to start
  (-device cold plug), or hot plug fail (device_add).

* Device post migration: can return failure, makes migration fail.
  Given the choice, I figure I'd pick an incorrect physical tray lock
  over a failed migration.

* Guest PREVENT ALLOW MEDIUM REMOVAL: can send error reply to guest.

  Does send the appropriate error when the virtual tray is locked.

  What sense to send when the ioctl() fails?

  How can the ioctl() fail?  When the tray is locked, but for that to
  happen some other process must have interfered with the lock (Bad
  process!  No treat for you!  Go away!).  We could synchronize the lock
  again right before the eject, but that merely shrinks the race's
  window.

I doubt adding the error handling is worth our while, but feel free to
send patches.

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

* Re: [Qemu-devel] [PATCH 09/55] block: Don't let locked flag prevent medium load
  2011-07-22 14:51   ` Kevin Wolf
@ 2011-07-22 15:33     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-22 15:33 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Kevin Wolf <kwolf@redhat.com> writes:

> Am 20.07.2011 18:23, schrieb Markus Armbruster:
>> Commit aea2a33c made bdrv_eject() obey the locked flag.  Correct for
>> medium eject (eject_flag set), incorrect for medium load (eject_flag
>> clear).  See MMC-5 Table 341 "Actions for Lock/Unlock/Eject".
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> SCSI doesn't really matter here, this is about host state. The comment
> for bdrv_set_locked only talks about eject, so it's probably right anyway.

For what it's worth, PATCH 28/55 moves this check to the device models,
where MMC-5 clearly applies.

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

* Re: [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (54 preceding siblings ...)
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 55/55] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
@ 2011-07-23  3:15 ` Amit Shah
  2011-07-25 15:33   ` Markus Armbruster
  2011-07-28  8:12 ` Kevin Wolf
  2011-07-28  9:34 ` Amit Shah
  57 siblings, 1 reply; 145+ messages in thread
From: Amit Shah @ 2011-07-23  3:15 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel, lcapitulino

On (Wed) 20 Jul 2011 [18:23:34], Markus Armbruster wrote:
> 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.

Sorry, haven't seen these patches yet, but a question: will adding
things like 'this removable device is a CDROM/CD-RW/DVD/DVD-dual
layer/DVD-dual-side/DVD-RAM, etc., need extra cleanups or will this
just fit in?

		Amit

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

* Re: [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 01/55] blockdev: Make eject fail for non-removable drives even with -f Markus Armbruster
@ 2011-07-25 12:27   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:27 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 02/55] block: Reset device model callbacks on detach
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 02/55] block: Reset device model callbacks on detach Markus Armbruster
@ 2011-07-25 12:27   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:27 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:36PM +0200, Markus Armbruster wrote:
> BlockDriverState members change_cb and change_opaque are initially
> null.  The device model may set them, with bdrv_set_change_cb().  If
> the device model gets detached (hot unplug), they're left dangling.
> Only safe because device hot unplug automatically destroys the
> BlockDriverState.  But that's a questionable feature, best not to rely
> on it.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 04/55] block: Generalize change_cb() to BlockDevOps
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 04/55] block: Generalize change_cb() to BlockDevOps Markus Armbruster
@ 2011-07-25 12:30   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:30 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:38PM +0200, Markus Armbruster wrote:
> So we can more easily add device model callbacks.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 05/55] block: Split change_cb() into change_media_cb(), resize_cb()
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 05/55] block: Split change_cb() into change_media_cb(), resize_cb() Markus Armbruster
@ 2011-07-25 12:31   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:31 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:39PM +0200, Markus Armbruster wrote:
> Multiplexing callbacks complicates matters needlessly.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 06/55] block/raw-win32: Drop disabled code for removable host devices
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 06/55] block/raw-win32: Drop disabled code for removable host devices Markus Armbruster
@ 2011-07-25 12:32   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:32 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:40PM +0200, Markus Armbruster wrote:
> It's been disabled since the start (commit 19cb3738, Aug 2006), and
> has been untouched except for spelling fixes and such.  I don't feel
> like dragging it along any further.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Ok, let's nuke it.

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

* Re: [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2 Markus Armbruster
@ 2011-07-25 12:34   ` Christoph Hellwig
  2011-07-25 17:15     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:34 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:44PM +0200, Markus Armbruster wrote:
> Drop WIN_SRST, it has same value as WIN_DEVICE_RESET.
> 
> 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.
> 
> Turn unused macros into comments.

I don't think that part is overly helpful.  In general you'd want to
keep all defines for protocol headers, just to make it easier to
actually use them later on.

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

* Re: [Qemu-devel] [PATCH 11/55] ide: Clean up case label indentation in ide_exec_cmd()
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 11/55] ide: Clean up case label indentation in ide_exec_cmd() Markus Armbruster
@ 2011-07-25 12:34   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-25 12:34 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
  2011-07-23  3:15 ` [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Amit Shah
@ 2011-07-25 15:33   ` Markus Armbruster
  2011-07-26  5:33     ` Amit Shah
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-25 15:33 UTC (permalink / raw)
  To: Amit Shah
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel, lcapitulino

Amit Shah <amit.shah@redhat.com> writes:

> On (Wed) 20 Jul 2011 [18:23:34], Markus Armbruster wrote:
>> 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.
>
> Sorry, haven't seen these patches yet, but a question: will adding
> things like 'this removable device is a CDROM/CD-RW/DVD/DVD-dual
> layer/DVD-dual-side/DVD-RAM, etc., need extra cleanups or will this
> just fit in?

I don't know, sorry.

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

* Re: [Qemu-devel] [PATCH 10/55] ide: Update command code definitions as per ACS-2 Table B.2
  2011-07-25 12:34   ` Christoph Hellwig
@ 2011-07-25 17:15     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-25 17:15 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:23:44PM +0200, Markus Armbruster wrote:
>> Drop WIN_SRST, it has same value as WIN_DEVICE_RESET.
>> 
>> 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.
>> 
>> Turn unused macros into comments.
>
> I don't think that part is overly helpful.  In general you'd want to
> keep all defines for protocol headers, just to make it easier to
> actually use them later on.

Which ones to keep?  Just non-obsolete ones?  According to which version
of the standard?

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

* Re: [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
  2011-07-25 15:33   ` Markus Armbruster
@ 2011-07-26  5:33     ` Amit Shah
  0 siblings, 0 replies; 145+ messages in thread
From: Amit Shah @ 2011-07-26  5:33 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel, lcapitulino

On (Mon) 25 Jul 2011 [17:33:12], Markus Armbruster wrote:
> Amit Shah <amit.shah@redhat.com> writes:
> 
> > On (Wed) 20 Jul 2011 [18:23:34], Markus Armbruster wrote:
> >> 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.
> >
> > Sorry, haven't seen these patches yet, but a question: will adding
> > things like 'this removable device is a CDROM/CD-RW/DVD/DVD-dual
> > layer/DVD-dual-side/DVD-RAM, etc., need extra cleanups or will this
> > just fit in?
> 
> I don't know, sorry.

No problem!

		Amit

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

* Re: [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM Markus Armbruster
@ 2011-07-26 11:57   ` Christoph Hellwig
  2011-07-26 13:33     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 11:57 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:46PM +0200, Markus Armbruster wrote:
> Must set the ATAPI device signature, see ACS-2 7.36.6 Outputs for
> PACKET feature set devices.

Odd but true, even if it's 7.38.2 in my local copy of the ACS spec.

It defintively should be documented in a comment next to the code,
given how odd the behaviour is.

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

* Re: [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 13/55] ide: Use a table to declare which drive kinds accept each command Markus Armbruster
@ 2011-07-26 11:58   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 11:58 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:47PM +0200, Markus Armbruster 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 14/55] ide: Reject ATA commands specific to drive kinds Markus Armbruster
@ 2011-07-26 11:58   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 11:58 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:48PM +0200, Markus Armbruster wrote:
> 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 15/55] ide/atapi: Clean up misleading name in cmd_start_stop_unit() Markus Armbruster
@ 2011-07-26 11:59   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 11:59 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:49PM +0200, Markus Armbruster wrote:
> "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.

Just as clear as the bdrv_eject name :)

Looks fine anyway,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 16/55] ide/atapi: Track tray open/close state Markus Armbruster
@ 2011-07-26 11:59   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 11:59 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:50PM +0200, 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own Markus Armbruster
@ 2011-07-26 12:00   ` Christoph Hellwig
  2011-07-26 13:36     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:00 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:51PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good, although I would have folded this patch into the previous
one.

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks Markus Armbruster
@ 2011-07-26 12:02   ` Christoph Hellwig
  2011-07-26 13:36     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:02 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:52PM +0200, Markus Armbruster wrote:
> Use a table to declare which drive kinds accept each command.
> 
> Limit READ_CAPACITY, READ_TOC, GET_CONFIGURATION to SCSI_CD, as per
> SPC-4.

READ CAPACITY is defined in SBC, and absolutely required for proper
operation with disks.

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

* Re: [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop()
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 19/55] scsi-disk: Factor out scsi_disk_emulate_start_stop() Markus Armbruster
@ 2011-07-26 12:03   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:53PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 20/55] scsi-disk: Track tray open/close state Markus Armbruster
@ 2011-07-26 12:03   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:54PM +0200, 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 21/55] block: Revert entanglement of bdrv_is_inserted() with tray status Markus Armbruster
@ 2011-07-26 12:10   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:10 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

> @@ -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 },

> +    /* [1] handler detects and reports not ready condition itself */

Why not comment this near the actual code?  The footnote scheme is
pretty odd and I've not seen it anywhere else in the code.

Otherwise looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 22/55] block: Drop tray status tracking, no longer used Markus Armbruster
@ 2011-07-26 12:11   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:11 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:56PM +0200, Markus Armbruster wrote:
> Commit 4be9762a is now completely redone.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 24/55] ide/atapi: Track tray locked state Markus Armbruster
@ 2011-07-26 12:13   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:13 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:58PM +0200, 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>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked
  2011-07-20 16:23 ` [Qemu-devel] [PATCH 25/55] ide/atapi: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
@ 2011-07-26 12:14   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:23:59PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  hw/ide/atapi.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 26/55] scsi-disk: Track tray locked state Markus Armbruster
@ 2011-07-26 12:14   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:00PM +0200, 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>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked Markus Armbruster
@ 2011-07-26 12:14   ` Christoph Hellwig
  2011-07-26 13:38     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:14 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:01PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>


Looks good, although I would have merged it into the previous one.


Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit()
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 31/55] ide: Provide IDEDeviceInfo method exit() Markus Armbruster
@ 2011-07-26 12:16   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:16 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:05PM +0200, Markus Armbruster wrote:
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 32/55] ide/atapi: Don't fail eject when tray is already open Markus Armbruster
@ 2011-07-26 12:16   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:16 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:06PM +0200, Markus Armbruster wrote:
> 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>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-07-26 12:17   ` Christoph Hellwig
  2011-07-26 13:43     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:17 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:07PM +0200, Markus Armbruster wrote:
> 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

But wondering:  do you actually use the physical CDROM passthrough?

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

* Re: [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 34/55] scsi-disk: Fix START_STOP to fail when it can't eject Markus Armbruster
@ 2011-07-26 12:17   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:17 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:08PM +0200, Markus Armbruster wrote:
> Don't fail when tray is already open.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 35/55] scsi-disk: Avoid physical/virtual tray state mismatch Markus Armbruster
@ 2011-07-26 12:17   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:17 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:09PM +0200, 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed()
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 39/55] block/raw: Fix to forward method bdrv_media_changed() Markus Armbruster
@ 2011-07-26 12:18   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:18 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:13PM +0200, Markus Armbruster wrote:
> 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.

Haha.  The patch looks fine to me anyway,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 40/55] block: Leave tracking media change to device models Markus Armbruster
@ 2011-07-26 12:19   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:19 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:14PM +0200, Markus Armbruster wrote:
> hw/fdc.c is the only one that cares.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Looks good,


Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all()
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 42/55] block: Clean up bdrv_flush_all() Markus Armbruster
@ 2011-07-26 12:19   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 12:19 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable"
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 45/55] block: Clean up remaining users of "removable" Markus Armbruster
  2011-07-21 17:33   ` Luiz Capitulino
@ 2011-07-26 13:03   ` Christoph Hellwig
  1 sibling, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 46/55] block: Drop BlockDriverState member removable
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 46/55] block: Drop BlockDriverState member removable Markus Armbruster
@ 2011-07-26 13:03   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:03 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 47/55] block: Move BlockConf & friends from block_int.h to block.h
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 47/55] block: Move BlockConf & friends from block_int.h to block.h Markus Armbruster
@ 2011-07-26 13:04   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:21PM +0200, Markus Armbruster wrote:
> 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.

Fine with me (and I added this originally).

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 48/55] hw: Trim superfluous #include "block_int.h"
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 48/55] hw: Trim superfluous #include "block_int.h" Markus Armbruster
@ 2011-07-26 13:04   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h Markus Armbruster
@ 2011-07-26 13:05   ` Christoph Hellwig
  2011-07-26 14:10     ` Markus Armbruster
  2011-07-29  8:56     ` Markus Armbruster
  0 siblings, 2 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:05 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:23PM +0200, Markus Armbruster wrote:
> Device models should be able to use it without an unclean include of
> block_int.h.

Hmm.  We already do proper read-modify-write cycles for actual data
transfers, so killing the buffer inside SD sounds like the better
idea.  qemu_blockalign really should be used only for block-layer internal
allocations.

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

* Re: [Qemu-devel] [PATCH 50/55] block: New bdrv_set_buffer_alignment()
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 50/55] block: New bdrv_set_buffer_alignment() Markus Armbruster
@ 2011-07-26 13:06   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:06 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:24PM +0200, Markus Armbruster wrote:
> Device models should be able to set it without an unclean include of
> block_int.h.

Fine with me,


Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 51/55] block: Reset buffer alignment on detach
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 51/55] block: Reset buffer alignment on detach Markus Armbruster
@ 2011-07-26 13:06   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:06 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:25PM +0200, Markus Armbruster wrote:
> 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.

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h Markus Armbruster
@ 2011-07-26 13:07   ` Christoph Hellwig
  2011-07-26 14:11     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:07 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:26PM +0200, Markus Armbruster wrote:
> Device models should be able to use them without an unclean include of
> block_int.h.

I don't think so.  In generall they aren't for use of device models at
all.  It's just that the IDE trim support with it's ranges is rather
"special".  If you absolutely want IDE to stop including block_int.h
I guess we'll have to lift that code into the block layer somehow.

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

* Re: [Qemu-devel] [PATCH 53/55] nbd: Clean up use of block_int.h
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 53/55] nbd: Clean up use of block_int.h Markus Armbruster
@ 2011-07-26 13:07   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:07 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 54/55] block: New change_media_cb() parameter load
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 54/55] block: New change_media_cb() parameter load Markus Armbruster
@ 2011-07-26 13:08   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:08 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:28PM +0200, Markus Armbruster wrote:
> To let device models distinguish between eject and load.

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 55/55] ide/atapi scsi-disk: Make monitor eject -f, then change work
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 55/55] ide/atapi scsi-disk: Make monitor eject -f, then change work Markus Armbruster
@ 2011-07-26 13:08   ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-26 13:08 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On Wed, Jul 20, 2011 at 06:24:29PM +0200, Markus Armbruster wrote:
> 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.

Looks fine,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [Qemu-devel] [PATCH 12/55] ide: Fix ATA command READ to set ATAPI signature for CD-ROM
  2011-07-26 11:57   ` Christoph Hellwig
@ 2011-07-26 13:33     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 13:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:23:46PM +0200, Markus Armbruster wrote:
>> Must set the ATAPI device signature, see ACS-2 7.36.6 Outputs for
>> PACKET feature set devices.
>
> Odd but true, even if it's 7.38.2 in my local copy of the ACS spec.
>
> It defintively should be documented in a comment next to the code,
> given how odd the behaviour is.

I can stick in a suitable comment when I respin.

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

* Re: [Qemu-devel] [PATCH 17/55] ide/atapi: Switch from BlockDriverState's tray_open to own
  2011-07-26 12:00   ` Christoph Hellwig
@ 2011-07-26 13:36     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 13:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:23:51PM +0200, Markus Armbruster wrote:
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> Looks good, although I would have folded this patch into the previous
> one.

I'll consider squashing when I respin.

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

* Re: [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks
  2011-07-26 12:02   ` Christoph Hellwig
@ 2011-07-26 13:36     ` Markus Armbruster
  2011-07-29  8:41       ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 13:36 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:23:52PM +0200, Markus Armbruster wrote:
>> Use a table to declare which drive kinds accept each command.
>> 
>> Limit READ_CAPACITY, READ_TOC, GET_CONFIGURATION to SCSI_CD, as per
>> SPC-4.
>
> READ CAPACITY is defined in SBC, and absolutely required for proper
> operation with disks.

Will fix.

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

* Re: [Qemu-devel] [PATCH 27/55] scsi-disk: Switch from BlockDriverState's locked to own tray_locked
  2011-07-26 12:14   ` Christoph Hellwig
@ 2011-07-26 13:38     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 13:38 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:24:01PM +0200, Markus Armbruster wrote:
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
>
> Looks good, although I would have merged it into the previous one.

I'll consider squashing when I respin.

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

* Re: [Qemu-devel] [PATCH 33/55] ide/atapi: Avoid physical/virtual tray state mismatch
  2011-07-26 12:17   ` Christoph Hellwig
@ 2011-07-26 13:43     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 13:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:24:07PM +0200, Markus Armbruster wrote:
>> 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.
>
> Looks good,
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
> But wondering:  do you actually use the physical CDROM passthrough?

In my opinion, it's one of the QEMU features friends don't let friends
use.  But it's there, I can fix it a little, so I fix it a little.  A
wiser man would perhaps close his eyes and move on to fix something more
useful :)

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

* Re: [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-07-26 13:05   ` Christoph Hellwig
@ 2011-07-26 14:10     ` Markus Armbruster
  2011-07-29  8:56     ` Markus Armbruster
  1 sibling, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 14:10 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:24:23PM +0200, Markus Armbruster wrote:
>> Device models should be able to use it without an unclean include of
>> block_int.h.
>
> Hmm.  We already do proper read-modify-write cycles for actual data
> transfers, so killing the buffer inside SD sounds like the better
> idea.  qemu_blockalign really should be used only for block-layer internal
> allocations.

Ok, dropping the patch.

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

* Re: [Qemu-devel] [PATCH 52/55] block: Move BlockDriverAIOCB & friends from block_int.h to block.h
  2011-07-26 13:07   ` Christoph Hellwig
@ 2011-07-26 14:11     ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-26 14:11 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:24:26PM +0200, Markus Armbruster wrote:
>> Device models should be able to use them without an unclean include of
>> block_int.h.
>
> I don't think so.  In generall they aren't for use of device models at
> all.  It's just that the IDE trim support with it's ranges is rather
> "special".  If you absolutely want IDE to stop including block_int.h
> I guess we'll have to lift that code into the block layer somehow.

Not "absolutely" enough to do the lifting now.  Dropping the patch.

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

* Re: [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (55 preceding siblings ...)
  2011-07-23  3:15 ` [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Amit Shah
@ 2011-07-28  8:12 ` Kevin Wolf
  2011-07-28  9:34 ` Amit Shah
  57 siblings, 0 replies; 145+ messages in thread
From: Kevin Wolf @ 2011-07-28  8:12 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Am 20.07.2011 18:23, 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.
> 
> Part I: Preliminaries
> PATCH 01-09: Assorted block layer fixes and cleanup

Thanks, applied patches 1-9 to the block branch.

> Part II: Move tray state to device models
> PATCH 10-18: IDE tray open/closed
> PATCH 19-22: SCSI tray open/closed
> PATCH 23-25: block layer kill tray_open
> PATCH 26-27: IDE tray lock
> PATCH 28-29: SCSI tray lock
> PATCH 30-32: block layer kill locked
> PATCH 33-35: IDE & SCSI synchronize physical tray on init
> PATCH 36-38: IDE & SCSI migrate tray state
> PATCH 39-41: block layer & fdc media_changed
> 
> Part III: Replace removable
> PATCH 42-44 clean up inappopriate uses of removable
> PATCH 45-46 replace remaining users
> 
> Part IV: Reduce unclean use of block_int.h
> PATCH 47-53
> 
> PART V: Improve eject -f
> PATCH 54-55

I'll wait for a v2 on top of the block branch for the rest of the series.

Kevin

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

* Re: [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes
  2011-07-20 16:23 [Qemu-devel] [PATCH 00/55] Block layer cleanup & fixes Markus Armbruster
                   ` (56 preceding siblings ...)
  2011-07-28  8:12 ` Kevin Wolf
@ 2011-07-28  9:34 ` Amit Shah
  57 siblings, 0 replies; 145+ messages in thread
From: Amit Shah @ 2011-07-28  9:34 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel, lcapitulino

On (Wed) 20 Jul 2011 [18:23:34], Markus Armbruster wrote:
> This patch series looks bigger than it is.  All the patches are small
> and hopefully easy to review.

Nice series!

ACK the entire series (barring the non-qdev users connecting to bdrv
and scsi patches, which I didn't quite follow).

		Amit

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

* Re: [Qemu-devel] [PATCH 18/55] scsi-disk: Reject CD-specific SCSI commands to disks
  2011-07-26 13:36     ` Markus Armbruster
@ 2011-07-29  8:41       ` Markus Armbruster
  0 siblings, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-07-29  8:41 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Markus Armbruster <armbru@redhat.com> writes:

> Christoph Hellwig <hch@lst.de> writes:
>
>> On Wed, Jul 20, 2011 at 06:23:52PM +0200, Markus Armbruster wrote:
>>> Use a table to declare which drive kinds accept each command.
>>> 
>>> Limit READ_CAPACITY, READ_TOC, GET_CONFIGURATION to SCSI_CD, as per
>>> SPC-4.
>>
>> READ CAPACITY is defined in SBC, and absolutely required for proper
>> operation with disks.
>
> Will fix.

Second thoughts: dropping this bug fix patch for now, because it clashes
with Hannes's work in progress[*], and the rest of my series doesn't
depend on it.

[*] [PATCH 6/6] scsi-disk: Check for supported commands
http://lists.gnu.org/archive/html/qemu-devel/2011-07/msg03082.html

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

* Re: [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-07-26 13:05   ` Christoph Hellwig
  2011-07-26 14:10     ` Markus Armbruster
@ 2011-07-29  8:56     ` Markus Armbruster
  2011-07-29 13:11       ` Christoph Hellwig
  1 sibling, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-07-29  8:56 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

Christoph Hellwig <hch@lst.de> writes:

> On Wed, Jul 20, 2011 at 06:24:23PM +0200, Markus Armbruster wrote:
>> Device models should be able to use it without an unclean include of
>> block_int.h.
>
> Hmm.  We already do proper read-modify-write cycles for actual data
> transfers, so killing the buffer inside SD sounds like the better
> idea.  qemu_blockalign really should be used only for block-layer internal
> allocations.

What about the uses in scsi-disk.c and ide/core.c?

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

* Re: [Qemu-devel] [PATCH 49/55] block: Declare qemu_blockalign() in block.h, not block_int.h
  2011-07-29  8:56     ` Markus Armbruster
@ 2011-07-29 13:11       ` Christoph Hellwig
  0 siblings, 0 replies; 145+ messages in thread
From: Christoph Hellwig @ 2011-07-29 13:11 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah, Christoph Hellwig

On Fri, Jul 29, 2011 at 10:56:07AM +0200, Markus Armbruster wrote:
> > Hmm.  We already do proper read-modify-write cycles for actual data
> > transfers, so killing the buffer inside SD sounds like the better
> > idea.  qemu_blockalign really should be used only for block-layer internal
> > allocations.
> 
> What about the uses in scsi-disk.c and ide/core.c?

They are allocating internal bounce buffers due to suboptimal I/O
models.  But given that this is the reality in multiple qemu drivers I
think I'll give up and ack the move.

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-07-20 16:24 ` [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test Markus Armbruster
@ 2011-07-30  2:24   ` andrzej zaborowski
  2011-08-01 12:33     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: andrzej zaborowski @ 2011-07-30  2:24 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
> 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.

This is a less generic test and more prone to be broken inadvertently,
so it seems like a step back.  What's the argument against the
convoluted and explicit test?

Cheers

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-07-30  2:24   ` andrzej zaborowski
@ 2011-08-01 12:33     ` Markus Armbruster
  2011-08-01 13:04       ` Peter Maydell
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-01 12:33 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: kwolf, stefano.stabellini, dbaryshkov, quintela, qemu-devel,
	lcapitulino, amit.shah

andrzej zaborowski <balrogg@gmail.com> writes:

> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>> 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.
>
> This is a less generic test and more prone to be broken inadvertently,
> so it seems like a step back.  What's the argument against the
> convoluted and explicit test?

My motivation for changing it was to reduce the uses of BlockDriverState
member removable prior to nuking it from orbit [PATCH 45/55].

I consider my change an improvement, because I find "dinfo->media_cd"
clearer than
"bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".

Moreover, it's the only place that uses bdrv_is_removable() to test
whether the block driver supports media eject.  All the other places use
dinfo->media_cd: hw/scsi-disk.c hw/xen_devconfig.c hw/ide/core.c
hw/ide/qdev.c.  Can't see why spitz & tosa need to check the same thing
differently, and why it's worth keeping bdrv_is_removable() around just
for that.

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-01 12:33     ` Markus Armbruster
@ 2011-08-01 13:04       ` Peter Maydell
  2011-08-03  8:12         ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Peter Maydell @ 2011-08-01 13:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
> andrzej zaborowski <balrogg@gmail.com> writes:
>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>> 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.
>>
>> This is a less generic test and more prone to be broken inadvertently,
>> so it seems like a step back.  What's the argument against the
>> convoluted and explicit test?
>
> My motivation for changing it was to reduce the uses of BlockDriverState
> member removable prior to nuking it from orbit [PATCH 45/55].
>
> I consider my change an improvement, because I find "dinfo->media_cd"
> clearer than
> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".

This seems like an argument for providing a bdrv_supports_eject()
or whatever we're actually trying to test for here. I kind of felt
the same way as Andrzej when I saw this patch going past but it
got lost in my mail folder...

-- PMM

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-01 13:04       ` Peter Maydell
@ 2011-08-03  8:12         ` Markus Armbruster
  2011-08-03 12:05           ` andrzej zaborowski
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-03  8:12 UTC (permalink / raw)
  To: Peter Maydell
  Cc: kwolf, quintela, dbaryshkov, stefano.stabellini, qemu-devel,
	lcapitulino, amit.shah

Peter Maydell <peter.maydell@linaro.org> writes:

> On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
>> andrzej zaborowski <balrogg@gmail.com> writes:
>>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>> 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.
>>>
>>> This is a less generic test and more prone to be broken inadvertently,
>>> so it seems like a step back.  What's the argument against the
>>> convoluted and explicit test?
>>
>> My motivation for changing it was to reduce the uses of BlockDriverState
>> member removable prior to nuking it from orbit [PATCH 45/55].
>>
>> I consider my change an improvement, because I find "dinfo->media_cd"
>> clearer than
>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".
>
> This seems like an argument for providing a bdrv_supports_eject()
> or whatever we're actually trying to test for here. I kind of felt
> the same way as Andrzej when I saw this patch going past but it
> got lost in my mail folder...

Well, what are you trying to test for here?

Let's start with figuring out what we actually test for right now (may
not be what you *want* to test for, but it's a start).  The test code is
"bdrv_is_inserted(bs) && !bdrv_is_removable(bs)".

bdrv_is_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, except when an ide-hd, scsi-hd,
scsi-generic or virtio-blk qdev is attached.

Since we're about to attach a device here, no other device can be
attached, and the mess simplifies into "when the BlockDriverState was
created with -drive if={floppy,sd} or -drive
if={ide,scsi,xen,none},media=cdrom".

Since we're getting IF_IDE, it further simplifies into "when the
BlockDriverState was created with -drive if=ide,media=cdrom".  Which is
what my patch tests.

The bdrv_is_inserted() part is actually redundant, because it can only
be false if bdrv_is_removable() is true: the only way to create an IDE
drive empty is with media=cdrom (makes bdrv_is_removable() true), and
media is ejectable only when bdrv_is_removable() is true.

Therefore, my patch preserves behavior.


Testing for "block driver supports eject" is something else entirely.
Block drivers "host_cdrom" and "host_floppy" implement method
bdrv_eject()[*].  Is that what you want?

Note that "block driver supports eject" is completely independent of
"monitor command eject works".  You can back a removable device such as
a CD-ROM with a block driver that doesn't support eject, say "file".
Monitor command eject works fine then.  Conversely, you can back a
non-removable device such as a disk with a block driver that does
support eject, such as "host_cdrom".  It may not be the wisest thing to
do, but it works.  Ejecting the physical media while the device model is
using it will result in I/O errors, to nobody's surprise.


Anyway.  bdrv_is_removable() must die.  You're using it.  Please tell me
what exactly you're trying to accomplish, so I can get it done without
bdrv_is_removable().  Best way to tell me is with a patch.


[*] "raw" implements bdrv_eject() as well, but it merely forwards, which
doesn't count.

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03  8:12         ` Markus Armbruster
@ 2011-08-03 12:05           ` andrzej zaborowski
  2011-08-03 13:28             ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: andrzej zaborowski @ 2011-08-03 12:05 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

On 3 August 2011 10:12, Markus Armbruster <armbru@redhat.com> wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>>> 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.
>>>>
>>>> This is a less generic test and more prone to be broken inadvertently,
>>>> so it seems like a step back.  What's the argument against the
>>>> convoluted and explicit test?
>>>
>>> My motivation for changing it was to reduce the uses of BlockDriverState
>>> member removable prior to nuking it from orbit [PATCH 45/55].
>>>
>>> I consider my change an improvement, because I find "dinfo->media_cd"
>>> clearer than
>>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".
>>
>> This seems like an argument for providing a bdrv_supports_eject()
>> or whatever we're actually trying to test for here. I kind of felt
>> the same way as Andrzej when I saw this patch going past but it
>> got lost in my mail folder...
>
> Well, what are you trying to test for here?
>
> Let's start with figuring out what we actually test for right now (may
> not be what you *want* to test for, but it's a start).  The test code is
> "bdrv_is_inserted(bs) && !bdrv_is_removable(bs)".
>
> bdrv_is_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, except when an ide-hd, scsi-hd,
> scsi-generic or virtio-blk qdev is attached.
>
> Since we're about to attach a device here, no other device can be
> attached, and the mess simplifies into "when the BlockDriverState was
> created with -drive if={floppy,sd} or -drive
> if={ide,scsi,xen,none},media=cdrom".
>
> Since we're getting IF_IDE, it further simplifies into "when the
> BlockDriverState was created with -drive if=ide,media=cdrom".

What's wrong with that again?  All sounds sensible to me.

> Which is
> what my patch tests.

It's like if you changed the named constants/#defines in a project for
their preprocessed values... Behaviour is preserved but it makes worse
code, and its easier to break too, when someone updates the value of
some constant.

>
> The bdrv_is_inserted() part is actually redundant, because it can only
> be false if bdrv_is_removable() is true: the only way to create an IDE
> drive empty is with media=cdrom (makes bdrv_is_removable() true), and
> media is ejectable only when bdrv_is_removable() is true.
>
> Therefore, my patch preserves behavior.
>
>
> Testing for "block driver supports eject" is something else entirely.
> Block drivers "host_cdrom" and "host_floppy" implement method
> bdrv_eject()[*].  Is that what you want?

No, from your description of ejectable it looks like we want to check
if the device supports the monitor command "eject", although
additionally testing for "block driver supports eject" may make sense.

Cheers

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 12:05           ` andrzej zaborowski
@ 2011-08-03 13:28             ` Markus Armbruster
  2011-08-03 13:37               ` andrzej zaborowski
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-03 13:28 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

andrzej zaborowski <balrogg@gmail.com> writes:

> On 3 August 2011 10:12, Markus Armbruster <armbru@redhat.com> wrote:
>> Peter Maydell <peter.maydell@linaro.org> writes:
>>
>>> On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>> 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.
>>>>>
>>>>> This is a less generic test and more prone to be broken inadvertently,
>>>>> so it seems like a step back.  What's the argument against the
>>>>> convoluted and explicit test?
>>>>
>>>> My motivation for changing it was to reduce the uses of BlockDriverState
>>>> member removable prior to nuking it from orbit [PATCH 45/55].
>>>>
>>>> I consider my change an improvement, because I find "dinfo->media_cd"
>>>> clearer than
>>>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".
>>>
>>> This seems like an argument for providing a bdrv_supports_eject()
>>> or whatever we're actually trying to test for here. I kind of felt
>>> the same way as Andrzej when I saw this patch going past but it
>>> got lost in my mail folder...
>>
>> Well, what are you trying to test for here?
>>
>> Let's start with figuring out what we actually test for right now (may
>> not be what you *want* to test for, but it's a start).  The test code is
>> "bdrv_is_inserted(bs) && !bdrv_is_removable(bs)".
>>
>> bdrv_is_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, except when an ide-hd, scsi-hd,
>> scsi-generic or virtio-blk qdev is attached.
>>
>> Since we're about to attach a device here, no other device can be
>> attached, and the mess simplifies into "when the BlockDriverState was
>> created with -drive if={floppy,sd} or -drive
>> if={ide,scsi,xen,none},media=cdrom".
>>
>> Since we're getting IF_IDE, it further simplifies into "when the
>> BlockDriverState was created with -drive if=ide,media=cdrom".
>
> What's wrong with that again?  All sounds sensible to me.

I'm not claiming otherwise, just double-checking this is what you want.

>> Which is
>> what my patch tests.
>
> It's like if you changed the named constants/#defines in a project for
> their preprocessed values... Behaviour is preserved but it makes worse
> code, and its easier to break too, when someone updates the value of
> some constant.

Well, you just said you want to check whether the drive was created as
CD-ROM.  The most direct way to check precisely that is drive->media_cd,
and I can't see how that could break.

If you can see how, please tell me.

If you want to check for something else, please explain what you want.

"Keep it the way it was" isn't an explanation.  And keeping
bdrv_is_removable() mess alive just for this one use would be silly.

[...]

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 13:28             ` Markus Armbruster
@ 2011-08-03 13:37               ` andrzej zaborowski
  2011-08-03 16:38                 ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: andrzej zaborowski @ 2011-08-03 13:37 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

On 3 August 2011 15:28, Markus Armbruster <armbru@redhat.com> wrote:
> andrzej zaborowski <balrogg@gmail.com> writes:
>
>> On 3 August 2011 10:12, Markus Armbruster <armbru@redhat.com> wrote:
>>> Peter Maydell <peter.maydell@linaro.org> writes:
>>>
>>>> On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>>> 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.
>>>>>>
>>>>>> This is a less generic test and more prone to be broken inadvertently,
>>>>>> so it seems like a step back.  What's the argument against the
>>>>>> convoluted and explicit test?
>>>>>
>>>>> My motivation for changing it was to reduce the uses of BlockDriverState
>>>>> member removable prior to nuking it from orbit [PATCH 45/55].
>>>>>
>>>>> I consider my change an improvement, because I find "dinfo->media_cd"
>>>>> clearer than
>>>>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".
>>>>
>>>> This seems like an argument for providing a bdrv_supports_eject()
>>>> or whatever we're actually trying to test for here. I kind of felt
>>>> the same way as Andrzej when I saw this patch going past but it
>>>> got lost in my mail folder...
>>>
>>> Well, what are you trying to test for here?
>>>
>>> Let's start with figuring out what we actually test for right now (may
>>> not be what you *want* to test for, but it's a start).  The test code is
>>> "bdrv_is_inserted(bs) && !bdrv_is_removable(bs)".
>>>
>>> bdrv_is_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, except when an ide-hd, scsi-hd,
>>> scsi-generic or virtio-blk qdev is attached.
>>>
>>> Since we're about to attach a device here, no other device can be
>>> attached, and the mess simplifies into "when the BlockDriverState was
>>> created with -drive if={floppy,sd} or -drive
>>> if={ide,scsi,xen,none},media=cdrom".
>>>
>>> Since we're getting IF_IDE, it further simplifies into "when the
>>> BlockDriverState was created with -drive if=ide,media=cdrom".
>>
>> What's wrong with that again?  All sounds sensible to me.
>
> I'm not claiming otherwise, just double-checking this is what you want.
>
>>> Which is
>>> what my patch tests.
>>
>> It's like if you changed the named constants/#defines in a project for
>> their preprocessed values... Behaviour is preserved but it makes worse
>> code, and its easier to break too, when someone updates the value of
>> some constant.
>
> Well, you just said you want to check whether the drive was created as
> CD-ROM.

I didn't say that, I want to check 1. if the underlaying device is
shown as removable (support monitor eject, I guess), 2. if the
underlaying storage can disappear for any other reason if that's
possible to check.

And I said that it looks like the inner implementation of the
_is_removable function is probably correct, but inlining it makes no
sense to me.  And the implementation shouldn't even bother us here.
Reread the part you quoted.

Cheers

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 13:37               ` andrzej zaborowski
@ 2011-08-03 16:38                 ` Markus Armbruster
  2011-08-03 17:26                   ` andrzej zaborowski
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-03 16:38 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

andrzej zaborowski <balrogg@gmail.com> writes:

> On 3 August 2011 15:28, Markus Armbruster <armbru@redhat.com> wrote:
>> andrzej zaborowski <balrogg@gmail.com> writes:
>>
>>> On 3 August 2011 10:12, Markus Armbruster <armbru@redhat.com> wrote:
>>>> Peter Maydell <peter.maydell@linaro.org> writes:
>>>>
>>>>> On 1 August 2011 13:33, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>>> On 20 July 2011 18:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>>>> 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.
>>>>>>>
>>>>>>> This is a less generic test and more prone to be broken inadvertently,
>>>>>>> so it seems like a step back.  What's the argument against the
>>>>>>> convoluted and explicit test?
>>>>>>
>>>>>> My motivation for changing it was to reduce the uses of BlockDriverState
>>>>>> member removable prior to nuking it from orbit [PATCH 45/55].
>>>>>>
>>>>>> I consider my change an improvement, because I find "dinfo->media_cd"
>>>>>> clearer than
>>>>>> "bdrv_is_inserted(dinfo->bdrv) && !bdrv_is_removable(dinfo->bdrv)".
>>>>>
>>>>> This seems like an argument for providing a bdrv_supports_eject()
>>>>> or whatever we're actually trying to test for here. I kind of felt
>>>>> the same way as Andrzej when I saw this patch going past but it
>>>>> got lost in my mail folder...
>>>>
>>>> Well, what are you trying to test for here?
>>>>
>>>> Let's start with figuring out what we actually test for right now (may
>>>> not be what you *want* to test for, but it's a start).  The test code is
>>>> "bdrv_is_inserted(bs) && !bdrv_is_removable(bs)".
>>>>
>>>> bdrv_is_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, except when an ide-hd, scsi-hd,
>>>> scsi-generic or virtio-blk qdev is attached.
>>>>
>>>> Since we're about to attach a device here, no other device can be
>>>> attached, and the mess simplifies into "when the BlockDriverState was
>>>> created with -drive if={floppy,sd} or -drive
>>>> if={ide,scsi,xen,none},media=cdrom".
>>>>
>>>> Since we're getting IF_IDE, it further simplifies into "when the
>>>> BlockDriverState was created with -drive if=ide,media=cdrom".
>>>
>>> What's wrong with that again?  All sounds sensible to me.
>>
>> I'm not claiming otherwise, just double-checking this is what you want.
>>
>>>> Which is
>>>> what my patch tests.
>>>
>>> It's like if you changed the named constants/#defines in a project for
>>> their preprocessed values... Behaviour is preserved but it makes worse
>>> code, and its easier to break too, when someone updates the value of
>>> some constant.
>>
>> Well, you just said you want to check whether the drive was created as
>> CD-ROM.
>
> I didn't say that, I want to check 1. if the underlaying device is
> shown as removable (support monitor eject, I guess),

After PATCH 45 all of them do, without exception.

"eject" works unless a device model is attached that doesn't want its
medium removed.

Before PATCH 45, "eject" sometimes refuses to work when no device model
is attached (arbitrary, but harmless), and sometimes worked even when
the attached device model doesn't want its medium removed (bug).  See
the patch description for details.

>                                                      2. if the
> underlaying storage can disappear for any other reason if that's
> possible to check.

bdrv_is_removable() *isn't* such a check.  It happily returns false for
-device if=ide,file=/dev/sr0.  tosa and spitz will happily use it, as
long as there's a CD in the drive during startup.

The block layer currently doesn't provide such a check.  For what it's
worth, IDE disks, SCSI disks and all the other non-removable decive
models other than microdrives happily work without it.

If you want such a check, what about a patch?

> And I said that it looks like the inner implementation of the
> _is_removable function is probably correct, but inlining it makes no
> sense to me.  And the implementation shouldn't even bother us here.
> Reread the part you quoted.

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 16:38                 ` Markus Armbruster
@ 2011-08-03 17:26                   ` andrzej zaborowski
  2011-08-03 18:24                     ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: andrzej zaborowski @ 2011-08-03 17:26 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
> andrzej zaborowski <balrogg@gmail.com> writes:
>>                                                      2. if the
>> underlaying storage can disappear for any other reason if that's
>> possible to check.
>
> bdrv_is_removable() *isn't* such a check.

Obviously I wasn't claiming it is, just that it might be useful, but
not necessrily possible.  After all pretty much any storage can be
"ejected" with enough force, depending on how far you want to go.

>>> What's wrong with that again?  All sounds sensible to me.
>>
>> I'm not claiming otherwise, just double-checking this is what you want.

So first you said you had a problem with _is_removable, and then you
said nothing was wrong with the implementation you outlined, plase
make up your mind.

Cheers

Cheers

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 17:26                   ` andrzej zaborowski
@ 2011-08-03 18:24                     ` Markus Armbruster
  2011-08-03 20:20                       ` andrzej zaborowski
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-03 18:24 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

andrzej zaborowski <balrogg@gmail.com> writes:

> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>                                                      2. if the
>>> underlaying storage can disappear for any other reason if that's
>>> possible to check.
>>
>> bdrv_is_removable() *isn't* such a check.
>
> Obviously I wasn't claiming it is, just that it might be useful, but
> not necessrily possible.  After all pretty much any storage can be
> "ejected" with enough force, depending on how far you want to go.
>
>>>> What's wrong with that again?  All sounds sensible to me.
>>>
>>> I'm not claiming otherwise, just double-checking this is what you want.
>
> So first you said you had a problem with _is_removable, and then you
> said nothing was wrong with the implementation you outlined, plase
> make up your mind.

I don't appreciate you quoting me out of context like that.

The sentence you quoted was in the middle of my attempt to get you to
explain what you're trying to accomplish there.  I started with
analyzing what your code does.  You asked "what's wrong with that", and
I replied that I'm not passing judgement on whether your code is right
or wrong, I just want to know what you're trying to do.

I'm getting tired of our misunderstandings, but let me try one more
time, and tiresomely verbose:

1. bdrv_is_removable() is ill-defined junk, and needs to go away.

   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.

   That's not semantics, that's an embarrassment.

2. I don't have an opinion on what should be done in
   tosa_microdrive_attach() and spitz_microdrive_attach().  Heck, I
   wouldn't touch it with a 9ft pole if I could help it.  But I have to,
   because it uses bdrv_is_removable().

3. My first try was to preserve the current behavior.  You don't like
   the result.  Fine.

4. For my second try, I tried to understand what you're trying to
   accomplish there.  Turns out you want to check whether "the
   underlaying storage can disappear for any other reason if that's
   possible to check."  Thanks for explaining that.

5. Sorry, that's not what the code there does.

6. The block layer does not offer an API to check that.  You're quite
   welcome to create it.

7. For what it's worth, IDE disks, SCSI disks and all the other
   non-removable decive models other than microdrives happily work
   without such a check.

What now?

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 18:24                     ` Markus Armbruster
@ 2011-08-03 20:20                       ` andrzej zaborowski
  2011-08-04  8:02                         ` Kevin Wolf
  2011-08-04  9:36                         ` Markus Armbruster
  0 siblings, 2 replies; 145+ messages in thread
From: andrzej zaborowski @ 2011-08-03 20:20 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
> andrzej zaborowski <balrogg@gmail.com> writes:
>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>                                                      2. if the
>>>> underlaying storage can disappear for any other reason if that's
>>>> possible to check.
>>>
>>> bdrv_is_removable() *isn't* such a check.
>>
>> Obviously I wasn't claiming it is, just that it might be useful, but
>> not necessrily possible.  After all pretty much any storage can be
>> "ejected" with enough force, depending on how far you want to go.
>>
>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>
>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>
>> So first you said you had a problem with _is_removable, and then you
>> said nothing was wrong with the implementation you outlined, plase
>> make up your mind.
>
> I don't appreciate you quoting me out of context like that.

I got quite annoyed when you started putting words in my mouth by
saying I said anything about CD-ROM.. the code in spitz/tosa is not
concerned with CD-ROMs even if downstream it boils down to that, it is
concerned with whether the device is removable or not, and that's what
the check does.  It doesn't help readability or anything by inlining
that check.  If you're trying to check for A then don't spell it out
as B, be explicit.  It's not a big deal but I just don't see the
point, sorry.

>
> The sentence you quoted was in the middle of my attempt to get you to
> explain what you're trying to accomplish there.

I already said about 3 times what it's trying to acomplish.  You also
have used the word "removable" so I'm sure you know what it means and
don't need further explanation.  But let's define it this way: if a
GUI is going to display an "eject" button next to a drive in the qemu
device tree, that's a removable device.  CD-ROM is an example of that.
 An IDE HDD is an example of something that's not going to have that
button (I assume).

> I started with
> analyzing what your code does.  You asked "what's wrong with that", and
> I replied that I'm not passing judgement on whether your code is right
> or wrong, I just want to know what you're trying to do.
>
> I'm getting tired of our misunderstandings, but let me try one more
> time, and tiresomely verbose:

Yes, same here.

>
> 1. bdrv_is_removable() is ill-defined junk, and needs to go away.

Then replace it with something else, I don't know.  Your original
argument was it was too convoluted.

>
>   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.
>
>   That's not semantics, that's an embarrassment.

Certainly if it can be made simpler then by all means let's make it
simpler, but world is complicated like that.

>
> 2. I don't have an opinion on what should be done in
>   tosa_microdrive_attach() and spitz_microdrive_attach().  Heck, I
>   wouldn't touch it with a 9ft pole if I could help it.  But I have to,
>   because it uses bdrv_is_removable().
>
> 3. My first try was to preserve the current behavior.  You don't like
>   the result.  Fine.
>
> 4. For my second try, I tried to understand what you're trying to
>   accomplish there.  Turns out you want to check whether "the
>   underlaying storage can disappear for any other reason if that's
>   possible to check."  Thanks for explaining that.

No, I shouldn't have mentioned that, it's a lateral "would be nice to
have" issue and as I said it's likely not worth it.

>
> 5. Sorry, that's not what the code there does.
>
> 6. The block layer does not offer an API to check that.  You're quite
>   welcome to create it.

See above.

>
> 7. For what it's worth, IDE disks, SCSI disks and all the other
>   non-removable decive models other than microdrives happily work
>   without such a check.

Yes, removing the check would probably make more sense than you
current approach, but then I don't see a particular need for it
either.  (You can remove other checks like writing beyond the end of
device and stuff will keep working.)

And you have used the word "non-removable" so you must know what it
means, why then are you asking about the intention of that if ()?

Cheers

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 20:20                       ` andrzej zaborowski
@ 2011-08-04  8:02                         ` Kevin Wolf
  2011-08-09  4:32                           ` andrzej zaborowski
  2011-08-04  9:36                         ` Markus Armbruster
  1 sibling, 1 reply; 145+ messages in thread
From: Kevin Wolf @ 2011-08-04  8:02 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, Markus Armbruster, amit.shah, lcapitulino

Am 03.08.2011 22:20, schrieb andrzej zaborowski:
> On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
>> andrzej zaborowski <balrogg@gmail.com> writes:
>>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>                                                      2. if the
>>>>> underlaying storage can disappear for any other reason if that's
>>>>> possible to check.
>>>>
>>>> bdrv_is_removable() *isn't* such a check.
>>>
>>> Obviously I wasn't claiming it is, just that it might be useful, but
>>> not necessrily possible.  After all pretty much any storage can be
>>> "ejected" with enough force, depending on how far you want to go.
>>>
>>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>>
>>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>>
>>> So first you said you had a problem with _is_removable, and then you
>>> said nothing was wrong with the implementation you outlined, plase
>>> make up your mind.
>>
>> I don't appreciate you quoting me out of context like that.
> 
> I got quite annoyed when you started putting words in my mouth by
> saying I said anything about CD-ROM.. the code in spitz/tosa is not
> concerned with CD-ROMs even if downstream it boils down to that, it is
> concerned with whether the device is removable or not, and that's what
> the check does.  It doesn't help readability or anything by inlining
> that check.  If you're trying to check for A then don't spell it out
> as B, be explicit.  It's not a big deal but I just don't see the
> point, sorry.
> 
>>
>> The sentence you quoted was in the middle of my attempt to get you to
>> explain what you're trying to accomplish there.
> 
> I already said about 3 times what it's trying to acomplish.  You also
> have used the word "removable" so I'm sure you know what it means and
> don't need further explanation.  But let's define it this way: if a
> GUI is going to display an "eject" button next to a drive in the qemu
> device tree, that's a removable device.  CD-ROM is an example of that.
>  An IDE HDD is an example of something that's not going to have that
> button (I assume).

But this is a property of the device, not of the backend. This means
that it belongs in the device emulation and not in block.c.

If you want to have a function spitz_microdrive_is_removable() or
similar in the device model I don't really mind (even though I don't see
the point), but the block layer is the wrong place for it.

Kevin

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-03 20:20                       ` andrzej zaborowski
  2011-08-04  8:02                         ` Kevin Wolf
@ 2011-08-04  9:36                         ` Markus Armbruster
  1 sibling, 0 replies; 145+ messages in thread
From: Markus Armbruster @ 2011-08-04  9:36 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: kwolf, Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

andrzej zaborowski <balrogg@gmail.com> writes:

> On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
>> andrzej zaborowski <balrogg@gmail.com> writes:
>>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>                                                      2. if the
>>>>> underlaying storage can disappear for any other reason if that's
>>>>> possible to check.
>>>>
>>>> bdrv_is_removable() *isn't* such a check.
>>>
>>> Obviously I wasn't claiming it is, just that it might be useful, but
>>> not necessrily possible.  After all pretty much any storage can be
>>> "ejected" with enough force, depending on how far you want to go.
>>>
>>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>>
>>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>>
>>> So first you said you had a problem with _is_removable, and then you
>>> said nothing was wrong with the implementation you outlined, plase
>>> make up your mind.
>>
>> I don't appreciate you quoting me out of context like that.
>
> I got quite annoyed when you started putting words in my mouth by
> saying I said anything about CD-ROM.. the code in spitz/tosa is not

I didn't intend to annoy.  It was an honest attempt to figure out what
you want to accomplish there.  Sorry it came out the wrong way.

[...]

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-04  8:02                         ` Kevin Wolf
@ 2011-08-09  4:32                           ` andrzej zaborowski
  2011-08-09  7:32                             ` Kevin Wolf
  0 siblings, 1 reply; 145+ messages in thread
From: andrzej zaborowski @ 2011-08-09  4:32 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, Markus Armbruster, amit.shah, lcapitulino

On 4 August 2011 10:02, Kevin Wolf <kwolf@redhat.com> wrote:
> Am 03.08.2011 22:20, schrieb andrzej zaborowski:
>> On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>>                                                      2. if the
>>>>>> underlaying storage can disappear for any other reason if that's
>>>>>> possible to check.
>>>>>
>>>>> bdrv_is_removable() *isn't* such a check.
>>>>
>>>> Obviously I wasn't claiming it is, just that it might be useful, but
>>>> not necessrily possible.  After all pretty much any storage can be
>>>> "ejected" with enough force, depending on how far you want to go.
>>>>
>>>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>>>
>>>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>>>
>>>> So first you said you had a problem with _is_removable, and then you
>>>> said nothing was wrong with the implementation you outlined, plase
>>>> make up your mind.
>>>
>>> I don't appreciate you quoting me out of context like that.
>>
>> I got quite annoyed when you started putting words in my mouth by
>> saying I said anything about CD-ROM.. the code in spitz/tosa is not
>> concerned with CD-ROMs even if downstream it boils down to that, it is
>> concerned with whether the device is removable or not, and that's what
>> the check does.  It doesn't help readability or anything by inlining
>> that check.  If you're trying to check for A then don't spell it out
>> as B, be explicit.  It's not a big deal but I just don't see the
>> point, sorry.
>>
>>>
>>> The sentence you quoted was in the middle of my attempt to get you to
>>> explain what you're trying to accomplish there.
>>
>> I already said about 3 times what it's trying to acomplish.  You also
>> have used the word "removable" so I'm sure you know what it means and
>> don't need further explanation.  But let's define it this way: if a
>> GUI is going to display an "eject" button next to a drive in the qemu
>> device tree, that's a removable device.  CD-ROM is an example of that.
>>  An IDE HDD is an example of something that's not going to have that
>> button (I assume).
>
> But this is a property of the device, not of the backend. This means
> that it belongs in the device emulation and not in block.c.

By device do you mean hw/ide/microdrive.c?  I'm not saying it belongs
in block.c, but logically it belongs in the same place as
bdrv_is_inserted, bdrv_is_locked, bdrv_eject etc. no?  So it is a
property of whatever "media" is property of.

>
> If you want to have a function spitz_microdrive_is_removable() or
> similar in the device model I don't really mind (even though I don't see
> the point), but the block layer is the wrong place for it.

Cheers
(I'm slow to reply because I'm on travel)

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-09  4:32                           ` andrzej zaborowski
@ 2011-08-09  7:32                             ` Kevin Wolf
  2011-08-09 11:56                               ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Kevin Wolf @ 2011-08-09  7:32 UTC (permalink / raw)
  To: andrzej zaborowski
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, Markus Armbruster, amit.shah, lcapitulino

Am 09.08.2011 06:32, schrieb andrzej zaborowski:
> On 4 August 2011 10:02, Kevin Wolf <kwolf@redhat.com> wrote:
>> Am 03.08.2011 22:20, schrieb andrzej zaborowski:
>>> On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>>>                                                      2. if the
>>>>>>> underlaying storage can disappear for any other reason if that's
>>>>>>> possible to check.
>>>>>>
>>>>>> bdrv_is_removable() *isn't* such a check.
>>>>>
>>>>> Obviously I wasn't claiming it is, just that it might be useful, but
>>>>> not necessrily possible.  After all pretty much any storage can be
>>>>> "ejected" with enough force, depending on how far you want to go.
>>>>>
>>>>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>>>>
>>>>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>>>>
>>>>> So first you said you had a problem with _is_removable, and then you
>>>>> said nothing was wrong with the implementation you outlined, plase
>>>>> make up your mind.
>>>>
>>>> I don't appreciate you quoting me out of context like that.
>>>
>>> I got quite annoyed when you started putting words in my mouth by
>>> saying I said anything about CD-ROM.. the code in spitz/tosa is not
>>> concerned with CD-ROMs even if downstream it boils down to that, it is
>>> concerned with whether the device is removable or not, and that's what
>>> the check does.  It doesn't help readability or anything by inlining
>>> that check.  If you're trying to check for A then don't spell it out
>>> as B, be explicit.  It's not a big deal but I just don't see the
>>> point, sorry.
>>>
>>>>
>>>> The sentence you quoted was in the middle of my attempt to get you to
>>>> explain what you're trying to accomplish there.
>>>
>>> I already said about 3 times what it's trying to acomplish.  You also
>>> have used the word "removable" so I'm sure you know what it means and
>>> don't need further explanation.  But let's define it this way: if a
>>> GUI is going to display an "eject" button next to a drive in the qemu
>>> device tree, that's a removable device.  CD-ROM is an example of that.
>>>  An IDE HDD is an example of something that's not going to have that
>>> button (I assume).
>>
>> But this is a property of the device, not of the backend. This means
>> that it belongs in the device emulation and not in block.c.
> 
> By device do you mean hw/ide/microdrive.c?

I mean just anything in hw/. I'm not familiar with how these devices
work internally, so if hw/ide/microdrive.c is the right place, fine.

> I'm not saying it belongs
> in block.c, but logically it belongs in the same place as
> bdrv_is_inserted, bdrv_is_locked, bdrv_eject etc. no?  So it is a
> property of whatever "media" is property of.

Depends. As long as you're talking about purely virtual device state, I
would say yes, they belong there, too. However, we have things like
CD-ROM passthrough where bdrv_is_inserted etc. are supposed to return
the status of the physical host device. These are host state and need to
be in the block layer.

Kevin

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-09  7:32                             ` Kevin Wolf
@ 2011-08-09 11:56                               ` Markus Armbruster
  2011-08-09 12:10                                 ` Kevin Wolf
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-09 11:56 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

Kevin Wolf <kwolf@redhat.com> writes:

> Am 09.08.2011 06:32, schrieb andrzej zaborowski:
>> On 4 August 2011 10:02, Kevin Wolf <kwolf@redhat.com> wrote:
>>> Am 03.08.2011 22:20, schrieb andrzej zaborowski:
>>>> On 3 August 2011 20:24, Markus Armbruster <armbru@redhat.com> wrote:
>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>> On 3 August 2011 18:38, Markus Armbruster <armbru@redhat.com> wrote:
>>>>>>> andrzej zaborowski <balrogg@gmail.com> writes:
>>>>>>>>                                                      2. if the
>>>>>>>> underlaying storage can disappear for any other reason if that's
>>>>>>>> possible to check.
>>>>>>>
>>>>>>> bdrv_is_removable() *isn't* such a check.
>>>>>>
>>>>>> Obviously I wasn't claiming it is, just that it might be useful, but
>>>>>> not necessrily possible.  After all pretty much any storage can be
>>>>>> "ejected" with enough force, depending on how far you want to go.
>>>>>>
>>>>>>>>> What's wrong with that again?  All sounds sensible to me.
>>>>>>>>
>>>>>>>> I'm not claiming otherwise, just double-checking this is what you want.
>>>>>>
>>>>>> So first you said you had a problem with _is_removable, and then you
>>>>>> said nothing was wrong with the implementation you outlined, plase
>>>>>> make up your mind.
>>>>>
>>>>> I don't appreciate you quoting me out of context like that.
>>>>
>>>> I got quite annoyed when you started putting words in my mouth by
>>>> saying I said anything about CD-ROM.. the code in spitz/tosa is not
>>>> concerned with CD-ROMs even if downstream it boils down to that, it is
>>>> concerned with whether the device is removable or not, and that's what
>>>> the check does.  It doesn't help readability or anything by inlining
>>>> that check.  If you're trying to check for A then don't spell it out
>>>> as B, be explicit.  It's not a big deal but I just don't see the
>>>> point, sorry.
>>>>
>>>>>
>>>>> The sentence you quoted was in the middle of my attempt to get you to
>>>>> explain what you're trying to accomplish there.
>>>>
>>>> I already said about 3 times what it's trying to acomplish.  You also
>>>> have used the word "removable" so I'm sure you know what it means and
>>>> don't need further explanation.  But let's define it this way: if a
>>>> GUI is going to display an "eject" button next to a drive in the qemu
>>>> device tree, that's a removable device.  CD-ROM is an example of that.
>>>>  An IDE HDD is an example of something that's not going to have that
>>>> button (I assume).
>>>
>>> But this is a property of the device, not of the backend. This means
>>> that it belongs in the device emulation and not in block.c.
>> 
>> By device do you mean hw/ide/microdrive.c?
>
> I mean just anything in hw/. I'm not familiar with how these devices
> work internally, so if hw/ide/microdrive.c is the right place, fine.

We have way too many things we call "device", or "driver"...  Let me try
to dispell the confusion.

Machines spitz, borzoi, terrier (hw/spitz.c) have a spitz microdrive
device.  Machine tosa (hw/tosa.c) has a tosa microdrive device.

Like all block devices, they consist of a frontend and a backend.

Our block device backend abstraction is BlockDriverState.  Internally, a
block device backend is the block layer sitting on top of an optional
BlockDriver.  No block driver is interpreted as no medium.

Monitor command "eject" drops the block driver.

Monitor command "change" first drops the block driver, then attaches a
new one.

A BlockDriver may support removable media.  Host device block drivers
do, the others don't.  Doesn't affect monitor commands eject and change
at all, because these *drop* the block driver.

A block device frontend is attached to a backend on initialization.  In
other words, a backend may exist alone, but a frontend is always
attached to a backend.

A block device frontend may support removable media.  If it does,
monitor commands eject and change work while the frontend is attached.
They always work while no frontend is attached.

Note: we got *two* different "removables" here, frontend and backend.
It is possible to back a removable frontend, say ide-cd, with a
non-removable backend, say file.  The opposite is also possible (whether
it's wise is a different question).

The frontend code is in hw/ide/microdrive.c.  It does *not* support
removable media.  Monitor commands eject and change refuse to touch this
device.

The property "monitor command eject is applicable to the device" is a
property of the frontend, because the frontend and only the frontend
decide whether eject is okay.

The property 'GUI shall display an "eject" button next to a drive in the
qemu device tree' is just the same.

Kevin wrote "this is a property of the device, not of the backend.  This
means that it belongs in the device emulation and not in block.c."
Kevin is correct.  The code is also correct: microdrive.c defines a
non-removable device (by not implementing callback change_media_cb()).
Therefore, monitor commands eject and change will not touch microdrives.

The checks in spitz_microdrive_attach() and tosa_microdrive_attach() do
*not* contribute to that.  All they accomplish is silently refrain from
creating the device if the user created the first IDE drive
(if=ide,index=0) with media=cd.  No more, no less.

I have no opinion on whether that's useful.

If you want to keep it, take my PATCH 44/55 as is.

If you want to create the drive regardless of media=cd, tell me, and
I'll do exactly that in my respin.

>> I'm not saying it belongs
>> in block.c, but logically it belongs in the same place as
>> bdrv_is_inserted, bdrv_is_locked, bdrv_eject etc. no?  So it is a
>> property of whatever "media" is property of.
>
> Depends. As long as you're talking about purely virtual device state, I
> would say yes, they belong there, too. However, we have things like
> CD-ROM passthrough where bdrv_is_inserted etc. are supposed to return
> the status of the physical host device. These are host state and need to
> be in the block layer.

bdrv_is_inserted() is about the backend's media.  At least it is after
my PATCH 21/55 cleans up the mess I made in commit 4be9762a.

bdrv_eject() is a function frontends supporting removable media call to
notify backends of medium eject/load.  If the backend happens to use a
host device block driver, it'll eject/load the physical medium.

Likewise, bdrv_set_locked() is a function frontends supporting removable
media call to notify backends of medium lock/unlock.  If the backend
happens to use a host device block driver, it'll lock/unlock the
physical medium.

bdrv_is_locked() is about the frontend's media lock.  To make this more
obvious, my PATCH 29/55 replaces it by bdrv_dev_is_medium_locked().  It
does *not* query the backend's lock (which may not even exist!) set by
bdrv_set_locked().

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-09 11:56                               ` Markus Armbruster
@ 2011-08-09 12:10                                 ` Kevin Wolf
  2011-08-09 12:36                                   ` Markus Armbruster
  0 siblings, 1 reply; 145+ messages in thread
From: Kevin Wolf @ 2011-08-09 12:10 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

Am 09.08.2011 13:56, schrieb Markus Armbruster:
> bdrv_is_locked() is about the frontend's media lock.  To make this more
> obvious, my PATCH 29/55 replaces it by bdrv_dev_is_medium_locked().  It
> does *not* query the backend's lock (which may not even exist!) set by
> bdrv_set_locked().

This sounds wrong (the behaviour, not your analysis). Do you plan to
remove bdrv_dev_is_medium_locked() as well? It is used by IDE and
scsi-disk (easy to replace) and in eject_device() in blockdev.c. Maybe
the 'eject' monitor command should be handled by another callback into
the device.

Kevin

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-09 12:10                                 ` Kevin Wolf
@ 2011-08-09 12:36                                   ` Markus Armbruster
  2011-08-09 12:46                                     ` Kevin Wolf
  0 siblings, 1 reply; 145+ messages in thread
From: Markus Armbruster @ 2011-08-09 12:36 UTC (permalink / raw)
  To: Kevin Wolf
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

Kevin Wolf <kwolf@redhat.com> writes:

> Am 09.08.2011 13:56, schrieb Markus Armbruster:
>> bdrv_is_locked() is about the frontend's media lock.  To make this more
>> obvious, my PATCH 29/55 replaces it by bdrv_dev_is_medium_locked().  It
>> does *not* query the backend's lock (which may not even exist!) set by
>> bdrv_set_locked().
>
> This sounds wrong (the behaviour, not your analysis). Do you plan to
> remove bdrv_dev_is_medium_locked() as well? It is used by IDE and
> scsi-disk (easy to replace) and in eject_device() in blockdev.c. Maybe
> the 'eject' monitor command should be handled by another callback into
> the device.

Just two users remain after my series:

* bdrv_info()

  It wants to show the frontend's lock state, and uses
  bdrv_dev_is_medium_locked() to get it from the frontend.

* eject_device()

  It needs to fail if the frontend has its medium locked.  It uses
  bdrv_dev_is_medium_locked() to get the lock state from the frontend.
  Pseudo code (-f glossed over for simplicity):

      unless frontend has removable media
              fail
      if frontend medium is not already open
         and frontend medium is locked
              fail
      drop the block driver

  I considered replacing this with "ask the frontend to eject", and then
  let the frontend decide whether to order the backend to drop the block
  driver.  I decided against it, since I need
  bdrv_dev_is_medium_locked() anyway for bdrv_info().  Besides, the
  series is long enough already.

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

* Re: [Qemu-devel] [PATCH 44/55] spitz tosa: Simplify "drive is suitable for microdrive" test
  2011-08-09 12:36                                   ` Markus Armbruster
@ 2011-08-09 12:46                                     ` Kevin Wolf
  0 siblings, 0 replies; 145+ messages in thread
From: Kevin Wolf @ 2011-08-09 12:46 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Maydell, quintela, dbaryshkov, stefano.stabellini,
	qemu-devel, lcapitulino, amit.shah

Am 09.08.2011 14:36, schrieb Markus Armbruster:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
>> Am 09.08.2011 13:56, schrieb Markus Armbruster:
>>> bdrv_is_locked() is about the frontend's media lock.  To make this more
>>> obvious, my PATCH 29/55 replaces it by bdrv_dev_is_medium_locked().  It
>>> does *not* query the backend's lock (which may not even exist!) set by
>>> bdrv_set_locked().
>>
>> This sounds wrong (the behaviour, not your analysis). Do you plan to
>> remove bdrv_dev_is_medium_locked() as well? It is used by IDE and
>> scsi-disk (easy to replace) and in eject_device() in blockdev.c. Maybe
>> the 'eject' monitor command should be handled by another callback into
>> the device.
> 
> Just two users remain after my series:
> 
> * bdrv_info()
> 
>   It wants to show the frontend's lock state, and uses
>   bdrv_dev_is_medium_locked() to get it from the frontend.

bdrv_info() is a nasty reason for keeping this in the block layer.

> * eject_device()
> 
>   It needs to fail if the frontend has its medium locked.  It uses
>   bdrv_dev_is_medium_locked() to get the lock state from the frontend.
>   Pseudo code (-f glossed over for simplicity):
> 
>       unless frontend has removable media
>               fail
>       if frontend medium is not already open
>          and frontend medium is locked
>               fail
>       drop the block driver
> 
>   I considered replacing this with "ask the frontend to eject", and then
>   let the frontend decide whether to order the backend to drop the block
>   driver.  I decided against it, since I need
>   bdrv_dev_is_medium_locked() anyway for bdrv_info().  Besides, the
>   series is long enough already.

I'm not asking to change it in this series, but in general I think it
would be a good change to make.

Kevin

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

end of thread, other threads:[~2011-08-09 14:11 UTC | newest]

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

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.