From c48bf317db968c8d18c91cbeb49591311002b61e Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 22 Oct 2026 14:04:42 +0300 Subject: [PATCH 1/2] Fix --osd-binary option of vitastor-disk exec-osd Command-line options are stored with dashes replaced by underscores, so options["osd-binary"] was never set and exec-osd always ran vitastor-osd. --- .gitea/workflows/test.yml | 18 ++++++++++++++++++ src/disk_tool/disk_tool_udev.cpp | 4 ++-- tests/run_tests.sh | 2 ++ tests/test_disk_exec_osd.sh | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100755 tests/test_disk_exec_osd.sh diff --git a/.gitea/workflows/test.yml b/.gitea/workflows/test.yml index 6c72c970..119ad069 100644 --- a/.gitea/workflows/test.yml +++ b/.gitea/workflows/test.yml @@ -1265,6 +1265,24 @@ jobs: echo "" done + test_disk_exec_osd: + runs-on: ubuntu-latest + needs: build + container: ${{env.TEST_IMAGE}}:${{github.sha}} + steps: + - name: Run test + id: test + timeout-minutes: 3 + run: /root/vitastor/tests/test_disk_exec_osd.sh + - name: Print logs + if: always() && steps.test.outcome == 'failure' + run: | + for i in /root/vitastor/testdata/*.log /root/vitastor/testdata/*.txt; do + echo "-------- $i --------" + cat $i + echo "" + done + test_root_node: runs-on: ubuntu-latest needs: build diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index c9d3a13c..866a4585 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -313,9 +313,9 @@ int disk_tool_t::exec_osd(std::string device) return 1; } std::string osd_binary = "vitastor-osd"; - if (options["osd-binary"] != "") + if (options["osd_binary"] != "") { - osd_binary = options["osd-binary"]; + osd_binary = options["osd_binary"]; } std::vector argstr; argstr.push_back(osd_binary.c_str()); diff --git a/tests/run_tests.sh b/tests/run_tests.sh index c29ef29b..24bf22b8 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -102,6 +102,8 @@ OLD=1 SCHEME=ec IMMEDIATE_COMMIT=1 ./test_rebalance_verify.sh ./test_cli_help.sh +./test_disk_exec_osd.sh + ./test_root_node.sh ./test_switch_primary.sh diff --git a/tests/test_disk_exec_osd.sh b/tests/test_disk_exec_osd.sh new file mode 100755 index 00000000..3bfa4e53 --- /dev/null +++ b/tests/test_disk_exec_osd.sh @@ -0,0 +1,17 @@ +#!/bin/bash -ex + +# vitastor-disk exec-osd must start the binary given with --osd-binary + +. `dirname $0`/common.sh + +[[ -e build/src/disk_tool/vitastor-disk-test ]] || ln -s vitastor-disk build/src/disk_tool/vitastor-disk-test + +dd if=/dev/zero of=./testdata/bin/sb.bin bs=4096 count=8 +echo '{"osd_num":1,"data_device":"'`realpath ./testdata/bin/sb.bin`'"}' | \ + build/src/disk_tool/vitastor-disk-test write-sb --io cached ./testdata/bin/sb.bin + +ARGS=`build/src/disk_tool/vitastor-disk exec-osd --io cached --osd-binary echo ./testdata/bin/sb.bin` || \ + format_error "exec-osd did not run the --osd-binary" +[[ "$ARGS" == "--data_device "*" --osd_num 1" ]] || format_error "exec-osd passed unexpected arguments: $ARGS" + +format_green OK -- 2.47.3 From 66da39caca2533b005407c238dd66efadf692801 Mon Sep 17 00:00:00 2001 From: Yury Luneff Date: Thu, 22 Oct 2026 14:07:21 +0300 Subject: [PATCH 2/2] Pass the checked device nodes to the OSD in vitastor-disk exec-osd exec-osd validated the superblock through the given device but forwarded the by-partuuid paths from it, and vitastor-osd opened whatever those links pointed to by then. With dm-multipath the link moves from the path partition to the dm partition in between, so the OSD opened a node other than the one checked. Forward the real_*_device nodes resolved by read_osd_superblock instead. --- src/disk_tool/disk_tool_udev.cpp | 16 +++++++++++++++- tests/test_disk_exec_osd.sh | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/disk_tool/disk_tool_udev.cpp b/src/disk_tool/disk_tool_udev.cpp index 866a4585..78bb3e06 100644 --- a/src/disk_tool/disk_tool_udev.cpp +++ b/src/disk_tool/disk_tool_udev.cpp @@ -317,12 +317,26 @@ int disk_tool_t::exec_osd(std::string device) { osd_binary = options["osd_binary"]; } + // Pass the nodes checked above, not the by-partuuid links: a link can move to another node meanwhile + std::string real_data = sb["real_data_device"].string_value(); + std::string real_meta = sb["real_meta_device"].string_value() != "" ? sb["real_meta_device"].string_value() : real_data; + std::map real_devices = { + { "data_device", real_data }, + { "meta_device", real_meta }, + { "journal_device", sb["real_journal_device"].string_value() != "" ? sb["real_journal_device"].string_value() : real_meta }, + }; std::vector argstr; argstr.push_back(osd_binary.c_str()); for (auto & kv: sb["params"].object_items()) { + std::string value = kv.second.is_string() ? kv.second.string_value() : kv.second.dump(); + auto real_it = real_devices.find(kv.first); + if (real_it != real_devices.end() && value != "") + { + value = real_it->second; + } argstr.push_back("--"+kv.first); - argstr.push_back(kv.second.is_string() ? kv.second.string_value() : kv.second.dump()); + argstr.push_back(value); } char *argv[argstr.size()+1]; for (int i = 0; i < argstr.size(); i++) diff --git a/tests/test_disk_exec_osd.sh b/tests/test_disk_exec_osd.sh index 3bfa4e53..3046ab8b 100755 --- a/tests/test_disk_exec_osd.sh +++ b/tests/test_disk_exec_osd.sh @@ -14,4 +14,12 @@ ARGS=`build/src/disk_tool/vitastor-disk exec-osd --io cached --osd-binary echo . format_error "exec-osd did not run the --osd-binary" [[ "$ARGS" == "--data_device "*" --osd_num 1" ]] || format_error "exec-osd passed unexpected arguments: $ARGS" +# exec-osd must pass the device it checked, not the superblock's link: the link can move meanwhile +ln -s `realpath ./testdata/bin/sb.bin` ./testdata/bin/sb-link +echo '{"osd_num":1,"data_device":"'`realpath ./testdata/bin`/sb-link'"}' | \ + build/src/disk_tool/vitastor-disk-test write-sb --io cached ./testdata/bin/sb.bin +ARGS=`build/src/disk_tool/vitastor-disk exec-osd --io cached --osd-binary echo ./testdata/bin/sb.bin` +[[ "$ARGS" == "--data_device `realpath ./testdata/bin/sb.bin` --osd_num 1" ]] || \ + format_error "exec-osd passed the superblock's link instead of the checked device: $ARGS" + format_green OK -- 2.47.3