Compare commits

..

1 Commits

Author SHA1 Message Date
abd4410a5c Correct vitastor-cli help for rm, raw-ls, fix and rm-osd
- rm: the --exact and --matching descriptions were swapped.
- raw-ls: show that --pool_id is required, and --pg_num unless --offset
  is given, and when the pool configuration fills in the rest.
- fix: show --bad-osds as required.
- rm-osd: describe -f, --allow-up and --allow-data-loss. Up OSDs are
  refused too, -f covers them and degraded/offline PGs, and
  --allow-data-loss covers incomplete ones and implies -f.

Apply the same corrections to the CLI documentation.
2026-10-25 16:10:29 +03:00
36 changed files with 94 additions and 805 deletions

View File

@@ -221,24 +221,6 @@ jobs:
echo ""
done
test_modify_pool:
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_modify_pool.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_etcd_fail:
runs-on: ubuntu-latest
needs: build
@@ -797,24 +779,6 @@ jobs:
echo ""
done
test_modify_image_resize:
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_modify_image_resize.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_rm_degraded:
runs-on: ubuntu-latest
needs: build
@@ -833,24 +797,6 @@ jobs:
echo ""
done
test_describe:
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_describe.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_snapshot_chain:
runs-on: ubuntu-latest
needs: build
@@ -1247,42 +1193,6 @@ jobs:
echo ""
done
test_cli_help:
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_cli_help.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_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
@@ -1661,24 +1571,6 @@ jobs:
echo ""
done
test_ls_tree:
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_ls_tree.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_snapshot_read_bitmap:
runs-on: ubuntu-latest
needs: build

View File

