This function was introduced to fetch/alloc new data for legacy entries
inside config file: 'lxc.network.foo'. Libvirt still need to support
both versions. So, this function can be easy to remove in the future.
Signed-off-by: Julio Faracco <jcfaracco(a)gmail.com>
---
src/lxc/lxc_native.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 7200743da7..4d26d1a20b 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -572,6 +572,37 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseDataPtr
data)
return -1;
}
+static lxcNetworkParseDataPtr
+lxcNetworkGetParseDataLegacy(lxcNetworkParseArray *networks,
+ const char *name)
+{
+ const char *suffix = STRSKIP(name, "lxc.network.");
+ int elem = virLXCNetworkConfigEntryTypeFromString(suffix);
+ size_t index = networks->nnetworks;
+
+ if (elem == VIR_LXC_NETWORK_CONFIG_TYPE) {
+ if (!networks->data) {
+ if (VIR_ALLOC_N(networks->data, index + 1) < 0)
+ return NULL;
+ } else {
+ if (VIR_REALLOC_N(networks->data, index + 1) < 0)
+ return NULL;
+ }
+
+ if (VIR_ALLOC(networks->data[index]) < 0)
+ return NULL;
+
+ networks->data[index]->index = index;
+ networks->nnetworks++;
+
+ /* Return a new network. */
+ return networks->data[index];
+ }
+
+ /* Return the last network. */
+ return networks->data[index-1];
+}
+
static int
lxcNetworkParseDataIPs(const char *name,
virConfValuePtr value,
@@ -679,8 +710,12 @@ lxcNetworkWalkCallback(const char *name, virConfValuePtr value, void
*data)
lxcNetworkParseArray *networks = data;
lxcNetworkParseDataPtr parseData = NULL;
- if (STRPREFIX(name, "lxc.network."))
+ if (STRPREFIX(name, "lxc.network.")) {
+ if (!(parseData = lxcNetworkGetParseDataLegacy(networks, name)))
+ return -1;
+
return lxcNetworkParseDataEntry(name, value, parseData);
+ }
return 0;
}
--
2.19.1