You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/05/23 23:49:02 UTC

[1/9] mesos git commit: Windows: Used Winsock class in slave and containerizer.

Repository: mesos
Updated Branches:
  refs/heads/master 9e942f06b -> d278b09d2


Windows: Used Winsock class in slave and containerizer.

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


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

Branch: refs/heads/master
Commit: d278b09d2d9083ed757f25651eaaa7925427a428
Parents: 1fcc832
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 16:19:01 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 src/slave/containerizer/mesos/main.cpp | 9 +++++++++
 src/slave/main.cpp                     | 9 +++++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d278b09d/src/slave/containerizer/mesos/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/main.cpp b/src/slave/containerizer/mesos/main.cpp
index ed0c6cd..1a0e765 100644
--- a/src/slave/containerizer/mesos/main.cpp
+++ b/src/slave/containerizer/mesos/main.cpp
@@ -14,6 +14,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#ifdef __WINDOWS__
+#include <process/windows/winsock.hpp>
+#endif // __WINDOWS__
+
 #include <stout/none.hpp>
 #include <stout/subcommand.hpp>
 
@@ -29,6 +33,11 @@ using namespace mesos::internal::slave;
 
 int main(int argc, char** argv)
 {
+#ifdef __WINDOWS__
+  // Initialize the Windows socket stack.
+  process::Winsock winsock;
+#endif
+
 #ifdef __linux__
   return Subcommand::dispatch(
       None(),

http://git-wip-us.apache.org/repos/asf/mesos/blob/d278b09d/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index 13ddfb9..ecaa782 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -31,6 +31,10 @@
 
 #include <process/owned.hpp>
 
+#ifdef __WINDOWS__
+#include <process/windows/winsock.hpp>
+#endif // __WINDOWS__
+
 #include <stout/check.hpp>
 #include <stout/flags.hpp>
 #include <stout/hashset.hpp>
@@ -98,6 +102,11 @@ void version()
 
 int main(int argc, char** argv)
 {
+#ifdef __WINDOWS__
+  // Initialize the Windows socket stack.
+  process::Winsock winsock;
+#endif
+
   GOOGLE_PROTOBUF_VERIFY_VERSION;
 
   slave::Flags flags;


[8/9] mesos git commit: Agent: Changed the names of symbols that are ambiguous on MSVC.

Posted by jo...@apache.org.
Agent: Changed the names of symbols that are ambiguous on MSVC.

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


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

Branch: refs/heads/master
Commit: 1fcc8329d2eeb19520fa793fc63630f7882264ed
Parents: 4155145
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 16:13:04 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 src/docker/docker.hpp | 4 ++--
 src/slave/slave.cpp   | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/1fcc8329/src/docker/docker.hpp
----------------------------------------------------------------------
diff --git a/src/docker/docker.hpp b/src/docker/docker.hpp
index da6e9a2..d9ffc18 100644
--- a/src/docker/docker.hpp
+++ b/src/docker/docker.hpp
@@ -120,8 +120,8 @@ public:
       const std::string& mappedDirectory,
       const Option<mesos::Resources>& resources = None(),
       const Option<std::map<std::string, std::string>>& env = None(),
-      const process::Subprocess::IO& stdout = process::Subprocess::PIPE(),
-      const process::Subprocess::IO& stderr = process::Subprocess::PIPE())
+      const process::Subprocess::IO& _stdout = process::Subprocess::PIPE(),
+      const process::Subprocess::IO& _stderr = process::Subprocess::PIPE())
     const;
 
   // Returns the current docker version.

http://git-wip-us.apache.org/repos/asf/mesos/blob/1fcc8329/src/slave/slave.cpp
----------------------------------------------------------------------
diff --git a/src/slave/slave.cpp b/src/slave/slave.cpp
index ce0e7b1..2941cf1 100644
--- a/src/slave/slave.cpp
+++ b/src/slave/slave.cpp
@@ -482,8 +482,8 @@ void Slave::initialize()
   // Ensure disk `source`s are accessible.
   foreach (
       const Resource& resource,
-      resources->filter([](const Resource& resource) {
-        return resource.has_disk() && resource.disk().has_source();
+      resources->filter([](const Resource& _resource) {
+        return _resource.has_disk() && _resource.disk().has_source();
       })) {
     // For `PATH` sources we create them if they do not exist.
     const Resource::DiskInfo::Source& source = resource.disk().source();


[3/9] mesos git commit: Stout: Added support for correct path delimiters in Windows.

Posted by jo...@apache.org.
Stout: Added support for correct path delimiters in Windows.

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


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

Branch: refs/heads/master
Commit: c3d8c92d2bd410353a30ea278765616b2a471b1e
Parents: 79f07ef
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 15:41:59 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/constants.hpp |  9 +++-
 3rdparty/stout/include/stout/os/mkdir.hpp     |  8 ++--
 3rdparty/stout/include/stout/path.hpp         | 48 ++++++++++++++--------
 3 files changed, 44 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c3d8c92d/3rdparty/stout/include/stout/os/constants.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/constants.hpp b/3rdparty/stout/include/stout/os/constants.hpp
index 438840a..c71d52e 100644
--- a/3rdparty/stout/include/stout/os/constants.hpp
+++ b/3rdparty/stout/include/stout/os/constants.hpp
@@ -17,7 +17,14 @@
 
 namespace os {
 
-const std::string DIRECTORY_SEPARATOR = "/";
+constexpr char WINDOWS_PATH_SEPARATOR = '\\';
+constexpr char POSIX_PATH_SEPARATOR = '/';
+
+#ifndef __WINDOWS__
+constexpr char PATH_SEPARATOR = POSIX_PATH_SEPARATOR;
+#else
+constexpr char PATH_SEPARATOR = WINDOWS_PATH_SEPARATOR;
+#endif // __WINDOWS__
 
 } // namespace os {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c3d8c92d/3rdparty/stout/include/stout/os/mkdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/mkdir.hpp b/3rdparty/stout/include/stout/os/mkdir.hpp
index e86dbfd..fe86864 100644
--- a/3rdparty/stout/include/stout/os/mkdir.hpp
+++ b/3rdparty/stout/include/stout/os/mkdir.hpp
@@ -42,13 +42,13 @@ inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
     }
   } else {
     std::vector<std::string> tokens =
-      strings::tokenize(directory, os::DIRECTORY_SEPARATOR);
+      strings::tokenize(directory, stringify(os::PATH_SEPARATOR));
 
     std::string path = "";
 
     // We got an absolute path, so keep the leading slash.
-    if (directory.find_first_of(os::DIRECTORY_SEPARATOR) == 0) {
-      path = os::DIRECTORY_SEPARATOR;
+    if (directory.find_first_of(stringify(os::PATH_SEPARATOR)) == 0) {
+      path = os::PATH_SEPARATOR;
     }
 
     foreach (const std::string& token, tokens) {
@@ -57,7 +57,7 @@ inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
         return ErrnoError();
       }
 
-      path += os::DIRECTORY_SEPARATOR;
+      path += os::PATH_SEPARATOR;
     }
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/c3d8c92d/3rdparty/stout/include/stout/path.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/path.hpp b/3rdparty/stout/include/stout/path.hpp
index ef53804..1b8326f 100644
--- a/3rdparty/stout/include/stout/path.hpp
+++ b/3rdparty/stout/include/stout/path.hpp
@@ -17,15 +17,24 @@
 #include <utility>
 #include <vector>
 
+#include <stout/stringify.hpp>
 #include <stout/strings.hpp>
 
+#include <stout/os/constants.hpp>
+
+
 namespace path {
 
 // Base case.
-inline std::string join(const std::string& path1, const std::string& path2)
+inline std::string join(
+    const std::string& path1,
+    const std::string& path2,
+    const char _separator = os::PATH_SEPARATOR)
 {
-  return strings::remove(path1, "/", strings::SUFFIX) + "/" +
-         strings::remove(path2, "/", strings::PREFIX);
+  const std::string separator = stringify(_separator);
+  return strings::remove(path1, separator, strings::SUFFIX) +
+         separator +
+         strings::remove(path2, separator, strings::PREFIX);
 }
 
 
@@ -55,7 +64,7 @@ inline std::string join(const std::vector<std::string>& paths)
 
 inline bool absolute(const std::string& path)
 {
-  if (path.empty() || path[0] != '/') {
+  if (path.empty() || path[0] != os::PATH_SEPARATOR) {
     return false;
   }
 
@@ -66,8 +75,10 @@ inline bool absolute(const std::string& path)
 
 
 /**
- * Represents a POSIX file systems path and offers common path
- * manipulations.
+ * Represents a POSIX or Windows file system path and offers common path
+ * manipulations. When reading the comments below, keep in mind that '/' refers
+ * to the path separator character, so read it as "'/' or '\', depending on
+ * platform".
  */
 class Path
 {
@@ -110,18 +121,18 @@ public:
     size_t end = value.size() - 1;
 
     // Remove trailing slashes.
-    if (value[end] == '/') {
-      end = value.find_last_not_of('/', end);
+    if (value[end] == os::PATH_SEPARATOR) {
+      end = value.find_last_not_of(os::PATH_SEPARATOR, end);
 
       // Paths containing only slashes result into "/".
       if (end == std::string::npos) {
-        return std::string("/");
+        return stringify(os::PATH_SEPARATOR);
       }
     }
 
     // 'start' should point towards the character after the last slash
     // that is non trailing.
-    size_t start = value.find_last_of('/', end);
+    size_t start = value.find_last_of(os::PATH_SEPARATOR, end);
 
     if (start == std::string::npos) {
       start = 0;
@@ -132,6 +143,11 @@ public:
     return value.substr(start, end + 1 - start);
   }
 
+  // TODO(hausdorff) Make sure this works on Windows for very short path names,
+  // such as "C:\Temp". There is a distinction between "C:" and "C:\", the
+  // former means "current directory of the C drive", while the latter means
+  // "The root of the C drive". Also make sure that UNC paths are handled.
+  // Will probably need to use the Windows path functions for that.
   /**
    * Extracts the component up to, but not including, the final '/'.
    * Trailing '/' characters are not counted as part of the pathname.
@@ -164,12 +180,12 @@ public:
     size_t end = value.size() - 1;
 
     // Remove trailing slashes.
-    if (value[end] == '/') {
-      end = value.find_last_not_of('/', end);
+    if (value[end] == os::PATH_SEPARATOR) {
+      end = value.find_last_not_of(os::PATH_SEPARATOR, end);
     }
 
     // Remove anything trailing the last slash.
-    end = value.find_last_of('/', end);
+    end = value.find_last_of(os::PATH_SEPARATOR, end);
 
     // Paths containing no slashes result in ".".
     if (end == std::string::npos) {
@@ -178,16 +194,16 @@ public:
 
     // Paths containing only slashes result in "/".
     if (end == 0) {
-      return std::string("/");
+      return stringify(os::PATH_SEPARATOR);
     }
 
     // 'end' should point towards the last non slash character
     // preceding the last slash.
-    end = value.find_last_not_of('/', end);
+    end = value.find_last_not_of(os::PATH_SEPARATOR, end);
 
     // Paths containing no non slash characters result in "/".
     if (end == std::string::npos) {
-      return std::string("/");
+      return stringify(os::PATH_SEPARATOR);
     }
 
     return value.substr(0, end + 1);


[4/9] mesos git commit: Stout: Implemented `os::fsync`.

Posted by jo...@apache.org.
Stout: Implemented `os::fsync`.

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


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

Branch: refs/heads/master
Commit: a8829e1ad07ba81099d9b9fabe1e93e2b36036e5
Parents: 9e942f0
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 15:23:02 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  3 ++
 3rdparty/stout/include/stout/os/fsync.hpp       | 24 +++++++++++
 3rdparty/stout/include/stout/os/posix/fsync.hpp | 36 ++++++++++++++++
 .../stout/include/stout/os/windows/fsync.hpp    | 44 ++++++++++++++++++++
 4 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a8829e1a/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 51d6659..ae4116b 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -69,6 +69,7 @@ nobase_include_HEADERS =			\
   stout/os/find.hpp				\
   stout/os/fork.hpp				\
   stout/os/freebsd.hpp				\
+  stout/os/fsync.hpp				\
   stout/os/ftruncate.hpp			\
   stout/os/getcwd.hpp				\
   stout/os/kill.hpp				\
@@ -109,6 +110,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/exists.hpp			\
   stout/os/posix/fcntl.hpp			\
   stout/os/posix/fork.hpp			\
+  stout/os/posix/fsync.hpp			\
   stout/os/posix/ftruncate.hpp			\
   stout/os/posix/kill.hpp			\
   stout/os/posix/killtree.hpp			\
@@ -133,6 +135,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/exists.hpp			\
   stout/os/windows/fcntl.hpp			\
   stout/os/windows/fork.hpp			\
+  stout/os/windows/fsync.hpp			\
   stout/os/windows/ftruncate.hpp		\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/a8829e1a/3rdparty/stout/include/stout/os/fsync.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/fsync.hpp b/3rdparty/stout/include/stout/os/fsync.hpp
new file mode 100644
index 0000000..bab337e
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/fsync.hpp
@@ -0,0 +1,24 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_FSYNC_HPP__
+#define __STOUT_OS_FSYNC_HPP__
+
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specifc system calls into separate directories.
+#ifdef __WINDOWS__
+#include <stout/os/windows/fsync.hpp>
+#else
+#include <stout/os/posix/fsync.hpp>
+#endif // __WINDOWS__
+
+#endif // __STOUT_OS_FSYNC_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/a8829e1a/3rdparty/stout/include/stout/os/posix/fsync.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/fsync.hpp b/3rdparty/stout/include/stout/os/posix/fsync.hpp
new file mode 100644
index 0000000..9a6bbf6
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/fsync.hpp
@@ -0,0 +1,36 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_FSYNC_HPP__
+#define __STOUT_OS_POSIX_FSYNC_HPP__
+
+#include <unistd.h>
+
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> fsync(int fd)
+{
+  if (::fsync(fd) == -1) {
+    return ErrnoError();
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_POSIX_FSYNC_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/a8829e1a/3rdparty/stout/include/stout/os/windows/fsync.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/fsync.hpp b/3rdparty/stout/include/stout/os/windows/fsync.hpp
new file mode 100644
index 0000000..e1c4868
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/fsync.hpp
@@ -0,0 +1,44 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_FSYNC_HPP__
+#define __STOUT_OS_WINDOWS_FSYNC_HPP__
+
+#include <io.h>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> fsync(int fd)
+{
+  const HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+  if (handle == INVALID_HANDLE_VALUE) {
+    return WindowsError(
+        "os::fsync: Could not get handle for given file descriptor");
+  }
+
+  if (!FlushFileBuffers(handle)) {
+    return WindowsError(
+        "os::fsync: Could not flush file buffers for given file descriptor");
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_FSYNC_HPP__


[6/9] mesos git commit: Updated Mesos to use `os::fsync`.

Posted by jo...@apache.org.
Updated Mesos to use `os::fsync`.


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

Branch: refs/heads/master
Commit: 79f07ef1447e1c74bb32372ac413f73d3ec56765
Parents: a8829e1
Author: Joris Van Remoortere <jo...@gmail.com>
Authored: Mon May 23 15:29:17 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 src/tests/containerizer/memory_test_helper.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/79f07ef1/src/tests/containerizer/memory_test_helper.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/memory_test_helper.cpp b/src/tests/containerizer/memory_test_helper.cpp
index 21c718d..a8fdc19 100644
--- a/src/tests/containerizer/memory_test_helper.cpp
+++ b/src/tests/containerizer/memory_test_helper.cpp
@@ -35,6 +35,7 @@
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
 
+#include <stout/os/fsync.hpp>
 #include <stout/os/pagesize.hpp>
 
 #include "tests/flags.hpp"
@@ -167,13 +168,10 @@ static Try<Nothing> increasePageCache(const vector<string>& tokens)
     }
 
     // Use fsync to make sure data is written to disk.
-    if (fsync(fd.get()) == -1) {
-      // Save the error message because os::close below might
-      // overwrite the errno.
-      const string message = os::strerror(errno);
-
+    Try<Nothing> fsync = os::fsync(fd.get());
+    if (fsync.isError()) {
       os::close(fd.get());
-      return Error("Failed to fsync: " + message);
+      return Error("Failed to fsync: " + fsync.error());
     }
   }
 


[5/9] mesos git commit: Stout: Removed warning in Windows implementation of `stat.hpp`.

Posted by jo...@apache.org.
Stout: Removed warning in Windows implementation of `stat.hpp`.

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


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

Branch: refs/heads/master
Commit: 78e00e90ffd8121bd7230e1ca965aff63ed920ac
Parents: c3d8c92
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 15:59:25 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/stat.hpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/78e00e90/3rdparty/stout/include/stout/os/windows/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/stat.hpp b/3rdparty/stout/include/stout/os/windows/stat.hpp
index f4414dd..e7f471b 100644
--- a/3rdparty/stout/include/stout/os/windows/stat.hpp
+++ b/3rdparty/stout/include/stout/os/windows/stat.hpp
@@ -126,7 +126,14 @@ inline Try<long> mtime(const std::string& path)
     return ErrnoError("Error invoking stat for '" + path + "'");
   }
 
-  return s.st_mtime;
+  // To be safe, we assert that `st_mtime` is represented as `__int64`. To
+  // conform to the POSIX, we also cast `st_mtime` to `long`; we choose to make
+  // this conversion explicit because we expect the truncation to not cause
+  // information loss.
+  static_assert(
+      std::is_same<__int64, __time64_t>::value,
+      "Mesos assumes `__time64_t` is represented as `__int64`");
+  return static_cast<long>(s.st_mtime);
 }
 
 


[7/9] mesos git commit: Stout: Set `_fmode` to binary in `protobuf.hpp`.

Posted by jo...@apache.org.
Stout: Set `_fmode` to binary in `protobuf.hpp`.

In Windows, the I/O subsystem will automatically convert linefeed
endings if the I/O is done on "text" files. For binary files, this
effect is almost never desirable.

This commit will turn of these conversions for protobuf I/O operations.

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


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

Branch: refs/heads/master
Commit: e42db6b93c00c3b757db28f567c1c99c23b6cd81
Parents: 78e00e9
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 16:02:38 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/protobuf.hpp | 51 ++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e42db6b9/3rdparty/stout/include/stout/protobuf.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/protobuf.hpp b/3rdparty/stout/include/stout/protobuf.hpp
index eb4ac8c..7bf704d 100644
--- a/3rdparty/stout/include/stout/protobuf.hpp
+++ b/3rdparty/stout/include/stout/protobuf.hpp
@@ -84,6 +84,16 @@ inline Try<Nothing> write(int fd, const google::protobuf::Message& message)
 }
 
 
+#ifdef __WINDOWS__
+// NOTE: Ordinarily this would go in a Windows-specific header; we put it here
+// to avoid complex forward declarations.
+inline Try<Nothing> write(HANDLE handle, const google::protobuf::Message& message)
+{
+  return write(_open_osfhandle(reinterpret_cast<intptr_t>(handle), O_WRONLY), message);
+}
+#endif // __WINDOWS__
+
+
 // Write out the given sequence of protobuf messages to the
 // specified file descriptor by repeatedly invoking write
 // on each of the messages.
@@ -107,9 +117,16 @@ Try<Nothing> write(
 template <typename T>
 Try<Nothing> write(const std::string& path, const T& t)
 {
+  int operation_flags = O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC;
+#ifdef __WINDOWS__
+  // NOTE: Windows does automatic linefeed conversions in I/O on text files.
+  // We include the `_O_BINARY` flag here to avoid this.
+  operation_flags |= _O_BINARY;
+#endif // __WINDOWS__
+
   Try<int> fd = os::open(
       path,
-      O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
+      operation_flags,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
   if (fd.isError()) {
@@ -131,9 +148,16 @@ inline Try<Nothing> append(
     const std::string& path,
     const google::protobuf::Message& message)
 {
+  int operation_flags = O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC;
+#ifdef __WINDOWS__
+  // NOTE: Windows does automatic linefeed conversions in I/O on text files.
+  // We include the `_O_BINARY` flag here to avoid this.
+  operation_flags |= _O_BINARY;
+#endif // __WINDOWS__
+
   Try<int> fd = os::open(
       path,
-      O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC,
+      operation_flags,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
   if (fd.isError()) {
@@ -289,14 +313,35 @@ Result<T> read(int fd, bool ignorePartial = false, bool undoFailed = false)
 }
 
 
+#ifdef __WINDOWS__
+// NOTE: Ordinarily this would go in a Windows-specific header; we put it here
+// to avoid complex forward declarations.
+template <typename T>
+Result<T> read(HANDLE handle, bool ignorePartial = false, bool undoFailed = false)
+{
+  return read<T>(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDONLY),
+      ignorePartial,
+      undoFailed);
+}
+#endif // __WINDOWS__
+
+
 // A wrapper function that wraps the above read() with open and
 // closing the file.
 template <typename T>
 Result<T> read(const std::string& path)
 {
+  int operation_flags = O_RDONLY | O_CLOEXEC;
+#ifdef __WINDOWS__
+  // NOTE: Windows does automatic linefeed conversions in I/O on text files.
+  // We include the `_O_BINARY` flag here to avoid this.
+  operation_flags |= _O_BINARY;
+#endif // __WINDOWS__
+
   Try<int> fd = os::open(
       path,
-      O_RDONLY | O_CLOEXEC,
+      operation_flags,
       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
   if (fd.isError()) {


[2/9] mesos git commit: Libprocess: Implemented `HANDLE` versions of file descriptor functions.

Posted by jo...@apache.org.
Libprocess: Implemented `HANDLE` versions of file descriptor functions.

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


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

Branch: refs/heads/master
Commit: 4155145c8973859c4dfb55856708c3c782660461
Parents: 490c532
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 16:09:08 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/io.hpp | 11 +++++++++++
 3rdparty/libprocess/src/io.cpp             | 23 +++++++++++++++++++++++
 2 files changed, 34 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4155145c/3rdparty/libprocess/include/process/io.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/io.hpp b/3rdparty/libprocess/include/process/io.hpp
index 2f1e626..fed246b 100644
--- a/3rdparty/libprocess/include/process/io.hpp
+++ b/3rdparty/libprocess/include/process/io.hpp
@@ -19,6 +19,9 @@
 #include <process/future.hpp>
 
 #include <stout/nothing.hpp>
+#ifdef __WINDOWS__
+#include <stout/windows.hpp>
+#endif // __WINDOWS__
 
 namespace process {
 namespace io {
@@ -78,6 +81,10 @@ Future<size_t> read(int fd, void* data, size_t size);
  *     or made non-blocking.
  */
 Future<std::string> read(int fd);
+#ifdef __WINDOWS__
+// Version of this function compatible with Windows `HANDLE`.
+Future<std::string> read(HANDLE fd);
+#endif // __WINDOWS__
 
 
 /**
@@ -119,6 +126,10 @@ Future<Nothing> write(int fd, const std::string& data);
  *     set to close-on-exec, or made non-blocking.
  */
 Future<Nothing> redirect(int from, Option<int> to, size_t chunk = 4096);
+#ifdef __WINDOWS__
+// Version of this function compatible with Windows `HANDLE`.
+Future<Nothing> redirect(HANDLE from, Option<int> to, size_t chunk = 4096);
+#endif // __WINDOWS__
 
 
 /**

http://git-wip-us.apache.org/repos/asf/mesos/blob/4155145c/3rdparty/libprocess/src/io.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/io.cpp b/3rdparty/libprocess/src/io.cpp
index 44dee23..d9c6075 100644
--- a/3rdparty/libprocess/src/io.cpp
+++ b/3rdparty/libprocess/src/io.cpp
@@ -444,6 +444,16 @@ Future<string> read(int fd)
 }
 
 
+#ifdef __WINDOWS__
+// NOTE: Ordinarily this would go in a Windows-specific header; we put it here
+// to avoid complex forward declarations.
+Future<string> read(HANDLE handle)
+{
+  return read(_open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDONLY));
+}
+#endif // __WINDOWS__
+
+
 Future<Nothing> write(int fd, const string& data)
 {
   process::initialize();
@@ -558,6 +568,19 @@ Future<Nothing> redirect(int from, Option<int> to, size_t chunk)
 }
 
 
+#ifdef __WINDOWS__
+// NOTE: Ordinarily this would go in a Windows-specific header; we put it here
+// to avoid complex forward declarations.
+Future<Nothing> redirect(HANDLE from, Option<int> to, size_t chunk)
+{
+  return redirect(
+      _open_osfhandle(reinterpret_cast<intptr_t>(from), O_RDWR),
+      to,
+      chunk);
+}
+#endif // __WINDOWS__
+
+
 // TODO(hartem): Most of the boilerplate code here is the same as
 // in io::read, so this needs to be refactored.
 Future<string> peek(int fd, size_t limit)


[9/9] mesos git commit: Stout: Implemented `HANDLE` versions of file descriptor functions.

Posted by jo...@apache.org.
Stout: Implemented `HANDLE` versions of file descriptor functions.

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


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

Branch: refs/heads/master
Commit: 490c532ce47f082d3359ee7e64d65b94019c4ef6
Parents: e42db6b
Author: Alex Clemmer <cl...@gmail.com>
Authored: Mon May 23 16:05:10 2016 -0700
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Mon May 23 16:48:48 2016 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/fcntl.hpp    |  8 +++++++
 .../stout/include/stout/os/windows/read.hpp     | 22 +++++++++++++++++++
 .../stout/include/stout/os/windows/write.hpp    | 23 ++++++++++++++++++++
 3 files changed, 53 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/490c532c/3rdparty/stout/include/stout/os/windows/fcntl.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/fcntl.hpp b/3rdparty/stout/include/stout/os/windows/fcntl.hpp
index bb5885e..63533ab 100644
--- a/3rdparty/stout/include/stout/os/windows/fcntl.hpp
+++ b/3rdparty/stout/include/stout/os/windows/fcntl.hpp
@@ -17,6 +17,7 @@
 
 #include <stout/nothing.hpp>
 #include <stout/try.hpp>
+#include <stout/windows.hpp>
 
 #include <stout/os/socket.hpp>
 
@@ -68,6 +69,13 @@ inline Try<Nothing> nonblock(int fd)
 }
 
 
+inline Try<Nothing> nonblock(HANDLE handle)
+{
+  return nonblock(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDONLY));
+}
+
+
 // NOTE: This is not supported on Windows.
 inline Try<bool> isNonblock(int fd)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/490c532c/3rdparty/stout/include/stout/os/windows/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/read.hpp b/3rdparty/stout/include/stout/os/windows/read.hpp
index a10df73..cb0abf7 100644
--- a/3rdparty/stout/include/stout/os/windows/read.hpp
+++ b/3rdparty/stout/include/stout/os/windows/read.hpp
@@ -15,6 +15,7 @@
 
 #include <io.h>
 
+#include <stout/result.hpp>
 #include <stout/windows.hpp> // For order-dependent networking headers.
 
 #include <stout/os/socket.hpp>
@@ -22,6 +23,10 @@
 
 namespace os {
 
+// Forward declaration for an OS-agnostic `read`.
+inline Result<std::string> read(int fd, size_t size);
+
+
 inline ssize_t read(int fd, void* data, size_t size)
 {
   if (net::is_socket(fd)) {
@@ -31,6 +36,23 @@ inline ssize_t read(int fd, void* data, size_t size)
   return ::_read(fd, data, size);
 }
 
+
+inline ssize_t read(HANDLE handle, void* data, size_t size)
+{
+  return ::os::read(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDONLY),
+      data,
+      size);
+}
+
+
+inline Result<std::string> read(HANDLE handle, size_t size)
+{
+  return ::os::read(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDONLY),
+      size);
+}
+
 } // namespace os {
 
 #endif // __STOUT_OS_WINDOWS_READ_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/490c532c/3rdparty/stout/include/stout/os/windows/write.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/write.hpp b/3rdparty/stout/include/stout/os/windows/write.hpp
index 9f75568..705ad03 100644
--- a/3rdparty/stout/include/stout/os/windows/write.hpp
+++ b/3rdparty/stout/include/stout/os/windows/write.hpp
@@ -15,6 +15,8 @@
 
 #include <io.h>
 
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
 #include <stout/windows.hpp> // For order-dependent networking headers.
 
 #include <stout/os/socket.hpp>
@@ -22,6 +24,10 @@
 
 namespace os {
 
+// Forward declaration for an OS-agnostic `write`.
+inline Try<Nothing> write(int fd, const std::string& message);
+
+
 inline ssize_t write(int fd, const void* data, size_t size)
 {
   if (net::is_socket(fd)) {
@@ -31,6 +37,23 @@ inline ssize_t write(int fd, const void* data, size_t size)
   return ::_write(fd, data, size);
 }
 
+
+inline ssize_t read(HANDLE handle, const void* data, size_t size)
+{
+  return ::os::write(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDWR),
+      data,
+      size);
+}
+
+
+inline Try<Nothing> write(HANDLE handle, const std::string& message)
+{
+  return ::os::write(
+      _open_osfhandle(reinterpret_cast<intptr_t>(handle), O_RDWR),
+      message);
+}
+
 } // namespace os {