Compare commits

..

1 Commits

Author SHA1 Message Date
b5e5b6af01 Limit pg_size to 64 in vitastor-cli create-pool and modify-pool
The CLI accepted pg_size up to 256, but clients and OSDs skip a pool
with pg_size > 64 and the monitor refuses it, so such a pool was
created or switched to a size nobody could serve, without an error.
Refuse pg_size > 64 with EINVAL, also with --force.
2026-10-25 16:10:29 +03:00
8 changed files with 39 additions and 52 deletions

View File

@@ -410,8 +410,8 @@ Create a pool. Required parameters:
| <!-- --> | <!-- --> |
|--------------------------|-----------------------------------------------------------------------------------------|
| `-s R` or `--pg_size R` | Number of replicas for replicated pools |
| `--ec N+K` | Number of data (N) and parity (K) chunks for erasure-coded pools |
| `-s R` or `--pg_size R` | Number of replicas for replicated pools, from 1 to 64 |
| `--ec N+K` | Number of data (N) and parity (K) chunks for erasure-coded pools, N+K from 3 to 64 |
| `-n N` or `--pg_count N` | PG count for the new pool (start with 10*\<OSD count\>/pg_size rounded to a power of 2) |
Optional parameters:

View File

@@ -429,8 +429,8 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
| <!-- --> | <!-- --> |
|---------------------------|-----------------------------------------------------------------------------------------------|
| `-s R` или `--pg_size R` | Число копий данных для реплицированных пулов |
| `--ec N+K` | Число частей данных (N) и чётности (K) для пулов с кодами коррекции ошибок |
| `-s R` или `--pg_size R` | Число копий данных для реплицированных пулов, от 1 до 64 |
| `--ec N+K` | Число частей данных (N) и чётности (K) для пулов с кодами коррекции ошибок, N+K от 3 до 64 |
| `-n N` или `--pg_count N` | Число PG для нового пула (начните с 10*\<число OSD\>/pg_size, округлённого до степени двойки) |
Необязательные параметры:

View File

@@ -197,8 +197,8 @@ static const char* help_text =
"\n"
"vitastor-cli create-pool|pool-create <name> (-s <pg_size>|--ec <N>+<K>) -n <pg_count> [OPTIONS]\n"
" Create a pool. Required parameters:\n"
" -s|--pg_size R Number of replicas for replicated pools\n"
" --ec N+K Number of data (N) and parity (K) chunks for erasure-coded pools\n"
" -s|--pg_size R Number of replicas for replicated pools, from 1 to 64\n"
" --ec N+K Number of data (N) and parity (K) chunks for erasure-coded pools, N+K from 3 to 64\n"
" -n|--pg_count N PG count for the new pool (start with 10*<OSD count>/pg_size rounded to a power of 2)\n"
" Optional parameters:\n"
" --pg_minsize <number> R or N+K minus number of failures to tolerate without downtime\n"

View File

@@ -287,20 +287,7 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_modify(json11::Json cfg)
changer->parent = this;
changer->image_name = cfg["image"].string_value();
changer->new_name = cfg["rename"].string_value();
if (!cfg["resize"].is_null())
{
bool ok = false;
changer->new_size = parse_size(cfg["resize"].as_string(), &ok);
if (!ok)
{
delete changer;
return [size = cfg["resize"].as_string()](cli_result_t & result)
{
result = (cli_result_t){ .err = EINVAL, .text = "Invalid syntax for size: "+size };
return true;
};
}
}
changer->new_size = parse_size(cfg["resize"].as_string());
changer->force_size = cfg["force_size"].bool_value();
changer->inc_size = cfg["inc_size"].bool_value();
changer->force = cfg["force"].bool_value();

View File

@@ -233,9 +233,10 @@ std::string validate_pool_config(json11::Json::object & new_cfg, json11::Json ol
{
return "PG size can't be smaller than 3 for EC/XOR pools";
}
if (pg_size > 256)
// same limit as in etcd_state_client.cpp and mon/pool_config.js
if (pg_size > 64)
{
return "PG size can't be greater than 256";
return "PG size can't be greater than 64";
}
// PG rules

View File

@@ -48,6 +48,8 @@ OLD=1 SCHEME=ec IMMEDIATE_COMMIT=1 ./test_interrupted_rebalance.sh
./test_failure_domain.sh
./test_pool_pg_size_limit.sh
./test_level_placement.sh
./test_snapshot.sh
@@ -64,8 +66,6 @@ OLD=1 ./test_move_reappear.sh
./test_rm.sh
./test_modify_image_resize.sh
./test_rm_degraded.sh
./test_snapshot_chain.sh

View File

@@ -1,28 +0,0 @@
#!/bin/bash -ex
# Test that modify refuses an invalid --resize value instead of ignoring it
. `dirname $0`/common.sh
wait_etcd
$ETCDCTL put /vitastor/config/pools '{"1":{"name":"testpool","scheme":"replicated","pg_size":2,"pg_minsize":1,"pg_count":1,"failure_domain":"osd"}}'
$VITASTOR_CLI create -s 1G --pool testpool testimg
for size in 1.5G 10X abc ''; do
r=0
$VITASTOR_CLI modify testimg --resize "$size" || r=$?
if [[ $r != 22 ]]; then
format_error "modify --resize '$size' should fail with EINVAL (22), but exited with $r"
fi
done
$ETCDCTL get --print-value-only /vitastor/config/inode/1/1 | jq -e '.size == 1073741824' || \
format_error "Image size should stay 1G after refused resizes"
$VITASTOR_CLI modify testimg --resize 2G
$ETCDCTL get --print-value-only /vitastor/config/inode/1/1 | jq -e '.size == 2147483648' || \
format_error "Image size should be 2G after --resize 2G"
format_green OK

View File

@@ -0,0 +1,27 @@
#!/bin/bash -ex
# Test that create-pool and modify-pool refuse pg_size > 64, which OSDs and clients don't support
. `dirname $0`/common.sh
wait_etcd
$ETCDCTL put /vitastor/config/pools '{"1":{"name":"testpool","scheme":"replicated","pg_size":2,"pg_minsize":1,"pg_count":1,"failure_domain":"osd"}}'
for args in "create-pool bigpool -s 65 -n 1 --force" "create-pool bigpool --ec 62+3 -n 1 --force" "modify-pool testpool -s 65"; do
r=0
$VITASTOR_CLI $args || r=$?
if [[ $r != 22 ]]; then
format_error "$args should fail with EINVAL (22), but exited with $r"
fi
done
$ETCDCTL get --print-value-only /vitastor/config/pools | jq -e 'keys == ["1"] and .["1"].pg_size == 2' || \
format_error "Pool configuration should not change after refused commands"
# 64 is still accepted
$VITASTOR_CLI modify-pool testpool -s 64
$ETCDCTL get --print-value-only /vitastor/config/pools | jq -e '.["1"].pg_size == 64' || \
format_error "modify-pool -s 64 should set pg_size to 64"
format_green OK