mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 10:13:56 -06:00
scsi-bus: Convert DeviceClass init to realize
Replace "init/destroy" with "realize/unrealize" in SCSIDeviceClass, which has errp as a parameter. So all the implementations now use error_setg instead of error_report for reporting error. Also in scsi_bus_legacy_handle_cmdline, report the error when initializing the if=scsi devices, before returning it, because in the callee, error_report is changed to error_setg. And the callers don't have the right locations (e.g. "-drive if=scsi"). 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
5ff5efb46c
commit
a818a4b69d
6 changed files with 95 additions and 97 deletions
|
@ -386,49 +386,49 @@ static void scsi_generic_reset(DeviceState *dev)
|
|||
scsi_device_purge_requests(s, SENSE_CODE(RESET));
|
||||
}
|
||||
|
||||
static void scsi_destroy(SCSIDevice *s)
|
||||
static void scsi_unrealize(SCSIDevice *s, Error **errp)
|
||||
{
|
||||
scsi_device_purge_requests(s, SENSE_CODE(NO_SENSE));
|
||||
blockdev_mark_auto_del(s->conf.bs);
|
||||
}
|
||||
|
||||
static int scsi_generic_initfn(SCSIDevice *s)
|
||||
static void scsi_generic_realize(SCSIDevice *s, Error **errp)
|
||||
{
|
||||
int rc;
|
||||
int sg_version;
|
||||
struct sg_scsi_id scsiid;
|
||||
|
||||
if (!s->conf.bs) {
|
||||
error_report("drive property not set");
|
||||
return -1;
|
||||
error_setg(errp, "drive property not set");
|
||||
return;
|
||||
}
|
||||
|
||||
if (bdrv_get_on_error(s->conf.bs, 0) != BLOCKDEV_ON_ERROR_ENOSPC) {
|
||||
error_report("Device doesn't support drive option werror");
|
||||
return -1;
|
||||
error_setg(errp, "Device doesn't support drive option werror");
|
||||
return;
|
||||
}
|
||||
if (bdrv_get_on_error(s->conf.bs, 1) != BLOCKDEV_ON_ERROR_REPORT) {
|
||||
error_report("Device doesn't support drive option rerror");
|
||||
return -1;
|
||||
error_setg(errp, "Device doesn't support drive option rerror");
|
||||
return;
|
||||
}
|
||||
|
||||
/* check we are using a driver managing SG_IO (version 3 and after */
|
||||
rc = bdrv_ioctl(s->conf.bs, SG_GET_VERSION_NUM, &sg_version);
|
||||
if (rc < 0) {
|
||||
error_report("cannot get SG_IO version number: %s. "
|
||||
"Is this a SCSI device?",
|
||||
strerror(-rc));
|
||||
return -1;
|
||||
error_setg(errp, "cannot get SG_IO version number: %s. "
|
||||
"Is this a SCSI device?",
|
||||
strerror(-rc));
|
||||
return;
|
||||
}
|
||||
if (sg_version < 30000) {
|
||||
error_report("scsi generic interface too old");
|
||||
return -1;
|
||||
error_setg(errp, "scsi generic interface too old");
|
||||
return;
|
||||
}
|
||||
|
||||
/* get LUN of the /dev/sg? */
|
||||
if (bdrv_ioctl(s->conf.bs, SG_GET_SCSI_ID, &scsiid)) {
|
||||
error_report("SG_GET_SCSI_ID ioctl failed");
|
||||
return -1;
|
||||
error_setg(errp, "SG_GET_SCSI_ID ioctl failed");
|
||||
return;
|
||||
}
|
||||
|
||||
/* define device state */
|
||||
|
@ -460,7 +460,6 @@ static int scsi_generic_initfn(SCSIDevice *s)
|
|||
}
|
||||
|
||||
DPRINTF("block size %d\n", s->blocksize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const SCSIReqOps scsi_generic_req_ops = {
|
||||
|
@ -501,8 +500,8 @@ static void scsi_generic_class_initfn(ObjectClass *klass, void *data)
|
|||
DeviceClass *dc = DEVICE_CLASS(klass);
|
||||
SCSIDeviceClass *sc = SCSI_DEVICE_CLASS(klass);
|
||||
|
||||
sc->init = scsi_generic_initfn;
|
||||
sc->destroy = scsi_destroy;
|
||||
sc->realize = scsi_generic_realize;
|
||||
sc->unrealize = scsi_unrealize;
|
||||
sc->alloc_req = scsi_new_request;
|
||||
sc->parse_cdb = scsi_generic_parse_cdb;
|
||||
dc->fw_name = "disk";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue