From: John Snow <jsnow@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jsnow@redhat.com,
Mao Zhongyi <maozy.fnst@cn.fujitsu.com>,
Markus Armbruster <armbru@redhat.com>,
Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
Subject: [Qemu-devel] [PULL 12/13] hw/ide: Convert DeviceClass init to realize
Date: Mon, 18 Sep 2017 20:11:46 -0400 [thread overview]
Message-ID: <20170919001147.23182-14-jsnow@redhat.com> (raw)
In-Reply-To: <20170919001147.23182-1-jsnow@redhat.com>
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Replace init with realize in IDEDeviceClass, which has errp
as a parameter. So all the implementations now use error_setg
instead of error_report for reporting error.
Cc: John Snow <jsnow@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Max Reitz <mreitz@redhat.com>
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: c4d27b4b5d9e37468e63e35214ce4833ca271542.1505737465.git.maozy.fnst@cn.fujitsu.com
Signed-off-by: John Snow <jsnow@redhat.com>
---
hw/ide/core.c | 7 ++--
hw/ide/qdev.c | 86 +++++++++++++++++++++----------------------
include/hw/ide/internal.h | 5 ++-
tests/qemu-iotests/051.pc.out | 10 +----
4 files changed, 51 insertions(+), 57 deletions(-)
diff --git a/hw/ide/core.c b/hw/ide/core.c
index b71ee4f..a19bd90 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -34,6 +34,7 @@
#include "hw/block/block.h"
#include "sysemu/block-backend.h"
#include "qemu/cutils.h"
+#include "qemu/error-report.h"
#include "hw/ide/internal.h"
#include "trace.h"
@@ -2461,7 +2462,7 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
const char *version, const char *serial, const char *model,
uint64_t wwn,
uint32_t cylinders, uint32_t heads, uint32_t secs,
- int chs_trans)
+ int chs_trans, Error **errp)
{
uint64_t nb_sectors;
@@ -2486,11 +2487,11 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
blk_set_guest_block_size(blk, 2048);
} else {
if (!blk_is_inserted(s->blk)) {
- error_report("Device needs media, but drive is empty");
+ error_setg(errp, "Device needs media, but drive is empty");
return -1;
}
if (blk_is_read_only(blk)) {
- error_report("Can't use a read-only drive");
+ error_setg(errp, "Can't use a read-only drive");
return -1;
}
blk_set_dev_ops(blk, &ide_hd_block_ops, s);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index cc2f5bd..d60ac25 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -80,7 +80,7 @@ static char *idebus_get_fw_dev_path(DeviceState *dev)
return g_strdup(path);
}
-static int ide_qdev_init(DeviceState *qdev)
+static void ide_qdev_realize(DeviceState *qdev, Error **errp)
{
IDEDevice *dev = IDE_DEVICE(qdev);
IDEDeviceClass *dc = IDE_DEVICE_GET_CLASS(dev);
@@ -91,34 +91,31 @@ static int ide_qdev_init(DeviceState *qdev)
}
if (dev->unit >= bus->max_units) {
- error_report("Can't create IDE unit %d, bus supports only %d units",
+ error_setg(errp, "Can't create IDE unit %d, bus supports only %d units",
dev->unit, bus->max_units);
- goto err;
+ return;
}
switch (dev->unit) {
case 0:
if (bus->master) {
- error_report("IDE unit %d is in use", dev->unit);
- goto err;
+ error_setg(errp, "IDE unit %d is in use", dev->unit);
+ return;
}
bus->master = dev;
break;
case 1:
if (bus->slave) {
- error_report("IDE unit %d is in use", dev->unit);
- goto err;
+ error_setg(errp, "IDE unit %d is in use", dev->unit);
+ return;
}
bus->slave = dev;
break;
default:
- error_report("Invalid IDE unit %d", dev->unit);
- goto err;
+ error_setg(errp, "Invalid IDE unit %d", dev->unit);
+ return;
}
- return dc->init(dev);
-
-err:
- return -1;
+ dc->realize(dev, errp);
}
IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive)
@@ -159,7 +156,7 @@ typedef struct IDEDrive {
IDEDevice dev;
} IDEDrive;
-static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
+static void ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind, Error **errp)
{
IDEBus *bus = DO_UPCAST(IDEBus, qbus, dev->qdev.parent_bus);
IDEState *s = bus->ifs + dev->unit;
@@ -168,8 +165,8 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
if (!dev->conf.blk) {
if (kind != IDE_CD) {
- error_report("No drive specified");
- return -1;
+ error_setg(errp, "No drive specified");
+ return;
} else {
/* Anonymous BlockBackend for an empty drive */
dev->conf.blk = blk_new(0, BLK_PERM_ALL);
@@ -182,36 +179,36 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
dev->conf.discard_granularity = 512;
} else if (dev->conf.discard_granularity &&
dev->conf.discard_granularity != 512) {
- error_report("discard_granularity must be 512 for ide");
- return -1;
+ error_setg(errp, "discard_granularity must be 512 for ide");
+ return;
}
blkconf_blocksizes(&dev->conf);
if (dev->conf.logical_block_size != 512) {
- error_report("logical_block_size must be 512 for IDE");
- return -1;
+ error_setg(errp, "logical_block_size must be 512 for IDE");
+ return;
}
blkconf_serial(&dev->conf, &dev->serial);
if (kind != IDE_CD) {
blkconf_geometry(&dev->conf, &dev->chs_trans, 65535, 16, 255, &err);
if (err) {
- error_report_err(err);
- return -1;
+ error_propagate(errp, err);
+ return;
}
}
blkconf_apply_backend_options(&dev->conf, kind == IDE_CD, kind != IDE_CD,
&err);
if (err) {
- error_report_err(err);
- return -1;
+ error_propagate(errp, err);
+ return;
}
if (ide_init_drive(s, dev->conf.blk, kind,
dev->version, dev->serial, dev->model, dev->wwn,
dev->conf.cyls, dev->conf.heads, dev->conf.secs,
- dev->chs_trans) < 0) {
- return -1;
+ dev->chs_trans, errp) < 0) {
+ return;
}
if (!dev->version) {
@@ -223,8 +220,6 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind kind)
add_boot_device_path(dev->conf.bootindex, &dev->qdev,
dev->unit ? "/disk@1" : "/disk@0");
-
- return 0;
}
static void ide_dev_get_bootindex(Object *obj, Visitor *v, const char *name,
@@ -270,17 +265,17 @@ static void ide_dev_instance_init(Object *obj)
object_property_set_int(obj, -1, "bootindex", NULL);
}
-static int ide_hd_initfn(IDEDevice *dev)
+static void ide_hd_realize(IDEDevice *dev, Error **errp)
{
- return ide_dev_initfn(dev, IDE_HD);
+ ide_dev_initfn(dev, IDE_HD, errp);
}
-static int ide_cd_initfn(IDEDevice *dev)
+static void ide_cd_realize(IDEDevice *dev, Error **errp)
{
- return ide_dev_initfn(dev, IDE_CD);
+ ide_dev_initfn(dev, IDE_CD, errp);
}
-static int ide_drive_initfn(IDEDevice *dev)
+static void ide_drive_realize(IDEDevice *dev, Error **errp)
{
DriveInfo *dinfo = NULL;
@@ -288,7 +283,7 @@ static int ide_drive_initfn(IDEDevice *dev)
dinfo = blk_legacy_dinfo(dev->conf.blk);
}
- return ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD);
+ ide_dev_initfn(dev, dinfo && dinfo->media_cd ? IDE_CD : IDE_HD, errp);
}
#define DEFINE_IDE_DEV_PROPERTIES() \
@@ -311,10 +306,11 @@ static void ide_hd_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
- k->init = ide_hd_initfn;
+
+ k->realize = ide_hd_realize;
dc->fw_name = "drive";
- dc->desc = "virtual IDE disk";
- dc->props = ide_hd_properties;
+ dc->desc = "virtual IDE disk";
+ dc->props = ide_hd_properties;
}
static const TypeInfo ide_hd_info = {
@@ -333,10 +329,11 @@ static void ide_cd_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
- k->init = ide_cd_initfn;
+
+ k->realize = ide_cd_realize;
dc->fw_name = "drive";
- dc->desc = "virtual IDE CD-ROM";
- dc->props = ide_cd_properties;
+ dc->desc = "virtual IDE CD-ROM";
+ dc->props = ide_cd_properties;
}
static const TypeInfo ide_cd_info = {
@@ -355,10 +352,11 @@ static void ide_drive_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
IDEDeviceClass *k = IDE_DEVICE_CLASS(klass);
- k->init = ide_drive_initfn;
+
+ k->realize = ide_drive_realize;
dc->fw_name = "drive";
- dc->desc = "virtual IDE disk or CD-ROM (legacy)";
- dc->props = ide_drive_properties;
+ dc->desc = "virtual IDE disk or CD-ROM (legacy)";
+ dc->props = ide_drive_properties;
}
static const TypeInfo ide_drive_info = {
@@ -371,7 +369,7 @@ static const TypeInfo ide_drive_info = {
static void ide_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->init = ide_qdev_init;
+ k->realize = ide_qdev_realize;
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
k->bus_type = TYPE_IDE_BUS;
k->props = ide_props;
diff --git a/include/hw/ide/internal.h b/include/hw/ide/internal.h
index 5b30d7a..7dd0db4 100644
--- a/include/hw/ide/internal.h
+++ b/include/hw/ide/internal.h
@@ -12,6 +12,7 @@
#include "sysemu/sysemu.h"
#include "hw/block/block.h"
#include "block/scsi.h"
+#include "qapi/error.h"
/* debug IDE devices */
#define USE_DMA_CDROM
@@ -496,7 +497,7 @@ struct IDEBus {
typedef struct IDEDeviceClass {
DeviceClass parent_class;
- int (*init)(IDEDevice *dev);
+ void (*realize)(IDEDevice *dev, Error **errp);
} IDEDeviceClass;
struct IDEDevice {
@@ -606,7 +607,7 @@ int ide_init_drive(IDEState *s, BlockBackend *blk, IDEDriveKind kind,
const char *version, const char *serial, const char *model,
uint64_t wwn,
uint32_t cylinders, uint32_t heads, uint32_t secs,
- int chs_trans);
+ int chs_trans, Error **errp);
void ide_init2(IDEBus *bus, qemu_irq irq);
void ide_exit(IDEState *s);
void ide_init_ioport(IDEBus *bus, ISADevice *isa, int iobase, int iobase2);
diff --git a/tests/qemu-iotests/051.pc.out b/tests/qemu-iotests/051.pc.out
index 76d7205..762fb9f 100644
--- a/tests/qemu-iotests/051.pc.out
+++ b/tests/qemu-iotests/051.pc.out
@@ -123,8 +123,7 @@ quit
Testing: -drive if=ide
QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) QEMU_PROG: Device needs media, but drive is empty
-QEMU_PROG: Initialization of device ide-hd failed: Device initialization failed.
+(qemu) QEMU_PROG: Initialization of device ide-hd failed: Device needs media, but drive is empty
Testing: -drive if=scsi
QEMU X.Y.Z monitor - type 'help' for more information
@@ -146,12 +145,10 @@ QEMU X.Y.Z monitor - type 'help' for more information
Testing: -drive if=none,id=disk -device ide-drive,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device ide-drive,drive=disk: Device needs media, but drive is empty
-QEMU_PROG: -device ide-drive,drive=disk: Device initialization failed.
Testing: -drive if=none,id=disk -device ide-hd,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device ide-hd,drive=disk: Device needs media, but drive is empty
-QEMU_PROG: -device ide-hd,drive=disk: Device initialization failed.
Testing: -drive if=none,id=disk -device lsi53c895a -device scsi-disk,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
@@ -179,8 +176,7 @@ quit
Testing: -drive file=TEST_DIR/t.qcow2,if=ide,readonly=on
QEMU X.Y.Z monitor - type 'help' for more information
-(qemu) QEMU_PROG: Block node is read-only
-QEMU_PROG: Initialization of device ide-hd failed: Device initialization failed.
+(qemu) QEMU_PROG: Initialization of device ide-hd failed: Block node is read-only
Testing: -drive file=TEST_DIR/t.qcow2,if=scsi,readonly=on
QEMU X.Y.Z monitor - type 'help' for more information
@@ -202,12 +198,10 @@ QEMU X.Y.Z monitor - type 'help' for more information
Testing: -drive file=TEST_DIR/t.qcow2,if=none,id=disk,readonly=on -device ide-drive,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device ide-drive,drive=disk: Block node is read-only
-QEMU_PROG: -device ide-drive,drive=disk: Device initialization failed.
Testing: -drive file=TEST_DIR/t.qcow2,if=none,id=disk,readonly=on -device ide-hd,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
(qemu) QEMU_PROG: -device ide-hd,drive=disk: Block node is read-only
-QEMU_PROG: -device ide-hd,drive=disk: Device initialization failed.
Testing: -drive file=TEST_DIR/t.qcow2,if=none,id=disk,readonly=on -device lsi53c895a -device scsi-disk,drive=disk
QEMU X.Y.Z monitor - type 'help' for more information
--
2.9.5
next prev parent reply other threads:[~2017-09-19 0:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-19 0:11 [Qemu-devel] [PULL 13/13] hw/block/fdc: Convert to realize John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 00/13] Ide patches John Snow
2017-09-19 10:04 ` Peter Maydell
2017-09-19 0:11 ` [Qemu-devel] [PULL 01/13] ide: ahci: unparent children buses before freeing their memory John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 02/13] hw/ide/microdrive: Mark the dscm1xxxx device with user_creatable = false John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 03/13] IDE: replace DEBUG_IDE with tracing system John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 04/13] IDE: Add register hints to tracing John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 05/13] IDE: add tracing for data ports John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 06/13] ATAPI: Replace DEBUG_IDE_ATAPI with tracing events John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 07/13] IDE: replace DEBUG_AIO with trace events John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 08/13] AHCI: Replace DPRINTF with trace-events John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 09/13] AHCI: Rework IRQ constants John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 10/13] AHCI: pretty-print FIS to buffer instead of stderr John Snow
2017-09-19 0:11 ` [Qemu-devel] [PULL 11/13] AHCI: remove DPRINTF macro John Snow
2017-09-19 0:11 ` John Snow [this message]
2017-09-19 0:11 ` [Qemu-devel] [PULL 13/13] hw/block/fdc: Convert to realize John Snow
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=20170919001147.23182-14-jsnow@redhat.com \
--to=jsnow@redhat.com \
--cc=armbru@redhat.com \
--cc=kwolf@redhat.com \
--cc=maozy.fnst@cn.fujitsu.com \
--cc=mreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@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).