[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Mount temporary devpts on /var/lib/libvirt/lxc/$NAME.devpts



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

Currently the lxc controller sets up the devpts instance on
$rootfsdef->src, but this only works if $rootfsdef is using
type=mount. To support type=block or type=file for the root
filesystem, we must use /var/lib/libvirt/lxc/$NAME.devpts
for the temporary devpts mount in the controller
---
 src/lxc/lxc_container.c  | 43 +++++++++++++++++++++++++------------------
 src/lxc/lxc_controller.c | 13 ++++---------
 2 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index bf17a38..be9bc6c 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -627,15 +627,17 @@ static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED,
 }
 #endif
 
-static int lxcContainerMountFSDevPTS(virDomainFSDefPtr root)
+static int lxcContainerMountFSDevPTS(virDomainDefPtr def,
+                                     const char *srcprefix)
 {
-    char *devpts = NULL;
-    int rc = -1;
+    int ret;
+    char *path = NULL;
 
-    if (virAsprintf(&devpts, "/.oldroot%s/dev/pts", root->src) < 0) {
-        virReportOOMError();
-        goto cleanup;
-    }
+    if ((ret = virAsprintf(&path,
+                           "%s/%s/%s.devpts",
+                           srcprefix ? srcprefix : "", LXC_STATE_DIR,
+                           def->name)) < 0)
+        return ret;
 
     if (virFileMakePath("/dev/pts") < 0) {
         virReportSystemError(errno, "%s",
@@ -643,19 +645,20 @@ static int lxcContainerMountFSDevPTS(virDomainFSDefPtr root)
         goto cleanup;
     }
 
-    VIR_DEBUG("Trying to move %s to %s", devpts, "/dev/pts");
-    if ((rc = mount(devpts, "/dev/pts", NULL, MS_MOVE, NULL)) < 0) {
-        virReportSystemError(errno, "%s",
-                             _("Failed to mount /dev/pts in container"));
+    VIR_DEBUG("Trying to move %s to /dev/pts", path);
+
+    if ((ret = mount(path, "/dev/pts",
+                     NULL, MS_MOVE, NULL)) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to mount %s on /dev/pts"),
+                             path);
         goto cleanup;
     }
 
-    rc = 0;
-
- cleanup:
-    VIR_FREE(devpts);
+cleanup:
+    VIR_FREE(path);
 
-    return rc;
+    return ret;
 }
 
 static int lxcContainerPopulateDevices(char **ttyPaths, size_t nttyPaths)
@@ -1961,7 +1964,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
         goto cleanup;
 
     /* Mounts /dev/pts */
-    if (lxcContainerMountFSDevPTS(root) < 0)
+    if (lxcContainerMountFSDevPTS(vmDef, "/.oldroot") < 0)
         goto cleanup;
 
     /* Populates device nodes in /dev/ */
@@ -2204,7 +2207,11 @@ static int lxcContainerChild(void *data)
 
     if (argv->nttyPaths) {
         if (root) {
-            if (virAsprintf(&ttyPath, "%s%s", root->src, argv->ttyPaths[0]) < 0) {
+            const char *tty = argv->ttyPaths[0];
+            if (STRPREFIX(tty, "/dev/pts/"))
+                tty += strlen("/dev/pts/");
+            if (virAsprintf(&ttyPath, "%s/%s.devpts/%s",
+                            LXC_STATE_DIR, vmDef->name, tty) < 0) {
                 virReportOOMError();
                 goto cleanup;
             }
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index bb369e2..1d1443c 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -1219,15 +1219,10 @@ virLXCControllerSetupDevPTS(virLXCControllerPtr ctrl)
     mount_options = virSecurityManagerGetMountOptions(ctrl->securityManager,
                                                       ctrl->def);
 
-    if (!virFileExists(root->src)) {
-        virReportSystemError(errno,
-                             _("root source %s does not exist"),
-                             root->src);
-        goto cleanup;
-    }
-
-    if (virAsprintf(&devpts, "%s/dev/pts", root->src) < 0 ||
-        virAsprintf(&ctrl->devptmx, "%s/dev/pts/ptmx", root->src) < 0) {
+    if (virAsprintf(&devpts, "%s/%s.devpts",
+                    LXC_STATE_DIR, ctrl->def->name) < 0 ||
+        virAsprintf(&ctrl->devptmx, "%s/%s.devpts/ptmx",
+                    LXC_STATE_DIR, ctrl->def->name) < 0) {
         virReportOOMError();
         goto cleanup;
     }
-- 
1.7.11.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]