From fadfb4f9b3951b8af7fd6e541ac6ceb120caa2c3 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 30 Jan 2018 12:06:36 -0500 Subject: [PATCH] qemu: Introduce qemuDomainGetSCSIControllerModel Rename and rework qemuDomainSetSCSIControllerModel since we're really not setting the SCSI controller model. Instead the code is either returning the existing SCSI controller model value, the default value based on the capabilities, or -1 with the error set. --- src/qemu/qemu_command.c | 3 ++- src/qemu/qemu_domain_address.c | 49 +++++++++++++++------------------- src/qemu/qemu_domain_address.h | 6 ++--- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 32ff385cf6..1142f302a8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2723,7 +2723,8 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef, *devstr = NULL; if (def->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { - if ((qemuDomainSetSCSIControllerModel(domainDef, qemuCaps, &model)) < 0) + model = qemuDomainGetSCSIControllerModel(domainDef, def, qemuCaps); + if (model < 0) return -1; if (!qemuBuildCheckSCSIControllerModel(qemuCaps, model)) diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 74f7df205c..5211b4f8a9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -42,35 +42,33 @@ VIR_LOG_INIT("qemu.qemu_domain_address"); /** * @def: Domain definition + * @cont: Domain controller def * @qemuCaps: qemu capabilities - * @model: model to either return or adjust * - * If the @model is already defined, return it immediately; otherwise, - * based on the @qemuCaps set the @model value to the default value. + * If the controller model is already defined, return it immediately; + * otherwise, based on the @qemuCaps return a default model value. * - * Returns @model on success, -1 on failure with error set. + * Returns model on success, -1 on failure with error set. */ int -qemuDomainSetSCSIControllerModel(const virDomainDef *def, - virQEMUCapsPtr qemuCaps, - int *model) +qemuDomainGetSCSIControllerModel(const virDomainDef *def, + const virDomainControllerDef *cont, + virQEMUCapsPtr qemuCaps) { - if (*model > 0) - return 0; + if (cont->model > 0) + return cont->model; - if (qemuDomainIsPSeries(def)) { - *model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI; - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_LSI)) { - *model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC; - } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_SCSI)) { - *model = VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to determine model for scsi controller")); - return -1; - } + if (qemuDomainIsPSeries(def)) + return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_LSI)) + return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC; + else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_SCSI)) + return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI; - return 0; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unable to determine model for SCSI controller idx=%d"), + cont->idx); + return -1; } @@ -90,7 +88,6 @@ qemuDomainFindSCSIControllerModel(const virDomainDef *def, virQEMUCapsPtr qemuCaps) { virDomainControllerDefPtr cont; - int model; if (!(cont = virDomainDeviceFindSCSIController(def, info))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -99,9 +96,7 @@ qemuDomainFindSCSIControllerModel(const virDomainDef *def, return -1; } - model = cont->model; - ignore_value(qemuDomainSetSCSIControllerModel(def, qemuCaps, &model)); - return model; + return qemuDomainGetSCSIControllerModel(def, cont, qemuCaps); } @@ -227,9 +222,9 @@ qemuDomainAssignSpaprVIOAddresses(virDomainDefPtr def, for (i = 0; i < def->ncontrollers; i++) { virDomainControllerDefPtr cont = def->controllers[i]; - model = cont->model; if (cont->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { - if (qemuDomainSetSCSIControllerModel(def, qemuCaps, &model) < 0) + model = qemuDomainGetSCSIControllerModel(def, cont, qemuCaps); + if (model < 0) goto cleanup; } diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h index 8a43468927..209b59e0d6 100644 --- a/src/qemu/qemu_domain_address.h +++ b/src/qemu/qemu_domain_address.h @@ -28,9 +28,9 @@ # include "qemu_conf.h" # include "qemu_capabilities.h" -int qemuDomainSetSCSIControllerModel(const virDomainDef *def, - virQEMUCapsPtr qemuCaps, - int *model); +int qemuDomainGetSCSIControllerModel(const virDomainDef *def, + const virDomainControllerDef *cont, + virQEMUCapsPtr qemuCaps); int qemuDomainFindSCSIControllerModel(const virDomainDef *def, virDomainDeviceInfoPtr info,