Repository: mesos
Updated Branches:
  refs/heads/master 03240d8f9 -> cb0efcf67


Avoided to concat cgroup internally in subsystems.

To avoid using `path::join(flags.cgroups_root, containerId.value())`
to concat cgroup internally in subsystems, pass cgroup to the
subsystem interfaces directly.

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


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

Branch: refs/heads/master
Commit: cb0efcf67781c6b6b6b3534534ab1a39a96753f6
Parents: 03240d8
Author: haosdent huang <haosd...@gmail.com>
Authored: Mon Oct 17 15:47:32 2016 -0700
Committer: Jie Yu <yujie....@gmail.com>
Committed: Mon Oct 17 16:13:01 2016 -0700

----------------------------------------------------------------------
 .../mesos/isolators/cgroups/cgroups.cpp         | 30 ++++++--
 .../mesos/isolators/cgroups/subsystem.cpp       | 30 ++++++--
 .../mesos/isolators/cgroups/subsystem.hpp       | 31 ++++++--
 .../mesos/isolators/cgroups/subsystems/cpu.cpp  | 22 ++----
 .../mesos/isolators/cgroups/subsystems/cpu.hpp  |  4 +-
 .../isolators/cgroups/subsystems/cpuacct.cpp    | 13 ++--
 .../isolators/cgroups/subsystems/cpuacct.hpp    |  3 +-
 .../isolators/cgroups/subsystems/devices.cpp    | 20 +++--
 .../isolators/cgroups/subsystems/devices.hpp    | 14 +++-
 .../isolators/cgroups/subsystems/memory.cpp     | 79 ++++++++++----------
 .../isolators/cgroups/subsystems/memory.hpp     | 28 +++++--
 .../isolators/cgroups/subsystems/net_cls.cpp    | 23 ++++--
 .../isolators/cgroups/subsystems/net_cls.hpp    | 16 +++-
 .../isolators/cgroups/subsystems/perf_event.cpp | 32 ++++----
 .../isolators/cgroups/subsystems/perf_event.hpp | 19 +++--
 15 files changed, 229 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
index c2fcc0b..2f6723c 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -329,7 +329,7 @@ Future<Nothing> CgroupsIsolatorProcess::___recover(
 
     foreach (const Owned<Subsystem>& subsystem, subsystems.get(hierarchy)) {
       recoveredSubsystems.insert(subsystem->name());
-      recovers.push_back(subsystem->recover(containerId));
+      recovers.push_back(subsystem->recover(containerId, cgroup));
     }
   }
 
