Compare commits

..

1 Commits

Author SHA1 Message Date
e5d4822325 Refuse an invalid --resize value in vitastor-cli modify
parse_size() returns 0 for a value it cannot parse, such as 1.5G, and
modify took 0 as "no resize": it printed "No change" and exited with 0.
Check the parse result and fail with EINVAL, as create does for --size.
Numeric sizes passed by internal callers (NFS, dd) parse as before.
2026-10-25 16:10:29 +03:00
5 changed files with 45 additions and 52 deletions

View File

@@ -287,7 +287,20 @@ 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();
changer->new_size = parse_size(cfg["resize"].as_string());
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->force_size = cfg["force_size"].bool_value();
changer->inc_size = cfg["inc_size"].bool_value();
changer->force = cfg["force"].bool_value();

View File

@@ -251,7 +251,7 @@ resume_1:
{ "title", "MISPLACED" },
});
cols.push_back(json11::Json::object{
{ "key", "fmt_degraded" },
{ "key", "fmt_misplaced" },
{ "title", "DEGRADED" },
});
cols.push_back(json11::Json::object{
@@ -273,8 +273,6 @@ resume_1:
load_pg_stats();
if (parent->waiting > 0)
return;
if (state == 100)
return;
format_pgs();
state = 100;
}

View File

@@ -61,10 +61,11 @@ OLD=1 SCHEME=ec ./test_snapshot.sh
OLD=1 ./test_move_reappear.sh
./test_degraded.sh
./test_pg_ls.sh
./test_rm.sh
./test_modify_image_resize.sh
./test_rm_degraded.sh
./test_snapshot_chain.sh

View File

@@ -0,0 +1,28 @@
#!/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

@@ -1,47 +0,0 @@
#!/bin/bash -ex
# Test vitastor-cli ls-pgs on degraded PGs
PG_COUNT=4
PG_SIZE=3
PG_MINSIZE=2
# Keep degraded objects until the checks are done
GLOBAL_CONFIG=',"no_recovery":true'
. `dirname $0`/run_3osds.sh
$VITASTOR_CLI create -s 32M testimg
# Data written while OSD 3 is down is degraded when it comes back
kill -9 $OSD3_PID
$ETCDCTL del /vitastor/osd/state/3
wait_condition 60 "$ETCDCTL get --prefix /vitastor/pg/state/ --print-value-only | jq -s -e '[ .[] | select(.state | index(\"degraded\")) ] | length == $PG_COUNT'" "PG peering without OSD 3"
$VITASTOR_CLI dd if=/dev/urandom oimg=testimg bs=1M count=32
start_osd 3
wait_condition 60 "$ETCDCTL get --prefix /vitastor/pgstats/ --print-value-only | jq -s -e '[ .[] | select(.degraded_count > 0) ] | length == $PG_COUNT'" "PG degradation"
$VITASTOR_CLI ls-pgs
# NUM and DEGRADED of every PG from the table, and degraded_count from JSON
$VITASTOR_CLI ls-pgs | awk 'NR == 1 { n = index($0, "NUM"); d = index($0, "DEGRADED"); e = index($0, "INCOMPLETE") }
NR > 1 { num = substr($0, n); sub(/ .*/, "", num); deg = substr($0, d, e-d); sub(/ +$/, "", deg); print num " " deg }' > ./testdata/pg_ls.txt
$VITASTOR_CLI ls-pgs --json | jq -r '.[] | "\(.pg_num) \(.degraded_count // 0)"' > ./testdata/pg_ls_json.txt
if [[ $(wc -l < ./testdata/pg_ls.txt) != $PG_COUNT ]]; then
format_error "ls-pgs should list $PG_COUNT PGs"
fi
while read num count; do
shown=$(awk '$1 == '$num' { $1 = ""; sub(/^ /, ""); print }' ./testdata/pg_ls.txt)
if [[ -z "$shown" || $count -gt 0 && "$shown" = "0 B" || $count -eq 0 && "$shown" != "0 B" ]]; then
format_error "ls-pgs shows DEGRADED=$shown for PG $num with $count degraded objects"
fi
done < ./testdata/pg_ls_json.txt
# An unknown pool is an error, not an empty table
if out=$($VITASTOR_CLI ls-pgs --pool nosuchpool 2>&1); then
format_error "ls-pgs should fail for an unknown pool"
fi
if [[ "$out" != "Pool nosuchpool not found" ]]; then
format_error "ls-pgs prints '$out' instead of the unknown pool error"
fi
format_green OK