]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools: avoid max() calls on rbd config options
authorJohn Spray <john.spray@redhat.com>
Wed, 12 Jul 2017 23:54:59 +0000 (19:54 -0400)
committerJohn Spray <john.spray@redhat.com>
Fri, 21 Jul 2017 10:27:28 +0000 (06:27 -0400)
These were awkward for typing of the '1' literal vs.
the int64_t settings.  The whole max() thing is also
unnecessary now, if we set proper bounds on the option
definitions.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/options.cc
src/common/options.h
src/tools/rbd/action/Export.cc
src/tools/rbd/action/Import.cc
src/tools/rbd_mirror/InstanceReplayer.cc
src/tools/rbd_mirror/Instances.cc
src/tools/rbd_mirror/LeaderWatcher.cc

index a930f362cd3ef016eb2b25e1ccc073068dc3da13..e5540b6717a391ec59c5bcc29bbaaef310bc8359 100644 (file)
@@ -4345,6 +4345,7 @@ const std::vector<Option> ceph_options = {
 
   Option("rbd_concurrent_management_ops", Option::TYPE_INT, Option::LEVEL_ADVANCED)
   .set_default(10)
+  .set_min(1)
   .set_description(""),
 
   Option("rbd_balance_snap_reads", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
@@ -4513,10 +4514,12 @@ const std::vector<Option> ceph_options = {
 
   Option("rbd_mirror_image_state_check_interval", Option::TYPE_INT, Option::LEVEL_ADVANCED)
   .set_default(30)
+  .set_min(1)
   .set_description(""),
 
   Option("rbd_mirror_leader_heartbeat_interval", Option::TYPE_INT, Option::LEVEL_ADVANCED)
   .set_default(5)
+  .set_min(1)
   .set_description(""),
 
   Option("rbd_mirror_leader_max_missed_heartbeats", Option::TYPE_INT, Option::LEVEL_ADVANCED)
index b3f9b331218fc5563492e45f4bac957246133115..99240d411b29cf4d30f10950b90b271351a736eb 100644 (file)
@@ -205,10 +205,17 @@ struct Option {
     desc = new_desc;
     return *this;
   }
+
+  template<typename T>
+  Option& set_min(const T& mi) {
+    set_value(min, mi);
+    return *this;
+  }
+
   template<typename T>
   Option& set_min_max(const T& mi, const T& ma) {
-    min = mi;
-    max = ma;
+    set_value(min, mi);
+    set_value(max, ma);
     return *this;
   }
 
index 1be951028b4aa7c37440018a9ee8e579f04ff228..708663a43104f3cc0cb3c9fdf2a4936449e8b0cd 100644 (file)
@@ -509,7 +509,7 @@ static int do_export(librbd::Image& image, const char *path, bool no_progress, i
     fd = STDOUT_FILENO;
     max_concurrent_ops = 1;
   } else {
-    max_concurrent_ops = max(g_conf->rbd_concurrent_management_ops, 1);
+    max_concurrent_ops = g_conf->rbd_concurrent_management_ops;
     fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
     if (fd < 0) {
       return -errno;
index 5bea7805da7382da7ba3cfeb062d4f00467a8f0e..0f31d810394bee1a8071142ca62605657265d63d 100644 (file)
@@ -37,7 +37,7 @@ struct ImportDiffContext {
   ImportDiffContext(librbd::Image *image, int fd, size_t size, bool no_progress)
     : image(image), fd(fd), size(size), pc("Importing image diff", no_progress),
       throttle((fd == STDIN_FILENO) ? 1 :
-               max(g_conf->rbd_concurrent_management_ops, 1), false), last_offset(0) {
+               g_conf->rbd_concurrent_management_ops, false), last_offset(0) {
   }
 
   void update_size(size_t new_size)
@@ -653,7 +653,7 @@ static int do_import_v1(int fd, librbd::Image &image, uint64_t size,
     throttle.reset(new SimpleThrottle(1, false));
   } else {
     throttle.reset(new SimpleThrottle(
-                     max(g_conf->rbd_concurrent_management_ops, 1), false));
+                     g_conf->rbd_concurrent_management_ops, false));
   }
 
   reqlen = min<uint64_t>(reqlen, size);
index 2b732617d8ae31f8f049acf7f538b459a4022ca3..5c2fa13a7ab60ad408c28ba6f93a7eba8325b036 100644 (file)
@@ -486,8 +486,7 @@ void InstanceReplayer<I>::schedule_image_state_check_task() {
       start_image_replayers();
     });
 
-  int after =
-    max(1, g_ceph_context->_conf->rbd_mirror_image_state_check_interval);
+  int after = g_ceph_context->_conf->rbd_mirror_image_state_check_interval;
 
   dout(20) << "scheduling image state check after " << after << " sec (task "
            << m_image_state_check_task << ")" << dendl;
index 0adc4f3428e7d3b6a0269263aca89e2527afaf92..302700e51bb618d850553f382489b713acc1d419 100644 (file)
@@ -228,7 +228,7 @@ void Instances<I>::schedule_remove_task(Instance &instance) {
 
   cancel_remove_task(instance);
 
-  int after = max(1, m_cct->_conf->rbd_mirror_leader_heartbeat_interval) *
+  int after = m_cct->_conf->rbd_mirror_leader_heartbeat_interval *
     (1 + m_cct->_conf->rbd_mirror_leader_max_missed_heartbeats +
      m_cct->_conf->rbd_mirror_leader_max_acquire_attempts_before_break);
 
index ca0783679baeed18331f7a0b48d2947e53db95c5..9e99d6b6f6e8beb96c2b1b68f2fef9c83716c874 100644 (file)
@@ -370,8 +370,7 @@ void LeaderWatcher<I>::schedule_timer_task(const std::string &name,
       m_timer_gate->timer_callback = timer_callback;
     });
 
-  int after = delay_factor *
-    max(1, m_cct->_conf->rbd_mirror_leader_heartbeat_interval);
+  int after = delay_factor * m_cct->_conf->rbd_mirror_leader_heartbeat_interval;
 
   dout(20) << "scheduling " << name << " after " << after << " sec (task "
            << m_timer_task << ")" << dendl;