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

[libvirt] [PATCH 02/16] LXC from native: import rootfs



LXC rootfs can be either a directory or a block device or an image
file. The first two types have been implemented, but the image file is
still to be done since LXC auto-guesses the file format at mount time
and the LXC driver doesn't support the 'auto' format.
---
 src/lxc/lxc_native.c                         | 70 ++++++++++++++++++++++++++++
 tests/lxcconf2xmldata/lxcconf2xml-simple.xml |  4 ++
 2 files changed, 74 insertions(+)

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 14b2844..2cd9143 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -21,6 +21,7 @@
  */
 
 #include <config.h>
+#include <sys/stat.h>
 
 #include "internal.h"
 #include "lxc_native.h"
@@ -204,6 +205,72 @@ lxcParseProperties(const char *properties)
     return table;
 }
 
+static virDomainFSDefPtr
+lxcCreateFSDef(int type, char *src, char* dst)
+{
+    virDomainFSDefPtr def;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    def->type = type;
+    def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
+    def->src = src;
+    def->dst = dst;
+
+    return def;
+}
+
+static int
+lxcAddFSDef(virDomainDefPtr def, int type, char *src, char *dst)
+{
+    virDomainFSDefPtr fsDef = NULL;
+
+    if (!(fsDef = lxcCreateFSDef(type, src, dst)))
+        goto error;
+
+    if (VIR_EXPAND_N(def->fss, def->nfss, 1) < 0)
+        goto error;
+    def->fss[def->nfss - 1] = fsDef;
+
+    return 0;
+
+error:
+    virDomainFSDefFree(fsDef);
+    return -1;
+}
+
+static int
+lxcSetRootfs(virDomainDefPtr def,
+             virPropertiesPtr properties)
+{
+    char *fssrc = NULL;
+    char *fsdst = NULL;
+    struct stat sb;
+    int type = VIR_DOMAIN_FS_TYPE_MOUNT;
+
+    if (VIR_STRDUP(fssrc, virPropertiesLookup(properties, "lxc.rootfs")) < 0 ||
+            VIR_STRDUP(fsdst, "/") < 0)
+        goto error;
+
+    if (stat(fssrc, &sb) < 0)
+        goto error;
+
+    if (S_ISBLK(sb.st_mode))
+        type = VIR_DOMAIN_FS_TYPE_BLOCK;
+
+
+    if (lxcAddFSDef(def, type, fssrc, fsdst) < 0)
+        goto error;
+
+    return 0;
+
+error:
+    VIR_FREE(fssrc);
+    VIR_FREE(fsdst);
+    return -1;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config,
                      const char *fstab ATTRIBUTE_UNUSED,
@@ -246,6 +313,9 @@ lxcParseConfigString(const char *config,
     if (!vmdef->name && VIR_STRDUP(vmdef->name, "unnamed"))
         goto error;
 
+    if (lxcSetRootfs(vmdef, properties) < 0)
+        goto error;
+
     goto cleanup;
 
 error:
diff --git a/tests/lxcconf2xmldata/lxcconf2xml-simple.xml b/tests/lxcconf2xmldata/lxcconf2xml-simple.xml
index a277751..621e699 100644
--- a/tests/lxcconf2xmldata/lxcconf2xml-simple.xml
+++ b/tests/lxcconf2xmldata/lxcconf2xml-simple.xml
@@ -13,5 +13,9 @@
   <on_reboot>restart</on_reboot>
   <on_crash>destroy</on_crash>
   <devices>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/var/lib/lxc/migrate_test/rootfs'/>
+      <target dir='/'/>
+    </filesystem>
   </devices>
 </domain>
-- 
1.8.5.2


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