Rather than repeat multiple steps in order to find the SCSI
controller model, let's combine them into one helper that will
return either the model from the definition or the default
model based on the capabilities.
This patch adds an extra check/error that the controller
that's being found actually exists. This just clarifies that
the error was because the controller doesn't exist rather
than the more generic error that we were unable to determine
the model from qemuDomainSetSCSIControllerModel when a -1
was passed in and the capabilities were unable to find one.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/qemu/qemu_alias.c | 12 ++++--------
src/qemu/qemu_command.c | 17 +++++------------
src/qemu/qemu_domain_address.c | 31 +++++++++++++++++++++++++++++++
src/qemu/qemu_domain_address.h | 4 ++++
4 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index ed96f9f4c..ed3af04de 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -190,14 +190,10 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
- virDomainControllerDefPtr cont;
-
- cont = virDomainDeviceFindSCSIController(def, &disk->info);
- if (cont)
- controllerModel = cont->model;
-
- if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
- &controllerModel)) < 0)
+ controllerModel = qemuDomainFindSCSIControllerModel(def,
+ &disk->info,
+ qemuCaps);
+ if (controllerModel < 0)
return -1;
}
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 113a2919b..32ff385cf 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1957,7 +1957,6 @@ qemuBuildDriveDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
- virDomainControllerDefPtr cont;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
const char *contAlias;
char *drivealias;
@@ -2043,11 +2042,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
goto error;
}
- cont = virDomainDeviceFindSCSIController(def, &disk->info);
- if (cont)
- controllerModel = cont->model;
- if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
- &controllerModel)) < 0)
+ controllerModel = qemuDomainFindSCSIControllerModel(def, &disk->info,
+ qemuCaps);
+ if (controllerModel < 0)
goto error;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) {
@@ -5143,16 +5140,12 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- virDomainControllerDefPtr cont;
int model = -1;
char *driveAlias;
const char *contAlias;
- cont = virDomainDeviceFindSCSIController(def, dev->info);
- if (cont)
- model = cont->model;
-
- if (qemuDomainSetSCSIControllerModel(def, qemuCaps, &model) < 0)
+ model = qemuDomainFindSCSIControllerModel(def, dev->info, qemuCaps);
+ if (model < 0)
goto error;
if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 86fe7ad11..74f7df205 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -74,6 +74,37 @@ qemuDomainSetSCSIControllerModel(const virDomainDef *def,
}
+/**
+ * @def: Domain definition
+ * @info: Domain device info
+ * @qemuCaps: QEMU capabilities
+ *
+ * Using the device info, find the controller related to the
+ * device by index and use that controller to return the model.
+ *
+ * Returns the model if found, -1 if not with an error message set
+ */
+int
+qemuDomainFindSCSIControllerModel(const virDomainDef *def,
+ virDomainDeviceInfoPtr info,
+ virQEMUCapsPtr qemuCaps)
+{
+ virDomainControllerDefPtr cont;
+ int model;
+
+ if (!(cont = virDomainDeviceFindSCSIController(def, info))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unable to find a SCSI controller for idx=%d"),
+ info->addr.drive.controller);
+ return -1;
+ }
+
+ model = cont->model;
+ ignore_value(qemuDomainSetSCSIControllerModel(def, qemuCaps, &model));
+ return model;
+}
+
+
static int
qemuDomainAssignVirtioSerialAddresses(virDomainDefPtr def)
{
diff --git a/src/qemu/qemu_domain_address.h b/src/qemu/qemu_domain_address.h
index e951a4c88..8a4346892 100644
--- a/src/qemu/qemu_domain_address.h
+++ b/src/qemu/qemu_domain_address.h
@@ -32,6 +32,10 @@ int qemuDomainSetSCSIControllerModel(const virDomainDef *def,
virQEMUCapsPtr qemuCaps,
int *model);
+int qemuDomainFindSCSIControllerModel(const virDomainDef *def,
+ virDomainDeviceInfoPtr info,
+ virQEMUCapsPtr qemuCaps);
+
int qemuDomainAssignAddresses(virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
virQEMUDriverPtr driver,
--
2.13.6