conf: Parse user supplied aliases

If driver that is calling the parse supports user supplied
aliases, they can be parsed even for inactive XMLs. However, to
avoid any clashes with aliases that libvirt generates, the user
ones have to have "ua-" prefix.

Note, that some drivers don't have notion of device aliases at
all. Also, in order to support user supplied aliases some extra
checks need to be done (e.g. during hotplug). Therefore we can't
just enable this feature for all the drivers. Thus we need a flag
that drivers set to tell parsing code that they can handle user
supplied device aliases.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2017-10-18 14:59:01 +02:00
parent ad30f069d1
commit c14f1ed206
2 changed files with 16 additions and 3 deletions

View File

@ -6454,6 +6454,10 @@ virDomainDeviceAddressParseXML(xmlNodePtr address,
}
#define USER_ALIAS_PREFIX "ua-"
#define USER_ALIAS_CHARS \
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
/* Parse the XML definition for a device address
* @param node XML nodeset to parse for device address definition
*/
@ -6472,6 +6476,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
xmlNodePtr rom = NULL;
char *type = NULL;
char *rombar = NULL;
char *aliasStr = NULL;
int ret = -1;
virDomainDeviceInfoClear(info);
@ -6480,7 +6485,6 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE) {
if (alias == NULL &&
!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
virXMLNodeNameEqual(cur, "alias")) {
alias = cur;
} else if (address == NULL &&
@ -6502,8 +6506,15 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
cur = cur->next;
}
if (alias)
info->alias = virXMLPropString(alias, "name");
if (alias) {
aliasStr = virXMLPropString(alias, "name");
if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) ||
(xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_USER_ALIAS &&
STRPREFIX(aliasStr, USER_ALIAS_PREFIX) &&
strspn(aliasStr, USER_ALIAS_CHARS) == strlen(aliasStr)))
VIR_STEAL_PTR(info->alias, aliasStr);
}
if (master) {
info->mastertype = VIR_DOMAIN_CONTROLLER_MASTER_USB;
@ -6537,6 +6548,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
virDomainDeviceInfoClear(info);
VIR_FREE(type);
VIR_FREE(rombar);
VIR_FREE(aliasStr);
return ret;
}

View File

@ -2488,6 +2488,7 @@ typedef enum {
VIR_DOMAIN_DEF_FEATURE_OFFLINE_VCPUPIN = (1 << 2),
VIR_DOMAIN_DEF_FEATURE_NAME_SLASH = (1 << 3),
VIR_DOMAIN_DEF_FEATURE_INDIVIDUAL_VCPUS = (1 << 4),
VIR_DOMAIN_DEF_FEATURE_USER_ALIAS = (1 << 5),
} virDomainDefFeatures;