You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2015/09/30 01:21:46 UTC
[1/2] mesos git commit: Ensured that slave's work_dir is a shared
mount in its own peer group when LinuxFilesystemIsolator is used.
Repository: mesos
Updated Branches:
refs/heads/master a6f1cf3a5 -> 2844a9617
Ensured that slave's work_dir is a shared mount in its own peer group
when LinuxFilesystemIsolator is used.
Review: https://reviews.apache.org/r/38858
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2844a961
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2844a961
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2844a961
Branch: refs/heads/master
Commit: 2844a9617e4cec34b41c52632971d2c472c0f63f
Parents: 68a9d95
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Sep 29 12:08:45 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Sep 29 16:15:11 2015 -0700
----------------------------------------------------------------------
src/linux/fs.hpp | 3 +
.../isolators/filesystem/linux.cpp | 51 +++++++++++++--
.../containerizer/filesystem_isolator_tests.cpp | 68 ++++++++++++++++++++
3 files changed, 115 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/2844a961/src/linux/fs.hpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.hpp b/src/linux/fs.hpp
index 0eb1642..2206220 100644
--- a/src/linux/fs.hpp
+++ b/src/linux/fs.hpp
@@ -206,6 +206,9 @@ struct MountInfoTable {
// for the calling process.
static Try<MountInfoTable> read(const Option<pid_t>& pid = None());
+ // TODO(jieyu): Introduce 'find' methods to find entries that match
+ // the given conditions (e.g., target, root, devno, etc.).
+
std::vector<Entry> entries;
};
http://git-wip-us.apache.org/repos/asf/mesos/blob/2844a961/src/slave/containerizer/isolators/filesystem/linux.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolators/filesystem/linux.cpp b/src/slave/containerizer/isolators/filesystem/linux.cpp
index 8fa929f..8823b78 100644
--- a/src/slave/containerizer/isolators/filesystem/linux.cpp
+++ b/src/slave/containerizer/isolators/filesystem/linux.cpp
@@ -93,7 +93,8 @@ Try<Isolator*> LinuxFilesystemIsolatorProcess::create(
}
}
- // Do a self bind mount if needed.
+ // Do a self bind mount if needed. If the mount already exists, make
+ // sure it is a shared mount of its own peer group.
if (workDirMount.isNone()) {
// NOTE: Instead of using fs::mount to perform the bind mount, we
// use the shell command here because the syscall 'mount' does not
@@ -117,13 +118,49 @@ Try<Isolator*> LinuxFilesystemIsolatorProcess::create(
"Failed to self bind mount '" + flags.work_dir +
"' and make it a shared mount: " + mount.error());
}
- }
+ } else {
+ if (workDirMount.get().shared().isNone()) {
+ // This is the case where the work directory mount is not a
+ // shared mount yet (possibly due to slave crash while preparing
+ // the work directory mount). It's safe to re-do the following.
+ Try<string> mount = os::shell(
+ "mount --make-slave %s && "
+ "mount --make-shared %s",
+ flags.work_dir.c_str(),
+ flags.work_dir.c_str());
- // TODO(jieyu): Currently, we don't check if the slave's work_dir
- // mount is a shared mount or not. We just assume it is. We cannot
- // simply mark the slave as shared again because that will create a
- // new peer group for the mounts. This is a temporary workaround for
- // now while we are thinking about fixes.
+ if (mount.isError()) {
+ return Error(
+ "Failed to self bind mount '" + flags.work_dir +
+ "' and make it a shared mount: " + mount.error());
+ }
+ } else {
+ // We need to make sure that the shared mount is in its own peer
+ // group. To check that, we need to get the parent mount.
+ foreach (const fs::MountInfoTable::Entry& entry, table.get().entries) {
+ if (entry.id == workDirMount.get().parent) {
+ // If the work directory mount and its parent mount are in
+ // the same peer group, we need to re-do the following
+ // commands so that they are in different peer groups.
+ if (entry.shared() == workDirMount.get().shared()) {
+ Try<string> mount = os::shell(
+ "mount --make-slave %s && "
+ "mount --make-shared %s",
+ flags.work_dir.c_str(),
+ flags.work_dir.c_str());
+
+ if (mount.isError()) {
+ return Error(
+ "Failed to self bind mount '" + flags.work_dir +
+ "' and make it a shared mount: " + mount.error());
+ }
+ }
+
+ break;
+ }
+ }
+ }
+ }
Owned<MesosIsolatorProcess> process(
new LinuxFilesystemIsolatorProcess(flags, provisioner));
http://git-wip-us.apache.org/repos/asf/mesos/blob/2844a961/src/tests/containerizer/filesystem_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/filesystem_isolator_tests.cpp b/src/tests/containerizer/filesystem_isolator_tests.cpp
index 41d098c..1e332e0 100644
--- a/src/tests/containerizer/filesystem_isolator_tests.cpp
+++ b/src/tests/containerizer/filesystem_isolator_tests.cpp
@@ -33,6 +33,10 @@
#include <stout/path.hpp>
#include <stout/uuid.hpp>
+#ifdef __linux__
+#include "linux/fs.hpp"
+#endif
+
#include "slave/paths.hpp"
#ifdef __linux__
@@ -904,6 +908,70 @@ TEST_F(LinuxFilesystemIsolatorTest, ROOT_SandboxEnvironmentVariable)
EXPECT_TRUE(wait.get().has_status());
EXPECT_EQ(0, wait.get().status());
}
+
+
+// This test verifies the slave's work directory mount preparation if
+// the mount does not exist initially.
+TEST_F(LinuxFilesystemIsolatorTest, ROOT_WorkDirMount)
+{
+ slave::Flags flags = CreateSlaveFlags();
+
+ Try<Isolator*> isolator =
+ LinuxFilesystemIsolatorProcess::create(flags, Owned<Provisioner>());
+
+ ASSERT_SOME(isolator);
+
+ Try<fs::MountInfoTable> table = fs::MountInfoTable::read();
+ ASSERT_SOME(table);
+
+ bool mountFound = false;
+ foreach (const fs::MountInfoTable::Entry& entry, table.get().entries) {
+ if (entry.target == flags.work_dir) {
+ EXPECT_SOME(entry.shared());
+ mountFound = true;
+ }
+ }
+
+ EXPECT_TRUE(mountFound);
+
+ delete isolator.get();
+}
+
+
+// This test verifies the slave's work directory mount preparation if
+// the mount already exists (e.g., to simulate the case when the slave
+// crashes while preparing the work directory mount).
+TEST_F(LinuxFilesystemIsolatorTest, ROOT_WorkDirMountPreExists)
+{
+ slave::Flags flags = CreateSlaveFlags();
+
+ // Simulate the situation in which the slave crashes while preparing
+ // the work directory mount.
+ ASSERT_SOME(os::shell(
+ "mount --bind %s %s",
+ flags.work_dir.c_str(),
+ flags.work_dir.c_str()));
+
+ Try<Isolator*> isolator =
+ LinuxFilesystemIsolatorProcess::create(flags, Owned<Provisioner>());
+
+ ASSERT_SOME(isolator);
+
+ Try<fs::MountInfoTable> table = fs::MountInfoTable::read();
+ ASSERT_SOME(table);
+
+ bool mountFound = false;
+ foreach (const fs::MountInfoTable::Entry& entry, table.get().entries) {
+ if (entry.target == flags.work_dir) {
+ EXPECT_SOME(entry.shared());
+ mountFound = true;
+ }
+ }
+
+ EXPECT_TRUE(mountFound);
+
+ delete isolator.get();
+}
#endif // __linux__
} // namespace tests {
[2/2] mesos git commit: Added support for getting shared and slave
mount peer group ID.
Posted by ji...@apache.org.
Added support for getting shared and slave mount peer group ID.
Review: https://reviews.apache.org/r/38855
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/68a9d950
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/68a9d950
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/68a9d950
Branch: refs/heads/master
Commit: 68a9d95090c8a84fff0ca0a350e678f9617e1a3e
Parents: a6f1cf3
Author: Jie Yu <yu...@gmail.com>
Authored: Tue Sep 29 10:36:19 2015 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Sep 29 16:15:11 2015 -0700
----------------------------------------------------------------------
src/linux/fs.cpp | 33 +++++++++
src/linux/fs.hpp | 12 +++-
src/tests/containerizer/fs_tests.cpp | 113 ++++++++++++++++++++++++++----
3 files changed, 144 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/68a9d950/src/linux/fs.cpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.cpp b/src/linux/fs.cpp
index 8631d89..27dc3e4 100644
--- a/src/linux/fs.cpp
+++ b/src/linux/fs.cpp
@@ -22,6 +22,7 @@
#include <linux/limits.h>
+#include <stout/check.hpp>
#include <stout/error.hpp>
#include <stout/numify.hpp>
#include <stout/path.hpp>
@@ -146,6 +147,38 @@ Try<MountInfoTable::Entry> MountInfoTable::Entry::parse(const string& s)
}
+Option<int> MountInfoTable::Entry::shared() const
+{
+ foreach (const string& token, strings::tokenize(optionalFields, " ")) {
+ if (strings::startsWith(token, "shared:")) {
+ Try<int> id = numify<int>(
+ strings::remove(token, "shared:", strings::PREFIX));
+
+ CHECK_SOME(id);
+ return id.get();
+ }
+ }
+
+ return None();
+}
+
+
+Option<int> MountInfoTable::Entry::master() const
+{
+ foreach (const string& token, strings::tokenize(optionalFields, " ")) {
+ if (strings::startsWith(token, "master:")) {
+ Try<int> id = numify<int>(
+ strings::remove(token, "master:", strings::PREFIX));
+
+ CHECK_SOME(id);
+ return id.get();
+ }
+ }
+
+ return None();
+}
+
+
bool MountTable::Entry::hasOption(const string& option) const
{
struct mntent mntent;
http://git-wip-us.apache.org/repos/asf/mesos/blob/68a9d950/src/linux/fs.hpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.hpp b/src/linux/fs.hpp
index f3aa0c2..0eb1642 100644
--- a/src/linux/fs.hpp
+++ b/src/linux/fs.hpp
@@ -167,8 +167,18 @@ struct MountInfoTable {
// See the /proc/[pid]/mountinfo section in 'man proc' for further
// details on each field.
struct Entry {
+ static Try<Entry> parse(const std::string& s);
+
Entry() {}
+ // Returns the ID of the peer group in which this mount resides.
+ // Returns none if this mount is not a shared mount.
+ Option<int> shared() const;
+
+ // Returns the ID of the peer group in which this mount's master
+ // resides in. Returns none if this mount is not a slave mount.
+ Option<int> master() const;
+
int id; // mountinfo[1]: mount ID.
int parent; // mountinfo[2]: parent ID.
dev_t devno; // mountinfo[3]: st_dev.
@@ -190,8 +200,6 @@ struct MountInfoTable {
std::string type; // mountinfo[9]: filesystem type.
std::string source; // mountinfo[10]: source dev, other.
-
- static Try<Entry> parse(const std::string& s);
};
// If pid is None() the "self" is used, i.e., the mountinfo table
http://git-wip-us.apache.org/repos/asf/mesos/blob/68a9d950/src/tests/containerizer/fs_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/fs_tests.cpp b/src/tests/containerizer/fs_tests.cpp
index 34d3c41..7fb4133 100644
--- a/src/tests/containerizer/fs_tests.cpp
+++ b/src/tests/containerizer/fs_tests.cpp
@@ -24,20 +24,27 @@
#include <stout/gtest.hpp>
#include <stout/none.hpp>
#include <stout/option.hpp>
+#include <stout/os.hpp>
#include <stout/try.hpp>
#include "linux/fs.hpp"
+#include "tests/utils.hpp"
+
+using std::string;
+
+using mesos::internal::fs::MountTable;
+using mesos::internal::fs::FileSystemTable;
+using mesos::internal::fs::MountInfoTable;
+
namespace mesos {
namespace internal {
namespace tests {
-using fs::MountTable;
-using fs::FileSystemTable;
-using fs::MountInfoTable;
+class FsTest : public TemporaryDirectoryTest {};
-TEST(FsTest, MountTableRead)
+TEST_F(FsTest, MountTableRead)
{
Try<MountTable> table = MountTable::read(_PATH_MOUNTED);
@@ -59,7 +66,7 @@ TEST(FsTest, MountTableRead)
}
-TEST(FsTest, MountTableHasOption)
+TEST_F(FsTest, MountTableHasOption)
{
Try<MountTable> table = MountTable::read(_PATH_MOUNTED);
@@ -77,7 +84,7 @@ TEST(FsTest, MountTableHasOption)
}
-TEST(FsTest, FileSystemTableRead)
+TEST_F(FsTest, FileSystemTableRead)
{
Try<FileSystemTable> table = FileSystemTable::read();
@@ -96,10 +103,10 @@ TEST(FsTest, FileSystemTableRead)
}
-TEST(FsTest, MountInfoTableParse)
+TEST_F(FsTest, MountInfoTableParse)
{
// Parse a private mount (no optional fields).
- const std::string privateMount =
+ const string privateMount =
"19 1 8:1 / / rw,relatime - ext4 /dev/sda1 rw,seclabel,data=ordered";
Try<MountInfoTable::Entry> entry = MountInfoTable::Entry::parse(privateMount);
@@ -116,7 +123,7 @@ TEST(FsTest, MountInfoTableParse)
EXPECT_EQ("/dev/sda1", entry.get().source);
// Parse a shared mount (includes one optional field).
- const std::string sharedMount =
+ const string sharedMount =
"19 1 8:1 / / rw,relatime shared:2 - ext4 /dev/sda1 rw,seclabel";
entry = MountInfoTable::Entry::parse(sharedMount);
@@ -134,10 +141,10 @@ TEST(FsTest, MountInfoTableParse)
}
-TEST(FsTest, DISABLED_MountInfoTableRead)
+TEST_F(FsTest, DISABLED_MountInfoTableRead)
{
// Examine the calling process's mountinfo table.
- Try<fs::MountInfoTable> table = fs::MountInfoTable::read();
+ Try<MountInfoTable> table = MountInfoTable::read();
ASSERT_SOME(table);
// Every system should have at least a rootfs mounted.
@@ -151,7 +158,7 @@ TEST(FsTest, DISABLED_MountInfoTableRead)
EXPECT_SOME(root);
// Repeat for pid 1.
- table = fs::MountInfoTable::read(1);
+ table = MountInfoTable::read(1);
ASSERT_SOME(table);
// Every system should have at least a rootfs mounted.
@@ -165,6 +172,88 @@ TEST(FsTest, DISABLED_MountInfoTableRead)
EXPECT_SOME(root);
}
+
+TEST_F(FsTest, ROOT_SharedMount)
+{
+ string directory = os::getcwd();
+
+ // Do a self bind mount of the temporary directory.
+ ASSERT_SOME(fs::mount(directory, directory, None(), MS_BIND, None()));
+
+ // Mark the mount as a shared mount.
+ ASSERT_SOME(fs::mount(None(), directory, None(), MS_SHARED, None()));
+
+ // Find the above mount in the mount table.
+ Try<MountInfoTable> table = MountInfoTable::read();
+ ASSERT_SOME(table);
+
+ Option<MountInfoTable::Entry> entry;
+ foreach (const MountInfoTable::Entry& _entry, table.get().entries) {
+ if (_entry.target == directory) {
+ entry = _entry;
+ }
+ }
+
+ ASSERT_SOME(entry);
+ EXPECT_SOME(entry.get().shared());
+
+ // Clean up the mount.
+ EXPECT_SOME(fs::unmount(directory));
+}
+
+
+TEST_F(FsTest, ROOT_SlaveMount)
+{
+ string directory = os::getcwd();
+
+ // Do a self bind mount of the temporary directory.
+ ASSERT_SOME(fs::mount(directory, directory, None(), MS_BIND, None()));
+
+ // Mark the mount as a shared mount of its own peer group.
+ ASSERT_SOME(fs::mount(None(), directory, None(), MS_PRIVATE, None()));
+ ASSERT_SOME(fs::mount(None(), directory, None(), MS_SHARED, None()));
+
+ // Create a sub-mount under 'directory'.
+ string source = path::join(directory, "source");
+ string target = path::join(directory, "target");
+
+ ASSERT_SOME(os::mkdir(source));
+ ASSERT_SOME(os::mkdir(target));
+
+ ASSERT_SOME(fs::mount(source, target, None(), MS_BIND, None()));
+
+ // Mark the sub-mount as a slave mount.
+ ASSERT_SOME(fs::mount(None(), target, None(), MS_SLAVE, None()));
+
+ // Find the above sub-mount in the mount table, and check if it is a
+ // slave mount as expected.
+ Try<MountInfoTable> table = MountInfoTable::read();
+ ASSERT_SOME(table);
+
+ Option<MountInfoTable::Entry> parent;
+ Option<MountInfoTable::Entry> child;
+ foreach (const MountInfoTable::Entry& entry, table.get().entries) {
+ if (entry.target == directory) {
+ ASSERT_NONE(parent);
+ parent = entry;
+ } else if (entry.target == target) {
+ ASSERT_NONE(child);
+ child = entry;
+ }
+ }
+
+ ASSERT_SOME(parent);
+ ASSERT_SOME(child);
+
+ EXPECT_SOME(parent.get().shared());
+ EXPECT_SOME(child.get().master());
+ EXPECT_EQ(child.get().master(), parent.get().shared());
+
+ // Clean up the mount.
+ EXPECT_SOME(fs::unmount(target));
+ EXPECT_SOME(fs::unmount(directory));
+}
+
} // namespace tests {
} // namespace internal {
} // namespace mesos {