Blob Blame History Raw
From c4df501b589eb7d4315c13bfe6ba653321135841 Mon Sep 17 00:00:00 2001
Message-Id: <c4df501b589eb7d4315c13bfe6ba653321135841@dist-git>
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
Date: Thu, 30 Nov 2017 17:45:57 +0100
Subject: [PATCH] Introduce virDomainDeviceAliasIsUserAlias
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Allow parts of code outside domain_conf to decide whether the alias
is user-specified or not.

(cherry picked from commit 309cd46b400d80420615b19adfebf7158492ae3b)

https://bugzilla.redhat.com/show_bug.cgi?id=1518148

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/conf/domain_conf.c   | 9 ++++++++-
 src/conf/domain_conf.h   | 2 ++
 src/libvirt_private.syms | 1 +
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 83392a42c0..bd6d851f21 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6662,6 +6662,13 @@ virDomainDeviceAddressParseXML(xmlNodePtr address,
 #define USER_ALIAS_CHARS \
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
 
+bool
+virDomainDeviceAliasIsUserAlias(const char *aliasStr)
+{
+    return STRPREFIX(aliasStr, USER_ALIAS_PREFIX);
+}
+
+
 /* Parse the XML definition for a device address
  * @param node XML nodeset to parse for device address definition
  */
@@ -6715,7 +6722,7 @@ virDomainDeviceInfoParseXML(virDomainXMLOptionPtr xmlopt ATTRIBUTE_UNUSED,
 
         if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) ||
             (xmlopt->config.features & VIR_DOMAIN_DEF_FEATURE_USER_ALIAS &&
-             STRPREFIX(aliasStr, USER_ALIAS_PREFIX) &&
+             virDomainDeviceAliasIsUserAlias(aliasStr) &&
              strspn(aliasStr, USER_ALIAS_CHARS) == strlen(aliasStr)))
             VIR_STEAL_PTR(info->alias, aliasStr);
     }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0e97f0437e..479a791f29 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2674,6 +2674,8 @@ int virDomainDeviceValidateAliasForHotplug(virDomainObjPtr vm,
                                            virDomainDeviceDefPtr dev,
                                            unsigned int flags);
 
+bool virDomainDeviceAliasIsUserAlias(const char *aliasStr);
+
 int virDomainDefValidate(virDomainDefPtr def,
                          virCapsPtr caps,
                          unsigned int parseFlags,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0449b0185f..19c1ecc408 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -292,6 +292,7 @@ virDomainDefVcpuOrderClear;
 virDomainDeleteConfig;
 virDomainDeviceAddressIsValid;
 virDomainDeviceAddressTypeToString;
+virDomainDeviceAliasIsUserAlias;
 virDomainDeviceDefCopy;
 virDomainDeviceDefFree;
 virDomainDeviceDefParse;
-- 
2.15.1