qemuBuildSmartcardCommandLine: Replace qemuBuildSmartcardFindCCIDController

We have a commonly used helper virDomainControllerAliasFind, which does
the same thing and also reports errors internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-10-11 17:01:53 +02:00
parent 43d48eebf9
commit b4026d9509

View File

@ -9048,32 +9048,6 @@ qemuBuildNetCommandLine(virQEMUDriver *driver,
}
static const char *
qemuBuildSmartcardFindCCIDController(const virDomainDef *def,
const virDomainSmartcardDef *smartcard)
{
size_t i;
/* Should never happen. But doesn't hurt to check. */
if (smartcard->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCID)
return NULL;
for (i = 0; i < def->ncontrollers; i++) {
const virDomainControllerDef *tmp = def->controllers[i];
if (tmp->type != VIR_DOMAIN_CONTROLLER_TYPE_CCID)
continue;
if (tmp->idx != smartcard->info.addr.ccid.controller)
continue;
return tmp->info.alias;
}
return NULL;
}
static int
qemuBuildSmartcardCommandLine(virLogManager *logManager,
virSecurityManager *secManager,
@ -9152,13 +9126,10 @@ qemuBuildSmartcardCommandLine(virLogManager *logManager,
return -1;
}
if (!(contAlias = qemuBuildSmartcardFindCCIDController(def,
smartcard))) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to find controller for %s"),
smartcard->info.alias);
if (!(contAlias = virDomainControllerAliasFind(def,
VIR_DOMAIN_CONTROLLER_TYPE_CCID,
smartcard->info.addr.ccid.controller)))
return -1;
}
virCommandAddArg(cmd, "-device");
virBufferAsprintf(&opt, ",id=%s,bus=%s.0", smartcard->info.alias, contAlias);