]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
common/options: convert a millisecs opt to a chrono::milliseconds when paring it
authorKefu Chai <kchai@redhat.com>
Sun, 27 Jun 2021 01:32:10 +0000 (09:32 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 27 Jun 2021 04:25:01 +0000 (12:25 +0800)
commit71f028effc857c9adc25630a5fa8b6fa07e98211
tree466efcf2d67e363aba86c6356f36aa025e3ae093
parent4537b14b34b9747deee85b9c9752634f7a858ce9
common/options: convert a millisecs opt to a chrono::milliseconds when paring it

Option always parses a new string value and convert it to a value_t
before validating it. and value_t is an alias of boost::variant<...>.
and we use "new_value < min" to tell if the new_value is out of the
bound or not, where both "new_value" and "min" are instances of
value_t. so it is critcal that these two values contain the same type
of value, otherwise boost::variant::operator< would

> Returns:
> If which() == rhs.which() then: content_this < content_rhs, where content_this is the content of *this and content_rhs is the content of rhs. Otherwise: which() < rhs.which().

where which() indicates which type of value is contained in the value_t.

before this change, instead of converting a new value of milliseconds to
std::chrono::milliseconds, we convert it to an uint64_t, whose index in
the value_t is 2, while the milliseconds value's index is 9, so
"new_value < min" evaluates to true even if "new_value" is 100 and "min"
is 30.

after this change, the new value of a milliseconds option is converted
to std::chrono::milliseconds, so it is comparable with its min value and
max value.

a minimal test is added to reproduce this issue.

the change which added the support of millisec to option was
29690a338ba4482d187e6036903e138437ae3bb4 which is not included by any
LTS branches, so no need to backport this fix.

Fixes: https://tracker.ceph.com/issues/51375
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/options.cc
src/test/common/CMakeLists.txt
src/test/common/test_option.cc [new file with mode: 0644]