You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/01/24 02:12:41 UTC

[05/11] mesos git commit: Multiple Disk: Updated Slave initialize to create DiskInfo paths.

Multiple Disk: Updated Slave initialize to create DiskInfo paths.

Create disk paths based on 'DiskInfo.Source' if the type is 'PATH'
and the directory does not yet exist. On linux we validate mounts
against the mount table.

Review: https://reviews.apache.org/r/42474


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0aef5253
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0aef5253
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0aef5253

Branch: refs/heads/master
Commit: 0aef5253de8f4ef7ef4766d8cdcd75978e2cba86
Parents: 3e9cf54
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Mon Jan 18 15:30:39 2016 -0500
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Sat Jan 23 17:11:03 2016 -0800

----------------------------------------------------------------------
 src/slave/containerizer/containerizer.cpp |  5 ++
 src/slave/slave.cpp                       | 73 +++++++++++++++++++++++++-
 src/v1/resources.cpp                      |  1 +
 3 files changed, 78 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0aef5253/src/slave/containerizer/containerizer.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/containerizer.cpp b/src/slave/containerizer/containerizer.cpp
index 5e7e55e..298acb0 100644
--- a/src/slave/containerizer/containerizer.cpp
+++ b/src/slave/containerizer/containerizer.cpp
@@ -154,6 +154,11 @@ Try<Resources> Containerizer::resources(const Flags& flags)
         flags.default_role).get();
   }
 
+  Option<Error> error = Resources::validate(resources);
+  if (error.isSome()) {
+    return error.get();
+  }
+
   return resources;
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/0aef5253/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index 2a992f9..1f4c836 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -64,6 +64,7 @@
 
 #ifdef __linux__
 #include "linux/cgroups.hpp"
+#include "linux/fs.hpp"
 #endif // __linux__
 
 #include "authentication/cram_md5/authenticatee.hpp"
@@ -353,6 +354,76 @@ void Slave::initialize()
     EXIT(1) << "Failed to determine slave resources: " << resources.error();
   }
 
+  // Ensure disk `source`s are accessible.
+  foreach (
+      const Resource& resource,
+      resources->filter([](const Resource& resource) {
+        return resource.has_disk() && resource.disk().has_source();
+      })) {
+    // For `PATH` sources we create them if they do not exist.
+    const Resource::DiskInfo::Source& source = resource.disk().source();
+    if (source.type() == Resource::DiskInfo::Source::PATH) {
+      CHECK(source.has_path());
+
+      Try<Nothing> mkdir =
+        os::mkdir(source.path().root(), true);
+
+      if (mkdir.isError()) {
+        EXIT(1) << "Failed to create DiskInfo path directory '"
+                << source.path().root() << "': " << mkdir.error();
+      }
+    } else if (source.type() == Resource::DiskInfo::Source::MOUNT) {
+      CHECK(source.has_mount());
+
+      // For `MOUNT` sources we fail if they don't exist.
+      // On Linux we test the mount table for existence.
+#ifdef __linux__
+      // Get the `realpath` of the `root` to verify it against the
+      // mount table entries.
+      // TODO(jmlvanre): Consider enforcing allowing only real paths
+      // as opposed to symlinks. This would prevent the ability for
+      // an operator to change the underlying data while the slave
+      // checkpointed `root` had the same value. We could also check
+      // the UUID of the underlying block device to catch this case.
+      Result<string> realpath = os::realpath(source.mount().root());
+
+      if (!realpath.isSome()) {
+        EXIT(1)
+          << "Failed to determine `realpath` for DiskInfo mount in resource '"
+          << resource << "' with path '" << source.mount().root() << "': "
+          << (realpath.isError() ? realpath.error() : "no such path");
+      }
+
+      // TODO(jmlvanre): Consider moving this out of the for loop.
+      Try<fs::MountTable> mountTable = fs::MountTable::read("/proc/mounts");
+      if (mountTable.isError()) {
+        EXIT(1) << "Failed to open mount table to verify mounts: "
+                << mountTable.error();
+      }
+
+      bool foundEntry = false;
+      foreach (const fs::MountTable::Entry& entry, mountTable.get().entries) {
+        if (entry.dir == realpath.get()) {
+          foundEntry = true;
+          break;
+        }
+      }
+
+      if (!foundEntry) {
+        EXIT(1) << "Failed to found mount '" << realpath.get()
+                << "' in /proc/mounts";
+      }
+#else // __linux__
+      // On other platforms we test whether that provided `root` exists.
+      if (!os::exists(source.mount().root())) {
+        EXIT(1) << "Failed to find mount point '" << source.mount().root();
+      }
+#endif // __linux__
+    } else {
+      EXIT(1) << "Unsupported 'DiskInfo.Source.Type' in '" << resource << "'";
+    }
+  }
+
   Attributes attributes;
   if (flags.attributes.isSome()) {
     attributes = Attributes::parse(flags.attributes.get());
@@ -4218,7 +4289,7 @@ void Slave::checkDiskUsage()
   // fs::usage() into async.
   // NOTE: We calculate disk usage of the file system on which the
   // slave work directory is mounted.
-  Future<double>(fs::usage(flags.work_dir))
+  Future<double>(::fs::usage(flags.work_dir))
     .onAny(defer(self(), &Slave::_checkDiskUsage, lambda::_1));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/0aef5253/src/v1/resources.cpp
----------------------------------------------------------------------
diff --git a/src/v1/resources.cpp b/src/v1/resources.cpp
index c1da047..8c5a72d 100644
--- a/src/v1/resources.cpp
+++ b/src/v1/resources.cpp
@@ -600,6 +600,7 @@ Try<Resources> Resources::parse(
     }
   }
 
+  // TODO(jmlvanre): Move this up into `Containerizer::resources`.
   Option<Error> error = internal::validateCommandLineResources(result);
   if (error.isSome()) {
     return error.get();