Skip to content

Commit

Permalink
mon/OSDMonitor: disallow setting pg_num < min or > max
Browse files Browse the repository at this point in the history
Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
liewegas committed Jan 3, 2022
1 parent 73893f4 commit 2d8753f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions qa/workunits/mon/pool_ops.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ ceph osd pool set $TEST_POOL pg_num_min 2
ceph osd pool get $TEST_POOL pg_num_min | grep 2
ceph osd pool set $TEST_POOL pg_num_max 33
ceph osd pool get $TEST_POOL pg_num_max | grep 33
expect_false ceph osd pool set $TEST_POOL pg_num_min 9
expect_false ceph osd pool set $TEST_POOL pg_num_max 7
expect_false ceph osd pool set $TEST_POOL pg_num 1
expect_false ceph osd pool set $TEST_POOL pg_num 44
ceph osd pool set $TEST_POOL pg_num_min 0
expect_false ceph osd pool get $TEST_POOL pg_num_min
ceph osd pool set $TEST_POOL pg_num_max 0
Expand Down
13 changes: 13 additions & 0 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8353,6 +8353,19 @@ int OSDMonitor::prepare_command_pool_set(const cmdmap_t& cmdmap,
return -EPERM;
}
}
int64_t pg_min = 0, pg_max = 0;
p.opts.get(pool_opts_t::PG_NUM_MIN, &pg_min);
p.opts.get(pool_opts_t::PG_NUM_MAX, &pg_max);
if (pg_min && n < pg_min) {
ss << "specified pg_num " << n
<< " < pg_num_min " << pg_min;
return -EINVAL;
}
if (pg_max && n > pg_max) {
ss << "specified pg_num " << n
<< " < pg_num_max " << pg_max;
return -EINVAL;
}
if (osdmap.require_osd_release < ceph_release_t::nautilus) {
// pre-nautilus osdmap format; increase pg_num directly
assert(n > (int)p.get_pg_num());
Expand Down

0 comments on commit 2d8753f

Please sign in to comment.