Repository: mesos Updated Branches: refs/heads/master 73cd79584 -> 0f93a8d6b
Fixed marking mounts as slave in ubuntu. Review: https://reviews.apache.org/r/39719 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/38996a7c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/38996a7c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/38996a7c Branch: refs/heads/master Commit: 38996a7c9ef77c2366ac94c4bf75f5ace0b3fec6 Parents: 73cd795 Author: Timothy Chen <[email protected]> Authored: Sun Oct 25 17:38:19 2015 +0000 Committer: Timothy Chen <[email protected]> Committed: Thu Nov 5 18:15:56 2015 -0800 ---------------------------------------------------------------------- src/CMakeLists.txt | 1 + src/Makefile.am | 2 + .../mesos/isolators/filesystem/linux.cpp | 11 ++- src/slave/containerizer/mesos/main.cpp | 4 +- src/slave/containerizer/mesos/mount.cpp | 88 ++++++++++++++++++++ src/slave/containerizer/mesos/mount.hpp | 63 ++++++++++++++ 6 files changed, 167 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d107e32..cbc25e3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -197,6 +197,7 @@ if (NOT WIN32) slave/containerizer/launcher.cpp slave/containerizer/mesos/containerizer.cpp slave/containerizer/mesos/launch.cpp + slave/containerizer/mesos/mount.cpp slave/containerizer/mesos/provisioner/paths.cpp slave/containerizer/mesos/provisioner/provisioner.cpp slave/containerizer/mesos/provisioner/store.cpp http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/Makefile.am ---------------------------------------------------------------------- diff --git a/src/Makefile.am b/src/Makefile.am index d6eb302..cee8fbf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -732,6 +732,7 @@ if OS_LINUX libmesos_no_3rdparty_la_SOURCES += linux/perf.cpp libmesos_no_3rdparty_la_SOURCES += linux/systemd.cpp libmesos_no_3rdparty_la_SOURCES += slave/containerizer/linux_launcher.cpp + libmesos_no_3rdparty_la_SOURCES += slave/containerizer/mesos/mount.cpp libmesos_no_3rdparty_la_SOURCES += slave/containerizer/mesos/isolators/cgroups/cpushare.cpp libmesos_no_3rdparty_la_SOURCES += slave/containerizer/mesos/isolators/cgroups/mem.cpp libmesos_no_3rdparty_la_SOURCES += slave/containerizer/mesos/isolators/cgroups/perf_event.cpp @@ -856,6 +857,7 @@ libmesos_no_3rdparty_la_SOURCES += \ slave/containerizer/linux_launcher.hpp \ slave/containerizer/mesos/containerizer.hpp \ slave/containerizer/mesos/launch.hpp \ + slave/containerizer/mesos/mount.hpp \ slave/containerizer/mesos/isolators/posix.hpp \ slave/containerizer/mesos/isolators/posix/disk.hpp \ slave/containerizer/mesos/isolators/cgroups/constants.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp index a126cd6..b0a15d4 100644 --- a/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp +++ b/src/slave/containerizer/mesos/isolators/filesystem/linux.cpp @@ -40,6 +40,8 @@ #include "slave/paths.hpp" +#include "slave/containerizer/mesos/mount.hpp" + #include "slave/containerizer/mesos/isolators/filesystem/linux.hpp" using namespace process; @@ -462,7 +464,14 @@ Try<string> LinuxFilesystemIsolatorProcess::script( // Make sure mounts in the container mount namespace do not // propagate back to the host mount namespace. - out << "mount --make-rslave /\n"; + // NOTE: We cannot simply run `mount --make-rslave /`, for more info + // please refer to comments in mount.hpp. + MesosContainerizerMount::Flags mountFlags; + mountFlags.operation = MesosContainerizerMount::MAKE_RSLAVE; + mountFlags.path = "/"; + out << path::join(flags.launcher_dir, "mesos-containerizer") << " " + << MesosContainerizerMount::NAME << " " + << stringify(mountFlags) << "\n"; // Try to unmount work directory mounts and persistent volume mounts // for other containers to release the extra references to them. http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/slave/containerizer/mesos/main.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/main.cpp b/src/slave/containerizer/mesos/main.cpp index 0e17931..7430cee 100644 --- a/src/slave/containerizer/mesos/main.cpp +++ b/src/slave/containerizer/mesos/main.cpp @@ -20,6 +20,7 @@ #include <stout/subcommand.hpp> #include "slave/containerizer/mesos/launch.hpp" +#include "slave/containerizer/mesos/mount.hpp" using namespace mesos::internal::slave; @@ -30,5 +31,6 @@ int main(int argc, char** argv) None(), argc, argv, - new MesosContainerizerLaunch()); + new MesosContainerizerLaunch(), + new MesosContainerizerMount()); } http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/slave/containerizer/mesos/mount.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/mount.cpp b/src/slave/containerizer/mesos/mount.cpp new file mode 100644 index 0000000..462778c --- /dev/null +++ b/src/slave/containerizer/mesos/mount.cpp @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "slave/containerizer/mesos/mount.hpp" + +#include <iostream> +#include <string> + +#include <stout/nothing.hpp> +#include <stout/try.hpp> + +#include "linux/fs.hpp" + +using std::cerr; +using std::endl; +using std::string; + +namespace mesos { +namespace internal { +namespace slave { + +const string MesosContainerizerMount::NAME = "mount"; +const string MesosContainerizerMount::MAKE_RSLAVE = "make-rslave"; + + +MesosContainerizerMount::Flags::Flags() +{ + add(&operation, + "operation", + "The mount operation to apply."); + + add(&path, + "path", + "The path to apply mount operation to."); +} + + +int MesosContainerizerMount::execute() +{ + if (flags.operation.isNone()) { + cerr << "Flag --operation is not specified" << endl; + return 1; + } + + if (flags.operation.get() == MAKE_RSLAVE) { + if (flags.path.isNone()) { + cerr << "Flag --path is required for " << MAKE_RSLAVE << endl; + return 1; + } + + Try<Nothing> mount = mesos::internal::fs::mount( + None(), + flags.path.get(), + None(), + MS_SLAVE | MS_REC, + NULL); + + if (mount.isError()) { + cerr << "Failed to mark rslave with path '" << flags.path.get() << "': " + << mount.error(); + return 1; + } + } else { + cerr << "Unsupported mount operation '" << flags.operation.get() << "'"; + return 1; + } + + return 0; +} + +} // namespace slave { +} // namespace internal { +} // namespace mesos { http://git-wip-us.apache.org/repos/asf/mesos/blob/38996a7c/src/slave/containerizer/mesos/mount.hpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/mount.hpp b/src/slave/containerizer/mesos/mount.hpp new file mode 100644 index 0000000..d20f058 --- /dev/null +++ b/src/slave/containerizer/mesos/mount.hpp @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MESOS_CONTAINERIZER_MOUNT_HPP__ +#define __MESOS_CONTAINERIZER_MOUNT_HPP__ + +#include <stout/option.hpp> +#include <stout/subcommand.hpp> + +namespace mesos { +namespace internal { +namespace slave { + +// "mount" subcommand functions similiarly to the mount program. +// However, this subcommand is necessary because of the following reasons: +// - `mount --make-rslave <dir>` doesn't work on ubuntu 14.04 due to an existing +// bug. +// - mount program only handles mounts that is recorded in /etc/mtab and +// /etc/fstab, and ignores mounts that are done via mount syscall. +// We need this subcommand so we can effect all mounts. +class MesosContainerizerMount : public Subcommand +{ +public: + static const std::string NAME; + static const std::string MAKE_RSLAVE; + + struct Flags : public flags::FlagsBase + { + Flags(); + + Option<std::string> operation; + Option<std::string> path; + }; + + MesosContainerizerMount() : Subcommand(NAME) {} + + Flags flags; + +protected: + virtual int execute(); + virtual flags::FlagsBase* getFlags() { return &flags; } +}; + +} // namespace slave { +} // namespace internal { +} // namespace mesos { + +#endif // __MESOS_CONTAINERIZER_MOUNT_HPP__
