[libvirt] [PATCH 2/4] Stop passing around old root directory prefix

Daniel P. Berrange berrange at redhat.com
Wed May 15 09:53:14 UTC 2013


From: "Daniel P. Berrange" <berrange at redhat.com>

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: Daniel P. Berrange <berrange at redhat.com>
---
 src/lxc/lxc_container.c | 85 ++++++++++++++++++++-----------------------------
 1 file changed, 35 insertions(+), 50 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index f0a085e..1ebb625 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -745,15 +745,14 @@ cleanup:
 }
 
 #if WITH_FUSE
-static int lxcContainerMountProcFuse(virDomainDefPtr def,
-                                     const char *srcprefix)
+static int lxcContainerMountProcFuse(virDomainDefPtr def)
 {
     int ret;
     char *meminfo_path = NULL;
 
     if ((ret = virAsprintf(&meminfo_path,
-                           "%s/%s/%s.fuse/meminfo",
-                           srcprefix ? srcprefix : "", LXC_STATE_DIR,
+                           "/.oldroot/%s/%s.fuse/meminfo",
+                           LXC_STATE_DIR,
                            def->name)) < 0)
         return ret;
 
@@ -768,22 +767,20 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def,
     return ret;
 }
 #else
-static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED,
-                                     const char *srcprefix ATTRIBUTE_UNUSED)
+static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED)
 {
     return 0;
 }
 #endif
 
