From 99b91e9eba418917c58e1b46299ea9e3e39c72af Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 4 Nov 2019 08:49:31 +0000 Subject: [PATCH] include/compat: Add missing win32 type and constant definitions The following types and constants are not defined on Windows, for which reason we're going to include them in compat.h. * uid_t, gid_t * sigset_t * HOST_NAME_MAX * O_CLOEXEC, which we're going to define as a no-op. By default, handles are not inherited by subprocesses. * SHUT_* flags * loff_t * __STRING * EBADE, ENODATA, ESHUTDOWN, ESTALE, EREMOTEIO * suseconds_t * SIGKILL, SIGINT - we're mostly going to stub signal handling on Windows Also, we'll have to make sure that pipe_cloexec uses C style linking, which would otherwise be affected as the include order changes. timeval.tv_sec is defined as long instead of time_t on Windows[1], which we'll have to take into account. [1] https://docs.microsoft.com/en-us/windows/win32/api/winsock/ns-winsock-timeval Signed-off-by: Lucian Petrut --- src/common/ceph_context.h | 1 + src/crush/CrushCompiler.cc | 4 +++ src/include/ceph_assert.h | 6 ++--- src/include/compat.h | 50 ++++++++++++++++++++++++++++++++++---- src/include/statlite.h | 2 ++ src/log/LogClock.h | 6 ++++- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index 187cd3d165a7a..3d1cff123c7e0 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -29,6 +29,7 @@ #include "include/any.h" #include "include/common_fwd.h" +#include "include/compat.h" #include "common/cmdparse.h" #include "common/code_environment.h" diff --git a/src/crush/CrushCompiler.cc b/src/crush/CrushCompiler.cc index eafda63afa753..9b4153f2563db 100644 --- a/src/crush/CrushCompiler.cc +++ b/src/crush/CrushCompiler.cc @@ -7,6 +7,10 @@ #define EBADE ECORRUPT #endif +#if defined(_WIN32) +#define EBADE EINVAL +#endif + #ifndef EBADE #define EBADE EFTYPE #endif diff --git a/src/include/ceph_assert.h b/src/include/ceph_assert.h index c0df90ce1450a..0627894ea6e07 100644 --- a/src/include/ceph_assert.h +++ b/src/include/ceph_assert.h @@ -4,13 +4,13 @@ #include #include -#if defined(__linux__) -#include - #ifndef __STRING # define __STRING(x) #x #endif +#if defined(__linux__) +#include + #elif defined(__FreeBSD__) #include #define __GNUC_PREREQ(minor, major) __GNUC_PREREQ__(minor, major) diff --git a/src/include/compat.h b/src/include/compat.h index bfb12579d692c..ceb55896a47b4 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -103,15 +103,15 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, #define XATTR_CREATE 1 #endif +#endif /* __APPLE__ */ + #ifndef HOST_NAME_MAX #ifdef MAXHOSTNAMELEN #define HOST_NAME_MAX MAXHOSTNAMELEN #else #define HOST_NAME_MAX 255 #endif -#endif - -#endif /* __APPLE__ */ +#endif /* HOST_NAME_MAX */ /* O_LARGEFILE is not defined/required on OSX/FreeBSD */ #ifndef O_LARGEFILE @@ -193,16 +193,56 @@ int sched_setaffinity(pid_t pid, size_t cpusetsize, int ceph_posix_fallocate(int fd, off_t offset, off_t len); -int pipe_cloexec(int pipefd[2], int flags); - #ifdef __cplusplus extern "C" { #endif +int pipe_cloexec(int pipefd[2], int flags); char *ceph_strerror_r(int errnum, char *buf, size_t buflen); #ifdef __cplusplus } #endif +#if defined(_WIN32) + +typedef _sigset_t sigset_t; + +typedef int uid_t; +typedef int gid_t; + +typedef long blksize_t; +typedef long blkcnt_t; +typedef long nlink_t; + +typedef long long loff_t; + +#define SHUT_RD SD_RECEIVE +#define SHUT_WR SD_SEND +#define SHUT_RDWR SD_BOTH + +#ifndef SIGINT +#define SIGINT 2 +#endif + +#ifndef SIGKILL +#define SIGKILL 9 +#endif + +#ifndef ENODATA +// mingw doesn't define this, the Windows SDK does. +#define ENODATA 120 +#endif + +#define ESHUTDOWN ECONNABORTED +#define ESTALE 256 +#define EREMOTEIO 257 + +// O_CLOEXEC is not defined on Windows. Since handles aren't inherited +// with subprocesses unless explicitly requested, we'll define this +// flag as a no-op. +#define O_CLOEXEC 0 + +#endif /* WIN32 */ + #endif /* !CEPH_COMPAT_H */ diff --git a/src/include/statlite.h b/src/include/statlite.h index 2ab3a940687d5..0ff4b04e71d08 100644 --- a/src/include/statlite.h +++ b/src/include/statlite.h @@ -11,6 +11,8 @@ extern "C" { #include #include +#include "include/compat.h" + struct statlite { dev_t st_dev; /* device */ ino_t st_ino; /* inode */ diff --git a/src/log/LogClock.h b/src/log/LogClock.h index 98d8c17f7ed73..6648f44f0b707 100644 --- a/src/log/LogClock.h +++ b/src/log/LogClock.h @@ -12,6 +12,10 @@ #include "include/ceph_assert.h" #include "common/ceph_time.h" +#ifndef suseconds_t +typedef long suseconds_t; +#endif + namespace ceph { namespace logging { namespace _logclock { @@ -130,7 +134,7 @@ inline int append_time(const log_time& t, char *out, int outlen) { bool coarse = t.time_since_epoch().count().coarse; auto tv = log_clock::to_timeval(t); std::tm bdt; - localtime_r(&tv.tv_sec, &bdt); + localtime_r((time_t*)&tv.tv_sec, &bdt); char tz[32] = { 0 }; strftime(tz, sizeof(tz), "%z", &bdt); -- 2.39.5