From ea0967c963a0250f8ab4c76e04f8ff461cff8a9d Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Mon, 12 Oct 2020 09:55:12 +0000 Subject: [PATCH] common,log,msg: Fix win32 compiler warnings This change will fix a few compiler warnings, most of them being type mismatches that affect Windows builds. Worth mentioning that "long" uses 32b on x64 Windows platforms, which is a constant source of type mismatches. There's a warning saying that the "select" event handler shouldn't be used in production. Considering that this is the only available mechanism on Windows for the time being, we're going to disable this warning. Signed-off-by: Lucian Petrut --- src/client/Client.cc | 42 ++++++++++++++++++------------------ src/common/compat.cc | 4 ++-- src/common/fork_function.h | 3 +-- src/common/ifaddrs_win32.cc | 1 + src/common/module.c | 5 ----- src/common/util.cc | 4 ++-- src/include/compat.h | 1 + src/log/Log.cc | 2 +- src/log/LogClock.h | 6 ++++++ src/msg/async/EventSelect.cc | 2 ++ src/tools/rbd/Utils.cc | 2 +- 11 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index 7fcc41933c3..d1fe129e39a 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -2681,7 +2681,7 @@ bool Client::ms_dispatch2(const MessageRef &m) if (is_unmounting()) { ldout(cct, 10) << "unmounting: trim pass, size was " << lru.lru_get_size() << "+" << inode_map.size() << dendl; - long unsigned size = lru.lru_get_size() + inode_map.size(); + uint64_t size = lru.lru_get_size() + inode_map.size(); trim_cache(); if (size < lru.lru_get_size() + inode_map.size()) { ldout(cct, 10) << "unmounting: trim pass, cache shrank, poking unmount()" << dendl; @@ -7164,8 +7164,8 @@ int Client::_do_setattr(Inode *in, struct ceph_statx *stx, int mask, return -EROFS; } if ((mask & CEPH_SETATTR_SIZE) && - (unsigned long)stx->stx_size > in->size && - is_quota_bytes_exceeded(in, (unsigned long)stx->stx_size - in->size, + (uint64_t)stx->stx_size > in->size && + is_quota_bytes_exceeded(in, (uint64_t)stx->stx_size - in->size, perms)) { return -EDQUOT; } @@ -7323,7 +7323,7 @@ force_request: CEPH_CAP_FILE_WR; } if (mask & CEPH_SETATTR_SIZE) { - if ((unsigned long)stx->stx_size < mdsmap->get_max_filesize()) { + if ((uint64_t)stx->stx_size < mdsmap->get_max_filesize()) { req->head.args.setattr.size = stx->stx_size; ldout(cct,10) << "changing size to " << stx->stx_size << dendl; } else { //too big! @@ -8088,7 +8088,7 @@ int Client::opendir(const char *relpath, dir_result_t **dirpp, const UserPerm& p r = _opendir(in.get(), dirpp, perms); /* if ENOTDIR, dirpp will be an uninitialized point and it's very dangerous to access its value */ if (r != -ENOTDIR) - tout(cct) << (unsigned long)*dirpp << std::endl; + tout(cct) << (uintptr_t)*dirpp << std::endl; return r; } @@ -8106,7 +8106,7 @@ int Client::_opendir(Inode *in, dir_result_t **dirpp, const UserPerm& perms) int Client::closedir(dir_result_t *dir) { tout(cct) << __func__ << std::endl; - tout(cct) << (unsigned long)dir << std::endl; + tout(cct) << (uintptr_t)dir << std::endl; ldout(cct, 3) << __func__ << "(" << dir << ") = 0" << dendl; std::scoped_lock lock(client_lock); @@ -13441,7 +13441,7 @@ int Client::ll_opendir(Inode *in, int flags, dir_result_t** dirpp, } int r = _opendir(in, dirpp, perms); - tout(cct) << (unsigned long)*dirpp << std::endl; + tout(cct) << (uintptr_t)*dirpp << std::endl; ldout(cct, 3) << "ll_opendir " << vino << " = " << r << " (" << *dirpp << ")" << dendl; @@ -13456,7 +13456,7 @@ int Client::ll_releasedir(dir_result_t *dirp) ldout(cct, 3) << "ll_releasedir " << dirp << dendl; tout(cct) << "ll_releasedir" << std::endl; - tout(cct) << (unsigned long)dirp << std::endl; + tout(cct) << (uintptr_t)dirp << std::endl; std::scoped_lock lock(client_lock); @@ -13472,7 +13472,7 @@ int Client::ll_fsyncdir(dir_result_t *dirp) ldout(cct, 3) << "ll_fsyncdir " << dirp << dendl; tout(cct) << "ll_fsyncdir" << std::endl; - tout(cct) << (unsigned long)dirp << std::endl; + tout(cct) << (uintptr_t)dirp << std::endl; std::scoped_lock lock(client_lock); return _fsync(dirp->inode.get(), false); @@ -13509,7 +13509,7 @@ int Client::ll_open(Inode *in, int flags, Fh **fhp, const UserPerm& perms) if (fhptr) { ll_unclosed_fh_set.insert(fhptr); } - tout(cct) << (unsigned long)fhptr << std::endl; + tout(cct) << (uintptr_t)fhptr << std::endl; ldout(cct, 3) << "ll_open " << vino << " " << ceph_flags_sys2wire(flags) << " = " << r << " (" << fhptr << ")" << dendl; return r; @@ -13588,7 +13588,7 @@ out: ino = inode->ino; } - tout(cct) << (unsigned long)*fhp << std::endl; + tout(cct) << (uintptr_t)*fhp << std::endl; tout(cct) << ino << std::endl; ldout(cct, 8) << "_ll_create " << vparent << " " << name << " 0" << oct << mode << dec << " " << ceph_flags_sys2wire(flags) << " = " << r << " (" << @@ -13679,7 +13679,7 @@ int Client::ll_read(Fh *fh, loff_t off, loff_t len, bufferlist *bl) ldout(cct, 3) << "ll_read " << fh << " " << fh->inode->ino << " " << " " << off << "~" << len << dendl; tout(cct) << "ll_read" << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; tout(cct) << off << std::endl; tout(cct) << len << std::endl; @@ -13815,7 +13815,7 @@ int Client::ll_write(Fh *fh, loff_t off, loff_t len, const char *data) ldout(cct, 3) << "ll_write " << fh << " " << fh->inode->ino << " " << off << "~" << len << dendl; tout(cct) << "ll_write" << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; tout(cct) << off << std::endl; tout(cct) << len << std::endl; @@ -13861,7 +13861,7 @@ int Client::ll_flush(Fh *fh) ldout(cct, 3) << "ll_flush " << fh << " " << fh->inode->ino << " " << dendl; tout(cct) << "ll_flush" << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); return _flush(fh); @@ -13875,7 +13875,7 @@ int Client::ll_fsync(Fh *fh, bool syncdataonly) ldout(cct, 3) << "ll_fsync " << fh << " " << fh->inode->ino << " " << dendl; tout(cct) << "ll_fsync" << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); int r = _fsync(fh, syncdataonly); @@ -13894,7 +13894,7 @@ int Client::ll_sync_inode(Inode *in, bool syncdataonly) ldout(cct, 3) << "ll_sync_inode " << *in << " " << dendl; tout(cct) << "ll_sync_inode" << std::endl; - tout(cct) << (unsigned long)in << std::endl; + tout(cct) << (uintptr_t)in << std::endl; std::scoped_lock lock(client_lock); return _fsync(in, syncdataonly); @@ -14041,7 +14041,7 @@ int Client::ll_fallocate(Fh *fh, int mode, int64_t offset, int64_t length) ldout(cct, 3) << __func__ << " " << fh << " " << fh->inode->ino << " " << dendl; tout(cct) << __func__ << " " << mode << " " << offset << " " << length << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); return _fallocate(fh, mode, offset, length); @@ -14075,7 +14075,7 @@ int Client::ll_release(Fh *fh) ldout(cct, 3) << __func__ << " (fh)" << fh << " " << fh->inode->ino << " " << dendl; tout(cct) << __func__ << " (fh)" << std::endl; - tout(cct) << (unsigned long)fh << std::endl; + tout(cct) << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); @@ -14091,7 +14091,7 @@ int Client::ll_getlk(Fh *fh, struct flock *fl, uint64_t owner) return -ENOTCONN; ldout(cct, 3) << "ll_getlk (fh)" << fh << " " << fh->inode->ino << dendl; - tout(cct) << "ll_getk (fh)" << (unsigned long)fh << std::endl; + tout(cct) << "ll_getk (fh)" << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); return _getlk(fh, fl, owner); @@ -14104,7 +14104,7 @@ int Client::ll_setlk(Fh *fh, struct flock *fl, uint64_t owner, int sleep) return -ENOTCONN; ldout(cct, 3) << __func__ << " (fh) " << fh << " " << fh->inode->ino << dendl; - tout(cct) << __func__ << " (fh)" << (unsigned long)fh << std::endl; + tout(cct) << __func__ << " (fh)" << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); return _setlk(fh, fl, owner, sleep); @@ -14117,7 +14117,7 @@ int Client::ll_flock(Fh *fh, int cmd, uint64_t owner) return -ENOTCONN; ldout(cct, 3) << __func__ << " (fh) " << fh << " " << fh->inode->ino << dendl; - tout(cct) << __func__ << " (fh)" << (unsigned long)fh << std::endl; + tout(cct) << __func__ << " (fh)" << (uintptr_t)fh << std::endl; std::scoped_lock lock(client_lock); return _flock(fh, cmd, owner); diff --git a/src/common/compat.cc b/src/common/compat.cc index aacfcc524a4..bac0cb81bc7 100644 --- a/src/common/compat.cc +++ b/src/common/compat.cc @@ -287,7 +287,7 @@ int pipe(int pipefd[2]) { long int lrand48(void) { long int val; val = (long int) rand(); - val << 16; + val <<= 16; val += (long int) rand(); return val; } @@ -385,7 +385,7 @@ int &alloc_tls() { return tlsvar; } -int apply_tls_workaround() { +void apply_tls_workaround() { // Workaround for the following Mingw bugs: // https://sourceforge.net/p/mingw-w64/bugs/727/ // https://sourceforge.net/p/mingw-w64/bugs/527/ diff --git a/src/common/fork_function.h b/src/common/fork_function.h index 4b223384658..3a4f2f29c08 100644 --- a/src/common/fork_function.h +++ b/src/common/fork_function.h @@ -18,13 +18,12 @@ #include "include/ceph_assert.h" #include "common/errno.h" +#ifndef _WIN32 static void _fork_function_dummy_sighandler(int sig) {} // Run a function post-fork, with a timeout. Function can return // 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, diff --git a/src/common/ifaddrs_win32.cc b/src/common/ifaddrs_win32.cc index 3ff58c8382b..d7de4a5ff8a 100644 --- a/src/common/ifaddrs_win32.cc +++ b/src/common/ifaddrs_win32.cc @@ -4,6 +4,7 @@ #include #include #include +#include #include "include/compat.h" diff --git a/src/common/module.c b/src/common/module.c index e08c49d15c3..a2a468ac3e1 100644 --- a/src/common/module.c +++ b/src/common/module.c @@ -82,11 +82,6 @@ int module_load(const char *module, const char *options) #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; diff --git a/src/common/util.cc b/src/common/util.cc index 6965ed1cf2a..6cb1f02733c 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -249,7 +249,7 @@ void collect_sys_info(map *m, CephContext *cct) get_windows_version(&ver); char version_str[64]; - snprintf(version_str, 64, "%d.%d (%d)", + snprintf(version_str, 64, "%lu.%lu (%lu)", ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber); char hostname[64]; @@ -257,7 +257,7 @@ void collect_sys_info(map *m, CephContext *cct) GetComputerNameA(hostname, &hostname_sz); SYSTEM_INFO sys_info; - char* arch_str; + const char* arch_str; GetNativeSystemInfo(&sys_info); switch (sys_info.wProcessorArchitecture) { diff --git a/src/include/compat.h b/src/include/compat.h index 1b807231f14..b454fc6a3f9 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -214,6 +214,7 @@ int ceph_memzero_s(void *dest, size_t destsz, size_t count); #include "include/win32/winsock_compat.h" #include +#include #include "include/win32/win32_errno.h" diff --git a/src/log/Log.cc b/src/log/Log.cc index 68a884e7111..3ddaa0534aa 100644 --- a/src/log/Log.cc +++ b/src/log/Log.cc @@ -375,7 +375,7 @@ void Log::dump_recent() { char pthread_name[16] = {0}; //limited by 16B include terminating null byte. ceph_pthread_getname(pthread_id, pthread_name, sizeof(pthread_name)); - snprintf(buf, sizeof(buf), " %lx / %s", pthread_id, pthread_name); + snprintf(buf, sizeof(buf), " %llx / %s", pthread_id, pthread_name); _log_message(buf, true); } diff --git a/src/log/LogClock.h b/src/log/LogClock.h index 1a9bc6cba2c..07531c8e51a 100644 --- a/src/log/LogClock.h +++ b/src/log/LogClock.h @@ -112,9 +112,15 @@ public: static timeval to_timeval(time_point t) { auto rep = t.time_since_epoch().count(); timespan ts(rep.count); + #ifndef _WIN32 return { static_cast(std::chrono::duration_cast(ts).count()), static_cast(std::chrono::duration_cast( ts % std::chrono::seconds(1)).count()) }; + #else + return { static_cast(std::chrono::duration_cast(ts).count()), + static_cast(std::chrono::duration_cast( + ts % std::chrono::seconds(1)).count()) }; + #endif } private: static time_point coarse_now() { diff --git a/src/msg/async/EventSelect.cc b/src/msg/async/EventSelect.cc index 8957792bb93..35000ccea5c 100644 --- a/src/msg/async/EventSelect.cc +++ b/src/msg/async/EventSelect.cc @@ -26,8 +26,10 @@ int SelectDriver::init(EventCenter *c, int nevent) { + #ifndef _WIN32 ldout(cct, 0) << "Select isn't suitable for production env, just avoid " << "compiling error or special purpose" << dendl; + #endif FD_ZERO(&rfds); FD_ZERO(&wfds); max_fd = 0; diff --git a/src/tools/rbd/Utils.cc b/src/tools/rbd/Utils.cc index eb1ea370ac7..6f2dfdcc1af 100644 --- a/src/tools/rbd/Utils.cc +++ b/src/tools/rbd/Utils.cc @@ -960,7 +960,7 @@ std::string timestr(time_t t) { localtime_r(&t, &tm); char buf[32]; - strftime(buf, sizeof(buf), "%F %T", &tm); + strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm); return buf; } -- 2.39.5