If virDomainControllerSCSINextUnit failed to find a slot on the current
VIR_DOMAIN_CONTROLLER_TYPE_SCSI controller(s), try to add a new controller;
otherwise, there may be multiple unit=0 entries for the same "next"
controller.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/conf/domain_conf.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 80daba9..9c6c739 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3953,7 +3953,7 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
int next_unit = 0;
unsigned controller = 0;
size_t i;
- int ret;
+ int ret = -1;
for (i = 0; i < def->ncontrollers; i++) {
if (def->controllers[i]->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI)
@@ -3972,6 +3972,17 @@ virDomainHostdevAssignAddress(virDomainXMLOptionPtr xmlopt,
}
}
+ /* If failed to find any VIR_DOMAIN_CONTROLLER_TYPE_SCSI or any space
+ * on existing VIR_DOMAIN_CONTROLLER_TYPE_SCSI controller(s), then
+ * try to add a new controller resulting in placement of this entry
+ * as unit=0
+ */
+ if (ret == -1 &&
+ virDomainDefMaybeAddController((virDomainDefPtr) def,
+ VIR_DOMAIN_CONTROLLER_TYPE_SCSI,
+ controller, -1) < 0)
+ return -1;
+
hostdev->info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
hostdev->info->addr.drive.controller = controller;
hostdev->info->addr.drive.bus = 0;
--
2.1.0