]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC from native: import rootfs
authorCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 5 Feb 2014 14:10:01 +0000 (15:10 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 12 Feb 2014 17:52:46 +0000 (17:52 +0000)
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
tests/lxcconf2xmldata/lxcconf2xml-simple.xml

index 723ebcfb6071108114997a37bf02e607f71b340f..af9d34e24883ce049235322ecf45586a9671c623 100644 (file)
 
 #define VIR_FROM_THIS VIR_FROM_LXC
 
+
+static virDomainFSDefPtr
+lxcCreateFSDef(int type,
+               const char *src,
+               const char* dst)
+{
+    virDomainFSDefPtr def;
+
+    if (VIR_ALLOC(def) < 0)
+        return NULL;
+
+    def->type = type;
+    def->accessmode = VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH;
+    if (src && VIR_STRDUP(def->src, src) < 0)
+        goto error;
+    if (VIR_STRDUP(def->dst, dst) < 0)
+        goto error;
+
+    return def;
+
+ error:
+    virDomainFSDefFree(def);
+    return NULL;
+}
+
+static int
+lxcAddFSDef(virDomainDefPtr def,
+            int type,
+            const char *src,
+            const 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)
+{
+    int type = VIR_DOMAIN_FS_TYPE_MOUNT;
+    virConfValuePtr value;
+
+    if (!(value = virConfGetValue(properties, "lxc.rootfs")) ||
+        !value->str) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Missing lxc.rootfs configuration"));
+        return -1;
+    }
+
+    if (STRPREFIX(value->str, "/dev/"))
+        type = VIR_DOMAIN_FS_TYPE_BLOCK;
+
+    if (lxcAddFSDef(def, type, value->str, "/") < 0)
+        return -1;
+
+    return 0;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config)
 {
@@ -73,6 +143,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:
index 641e62484eaa7a2b0d6ccf726e46e5e7334d36dc..eebcb4ed5825833cdc33456143c3e051d4fb284a 100644 (file)
@@ -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>