[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 1/8] block: Pass errp in blkconf_geometry
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 1/8] block: Pass errp in blkconf_geometry |
Date: |
Thu, 28 Aug 2014 16:13:18 +0200 |
From: Fam Zheng <address@hidden>
This allows us to pass error information to caller.
Reviewed-by: Andreas Färber <address@hidden>
Reviewed-by: Stefan Hajnoczi <address@hidden>
Signed-off-by: Fam Zheng <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/block/block.c | 18 +++++++++---------
hw/block/virtio-blk.c | 7 +++----
hw/ide/qdev.c | 11 ++++++++---
hw/scsi/scsi-disk.c | 11 ++++++++---
include/hw/block/block.h | 6 ++++--
5 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/hw/block/block.c b/hw/block/block.c
index 33dd3f3..b6a6dc6 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -22,8 +22,9 @@ void blkconf_serial(BlockConf *conf, char **serial)
}
}
-int blkconf_geometry(BlockConf *conf, int *ptrans,
- unsigned cyls_max, unsigned heads_max, unsigned secs_max)
+void blkconf_geometry(BlockConf *conf, int *ptrans,
+ unsigned cyls_max, unsigned heads_max, unsigned secs_max,
+ Error **errp)
{
DriveInfo *dinfo;
@@ -46,17 +47,16 @@ int blkconf_geometry(BlockConf *conf, int *ptrans,
}
if (conf->cyls || conf->heads || conf->secs) {
if (conf->cyls < 1 || conf->cyls > cyls_max) {
- error_report("cyls must be between 1 and %u", cyls_max);
- return -1;
+ error_setg(errp, "cyls must be between 1 and %u", cyls_max);
+ return;
}
if (conf->heads < 1 || conf->heads > heads_max) {
- error_report("heads must be between 1 and %u", heads_max);
- return -1;
+ error_setg(errp, "heads must be between 1 and %u", heads_max);
+ return;
}
if (conf->secs < 1 || conf->secs > secs_max) {
- error_report("secs must be between 1 and %u", secs_max);
- return -1;
+ error_setg(errp, "secs must be between 1 and %u", secs_max);
+ return;
}
}
- return 0;
}
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 302c39e..0b68a17 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -728,9 +728,7 @@ static void virtio_blk_device_realize(DeviceState *dev,
Error **errp)
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOBlock *s = VIRTIO_BLK(dev);
VirtIOBlkConf *blk = &(s->blk);
-#ifdef CONFIG_VIRTIO_BLK_DATA_PLANE
Error *err = NULL;
-#endif
static int virtio_blk_id;
if (!blk->conf.bs) {
@@ -744,8 +742,9 @@ static void virtio_blk_device_realize(DeviceState *dev,
Error **errp)
blkconf_serial(&blk->conf, &blk->serial);
s->original_wce = bdrv_enable_write_cache(blk->conf.bs);
- if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
- error_setg(errp, "Error setting geometry");
+ blkconf_geometry(&blk->conf, NULL, 65535, 255, 255, &err);
+ if (err) {
+ error_propagate(errp, err);
return;
}
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index 6e475e6..b4a4671 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -151,6 +151,7 @@ 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;
+ Error *err = NULL;
if (dev->conf.discard_granularity == -1) {
dev->conf.discard_granularity = 512;
@@ -161,9 +162,13 @@ static int ide_dev_initfn(IDEDevice *dev, IDEDriveKind
kind)
}
blkconf_serial(&dev->conf, &dev->serial);
- if (kind != IDE_CD
- && blkconf_geometry(&dev->conf, &dev->chs_trans, 65536, 16, 255) < 0) {
- return -1;
+ if (kind != IDE_CD) {
+ blkconf_geometry(&dev->conf, &dev->chs_trans, 65536, 16, 255, &err);
+ if (err) {
+ error_report("%s", error_get_pretty(err));
+ error_free(err);
+ return -1;
+ }
}
if (ide_init_drive(s, dev->conf.bs, kind,
diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
index d55521d..b7ebdd7 100644
--- a/hw/scsi/scsi-disk.c
+++ b/hw/scsi/scsi-disk.c
@@ -2237,6 +2237,7 @@ static void scsi_disk_unit_attention_reported(SCSIDevice
*dev)
static int scsi_initfn(SCSIDevice *dev)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
+ Error *err = NULL;
if (!s->qdev.conf.bs) {
error_report("drive property not set");
@@ -2250,9 +2251,13 @@ static int scsi_initfn(SCSIDevice *dev)
}
blkconf_serial(&s->qdev.conf, &s->serial);
- if (dev->type == TYPE_DISK
- && blkconf_geometry(&dev->conf, NULL, 65535, 255, 255) < 0) {
- return -1;
+ if (dev->type == TYPE_DISK) {
+ blkconf_geometry(&dev->conf, NULL, 65535, 255, 255, &err);
+ if (err) {
+ error_report("%s", error_get_pretty(err));
+ error_free(err);
+ return -1;
+ }
}
if (s->qdev.conf.discard_granularity == -1) {
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
index 7c3d6c8..3a01488 100644
--- a/include/hw/block/block.h
+++ b/include/hw/block/block.h
@@ -12,6 +12,7 @@
#define HW_BLOCK_COMMON_H
#include "qemu-common.h"
+#include "qapi/error.h"
/* Configuration */
@@ -60,8 +61,9 @@ static inline unsigned int get_physical_block_exp(BlockConf
*conf)
/* Configuration helpers */
void blkconf_serial(BlockConf *conf, char **serial);
-int blkconf_geometry(BlockConf *conf, int *trans,
- unsigned cyls_max, unsigned heads_max, unsigned secs_max);
+void blkconf_geometry(BlockConf *conf, int *trans,
+ unsigned cyls_max, unsigned heads_max, unsigned secs_max,
+ Error **errp);
/* Hard disk geometry */
--
1.8.3.1
- [Qemu-devel] [PULL 0/8] SCSI and memory changes for 2014-08-28, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 3/8] block/iscsi: fix memory corruption on iscsi resize, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 1/8] block: Pass errp in blkconf_geometry,
Paolo Bonzini <=
- [Qemu-devel] [PULL 4/8] scsi-generic: remove superfluous DPRINTF avoid to break compiling, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 6/8] xen-hvm: Constify string, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 2/8] scsi-bus: Convert DeviceClass init to realize, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 7/8] xen: hvm: Abstract away memory region name ref, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 5/8] virtio-scsi: Report error if num_queues is 0 or too large, Paolo Bonzini, 2014/08/28
- [Qemu-devel] [PULL 8/8] memory: Lazy init name from QOM name as needed, Paolo Bonzini, 2014/08/28
- Re: [Qemu-devel] [PULL 0/8] SCSI and memory changes for 2014-08-28, Peter Maydell, 2014/08/28