From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Anthony Liguori" <aliguori@us.ibm.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Alexander Graf" <agraf@suse.de>,
"open list:sPAPR" <qemu-ppc@nongnu.org>,
"Paul Brook" <paul@codesourcery.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Andreas Färber" <afaerber@suse.de>,
"Gerd Hoffmann" <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH qom-next] scsi: Improve error propagation for scsi_bus_legacy_handle_cmdline()
Date: Sun, 21 Jul 2013 12:30:54 +0200 [thread overview]
Message-ID: <1374402654-23574-1-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <7da0c8dce11d32c300df10dade5e099b3aae7114.1372673778.git.hutao@cn.fujitsu.com>
Let scsi_bus_legacy_add_drive() and scsi_bus_legacy_handle_cmdline()
return an Error**. Prepare qdev initfns for QOM realize error model.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
hw/pci/pci-hotplug-old.c | 2 +-
hw/scsi/esp-pci.c | 7 ++++++-
hw/scsi/esp.c | 6 ++++--
hw/scsi/lsi53c895a.c | 7 ++++++-
hw/scsi/megasas.c | 7 ++++++-
hw/scsi/scsi-bus.c | 22 +++++++++++++++-------
hw/scsi/spapr_vscsi.c | 7 ++++++-
hw/scsi/virtio-scsi.c | 7 ++++++-
hw/usb/dev-storage.c | 4 +++-
include/hw/scsi/scsi.h | 4 ++--
10 files changed, 55 insertions(+), 18 deletions(-)
diff --git a/hw/pci/pci-hotplug-old.c b/hw/pci/pci-hotplug-old.c
index 8077289..619fe47 100644
--- a/hw/pci/pci-hotplug-old.c
+++ b/hw/pci/pci-hotplug-old.c
@@ -127,7 +127,7 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter,
dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1);
dinfo->bus = scsibus->busnr;
scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo->bdrv, dinfo->unit,
- false, -1, NULL);
+ false, -1, NULL, NULL);
if (!scsidev) {
return -1;
}
diff --git a/hw/scsi/esp-pci.c b/hw/scsi/esp-pci.c
index 6cdfd53..2ac21d4 100644
--- a/hw/scsi/esp-pci.c
+++ b/hw/scsi/esp-pci.c
@@ -346,6 +346,7 @@ static int esp_pci_scsi_init(PCIDevice *dev)
DeviceState *d = DEVICE(dev);
ESPState *s = &pci->esp;
uint8_t *pci_conf;
+ Error *err = NULL;
pci_conf = dev->config;
@@ -364,7 +365,11 @@ static int esp_pci_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, d, &esp_pci_scsi_info, NULL);
if (!d->hotplugged) {
- return scsi_bus_legacy_handle_cmdline(&s->bus);
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_free(err);
+ return -1;
+ }
}
return 0;
}
diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index c24b632..94639b8 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -676,6 +676,7 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
SysBusESPState *sysbus = ESP(dev);
ESPState *s = &sysbus->esp;
+ Error *err = NULL;
sysbus_init_irq(sbd, &s->irq);
assert(sysbus->it_shift != -1);
@@ -688,8 +689,9 @@ static void sysbus_esp_realize(DeviceState *dev, Error **errp)
qdev_init_gpio_in(dev, sysbus_esp_gpio_demux, 2);
scsi_bus_new(&s->bus, dev, &esp_scsi_info, NULL);
- if (scsi_bus_legacy_handle_cmdline(&s->bus) < 0) {
- error_setg(errp, "Handling legacy SCSI command line failed");
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
return;
}
}
diff --git a/hw/scsi/lsi53c895a.c b/hw/scsi/lsi53c895a.c
index e11224f..776e31a 100644
--- a/hw/scsi/lsi53c895a.c
+++ b/hw/scsi/lsi53c895a.c
@@ -2096,6 +2096,7 @@ static int lsi_scsi_init(PCIDevice *dev)
LSIState *s = LSI53C895A(dev);
DeviceState *d = DEVICE(dev);
uint8_t *pci_conf;
+ Error *err = NULL;
pci_conf = dev->config;
@@ -2118,7 +2119,11 @@ static int lsi_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, d, &lsi_scsi_info, NULL);
if (!d->hotplugged) {
- return scsi_bus_legacy_handle_cmdline(&s->bus);
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_free(err);
+ return -1;
+ }
}
return 0;
}
diff --git a/hw/scsi/megasas.c b/hw/scsi/megasas.c
index 2ae4346..eb52164 100644
--- a/hw/scsi/megasas.c
+++ b/hw/scsi/megasas.c
@@ -2102,6 +2102,7 @@ static int megasas_scsi_init(PCIDevice *dev)
MegasasState *s = MEGASAS(dev);
uint8_t *pci_conf;
int i, bar_type;
+ Error *err = NULL;
pci_conf = dev->config;
@@ -2172,7 +2173,11 @@ static int megasas_scsi_init(PCIDevice *dev)
scsi_bus_new(&s->bus, DEVICE(dev), &megasas_scsi_info, NULL);
if (!d->hotplugged) {
- return scsi_bus_legacy_handle_cmdline(&s->bus);
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_free(err);
+ return -1;
+ }
}
return 0;
}
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index a92b7c1..b5a863a 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -209,10 +209,11 @@ static int scsi_qdev_exit(DeviceState *qdev)
/* handle legacy '-drive if=scsi,...' cmd line args */
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
int unit, bool removable, int bootindex,
- const char *serial)
+ const char *serial, Error **errp)
{
const char *driver;
DeviceState *dev;
+ Error *err = NULL;
driver = bdrv_is_sg(bdrv) ? "scsi-generic" : "scsi-disk";
dev = qdev_create(&bus->qbus, driver);
@@ -227,19 +228,25 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
qdev_prop_set_string(dev, "serial", serial);
}
if (qdev_prop_set_drive(dev, "drive", bdrv) < 0) {
+ error_setg(errp, "Setting drive property failed");
qdev_free(dev);
return NULL;
}
- if (qdev_init(dev) < 0)
+ object_property_set_bool(OBJECT(dev), true, "realized", &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
+ qdev_free(dev);
return NULL;
+ }
return SCSI_DEVICE(dev);
}
-int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
+void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp)
{
Location loc;
DriveInfo *dinfo;
- int res = 0, unit;
+ int unit;
+ Error *err = NULL;
loc_push_none(&loc);
for (unit = 0; unit <= bus->info->max_target; unit++) {
@@ -248,13 +255,14 @@ int scsi_bus_legacy_handle_cmdline(SCSIBus *bus)
continue;
}
qemu_opts_loc_restore(dinfo->opts);
- if (!scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL)) {
- res = -1;
+ scsi_bus_legacy_add_drive(bus, dinfo->bdrv, unit, false, -1, NULL,
+ &err);
+ if (err != NULL) {
+ error_propagate(errp, err);
break;
}
}
loc_pop(&loc);
- return res;
}
static int32_t scsi_invalid_field(SCSIRequest *req, uint8_t *buf)
diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
index e8978bf..55b44b9 100644
--- a/hw/scsi/spapr_vscsi.c
+++ b/hw/scsi/spapr_vscsi.c
@@ -912,12 +912,17 @@ static void spapr_vscsi_reset(VIOsPAPRDevice *dev)
static int spapr_vscsi_init(VIOsPAPRDevice *dev)
{
VSCSIState *s = VIO_SPAPR_VSCSI_DEVICE(dev);
+ Error *err = NULL;
dev->crq.SendFunc = vscsi_do_crq;
scsi_bus_new(&s->bus, &dev->qdev, &vscsi_scsi_info, NULL);
if (!dev->qdev.hotplugged) {
- scsi_bus_legacy_handle_cmdline(&s->bus);
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_free(err);
+ return -1;
+ }
}
return 0;
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index 712f0ad..42cb73b 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -619,6 +619,7 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
VirtIOSCSICommon *vs = VIRTIO_SCSI_COMMON(vdev);
VirtIOSCSI *s = VIRTIO_SCSI(vdev);
static int virtio_scsi_id;
+ Error *err = NULL;
int ret;
ret = virtio_scsi_common_init(vs);
@@ -629,7 +630,11 @@ static int virtio_scsi_device_init(VirtIODevice *vdev)
scsi_bus_new(&s->bus, qdev, &virtio_scsi_scsi_info, vdev->bus_name);
if (!qdev->hotplugged) {
- scsi_bus_legacy_handle_cmdline(&s->bus);
+ scsi_bus_legacy_handle_cmdline(&s->bus, &err);
+ if (err != NULL) {
+ error_free(err);
+ return -1;
+ }
}
register_savevm(qdev, "virtio-scsi", virtio_scsi_id++, 1,
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index fe914ab..1954811 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -595,6 +595,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
MSDState *s = DO_UPCAST(MSDState, dev, dev);
BlockDriverState *bs = s->conf.bs;
SCSIDevice *scsi_dev;
+ Error *err = NULL;
if (!bs) {
error_report("drive property not set");
@@ -619,7 +620,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
usb_desc_init(dev);
scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL);
scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
- s->conf.bootindex, dev->serial);
+ s->conf.bootindex, dev->serial,
+ &err);
if (!scsi_dev) {
return -1;
}
diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h
index 9786e00..8786531 100644
--- a/include/hw/scsi/scsi.h
+++ b/include/hw/scsi/scsi.h
@@ -162,8 +162,8 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d)
SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockDriverState *bdrv,
int unit, bool removable, int bootindex,
- const char *serial);
-int scsi_bus_legacy_handle_cmdline(SCSIBus *bus);
+ const char *serial, Error **errp);
+void scsi_bus_legacy_handle_cmdline(SCSIBus *bus, Error **errp);
/*
* Predefined sense codes
--
1.8.1.4
next prev parent reply other threads:[~2013-07-21 10:31 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-01 10:18 [Qemu-devel] [PATCH v2 00/26] use realizefn for SysBusDevice, part 1 Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 01/26] sysbus: document SysBusDeviceClass about @init Hu Tao
2013-07-03 1:19 ` Andreas Färber
2013-07-03 1:24 ` Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 02/26] ohci: QOM'ify some more Hu Tao
2013-07-03 1:52 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 03/26] ohci: use realize for ohci Hu Tao
2013-07-07 15:22 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 04/26] i440fx-pcihost: use realize for i440fx-pcihost Hu Tao
2013-07-07 21:24 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 05/26] i440fx: use type-safe cast instead of directly access of parent dev Hu Tao
2013-07-07 17:03 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 06/26] q35: " Hu Tao
2013-07-07 23:05 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 07/26] q35: use realize for q35 host Hu Tao
2013-07-08 1:20 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 08/26] fdc: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 09/26] fdc: use realize for fdc Hu Tao
2013-07-21 9:27 ` Andreas Färber
2013-07-21 9:31 ` [Qemu-devel] [PATCH qom-next] fdc: Improve error propagation for QOM realize Andreas Färber
2013-07-22 7:38 ` Hu Tao
2013-07-22 8:26 ` Stefan Hajnoczi
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 10/26] pflash-cfi01: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 11/26] pflash_cfi01: use realize for pflash_cfi01 Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 12/26] pflash-cfi02: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 13/26] pflash_cfi02: use realize for pflash_cfi02 Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 14/26] ahci: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 15/26] ahci: use realize for ahci Hu Tao
2013-07-21 9:13 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 16/26] fwcfg: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 17/26] fwcfg: use realize for fwcfg Hu Tao
2013-07-21 9:35 ` Andreas Färber
2013-07-22 8:37 ` Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 18/26] scsi esp: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 19/26] scsi esp: use realize for scsi esp Hu Tao
2013-07-21 9:47 ` Andreas Färber
2013-07-21 10:30 ` Andreas Färber [this message]
2013-07-22 9:16 ` [Qemu-devel] [PATCH qom-next] scsi: Improve error propagation for scsi_bus_legacy_handle_cmdline() Hu Tao
2013-07-22 10:24 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 20/26] hpet: QOM'ify some more Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 21/26] hpet: use realize for hpet Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 22/26] kvmclock: QOM'ify some more Hu Tao
2013-07-16 14:00 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 23/26] kvmclock: use realize for kvmclock Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 24/26] kvmvapic realize Hu Tao
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 25/26] ioapic: use realize for ioapic Hu Tao
2013-07-21 10:35 ` Andreas Färber
2013-07-01 10:18 ` [Qemu-devel] [PATCH v2 26/26] isa bus: remove isabus_bridge_init since it does nothing Hu Tao
2013-07-21 10:58 ` [Qemu-devel] [PATCH v2 00/26] use realizefn for SysBusDevice, part 1 Andreas Färber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1374402654-23574-1-git-send-email-afaerber@suse.de \
--to=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=paul@codesourcery.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).