[PATCH v3] lxc: Include support to lxc version 3.0 or higher.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch introduce the new settings for LXC 3.0 or higher. The older
versions keep the compatibility to deprecated settings for LXC, but
after release 3.0, the compatibility was removed. This commit adds the
support to the refactored settings.

v1-v2: Michal's suggestions to handle differences between versions.
v2-v3: Adding suggestions from Pino and John too.

Signed-off-by: Julio Faracco <jcfaracco@xxxxxxxxx>
---
 src/lxc/lxc_native.c | 45 +++++++++++++++++++++++++++++++-------------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index cbdec723dd..d3ba12bb0e 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -200,8 +200,13 @@ lxcSetRootfs(virDomainDefPtr def,
     int type = VIR_DOMAIN_FS_TYPE_MOUNT;
     VIR_AUTOFREE(char *) value = NULL;
 
-    if (virConfGetValueString(properties, "lxc.rootfs", &value) <= 0)
-        return -1;
+    if (virConfGetValueString(properties, "lxc.rootfs.path", &value) <= 0) {
+        virResetLastError();
+
+        /* Check for pre LXC 3.0 legacy key */
+        if (virConfGetValueString(properties, "lxc.rootfs", &value) <= 0)
+            return -1;
+    }
 
     if (STRPREFIX(value, "/dev/"))
         type = VIR_DOMAIN_FS_TYPE_BLOCK;
@@ -684,8 +689,13 @@ lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
     virDomainChrDefPtr console;
     size_t i;
 
-    if (virConfGetValueString(properties, "lxc.tty", &value) <= 0)
-        return 0;
+    if (virConfGetValueString(properties, "lxc.tty.max", &value) <= 0) {
+        virResetLastError();
+
+        /* Check for pre LXC 3.0 legacy key */
+        if (virConfGetValueString(properties, "lxc.tty", &value) <= 0)
+            return 0;
+    }
 
     if (virStrToLong_i(value, NULL, 10, &nbttys) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse int: '%s'"),
@@ -724,12 +734,13 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr value, void *data)
     char type;
     unsigned long start, target, count;
 
-    if (STRNEQ(name, "lxc.id_map") || !value->str)
+    /* LXC 3.0 uses "lxc.idmap", while legacy used "lxc.id_map" */
+    if (STRNEQ(name, "lxc.idmap") || STRNEQ(name, "lxc.id_map") || !value->str)
         return 0;
 
     if (sscanf(value->str, "%c %lu %lu %lu", &type,
                &target, &start, &count) != 4) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid lxc.id_map: '%s'"),
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid: '%s'"),
                        value->str);
         return -1;
     }
@@ -1041,19 +1052,27 @@ lxcParseConfigString(const char *config,
     if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0)
         goto error;
 
-    if (virConfGetValueString(properties, "lxc.utsname", &value) <= 0 ||
-        VIR_STRDUP(vmdef->name, value) < 0)
-        goto error;
+    if (virConfGetValueString(properties, "lxc.uts.name", &value) <= 0) {
+        virResetLastError();
+
+        /* Check for pre LXC 3.0 legacy key */
+        if (virConfGetValueString(properties, "lxc.utsname", &value) <= 0)
+            goto error;
+    }
+
     if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0))
         goto error;
 
     if (lxcSetRootfs(vmdef, properties) < 0)
         goto error;
 
-    /* Look for fstab: we shouldn't have it */
-    if (virConfGetValue(properties, "lxc.mount")) {
+    /* LXC 3.0 uses "lxc.mount.fstab", while legacy used just "lxc.mount".
+     * In either case, generate the error to use "lxc.mount.entry" instead */
+    if (virConfGetValue(properties, "lxc.mount.fstab") ||
+        virConfGetValue(properties, "lxc.mount")) {
         virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
-                       _("lxc.mount found, use lxc.mount.entry lines instead"));
+                       _("lxc.mount.fstab or lxc.mount found, use "
+                         "lxc.mount.entry lines instead"));
         goto error;
     }
 
@@ -1069,7 +1088,7 @@ lxcParseConfigString(const char *config,
     if (lxcCreateConsoles(vmdef, properties) < 0)
         goto error;
 
-    /* lxc.id_map */
+    /* lxc.idmap or legacy lxc.id_map */
     if (virConfWalk(properties, lxcIdmapWalkCallback, vmdef) < 0)
         goto error;
 
-- 
2.19.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux