Split ide-drive and scsi-disk qdevs, and more
PATCH 1/8 virtio-pci: Check for virtio_blk_init() failure
In reply to Markus ArmbrusterIt can't actually fail now, but the next commit will change that.
s390_virtio_blk_init() already checks for failure, but virtio_blk_init_pci() doesn't. Fix that.
--- hw/virtio-pci.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
hw/virtio-pci.c +3 -0
@@ -552,6 +552,9 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev)return -1 ; } vdev =virtio_blk_init (&pci_dev->qdev, &proxy->block); +if (!vdev) { +return -1 ; + } vdev->nvectors = proxy->nvectors; virtio_init_pci(proxy, vdev, PCI_VENDOR_ID_REDHAT_QUMRANET,
Signature · 1 line
1.6.6.1
cover Split ide-drive and scsi-disk qdevs, and more
This patch series is about purging the "type hint" from the block layer. My previous series cleaned up improper uses it. Remaining uses are info block and qdevs ide-drive, scsidisk.
Remove the type hint from info block. Its value is unreliable anyway.
ide-drive and scsi-disk can either act as disk or as CD drive. They use their drive's type hint to decide between disk and CD. This is unclean. Disk vs. CD needs to be in qdev, not BlockDriverState, because it belongs to the drive's guest part.
Split them into separate devices for disk and CD. Keep the old ones for backward compatibility.
Bonus fix: reject empty drives unless media is removable (1-3/8).
This patch series is available atgit://repo.or.cz/qemu/armbru.git
tag block-qdev-split: this series, based on tag block-fixes-2-v2: my previous series, based on tag blockdev-base, which the current kevin/block
Markus Armbruster (8):
virtio-pci: Check for virtio_blk_init() failure
virtio-blk: Fix virtio-blk-s390 to require drive
ide scsi virtio-blk: Reject empty drives unless media is removable block QMP: Drop query-block member "type" (type= in info block)
ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd"
scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
blockdev: Store -drive option media in DriveInfo
block: Remove type hint
block.c | 32 +------------ block.h | 5 -- block_int.h | 1 - blockdev.c | 5 +- blockdev.h | 1 + hw/ide/core.c | 14 ++++-- hw/ide/internal.h | 2 +- hw/ide/qdev.c | 70 +++++++++++++++++++++++------ hw/scsi-disk.c | 124 +++++++++++++++++++++++++++++++++++++++++----------- hw/virtio-blk.c | 10 ++++ hw/virtio-pci.c | 5 +- hw/xen_devconfig.c | 2 +- qemu-monitor.hx | 6 --- 13 files changed, 185 insertions(+), 92 deletions(-)
PATCH 3/8 ide scsi virtio-blk: Reject empty drives unless media is removable
Disks without media make no sense. For SCSI, a Linux guest kernel complains during boot. I didn't try other combinations.
scsi-generic doesn't need the additional check, because it already requires bdrv_is_sg(), which fails without media.
--- hw/ide/core.c | 4 ++++ hw/scsi-disk.c | 5 +++++ hw/virtio-blk.c | 4 ++++ 3 files changed, 13 insertions(+), 0 deletions(-)
hw/ide/core.c +4 -0
@@ -2630,6 +2630,10 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, s->drive_kind =IDE_CD ;bdrv_set_change_cb (bs, cdrom_change_cb, s); }else { +if (!bdrv_is_inserted (s->bs)) { +error_report ("Device needs media, but drive is empty" ); +return -1 ; + }if (bdrv_is_read_only (bs)) {error_report ("Can't use a read-only drive" );return -1 ;
hw/scsi-disk.c +5 -0
@@ -1059,6 +1059,11 @@ static int scsi_disk_initfn(SCSIDevice *dev) s->bs = s->qdev.conf.bs; is_cd =bdrv_get_type_hint (s->bs) ==BDRV_TYPE_CDROM ; +if (!is_cd && !bdrv_is_inserted (s->bs)) { +error_report ("Device needs media, but drive is empty" ); +return -1 ; + } +if (bdrv_get_on_error (s->bs,1 ) !=BLOCK_ERR_REPORT ) {error_report ("Device doesn't support drive option rerror" );return -1 ;
hw/virtio-blk.c +4 -0
@@ -495,6 +495,10 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)error_report ("virtio-blk-pci: drive property not set" );return NULL ; } +if (!bdrv_is_inserted (conf->bs)) { +error_report ("Device needs media, but drive is empty" ); +return NULL ; + } s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config),
Signature · 1 line
1.6.6.1
PATCH 4/8 block QMP: Drop query-block member "type" (type= in info block)
In reply to Markus ArmbrusterIts value is unreliable: a block device used as floppy has type "floppy" if created with if=floppy, but type "hd" if created with if=none.
That's because with if=none, the type is at best a declaration of
intent: the drive can be connected to any guest device. Its type is really the guest device's business. Reporting it here is wrong.
--- block.c | 20 +++----------------- qemu-monitor.hx | 6 ------ 2 files changed, 3 insertions(+), 23 deletions(-)
block.c +3 -17
@@ -1533,9 +1533,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque) bs_dict =qobject_to_qdict (obj); -monitor_printf (mon,"%s: type=%s removable=%d" , +monitor_printf (mon,"%s: removable=%d" ,qdict_get_str (bs_dict,"device" ), -qdict_get_str (bs_dict,"type" ),qdict_get_bool (bs_dict,"removable" ));if (qdict_get_bool (bs_dict,"removable" )) {
@@ -1576,23 +1575,10 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QTAILQ_FOREACH(bs, &bdrv_states, list) {QObject *bs_obj; -const char *type ="unknown" ; - -switch (bs->type) { -case BDRV_TYPE_HD : - type ="hd" ; -break ; -case BDRV_TYPE_CDROM : - type ="cdrom" ; -break ; -case BDRV_TYPE_FLOPPY : - type ="floppy" ; -break ; - } - bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': %s, " + bs_obj =qobject_from_jsonf ("{ 'device': %s, " "'removable': %i, 'locked': %i }" , - bs->device_name, type, bs->removable, + bs->device_name, bs->removable, bs->locked);if (bs->drv) {
qemu-monitor.hx +0 -6
@@ -1723,8 +1723,6 @@ is a json-array of all devices. Each json-object contain the following: - "device": device name (json-string) -- "type": device type (json-string) - - Possible values: "hd", "cdrom", "floppy", "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) - "inserted": only present if the device is inserted, it is a json-object
@@ -1755,25 +1753,21 @@ Example: "encrypted":false, "file":"disks/test.img" }, - "type":"hd" }, { "device":"ide1-cd0", "locked":false, "removable":true, - "type":"cdrom" }, { "device":"floppy0", "locked":false, "removable":true, - "type": "floppy" }, { "device":"sd0", "locked":false, "removable":true, - "type":"floppy" } ] }
Signature · 1 line
1.6.6.1
PATCH 8/8 block: Remove type hint
In reply to Markus ArmbrusterNo users left.
bdrv_set_type_hint() can make the media removable by side effect. Make that explicit.
--- block.c | 12 ------------ block.h | 5 ----- block_int.h | 1 - blockdev.c | 4 ++-- 4 files changed, 2 insertions(+), 20 deletions(-)
block.c +0 -12
@@ -1260,13 +1260,6 @@ void bdrv_set_geometry_hint(BlockDriverState *bs, bs->secs = secs; } -void bdrv_set_type_hint (BlockDriverState *bs,int type) -{ - bs->type = type; - bs->removable = ((type ==BDRV_TYPE_CDROM || - type ==BDRV_TYPE_FLOPPY )); -} -void bdrv_set_translation_hint (BlockDriverState *bs,int translation) { bs->translation = translation;
@@ -1280,11 +1273,6 @@ void bdrv_get_geometry_hint(BlockDriverState *bs, *psecs = bs->secs; } -int bdrv_get_type_hint (BlockDriverState *bs) -{ -return bs->type; -} -int bdrv_get_translation_hint (BlockDriverState *bs) {return bs->translation;
block.h +0 -5
@@ -150,9 +150,6 @@ int bdrv_has_zero_init(BlockDriverState *bs);int bdrv_is_allocated (BlockDriverState *bs,int64_t sector_num,int nb_sectors,int *pnum); -#define BDRV_TYPE_HD 0 -#define BDRV_TYPE_CDROM 1 -#define BDRV_TYPE_FLOPPY 2#define BIOS_ATA_TRANSLATION_AUTO 0#define BIOS_ATA_TRANSLATION_NONE 1#define BIOS_ATA_TRANSLATION_LBA 2
@@ -161,11 +158,9 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,void bdrv_set_geometry_hint (BlockDriverState *bs,int cyls,int heads,int secs); -void bdrv_set_type_hint (BlockDriverState *bs,int type);void bdrv_set_translation_hint (BlockDriverState *bs,int translation);void bdrv_get_geometry_hint (BlockDriverState *bs,int *pcyls,int *pheads,int *psecs); -int bdrv_get_type_hint (BlockDriverState *bs);int bdrv_get_translation_hint (BlockDriverState *bs);void bdrv_set_on_error (BlockDriverState *bs,BlockErrorAction on_read_error,BlockErrorAction on_write_error);
block_int.h +0 -1
@@ -186,7 +186,6 @@ struct BlockDriverState {/* NOTE: the following infos are only hints for real hardware drivers. They are not used by the block driver */ int cyls, heads, secs, translation; -int type;BlockErrorAction on_read_error, on_write_error;char device_name[32 ];unsigned long *dirty_bitmap;
blockdev.c +2 -2
@@ -436,7 +436,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) }break ;case MEDIA_CDROM : -bdrv_set_type_hint (dinfo->bdrv,BDRV_TYPE_CDROM ); +bdrv_set_removable (dinfo->bdrv,1 ); dinfo->media_cd =1 ;break ; }
@@ -445,7 +445,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)/* FIXME: This isn't really a floppy, but it's a reasonable approximation. */ case IF_FLOPPY : -bdrv_set_type_hint (dinfo->bdrv,BDRV_TYPE_FLOPPY ); +bdrv_set_removable (dinfo->bdrv,1 );break ;case IF_PFLASH :case IF_MTD :
Signature · 1 line
1.6.6.1
PATCH 2/8 virtio-blk: Fix virtio-blk-s390 to require drive
In reply to Markus ArmbrusterMove the check from virtio_blk_init_pci(), where it protects only virtio-blk-pci, to virtio_blk_init(). Without that, virtio-blk-s390 initializes without a drive. I figure that can lead to null pointer dereferences.
--- hw/virtio-blk.c | 6 ++++++ hw/virtio-pci.c | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-)
hw/virtio-blk.c +6 -0
@@ -12,6 +12,7 @@*/ #include <qemu-common.h> +#include "qemu-error.h" #include "virtio-blk.h" #ifdef __linux__# include <scsi/sg.h>
@@ -490,6 +491,11 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)static int virtio_blk_id;DriveInfo *dinfo; +if (!conf->bs) { +error_report ("virtio-blk-pci: drive property not set" ); +return NULL ; + } + s = (VirtIOBlock *)virtio_common_init ("virtio-blk" ,VIRTIO_ID_BLOCK ,sizeof (struct virtio_blk_config ),sizeof (VirtIOBlock));
hw/virtio-pci.c +0 -4
@@ -547,10 +547,6 @@ static int virtio_blk_init_pci(PCIDevice *pci_dev) proxy->class_code != PCI_CLASS_STORAGE_OTHER) proxy->class_code =PCI_CLASS_STORAGE_SCSI ; -if (!proxy->block.bs) { -error_report ("virtio-blk-pci: drive property not set" ); -return -1 ; - } vdev =virtio_blk_init (&pci_dev->qdev, &proxy->block);if (!vdev) {return -1 ;
Signature · 1 line
1.6.6.1
PATCH 5/8 ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd"
In reply to Markus ArmbrusterDisk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Keep ide-drive for backward compatibility.
--- hw/ide/core.c | 11 +++++--- hw/ide/internal.h | 2 +- hw/ide/qdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 66 insertions(+), 19 deletions(-)
hw/ide/core.c +7 -4
@@ -2595,13 +2595,15 @@ void ide_bus_reset(IDEBus *bus)ide_clear_hob (bus); } -int ide_init_drive (IDEState *s,BlockDriverState *bs, +int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind,const char *version,const char *serial) {int cylinders, heads, secs;uint64_t nb_sectors; s->bs = bs; + s->drive_kind = kind; +bdrv_get_geometry (bs, &nb_sectors);bdrv_guess_geometry (bs, &cylinders, &heads, &secs);if (cylinders <1 || cylinders >16383 ) {
@@ -2626,8 +2628,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, s->smart_autosave =1 ; s->smart_errors =0 ; s->smart_selftest_count =0 ; -if (bdrv_get_type_hint (bs) ==BDRV_TYPE_CDROM ) { - s->drive_kind =IDE_CD ; +if (kind ==IDE_CD ) {bdrv_set_change_cb (bs, cdrom_change_cb, s); }else {if (!bdrv_is_inserted (s->bs)) {
@@ -2692,7 +2693,9 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, dinfo = i ==0 ? hd0 : hd1;ide_init1 (bus, i);if (dinfo) { -if (ide_init_drive (&bus->ifs[i], dinfo->bdrv,NULL , +if (ide_init_drive (&bus->ifs[i], dinfo->bdrv, +bdrv_get_type_hint (dinfo->bdrv) ==BDRV_TYPE_CDROM ?IDE_CD :IDE_HD , +NULL , *dinfo->serial ? dinfo->serial :NULL ) <0 ) {error_report ("Can't set up IDE drive %s" , dinfo->id);exit (1 );
hw/ide/internal.h +1 -1
@@ -556,7 +556,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);void ide_data_writel (void *opaque,uint32_t addr,uint32_t val);uint32_t ide_data_readl (void *opaque,uint32_t addr); -int ide_init_drive (IDEState *s,BlockDriverState *bs, +int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind,const char *version,const char *serial);void ide_init2 (IDEBus *bus,qemu_irq irq); void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
hw/ide/qdev.c +58 -14
100 lines not on this page · raw message
Signature · 1 line
1.6.6.1
PATCH 6/8 scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
In reply to Markus ArmbrusterDisk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Keep scsi-disk for backward compatibility.
--- hw/scsi-disk.c | 117 +++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 91 insertions(+), 26 deletions(-)
hw/scsi-disk.c +91 -26
@@ -67,6 +67,7 @@ struct SCSIDiskStateQEMUBH *bh;char *version;char *serial; +int is_cd; };static SCSIDiskReq *scsi_new_request (SCSIDevice *d,uint32_t tag,uint32_t lun)
@@ -339,7 +340,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)return -1 ; } -if (bdrv_get_type_hint (s->bs) ==BDRV_TYPE_CDROM ) { +if (s->is_cd) { outbuf[buflen++] =5 ; }else { outbuf[buflen++] =0 ;
@@ -452,7 +453,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf)return buflen; } -if (bdrv_get_type_hint (s->bs) ==BDRV_TYPE_CDROM ) { +if (s->is_cd) { outbuf[0 ] =5 ; outbuf[1 ] =0x80 ;memcpy (&outbuf[16 ],"QEMU CD-ROM " ,16 );
@@ -566,7 +567,7 @@ static int mode_sense_page(SCSIRequest *req, int page, uint8_t *p)return 20 ;case 0x2a :/* CD Capabilities and Mechanical Status page. */ -if (bdrv_get_type_hint (bdrv) !=BDRV_TYPE_CDROM ) +if (!s->is_cd)return 0 ; p[0 ] =0x2a ; p[1 ] =0x14 ;
@@ -755,7 +756,7 @@ static int scsi_disk_emulate_command(SCSIRequest *req, uint8_t *outbuf) goto illegal_request;break ;case START_STOP : -if (bdrv_get_type_hint (s->bs) ==BDRV_TYPE_CDROM && (req->cmd.buf[4 ] &2 )) { +if (s->is_cd && (req->cmd.buf[4 ] &2 )) {/* load/eject medium */ bdrv_eject (s->bs, !(req->cmd.buf[4 ] &1 )); }
@@ -1046,10 +1047,9 @@ static void scsi_destroy(SCSIDevice *dev)blockdev_mark_auto_del (s->qdev.conf.bs); } -static int scsi_disk_initfn (SCSIDevice *dev) +static int scsi_initfn (SCSIDevice *dev,int is_cd) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); -int is_cd;DriveInfo *dinfo;if (!s->qdev.conf.bs) {
@@ -1057,7 +1057,7 @@ static int scsi_disk_initfn(SCSIDevice *dev)return -1 ; } s->bs = s->qdev.conf.bs; - is_cd =bdrv_get_type_hint (s->bs) ==BDRV_TYPE_CDROM ; + s->is_cd = is_cd;if (!is_cd && !bdrv_is_inserted (s->bs)) {error_report ("Device needs media, but drive is empty" );
@@ -1097,28 +1097,93 @@ static int scsi_disk_initfn(SCSIDevice *dev)return 0 ; } -static SCSIDeviceInfo scsi_disk_info = { - .qdev.name ="scsi-disk" , - .qdev.desc ="virtual scsi disk or cdrom" , - .qdev.size =sizeof (SCSIDiskState), - .qdev.reset = scsi_disk_reset, - .init = scsi_disk_initfn, - .destroy = scsi_destroy, - .send_command = scsi_send_command, - .read_data = scsi_read_data, - .write_data = scsi_write_data, - .cancel_io = scsi_cancel_io, - .get_buf = scsi_get_buf, - .qdev.props = (Property []) { -DEFINE_BLOCK_PROPERTIES (SCSIDiskState, qdev.conf), -DEFINE_PROP_STRING ("ver" , SCSIDiskState, version), -DEFINE_PROP_STRING ("serial" , SCSIDiskState, serial), -DEFINE_PROP_END_OF_LIST (), - }, +static int scsi_hd_initfn (SCSIDevice *dev) +{ +return scsi_initfn (dev,0 ); +} + +static int scsi_cd_initfn (SCSIDevice *dev) +{ +return scsi_initfn (dev,1 ); +} + +static int scsi_disk_initfn (SCSIDevice *dev) +{ +int is_cd; + +if (!dev->conf.bs) { + is_cd =0 ;/* will die in scsi_initfn() */ + }else { + is_cd =bdrv_get_type_hint (dev->conf.bs) ==BDRV_TYPE_CDROM ; + } + +return scsi_initfn (dev, is_cd); +} + +static SCSIDeviceInfo scsi_disk_info[] = { + { + .qdev.name ="scsi-hd" , + .qdev.desc ="virtual scsi disk" , + .qdev.size =sizeof (SCSIDiskState), + .qdev.reset = scsi_disk_reset, + .init = scsi_hd_initfn, + .destroy = scsi_destroy, + .send_command = scsi_send_command, + .read_data = scsi_read_data, + .write_data = scsi_write_data, + .cancel_io = scsi_cancel_io, + .get_buf = scsi_get_buf, + .qdev.props = (Property []) { +DEFINE_BLOCK_PROPERTIES (SCSIDiskState, qdev.conf), +DEFINE_PROP_STRING ("ver" , SCSIDiskState, version), +DEFINE_PROP_STRING ("serial" , SCSIDiskState, serial), +DEFINE_PROP_END_OF_LIST (), + } + },{ + .qdev.name ="scsi-cd" , + .qdev.desc ="virtual scsi cdrom" , + .qdev.size =sizeof (SCSIDiskState), + .qdev.reset = scsi_disk_reset, + .init = scsi_cd_initfn, + .destroy = scsi_destroy, + .send_command = scsi_send_command, + .read_data = scsi_read_data, + .write_data = scsi_write_data, + .cancel_io = scsi_cancel_io, + .get_buf = scsi_get_buf, + .qdev.props = (Property []) { +DEFINE_BLOCK_PROPERTIES (SCSIDiskState, qdev.conf), +DEFINE_PROP_STRING ("ver" , SCSIDiskState, version), +DEFINE_PROP_STRING ("serial" , SCSIDiskState, serial), +DEFINE_PROP_END_OF_LIST (), + }, + },{ + .qdev.name ="scsi-disk" ,/* legacy -device scsi-disk */ + .qdev.desc ="virtual scsi disk or cdrom (legacy)" , + .qdev.size =sizeof (SCSIDiskState), + .qdev.reset = scsi_disk_reset, + .init = scsi_disk_initfn, + .destroy = scsi_destroy, + .send_command = scsi_send_command, + .read_data = scsi_read_data, + .write_data = scsi_write_data, + .cancel_io = scsi_cancel_io, + .get_buf = scsi_get_buf, + .qdev.props = (Property []) { +DEFINE_BLOCK_PROPERTIES (SCSIDiskState, qdev.conf), +DEFINE_PROP_STRING ("ver" , SCSIDiskState, version), +DEFINE_PROP_STRING ("serial" , SCSIDiskState, serial), +DEFINE_PROP_END_OF_LIST (), + } + } };static void scsi_disk_register_devices (void ) { -scsi_qdev_register (&scsi_disk_info); +int i; + +for (i =0 ; i <ARRAY_SIZE (scsi_disk_info); i++) { +scsi_qdev_register (&scsi_disk_info[i]); + } }device_init (scsi_disk_register_devices)
Signature · 1 line
1.6.6.1
PATCH 7/8 blockdev: Store -drive option media in DriveInfo
In reply to Markus ArmbrusterUse it instead of bdrv_get_type_hint() to pick HD vs. CD for IDE, SCSI and XEN drives.
--- blockdev.c | 1 + blockdev.h | 1 + hw/ide/core.c | 3 +-- hw/ide/qdev.c | 10 ++++------ hw/scsi-disk.c | 4 +++- hw/xen_devconfig.c | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-)
blockdev.c +1 -0
@@ -437,6 +437,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)break ;case MEDIA_CDROM :bdrv_set_type_hint (dinfo->bdrv,BDRV_TYPE_CDROM ); + dinfo->media_cd =1 ;break ; }break ;
blockdev.h +1 -0
@@ -32,6 +32,7 @@ typedef struct DriveInfo {int bus;int unit;int auto_del;/* see blockdev_mark_auto_del() */ +int media_cd;QemuOpts *opts;char serial[BLOCK_SERIAL_STRLEN +1 ];QTAILQ_ENTRY (DriveInfo) next;
hw/ide/core.c +1 -2
@@ -2694,8 +2694,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,ide_init1 (bus, i);if (dinfo) {if (ide_init_drive (&bus->ifs[i], dinfo->bdrv, -bdrv_get_type_hint (dinfo->bdrv) ==BDRV_TYPE_CDROM ?IDE_CD :IDE_HD , -NULL , + dinfo->media_cd ?IDE_CD :IDE_HD ,NULL , *dinfo->serial ? dinfo->serial :NULL ) <0 ) {error_report ("Can't set up IDE drive %s" , dinfo->id);exit (1 );
hw/ide/qdev.c +4 -6
@@ -82,9 +82,7 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) {DeviceState *dev; - dev =qdev_create (&bus->qbus, -bdrv_get_type_hint (drive->bdrv) ==BDRV_TYPE_CDROM - ?"ide-hd" :"ide-cd" ); + dev =qdev_create (&bus->qbus, drive->media_cd ?"ide-hd" :"ide-cd" );qdev_prop_set_uint32 (dev,"unit" , unit);qdev_prop_set_drive_nofail (dev,"drive" , drive->bdrv);qdev_init_nofail (dev);
@@ -145,9 +143,9 @@ static int ide_cd_initfn(IDEDevice *dev)static int ide_drive_initfn (IDEDevice *dev) { -return ide_dev_initfn (dev, -bdrv_get_type_hint (dev->conf.bs) ==BDRV_TYPE_CDROM - ?IDE_CD :IDE_HD ); +DriveInfo *dinfo =drive_get_by_blockdev (dev->conf.bs); + +return ide_dev_initfn (dev, dinfo->media_cd ?IDE_CD :IDE_HD ); }#define DEFINE_IDE_DRIVE_PROPERTIES () \
hw/scsi-disk.c +3 -1
@@ -1110,11 +1110,13 @@ static int scsi_cd_initfn(SCSIDevice *dev)static int scsi_disk_initfn (SCSIDevice *dev) {int is_cd; +DriveInfo *dinfo;if (!dev->conf.bs) { is_cd =0 ;/* will die in scsi_initfn() */ }else { - is_cd =bdrv_get_type_hint (dev->conf.bs) ==BDRV_TYPE_CDROM ; + dinfo =drive_get_by_blockdev (dev->conf.bs); + is_cd = dinfo->media_cd; }return scsi_initfn (dev, is_cd);
hw/xen_devconfig.c +1 -1
@@ -94,7 +94,7 @@ int xen_config_dev_blk(DriveInfo *disk) {char fe[256 ], be[256 ];int vdev =202 *256 +16 * disk->unit; -int cdrom = disk->bdrv->type ==BDRV_TYPE_CDROM ; +int cdrom = disk->media_cd;const char *devtype = cdrom ?"cdrom" :"disk" ;const char *mode = cdrom ?"r" :"w" ;
Signature · 1 line
1.6.6.1
[Qemu-devel] Re: [PATCH 4/8] block QMP: Drop query-block member "type" (type= in info block)
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
Am 06.07.2010 14:37, schrieb Markus Armbruster:
Quoted 8 lines
Its value is unreliable: a block device used as floppy has type "floppy" if created with if=floppy, but type "hd" if created with if=none.
That's because with if=none, the type is at best a declaration of
intent: the drive can be connected to any guest device. Its type is really the guest device's business. Reporting it here is wrong.
Quoted 5 lines
Quoted 1 line
Signed-off-by Markus Armbruster <[email protected]>Dan, I'd like to have your Acked-by for this patch before applying it. Can libvirt handle such a change in the monitor output, or does it even use info block?
We don't use the 'info block' or query-block commands at this point in time, only 'info blockstats'/'query-blockstats'. So it should be fine to drop this field from libvirt's POV.
Regards,
Daniel
Signature · 4 lines
|: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
[Qemu-devel] Re: [PATCH 4/8] block QMP: Drop query-block member "type" (type= in info block)
In reply to Markus ArmbrusterAm 06.07.2010 14:37, schrieb Markus Armbruster:
Quoted 9 lines
Its value is unreliable: a block device used as floppy has type "floppy" if created with if=floppy, but type "hd" if created with if=none.
That's because with if=none, the type is at best a declaration of
intent: the drive can be connected to any guest device. Its type is really the guest device's business. Reporting it here is wrong.Signed-off-by Markus Armbruster <[email protected]>
Dan, I'd like to have your Acked-by for this patch before applying it. Can libvirt handle such a change in the monitor output, or does it even use info block?
Kevin
Quoted 85 lines
--- block.c | 20 +++----------------- qemu-monitor.hx | 6 ------ 2 files changed, 3 insertions(+), 23 deletions(-)block.c +3
-17@@ -1533,9 +1533,8 @@ static void bdrv_print_dict(QObject *obj, void *opaque) bs_dict =qobject_to_qdict (obj); -monitor_printf (mon,"%s: type=%s removable=%d" , +monitor_printf (mon,"%s: removable=%d" ,qdict_get_str (bs_dict,"device" ), -qdict_get_str (bs_dict,"type" ),qdict_get_bool (bs_dict,"removable" ));if (qdict_get_bool (bs_dict,"removable" )) {@@ -1576,23 +1575,10 @@ void bdrv_info(Monitor *mon, QObject **ret_data) QTAILQ_FOREACH(bs, &bdrv_states, list) {QObject *bs_obj; -const char *type ="unknown" ; - -switch (bs->type) { -case BDRV_TYPE_HD : - type ="hd" ; -break ; -case BDRV_TYPE_CDROM : - type ="cdrom" ; -break ; -case BDRV_TYPE_FLOPPY : - type ="floppy" ; -break ; - } - bs_obj =qobject_from_jsonf ("{ 'device': %s, 'type': %s, " + bs_obj =qobject_from_jsonf ("{ 'device': %s, " "'removable': %i, 'locked': %i }" , - bs->device_name, type, bs->removable, + bs->device_name, bs->removable, bs->locked);if (bs->drv) {qemu-monitor.hx +0
-6@@ -1723,8 +1723,6 @@ is a json-array of all devices. Each json-object contain the following: - "device": device name (json-string) -- "type": device type (json-string) - - Possible values: "hd", "cdrom", "floppy", "unknown" - "removable": true if the device is removable, false otherwise (json-bool) - "locked": true if the device is locked, false otherwise (json-bool) - "inserted": only present if the device is inserted, it is a json-object@@ -1755,25 +1753,21 @@ Example: "encrypted":false, "file":"disks/test.img" }, - "type":"hd" }, { "device":"ide1-cd0", "locked":false, "removable":true, - "type":"cdrom" }, { "device":"floppy0", "locked":false, "removable":true, - "type": "floppy" }, { "device":"sd0", "locked":false, "removable":true, - "type":"floppy" } ] }
[Qemu-devel] Re: [PATCH 1/8] virtio-pci: Check for virtio_blk_init() failure
In reply to Markus ArmbrusterLooks good,
[Qemu-devel] Re: [PATCH 2/8] virtio-blk: Fix virtio-blk-s390 to require drive
In reply to Markus ArmbrusterLooks good,
[Qemu-devel] Re: [PATCH 3/8] ide scsi virtio-blk: Reject empty drives unless media is removable
In reply to Markus ArmbrusterQuoted 5 lines · Markus Armbruster
Disks without media make no sense. For SCSI, a Linux guest kernel complains during boot. I didn't try other combinations.
scsi-generic doesn't need the additional check, because it already requires
bdrv_is_sg(), which fails without media.
Looks good,
[Qemu-devel] Re: [PATCH 4/8] block QMP: Drop query-block member "type" (type= in info block)
In reply to Markus ArmbrusterLooks correct to me,
[Qemu-devel] Re: [PATCH 5/8] ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd"
In reply to Markus ArmbrusterLooks good,
[Qemu-devel] Re: [PATCH 6/8] scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
In reply to Markus ArmbrusterQuoted 2 lines · Markus Armbruster
Disk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Looks good, but the scsi-hd name feelds kinda awkward. This is one case we're I'm really wondering if the compatiblity is worth it or if we should just keep using scsi-disk for the real disk.
[Qemu-devel] Re: [PATCH 7/8] blockdev: Store -drive option media in DriveInfo
In reply to Markus ArmbrusterI'd rather have an enum about the drive type instead of the is_cdrom flag. In addition I think patch 8 should be folded into this one.
[Qemu-devel] Re: [PATCH 6/8] scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
In reply to Christoph HellwigAm 07.07.2010 03:37, schrieb Christoph Hellwig:
Quoted 7 lines · Markus Armbruster
Quoted 2 lines
Disk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Looks good, but the scsi-hd name feelds kinda awkward. This is one case we're I'm really wondering if the compatiblity is worth it or if we should just keep using scsi-disk for the real disk.
In any case the name should be consistent with ide-hd. And I'm not sure if it's really helpful to have ide-drive and ide-disk.
Kevin
[Qemu-devel] Re: [PATCH 6/8] scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
Quoted 11 lines · Kevin Wolf
Am 07.07.2010 03:37, schrieb Christoph Hellwig:
Quoted 7 lines · Markus Armbruster
Quoted 2 lines
Disk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Looks good, but the scsi-hd name feelds kinda awkward. This is one case we're I'm really wondering if the compatiblity is worth it or if we should just keep using scsi-disk for the real disk.
In any case the name should be consistent with ide-hd. And I'm not sure if it's really helpful to have ide-drive and ide-disk.
{ide,scsi}-{hd,cd} is the best consistent set of names I could find within the backward compatibility straightjacket.
By the way, we could use a way to mark qdevs and properties deprecated.
[Qemu-devel] Re: [PATCH 5/8] ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd"
In reply to Markus ArmbrusterAm 06.07.2010 14:37, schrieb Markus Armbruster:
Quoted 127 lines
Disk vs. CD needs to be in qdev, because it belongs to the drive's guest part.
Keep ide-drive for backward compatibility.
Signed-off-by Markus Armbruster <[email protected]>--- hw/ide/core.c | 11 +++++--- hw/ide/internal.h | 2 +- hw/ide/qdev.c | 72 ++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 66 insertions(+), 19 deletions(-)hw/ide/core.c +7
-4@@ -2595,13 +2595,15 @@ void ide_bus_reset(IDEBus *bus)ide_clear_hob (bus); } -int ide_init_drive (IDEState *s,BlockDriverState *bs, +int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind,const char *version,const char *serial) {int cylinders, heads, secs;uint64_t nb_sectors; s->bs = bs; + s->drive_kind = kind; +bdrv_get_geometry (bs, &nb_sectors);bdrv_guess_geometry (bs, &cylinders, &heads, &secs);if (cylinders <1 || cylinders >16383 ) {@@ -2626,8 +2628,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, s->smart_autosave =1 ; s->smart_errors =0 ; s->smart_selftest_count =0 ; -if (bdrv_get_type_hint (bs) ==BDRV_TYPE_CDROM ) { - s->drive_kind =IDE_CD ; +if (kind ==IDE_CD ) {bdrv_set_change_cb (bs, cdrom_change_cb, s); }else {if (!bdrv_is_inserted (s->bs)) {@@ -2692,7 +2693,9 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, dinfo = i ==0 ? hd0 : hd1;ide_init1 (bus, i);if (dinfo) { -if (ide_init_drive (&bus->ifs[i], dinfo->bdrv,NULL , +if (ide_init_drive (&bus->ifs[i], dinfo->bdrv, +bdrv_get_type_hint (dinfo->bdrv) ==BDRV_TYPE_CDROM ?IDE_CD :IDE_HD , +NULL , *dinfo->serial ? dinfo->serial :NULL ) <0 ) {error_report ("Can't set up IDE drive %s" , dinfo->id);exit (1 );hw/ide/internal.h +1
-1@@ -556,7 +556,7 @@ uint32_t ide_data_readw(void *opaque, uint32_t addr);void ide_data_writel (void *opaque,uint32_t addr,uint32_t val);uint32_t ide_data_readl (void *opaque,uint32_t addr); -int ide_init_drive (IDEState *s,BlockDriverState *bs, +int ide_init_drive (IDEState *s,BlockDriverState *bs,IDEDriveKind kind,const char *version,const char *serial);void ide_init2 (IDEBus *bus,qemu_irq irq); void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,hw/ide/qdev.c +18
-13@@ -82,7 +82,9 @@ IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive) {DeviceState *dev; - dev =qdev_create (&bus->qbus,"ide-drive" ); + dev =qdev_create (&bus->qbus, +bdrv_get_type_hint (drive->bdrv) ==BDRV_TYPE_CDROM + ?"ide-hd" :"ide-cd" );qdev_prop_set_uint32 (dev,"unit" , unit);qdev_prop_set_drive_nofail (dev,"drive" , drive->bdrv);qdev_init_nofail (dev);@@ -102,7 +104,7 @@ typedef struct IDEDrive {IDEDevice dev; } IDEDrive; -static int ide_drive_initfn (IDEDevice *dev) +static int ide_dev_initfn (IDEDevice *dev,IDEDriveKind kind) {IDEBus *bus =DO_UPCAST (IDEBus, qbus, dev->qdev.parent_bus);IDEState *s = bus->ifs + dev->unit;@@ -118,7 +120,7 @@ static int ide_drive_initfn(IDEDevice *dev) } } -if (ide_init_drive (s, dev->conf.bs, dev->version, serial) <0 ) { +if (ide_init_drive (s, dev->conf.bs, kind, dev->version, serial) <0 ) {return -1 ; }@@ -131,21 +133,63 @@ static int ide_drive_initfn(IDEDevice *dev)return 0 ; } -static IDEDeviceInfo ide_drive_info = { - .qdev.name ="ide-drive" , - .qdev.size =sizeof (IDEDrive), - .init = ide_drive_initfn, - .qdev.props = (Property []) { -DEFINE_PROP_UINT32 ("unit" , IDEDrive, dev.unit,-1 ), -DEFINE_BLOCK_PROPERTIES (IDEDrive, dev.conf), -DEFINE_PROP_STRING ("ver" , IDEDrive, dev.version), -DEFINE_PROP_STRING ("serial" , IDEDrive, dev.serial), -DEFINE_PROP_END_OF_LIST (), +static int ide_hd_initfn (IDEDevice *dev) +{ +return ide_dev_initfn (dev,IDE_HD ); +} + +static int ide_cd_initfn (IDEDevice *dev) +{ +return ide_dev_initfn (dev,IDE_CD ); +} + +static int ide_drive_initfn (IDEDevice *dev) +{ + return ide_dev_initfn(dev,
hw/ide/qdev.c static int ide_drive_initfn(IDEDevice *dev) · line 158
Quoted 10 lines
hw/ide/qdev.c +10
-0+bdrv_get_type_hint (dev->conf.bs) ==BDRV_TYPE_CDROM + ? IDE_CD : IDE_HD); +} + +#define DEFINE_IDE_DRIVE_PROPERTIES () \ + DEFINE_PROP_UINT32("unit", IDEDrive, dev.unit, -1), \ + DEFINE_BLOCK_PROPERTIES(IDEDrive, dev.conf), \ + DEFINE_PROP_STRING("ver", IDEDrive, dev.version), \ + DEFINE_PROP_STRING("serial", IDEDrive, dev.serial) +
Whitespace error.
If you don't need to respin, I'll fix it when applying the series.
Kevin
Kevin Wolf
AppliedAm 06.07.2010 14:37, schrieb Markus Armbruster:
Quoted 22 lines
This patch series is about purging the "type hint" from the block layer. My previous series cleaned up improper uses it. Remaining uses are info block and qdevs ide-drive, scsidisk.
Remove the type hint from info block. Its value is unreliable anyway.
ide-drive and scsi-disk can either act as disk or as CD drive. They use their drive's type hint to decide between disk and CD. This is unclean. Disk vs. CD needs to be in qdev, not BlockDriverState, because it belongs to the drive's guest part.
Split them into separate devices for disk and CD. Keep the old ones for backward compatibility.
Bonus fix: reject empty drives unless media is removable (1-3/8).
This patch series is available at
git://repo.or.cz/qemu/armbru.git
tag block-qdev-split: this series, based on tag block-fixes-2-v2: my previous series, based on tag blockdev-base, which the current kevin/block
Quoted 4 lines
Markus Armbruster (8):
virtio-pci: Check forvirtio_blk_init()failure
virtio-blk: Fix virtio-blk-s390 to require drive
ide scsi virtio-blk: Reject empty drives unless media is removable
Thanks, applied patches 1-3 to the block branch.
Quoted 5 lines
block QMP: Drop query-block member "type" (type= in info block)
ide: Split qdev "ide-drive" into "ide-hd" and "ide-cd"
scsi: Split qdev "scsi-disk" into "scsi-hd" and "scsi-cd"
blockdev: Store -drive option media in DriveInfo
block: Remove type hint
As discussed on IRC last week I'll wait for a respin for the remaining ones.
Kevin