From: Cédric Bosdonnat Date: Wed, 5 Feb 2014 14:10:01 +0000 (+0100) Subject: LXC from native: import rootfs X-Git-Tag: v1.2.2-rc1~114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=197b13e5d9f9fb89148a2b402ec0bf3db8f865b6;p=thirdparty%2Flibvirt.git 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. --- diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 723ebcfb60..af9d34e248 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -31,6 +31,76 @@ #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: diff --git a/tests/lxcconf2xmldata/lxcconf2xml-simple.xml b/tests/lxcconf2xmldata/lxcconf2xml-simple.xml index 641e62484e..eebcb4ed58 100644 --- a/tests/lxcconf2xmldata/lxcconf2xml-simple.xml +++ b/tests/lxcconf2xmldata/lxcconf2xml-simple.xml @@ -13,5 +13,9 @@ restart destroy + + + +