]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
src/*: do not pass cct to ceph_version_to_str()
authorKefu Chai <kchai@redhat.com>
Thu, 10 Dec 2020 06:17:07 +0000 (14:17 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 10 Dec 2020 10:26:39 +0000 (18:26 +0800)
in e5b1ae5554c4d8a20f9f0ff562b231ad0b0ba0ab, a new option named
"debug_version_for_testing" is introduced to override the version so
we can test version check.

in crimson, we have two families of shared functions.

- one of them is used by alien store. they are compiled with
  -DWITH_SEASTAR and -DWITH_ALIEN, to enable the shim code between
  seastar and POSIX thread.
- another is used by crimson in general. where no lock is allowed.

currently, we use the "crimson" and "ceph" namespace to differentiate
these two families of functions, so they can colocate in the same
executable without violating the ODR. see src/include/common_fwd.h for
more details.

the functions defined in src/common/version.cc are also shared by
alien store and crimson code. and because we have different
implementations of `CephContext` in crimson and in classic OSD (i.e.
alienstore), we have to have different implementations of this function
as well, if we follow the same approach. but since these functions are
very simple and are non-blocking, there is not much value in
differentiating them, it is better to inject the test settings using
environment variable instead of using ceph option subsystem.

in this change, "ceph_debug_version_for_testing" environment variable is
checked instead, so that crimson and alienstore can share the same
compilation unit of version.cc. and "debug_version_for_testing" option
is removed.

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/standalone/misc/ver-health.sh
src/common/admin_socket.cc
src/common/options.cc
src/common/util.cc
src/common/version.cc
src/common/version.h
src/crimson/admin/admin_socket.cc
src/global/signal_handler.cc
src/libcephfs.cc
src/mon/Monitor.cc
src/tools/immutable_object_cache/CacheClient.cc

index 80d0b690494ba6850f18f4246f7668f01442cbd6..3c480b2b105330a1452790a8e7695fdf60dc15a3 100755 (executable)
@@ -85,7 +85,7 @@ function TEST_check_version_health_1() {
     ceph health detail | grep DAEMON_OLD_VERSION && return 1
 
     kill_daemons $dir KILL osd.1
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" activate_osd $dir 1
+    ceph_debug_version_for_testing=01.00.00-gversion-test activate_osd $dir 1
 
     wait_for_health_string "HEALTH_WARN .*There is a daemon running an older version of ceph" || return 1
 
@@ -96,9 +96,9 @@ function TEST_check_version_health_1() {
     ceph health detail | grep -q "osd.1 is running an older version of ceph: 01.00.00-gversion-test" || return 1
 
     kill_daemons $dir KILL osd.2
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" activate_osd $dir 2
+    ceph_debug_version_for_testing=01.00.00-gversion-test activate_osd $dir 2
     kill_daemons $dir KILL osd.0
-    EXTRA_OPTS=" --debug_version_for_testing=02.00.00-gversion-test" activate_osd $dir 0
+    ceph_debug_version_for_testing=02.00.00-gversion-test activate_osd $dir 0
 
     wait_for_health_string "HEALTH_ERR .*There are daemons running multiple old versions of ceph" || return 1
 
@@ -135,12 +135,12 @@ function TEST_check_version_health_2() {
     ceph health detail | grep DAEMON_OLD_VERSION && return 1
 
     kill_daemons $dir KILL mon.b
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" run_mon $dir b --mon_warn_older_version_delay=0.0
+    ceph_debug_version_for_testing=01.00.00-gversion-test run_mon $dir b --mon_warn_older_version_delay=0.0
     # XXX: Manager doesn't seem to use the test specific config for version
     #kill_daemons $dir KILL mgr.x
-    #EXTRA_OPTS=" --debug_version_for_testing=02.00.00-gversion-test" run_mgr $dir x
+    #ceph_debug_version_for_testing=02.00.00-gversion-test run_mgr $dir x
     kill_daemons $dir KILL mds.m
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" run_mds $dir m
+    ceph_debug_version_for_testing=01.00.00-gversion-test run_mds $dir m
 
     wait_for_health_string "HEALTH_WARN .*There are daemons running an older version of ceph" || return 1
 
@@ -151,9 +151,9 @@ function TEST_check_version_health_2() {
     ceph health detail | grep -q "mon.b mds.m are running an older version of ceph: 01.00.00-gversion-test" || return 1
 
     kill_daemons $dir KILL osd.2
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" activate_osd $dir 2
+    ceph_debug_version_for_testing=01.00.00-gversion-test activate_osd $dir 2
     kill_daemons $dir KILL osd.0
-    EXTRA_OPTS=" --debug_version_for_testing=02.00.00-gversion-test" activate_osd $dir 0
+    ceph_debug_version_for_testing=02.00.00-gversion-test activate_osd $dir 0
 
     wait_for_health_string "HEALTH_ERR .*There are daemons running multiple old versions of ceph" || return 1
 
@@ -187,7 +187,7 @@ function TEST_check_version_health_3() {
     ceph health detail | grep DAEMON_OLD_VERSION && return 1
 
     kill_daemons $dir KILL osd.1
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" activate_osd $dir 1
+    ceph_debug_version_for_testing=01.00.00-gversion-test activate_osd $dir 1
 
     # Wait 50% of 20 second delay config
     sleep 10
@@ -204,9 +204,9 @@ function TEST_check_version_health_3() {
     ceph health detail | grep -q "osd.1 is running an older version of ceph: 01.00.00-gversion-test" || return 1
 
     kill_daemons $dir KILL osd.2
-    EXTRA_OPTS=" --debug_version_for_testing=01.00.00-gversion-test" activate_osd $dir 2
+    ceph_debug_version_for_testing=01.00.00-gversion-test activate_osd $dir 2
     kill_daemons $dir KILL osd.0
-    EXTRA_OPTS=" --debug_version_for_testing=02.00.00-gversion-test" activate_osd $dir 0
+    ceph_debug_version_for_testing=02.00.00-gversion-test activate_osd $dir 0
 
     wait_for_health_string "HEALTH_ERR .*There are daemons running multiple old versions of ceph" || return 1
 
index 95a1efc54e66ff2c8743b65f766fcbe6591b1908..01021d94193bf10034828f61a2196b2b61ad5fa8 100644 (file)
@@ -631,9 +631,7 @@ public:
     } else {
       f->open_object_section("version");
       if (command == "version") {
-#ifndef WITH_ALIEN
-       f->dump_string("version", ceph_version_to_str(nullptr));
-#endif
+       f->dump_string("version", ceph_version_to_str());
        f->dump_string("release", ceph_release_to_str());
        f->dump_string("release_type", ceph_release_type());
       } else if (command == "git_version") {
index 367e52ee0dba2e127731c9875fb6f9e6c6813c83..a85d0ffe21083dfff6a7ecb6a07231cb6cd56cf7 100644 (file)
@@ -8821,10 +8821,6 @@ std::vector<Option> get_mds_client_options() {
     .set_description("Size of thread pool for ASIO completions")
     .add_tag("client"),
 
-    Option("debug_version_for_testing", Option::TYPE_STR, Option::LEVEL_DEV)
-    .set_default("")
-    .set_description("Override ceph_version_short for testing"),
-
     Option("client_shutdown_timeout", Option::TYPE_SECS, Option::LEVEL_ADVANCED)
     .set_flag(Option::FLAG_RUNTIME)
     .set_default(30)
index 7e9ca49f0393be04bb5495028c1b99ba3122abe9..6cb1f02733cfce00efd21aca57624b26a91fa927 100644 (file)
@@ -229,7 +229,7 @@ void collect_sys_info(map<string, string> *m, CephContext *cct)
 {
   // version
   (*m)["ceph_version"] = pretty_version_to_str();
-  (*m)["ceph_version_short"] = ceph_version_to_str(cct);
+  (*m)["ceph_version_short"] = ceph_version_to_str();
   (*m)["ceph_release"] = ceph_release_to_str();
 
   #ifndef _WIN32
index 24d1c8a843eea145f1867bf177ca0cf2c9e151d2..96f17863e18f89bdf0c8dc697622b84fd0858226 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "common/version.h"
 
-#include <string.h>
+#include <stdlib.h>
 #include <sstream>
 
 #include "ceph_ver.h"
 #define _STR(x) #x
 #define STRINGIFY(x) _STR(x)
 
-// Keep ver.c_str() available
-static std::string ver;
-
-const char *ceph_version_to_str(CephContext *cct)
+const char *ceph_version_to_str()
 {
-  if (cct) ver = cct->_conf.get_val<std::string>("debug_version_for_testing");
-  if (ver.size() > 0)
-    return ver.c_str();
-  return CEPH_GIT_NICE_VER;
+  char* debug_version_for_testing = getenv("ceph_debug_version_for_testing");
+  if (debug_version_for_testing) {
+    return debug_version_for_testing;
+  } else {
+    return CEPH_GIT_NICE_VER;
+  }
 }
 
 const char *ceph_release_to_str(void)
index 067148a060df61d932b35a0a84fc3a18fcee05db..ffa6a17a5de861e990954d700728c048d44f773f 100644 (file)
 #define CEPH_COMMON_VERSION_H
 
 #include <string>
-#include "common/ceph_context.h"
 
 // Return a string describing the Ceph version
-const char *ceph_version_to_str(CephContext *cct);
+const char *ceph_version_to_str();
 
 // Return a string with the Ceph release
 const char *ceph_release_to_str(void);
index 75cb80a46609264a09f82e865a234e00bc9589e5..852185af18d9547851b74902d20065ae5546f3ba 100644 (file)
@@ -298,7 +298,7 @@ class VersionHook final : public AdminSocketHook {
   {
     unique_ptr<Formatter> f{Formatter::create(format, "json-pretty", "json-pretty")};
     f->open_object_section("version");
-    f->dump_string("version", ceph_version_to_str(nullptr));
+    f->dump_string("version", ceph_version_to_str());
     f->dump_string("release", ceph_release_to_str());
     f->dump_string("release_type", ceph_release_type());
     f->close_section();
index a9e9e28bf1451e230228b046e60a3834aec9dbb0..0447f96e1b18138ddc0122a8b9bae9310c88b141 100644 (file)
@@ -204,7 +204,7 @@ static void handle_fatal_signal(int signum)
        now.gmtime(jf.dump_stream("timestamp"));
        jf.dump_string("process_name", g_process_name);
        jf.dump_string("entity_name", g_ceph_context->_conf->name.to_str());
-       jf.dump_string("ceph_version", ceph_version_to_str(g_ceph_context));
+       jf.dump_string("ceph_version", ceph_version_to_str());
 
        struct utsname u;
        r = uname(&u);
index 7e280815a0694db0ba2baf7b5941636b9d54c63d..a17577ac7fc2f828a2717d9ffa376e2a790fe852 100644 (file)
@@ -362,7 +362,7 @@ extern "C" void ceph_userperm_destroy(UserPerm *perm)
 extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch)
 {
   int major, minor, patch;
-  const char *v = ceph_version_to_str(nullptr);
+  const char *v = ceph_version_to_str();
 
   int n = sscanf(v, "%d.%d.%d", &major, &minor, &patch);
   if (pmajor)
index 0898222ec6104bdd828a53c3e6e0ad041fc0162c..d28e21a746f759c8db6d375fe391bb165d8fd6ce 100644 (file)
@@ -3642,7 +3642,7 @@ void Monitor::handle_command(MonOpRequestRef op)
       f.reset(Formatter::create("json-pretty"));
     f->open_object_section("report");
     f->dump_stream("cluster_fingerprint") << fingerprint;
-    f->dump_string("version", ceph_version_to_str(cct));
+    f->dump_string("version", ceph_version_to_str());
     f->dump_string("commit", git_version_to_str());
     f->dump_stream("timestamp") << ceph_clock_now();
 
index d378992719c7bd8f8e4eec04c4cad8e1722a787b..e31713cd5079d519599124126c2d5bc6bc673fb1 100644 (file)
@@ -380,7 +380,7 @@ namespace immutable_obj_cache {
   int CacheClient::register_client(Context* on_finish) {
     ObjectCacheRequest* reg_req = new ObjectCacheRegData(RBDSC_REGISTER,
                                                          m_sequence_id++,
-                                                         ceph_version_to_str(m_cct));
+                                                         ceph_version_to_str());
     reg_req->encode();
 
     bufferlist bl;