conf: utility to return alias of a controller based on type/index

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).
This commit is contained in:
Laine Stump 2015-04-29 15:37:20 -04:00
parent a692277873
commit a3dfaf1272
3 changed files with 38 additions and 0 deletions

View File

@ -12506,6 +12506,40 @@ virDomainControllerFind(virDomainDefPtr def,
return -1; 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 int
virDomainControllerFindByType(virDomainDefPtr def, virDomainControllerFindByType(virDomainDefPtr def,
int type) int type)

View File

@ -2745,6 +2745,9 @@ int virDomainControllerFindByType(virDomainDefPtr def, int type);
int virDomainControllerFindByPCIAddress(virDomainDefPtr def, int virDomainControllerFindByPCIAddress(virDomainDefPtr def,
virDevicePCIAddressPtr addr); virDevicePCIAddressPtr addr);
virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i); virDomainControllerDefPtr virDomainControllerRemove(virDomainDefPtr def, size_t i);
const char *virDomainControllerAliasFind(virDomainDefPtr def,
int type, int idx)
ATTRIBUTE_NONNULL(1);
int virDomainLeaseIndex(virDomainDefPtr def, int virDomainLeaseIndex(virDomainDefPtr def,
virDomainLeaseDefPtr lease); virDomainLeaseDefPtr lease);

View File

@ -181,6 +181,7 @@ virDomainClockBasisTypeToString;
virDomainClockOffsetTypeFromString; virDomainClockOffsetTypeFromString;
virDomainClockOffsetTypeToString; virDomainClockOffsetTypeToString;
virDomainConfigFile; virDomainConfigFile;
virDomainControllerAliasFind;
virDomainControllerDefFree; virDomainControllerDefFree;
virDomainControllerFind; virDomainControllerFind;
virDomainControllerFindByType; virDomainControllerFindByType;