Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip 13829 #7390

Merged
merged 2 commits into from Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions qa/workunits/cephtool/test.sh
Expand Up @@ -1647,6 +1647,12 @@ function test_osd_bench()
ceph tell osd.0 bench 104857600 2097152
}

function test_osd_negative_filestore_merge_threshold()
{
$SUDO ceph daemon osd.0 config set filestore_merge_threshold -1
expect_config_value "osd.0" "filestore_merge_threshold" -1
}

function test_mon_tell()
{
ceph tell mon.a version
Expand Down Expand Up @@ -1818,6 +1824,7 @@ MON_TESTS+=" mon_ping"
MON_TESTS+=" mon_deprecated_commands"
MON_TESTS+=" mon_caps"
OSD_TESTS+=" osd_bench"
OSD_TESTS+=" osd_negative_filestore_merge_threshold"
OSD_TESTS+=" tiering_agent"

MDS_TESTS+=" mds_tell"
Expand Down
50 changes: 28 additions & 22 deletions src/common/strtol.cc
Expand Up @@ -14,10 +14,10 @@

#include "strtol.h"

#include <errno.h>
#include <limits.h>
#include <cerrno>
#include <climits>
#include <cstdlib>
#include <sstream>
#include <stdlib.h>

using std::ostringstream;

Expand Down Expand Up @@ -129,14 +129,15 @@ float strict_strtof(const char *str, std::string *err)
return ret;
}

uint64_t strict_sistrtoll(const char *str, std::string *err)
template<typename T>
T strict_si_cast(const char *str, std::string *err)
{
std::string s(str);
if (s.empty()) {
*err = "strict_sistrtoll: value not specified";
return 0;
}
const char &u = s.at(s.size()-1); //str[std::strlen(str)-1];
const char &u = s.back();
int m = 0;
if (u == 'B')
m = 0;
Expand All @@ -155,30 +156,35 @@ uint64_t strict_sistrtoll(const char *str, std::string *err)
else
m = -1;

const char *v = NULL;
if (m >= 0)
s = std::string(str, s.size()-1);
v = s.c_str();

long long r_ll = strict_strtoll(v, 10, err);
s.pop_back();
else
m = 0;

if (r_ll < 0) {
long long ll = strict_strtoll(s.c_str(), 10, err);
if (ll < 0 && !std::numeric_limits<T>::is_signed) {
*err = "strict_sistrtoll: value should not be negative";
return 0;
}
if (ll < (long long)std::numeric_limits<T>::min() >> m) {
*err = "strict_sistrtoll: value seems to be too small";
return 0;
}
if (ll > std::numeric_limits<T>::max() >> m) {
*err = "strict_sistrtoll: value seems to be too large";
return 0;

uint64_t r = r_ll;
if (err->empty() && m > 0) {
if (r > (std::numeric_limits<uint64_t>::max() >> m)) {
*err = "strict_sistrtoll: value seems to be too large";
return 0;
}
r <<= m;
}
return r;
return (ll << m);
}

template <>
uint64_t strict_si_cast(const char *str, std::string *err) {
return strict_sistrtoll(str, err);
template int strict_si_cast<int>(const char *str, std::string *err);

template long long strict_si_cast<long long>(const char *str, std::string *err);

template uint64_t strict_si_cast<uint64_t>(const char *str, std::string *err);

uint64_t strict_sistrtoll(const char *str, std::string *err)
{
return strict_si_cast<uint64_t>(str, err);
}
18 changes: 2 additions & 16 deletions src/common/strtol.h
Expand Up @@ -31,21 +31,7 @@ float strict_strtof(const char *str, std::string *err);

uint64_t strict_sistrtoll(const char *str, std::string *err);

template <typename Target>
Target strict_si_cast(const char *str, std::string *err) {
uint64_t ret = strict_sistrtoll(str, err);
if (!err->empty())
return ret;
if (ret > (uint64_t)std::numeric_limits<Target>::max()) {
err->append("The option value '");
err->append(str);
err->append("' seems to be too large");
return 0;
}
return ret;
}

template <>
uint64_t strict_si_cast(const char *str, std::string *err);
template<typename T>
T strict_si_cast(const char *str, std::string *err);

#endif
8 changes: 0 additions & 8 deletions src/test/daemon_config.cc
Expand Up @@ -338,14 +338,6 @@ TEST(DaemonConfig, ThreadSafety1) {
}

TEST(DaemonConfig, InvalidIntegers) {
{
int ret = g_ceph_context->_conf->set_val("num_client", "-1");
ASSERT_EQ(ret, -EINVAL);
}
{
int ret = g_ceph_context->_conf->set_val("num_client", "-1K");
ASSERT_EQ(ret, -EINVAL);
}
{
long long bad_value = (long long)std::numeric_limits<int>::max() + 1;
string str = boost::lexical_cast<string>(bad_value);
Expand Down