The function is modified to be stateless, which is more
consistent with existing helpers that deal with figuring out
default models for devices, and its name needs to change
accordingly.
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
src/qemu/qemu_domain.c | 21 +++++++++++----------
src/qemu/qemu_domain.h | 6 +++---
src/qemu/qemu_hotplug.c | 5 +++--
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 672f1ce59f..97336d5002 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4106,23 +4106,23 @@ qemuDomainDefAddDefaultAudioBackend(virQEMUDriver *driver,
/**
+ * qemuDomainDefaultSCSIControllerModel:
* @def: Domain definition
* @cont: Domain controller def
* @qemuCaps: qemu capabilities
*
- * If the controller model is already defined, return it immediately;
- * otherwise, based on the @qemuCaps return a default model value.
+ * Decides the preferred model for a SCSI controller that it to be
+ * added to @def. The choice might be based on various factors,
+ * including the architecture, machine type and what devices are
+ * available according to @qemuCaps.
*
* Returns model on success, -1 on failure with error set.
*/
int
-qemuDomainGetSCSIControllerModel(const virDomainDef *def,
- const virDomainControllerDef *cont,
- virQEMUCaps *qemuCaps)
+qemuDomainDefaultSCSIControllerModel(const virDomainDef *def,
+ const virDomainControllerDef *cont,
+ virQEMUCaps *qemuCaps)
{
- if (cont->model > 0)
- return cont->model;
-
if (qemuDomainIsPSeries(def))
return VIR_DOMAIN_CONTROLLER_MODEL_SCSI_IBMVSCSI;
if (ARCH_IS_S390(def->os.arch))
@@ -5621,9 +5621,10 @@ qemuDomainControllerDefPostParse(virDomainControllerDef *cont,
switch (cont->type) {
case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
/* Set the default SCSI controller model if not already set */
- cont->model = qemuDomainGetSCSIControllerModel(def, cont, qemuCaps);
+ if (cont->model <= 0)
+ cont->model = qemuDomainDefaultSCSIControllerModel(def, cont, qemuCaps);
- if (cont->model < 0)
+ if (cont->model <= 0)
return -1;
break;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 4dfc0ab5c7..48f966fa2a 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -836,9 +836,9 @@ bool qemuDomainHasBuiltinESP(const virDomainDef *def);
bool qemuDomainNeedsFDC(const virDomainDef *def);
bool qemuDomainSupportsPCI(const virDomainDef *def);
bool qemuDomainSupportsPCIMultibus(const virDomainDef *def);
-int qemuDomainGetSCSIControllerModel(const virDomainDef *def,
- const virDomainControllerDef *cont,
- virQEMUCaps *qemuCaps);
+int qemuDomainDefaultSCSIControllerModel(const virDomainDef *def,
+ const virDomainControllerDef *cont,
+ virQEMUCaps *qemuCaps);
void qemuDomainUpdateCurrentMemorySize(virDomainObj *vm);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c883fef0e9..4fd7b7f756 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -878,9 +878,10 @@ qemuDomainFindOrCreateSCSIDiskController(virDomainObj *vm,
cont->idx = controller;
cont->model = model;
- cont->model = qemuDomainGetSCSIControllerModel(vm->def, cont, priv->qemuCaps);
+ if (cont->model <= 0)
+ cont->model = qemuDomainDefaultSCSIControllerModel(vm->def, cont, priv->qemuCaps);
- if (cont->model < 0) {
+ if (cont->model <= 0) {
VIR_FREE(cont);
return NULL;
}
--
2.43.0
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org