From c172a3733ecf781092c15e0e42b9da3a7c5b5dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 17 Aug 2021 17:24:08 +0200 Subject: [PATCH] qemu: alias: prepare qemuAssignDeviceFSAlias for disjunct ranges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iterate through the array to find the first free index. Signed-off-by: Ján Tomko Reviewed-by: Peter Krempa --- src/qemu/qemu_alias.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index 81a1e7eeed..4153050bec 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -336,13 +336,23 @@ qemuAssignDeviceNetAlias(virDomainDef *def, static int -qemuAssignDeviceFSAlias(virDomainFSDef *fss, - int idx) +qemuAssignDeviceFSAlias(virDomainDef *def, + virDomainFSDef *fss) { + size_t i; + int maxidx = 0; + if (fss->info.alias) return 0; - fss->info.alias = g_strdup_printf("fs%d", idx); + for (i = 0; i < def->nfss; i++) { + int idx; + + if ((idx = qemuDomainDeviceAliasIndex(&def->fss[i]->info, "fs")) >= maxidx) + maxidx = idx + 1; + } + + fss->info.alias = g_strdup_printf("fs%d", maxidx); return 0; } @@ -634,7 +644,7 @@ qemuAssignDeviceAliases(virDomainDef *def, virQEMUCaps *qemuCaps) } for (i = 0; i < def->nfss; i++) { - if (qemuAssignDeviceFSAlias(def->fss[i], i) < 0) + if (qemuAssignDeviceFSAlias(def, def->fss[i]) < 0) return -1; } for (i = 0; i < def->nsounds; i++) {