43fe83
From dc8bdc9729fda24e5a12e78d713f956e071c0492 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <dc8bdc9729fda24e5a12e78d713f956e071c0492.1380112456.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Fri, 20 Sep 2013 13:07:49 +0100
43fe83
Subject: [PATCH] Move array of mounts out of lxcContainerMountBasicFS
43fe83
43fe83
For
43fe83
43fe83
  https://bugzilla.redhat.com/show_bug.cgi?id=872648
43fe83
43fe83
Move the array of basic mounts out of the lxcContainerMountBasicFS
43fe83
function, to a global variable. This is to allow it to be referenced
43fe83
by other methods wanting to know what the basic mount paths are.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit f27f5f7eddf531159d791a2b5ac438ca011b5f26)
43fe83
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
43fe83
---
43fe83
 src/lxc/lxc_container.c | 79 ++++++++++++++++++++++++++-----------------------
43fe83
 1 file changed, 42 insertions(+), 37 deletions(-)
43fe83
43fe83
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
43fe83
index c41ab40..d3154d8 100644
43fe83
--- a/src/lxc/lxc_container.c
43fe83
+++ b/src/lxc/lxc_container.c
43fe83
@@ -750,45 +750,50 @@ err:
43fe83
 }
43fe83
 
43fe83
 
43fe83
-static int lxcContainerMountBasicFS(bool userns_enabled)
43fe83
-{
43fe83
-    const struct {
43fe83
-        const char *src;
43fe83
-        const char *dst;
43fe83
-        const char *type;
43fe83
-        const char *opts;
43fe83
-        int mflags;
43fe83
-    } mnts[] = {
43fe83
-        /* When we want to make a bind mount readonly, for unknown reasons,
43fe83
-         * it is currently necessary to bind it once, and then remount the
43fe83
-         * bind with the readonly flag. If this is not done, then the original
43fe83
-         * mount point in the main OS becomes readonly too which is not what
43fe83
-         * we want. Hence some things have two entries here.
43fe83
-         */
43fe83
-        { "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
-        { "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND },
43fe83
-        { "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
-        { "sysfs", "/sys", "sysfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
-        { "sysfs", "/sys", "sysfs", NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
-        { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
-        { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
+typedef struct {
43fe83
+    const char *src;
43fe83
+    const char *dst;
43fe83
+    const char *type;
43fe83
+    const char *opts;
43fe83
+    int mflags;
43fe83
+} virLXCBasicMountInfo;
43fe83
+
43fe83
+static const virLXCBasicMountInfo lxcBasicMounts[] = {
43fe83
+    /* When we want to make a bind mount readonly, for unknown reasons,
43fe83
+     * it is currently necessary to bind it once, and then remount the
43fe83
+     * bind with the readonly flag. If this is not done, then the original
43fe83
+     * mount point in the main OS becomes readonly too which is not what
43fe83
+     * we want. Hence some things have two entries here.
43fe83
+     */
43fe83
+    { "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
+    { "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND },
43fe83
+    { "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
+    { "sysfs", "/sys", "sysfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
+    { "sysfs", "/sys", "sysfs", NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
+    { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
+    { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
 #if WITH_SELINUX
43fe83
-        { SELINUX_MOUNT, SELINUX_MOUNT, "selinuxfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
-        { SELINUX_MOUNT, SELINUX_MOUNT, NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
+    { SELINUX_MOUNT, SELINUX_MOUNT, "selinuxfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV },
43fe83
+    { SELINUX_MOUNT, SELINUX_MOUNT, NULL, NULL, MS_BIND|MS_REMOUNT|MS_RDONLY },
43fe83
 #endif
43fe83
-    };
43fe83
+};
43fe83
+
43fe83
+
43fe83
+static int lxcContainerMountBasicFS(bool userns_enabled)
43fe83
+{
43fe83
     size_t i;
43fe83
     int rc = -1;
43fe83
 
43fe83
     VIR_DEBUG("Mounting basic filesystems");
43fe83
 
43fe83
-    for (i = 0; i < ARRAY_CARDINALITY(mnts); i++) {
43fe83
+    for (i = 0; i < ARRAY_CARDINALITY(lxcBasicMounts); i++) {
43fe83
+        virLXCBasicMountInfo const *mnt = &lxcBasicMounts[i];
43fe83
         const char *srcpath = NULL;
43fe83
 
43fe83
         VIR_DEBUG("Processing %s -> %s",
43fe83
-                  mnts[i].src, mnts[i].dst);
43fe83
+                  mnt->src, mnt->dst);
43fe83
 
43fe83
-        srcpath = mnts[i].src;
43fe83
+        srcpath = mnt->src;
43fe83
 
43fe83
         /* Skip if mount doesn't exist in source */
43fe83
         if ((srcpath[0] == '/') &&
43fe83
@@ -796,34 +801,34 @@ static int lxcContainerMountBasicFS(bool userns_enabled)
43fe83
             continue;
43fe83
 
43fe83
 #if WITH_SELINUX
43fe83
-        if (STREQ(mnts[i].src, SELINUX_MOUNT) &&
43fe83
+        if (STREQ(mnt->src, SELINUX_MOUNT) &&
43fe83
             !is_selinux_enabled())
43fe83
             continue;
43fe83
 #endif
43fe83
 
43fe83
-        if (STREQ(mnts[i].src, "securityfs") && userns_enabled)
43fe83
+        if (STREQ(mnt->src, "securityfs") && userns_enabled)
43fe83
             continue;
43fe83
 
43fe83
-        if (virFileMakePath(mnts[i].dst) < 0) {
43fe83
+        if (virFileMakePath(mnt->dst) < 0) {
43fe83
             virReportSystemError(errno,
43fe83
                                  _("Failed to mkdir %s"),
43fe83
-                                 mnts[i].src);
43fe83
+                                 mnt->src);
43fe83
             goto cleanup;
43fe83
         }
43fe83
 
43fe83
         VIR_DEBUG("Mount %s on %s type=%s flags=%x, opts=%s",
43fe83
-                  srcpath, mnts[i].dst, mnts[i].type, mnts[i].mflags, mnts[i].opts);
43fe83
-        if (mount(srcpath, mnts[i].dst, mnts[i].type, mnts[i].mflags, mnts[i].opts) < 0) {
43fe83
+                  srcpath, mnt->dst, mnt->type, mnt->mflags, mnt->opts);
43fe83
+        if (mount(srcpath, mnt->dst, mnt->type, mnt->mflags, mnt->opts) < 0) {
43fe83
 #if WITH_SELINUX
43fe83
-            if (STREQ(mnts[i].src, SELINUX_MOUNT) &&
43fe83
+            if (STREQ(mnt->src, SELINUX_MOUNT) &&
43fe83
                 (errno == EINVAL || errno == EPERM))
43fe83
                 continue;
43fe83
 #endif
43fe83
 
43fe83
             virReportSystemError(errno,
43fe83
                                  _("Failed to mount %s on %s type %s flags=%x opts=%s"),
43fe83
-                                 srcpath, mnts[i].dst, NULLSTR(mnts[i].type),
43fe83
-                                 mnts[i].mflags, NULLSTR(mnts[i].opts));
43fe83
+                                 srcpath, mnt->dst, NULLSTR(mnt->type),
43fe83
+                                 mnt->mflags, NULLSTR(mnt->opts));
43fe83
             goto cleanup;
43fe83
         }
43fe83
     }
43fe83
-- 
43fe83
1.8.3.2
43fe83