diff options
author | Justin DeMartino <jjdemartino@google.com> | 2020-10-14 19:39:53 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-10-14 19:39:53 +0000 |
commit | 0d11af03e43f110b0bb160f7e20436d0043e3038 (patch) | |
tree | 48f8bcca856276ec73a86dd3fb26143d3ca64578 /init/mount_namespace.cpp | |
parent | 075666ebd0dee8d0c4a2efa54f7c324a3f67ee2a (diff) | |
parent | a6c01e4e98d2b343dcecfc99611e2e6250c730db (diff) |
Merge changes from topic "SP1A.200921.001" into s-keystone-qcom-dev
* changes:
fs_mgr: adb-remount-test.sh: filter out more administrivia mounts.
Merge SP1A.200921.001 Change-Id: I90b97c4e9fb10b1f45e74def404823eed5b1aaa8
Diffstat (limited to 'init/mount_namespace.cpp')
-rw-r--r-- | init/mount_namespace.cpp | 59 |
1 files changed, 13 insertions, 46 deletions
diff --git a/init/mount_namespace.cpp b/init/mount_namespace.cpp index f8359bc64..59cc140e4 100644 --- a/init/mount_namespace.cpp +++ b/init/mount_namespace.cpp @@ -44,50 +44,17 @@ namespace android { namespace init { namespace { -static bool BindMount(const std::string& source, const std::string& mount_point, - bool recursive = false) { - unsigned long mountflags = MS_BIND; - if (recursive) { - mountflags |= MS_REC; - } - if (mount(source.c_str(), mount_point.c_str(), nullptr, mountflags, nullptr) == -1) { +static bool BindMount(const std::string& source, const std::string& mount_point) { + if (mount(source.c_str(), mount_point.c_str(), nullptr, MS_BIND | MS_REC, nullptr) == -1) { PLOG(ERROR) << "Failed to bind mount " << source; return false; } return true; } -static bool MakeShared(const std::string& mount_point, bool recursive = false) { - unsigned long mountflags = MS_SHARED; - if (recursive) { - mountflags |= MS_REC; - } - if (mount(nullptr, mount_point.c_str(), nullptr, mountflags, nullptr) == -1) { - PLOG(ERROR) << "Failed to change propagation type to shared"; - return false; - } - return true; -} - -static bool MakeSlave(const std::string& mount_point, bool recursive = false) { - unsigned long mountflags = MS_SLAVE; - if (recursive) { - mountflags |= MS_REC; - } - if (mount(nullptr, mount_point.c_str(), nullptr, mountflags, nullptr) == -1) { - PLOG(ERROR) << "Failed to change propagation type to slave"; - return false; - } - return true; -} - -static bool MakePrivate(const std::string& mount_point, bool recursive = false) { - unsigned long mountflags = MS_PRIVATE; - if (recursive) { - mountflags |= MS_REC; - } +static bool ChangeMount(const std::string& mount_point, unsigned long mountflags) { if (mount(nullptr, mount_point.c_str(), nullptr, mountflags, nullptr) == -1) { - PLOG(ERROR) << "Failed to change propagation type to private"; + PLOG(ERROR) << "Failed to remount " << mount_point << " as " << std::hex << mountflags; return false; } return true; @@ -225,17 +192,17 @@ bool SetupMountNamespaces() { // needed for /foo/bar, then we will make /foo/bar as a mount point (by // bind-mounting by to itself) and set the propagation type of the mount // point to private. - if (!MakeShared("/", true /*recursive*/)) return false; + if (!ChangeMount("/", MS_SHARED | MS_REC)) return false; // /apex is a private mountpoint to give different sets of APEXes for // the bootstrap and default mount namespaces. The processes running with // the bootstrap namespace get APEXes from the read-only partition. - if (!(MakePrivate("/apex"))) return false; + if (!(ChangeMount("/apex", MS_PRIVATE))) return false; // /linkerconfig is a private mountpoint to give a different linker configuration // based on the mount namespace. Subdirectory will be bind-mounted based on current mount // namespace - if (!(MakePrivate("/linkerconfig"))) return false; + if (!(ChangeMount("/linkerconfig", MS_PRIVATE))) return false; // The two mount namespaces present challenges for scoped storage, because // vold, which is responsible for most of the mounting, lives in the @@ -266,15 +233,15 @@ bool SetupMountNamespaces() { if (!mkdir_recursive("/mnt/user", 0755)) return false; if (!mkdir_recursive("/mnt/installer", 0755)) return false; if (!mkdir_recursive("/mnt/androidwritable", 0755)) return false; - if (!(BindMount("/mnt/user", "/mnt/installer", true))) return false; - if (!(BindMount("/mnt/user", "/mnt/androidwritable", true))) return false; + if (!(BindMount("/mnt/user", "/mnt/installer"))) return false; + if (!(BindMount("/mnt/user", "/mnt/androidwritable"))) return false; // First, make /mnt/installer and /mnt/androidwritable a slave bind mount - if (!(MakeSlave("/mnt/installer"))) return false; - if (!(MakeSlave("/mnt/androidwritable"))) return false; + if (!(ChangeMount("/mnt/installer", MS_SLAVE))) return false; + if (!(ChangeMount("/mnt/androidwritable", MS_SLAVE))) return false; // Then, make it shared again - effectively creating a new peer group, that // will be inherited by new mount namespaces. - if (!(MakeShared("/mnt/installer"))) return false; - if (!(MakeShared("/mnt/androidwritable"))) return false; + if (!(ChangeMount("/mnt/installer", MS_SHARED))) return false; + if (!(ChangeMount("/mnt/androidwritable", MS_SHARED))) return false; bootstrap_ns_fd.reset(OpenMountNamespace()); bootstrap_ns_id = GetMountNamespaceId(); |