[libvirt] [PATCH v2 02/11] conf: Parse user supplied aliases

Michal Privoznik mprivozn at redhat.com
Fri Oct 20 14:52:12 UTC 2017


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 at redhat.com>
---
 src/conf/domain_conf.c | 18 +++++++++++++++---
 src/conf/domain_conf.h |  1 +
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ce9b4ee7f..40fcbc7df 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 f251f390b..1a3574aa7 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;
 
 
-- 
2.13.6




More information about the libvir-list mailing list