提交 31453a83 编写于 作者: D Daniel P. Berrange 提交者: Michal Privoznik

Stop passing around old root directory prefix

Many methods accept a string parameter specifying the
old root directory prefix. Since removal of the non-pivot
root container setup codepaths, this parameter is obsolete
in many methods where the callers always pass "/.oldroot".
Signed-off-by: NDaniel P. Berrange <berrange@redhat.com>
上级 37cebfec
...@@ -745,15 +745,14 @@ cleanup: ...@@ -745,15 +745,14 @@ cleanup:
} }
#if WITH_FUSE #if WITH_FUSE
static int lxcContainerMountProcFuse(virDomainDefPtr def, static int lxcContainerMountProcFuse(virDomainDefPtr def)
const char *srcprefix)
{ {
int ret; int ret;
char *meminfo_path = NULL; char *meminfo_path = NULL;
if ((ret = virAsprintf(&meminfo_path, if ((ret = virAsprintf(&meminfo_path,
"%s/%s/%s.fuse/meminfo", "/.oldroot/%s/%s.fuse/meminfo",
srcprefix ? srcprefix : "", LXC_STATE_DIR, LXC_STATE_DIR,
def->name)) < 0) def->name)) < 0)
return ret; return ret;
...@@ -768,22 +767,20 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def, ...@@ -768,22 +767,20 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def,
return ret; return ret;
} }
#else #else
static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED, static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED)
const char *srcprefix ATTRIBUTE_UNUSED)
{ {
return 0; return 0;
} }
#endif #endif
static int lxcContainerMountFSDevPTS(virDomainDefPtr def, static int lxcContainerMountFSDevPTS(virDomainDefPtr def)
const char *srcprefix)
{ {
int ret; int ret;
char *path = NULL; char *path = NULL;
if ((ret = virAsprintf(&path, if ((ret = virAsprintf(&path,
"%s/%s/%s.devpts", "/.oldroot/%s/%s.devpts",
srcprefix ? srcprefix : "", LXC_STATE_DIR, LXC_STATE_DIR,
def->name)) < 0) def->name)) < 0)
return ret; return ret;
...@@ -1067,8 +1064,7 @@ lxcContainerMountDetectFilesystem(const char *src ATTRIBUTE_UNUSED, ...@@ -1067,8 +1064,7 @@ lxcContainerMountDetectFilesystem(const char *src ATTRIBUTE_UNUSED,
*/ */
static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
int fsflags, int fsflags,
const char *src, const char *src)
const char *srcprefix)
{ {
FILE *fp = NULL; FILE *fp = NULL;
int ret = -1; int ret = -1;
...@@ -1078,12 +1074,12 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs, ...@@ -1078,12 +1074,12 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
char *line = NULL; char *line = NULL;
const char *type; const char *type;
VIR_DEBUG("src=%s srcprefix=%s dst=%s", src, srcprefix, fs->dst); VIR_DEBUG("src=%s dst=%s", src, fs->dst);
/* First time around we use /etc/filesystems */ /* First time around we use /etc/filesystems */
retry: retry:
if (virAsprintf(&fslist, "%s%s", if (virAsprintf(&fslist, "/.oldroot%s",
srcprefix, tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) { tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
...@@ -1196,8 +1192,7 @@ cleanup: ...@@ -1196,8 +1192,7 @@ cleanup:
* probing for filesystem type * probing for filesystem type
*/ */
static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs, static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
const char *src, const char *src)
const char *srcprefix)
{ {
int fsflags = 0; int fsflags = 0;
int ret = -1; int ret = -1;
...@@ -1226,7 +1221,7 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs, ...@@ -1226,7 +1221,7 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
} }
ret = 0; ret = 0;
} else { } else {
ret = lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix); ret = lxcContainerMountFSBlockAuto(fs, fsflags, src);
} }
cleanup: cleanup:
...@@ -1246,7 +1241,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs, ...@@ -1246,7 +1241,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
goto cleanup; goto cleanup;
} }
ret = lxcContainerMountFSBlockHelper(fs, src, srcprefix); ret = lxcContainerMountFSBlockHelper(fs, src);
VIR_DEBUG("Done mounting filesystem ret=%d", ret); VIR_DEBUG("Done mounting filesystem ret=%d", ret);
...@@ -1300,16 +1295,15 @@ cleanup: ...@@ -1300,16 +1295,15 @@ cleanup:
static int lxcContainerMountFS(virDomainFSDefPtr fs, static int lxcContainerMountFS(virDomainFSDefPtr fs,
const char *srcprefix,
char *sec_mount_options) char *sec_mount_options)
{ {
switch (fs->type) { switch (fs->type) {
case VIR_DOMAIN_FS_TYPE_MOUNT: case VIR_DOMAIN_FS_TYPE_MOUNT:
if (lxcContainerMountFSBind(fs, srcprefix) < 0) if (lxcContainerMountFSBind(fs, "/.oldroot") < 0)
return -1; return -1;
break; break;
case VIR_DOMAIN_FS_TYPE_BLOCK: case VIR_DOMAIN_FS_TYPE_BLOCK:
if (lxcContainerMountFSBlock(fs, srcprefix) < 0) if (lxcContainerMountFSBlock(fs, "/.oldroot") < 0)
return -1; return -1;
break; break;
case VIR_DOMAIN_FS_TYPE_RAM: case VIR_DOMAIN_FS_TYPE_RAM:
...@@ -1339,12 +1333,11 @@ static int lxcContainerMountFS(virDomainFSDefPtr fs, ...@@ -1339,12 +1333,11 @@ static int lxcContainerMountFS(virDomainFSDefPtr fs,
static int lxcContainerMountAllFS(virDomainDefPtr vmDef, static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
const char *dstprefix,
bool skipRoot, bool skipRoot,
char *sec_mount_options) char *sec_mount_options)
{ {
size_t i; size_t i;
VIR_DEBUG("Mounting %s %d", dstprefix, skipRoot); VIR_DEBUG("Mounting %d", skipRoot);
/* Pull in rest of container's mounts */ /* Pull in rest of container's mounts */
for (i = 0 ; i < vmDef->nfss ; i++) { for (i = 0 ; i < vmDef->nfss ; i++) {
...@@ -1356,7 +1349,7 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef, ...@@ -1356,7 +1349,7 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
false) < 0) false) < 0)
return -1; return -1;
if (lxcContainerMountFS(vmDef->fss[i], dstprefix, sec_mount_options) < 0) if (lxcContainerMountFS(vmDef->fss[i], sec_mount_options) < 0)
return -1; return -1;
} }
...@@ -1367,7 +1360,6 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef, ...@@ -1367,7 +1360,6 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
static int lxcContainerSetupDisk(virDomainDefPtr vmDef, static int lxcContainerSetupDisk(virDomainDefPtr vmDef,
virDomainDiskDefPtr def, virDomainDiskDefPtr def,
const char *dstprefix,
virSecurityManagerPtr securityDriver) virSecurityManagerPtr securityDriver)
{ {
char *src = NULL; char *src = NULL;
...@@ -1388,7 +1380,7 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef, ...@@ -1388,7 +1380,7 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&src, "%s/%s", dstprefix, def->src) < 0) { if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
...@@ -1448,15 +1440,14 @@ cleanup: ...@@ -1448,15 +1440,14 @@ cleanup:
} }
static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef, static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef,
const char *dstprefix,
virSecurityManagerPtr securityDriver) virSecurityManagerPtr securityDriver)
{ {
size_t i; size_t i;
VIR_DEBUG("Setting up disks %s", dstprefix); VIR_DEBUG("Setting up disks");
for (i = 0 ; i < vmDef->ndisks ; i++) { for (i = 0 ; i < vmDef->ndisks ; i++) {
if (lxcContainerSetupDisk(vmDef, vmDef->disks[i], if (lxcContainerSetupDisk(vmDef, vmDef->disks[i],
dstprefix, securityDriver) < 0) securityDriver) < 0)
return -1; return -1;
} }
...@@ -1467,7 +1458,6 @@ static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef, ...@@ -1467,7 +1458,6 @@ static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef,
static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNUSED, static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
virDomainHostdevDefPtr def ATTRIBUTE_UNUSED, virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
const char *dstprefix ATTRIBUTE_UNUSED,
virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED) virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
{ {
int ret = -1; int ret = -1;
...@@ -1490,7 +1480,7 @@ static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNU ...@@ -1490,7 +1480,7 @@ static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNU
goto cleanup; goto cleanup;
} }
if (virAsprintf(&src, "%s/%s", dstprefix, dstfile) < 0) { if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
...@@ -1540,7 +1530,6 @@ cleanup: ...@@ -1540,7 +1530,6 @@ cleanup:
static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_UNUSED, static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
virDomainHostdevDefPtr def ATTRIBUTE_UNUSED, virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
const char *dstprefix ATTRIBUTE_UNUSED,
virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED) virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
{ {
char *src = NULL; char *src = NULL;
...@@ -1554,7 +1543,7 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U ...@@ -1554,7 +1543,7 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U
goto cleanup; goto cleanup;
} }
if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.storage.block) < 0) { if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.storage.block) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
...@@ -1598,7 +1587,6 @@ cleanup: ...@@ -1598,7 +1587,6 @@ cleanup:
static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUSED, static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
virDomainHostdevDefPtr def ATTRIBUTE_UNUSED, virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
const char *dstprefix ATTRIBUTE_UNUSED,
virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED) virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
{ {
char *src = NULL; char *src = NULL;
...@@ -1612,7 +1600,7 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS ...@@ -1612,7 +1600,7 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS
goto cleanup; goto cleanup;
} }
if (virAsprintf(&src, "%s/%s", dstprefix, def->source.caps.u.misc.chardev) < 0) { if (virAsprintf(&src, "/.oldroot/%s", def->source.caps.u.misc.chardev) < 0) {
virReportOOMError(); virReportOOMError();
goto cleanup; goto cleanup;
} }
...@@ -1655,12 +1643,11 @@ cleanup: ...@@ -1655,12 +1643,11 @@ cleanup:
static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef, static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef,
virDomainHostdevDefPtr def, virDomainHostdevDefPtr def,
const char *dstprefix,
virSecurityManagerPtr securityDriver) virSecurityManagerPtr securityDriver)
{ {
switch (def->source.subsys.type) { switch (def->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
return lxcContainerSetupHostdevSubsysUSB(vmDef, def, dstprefix, securityDriver); return lxcContainerSetupHostdevSubsysUSB(vmDef, def, securityDriver);
default: default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
...@@ -1673,15 +1660,14 @@ static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef, ...@@ -1673,15 +1660,14 @@ static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef,
static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef, static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef,
virDomainHostdevDefPtr def, virDomainHostdevDefPtr def,
const char *dstprefix,
virSecurityManagerPtr securityDriver) virSecurityManagerPtr securityDriver)
{ {
switch (def->source.subsys.type) { switch (def->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_STORAGE:
return lxcContainerSetupHostdevCapsStorage(vmDef, def, dstprefix, securityDriver); return lxcContainerSetupHostdevCapsStorage(vmDef, def, securityDriver);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_MISC:
return lxcContainerSetupHostdevCapsMisc(vmDef, def, dstprefix, securityDriver); return lxcContainerSetupHostdevCapsMisc(vmDef, def, securityDriver);
case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET: case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
return 0; // case is handled in virLXCControllerMoveInterfaces return 0; // case is handled in virLXCControllerMoveInterfaces
...@@ -1696,21 +1682,20 @@ static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef, ...@@ -1696,21 +1682,20 @@ static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef,
static int lxcContainerSetupAllHostdevs(virDomainDefPtr vmDef, static int lxcContainerSetupAllHostdevs(virDomainDefPtr vmDef,
const char *dstprefix,
virSecurityManagerPtr securityDriver) virSecurityManagerPtr securityDriver)
{ {
size_t i; size_t i;
VIR_DEBUG("Setting up hostdevs %s", dstprefix); VIR_DEBUG("Setting up hostdevs");
for (i = 0 ; i < vmDef->nhostdevs ; i++) { for (i = 0 ; i < vmDef->nhostdevs ; i++) {
virDomainHostdevDefPtr def = vmDef->hostdevs[i]; virDomainHostdevDefPtr def = vmDef->hostdevs[i];
switch (def->mode) { switch (def->mode) {
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (lxcContainerSetupHostdevSubsys(vmDef, def, dstprefix, securityDriver) < 0) if (lxcContainerSetupHostdevSubsys(vmDef, def, securityDriver) < 0)
return -1; return -1;
break; break;
case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES: case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
if (lxcContainerSetupHostdevCaps(vmDef, def, dstprefix, securityDriver) < 0) if (lxcContainerSetupHostdevCaps(vmDef, def, securityDriver) < 0)
return -1; return -1;
break; break;
default: default:
...@@ -1789,7 +1774,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef, ...@@ -1789,7 +1774,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
/* Mounts /proc/meminfo etc sysinfo */ /* Mounts /proc/meminfo etc sysinfo */
if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0) if (lxcContainerMountProcFuse(vmDef) < 0)
goto cleanup; goto cleanup;
/* Now we can re-mount the cgroups controllers in the /* Now we can re-mount the cgroups controllers in the
...@@ -1798,7 +1783,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef, ...@@ -1798,7 +1783,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
/* Mounts /dev/pts */ /* Mounts /dev/pts */
if (lxcContainerMountFSDevPTS(vmDef, "/.oldroot") < 0) if (lxcContainerMountFSDevPTS(vmDef) < 0)
goto cleanup; goto cleanup;
/* Populates device nodes in /dev/ */ /* Populates device nodes in /dev/ */
...@@ -1806,15 +1791,15 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef, ...@@ -1806,15 +1791,15 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
goto cleanup; goto cleanup;
/* Sets up any non-root mounts from guest config */ /* Sets up any non-root mounts from guest config */
if (lxcContainerMountAllFS(vmDef, "/.oldroot", true, sec_mount_options) < 0) if (lxcContainerMountAllFS(vmDef, true, sec_mount_options) < 0)
goto cleanup; goto cleanup;
/* Sets up any extra disks from guest config */ /* Sets up any extra disks from guest config */
if (lxcContainerSetupAllDisks(vmDef, "/.oldroot", securityDriver) < 0) if (lxcContainerSetupAllDisks(vmDef, securityDriver) < 0)
goto cleanup; goto cleanup;
/* Sets up any extra host devices from guest config */ /* Sets up any extra host devices from guest config */
if (lxcContainerSetupAllHostdevs(vmDef, "/.oldroot", securityDriver) < 0) if (lxcContainerSetupAllHostdevs(vmDef, securityDriver) < 0)
goto cleanup; goto cleanup;
/* Gets rid of all remaining mounts from host OS, including /.oldroot itself */ /* Gets rid of all remaining mounts from host OS, including /.oldroot itself */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册