You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jp...@apache.org on 2018/12/05 01:50:39 UTC
[mesos] 03/04: Applied the `ContainerMountInfo` protobuf helper.
This is an automated email from the ASF dual-hosted git repository.
jpeach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit d5fabcfddafdbc6589492909d71dc43c288ff7e7
Author: James Peach <jp...@apache.org>
AuthorDate: Tue Dec 4 13:57:24 2018 -0800
Applied the `ContainerMountInfo` protobuf helper.
Now that there is a protobuf helper to manufacture `ContainerMountInfo`
messages, apply it where appropriate.
Review: https://reviews.apache.org/r/69450/
---
.../mesos/isolators/cgroups/cgroups.cpp | 72 ++++++++++------------
.../mesos/isolators/docker/volume/isolator.cpp | 9 +--
.../mesos/isolators/filesystem/shared.cpp | 8 +--
.../mesos/isolators/namespaces/pid.cpp | 9 ++-
.../mesos/isolators/volume/host_path.cpp | 8 +--
.../containerizer/mesos/isolators/volume/image.cpp | 9 +--
.../mesos/isolators/volume/sandbox_path.cpp | 8 +--
7 files changed, 59 insertions(+), 64 deletions(-)
diff --git a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
index 507665c..8f94453 100644
--- a/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
+++ b/src/slave/containerizer/mesos/isolators/cgroups/cgroups.cpp
@@ -585,15 +585,13 @@ Future<Option<ContainerLaunchInfo>> CgroupsIsolatorProcess::__prepare(
// cgroups mount, e.g.:
// mount --bind /sys/fs/cgroup/memory/mesos/<containerId> /sys/fs/cgroup/memory // NOLINT(whitespace/line_length)
foreach (const string& hierarchy, subsystems.keys()) {
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(path::join(hierarchy, infos[rootContainerId]->cgroup));
-
- mount->set_target(path::join(
- containerConfig.rootfs(),
- "/sys/fs/cgroup",
- Path(hierarchy).basename()));
-
- mount->set_flags(MS_BIND | MS_REC);
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ path::join(hierarchy, infos[rootContainerId]->cgroup),
+ path::join(
+ containerConfig.rootfs(),
+ "/sys/fs/cgroup",
+ Path(hierarchy).basename()),
+ MS_BIND | MS_REC);
}
// Linux launcher will create freezer and systemd cgroups for the container,
@@ -607,38 +605,34 @@ Future<Option<ContainerLaunchInfo>> CgroupsIsolatorProcess::__prepare(
hierarchy.error());
}
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(path::join(
- hierarchy.get(),
- flags.cgroups_root,
- containerizer::paths::buildPath(
- containerId,
- CGROUP_SEPARATOR,
- containerizer::paths::JOIN)));
-
- mount->set_target(path::join(
- containerConfig.rootfs(),
- "/sys/fs/cgroup",
- "freezer"));
-
- mount->set_flags(MS_BIND | MS_REC);
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ path::join(
+ hierarchy.get(),
+ flags.cgroups_root,
+ containerizer::paths::buildPath(
+ containerId,
+ CGROUP_SEPARATOR,
+ containerizer::paths::JOIN)),
+ path::join(
+ containerConfig.rootfs(),
+ "/sys/fs/cgroup",
+ "freezer"),
+ MS_BIND | MS_REC);
if (systemd::enabled()) {
- mount = launchInfo.add_mounts();
- mount->set_source(path::join(
- systemd::hierarchy(),
- flags.cgroups_root,
- containerizer::paths::buildPath(
- containerId,
- CGROUP_SEPARATOR,
- containerizer::paths::JOIN)));
-
- mount->set_target(path::join(
- containerConfig.rootfs(),
- "/sys/fs/cgroup",
- "systemd"));
-
- mount->set_flags(MS_BIND | MS_REC);
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ path::join(
+ systemd::hierarchy(),
+ flags.cgroups_root,
+ containerizer::paths::buildPath(
+ containerId,
+ CGROUP_SEPARATOR,
+ containerizer::paths::JOIN)),
+ path::join(
+ containerConfig.rootfs(),
+ "/sys/fs/cgroup",
+ "systemd"),
+ MS_BIND | MS_REC);
}
}
diff --git a/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp b/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
index d193883..a72fc84 100644
--- a/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
+++ b/src/slave/containerizer/mesos/isolators/docker/volume/isolator.cpp
@@ -24,6 +24,8 @@
#include <stout/os/realpath.hpp>
#include <stout/os/which.hpp>
+#include "common/protobuf_utils.hpp"
+
#include "linux/ns.hpp"
#include "slave/flags.hpp"
@@ -555,10 +557,9 @@ Future<Option<ContainerLaunchInfo>> DockerVolumeIsolatorProcess::_prepare(
LOG(INFO) << "Mounting docker volume mount point '" << source
<< "' to '" << target << "' for container " << containerId;
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(source);
- mount->set_target(target);
- mount->set_flags(
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ source,
+ target,
MS_BIND | MS_REC | (volumeMode == Volume::RO ? MS_RDONLY : 0));
}
diff --git a/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp b/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
index 5b481b5..eed030b 100644
--- a/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
+++ b/src/slave/containerizer/mesos/isolators/filesystem/shared.cpp
@@ -24,6 +24,8 @@
#include <stout/os/strerror.hpp>
+#include "common/protobuf_utils.hpp"
+
#include "linux/ns.hpp"
#include "slave/containerizer/mesos/isolators/filesystem/shared.hpp"
@@ -213,10 +215,8 @@ Future<Option<ContainerLaunchInfo>> SharedFilesystemIsolatorProcess::prepare(
}
}
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(hostPath);
- mount->set_target(volume.container_path());
- mount->set_flags(MS_BIND | MS_REC);
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ hostPath, volume.container_path(), MS_BIND | MS_REC);
}
return launchInfo;
diff --git a/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp b/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
index 73e0963..5df3122 100644
--- a/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
+++ b/src/slave/containerizer/mesos/isolators/namespaces/pid.cpp
@@ -20,6 +20,8 @@
#include <stout/strings.hpp>
+#include "common/protobuf_utils.hpp"
+
#include "linux/ns.hpp"
#include "slave/containerizer/mesos/isolators/namespaces/pid.hpp"
@@ -138,11 +140,8 @@ Future<Option<ContainerLaunchInfo>> NamespacesPidIsolatorProcess::prepare(
// mount namespace.
//
// TOOD(jieyu): Consider unmount the existing /proc.
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source("proc");
- mount->set_target("/proc");
- mount->set_type("proc");
- mount->set_flags(MS_NOSUID | MS_NODEV | MS_NOEXEC);
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ "proc", "/proc", "proc", MS_NOSUID | MS_NODEV | MS_NOEXEC);
return launchInfo;
}
diff --git a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
index 88ecf91..2e4cd2b 100644
--- a/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/host_path.cpp
@@ -32,6 +32,7 @@
#include <stout/os/stat.hpp>
#include <stout/os/touch.hpp>
+#include "common/protobuf_utils.hpp"
#include "common/validation.hpp"
#include "linux/fs.hpp"
@@ -309,10 +310,9 @@ Future<Option<ContainerLaunchInfo>> VolumeHostPathIsolatorProcess::prepare(
// result, no need for the bind mount because the 'hostPath' is
// already accessible in the container.
if (hostPath.get() != mountPoint) {
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(hostPath.get());
- mount->set_target(mountPoint);
- mount->set_flags(
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ hostPath.get(),
+ mountPoint,
MS_BIND | MS_REC | (volume.mode() == Volume::RO ? MS_RDONLY : 0));
}
}
diff --git a/src/slave/containerizer/mesos/isolators/volume/image.cpp b/src/slave/containerizer/mesos/isolators/volume/image.cpp
index bb3fc65..b111252 100644
--- a/src/slave/containerizer/mesos/isolators/volume/image.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/image.cpp
@@ -33,6 +33,8 @@
#include <stout/os/exists.hpp>
#include <stout/os/mkdir.hpp>
+#include "common/protobuf_utils.hpp"
+
#include "slave/containerizer/mesos/isolators/volume/image.hpp"
#include "slave/containerizer/mesos/provisioner/provisioner.hpp"
@@ -247,10 +249,9 @@ Future<Option<ContainerLaunchInfo>> VolumeImageIsolatorProcess::_prepare(
"Provisioned rootfs '" + source + "' does not exist");
}
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(source);
- mount->set_target(target);
- mount->set_flags(
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ source,
+ target,
MS_BIND | MS_REC | (volumeMode == Volume::RO ? MS_RDONLY : 0));
}
diff --git a/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp b/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
index 300b3d9..ecd467c 100644
--- a/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
+++ b/src/slave/containerizer/mesos/isolators/volume/sandbox_path.cpp
@@ -33,6 +33,7 @@
#include <stout/os/stat.hpp>
#include <stout/os/touch.hpp>
+#include "common/protobuf_utils.hpp"
#include "common/validation.hpp"
#ifdef __linux__
@@ -375,10 +376,9 @@ Future<Option<ContainerLaunchInfo>> VolumeSandboxPathIsolatorProcess::prepare(
<< "'" << source << "' to '" << target << "' "
<< "for container " << containerId;
- ContainerMountInfo* mount = launchInfo.add_mounts();
- mount->set_source(source);
- mount->set_target(target);
- mount->set_flags(
+ *launchInfo.add_mounts() = protobuf::slave::createContainerMount(
+ source,
+ target,
MS_BIND | MS_REC | (volume.mode() == Volume::RO ? MS_RDONLY : 0));
#endif // __linux__
} else {