mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
lxc: replace VIR_FREE with g_autofree / g_free
Reviewed-by: Laine Stump <laine@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
a5a297f387
commit
9bcd47cd7b
@ -387,16 +387,16 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
|||||||
int *nicindexes)
|
int *nicindexes)
|
||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
char *machineName = virLXCDomainGetMachineName(def, 0);
|
g_autofree char *machineName = virLXCDomainGetMachineName(def, 0);
|
||||||
|
|
||||||
if (!machineName)
|
if (!machineName)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
if (def->resource->partition[0] != '/') {
|
if (def->resource->partition[0] != '/') {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("Resource partition '%s' must start with '/'"),
|
_("Resource partition '%s' must start with '/'"),
|
||||||
def->resource->partition);
|
def->resource->partition);
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virCgroupNewMachine(machineName,
|
if (virCgroupNewMachine(machineName,
|
||||||
@ -410,7 +410,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
|||||||
-1,
|
-1,
|
||||||
0,
|
0,
|
||||||
&cgroup) < 0)
|
&cgroup) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
/* setup control group permissions for user namespace */
|
/* setup control group permissions for user namespace */
|
||||||
if (def->idmap.uidmap) {
|
if (def->idmap.uidmap) {
|
||||||
@ -419,14 +419,10 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def,
|
|||||||
def->idmap.gidmap[0].target,
|
def->idmap.gidmap[0].target,
|
||||||
(1 << VIR_CGROUP_CONTROLLER_SYSTEMD)) < 0) {
|
(1 << VIR_CGROUP_CONTROLLER_SYSTEMD)) < 0) {
|
||||||
virCgroupFree(&cgroup);
|
virCgroupFree(&cgroup);
|
||||||
cgroup = NULL;
|
return NULL;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(machineName);
|
|
||||||
|
|
||||||
return cgroup;
|
return cgroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
|
|||||||
virCapsPtr caps;
|
virCapsPtr caps;
|
||||||
virCapsGuestPtr guest;
|
virCapsGuestPtr guest;
|
||||||
virArch altArch;
|
virArch altArch;
|
||||||
char *lxc_path = NULL;
|
g_autofree char *lxc_path = NULL;
|
||||||
|
|
||||||
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
if ((caps = virCapabilitiesNew(virArchFromHost(),
|
||||||
false, false)) == NULL)
|
false, false)) == NULL)
|
||||||
@ -135,8 +135,6 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(lxc_path);
|
|
||||||
|
|
||||||
if (driver) {
|
if (driver) {
|
||||||
/* Security driver data */
|
/* Security driver data */
|
||||||
const char *doi, *model, *label, *type;
|
const char *doi, *model, *label, *type;
|
||||||
@ -167,7 +165,6 @@ virCapsPtr virLXCDriverCapsInit(virLXCDriverPtr driver)
|
|||||||
return caps;
|
return caps;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(lxc_path);
|
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -290,9 +287,9 @@ virLXCDriverConfigDispose(void *obj)
|
|||||||
{
|
{
|
||||||
virLXCDriverConfigPtr cfg = obj;
|
virLXCDriverConfigPtr cfg = obj;
|
||||||
|
|
||||||
VIR_FREE(cfg->configDir);
|
g_free(cfg->configDir);
|
||||||
VIR_FREE(cfg->autostartDir);
|
g_free(cfg->autostartDir);
|
||||||
VIR_FREE(cfg->stateDir);
|
g_free(cfg->stateDir);
|
||||||
VIR_FREE(cfg->logDir);
|
g_free(cfg->logDir);
|
||||||
VIR_FREE(cfg->securityDriverName);
|
g_free(cfg->securityDriverName);
|
||||||
}
|
}
|
||||||
|
@ -136,8 +136,8 @@ int lxcContainerHasReboot(void)
|
|||||||
CLONE_NEWIPC|SIGCHLD;
|
CLONE_NEWIPC|SIGCHLD;
|
||||||
int cpid;
|
int cpid;
|
||||||
char *childStack;
|
char *childStack;
|
||||||
char *stack;
|
g_autofree char *stack = NULL;
|
||||||
char *buf;
|
g_autofree char *buf = NULL;
|
||||||
int cmd, v;
|
int cmd, v;
|
||||||
int status;
|
int status;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
@ -152,10 +152,8 @@ int lxcContainerHasReboot(void)
|
|||||||
if (virStrToLong_i(buf, NULL, 10, &v) < 0) {
|
if (virStrToLong_i(buf, NULL, 10, &v) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Malformed ctrl-alt-del setting '%s'"), buf);
|
_("Malformed ctrl-alt-del setting '%s'"), buf);
|
||||||
VIR_FREE(buf);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_FREE(buf);
|
|
||||||
cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
|
cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
|
||||||
|
|
||||||
if (VIR_ALLOC_N(stack, stacksize) < 0)
|
if (VIR_ALLOC_N(stack, stacksize) < 0)
|
||||||
@ -164,7 +162,6 @@ int lxcContainerHasReboot(void)
|
|||||||
childStack = stack + stacksize;
|
childStack = stack + stacksize;
|
||||||
|
|
||||||
cpid = clone(lxcContainerRebootChild, childStack, flags, &cmd);
|
cpid = clone(lxcContainerRebootChild, childStack, flags, &cmd);
|
||||||
VIR_FREE(stack);
|
|
||||||
if (cpid < 0) {
|
if (cpid < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Unable to clone to check reboot support"));
|
_("Unable to clone to check reboot support"));
|
||||||
@ -638,7 +635,7 @@ static int lxcContainerResolveSymlinks(virDomainFSDefPtr fs, bool gentle)
|
|||||||
|
|
||||||
VIR_DEBUG("Resolved '%s' to %s", fs->src->path, newroot);
|
VIR_DEBUG("Resolved '%s' to %s", fs->src->path, newroot);
|
||||||
|
|
||||||
VIR_FREE(fs->src->path);
|
g_free(fs->src->path);
|
||||||
fs->src->path = newroot;
|
fs->src->path = newroot;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -648,7 +645,7 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def,
|
|||||||
virDomainFSDefPtr root,
|
virDomainFSDefPtr root,
|
||||||
const char *sec_mount_options)
|
const char *sec_mount_options)
|
||||||
{
|
{
|
||||||
char *dst;
|
g_autofree char *dst = NULL;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
VIR_DEBUG("Prepare root %d", root->type);
|
VIR_DEBUG("Prepare root %d", root->type);
|
||||||
@ -679,24 +676,21 @@ static int lxcContainerPrepareRoot(virDomainDefPtr def,
|
|||||||
|
|
||||||
if (lxcContainerMountFSBlock(root, "", sec_mount_options) < 0) {
|
if (lxcContainerMountFSBlock(root, "", sec_mount_options) < 0) {
|
||||||
root->dst = tmp;
|
root->dst = tmp;
|
||||||
VIR_FREE(dst);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
root->dst = tmp;
|
root->dst = tmp;
|
||||||
root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
root->type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
||||||
VIR_FREE(root->src->path);
|
g_free(root->src->path);
|
||||||
root->src->path = dst;
|
root->src->path = g_steal_pointer(&dst);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
||||||
{
|
{
|
||||||
int ret;
|
g_autofree char *oldroot = NULL;
|
||||||
char *oldroot = NULL, *newroot = NULL;
|
g_autofree char *newroot = NULL;
|
||||||
|
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
VIR_DEBUG("Pivot via %s", root->src->path);
|
VIR_DEBUG("Pivot via %s", root->src->path);
|
||||||
|
|
||||||
@ -704,7 +698,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
if (mount("", "/", "none", MS_PRIVATE|MS_REC, NULL) < 0) {
|
if (mount("", "/", "none", MS_PRIVATE|MS_REC, NULL) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Failed to make root private"));
|
_("Failed to make root private"));
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldroot = g_strdup_printf("%s/.oldroot", root->src->path);
|
oldroot = g_strdup_printf("%s/.oldroot", root->src->path);
|
||||||
@ -713,7 +707,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
oldroot);
|
oldroot);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a tmpfs root since old and new roots must be
|
/* Create a tmpfs root since old and new roots must be
|
||||||
@ -722,7 +716,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount empty tmpfs at %s"),
|
_("Failed to mount empty tmpfs at %s"),
|
||||||
oldroot);
|
oldroot);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a directory called 'new' in tmpfs */
|
/* Create a directory called 'new' in tmpfs */
|
||||||
@ -732,7 +726,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
newroot);
|
newroot);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ... and mount our root onto it */
|
/* ... and mount our root onto it */
|
||||||
@ -740,7 +734,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to bind %s to new root %s"),
|
_("Failed to bind %s to new root %s"),
|
||||||
root->src->path, newroot);
|
root->src->path, newroot);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (root->readonly) {
|
if (root->readonly) {
|
||||||
@ -748,7 +742,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to make new root %s readonly"),
|
_("Failed to make new root %s readonly"),
|
||||||
root->src->path);
|
root->src->path);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -757,7 +751,7 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
if (chdir(newroot) < 0) {
|
if (chdir(newroot) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to chdir into %s"), newroot);
|
_("Failed to chdir into %s"), newroot);
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The old root directory will live at /.oldroot after
|
/* The old root directory will live at /.oldroot after
|
||||||
@ -765,20 +759,14 @@ static int lxcContainerPivotRoot(virDomainFSDefPtr root)
|
|||||||
if (pivot_root(".", ".oldroot") < 0) {
|
if (pivot_root(".", ".oldroot") < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Failed to pivot root"));
|
_("Failed to pivot root"));
|
||||||
goto err;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* CWD is undefined after pivot_root, so go to / */
|
/* CWD is undefined after pivot_root, so go to / */
|
||||||
if (chdir("/") < 0)
|
if (chdir("/") < 0)
|
||||||
goto err;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
err:
|
|
||||||
VIR_FREE(oldroot);
|
|
||||||
VIR_FREE(newroot);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -845,7 +833,7 @@ static int lxcContainerSetReadOnly(void)
|
|||||||
tmp = g_strdup(mntent.mnt_dir);
|
tmp = g_strdup(mntent.mnt_dir);
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
|
if (VIR_APPEND_ELEMENT(mounts, nmounts, tmp) < 0) {
|
||||||
VIR_FREE(tmp);
|
g_free(tmp);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -881,13 +869,12 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
bool netns_disabled)
|
bool netns_disabled)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
int rc = -1;
|
|
||||||
char* mnt_src = NULL;
|
|
||||||
int mnt_mflags;
|
int mnt_mflags;
|
||||||
|
|
||||||
VIR_DEBUG("Mounting basic filesystems");
|
VIR_DEBUG("Mounting basic filesystems");
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS(lxcBasicMounts); i++) {
|
for (i = 0; i < G_N_ELEMENTS(lxcBasicMounts); i++) {
|
||||||
|
g_autofree char *mnt_src = NULL;
|
||||||
bool bindOverReadonly;
|
bool bindOverReadonly;
|
||||||
virLXCBasicMountInfo const *mnt = &lxcBasicMounts[i];
|
virLXCBasicMountInfo const *mnt = &lxcBasicMounts[i];
|
||||||
|
|
||||||
@ -908,27 +895,23 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
mnt_src, mnt->dst);
|
mnt_src, mnt->dst);
|
||||||
|
|
||||||
if (mnt->skipUnmounted) {
|
if (mnt->skipUnmounted) {
|
||||||
char *hostdir;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
g_autofree char *hostdir = g_strdup_printf("/.oldroot%s",
|
||||||
hostdir = g_strdup_printf("/.oldroot%s", mnt->dst);
|
mnt->dst);
|
||||||
|
|
||||||
ret = virFileIsMountPoint(hostdir);
|
ret = virFileIsMountPoint(hostdir);
|
||||||
VIR_FREE(hostdir);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
VIR_DEBUG("Skipping '%s' which isn't mounted in host",
|
VIR_DEBUG("Skipping '%s' which isn't mounted in host",
|
||||||
mnt->dst);
|
mnt->dst);
|
||||||
VIR_FREE(mnt_src);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnt->skipUserNS && userns_enabled) {
|
if (mnt->skipUserNS && userns_enabled) {
|
||||||
VIR_DEBUG("Skipping due to user ns enablement");
|
VIR_DEBUG("Skipping due to user ns enablement");
|
||||||
VIR_FREE(mnt_src);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -936,13 +919,11 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
* missing folder in /proc due to the absence of a kernel feature */
|
* missing folder in /proc due to the absence of a kernel feature */
|
||||||
if (STRPREFIX(mnt_src, "/") && !virFileExists(mnt_src)) {
|
if (STRPREFIX(mnt_src, "/") && !virFileExists(mnt_src)) {
|
||||||
VIR_DEBUG("Skipping due to missing source: %s", mnt_src);
|
VIR_DEBUG("Skipping due to missing source: %s", mnt_src);
|
||||||
VIR_FREE(mnt_src);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mnt->skipNoNetns && netns_disabled) {
|
if (mnt->skipNoNetns && netns_disabled) {
|
||||||
VIR_DEBUG("Skipping due to absence of network namespace");
|
VIR_DEBUG("Skipping due to absence of network namespace");
|
||||||
VIR_FREE(mnt_src);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +931,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mkdir %s"),
|
_("Failed to mkdir %s"),
|
||||||
mnt->dst);
|
mnt->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -969,7 +950,7 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
_("Failed to mount %s on %s type %s flags=0x%x"),
|
_("Failed to mount %s on %s type %s flags=0x%x"),
|
||||||
mnt_src, mnt->dst, NULLSTR(mnt->type),
|
mnt_src, mnt->dst, NULLSTR(mnt->type),
|
||||||
mnt_mflags & ~MS_RDONLY);
|
mnt_mflags & ~MS_RDONLY);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bindOverReadonly &&
|
if (bindOverReadonly &&
|
||||||
@ -979,26 +960,18 @@ static int lxcContainerMountBasicFS(bool userns_enabled,
|
|||||||
_("Failed to re-mount %s on %s flags=0x%x"),
|
_("Failed to re-mount %s on %s flags=0x%x"),
|
||||||
mnt_src, mnt->dst,
|
mnt_src, mnt->dst,
|
||||||
MS_BIND|MS_REMOUNT|MS_RDONLY);
|
MS_BIND|MS_REMOUNT|MS_RDONLY);
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(mnt_src);
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
rc = 0;
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(mnt_src);
|
|
||||||
VIR_DEBUG("rc=%d", rc);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if WITH_FUSE
|
#if WITH_FUSE
|
||||||
static int lxcContainerMountProcFuse(virDomainDefPtr def,
|
static int lxcContainerMountProcFuse(virDomainDefPtr def,
|
||||||
const char *stateDir)
|
const char *stateDir)
|
||||||
{
|
{
|
||||||
int ret;
|
g_autofree char *meminfo_path = NULL;
|
||||||
char *meminfo_path = NULL;
|
|
||||||
|
|
||||||
VIR_DEBUG("Mount /proc/meminfo stateDir=%s", stateDir);
|
VIR_DEBUG("Mount /proc/meminfo stateDir=%s", stateDir);
|
||||||
|
|
||||||
@ -1006,15 +979,15 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def,
|
|||||||
stateDir,
|
stateDir,
|
||||||
def->name);
|
def->name);
|
||||||
|
|
||||||
if ((ret = mount(meminfo_path, "/proc/meminfo",
|
if (mount(meminfo_path, "/proc/meminfo",
|
||||||
NULL, MS_BIND, NULL)) < 0) {
|
NULL, MS_BIND, NULL) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount %s on /proc/meminfo"),
|
_("Failed to mount %s on /proc/meminfo"),
|
||||||
meminfo_path);
|
meminfo_path);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(meminfo_path);
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static int lxcContainerMountProcFuse(virDomainDefPtr def G_GNUC_UNUSED,
|
static int lxcContainerMountProcFuse(virDomainDefPtr def G_GNUC_UNUSED,
|
||||||
@ -1027,8 +1000,7 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def G_GNUC_UNUSED,
|
|||||||
static int lxcContainerMountFSDev(virDomainDefPtr def,
|
static int lxcContainerMountFSDev(virDomainDefPtr def,
|
||||||
const char *stateDir)
|
const char *stateDir)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *path = NULL;
|
||||||
char *path = NULL;
|
|
||||||
int flags = def->idmap.nuidmap ? MS_BIND : MS_MOVE;
|
int flags = def->idmap.nuidmap ? MS_BIND : MS_MOVE;
|
||||||
|
|
||||||
VIR_DEBUG("Mount /dev/ stateDir=%s", stateDir);
|
VIR_DEBUG("Mount /dev/ stateDir=%s", stateDir);
|
||||||
@ -1038,7 +1010,7 @@ static int lxcContainerMountFSDev(virDomainDefPtr def,
|
|||||||
if (virFileMakePath("/dev") < 0) {
|
if (virFileMakePath("/dev") < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot create /dev"));
|
_("Cannot create /dev"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Trying to %s %s to /dev", def->idmap.nuidmap ?
|
VIR_DEBUG("Trying to %s %s to /dev", def->idmap.nuidmap ?
|
||||||
@ -1048,21 +1020,16 @@ static int lxcContainerMountFSDev(virDomainDefPtr def,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount %s on /dev"),
|
_("Failed to mount %s on /dev"),
|
||||||
path);
|
path);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
|
static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
|
||||||
const char *stateDir)
|
const char *stateDir)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *path = NULL;
|
||||||
char *path = NULL;
|
|
||||||
int flags = def->idmap.nuidmap ? MS_BIND : MS_MOVE;
|
int flags = def->idmap.nuidmap ? MS_BIND : MS_MOVE;
|
||||||
|
|
||||||
VIR_DEBUG("Mount /dev/pts stateDir=%s", stateDir);
|
VIR_DEBUG("Mount /dev/pts stateDir=%s", stateDir);
|
||||||
@ -1072,7 +1039,7 @@ static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
|
|||||||
if (virFileMakePath("/dev/pts") < 0) {
|
if (virFileMakePath("/dev/pts") < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Cannot create /dev/pts"));
|
_("Cannot create /dev/pts"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Trying to %s %s to /dev/pts", def->idmap.nuidmap ?
|
VIR_DEBUG("Trying to %s %s to /dev/pts", def->idmap.nuidmap ?
|
||||||
@ -1082,13 +1049,10 @@ static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount %s on /dev/pts"),
|
_("Failed to mount %s on /dev/pts"),
|
||||||
path);
|
path);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
|
||||||
VIR_FREE(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths)
|
static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths)
|
||||||
@ -1118,15 +1082,10 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < nttyPaths; i++) {
|
for (i = 0; i < nttyPaths; i++) {
|
||||||
char *tty;
|
g_autofree char *tty = g_strdup_printf("/dev/tty%zu", i + 1);
|
||||||
tty = g_strdup_printf("/dev/tty%zu", i + 1);
|
|
||||||
|
|
||||||
if (virFileBindMountDevice(ttyPaths[i], tty) < 0) {
|
if (virFileBindMountDevice(ttyPaths[i], tty) < 0)
|
||||||
VIR_FREE(tty);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
VIR_FREE(tty);
|
|
||||||
|
|
||||||
if (i == 0 &&
|
if (i == 0 &&
|
||||||
virFileBindMountDevice(ttyPaths[i], "/dev/console") < 0)
|
virFileBindMountDevice(ttyPaths[i], "/dev/console") < 0)
|
||||||
@ -1139,8 +1098,7 @@ static int lxcContainerSetupDevices(char **ttyPaths, size_t nttyPaths)
|
|||||||
static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
||||||
const char *srcprefix)
|
const char *srcprefix)
|
||||||
{
|
{
|
||||||
char *src = NULL;
|
g_autofree char *src = NULL;
|
||||||
int ret = -1;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
|
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
|
||||||
@ -1151,20 +1109,20 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
|||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
virReportSystemError(errno, _("Unable to stat bind target %s"),
|
virReportSystemError(errno, _("Unable to stat bind target %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
/* ENOENT => create the target dir or file */
|
/* ENOENT => create the target dir or file */
|
||||||
if (stat(src, &st) < 0) {
|
if (stat(src, &st) < 0) {
|
||||||
virReportSystemError(errno, _("Unable to stat bind source %s"),
|
virReportSystemError(errno, _("Unable to stat bind source %s"),
|
||||||
src);
|
src);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
if (S_ISDIR(st.st_mode)) {
|
if (S_ISDIR(st.st_mode)) {
|
||||||
if (virFileMakePath(fs->dst) < 0) {
|
if (virFileMakePath(fs->dst) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Create Empty file for target mount point */
|
/* Create Empty file for target mount point */
|
||||||
@ -1174,14 +1132,14 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create bind target %s"),
|
_("Failed to create bind target %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (VIR_CLOSE(fd) < 0) {
|
if (VIR_CLOSE(fd) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to close bind target %s"),
|
_("Failed to close bind target %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1190,7 +1148,7 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to bind mount directory %s to %s"),
|
_("Failed to bind mount directory %s to %s"),
|
||||||
src, fs->dst);
|
src, fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs->readonly) {
|
if (fs->readonly) {
|
||||||
@ -1202,11 +1160,7 @@ static int lxcContainerMountFSBind(virDomainFSDefPtr fs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(src);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1307,14 +1261,14 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
bool tryProc = false;
|
bool tryProc = false;
|
||||||
bool gotStar = false;
|
bool gotStar = false;
|
||||||
char *fslist = NULL;
|
g_autofree char *fslist = NULL;
|
||||||
char *line = NULL;
|
|
||||||
const char *type;
|
const char *type;
|
||||||
|
|
||||||
VIR_DEBUG("src=%s dst=%s srcprefix=%s", src, fs->dst, srcprefix);
|
VIR_DEBUG("src=%s dst=%s srcprefix=%s", src, fs->dst, srcprefix);
|
||||||
|
|
||||||
/* First time around we use /etc/filesystems */
|
/* First time around we use /etc/filesystems */
|
||||||
retry:
|
retry:
|
||||||
|
g_free(fslist);
|
||||||
fslist = g_strdup_printf("%s%s", srcprefix,
|
fslist = g_strdup_printf("%s%s", srcprefix,
|
||||||
tryProc ? "/proc/filesystems" : "/etc/filesystems");
|
tryProc ? "/proc/filesystems" : "/etc/filesystems");
|
||||||
|
|
||||||
@ -1326,7 +1280,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
|
|||||||
if (errno == ENOENT &&
|
if (errno == ENOENT &&
|
||||||
!tryProc) {
|
!tryProc) {
|
||||||
tryProc = true;
|
tryProc = true;
|
||||||
VIR_FREE(fslist);
|
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1337,8 +1290,8 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!feof(fp)) {
|
while (!feof(fp)) {
|
||||||
|
g_autofree char *line = NULL;
|
||||||
size_t n;
|
size_t n;
|
||||||
VIR_FREE(line);
|
|
||||||
if (getline(&line, &n, fp) <= 0) {
|
if (getline(&line, &n, fp) <= 0) {
|
||||||
if (feof(fp))
|
if (feof(fp))
|
||||||
break;
|
break;
|
||||||
@ -1401,7 +1354,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
|
|||||||
!tryProc &&
|
!tryProc &&
|
||||||
gotStar) {
|
gotStar) {
|
||||||
tryProc = true;
|
tryProc = true;
|
||||||
VIR_FREE(fslist);
|
|
||||||
VIR_FORCE_FCLOSE(fp);
|
VIR_FORCE_FCLOSE(fp);
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
@ -1415,8 +1367,6 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
|
|||||||
VIR_DEBUG("Done mounting filesystem ret=%d tryProc=%d", ret, tryProc);
|
VIR_DEBUG("Done mounting filesystem ret=%d tryProc=%d", ret, tryProc);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(line);
|
|
||||||
VIR_FREE(fslist);
|
|
||||||
VIR_FORCE_FCLOSE(fp);
|
VIR_FORCE_FCLOSE(fp);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1432,8 +1382,7 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
|
|||||||
const char *sec_mount_options)
|
const char *sec_mount_options)
|
||||||
{
|
{
|
||||||
int fsflags = 0;
|
int fsflags = 0;
|
||||||
int ret = -1;
|
g_autofree char *format = NULL;
|
||||||
char *format = NULL;
|
|
||||||
|
|
||||||
if (fs->readonly)
|
if (fs->readonly)
|
||||||
fsflags |= MS_RDONLY;
|
fsflags |= MS_RDONLY;
|
||||||
@ -1442,11 +1391,11 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lxcContainerMountDetectFilesystem(src, &format) < 0)
|
if (lxcContainerMountDetectFilesystem(src, &format) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (format) {
|
if (format) {
|
||||||
VIR_DEBUG("Mount '%s' on '%s' with detected format '%s' opts '%s'",
|
VIR_DEBUG("Mount '%s' on '%s' with detected format '%s' opts '%s'",
|
||||||
@ -1455,16 +1404,12 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount device %s to %s as %s"),
|
_("Failed to mount device %s to %s as %s"),
|
||||||
src, fs->dst, format);
|
src, fs->dst, format);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
ret = lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix, sec_mount_options);
|
return lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix, sec_mount_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(format);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1472,7 +1417,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
|
|||||||
const char *srcprefix,
|
const char *srcprefix,
|
||||||
const char *sec_mount_options)
|
const char *sec_mount_options)
|
||||||
{
|
{
|
||||||
char *src = NULL;
|
g_autofree char *src = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
|
VIR_DEBUG("src=%s dst=%s", fs->src->path, fs->dst);
|
||||||
@ -1483,7 +1428,6 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
|
|||||||
|
|
||||||
VIR_DEBUG("Done mounting filesystem ret=%d", ret);
|
VIR_DEBUG("Done mounting filesystem ret=%d", ret);
|
||||||
|
|
||||||
VIR_FREE(src);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1491,8 +1435,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
|
|||||||
static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
|
static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
|
||||||
char *sec_mount_options)
|
char *sec_mount_options)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *data = NULL;
|
||||||
char *data = NULL;
|
|
||||||
|
|
||||||
VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
|
VIR_DEBUG("usage=%lld sec=%s", fs->usage, sec_mount_options);
|
||||||
|
|
||||||
@ -1502,14 +1445,14 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create %s"),
|
_("Failed to create %s"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mount("tmpfs", fs->dst, "tmpfs", MS_NOSUID|MS_NODEV, data) < 0) {
|
if (mount("tmpfs", fs->dst, "tmpfs", MS_NOSUID|MS_NODEV, data) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to mount directory %s as tmpfs"),
|
_("Failed to mount directory %s as tmpfs"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs->readonly) {
|
if (fs->readonly) {
|
||||||
@ -1518,15 +1461,11 @@ static int lxcContainerMountFSTmpfs(virDomainFSDefPtr fs,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to make directory %s readonly"),
|
_("Failed to make directory %s readonly"),
|
||||||
fs->dst);
|
fs->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(data);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1600,8 +1539,8 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
|
|||||||
|
|
||||||
int lxcContainerSetupHostdevCapsMakePath(const char *dev)
|
int lxcContainerSetupHostdevCapsMakePath(const char *dev)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *dir = NULL;
|
||||||
char *dir, *tmp;
|
char *tmp;
|
||||||
|
|
||||||
dir = g_strdup(dev);
|
dir = g_strdup(dev);
|
||||||
|
|
||||||
@ -1611,30 +1550,25 @@ int lxcContainerSetupHostdevCapsMakePath(const char *dev)
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Failed to create directory for '%s' dev '%s'"),
|
_("Failed to create directory for '%s' dev '%s'"),
|
||||||
dir, dev);
|
dir, dev);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dir);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int lxcContainerUnmountForSharedRoot(const char *stateDir,
|
static int lxcContainerUnmountForSharedRoot(const char *stateDir,
|
||||||
const char *domain)
|
const char *domain)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *tmp = NULL;
|
||||||
char *tmp = NULL;
|
|
||||||
|
|
||||||
#if WITH_SELINUX
|
#if WITH_SELINUX
|
||||||
/* Some versions of Linux kernel don't let you overmount
|
/* Some versions of Linux kernel don't let you overmount
|
||||||
* the selinux filesystem, so make sure we kill it first
|
* the selinux filesystem, so make sure we kill it first
|
||||||
*/
|
*/
|
||||||
if (lxcContainerUnmountSubtree(SELINUX_MOUNT, false) < 0)
|
if (lxcContainerUnmountSubtree(SELINUX_MOUNT, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* These filesystems are created by libvirt temporarily, they
|
/* These filesystems are created by libvirt temporarily, they
|
||||||
@ -1642,20 +1576,20 @@ static int lxcContainerUnmountForSharedRoot(const char *stateDir,
|
|||||||
tmp = g_strdup_printf("%s/%s.dev", stateDir, domain);
|
tmp = g_strdup_printf("%s/%s.dev", stateDir, domain);
|
||||||
|
|
||||||
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_FREE(tmp);
|
g_free(tmp);
|
||||||
tmp = g_strdup_printf("%s/%s.devpts", stateDir, domain);
|
tmp = g_strdup_printf("%s/%s.devpts", stateDir, domain);
|
||||||
|
|
||||||
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
#if WITH_FUSE
|
#if WITH_FUSE
|
||||||
VIR_FREE(tmp);
|
g_free(tmp);
|
||||||
tmp = g_strdup_printf("%s/%s.fuse", stateDir, domain);
|
tmp = g_strdup_printf("%s/%s.fuse", stateDir, domain);
|
||||||
|
|
||||||
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
if (lxcContainerUnmountSubtree(tmp, false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* If we have the root source being '/', then we need to
|
/* If we have the root source being '/', then we need to
|
||||||
@ -1665,13 +1599,9 @@ static int lxcContainerUnmountForSharedRoot(const char *stateDir,
|
|||||||
if (lxcContainerUnmountSubtree("/sys", false) < 0 ||
|
if (lxcContainerUnmountSubtree("/sys", false) < 0 ||
|
||||||
lxcContainerUnmountSubtree("/dev", false) < 0 ||
|
lxcContainerUnmountSubtree("/dev", false) < 0 ||
|
||||||
lxcContainerUnmountSubtree("/proc", false) < 0)
|
lxcContainerUnmountSubtree("/proc", false) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1704,8 +1634,8 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
|||||||
{
|
{
|
||||||
virCgroupPtr cgroup = NULL;
|
virCgroupPtr cgroup = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *sec_mount_options;
|
g_autofree char *sec_mount_options = NULL;
|
||||||
char *stateDir = NULL;
|
g_autofree char *stateDir = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("Setup pivot root");
|
VIR_DEBUG("Setup pivot root");
|
||||||
|
|
||||||
@ -1776,9 +1706,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(stateDir);
|
|
||||||
virCgroupFree(&cgroup);
|
virCgroupFree(&cgroup);
|
||||||
VIR_FREE(sec_mount_options);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2128,9 +2056,8 @@ static const char hostname_validchars[] =
|
|||||||
|
|
||||||
static int lxcContainerSetHostname(virDomainDefPtr def)
|
static int lxcContainerSetHostname(virDomainDefPtr def)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *name = NULL;
|
||||||
char *name = NULL;
|
const char *hostname = NULL;
|
||||||
char *hostname = NULL;
|
|
||||||
|
|
||||||
/* Filter the VM name to get a valid hostname */
|
/* Filter the VM name to get a valid hostname */
|
||||||
name = g_strdup(def->name);
|
name = g_strdup(def->name);
|
||||||
@ -2143,13 +2070,10 @@ static int lxcContainerSetHostname(virDomainDefPtr def)
|
|||||||
|
|
||||||
if (sethostname(hostname, strlen(hostname)) < 0) {
|
if (sethostname(hostname, strlen(hostname)) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("Failed to set hostname"));
|
virReportSystemError(errno, "%s", _("Failed to set hostname"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FREE(name);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2170,11 +2094,11 @@ static int lxcContainerChild(void *data)
|
|||||||
virDomainDefPtr vmDef = argv->config;
|
virDomainDefPtr vmDef = argv->config;
|
||||||
int ttyfd = -1;
|
int ttyfd = -1;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *ttyPath = NULL;
|
g_autofree char *ttyPath = NULL;
|
||||||
virDomainFSDefPtr root;
|
virDomainFSDefPtr root;
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
int hasReboot;
|
int hasReboot;
|
||||||
gid_t *groups = NULL;
|
g_autofree gid_t *groups = NULL;
|
||||||
int ngroups;
|
int ngroups;
|
||||||
|
|
||||||
if (NULL == vmDef) {
|
if (NULL == vmDef) {
|
||||||
@ -2303,7 +2227,6 @@ static int lxcContainerChild(void *data)
|
|||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(ttyPath);
|
|
||||||
VIR_FORCE_CLOSE(ttyfd);
|
VIR_FORCE_CLOSE(ttyfd);
|
||||||
VIR_FORCE_CLOSE(argv->monitor);
|
VIR_FORCE_CLOSE(argv->monitor);
|
||||||
VIR_FORCE_CLOSE(argv->handshakefd);
|
VIR_FORCE_CLOSE(argv->handshakefd);
|
||||||
@ -2321,7 +2244,6 @@ static int lxcContainerChild(void *data)
|
|||||||
virGetLastErrorMessage());
|
virGetLastErrorMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(groups);
|
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -2383,7 +2305,8 @@ int lxcContainerStart(virDomainDefPtr def,
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int cflags;
|
int cflags;
|
||||||
int stacksize = getpagesize() * 4;
|
int stacksize = getpagesize() * 4;
|
||||||
char *stack, *stacktop;
|
g_autofree char *stack = NULL;
|
||||||
|
char *stacktop;
|
||||||
lxc_child_argv_t args = {
|
lxc_child_argv_t args = {
|
||||||
.config = def,
|
.config = def,
|
||||||
.securityDriver = securityDriver,
|
.securityDriver = securityDriver,
|
||||||
@ -2410,7 +2333,6 @@ int lxcContainerStart(virDomainDefPtr def,
|
|||||||
if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_USER) < 0) {
|
if (virProcessNamespaceAvailable(VIR_PROCESS_NAMESPACE_USER) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Kernel doesn't support user namespace"));
|
_("Kernel doesn't support user namespace"));
|
||||||
VIR_FREE(stack);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Enable user namespace");
|
VIR_DEBUG("Enable user namespace");
|
||||||
@ -2426,7 +2348,6 @@ int lxcContainerStart(virDomainDefPtr def,
|
|||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
_("Config asks for inherit net namespace "
|
_("Config asks for inherit net namespace "
|
||||||
"as well as private network interfaces"));
|
"as well as private network interfaces"));
|
||||||
VIR_FREE(stack);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
VIR_DEBUG("Inheriting a net namespace");
|
VIR_DEBUG("Inheriting a net namespace");
|
||||||
@ -2446,7 +2367,6 @@ int lxcContainerStart(virDomainDefPtr def,
|
|||||||
|
|
||||||
VIR_DEBUG("Cloning container init process");
|
VIR_DEBUG("Cloning container init process");
|
||||||
pid = clone(lxcContainerChild, stacktop, cflags, &args);
|
pid = clone(lxcContainerChild, stacktop, cflags, &args);
|
||||||
VIR_FREE(stack);
|
|
||||||
VIR_DEBUG("clone() completed, new container PID is %d", pid);
|
VIR_DEBUG("clone() completed, new container PID is %d", pid);
|
||||||
|
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
@ -191,7 +191,7 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
|
|||||||
{
|
{
|
||||||
virLXCControllerPtr ctrl = NULL;
|
virLXCControllerPtr ctrl = NULL;
|
||||||
virLXCDriverPtr driver = NULL;
|
virLXCDriverPtr driver = NULL;
|
||||||
char *configFile = NULL;
|
g_autofree char *configFile = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ctrl) < 0)
|
if (VIR_ALLOC(ctrl) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -220,7 +220,6 @@ static virLXCControllerPtr virLXCControllerNew(const char *name)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
|
||||||
virLXCControllerDriverFree(driver);
|
virLXCControllerDriverFree(driver);
|
||||||
return ctrl;
|
return ctrl;
|
||||||
|
|
||||||
@ -288,22 +287,22 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
|||||||
virObjectUnref(ctrl->securityManager);
|
virObjectUnref(ctrl->securityManager);
|
||||||
|
|
||||||
for (i = 0; i < ctrl->nveths; i++)
|
for (i = 0; i < ctrl->nveths; i++)
|
||||||
VIR_FREE(ctrl->veths[i]);
|
g_free(ctrl->veths[i]);
|
||||||
VIR_FREE(ctrl->veths);
|
g_free(ctrl->veths);
|
||||||
VIR_FREE(ctrl->nicindexes);
|
g_free(ctrl->nicindexes);
|
||||||
|
|
||||||
for (i = 0; i < ctrl->npassFDs; i++)
|
for (i = 0; i < ctrl->npassFDs; i++)
|
||||||
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
VIR_FORCE_CLOSE(ctrl->passFDs[i]);
|
||||||
VIR_FREE(ctrl->passFDs);
|
g_free(ctrl->passFDs);
|
||||||
|
|
||||||
for (i = 0; i < ctrl->nconsoles; i++)
|
for (i = 0; i < ctrl->nconsoles; i++)
|
||||||
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
virLXCControllerConsoleClose(&(ctrl->consoles[i]));
|
||||||
VIR_FREE(ctrl->consoles);
|
g_free(ctrl->consoles);
|
||||||
|
|
||||||
VIR_FREE(ctrl->devptmx);
|
g_free(ctrl->devptmx);
|
||||||
|
|
||||||
virDomainObjEndAPI(&ctrl->vm);
|
virDomainObjEndAPI(&ctrl->vm);
|
||||||
VIR_FREE(ctrl->name);
|
g_free(ctrl->name);
|
||||||
|
|
||||||
if (ctrl->timerShutdown != -1)
|
if (ctrl->timerShutdown != -1)
|
||||||
virEventRemoveTimeout(ctrl->timerShutdown);
|
virEventRemoveTimeout(ctrl->timerShutdown);
|
||||||
@ -311,14 +310,14 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
|||||||
virObjectUnref(ctrl->daemon);
|
virObjectUnref(ctrl->daemon);
|
||||||
virLXCControllerFreeFuse(ctrl);
|
virLXCControllerFreeFuse(ctrl);
|
||||||
|
|
||||||
VIR_FREE(ctrl->nbdpids);
|
g_free(ctrl->nbdpids);
|
||||||
|
|
||||||
VIR_FREE(ctrl->nsFDs);
|
g_free(ctrl->nsFDs);
|
||||||
virCgroupFree(&ctrl->cgroup);
|
virCgroupFree(&ctrl->cgroup);
|
||||||
|
|
||||||
/* This must always be the last thing to be closed */
|
/* This must always be the last thing to be closed */
|
||||||
VIR_FORCE_CLOSE(ctrl->handshakeFd);
|
VIR_FORCE_CLOSE(ctrl->handshakeFd);
|
||||||
VIR_FREE(ctrl);
|
g_free(ctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -469,7 +468,7 @@ static int virLXCControllerSetupLoopDeviceFS(virDomainFSDefPtr fs)
|
|||||||
* the rest of container setup 'just works'
|
* the rest of container setup 'just works'
|
||||||
*/
|
*/
|
||||||
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
||||||
VIR_FREE(fs->src->path);
|
g_free(fs->src->path);
|
||||||
fs->src->path = loname;
|
fs->src->path = loname;
|
||||||
loname = NULL;
|
loname = NULL;
|
||||||
|
|
||||||
@ -480,7 +479,7 @@ static int virLXCControllerSetupLoopDeviceFS(virDomainFSDefPtr fs)
|
|||||||
static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
|
static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
|
||||||
{
|
{
|
||||||
int lofd;
|
int lofd;
|
||||||
char *loname = NULL;
|
g_autofree char *loname = NULL;
|
||||||
const char *src = virDomainDiskGetSource(disk);
|
const char *src = virDomainDiskGetSource(disk);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -501,7 +500,6 @@ static int virLXCControllerSetupLoopDeviceDisk(virDomainDiskDefPtr disk)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(loname);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
VIR_FORCE_CLOSE(lofd);
|
VIR_FORCE_CLOSE(lofd);
|
||||||
|
|
||||||
@ -533,7 +531,7 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFSDefPtr fs)
|
|||||||
* the rest of container setup 'just works'
|
* the rest of container setup 'just works'
|
||||||
*/
|
*/
|
||||||
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
fs->type = VIR_DOMAIN_FS_TYPE_BLOCK;
|
||||||
VIR_FREE(fs->src->path);
|
g_free(fs->src->path);
|
||||||
fs->src->path = dev;
|
fs->src->path = dev;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -542,7 +540,7 @@ static int virLXCControllerSetupNBDDeviceFS(virDomainFSDefPtr fs)
|
|||||||
|
|
||||||
static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
|
static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
|
||||||
{
|
{
|
||||||
char *dev;
|
g_autofree char *dev = NULL;
|
||||||
const char *src = virDomainDiskGetSource(disk);
|
const char *src = virDomainDiskGetSource(disk);
|
||||||
int format = virDomainDiskGetFormat(disk);
|
int format = virDomainDiskGetFormat(disk);
|
||||||
|
|
||||||
@ -565,11 +563,8 @@ static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
|
|||||||
* the rest of container setup 'just works'
|
* the rest of container setup 'just works'
|
||||||
*/
|
*/
|
||||||
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
|
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_BLOCK);
|
||||||
if (virDomainDiskSetSource(disk, dev) < 0) {
|
if (virDomainDiskSetSource(disk, dev) < 0)
|
||||||
VIR_FREE(dev);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
VIR_FREE(dev);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -577,16 +572,15 @@ static int virLXCControllerSetupNBDDeviceDisk(virDomainDiskDefPtr disk)
|
|||||||
static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
|
static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
|
||||||
const char *dev)
|
const char *dev)
|
||||||
{
|
{
|
||||||
char *pidpath = NULL;
|
g_autofree char *pidpath = NULL;
|
||||||
pid_t *pids = NULL;
|
g_autofree pid_t *pids = NULL;
|
||||||
size_t npids = 0;
|
size_t npids = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
|
||||||
size_t loops = 0;
|
size_t loops = 0;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (!STRPREFIX(dev, "/dev/"))
|
if (!STRPREFIX(dev, "/dev/"))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
pidpath = g_strdup_printf("/sys/devices/virtual/block/%s/pid", dev + 5);
|
pidpath = g_strdup_printf("/sys/devices/virtual/block/%s/pid", dev + 5);
|
||||||
|
|
||||||
@ -600,27 +594,22 @@ static int virLXCControllerAppendNBDPids(virLXCControllerPtr ctrl,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Cannot check NBD device %s pid"),
|
_("Cannot check NBD device %s pid"),
|
||||||
dev + 5);
|
dev + 5);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virPidFileReadPath(pidpath, &pid) < 0)
|
if (virPidFileReadPath(pidpath, &pid) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virProcessGetPids(pid, &npids, &pids) < 0)
|
if (virProcessGetPids(pid, &npids, &pids) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < npids; i++) {
|
for (i = 0; i < npids; i++) {
|
||||||
if (VIR_APPEND_ELEMENT(ctrl->nbdpids, ctrl->nnbdpids, pids[i]) < 0)
|
if (VIR_APPEND_ELEMENT(ctrl->nbdpids, ctrl->nnbdpids, pids[i]) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(pids);
|
|
||||||
VIR_FREE(pidpath);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
static int virLXCControllerSetupLoopDevices(virLXCControllerPtr ctrl)
|
||||||
@ -957,7 +946,7 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
|
|||||||
{
|
{
|
||||||
virNetServerPtr srv = NULL;
|
virNetServerPtr srv = NULL;
|
||||||
virNetServerServicePtr svc = NULL;
|
virNetServerServicePtr svc = NULL;
|
||||||
char *sockpath;
|
g_autofree char *sockpath = NULL;
|
||||||
|
|
||||||
sockpath = g_strdup_printf("%s/%s.sock", LXC_STATE_DIR, ctrl->name);
|
sockpath = g_strdup_printf("%s/%s.sock", LXC_STATE_DIR, ctrl->name);
|
||||||
|
|
||||||
@ -1002,11 +991,9 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
virNetDaemonUpdateServices(ctrl->daemon, true);
|
virNetDaemonUpdateServices(ctrl->daemon, true);
|
||||||
VIR_FREE(sockpath);
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(sockpath);
|
|
||||||
virObjectUnref(srv);
|
virObjectUnref(srv);
|
||||||
virObjectUnref(ctrl->daemon);
|
virObjectUnref(ctrl->daemon);
|
||||||
ctrl->daemon = NULL;
|
ctrl->daemon = NULL;
|
||||||
@ -1606,11 +1593,10 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
|
|||||||
virDomainHostdevDefPtr def,
|
virDomainHostdevDefPtr def,
|
||||||
virSecurityManagerPtr securityDriver)
|
virSecurityManagerPtr securityDriver)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
g_autofree char *src = NULL;
|
||||||
char *src = NULL;
|
g_autofree char *dstdir = NULL;
|
||||||
char *dstdir = NULL;
|
g_autofree char *dstfile = NULL;
|
||||||
char *dstfile = NULL;
|
g_autofree char *vroot = NULL;
|
||||||
char *vroot = NULL;
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
|
virDomainHostdevSubsysUSBPtr usbsrc = &def->source.subsys.u.usb;
|
||||||
@ -1626,14 +1612,14 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
|
|||||||
if (stat(src, &sb) < 0) {
|
if (stat(src, &sb) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Unable to access %s"), src);
|
_("Unable to access %s"), src);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!S_ISCHR(sb.st_mode)) {
|
if (!S_ISCHR(sb.st_mode)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("USB source %s was not a character device"),
|
_("USB source %s was not a character device"),
|
||||||
src);
|
src);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
mode = 0700 | S_IFCHR;
|
mode = 0700 | S_IFCHR;
|
||||||
@ -1641,7 +1627,7 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
|
|||||||
if (virFileMakePath(dstdir) < 0) {
|
if (virFileMakePath(dstdir) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Unable to create %s"), dstdir);
|
_("Unable to create %s"), dstdir);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Creating dev %s (%d,%d)",
|
VIR_DEBUG("Creating dev %s (%d,%d)",
|
||||||
@ -1650,24 +1636,17 @@ virLXCControllerSetupHostdevSubsysUSB(virDomainDefPtr vmDef,
|
|||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Unable to create device %s"),
|
_("Unable to create device %s"),
|
||||||
dstfile);
|
dstfile);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lxcContainerChown(vmDef, dstfile) < 0)
|
if (lxcContainerChown(vmDef, dstfile) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virSecurityManagerSetHostdevLabel(securityDriver,
|
if (virSecurityManagerSetHostdevLabel(securityDriver,
|
||||||
vmDef, def, vroot) < 0)
|
vmDef, def, vroot) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(src);
|
|
||||||
VIR_FREE(dstfile);
|
|
||||||
VIR_FREE(dstdir);
|
|
||||||
VIR_FREE(vroot);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1676,8 +1655,8 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
|
|||||||
virDomainHostdevDefPtr def,
|
virDomainHostdevDefPtr def,
|
||||||
virSecurityManagerPtr securityDriver)
|
virSecurityManagerPtr securityDriver)
|
||||||
{
|
{
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
@ -1741,8 +1720,6 @@ virLXCControllerSetupHostdevCapsStorage(virDomainDefPtr vmDef,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
def->source.caps.u.storage.block = dev;
|
def->source.caps.u.storage.block = dev;
|
||||||
VIR_FREE(dst);
|
|
||||||
VIR_FREE(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1752,8 +1729,8 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
|
|||||||
virDomainHostdevDefPtr def,
|
virDomainHostdevDefPtr def,
|
||||||
virSecurityManagerPtr securityDriver)
|
virSecurityManagerPtr securityDriver)
|
||||||
{
|
{
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
@ -1817,8 +1794,6 @@ virLXCControllerSetupHostdevCapsMisc(virDomainDefPtr vmDef,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
def->source.caps.u.misc.chardev = dev;
|
def->source.caps.u.misc.chardev = dev;
|
||||||
VIR_FREE(dst);
|
|
||||||
VIR_FREE(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1910,7 +1885,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
|
|||||||
virDomainDiskDefPtr def,
|
virDomainDiskDefPtr def,
|
||||||
virSecurityManagerPtr securityDriver)
|
virSecurityManagerPtr securityDriver)
|
||||||
{
|
{
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
@ -1979,7 +1954,6 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
def->src->path = tmpsrc;
|
def->src->path = tmpsrc;
|
||||||
VIR_FREE(dst);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2125,7 +2099,8 @@ lxcCreateTty(virLXCControllerPtr ctrl, int *ttymaster,
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
VIR_FORCE_CLOSE(*ttymaster);
|
VIR_FORCE_CLOSE(*ttymaster);
|
||||||
VIR_FREE(*ttyName);
|
g_free(*ttyName);
|
||||||
|
*ttyName = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -2233,9 +2208,10 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl,
|
|||||||
char **containerTTYPaths)
|
char **containerTTYPaths)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
g_autofree char *ttyHostPath = NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < ctrl->nconsoles; i++) {
|
for (i = 0; i < ctrl->nconsoles; i++) {
|
||||||
|
g_autofree char *ttyHostPath = NULL;
|
||||||
|
|
||||||
VIR_DEBUG("Opening tty on private %s", ctrl->devptmx);
|
VIR_DEBUG("Opening tty on private %s", ctrl->devptmx);
|
||||||
if (lxcCreateTty(ctrl,
|
if (lxcCreateTty(ctrl,
|
||||||
&ctrl->consoles[i].contFd,
|
&ctrl->consoles[i].contFd,
|
||||||
@ -2248,8 +2224,6 @@ virLXCControllerSetupConsoles(virLXCControllerPtr ctrl,
|
|||||||
/* Change the owner of tty device to the root user of container */
|
/* Change the owner of tty device to the root user of container */
|
||||||
if (lxcContainerChown(ctrl->def, ttyHostPath) < 0)
|
if (lxcContainerChown(ctrl->def, ttyHostPath) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
VIR_FREE(ttyHostPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -2484,8 +2458,8 @@ virLXCControllerRun(virLXCControllerPtr ctrl)
|
|||||||
VIR_FORCE_CLOSE(containerhandshake[1]);
|
VIR_FORCE_CLOSE(containerhandshake[1]);
|
||||||
|
|
||||||
for (i = 0; i < ctrl->nconsoles; i++)
|
for (i = 0; i < ctrl->nconsoles; i++)
|
||||||
VIR_FREE(containerTTYPaths[i]);
|
g_free(containerTTYPaths[i]);
|
||||||
VIR_FREE(containerTTYPaths);
|
g_free(containerTTYPaths);
|
||||||
|
|
||||||
virLXCControllerStopInit(ctrl);
|
virLXCControllerStopInit(ctrl);
|
||||||
|
|
||||||
@ -2517,9 +2491,9 @@ int main(int argc, char *argv[])
|
|||||||
{ "help", 0, NULL, 'h' },
|
{ "help", 0, NULL, 'h' },
|
||||||
{ 0, 0, 0, 0 },
|
{ 0, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
int *ttyFDs = NULL;
|
g_autofree int *ttyFDs = NULL;
|
||||||
size_t nttyFDs = 0;
|
size_t nttyFDs = 0;
|
||||||
int *passFDs = NULL;
|
g_autofree int *passFDs = NULL;
|
||||||
size_t npassFDs = 0;
|
size_t npassFDs = 0;
|
||||||
virLXCControllerPtr ctrl = NULL;
|
virLXCControllerPtr ctrl = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -2760,10 +2734,8 @@ int main(int argc, char *argv[])
|
|||||||
virLXCControllerDeleteInterfaces(ctrl);
|
virLXCControllerDeleteInterfaces(ctrl);
|
||||||
for (i = 0; i < nttyFDs; i++)
|
for (i = 0; i < nttyFDs; i++)
|
||||||
VIR_FORCE_CLOSE(ttyFDs[i]);
|
VIR_FORCE_CLOSE(ttyFDs[i]);
|
||||||
VIR_FREE(ttyFDs);
|
|
||||||
for (i = 0; i < npassFDs; i++)
|
for (i = 0; i < npassFDs; i++)
|
||||||
VIR_FORCE_CLOSE(passFDs[i]);
|
VIR_FORCE_CLOSE(passFDs[i]);
|
||||||
VIR_FREE(passFDs);
|
|
||||||
|
|
||||||
virLXCControllerFree(ctrl);
|
virLXCControllerFree(ctrl);
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ virLXCDomainObjPrivateAlloc(void *opaque G_GNUC_UNUSED)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virLXCDomainObjInitJob(priv) < 0) {
|
if (virLXCDomainObjInitJob(priv) < 0) {
|
||||||
VIR_FREE(priv);
|
g_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ virLXCDomainObjPrivateFree(void *data)
|
|||||||
|
|
||||||
virCgroupFree(&priv->cgroup);
|
virCgroupFree(&priv->cgroup);
|
||||||
virLXCDomainObjFreeJob(priv);
|
virLXCDomainObjFreeJob(priv);
|
||||||
VIR_FREE(priv);
|
g_free(priv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -200,8 +200,8 @@ lxcDomainDefNamespaceFree(void *nsdata)
|
|||||||
size_t i;
|
size_t i;
|
||||||
lxcDomainDefPtr lxcDef = nsdata;
|
lxcDomainDefPtr lxcDef = nsdata;
|
||||||
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
|
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++)
|
||||||
VIR_FREE(lxcDef->ns_val[i]);
|
g_free(lxcDef->ns_val[i]);
|
||||||
VIR_FREE(nsdata);
|
g_free(nsdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -209,12 +209,11 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
|
|||||||
void **data)
|
void **data)
|
||||||
{
|
{
|
||||||
lxcDomainDefPtr lxcDef = NULL;
|
lxcDomainDefPtr lxcDef = NULL;
|
||||||
xmlNodePtr *nodes = NULL;
|
g_autofree xmlNodePtr *nodes = NULL;
|
||||||
bool uses_lxc_ns = false;
|
bool uses_lxc_ns = false;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
int feature;
|
int feature;
|
||||||
int n;
|
int n;
|
||||||
char *tmp = NULL;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if (VIR_ALLOC(lxcDef) < 0)
|
if (VIR_ALLOC(lxcDef) < 0)
|
||||||
@ -226,6 +225,7 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
|
|||||||
uses_lxc_ns |= n > 0;
|
uses_lxc_ns |= n > 0;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
g_autofree char *tmp = NULL;
|
||||||
if ((feature = virLXCDomainNamespaceTypeFromString(
|
if ((feature = virLXCDomainNamespaceTypeFromString(
|
||||||
(const char *)nodes[i]->name)) < 0) {
|
(const char *)nodes[i]->name)) < 0) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
@ -246,10 +246,8 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
|
|||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Unknown LXC namespace source '%s'"),
|
_("Unknown LXC namespace source '%s'"),
|
||||||
tmp);
|
tmp);
|
||||||
VIR_FREE(tmp);
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(tmp);
|
|
||||||
|
|
||||||
if (!(lxcDef->ns_val[feature] =
|
if (!(lxcDef->ns_val[feature] =
|
||||||
virXMLPropString(nodes[i], "value"))) {
|
virXMLPropString(nodes[i], "value"))) {
|
||||||
@ -258,15 +256,13 @@ lxcDomainDefNamespaceParse(xmlXPathContextPtr ctxt,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
VIR_FREE(nodes);
|
|
||||||
ctxt->node = node;
|
ctxt->node = node;
|
||||||
if (uses_lxc_ns)
|
if (uses_lxc_ns)
|
||||||
*data = lxcDef;
|
*data = lxcDef;
|
||||||
else
|
else
|
||||||
VIR_FREE(lxcDef);
|
g_free(lxcDef);
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
VIR_FREE(nodes);
|
|
||||||
lxcDomainDefNamespaceFree(lxcDef);
|
lxcDomainDefNamespaceFree(lxcDef);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -496,7 +492,9 @@ virLXCDomainSetRunlevel(virDomainObjPtr vm,
|
|||||||
lxcDomainInitctlCallback,
|
lxcDomainInitctlCallback,
|
||||||
&data);
|
&data);
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(data.st);
|
g_free(data.st);
|
||||||
VIR_FREE(data.st_valid);
|
data.st = NULL;
|
||||||
|
g_free(data.st_valid);
|
||||||
|
data.st_valid = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1496,7 +1496,8 @@ static int lxcStateInitialize(bool privileged,
|
|||||||
return VIR_DRV_STATE_INIT_ERROR;
|
return VIR_DRV_STATE_INIT_ERROR;
|
||||||
lxc_driver->lockFD = -1;
|
lxc_driver->lockFD = -1;
|
||||||
if (virMutexInit(&lxc_driver->lock) < 0) {
|
if (virMutexInit(&lxc_driver->lock) < 0) {
|
||||||
VIR_FREE(lxc_driver);
|
g_free(lxc_driver);
|
||||||
|
lxc_driver = NULL;
|
||||||
return VIR_DRV_STATE_INIT_ERROR;
|
return VIR_DRV_STATE_INIT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1633,7 +1634,8 @@ static int lxcStateCleanup(void)
|
|||||||
|
|
||||||
virObjectUnref(lxc_driver->config);
|
virObjectUnref(lxc_driver->config);
|
||||||
virMutexDestroy(&lxc_driver->lock);
|
virMutexDestroy(&lxc_driver->lock);
|
||||||
VIR_FREE(lxc_driver);
|
g_free(lxc_driver);
|
||||||
|
lxc_driver = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2473,7 +2475,8 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
|
|||||||
{
|
{
|
||||||
virLXCDriverPtr driver = dom->conn->privateData;
|
virLXCDriverPtr driver = dom->conn->privateData;
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
char *configFile = NULL, *autostartLink = NULL;
|
g_autofree char *configFile = NULL;
|
||||||
|
g_autofree char *autostartLink = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
||||||
|
|
||||||
@ -2538,8 +2541,6 @@ static int lxcDomainSetAutostart(virDomainPtr dom,
|
|||||||
virLXCDomainObjEndJob(driver, vm);
|
virLXCDomainObjEndJob(driver, vm);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(configFile);
|
|
||||||
VIR_FREE(autostartLink);
|
|
||||||
virDomainObjEndAPI(&vm);
|
virDomainObjEndAPI(&vm);
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
@ -2551,8 +2552,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm)
|
|||||||
int check_interval = 1; /* In milliseconds */
|
int check_interval = 1; /* In milliseconds */
|
||||||
int exp = 10;
|
int exp = 10;
|
||||||
int waited_time = 0;
|
int waited_time = 0;
|
||||||
int ret = -1;
|
g_autofree char *state = NULL;
|
||||||
char *state = NULL;
|
|
||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
|
||||||
while (waited_time < timeout) {
|
while (waited_time < timeout) {
|
||||||
@ -2599,10 +2599,8 @@ static int lxcFreezeContainer(virDomainObjPtr vm)
|
|||||||
}
|
}
|
||||||
VIR_DEBUG("Read freezer.state: %s", state);
|
VIR_DEBUG("Read freezer.state: %s", state);
|
||||||
|
|
||||||
if (STREQ(state, "FROZEN")) {
|
if (STREQ(state, "FROZEN"))
|
||||||
ret = 0;
|
return 0;
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
waited_time += check_interval;
|
waited_time += check_interval;
|
||||||
/*
|
/*
|
||||||
@ -2614,7 +2612,6 @@ static int lxcFreezeContainer(virDomainObjPtr vm)
|
|||||||
* In that case, eager polling will just waste CPU time.
|
* In that case, eager polling will just waste CPU time.
|
||||||
*/
|
*/
|
||||||
check_interval *= exp;
|
check_interval *= exp;
|
||||||
VIR_FREE(state);
|
|
||||||
}
|
}
|
||||||
VIR_DEBUG("lxcFreezeContainer timeout");
|
VIR_DEBUG("lxcFreezeContainer timeout");
|
||||||
error:
|
error:
|
||||||
@ -2624,11 +2621,7 @@ static int lxcFreezeContainer(virDomainObjPtr vm)
|
|||||||
* This is likely to fall the group back again gracefully.
|
* This is likely to fall the group back again gracefully.
|
||||||
*/
|
*/
|
||||||
virCgroupSetFreezerState(priv->cgroup, "THAWED");
|
virCgroupSetFreezerState(priv->cgroup, "THAWED");
|
||||||
ret = -1;
|
return -1;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(state);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lxcDomainSuspend(virDomainPtr dom)
|
static int lxcDomainSuspend(virDomainPtr dom)
|
||||||
@ -3345,7 +3338,7 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
|
|||||||
virDomainDiskDefPtr def = dev->data.disk;
|
virDomainDiskDefPtr def = dev->data.disk;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char *file = NULL;
|
g_autofree char *file = NULL;
|
||||||
int perms;
|
int perms;
|
||||||
const char *src = NULL;
|
const char *src = NULL;
|
||||||
|
|
||||||
@ -3433,7 +3426,6 @@ lxcDomainAttachDeviceDiskLive(virLXCDriverPtr driver,
|
|||||||
cleanup:
|
cleanup:
|
||||||
if (src)
|
if (src)
|
||||||
virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
|
virDomainAuditDisk(vm, NULL, def->src, "attach", ret == 0);
|
||||||
VIR_FREE(file);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3584,7 +3576,7 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
|
|||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainHostdevDefPtr def = dev->data.hostdev;
|
virDomainHostdevDefPtr def = dev->data.hostdev;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *src = NULL;
|
g_autofree char *src = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
virUSBDevicePtr usb = NULL;
|
virUSBDevicePtr usb = NULL;
|
||||||
virDomainHostdevSubsysUSBPtr usbsrc;
|
virDomainHostdevSubsysUSBPtr usbsrc;
|
||||||
@ -3643,7 +3635,6 @@ lxcDomainAttachDeviceHostdevSubsysUSBLive(virLXCDriverPtr driver,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virDomainAuditHostdev(vm, def, "attach", ret == 0);
|
virDomainAuditHostdev(vm, def, "attach", ret == 0);
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
VIR_FREE(src);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3910,14 +3901,14 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
|
|||||||
{
|
{
|
||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainDiskDefPtr def = NULL;
|
virDomainDiskDefPtr def = NULL;
|
||||||
int idx, ret = -1;
|
int idx;
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
const char *src;
|
const char *src;
|
||||||
|
|
||||||
if (!priv->initpid) {
|
if (!priv->initpid) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("Cannot attach disk until init PID is known"));
|
_("Cannot attach disk until init PID is known"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((idx = virDomainDiskIndexByName(vm->def,
|
if ((idx = virDomainDiskIndexByName(vm->def,
|
||||||
@ -3925,7 +3916,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
|
|||||||
false)) < 0) {
|
false)) < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("disk %s not found"), dev->data.disk->dst);
|
_("disk %s not found"), dev->data.disk->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
def = vm->def->disks[idx];
|
def = vm->def->disks[idx];
|
||||||
@ -3936,12 +3927,12 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
|
|||||||
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
if (!virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_DEVICES)) {
|
||||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
_("devices cgroup isn't mounted"));
|
_("devices cgroup isn't mounted"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
|
if (lxcDomainAttachDeviceUnlink(vm, dst) < 0) {
|
||||||
virDomainAuditDisk(vm, def->src, NULL, "detach", false);
|
virDomainAuditDisk(vm, def->src, NULL, "detach", false);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
virDomainAuditDisk(vm, def->src, NULL, "detach", true);
|
virDomainAuditDisk(vm, def->src, NULL, "detach", true);
|
||||||
|
|
||||||
@ -3953,11 +3944,7 @@ lxcDomainDetachDeviceDiskLive(virDomainObjPtr vm,
|
|||||||
virDomainDiskRemove(vm->def, idx);
|
virDomainDiskRemove(vm->def, idx);
|
||||||
virDomainDiskDefFree(def);
|
virDomainDiskDefFree(def);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(dst);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -4055,7 +4042,7 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
|
|||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
virDomainHostdevDefPtr def = NULL;
|
virDomainHostdevDefPtr def = NULL;
|
||||||
int idx, ret = -1;
|
int idx, ret = -1;
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
virUSBDevicePtr usb = NULL;
|
virUSBDevicePtr usb = NULL;
|
||||||
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||||
virDomainHostdevSubsysUSBPtr usbsrc;
|
virDomainHostdevSubsysUSBPtr usbsrc;
|
||||||
@ -4103,7 +4090,6 @@ lxcDomainDetachDeviceHostdevUSBLive(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virUSBDeviceFree(usb);
|
virUSBDeviceFree(usb);
|
||||||
VIR_FREE(dst);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4948,8 +4934,6 @@ lxcDomainGetHostname(virDomainPtr dom,
|
|||||||
virDomainObjPtr vm = NULL;
|
virDomainObjPtr vm = NULL;
|
||||||
char macaddr[VIR_MAC_STRING_BUFLEN];
|
char macaddr[VIR_MAC_STRING_BUFLEN];
|
||||||
g_autoptr(virConnect) conn = NULL;
|
g_autoptr(virConnect) conn = NULL;
|
||||||
virNetworkDHCPLeasePtr *leases = NULL;
|
|
||||||
int n_leases;
|
|
||||||
size_t i, j;
|
size_t i, j;
|
||||||
char *hostname = NULL;
|
char *hostname = NULL;
|
||||||
|
|
||||||
@ -4973,6 +4957,8 @@ lxcDomainGetHostname(virDomainPtr dom,
|
|||||||
for (i = 0; i < vm->def->nnets; i++) {
|
for (i = 0; i < vm->def->nnets; i++) {
|
||||||
g_autoptr(virNetwork) network = NULL;
|
g_autoptr(virNetwork) network = NULL;
|
||||||
virDomainNetDefPtr net = vm->def->nets[i];
|
virDomainNetDefPtr net = vm->def->nets[i];
|
||||||
|
g_autofree virNetworkDHCPLeasePtr *leases = NULL;
|
||||||
|
int n_leases;
|
||||||
|
|
||||||
if (net->type != VIR_DOMAIN_NET_TYPE_NETWORK)
|
if (net->type != VIR_DOMAIN_NET_TYPE_NETWORK)
|
||||||
continue;
|
continue;
|
||||||
@ -4996,8 +4982,6 @@ lxcDomainGetHostname(virDomainPtr dom,
|
|||||||
virNetworkDHCPLeaseFree(lease);
|
virNetworkDHCPLeaseFree(lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(leases);
|
|
||||||
|
|
||||||
if (hostname)
|
if (hostname)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
@ -326,10 +326,10 @@ int lxcSetupFuse(virLXCFusePtr *f, virDomainDefPtr def)
|
|||||||
*f = fuse;
|
*f = fuse;
|
||||||
return ret;
|
return ret;
|
||||||
cleanup1:
|
cleanup1:
|
||||||
VIR_FREE(fuse->mountpoint);
|
g_free(fuse->mountpoint);
|
||||||
virMutexDestroy(&fuse->lock);
|
virMutexDestroy(&fuse->lock);
|
||||||
cleanup2:
|
cleanup2:
|
||||||
VIR_FREE(fuse);
|
g_free(fuse);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,8 +356,8 @@ void lxcFreeFuse(virLXCFusePtr *f)
|
|||||||
fuse_exit(fuse->fuse);
|
fuse_exit(fuse->fuse);
|
||||||
virMutexUnlock(&fuse->lock);
|
virMutexUnlock(&fuse->lock);
|
||||||
|
|
||||||
VIR_FREE(fuse->mountpoint);
|
g_free(fuse->mountpoint);
|
||||||
VIR_FREE(*f);
|
g_free(*f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -143,7 +143,7 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm,
|
|||||||
virLXCMonitorCallbacksPtr cb)
|
virLXCMonitorCallbacksPtr cb)
|
||||||
{
|
{
|
||||||
virLXCMonitorPtr mon;
|
virLXCMonitorPtr mon;
|
||||||
char *sockpath = NULL;
|
g_autofree char *sockpath = NULL;
|
||||||
|
|
||||||
if (virLXCMonitorInitialize() < 0)
|
if (virLXCMonitorInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -180,14 +180,11 @@ virLXCMonitorPtr virLXCMonitorNew(virDomainObjPtr vm,
|
|||||||
mon->vm = virObjectRef(vm);
|
mon->vm = virObjectRef(vm);
|
||||||
memcpy(&mon->cb, cb, sizeof(mon->cb));
|
memcpy(&mon->cb, cb, sizeof(mon->cb));
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(sockpath);
|
|
||||||
return mon;
|
return mon;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnref(mon);
|
virObjectUnref(mon);
|
||||||
mon = NULL;
|
return NULL;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,11 +93,11 @@ lxcFstabFree(lxcFstabPtr fstab)
|
|||||||
lxcFstabPtr next = NULL;
|
lxcFstabPtr next = NULL;
|
||||||
next = fstab->next;
|
next = fstab->next;
|
||||||
|
|
||||||
VIR_FREE(fstab->src);
|
g_free(fstab->src);
|
||||||
VIR_FREE(fstab->dst);
|
g_free(fstab->dst);
|
||||||
VIR_FREE(fstab->type);
|
g_free(fstab->type);
|
||||||
VIR_FREE(fstab->options);
|
g_free(fstab->options);
|
||||||
VIR_FREE(fstab);
|
g_free(fstab);
|
||||||
|
|
||||||
fstab = next;
|
fstab = next;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ lxcFstabFree(lxcFstabPtr fstab)
|
|||||||
|
|
||||||
static char ** lxcStringSplit(const char *string)
|
static char ** lxcStringSplit(const char *string)
|
||||||
{
|
{
|
||||||
char *tmp;
|
g_autofree char *tmp = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t ntokens = 0;
|
size_t ntokens = 0;
|
||||||
char **parts;
|
char **parts;
|
||||||
@ -136,12 +136,10 @@ static char ** lxcStringSplit(const char *string)
|
|||||||
result[ntokens - 2] = g_strdup(parts[i]);
|
result[ntokens - 2] = g_strdup(parts[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(tmp);
|
|
||||||
virStringListFree(parts);
|
virStringListFree(parts);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(tmp);
|
|
||||||
virStringListFree(parts);
|
virStringListFree(parts);
|
||||||
virStringListFree(result);
|
virStringListFree(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -257,7 +255,7 @@ static int
|
|||||||
lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
|
lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
|
||||||
{
|
{
|
||||||
const char *src = NULL;
|
const char *src = NULL;
|
||||||
char *dst = NULL;
|
g_autofree char *dst = NULL;
|
||||||
char **options = virStringSplit(fstab->options, ",", 0);
|
char **options = virStringSplit(fstab->options, ",", 0);
|
||||||
bool readonly;
|
bool readonly;
|
||||||
int type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
int type = VIR_DOMAIN_FS_TYPE_MOUNT;
|
||||||
@ -313,7 +311,6 @@ lxcAddFstabLine(virDomainDefPtr def, lxcFstabPtr fstab)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(dst);
|
|
||||||
virStringListFree(options);
|
virStringListFree(options);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -444,8 +441,8 @@ lxcAddNetworkRouteDefinition(const char *address,
|
|||||||
size_t *nroutes)
|
size_t *nroutes)
|
||||||
{
|
{
|
||||||
virNetDevIPRoutePtr route = NULL;
|
virNetDevIPRoutePtr route = NULL;
|
||||||
char *familyStr = NULL;
|
g_autofree char *familyStr = NULL;
|
||||||
char *zero = NULL;
|
g_autofree char *zero = NULL;
|
||||||
|
|
||||||
zero = g_strdup(family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL : VIR_SOCKET_ADDR_IPV6_ALL);
|
zero = g_strdup(family == AF_INET ? VIR_SOCKET_ADDR_IPV4_ALL : VIR_SOCKET_ADDR_IPV6_ALL);
|
||||||
|
|
||||||
@ -459,14 +456,9 @@ lxcAddNetworkRouteDefinition(const char *address,
|
|||||||
if (VIR_APPEND_ELEMENT(*routes, *nroutes, route) < 0)
|
if (VIR_APPEND_ELEMENT(*routes, *nroutes, route) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
VIR_FREE(familyStr);
|
|
||||||
VIR_FREE(zero);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
VIR_FREE(familyStr);
|
|
||||||
VIR_FREE(zero);
|
|
||||||
virNetDevIPRouteFree(route);
|
virNetDevIPRouteFree(route);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -499,7 +491,7 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data)
|
|||||||
/* This still requires the user to manually setup the vlan interface
|
/* This still requires the user to manually setup the vlan interface
|
||||||
* on the host */
|
* on the host */
|
||||||
if (isVlan && data->vlanid) {
|
if (isVlan && data->vlanid) {
|
||||||
VIR_FREE(hostdev->source.caps.u.net.ifname);
|
g_free(hostdev->source.caps.u.net.ifname);
|
||||||
hostdev->source.caps.u.net.ifname = g_strdup_printf("%s.%s",
|
hostdev->source.caps.u.net.ifname = g_strdup_printf("%s.%s",
|
||||||
data->link,
|
data->link,
|
||||||
data->vlanid);
|
data->vlanid);
|
||||||
@ -553,8 +545,9 @@ lxcAddNetworkDefinition(virDomainDefPtr def, lxcNetworkParseData *data)
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
for (i = 0; i < data->nips; i++)
|
for (i = 0; i < data->nips; i++)
|
||||||
VIR_FREE(data->ips[i]);
|
g_free(data->ips[i]);
|
||||||
VIR_FREE(data->ips);
|
g_free(data->ips);
|
||||||
|
data->ips = NULL;
|
||||||
virDomainNetDefFree(net);
|
virDomainNetDefFree(net);
|
||||||
virDomainHostdevDefFree(hostdev);
|
virDomainHostdevDefFree(hostdev);
|
||||||
return -1;
|
return -1;
|
||||||
@ -568,7 +561,7 @@ lxcNetworkParseDataIPs(const char *name,
|
|||||||
{
|
{
|
||||||
int family = AF_INET;
|
int family = AF_INET;
|
||||||
char **ipparts = NULL;
|
char **ipparts = NULL;
|
||||||
virNetDevIPAddrPtr ip = NULL;
|
g_autofree virNetDevIPAddrPtr ip = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ip) < 0)
|
if (VIR_ALLOC(ip) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -585,16 +578,13 @@ lxcNetworkParseDataIPs(const char *name,
|
|||||||
_("Invalid CIDR address: '%s'"), value->str);
|
_("Invalid CIDR address: '%s'"), value->str);
|
||||||
|
|
||||||
virStringListFree(ipparts);
|
virStringListFree(ipparts);
|
||||||
VIR_FREE(ip);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virStringListFree(ipparts);
|
virStringListFree(ipparts);
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0) {
|
if (VIR_APPEND_ELEMENT(parseData->ips, parseData->nips, ip) < 0)
|
||||||
VIR_FREE(ip);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -792,16 +782,18 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < networks.ndata; i++)
|
for (i = 0; i < networks.ndata; i++)
|
||||||
VIR_FREE(networks.parseData[i]);
|
g_free(networks.parseData[i]);
|
||||||
VIR_FREE(networks.parseData);
|
g_free(networks.parseData);
|
||||||
|
networks.parseData = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
for (i = 0; i < networks.ndata; i++) {
|
for (i = 0; i < networks.ndata; i++) {
|
||||||
lxcNetworkParseDataPtr data = networks.parseData[i];
|
lxcNetworkParseDataPtr data = networks.parseData[i];
|
||||||
for (j = 0; j < data->nips; j++)
|
for (j = 0; j < data->nips; j++)
|
||||||
VIR_FREE(data->ips[j]);
|
g_free(data->ips[j]);
|
||||||
VIR_FREE(data->ips);
|
g_free(data->ips);
|
||||||
|
data->ips = NULL;
|
||||||
}
|
}
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -905,7 +897,8 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
|
|||||||
size = size / 1024;
|
size = size / 1024;
|
||||||
virDomainDefSetMemoryTotal(def, size);
|
virDomainDefSetMemoryTotal(def, size);
|
||||||
def->mem.hard_limit = virMemoryLimitTruncate(size);
|
def->mem.hard_limit = virMemoryLimitTruncate(size);
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virConfGetValueString(properties,
|
if (virConfGetValueString(properties,
|
||||||
@ -914,7 +907,8 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr properties)
|
|||||||
if (lxcConvertSize(value, &size) < 0)
|
if (lxcConvertSize(value, &size) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
def->mem.soft_limit = virMemoryLimitTruncate(size / 1024);
|
def->mem.soft_limit = virMemoryLimitTruncate(size / 1024);
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virConfGetValueString(properties,
|
if (virConfGetValueString(properties,
|
||||||
@ -937,14 +931,16 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties)
|
|||||||
if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0)
|
if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
def->cputune.sharesSpecified = true;
|
def->cputune.sharesSpecified = true;
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us",
|
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us",
|
||||||
&value) > 0) {
|
&value) > 0) {
|
||||||
if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0)
|
if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us",
|
if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us",
|
||||||
@ -972,7 +968,8 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties)
|
|||||||
if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
|
def->placement_mode = VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC;
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems",
|
if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems",
|
||||||
@ -1001,7 +998,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data)
|
|||||||
virBlkioDevicePtr device = NULL;
|
virBlkioDevicePtr device = NULL;
|
||||||
virDomainDefPtr def = data;
|
virDomainDefPtr def = data;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!STRPREFIX(name, "lxc.cgroup.blkio.") ||
|
if (!STRPREFIX(name, "lxc.cgroup.blkio.") ||
|
||||||
@ -1077,8 +1074,6 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfValuePtr value, void *data)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virStringListFree(parts);
|
virStringListFree(parts);
|
||||||
VIR_FREE(path);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1172,7 +1167,8 @@ lxcParseConfigString(const char *config,
|
|||||||
else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64"))
|
else if (arch == VIR_ARCH_NONE && STREQ(value, "amd64"))
|
||||||
arch = VIR_ARCH_X86_64;
|
arch = VIR_ARCH_X86_64;
|
||||||
vmdef->os.arch = arch;
|
vmdef->os.arch = arch;
|
||||||
VIR_FREE(value);
|
g_free(value);
|
||||||
|
value = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
vmdef->os.init = g_strdup("/sbin/init");
|
vmdef->os.init = g_strdup("/sbin/init");
|
||||||
|
@ -135,14 +135,13 @@ static void
|
|||||||
lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg,
|
lxcProcessRemoveDomainStatus(virLXCDriverConfigPtr cfg,
|
||||||
virDomainObjPtr vm)
|
virDomainObjPtr vm)
|
||||||
{
|
{
|
||||||
char *file = NULL;
|
g_autofree char *file = g_strdup_printf("%s/%s.xml",
|
||||||
|
cfg->stateDir,
|
||||||
file = g_strdup_printf("%s/%s.xml", cfg->stateDir, vm->def->name);
|
vm->def->name);
|
||||||
|
|
||||||
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
|
if (unlink(file) < 0 && errno != ENOENT && errno != ENOTDIR)
|
||||||
VIR_WARN("Failed to remove domain XML for %s: %s",
|
VIR_WARN("Failed to remove domain XML for %s: %s",
|
||||||
vm->def->name, g_strerror(errno));
|
vm->def->name, g_strerror(errno));
|
||||||
VIR_FREE(file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -170,13 +169,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
/* now that we know it's stopped call the hook if present */
|
/* now that we know it's stopped call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
|
|
||||||
/* we can't stop the operation even if the script raised an error */
|
/* we can't stop the operation even if the script raised an error */
|
||||||
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END,
|
VIR_HOOK_LXC_OP_STOPPED, VIR_HOOK_SUBOP_END,
|
||||||
NULL, xml, NULL);
|
NULL, xml, NULL);
|
||||||
VIR_FREE(xml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virSecurityManagerRestoreAllLabel(driver->securityManager,
|
virSecurityManagerRestoreAllLabel(driver->securityManager,
|
||||||
@ -185,9 +183,12 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
/* Clear out dynamically assigned labels */
|
/* Clear out dynamically assigned labels */
|
||||||
if (vm->def->nseclabels &&
|
if (vm->def->nseclabels &&
|
||||||
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) {
|
vm->def->seclabels[0]->type == VIR_DOMAIN_SECLABEL_DYNAMIC) {
|
||||||
VIR_FREE(vm->def->seclabels[0]->model);
|
g_free(vm->def->seclabels[0]->model);
|
||||||
VIR_FREE(vm->def->seclabels[0]->label);
|
g_free(vm->def->seclabels[0]->label);
|
||||||
VIR_FREE(vm->def->seclabels[0]->imagelabel);
|
g_free(vm->def->seclabels[0]->imagelabel);
|
||||||
|
vm->def->seclabels[0]->model = NULL;
|
||||||
|
vm->def->seclabels[0]->label = NULL;
|
||||||
|
vm->def->seclabels[0]->imagelabel = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop autodestroy in case guest is restarted */
|
/* Stop autodestroy in case guest is restarted */
|
||||||
@ -243,17 +244,17 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver,
|
|||||||
* the bug we are working around here.
|
* the bug we are working around here.
|
||||||
*/
|
*/
|
||||||
virCgroupTerminateMachine(priv->machineName);
|
virCgroupTerminateMachine(priv->machineName);
|
||||||
VIR_FREE(priv->machineName);
|
g_free(priv->machineName);
|
||||||
|
priv->machineName = NULL;
|
||||||
|
|
||||||
/* The "release" hook cleans up additional resources */
|
/* The "release" hook cleans up additional resources */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
|
|
||||||
/* we can't stop the operation even if the script raised an error */
|
/* we can't stop the operation even if the script raised an error */
|
||||||
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
VIR_HOOK_LXC_OP_RELEASE, VIR_HOOK_SUBOP_END,
|
VIR_HOOK_LXC_OP_RELEASE, VIR_HOOK_SUBOP_END,
|
||||||
NULL, xml, NULL);
|
NULL, xml, NULL);
|
||||||
VIR_FREE(xml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virDomainObjRemoveTransientDef(vm);
|
virDomainObjRemoveTransientDef(vm);
|
||||||
@ -442,12 +443,9 @@ static int virLXCProcessSetupNamespaceName(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
static int virLXCProcessSetupNamespacePID(int ns_type, const char *name)
|
static int virLXCProcessSetupNamespacePID(int ns_type, const char *name)
|
||||||
{
|
{
|
||||||
int fd;
|
g_autofree char *path = g_strdup_printf("/proc/%s/ns/%s",
|
||||||
char *path;
|
name, nsInfoLocal[ns_type]);
|
||||||
|
int fd = open(path, O_RDONLY);
|
||||||
path = g_strdup_printf("/proc/%s/ns/%s", name, nsInfoLocal[ns_type]);
|
|
||||||
fd = open(path, O_RDONLY);
|
|
||||||
VIR_FREE(path);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("failed to open ns %s"),
|
_("failed to open ns %s"),
|
||||||
@ -460,7 +458,7 @@ static int virLXCProcessSetupNamespacePID(int ns_type, const char *name)
|
|||||||
|
|
||||||
static int virLXCProcessSetupNamespaceNet(int ns_type, const char *name)
|
static int virLXCProcessSetupNamespaceNet(int ns_type, const char *name)
|
||||||
{
|
{
|
||||||
char *path;
|
g_autofree char *path = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
if (ns_type != VIR_LXC_DOMAIN_NAMESPACE_SHARENET) {
|
if (ns_type != VIR_LXC_DOMAIN_NAMESPACE_SHARENET) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -471,7 +469,6 @@ static int virLXCProcessSetupNamespaceNet(int ns_type, const char *name)
|
|||||||
|
|
||||||
path = g_strdup_printf("%s/netns/%s", RUNSTATEDIR, name);
|
path = g_strdup_printf("%s/netns/%s", RUNSTATEDIR, name);
|
||||||
fd = open(path, O_RDONLY);
|
fd = open(path, O_RDONLY);
|
||||||
VIR_FREE(path);
|
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("failed to open netns %s"), name);
|
_("failed to open netns %s"), name);
|
||||||
@ -669,7 +666,8 @@ virLXCProcessCleanInterfaces(virDomainDefPtr def)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
VIR_FREE(def->nets[i]->ifname_guest_actual);
|
g_free(def->nets[i]->ifname_guest_actual);
|
||||||
|
def->nets[i]->ifname_guest_actual = NULL;
|
||||||
VIR_DEBUG("Cleared net names: %s", def->nets[i]->ifname_guest);
|
VIR_DEBUG("Cleared net names: %s", def->nets[i]->ifname_guest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -757,24 +755,20 @@ virLXCProcessGetNsInode(pid_t pid,
|
|||||||
const char *nsname,
|
const char *nsname,
|
||||||
ino_t *inode)
|
ino_t *inode)
|
||||||
{
|
{
|
||||||
char *path = NULL;
|
g_autofree char *path = NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
path = g_strdup_printf("/proc/%lld/ns/%s", (long long)pid, nsname);
|
path = g_strdup_printf("/proc/%lld/ns/%s", (long long)pid, nsname);
|
||||||
|
|
||||||
if (stat(path, &sb) < 0) {
|
if (stat(path, &sb) < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("Unable to stat %s"), path);
|
_("Unable to stat %s"), path);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
*inode = sb.st_ino;
|
*inode = sb.st_ino;
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
VIR_FREE(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -929,8 +923,8 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
|
|||||||
const char *pidfile)
|
const char *pidfile)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
char *filterstr;
|
g_autofree char *filterstr = NULL;
|
||||||
char *outputstr;
|
g_autofree char *outputstr = NULL;
|
||||||
virCommandPtr cmd;
|
virCommandPtr cmd;
|
||||||
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
||||||
|
|
||||||
@ -950,7 +944,6 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
virCommandAddEnvPair(cmd, "LIBVIRT_LOG_FILTERS", filterstr);
|
virCommandAddEnvPair(cmd, "LIBVIRT_LOG_FILTERS", filterstr);
|
||||||
VIR_FREE(filterstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg->log_libvirtd) {
|
if (cfg->log_libvirtd) {
|
||||||
@ -962,7 +955,6 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
virCommandAddEnvPair(cmd, "LIBVIRT_LOG_OUTPUTS", outputstr);
|
virCommandAddEnvPair(cmd, "LIBVIRT_LOG_OUTPUTS", outputstr);
|
||||||
VIR_FREE(outputstr);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
virCommandAddEnvFormat(cmd,
|
virCommandAddEnvFormat(cmd,
|
||||||
@ -985,12 +977,11 @@ virLXCProcessBuildControllerCmd(virLXCDriverPtr driver,
|
|||||||
|
|
||||||
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
|
for (i = 0; i < VIR_LXC_DOMAIN_NAMESPACE_LAST; i++) {
|
||||||
if (nsInheritFDs[i] > 0) {
|
if (nsInheritFDs[i] > 0) {
|
||||||
char *tmp = NULL;
|
g_autofree char *tmp = g_strdup_printf("--share-%s",
|
||||||
tmp = g_strdup_printf("--share-%s", nsInfoLocal[i]);
|
nsInfoLocal[i]);
|
||||||
virCommandAddArg(cmd, tmp);
|
virCommandAddArg(cmd, tmp);
|
||||||
virCommandAddArgFormat(cmd, "%d", nsInheritFDs[i]);
|
virCommandAddArgFormat(cmd, "%d", nsInheritFDs[i]);
|
||||||
virCommandPassFD(cmd, nsInheritFDs[i], 0);
|
virCommandPassFD(cmd, nsInheritFDs[i], 0);
|
||||||
VIR_FREE(tmp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1188,15 +1179,15 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
int rc = -1, r;
|
int rc = -1, r;
|
||||||
size_t nttyFDs = 0;
|
size_t nttyFDs = 0;
|
||||||
int *ttyFDs = NULL;
|
g_autofree int *ttyFDs = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
char *logfile = NULL;
|
g_autofree char *logfile = NULL;
|
||||||
int logfd = -1;
|
int logfd = -1;
|
||||||
VIR_AUTOSTRINGLIST veths = NULL;
|
VIR_AUTOSTRINGLIST veths = NULL;
|
||||||
int handshakefds[2] = { -1, -1 };
|
int handshakefds[2] = { -1, -1 };
|
||||||
off_t pos = -1;
|
off_t pos = -1;
|
||||||
char ebuf[1024];
|
char ebuf[1024];
|
||||||
char *timestamp;
|
g_autofree char *timestamp = NULL;
|
||||||
int nsInheritFDs[VIR_LXC_DOMAIN_NAMESPACE_LAST];
|
int nsInheritFDs[VIR_LXC_DOMAIN_NAMESPACE_LAST];
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
virLXCDomainObjPrivatePtr priv = vm->privateData;
|
||||||
@ -1205,7 +1196,7 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
virLXCDriverConfigPtr cfg = virLXCDriverGetConfig(driver);
|
||||||
virCgroupPtr selfcgroup;
|
virCgroupPtr selfcgroup;
|
||||||
int status;
|
int status;
|
||||||
char *pidfile = NULL;
|
g_autofree char *pidfile = NULL;
|
||||||
|
|
||||||
if (virCgroupNewSelf(&selfcgroup) < 0)
|
if (virCgroupNewSelf(&selfcgroup) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -1283,18 +1274,14 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Run an early hook to set-up missing devices */
|
/* Run an early hook to set-up missing devices */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
int hookret;
|
|
||||||
|
|
||||||
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
|
||||||
VIR_HOOK_LXC_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN,
|
|
||||||
NULL, xml, NULL);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the script raised an error abort the launch
|
* If the script raised an error abort the launch
|
||||||
*/
|
*/
|
||||||
if (hookret < 0)
|
if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
|
VIR_HOOK_LXC_OP_PREPARE, VIR_HOOK_SUBOP_BEGIN,
|
||||||
|
NULL, xml, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1348,10 +1335,10 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_FREE(vm->def->consoles[i]->source->data.file.path);
|
g_free(vm->def->consoles[i]->source->data.file.path);
|
||||||
vm->def->consoles[i]->source->data.file.path = ttyPath;
|
vm->def->consoles[i]->source->data.file.path = ttyPath;
|
||||||
|
|
||||||
VIR_FREE(vm->def->consoles[i]->info.alias);
|
g_free(vm->def->consoles[i]->info.alias);
|
||||||
vm->def->consoles[i]->info.alias = g_strdup_printf("console%zu", i);
|
vm->def->consoles[i]->info.alias = g_strdup_printf("console%zu", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1388,18 +1375,14 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* now that we know it is about to start call the hook if present */
|
/* now that we know it is about to start call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
int hookret;
|
|
||||||
|
|
||||||
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
|
||||||
VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN,
|
|
||||||
NULL, xml, NULL);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the script raised an error abort the launch
|
* If the script raised an error abort the launch
|
||||||
*/
|
*/
|
||||||
if (hookret < 0)
|
if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
|
VIR_HOOK_LXC_OP_START, VIR_HOOK_SUBOP_BEGIN,
|
||||||
|
NULL, xml, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1411,7 +1394,6 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
VIR_WARN("Unable to write timestamp to logfile: %s",
|
VIR_WARN("Unable to write timestamp to logfile: %s",
|
||||||
g_strerror(errno));
|
g_strerror(errno));
|
||||||
}
|
}
|
||||||
VIR_FREE(timestamp);
|
|
||||||
|
|
||||||
/* Log generated command line */
|
/* Log generated command line */
|
||||||
virCommandWriteArgLog(cmd, logfd);
|
virCommandWriteArgLog(cmd, logfd);
|
||||||
@ -1530,18 +1512,14 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* finally we can call the 'started' hook script if any */
|
/* finally we can call the 'started' hook script if any */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
int hookret;
|
|
||||||
|
|
||||||
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
|
||||||
VIR_HOOK_LXC_OP_STARTED, VIR_HOOK_SUBOP_BEGIN,
|
|
||||||
NULL, xml, NULL);
|
|
||||||
VIR_FREE(xml);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the script raised an error abort the launch
|
* If the script raised an error abort the launch
|
||||||
*/
|
*/
|
||||||
if (hookret < 0)
|
if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
|
VIR_HOOK_LXC_OP_STARTED, VIR_HOOK_SUBOP_BEGIN,
|
||||||
|
NULL, xml, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1559,11 +1537,8 @@ int virLXCProcessStart(virConnectPtr conn,
|
|||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
for (i = 0; i < nttyFDs; i++)
|
for (i = 0; i < nttyFDs; i++)
|
||||||
VIR_FORCE_CLOSE(ttyFDs[i]);
|
VIR_FORCE_CLOSE(ttyFDs[i]);
|
||||||
VIR_FREE(ttyFDs);
|
|
||||||
VIR_FORCE_CLOSE(handshakefds[0]);
|
VIR_FORCE_CLOSE(handshakefds[0]);
|
||||||
VIR_FORCE_CLOSE(handshakefds[1]);
|
VIR_FORCE_CLOSE(handshakefds[1]);
|
||||||
VIR_FREE(pidfile);
|
|
||||||
VIR_FREE(logfile);
|
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
virObjectUnref(caps);
|
virObjectUnref(caps);
|
||||||
|
|
||||||
@ -1710,15 +1685,12 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
|
|||||||
|
|
||||||
/* now that we know it's reconnected call the hook if present */
|
/* now that we know it's reconnected call the hook if present */
|
||||||
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
if (virHookPresent(VIR_HOOK_DRIVER_LXC)) {
|
||||||
char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
g_autofree char *xml = virDomainDefFormat(vm->def, driver->xmlopt, 0);
|
||||||
int hookret;
|
|
||||||
|
|
||||||
/* we can't stop the operation even if the script raised an error */
|
/* we can't stop the operation even if the script raised an error */
|
||||||
hookret = virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
if (virHookCall(VIR_HOOK_DRIVER_LXC, vm->def->name,
|
||||||
VIR_HOOK_LXC_OP_RECONNECT, VIR_HOOK_SUBOP_BEGIN,
|
VIR_HOOK_LXC_OP_RECONNECT, VIR_HOOK_SUBOP_BEGIN,
|
||||||
NULL, xml, NULL);
|
NULL, xml, NULL) < 0)
|
||||||
VIR_FREE(xml);
|
|
||||||
if (hookret < 0)
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user