From: Michal Privoznik Date: Wed, 18 Oct 2017 12:59:01 +0000 (+0200) Subject: conf: Parse user supplied aliases X-Git-Tag: v3.9.0-rc1~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c14f1ed20647f2c6d0ae14bf8c50234217d2a57b;p=thirdparty%2Flibvirt.git 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 --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce9b4ee7f0..40fcbc7dfa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f251f390b7..1a3574aa72 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -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;