block: Create empty drives without explicit BB
cover block: Create empty drives without explicit BB
This series allows creating empty IDE and SCSI CD-ROM drives by leaving out the drive=... option. At the moment, such drives are still relatively useless because you can't insert a medium at runtime yet, but we'll change the QMP commands soon to accept qdev device names instead of BlockBackend names.
Kevin Wolf (2):
ide: ide-cd without drive property for empty drive
scsi: scsi-cd without drive property for empty drive
hw/ide/qdev.c | 20 +++++++++++++++----- hw/scsi/scsi-disk.c | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/2 ide: ide-cd without drive property for empty drive
This allows to create an empty ide-cd device without manually creating a BlockBackend.
--- hw/ide/qdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
hw/ide/qdev.c +15 -5
@@ -75,10 +75,6 @@ static int ide_qdev_init(DeviceState *qdev)IDEDeviceClass *dc =IDE_DEVICE_GET_CLASS (dev);IDEBus *bus =DO_UPCAST (IDEBus, qbus, qdev->parent_bus); -if (!dev->conf.blk) { -error_report ("No drive specified" ); - goto err; - }if (dev->unit ==-1 ) { dev->unit = bus->master ?1 :0 ; }
@@ -158,6 +154,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)IDEState *s = bus->ifs + dev->unit;Error *err =NULL ; +if (!dev->conf.blk) { +if (kind !=IDE_CD ) { +error_report ("No drive specified" ); +return -1 ; + }else { +/* Anonymous BlockBackend for an empty drive */ + dev->conf.blk =blk_new (); + } + } +if (dev->conf.discard_granularity ==-1 ) { dev->conf.discard_granularity =512 ; } else if (dev->conf.discard_granularity &&
@@ -257,7 +263,11 @@ static int ide_cd_initfn(IDEDevice *dev)static int ide_drive_initfn (IDEDevice *dev) { -DriveInfo *dinfo =blk_legacy_dinfo (dev->conf.blk); +DriveInfo *dinfo =NULL ; + +if (dev->conf.blk) { + dinfo =blk_legacy_dinfo (dev->conf.blk); + }return ide_dev_initfn (dev, dinfo && dinfo->media_cd ?IDE_CD :IDE_HD ); }
Signature · 1 line
1.8.3.1
PATCH 2/2 scsi: scsi-cd without drive property for empty drive
In reply to Kevin WolfThis allows to create an empty scsi-cd device without manually creating a BlockBackend.
--- hw/scsi/scsi-disk.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/scsi/scsi-disk.c +5 -0
@@ -2359,6 +2359,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp)static void scsi_cd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); + +if (!dev->conf.blk) { + dev->conf.blk =blk_new (); + } + s->qdev.blocksize =2048 ; s->qdev.type =TYPE_ROM ; s->features |=1 <<SCSI_DISK_F_REMOVABLE ;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 1/2] ide: ide-cd without drive property for empty drive
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
This allows to create an empty ide-cd device without manually creating a BlockBackend.
Signed-off-by Kevin Wolf <[email protected]>--- hw/ide/qdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
hw/ide/qdev.c static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) · line 163
Quoted 10 lines
hw/ide/qdev.c +7
-0@@ -158,6 +154,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)IDEState *s = bus->ifs + dev->unit;Error *err =NULL ; +if (!dev->conf.blk) { +if (kind !=IDE_CD ) { +error_report ("No drive specified" ); +return -1 ; + }else { +/* Anonymous BlockBackend for an empty drive */ + dev->conf.blk =blk_new ();
So we either fail or dev->conf.blk is set...
Quoted 8 lines
hw/ide/qdev.c +3
-0+ } + } +if (dev->conf.discard_granularity ==-1 ) { dev->conf.discard_granularity =512 ; } else if (dev->conf.discard_granularity &&@@ -257,7 +263,11 @@ static int ide_cd_initfn(IDEDevice *dev)
hw/ide/qdev.c static int ide_cd_initfn(IDEDevice *dev) · line 272
Quoted 10 lines
hw/ide/qdev.c +5
-1static int ide_drive_initfn (IDEDevice *dev) { -DriveInfo *dinfo =blk_legacy_dinfo (dev->conf.blk); +DriveInfo *dinfo =NULL ; + +if (dev->conf.blk) { + dinfo =blk_legacy_dinfo (dev->conf.blk); + }return ide_dev_initfn (dev, dinfo && dinfo->media_cd ?IDE_CD :IDE_HD );
...yet, this claims dev->conf.blk can be NULL. What am I missing?
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 2/2] scsi: scsi-cd without drive property for empty drive
In reply to Kevin WolfQuoted 1 line · Kevin Wolf
This allows to create an empty scsi-cd device without manually creating
Grammar might sound better as:
This allows the creation of an empty
or
This allows a user to create an empty
Quoted 12 lines
a BlockBackend.
Signed-off-by Kevin Wolf <[email protected]>--- hw/scsi/scsi-disk.c | 5 +++++ 1 file changed, 5 insertions(+)hw/scsi/scsi-disk.c +0
-0
hw/scsi/scsi-disk.c static void scsi_hd_realize(SCSIDevice *dev, Error **errp) · line 2366
Quoted 8 lines
hw/scsi/scsi-disk.c +5
-0@@ -2359,6 +2359,11 @@ static void scsi_hd_realize(SCSIDevice *dev, Error **errp)static void scsi_cd_realize (SCSIDevice *dev,Error **errp) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev); + +if (!dev->conf.blk) { + dev->conf.blk =blk_new (); + } +
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 1/2] ide: ide-cd without drive property for empty drive
In reply to Eric BlakeAm 14.07.2016 um 21:48 hat Eric Blake geschrieben:
Quoted 40 lines · Kevin Wolf
Quoted 9 lines
This allows to create an empty ide-cd device without manually creating a BlockBackend.
Signed-off-by Kevin Wolf <[email protected]>--- hw/ide/qdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)hw/ide/qdev.c static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) · line 163
Quoted 10 lines
hw/ide/qdev.c +7
-0@@ -158,6 +154,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)IDEState *s = bus->ifs + dev->unit;Error *err =NULL ; +if (!dev->conf.blk) { +if (kind !=IDE_CD ) { +error_report ("No drive specified" ); +return -1 ; + }else { +/* Anonymous BlockBackend for an empty drive */ + dev->conf.blk =blk_new ();So we either fail or
dev->conf.blkis set...Quoted 17 lines
hw/ide/qdev.c +8
-1+ } + } +if (dev->conf.discard_granularity ==-1 ) { dev->conf.discard_granularity =512 ; } else if (dev->conf.discard_granularity &&@@ -257,7 +263,11 @@ static int ide_cd_initfn(IDEDevice *dev)static int ide_drive_initfn (IDEDevice *dev) { -DriveInfo *dinfo =blk_legacy_dinfo (dev->conf.blk); +DriveInfo *dinfo =NULL ; + +if (dev->conf.blk) { + dinfo =blk_legacy_dinfo (dev->conf.blk); + }
Quoted 3 lines
hw/ide/qdev.c static int ide_cd_initfn(IDEDevice *dev) · line 272
Quoted 1 line
hw/ide/qdev.c +0
-0return ide_dev_initfn (dev, dinfo && dinfo->media_cd ?IDE_CD :IDE_HD );...yet, this claims
dev->conf.blkcan be NULL. What am I missing?
That ide_drive_initfn() is the outer function and runs first, before we handle the case in ide_dev_initfn()?
Kevin
Re: [Qemu-devel] [PATCH 1/2] ide: ide-cd without drive property for empty drive
Quoted 41 lines · Kevin Wolf
Am 14.07.2016 um 21:48 hat Eric Blake geschrieben:
Quoted 40 lines · Kevin Wolf
Quoted 9 lines
This allows to create an empty ide-cd device without manually creating a BlockBackend.
Signed-off-by Kevin Wolf <[email protected]>--- hw/ide/qdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)hw/ide/qdev.c static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) · line 163
Quoted 10 lines
hw/ide/qdev.c +7
-0@@ -158,6 +154,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)IDEState *s = bus->ifs + dev->unit;Error *err =NULL ; +if (!dev->conf.blk) { +if (kind !=IDE_CD ) { +error_report ("No drive specified" ); +return -1 ; + }else { +/* Anonymous BlockBackend for an empty drive */ + dev->conf.blk =blk_new ();So we either fail or
dev->conf.blkis set...Quoted 17 lines
hw/ide/qdev.c +8
-1+ } + } +if (dev->conf.discard_granularity ==-1 ) { dev->conf.discard_granularity =512 ; } else if (dev->conf.discard_granularity &&@@ -257,7 +263,11 @@ static int ide_cd_initfn(IDEDevice *dev)static int ide_drive_initfn (IDEDevice *dev) { -DriveInfo *dinfo =blk_legacy_dinfo (dev->conf.blk); +DriveInfo *dinfo =NULL ; + +if (dev->conf.blk) { + dinfo =blk_legacy_dinfo (dev->conf.blk); + }
Quoted 6 lines
Quoted 3 lines
hw/ide/qdev.c static int ide_cd_initfn(IDEDevice *dev) · line 272
Quoted 1 line
hw/ide/qdev.c +0
-0return ide_dev_initfn (dev, dinfo && dinfo->media_cd ?IDE_CD :IDE_HD );...yet, this claims
dev->conf.blkcan be NULL. What am I missing?That
ide_drive_initfn()is the outer function and runs first, before we handle the case inide_dev_initfn()?
Ah, I think I glazed over the difference between 'dev' and 'drive', and was thinking 'both of these are initfn, what's different?'. I think you are okay, after all.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Kevin Wolf
AppliedRe: [Qemu-devel] [PATCH 1/2] ide: ide-cd without drive property for empty drive
Am 04.08.2016 um 18:03 hat Eric Blake geschrieben:
Quoted 46 lines · Kevin Wolf
Quoted 45 lines
Am 14.07.2016 um 21:48 hat Eric Blake geschrieben:
Quoted 43 lines · Kevin Wolf
Quoted 9 lines
This allows to create an empty ide-cd device without manually creating a BlockBackend.
Signed-off-by Kevin Wolf <[email protected]>--- hw/ide/qdev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)hw/ide/qdev.c static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind) · line 163
Quoted 10 lines
hw/ide/qdev.c +7
-0@@ -158,6 +154,16 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)IDEState *s = bus->ifs + dev->unit;Error *err =NULL ; +if (!dev->conf.blk) { +if (kind !=IDE_CD ) { +error_report ("No drive specified" ); +return -1 ; + }else { +/* Anonymous BlockBackend for an empty drive */ + dev->conf.blk =blk_new ();So we either fail or
dev->conf.blkis set...Quoted 8 lines
hw/ide/qdev.c +3
-0+ } + } +if (dev->conf.discard_granularity ==-1 ) { dev->conf.discard_granularity =512 ; } else if (dev->conf.discard_granularity &&@@ -257,7 +263,11 @@ static int ide_cd_initfn(IDEDevice *dev)hw/ide/qdev.c static int ide_cd_initfn(IDEDevice *dev) · line 272
Quoted 10 lines
hw/ide/qdev.c +5
-1static int ide_drive_initfn (IDEDevice *dev) { -DriveInfo *dinfo =blk_legacy_dinfo (dev->conf.blk); +DriveInfo *dinfo =NULL ; + +if (dev->conf.blk) { + dinfo =blk_legacy_dinfo (dev->conf.blk); + }return ide_dev_initfn (dev, dinfo && dinfo->media_cd ?IDE_CD :IDE_HD );...yet, this claims
dev->conf.blkcan be NULL. What am I missing?
Quoted 6 lines
Quoted 2 lines
That
ide_drive_initfn()is the outer function and runs first, before we handle the case inide_dev_initfn()?Ah, I think I glazed over the difference between 'dev' and 'drive', and was thinking 'both of these are initfn, what's different?'. I think you are okay, after all.
I noted this down as an Acked-by for now. If you decide to give an actual R-b, I'll update that.
Applied the series to block-next.
Kevin