As it turns out virDomainDeviceFindControllerModel was only ever
called for SCSI controllers using VIR_DOMAIN_CONTROLLER_TYPE_SCSI
as a parameter.
So rename to virDomainDeviceFindSCSIController and rather than
return a model, let's return a virDomainControllerDefPtr to let
the caller reference whatever it wants.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 24 +++++++++++-------------
src/conf/domain_conf.h | 6 +++---
src/libvirt_private.syms | 2 +-
src/qemu/qemu_alias.c | 8 +++++---
src/qemu/qemu_command.c | 13 ++++++++-----
src/vbox/vbox_common.c | 8 ++++----
6 files changed, 32 insertions(+), 29 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9c9e3334f..b39667952 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7821,21 +7821,20 @@ virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
return ret;
}
-int
-virDomainDeviceFindControllerModel(const virDomainDef *def,
- virDomainDeviceInfoPtr info,
- int controllerType)
+
+virDomainControllerDefPtr
+virDomainDeviceFindSCSIController(const virDomainDef *def,
+ virDomainDeviceInfoPtr info)
{
- int model = -1;
size_t i;
for (i = 0; i < def->ncontrollers; i++) {
- if (def->controllers[i]->type == controllerType &&
+ if (def->controllers[i]->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI
&&
def->controllers[i]->idx == info->addr.drive.controller)
- model = def->controllers[i]->model;
+ return def->controllers[i];
}
- return model;
+ return NULL;
}
virDomainDiskDefPtr
@@ -17804,17 +17803,16 @@ virDomainDefMaybeAddHostdevSCSIcontroller(virDomainDefPtr def)
hostdev = def->hostdevs[i];
if (virHostdevIsSCSIDevice(hostdev) &&
(int)hostdev->info->addr.drive.controller > maxController) {
- int model = -1;
+ virDomainControllerDefPtr cont;
maxController = hostdev->info->addr.drive.controller;
/* We may be creating a new controller because this one is full.
* So let's grab the model from it and update the model we're
* going to add as long as this one isn't undefined. The premise
* being keeping the same controller model for all SCSI hostdevs. */
- model = virDomainDeviceFindControllerModel(def, hostdev->info,
- VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
- if (model != -1)
- newModel = model;
+ cont = virDomainDeviceFindSCSIController(def, hostdev->info);
+ if (cont && cont->model != -1)
+ newModel = cont->model;
}
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ed8526092..21e004515 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2759,9 +2759,9 @@ int virDomainDiskSetDriver(virDomainDiskDefPtr def, const char
*name)
ATTRIBUTE_RETURN_CHECK;
int virDomainDiskGetFormat(virDomainDiskDefPtr def);
void virDomainDiskSetFormat(virDomainDiskDefPtr def, int format);
-int virDomainDeviceFindControllerModel(const virDomainDef *def,
- virDomainDeviceInfoPtr info,
- int controllerType);
+virDomainControllerDefPtr
+virDomainDeviceFindSCSIController(const virDomainDef *def,
+ virDomainDeviceInfoPtr info);
virDomainDiskDefPtr virDomainDiskFindByBusAndDst(virDomainDefPtr def,
int bus,
char *dst);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 792fb6056..68a1f496e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -298,7 +298,7 @@ virDomainDeviceAliasIsUserAlias;
virDomainDeviceDefCopy;
virDomainDeviceDefFree;
virDomainDeviceDefParse;
-virDomainDeviceFindControllerModel;
+virDomainDeviceFindSCSIController;
virDomainDeviceGetInfo;
virDomainDeviceInfoIterate;
virDomainDeviceTypeToString;
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 37fe2aa80..ed96f9f4c 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -190,9 +190,11 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def,
if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
- controllerModel =
- virDomainDeviceFindControllerModel(def, &disk->info,
- VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+ virDomainControllerDefPtr cont;
+
+ cont = virDomainDeviceFindSCSIController(def, &disk->info);
+ if (cont)
+ controllerModel = cont->model;
if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
&controllerModel)) < 0)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c66307ee0..113a2919b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1957,6 +1957,7 @@ qemuBuildDriveDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer opt = VIR_BUFFER_INITIALIZER;
+ virDomainControllerDefPtr cont;
const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus);
const char *contAlias;
char *drivealias;
@@ -2042,9 +2043,9 @@ qemuBuildDriveDevStr(const virDomainDef *def,
goto error;
}
- controllerModel =
- virDomainDeviceFindControllerModel(def, &disk->info,
- VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+ cont = virDomainDeviceFindSCSIController(def, &disk->info);
+ if (cont)
+ controllerModel = cont->model;
if ((qemuDomainSetSCSIControllerModel(def, qemuCaps,
&controllerModel)) < 0)
goto error;
@@ -5142,12 +5143,14 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def,
virQEMUCapsPtr qemuCaps)
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
+ virDomainControllerDefPtr cont;
int model = -1;
char *driveAlias;
const char *contAlias;
- model = virDomainDeviceFindControllerModel(def, dev->info,
- VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
+ cont = virDomainDeviceFindSCSIController(def, dev->info);
+ if (cont)
+ model = cont->model;
if (qemuDomainSetSCSIControllerModel(def, qemuCaps, &model) < 0)
goto error;
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 33aefabe5..6704772e6 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1047,10 +1047,11 @@ static int
vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
{
size_t i;
- int type, ret = 0, model = -1;
+ int type, ret = 0;
const char *src = NULL;
nsresult rc = 0;
virDomainDiskDefPtr disk = NULL;
+ virDomainControllerDefPtr cont;
PRUnichar *storageCtlName = NULL;
char *controllerName = NULL;
IMedium *medium = NULL;
@@ -1126,9 +1127,8 @@ vboxAttachDrives(virDomainDefPtr def, vboxDriverPtr data, IMachine
*machine)
case VIR_DOMAIN_DISK_BUS_SCSI:
VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SCSI_NAME, &storageCtlName);
- model = virDomainDeviceFindControllerModel(def, &disk->info,
- VIR_DOMAIN_CONTROLLER_TYPE_SCSI);
- if (model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1068) {
+ cont = virDomainDeviceFindSCSIController(def, &disk->info);
+ if (cont && cont->model ==
VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSISAS1068) {
VBOX_UTF16_FREE(storageCtlName);
VBOX_UTF8_TO_UTF16(VBOX_CONTROLLER_SAS_NAME, &storageCtlName);
}
--
2.13.6