Block layer cleanup & fixes
v2 cover Block layer cleanup & fixes
This patch series looks bigger than it is. All the patches are small and hopefully easy to review.
Objectives:
* Push BlockDriverState members locked, tray_open, media_changed into device models, where they belong.
* BlockDriverState member removable is a confusing mess, replace it.
* Improve eject -f.
Also clean up minor messes as they get in the way.
It is based on Kevin's block branch f08df41b.
Part I: Preliminaries
PATCH 01-03: Work on block layer interface for device models
Part II: Move tray state to device models
PATCH 04-10 IDE tray open/closed
PATCH 11-12 SCSI tray open/closed
PATCH 13-14 block layer kill tray_open
PATCH 15-16 IDE & SCSI tray lock
PATCH 17-19 block layer kill locked
PATCH 20-24 IDE & SCSI tray bug fixes
PATCH 25-27 IDE & SCSI migrate tray state
PATCH 28-30 block layer & fdc media_changed
Part III: Replace removable
PATCH 31-34 clean up inappopriate uses of removable PATCH 35-36 replace remaining users
Part IV: Miscellaneous
PATCH 37 cover tray open/closed in info block
PATCH 38-43 Reduce unclean use of block_int.h
PATCH 44-45 Improve eject -f
Naturally, I want all parts applied. But I did my best to make applying only a prefix workable, too.
Review invited from:
* Kevin, Christoph and Amit reviewed v1.
* Hannes commented on the SCSI stuff in v1.
* Luiz, the following patches affect QMP's query-block: PATCH 35 block: Clean up remaining users of "removable"' and PATCH 38 block: Show whether the guest ejected the medium in info block'.
* Juan, please review PATCH 26 ide/atapi: Preserve tray state on migration', PATCH 27 scsi-disk: Preserve tray state on migration', and PATCH 32 `savevm: Include writable devices with removable media'.
* Andrzej commented to v1 of PATCH 34 `spitz tosa: Simplify "drive is suitable for microdrive" test'. It is unchanged.
* Stefano, you reviewed v1 of PATCH 35 (affects "-drive if=xen"). Please have a look at new PATCH 33 `xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD"'.
Testing
* Both master and the block branch are broken for me by Avi's memory API work (Avi reproduced, and claims to have a fix), so for testing I had to rebase the block branch on an older master cde1a700 plus my
dependencies: some Xen work e3745602..679f4f8b, and some nand work 64de0e46..63efb1d9.
* Linux boots, both from HD and CD.
* For both IDE and SCSI:
- info block reports tray state correctly
- Guest locking the tray stops eject (without -f) and change
- eject -f; change works even while tray is locked by guest
- Physical tray state tracks the virtual one (file=/dev/sr0)
- Reading /dev/sr0 with tray open behaves as before: IDE closes the tray and reads (matches bare metal), SCSI reports no medium
- Tray state is migrated correctly (tested with savevm/loadvm)
* Guest still notices CD media change (IDE only, SCSI doesn't work before or after my patches because GESN isn't implemented)
* Migrating ide-cd to older version works when tray is closed and unlocked, else fails (tested with savevm/loadvm)
* Migrating scsi-cd to older version fails
* Linux detects fdc media change (from monitor)
* savevm and loadvm snapshot read/write floppy
* spitz and tosa initialize their microdrive as before (PATCH 34; tested with -S -M {spitz,tosa}, didn't actually try to boot)
Not tested:
* BlockDriver "host_floppy"
Lack the hardware. Like pretty much everybody not running a computer museum.
Is keeping BlockDriver "host_floppy" around still worth our while?
If the answer is no, I'm happy to respin with PATCH 28-30 replaced by a single patch to remove it, and simplify block.c and hw/fdc.c.
v2:
* Rebased to block branch; non-trivial conflicts:
- Old PATCH 01-02,06-09 already there, drop
- `block: Attach non-qdev devices as well':
- cover new pci_piix3_xen_ide_unplug()
- hw/nand has been qdefivied, drop hunk
- onenand_init() changed, rewrite hunk
- pci_piix3_xen_ide_unplug() needs new PATCH 33.
* Drop old PATCH 18 `scsi-disk: Reject CD-specific SCSI commands to disks' because Hannes wants to do it differently, and it's not essential to this series.
* Christoph's advice:
- Rework `ide: Update command code definitions as per ACS-2'
- Add comment to `ide: Fix ATA command READ to set ATAPI signature for CD-ROM'
- Squash ide/atapi: Track tray open/close state' and ide/atapi:
Switch from BlockDriverState's tray_open to own'
- Squash ide/atapi: Track tray locked state' and ide/atapi: Switch from BlockDriverState's locked to own tray_locked'
- Squash scsi-disk: Track tray locked state' and scsi-disk: Switch from BlockDriverState's locked to own tray_locked'
- Drop `block: Move BlockDriverAIOCB & friends from block_int.h to block.h'
* Luiz's advice:
- Change query-block to always include "ejected" for removable devices. Requires moving `block: Show whether the guest ejected the medium in info block', which causes a bunch of conflicts.
* A few cosmetic improvements
Markus Armbruster (45):
block: Attach non-qdev devices as well
block: Generalize change_cb() to BlockDevOps
block: Split change_cb() into change_media_cb(), resize_cb()
ide: Update command code definitions as per ACS-2 Table B.2
ide: Clean up case label indentation in ide_exec_cmd()
ide: Fix ATA command READ to set ATAPI signature for CD-ROM
ide: Use a table to declare which drive kinds accept each command
ide: Reject ATA commands specific to drive kinds ide/atapi: Clean up misleading name in cmd_start_stop_unit() ide/atapi: Track tray open/close state
scsi-disk: Factor out scsi_disk_emulate_start_stop()
scsi-disk: Track tray open/close state
block: Revert entanglement of bdrv_is_inserted() with tray status
block: Drop tray status tracking, no longer used ide/atapi: Track tray locked state
scsi-disk: Track tray locked state
block: Leave enforcing tray lock to device models
block: Drop medium lock tracking, ask device models instead
block: Rename bdrv_set_locked() to bdrv_lock_medium()
ide: Provide IDEDeviceInfo method exit()
ide/atapi: Don't fail eject when tray is already open ide/atapi: Avoid physical/virtual tray state mismatch
scsi-disk: Fix START_STOP to fail when it can't eject
scsi-disk: Avoid physical/virtual tray state mismatch
ide: Give vmstate structs internal linkage where possible ide/atapi: Preserve tray state on migration
scsi-disk: Preserve tray state on migration
block/raw: Fix to forward method bdrv_media_changed()
block: Leave tracking media change to device models
fdc: Make media change detection more robust
block: Clean up bdrv_flush_all()
savevm: Include writable devices with removable media
xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD" spitz tosa: Simplify "drive is suitable for microdrive" test
block: Clean up remaining users of "removable"
block: Drop BlockDriverState member removable
block: Show whether the guest ejected the medium in info block
block: Move BlockConf & friends from block_int.h to block.h
hw: Trim superfluous #include "block_int.h"
block: Declare qemu_blockalign() in block.h, not block_int.h
block: New bdrv_set_buffer_alignment()
block: Reset buffer alignment on detach
nbd: Clean up use of block_int.h
block: New change_media_cb() parameter load
ide/atapi scsi-disk: Make monitor eject -f, then change work
block.c | 195 +++++++++++++++++++++++++++----------------------- block.h | 90 ++++++++++++++++++++--- block/nbd.c | 1 + block/raw-posix.c | 8 +- block/raw.c | 13 +++- block_int.h | 54 ++------------- blockdev.c | 15 ++--- hw/fdc.c | 48 ++++++------- hw/ide/atapi.c | 58 +++++++-------- hw/ide/cmd646.c | 1 - hw/ide/core.c | 196 ++++++++++++++++++++++++++++++++++++++------------ hw/ide/ich.c | 1 - hw/ide/internal.h | 175 ++++++++++++++++++++++++--------------------- hw/ide/isa.c | 1 - hw/ide/macio.c | 1 - hw/ide/microdrive.c | 1 - hw/ide/mmio.c | 1 - hw/ide/pci.c | 1 - hw/ide/piix.c | 7 +- hw/ide/qdev.c | 30 ++++++++ hw/ide/via.c | 1 - hw/lsi53c895a.c | 1 - hw/onenand.c | 4 +- hw/pflash_cfi01.c | 1 + hw/pflash_cfi02.c | 1 + hw/qdev-properties.c | 6 +- hw/scsi-bus.c | 10 +++ hw/scsi-disk.c | 111 ++++++++++++++++++++++++++--- hw/scsi-generic.c | 1 - hw/scsi.h | 5 +- hw/sd.c | 14 ++-- hw/spitz.c | 10 +-- hw/tosa.c | 10 +-- hw/usb-msd.c | 2 +- hw/virtio-blk.c | 15 ++-- hw/virtio.h | 2 +- hw/xen_disk.c | 1 + nbd.c | 1 + nbd.h | 2 - qmp-commands.hx | 2 + savevm.c | 4 +- trace-events | 2 +- 42 files changed, 690 insertions(+), 413 deletions(-)
Signature · 1 line
1.7.6
PATCH v2 1/45 block: Attach non-qdev devices as well
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().
--- block.c | 29 ++++++++++++++++++++--------- block.h | 7 ++++--- block_int.h | 3 ++- blockdev.c | 5 ++--- hw/ide/core.c | 1 + hw/ide/piix.c | 4 ++-- hw/onenand.c | 4 +++- hw/pflash_cfi01.c | 1 + hw/pflash_cfi02.c | 1 + hw/qdev-properties.c | 6 +++--- hw/sd.c | 1 + hw/usb-msd.c | 2 +- hw/xen_disk.c | 1 + 13 files changed, 42 insertions(+), 23 deletions(-)
block.c +20 -9
@@ -728,7 +728,7 @@ void bdrv_make_anon(BlockDriverState *bs)void bdrv_delete (BlockDriverState *bs) { -assert (!bs->peer); +assert (!bs->dev);/* remove from list, if necessary */ bdrv_make_anon (bs);
@@ -742,26 +742,37 @@ void bdrv_delete(BlockDriverState *bs)qemu_free (bs); } -int bdrv_attach (BlockDriverState *bs,DeviceState *qdev) +int bdrv_attach_dev (BlockDriverState *bs,void *dev) +/* TODO change to DeviceState *dev when all users are qdevified */ { -if (bs->peer) { +if (bs->dev) {return -EBUSY ; } - bs->peer = qdev; + bs->dev = dev;return 0 ; } -void bdrv_detach (BlockDriverState *bs,DeviceState *qdev) +/* TODO qdevified devices don't use this, remove when devices are qdevified */ +void bdrv_attach_dev_nofail (BlockDriverState *bs,void *dev) { -assert (bs->peer == qdev); - bs->peer =NULL ; +if (bdrv_attach_dev (bs, dev) <0 ) { +abort (); + } +} + +void bdrv_detach_dev (BlockDriverState *bs,void *dev) +/* TODO change to DeviceState *dev when all users are qdevified */ +{ +assert (bs->dev == dev); + bs->dev =NULL ; bs->change_cb =NULL ; bs->change_opaque =NULL ; } -DeviceState *bdrv_get_attached (BlockDriverState *bs) +/* TODO change to return DeviceState * when all users are qdevified */ +void *bdrv_get_attached_dev (BlockDriverState *bs) { -return bs->peer; +return bs->dev; }/*
block.h +4 -3
@@ -73,9 +73,10 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);int bdrv_open (BlockDriverState *bs,const char *filename,int flags,BlockDriver *drv);void bdrv_close (BlockDriverState *bs); -int bdrv_attach (BlockDriverState *bs,DeviceState *qdev); -void bdrv_detach (BlockDriverState *bs,DeviceState *qdev); -DeviceState *bdrv_get_attached (BlockDriverState *bs); +int bdrv_attach_dev (BlockDriverState *bs,void *dev); +void bdrv_attach_dev_nofail (BlockDriverState *bs,void *dev); +void bdrv_detach_dev (BlockDriverState *bs,void *dev); +void *bdrv_get_attached_dev (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num,
block_int.h +2 -1
@@ -167,7 +167,8 @@ struct BlockDriverState {BlockDriver *drv;/* NULL means no media */ void *opaque; -DeviceState *peer; +void *dev;/* attached device model, if any */ +/* TODO change to DeviceState when all users are qdevified */ char filename[1024 ];char backing_file[1024 ];/* if non zero, the image is a diff of
blockdev.c +2 -3
@@ -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));
hw/ide/core.c +1 -0
@@ -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]); }
hw/ide/piix.c +2 -2
@@ -162,9 +162,9 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)for (; i <3 ; i++) { di =drive_get_by_index (IF_IDE , i);if (di !=NULL && di->bdrv !=NULL && !di->bdrv->removable) { -DeviceState *ds =bdrv_get_attached (di->bdrv); +DeviceState *ds =bdrv_get_attached_dev (di->bdrv);if (ds) { -bdrv_detach (di->bdrv, ds); +bdrv_detach_dev (di->bdrv, ds); }bdrv_close (di->bdrv); pci_ide->bus[di->bus].ifs[di->unit].bs =NULL ;
hw/onenand.c +3 -1
@@ -717,7 +717,9 @@ void *onenand_init(BlockDriverState *bdrv, s->iomemtype =cpu_register_io_memory (onenand_readfn, onenand_writefn, s,DEVICE_NATIVE_ENDIAN ); s->bdrv = bdrv; -if (!s->bdrv) { +if (s->bdrv) { +bdrv_attach_dev_nofail (s->bdrv, s); + }else { s->image =memset (qemu_malloc (size + (size >>5 )),0xff , size + (size >>5 )); }
hw/pflash_cfi01.c +1 -0
@@ -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).
hw/pflash_cfi02.c +1 -0
@@ -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).
hw/qdev-properties.c +3 -3
@@ -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),
hw/sd.c +1 -0
@@ -449,6 +449,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi) sd->enable =1 ;sd_reset (sd, bs);if (sd->bdrv) { +bdrv_attach_dev_nofail (sd->bdrv, sd);bdrv_set_change_cb (sd->bdrv, sd_cardchange, sd); }return sd;
hw/usb-msd.c +1 -1
@@ -523,7 +523,7 @@ static int usb_msd_initfn(USBDevice *dev)* * The hack is probably a bad idea. */ -bdrv_detach (bs, &s->dev.qdev); +bdrv_detach_dev (bs, &s->dev.qdev); s->conf.bs =NULL ;if (!s->serial) {
hw/xen_disk.c +1 -0
@@ -692,6 +692,7 @@ static int blk_init(struct XenDevice *xendev)xen_be_printf (&blkdev->xendev,2 ,"get configured bdrv (cmdline setup)\n" ); blkdev->bs = blkdev->dinfo->bdrv; } +bdrv_attach_dev_nofail (blkdev->bs, blkdev); blkdev->file_blk =BLOCK_SIZE ; blkdev->file_size =bdrv_getlength (blkdev->bs);if (blkdev->file_size <0 ) {
Signature · 1 line
1.7.6
PATCH v2 2/45 block: Generalize change_cb() to BlockDevOps
In reply to Markus ArmbrusterSo we can more easily add device model callbacks.
--- 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(-)
block.c +21 -22
@@ -44,6 +44,7 @@#include <windows.h> #endif +static void bdrv_dev_change_cb (BlockDriverState *bs,int reason);static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);
@@ -661,10 +662,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }if (!bdrv_key_required (bs)) { -/* call the change callback */ bs->media_changed =1 ; -if (bs->change_cb) - bs->change_cb (bs->change_opaque,CHANGE_MEDIA ); +bdrv_dev_change_cb (bs,CHANGE_MEDIA ); }return 0 ;
@@ -700,10 +699,8 @@ void bdrv_close(BlockDriverState *bs)bdrv_close (bs->file); } -/* call the change callback */ bs->media_changed =1 ; -if (bs->change_cb) - bs->change_cb (bs->change_opaque,CHANGE_MEDIA ); +bdrv_dev_change_cb (bs,CHANGE_MEDIA ); } }
@@ -765,8 +762,8 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev) {assert (bs->dev == dev); bs->dev =NULL ; - bs->change_cb =NULL ; - bs->change_opaque =NULL ; + bs->dev_ops =NULL ; + bs->dev_opaque =NULL ; }/* TODO change to return DeviceState * when all users are qdevified */
@@ -775,6 +772,20 @@ void *bdrv_get_attached_dev(BlockDriverState *bs)return bs->dev; } +void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops, +void *opaque) +{ + bs->dev_ops = ops; + bs->dev_opaque = opaque; +} + +static void bdrv_dev_change_cb (BlockDriverState *bs,int reason) +{ +if (bs->dev_ops && bs->dev_ops->change_cb) { + bs->dev_ops->change_cb (bs->dev_opaque, reason); + } +} +/* * Run consistency checks on an image *
@@ -1232,9 +1243,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate (bs, offset);if (ret ==0 ) { ret =refresh_total_sectors (bs, offset >>BDRV_SECTOR_BITS ); -if (bs->change_cb) { - bs->change_cb (bs->change_opaque,CHANGE_SIZE ); - } +bdrv_dev_change_cb (bs,CHANGE_SIZE ); }return ret; }
@@ -1572,15 +1581,6 @@ int bdrv_enable_write_cache(BlockDriverState *bs)return bs->enable_write_cache; } -/* XXX: no longer used */ -void bdrv_set_change_cb (BlockDriverState *bs, -void (*change_cb)(void *opaque,int reason), -void *opaque) -{ - bs->change_cb = change_cb; - bs->change_opaque = opaque; -} -int bdrv_is_encrypted (BlockDriverState *bs) {if (bs->backing_hd && bs->backing_hd->encrypted)
@@ -1619,8 +1619,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ bs->media_changed =1 ; -if (bs->change_cb) - bs->change_cb (bs->change_opaque,CHANGE_MEDIA ); +bdrv_dev_change_cb (bs,CHANGE_MEDIA ); }return ret; }
block.h +6 -3
@@ -28,6 +28,10 @@ typedef struct QEMUSnapshotInfo {uint64_t vm_clock_nsec;/* VM clock relative to boot */ } QEMUSnapshotInfo; +typedef struct BlockDevOps { +void (*change_cb)(void *opaque,int reason); +}BlockDevOps ; +#define BDRV_O_RDWR 0x0002#define BDRV_O_SNAPSHOT 0x0008/* open the file read only and save writes in a snapshot */ #define BDRV_O_NOCACHE 0x0020/* do not use the host page cache */
@@ -77,6 +81,8 @@ int bdrv_attach_dev(BlockDriverState *bs, void *dev);void bdrv_attach_dev_nofail (BlockDriverState *bs,void *dev);void bdrv_detach_dev (BlockDriverState *bs,void *dev);void *bdrv_get_attached_dev (BlockDriverState *bs); +void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops, +void *opaque);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num,
@@ -192,9 +198,6 @@ int bdrv_media_changed(BlockDriverState *bs);int bdrv_is_locked (BlockDriverState *bs);void bdrv_set_locked (BlockDriverState *bs,int locked);int bdrv_eject (BlockDriverState *bs,int eject_flag); -void bdrv_set_change_cb (BlockDriverState *bs, -void (*change_cb)(void *opaque,int reason), -void *opaque);void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size);BlockDriverState *bdrv_find (const char *name);BlockDriverState *bdrv_next (BlockDriverState *bs);
block_int.h +2 -3
@@ -160,15 +160,14 @@ struct BlockDriverState {int encrypted;/* if true, the media is encrypted */ int valid_key;/* if true, a valid encryption key has been set */ int sg;/* if true, the device is a /dev/sg* */ -/* event callback when inserting/removing */ -void (*change_cb)(void *opaque,int reason); -void *change_opaque;BlockDriver *drv;/* NULL means no media */ void *opaque;void *dev;/* attached device model, if any */ /* TODO change to DeviceState when all users are qdevified */ +const BlockDevOps *dev_ops; +void *dev_opaque;char filename[1024 ];char backing_file[1024 ];/* if non zero, the image is a diff of
hw/ide/core.c +5 -1
@@ -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)) {
hw/sd.c +5 -1
@@ -435,6 +435,10 @@ static void sd_cardchange(void *opaque, int reason) } } +static const BlockDevOps sd_block_ops = { + .change_cb = sd_cardchange, +}; +/* We do not model the chip select pin, so allow the board to select whether card should be in SSI or MMC/SD mode. It is also up to the board to ensure that ssi transfers only occur when the chip select
@@ -450,7 +454,7 @@ SDState *sd_init(BlockDriverState *bs, int is_spi)sd_reset (sd, bs);if (sd->bdrv) {bdrv_attach_dev_nofail (sd->bdrv, sd); -bdrv_set_change_cb (sd->bdrv, sd_cardchange, sd); +bdrv_set_dev_ops (sd->bdrv, &sd_block_ops, sd); }return sd; }
hw/virtio-blk.c +5 -1
@@ -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" );
Signature · 1 line
1.7.6
PATCH v2 3/45 block: Split change_cb() into change_media_cb(), resize_cb()
In reply to Markus ArmbrusterMultiplexing callbacks complicates matters needlessly.
--- 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(-)
block.c +15 -8
@@ -44,7 +44,7 @@#include <windows.h> #endif -static void bdrv_dev_change_cb (BlockDriverState *bs,int reason); +static void bdrv_dev_change_media_cb (BlockDriverState *bs);static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);
@@ -663,7 +663,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,if (!bdrv_key_required (bs)) { bs->media_changed =1 ; -bdrv_dev_change_cb (bs,CHANGE_MEDIA ); +bdrv_dev_change_media_cb (bs); }return 0 ;
@@ -700,7 +700,7 @@ void bdrv_close(BlockDriverState *bs) } bs->media_changed =1 ; -bdrv_dev_change_cb (bs,CHANGE_MEDIA ); +bdrv_dev_change_media_cb (bs); } }
@@ -779,10 +779,17 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, bs->dev_opaque = opaque; } -static void bdrv_dev_change_cb (BlockDriverState *bs,int reason) +static void bdrv_dev_change_media_cb (BlockDriverState *bs) { -if (bs->dev_ops && bs->dev_ops->change_cb) { - bs->dev_ops->change_cb (bs->dev_opaque, reason); +if (bs->dev_ops && bs->dev_ops->change_media_cb) { + bs->dev_ops->change_media_cb (bs->dev_opaque); + } +} + +static void bdrv_dev_resize_cb (BlockDriverState *bs) +{ +if (bs->dev_ops && bs->dev_ops->resize_cb) { + bs->dev_ops->resize_cb (bs->dev_opaque); } }
@@ -1243,7 +1250,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate (bs, offset);if (ret ==0 ) { ret =refresh_total_sectors (bs, offset >>BDRV_SECTOR_BITS ); -bdrv_dev_change_cb (bs,CHANGE_SIZE ); +bdrv_dev_resize_cb (bs); }return ret; }
@@ -1619,7 +1626,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ bs->media_changed =1 ; -bdrv_dev_change_cb (bs,CHANGE_MEDIA ); +bdrv_dev_change_media_cb (bs); }return ret; }
block.h +11 -1
@@ -28,8 +28,18 @@ typedef struct QEMUSnapshotInfo {uint64_t vm_clock_nsec;/* VM clock relative to boot */ } QEMUSnapshotInfo; +/* Callbacks for block device models */ typedef struct BlockDevOps { -void (*change_cb)(void *opaque,int reason); +/* +* Runs when virtual media changed (monitor commands eject, change) +* Beware: doesn't run when a host device's physical media +* changes. Sure would be useful if it did. +*/ +void (*change_media_cb)(void *opaque); +/* +* Runs when the size changed (e.g. monitor command block_resize) +*/ +void (*resize_cb)(void *opaque); }BlockDevOps ;#define BDRV_O_RDWR 0x0002
block_int.h +0 -3
@@ -211,9 +211,6 @@ struct BlockDriverState {void *private; }; -#define CHANGE_MEDIA 0x01 -#define CHANGE_SIZE 0x02 -struct BlockDriverAIOCB {AIOPool *pool;BlockDriverState *bs;
hw/ide/core.c +2 -6
@@ -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,
hw/sd.c +2 -6
@@ -420,14 +420,10 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) sd->pwd_len =0 ; } -static void sd_cardchange (void *opaque,int reason) +static void sd_cardchange (void *opaque) {SDState *sd = opaque; -if (!(reason &CHANGE_MEDIA )) { -return ; - } -qemu_set_irq (sd->inserted_cb,bdrv_is_inserted (sd->bdrv));if (bdrv_is_inserted (sd->bdrv)) {sd_reset (sd, sd->bdrv);
@@ -436,7 +432,7 @@ static void sd_cardchange(void *opaque, int reason) }static const BlockDevOps sd_block_ops = { - .change_cb = sd_cardchange, + .change_media_cb = sd_cardchange, };/* We do not model the chip select pin, so allow the board to select
hw/virtio-blk.c +3 -5
@@ -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,
Signature · 1 line
1.7.6
PATCH v2 4/45 ide: Update command code definitions as per ACS-2 Table B.2
In reply to Markus ArmbrusterDrop WIN_SRST, it has the same value as WIN_DEVICE_RESET.
Drop unused WIN_RESTORE, it has the same value as WIN_RECAL.
Drop codes that are not implemented and long obsolete: WIN_READ_LONG, WIN_READ_LONG_ONCE, WIN_WRITE_LONG, WIN_WRITE_LONG_ONCE, WIN_FORMAT (all obsolete since ATA4), WIN_ACKMEDIACHANGE, WIN_POSTBOOT, WIN_PREBOOT (obsolete since ATA3), WIN_WRITE_SAME (obsolete since ATA3, code reused for something else in ACS2), WIN_IDENTIFY_DMA (obsolete since ATA4).
Drop codes that are not implemented and vendor-specific:EXABYTE_ENABLE_NEST, DISABLE_SEAGATE.
Drop WIN_INIT, it isn't implemented, its value used to be reserved, and is used for something else since ATA8.
CFA_IDLEIMMEDIATE isn't specific to CFATA. ACS-2 shows it as a defined command in ATA-1, -2 and -3. Rename to WIN_IDLEIMMEDIATE2.
Mark vendor specific, retired, and obsolete codes.
--- hw/ide/core.c | 4 +- hw/ide/internal.h | 171 ++++++++++++++++++++++++++++------------------------- 2 files changed, 92 insertions(+), 83 deletions(-)
hw/ide/core.c +2 -2
@@ -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);
hw/ide/internal.h +90 -81
226 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH v2 5/45 ide: Clean up case label indentation in ide_exec_cmd()
In reply to Markus Armbruster--- hw/ide/core.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
hw/ide/core.c +6 -6
@@ -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 )
Signature · 1 line
1.7.6
PATCH v2 6/45 ide: Fix ATA command READ to set ATAPI signature for CD-ROM
In reply to Markus ArmbrusterMust set the ATAPI device signature, see ATA4 8.27.5.2 Outputs for PACKET Command feature set devices, and ACS-2 7.36.6 Outputs for PACKET feature set devices.
--- hw/ide/core.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/ide/core.c +3 -1
@@ -958,8 +958,10 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) lba48 =1 ;case WIN_READ :case WIN_READ_ONCE : -if (!s->bs) +if (s->drive_kind ==IDE_CD ) { +ide_set_signature (s);/* odd, but ATA4 8.27.5.2 requires it */ goto abort_cmd; + }ide_cmd_lba48_transform (s, lba48); s->req_nb_sectors =1 ;ide_sector_read (s);
Signature · 1 line
1.7.6
PATCH v2 7/45 ide: Use a table to declare which drive kinds accept each command
In reply to Markus ArmbrusterNo functional change.
It would be nice to have handler functions in the table, like commit e1a064f9 did for ATAPI. Left for another day.
--- hw/ide/core.c | 104 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 79 insertions(+), 25 deletions(-)
hw/ide/core.c +79 -25
@@ -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);
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
Quoted 16 lines · Markus Armbruster
No functional change.
It would be nice to have handler functions in the table, like commit
e1a064f9did for ATAPI. Left for another day.Signed-off-by Markus Armbruster <[email protected]>---
hw/ide/core.c | 104 +++++++++++++++++++++++++++++++++++++++++++--------------1 files changed, 79 insertions(+), 25 deletions(-)hw/ide/core.c +0
-0@@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) }
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 886
Quoted 10 lines
hw/ide/core.c +8
-0} +#define HD_OK (1u << IDE_HD) +#define CD_OK (1u << IDE_CD) +#define CFA_OK (1u << IDE_CFATA) +#define HD_CFA_OK (HD_OK | CFA_OK) +#define ALL_OK (HD_OK | CD_OK | CFA_OK) + +/* See ACS-2 T13/2015-D Table B.2 Command codes */ +uint8_t ide_cmd_table[0x100 ] = {
Missing 'static'.
Quoted 184 lines
hw/ide/core.c +67
-0+ /* 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) {hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;
/* XXX: Check that seek is within bounds */
s->status=READY_STAT|SEEK_STAT;ide_set_irq(s->bus);
break;
/* ATAPI commands */
caseWIN_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;
caseWIN_DIAGNOSE:hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;ide_set_signature(s);
s->status=0x00; /* NOTE: READY is _not_ set */s->error=0x01;
break;
caseWIN_PACKETCMD:
- if (s->drive_kind!=IDE_CD)
- gotoabort_cmd;
/* overlapping commands not supported */ if (s->feature&0x02)
gotoabort_cmd;hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;
s->error=0x09; /* miscellaneous error */s->status=READY_STAT|SEEK_STAT;ide_set_irq(s->bus);
break;
caseCFA_ERASE_SECTORS:
caseCFA_WEAR_LEVEL:
- if (s->drive_kind!=IDE_CFATA)
- gotoabort_cmd;
if (val ==CFA_WEAR_LEVEL)
s->nsector= 0;
if (val ==CFA_ERASE_SECTORS)hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;
s->error=0x00;
s->status=READY_STAT|SEEK_STAT;
memset(s->io_buffer, 0, 0x200);hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;
switch (s->feature) {
case0x02: /* Inquiry Metadata Storage */ide_cfata_metadata_inquiry(s);hw/ide/core.c +0
-0@@ -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)
- gotoabort_cmd;
switch (s->feature) {
case0x01: /* sense temperature in device */s->nsector=0x50; /* +20 C */hw/ide/core.c +0
-0@@ -1239,8 +1294,6 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) break;case
WIN_SMART:
- if (s->drive_kind==IDE_CD)
- gotoabort_cmd;
if (s->hcyl!=0xc2||s->lcyl!=0x4f) gotoabort_cmd;
if (!s->smart_enabled &&s->feature!=SMART_ENABLE)hw/ide/core.c +0
-0@@ -1395,6 +1448,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) } break;default:
+ /* should not be reachable */
abort_cmd:
ide_abort_command(s);
ide_set_irq(s->bus);
--
1.7.6
Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
Quoted 19 lines · Blue Swirl
Quoted 18 lines · Markus Armbruster
No functional change.
It would be nice to have handler functions in the table, like commit
e1a064f9did for ATAPI. Left for another day.Signed-off-by Markus Armbruster <[email protected]>---
hw/ide/core.c | 104 +++++++++++++++++++++++++++++++++++++++++++--------------1 files changed, 79 insertions(+), 25 deletions(-)hw/ide/core.c +0
-0@@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) } }
Quoted 10 lines
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 886
Quoted 8 lines
hw/ide/core.c +8
-0+#define HD_OK (1u << IDE_HD) +#define CD_OK (1u << IDE_CD) +#define CFA_OK (1u << IDE_CFATA) +#define HD_CFA_OK (HD_OK | CFA_OK) +#define ALL_OK (HD_OK | CD_OK | CFA_OK) + +/* See ACS-2 T13/2015-D Table B.2 Command codes */ +uint8_t ide_cmd_table[0x100 ] = {Missing 'static'.
Thanks, will fix.
[...]
Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
In reply to Blue SwirlAm 03.08.2011 18:53, schrieb Blue Swirl:
Quoted 19 lines · Markus Armbruster
Quoted 18 lines
No functional change.
It would be nice to have handler functions in the table, like commit
e1a064f9did for ATAPI. Left for another day.Signed-off-by Markus Armbruster <[email protected]>--- hw/ide/core.c | 104 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 79 insertions(+), 25 deletions(-)hw/ide/core.c +0
-0@@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) } }
Quoted 10 lines
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 886
Quoted 8 lines
hw/ide/core.c +8
-0+#define HD_OK (1u << IDE_HD) +#define CD_OK (1u << IDE_CD) +#define CFA_OK (1u << IDE_CFATA) +#define HD_CFA_OK (HD_OK | CFA_OK) +#define ALL_OK (HD_OK | CD_OK | CFA_OK) + +/* See ACS-2 T13/2015-D Table B.2 Command codes */ +uint8_t ide_cmd_table[0x100 ] = {Missing 'static'.
And const, while we're at it.
Quoted 55 lines
Quoted 55 lines
hw/ide/core.c +55
-0+ /* 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,
Quoted 8 lines
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 949
Quoted 8 lines
hw/ide/core.c +8
-0+ [CFA_WEAR_LEVEL] = CFA_OK, + [WIN_READ_NATIVE_MAX] = ALL_OK, +}; + +static bool ide_cmd_permitted (IDEState *s,uint32_t cmd) +{ +return cmd <=0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind)); +}
Doesn't cmd < ARRAY_SIZE(ide_cmd_table) better describe what you want?
Kevin
Re: [Qemu-devel] [PATCH v2 07/45] ide: Use a table to declare which drive kinds accept each command
Quoted 31 lines · Kevin Wolf
Am 03.08.2011 18:53, schrieb Blue Swirl:
Quoted 19 lines · Markus Armbruster
Quoted 18 lines
No functional change.
It would be nice to have handler functions in the table, like commit
e1a064f9did for ATAPI. Left for another day.Signed-off-by Markus Armbruster <[email protected]>--- hw/ide/core.c | 104 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 79 insertions(+), 25 deletions(-)hw/ide/core.c +0
-0@@ -876,6 +876,77 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) } }Quoted 10 lines
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 886
Quoted 8 lines
hw/ide/core.c +8
-0+#define HD_OK (1u << IDE_HD) +#define CD_OK (1u << IDE_CD) +#define CFA_OK (1u << IDE_CFATA) +#define HD_CFA_OK (HD_OK | CFA_OK) +#define ALL_OK (HD_OK | CD_OK | CFA_OK) + +/* See ACS-2 T13/2015-D Table B.2 Command codes */ +uint8_t ide_cmd_table[0x100 ] = {Missing 'static'.
Quoted 1 line
And const, while we're at it.
Yes.
Quoted 57 lines
Quoted 57 lines
Quoted 57 lines
hw/ide/core.c +57
-0+ /* 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,
Quoted 8 lines
Quoted 6 lines
hw/ide/core.c void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val) · line 949
Quoted 6 lines
hw/ide/core.c +6
-0+}; + +static bool ide_cmd_permitted (IDEState *s,uint32_t cmd) +{ +return cmd <=0xff && (ide_cmd_table[cmd] & (1u << s->drive_kind)); +}Doesn't cmd <
ARRAY_SIZE(ide_cmd_table)better describe what you want?
Since I touch this patch anyway, I'll do this your way.
PATCH v2 8/45 ide: Reject ATA commands specific to drive kinds
In reply to Markus ArmbrusterACS-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.
--- hw/ide/core.c | 50 +++++++++++++++++++++++++------------------------- 1 files changed, 25 insertions(+), 25 deletions(-)
hw/ide/core.c +25 -25
@@ -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,
Signature · 1 line
1.7.6
PATCH v2 9/45 ide/atapi: Clean up misleading name in cmd_start_stop_unit()
In reply to Markus Armbruster"eject" is misleading; it means "eject" when start is clear, but "load" when start is set. Rename to loej, because that's how MMC-5 calls it, in section 6.40.
--- hw/ide/atapi.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/ide/atapi.c +4 -4
@@ -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); }
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 19 lines
"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 <[email protected]>--- hw/ide/atapi.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)hw/ide/atapi.c +0
-2@@ -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 ;
hw/ide/atapi.c static void cmd_seek(IDEState *s, uint8_t* buf) · line 902
Quoted 10 lines
hw/ide/atapi.c +4
-2- eject = (buf[4 ] >>1 ) &1 ; +int sense, err =0 ; +bool start = buf[4 ] &1 ; +bool loej = buf[4 ] &2 ; -if (eject) { +if (loej) { err =bdrv_eject (s->bs, !start); }
"eject" has the advantage that I immediately know that it's something to do with the tray. "loej" on the other hand is a sequence of four random characters. Maybe add a comment?
Kevin
Re: [Qemu-devel] [PATCH v2 09/45] ide/atapi: Clean up misleading name in cmd_start_stop_unit()
Quoted 25 lines · Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 24 lines
"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 <[email protected]>--- hw/ide/atapi.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)hw/ide/atapi.c +3
-3@@ -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 ;
Quoted 9 lines
hw/ide/atapi.c static void cmd_seek(IDEState *s, uint8_t* buf) · line 902
Quoted 5 lines
hw/ide/atapi.c +1
-1-if (eject) { +if (loej) { err =bdrv_eject (s->bs, !start); }"eject" has the advantage that I immediately know that it's something to do with the tray. "loej" on the other hand is a sequence of four random characters. Maybe add a comment?
The name "loej" comes from MMC-5. I can add a comment to its definition.
PATCH v2 10/45 ide/atapi: Track tray open/close state
In reply to Markus ArmbrusterWe 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.
--- hw/ide/atapi.c | 6 +++++- hw/ide/internal.h | 1 + 2 files changed, 6 insertions(+), 1 deletions(-)
hw/ide/atapi.c +5 -1
@@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,uint8_t event_code, media_status; media_status =0 ; -if (s->bs->tray_open) { +if (s->tray_open) { media_status =MS_TRAY_OPEN ; }else if (bdrv_is_inserted (s->bs)) { media_status =MS_MEDIA_PRESENT ;
@@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)ide_atapi_cmd_error (s,SENSE_NOT_READY ,ASC_MEDIUM_NOT_PRESENT );break ; } + +if (loej && !err) { + s->tray_open = !start; + } }static void cmd_mechanism_status (IDEState *s,uint8_t * buf)
hw/ide/internal.h +1 -0
@@ -442,6 +442,7 @@ struct IDEState {struct unreported_events events;uint8_t sense_key;uint8_t asc; +bool tray_open;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 39 lines
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 <[email protected]>--- hw/ide/atapi.c | 6 +++++- hw/ide/internal.h | 1 + 2 files changed, 6 insertions(+), 1 deletions(-)hw/ide/atapi.c +5
-1@@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,uint8_t event_code, media_status; media_status =0 ; -if (s->bs->tray_open) { +if (s->tray_open) { media_status =MS_TRAY_OPEN ; }else if (bdrv_is_inserted (s->bs)) { media_status =MS_MEDIA_PRESENT ;@@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)ide_atapi_cmd_error (s,SENSE_NOT_READY ,ASC_MEDIUM_NOT_PRESENT );break ; } + +if (loej && !err) { + s->tray_open = !start; + } }static void cmd_mechanism_status (IDEState *s,uint8_t * buf)hw/ide/internal.h +0
-0
hw/ide/internal.h struct IDEState { · line 448
Quoted 7 lines
hw/ide/internal.h +1
-0@@ -442,6 +442,7 @@ struct IDEState {struct unreported_events events;uint8_t sense_key;uint8_t asc; +bool tray_open;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;
Probably needs to be migrated.
Kevin
Re: [Qemu-devel] [PATCH v2 10/45] ide/atapi: Track tray open/close state
Quoted 34 lines · Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 33 lines
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 <[email protected]>--- hw/ide/atapi.c | 6 +++++- hw/ide/internal.h | 1 + 2 files changed, 6 insertions(+), 1 deletions(-)hw/ide/atapi.c +5
-1@@ -510,7 +510,7 @@ static unsigned int event_status_media(IDEState *s,uint8_t event_code, media_status; media_status =0 ; -if (s->bs->tray_open) { +if (s->tray_open) { media_status =MS_TRAY_OPEN ; }else if (bdrv_is_inserted (s->bs)) { media_status =MS_MEDIA_PRESENT ;@@ -915,6 +915,10 @@ static void cmd_start_stop_unit(IDEState *s, uint8_t* buf)ide_atapi_cmd_error (s,SENSE_NOT_READY ,ASC_MEDIUM_NOT_PRESENT );break ; } + +if (loej && !err) { + s->tray_open = !start; + } }
Quoted 15 lines
hw/ide/internal.h struct IDEState { · line 448
Quoted 13 lines
hw/ide/atapi.c +0
-0static void cmd_mechanism_status (IDEState *s,uint8_t * buf)hw/ide/internal.h +1
-0@@ -442,6 +442,7 @@ struct IDEState {struct unreported_events events;uint8_t sense_key;uint8_t asc; +bool tray_open;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;Probably needs to be migrated.
Correct, but I chose to fix that separately, in PATCH 27/45. Note that this patch neither breaks nor fixes anything. It just prepares the ground for fixes.
PATCH v2 11/45 scsi-disk: Factor out scsi_disk_emulate_start_stop()
In reply to Markus Armbruster--- hw/scsi-disk.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
hw/scsi-disk.c +13 -4
@@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } +static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +{ +SCSIRequest *req = &r->req; +SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); +bool start = req->cmd.buf[4 ] &1 ; +bool loej = req->cmd.buf[4 ] &2 ; + +if (s->qdev.type ==TYPE_ROM && loej) { +bdrv_eject (s->bs, !start); + } +} +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf) {SCSIRequest *req = &r->req;
@@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -if (s->qdev.type ==TYPE_ROM && (req->cmd.buf[4 ] &2 )) { -/* load/eject medium */ -bdrv_eject (s->bs, !(req->cmd.buf[4 ] &1 )); - } +scsi_disk_emulate_start_stop (r);break ;case ALLOW_MEDIUM_REMOVAL :bdrv_set_locked (s->bs, req->cmd.buf[4 ] &1 );
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
Quoted 30 lines · Markus Armbruster
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)hw/scsi-disk.c +12
-0@@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } +static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +{ +SCSIRequest *req =&r->req; +SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); +bool start = req->cmd.buf[4 ]&1 ; +bool loej = req->cmd.buf[4 ]&2 ; + +if (s->qdev.type ==TYPE_ROM && loej) { +bdrv_eject (s->bs, !start); + } +} +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf) {SCSIRequest *req =&r->req;@@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;
hw/scsi-disk.c static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) · line 891
Quoted 10 lines
hw/scsi-disk.c +1
-4break ;case START_STOP : -if (s->qdev.type ==TYPE_ROM && (req->cmd.buf[4 ]&2 )) { -/* load/eject medium */ -bdrv_eject (s->bs, !(req->cmd.buf[4 ]&1 )); - } +scsi_disk_emulate_start_stop (r);break ;case ALLOW_MEDIUM_REMOVAL :bdrv_set_locked (s->bs, req->cmd.buf[4 ]&1 );
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
In reply to Markus ArmbrusterAm 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 29 lines
Signed-off-by Markus Armbruster <[email protected]>--- hw/scsi-disk.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)hw/scsi-disk.c +12
-0@@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } +static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +{ +SCSIRequest *req = &r->req; +SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); +bool start = req->cmd.buf[4 ] &1 ; +bool loej = req->cmd.buf[4 ] &2 ; + +if (s->qdev.type ==TYPE_ROM && loej) { +bdrv_eject (s->bs, !start); + } +} +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf) {SCSIRequest *req = &r->req;
hw/scsi-disk.c static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) · line 877
Quoted 5 lines
hw/scsi-disk.c +0
-2@@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -if (s->qdev.type ==TYPE_ROM && (req->cmd.buf[4 ] &2 )) { -/* load/eject medium */
So here we actually had the comment before. Can we retain it?
Kevin
Re: [Qemu-devel] [PATCH v2 11/45] scsi-disk: Factor out scsi_disk_emulate_start_stop()
Quoted 29 lines · Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 28 lines
Signed-off-by Markus Armbruster <[email protected]>--- hw/scsi-disk.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)hw/scsi-disk.c +12
-0@@ -820,6 +820,18 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } +static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +{ +SCSIRequest *req = &r->req; +SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev); +bool start = req->cmd.buf[4 ] &1 ; +bool loej = req->cmd.buf[4 ] &2 ; + +if (s->qdev.type ==TYPE_ROM && loej) { +bdrv_eject (s->bs, !start); + } +} +static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf) {SCSIRequest *req = &r->req;
Quoted 8 lines
hw/scsi-disk.c static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) · line 877
Quoted 6 lines
hw/scsi-disk.c +0
-2@@ -873,10 +885,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -if (s->qdev.type ==TYPE_ROM && (req->cmd.buf[4 ] &2 )) { -/* load/eject medium */ So here we actually had the comment before. Can we retain it?
We never had it in atapi.c, actually.
The fact that my scsi_disk_emulate_command() is very similar to atapi.c's cmd_start_stop_unit() is no accident. Whatever comment I'll add to atapi.c, I'll add here, too.
PATCH v2 12/45 scsi-disk: Track tray open/close state
In reply to Markus ArmbrusterWe 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.
--- hw/scsi-disk.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
hw/scsi-disk.c +2 -0
@@ -72,6 +72,7 @@ struct SCSIDiskStatechar *version;char *serial;SCSISense sense; +bool tray_open; };static int scsi_handle_rw_error (SCSIDiskReq *r,int error,int type);
@@ -829,6 +830,7 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)if (s->qdev.type ==TYPE_ROM && loej) {bdrv_eject (s->bs, !start); + s->tray_open = !start; } }
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 12/45] scsi-disk: Track tray open/close state
Quoted 22 lines · Markus Armbruster
We already track it in BlockDriverState since commit
4be9762a. As discussed in that commit's message, we should track it in the device device models instead, because it's device state.Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)hw/scsi-disk.c +1
-0@@ -72,6 +72,7 @@ struct SCSIDiskStatechar *version;char *serial;SCSISense sense; +bool tray_open; };static int scsi_handle_rw_error (SCSIDiskReq *r,int error,int type);
hw/scsi-disk.c static void scsi_disk_emulate_start_stop(SCSIDiskReq *r) · line 836
Quoted 7 lines
hw/scsi-disk.c +1
-0@@ -829,6 +830,7 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)if (s->qdev.type ==TYPE_ROM && loej) {bdrv_eject (s->bs, !start); + s->tray_open = !start; } }
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH v2 13/45 block: Revert entanglement of bdrv_is_inserted() with tray status
In reply to Markus ArmbrusterCommit 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.
--- block.c | 7 +++---- hw/ide/atapi.c | 15 ++++++++------- hw/scsi-disk.c | 10 ++++++++-- 3 files changed, 19 insertions(+), 13 deletions(-)
block.c +3 -4
@@ -2986,13 +2986,12 @@ static int coroutine_fn bdrv_co_flush_em(BlockDriverState *bs)int bdrv_is_inserted (BlockDriverState *bs) {BlockDriver *drv = bs->drv; -int ret; +if (!drv)return 0 ;if (!drv->bdrv_is_inserted) -return !bs->tray_open; - ret = drv->bdrv_is_inserted (bs); -return ret; +return 1 ; +return drv->bdrv_is_inserted (bs); }/**
hw/ide/atapi.c +8 -7
@@ -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 ;
hw/scsi-disk.c +8 -2
@@ -186,6 +186,9 @@ static void scsi_read_data(SCSIRequest *req)if (n >SCSI_DMA_BUF_SIZE /512 ) n =SCSI_DMA_BUF_SIZE /512 ; +if (s->tray_open) { +scsi_read_complete (r, -ENOMEDIUM ); + } r->iov.iov_len = n *512 ;qemu_iovec_init_external (&r->qiov, &r->iov,1 ); r->req.aiocb = bdrv_aio_readv(s->bs, r->sector, &r->qiov, n,
@@ -284,6 +287,9 @@ static void scsi_write_data(SCSIRequest *req) n = r->iov.iov_len /512 ;if (n) { +if (s->tray_open) { +scsi_write_complete (r, -ENOMEDIUM ); + }qemu_iovec_init_external (&r->qiov, &r->iov,1 ); r->req.aiocb =bdrv_aio_writev (s->bs, r->sector, &r->qiov, n, scsi_write_complete, r);
@@ -844,7 +850,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)switch (req->cmd.buf[0 ]) {case TEST_UNIT_READY : -if (!bdrv_is_inserted (s->bs)) +if (s->tray_open || !bdrv_is_inserted (s->bs)) goto not_ready;break ;case REQUEST_SENSE :
@@ -987,7 +993,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)return buflen; not_ready: -if (!bdrv_is_inserted (s->bs)) { +if (s->tray_open || !bdrv_is_inserted (s->bs)) {scsi_command_complete (r,CHECK_CONDITION ,SENSE_CODE (NO_MEDIUM )); }else {scsi_command_complete (r,CHECK_CONDITION ,SENSE_CODE (LUN_NOT_READY ));
Signature · 1 line
1.7.6
PATCH v2 14/45 block: Drop tray status tracking, no longer used
In reply to Markus ArmbrusterCommit 4be9762a is now completely redone.
--- block.c | 1 - block_int.h | 1 - 2 files changed, 0 insertions(+), 2 deletions(-)
block.c +0 -1
@@ -3027,7 +3027,6 @@ int bdrv_eject(BlockDriverState *bs, int eject_flag)if (drv && drv->bdrv_eject) { drv->bdrv_eject (bs, eject_flag); } - bs->tray_open = eject_flag;return 0 ; }
block_int.h +0 -1
@@ -156,7 +156,6 @@ struct BlockDriverState {int open_flags;/* flags used to open the file, re-used for re-open */ int removable;/* if true, the media can be removed */ int locked;/* if true, the media cannot temporarily be ejected */ -int tray_open;/* if true, the virtual tray is open */ int encrypted;/* if true, the media is encrypted */ int valid_key;/* if true, a valid encryption key has been set */ int sg;/* if true, the device is a /dev/sg* */
Signature · 1 line
1.7.6
PATCH v2 15/45 ide/atapi: Track tray locked state
In reply to Markus ArmbrusterWe 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.
--- hw/ide/atapi.c | 4 +++- hw/ide/internal.h | 1 + 2 files changed, 4 insertions(+), 1 deletions(-)
hw/ide/atapi.c +3 -1
@@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf) buf[12 ] =0x71 ; buf[13 ] =3 <<5 ; buf[14 ] = (1 <<0 ) | (1 <<3 ) | (1 <<5 ); -if (bdrv_is_locked (s->bs)) +if (s->tray_locked) { buf[6 ] |=1 <<1 ; + } buf[15 ] =0x00 ;cpu_to_ube16 (&buf[16 ],706 ); buf[18 ] =0 ;
@@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)static void cmd_prevent_allow_medium_removal (IDEState *s,uint8_t * buf) { + s->tray_locked = buf[4 ] &1 ;bdrv_set_locked (s->bs, buf[4 ] &1 );ide_atapi_cmd_ok (s); }
hw/ide/internal.h +1 -0
@@ -443,6 +443,7 @@ struct IDEState {uint8_t sense_key;uint8_t asc;bool tray_open; +bool tray_locked;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 38 lines
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 <[email protected]>--- hw/ide/atapi.c | 4 +++- hw/ide/internal.h | 1 + 2 files changed, 4 insertions(+), 1 deletions(-)hw/ide/atapi.c +3
-1@@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf) buf[12 ] =0x71 ; buf[13 ] =3 <<5 ; buf[14 ] = (1 <<0 ) | (1 <<3 ) | (1 <<5 ); -if (bdrv_is_locked (s->bs)) +if (s->tray_locked) { buf[6 ] |=1 <<1 ; + } buf[15 ] =0x00 ;cpu_to_ube16 (&buf[16 ],706 ); buf[18 ] =0 ;@@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)static void cmd_prevent_allow_medium_removal (IDEState *s,uint8_t * buf) { + s->tray_locked = buf[4 ] &1 ;bdrv_set_locked (s->bs, buf[4 ] &1 );ide_atapi_cmd_ok (s); }hw/ide/internal.h +0
-0
hw/ide/internal.h struct IDEState { · line 449
Quoted 7 lines
hw/ide/internal.h +1
-0@@ -443,6 +443,7 @@ struct IDEState {uint8_t sense_key;uint8_t asc;bool tray_open; +bool tray_locked;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;
Same as tray open/close status: Needs to be migrated.
Kevin
Re: [Qemu-devel] [PATCH v2 15/45] ide/atapi: Track tray locked state
Quoted 40 lines · Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 39 lines
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 <[email protected]>--- hw/ide/atapi.c | 4 +++- hw/ide/internal.h | 1 + 2 files changed, 4 insertions(+), 1 deletions(-)hw/ide/atapi.c +3
-1@@ -777,8 +777,9 @@ static void cmd_mode_sense(IDEState *s, uint8_t *buf) buf[12 ] =0x71 ; buf[13 ] =3 <<5 ; buf[14 ] = (1 <<0 ) | (1 <<3 ) | (1 <<5 ); -if (bdrv_is_locked (s->bs)) +if (s->tray_locked) { buf[6 ] |=1 <<1 ; + } buf[15 ] =0x00 ;cpu_to_ube16 (&buf[16 ],706 ); buf[18 ] =0 ;@@ -820,6 +821,7 @@ static void cmd_test_unit_ready(IDEState *s, uint8_t *buf)static void cmd_prevent_allow_medium_removal (IDEState *s,uint8_t * buf) { + s->tray_locked = buf[4 ] &1 ;bdrv_set_locked (s->bs, buf[4 ] &1 );ide_atapi_cmd_ok (s); }hw/ide/internal.h +0
-0@@ -443,6 +443,7 @@ struct IDEState {uint8_t sense_key;
Quoted 8 lines
hw/ide/internal.h struct IDEState { · line 449
Quoted 6 lines
hw/ide/internal.h +1
-0uint8_t asc;bool tray_open; +bool tray_locked;uint8_t cdrom_changed;int packet_transfer_size;int elementary_transfer_size;Same as tray open/close status: Needs to be migrated.
Correct, but I chose to fix that separately, in PATCH 26/45. Note that this patch neither breaks nor fixes anything. It just prepares the ground for fixes.
PATCH v2 16/45 scsi-disk: Track tray locked state
In reply to Markus ArmbrusterWe 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.
--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/scsi-disk.c +3 -1
@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };static int scsi_handle_rw_error (SCSIDiskReq *r,int error,int type);
@@ -678,7 +679,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p, p[5 ] =0xff ;/* CD DA, DA accurate, RW supported, RW corrected, C2 errors, ISRC, UPC, Bar code */ - p[6 ] =0x2d | (bdrv_is_locked (s->bs)?2 :0 ); + p[6 ] =0x2d | (s->tray_locked ?2 :0 );/* Locking supported, jumper present, eject, tray */ p[7 ] =0 ;/* no volume & mute control, no changer */
@@ -896,6 +897,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)scsi_disk_emulate_start_stop (r);break ;case ALLOW_MEDIUM_REMOVAL : + s->tray_locked = req->cmd.buf[4 ] &1 ;bdrv_set_locked (s->bs, req->cmd.buf[4 ] &1 );break ;case READ_CAPACITY_10 :
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
Quoted 14 lines · Markus Armbruster
We already track it in BlockDriverState. Just like tray open/close state, we should track it in the device models instead, because it's device state.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)hw/scsi-disk.c +0
-0
hw/scsi-disk.c struct SCSIDiskState · line 78
Quoted 6 lines
hw/scsi-disk.c +1
-0@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };
Hmm. Shouldn't we use a more generic 'flags' here and have bits for the individual tray states? Feels like a waste to have individual values here.
Quoted 11 lines
hw/scsi-disk.c +1
-1static int scsi_handle_rw_error (SCSIDiskReq *r,int error,int type);@@ -678,7 +679,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p, p[5 ] =0xff ;/* CD DA, DA accurate, RW supported, RW corrected, C2 errors, ISRC, UPC, Bar code */ - p[6 ] =0x2d | (bdrv_is_locked (s->bs)?2 :0 ); + p[6 ] =0x2d | (s->tray_locked ?2 :0 );/* Locking supported, jumper present, eject, tray */ p[7 ] =0 ;/* no volume& mute control, no changer */
hw/scsi-disk.c static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) · line 903
Quoted 7 lines
hw/scsi-disk.c +1
-0@@ -896,6 +897,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)scsi_disk_emulate_start_stop (r);break ;case ALLOW_MEDIUM_REMOVAL : + s->tray_locked = req->cmd.buf[4 ]&1 ;bdrv_set_locked (s->bs, req->cmd.buf[4 ]&1 );break ;case READ_CAPACITY_10 :
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
Quoted 10 lines · Hannes Reinecke
Quoted 9 lines · Markus Armbruster
We already track it in BlockDriverState. Just like tray open/close state, we should track it in the device models instead, because it's device state.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
Quoted 14 lines
hw/scsi-disk.c struct SCSIDiskState · line 78
Quoted 11 lines
hw/scsi-disk.c +1
-0@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };Hmm. Shouldn't we use a more generic 'flags' here and have bits for the individual tray states?
Feels like a waste to have individual values here.
On my system, struct SCSIDiskState is 248 bytes before my series (5 bytes of padding at the end), and 248 bytes after (3 bytes padding). We use one per disk.
I dare say switching to flags won't make a noticable difference in memory use ;)
The bool members are easy to read and hard to screw up.
Flags can be nicer when you manipulate several of them together.
Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
Quoted 31 lines · Markus Armbruster
Quoted 10 lines · Hannes Reinecke
Quoted 9 lines · Markus Armbruster
We already track it in BlockDriverState. Just like tray open/close state, we should track it in the device models instead, because it's device state.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)Quoted 14 lines
hw/scsi-disk.c struct SCSIDiskState · line 78
Quoted 11 lines
hw/scsi-disk.c +1
-0@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };Hmm. Shouldn't we use a more generic 'flags' here and have bits for the individual tray states?
Feels like a waste to have individual values here.On my system, struct SCSIDiskState is 248 bytes before my series (5 bytes of padding at the end), and 248 bytes after (3 bytes padding). We use one per disk.
Quoted 6 lines
I dare say switching to flags won't make a noticable difference in memory use ;)
The bool members are easy to read and hard to screw up.
Flags can be nicer when you manipulate several of them together.
Well, but this just proves my point.
Each 'bool' variable takes up one byte, of which only one bit is used. Which qualifies as a waste of space. But if that's okay with everyone and the general consensus on how to code flags in qemu, I'll shut up.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
Quoted 35 lines · Hannes Reinecke
Quoted 34 lines · Markus Armbruster
Quoted 10 lines · Hannes Reinecke
Quoted 9 lines · Markus Armbruster
We already track it in BlockDriverState. Just like tray open/close state, we should track it in the device models instead, because it's device state.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)Quoted 14 lines
hw/scsi-disk.c struct SCSIDiskState · line 78
Quoted 11 lines
hw/scsi-disk.c +1
-0@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };Hmm. Shouldn't we use a more generic 'flags' here and have bits for the individual tray states?
Feels like a waste to have individual values here.On my system, struct SCSIDiskState is 248 bytes before my series (5 bytes of padding at the end), and 248 bytes after (3 bytes padding). We use one per disk.
I dare say switching to flags won't make a noticable difference in memory use ;)
Quoted 7 lines
Quoted 3 lines
The bool members are easy to read and hard to screw up.
Flags can be nicer when you manipulate several of them together.
Well, but this just proves my point.
Each 'bool' variable takes up one byte, of which only one bit is used. Which qualifies as a waste of space.
A few data bytes per SCSI disk are a drop in the ocean.
Plus they're offset by the flags data word and the extra code bytes you need to extract the bits.
Quoted 2 lines
But if that's okay with everyone and the general consensus on how to code flags in qemu, I'll shut up.
It's a big series, and respinning it is work. Can we sort such things in followup patches?
Re: [Qemu-devel] [PATCH v2 16/45] scsi-disk: Track tray locked state
Quoted 47 lines · Markus Armbruster
Quoted 35 lines · Hannes Reinecke
Quoted 34 lines · Markus Armbruster
Quoted 10 lines · Hannes Reinecke
Quoted 9 lines · Markus Armbruster
We already track it in BlockDriverState. Just like tray open/close state, we should track it in the device models instead, because it's device state.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)Quoted 14 lines
hw/scsi-disk.c struct SCSIDiskState · line 78
Quoted 11 lines
hw/scsi-disk.c +1
-0@@ -73,6 +73,7 @@ struct SCSIDiskStatechar *serial;SCSISense sense;bool tray_open; +bool tray_locked; };Hmm. Shouldn't we use a more generic 'flags' here and have bits for the individual tray states?
Feels like a waste to have individual values here.On my system, struct SCSIDiskState is 248 bytes before my series (5 bytes of padding at the end), and 248 bytes after (3 bytes padding). We use one per disk.
I dare say switching to flags won't make a noticable difference in memory use ;)
Quoted 7 lines
Quoted 3 lines
The bool members are easy to read and hard to screw up.
Flags can be nicer when you manipulate several of them together.
Well, but this just proves my point.
Each 'bool' variable takes up one byte, of which only one bit is used. Which qualifies as a waste of space.A few data bytes per SCSI disk are a drop in the ocean.
Quoted 8 lines
Plus they're offset by the flags data word and the extra code bytes you need to extract the bits.
Quoted 2 lines
But if that's okay with everyone and the general consensus on how to code flags in qemu, I'll shut up.
It's a big series, and respinning it is work. Can we sort such things in followup patches?
As said, it's a minor point.
And as it's only a byte you are correct about a drop in the ocean.
And Paolo promised to keep it up in a further patch series. So I'll retract my objection.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH v2 17/45 block: Leave enforcing tray lock to device models
In reply to Markus ArmbrusterThe 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.
--- block.c | 7 +------ block.h | 2 +- hw/ide/atapi.c | 29 +++++++++-------------------- hw/scsi-disk.c | 3 +++ 4 files changed, 14 insertions(+), 27 deletions(-)
block.c +1 -6
@@ -3016,18 +3016,13 @@ int bdrv_media_changed(BlockDriverState *bs)/** * If eject_flag is TRUE, eject the media. Otherwise, close the tray */ -int bdrv_eject (BlockDriverState *bs,int eject_flag) +void bdrv_eject (BlockDriverState *bs,int eject_flag) {BlockDriver *drv = bs->drv; -if (eject_flag && bs->locked) { -return -EBUSY ; - } -if (drv && drv->bdrv_eject) { drv->bdrv_eject (bs, eject_flag); } -return 0 ; }int bdrv_is_locked (BlockDriverState *bs)
block.h +1 -1
@@ -207,7 +207,7 @@ int bdrv_is_inserted(BlockDriverState *bs);int bdrv_media_changed (BlockDriverState *bs);int bdrv_is_locked (BlockDriverState *bs);void bdrv_set_locked (BlockDriverState *bs,int locked); -int bdrv_eject (BlockDriverState *bs,int eject_flag); +void bdrv_eject (BlockDriverState *bs,int eject_flag);void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size);BlockDriverState *bdrv_find (const char *name);BlockDriverState *bdrv_next (BlockDriverState *bs);
hw/ide/atapi.c +9 -20
@@ -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)
hw/scsi-disk.c +3 -0
@@ -836,6 +836,9 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)bool loej = req->cmd.buf[4 ] &2 ;if (s->qdev.type ==TYPE_ROM && loej) { +if (!start && s->tray_locked) { +return ; + }bdrv_eject (s->bs, !start); s->tray_open = !start; }
Signature · 1 line
1.7.6
PATCH v2 18/45 block: Drop medium lock tracking, ask device models instead
In reply to Markus ArmbrusterRequires new BlockDevOps member is_medium_locked(). Implement for IDE and SCSI CD-ROMs.
--- block.c | 16 +++++++++------- block.h | 8 +++++++- block_int.h | 1 - blockdev.c | 2 +- hw/ide/core.c | 6 ++++++ hw/scsi-disk.c | 10 ++++++++++ 6 files changed, 33 insertions(+), 10 deletions(-)
block.c +9 -7
@@ -793,6 +793,14 @@ static void bdrv_dev_resize_cb(BlockDriverState *bs) } } +bool bdrv_dev_is_medium_locked (BlockDriverState *bs) +{ +if (bs->dev_ops && bs->dev_ops->is_medium_locked) { +return bs->dev_ops->is_medium_locked (bs->dev_opaque); + } +return false; +} +/* * Run consistency checks on an image *
@@ -1854,7 +1862,7 @@ void bdrv_info(Monitor *mon, QObject **ret_data) bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }" , bs->device_name, bs->removable, - bs->locked); +bdrv_dev_is_medium_locked (bs));if (bs->drv) {QObject *obj;
@@ -3025,11 +3033,6 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag) } } -int bdrv_is_locked (BlockDriverState *bs) -{ -return bs->locked; -} -/** * Lock or unlock the media (if it is locked, the user won't be able * to eject it manually).
@@ -3040,7 +3043,6 @@ void bdrv_set_locked(BlockDriverState *bs, int locked)trace_bdrv_set_locked (bs, locked); - bs->locked = locked;if (drv && drv->bdrv_set_locked) { drv->bdrv_set_locked (bs, locked); }
block.h +7 -1
@@ -37,6 +37,12 @@ typedef struct BlockDevOps {*/ void (*change_media_cb)(void *opaque);/* +* Is the virtual medium locked into the device? +* Device models should implement this only when device has such a +* lock. +*/ +bool (*is_medium_locked)(void *opaque); +/* * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque);
@@ -93,6 +99,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);void *bdrv_get_attached_dev (BlockDriverState *bs);void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops,void *opaque); +bool bdrv_dev_is_medium_locked (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num,
@@ -205,7 +212,6 @@ int bdrv_is_sg(BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);int bdrv_is_inserted (BlockDriverState *bs);int bdrv_media_changed (BlockDriverState *bs); -int bdrv_is_locked (BlockDriverState *bs);void bdrv_set_locked (BlockDriverState *bs,int locked);void bdrv_eject (BlockDriverState *bs,int eject_flag);void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size);
block_int.h +0 -1
@@ -155,7 +155,6 @@ struct BlockDriverState {int keep_read_only;/* if true, the media was requested to stay read only */ int open_flags;/* flags used to open the file, re-used for re-open */ int removable;/* if true, the media can be removed */ -int locked;/* if true, the media cannot temporarily be ejected */ int encrypted;/* if true, the media is encrypted */ int valid_key;/* if true, a valid encryption key has been set */ int sg;/* if true, the device is a /dev/sg* */
blockdev.c +1 -1
@@ -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 ; }
hw/ide/core.c +6 -0
@@ -1769,8 +1769,14 @@ void ide_bus_reset(IDEBus *bus) bus->dma->ops->reset (bus->dma); } +static bool ide_cd_is_medium_locked (void *opaque) +{ +return ((IDEState *)opaque)->tray_locked; +} +static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .is_medium_locked = ide_cd_is_medium_locked, }; int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
hw/scsi-disk.c +10 -0
@@ -1201,6 +1201,15 @@ static void scsi_destroy(SCSIDevice *dev)blockdev_mark_auto_del (s->qdev.conf.bs); } +static bool scsi_cd_is_medium_locked (void *opaque) +{ +return ((SCSIDiskState *)opaque)->tray_locked; +} + +static const BlockDevOps scsi_cd_block_ops = { + .is_medium_locked = scsi_cd_is_medium_locked, +}; +static int scsi_initfn (SCSIDevice *dev,uint8_t scsi_type) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev);
@@ -1235,6 +1244,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) }if (scsi_type ==TYPE_ROM ) { +bdrv_set_dev_ops (s->bs, &scsi_cd_block_ops, s); s->qdev.blocksize =2048 ; }else if (scsi_type ==TYPE_DISK ) { s->qdev.blocksize = s->qdev.conf.logical_block_size;
Signature · 1 line
1.7.6
PATCH v2 19/45 block: Rename bdrv_set_locked() to bdrv_lock_medium()
In reply to Markus Armbruster--- 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(-)
block.c +4 -4
@@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)* Lock or unlock the media (if it is locked, the user won't be able * to eject it manually). */ -void bdrv_set_locked (BlockDriverState *bs,int locked) +void bdrv_lock_medium (BlockDriverState *bs,int locked) {BlockDriver *drv = bs->drv; -trace_bdrv_set_locked (bs, locked); +trace_bdrv_lock_medium (bs, locked); -if (drv && drv->bdrv_set_locked) { - drv->bdrv_set_locked (bs, locked); +if (drv && drv->bdrv_lock_medium) { + drv->bdrv_lock_medium (bs, locked); } }
block.h +1 -1
@@ -212,7 +212,7 @@ int bdrv_is_sg(BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);int bdrv_is_inserted (BlockDriverState *bs);int bdrv_media_changed (BlockDriverState *bs); -void bdrv_set_locked (BlockDriverState *bs,int locked); +void bdrv_lock_medium (BlockDriverState *bs,int locked);void bdrv_eject (BlockDriverState *bs,int eject_flag);void bdrv_get_format (BlockDriverState *bs,char *buf,int buf_size);BlockDriverState *bdrv_find (const char *name);
block/raw-posix.c +4 -4
@@ -1358,7 +1358,7 @@ static void cdrom_eject(BlockDriverState *bs, int eject_flag) } } -static void cdrom_set_locked (BlockDriverState *bs,int locked) +static void cdrom_lock_medium (BlockDriverState *bs,int locked) {BDRVRawState *s = bs->opaque;
@@ -1396,7 +1396,7 @@ static BlockDriver bdrv_host_cdrom = {/* removable device support */ .bdrv_is_inserted = cdrom_is_inserted, .bdrv_eject = cdrom_eject, - .bdrv_set_locked = cdrom_set_locked, + .bdrv_lock_medium = cdrom_lock_medium,/* generic scsi device */ .bdrv_ioctl = hdev_ioctl,
@@ -1477,7 +1477,7 @@ static void cdrom_eject(BlockDriverState *bs, int eject_flag)cdrom_reopen (bs); } -static void cdrom_set_locked (BlockDriverState *bs,int locked) +static void cdrom_lock_medium (BlockDriverState *bs,int locked) {BDRVRawState *s = bs->opaque;
@@ -1517,7 +1517,7 @@ static BlockDriver bdrv_host_cdrom = {/* removable device support */ .bdrv_is_inserted = cdrom_is_inserted, .bdrv_eject = cdrom_eject, - .bdrv_set_locked = cdrom_set_locked, + .bdrv_lock_medium = cdrom_lock_medium, };#endif /* __FreeBSD__ */
block/raw.c +3 -3
@@ -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,
block_int.h +1 -1
@@ -119,7 +119,7 @@ struct BlockDriver {int (*bdrv_is_inserted)(BlockDriverState *bs);int (*bdrv_media_changed)(BlockDriverState *bs);void (*bdrv_eject)(BlockDriverState *bs,int eject_flag); -void (*bdrv_set_locked)(BlockDriverState *bs,int locked); +void (*bdrv_lock_medium)(BlockDriverState *bs,int locked);/* to control generic scsi devices */ int (*bdrv_ioctl)(BlockDriverState *bs,unsigned long int req,void *buf);
hw/ide/atapi.c +1 -1
@@ -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); }
hw/scsi-disk.c +1 -1
@@ -901,7 +901,7 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf)break ;case ALLOW_MEDIUM_REMOVAL : s->tray_locked = req->cmd.buf[4 ] &1 ; -bdrv_set_locked (s->bs, req->cmd.buf[4 ] &1 ); +bdrv_lock_medium (s->bs, req->cmd.buf[4 ] &1 );break ;case READ_CAPACITY_10 :/* The normal LEN field for this command is zero. */
trace-events +1 -1
@@ -65,7 +65,7 @@ disable bdrv_aio_multiwrite_latefail(void *mcb, int i) "mcb %p i %d" disable bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p" disable bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" disable bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" -disable bdrv_set_locked(void *bs, int locked) "bs %p locked %d" +disable bdrv_lock_medium(void *bs, int locked) "bs %p locked %d" disable bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" disable bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" disable bdrv_co_io(int is_write, void *acb) "is_write %d acb %p"
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 17 lines
Signed-off-by Markus Armbruster <[email protected]>--- 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(-)block.c +0
-0
block.c void bdrv_eject(BlockDriverState *bs, int eject_flag) · line 3040
Quoted 5 lines
block.c +1
-1@@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)* Lock or unlock the media (if it is locked, the user won't be able * to eject it manually). */ -void bdrv_set_locked (BlockDriverState *bs,int locked) +void bdrv_lock_medium (BlockDriverState *bs,int locked)
Make locked a bool while we're changing the signature everywhere?
Kevin
Re: [Qemu-devel] [PATCH v2 19/45] block: Rename bdrv_set_locked() to bdrv_lock_medium()
Quoted 13 lines · Kevin Wolf
Am 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 12 lines
Signed-off-by Markus Armbruster <[email protected]>--- 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(-)
Quoted 12 lines
block.c void bdrv_eject(BlockDriverState *bs, int eject_flag) · line 3040
Quoted 10 lines
block.c +1
-1@@ -3037,14 +3037,14 @@ void bdrv_eject(BlockDriverState *bs, int eject_flag)* Lock or unlock the media (if it is locked, the user won't be able * to eject it manually). */ -void bdrv_set_locked (BlockDriverState *bs,int locked) +void bdrv_lock_medium (BlockDriverState *bs,int locked)Make locked a bool while we're changing the signature everywhere?
Good idea.
PATCH v2 20/45 ide: Provide IDEDeviceInfo method exit()
In reply to Markus Armbruster--- hw/ide/internal.h | 1 + hw/ide/qdev.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-)
hw/ide/internal.h +1 -0
@@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);struct IDEDeviceInfo {DeviceInfo qdev;ide_qdev_initfn init; +ide_qdev_initfn exit; };#define BM_STATUS_DMAING 0x01
hw/ide/qdev.c +12 -0
@@ -91,9 +91,21 @@ err:return -1 ; } +static int ide_qdev_exit (DeviceState *qdev) +{ +IDEDevice *dev =DO_UPCAST (IDEDevice, qdev, qdev); +IDEDeviceInfo *info =DO_UPCAST (IDEDeviceInfo, qdev, qdev->info); + +if (info->exit) { +return info->exit (dev); + } +return 0 ; +} +static void ide_qdev_register (IDEDeviceInfo *info) { info->qdev.init = ide_qdev_init; + info->qdev.exit = ide_qdev_exit; info->qdev.bus_info = &ide_bus_info;qdev_register (&info->qdev); }
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit()
Quoted 26 lines · On Wed, 3 Aug 2011 15:07:59 +0200 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- hw/ide/internal.h | 1 + hw/ide/qdev.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-)hw/ide/internal.h +1
-0@@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);struct IDEDeviceInfo {DeviceInfo qdev;ide_qdev_initfn init; +ide_qdev_initfn exit; };#define BM_STATUS_DMAING 0x01hw/ide/qdev.c +0
-0@@ -91,9 +91,21 @@ err:return -1 ; }
hw/ide/qdev.c err: · line 102
Quoted 10 lines
hw/ide/qdev.c +9
-0+static int ide_qdev_exit (DeviceState *qdev) +{ +IDEDevice *dev =DO_UPCAST (IDEDevice, qdev, qdev); +IDEDeviceInfo *info =DO_UPCAST (IDEDeviceInfo, qdev, qdev->info); + +if (info->exit) { +return info->exit (dev); + } +return 0 ;
return info->exit ? info->exit(dev) : 0;
Quoted 9 lines
hw/ide/qdev.c +3
-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); }
Re: [Qemu-devel] [PATCH v2 20/45] ide: Provide IDEDeviceInfo method exit()
Quoted 30 lines · Luiz Capitulino
Quoted 27 lines · On Wed, 3 Aug 2011 15:07:59 +0200 Markus Armbruster <[email protected]> wrote:
Signed-off-by Markus Armbruster <[email protected]>--- hw/ide/internal.h | 1 + hw/ide/qdev.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-)hw/ide/internal.h +1
-0@@ -529,6 +529,7 @@ typedef int (*ide_qdev_initfn)(IDEDevice *dev);struct IDEDeviceInfo {DeviceInfo qdev;ide_qdev_initfn init; +ide_qdev_initfn exit; };#define BM_STATUS_DMAING 0x01hw/ide/qdev.c +0
-0@@ -91,9 +91,21 @@ err:return -1 ; }
Quoted 11 lines
hw/ide/qdev.c err: · line 102
Quoted 9 lines
hw/ide/qdev.c +9
-0+static int ide_qdev_exit (DeviceState *qdev) +{ +IDEDevice *dev =DO_UPCAST (IDEDevice, qdev, qdev); +IDEDeviceInfo *info =DO_UPCAST (IDEDeviceInfo, qdev, qdev->info); + +if (info->exit) { +return info->exit (dev); + } +return 0 ;return
info->exit?info->exit(dev): 0;
Matter of taste. I'll consider it when I respin.
Quoted 10 lines
Quoted 10 lines
hw/ide/qdev.c +3
-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); }
PATCH v2 21/45 ide/atapi: Don't fail eject when tray is already open
In reply to Markus ArmbrusterMMC-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.
--- hw/ide/atapi.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/ide/atapi.c +1 -1
@@ -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 );
Signature · 1 line
1.7.6
PATCH v2 22/45 ide/atapi: Avoid physical/virtual tray state mismatch
In reply to Markus ArmbrusterWhen 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.
--- hw/ide/core.c | 4 ++++ hw/ide/qdev.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
hw/ide/core.c +4 -0
@@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,ide_reset (s);bdrv_set_removable (bs, s->drive_kind ==IDE_CD ); +if (s->drive_kind ==IDE_CD ) { +bdrv_lock_medium (bs, s->tray_locked); +bdrv_eject (bs, s->tray_open); + }return 0 ; }
hw/ide/qdev.c +18 -0
@@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)return ide_dev_initfn (dev,IDE_CD ); } +static int ide_cd_exitfn (IDEDevice *dev) +{ +bdrv_lock_medium (dev->conf.bs,0 ); +return 0 ; +} +static int ide_drive_initfn (IDEDevice *dev) {DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs);
@@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)return ide_dev_initfn (dev, dinfo->media_cd ?IDE_CD :IDE_HD ); } +static int ide_drive_exitfn (IDEDevice *dev) +{ +DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs); + +if (dinfo->media_cd) { +return ide_cd_exitfn (dev); + } +return 0 ; +} +#define DEFINE_IDE_DEV_PROPERTIES () \ DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \
@@ -211,6 +227,7 @@ static IDEDeviceInfo ide_dev_info[] = { .qdev.desc = "virtual IDE CD-ROM", .qdev.size = sizeof(IDEDrive), .init = ide_cd_initfn, + .exit = ide_cd_exitfn, .qdev.props = (Property []) {DEFINE_IDE_DEV_PROPERTIES (),DEFINE_PROP_END_OF_LIST (),
@@ -221,6 +238,7 @@ static IDEDeviceInfo ide_dev_info[] = { .qdev.desc = "virtual IDE disk or CD-ROM (legacy)", .qdev.size = sizeof(IDEDrive), .init = ide_drive_initfn, + .exit = ide_drive_exitfn, .qdev.props = (Property []) {DEFINE_IDE_DEV_PROPERTIES (),DEFINE_PROP_END_OF_LIST (),
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 46 lines
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, andbdrv_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 <[email protected]>--- hw/ide/core.c | 4 ++++ hw/ide/qdev.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)hw/ide/core.c +4
-0@@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,ide_reset (s);bdrv_set_removable (bs, s->drive_kind ==IDE_CD ); +if (s->drive_kind ==IDE_CD ) { +bdrv_lock_medium (bs, s->tray_locked); +bdrv_eject (bs, s->tray_open); + }return 0 ; }hw/ide/qdev.c +6
-0@@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)return ide_dev_initfn (dev,IDE_CD ); } +static int ide_cd_exitfn (IDEDevice *dev) +{ +bdrv_lock_medium (dev->conf.bs,0 ); +return 0 ; +} +static int ide_drive_initfn (IDEDevice *dev) {DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs);
hw/ide/qdev.c static int ide_drive_initfn(IDEDevice *dev) · line 204
Quoted 10 lines
hw/ide/qdev.c +7
-0@@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)return ide_dev_initfn (dev, dinfo->media_cd ?IDE_CD :IDE_HD ); } +static int ide_drive_exitfn (IDEDevice *dev) +{ +DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs); + +if (dinfo->media_cd) { +return ide_cd_exitfn (dev); + }
Is dinfo->media_cd guaranteed to be the same as s->drive_kind? I wouldn't have expected this to be true at least since the introduction of ide-hd/cd.
Kevin
Re: [Qemu-devel] [PATCH v2 22/45] ide/atapi: Avoid physical/virtual tray state mismatch
Quoted 50 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 49 lines
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, andbdrv_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 <[email protected]>--- hw/ide/core.c | 4 ++++ hw/ide/qdev.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)hw/ide/core.c +4
-0@@ -1839,6 +1839,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,ide_reset (s);bdrv_set_removable (bs, s->drive_kind ==IDE_CD ); +if (s->drive_kind ==IDE_CD ) { +bdrv_lock_medium (bs, s->tray_locked); +bdrv_eject (bs, s->tray_open); + }return 0 ; }hw/ide/qdev.c +6
-0@@ -182,6 +182,12 @@ static int ide_cd_initfn(IDEDevice *dev)return ide_dev_initfn (dev,IDE_CD ); } +static int ide_cd_exitfn (IDEDevice *dev) +{ +bdrv_lock_medium (dev->conf.bs,0 ); +return 0 ; +} +static int ide_drive_initfn (IDEDevice *dev) {DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs);@@ -189,6 +195,16 @@ static int ide_drive_initfn(IDEDevice *dev)return ide_dev_initfn (dev, dinfo->media_cd ?IDE_CD :IDE_HD ); }
Quoted 11 lines
hw/ide/qdev.c static int ide_drive_initfn(IDEDevice *dev) · line 204
Quoted 7 lines
hw/ide/qdev.c +7
-0+static int ide_drive_exitfn (IDEDevice *dev) +{ +DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs); + +if (dinfo->media_cd) { +return ide_cd_exitfn (dev); + }Is
dinfo->media_cdguaranteed to be the same ass->drive_kind? I wouldn't have expected this to be true at least since the introduction of ide-hd/cd.
I'm afraid you're right. Now I need to find a way from IDEDevice to IDEState. These IDE data structures are sick...
PATCH v2 23/45 scsi-disk: Fix START_STOP to fail when it can't eject
In reply to Markus ArmbrusterDon't fail when tray is already open.
--- hw/scsi-bus.c | 10 ++++++++++ hw/scsi-disk.c | 15 +++++++++++---- hw/scsi.h | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-)
hw/scsi-bus.c +10 -0
@@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = { .key = NOT_READY, .asc = 0x3a, .ascq = 0x00 }; +/* LUN not ready, medium removal prevented */ +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = { + .key =NOT_READY , .asc =0x53 , .ascq =0x00 +}; +/* Hardware error, internal target failure */ const struct SCSISense sense_code_TARGET_FAILURE = { .key =HARDWARE_ERROR , .asc =0x44 , .ascq =0x00
@@ -466,6 +471,11 @@ const struct SCSISense sense_code_LUN_NOT_SUPPORTED = { .key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00 }; +/* Illegal request, medium removal prevented */ +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL = { + .key =ILLEGAL_REQUEST , .asc =0x53 , .ascq =0x00 +}; +/* Command aborted, I/O process terminated */ const struct SCSISense sense_code_IO_ERROR = { .key =ABORTED_COMMAND , .asc =0x00 , .ascq =0x06
hw/scsi-disk.c +11 -4
@@ -828,7 +828,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } -static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +static int scsi_disk_emulate_start_stop (SCSIDiskReq *r) {SCSIRequest *req = &r->req;SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev);
@@ -836,12 +836,17 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)bool loej = req->cmd.buf[4 ] &2 ;if (s->qdev.type ==TYPE_ROM && loej) { -if (!start && s->tray_locked) { -return ; +if (!start && !s->tray_open && s->tray_locked) { +scsi_command_complete (r,CHECK_CONDITION , +bdrv_is_inserted (s->bs) + ?SENSE_CODE (MEDIUM_REMOVAL_PREVENTED_ILL ) + :SENSE_CODE (MEDIUM_REMOVAL_PREVENTED_NR )); +return -1 ; }bdrv_eject (s->bs, !start); s->tray_open = !start; } +return 0 ; }static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf)
@@ -897,7 +902,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -scsi_disk_emulate_start_stop (r); +if (scsi_disk_emulate_start_stop (r) <0 ) { +return -1 ; + }break ;case ALLOW_MEDIUM_REMOVAL : s->tray_locked = req->cmd.buf[4 ] &1 ;
hw/scsi.h +4 -0
@@ -118,6 +118,8 @@ extern const struct SCSISense sense_code_NO_SENSE;extern const struct SCSISense sense_code_LUN_NOT_READY;/* LUN not ready, Medium not present */ extern const struct SCSISense sense_code_NO_MEDIUM; +/* LUN not readt, medium removal prevented */ +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR;/* Hardware error, internal target failure */ extern const struct SCSISense sense_code_TARGET_FAILURE;/* Illegal request, invalid command operation code */
@@ -128,6 +130,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;extern const struct SCSISense sense_code_INVALID_FIELD;/* Illegal request, LUN not supported */ extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; +/* Illegal request, medium removal prevented */ +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL;/* Command aborted, I/O process terminated */ extern const struct SCSISense sense_code_IO_ERROR;/* Command aborted, I_T Nexus loss occurred */
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject
Quoted 14 lines · Markus Armbruster
Don't fail when tray is already open.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-bus.c | 10 ++++++++++ hw/scsi-disk.c | 15 +++++++++++---- hw/scsi.h | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-)hw/scsi-bus.c +0
-0
hw/scsi-bus.c const struct SCSISense sense_code_NO_MEDIUM = { · line 448
Quoted 8 lines
hw/scsi-bus.c +5
-0@@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = { .key = NOT_READY, .asc = 0x3a, .ascq = 0x00 }; +/* LUN not ready, medium removal prevented */ +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = { + .key =NOT_READY , .asc =0x53 , .ascq =0x00 +}; +
I would prefer to have the naming reversed,
eg NOT_READY_REMOVAL_PREVENTED
hw/scsi-bus.c const struct SCSISense sense_code_LUN_NOT_SUPPORTED = { · line 478
Quoted 12 lines
hw/scsi-bus.c +5
-0/* Hardware error, internal target failure */ const struct SCSISense sense_code_TARGET_FAILURE = { .key =HARDWARE_ERROR , .asc =0x44 , .ascq =0x00 @@ -466,6 +471,11 @@ const struct SCSISense sense_code_LUN_NOT_SUPPORTED = { .key = ILLEGAL_REQUEST, .asc = 0x25, .ascq = 0x00 }; +/* Illegal request, medium removal prevented */ +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL = { + .key =ILLEGAL_REQUEST , .asc =0x53 , .ascq =0x00 +}; +
Same here: ILLEGAL_REQ_REMOVAL_PREVENTED
Quoted 52 lines
hw/scsi-bus.c +0
-0/* Command aborted, I/O process terminated */ const struct SCSISense sense_code_IO_ERROR = { .key =ABORTED_COMMAND , .asc =0x00 , .ascq =0x06 hw/scsi-disk.c +11
-4@@ -828,7 +828,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *req, uint8_t *outbuf)return toclen; } -static void scsi_disk_emulate_start_stop (SCSIDiskReq *r) +static int scsi_disk_emulate_start_stop (SCSIDiskReq *r) {SCSIRequest *req =&r->req;SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, req->dev);@@ -836,12 +836,17 @@ static void scsi_disk_emulate_start_stop(SCSIDiskReq *r)bool loej = req->cmd.buf[4 ]&2 ;if (s->qdev.type ==TYPE_ROM && loej) { -if (!start&& s->tray_locked) { -return ; +if (!start&& !s->tray_open&& s->tray_locked) { +scsi_command_complete (r,CHECK_CONDITION , +bdrv_is_inserted (s->bs) + ?SENSE_CODE (MEDIUM_REMOVAL_PREVENTED_ILL ) + :SENSE_CODE (MEDIUM_REMOVAL_PREVENTED_NR )); +return -1 ; }bdrv_eject (s->bs, !start); s->tray_open = !start; } +return 0 ; }static int scsi_disk_emulate_command (SCSIDiskReq *r,uint8_t *outbuf)@@ -897,7 +902,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -scsi_disk_emulate_start_stop (r); +if (scsi_disk_emulate_start_stop (r)<0 ) { +return -1 ; + }break ;case ALLOW_MEDIUM_REMOVAL : s->tray_locked = req->cmd.buf[4 ]&1 ;hw/scsi.h +0
-0
hw/scsi.h extern const struct SCSISense sense_code_NO_SENSE; · line 122
Quoted 5 lines
hw/scsi.h +2
-0@@ -118,6 +118,8 @@ extern const struct SCSISense sense_code_NO_SENSE;extern const struct SCSISense sense_code_LUN_NOT_READY;/* LUN not ready, Medium not present */ extern const struct SCSISense sense_code_NO_MEDIUM; +/* LUN not readt, medium removal prevented */ +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR;
LUN not ready.
Naming see above.
hw/scsi.h extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; · line 134
Quoted 9 lines
hw/scsi.h +2
-0/* Hardware error, internal target failure */ extern const struct SCSISense sense_code_TARGET_FAILURE;/* Illegal request, invalid command operation code */ @@ -128,6 +130,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE;extern const struct SCSISense sense_code_INVALID_FIELD;/* Illegal request, LUN not supported */ extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; +/* Illegal request, medium removal prevented */ +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL;
See above.
hw/scsi.h extern const struct SCSISense sense_code_LBA_OUT_OF_RANGE; · line 137
Quoted 3 lines
hw/scsi.h +0
-0/* Command aborted, I/O process terminated */ extern const struct SCSISense sense_code_IO_ERROR;/* Command aborted, I_T Nexus loss occurred */
Other than that it's okay.
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject
Quoted 18 lines · Hannes Reinecke
Quoted 17 lines · Markus Armbruster
Don't fail when tray is already open.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-bus.c | 10 ++++++++++ hw/scsi-disk.c | 15 +++++++++++---- hw/scsi.h | 4 ++++ 3 files changed, 25 insertions(+), 4 deletions(-)hw/scsi-bus.c +0
-0@@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM = { .key = NOT_READY, .asc = 0x3a, .ascq = 0x00 };
Quoted 7 lines
hw/scsi-bus.c const struct SCSISense sense_code_NO_MEDIUM = { · line 448
Quoted 5 lines
hw/scsi-bus.c +5
-0+/* LUN not ready, medium removal prevented */ +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR = { + .key =NOT_READY , .asc =0x53 , .ascq =0x00 +}; +I would prefer to have the naming reversed,
egNOT_READY_REMOVAL_PREVENTED
I don't care, so I'll do it your way :)
More of the same below, plus typos, all noted, thanks!
By the way, I hate having to define a struct SCSISense in another file (and make up a name for it!) just to report sense. And I hate the silly macro trickery to mask the long names even more.
To make sense of
scsi_command_complete(r, CHECK_CONDITION, SENSE_CODE(NO_MEDIUM));
I have to look up SENSE_CODE() in scsi.h:
#define SENSE_CODE(x) sense_code_ ## x
which leads me to scsi-bus.c:
/* LUN not ready, Medium not present */
const struct SCSISense sense_code_NO_MEDIUM = {
.key = NOT_READY, .asc = 0x3a, .ascq = 0x00
};Compare to IDE:
ide_atapi_cmd_error(s, SENSE_NOT_READY, ASC_MEDIUM_NOT_PRESENT);
[...]
PATCH v2 24/45 scsi-disk: Avoid physical/virtual tray state mismatch
In reply to Markus ArmbrusterWhen 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.
--- hw/scsi-disk.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
hw/scsi-disk.c +7 -0
@@ -1205,6 +1205,9 @@ static void scsi_destroy(SCSIDevice *dev)SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev);scsi_device_purge_requests (&s->qdev); +if (s->qdev.type ==TYPE_ROM ) { +bdrv_lock_medium (s->qdev.conf.bs,0 ); + }blockdev_mark_auto_del (s->qdev.conf.bs); }
@@ -1265,6 +1268,10 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) s->qdev.type = scsi_type;qemu_add_vm_change_state_handler (scsi_dma_restart_cb, s);bdrv_set_removable (s->bs, scsi_type ==TYPE_ROM ); +if (scsi_type ==TYPE_ROM ) { +bdrv_lock_medium (s->bs, s->tray_locked); +bdrv_eject (s->bs, s->tray_open); + }add_boot_device_path (s->qdev.conf.bootindex, &dev->qdev,",0" );return 0 ; }
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 24/45] scsi-disk: Avoid physical/virtual tray state mismatch
Quoted 27 lines · Markus Armbruster
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, andbdrv_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<[email protected]>--- hw/scsi-disk.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)hw/scsi-disk.c +3
-0@@ -1205,6 +1205,9 @@ static void scsi_destroy(SCSIDevice *dev)SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev);scsi_device_purge_requests (&s->qdev); +if (s->qdev.type ==TYPE_ROM ) { +bdrv_lock_medium (s->qdev.conf.bs,0 ); + }blockdev_mark_auto_del (s->qdev.conf.bs); }
hw/scsi-disk.c static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) · line 1277
Quoted 10 lines
hw/scsi-disk.c +4
-0@@ -1265,6 +1268,10 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) s->qdev.type = scsi_type;qemu_add_vm_change_state_handler (scsi_dma_restart_cb, s);bdrv_set_removable (s->bs, scsi_type ==TYPE_ROM ); +if (scsi_type ==TYPE_ROM ) { +bdrv_lock_medium (s->bs, s->tray_locked); +bdrv_eject (s->bs, s->tray_open); + }add_boot_device_path (s->qdev.conf.bootindex,&dev->qdev,",0" );return 0 ; }
We could go not into metaphysical arguments that we're exposing the host state to the guest here. But I guess that would be taking things too far :-)
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
PATCH v2 25/45 ide: Give vmstate structs internal linkage where possible
In reply to Markus Armbruster--- hw/ide/core.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
hw/ide/core.c +3 -3
@@ -2051,7 +2051,7 @@ static bool ide_error_needed(void *opaque) }/* Fields for GET_EVENT_STATUS_NOTIFICATION ATAPI command */ -const VMStateDescription vmstate_ide_atapi_gesn_state = { +static const VMStateDescription vmstate_ide_atapi_gesn_state = { .name ="ide_drive/atapi/gesn_state" , .version_id =1 , .minimum_version_id =1 ,
@@ -2063,7 +2063,7 @@ const VMStateDescription vmstate_ide_atapi_gesn_state = { } }; -const VMStateDescription vmstate_ide_drive_pio_state = { +static const VMStateDescription vmstate_ide_drive_pio_state = { .name ="ide_drive/pio_state" , .version_id =1 , .minimum_version_id =1 ,
@@ -2125,7 +2125,7 @@ const VMStateDescription vmstate_ide_drive = { } }; -const VMStateDescription vmstate_ide_error_status = { +static const VMStateDescription vmstate_ide_error_status = { .name ="ide_bus/error" , .version_id =1 , .minimum_version_id =1 ,
Signature · 1 line
1.7.6
PATCH v2 26/45 ide/atapi: Preserve tray state on migration
In reply to Markus ArmbrusterUse a subsection, so that migration to older version still works, provided the tray is closed and unlocked.
--- hw/ide/core.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
hw/ide/core.c +32 -0
@@ -2036,6 +2036,22 @@ static bool ide_drive_pio_state_needed(void *opaque) || (s->bus->error_status & BM_STATUS_PIO_RETRY); } +static int ide_tray_state_post_load (void *opaque,int version_id) +{ +IDEState *s = opaque; + +bdrv_eject (s->bs, s->tray_open); +bdrv_lock_medium (s->bs, s->tray_locked); +return 0 ; +} + +static bool ide_tray_state_needed (void *opaque) +{ +IDEState *s = opaque; + +return s->tray_open || s->tray_locked; +} +static bool ide_atapi_gesn_needed (void *opaque) {IDEState *s = opaque;
@@ -2063,6 +2079,19 @@ static const VMStateDescription vmstate_ide_atapi_gesn_state = { } }; +static const VMStateDescription vmstate_ide_tray_state = { + .name ="ide_drive/tray_state" , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .post_load = ide_tray_state_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, IDEState), +VMSTATE_BOOL (tray_locked, IDEState), +VMSTATE_END_OF_LIST () + } +}; +static const VMStateDescription vmstate_ide_drive_pio_state = { .name ="ide_drive/pio_state" , .version_id =1 ,
@@ -2117,6 +2146,9 @@ const VMStateDescription vmstate_ide_drive = { .vmsd = &vmstate_ide_drive_pio_state, .needed = ide_drive_pio_state_needed, }, { + .vmsd = &vmstate_ide_tray_state, + .needed = ide_tray_state_needed, + }, { .vmsd = &vmstate_ide_atapi_gesn_state, .needed = ide_atapi_gesn_needed, }, {
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 4 lines
Use a subsection, so that migration to older version still works, provided the tray is closed and unlocked.
Signed-off-by Markus Armbruster <[email protected]>
Ah, here is the migration part. The state wasn't migrated before, so not doing it in patch 10 doesn't break anything. I would still prefer to add migration in the same patch that adds the fields.
You could just move the subsection itself and keep the post_load part here if it doesn't fit naturally in one of the other patches of the series.
On another note, have our subsections been fixed meanwhile? If not, increasing the version number instead might be the right choice. Paolo?
Kevin
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
Quoted 9 lines · Kevin Wolf
Ah, here is the migration part. The state wasn't migrated before, so not doing it in patch 10 doesn't break anything. I would still prefer to add migration in the same patch that adds the fields.
You could just move the subsection itself and keep the
post_loadpart here if it doesn't fit naturally in one of the other patches of the series.On another note, have our subsections been fixed meanwhile? If not, increasing the version number instead might be the right choice. Paolo?
No, they haven't, but there's hope they will before 1.0.
Paolo
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Kevin Wolf
Ah, here is the migration part. The state wasn't migrated before, so not doing it in patch 10 doesn't break anything. I would still prefer to add migration in the same patch that adds the fields.
Quoted 7 lines
Quoted 5 lines
You could just move the subsection itself and keep the
post_loadpart here if it doesn't fit naturally in one of the other patches of the series.On another note, have our subsections been fixed meanwhile? If not, increasing the version number instead might be the right choice. Paolo?
No, they haven't, but there's hope they will before 1.0.
Use a subsection here anyway? Or should I throw up my hands and bump the version number?
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
Quoted 6 lines · Markus Armbruster
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
On another note, have our subsections been fixed meanwhile? If not, increasing the version number instead might be the right choice. Paolo?
No, they haven't, but there's hope they will before 1.0.
Use a subsection here anyway? Or should I throw up my hands and bump the version number?
Yes, I'd use a subsection for ide/atapi (not for SCSI of course).
Paolo
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
In reply to Kevin WolfQuoted 4 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 3 lines
Use a subsection, so that migration to older version still works, provided the tray is closed and unlocked.
Quoted 8 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>Ah, here is the migration part. The state wasn't migrated before, so not doing it in patch 10 doesn't break anything. I would still prefer to add migration in the same patch that adds the fields.
You could just move the subsection itself and keep the
post_loadpart here if it doesn't fit naturally in one of the other patches of the series.
I don't get this part, I'm afraid.
Quoted 4 lines
On another note, have our subsections been fixed meanwhile? If not, increasing the version number instead might be the right choice. Paolo?
Kevin
Re: [Qemu-devel] [PATCH v2 26/45] ide/atapi: Preserve tray state on migration
Am 02.09.2011 17:20, schrieb Markus Armbruster:
Quoted 8 lines
Quoted 6 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 4 lines
Use a subsection, so that migration to older version still works, provided the tray is closed and unlocked.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 8 lines
Quoted 6 lines
Ah, here is the migration part. The state wasn't migrated before, so not doing it in patch 10 doesn't break anything. I would still prefer to add migration in the same patch that adds the fields.
You could just move the subsection itself and keep the
post_loadpart here if it doesn't fit naturally in one of the other patches of the series.I don't get this part, I'm afraid.
I was afraid that you can't merge all of this patch into patch 10 because the post_load functions depends on later patches. So I suggested that you just add the subsection definition itself to patch 10 and keep the addition of post_load as patch 26.
Kevin
PATCH v2 27/45 scsi-disk: Preserve tray state on migration
In reply to Markus ArmbrusterBreaks 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.
--- hw/scsi-disk.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)
hw/scsi-disk.c +35 -0
@@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)return scsi_initfn (dev, scsi_type); } +static int scsi_cd_post_load (void *opaque,int version_id) +{ +SCSIDiskState *s = opaque; + +bdrv_eject (s->bs, s->tray_open); +bdrv_lock_medium (s->bs, s->tray_locked); +return 0 ; +} + +static const VMStateDescription vmstate_scsi_cd = { + .name ="scsi-cd" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_scsi_disk = { + .name ="scsi-disk" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; +#define DEFINE_SCSI_DISK_PROPERTIES () \ DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_STRING("ver", SCSIDiskState, version), \
@@ -1333,6 +1366,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI CD-ROM", .qdev.size = sizeof(SCSIDiskState), + .qdev.vmsd = &vmstate_scsi_cd, .qdev.reset = scsi_disk_reset, .init = scsi_cd_initfn, .destroy = scsi_destroy,
@@ -1353,6 +1387,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)", .qdev.size = sizeof(SCSIDiskState), + .qdev.vmsd = &vmstate_scsi_disk, .qdev.reset = scsi_disk_reset, .init = scsi_disk_initfn, .destroy = scsi_destroy,
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
Quoted 40 lines · Markus Armbruster
Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older versions. We normally use subsections to avoid that. Not possible here, because we don't have a section to begin with. Too bad.
Signed-off-by Markus Armbruster<[email protected]>--- hw/scsi-disk.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)hw/scsi-disk.c +23
-0@@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)return scsi_initfn (dev, scsi_type); } +static int scsi_cd_post_load (void *opaque,int version_id) +{ +SCSIDiskState *s = opaque; + +bdrv_eject (s->bs, s->tray_open); +bdrv_lock_medium (s->bs, s->tray_locked); +return 0 ; +} + +static const VMStateDescription vmstate_scsi_cd = { + .name ="scsi-cd" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_scsi_disk = { + .name ="scsi-disk" ,
hw/scsi-disk.c static int scsi_disk_initfn(SCSIDevice *dev) · line 1336
Quoted 10 lines
hw/scsi-disk.c +10
-0+ .version_id = 0, + .minimum_version_id = 0, + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; +
And again; if we had just one 'flags' value we would have to save only one variable. And wouldn't need to touch this one for future states.
Quoted 12 lines
hw/scsi-disk.c +1
-0#define DEFINE_SCSI_DISK_PROPERTIES () \ DEFINE_BLOCK_PROPERTIES(SCSIDiskState, qdev.conf), \ DEFINE_PROP_STRING("ver", SCSIDiskState, version), \@@ -1333,6 +1366,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI CD-ROM", .qdev.size = sizeof(SCSIDiskState), + .qdev.vmsd =&vmstate_scsi_cd, .qdev.reset = scsi_disk_reset, .init = scsi_cd_initfn, .destroy = scsi_destroy,
hw/scsi-disk.c static SCSIDeviceInfo scsi_disk_info[] = { · line 1393
Quoted 7 lines
hw/scsi-disk.c +1
-0@@ -1353,6 +1387,7 @@ static SCSIDeviceInfo scsi_disk_info[] = { .qdev.fw_name = "disk", .qdev.desc = "virtual SCSI disk or CD-ROM (legacy)", .qdev.size = sizeof(SCSIDiskState), + .qdev.vmsd =&vmstate_scsi_disk, .qdev.reset = scsi_disk_reset, .init = scsi_disk_initfn, .destroy = scsi_destroy,
Cheers,
Hannes
Signature · 4 lines
Dr. Hannes Reinecke zSeries & Storage [email protected] +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
Quoted 45 lines · Hannes Reinecke
Quoted 44 lines · Markus Armbruster
Breaks migration of qdevs "scsi-cd" and legacy "scsi-disk" to older versions. We normally use subsections to avoid that. Not possible here, because we don't have a section to begin with. Too bad.
Signed-off-by Markus Armbruster<[email protected]>---
hw/scsi-disk.c| 35 +++++++++++++++++++++++++++++++++++1 files changed, 35 insertions(+), 0 deletions(-)hw/scsi-disk.c +27
-0@@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)return scsi_initfn (dev, scsi_type); } +static int scsi_cd_post_load (void *opaque,int version_id) +{ +SCSIDiskState *s = opaque; + +bdrv_eject (s->bs, s->tray_open); +bdrv_lock_medium (s->bs, s->tray_locked); +return 0 ; +} + +static const VMStateDescription vmstate_scsi_cd = { + .name ="scsi-cd" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_scsi_disk = { + .name ="scsi-disk" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) {
Quoted 8 lines
hw/scsi-disk.c static int scsi_disk_initfn(SCSIDevice *dev) · line 1324
Quoted 6 lines
hw/scsi-disk.c +6
-0+VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), + VMSTATE_END_OF_LIST() + } +}; +And again; if we had just one 'flags' value we would have to save only one variable. And wouldn't need to touch this one for future states.
Agreed, but we have time until 0.16 to fix this. I plan to migrate more stuff (unit attention state, for one), I'll take care of this too.
Paolo
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
In reply to Hannes ReineckeAm 04.08.2011 08:23, schrieb Hannes Reinecke:
Quoted 46 lines · Markus Armbruster
Quoted 45 lines
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<[email protected]>--- hw/scsi-disk.c | 35 +++++++++++++++++++++++++++++++++++ 1 files changed, 35 insertions(+), 0 deletions(-)hw/scsi-disk.c +28
-0@@ -1301,6 +1301,39 @@ static int scsi_disk_initfn(SCSIDevice *dev)return scsi_initfn (dev, scsi_type); } +static int scsi_cd_post_load (void *opaque,int version_id) +{ +SCSIDiskState *s = opaque; + +bdrv_eject (s->bs, s->tray_open); +bdrv_lock_medium (s->bs, s->tray_locked); +return 0 ; +} + +static const VMStateDescription vmstate_scsi_cd = { + .name ="scsi-cd" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState), +VMSTATE_BOOL (tray_locked, SCSIDiskState), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_scsi_disk = { + .name ="scsi-disk" , + .version_id =0 , + .minimum_version_id =0 , + .post_load = scsi_cd_post_load, + .fields = (VMStateField []) { +VMSTATE_BOOL (tray_open, SCSIDiskState),
Quoted 8 lines
hw/scsi-disk.c static int scsi_disk_initfn(SCSIDevice *dev) · line 1324
Quoted 5 lines
hw/scsi-disk.c +5
-0+VMSTATE_BOOL (tray_locked, SCSIDiskState), + VMSTATE_END_OF_LIST() + } +}; +And again; if we had just one 'flags' value we would have to save only one variable. And wouldn't need to touch this one for future states.
I think the policy is that you need to add a subsection anyway, even if you just add a flag to an existing field.
Kevin
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
In reply to Markus ArmbrusterAm 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 5 lines
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 <[email protected]>
A more logical approach would be to add migration support to SCSI first. I guess adding .unmigratable = 1 makes more sense at the moment.
Kevin
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
Quoted 8 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 5 lines
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 <[email protected]>A more logical approach would be to add migration support to SCSI first.
Isn't that what I do?
Quoted 1 line
I guess adding .unmigratable = 1 makes more sense at the moment.
Why?
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
Am 02.09.2011 17:35, schrieb Markus Armbruster:
Quoted 9 lines
Quoted 7 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 5 lines
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 <[email protected]>
Quoted 7 lines
Quoted 1 line
A more logical approach would be to add migration support to SCSI first.
Isn't that what I do?
Quoted 1 line
I guess adding .unmigratable = 1 makes more sense at the moment.
Why?
Hm, you mean that we can successfully migrate SCSI today?
SCSIDiskState doesn't seem to directly have anything variable that must be migrated. I think SCSIDevice does have fields that need to be migrated (unit_attention, sense and the request list). I'm not sure what other state scsi-bus involves, but unless the SCSI controllers can restore all of it, it should have a VMState, too.
Kevin
Re: [Qemu-devel] [PATCH v2 27/45] scsi-disk: Preserve tray state on migration
Quoted 18 lines · Kevin Wolf
Am 02.09.2011 17:35, schrieb Markus Armbruster:
Quoted 9 lines
Quoted 7 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 5 lines
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 <[email protected]>Quoted 7 lines
Quoted 1 line
A more logical approach would be to add migration support to SCSI first.
Isn't that what I do?
Quoted 1 line
I guess adding .unmigratable = 1 makes more sense at the moment.
Why?
Quoted 7 lines
Hm, you mean that we can successfully migrate SCSI today?
SCSIDiskState doesn't seem to directly have anything variable that must be migrated. I think SCSIDevice does have fields that need to be migrated (
unit_attention, sense and the request list). I'm not sure what other state scsi-bus involves, but unless the SCSI controllers can restore all of it, it should have a VMState, too.
Easiest solution is to just drop my patch then.
PATCH v2 28/45 block/raw: Fix to forward method bdrv_media_changed()
In reply to Markus ArmbrusterBlock 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.
--- block/raw.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
block/raw.c +7 -0
@@ -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,
Signature · 1 line
1.7.6
PATCH v2 29/45 block: Leave tracking media change to device models
In reply to Markus Armbrusterhw/fdc.c is the only one that cares.
--- block.c | 20 ++++++-------------- block_int.h | 1 - hw/fdc.c | 40 ++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 37 deletions(-)
block.c +6 -14
@@ -662,7 +662,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }if (!bdrv_key_required (bs)) { - bs->media_changed =1 ;bdrv_dev_change_media_cb (bs); }
@@ -699,7 +698,6 @@ void bdrv_close(BlockDriverState *bs)bdrv_close (bs->file); } - bs->media_changed =1 ;bdrv_dev_change_media_cb (bs); } }
@@ -1633,7 +1631,6 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) }else if (!bs->valid_key) { bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ - bs->media_changed =1 ;bdrv_dev_change_media_cb (bs); }return ret;
@@ -3003,22 +3000,17 @@ int bdrv_is_inserted(BlockDriverState *bs) }/** -* Return TRUE if the media changed since the last call to this -* function. It is currently only used for floppy disks +* Return whether the media changed since the last call to this +* function, or -ENOTSUP if we don't know. Most drivers don't know. */ int bdrv_media_changed (BlockDriverState *bs) {BlockDriver *drv = bs->drv; -int ret; -if (!drv || !drv->bdrv_media_changed) - ret = -ENOTSUP ; -else - ret = drv->bdrv_media_changed (bs); -if (ret == -ENOTSUP ) - ret = bs->media_changed; - bs->media_changed =0 ; -return ret; +if (drv && drv->bdrv_media_changed) { +return drv->bdrv_media_changed (bs); + } +return -ENOTSUP ; }/**
block_int.h +0 -1
@@ -172,7 +172,6 @@ struct BlockDriverState {this file image */ char backing_format[16 ];/* if non-zero and backing_file exists */ int is_temporary; -int media_changed;BlockDriverState *backing_hd;BlockDriverState *file;
hw/fdc.c +18 -22
@@ -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 ;
Signature · 1 line
1.7.6
PATCH v2 30/45 fdc: Make media change detection more robust
In reply to Markus Armbrusterfdctrl_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.
--- hw/fdc.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-)
hw/fdc.c +8 -4
@@ -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); }
Signature · 1 line
1.7.6
PATCH v2 31/45 block: Clean up bdrv_flush_all()
In reply to Markus ArmbrusterChange (!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.
--- block.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
block.c +1 -2
@@ -1721,8 +1721,7 @@ void bdrv_flush_all(void)BlockDriverState *bs; QTAILQ_FOREACH(bs, &bdrv_states, list) { -if (bs->drv && !bdrv_is_read_only (bs) && - (!bdrv_is_removable (bs) ||bdrv_is_inserted (bs))) { +if (!bdrv_is_read_only (bs) &&bdrv_is_inserted (bs)) {bdrv_flush (bs); } }
Signature · 1 line
1.7.6
PATCH v2 32/45 savevm: Include writable devices with removable media
In reply to Markus Armbrustersavevm 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.
--- block.c | 2 +- savevm.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
block.c +1 -1
@@ -2047,7 +2047,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event)int bdrv_can_snapshot (BlockDriverState *bs) {BlockDriver *drv = bs->drv; -if (!drv ||bdrv_is_removable (bs) ||bdrv_is_read_only (bs)) { +if (!drv || !bdrv_is_inserted (bs) ||bdrv_is_read_only (bs)) {return 0 ; }
savevm.c +2 -2
@@ -1914,7 +1914,7 @@ void do_savevm(Monitor *mon, const QDict *qdict) bs =NULL ;while ((bs =bdrv_next (bs))) { -if (bdrv_is_removable (bs) ||bdrv_is_read_only (bs)) { +if (!bdrv_is_inserted (bs) ||bdrv_is_read_only (bs)) {continue ; }
@@ -2034,7 +2034,7 @@ int load_vmstate(const char *name) bs =NULL ;while ((bs =bdrv_next (bs))) { -if (bdrv_is_removable (bs) ||bdrv_is_read_only (bs)) { +if (!bdrv_is_inserted (bs) ||bdrv_is_read_only (bs)) {continue ; }
Signature · 1 line
1.7.6
PATCH v2 33/45 xen: Clean up pci_piix3_xen_ide_unplug()'s test for "not a CD"
In reply to Markus Armbrusterpci_piix3_xen_ide_unplug() unplugs only disks, not CD-ROMs. It peeks into the DriveInfo's BlockDriverState to distinguish between the two. Unclean; use DriveInfo member media_cd, like xen_config_dev_blk().
--- hw/ide/piix.c | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
hw/ide/piix.c +1 -2
@@ -27,7 +27,6 @@#include <hw/pci.h> #include <hw/isa.h> #include "block.h" -#include "block_int.h" #include "sysemu.h" #include "dma.h"
@@ -161,7 +160,7 @@ static int pci_piix3_xen_ide_unplug(DeviceState *dev)for (; i <3 ; i++) { di =drive_get_by_index (IF_IDE , i); -if (di !=NULL && di->bdrv !=NULL && !di->bdrv->removable) { +if (di !=NULL && !di->media_cd) {DeviceState *ds =bdrv_get_attached_dev (di->bdrv);if (ds) {bdrv_detach_dev (di->bdrv, ds);
Signature · 1 line
1.7.6
PATCH v2 34/45 spitz tosa: Simplify "drive is suitable for microdrive" test
In reply to Markus ArmbrusterWe 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.
--- hw/spitz.c | 10 +++------- hw/tosa.c | 10 +++------- 2 files changed, 6 insertions(+), 14 deletions(-)
hw/spitz.c +3 -7
@@ -708,17 +708,13 @@ static void spitz_ssp_attach(PXA2xxState *cpu)static void spitz_microdrive_attach (PXA2xxState *cpu,int slot) {PCMCIACardState *md; -BlockDriverState *bs;DriveInfo *dinfo; dinfo =drive_get (IF_IDE ,0 ,0 ); -if (!dinfo) +if (!dinfo || dinfo->media_cd)return ; - bs = dinfo->bdrv; -if (bdrv_is_inserted (bs) && !bdrv_is_removable (bs)) { - md =dscm1xxxx_init (dinfo); -pxa2xx_pcmcia_attach (cpu->pcmcia[slot], md); - } + md =dscm1xxxx_init (dinfo); +pxa2xx_pcmcia_attach (cpu->pcmcia[slot], md); }/* Wm8750 and Max7310 on I2C */
hw/tosa.c +3 -7
@@ -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)
Signature · 1 line
1.7.6
PATCH v2 35/45 block: Clean up remaining users of "removable"
In reply to Markus ArmbrusterBlockDriverState 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.
--- block.c | 18 +++++++++++------- block.h | 3 ++- blockdev.c | 2 +- hw/scsi-disk.c | 5 +++++ 4 files changed, 19 insertions(+), 9 deletions(-)
block.c +11 -7
@@ -775,6 +775,9 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, { bs->dev_ops = ops; bs->dev_opaque = opaque; +if (bdrv_dev_has_removable_media (bs) && bs == bs_snapshots) { + bs_snapshots =NULL ; + } }static void bdrv_dev_change_media_cb (BlockDriverState *bs)
@@ -784,6 +787,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs) } } +bool bdrv_dev_has_removable_media (BlockDriverState *bs) +{ +return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); +} +static void bdrv_dev_resize_cb (BlockDriverState *bs) {if (bs->dev_ops && bs->dev_ops->resize_cb) {
@@ -1289,7 +1297,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)if (!drv)return -ENOMEDIUM ; -if (bs->growable || bs->removable) { +if (bs->growable ||bdrv_dev_has_removable_media (bs)) {if (drv->bdrv_getlength) {return drv->bdrv_getlength (bs); }
@@ -1574,11 +1582,6 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } } -int bdrv_is_removable (BlockDriverState *bs) -{ -return bs->removable; -} -int bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only;
@@ -1857,7 +1860,8 @@ void bdrv_info(Monitor *mon, QObject **ret_data) bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }" , - bs->device_name, bs->removable, + bs->device_name, +bdrv_dev_has_removable_media (bs),bdrv_dev_is_medium_locked (bs));if (bs->drv) {
block.h +2 -1
@@ -34,6 +34,7 @@ typedef struct BlockDevOps {* Runs when virtual media changed (monitor commands eject, change) * Beware: doesn't run when a host device's physical media * changes. Sure would be useful if it did. +* Device models with removable media must implement this callback. */ void (*change_media_cb)(void *opaque);/*
@@ -99,6 +100,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);void *bdrv_get_attached_dev (BlockDriverState *bs);void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops,void *opaque); +bool bdrv_dev_has_removable_media (BlockDriverState *bs);bool bdrv_dev_is_medium_locked (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors);
@@ -206,7 +208,6 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read);void bdrv_set_removable (BlockDriverState *bs,int removable); -int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);
blockdev.c +1 -1
@@ -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 ; }
hw/scsi-disk.c +5 -0
@@ -1211,12 +1211,17 @@ static void scsi_destroy(SCSIDevice *dev)blockdev_mark_auto_del (s->qdev.conf.bs); } +static void scsi_cd_change_media_cb (void *opaque) +{ +} +static bool scsi_cd_is_medium_locked (void *opaque) {return ((SCSIDiskState *)opaque)->tray_locked; }static const BlockDevOps scsi_cd_block_ops = { + .change_media_cb = scsi_cd_change_media_cb, .is_medium_locked = scsi_cd_is_medium_locked, };
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 35/45] block: Clean up remaining users of "removable"
Quoted 46 lines · On Wed, 3 Aug 2011 15:08:14 +0200 Markus Armbruster <[email protected]> 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(), viabdrv_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 commit46a4e4e6). 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 callbdrv_set_removable(..., 0)(most devices don't)The commit makes the drive non-removable, and enables the length cache.
Quoted 8 lines
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 <[email protected]>
Looks good to me.
Quoted 127 lines
--- block.c | 18 +++++++++++------- block.h | 3 ++- blockdev.c | 2 +- hw/scsi-disk.c | 5 +++++ 4 files changed, 19 insertions(+), 9 deletions(-)block.c +11
-7@@ -775,6 +775,9 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, { bs->dev_ops = ops; bs->dev_opaque = opaque; +if (bdrv_dev_has_removable_media (bs) && bs == bs_snapshots) { + bs_snapshots =NULL ; + } }static void bdrv_dev_change_media_cb (BlockDriverState *bs)@@ -784,6 +787,11 @@ static void bdrv_dev_change_media_cb(BlockDriverState *bs) } } +bool bdrv_dev_has_removable_media (BlockDriverState *bs) +{ +return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); +} +static void bdrv_dev_resize_cb (BlockDriverState *bs) {if (bs->dev_ops && bs->dev_ops->resize_cb) {@@ -1289,7 +1297,7 @@ int64_t bdrv_getlength(BlockDriverState *bs)if (!drv)return -ENOMEDIUM ; -if (bs->growable || bs->removable) { +if (bs->growable ||bdrv_dev_has_removable_media (bs)) {if (drv->bdrv_getlength) {return drv->bdrv_getlength (bs); }@@ -1574,11 +1582,6 @@ void bdrv_set_removable(BlockDriverState *bs, int removable) } } -int bdrv_is_removable (BlockDriverState *bs) -{ -return bs->removable; -} -int bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only;@@ -1857,7 +1860,8 @@ void bdrv_info(Monitor *mon, QObject **ret_data) bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }" , - bs->device_name, bs->removable, + bs->device_name, +bdrv_dev_has_removable_media (bs),bdrv_dev_is_medium_locked (bs));if (bs->drv) {block.h +2
-1@@ -34,6 +34,7 @@ typedef struct BlockDevOps {* Runs when virtual media changed (monitor commands eject, change) * Beware: doesn't run when a host device's physical media * changes. Sure would be useful if it did. +* Device models with removable media must implement this callback. */ void (*change_media_cb)(void *opaque);/* @@ -99,6 +100,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev);void *bdrv_get_attached_dev (BlockDriverState *bs);void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops,void *opaque); +bool bdrv_dev_has_removable_media (BlockDriverState *bs);bool bdrv_dev_is_medium_locked (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors);@@ -206,7 +208,6 @@ void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error, BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read);void bdrv_set_removable (BlockDriverState *bs,int removable); -int bdrv_is_removable (BlockDriverState *bs);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);blockdev.c +1
-1@@ -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 ; }hw/scsi-disk.c +5
-0@@ -1211,12 +1211,17 @@ static void scsi_destroy(SCSIDevice *dev)blockdev_mark_auto_del (s->qdev.conf.bs); } +static void scsi_cd_change_media_cb (void *opaque) +{ +} +static bool scsi_cd_is_medium_locked (void *opaque) {return ((SCSIDiskState *)opaque)->tray_locked; }static const BlockDevOps scsi_cd_block_ops = { + .change_media_cb = scsi_cd_change_media_cb, .is_medium_locked = scsi_cd_is_medium_locked, };
PATCH v2 36/45 block: Drop BlockDriverState member removable
In reply to Markus ArmbrusterIt's a confused mess (see previous commit). No users remain.
--- 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(-)
block.c +0 -8
@@ -1574,14 +1574,6 @@ BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read)return is_read ? bs->on_read_error : bs->on_write_error; } -void bdrv_set_removable (BlockDriverState *bs,int removable) -{ - bs->removable = removable; -if (removable && bs == bs_snapshots) { - bs_snapshots =NULL ; - } -} -int bdrv_is_read_only (BlockDriverState *bs) {return bs->read_only;
block.h +0 -1
@@ -207,7 +207,6 @@ int bdrv_get_translation_hint(BlockDriverState *bs);void bdrv_set_on_error (BlockDriverState *bs,BlockErrorAction on_read_error,BlockErrorAction on_write_error);BlockErrorAction bdrv_get_on_error (BlockDriverState *bs,int is_read); -void bdrv_set_removable (BlockDriverState *bs,int removable);int bdrv_is_read_only (BlockDriverState *bs);int bdrv_is_sg (BlockDriverState *bs);int bdrv_enable_write_cache (BlockDriverState *bs);
block_int.h +0 -1
@@ -154,7 +154,6 @@ struct BlockDriverState {int read_only;/* if true, the media is read only */ int keep_read_only;/* if true, the media was requested to stay read only */ int open_flags;/* flags used to open the file, re-used for re-open */ -int removable;/* if true, the media can be removed */ int encrypted;/* if true, the media is encrypted */ int valid_key;/* if true, a valid encryption key has been set */ int sg;/* if true, the device is a /dev/sg* */
blockdev.c +0 -5
@@ -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 ;
hw/fdc.c +0 -1
@@ -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); } }
hw/ide/core.c +0 -1
@@ -1838,7 +1838,6 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind, }ide_reset (s); -bdrv_set_removable (bs, s->drive_kind ==IDE_CD );if (s->drive_kind ==IDE_CD ) {bdrv_lock_medium (bs, s->tray_locked);bdrv_eject (bs, s->tray_open);
hw/scsi-disk.c +0 -1
@@ -1272,7 +1272,6 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type) s->qdev.type = scsi_type;qemu_add_vm_change_state_handler (scsi_dma_restart_cb, s); -bdrv_set_removable (s->bs, scsi_type ==TYPE_ROM );if (scsi_type ==TYPE_ROM ) {bdrv_lock_medium (s->bs, s->tray_locked);bdrv_eject (s->bs, s->tray_open);
hw/scsi-generic.c +0 -1
@@ -534,7 +534,6 @@ static int scsi_generic_initfn(SCSIDevice *dev)DPRINTF ("block size %d\n" , s->qdev.blocksize); s->driver_status =0 ;memset (s->sensebuf,0 ,sizeof (s->sensebuf)); -bdrv_set_removable (s->bs,0 );return 0 ; }
hw/virtio-blk.c +0 -1
@@ -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;
Signature · 1 line
1.7.6
PATCH v2 37/45 block: Show whether the guest ejected the medium in info block
In reply to Markus ArmbrusterNeed to ask the device, so this requires new BlockDevOps member is_medium_ejected().
--- block.c | 17 +++++++++++++++-- block.h | 6 ++++++ hw/ide/core.c | 6 ++++++ hw/scsi-disk.c | 6 ++++++ qmp-commands.hx | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-)
block.c +15 -2
@@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs)return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); } +bool bdrv_dev_is_medium_ejected (BlockDriverState *bs) +{ +if (bs->dev_ops && bs->dev_ops->is_medium_ejected) { +return bs->dev_ops->is_medium_ejected (bs->dev_opaque); + } +return false; +} +static void bdrv_dev_resize_cb (BlockDriverState *bs) {if (bs->dev_ops && bs->dev_ops->resize_cb) {
@@ -1813,8 +1821,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque)if (qdict_get_bool (bs_dict,"removable" )) {monitor_printf (mon," locked=%d" ,qdict_get_bool (bs_dict,"locked" )); +monitor_printf (mon," ejected=%d" ,qdict_get_bool (bs_dict,"ejected" )); } -if (qdict_haskey (bs_dict,"inserted" )) {QDict *qdict =qobject_to_qdict (qdict_get (bs_dict,"inserted" ));
@@ -1849,16 +1857,21 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QTAILQ_FOREACH(bs, &bdrv_states, list) {QObject *bs_obj; +QDict *bs_dict; bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }" , bs->device_name,bdrv_dev_has_removable_media (bs),bdrv_dev_is_medium_locked (bs)); + bs_dict =qobject_to_qdict (bs_obj); +if (bdrv_dev_has_removable_media (bs)) { +qdict_put (bs_dict,"ejected" , +qbool_from_int (bdrv_dev_is_medium_ejected (bs))); + }if (bs->drv) {QObject *obj; -QDict *bs_dict =qobject_to_qdict (bs_obj); obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " "'encrypted': %i }",
block.h +6 -0
@@ -38,6 +38,11 @@ typedef struct BlockDevOps {*/ void (*change_media_cb)(void *opaque);/* +* Is medium ejected from the device? +* Device models calling bdrv_eject() should implement this. +*/ +bool (*is_medium_ejected)(void *opaque); +/* * Is the virtual medium locked into the device? * Device models should implement this only when device has such a * lock.
@@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs);void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops,void *opaque);bool bdrv_dev_has_removable_media (BlockDriverState *bs); +bool bdrv_dev_is_medium_ejected (BlockDriverState *bs);bool bdrv_dev_is_medium_locked (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors);
hw/ide/core.c +6 -0
@@ -1769,6 +1769,11 @@ void ide_bus_reset(IDEBus *bus) bus->dma->ops->reset (bus->dma); } +static bool ide_cd_medium_ejected (void *opaque) +{ +return ((IDEState *)opaque)->tray_open; +} +static bool ide_cd_is_medium_locked (void *opaque) {return ((IDEState *)opaque)->tray_locked;
@@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque)static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .is_medium_ejected = ide_cd_medium_ejected, .is_medium_locked = ide_cd_is_medium_locked, };
hw/scsi-disk.c +6 -0
@@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque) { } +static bool scsi_cd_is_medium_ejected (void *opaque) +{ +return ((SCSIDiskState *)opaque)->tray_open; +} +static bool scsi_cd_is_medium_locked (void *opaque) {return ((SCSIDiskState *)opaque)->tray_locked;
@@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque)static const BlockDevOps scsi_cd_block_ops = { .change_media_cb = scsi_cd_change_media_cb, + .is_medium_ejected = scsi_cd_is_medium_ejected, .is_medium_locked = scsi_cd_is_medium_locked, };
qmp-commands.hx +2 -0
@@ -1131,6 +1131,8 @@ Each json-object contain the following: - Possible values: "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) +- "ejected": only present if removable, true if the device ejected its + media (json-bool) - "inserted": only present if the device is inserted, it is a json-object containing the following: - "file": device file name (json-string)
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
Quoted 4 lines · On Wed, 3 Aug 2011 15:08:16 +0200 Markus Armbruster <[email protected]> wrote:
Need to ask the device, so this requires new BlockDevOps member
is_medium_ejected().Signed-off-by Markus Armbruster <[email protected]>
Looks good to me.
Quoted 145 lines
--- block.c | 17 +++++++++++++++-- block.h | 6 ++++++ hw/ide/core.c | 6 ++++++ hw/scsi-disk.c | 6 ++++++ qmp-commands.hx | 2 ++ 5 files changed, 35 insertions(+), 2 deletions(-)block.c +15
-2@@ -792,6 +792,14 @@ bool bdrv_dev_has_removable_media(BlockDriverState *bs)return !bs->dev || (bs->dev_ops && bs->dev_ops->change_media_cb); } +bool bdrv_dev_is_medium_ejected (BlockDriverState *bs) +{ +if (bs->dev_ops && bs->dev_ops->is_medium_ejected) { +return bs->dev_ops->is_medium_ejected (bs->dev_opaque); + } +return false; +} +static void bdrv_dev_resize_cb (BlockDriverState *bs) {if (bs->dev_ops && bs->dev_ops->resize_cb) {@@ -1813,8 +1821,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque)if (qdict_get_bool (bs_dict,"removable" )) {monitor_printf (mon," locked=%d" ,qdict_get_bool (bs_dict,"locked" )); +monitor_printf (mon," ejected=%d" ,qdict_get_bool (bs_dict,"ejected" )); } -if (qdict_haskey (bs_dict,"inserted" )) {QDict *qdict =qobject_to_qdict (qdict_get (bs_dict,"inserted" ));@@ -1849,16 +1857,21 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QTAILQ_FOREACH(bs, &bdrv_states, list) {QObject *bs_obj; +QDict *bs_dict; bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': 'unknown', " "'removable': %i, 'locked': %i }" , bs->device_name,bdrv_dev_has_removable_media (bs),bdrv_dev_is_medium_locked (bs)); + bs_dict =qobject_to_qdict (bs_obj); +if (bdrv_dev_has_removable_media (bs)) { +qdict_put (bs_dict,"ejected" , +qbool_from_int (bdrv_dev_is_medium_ejected (bs))); + }if (bs->drv) {QObject *obj; -QDict *bs_dict =qobject_to_qdict (bs_obj); obj = qobject_from_jsonf("{ 'file': %s, 'ro': %i, 'drv': %s, " "'encrypted': %i }",block.h +6
-0@@ -38,6 +38,11 @@ typedef struct BlockDevOps {*/ void (*change_media_cb)(void *opaque);/* +* Is medium ejected from the device? +* Device models calling bdrv_eject() should implement this. +*/ +bool (*is_medium_ejected)(void *opaque); +/* * Is the virtual medium locked into the device? * Device models should implement this only when device has such a * lock. @@ -101,6 +106,7 @@ void *bdrv_get_attached_dev(BlockDriverState *bs);void bdrv_set_dev_ops (BlockDriverState *bs,const BlockDevOps *ops,void *opaque);bool bdrv_dev_has_removable_media (BlockDriverState *bs); +bool bdrv_dev_is_medium_ejected (BlockDriverState *bs);bool bdrv_dev_is_medium_locked (BlockDriverState *bs);int bdrv_read (BlockDriverState *bs,int64_t sector_num,uint8_t *buf,int nb_sectors);hw/ide/core.c +6
-0@@ -1769,6 +1769,11 @@ void ide_bus_reset(IDEBus *bus) bus->dma->ops->reset (bus->dma); } +static bool ide_cd_medium_ejected (void *opaque) +{ +return ((IDEState *)opaque)->tray_open; +} +static bool ide_cd_is_medium_locked (void *opaque) {return ((IDEState *)opaque)->tray_locked;@@ -1776,6 +1781,7 @@ static bool ide_cd_is_medium_locked(void *opaque)static const BlockDevOps ide_cd_block_ops = { .change_media_cb = ide_cd_change_cb, + .is_medium_ejected = ide_cd_medium_ejected, .is_medium_locked = ide_cd_is_medium_locked, };hw/scsi-disk.c +6
-0@@ -1215,6 +1215,11 @@ static void scsi_cd_change_media_cb(void *opaque) { } +static bool scsi_cd_is_medium_ejected (void *opaque) +{ +return ((SCSIDiskState *)opaque)->tray_open; +} +static bool scsi_cd_is_medium_locked (void *opaque) {return ((SCSIDiskState *)opaque)->tray_locked;@@ -1222,6 +1227,7 @@ static bool scsi_cd_is_medium_locked(void *opaque)static const BlockDevOps scsi_cd_block_ops = { .change_media_cb = scsi_cd_change_media_cb, + .is_medium_ejected = scsi_cd_is_medium_ejected, .is_medium_locked = scsi_cd_is_medium_locked, };qmp-commands.hx +2
-0@@ -1131,6 +1131,8 @@ Each json-object contain the following: - Possible values: "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) +- "ejected": only present if removable, true if the device ejected its + media (json-bool) - "inserted": only present if the device is inserted, it is a json-object containing the following: - "file": device file name (json-string)
Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
In reply to Markus ArmbrusterAm 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 4 lines
Need to ask the device, so this requires new BlockDevOps member
is_medium_ejected().Signed-off-by Markus Armbruster <[email protected]>
I find the name confusing. "medium is ejected" seems to mean "tray is open". It isn't obvious that "tray is closed, but no medium is inserted" is not "medium is ejected".
Why not call it tray_open like in the devices?
Kevin
Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
Quoted 11 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 4 lines
Need to ask the device, so this requires new BlockDevOps member
is_medium_ejected().Signed-off-by Markus Armbruster <[email protected]>I find the name confusing. "medium is ejected" seems to mean "tray is open". It isn't obvious that "tray is closed, but no medium is inserted" is not "medium is ejected".
Why not call it
tray_openlike in the devices?
Not all all devices with removable media have trays. I'll rename it anyway. We'll figure out how to handle devices without trays when we add one.
Re: [Qemu-devel] [PATCH v2 37/45] block: Show whether the guest ejected the medium in info block
Am 02.09.2011 17:29, schrieb Markus Armbruster:
Quoted 12 lines
Quoted 10 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 4 lines
Need to ask the device, so this requires new BlockDevOps member
is_medium_ejected().Signed-off-by Markus Armbruster <[email protected]>I find the name confusing. "medium is ejected" seems to mean "tray is open". It isn't obvious that "tray is closed, but no medium is inserted" is not "medium is ejected".
Quoted 5 lines
Quoted 1 line
Why not call it
tray_openlike in the devices?Not all all devices with removable media have trays. I'll rename it anyway. We'll figure out how to handle devices without trays when we add one.
Then you need to clarify the intended semantics. For devices without a tray it's completely unclear to me what it means. The example for such a device that we have today is floppy.
Kevin
PATCH v2 38/45 block: Move BlockConf & friends from block_int.h to block.h
In reply to Markus ArmbrusterIt'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.
--- 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(-)
block.h +38 -0
@@ -331,4 +331,42 @@ typedef enum {#define BLKDBG_EVENT (bs, evt) bdrv_debug_event(bs, evt)void bdrv_debug_event (BlockDriverState *bs,BlkDebugEvent event); + +/* Convenience for block device models */ + +typedef struct BlockConf { +BlockDriverState *bs; +uint16_t physical_block_size; +uint16_t logical_block_size; +uint16_t min_io_size; +uint32_t opt_io_size; +int32_t bootindex; +uint32_t discard_granularity; +}BlockConf ; + +static inline unsigned int get_physical_block_exp (BlockConf *conf) +{ +unsigned int exp =0 , size; + +for (size = conf->physical_block_size; + size > conf->logical_block_size; + size >>=1 ) { + exp++; + } + +return exp; +} + +#define DEFINE_BLOCK_PROPERTIES (_state, _conf) \ + DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ + DEFINE_PROP_UINT16("logical_block_size", _state, \ + _conf.logical_block_size, 512), \ + DEFINE_PROP_UINT16("physical_block_size", _state, \ + _conf.physical_block_size, 512), \ + DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ + DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ + DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ + DEFINE_PROP_UINT32("discard_granularity", _state, \ + _conf.discard_granularity, 0) +#endif
block_int.h +0 -35
@@ -227,39 +227,4 @@ void *qemu_blockalign(BlockDriverState *bs, size_t size);int is_windows_drive (const char *filename);#endif -typedef struct BlockConf { -BlockDriverState *bs; -uint16_t physical_block_size; -uint16_t logical_block_size; -uint16_t min_io_size; -uint32_t opt_io_size; -int32_t bootindex; -uint32_t discard_granularity; -}BlockConf ; - -static inline unsigned int get_physical_block_exp (BlockConf *conf) -{ -unsigned int exp =0 , size; - -for (size = conf->physical_block_size; - size > conf->logical_block_size; - size >>=1 ) { - exp++; - } - -return exp; -} - -#define DEFINE_BLOCK_PROPERTIES (_state, _conf) \ - DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ - DEFINE_PROP_UINT16("logical_block_size", _state, \ - _conf.logical_block_size, 512), \ - DEFINE_PROP_UINT16("physical_block_size", _state, \ - _conf.physical_block_size, 512), \ - DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ - DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ - DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ - DEFINE_PROP_UINT32("discard_granularity", _state, \ - _conf.discard_granularity, 0) -#endif /* BLOCK_INT_H */
hw/ide/core.c +1 -0
@@ -30,6 +30,7 @@#include "sysemu.h" #include "dma.h" #include "blockdev.h" +#include "block_int.h" #include <hw/ide/internal.h>
hw/ide/internal.h +0 -1
@@ -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"
hw/scsi-disk.c +1 -0
@@ -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
hw/scsi.h +0 -1
@@ -3,7 +3,6 @@#include "qdev.h" #include "block.h" -#include "block_int.h" #define MAX_SCSI_DEVS 255
hw/virtio-blk.c +1 -0
@@ -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>
hw/virtio.h +1 -1
@@ -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"
Signature · 1 line
1.7.6
PATCH v2 39/45 hw: Trim superfluous #include "block_int.h"
In reply to Markus ArmbrusterIncluding it in device models is unclean, including it without a reason adds insult to injury.
--- hw/fdc.c | 1 - hw/ide/cmd646.c | 1 - hw/ide/ich.c | 1 - hw/ide/isa.c | 1 - hw/ide/macio.c | 1 - hw/ide/microdrive.c | 1 - hw/ide/mmio.c | 1 - hw/ide/pci.c | 1 - hw/ide/via.c | 1 - hw/lsi53c895a.c | 1 - 10 files changed, 0 insertions(+), 10 deletions(-)
hw/fdc.c +0 -1
@@ -36,7 +36,6 @@#include "qdev-addr.h" #include "blockdev.h" #include "sysemu.h" -#include "block_int.h" /********************************************************/ /* debug Floppy devices */
hw/ide/cmd646.c +0 -1
@@ -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"
hw/ide/ich.c +0 -1
@@ -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>
hw/ide/isa.c +0 -1
@@ -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>
hw/ide/macio.c +0 -1
@@ -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>
hw/ide/microdrive.c +0 -1
@@ -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>
hw/ide/mmio.c +0 -1
@@ -24,7 +24,6 @@*/ #include <hw/hw.h> #include "block.h" -#include "block_int.h" #include "dma.h" #include <hw/ide/internal.h>
hw/ide/pci.c +0 -1
@@ -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>
hw/ide/via.c +0 -1
@@ -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"
hw/lsi53c895a.c +0 -1
@@ -15,7 +15,6 @@#include "hw.h" #include "pci.h" #include "scsi.h" -#include "block_int.h" //#define DEBUG_LSI //#define DEBUG_LSI_REG
Signature · 1 line
1.7.6
PATCH v2 40/45 block: Declare qemu_blockalign() in block.h, not block_int.h
In reply to Markus ArmbrusterDevice models should be able to use it without an unclean include of block_int.h.
--- block.h | 2 ++ block_int.h | 2 -- hw/sd.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)
block.h +2 -0
@@ -269,6 +269,8 @@ int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, char *options, uint64_t img_size, int flags); +void *qemu_blockalign (BlockDriverState *bs,size_t size); +#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048void bdrv_set_dirty_tracking (BlockDriverState *bs,int enable);
block_int.h +0 -2
@@ -221,8 +221,6 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque);void qemu_aio_release (void *p); -void *qemu_blockalign (BlockDriverState *bs,size_t size); -#ifdef _WIN32int is_windows_drive (const char *filename);#endif
hw/sd.c +0 -1
@@ -31,7 +31,6 @@#include "hw.h" #include "block.h" -#include "block_int.h" #include "sd.h" //#define DEBUG_SD 1
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
Quoted 2 lines · On Wed, 3 Aug 2011 15:08:19 +0200 Markus Armbruster <[email protected]> wrote:
Device models should be able to use it without an unclean include of
block_int.h.
Nitpick: I'd do the prototype move after patch 38/45 and include the block_int.h removal in the patch you're trimming block_int.h includes.
Quoted 46 lines
Signed-off-by Markus Armbruster <[email protected]>--- block.h | 2 ++ block_int.h | 2 -- hw/sd.c | 1 - 3 files changed, 2 insertions(+), 3 deletions(-)block.h +2
-0@@ -269,6 +269,8 @@ int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, char *options, uint64_t img_size, int flags); +void *qemu_blockalign (BlockDriverState *bs,size_t size); +#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048void bdrv_set_dirty_tracking (BlockDriverState *bs,int enable);block_int.h +0
-2@@ -221,8 +221,6 @@ void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs, BlockDriverCompletionFunc *cb, void *opaque);void qemu_aio_release (void *p); -void *qemu_blockalign (BlockDriverState *bs,size_t size); -#ifdef _WIN32int is_windows_drive (const char *filename);#endif hw/sd.c +0
-1@@ -31,7 +31,6 @@#include "hw.h" #include "block.h" -#include "block_int.h" #include "sd.h" //#define DEBUG_SD 1
Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
Quoted 8 lines · Luiz Capitulino
Quoted 2 lines · On Wed, 3 Aug 2011 15:08:19 +0200 Markus Armbruster <[email protected]> wrote:
Device models should be able to use it without an unclean include of
block_int.h.Nitpick: I'd do the prototype move after patch 38/45 and include the
block_int.hremoval in the patch you're trimmingblock_int.hincludes.
Care to explain why?
Re: [Qemu-devel] [PATCH v2 40/45] block: Declare qemu_blockalign() in block.h, not block_int.h
Quoted 5 lines · On Thu, 04 Aug 2011 20:22:15 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 3 lines · Luiz Capitulino
On Wed, 3 Aug 2011 15:08:19 +0200
Markus Armbruster <[email protected]> wrote:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Device models should be able to use it without an unclean include of
block_int.h.Nitpick: I'd do the prototype move after patch 38/45 and include the
block_int.hremoval in the patch you're trimmingblock_int.hincludes.Care to explain why?
Seems more logical to me to solve the dependencies one by one and then drop the includes in one shot. Maybe could even be done in a different series.
PATCH v2 41/45 block: New bdrv_set_buffer_alignment()
In reply to Markus ArmbrusterDevice models should be able to set it without an unclean include of block_int.h.
--- block.c | 6 ++++-- block.h | 1 + hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 3 +-- 5 files changed, 8 insertions(+), 6 deletions(-)
block.c +4 -2
@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment =512 ;pstrcpy (bs->filename,sizeof (bs->filename), filename);
@@ -3070,7 +3069,10 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,return NULL ; } - +void bdrv_set_buffer_alignment (BlockDriverState *bs,int align) +{ + bs->buffer_alignment = align; +}void *qemu_blockalign (BlockDriverState *bs,size_t size) {
block.h +1 -0
@@ -269,6 +269,7 @@ int bdrv_img_create(const char *filename, const char *fmt, const char *base_filename, const char *base_fmt, char *options, uint64_t img_size, int flags); +void bdrv_set_buffer_alignment (BlockDriverState *bs,int align);void *qemu_blockalign (BlockDriverState *bs,size_t size);#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048
hw/ide/core.c +1 -1
@@ -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" );
hw/scsi-disk.c +1 -1
@@ -1275,7 +1275,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)return -1 ; } s->cluster_size = s->qdev.blocksize /512 ; - s->bs->buffer_alignment = s->qdev.blocksize; +bdrv_set_buffer_alignment (s->bs, s->qdev.blocksize); s->qdev.type = scsi_type;qemu_add_vm_change_state_handler (scsi_dma_restart_cb, s);
hw/virtio-blk.c +1 -2
@@ -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" );
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 17 lines
Device models should be able to set it without an unclean include of
block_int.h.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- block.h | 1 + hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 3 +-- 5 files changed, 8 insertions(+), 6 deletions(-)block.c +0
-0
block.c static int bdrv_open_common(BlockDriverState *bs, const char *filename, · line 456
Quoted 5 lines
block.c +0
-1@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment =512 ;
This comment is still right.
Kevin
Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
Quoted 13 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 12 lines
Device models should be able to set it without an unclean include of
block_int.h.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- block.h | 1 + hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 3 +-- 5 files changed, 8 insertions(+), 6 deletions(-)
Quoted 12 lines
block.c static int bdrv_open_common(BlockDriverState *bs, const char *filename, · line 456
Quoted 10 lines
block.c +0
-1@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment =512 ;This comment is still right.
It's also next to useless. I hate comments paraphrasing the code :)
I'll keep it if you insist.
Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
Am 02.09.2011 17:30, schrieb Markus Armbruster:
Quoted 28 lines
Quoted 13 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 12 lines
Device models should be able to set it without an unclean include of
block_int.h.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- block.h | 1 + hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 3 +-- 5 files changed, 8 insertions(+), 6 deletions(-)Quoted 12 lines
block.c static int bdrv_open_common(BlockDriverState *bs, const char *filename, · line 456
Quoted 10 lines
block.c +0
-1@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment =512 ;This comment is still right.
Quoted 3 lines
It's also next to useless. I hate comments paraphrasing the code :)
I'll keep it if you insist.
The information that the comment gives isn't that we set it to 512, but that this is only a default and "drivers" (should be "devices", I think) are expected to change it.
Kevin
Re: [Qemu-devel] [PATCH v2 41/45] block: New bdrv_set_buffer_alignment()
Quoted 29 lines · Kevin Wolf
Am 02.09.2011 17:30, schrieb Markus Armbruster:
Quoted 28 lines
Quoted 25 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 17 lines
Device models should be able to set it without an unclean include of
block_int.h.Signed-off-by Markus Armbruster <[email protected]>--- block.c | 6 ++++-- block.h | 1 + hw/ide/core.c | 2 +- hw/scsi-disk.c | 2 +- hw/virtio-blk.c | 3 +-- 5 files changed, 8 insertions(+), 6 deletions(-)block.c +0
-0block.c static int bdrv_open_common(BlockDriverState *bs, const char *filename, · line 456
Quoted 5 lines
block.c +0
-1@@ -453,7 +453,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename, bs->encrypted =0 ; bs->valid_key =0 ; bs->open_flags = flags; -/* buffer_alignment defaulted to 512, drivers can change this value */ bs->buffer_alignment =512 ;This comment is still right.
Quoted 7 lines
Quoted 3 lines
It's also next to useless. I hate comments paraphrasing the code :)
I'll keep it if you insist.
The information that the comment gives isn't that we set it to 512, but that this is only a default and "drivers" (should be "devices", I think) are expected to change it.
Devices can and do change any number of default values set up here, and documenting that just for buffer_alignment is useless at best, misleading at worst.
Nevertheless, I'll keep it if you insist.
PATCH v2 42/45 block: Reset buffer alignment on detach
In reply to Markus ArmbrusterBlockDriverState 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.
--- block.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
block.c +1 -0
@@ -761,6 +761,7 @@ void bdrv_detach_dev(BlockDriverState *bs, void *dev) bs->dev =NULL ; bs->dev_ops =NULL ; bs->dev_opaque =NULL ; + bs->buffer_alignment =512 ; }/* TODO change to return DeviceState * when all users are qdevified */
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 8 lines
BlockDriverState member
buffer_alignmentis initially 512. The device model may set them, withbdrv_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 <[email protected]>
Hm, I'm not sure about this... Maybe instead of doing it on open and detach, which is a strange combination, the right thing would be to do it on attach?
Kevin
Re: [Qemu-devel] [PATCH v2 42/45] block: Reset buffer alignment on detach
Quoted 8 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 7 lines
BlockDriverState member
buffer_alignmentis initially 512. The device model may set them, withbdrv_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.
Quoted 5 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>Hm, I'm not sure about this... Maybe instead of doing it on open and detach, which is a strange combination, the right thing would be to do it on attach?
Maybe. My readiness to rearrange code for neatness declines a bit beyond PATCH#30 or so ;)
PATCH v2 43/45 nbd: Clean up use of block_int.h
In reply to Markus Armbruster--- block/nbd.c | 1 + nbd.c | 1 + nbd.h | 2 -- 3 files changed, 2 insertions(+), 2 deletions(-)
block/nbd.c +1 -0
@@ -28,6 +28,7 @@#include "qemu-common.h" #include "nbd.h" +#include "block_int.h" #include "module.h" #include "qemu_socket.h"
nbd.c +1 -0
@@ -17,6 +17,7 @@*/ #include "nbd.h" +#include "block.h" #include <errno.h> #include <string.h>
nbd.h +0 -2
@@ -23,8 +23,6 @@#include <qemu-common.h> -#include "block_int.h" -struct nbd_request {uint32_t magic;uint32_t type;
Signature · 1 line
1.7.6
PATCH v2 44/45 block: New change_media_cb() parameter load
In reply to Markus ArmbrusterTo let device models distinguish between eject and load.
--- 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(-)
block.c +6 -6
@@ -44,7 +44,7 @@#include <windows.h> #endif -static void bdrv_dev_change_media_cb (BlockDriverState *bs); +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load);static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);
@@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }if (!bdrv_key_required (bs)) { -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, true); }return 0 ;
@@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)bdrv_close (bs->file); } -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, false); } }
@@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, } } -static void bdrv_dev_change_media_cb (BlockDriverState *bs) +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load) {if (bs->dev_ops && bs->dev_ops->change_media_cb) { - bs->dev_ops->change_media_cb (bs->dev_opaque); + bs->dev_ops->change_media_cb (bs->dev_opaque, load); } }
@@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) }else if (!bs->valid_key) { bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs,1 ); }return ret; }
block.h +2 -1
@@ -32,11 +32,12 @@ typedef struct QEMUSnapshotInfo { typedef struct BlockDevOps { /* * Runs when virtual media changed (monitor commands eject, change) + * Argument load is true on load and false on eject. * Beware: doesn't run when a host device's physical media * changes. Sure would be useful if it did. * Device models with removable media must implement this callback. */ - void (*change_media_cb)(void *opaque); + void (*change_media_cb)(void *opaque, bool load); /* * Is medium ejected from the device? * Device models calling bdrv_eject() should implement this.
hw/fdc.c +1 -1
@@ -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;
hw/ide/core.c +1 -1
@@ -759,7 +759,7 @@ static void ide_cfata_metadata_write(IDEState *s) }/* called when the inserted state of the media has changed */ -static void ide_cd_change_cb (void *opaque) +static void ide_cd_change_cb (void *opaque,bool load) {IDEState *s = opaque;uint64_t nb_sectors;
hw/scsi-disk.c +1 -1
@@ -1212,7 +1212,7 @@ static void scsi_destroy(SCSIDevice *dev)blockdev_mark_auto_del (s->qdev.conf.bs); } -static void scsi_cd_change_media_cb (void *opaque) +static void scsi_cd_change_media_cb (void *opaque,bool load) { }
hw/sd.c +1 -1
@@ -419,7 +419,7 @@ static void sd_reset(SDState *sd, BlockDriverState *bdrv) sd->pwd_len =0 ; } -static void sd_cardchange (void *opaque) +static void sd_cardchange (void *opaque,bool load) {SDState *sd = opaque;
Signature · 1 line
1.7.6
Re: [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 57 lines
To let device models distinguish between eject and load.
Signed-off-by Markus Armbruster <[email protected]>--- 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(-)block.c +5
-5@@ -44,7 +44,7 @@#include <windows.h> #endif -static void bdrv_dev_change_media_cb (BlockDriverState *bs); +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load);static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);@@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }if (!bdrv_key_required (bs)) { -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, true); }return 0 ;@@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)bdrv_close (bs->file); } -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, false); } }@@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, } } -static void bdrv_dev_change_media_cb (BlockDriverState *bs) +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load) {if (bs->dev_ops && bs->dev_ops->change_media_cb) { - bs->dev_ops->change_media_cb (bs->dev_opaque); + bs->dev_ops->change_media_cb (bs->dev_opaque, load); } }
block.c int bdrv_set_key(BlockDriverState *bs, const char *key) · line 1637
Quoted 5 lines
block.c +1
-1@@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) }else if (!bs->valid_key) { bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs,1 );
s/1/true/
Kevin
Re: [Qemu-devel] [PATCH v2 44/45] block: New change_media_cb() parameter load
Quoted 57 lines · Kevin Wolf
Am 03.08.2011 15:08, schrieb Markus Armbruster:
Quoted 56 lines
To let device models distinguish between eject and load.
Signed-off-by Markus Armbruster <[email protected]>--- 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(-)block.c +5
-5@@ -44,7 +44,7 @@#include <windows.h> #endif -static void bdrv_dev_change_media_cb (BlockDriverState *bs); +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load);static BlockDriverAIOCB *bdrv_aio_readv_em (BlockDriverState *bs,int64_t sector_num,QEMUIOVector *qiov,int nb_sectors,BlockDriverCompletionFunc *cb,void *opaque);@@ -661,7 +661,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }if (!bdrv_key_required (bs)) { -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, true); }return 0 ;@@ -697,7 +697,7 @@ void bdrv_close(BlockDriverState *bs)bdrv_close (bs->file); } -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs, false); } }@@ -780,10 +780,10 @@ void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, } } -static void bdrv_dev_change_media_cb (BlockDriverState *bs) +static void bdrv_dev_change_media_cb (BlockDriverState *bs,bool load) {if (bs->dev_ops && bs->dev_ops->change_media_cb) { - bs->dev_ops->change_media_cb (bs->dev_opaque); + bs->dev_ops->change_media_cb (bs->dev_opaque, load); } }
Quoted 8 lines
block.c int bdrv_set_key(BlockDriverState *bs, const char *key) · line 1637
Quoted 6 lines
block.c +1
-1@@ -1634,7 +1634,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) }else if (!bs->valid_key) { bs->valid_key =1 ;/* call the change callback now, we skipped it on open */ -bdrv_dev_change_media_cb (bs); +bdrv_dev_change_media_cb (bs,1 );s/1/true/
Thanks, will fix.
PATCH v2 45/45 ide/atapi scsi-disk: Make monitor eject -f, then change work
In reply to Markus Armbrusterchange 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.
--- blockdev.c | 3 ++- hw/ide/core.c | 1 + hw/scsi-disk.c | 1 + 3 files changed, 4 insertions(+), 1 deletions(-)
blockdev.c +2 -1
@@ -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 ; }
hw/ide/core.c +1 -0
@@ -764,6 +764,7 @@ static void ide_cd_change_cb(void *opaque, bool load)IDEState *s = opaque;uint64_t nb_sectors; + s->tray_open = !load;bdrv_get_geometry (s->bs, &nb_sectors); s->nb_sectors = nb_sectors;
hw/scsi-disk.c +1 -0
@@ -1214,6 +1214,7 @@ static void scsi_destroy(SCSIDevice *dev)static void scsi_cd_change_media_cb (void *opaque,bool load) { + ((SCSIDiskState *)opaque)->tray_open = !load; }static bool scsi_cd_is_medium_ejected (void *opaque)
Signature · 1 line
1.7.6
Quoted 5 lines · Markus Armbruster
* Both master and the block branch are broken for me by Avi's memory API work (Avi reproduced, and claims to have a fix), so for testing I had to rebase the block branch on an older master
cde1a700plus my
dependencies: some Xen worke3745602..679f4f8b, and some nand work64de0e46..63efb1d9.
The problem is that the old-style 440FX PAM dislikes the new-style memory registration. The fix is the conversion of 440FX to the memory API, which will arrive with the third batch of my patchset.
Signature · 1 line
error compiling committee.c: too many arguments to function
Kevin Wolf
AppliedAm 03.08.2011 15:07, schrieb Markus Armbruster:
Quoted 33 lines
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_changedinto device models, where they belong.* BlockDriverState member removable is a confusing mess, replace it.
* Improve eject -f.
Also clean up minor messes as they get in the way.
It is based on Kevin's block branch
f08df41b.Part I: Preliminaries
PATCH 01-03: Work on block layer interface for device modelsPart II: Move tray state to device models
PATCH 04-10 IDE tray open/closed
PATCH 11-12 SCSI tray open/closed
PATCH 13-14 block layer killtray_open
PATCH 15-16 IDE & SCSI tray lock
PATCH 17-19 block layer kill locked
PATCH 20-24 IDE & SCSI tray bug fixes
PATCH 25-27 IDE & SCSI migrate tray state
PATCH 28-30 block layer & fdcmedia_changedPart III: Replace removable
PATCH 31-34 clean up inappopriate uses of removable PATCH 35-36 replace remaining users
Quoted 7 lines
Part IV: Miscellaneous
PATCH 37 cover tray open/closed in info block
PATCH 38-43 Reduce unclean use ofblock_int.h
PATCH 44-45 Improve eject -fNaturally, I want all parts applied. But I did my best to make applying only a prefix workable, too.
Thanks, applied some patches to the block branch. Waiting for v3 for the rest.
I didn't pick them only from the start of the series, but considered any patch that looked good and didn't seem to depend on other patches. This means that some patches may be applied in a different order now, but I'm relatively sure that it doesn't break things.
Kevin