1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

domain-conf: cleanup controller insert function

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2015-11-11 15:18:07 +01:00
parent a9a583d6df
commit 6fdbdafcd7

View File

@ -13397,6 +13397,7 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
int idx;
/* Tenatively plan to insert controller at the end. */
int insertAt = -1;
virDomainControllerDefPtr current = NULL;
/* Then work backwards looking for controllers of
* the same type. If we find a controller with a
@ -13404,17 +13405,19 @@ void virDomainControllerInsertPreAlloced(virDomainDefPtr def,
* that position
*/
for (idx = (def->ncontrollers - 1); idx >= 0; idx--) {
/* If bus matches and current controller is after
* new controller, then new controller should go here */
if (def->controllers[idx]->type == controller->type &&
def->controllers[idx]->idx > controller->idx) {
insertAt = idx;
} else if (def->controllers[idx]->type == controller->type &&
insertAt == -1) {
/* Last controller with match bus is before the
* new controller, then put new controller just after
*/
insertAt = idx + 1;
current = def->controllers[idx];
if (current->type == controller->type) {
if (current->idx > controller->idx) {
/* If bus matches and current controller is after
* new controller, then new controller should go here
* */
insertAt = idx;
} else if (insertAt == -1) {
/* Last controller with match bus is before the
* new controller, then put new controller just after
*/
insertAt = idx + 1;
}
}
}