mirror of https://gitee.com/openkylin/qemu.git
block: Pass errp in blkconf_geometry
This allows us to pass error information to caller. Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
2656eb7c59
commit
5ff5efb46c
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
Loading…
Reference in New Issue