@@ -358,7 +358,7 @@ host stump
## ls-osd
`vitastor-cli osds|ls-osds|ls-osd|osd-ls [-l|--long]`
`vitastor-cli osds|ls-osd|osd-ls [-l|--long]`
Show current OSDs as list, optionally with I/O statistics if -l is specified.
@@ -413,8 +413,8 @@ Create a pool. Required parameters:
| <!-- --> | <!-- --> |
|--------------------------|-----------------------------------------------------------------------------------------|
| `-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 |
| `-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 |
| `-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:
@@ -428,7 +428,7 @@ Optional parameters:
| `--block_size 128k` | Put pool only on OSDs with this data block size |
| `--bitmap_granularity 4k` | Put pool only on OSDs with this logical sector size |
| `--immediate_commit none` | Put pool only on OSDs with this or larger immediate_commit (none < small < all) |
| `--level_placement <rules>` | Use additional failure domain rules (example: "dc=112233", "" to remove) |
| `--level_placement <rules>` | Use additional failure domain rules (example: "dc=112233") |
| `--raw_placement <rules>` | Specify raw PG generation rules ([details](../config/pool.en.md#raw_placement)) |
| `--local_reads primary` | Local read policy for replicated pools: primary, nearest or random |
| `--primary_affinity_tags tags` | Prefer to put primary copies on OSDs with all specified tags |
@@ -473,8 +473,6 @@ These, however, can still be modified with -f|--force.
See [create-pool](#create-pool) for parameter descriptions.
Renaming with --name fails if the new name is already taken by a different pool.
Examples:
`vitastor-cli modify-pool pool_A --name pool_B`
@@ -513,7 +511,7 @@ the Vitastor authorization model.
## modify-user
`vitastor-cli modify-user|user-modify --groups <group1,group2,...> <username>`
`vitastor-cli modify-user --groups <group1,group2,...> <username>`
Create or update a user with the given name (matching TLS certificate CN).

View File

@@ -378,7 +378,7 @@ host stump
## ls-osd
`vitastor-cli osds|ls-osds|ls-osd|osd-ls [-l|--long]`
`vitastor-cli osds|ls-osd|osd-ls [-l|--long]`
Показать список OSD, со статистикой ввода-вывода, если установлено -l.
@@ -408,7 +408,7 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
## pg-list
`vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs|pgs [OPTIONS] [state1+state2] [^state3] [...]`
`vitastor-cli pg-list|pg-ls|list-pg|ls-pg|ls-pgs [OPTIONS] [state1+state2] [^state3] [...]`
Вывести список PG с состояними, удовлетворяющими любому из переданных фильтров (^ или !
в начале фильтра означает отрицание). Опции:
@@ -434,8 +434,8 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
| <!-- --> | <!-- --> |
|---------------------------|-----------------------------------------------------------------------------------------------|
| `-s R` или `--pg_size R` | Число копий данных для реплицированных пулов, от 1 до 64 |
| `--ec N+K` | Число частей данных (N) и чётности (K) для пулов с кодами коррекции ошибок, N+K от 3 до 64 |
| `-s R` или `--pg_size R` | Число копий данных для реплицированных пулов |
| `--ec N+K` | Число частей данных (N) и чётности (K) для пулов с кодами коррекции ошибок |
| `-n N` или `--pg_count N` | Число PG для нового пула (начните с 10*\<число OSD\>/pg_size, округлённого до степени двойки) |
Необязательные параметры:
@@ -449,7 +449,7 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
| `--block_size 128k` | ...только OSD с данным размером блока |
| `--bitmap_granularity 4k` | ...только OSD с данным размером логического сектора |
| `--immediate_commit none` | ...только OSD с этим или большим immediate_commit (none < small < all) |
| `--level_placement <rules>` | Задать правила дополнительных доменов отказа (пример: "dc=112233", "" — удалить) |
| `--level_placement <rules>` | Задать правила дополнительных доменов отказа (пример: "dc=112233") |
| `--raw_placement <rules>` | Задать низкоуровневые правила генерации PG ([детали](../config/pool.ru.md#raw_placement)) |
| `--local_reads primary` | Политика локальных чтений для реплик: primary, nearest или random |
| `--primary_affinity_tags tags` | Предпочитать OSD со всеми данными тегами для роли первичных |
@@ -492,8 +492,6 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
Описания параметров смотрите в [create-pool](#create-pool).
Переименование с --name запрещается, если новое название уже занято другим пулом.
Примеры:
`vitastor-cli modify-pool pool_A --name pool_B`
@@ -534,7 +532,7 @@ OSD PARENT UP SIZE USED% TAGS WEIGHT BLOCK BITMAP
## modify-user
`vitastor-cli modify-user|user-modify --groups <group1,group2,...> <username>`
`vitastor-cli modify-user --groups <group1,group2,...> <username>`
Создать или изменить пользователя с указанным именем (совпадающим с CN TLS-сертификата).

View File

@@ -21,11 +21,8 @@ if("${CMAKE_INSTALL_PREFIX}" MATCHES "^/usr/local/?$")
endif()
set(ENABLE_COVERAGE false CACHE BOOL "Enable code coverage")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-DVITASTOR_VERSION="3.2.2")
add_definitions(-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wno-c99-designator -Wno-vla-cxx-extension -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fdiagnostics-color=always -fno-omit-frame-pointer -fvisibility=hidden -I ${CMAKE_SOURCE_DIR}/src)
add_definitions(-D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Wall -Wno-sign-compare -Wno-comment -Wno-parentheses -Wno-pointer-arith -fdiagnostics-color=always -fno-omit-frame-pointer -fvisibility=hidden -I ${CMAKE_SOURCE_DIR}/src)
add_link_options(-fno-omit-frame-pointer)
if (${WITH_ASAN})
add_definitions(-fsanitize=address)

View File

@@ -572,7 +572,7 @@ void blockstore_heap_t::finish_load()
if (postponed_items.size())
{
// Sort "postponed" items and load in batches
std::sort(postponed_items.begin(), postponed_items.end(), [](const heap_list_item_t* a, const heap_list_item_t* b)
std::sort(postponed_items.begin(), postponed_items.end(), [this](const heap_list_item_t* a, const heap_list_item_t* b)
{
return a->entry.inode < b->entry.inode || a->entry.inode == b->entry.inode &&
(a->entry.stripe < b->entry.stripe || a->entry.stripe == b->entry.stripe &&

View File

@@ -273,7 +273,7 @@ resume_6:
rc->buf = (uint8_t*)memalign_or_die(MEM_ALIGNMENT, rc->len);
data = ((ring_data_t*)sqe->user_data);
data->iov = (iovec){ rc->buf, rc->len };
data->callback = [rc](ring_data_t *data)
data->callback = [this, rc](ring_data_t *data)
{
if (data->res < 0)
{

View File

@@ -355,7 +355,7 @@ resume_11:
BS_SUBMIT_GET_SQE(sqe, data);
io_uring_prep_fsync(sqe, dsk.data_fd, IORING_FSYNC_DATASYNC);
data->iov = { 0 };
data->callback = [this, fs = data_fsync_cur](ring_data_t *data)
data->callback = [this, op, fs = data_fsync_cur](ring_data_t *data)
{
live = true;
if (data->res != 0)

View File

@@ -83,8 +83,10 @@ int blockstore_impl_t::continue_sync(blockstore_op_t *op)
if (dsk.csum_block_size)
{
// More complex check because all journal entries have different lengths
int left = PRIV(op)->sync_big_writes.size();
for (auto & sbw: PRIV(op)->sync_big_writes)
{
left--;
auto & dirty_entry = dirty_db.at(sbw);
uint64_t dyn_size = dsk.dirty_dyn_size(dirty_entry.offset, dirty_entry.len);
if (!space_check.check_available(op, 1, sizeof(journal_entry_big_write) + dyn_size, 0))

View File

@@ -245,7 +245,7 @@ void cluster_client_t::inc_wait(uint64_t opcode, uint64_t flags, cluster_op_t *n
{
next->prev_wait += inc;
assert(next->prev_wait >= 0);
if (!next->prev_wait && !continuing_ops)
if (!next->prev_wait)
{
// Kind of std::vector with local "small vector optimisation"
if (bh_op_count >= bh_op_max)

View File

@@ -71,8 +71,8 @@ struct msgr_rdma_connection_t;
struct msgr_rdma_context_t;
#endif
class op_aes_xts_encrypt_t;
class op_aes_xts_decrypt_t;
struct op_aes_xts_encrypt_t;
struct op_aes_xts_decrypt_t;
void destroy_aes_xts_encrypt(op_aes_xts_encrypt_t *encrypt_ctx);
void destroy_aes_xts_decrypt(op_aes_xts_decrypt_t *decrypt_ctx);
@@ -216,7 +216,7 @@ protected:
friend class copy_op_writer_t;
friend class gcm_op_writer_t;
friend class get_op_writer_t;
friend struct osd_client_t;
friend class osd_client_t;
int keepalive_timer_id = -1;

View File

@@ -284,6 +284,7 @@ bool msgr_handshake_t::on_error(const std::string & prefix)
bool msgr_handshake_t::init(bool server_mode)
{
this->ctx = ctx;
std::unique_ptr<EVP_PKEY_CTX, decltype(&EVP_PKEY_CTX_free)> kctx(EVP_PKEY_CTX_new(ctx->params, NULL), EVP_PKEY_CTX_free);
if (!kctx)
return on_error("EVP_PKEY_CTX_new with EC params: ");

View File

@@ -185,7 +185,7 @@ static const char* help_text =
"vitastor-cli osd-tree [-l|--long]\n"
" Show current OSD tree, optionally with I/O statistics if -l is specified.\n"
"\n"
"vitastor-cli osds|ls-osds|ls-osd|osd-ls [-l|--long]\n"
"vitastor-cli osds|ls-osd|osd-ls [-l|--long]\n"
" Show current OSDs as list, optionally with I/O statistics if -l is specified.\n"
"\n"
"vitastor-cli modify-osd [--tags tag1,tag2,...] [--reweight <number>] [--noout true/false] <osd_number>\n"
@@ -203,8 +203,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, 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"
" -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"
" -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"
@@ -214,7 +214,7 @@ static const char* help_text =
" --block_size 128k Put pool only on OSDs with this data block size\n"
" --bitmap_granularity 4k Put pool only on OSDs with this logical sector size\n"
" --immediate_commit all Put pool only on OSDs with this or larger immediate_commit (none < small < all)\n"
" --level_placement <rules> Use additional failure domain rules (example: \"dc=112233\", \"\" to remove)\n"
" --level_placement <rules> Use additional failure domain rules (example: \"dc=112233\")\n"
" --raw_placement <rules> Specify raw PG generation rules (see documentation for details)\n"
" --local_reads primary Local read policy for replicated pools: primary, nearest or random\n"
" --primary_affinity_tags tags Prefer to put primary copies on OSDs with all specified tags\n"
@@ -241,7 +241,6 @@ static const char* help_text =
" [--immediate_commit <all|small|none>] [--pg_stripe_size <size>]\n"
" These, however, can still be modified with -f|--force.\n"
" See create-pool for parameter descriptions.\n"
" Renaming with --name fails if another pool already has the new name.\n"
" Examples:\n"
" vitastor-cli modify-pool pool_A --name pool_B\n"
" vitastor-cli modify-pool 2 --pg_size 4 -n 128\n"
@@ -260,7 +259,7 @@ static const char* help_text =
"vitastor-cli ls-users|user-ls|ls-user|list-users [<name> ...]\n"
" List users (only with specified names if passed).\n"
"\n"
"vitastor-cli modify-user|user-modify --type <type> --groups group1,group2,... <username>\n"
"vitastor-cli modify-user --type <type> --groups group1,group2,... <username>\n"
" Create or update user permissions. User names match CN of their certificates.\n"
" --type TYPE Set user type: client or admin. Default is client.\n"
" --groups GROUPS Set user's groups.\n"

View File

@@ -37,6 +37,7 @@ struct dd_in_info_t
// in
std::string iimg, ifile;
bool in_direct = false;
bool detect_size = true;
// out
cli_result_t result;
@@ -67,7 +68,10 @@ struct dd_in_info_t
return;
}
in_granularity = pool_it->second.bitmap_granularity;
in_size = iwatch->cfg.size;
if (detect_size)
{
in_size = iwatch->cfg.size;
}
in_seekable = true;
return;
}
@@ -88,31 +92,33 @@ struct dd_in_info_t
{
ifd = 0;
}
struct stat st;
if (fstat(ifd, &st) < 0)
if (detect_size)
{
result = (cli_result_t){ .err = errno, .text = "Failed to stat "+ifile+": "+std::string(strerror(errno)) };
close(ifd);
ifd = -1;
return;
}
if (S_ISREG(st.st_mode))
{
in_size = st.st_size;
}
else if (S_ISBLK(st.st_mode))
{
if (ioctl(ifd, BLKGETSIZE64, &in_size) < 0)
struct stat st;
if (fstat(ifd, &st) < 0)
{
result = (cli_result_t){ .err = errno, .text = "Failed to get "+ifile+" size: "+std::string(strerror(errno)) };
result = (cli_result_t){ .err = errno, .text = "Failed to stat "+ifile+": "+std::string(strerror(errno)) };
close(ifd);
ifd = -1;
return;
}
if (S_ISREG(st.st_mode))
{
in_size = st.st_size;
}
else if (S_ISBLK(st.st_mode))
{
if (ioctl(ifd, BLKGETSIZE64, &in_size) < 0)
{
result = (cli_result_t){ .err = errno, .text = "Failed to get "+ifile+" size: "+std::string(strerror(errno)) };
close(ifd);
ifd = -1;
return;
}
}
}
in_seekable = false;
// a seekable character device has no size (st_size 0), read it like a pipe
if (!S_ISCHR(st.st_mode) && lseek(ifd, 1, SEEK_SET) == (off_t)1)
if (lseek(ifd, 1, SEEK_SET) == (off_t)1)
{
in_seekable = true;
lseek(ifd, 0, SEEK_SET);
@@ -169,7 +175,7 @@ struct dd_out_info_t
return NULL;
}
bool open_output(cli_tool_t *parent, int & state, int base_state, uint64_t oseek, uint64_t blocksize)
bool open_output(cli_tool_t *parent, int & state, int base_state)
{
if (state == base_state)
goto resume_1;
@@ -206,13 +212,6 @@ struct dd_out_info_t
return true;
}
}
if ((oseek % out_granularity) || (blocksize % out_granularity))
{
result = (cli_result_t){ .err = EINVAL, .text = "Unaligned write to Vitastor is not supported" };
parent->cli->st_cli->close_watch(owatch);
owatch = NULL;
return true;
}
if (out_size % 4096)
{
out_size += (4096 - (out_size % 4096));
@@ -289,13 +288,13 @@ resume_2:
}
if (ofile != "")
{
ofd = open(ofile.c_str(), (out_direct ? O_DIRECT : 0) | (out_append ? O_WRONLY|O_APPEND : O_RDWR) | (out_create ? O_CREAT : 0), 0666);
ofd = open(ofile.c_str(), (out_direct ? O_DIRECT : 0) | (out_append ? O_APPEND : O_RDWR) | (out_create ? O_CREAT : 0), 0666);
if (ofd < 0)
{
result = (cli_result_t){ .err = errno, .text = "Failed to open "+ofile+": "+std::string(strerror(errno)) };
return true;
}
if (out_trunc && ftruncate(ofd, out_size ? out_size : oseek) < 0)
if (out_trunc && ftruncate(ofd, out_size) < 0)
{
result = (cli_result_t){ .err = errno, .text = "Failed to truncate "+ofile+": "+std::string(strerror(errno)) };
return true;
@@ -315,16 +314,6 @@ resume_2:
out_seekable = true;
lseek(ofd, 0, SEEK_SET);
}
struct stat st;
if (fstat(ofd, &st) < 0)
{
result = (cli_result_t){ .err = errno, .text = "Failed to stat "+(ofile != "" ? ofile : "stdout")+": "+std::string(strerror(errno)) };
return true;
}
if (!S_ISREG(st.st_mode) && !S_ISBLK(st.st_mode))
{
end_fsync = false;
}
return true;
}
@@ -406,7 +395,6 @@ struct cli_dd_t
uint64_t written_size = 0;
uint64_t written_progress = 0;
timespec tv_begin = {}, tv_progress = {};
bool progress_shown = false;
int state = 0;
int copy_error = 0;
int in_waiting = 0, out_waiting = 0;
@@ -425,7 +413,6 @@ struct cli_dd_t
auto res = read(fd, buf, blocksize < to_skip ? blocksize : to_skip);
if (res <= 0)
{
free(buf);
return res == 0 ? -EPIPE : -errno;
}
to_skip -= res;
@@ -735,12 +722,6 @@ struct cli_dd_t
{
return;
}
if (end && !end_status && !parent->json_output)
{
if (progress_shown)
fprintf(stderr, "\r\033[K");
return;
}
timespec tv_now;
clock_gettime(CLOCK_REALTIME, &tv_now);
double sec_delta = ((tv_now.tv_sec - tv_progress.tv_sec) + (double)(tv_now.tv_nsec - tv_progress.tv_nsec)/1000000000.0);
@@ -783,7 +764,6 @@ struct cli_dd_t
format_size((uint64_t)(delta/sec_delta), true).c_str(),
format_size((uint64_t)(written_size/sec_total), true).c_str()
);
progress_shown = true;
}
}
@@ -846,12 +826,6 @@ struct cli_dd_t
state = 100;
return;
}
if (oinfo.ofile != "" && oinfo.out_append && oinfo.out_trunc)
{
result = (cli_result_t){ .err = EINVAL, .text = "conv=trunc and oflag=append can't be used together" };
state = 100;
return;
}
if ((iinfo.iimg != "" ? "i"+iinfo.iimg : "f"+iinfo.ifile) == (oinfo.oimg != "" ? "i"+oinfo.oimg : "f"+oinfo.ofile))
{
result = (cli_result_t){ .err = EINVAL, .text = "Input and output image/file can't be equal" };
@@ -874,20 +848,13 @@ struct cli_dd_t
state = 100;
return;
}
if (iinfo.in_seekable && iseek >= iinfo.in_size)
{
iinfo.close_input(parent);
result = (cli_result_t){ .err = EINVAL, .text = "Input seek position is beyond end of input" };
state = 100;
return;
}
if (!oinfo.out_size && (iinfo.in_seekable || bytelimit))
if (!oinfo.out_size)
{
oinfo.out_size = oseek + (iinfo.in_seekable && (!bytelimit || iinfo.in_size-iseek < bytelimit) ? iinfo.in_size-iseek : bytelimit);
}
resume_1:
resume_2:
if (!oinfo.open_output(parent, state, 1, oseek, blocksize))
if (!oinfo.open_output(parent, state, 1))
{
return;
}
@@ -904,6 +871,11 @@ resume_2:
goto close_end;
}
// Copy data
if (iinfo.in_seekable && iseek >= iinfo.in_size)
{
result = (cli_result_t){ .err = EINVAL, .text = "Input seek position is beyond end of input" };
goto close_end;
}
if (!iinfo.iwatch && !iinfo.in_seekable && iseek)
{
// Read and ignore some data from input
@@ -917,8 +889,9 @@ resume_2:
in_iodepth = iinfo.in_seekable ? iodepth : 1;
out_iodepth = oinfo.out_seekable ? iodepth : 1;
write_zero = write_zero || !oinfo.out_seekable;
oinfo.end_fsync = oinfo.end_fsync && oinfo.out_seekable;
read_offset = 0;
read_end = iinfo.in_seekable ? iinfo.in_size-iseek : UINT64_MAX;
read_end = iinfo.in_seekable ? iinfo.in_size-iseek : 0;
if (oinfo.out_size && (!read_end || read_end > oinfo.out_size-oseek))
read_end = oinfo.out_size-oseek;
if (bytelimit && (!read_end || read_end > bytelimit))
@@ -1027,14 +1000,10 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_dd(json11::Json cfg)
if (!dd->iodepth)
dd->iodepth = 4;
if (cfg["status"] == "none")
{
dd->end_status = false;
progress = false;
}
else if (cfg["status"] == "noxfer")
dd->end_status = false;
else if (cfg["status"] == "progress")
progress = true;
dd->iinfo.detect_size = cfg["size"].is_null();
dd->oinfo.out_size = parse_size(cfg["size"].as_string());
dd->conv = explode_json(",", cfg["conv"]);
dd->iflag = explode_json(",", cfg["iflag"]);

View File

@@ -41,8 +41,6 @@ struct cli_describe_t
std::vector<osd_num_t> only_osds;
uint64_t min_inode = 0, max_inode = 0;
uint64_t min_offset = 0, max_offset = 0;
std::map<osd_num_t, std::string> skipped_pgs;
bool incomplete = false;
cli_tool_t *parent = NULL;
int state = 0;
@@ -57,13 +55,6 @@ struct cli_describe_t
return state == 100;
}
bool is_osd_up(osd_num_t osd_num)
{
auto & peer_states = parent->cli->st_cli->peer_states;
auto peer_it = peer_states.find(osd_num);
return peer_it != peer_states.end() && !peer_it->second.is_null();
}
void parse_options(json11::Json cfg)
{
uint64_t pool_id;
@@ -92,18 +83,19 @@ struct cli_describe_t
}
only_pg = cfg["pg"].uint64_value();
min_inode = cfg["inode"].uint64_value();
min_offset = stoull_full(cfg["min_offset"].string_value(), 0);
max_offset = stoull_full(cfg["max_offset"].string_value(), 0);
if (min_inode)
{
if (!INODE_POOL(min_inode))
min_inode |= (uint64_t)only_pool << (64-POOL_ID_BITS);
max_inode = min_inode;
min_offset = max_offset = 0;
}
else
{
min_inode = stoull_full(cfg["min_inode"].string_value(), 0); // to support 0x...
max_inode = stoull_full(cfg["max_inode"].string_value(), 0);
min_offset = stoull_full(cfg["min_offset"].string_value(), 0);
max_offset = stoull_full(cfg["max_offset"].string_value(), 0);
if (!min_inode && !max_inode && only_pool)
{
min_inode = (uint64_t)only_pool << (64-POOL_ID_BITS);
@@ -111,9 +103,6 @@ struct cli_describe_t
(((uint64_t)1 << (64-POOL_ID_BITS)) - 1);
}
}
// The OSD ends the listing at (max_inode, max_offset) inclusive
if (max_inode && cfg["max_offset"].is_null())
max_offset = UINT64_MAX;
only_osds = parse_uint64_list(cfg["osds"]);
object_state = stoull_full(cfg["object_state"].string_value(), 0);
if (!object_state && cfg["object_state"].is_string())
@@ -169,43 +158,10 @@ struct cli_describe_t
if (pp.first >= min_pool && (!max_pool || pp.first <= max_pool))
{
for (auto & pgp: pp.second.pg_config)
{
if (only_pool && only_pg && (pp.first != only_pool || pgp.first != only_pg))
continue;
if (is_osd_up(pgp.second.cur_primary))
only_osds.push_back(pgp.second.cur_primary);
else
{
auto & pgs = skipped_pgs[pgp.second.cur_primary];
pgs += (pgs == "" ? "" : ", ")+std::to_string(pp.first)+"/"+std::to_string(pgp.first);
}
}
only_osds.push_back(pgp.second.cur_primary);
}
}
}
else
{
std::vector<osd_num_t> filtered_osds;
for (auto osd_num: only_osds)
{
if (is_osd_up(osd_num))
filtered_osds.push_back(osd_num);
else
skipped_pgs[osd_num] = "";
}
only_osds = filtered_osds;
}
// Requests to an OSD which is down are never answered
for (auto & sk: skipped_pgs)
{
if (!sk.first)
fprintf(stderr, "No primary OSD for PG %s, skipping\n", sk.second.c_str());
else if (sk.second != "")
fprintf(stderr, "OSD %ju is down, skipping PG %s\n", sk.first, sk.second.c_str());
else
fprintf(stderr, "OSD %ju is down, skipping it\n", sk.first);
incomplete = true;
}
remove_duplicates(only_osds);
parent->cli->init_msgr();
if (parent->json_output && parent->is_command_line)
@@ -234,7 +190,6 @@ struct cli_describe_t
{
if (op->reply.hdr.retval < 0)
{
incomplete = true;
fprintf(
stderr, "Failed to describe objects on OSD %ju (retval=%jd)\n",
osd_num, op->reply.hdr.retval
@@ -242,7 +197,6 @@ struct cli_describe_t
}
else if (op->reply.describe.result_bytes != op->reply.hdr.retval * sizeof(osd_reply_describe_item_t))
{
incomplete = true;
fprintf(
stderr, "Invalid response size from OSD %ju (expected %ju bytes, got %ju bytes)\n",
osd_num, op->reply.hdr.retval * sizeof(osd_reply_describe_item_t), op->reply.describe.result_bytes
@@ -309,13 +263,6 @@ struct cli_describe_t
{
result.data = describe_items;
}
if (incomplete)
{
result.err = EIO;
if (parent->json_output && parent->is_command_line)
parent->json_output = false;
result.text = "The listing is incomplete, see the messages above";
}
state = 100;
describe_items.clear();
}

View File

@@ -21,20 +21,12 @@ struct cli_fix_t
json11::Json options;
cli_result_t result;
json11::Json::array fix_result;
bool incomplete = false;
bool is_done()
{
return state == 100;
}
bool is_osd_up(osd_num_t osd_num)
{
auto & peer_states = parent->cli->st_cli->peer_states;
auto peer_it = peer_states.find(osd_num);
return peer_it != peer_states.end() && !peer_it->second.is_null();
}
void parse_objects_str(std::string str)
{
str = trim(str);
@@ -131,20 +123,6 @@ struct cli_fix_t
state = 100;
return;
}
{
std::string down_osds;
for (auto osd_num: bad_osds)
{
if (!is_osd_up(osd_num))
down_osds += (down_osds == "" ? "" : ", ")+std::to_string(osd_num);
}
if (down_osds != "")
{
result = (cli_result_t){ .err = EAGAIN, .text = "Bad OSD(s) "+down_osds+" are down, can't remove object copies from them" };
state = 100;
return;
}
}
remove_duplicates(objects);
parent->cli->init_msgr();
resume_1:
@@ -160,7 +138,6 @@ struct cli_fix_t
if (pool_cfg_it == parent->cli->st_cli->pool_config.end())
{
fprintf(stderr, "Object %jx:%jx is from unknown pool\n", obj.inode, obj.stripe);
incomplete = true;
continue;
}
auto & pool_cfg = pool_cfg_it->second;
@@ -173,20 +150,9 @@ struct cli_fix_t
stderr, "Object %jx:%jx is from PG %u/%u which is not currently active\n",
obj.inode, obj.stripe, pool_cfg_it->first, pg_num
);
incomplete = true;
continue;
}
osd_num_t primary_osd = pg_it->second.cur_primary;
if (!is_osd_up(primary_osd))
{
// Requests to an OSD which is down are never answered
fprintf(
stderr, "Object %jx:%jx is from PG %u/%u whose primary OSD %ju is down\n",
obj.inode, obj.stripe, pool_cfg_it->first, pg_num, primary_osd
);
incomplete = true;
continue;
}
// Describe -> Remove some copies -> Scrub again
osd_op_t *op = new osd_op_t;
op->req = (osd_any_op_t){
@@ -206,7 +172,6 @@ struct cli_fix_t
if (op->reply.hdr.retval < 0 || op->reply.describe.result_bytes != op->reply.hdr.retval * sizeof(osd_reply_describe_item_t))
{
fprintf(stderr, "Failed to describe objects on OSD %ju (retval=%jd)\n", primary_osd, op->reply.hdr.retval);
incomplete = true;
parent->waiting--;
loop();
}
@@ -243,7 +208,6 @@ struct cli_fix_t
(*rm_count)--;
if (rm_op->reply.hdr.retval < 0)
{
incomplete = true;
fprintf(
stderr, "Failed to remove object %jx:%jx from OSD %ju (retval=%jd)\n",
rm_op->req.sec_del.oid.inode, rm_op->req.sec_del.oid.stripe,
@@ -288,7 +252,6 @@ struct cli_fix_t
{
if (scrub_op->reply.hdr.retval < 0 && scrub_op->reply.hdr.retval != -ENOENT)
{
incomplete = true;
fprintf(
stderr, "Failed to scrub %jx:%jx on OSD %ju (retval=%jd)\n",
obj.inode, obj.stripe, primary_osd, scrub_op->reply.hdr.retval
@@ -326,11 +289,6 @@ struct cli_fix_t
{
result.data = fix_result;
}
if (incomplete)
{
result.err = EIO;
result.text = "Some objects were not fixed, see the messages above";
}
state = 100;
}
};

View File

@@ -250,17 +250,11 @@ resume_1:
json11::Json::array to_tree(const json11::Json::array & array)
{
std::set<uint64_t> listed;
for (const auto & item: array)
{
listed.insert(item["inode_id"].uint64_value());
}
std::map<uint64_t, json11::Json::array> children;
for (const auto & item: array)
{
uint64_t parent_id = item["parent_inode_id"].uint64_value();
// Layers with a filtered out parent are shown as roots
children[listed.find(parent_id) != listed.end() ? parent_id : 0].push_back(item);
children[parent_id].push_back(item);
}
json11::Json::array tree;
std::function<void(uint64_t, const std::string &)> add_children = [&](uint64_t parent_id, const std::string & prefix)

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

@@ -412,8 +412,6 @@ resume_1:
load_osd_tree();
if (parent->waiting > 0)
return;
if (state == 100)
return;
format_tree();
state = 100;
}

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

@@ -103,22 +103,24 @@ std::string validate_pool_config(json11::Json::object & new_cfg, json11::Json ol
// level=rule, level=rule, ...
if (!value.is_object())
{
if (!value.is_null() && !value.is_string())
{
return key+" must be a string";
}
json11::Json::object obj;
for (auto & item: explode(",", value.string_value(), true))
{
auto pair = explode("=", item, true);
if (pair.size() != 2)
if (pair.size() >= 2)
{
return "--level_placement must be <level>=<rule>[,<level>=<rule>...], but it is "+value.string_value();
obj[pair[0]] = pair[1];
}
obj[pair[0]] = pair[1];
}
// empty value = remove the rules; null keeps the old ones from being merged back
value = obj.size() ? json11::Json(obj) : json11::Json();
if (obj.size())
{
value = obj;
}
else
{
new_cfg.erase(kv_it++);
continue;
}
}
}
else if (key == "osd_tags" || key == "primary_affinity_tags")
@@ -167,10 +169,6 @@ std::string validate_pool_config(json11::Json::object & new_cfg, json11::Json ol
{
new_cfg.erase("local_reads");
}
if (new_cfg.find("level_placement") != new_cfg.end() && new_cfg["level_placement"].is_null())
{
new_cfg.erase("level_placement");
}
// Prevent autovivification of object keys. Now we don't modify the config, we just check it
json11::Json cfg = new_cfg;
@@ -235,10 +233,9 @@ 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";
}
// same limit as in etcd_state_client.cpp and mon/pool_config.js
if (pg_size > 64)
if (pg_size > 256)
{
return "PG size can't be greater than 64";
return "PG size can't be greater than 256";
}
// PG rules

View File

@@ -116,21 +116,7 @@ resume_1:
state = 100;
return;
}
if (new_cfg["name"] != old_cfg["name"])
{
for (auto & pce: kv.value.object_items())
{
if (pce.second["name"] == new_cfg["name"])
{
result = (cli_result_t){
.err = EEXIST,
.text = "Pool with name \""+new_cfg["name"].string_value()+"\" already exists (ID "+pce.first+")",
};
state = 100;
return;
}
}
}
if (new_cfg.find("used_for_app") != new_cfg.end() && !force)
{
// Check that pool doesn't have images

View File

@@ -329,27 +329,8 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_rm_data(json11::Json cfg)
}
remover->down_ok = cfg["down_ok"].bool_value();
remover->pool_id = INODE_POOL(remover->inode);
bool min_max_ok = true;
if (!cfg["min_offset"].is_null())
{
remover->min_offset = cfg["min_offset"].uint64_value();
if (!remover->min_offset && cfg["min_offset"].as_string() != "0")
min_max_ok = false;
}
if (!cfg["max_offset"].is_null())
{
remover->max_offset = cfg["max_offset"].uint64_value();
if (!remover->max_offset && cfg["max_offset"].as_string() != "0")
min_max_ok = false;
}
if (!min_max_ok)
{
return [](cli_result_t & result)
{
result = (cli_result_t){ .err = EINVAL, .text = "Invalid min_offset or max_offset" };
return true;
};
}
remover->min_offset = cfg["min_offset"].uint64_value();
remover->max_offset = cfg["max_offset"].uint64_value();
return [remover](cli_result_t & result)
{
remover->loop();

View File

@@ -170,8 +170,7 @@ struct rm_osd_t
}
if (still_up.size() && !allow_up)
error += (still_up.size() == 1 ? "OSD " : "OSDs ") + implode(", ", still_up) +
(still_up.size() == 1 ? " is" : " are") + " still up. Use `vitastor-disk purge` to delete " +
(still_up.size() == 1 ? "it" : "them") + ".\n";
(still_up.size() == 1 ? "is" : "are") + " still up. Use `vitastor-disk purge` to delete them.\n";
if (is_dataloss && !force_dataloss && !dry_run)
error += "OSDs not deleted. Please move data to other OSDs or bypass this check with --allow-data-loss if you know what you are doing.\n";
else if (is_warning && !force_warning && !dry_run)

View File

@@ -313,30 +313,16 @@ 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"];
}
// 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<std::string, std::string> 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<std::string> 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(value);
argstr.push_back(kv.second.is_string() ? kv.second.string_value() : kv.second.dump());
}
char *argv[argstr.size()+1];
for (int i = 0; i < argstr.size(); i++)

View File

@@ -558,11 +558,13 @@ void osd_t::scrub_check_results(osd_op_t *cur_op)
}
else
{
int total = 0;
for (int i = 0; i < op_data->stripe_count; i++)
{
if (!op_data->stripes[i].not_exists)
{
// use "missing" flag to distinguish actual read errors and inconsistent chunks
total++;
op_data->stripes[i].missing = true;
}
}

View File

@@ -371,7 +371,7 @@ int main(int narg, char *args[])
auto ringloop = new ring_loop_t(RINGLOOP_DEFAULT_SIZE);
auto epmgr = new epoll_manager_t(ringloop);
auto cli = cluster_client_t::create(ringloop, epmgr->tfd, cfg);
test_data_t data = { .cli = cli, .ringloop = ringloop, .inode = inode };
test_data_t data = { .cli = cli, .ringloop = ringloop, inode = inode };
// Wait for init
cli->on_ready([&]() { data.done = true; });
data.wait();

View File

@@ -1122,37 +1122,6 @@ void test_pg_config_disappears()
printf("[ok] test_pg_config_disappears\n");
}
void test_sync_released_during_continue_ops()
{
json11::Json config;
timerfd_manager_t *tfd = new timerfd_manager_t([](int fd, bool wr, std::function<void(int, int)> callback){});
etcd_mock_t etcd_store;
etcd_state_client_mock_t *mock = new etcd_state_client_mock_t(etcd_store);
mock->pause();
cluster_client_t *cli = new cluster_client_t(NULL, tfd, config, std::unique_ptr<etcd_state_client_t>(mock));
configure_single_pg_pool(mock);
mock->resume();
// The OSD isn't connected: the write waits, and the SYNC waits for the write
int *r1 = test_write(cli, 0, 4096, 0x55);
int *r2 = test_sync(cli);
// The write fails in continue_ops(), and the SYNC it releases completes and is freed at once:
// continue_ops() must not go on from the write to the SYNC
can_complete(r1);
can_complete(r2);
mock->set("/vitastor/pg/config", json11::Json::object {
{ "items", json11::Json::object { } }
});
assert(*r1 == -EINVAL);
check_completed(r2);
delete r1;
delete cli;
delete tfd;
printf("[ok] test_sync_released_during_continue_ops\n");
}
void test_snapshot_over_nonexistent_pool()
{
json11::Json config;
@@ -1357,7 +1326,6 @@ int main(int narg, char *args[])
test_sync_fail_dirty_state_loss();
cluster_client_test_t::test_vault();
test_pg_config_disappears();
test_sync_released_during_continue_ops();
test_snapshot_over_nonexistent_pool();
return 0;
}

View File

@@ -18,8 +18,6 @@ SCHEME=ec ./test_change_pg_count.sh
./test_create_nomaxid.sh
./test_modify_pool.sh
./test_etcd_fail.sh
ANTIETCD=1 ./test_etcd_fail.sh
@@ -66,10 +64,7 @@ OLD=1 ./test_move_reappear.sh
./test_rm.sh
./test_modify_image_resize.sh
./test_rm_degraded.sh
./test_describe.sh
./test_snapshot_chain.sh
SCHEME=ec ./test_snapshot_chain.sh
@@ -100,10 +95,6 @@ OLD=1 SCHEME=ec IMMEDIATE_COMMIT=1 ./test_rebalance_verify.sh
./test_dd.sh
./test_cli_help.sh
./test_disk_exec_osd.sh
./test_root_node.sh
./test_switch_primary.sh
@@ -131,7 +122,6 @@ OLD=1 ./test_corrupt_all.sh
./test_reweight_half.sh
./test_snapshot_pool2.sh
./test_ls_tree.sh
./test_snapshot_read_bitmap.sh
TEST_NAME=csum_32k_dmj OSD_ARGS="--data_csum_type crc32c --csum_block_size 32k --inmemory_metadata false --inmemory_journal false" OFFSET_ARGS=$OSD_ARGS ./test_heal.sh

View File

@@ -1,14 +0,0 @@
#!/bin/bash -ex
# Test that vitastor-cli --help knows every command name and alias the CLI accepts
. `dirname $0`/common.sh
for cmd in $(grep -o 'cmd\[0\] == "[^"]*"' src/cmd/cli.cpp | sed 's/.*== "//; s/"$//'); do
build/src/cmd/vitastor-cli --help $cmd > ./testdata/help.txt 2>&1 || true
if grep -q '^Unknown command' ./testdata/help.txt; then
format_error "vitastor-cli --help $cmd does not know the command"
fi
done
format_green OK

View File

@@ -24,85 +24,4 @@ $VITASTOR_CLI dd iimg=testimg2 iodepth=4 bs=1M count=128 > ./testdata/testfile1
diff ./testdata/testfile ./testdata/testfile1
rm ./testdata/testfile1
# size= sets the output size, the input size is still detected
$VITASTOR_CLI dd iimg=testimg oimg=testimg3 iodepth=4 size=192M
$VITASTOR_CLI dd if=./testdata/testfile oimg=testimg4 iodepth=4 size=192M
for img in testimg3 testimg4; do
size=$($VITASTOR_CLI ls --json | jq -r '.[] | select(.name == "'$img'") | .size')
[[ "$size" = $((192*1024*1024)) ]] || format_error "dd size=192M created $img with size $size"
$VITASTOR_CLI dd iimg=$img iodepth=4 bs=1M count=128 > ./testdata/testfile1
diff ./testdata/testfile ./testdata/testfile1
rm ./testdata/testfile1
done
# skip beyond the end of input fails before the output image is created
rc=0
$VITASTOR_CLI dd iimg=testimg oimg=testimg5 bs=1M skip=200 count=1 || rc=$?
[[ $rc = 22 ]] || format_error "dd skip beyond the end of input returned $rc instead of EINVAL"
if $VITASTOR_CLI ls --json | jq -e '.[] | select(.name == "testimg5")'; then
format_error "dd skip beyond the end of input created the output image"
fi
# status=none prints nothing, also with the default --progress 1
$VITASTOR_CLI dd iimg=testimg of=./testdata/testfile1 iodepth=4 status=none 2>./testdata/dd.err
[[ ! -s ./testdata/dd.err ]] || format_error "dd status=none printed: $(cat ./testdata/dd.err)"
diff ./testdata/testfile ./testdata/testfile1
rm ./testdata/testfile1
# status=noxfer drops the final statistics line
$VITASTOR_CLI --progress 0 dd iimg=testimg of=./testdata/testfile1 iodepth=4 status=noxfer 2>./testdata/dd.err
[[ ! -s ./testdata/dd.err ]] || format_error "dd status=noxfer printed: $(cat ./testdata/dd.err)"
rm ./testdata/testfile1
# with --progress 1 the progress line, if it was shown at all, is cleared at the end
clear_line=$'\r\033[K'
for count in 128 4; do
$VITASTOR_CLI dd iimg=testimg of=./testdata/testfile1 iodepth=4 bs=1M count=$count status=noxfer 2>./testdata/dd.err
if [[ $(wc -l < ./testdata/dd.err) != 0 || ( -s ./testdata/dd.err && "$(cat ./testdata/dd.err)" != *copied*"$clear_line" ) ]]; then
format_error "dd status=noxfer count=$count printed: $(cat -v ./testdata/dd.err)"
fi
head -c ${count}M ./testdata/testfile | cmp - ./testdata/testfile1
rm ./testdata/testfile1
done
# oflag=append appends to the output file
cp ./testdata/over ./testdata/testfile1
$VITASTOR_CLI dd iimg=testimg of=./testdata/testfile1 iodepth=4 bs=1M count=8 oflag=append
(cat ./testdata/over; head -c 8M ./testdata/testfile) | cmp - ./testdata/testfile1 || format_error "dd oflag=append did not append to the output file"
rm ./testdata/testfile1
# conv=trunc contradicts oflag=append: fail without touching the output file
cp ./testdata/over ./testdata/testfile1
rc=0
$VITASTOR_CLI dd iimg=testimg of=./testdata/testfile1 iodepth=4 bs=1M count=8 oflag=append conv=trunc || rc=$?
[[ $rc = 22 ]] || format_error "dd conv=trunc oflag=append returned $rc instead of EINVAL"
cmp ./testdata/over ./testdata/testfile1 || format_error "dd conv=trunc oflag=append changed the output file"
rm ./testdata/testfile1
# pipe in without count - copy to the end of input
$VITASTOR_CLI dd iimg=testimg iodepth=4 | $VITASTOR_CLI dd of=./testdata/testfile1 iodepth=4
diff ./testdata/testfile ./testdata/testfile1
rm ./testdata/testfile1
$VITASTOR_CLI dd iimg=testimg iodepth=4 | $VITASTOR_CLI dd of=./testdata/testfile1 iodepth=4 bs=1M seek=4
(head -c 4M /dev/zero; cat ./testdata/testfile) | cmp - ./testdata/testfile1 || format_error "dd from a pipe with seek= did not copy the whole input"
rm ./testdata/testfile1
# unaligned image I/O fails with EINVAL before the output image is created or resized
for args in "if=./testdata/testfile oimg=testimg6 seek=512B" "if=./testdata/testfile oimg=testimg2 seek=512B" "iimg=testimg oimg=testimg7 skip=512B"; do
rc=0
$VITASTOR_CLI dd iodepth=4 $args || rc=$?
[[ $rc = 22 ]] || format_error "dd $args returned $rc instead of EINVAL"
done
if $VITASTOR_CLI ls --json | jq -e '.[] | select(.name == "testimg6" or .name == "testimg7")'; then
format_error "dd with unaligned image I/O created the output image"
fi
size=$($VITASTOR_CLI ls --json | jq -r '.[] | select(.name == "testimg2") | .size')
[[ "$size" = $((128*1024*1024)) ]] || format_error "dd with unaligned seek resized testimg2 to $size"
# a character device is read like a pipe, up to count= or size=
$VITASTOR_CLI dd if=/dev/zero oimg=testimg8 size=32M
size=$($VITASTOR_CLI ls --json | jq -r '.[] | select(.name == "testimg8") | .size')
[[ "$size" = $((32*1024*1024)) ]] || format_error "dd if=/dev/zero size=32M created testimg8 with size $size"
$VITASTOR_CLI dd if=/dev/zero of=./testdata/testfile1 bs=1M count=4 conv=nosparse
head -c 4M /dev/zero | cmp - ./testdata/testfile1 || format_error "dd if=/dev/zero count=4 did not write 4 MiB of zeros"
rm ./testdata/testfile1
format_green OK

View File

@@ -1,98 +0,0 @@
#!/bin/bash -ex
# Test vitastor-cli describe and fix on degraded objects and with down OSDs
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/pg/state/ --print-value-only | jq -s -e '[ .[] | select((.state | index(\"active\")) and (.state | index(\"has_degraded\"))) ] | length == $PG_COUNT'" "PG peering with OSD 3"
INODE_ID=$($VITASTOR_CLI ls --json | jq -r '.[] | select(.name == "testimg") | .inode_id')
INODE=$(printf '0x%x' $INODE_ID)
INODE_NUM=$((INODE_ID & 0xffffffffffff))
# --inode lists the whole inode, not only its first object
all=$($VITASTOR_CLI describe --json | jq -c '[ .[] | select(.inode == "'$INODE'") | .stripe ] | unique')
if [[ $(echo "$all" | jq length) -le 1 ]]; then
format_error "describe should list more than one degraded object of testimg: $all"
fi
one=$($VITASTOR_CLI describe --pool 1 --inode $INODE_NUM --json | jq -c '[ .[].stripe ] | unique')
if [[ "$one" != "$all" ]]; then
format_error "describe --inode lists objects $one instead of $all"
fi
# --min-offset and --max-offset narrow --inode, and --max-inode includes its whole inode
second=$(echo "$all" | jq -r '.[1]')
part=$($VITASTOR_CLI describe --pool 1 --inode $INODE_NUM --min-offset $second --max-offset $second --json | jq -c '[ .[].stripe ] | unique')
if [[ "$part" != "[\"$second\"]" ]]; then
format_error "describe --inode --min-offset $second --max-offset $second lists objects $part"
fi
range=$($VITASTOR_CLI describe --min-inode $INODE --max-inode $INODE --json | jq -c '[ .[].stripe ] | unique')
if [[ "$range" != "$all" ]]; then
format_error "describe --min-inode $INODE --max-inode $INODE lists objects $range instead of $all"
fi
# describe and fix must not wait for an OSD which is down.
# Stop the monitor so that PGs keep the down OSD as their primary,
# and stop a primary OSD which has the latest data, so other PGs stay degraded.
VICTIM=$($VITASTOR_CLI ls-pgs --json | jq -r '[ .[].cur_primary | select(. == 1 or . == 2) ] | first')
VICTIM_PG=$($VITASTOR_CLI ls-pgs --json | jq -r '[ .[] | select(.cur_primary == '$VICTIM') | .pg_num ] | first')
OTHER_PG=$($VITASTOR_CLI ls-pgs --json | jq -r '[ .[] | select(.cur_primary != '$VICTIM') | .pg_num ] | first')
OTHER_PG_COUNT=$($VITASTOR_CLI ls-pgs --json | jq '[ .[] | select(.cur_primary != '$VICTIM') ] | length')
if [[ "$VICTIM" = null || "$OTHER_PG_COUNT" = 0 ]]; then
format_error "Expected PGs with primary OSD 1 or 2 and PGs with other primary OSDs"
fi
VICTIM_OBJ=$($VITASTOR_CLI describe --pool 1 --pg $VICTIM_PG --json | jq -r '.[0] | .inode+":"+.stripe')
OTHER_OBJ=$($VITASTOR_CLI describe --pool 1 --pg $OTHER_PG --json | jq -r '.[0] | .inode+":"+.stripe')
kill -9 $MON_PID
eval kill -9 \$OSD${VICTIM}_PID
$ETCDCTL del /vitastor/osd/state/$VICTIM
wait_condition 60 "$ETCDCTL get --prefix /vitastor/pg/state/ --print-value-only | jq -s -e '[ .[] | select(.primary != $VICTIM and (.state | index(\"degraded\"))) ] | length == $OTHER_PG_COUNT'" "PG peering without OSD $VICTIM"
# Keep PG 1/$VICTIM_PG active with the down primary, as it is until the OSD's etcd lease expires
$ETCDCTL put /vitastor/pg/state/1/$VICTIM_PG '{"peers":[1,2,3],"primary":'$VICTIM',"state":["active"]}'
# A listing with skipped OSDs or PGs is incomplete: EIO, but still valid JSON on stdout
for args in "" "--osds 1,2,3" "--pool 1 --pg $VICTIM_PG"; do
rc=0
timeout 30 $VITASTOR_CLI describe $args --json > ./testdata/describe.json 2> ./testdata/describe.err || rc=$?
[[ $rc == 5 ]] || format_error "describe $args exited with $rc instead of EIO with OSD $VICTIM down"
grep -q "OSD $VICTIM is down, skipping \(it\|PG 1/$VICTIM_PG\)" ./testdata/describe.err || \
format_error "describe $args should warn about OSD $VICTIM: $(cat ./testdata/describe.err)"
grep -q "The listing is incomplete" ./testdata/describe.err || \
format_error "describe $args should say that the listing is incomplete: $(cat ./testdata/describe.err)"
count=$(jq length ./testdata/describe.json) || format_error "describe $args printed invalid JSON"
if [[ "$args" == --pool* ]]; then
[[ $count == 0 ]] || format_error "describe $args should list nothing"
else
[[ $count -gt 0 ]] || format_error "describe $args should still list objects from the other OSDs"
fi
done
if timeout 30 $VITASTOR_CLI fix --bad-osds $VICTIM --objects $OTHER_OBJ 2> ./testdata/fix.err; then
format_error "fix should refuse to work with bad OSD $VICTIM down"
fi
grep -q "Bad OSD(s) $VICTIM are down" ./testdata/fix.err || format_error "fix printed: $(cat ./testdata/fix.err)"
# An object which is skipped is not fixed: EIO
rc=0
timeout 30 $VITASTOR_CLI fix --bad-osds 3 --objects $VICTIM_OBJ 2> ./testdata/fix.err || rc=$?
[[ $rc == 5 ]] || format_error "fix exited with $rc instead of EIO on an object from PG 1/$VICTIM_PG with primary OSD $VICTIM down"
grep -q "is from PG 1/$VICTIM_PG whose primary OSD $VICTIM is down" ./testdata/fix.err || \
format_error "fix should skip the object from PG 1/$VICTIM_PG: $(cat ./testdata/fix.err)"
grep -q "Some objects were not fixed" ./testdata/fix.err || \
format_error "fix should say that it skipped objects: $(cat ./testdata/fix.err)"
format_green OK

View File

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

View File

@@ -36,23 +36,4 @@ $ETCDCTL get --prefix /vitastor/pg/config --print-value-only | \
(. | map_values((. - 1) / 2 | floor) | unique | length) == 6 and
(. | map_values((. - 1) / 4 | floor) | unique | length) == 3) ] | length) == 32'
# A malformed --level_placement is refused, an empty one removes the rules
r=0
$VITASTOR_CLI modify-pool testpool --level_placement rack || r=$?
if [[ $r != 22 ]]; then
format_error "modify-pool --level_placement rack should fail with EINVAL (22), but exited with $r"
fi
$ETCDCTL get --print-value-only /vitastor/config/pools | jq -e '.["1"].level_placement == {"rack":"112233"}' || \
format_error "level_placement should stay rack=112233 after a refused change"
$VITASTOR_CLI modify-pool testpool --level_placement ''
$ETCDCTL get --print-value-only /vitastor/config/pools | jq -e '.["1"] | has("level_placement") | not' || \
format_error "modify-pool --level_placement '' should remove level_placement"
sleep 2
if grep -q 'configuration is invalid' ./testdata/mon.log; then
format_error "Monitor refused the pool configuration without level_placement"
fi
$ETCDCTL get --prefix /vitastor/pg/config --print-value-only | \
jq -s -e '([ .[0].items["1"] | .[].osd_set | map_values(. | tonumber) | select(
(. | map_values((. - 1) / 2 | floor) | unique | length) == 6) ] | length) == 32'
format_green OK

View File

@@ -1,40 +0,0 @@
#!/bin/bash -ex
# Test vitastor-cli ls --tree with filters which leave out parent layers
. `dirname $0`/run_3osds.sh
$VITASTOR_CLI create -s 128M testimg
$VITASTOR_CLI snap-create testimg@snap1
$VITASTOR_CLI create --parent testimg@snap1 testclone
$VITASTOR_CLI create-pool testpool2 -s 3 -n 4 --failure_domain osd
wait_pool_up 30 2 3 4
$VITASTOR_CLI create --parent testimg@snap1 -p testpool2 testclone2
# First column of each row without the header
check_tree()
{
local expected=$1
shift
local rows=$($VITASTOR_CLI ls --tree "$@" | tail -n +2 | sed 's/ .*//' | tr '\n' ';')
if [[ "$rows" != "$expected" ]]; then
format_error "ls --tree $* shows '$rows', expected '$expected'"
fi
}
$VITASTOR_CLI ls --tree
check_tree 'testimg@snap1;├─ testclone;├─ testclone2;└─ testimg;'
check_tree 'testimg@snap1;└─ testimg;' 'testimg*'
# Layers whose parent is filtered out are shown as roots
check_tree 'testimg;' testimg
check_tree 'testclone;testimg;' testclone testimg
check_tree 'testclone;' -n 1
check_tree 'testclone2;' -p testpool2
if ! $VITASTOR_CLI ls --tree testimg | grep -q ' testimg@snap1 *$'; then
format_error "ls --tree testimg should show testimg@snap1 as the parent"
fi
format_green OK

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

@@ -1,53 +0,0 @@
#!/bin/bash -ex
# Test that modify-pool --name refuses to take the name of another pool
. `dirname $0`/common.sh
wait_etcd
POOL='"scheme":"replicated","pg_size":2,"pg_minsize":1,"pg_count":1,"failure_domain":"osd"'
$ETCDCTL put /vitastor/config/pools '{"1":{"name":"pool1",'$POOL'},"2":{"name":"pool2",'$POOL'}}'
for p in pool2 2; do
r=0
$VITASTOR_CLI modify-pool $p --name pool1 || r=$?
if [[ $r != 17 ]]; then
format_error "modify-pool $p --name pool1 should fail with EEXIST (17), but exited with $r"
fi
done
names=$($ETCDCTL get --print-value-only /vitastor/config/pools | jq -c '[ .[].name ]')
if [[ "$names" != '["pool1","pool2"]' ]]; then
format_error "Pool names should stay pool1, pool2, but they are $names"
fi
# A free name and the pool's own name are still accepted
$VITASTOR_CLI modify-pool pool2 --name pool3
$VITASTOR_CLI modify-pool pool3 --name pool3 --pg_count 2
cfg=$($ETCDCTL get --print-value-only /vitastor/config/pools | jq -c '[ .[] | [ .name, .pg_count ] ]')
if [[ "$cfg" != '[["pool1",1],["pool3",2]]' ]]; then
format_error "Pools should be pool1 (1 PG) and pool3 (2 PGs), but they are $cfg"
fi
# Test that create-pool and modify-pool refuse pg_size > 64, which OSDs and clients don't support
$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