[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 2/6] hw/block/fdc: Convert to realize
From: |
Mao Zhongyi |
Subject: |
[Qemu-block] [PATCH 2/6] hw/block/fdc: Convert to realize |
Date: |
Wed, 26 Jul 2017 20:02:51 +0800 |
Convert floppy_drive_init() to realize and rename it to
floppy_drive_realize().
Cc: John Snow <address@hidden>
Cc: Kevin Wolf <address@hidden>
Cc: Max Reitz <address@hidden>
Cc: Markus Armbruster <address@hidden>
Signed-off-by: Mao Zhongyi <address@hidden>
---
hw/block/fdc.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 4011290..02f4a46 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -517,7 +517,7 @@ static Property floppy_drive_properties[] = {
DEFINE_PROP_END_OF_LIST(),
};
-static int floppy_drive_init(DeviceState *qdev)
+static void floppy_drive_realize(DeviceState *qdev, Error **errp)
{
FloppyDrive *dev = FLOPPY_DRIVE(qdev);
FloppyBus *bus = FLOPPY_BUS(qdev->parent_bus);
@@ -535,15 +535,15 @@ static int floppy_drive_init(DeviceState *qdev)
}
if (dev->unit >= MAX_FD) {
- error_report("Can't create floppy unit %d, bus supports only %d units",
- dev->unit, MAX_FD);
- return -1;
+ error_setg(errp, "Can't create floppy unit %d, bus supports "
+ "only %d units", dev->unit, MAX_FD);
+ return;
}
drive = get_drv(bus->fdc, dev->unit);
if (drive->blk) {
- error_report("Floppy unit %d is in use", dev->unit);
- return -1;
+ error_setg(errp, "Floppy unit %d is in use", dev->unit);
+ return;
}
if (!dev->conf.blk) {
@@ -557,8 +557,9 @@ static int floppy_drive_init(DeviceState *qdev)
if (dev->conf.logical_block_size != 512 ||
dev->conf.physical_block_size != 512)
{
- error_report("Physical and logical block size must be 512 for floppy");
- return -1;
+ error_setg(errp, "Physical and logical block size must "
+ "be 512 for floppy");
+ return;
}
/* rerror/werror aren't supported by fdc and therefore not even registered
@@ -570,20 +571,20 @@ static int floppy_drive_init(DeviceState *qdev)
blkconf_apply_backend_options(&dev->conf, blk_is_read_only(dev->conf.blk),
false, &local_err);
if (local_err) {
- error_report_err(local_err);
- return -1;
+ error_propagate(errp, local_err);
+ return;
}
/* 'enospc' is the default for -drive, 'report' is what blk_new() gives us
* for empty drives. */
if (blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_ENOSPC &&
blk_get_on_error(dev->conf.blk, 0) != BLOCKDEV_ON_ERROR_REPORT) {
- error_report("fdc doesn't support drive option werror");
- return -1;
+ error_setg(errp, "fdc doesn't support drive option werror");
+ return;
}
if (blk_get_on_error(dev->conf.blk, 1) != BLOCKDEV_ON_ERROR_REPORT) {
- error_report("fdc doesn't support drive option rerror");
- return -1;
+ error_setg(errp, "fdc doesn't support drive option rerror");
+ return;
}
drive->conf = &dev->conf;
@@ -599,14 +600,12 @@ static int floppy_drive_init(DeviceState *qdev)
dev->type = drive->drive;
fd_revalidate(drive);
-
- return 0;
}
static void floppy_drive_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
- k->init = floppy_drive_init;
+ k->realize = floppy_drive_realize;
set_bit(DEVICE_CATEGORY_STORAGE, k->categories);
k->bus_type = TYPE_FLOPPY_BUS;
k->props = floppy_drive_properties;
--
2.9.4
- [Qemu-block] [PATCH 0/6] Convert to realize and improve error handling, Mao Zhongyi, 2017/07/26
- [Qemu-block] [PATCH 3/6] hw/block/nvme: Convert to realize, Mao Zhongyi, 2017/07/26
- [Qemu-block] [PATCH 6/6] dev-storage: Fix the unusual function name, Mao Zhongyi, 2017/07/26
- [Qemu-block] [PATCH 5/6] hw/block: Use errp directly rather than local_err, Mao Zhongyi, 2017/07/26
- [Qemu-block] [PATCH 2/6] hw/block/fdc: Convert to realize,
Mao Zhongyi <=
- [Qemu-block] [PATCH 1/6] hw/ide: Convert DeviceClass init to realize, Mao Zhongyi, 2017/07/26
- [Qemu-block] [PATCH 4/6] hw/block: Fix the return type, Mao Zhongyi, 2017/07/26