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
3 changed files with 44 additions and 1 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

@@ -64,6 +64,8 @@ OLD=1 ./test_move_reappear.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