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 2017/08/22 20:53:23 UTC

[3/8] mesos git commit: Exposed LinuxLauncher cgroups helper.

Exposed LinuxLauncher cgroups helper.

Expose the LinuxLauncher cgroups helper to generate the cgroups
path from a container ID. This is needed by the `network/ports`
isolator.

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


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

Branch: refs/heads/master
Commit: 092e4c5f1ab3753a7ba1dccaeb88b2fb58c0a3e6
Parents: 5fb4281
Author: James Peach <jp...@apache.org>
Authored: Tue Aug 22 13:37:40 2017 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Aug 22 13:37:40 2017 -0700

----------------------------------------------------------------------
 .../containerizer/mesos/linux_launcher.cpp      | 39 ++++++++++----------
 .../containerizer/mesos/linux_launcher.hpp      |  6 +++
 2 files changed, 26 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/092e4c5f/src/slave/containerizer/mesos/linux_launcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.cpp b/src/slave/containerizer/mesos/linux_launcher.cpp
index 1cea04e..554c598 100644
--- a/src/slave/containerizer/mesos/linux_launcher.cpp
+++ b/src/slave/containerizer/mesos/linux_launcher.cpp
@@ -107,10 +107,6 @@ private:
     Option<pid_t> pid = None();
   };
 
-  // Helper for determining the cgroup for a container (i.e., the path
-  // in a cgroup subsystem).
-  string cgroup(const ContainerID& containerId);
-
   // Helper for parsing the cgroup path to determine the container ID
   // it belongs to.
   Option<ContainerID> parse(const string& cgroup);
@@ -178,6 +174,19 @@ bool LinuxLauncher::available()
 }
 
 
+string LinuxLauncher::cgroup(
+    const string& cgroupsRoot,
+    const ContainerID& containerId)
+{
+  return path::join(
+      cgroupsRoot,
+      containerizer::paths::buildPath(
+          containerId,
+          CGROUP_SEPARATOR,
+          containerizer::paths::JOIN));
+}
+
+
 LinuxLauncher::LinuxLauncher(
     const Flags& flags,
     const string& freezerHierarchy,
@@ -454,7 +463,7 @@ Try<pid_t> LinuxLauncherProcess::fork(
   parentHooks.emplace_back(Subprocess::ParentHook([=](pid_t child) {
     return cgroups::isolate(
         freezerHierarchy,
-        cgroup(containerId),
+        LinuxLauncher::cgroup(this->flags.cgroups_root, containerId),
         child);
   }));
 
@@ -519,6 +528,9 @@ Future<Nothing> LinuxLauncherProcess::destroy(const ContainerID& containerId)
     }
   }
 
+  const string cgroup =
+    LinuxLauncher::cgroup(flags.cgroups_root, container->id);
+
   // We remove the container so that we don't attempt multiple
   // destroys simultaneously and no other functions will return
   // information about the container that is currently being (or has
@@ -534,7 +546,7 @@ Future<Nothing> LinuxLauncherProcess::destroy(const ContainerID& containerId)
   // is considered partially destroyed if we have recovered it from
   // ContainerState but we don't have a freezer cgroup for it. If this
   // is a partially destroyed container than there is nothing to do.
-  Try<bool> exists = cgroups::exists(freezerHierarchy, cgroup(container->id));
+  Try<bool> exists = cgroups::exists(freezerHierarchy, cgroup);
   if (exists.isError()) {
     return Failure("Failed to determine if cgroup exists: " + exists.error());
   }
@@ -545,7 +557,7 @@ Future<Nothing> LinuxLauncherProcess::destroy(const ContainerID& containerId)
     return Nothing();
   }
 
-  LOG(INFO) << "Using freezer to destroy cgroup " << cgroup(container->id);
+  LOG(INFO) << "Using freezer to destroy cgroup " << cgroup;
 
   // TODO(benh): If this is the last container at a nesting level,
   // should we also delete the `CGROUP_SEPARATOR` cgroup too?
@@ -554,7 +566,7 @@ Future<Nothing> LinuxLauncherProcess::destroy(const ContainerID& containerId)
   // retry?
   return cgroups::destroy(
       freezerHierarchy,
-      cgroup(container->id),
+      cgroup,
       cgroups::DESTROY_TIMEOUT);
 }
 
@@ -578,17 +590,6 @@ Future<ContainerStatus> LinuxLauncherProcess::status(
 }
 
 
-string LinuxLauncherProcess::cgroup(const ContainerID& containerId)
-{
-  return path::join(
-      flags.cgroups_root,
-      containerizer::paths::buildPath(
-          containerId,
-          CGROUP_SEPARATOR,
-          containerizer::paths::JOIN));
-}
-
-
 Option<ContainerID> LinuxLauncherProcess::parse(const string& cgroup)
 {
   Option<ContainerID> current;

http://git-wip-us.apache.org/repos/asf/mesos/blob/092e4c5f/src/slave/containerizer/mesos/linux_launcher.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/linux_launcher.hpp b/src/slave/containerizer/mesos/linux_launcher.hpp
index e152523..0ea9b87 100644
--- a/src/slave/containerizer/mesos/linux_launcher.hpp
+++ b/src/slave/containerizer/mesos/linux_launcher.hpp
@@ -37,6 +37,12 @@ public:
   // Returns 'true' if prerequisites for using LinuxLauncher are available.
   static bool available();
 
+  // Helper for determining the cgroup for a container (i.e., the path
+  // in a cgroup subsystem).
+  static std::string cgroup(
+      const std::string& cgroupsRoot,
+      const ContainerID& containerId);
+
   virtual ~LinuxLauncher();
 
   virtual process::Future<hashset<ContainerID>> recover(