diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2012-12-13 23:34:23 +0000 |
---|---|---|
committer | Greg Farnum <greg@inktank.com> | 2012-12-13 15:38:55 -0800 |
commit | e3ed28eb2d33cf8c5bc8a36af919e6a8e566ad6b (patch) | |
tree | 310b2c431f17b39f15ccb4f408a07236dfa976d2 | |
parent | 8103414a45a02275b61e9bee93a60db0619f7a1c (diff) | |
download | ceph-e3ed28eb2d33cf8c5bc8a36af919e6a8e566ad6b.tar.gz |
mon: OSDMonitor: don't allow creation of pools with > 65535 pgs
There are some limitations to the number of possible pg's per pool, and
by allowing the 'osd pool create' command to succeed, we were making room
to some anomalous behavior.
Fixes: #3617
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
Reviewed-by: Greg Farnum <greg@inktank.com>
-rw-r--r-- | src/mon/OSDMonitor.cc | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 476e5138b30..e893655dab6 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -2623,22 +2623,34 @@ bool OSDMonitor::prepare_command(MMonCommand *m) } int pg_num = 0; int pgp_num = 0; - const char *start = m->cmd[4].c_str(); - char *end = (char*)start; - pgp_num = pg_num = strtol(start, &end, 10); - if (*end != '\0') { // failed to parse + + /* Don't allow over 65535 pgs in a single pool */ + pg_num = parse_pos_long(m->cmd[4].c_str(), &ss); + if ((pg_num == 0) || (pg_num > 65535)) { + ss << "'pg_num' must be greater than 0 and lower or equal than 65535"; + err = -ERANGE; + goto out; + } + + if (pg_num < 0) { err = -EINVAL; - ss << "usage: osd pool create <poolname> <pg_num> [pgp_num]"; goto out; - } else if (m->cmd.size() > 5) { // check for pgp_num too - start = m->cmd[5].c_str(); - end = (char *)start; - pgp_num = strtol(start, &end, 10); - if (*end != '\0') { // failed to parse - err = -EINVAL; - ss << "usage: osd pool create <poolname> <pg_num> [pgp_num]"; - goto out; - } + } + + pgp_num = pg_num; + if (m->cmd.size() > 5) { + pgp_num = parse_pos_long(m->cmd[5].c_str(), &ss); + if (pgp_num < 0) { + err = -EINVAL; + goto out; + } + + if ((pgp_num == 0) || (pgp_num > pg_num)) { + ss << "'pgp_num' must be greater than 0 and lower or equal than 'pg_num'" + << ", which in this case is " << pg_num; + err = -ERANGE; + goto out; + } } if (osdmap.name_pool.count(m->cmd[3])) { |