]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Parse user supplied aliases
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Oct 2017 12:59:01 +0000 (14:59 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sun, 22 Oct 2017 11:49:46 +0000 (13:49 +0200)
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>
src/conf/domain_conf.c
src/conf/domain_conf.h

index ce9b4ee7f0207050214d7efbb1dc6b7af3726b7c..40fcbc7dfa1d893914349990ee084f009eaa45ee 100644 (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;
 }
 
index f251f390b7a00d673f68ed92f54c17bba1a34919..1a3574aa728f9032eb849db4913a094ba99e84c0 100644 (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;