[PATCH v3 03/21] LXC from native: import rootfs

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

 



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                         | 69 ++++++++++++++++++++++++++++
 tests/lxcconf2xmldata/lxcconf2xml-simple.xml |  4 ++
 2 files changed, 73 insertions(+)

diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index 723ebcf..86d0dd3 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -31,6 +31,72 @@
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
+
+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,
+             virConfPtr properties)
+{
+    char *fssrc = NULL;
+    char *fsdst = NULL;
+    int type = VIR_DOMAIN_FS_TYPE_MOUNT;
+    virConfValuePtr value;
+
+    if (!(value = virConfGetValue(properties, "lxc.rootfs")) ||
+           !value->str ||
+           (VIR_STRDUP(fssrc, value->str) < 0) ||
+            VIR_STRDUP(fsdst, "/") < 0)
+        goto error;
+
+    if (STRPREFIX(fssrc, "/dev/"))
+        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)
 {
@@ -73,6 +139,9 @@ lxcParseConfigString(const char *config)
     if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0))
         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 641e624..eebcb4e 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

--
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]