]> xenbits.xensource.com Git - libvirt.git/commitdiff
mount fuse's meminfo file to container's /proc/meminfo
authorGao feng <gaofeng@cn.fujitsu.com>
Mon, 12 Nov 2012 07:02:28 +0000 (15:02 +0800)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 28 Nov 2012 10:28:49 +0000 (10:28 +0000)
we already have virtualize meminfo for container through fuse filesystem,
add function lxcContainerMountProcFuse to mount this meminfo file to
the container's /proc/meminfo.

So we can isolate container's /proc/meminfo from host now.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
src/lxc/lxc_container.c

index 8e2e3ecab9fdc87c7412f885d9223f5222f7d068..3014564e8ee00d8bd7b00d13fcb7f45e3cbe7317 100644 (file)
@@ -595,6 +595,36 @@ cleanup:
     return rc;
 }
 
+#if HAVE_FUSE
+static int lxcContainerMountProcFuse(virDomainDefPtr def,
+                                     const char *srcprefix)
+{
+    int ret;
+    char *meminfo_path = NULL;
+
+    if ((ret = virAsprintf(&meminfo_path,
+                           "%s/%s/%s/meminfo",
+                           srcprefix, LXC_STATE_DIR,
+                           def->name)) < 0)
+        return ret;
+
+    if ((ret = mount(meminfo_path, "/proc/meminfo",
+                     NULL, MS_BIND, NULL)) < 0) {
+        virReportSystemError(errno,
+                             _("Failed to mount %s on /proc/meminfo"),
+                             meminfo_path);
+    }
+
+    VIR_FREE(meminfo_path);
+    return ret;
+}
+#else
+static int lxcContainerMountProcFuse(virDomainDefPtr def ATTRIBUTE_UNUSED,
+                                     const char *srcprefix ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
+#endif
 
 static int lxcContainerMountFSDevPTS(virDomainFSDefPtr root)
 {
@@ -1554,6 +1584,10 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr vmDef,
     if (lxcContainerMountBasicFS(true, sec_mount_options) < 0)
         goto cleanup;
 
+    /* Mounts /proc/meminfo etc sysinfo */
+    if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0)
+        goto cleanup;
+
     /* Now we can re-mount the cgroups controllers in the
      * same configuration as before */
     if (lxcContainerMountCGroups(mounts, nmounts,
@@ -1650,6 +1684,10 @@ static int lxcContainerSetupExtraMounts(virDomainDefPtr vmDef,
     if (lxcContainerMountBasicFS(false, sec_mount_options) < 0)
         goto cleanup;
 
+    /* Mounts /proc/meminfo etc sysinfo */
+    if (lxcContainerMountProcFuse(vmDef, "/.oldroot") < 0)
+        goto cleanup;
+
     /* Now we can re-mount the cgroups controllers in the
      * same configuration as before */
     if (lxcContainerMountCGroups(mounts, nmounts,