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 2016/02/06 00:39:30 UTC

mesos git commit: Added helper functions in cgroup for supporting net_cls subsystem.

Repository: mesos
Updated Branches:
  refs/heads/master 8b5cb55e6 -> 3500ce5a3


Added helper functions in cgroup for supporting net_cls subsystem.

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


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

Branch: refs/heads/master
Commit: 3500ce5a3971844d7b0083db1781deff5f6e65b9
Parents: 8b5cb55
Author: Avinash sridharan <av...@mesosphere.io>
Authored: Fri Feb 5 15:14:13 2016 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Fri Feb 5 15:39:11 2016 -0800

----------------------------------------------------------------------
 src/linux/cgroups.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
 src/linux/cgroups.hpp | 18 ++++++++++++++++++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3500ce5a/src/linux/cgroups.cpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.cpp b/src/linux/cgroups.cpp
index bbc1fb3..df18ed4 100644
--- a/src/linux/cgroups.cpp
+++ b/src/linux/cgroups.cpp
@@ -2457,4 +2457,45 @@ Future<Nothing> thaw(
 
 } // namespace freezer {
 
+
+namespace net_cls {
+
+Try<uint32_t> classid(
+    const string& hierarchy,
+    const string& cgroup)
+{
+  Try<string> read = cgroups::read(hierarchy, cgroup, "net_cls.classid");
+  if (read.isError()) {
+    return Error("Unable to read the `net_cls.classid`: " + read.error());
+  }
+
+  Try<uint32_t> handle = numify<uint32_t>(strings::trim(read.get()));
+  if (handle.isError()) {
+    return Error("Not a valid number");
+  }
+
+  return handle.get();
+}
+
+
+Try<Nothing> classid(
+    const string& hierarchy,
+    const string& cgroup,
+    uint32_t handle)
+{
+  Try<Nothing> write = cgroups::write(
+      hierarchy,
+      cgroup,
+      "net_cls.classid",
+      stringify(handle));
+
+  if (write.isError()) {
+    return Error("Failed to write to 'net_cls.classid': " + write.error());
+  }
+
+  return Nothing();
+}
+
+} // namespace net_cls {
+
 } // namespace cgroups {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3500ce5a/src/linux/cgroups.hpp
----------------------------------------------------------------------
diff --git a/src/linux/cgroups.hpp b/src/linux/cgroups.hpp
index 83b3e40..51ccefd 100644
--- a/src/linux/cgroups.hpp
+++ b/src/linux/cgroups.hpp
@@ -647,6 +647,24 @@ process::Future<Nothing> thaw(
 
 } // namespace freezer {
 
+
+// Net_cls subsystem.
+namespace net_cls {
+
+// Read the uint32_t handle set in `net_cls.classid`.
+Try<uint32_t> classid(
+    const std::string& hierarchy,
+    const std::string& cgroup);
+
+
+// Write the uint32_t handle to the `net_cls.classid`.
+Try<Nothing> classid(
+    const std::string& hierarchy,
+    const std::string& cgroup,
+    const uint32_t handle);
+
+} // namespace net_cls {
+
 } // namespace cgroups {
 
 namespace std {