teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame 0001-switch-root-remount-to-MS_PRIVATE.patch

Lennart Poettering bff934
From f47fc35555565c4b161c2e44b357b4dbaf3a997d Mon Sep 17 00:00:00 2001
Lennart Poettering bff934
From: Lennart Poettering <lennart@poettering.net>
Lennart Poettering bff934
Date: Sun, 12 Aug 2012 01:29:41 +0200
Lennart Poettering bff934
Subject: [PATCH] switch-root: remount to MS_PRIVATE
Lennart Poettering bff934
Lennart Poettering bff934
The kernel does not allow switching roots if things are mounted
Lennart Poettering bff934
MS_SHARED. As a work-around, remount things MS_PRIVATE before switching
Lennart Poettering bff934
roots.
Lennart Poettering bff934
Lennart Poettering bff934
This should be fixed in the kernel for good.
Lennart Poettering bff934
Lennart Poettering bff934
https://bugzilla.redhat.com/show_bug.cgi?id=847418
Lennart Poettering bff934
---
Lennart Poettering bff934
 src/core/shutdown.c    | 17 ++++++++---------
Lennart Poettering bff934
 src/core/switch-root.c |  9 +++++++++
Lennart Poettering bff934
 2 files changed, 17 insertions(+), 9 deletions(-)
Lennart Poettering bff934
Lennart Poettering bff934
diff --git a/src/core/shutdown.c b/src/core/shutdown.c
Lennart Poettering bff934
index 0b7cbd8..c3a4c39 100644
Lennart Poettering bff934
--- a/src/core/shutdown.c
Lennart Poettering bff934
+++ b/src/core/shutdown.c
Lennart Poettering bff934
@@ -104,15 +104,14 @@ static int pivot_to_new_root(void) {
Lennart Poettering bff934
                 return -errno;
Lennart Poettering bff934
         }
Lennart Poettering bff934
 
Lennart Poettering bff934
-        /*
Lennart Poettering bff934
-          In case some evil process made "/" MS_SHARED
Lennart Poettering bff934
-          It works for pivot_root, but the ref count for the root device
Lennart Poettering bff934
-          is not decreasing :-/
Lennart Poettering bff934
-        */
Lennart Poettering bff934
-        if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0) {
Lennart Poettering bff934
-                log_error("Failed to make \"/\" private mount %m");
Lennart Poettering bff934
-                return -errno;
Lennart Poettering bff934
-        }
Lennart Poettering bff934
+        /* Work-around for a kernel bug: for some reason the kernel
Lennart Poettering bff934
+         * refuses switching root if any file systems are mounted
Lennart Poettering bff934
+         * MS_SHARED. Hence remount them MS_PRIVATE here as a
Lennart Poettering bff934
+         * work-around.
Lennart Poettering bff934
+         *
Lennart Poettering bff934
+         * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */
Lennart Poettering bff934
+        if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
Lennart Poettering bff934
+                log_warning("Failed to make \"/\" private mount: %m");
Lennart Poettering bff934
 
Lennart Poettering bff934
         if (pivot_root(".", "oldroot") < 0) {
Lennart Poettering bff934
                 log_error("pivot failed: %m");
Lennart Poettering bff934
diff --git a/src/core/switch-root.c b/src/core/switch-root.c
Lennart Poettering bff934
index 9832a52..efc7d34 100644
Lennart Poettering bff934
--- a/src/core/switch-root.c
Lennart Poettering bff934
+++ b/src/core/switch-root.c
Lennart Poettering bff934
@@ -56,6 +56,15 @@ int switch_root(const char *new_root) {
Lennart Poettering bff934
                 goto fail;
Lennart Poettering bff934
         }
Lennart Poettering bff934
 
Lennart Poettering bff934
+        /* Work-around for a kernel bug: for some reason the kernel
Lennart Poettering bff934
+         * refuses switching root if any file systems are mounted
Lennart Poettering bff934
+         * MS_SHARED. Hence remount them MS_PRIVATE here as a
Lennart Poettering bff934
+         * work-around.
Lennart Poettering bff934
+         *
Lennart Poettering bff934
+         * https://bugzilla.redhat.com/show_bug.cgi?id=847418 */
Lennart Poettering bff934
+        if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
Lennart Poettering bff934
+                log_warning("Failed to make \"/\" private mount: %m");
Lennart Poettering bff934
+
Lennart Poettering bff934
         NULSTR_FOREACH(i, move_mounts) {
Lennart Poettering bff934
                 char new_mount[PATH_MAX];
Lennart Poettering bff934
                 struct stat sb;
Lennart Poettering bff934
-- 
Lennart Poettering bff934
1.7.11.2
Lennart Poettering bff934