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 2018/02/08 01:25:53 UTC

[03/12] mesos git commit: Added `csi::paths::parseContainerPath` helper.

Added `csi::paths::parseContainerPath` helper.

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


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

Branch: refs/heads/master
Commit: e39a610b8335e8bf6d295e7a1d44bfccbb44d69f
Parents: a8cd3c7
Author: Chun-Hung Hsiao <ch...@mesosphere.io>
Authored: Wed Feb 7 16:03:53 2018 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Wed Feb 7 16:03:53 2018 -0800

----------------------------------------------------------------------
 src/csi/paths.cpp                          | 37 ++++++++++++++++++++++++-
 src/csi/paths.hpp                          | 13 +++++++++
 src/resource_provider/storage/provider.cpp | 17 ++++++++++--
 3 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e39a610b/src/csi/paths.cpp
----------------------------------------------------------------------
diff --git a/src/csi/paths.cpp b/src/csi/paths.cpp
index 60fca88..0d42db2 100644
--- a/src/csi/paths.cpp
+++ b/src/csi/paths.cpp
@@ -80,6 +80,41 @@ string getContainerPath(
 }
 
 
+Try<ContainerPath> parseContainerPath(const string& rootDir, const string& dir)
+{
+  // TODO(chhsiao): Consider using `<regex>`, which requires GCC 4.9+.
+
+  // Make sure there's a separator at the end of the `rootDir` so that
+  // we don't accidentally slice off part of a directory.
+  const string prefix = path::join(rootDir, "");
+
+  if (!strings::startsWith(dir, prefix)) {
+    return Error(
+        "Directory '" + dir + "' does not fall under the root directory '" +
+        rootDir + "'");
+  }
+
+  vector<string> tokens = strings::tokenize(
+      dir.substr(prefix.size()),
+      stringify(os::PATH_SEPARATOR));
+
+  // A complete container path consists of 4 tokens:
+  //   <type>/<name>/containers/<volume_id>
+  if (tokens.size() != 4 || tokens[2] != CONTAINERS_DIR) {
+    return Error(
+        "Path '" + path::join(tokens) + "' does not match the structure of a "
+        "container path");
+  }
+
+  ContainerPath path;
+  path.type = tokens[0];
+  path.name = tokens[1];
+  path.containerId.set_value(tokens[3]);
+
+  return path;
+}
+
+
 string getContainerInfoPath(
     const string& rootDir,
     const string& type,
@@ -186,7 +221,7 @@ Try<VolumePath> parseVolumePath(const string& rootDir, const string& dir)
 {
   // TODO(chhsiao): Consider using `<regex>`, which requires GCC 4.9+.
 
-  // Make sure there's a separator at the end of the `rootdir` so that
+  // Make sure there's a separator at the end of the `rootDir` so that
   // we don't accidentally slice off part of a directory.
   const string prefix = path::join(rootDir, "");
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/e39a610b/src/csi/paths.hpp
----------------------------------------------------------------------
diff --git a/src/csi/paths.hpp b/src/csi/paths.hpp
index 37f65f8..7892e5e 100644
--- a/src/csi/paths.hpp
+++ b/src/csi/paths.hpp
@@ -45,6 +45,14 @@ namespace paths {
 //               |-- <volume_id> (mount point)
 
 
+struct ContainerPath
+{
+  std::string type;
+  std::string name;
+  ContainerID containerId;
+};
+
+
 struct VolumePath
 {
   std::string type;
@@ -66,6 +74,11 @@ std::string getContainerPath(
     const ContainerID& containerId);
 
 
+Try<ContainerPath> parseContainerPath(
+    const std::string& rootDir,
+    const std::string& dir);
+
+
 std::string getContainerInfoPath(
     const std::string& rootDir,
     const std::string& type,

http://git-wip-us.apache.org/repos/asf/mesos/blob/e39a610b/src/resource_provider/storage/provider.cpp
----------------------------------------------------------------------
diff --git a/src/resource_provider/storage/provider.cpp b/src/resource_provider/storage/provider.cpp
index 604cadf..786a0ce 100644
--- a/src/resource_provider/storage/provider.cpp
+++ b/src/resource_provider/storage/provider.cpp
@@ -706,8 +706,21 @@ Future<Nothing> StorageLocalResourceProviderProcess::recoverServices()
   list<Future<Nothing>> futures;
 
   foreach (const string& path, containerPaths.get()) {
-    ContainerID containerId;
-    containerId.set_value(Path(path).basename());
+    Try<csi::paths::ContainerPath> containerPath =
+      csi::paths::parseContainerPath(
+          slave::paths::getCsiRootDir(workDir),
+          path);
+
+    if (containerPath.isError()) {
+      return Failure(
+          "Failed to parse container path '" + path + "': " +
+          containerPath.error());
+    }
+
+    CHECK_EQ(info.storage().plugin().type(), containerPath->type);
+    CHECK_EQ(info.storage().plugin().name(), containerPath->name);
+
+    const ContainerID& containerId = containerPath->containerId;
 
     // Do not kill the up-to-date controller or node container.
     // Otherwise, kill them and perform cleanups.