You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by id...@apache.org on 2015/03/11 01:24:44 UTC

[02/10] mesos git commit: Accept dummy arguments for fs::mount().

Accept dummy arguments for fs::mount().

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


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

Branch: refs/heads/master
Commit: eafef12b3b0f6a6e48f1d7e623f3a81c4834938c
Parents: 55869a5
Author: Ian Downes <id...@twitter.com>
Authored: Wed Feb 25 11:43:53 2015 -0800
Committer: Ian Downes <id...@twitter.com>
Committed: Tue Mar 10 17:18:25 2015 -0700

----------------------------------------------------------------------
 src/linux/fs.cpp                                 | 19 +++++++++++++------
 src/linux/fs.hpp                                 | 18 +++++++++++++++---
 .../containerizer/isolators/namespaces/pid.cpp   |  2 +-
 .../isolators/network/port_mapping.cpp           |  2 +-
 4 files changed, 30 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/eafef12b/src/linux/fs.cpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.cpp b/src/linux/fs.cpp
index b2af7a6..54afcc0 100644
--- a/src/linux/fs.cpp
+++ b/src/linux/fs.cpp
@@ -151,18 +151,25 @@ Try<FileSystemTable> FileSystemTable::read()
 }
 
 
-Try<Nothing> mount(const std::string& source,
+Try<Nothing> mount(const Option<std::string>& source,
                    const std::string& target,
-                   const std::string& type,
+                   const Option<std::string>& type,
                    unsigned long flags,
                    const void* data)
 {
   // The prototype of function 'mount' on Linux is as follows:
-  // int mount(const char *source, const char *target,
-  //           const char *filesystemtype, unsigned long mountflags,
+  // int mount(const char *source,
+  //           const char *target,
+  //           const char *filesystemtype,
+  //           unsigned long mountflags,
   //           const void *data);
-  if (::mount(source.c_str(), target.c_str(), type.c_str(), flags, data) < 0) {
-    return ErrnoError("Failed to mount '" + source + "' at '" + target + "'");
+  if (::mount(
+        (source.isSome() ? source.get().c_str() : NULL),
+        target.c_str(),
+        (type.isSome() ? type.get().c_str() : NULL),
+        flags,
+        data) < 0) {
+    return ErrnoError();
   }
 
   return Nothing();

http://git-wip-us.apache.org/repos/asf/mesos/blob/eafef12b/src/linux/fs.hpp
----------------------------------------------------------------------
diff --git a/src/linux/fs.hpp b/src/linux/fs.hpp
index 8280bcb..a9ce7ed 100644
--- a/src/linux/fs.hpp
+++ b/src/linux/fs.hpp
@@ -28,6 +28,7 @@
 #include <vector>
 
 #include <stout/nothing.hpp>
+#include <stout/option.hpp>
 #include <stout/try.hpp>
 
 
@@ -121,15 +122,26 @@ struct FileSystemTable {
 
 
 // Mount a file system.
-// @param   source    Specify the file system (often a device name).
+// @param   source    Specify the file system (often a device name but
+//                    it can also be a directory for a bind mount).
+//                    If None(), NULL will be passed as a dummy
+//                    argument to mount(), i.e., it is not used for
+//                    the specified mount operation. For example, you
+//                    can mount a filesystem specified in /etc/fstab
+//                    by just specifying the target.
 // @param   target    Directory to be attached to.
 // @param   type      File system type (listed in /proc/filesystems).
+//                    If None(), NULL will be passed as a dummy
+//                    argument to mount(), i.e., it is not used for
+//                    the specified mount operation. For example, it
+//                    should be None() for a bind mount as it will
+//                    inherit the type of the source.
 // @param   flags     Mount flags.
 // @param   data      Extra data interpreted by different file systems.
 // @return  Whether the mount operation succeeds.
-Try<Nothing> mount(const std::string& source,
+Try<Nothing> mount(const Option<std::string>& source,
                    const std::string& target,
-                   const std::string& type,
+                   const Option<std::string>& type,
                    unsigned long flags,
                    const void* data);
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/eafef12b/src/slave/containerizer/isolators/namespaces/pid.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolators/namespaces/pid.cpp b/src/slave/containerizer/isolators/namespaces/pid.cpp
index 7e72b34..44b18c6 100644
--- a/src/slave/containerizer/isolators/namespaces/pid.cpp
+++ b/src/slave/containerizer/isolators/namespaces/pid.cpp
@@ -200,7 +200,7 @@ Future<Nothing> NamespacesPidIsolatorProcess::isolate(
     return Failure("Failed to create bind mount target: " + touch.error());
   }
 
-  Try<Nothing> mount = fs::mount(source, target, "none", MS_BIND, NULL);
+  Try<Nothing> mount = fs::mount(source, target, None(), MS_BIND, NULL);
   if (mount.isError()) {
     return Failure(
         "Failed to mount pid namespace handle from " +

http://git-wip-us.apache.org/repos/asf/mesos/blob/eafef12b/src/slave/containerizer/isolators/network/port_mapping.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/isolators/network/port_mapping.cpp b/src/slave/containerizer/isolators/network/port_mapping.cpp
index aebc528..e5e6fa6 100644
--- a/src/slave/containerizer/isolators/network/port_mapping.cpp
+++ b/src/slave/containerizer/isolators/network/port_mapping.cpp
@@ -1620,7 +1620,7 @@ Future<Nothing> PortMappingIsolatorProcess::isolate(
     return Failure("Failed to create the bind mount point: " + touch.error());
   }
 
-  Try<Nothing> mount = fs::mount(source, target, "none", MS_BIND, NULL);
+  Try<Nothing> mount = fs::mount(source, target, None(), MS_BIND, NULL);
   if (mount.isError()) {
     return Failure(
         "Failed to mount the network namespace handle from " +