mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
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:
parent
7195c807b2
commit
197b13e5d9
@ -31,6 +31,76 @@
|
|||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_LXC
|
#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
|
virDomainDefPtr
|
||||||
lxcParseConfigString(const char *config)
|
lxcParseConfigString(const char *config)
|
||||||
{
|
{
|
||||||
@ -73,6 +143,9 @@ lxcParseConfigString(const char *config)
|
|||||||
if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0))
|
if (!vmdef->name && (VIR_STRDUP(vmdef->name, "unnamed") < 0))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
if (lxcSetRootfs(vmdef, properties) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -13,5 +13,9 @@
|
|||||||
<on_reboot>restart</on_reboot>
|
<on_reboot>restart</on_reboot>
|
||||||
<on_crash>destroy</on_crash>
|
<on_crash>destroy</on_crash>
|
||||||
<devices>
|
<devices>
|
||||||
|
<filesystem type='mount' accessmode='passthrough'>
|
||||||
|
<source dir='/var/lib/lxc/migrate_test/rootfs'/>
|
||||||
|
<target dir='/'/>
|
||||||
|
</filesystem>
|
||||||
</devices>
|
</devices>
|
||||||
</domain>
|
</domain>
|
||||||
|
Loading…
Reference in New Issue
Block a user