Because there are multiple potential reasons for an error, this function logs any errors before returning NULL (since the caller won't have the information needed to determine which was the reason for failure). --- src/conf/domain_conf.c | 34 ++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 38 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4cd36a1..22f49c9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12554,6 +12554,40 @@ virDomainControllerFind(virDomainDefPtr def, return -1; } + +const char * +virDomainControllerAliasFind(virDomainDefPtr def, + int type, int idx) +{ + int contIndex; + const char *contTypeStr = virDomainControllerTypeToString(type); + + if (!contTypeStr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Unknown controller type %d"), + type); + return NULL; + } + + contIndex = virDomainControllerFind(def, type, idx); + if (contIndex < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not find %s controller with index %d " + "required for device"), + contTypeStr, idx); + return NULL; + } + if (!def->controllers[contIndex]->info.alias) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Device alias was not set for %s controller " + "with index %d "), + contTypeStr, idx); + return NULL; + } + return def->controllers[contIndex]->info.alias; +} + + int virDomainControllerFindByType(virDomainDefPtr def, int type) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 087d282..7cc655b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2754,6 +2754,9 @@ int virDomainControllerFindByType(virDomainDefPtr def, int type); int virDomainControllerFindByPCIAddress(virDomainDefPtr def, virDevicePCIAddressPtr addr); virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i); +const char *virDomainControllerAliasFind(virDomainDefPtr def, + int type, int idx) + ATTRIBUTE_NONNULL(1); int virDomainLeaseIndex(virDomainDefPtr def, virDomainLeaseDefPtr lease); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c8e6fb4..0eb5f75 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -181,6 +181,7 @@ virDomainClockBasisTypeToString; virDomainClockOffsetTypeFromString; virDomainClockOffsetTypeToString; virDomainConfigFile; +virDomainControllerAliasFind; virDomainControllerDefFree; virDomainControllerFind; virDomainControllerFindByType; -- 2.1.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list