]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common,log,msg: Fix win32 compiler warnings
authorLucian Petrut <lpetrut@cloudbasesolutions.com>
Mon, 12 Oct 2020 09:55:12 +0000 (09:55 +0000)
committerLucian Petrut <lpetrut@cloudbasesolutions.com>
Wed, 28 Oct 2020 09:56:06 +0000 (09:56 +0000)
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 <lpetrut@cloudbasesolutions.com>
src/client/Client.cc
src/common/compat.cc
src/common/fork_function.h
src/common/ifaddrs_win32.cc
src/common/module.c
src/common/util.cc
src/include/compat.h
src/log/Log.cc
src/log/LogClock.h
src/msg/async/EventSelect.cc
src/tools/rbd/Utils.cc

index 7fcc41933c333e5c1f196771ce1724936a8bbf6d..d1fe129e39a94000d5f9424221e8a3a209d810ff 100644 (file)
@@ -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);
index aacfcc524a4400dab708726cf4783394515f0119..bac0cb81bc70e5ed93bf2c3854f9c1385e326d2f 100644 (file)
@@ -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/
index 4b223384658195b906c4c54e688cd96fa0c0dffe..3a4f2f29c08a274d13c9e92c54a6f5f58a2326f7 100644 (file)
 #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,
index 3ff58c8382b36f2a36163005cba1093f089341d4..d7de4a5ff8ae2892872a54c88d990aef40fb0540 100644 (file)
@@ -4,6 +4,7 @@
 #include <iphlpapi.h>
 #include <ws2tcpip.h>
 #include <ifaddrs.h>
+#include <stdio.h>
 
 #include "include/compat.h"
 
index e08c49d15c39389df97a919a1763010b90d82354..a2a468ac3e1f757751ffdc28e493eec941a457e7 100644 (file)
@@ -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;
index 6965ed1cf2a23c6531457f145755716c3a8f0f3a..6cb1f02733cfce00efd21aca57624b26a91fa927 100644 (file)
@@ -249,7 +249,7 @@ void collect_sys_info(map<string, string> *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<string, string> *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) {
index 1b807231f1417d7f8171fb3edfd7fb7408f04070..b454fc6a3f98182bf1fe6769b2d0a9a7adac82fb 100644 (file)
@@ -214,6 +214,7 @@ int ceph_memzero_s(void *dest, size_t destsz, size_t count);
 #include "include/win32/winsock_compat.h"
 
 #include <windows.h>
+#include <time.h>
 
 #include "include/win32/win32_errno.h"
 
index 68a884e7111efe1706fc92ae97f54c581b58e96e..3ddaa0534aab6a365483981f195a8e9b2a817e35 100644 (file)
@@ -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);
   }
 
index 1a9bc6cba2ce162b545defd56f32a5bab1a8bd6c..07531c8e51a9f8223b60045314d8f73e0fdcf596 100644 (file)
@@ -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<time_t>(std::chrono::duration_cast<std::chrono::seconds>(ts).count()),
              static_cast<suseconds_t>(std::chrono::duration_cast<std::chrono::microseconds>(
                ts % std::chrono::seconds(1)).count()) };
+    #else
+    return { static_cast<long>(std::chrono::duration_cast<std::chrono::seconds>(ts).count()),
+             static_cast<long>(std::chrono::duration_cast<std::chrono::microseconds>(
+               ts % std::chrono::seconds(1)).count()) };
+    #endif
   }
 private:
   static time_point coarse_now() {
index 8957792bb93859e254e1e5a96c06e877e9596487..35000ccea5c8afca6392707e4a4345287ae7cf17 100644 (file)
 
 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;
index eb1ea370ac7e9f3bf9c2a36b944502483899545a..6f2dfdcc1afb5e22b511aa5c8ed1dcb67ba8de89 100644 (file)
@@ -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;
 }