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.
This commit is contained in:
Cédric Bosdonnat 2014-02-05 15:10:01 +01:00 committed by Daniel P. Berrange
parent 7195c807b2
commit 197b13e5d9
2 changed files with 77 additions and 0 deletions

View File

@ -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:

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