From 61227dfbaf4aa357baad18f906f3b59194378d87 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Fri, 18 Oct 2019 15:51:30 +0000 Subject: [PATCH] common: stub certain modules and functions on Windows We're going to stub certain modules and functions for Windows builds. Some of them will be implemented in subsequent commits, some are platform specific and will be skipped. Modules: * module.c * subprocess.cc * blkdev.cc * dns_resolve.cc * numa.cc * syslog.h * statvfs.h * libblk * neorados Functions: x signal functions x fork x chown * socketpair_cloexec * dump_open_fds * run_cmd * is_symlink * CInode::d_type * nbd commands Signed-off-by: Lucian Petrut Signed-off-by: Alin Gabriel Serdean --- src/CMakeLists.txt | 2 + src/common/CMakeLists.txt | 18 +++-- src/common/SubProcess.cc | 22 +++++ src/common/SubProcess.h | 2 + src/common/Thread.cc | 5 ++ src/common/blkdev_win32.cc | 137 ++++++++++++++++++++++++++++++++ src/common/compat.cc | 21 +++++ src/common/dns_resolve.h | 2 + src/common/dns_resolve_win32.cc | 65 +++++++++++++++ src/common/fd.cc | 6 ++ src/common/fork_function.h | 13 +++ src/common/ipaddr.cc | 2 +- src/common/module.c | 21 +++++ src/common/numa.cc | 3 +- src/common/signal.cc | 12 +++ src/include/compat.h | 20 +++++ src/include/win32/sys/statvfs.h | 0 src/include/win32/syslog.h | 62 +++++++++++++++ src/os/ObjectStore.h | 2 +- src/tools/CMakeLists.txt | 2 +- src/tools/rbd/action/Nbd.cc | 11 ++- 21 files changed, 415 insertions(+), 13 deletions(-) create mode 100644 src/common/blkdev_win32.cc create mode 100644 src/common/dns_resolve_win32.cc create mode 100644 src/include/win32/sys/statvfs.h create mode 100644 src/include/win32/syslog.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0227d8750f2..801bbe5941f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -544,7 +544,9 @@ endif() add_subdirectory(kv) add_subdirectory(os) +if(NOT WIN32) add_subdirectory(blk) +endif() add_subdirectory(osd) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index fbf6915f2c6..470ad46234a 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -45,7 +45,6 @@ set(common_srcs admin_socket_client.cc assert.cc bit_str.cc - blkdev.cc bloom_filter.cc ceph_argparse.cc ceph_context.cc @@ -64,7 +63,6 @@ set(common_srcs condition_variable_debug.cc config.cc config_values.cc - dns_resolve.cc dout.cc entity_name.cc environment.cc @@ -76,9 +74,7 @@ set(common_srcs histogram.cc hobject.cc hostname.cc - ipaddr.cc iso_8601.cc - linux_version.c lockdep.cc mempool.cc mime.c @@ -93,7 +89,6 @@ set(common_srcs pick_address.cc random_string.cc reverse.c - run_cmd.cc scrub_types.cc shared_mutex_debug.cc signal.cc @@ -108,6 +103,19 @@ set(common_srcs util.cc version.cc) +if(WIN32) + list(APPEND common_srcs + blkdev_win32.cc + dns_resolve_win32.cc) +else() + list(APPEND common_srcs + blkdev.cc + dns_resolve.cc + ipaddr.cc + linux_version.c + run_cmd.cc) +endif() + set_source_files_properties(${CMAKE_SOURCE_DIR}/src/common/version.cc APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_BINARY_DIR}/src/include/ceph_ver.h) diff --git a/src/common/SubProcess.cc b/src/common/SubProcess.cc index 1faf33e36ee..ab4ecd18021 100644 --- a/src/common/SubProcess.cc +++ b/src/common/SubProcess.cc @@ -102,6 +102,7 @@ void SubProcess::close_stderr() { close(stderr_pipe_in_fd); } +#ifndef _WIN32 void SubProcess::kill(int signo) const { ceph_assert(is_spawned()); @@ -273,6 +274,7 @@ int SubProcess::join() { errstr << cmd << ": waitpid: unknown status returned\n"; return EXIT_FAILURE; } +#endif /* _WIN32 */ SubProcessTimed::SubProcessTimed(const char *cmd, std_fd_op stdin_op, std_fd_op stdout_op, std_fd_op stderr_op, @@ -288,6 +290,7 @@ void timeout_sighandler(int sig) { } static void dummy_sighandler(int sig) {} +#ifndef _WIN32 void SubProcessTimed::exec() { ceph_assert(is_child()); @@ -392,3 +395,22 @@ void SubProcessTimed::exec() { fail_exit: _exit(EXIT_FAILURE); } + +#else +int SubProcess::join() { + return EXIT_FAILURE; +} + +void SubProcess::kill(int signo) const { +} + +int SubProcess::spawn() { + return EXIT_FAILURE; +} + +void SubProcess::exec() { +} + +void SubProcessTimed::exec() { +} +#endif /* _WIN32 */ diff --git a/src/common/SubProcess.h b/src/common/SubProcess.h index 763822af490..829749284fc 100644 --- a/src/common/SubProcess.h +++ b/src/common/SubProcess.h @@ -21,7 +21,9 @@ #include #endif +#ifndef _WIN32 #include +#endif #include #include diff --git a/src/common/Thread.cc b/src/common/Thread.cc index edbd7d34c87..45451040c4a 100644 --- a/src/common/Thread.cc +++ b/src/common/Thread.cc @@ -125,6 +125,8 @@ int Thread::try_create(size_t stacksize) // the set of signals we want to block. (It's ok to block signals more // signals than usual for a little while-- they will just be delivered to // another thread or delieverd to this thread later.) + + #ifndef _WIN32 sigset_t old_sigset; if (g_code_env == CODE_ENVIRONMENT_LIBRARY) { block_signals(NULL, &old_sigset); @@ -135,6 +137,9 @@ int Thread::try_create(size_t stacksize) } r = pthread_create(&thread_id, thread_attr, _entry_func, (void*)this); restore_sigset(&old_sigset); + #else + r = pthread_create(&thread_id, thread_attr, _entry_func, (void*)this); + #endif if (thread_attr) { pthread_attr_destroy(thread_attr); diff --git a/src/common/blkdev_win32.cc b/src/common/blkdev_win32.cc new file mode 100644 index 00000000000..c3e28e343ff --- /dev/null +++ b/src/common/blkdev_win32.cc @@ -0,0 +1,137 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 SUSE LINUX GmbH + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include "blkdev.h" + +int get_device_by_path(const char *path, char* partition, char* device, + size_t max) +{ + return -EOPNOTSUPP; +} + + +BlkDev::BlkDev(int f) + : fd(f) +{} + +BlkDev::BlkDev(const std::string& devname) + : devname(devname) +{} + +int BlkDev::get_devid(dev_t *id) const +{ + return -EOPNOTSUPP; +} + +const char *BlkDev::sysfsdir() const { + assert(false); // Should never be called on Windows + return ""; +} + +int BlkDev::dev(char *dev, size_t max) const +{ + return -EOPNOTSUPP; +} + +int BlkDev::get_size(int64_t *psize) const +{ + return -EOPNOTSUPP; +} + +bool BlkDev::support_discard() const +{ + return false; +} + +int BlkDev::discard(int64_t offset, int64_t len) const +{ + return -EOPNOTSUPP; +} + +bool BlkDev::is_rotational() const +{ + return false; +} + +int BlkDev::model(char *model, size_t max) const +{ + return -EOPNOTSUPP; +} + +int BlkDev::serial(char *serial, size_t max) const +{ + return -EOPNOTSUPP; +} + +int BlkDev::partition(char *partition, size_t max) const +{ + return -EOPNOTSUPP; +} + +int BlkDev::wholedisk(char *wd, size_t max) const +{ + return -EOPNOTSUPP; +} + +void get_dm_parents(const std::string& dev, std::set *ls) +{ +} + +void get_raw_devices(const std::string& in, + std::set *ls) +{ +} + +int get_vdo_stats_handle(const char *devname, std::string *vdo_name) +{ + return -1; +} + +int64_t get_vdo_stat(int fd, const char *property) +{ + return 0; +} + +bool get_vdo_utilization(int fd, uint64_t *total, uint64_t *avail) +{ + return false; +} + +std::string get_device_id(const std::string& devname, + std::string *err) +{ + if (err) { + *err = "not implemented"; + } + return std::string(); +} + +int block_device_run_smartctl(const char *device, int timeout, + std::string *result) +{ + return -EOPNOTSUPP; +} + +int block_device_get_metrics(const std::string& devname, int timeout, + json_spirit::mValue *result) +{ + return -EOPNOTSUPP; +} + +int block_device_run_nvme(const char *device, const char *vendor, int timeout, + std::string *result) +{ + return -EOPNOTSUPP; +} diff --git a/src/common/compat.cc b/src/common/compat.cc index e38aff4fb1d..74e99165572 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -148,6 +148,9 @@ int socketpair_cloexec(int domain, int type, int protocol, int sv[2]) { #ifdef SOCK_CLOEXEC return socketpair(domain, type|SOCK_CLOEXEC, protocol, sv); +#elif _WIN32 + /* TODO */ + return -ENOTSUP; #else int rc = socketpair(domain, type, protocol, sv); if (rc == -1) @@ -207,3 +210,21 @@ char *ceph_strerror_r(int errnum, char *buf, size_t buflen) return buf; #endif } + +#ifdef _WIN32 + +// chown is not available on Windows. Plus, changing file owners is not +// a common practice on Windows. +int chown(const char *path, uid_t owner, gid_t group) { + return 0; +} + +int fchown(int fd, uid_t owner, gid_t group) { + return 0; +} + +int lchown(const char *path, uid_t owner, gid_t group) { + return 0; +} + +#endif /* _WIN32 */ \ No newline at end of file diff --git a/src/common/dns_resolve.h b/src/common/dns_resolve.h index d3bbf103b52..7a32e2a2a62 100644 --- a/src/common/dns_resolve.h +++ b/src/common/dns_resolve.h @@ -139,11 +139,13 @@ class DNSResolver { void put_state(res_state s); #endif +#ifndef _WIN32 /* this private function allows to reuse the res_state structure used * by other function of this class */ int resolve_ip_addr(CephContext *cct, res_state *res, const std::string& hostname, entity_addr_t *addr); +#endif std::string srv_protocol_to_str(SRV_Protocol proto) { switch (proto) { diff --git a/src/common/dns_resolve_win32.cc b/src/common/dns_resolve_win32.cc new file mode 100644 index 00000000000..b7a888b30eb --- /dev/null +++ b/src/common/dns_resolve_win32.cc @@ -0,0 +1,65 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2019 SUSE LINUX GmbH + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "include/scope_guard.h" +#include "dns_resolve.h" +#include "common/debug.h" + +#define dout_subsys ceph_subsys_ + + +namespace ceph { + +int ResolvHWrapper::res_query(const char *hostname, int cls, + int type, u_char *buf, int bufsz) { + return -1; +} + +int ResolvHWrapper::res_search(const char *hostname, int cls, + int type, u_char *buf, int bufsz) { + return -1; +} + +DNSResolver::~DNSResolver() +{ + delete resolv_h; +} + +int DNSResolver::resolve_cname(CephContext *cct, const string& hostname, + string *cname, bool *found) +{ + return -ENOTSUP; +} + +int DNSResolver::resolve_ip_addr(CephContext *cct, const string& hostname, + entity_addr_t *addr) +{ + return -ENOTSUP; +} + +int DNSResolver::resolve_srv_hosts(CephContext *cct, const string& service_name, + const SRV_Protocol trans_protocol, + map *srv_hosts) +{ + return this->resolve_srv_hosts(cct, service_name, trans_protocol, "", srv_hosts); +} + +int DNSResolver::resolve_srv_hosts(CephContext *cct, const string& service_name, + const SRV_Protocol trans_protocol, const string& domain, + map *srv_hosts) +{ + return -ENOTSUP; +} + +} diff --git a/src/common/fd.cc b/src/common/fd.cc index 931d4353c2b..89d18940b63 100644 --- a/src/common/fd.cc +++ b/src/common/fd.cc @@ -16,6 +16,7 @@ #include "debug.h" #include "errno.h" +#ifndef _WIN32 void dump_open_fds(CephContext *cct) { #ifdef __APPLE__ @@ -51,3 +52,8 @@ void dump_open_fds(CephContext *cct) closedir(d); } +#else +void dump_open_fds(CephContext *cct) +{ +} +#endif diff --git a/src/common/fork_function.h b/src/common/fork_function.h index 9076cc5a995..4b223384658 100644 --- a/src/common/fork_function.h +++ b/src/common/fork_function.h @@ -10,7 +10,9 @@ #include #include +#ifndef _WIN32 #include +#endif #include #include "include/ceph_assert.h" @@ -22,6 +24,7 @@ static void _fork_function_dummy_sighandler(int sig) {} // int8_t only due to unix exit code limitations. Returns -ETIMEDOUT // if timeout is reached. +#ifndef _WIN32 static inline int fork_function( int timeout, std::ostream& errstr, @@ -162,3 +165,13 @@ static inline int fork_function( fail_exit: _exit(EXIT_FAILURE); } +#else +static inline int fork_function( + int timeout, + std::ostream& errstr, + std::function f) +{ + errstr << "Forking is not available on Windows.\n"; + return -1; +} +#endif diff --git a/src/common/ipaddr.cc b/src/common/ipaddr.cc index d166dc8b412..16114093798 100644 --- a/src/common/ipaddr.cc +++ b/src/common/ipaddr.cc @@ -36,7 +36,7 @@ void netmask_ipv4(const struct in_addr *addr, static bool match_numa_node(const string& if_name, int numa_node) { -#ifdef WITH_SEASTAR +#if defined(WITH_SEASTAR) || defined(_WIN32) return true; #else int if_node = -1; diff --git a/src/common/module.c b/src/common/module.c index e67b3bf933a..e08c49d15c3 100644 --- a/src/common/module.c +++ b/src/common/module.c @@ -20,6 +20,7 @@ #include #endif +#ifndef _WIN32 /* * TODO: Switch to libkmod when we abandon older platforms. The APIs * we want are: @@ -77,3 +78,23 @@ int module_load(const char *module, const char *options) return run_command(command); } + +#else + +// We're stubbing out those functions, for now. +static int run_command(const char *command) +{ + return -1; +} + +int module_has_param(const char *module, const char *param) +{ + return -1; +} + +int module_load(const char *module, const char *options) +{ + return -1; +} + +#endif /* _WIN32 */ diff --git a/src/common/numa.cc b/src/common/numa.cc index 89368bd4005..87fde6e68af 100644 --- a/src/common/numa.cc +++ b/src/common/numa.cc @@ -188,8 +188,7 @@ int set_cpu_affinity_all_threads(size_t cpu_set_size, cpu_set_t *cpu_set) return 0; } -#elif defined(__FreeBSD__) - +#else int parse_cpu_set_list(const char *s, size_t *cpu_set_size, cpu_set_t *cpu_set) diff --git a/src/common/signal.cc b/src/common/signal.cc index edb6aa17aa6..97f13edfafb 100644 --- a/src/common/signal.cc +++ b/src/common/signal.cc @@ -30,6 +30,7 @@ using namespace std::literals; +#ifndef _WIN32 std::string signal_mask_to_str() { sigset_t old_sigset; @@ -83,3 +84,14 @@ void unblock_all_signals(sigset_t *old_sigset) int ret = pthread_sigmask(SIG_UNBLOCK, &sigset, old_sigset); ceph_assert(ret == 0); } +#else +std::string signal_mask_to_str() +{ + return "(unsupported signal)"; +} + +// Windows provides limited signal functionality. +void block_signals(const int *siglist, sigset_t *old_sigset) {} +void restore_sigset(const sigset_t *old_sigset) {} +void unblock_all_signals(sigset_t *old_sigset) {} +#endif /* _WIN32 */ diff --git a/src/include/compat.h b/src/include/compat.h index a7cf55b42ba..9197863e32b 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -219,6 +219,14 @@ typedef long nlink_t; typedef long long loff_t; +#define CPU_SETSIZE (sizeof(size_t)*8) + +typedef union +{ + char cpuset[CPU_SETSIZE/8]; + size_t _align; +} cpu_set_t; + #define SHUT_RD SD_RECEIVE #define SHUT_WR SD_SEND #define SHUT_RDWR SD_BOTH @@ -245,6 +253,18 @@ typedef long long loff_t; // flag as a no-op. #define O_CLOEXEC 0 +#ifdef __cplusplus +extern "C" { +#endif + +int chown(const char *path, uid_t owner, gid_t group); +int fchown(int fd, uid_t owner, gid_t group); +int lchown(const char *path, uid_t owner, gid_t group); + +#ifdef __cplusplus +} +#endif + #endif /* WIN32 */ #endif /* !CEPH_COMPAT_H */ diff --git a/src/include/win32/sys/statvfs.h b/src/include/win32/sys/statvfs.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/include/win32/syslog.h b/src/include/win32/syslog.h new file mode 100644 index 00000000000..d59cd3d0c7c --- /dev/null +++ b/src/include/win32/syslog.h @@ -0,0 +1,62 @@ +/* + * Copyright 2013, 2015 Cloudbase Solutions Srl + * + * 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 SYSLOG_H +#define SYSLOG_H 1 + +#define LOG_EMERG 0 /* system is unusable */ +#define LOG_ALERT 1 /* action must be taken immediately */ +#define LOG_CRIT 2 /* critical conditions */ +#define LOG_ERR 3 /* error conditions */ +#define LOG_WARNING 4 /* warning conditions */ +#define LOG_NOTICE 5 /* normal but significant condition */ +#define LOG_INFO 6 /* informational */ +#define LOG_DEBUG 7 /* debug-level messages */ +#define LOG_NDELAY 8 /* don't delay open */ + +#define LOG_KERN (0<<3) /* kernel messages */ +#define LOG_USER (1<<3) /* user-level messages */ +#define LOG_MAIL (2<<3) /* mail system */ +#define LOG_DAEMON (3<<3) /* system daemons */ +#define LOG_AUTH (4<<3) /* security/authorization messages */ +#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ +#define LOG_LPR (6<<3) /* line printer subsystem */ +#define LOG_NEWS (7<<3) /* network news subsystem */ +#define LOG_UUCP (8<<3) /* UUCP subsystem */ +#define LOG_CRON (9<<3) /* clock daemon */ +#define LOG_AUTHPRIV (10<<3) /* security/authorization messages */ +#define LOG_FTP (11<<3) /* FTP daemon */ + +#define LOG_LOCAL0 (16<<3) /* reserved for local use */ +#define LOG_LOCAL1 (17<<3) /* reserved for local use */ +#define LOG_LOCAL2 (18<<3) /* reserved for local use */ +#define LOG_LOCAL3 (19<<3) /* reserved for local use */ +#define LOG_LOCAL4 (20<<3) /* reserved for local use */ +#define LOG_LOCAL5 (21<<3) /* reserved for local use */ +#define LOG_LOCAL6 (22<<3) /* reserved for local use */ +#define LOG_LOCAL7 (23<<3) /* reserved for local use */ + +static inline void +openlog(const char *ident, int option, int facility) +{ +} + +static inline void +syslog(int priority, const char *format, ...) +{ +} + +#endif /* syslog.h */ diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 9a9c075fc2b..bfd5ba47579 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -32,7 +32,7 @@ #include #include -#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun) || defined(_WIN32) #include #else #include /* or */ diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index f460ce1ae2d..579a8f791e7 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -16,7 +16,7 @@ else() endif() install(TARGETS rados DESTINATION bin) -if(WITH_BOOST_CONTEXT) +if(WITH_BOOST_CONTEXT AND NOT WIN32) set(neorados_srcs neorados.cc) add_executable(neorados ${neorados_srcs}) diff --git a/src/tools/rbd/action/Nbd.cc b/src/tools/rbd/action/Nbd.cc index ab62e9a7bf8..78205f48c6b 100644 --- a/src/tools/rbd/action/Nbd.cc +++ b/src/tools/rbd/action/Nbd.cc @@ -21,6 +21,10 @@ namespace po = boost::program_options; static int call_nbd_cmd(const po::variables_map &vm, const std::vector &args, const std::vector &ceph_global_init_args) { + #ifdef _WIN32 + std::cerr << "rbd: nbd device is not supported" << std::endl; + return -EOPNOTSUPP; + #else char exe_path[PATH_MAX]; ssize_t exe_path_bytes = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); @@ -53,6 +57,7 @@ static int call_nbd_cmd(const po::variables_map &vm, } return 0; + #endif } int get_image_or_snap_spec(const po::variables_map &vm, std::string *spec) { @@ -99,7 +104,7 @@ int parse_options(const std::vector &options, int execute_list(const po::variables_map &vm, const std::vector &ceph_global_init_args) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; #endif @@ -120,7 +125,7 @@ int execute_list(const po::variables_map &vm, int execute_map(const po::variables_map &vm, const std::vector &ceph_global_init_args) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; #endif @@ -163,7 +168,7 @@ int execute_map(const po::variables_map &vm, int execute_unmap(const po::variables_map &vm, const std::vector &ceph_global_init_args) { -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(_WIN32) std::cerr << "rbd: nbd device is not supported" << std::endl; return -EOPNOTSUPP; #endif -- 2.39.5