@@ -429,7 +429,9 @@ Future<Option<ContainerLaunchInfo>> 
CgroupsIsolatorProcess::prepare(
 
     foreach (const Owned<Subsystem>& subsystem, subsystems.get(hierarchy)) {
       infos[containerId]->subsystems.insert(subsystem->name());
-      prepares.push_back(subsystem->prepare(containerId));
+      prepares.push_back(subsystem->prepare(
+          containerId,
+          infos[containerId]->cgroup));
     }
 
     // Chown the cgroup so the executor can create nested cgroups. Do
@@ -567,7 +569,10 @@ Future<Nothing> CgroupsIsolatorProcess::isolate(
 
   list<Future<Nothing>> isolates;
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
-    isolates.push_back(subsystem->isolate(containerId, pid));
+    isolates.push_back(subsystem->isolate(
+        containerId,
+        infos[containerId]->cgroup,
+        pid));
   }
 
   return await(isolates)
@@ -616,7 +621,7 @@ Future<ContainerLimitation> CgroupsIsolatorProcess::watch(
 
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
     if (infos[containerId]->subsystems.contains(subsystem->name())) {
-      subsystem->watch(containerId)
+      subsystem->watch(containerId, infos[containerId]->cgroup)
         .onAny(defer(
             PID<CgroupsIsolatorProcess>(this),
             &CgroupsIsolatorProcess::_watch,
@@ -658,7 +663,10 @@ Future<Nothing> CgroupsIsolatorProcess::update(
   list<Future<Nothing>> updates;
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
     if (infos[containerId]->subsystems.contains(subsystem->name())) {
-      updates.push_back(subsystem->update(containerId, resources));
+      updates.push_back(subsystem->update(
+          containerId,
+          infos[containerId]->cgroup,
+          resources));
     }
   }
 
@@ -706,7 +714,9 @@ Future<ResourceStatistics> CgroupsIsolatorProcess::usage(
   list<Future<ResourceStatistics>> usages;
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
     if (infos[containerId]->subsystems.contains(subsystem->name())) {
-      usages.push_back(subsystem->usage(containerId));
+      usages.push_back(subsystem->usage(
+          containerId,
+          infos[containerId]->cgroup));
     }
   }
 
@@ -744,7 +754,9 @@ Future<ContainerStatus> CgroupsIsolatorProcess::status(
   list<Future<ContainerStatus>> statuses;
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
     if (infos[containerId]->subsystems.contains(subsystem->name())) {
-      statuses.push_back(subsystem->status(containerId));
+      statuses.push_back(subsystem->status(
+          containerId,
+          infos[containerId]->cgroup));
     }
   }
 
@@ -785,7 +797,9 @@ Future<Nothing> CgroupsIsolatorProcess::cleanup(
   list<Future<Nothing>> cleanups;
   foreachvalue (const Owned<Subsystem>& subsystem, subsystems) {
     if (infos[containerId]->subsystems.contains(subsystem->name())) {
-      cleanups.push_back(subsystem->cleanup(containerId));
+      cleanups.push_back(subsystem->cleanup(
+          containerId,
+          infos[containerId]->cgroup));
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
index 05cb8b8..bf7dc9e 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.cpp
@@ -75,25 +75,34 @@ Subsystem::Subsystem(
     hierarchy(_hierarchy) {}
 
 
-Future<Nothing> Subsystem::recover(const ContainerID& containerId)
+Future<Nothing> Subsystem::recover(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return Nothing();
 }
 
 
-Future<Nothing> Subsystem::prepare(const ContainerID& containerId)
+Future<Nothing> Subsystem::prepare(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return Nothing();
 }
 
 
-Future<Nothing> Subsystem::isolate(const ContainerID& containerId, pid_t pid)
+Future<Nothing> Subsystem::isolate(
+    const ContainerID& containerId,
+    const string& cgroup,
+    pid_t pid)
 {
   return Nothing();
 }
 
 
-Future<ContainerLimitation> Subsystem::watch(const ContainerID& containerId)
+Future<ContainerLimitation> Subsystem::watch(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return Future<ContainerLimitation>();
 }
@@ -101,25 +110,32 @@ Future<ContainerLimitation> Subsystem::watch(const 
ContainerID& containerId)
 
 Future<Nothing> Subsystem::update(
     const ContainerID& containerId,
+    const string& cgroup,
     const Resources& resources)
 {
   return Nothing();
 }
 
 
-Future<ResourceStatistics> Subsystem::usage(const ContainerID& containerId)
+Future<ResourceStatistics> Subsystem::usage(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return ResourceStatistics();
 }
 
 
-Future<ContainerStatus> Subsystem::status(const ContainerID& containerId)
+Future<ContainerStatus> Subsystem::status(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return ContainerStatus();
 }
 
 
-Future<Nothing> Subsystem::cleanup(const ContainerID& containerId)
+Future<Nothing> Subsystem::cleanup(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   return Nothing();
 }

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
index 6594110..bbc208b 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystem.hpp
@@ -69,49 +69,61 @@ public:
    * Recover the cgroups subsystem for the associated container.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return Nothing or an error if `recover` fails.
    */
-  virtual process::Future<Nothing> recover(const ContainerID& containerId);
+  virtual process::Future<Nothing> recover(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   /**
    * Prepare the cgroups subsystem for the associated container.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return Nothing or an error if `prepare` fails.
    */
-  virtual process::Future<Nothing> prepare(const ContainerID& containerId);
+  virtual process::Future<Nothing> prepare(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   /**
    * Isolate the associated container to cgroups subsystem.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @param pid The process id of container.
    * @return Nothing or an error if `isolate` fails.
    */
   virtual process::Future<Nothing> isolate(
       const ContainerID& containerId,
+      const std::string& cgroup,
       pid_t pid);
 
   /**
    * Watch the container and report if any resource constraint impacts it.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return The resource limitation that impacts the container or an
    *     error if `watch` fails.
    */
   virtual process::Future<mesos::slave::ContainerLimitation> watch(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   /**
    * Update resources allocated to the associated container in this
    * cgroups subsystem.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @param resources The resources need to update.
    * @return Nothing or an error if `update` fails.
    */
   virtual process::Future<Nothing> update(
       const ContainerID& containerId,
+      const std::string& cgroup,
       const Resources& resources);
 
   /**
@@ -119,21 +131,25 @@ public:
    * associated container.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return The resource usage statistics or an error if gather statistics
    *     fails.
    */
   virtual process::Future<ResourceStatistics> usage(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   /**
    * Get the run-time status of cgroups subsystem specific properties
    * associated with the container.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return The container status or an error if get fails.
    */
   virtual process::Future<ContainerStatus> status(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   /**
    * Clean up the cgroups subsystem for the associated container. It
@@ -144,9 +160,12 @@ public:
    * container is unknown to the subsystem.
    *
    * @param containerId The target containerId.
+   * @param cgroup The target cgroup.
    * @return Nothing or an error if `cleanup` fails.
    */
-  virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+  virtual process::Future<Nothing> cleanup(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 protected:
   Subsystem(const Flags& _flags, const std::string& _hierarchy);

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.cpp
index 5912c65..39da15a 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.cpp
@@ -67,6 +67,7 @@ CpuSubsystem::CpuSubsystem(
 
 Future<Nothing> CpuSubsystem::update(
     const ContainerID& containerId,
+    const std::string& cgroup,
     const Resources& resources)
 {
   if (resources.cpus().isNone()) {
@@ -91,10 +92,7 @@ Future<Nothing> CpuSubsystem::update(
         MIN_CPU_SHARES);
   }
 
-  Try<Nothing> write = cgroups::cpu::shares(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
-      shares);
+  Try<Nothing> write = cgroups::cpu::shares(hierarchy, cgroup, shares);
 
   if (write.isError()) {
     return Failure("Failed to update 'cpu.shares': " + write.error());
@@ -106,10 +104,7 @@ Future<Nothing> CpuSubsystem::update(
 
   // Set cfs quota if enabled.
   if (flags.cgroups_enable_cfs) {
-    write = cgroups::cpu::cfs_period_us(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
-        CPU_CFS_PERIOD);
+    write = cgroups::cpu::cfs_period_us(hierarchy, cgroup, CPU_CFS_PERIOD);
 
     if (write.isError()) {
       return Failure("Failed to update 'cpu.cfs_period_us': " + write.error());
@@ -117,10 +112,7 @@ Future<Nothing> CpuSubsystem::update(
 
     Duration quota = std::max(CPU_CFS_PERIOD * cpus, MIN_CPU_CFS_QUOTA);
 
-    write = cgroups::cpu::cfs_quota_us(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
-        quota);
+    write = cgroups::cpu::cfs_quota_us(hierarchy, cgroup, quota);
 
     if (write.isError()) {
       return Failure("Failed to update 'cpu.cfs_quota_us': " + write.error());
@@ -136,7 +128,9 @@ Future<Nothing> CpuSubsystem::update(
 }
 
 
-Future<ResourceStatistics> CpuSubsystem::usage(const ContainerID& containerId)
+Future<ResourceStatistics> CpuSubsystem::usage(
+    const ContainerID& containerId,
+    const std::string& cgroup)
 {
   ResourceStatistics result;
 
@@ -144,7 +138,7 @@ Future<ResourceStatistics> CpuSubsystem::usage(const 
ContainerID& containerId)
   if (flags.cgroups_enable_cfs) {
     Try<hashmap<string, uint64_t>> stat = cgroups::stat(
         hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
+        cgroup,
         "cpu.stat");
 
     if (stat.isError()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.hpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.hpp
index c1f1004..282a761 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpu.hpp
@@ -51,10 +51,12 @@ public:
 
   virtual process::Future<Nothing> update(
       const ContainerID& containerId,
+      const std::string& cgroup,
       const Resources& resources);
 
   virtual process::Future<ResourceStatistics> usage(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 private:
   CpuSubsystem(const Flags& flags, const std::string& hierarchy);

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.cpp
index a35ecb0..ffa0d3b 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.cpp
@@ -47,7 +47,8 @@ CpuacctSubsystem::CpuacctSubsystem(
 
 
 Future<ResourceStatistics> CpuacctSubsystem::usage(
-    const ContainerID& containerId)
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   ResourceStatistics result;
 
@@ -64,9 +65,7 @@ Future<ResourceStatistics> CpuacctSubsystem::usage(
   // performance bottleneck, some kind of rate limiting mechanism
   // needs to be employed.
   if (flags.cgroups_cpu_enable_pids_and_tids_count) {
-    Try<set<pid_t>> pids = cgroups::processes(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()));
+    Try<set<pid_t>> pids = cgroups::processes(hierarchy, cgroup);
 
     if (pids.isError()) {
       return Failure("Failed to get number of processes: " + pids.error());
@@ -74,9 +73,7 @@ Future<ResourceStatistics> CpuacctSubsystem::usage(
 
     result.set_processes(pids.get().size());
 
-    Try<set<pid_t>> tids = cgroups::threads(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()));
+    Try<set<pid_t>> tids = cgroups::threads(hierarchy, cgroup);
 
     if (tids.isError()) {
       return Failure("Failed to get number of threads: " + tids.error());
@@ -93,7 +90,7 @@ Future<ResourceStatistics> CpuacctSubsystem::usage(
   // Add the cpuacct.stat information.
   Try<hashmap<string, uint64_t>> stat = cgroups::stat(
       hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
+      cgroup,
       "cpuacct.stat");
 
   if (stat.isError()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.hpp
index 10fbbc9..e4977da 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/cpuacct.hpp
@@ -50,7 +50,8 @@ public:
   }
 
   virtual process::Future<ResourceStatistics> usage(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 private:
   CpuacctSubsystem(const Flags& flags, const std::string& hierarchy);

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.cpp
index 0afc248..9b5cf83 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.cpp
@@ -74,7 +74,9 @@ DevicesSubsystem::DevicesSubsystem(
     Subsystem(_flags, _hierarchy) {}
 
 
-Future<Nothing> DevicesSubsystem::recover(const ContainerID& containerId)
+Future<Nothing> DevicesSubsystem::recover(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (containerIds.contains(containerId)) {
     return Failure(
@@ -88,7 +90,9 @@ Future<Nothing> DevicesSubsystem::recover(const ContainerID& 
containerId)
 }
 
 
-Future<Nothing> DevicesSubsystem::prepare(const ContainerID& containerId)
+Future<Nothing> DevicesSubsystem::prepare(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (containerIds.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been prepared");
@@ -117,10 +121,7 @@ Future<Nothing> DevicesSubsystem::prepare(const 
ContainerID& containerId)
   all.access.write = true;
   all.access.mknod = true;
 
-  Try<Nothing> deny = cgroups::devices::deny(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
-      all);
+  Try<Nothing> deny = cgroups::devices::deny(hierarchy, cgroup, all);
 
   if (deny.isError()) {
     return Failure("Failed to deny all devices: " + deny.error());
@@ -133,7 +134,8 @@ Future<Nothing> DevicesSubsystem::prepare(const 
ContainerID& containerId)
     CHECK_SOME(entry);
 
     Try<Nothing> allow = cgroups::devices::allow(
-        hierarchy, path::join(flags.cgroups_root, containerId.value()),
+        hierarchy,
+        cgroup,
         entry.get());
 
     if (allow.isError()) {
@@ -148,7 +150,9 @@ Future<Nothing> DevicesSubsystem::prepare(const 
ContainerID& containerId)
 }
 
 
-Future<Nothing> DevicesSubsystem::cleanup(const ContainerID& containerId)
+Future<Nothing> DevicesSubsystem::cleanup(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!containerIds.contains(containerId)) {
     VLOG(1) << "Ignoring cleanup subsystem '" << name() << "' "

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.hpp
index b5d5ed2..ca27271 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/devices.hpp
@@ -50,9 +50,17 @@ public:
     return CGROUP_SUBSYSTEM_DEVICES_NAME;
   }
 
-  virtual process::Future<Nothing> prepare(const ContainerID& containerId);
-  virtual process::Future<Nothing> recover(const ContainerID& containerId);
-  virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+  virtual process::Future<Nothing> prepare(
+      const ContainerID& containerId,
+      const std::string& cgroup);
+
+  virtual process::Future<Nothing> recover(
+      const ContainerID& containerId,
+      const std::string& cgroup);
+
+  virtual process::Future<Nothing> cleanup(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 private:
   DevicesSubsystem(const Flags& flags, const std::string& hierarchy);

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
index 5b3ce15..009e996 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.cpp
@@ -115,7 +115,9 @@ MemorySubsystem::MemorySubsystem(
     Subsystem(_flags, _hierarchy) {}
 
 
-Future<Nothing> MemorySubsystem::recover(const ContainerID& containerId)
+Future<Nothing> MemorySubsystem::recover(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been 
recovered");
@@ -123,14 +125,16 @@ Future<Nothing> MemorySubsystem::recover(const 
ContainerID& containerId)
 
   infos.put(containerId, Owned<Info>(new Info));
 
-  oomListen(containerId);
-  pressureListen(containerId);
+  oomListen(containerId, cgroup);
+  pressureListen(containerId, cgroup);
 
   return Nothing();
 }
 
 
-Future<Nothing> MemorySubsystem::prepare(const ContainerID& containerId)
+Future<Nothing> MemorySubsystem::prepare(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been prepared");
@@ -138,15 +142,16 @@ Future<Nothing> MemorySubsystem::prepare(const 
ContainerID& containerId)
 
   infos.put(containerId, Owned<Info>(new Info));
 
-  oomListen(containerId);
-  pressureListen(containerId);
+  oomListen(containerId, cgroup);
+  pressureListen(containerId, cgroup);
 
   return Nothing();
 }
 
 
 Future<ContainerLimitation> MemorySubsystem::watch(
-    const ContainerID& containerId)
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     return Failure(
@@ -160,6 +165,7 @@ Future<ContainerLimitation> MemorySubsystem::watch(
 
 Future<Nothing> MemorySubsystem::update(
     const ContainerID& containerId,
+    const string& cgroup,
     const Resources& resources)
 {
   if (!infos.contains(containerId)) {
@@ -181,7 +187,7 @@ Future<Nothing> MemorySubsystem::update(
   // Always set the soft limit.
   Try<Nothing> write = cgroups::memory::soft_limit_in_bytes(
       hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
+      cgroup,
       limit);
 
   if (write.isError()) {
@@ -194,9 +200,7 @@ Future<Nothing> MemorySubsystem::update(
             << limit << " for container " << containerId;
 
   // Read the existing limit.
-  Try<Bytes> currentLimit = cgroups::memory::limit_in_bytes(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  Try<Bytes> currentLimit = cgroups::memory::limit_in_bytes(hierarchy, cgroup);
 
   // NOTE: If `flags.cgroups_limit_swap` is (has been) used then both
   // 'limit_in_bytes' and 'memsw.limit_in_bytes' will always be set to
@@ -235,7 +239,7 @@ Future<Nothing> MemorySubsystem::update(
     // memsw.limit_in_bytes if `cgroups_limit_swap` is true.
     Try<Nothing> write = cgroups::memory::limit_in_bytes(
         hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
+        cgroup,
         limit);
 
     if (write.isError()) {
@@ -250,7 +254,7 @@ Future<Nothing> MemorySubsystem::update(
     if (flags.cgroups_limit_swap) {
       Try<bool> write = cgroups::memory::memsw_limit_in_bytes(
           hierarchy,
-          path::join(flags.cgroups_root, containerId.value()),
+          cgroup,
           limit);
 
       if (write.isError()) {
@@ -269,7 +273,8 @@ Future<Nothing> MemorySubsystem::update(
 
 
 Future<ResourceStatistics> MemorySubsystem::usage(
-    const ContainerID& containerId)
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     return Failure(
@@ -284,9 +289,7 @@ Future<ResourceStatistics> MemorySubsystem::usage(
   // The rss from memory.stat is wrong in two dimensions:
   //   1. It does not include child cgroups.
   //   2. It does not include any file backed pages.
-  Try<Bytes> usage = cgroups::memory::usage_in_bytes(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  Try<Bytes> usage = cgroups::memory::usage_in_bytes(hierarchy, cgroup);
 
   if (usage.isError()) {
     return Failure("Failed to parse 'memory.usage_in_bytes': " + 
usage.error());
@@ -295,9 +298,7 @@ Future<ResourceStatistics> MemorySubsystem::usage(
   result.set_mem_total_bytes(usage.get().bytes());
 
   if (flags.cgroups_limit_swap) {
-    Try<Bytes> usage = cgroups::memory::memsw_usage_in_bytes(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()));
+    Try<Bytes> usage = cgroups::memory::memsw_usage_in_bytes(hierarchy, 
cgroup);
 
     if (usage.isError()) {
       return Failure(
@@ -311,7 +312,7 @@ Future<ResourceStatistics> MemorySubsystem::usage(
   // structure, e.g, cgroups::memory::stat.
   Try<hashmap<string, uint64_t>> stat = cgroups::stat(
       hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
+      cgroup,
       "memory.stat");
 
   if (stat.isError()) {
@@ -408,7 +409,9 @@ Future<ResourceStatistics> MemorySubsystem::_usage(
 }
 
 
-Future<Nothing> MemorySubsystem::cleanup(const ContainerID& containerId)
+Future<Nothing> MemorySubsystem::cleanup(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     VLOG(1) << "Ignoring cleanup subsystem '" << name() << "' "
@@ -427,15 +430,15 @@ Future<Nothing> MemorySubsystem::cleanup(const 
ContainerID& containerId)
 }
 
 
-void MemorySubsystem::oomListen(const ContainerID& containerId)
+void MemorySubsystem::oomListen(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   CHECK(infos.contains(containerId));
 
   const Owned<Info>& info = infos[containerId];
 
-  info->oomNotifier = cgroups::memory::oom::listen(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  info->oomNotifier = cgroups::memory::oom::listen(hierarchy, cgroup);
 
   // If the listening fails immediately, something very wrong
   // happened. Therefore, we report a fatal error here.
@@ -452,12 +455,14 @@ void MemorySubsystem::oomListen(const ContainerID& 
containerId)
       defer(PID<MemorySubsystem>(this),
             &MemorySubsystem::oomWaited,
             containerId,
+            cgroup,
             lambda::_1));
 }
 
 
 void MemorySubsystem::oomWaited(
     const ContainerID& containerId,
+    const string& cgroup,
     const Future<Nothing>& future)
 {
   if (future.isDiscarded()) {
@@ -491,9 +496,7 @@ void MemorySubsystem::oomWaited(
   // NOTE: If 'flags.cgroups_limit_swap' is (has been) used, then both
   // 'limit_in_bytes' and 'memsw.limit_in_bytes' will always be set to
   // the same value.
-  Try<Bytes> limit = cgroups::memory::limit_in_bytes(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  Try<Bytes> limit = cgroups::memory::limit_in_bytes(hierarchy, cgroup);
 
   if (limit.isError()) {
     LOG(ERROR) << "Failed to read 'memory.limit_in_bytes': " << limit.error();
@@ -502,9 +505,7 @@ void MemorySubsystem::oomWaited(
   }
 
   // Output the maximum memory usage.
-  Try<Bytes> usage = cgroups::memory::max_usage_in_bytes(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  Try<Bytes> usage = cgroups::memory::max_usage_in_bytes(hierarchy, cgroup);
 
   if (usage.isError()) {
     LOG(ERROR) << "Failed to read 'memory.max_usage_in_bytes': "
@@ -516,10 +517,7 @@ void MemorySubsystem::oomWaited(
   // Output 'memory.stat' of the cgroup to help with debugging.
   // NOTE: With kernel OOM-killer enabled these stats may not reflect
   // memory state at time of OOM.
-  Try<string> read = cgroups::read(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()),
-      "memory.stat");
+  Try<string> read = cgroups::read(hierarchy, cgroup, "memory.stat");
 
   if (read.isError()) {
     LOG(ERROR) << "Failed to read 'memory.stat': " << read.error();
@@ -545,15 +543,14 @@ void MemorySubsystem::oomWaited(
 }
 
 
-void MemorySubsystem::pressureListen(const ContainerID& containerId)
+void MemorySubsystem::pressureListen(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   CHECK(infos.contains(containerId));
 
   foreach (const Level& level, levels()) {
-    Try<Owned<Counter>> counter = Counter::create(
-        hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
-        level);
+    Try<Owned<Counter>> counter = Counter::create(hierarchy, cgroup, level);
 
     if (counter.isError()) {
       LOG(ERROR) << "Failed to listen on '" << level << "' memory pressure "

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.hpp
index a1c87ce..d79fda3 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/memory.hpp
@@ -55,21 +55,30 @@ public:
     return CGROUP_SUBSYSTEM_MEMORY_NAME;
   }
 
-  virtual process::Future<Nothing> prepare(const ContainerID& containerId);
+  virtual process::Future<Nothing> prepare(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> recover(const ContainerID& containerId);
+  virtual process::Future<Nothing> recover(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   virtual process::Future<mesos::slave::ContainerLimitation> watch(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   virtual process::Future<Nothing> update(
       const ContainerID& containerId,
+      const std::string& cgroup,
       const Resources& resources);
 
   virtual process::Future<ResourceStatistics> usage(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+  virtual process::Future<Nothing> cleanup(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 private:
   struct Info
@@ -94,16 +103,21 @@ private:
 
   // Start listening on OOM events. This function will create an
   // eventfd and start polling on it.
-  void oomListen(const ContainerID& containerId);
+  void oomListen(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   // This function is invoked when the polling on eventfd has a
   // result.
   void oomWaited(
       const ContainerID& containerId,
+      const std::string& cgroup,
       const process::Future<Nothing>& future);
 
   // Start listening on memory pressure events.
-  void pressureListen(const ContainerID& containerId);
+  void pressureListen(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   // Stores cgroups associated information for container.
   hashmap<ContainerID, process::Owned<Info>> infos;

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.cpp
index 93539f1..2608df1 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.cpp
@@ -308,16 +308,16 @@ NetClsSubsystem::NetClsSubsystem(
 }
 
 
-Future<Nothing> NetClsSubsystem::recover(const ContainerID& containerId)
+Future<Nothing> NetClsSubsystem::recover(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been 
recovered");
   }
 
   // Read the net_cls handle.
-  Result<NetClsHandle> handle = recoverHandle(
-      hierarchy,
-      path::join(flags.cgroups_root, containerId.value()));
+  Result<NetClsHandle> handle = recoverHandle(hierarchy, cgroup);
 
   if (handle.isError()) {
     return Failure(
@@ -334,7 +334,9 @@ Future<Nothing> NetClsSubsystem::recover(const ContainerID& 
containerId)
 }
 
 
-Future<Nothing> NetClsSubsystem::prepare(const ContainerID& containerId)
+Future<Nothing> NetClsSubsystem::prepare(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been prepared");
@@ -361,6 +363,7 @@ Future<Nothing> NetClsSubsystem::prepare(const ContainerID& 
containerId)
 
 Future<Nothing> NetClsSubsystem::isolate(
     const ContainerID& containerId,
+    const string& cgroup,
     pid_t pid)
 {
   if (!infos.contains(containerId)) {
@@ -376,7 +379,7 @@ Future<Nothing> NetClsSubsystem::isolate(
   if (info->handle.isSome()) {
     Try<Nothing> write = cgroups::net_cls::classid(
         hierarchy,
-        path::join(flags.cgroups_root, containerId.value()),
+        cgroup,
         info->handle->get());
 
     if (write.isError()) {
@@ -390,7 +393,9 @@ Future<Nothing> NetClsSubsystem::isolate(
 }
 
 
-Future<ContainerStatus> NetClsSubsystem::status(const ContainerID& containerId)
+Future<ContainerStatus> NetClsSubsystem::status(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     return Failure(
@@ -416,7 +421,9 @@ Future<ContainerStatus> NetClsSubsystem::status(const 
ContainerID& containerId)
 }
 
 
-Future<Nothing> NetClsSubsystem::cleanup(const ContainerID& containerId)
+Future<Nothing> NetClsSubsystem::cleanup(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     VLOG(1) << "Ignoring cleanup subsystem '" << name() << "' "

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp
index 1620865..bcaa161 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/net_cls.hpp
@@ -144,18 +144,26 @@ public:
     return CGROUP_SUBSYSTEM_NET_CLS_NAME;
   }
 
-  virtual process::Future<Nothing> recover(const ContainerID& containerId);
+  virtual process::Future<Nothing> recover(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> prepare(const ContainerID& containerId);
+  virtual process::Future<Nothing> prepare(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   virtual process::Future<Nothing> isolate(
       const ContainerID& containerId,
+      const std::string& cgroup,
       pid_t pid);
 
   virtual process::Future<ContainerStatus> status(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+  virtual process::Future<Nothing> cleanup(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 private:
   NetClsSubsystem(

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp
index cc39f28..d394d79 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.cpp
@@ -93,32 +93,37 @@ void PerfEventSubsystem::initialize()
 }
 
 
-Future<Nothing> PerfEventSubsystem::recover(const ContainerID& containerId)
+Future<Nothing> PerfEventSubsystem::recover(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been 
recovered");
   }
 
-  infos.put(containerId, Owned<Info>(new Info));
+  infos.put(containerId, Owned<Info>(new Info(cgroup)));
 
   return Nothing();
 }
 
 
-Future<Nothing> PerfEventSubsystem::prepare(const ContainerID& containerId)
+Future<Nothing> PerfEventSubsystem::prepare(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (infos.contains(containerId)) {
     return Failure("The subsystem '" + name() + "' has already been prepared");
   }
 
-  infos.put(containerId, Owned<Info>(new Info));
+  infos.put(containerId, Owned<Info>(new Info(cgroup)));
 
   return Nothing();
 }
 
 
 Future<ResourceStatistics> PerfEventSubsystem::usage(
-    const ContainerID& containerId)
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     return Failure(
@@ -133,7 +138,9 @@ Future<ResourceStatistics> PerfEventSubsystem::usage(
 }
 
 
-Future<Nothing> PerfEventSubsystem::cleanup(const ContainerID& containerId)
+Future<Nothing> PerfEventSubsystem::cleanup(
+    const ContainerID& containerId,
+    const string& cgroup)
 {
   if (!infos.contains(containerId)) {
     VLOG(1) << "Ignoring cleanup subsystem '" << name() << "' "
@@ -155,8 +162,8 @@ void PerfEventSubsystem::sample()
   // fail if the cgroup is destroyed before running perf.
   set<string> cgroups;
 
-  foreachkey (const ContainerID& containerId, infos) {
-    cgroups.insert(path::join(flags.cgroups_root, containerId.value()));
+  foreachvalue (const Owned<Info>& info, infos) {
+    cgroups.insert(info->cgroup);
   }
 
   // The discard timeout includes an allowance of twice the
@@ -194,12 +201,9 @@ void PerfEventSubsystem::_sample(
   } else {
     // Store the latest statistics, note that cgroups added in the
     // interim will be picked up by the next sample.
-    foreachpair (const ContainerID& containerId,
-                 const Owned<Info>& info,
-                 infos) {
-      string cgroup = path::join(flags.cgroups_root, containerId.value());
-      if (statistics->contains(cgroup)) {
-        info->statistics = statistics->get(cgroup).get();
+    foreachvalue (const Owned<Info>& info, infos) {
+      if (statistics->contains(info->cgroup)) {
+        info->statistics = statistics->get(info->cgroup).get();
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/cb0efcf6/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.hpp
----------------------------------------------------------------------
diff --git 
a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.hpp 
b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.hpp
index 5a0adfd..14c0e79 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.hpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/subsystems/perf_event.hpp
@@ -55,14 +55,21 @@ public:
     return CGROUP_SUBSYSTEM_PERF_EVENT_NAME;
   }
 
-  virtual process::Future<Nothing> prepare(const ContainerID& containerId);
+  virtual process::Future<Nothing> prepare(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> recover(const ContainerID& containerId);
+  virtual process::Future<Nothing> recover(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
   virtual process::Future<ResourceStatistics> usage(
-      const ContainerID& containerId);
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
-  virtual process::Future<Nothing> cleanup(const ContainerID& containerId);
+  virtual process::Future<Nothing> cleanup(
+      const ContainerID& containerId,
+      const std::string& cgroup);
 
 protected:
   virtual void initialize();
@@ -75,7 +82,8 @@ private:
 
   struct Info
   {
-    Info()
+    Info(const std::string& _cgroup)
+      : cgroup(_cgroup)
     {
       // Ensure the initial statistics include the required fields.
       // Note the duration is set to zero to indicate no sampling has
@@ -85,6 +93,7 @@ private:
       statistics.set_duration(Seconds(0).secs());
     }
 
+    const std::string cgroup;
     PerfStatistics statistics;
   };
 

Reply via email to