From ad30f069d108c9e6f30c2aec227d609df3b4e9af Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 20 Oct 2017 13:24:41 +0200 Subject: [PATCH] qemu_alias: Be more tolerant if alias don't follow our format When assigning alias to a device we usually iterate over other devices of its kind trying to find next index. We do this by stripping down the prefix and then parsing number at the end, Usually, if the prefix doesn't match the one we are expecting, we just continue with next iteration. Except for couple of functions: qemuGetNextChrDevIndex(), qemuAssignDeviceRedirdevAlias() and qemuAssignDeviceShmemAlias(). Signed-off-by: Michal Privoznik --- src/qemu/qemu_alias.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index d06a3d63e6..37fe2aa802 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -73,11 +73,8 @@ qemuGetNextChrDevIndex(virDomainDefPtr def, ssize_t thisidx; if (((thisidx = qemuDomainDeviceAliasIndex(&arrPtr[i]->info, prefix)) < 0) && (prefix2 && - (thisidx = qemuDomainDeviceAliasIndex(&arrPtr[i]->info, prefix2)) < 0)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to determine device index for character device")); - return -1; - } + (thisidx = qemuDomainDeviceAliasIndex(&arrPtr[i]->info, prefix2)) < 0)) + continue; if (thisidx >= idx) idx = thisidx + 1; } @@ -391,11 +388,8 @@ qemuAssignDeviceRedirdevAlias(virDomainDefPtr def, idx = 0; for (i = 0; i < def->nredirdevs; i++) { int thisidx; - if ((thisidx = qemuDomainDeviceAliasIndex(&def->redirdevs[i]->info, "redir")) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to determine device index for redirected device")); - return -1; - } + if ((thisidx = qemuDomainDeviceAliasIndex(&def->redirdevs[i]->info, "redir")) < 0) + continue; if (thisidx >= idx) idx = thisidx + 1; } @@ -491,12 +485,8 @@ qemuAssignDeviceShmemAlias(virDomainDefPtr def, int thisidx; if ((thisidx = qemuDomainDeviceAliasIndex(&def->shmems[i]->info, - "shmem")) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to determine device index " - "for shmem device")); - return -1; - } + "shmem")) < 0) + continue; if (thisidx >= idx) idx = thisidx + 1;