-static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
-                                     const char *srcprefix)
+static int lxcContainerMountFSDevPTS(virDomainDefPtr def)
 {
     int ret;
     char *path = NULL;
 
     if ((ret = virAsprintf(&path,
-                           "%s/%s/%s.devpts",
-                           srcprefix ? srcprefix : "", LXC_STATE_DIR,
+                           "/.oldroot/%s/%s.devpts",
+                           LXC_STATE_DIR,
                            def->name)) < 0)
         return ret;
 
@@ -1067,8 +1064,7 @@ lxcContainerMountDetectFilesystem(const char *src ATTRIBUTE_UNUSED,
  */
 static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
                                         int fsflags,
-                                        const char *src,
-                                        const char *srcprefix)
+                                        const char *src)
 {
     FILE *fp = NULL;
     int ret = -1;
@@ -1078,12 +1074,12 @@ static int lxcContainerMountFSBlockAuto(virDomainFSDefPtr fs,
     char *line = NULL;
     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 */
 retry:
-    if (virAsprintf(&fslist, "%s%s",
-                    srcprefix, tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) {
+    if (virAsprintf(&fslist, "/.oldroot%s",
+                    tryProc ? "/proc/filesystems" : "/etc/filesystems") < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1196,8 +1192,7 @@ cleanup:
  * probing for filesystem type
  */
 static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
-                                          const char *src,
-                                          const char *srcprefix)
+                                          const char *src)
 {
     int fsflags = 0;
     int ret = -1;
@@ -1226,7 +1221,7 @@ static int lxcContainerMountFSBlockHelper(virDomainFSDefPtr fs,
         }
         ret = 0;
     } else {
-        ret = lxcContainerMountFSBlockAuto(fs, fsflags, src, srcprefix);
+        ret = lxcContainerMountFSBlockAuto(fs, fsflags, src);
     }
 
 cleanup:
@@ -1246,7 +1241,7 @@ static int lxcContainerMountFSBlock(virDomainFSDefPtr fs,
         goto cleanup;
     }
 
-    ret = lxcContainerMountFSBlockHelper(fs, src, srcprefix);
+    ret = lxcContainerMountFSBlockHelper(fs, src);
 
     VIR_DEBUG("Done mounting filesystem ret=%d", ret);
 
@@ -1300,16 +1295,15 @@ cleanup:
 
 
 static int lxcContainerMountFS(virDomainFSDefPtr fs,
-                               const char *srcprefix,
                                char *sec_mount_options)
 {
     switch (fs->type) {
     case VIR_DOMAIN_FS_TYPE_MOUNT:
-        if (lxcContainerMountFSBind(fs, srcprefix) < 0)
+        if (lxcContainerMountFSBind(fs, "/.oldroot") < 0)
             return -1;
         break;
     case VIR_DOMAIN_FS_TYPE_BLOCK:
-        if (lxcContainerMountFSBlock(fs, srcprefix) < 0)
+        if (lxcContainerMountFSBlock(fs, "/.oldroot") < 0)
             return -1;
         break;
     case VIR_DOMAIN_FS_TYPE_RAM:
@@ -1339,12 +1333,11 @@ static int lxcContainerMountFS(virDomainFSDefPtr fs,
 
 
 static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
-                                  const char *dstprefix,
                                   bool skipRoot,
                                   char *sec_mount_options)
 {
     size_t i;
-    VIR_DEBUG("Mounting %s %d", dstprefix, skipRoot);
+    VIR_DEBUG("Mounting %d", skipRoot);
 
     /* Pull in rest of container's mounts */
     for (i = 0 ; i < vmDef->nfss ; i++) {
@@ -1356,7 +1349,7 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
                                        false) < 0)
             return -1;
 
-        if (lxcContainerMountFS(vmDef->fss[i], dstprefix, sec_mount_options) < 0)
+        if (lxcContainerMountFS(vmDef->fss[i], sec_mount_options) < 0)
             return -1;
     }
 
@@ -1367,7 +1360,6 @@ static int lxcContainerMountAllFS(virDomainDefPtr vmDef,
 
 static int lxcContainerSetupDisk(virDomainDefPtr vmDef,
                                  virDomainDiskDefPtr def,
-                                 const char *dstprefix,
                                  virSecurityManagerPtr securityDriver)
 {
     char *src = NULL;
@@ -1388,7 +1380,7 @@ static int lxcContainerSetupDisk(virDomainDefPtr vmDef,
         goto cleanup;
     }
 
-    if (virAsprintf(&src, "%s/%s", dstprefix, def->src) < 0) {
+    if (virAsprintf(&src, "/.oldroot/%s", def->src) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1448,15 +1440,14 @@ cleanup:
 }
 
 static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef,
-                                     const char *dstprefix,
                                      virSecurityManagerPtr securityDriver)
 {
     size_t i;
-    VIR_DEBUG("Setting up disks %s", dstprefix);
+    VIR_DEBUG("Setting up disks");
 
     for (i = 0 ; i < vmDef->ndisks ; i++) {
         if (lxcContainerSetupDisk(vmDef, vmDef->disks[i],
-                                  dstprefix, securityDriver) < 0)
+                                  securityDriver) < 0)
             return -1;
     }
 
@@ -1467,7 +1458,6 @@ static int lxcContainerSetupAllDisks(virDomainDefPtr vmDef,
 
 static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
                                              virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
-                                             const char *dstprefix ATTRIBUTE_UNUSED,
                                              virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
 {
     int ret = -1;
@@ -1490,7 +1480,7 @@ static int lxcContainerSetupHostdevSubsysUSB(virDomainDefPtr vmDef ATTRIBUTE_UNU
         goto cleanup;
     }
 
-    if (virAsprintf(&src, "%s/%s", dstprefix, dstfile) < 0) {
+    if (virAsprintf(&src, "/.oldroot/%s", dstfile) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -1540,7 +1530,6 @@ cleanup:
 
 static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
                                                virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
-                                               const char *dstprefix ATTRIBUTE_UNUSED,
                                                virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
 {
     char *src = NULL;
@@ -1554,7 +1543,7 @@ static int lxcContainerSetupHostdevCapsStorage(virDomainDefPtr vmDef ATTRIBUTE_U
         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();
         goto cleanup;
     }
@@ -1598,7 +1587,6 @@ cleanup:
 
 static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUSED,
                                             virDomainHostdevDefPtr def ATTRIBUTE_UNUSED,
-                                            const char *dstprefix ATTRIBUTE_UNUSED,
                                             virSecurityManagerPtr securityDriver ATTRIBUTE_UNUSED)
 {
     char *src = NULL;
@@ -1612,7 +1600,7 @@ static int lxcContainerSetupHostdevCapsMisc(virDomainDefPtr vmDef ATTRIBUTE_UNUS
         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();
         goto cleanup;
     }
@@ -1655,12 +1643,11 @@ cleanup:
 
 static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef,
                                           virDomainHostdevDefPtr def,
-                                          const char *dstprefix,
                                           virSecurityManagerPtr securityDriver)
 {
     switch (def->source.subsys.type) {
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
-        return lxcContainerSetupHostdevSubsysUSB(vmDef, def, dstprefix, securityDriver);
+        return lxcContainerSetupHostdevSubsysUSB(vmDef, def, securityDriver);
 
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -1673,15 +1660,14 @@ static int lxcContainerSetupHostdevSubsys(virDomainDefPtr vmDef,
 
 static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef,
                                         virDomainHostdevDefPtr def,
-                                        const char *dstprefix,
                                         virSecurityManagerPtr securityDriver)
 {
     switch (def->source.subsys.type) {
     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:
-        return lxcContainerSetupHostdevCapsMisc(vmDef, def, dstprefix, securityDriver);
+        return lxcContainerSetupHostdevCapsMisc(vmDef, def, securityDriver);
 
     case VIR_DOMAIN_HOSTDEV_CAPS_TYPE_NET:
         return 0; // case is handled in virLXCControllerMoveInterfaces
@@ -1696,21 +1682,20 @@ static int lxcContainerSetupHostdevCaps(virDomainDefPtr vmDef,
 
 
 static int lxcContainerSetupAllHostdevs(virDomainDefPtr vmDef,
-                                        const char *dstprefix,
                                         virSecurityManagerPtr securityDriver)
 {
     size_t i;
-    VIR_DEBUG("Setting up hostdevs %s", dstprefix);
+    VIR_DEBUG("Setting up hostdevs");
 
     for (i = 0 ; i < vmDef->nhostdevs ; i++) {
         virDomainHostdevDefPtr def = vmDef->hostdevs[i];
         switch (def->mode) {
         case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
-            if (lxcContainerSetupHostdevSubsys(vmDef, def, dstprefix, securityDriver) < 0)
+            if (lxcContainerSetupHostdevSubsys(vmDef, def, securityDriver) < 0)
                 return -1;
             break;
         case VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES:
-            if (lxcContainerSetupHostdevCaps(vmDef, def, dstprefix, securityDriver) < 0)
+            if (lxcContainerSetupHostdevCaps(vmDef, def, securityDriver) < 0)
                 return -1;
             break;
         default:
@@ -1789,7 +1774,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
         goto cleanup;
 
     /* Mounts /proc/meminfo etc sysinfo */
-    if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0)
+    if (lxcContainerMountProcFuse(vmDef) < 0)
         goto cleanup;
 
     /* Now we can re-mount the cgroups controllers in the
@@ -1798,7 +1783,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
         goto cleanup;
 
     /* Mounts /dev/pts */
-    if (lxcContainerMountFSDevPTS(vmDef, "/.oldroot") < 0)
+    if (lxcContainerMountFSDevPTS(vmDef) < 0)
         goto cleanup;
 
     /* Populates device nodes in /dev/ */
@@ -1806,15 +1791,15 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
         goto cleanup;
 
     /* 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;
 
     /* Sets up any extra disks from guest config */
-    if (lxcContainerSetupAllDisks(vmDef, "/.oldroot", securityDriver) < 0)
+    if (lxcContainerSetupAllDisks(vmDef, securityDriver) < 0)
         goto cleanup;
 
     /* Sets up any extra host devices from guest config */
-    if (lxcContainerSetupAllHostdevs(vmDef, "/.oldroot", securityDriver) < 0)
+    if (lxcContainerSetupAllHostdevs(vmDef, securityDriver) < 0)
         goto cleanup;
 
    /* Gets rid of all remaining mounts from host OS, including /.oldroot itself */
-- 
1.8.2.1




More information about the libvir-list mailing list