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/09/13 17:54:40 UTC
[14/17] mesos git commit: Support changing the cgroup owner for
command tasks that has rootfs.
Support changing the cgroup owner for command tasks that has rootfs.
For command tasks that have rootfs defined, the command executor will
be running as root. However, the task might want to manipulate
cgroups. This patch allows that.
Review: https://reviews.apache.org/r/51835
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0c3a227a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0c3a227a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0c3a227a
Branch: refs/heads/master
Commit: 0c3a227a5b71e9b8d4578fecedd819b76fbaca21
Parents: feb5114
Author: Jie Yu <yu...@gmail.com>
Authored: Mon Sep 12 21:33:34 2016 -0700
Committer: Jie Yu <yu...@gmail.com>
Committed: Tue Sep 13 10:52:01 2016 -0700
----------------------------------------------------------------------
.../mesos/isolators/cgroups/cgroups.cpp | 45 ++++++++++++++++----
1 file changed, 36 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/0c3a227a/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 8b6dfde..e87d055 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -404,16 +404,43 @@ Future<Option<ContainerLaunchInfo>> CgroupsIsolatorProcess::prepare(
// TODO(haosdent): Multiple tasks under the same user can change
// cgroups settings for each other. A better solution is using
// cgroups namespaces and user namespaces to achieve the goal.
+ //
+ // NOTE: We only need to handle the case where 'flags.switch_user'
+ // is true (i.e., 'containerConfig.has_user() == true'). If
+ // 'flags.switch_user' is false, the cgroup will be owned by root
+ // anyway since cgroups isolator requires root permission.
if (containerConfig.has_user()) {
- Try<Nothing> chown = os::chown(
- containerConfig.user(),
- path,
- false);
-
- if (chown.isError()) {
- return Failure(
- "Failed to chown the cgroup at "
- "'" + path + "': " + chown.error());
+ Option<string> user;
+ if (containerConfig.has_task_info() && containerConfig.has_rootfs()) {
+ // Command task that has a rootfs. In this case, the executor
+ // will be running under root, and the command task itself
+ // might be running under a different user.
+ //
+ // TODO(jieyu): The caveat here is that if the 'user' in
+ // task's command is not set, we don't know exactly what user
+ // the task will be running as because we don't know the
+ // framework user. We do not support this case right now.
+ if (containerConfig.task_info().command().has_user()) {
+ user = containerConfig.task_info().command().user();
+ }
+ } else {
+ user = containerConfig.user();
+ }
+
+ if (user.isSome()) {
+ VLOG(1) << "Chown the cgroup at '" << path << "' to user "
+ << "'" << user.get() << "' for container " << containerId;
+
+ Try<Nothing> chown = os::chown(
+ user.get(),
+ path,
+ false);
+
+ if (chown.isError()) {
+ return Failure(
+ "Failed to chown the cgroup at '" + path + "' "
+ "to user '" + user.get() + "': " + chown.error());
+ }
}
}
}