mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-20 06:56:28 -05:00
Add regression test for multi parity
This commit is contained in:
parent
0fba4722c0
commit
bec310d50b
18 changed files with 91 additions and 65 deletions
|
|
@ -1947,7 +1947,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
|
|||
}
|
||||
|
||||
parity_ptr[l] = &parity[l];
|
||||
ret = parity_create(parity_ptr[l], &state->parity[l], l, state->file_mode);
|
||||
ret = parity_create(parity_ptr[l], &state->parity[l], l, state->file_mode, state->opt.parity_limit_size);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("WARNING! Without an accessible %s file, it isn't possible to fix any error.\n", lev_name(l));
|
||||
|
|
@ -1968,7 +1968,7 @@ int state_check(struct snapraid_state* state, int fix, block_off_t blockstart, b
|
|||
/* it may fail if the file doesn't exist, in this case we continue to check the files */
|
||||
for (l = 0; l < state->level; ++l) {
|
||||
parity_ptr[l] = &parity[l];
|
||||
ret = parity_open(parity_ptr[l], &state->parity[l], l, state->file_mode);
|
||||
ret = parity_open(parity_ptr[l], &state->parity[l], l, state->file_mode, state->opt.parity_limit_size);
|
||||
if (ret == -1) {
|
||||
msg_status("No accessible %s file, only files will be checked.\n", lev_name(l));
|
||||
/* continue anyway */
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ void state_dry(struct snapraid_state* state, block_off_t blockstart, block_off_t
|
|||
/* open the file for reading */
|
||||
/* it may fail if the file doesn't exist, in this case we continue to dry the files */
|
||||
for (l = 0; l < state->level; ++l) {
|
||||
ret = parity_open(&parity_handle[l], &state->parity[l], l, state->file_mode);
|
||||
ret = parity_open(&parity_handle[l], &state->parity[l], l, state->file_mode, state->opt.parity_limit_size);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("WARNING! Without an accessible %s file, it isn't possible to dry.\n", lev_name(l));
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@
|
|||
#include "parity.h"
|
||||
#include "handle.h"
|
||||
|
||||
/**
|
||||
* Pseudo random limits for parity
|
||||
*/
|
||||
#define PARITY_LIMIT(size,split,level) \
|
||||
size ? size + (123562341 + split * 634542351 + level * 983491341) % size : 0
|
||||
|
||||
/****************************************************************************/
|
||||
/* parity */
|
||||
|
||||
|
|
@ -178,7 +184,7 @@ void parity_size(struct snapraid_parity_handle* handle, data_off_t* out_size)
|
|||
*out_size = size;
|
||||
}
|
||||
|
||||
int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode)
|
||||
int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode, uint64_t limit_size)
|
||||
{
|
||||
unsigned s;
|
||||
|
||||
|
|
@ -194,6 +200,7 @@ int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_p
|
|||
pathcpy(split->path, sizeof(split->path), parity->split_map[s].path);
|
||||
split->f = -1;
|
||||
split->size = parity->split_map[s].size;
|
||||
split->limit_size = PARITY_LIMIT(limit_size, s, level);
|
||||
++handle->split_mac;
|
||||
|
||||
/* opening in sequential mode in Windows */
|
||||
|
|
@ -248,6 +255,10 @@ static int parity_handle_grow(struct snapraid_split_handle* split, data_off_t si
|
|||
{
|
||||
int ret;
|
||||
|
||||
/* simulate a failure for testing limits */
|
||||
if (split->limit_size != 0 && size > (data_off_t)split->limit_size)
|
||||
return -1;
|
||||
|
||||
#if HAVE_FALLOCATE
|
||||
if (!skip_fallocate) {
|
||||
/*
|
||||
|
|
@ -500,7 +511,7 @@ int parity_chsize(struct snapraid_parity_handle* handle, struct snapraid_parity*
|
|||
return 0;
|
||||
}
|
||||
|
||||
int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode)
|
||||
int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode, uint64_t limit_size)
|
||||
{
|
||||
unsigned s;
|
||||
|
||||
|
|
@ -516,6 +527,7 @@ int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_par
|
|||
pathcpy(split->path, sizeof(split->path), parity->split_map[s].path);
|
||||
split->f = -1;
|
||||
split->size = parity->split_map[s].size;
|
||||
split->limit_size = PARITY_LIMIT(limit_size, s, level);
|
||||
++handle->split_mac;
|
||||
|
||||
/* open for read */
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ struct snapraid_split_handle {
|
|||
* Note that this value CANNOT be PARITY_SIZE_INVALID.
|
||||
*/
|
||||
uint64_t size;
|
||||
|
||||
/**
|
||||
* Artificial size limit for testing.
|
||||
* 0 means unlimited.
|
||||
*/
|
||||
uint64_t limit_size;
|
||||
};
|
||||
|
||||
struct snapraid_parity_handle {
|
||||
|
|
@ -78,12 +84,11 @@ int parity_is_invalid(struct snapraid_state* state);
|
|||
*/
|
||||
void parity_overflow(struct snapraid_state* state, data_off_t size);
|
||||
|
||||
|
||||
/**
|
||||
* Create the parity file.
|
||||
* \param out_size Return the size of the parity file.
|
||||
*/
|
||||
int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode);
|
||||
int parity_create(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode, uint64_t limit_size);
|
||||
|
||||
/**
|
||||
* Change the parity size.
|
||||
|
|
@ -101,7 +106,7 @@ void parity_size(struct snapraid_parity_handle* handle, data_off_t* out_size);
|
|||
/**
|
||||
* Open an already existing parity file.
|
||||
*/
|
||||
int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode);
|
||||
int parity_open(struct snapraid_parity_handle* handle, const struct snapraid_parity* parity, unsigned level, int mode, uint64_t limit_size);
|
||||
|
||||
/**
|
||||
* Flush the parity file in the disk.
|
||||
|
|
|
|||
|
|
@ -854,7 +854,7 @@ int state_scrub(struct snapraid_state* state, int plan, int olderthan)
|
|||
|
||||
/* open the file for reading */
|
||||
for (l = 0; l < state->level; ++l) {
|
||||
ret = parity_open(&parity_handle[l], &state->parity[l], l, state->file_mode);
|
||||
ret = parity_open(&parity_handle[l], &state->parity[l], l, state->file_mode, state->opt.parity_limit_size);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("WARNING! Without an accessible %s file, it isn't possible to scrub.\n", lev_name(l));
|
||||
|
|
|
|||
|
|
@ -290,6 +290,7 @@ void config(char* conf, size_t conf_size, const char* argv0)
|
|||
#define OPT_TEST_IO_ADVISE_DISCARD_8 298
|
||||
#define OPT_TEST_IO_ADVISE_DISCARD_32 299
|
||||
#define OPT_TEST_IO_ADVISE_DIRECT 300
|
||||
#define OPT_TEST_PARITY_LIMIT 301
|
||||
|
||||
#if HAVE_GETOPT_LONG
|
||||
struct option long_options[] = {
|
||||
|
|
@ -447,6 +448,9 @@ struct option long_options[] = {
|
|||
/* Set the io advise to direct */
|
||||
{ "test-io-advise-direct", 0, 0, OPT_TEST_IO_ADVISE_DIRECT },
|
||||
|
||||
/* Set an artificial parity limit */
|
||||
{ "test-parity-limit", 1, 0, OPT_TEST_PARITY_LIMIT },
|
||||
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
|
@ -867,6 +871,9 @@ int main(int argc, char* argv[])
|
|||
case OPT_TEST_IO_ADVISE_DIRECT :
|
||||
opt.file_mode = ADVISE_DIRECT;
|
||||
break;
|
||||
case OPT_TEST_PARITY_LIMIT :
|
||||
opt.parity_limit_size = atoll(optarg);
|
||||
break;
|
||||
default :
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("Unknown option '%c'\n", (char)c);
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ struct snapraid_option {
|
|||
unsigned io_cache; /**< Number of IO buffers to use. 0 for default. */
|
||||
int auto_conf; /**< Allow to run without configuration file. */
|
||||
int force_stats; /**< Force stats print during process. */
|
||||
uint64_t parity_limit_size; /**< Test limit for parity files. */
|
||||
};
|
||||
|
||||
struct snapraid_state {
|
||||
|
|
|
|||
|
|
@ -1448,7 +1448,7 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
|
|||
block_off_t parityblocks;
|
||||
|
||||
/* create the file and open for writing */
|
||||
ret = parity_create(&parity_handle[l], &state->parity[l], l, state->file_mode);
|
||||
ret = parity_create(&parity_handle[l], &state->parity[l], l, state->file_mode, state->opt.parity_limit_size);
|
||||
if (ret == -1) {
|
||||
/* LCOV_EXCL_START */
|
||||
log_fatal("WARNING! Without an accessible %s file, it isn't possible to sync.\n", lev_name(l));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue