mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 10:51:54 -04:00
Removes duplicate code introducing block_is_enabled().
This commit is contained in:
parent
2b4e6694ce
commit
47c2165f63
3 changed files with 92 additions and 119 deletions
|
|
@ -775,7 +775,7 @@ close_and_continue:
|
|||
/**
|
||||
* Check if we have to process the specified block index ::i.
|
||||
*/
|
||||
static int block_is_enabled(struct snapraid_state* state, unsigned i, struct snapraid_handle* handle, unsigned diskmax)
|
||||
static int block_is_enabled(struct snapraid_state* state, block_off_t i, struct snapraid_handle* handle, unsigned diskmax)
|
||||
{
|
||||
int one_tocheck;
|
||||
snapraid_info info;
|
||||
|
|
|
|||
124
cmdline/scrub.c
124
cmdline/scrub.c
|
|
@ -35,6 +35,53 @@ struct snapraid_rehash {
|
|||
struct snapraid_block* block;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if we have to process the specified block index ::i.
|
||||
*/
|
||||
static int block_is_enabled(struct snapraid_state* state, block_off_t i, time_t timelimit, block_off_t lastlimit, block_off_t* countlast)
|
||||
{
|
||||
time_t blocktime;
|
||||
snapraid_info info;
|
||||
|
||||
/* if it's unused */
|
||||
info = info_get(&state->infoarr, i);
|
||||
if (info == 0) {
|
||||
/* skip it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* blocks marked as bad are always checked */
|
||||
if (!info_get_bad(info)) {
|
||||
|
||||
/* if it's too new */
|
||||
blocktime = info_get_time(info);
|
||||
if (blocktime > timelimit) {
|
||||
/* skip it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* skip odd blocks, used only for testing */
|
||||
if (state->opt.force_scrub_even && (i % 2) != 0) {
|
||||
/* skip it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* if the time is less than the limit, always include */
|
||||
/* otherwise, check if we reached the last limit count */
|
||||
if (blocktime == timelimit) {
|
||||
/* if we reached the count limit */
|
||||
if (*countlast >= lastlimit) {
|
||||
/* skip it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
++*countlast;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int state_scrub_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax, time_t timelimit, block_off_t lastlimit, time_t now)
|
||||
{
|
||||
struct snapraid_handle* handle;
|
||||
|
|
@ -80,44 +127,8 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
countmax = 0;
|
||||
countlast = 0;
|
||||
for (i = blockstart; i < blockmax; ++i) {
|
||||
time_t blocktime;
|
||||
snapraid_info info;
|
||||
|
||||
/* if it's unused */
|
||||
info = info_get(&state->infoarr, i);
|
||||
if (info == 0) {
|
||||
/* skip it */
|
||||
if (!block_is_enabled(state, i, timelimit, lastlimit, &countlast))
|
||||
continue;
|
||||
}
|
||||
|
||||
/* blocks marked as bad are always checked */
|
||||
if (!info_get_bad(info)) {
|
||||
|
||||
/* if it's too new */
|
||||
blocktime = info_get_time(info);
|
||||
if (blocktime > timelimit) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip odd blocks, used only for testing */
|
||||
if (state->opt.force_scrub_even && (i % 2) != 0) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* if the time is less than the limit, always include */
|
||||
/* otherwise, check if we reached the last limit count */
|
||||
if (blocktime == timelimit) {
|
||||
/* if we reached the count limit */
|
||||
if (countlast >= lastlimit) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
++countlast;
|
||||
}
|
||||
}
|
||||
|
||||
++countmax;
|
||||
}
|
||||
|
|
@ -137,48 +148,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
countlast = 0;
|
||||
state_progress_begin(state, blockstart, blockmax, countmax);
|
||||
for (i = blockstart; i < blockmax; ++i) {
|
||||
time_t blocktime;
|
||||
snapraid_info info;
|
||||
int error_on_this_block;
|
||||
int silent_error_on_this_block;
|
||||
int block_is_unsynced;
|
||||
int rehash;
|
||||
|
||||
/* if it's unused */
|
||||
info = info_get(&state->infoarr, i);
|
||||
if (info == 0) {
|
||||
/* skip it */
|
||||
if (!block_is_enabled(state, i, timelimit, lastlimit, &countlast))
|
||||
continue;
|
||||
}
|
||||
|
||||
/* blocks marked as bad are always checked */
|
||||
if (!info_get_bad(info)) {
|
||||
|
||||
/* if it's too new */
|
||||
blocktime = info_get_time(info);
|
||||
if (blocktime > timelimit) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* skip odd blocks, used only for testing */
|
||||
if (state->opt.force_scrub_even && (i % 2) != 0) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* if the time is less than the limit, always include */
|
||||
/* otherwise, check if we reached the last limit count */
|
||||
if (blocktime == timelimit) {
|
||||
/* if we reached the count limit */
|
||||
if (countlast >= lastlimit) {
|
||||
/* skip it */
|
||||
continue;
|
||||
}
|
||||
|
||||
++countlast;
|
||||
}
|
||||
}
|
||||
|
||||
/* one more block processed for autosave */
|
||||
++autosavedone;
|
||||
|
|
@ -192,6 +169,9 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par
|
|||
/* if not, parity is not even checked */
|
||||
block_is_unsynced = 0;
|
||||
|
||||
/* get block specific info */
|
||||
info = info_get(&state->infoarr, i);
|
||||
|
||||
/* if we have to use the old hash */
|
||||
rehash = info_get_rehash(info);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
for (j = 0; j < diskmax; ++j) {
|
||||
struct snapraid_disk* disk = handle[j].disk;
|
||||
|
||||
/* if unused disk skip it */
|
||||
/* if no disk, nothing to check */
|
||||
if (!disk)
|
||||
continue;
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ static int state_hash_process(struct snapraid_state* state, block_off_t blocksta
|
|||
for (j = 0; j < diskmax; ++j) {
|
||||
struct snapraid_disk* disk = handle[j].disk;
|
||||
|
||||
/* if unused disk skip it */
|
||||
/* if no disk, nothing to check */
|
||||
if (!disk)
|
||||
continue;
|
||||
|
||||
|
|
@ -369,6 +369,41 @@ struct snapraid_rehash {
|
|||
struct snapraid_block* block;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if we have to process the specified block index ::i.
|
||||
*/
|
||||
static int block_is_enabled(block_off_t i, struct snapraid_handle* handle, unsigned diskmax)
|
||||
{
|
||||
unsigned j;
|
||||
int one_invalid;
|
||||
int one_valid;
|
||||
|
||||
/* for each disk */
|
||||
one_invalid = 0;
|
||||
one_valid = 0;
|
||||
for (j = 0; j < diskmax; ++j) {
|
||||
struct snapraid_block* block;
|
||||
|
||||
/* if no disk, nothing to check */
|
||||
if (!handle[j].disk)
|
||||
continue;
|
||||
|
||||
block = disk_block_get(handle[j].disk, i);
|
||||
|
||||
if (block_has_file(block))
|
||||
one_valid = 1;
|
||||
|
||||
if (block_has_invalid_parity(block))
|
||||
one_invalid = 1;
|
||||
}
|
||||
|
||||
/* if none valid or none invalid, we don't need to update */
|
||||
if (!one_invalid || !one_valid)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int state_sync_process(struct snapraid_state* state, struct snapraid_parity_handle** parity, block_off_t blockstart, block_off_t blockmax)
|
||||
{
|
||||
struct snapraid_handle* handle;
|
||||
|
|
@ -429,30 +464,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
/* first count the number of blocks to process */
|
||||
countmax = 0;
|
||||
for (i = blockstart; i < blockmax; ++i) {
|
||||
int one_invalid;
|
||||
int one_valid;
|
||||
|
||||
/* for each disk */
|
||||
one_invalid = 0;
|
||||
one_valid = 0;
|
||||
for (j = 0; j < diskmax; ++j) {
|
||||
struct snapraid_block* block = BLOCK_EMPTY;
|
||||
if (handle[j].disk)
|
||||
block = disk_block_get(handle[j].disk, i);
|
||||
|
||||
if (block_has_file(block)) {
|
||||
one_valid = 1;
|
||||
}
|
||||
if (block_has_invalid_parity(block)) {
|
||||
one_invalid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* if none valid or none invalid, we don't need to update */
|
||||
if (!one_invalid || !one_valid) {
|
||||
if (!block_is_enabled(i, handle, diskmax))
|
||||
continue;
|
||||
}
|
||||
|
||||
++countmax;
|
||||
}
|
||||
|
||||
|
|
@ -473,8 +486,6 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
|
||||
for (i = blockstart; i < blockmax; ++i) {
|
||||
unsigned failed_count;
|
||||
int one_invalid;
|
||||
int one_valid;
|
||||
int error_on_this_block;
|
||||
int silent_error_on_this_block;
|
||||
int fixed_error_on_this_block;
|
||||
|
|
@ -482,26 +493,8 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
|
|||
snapraid_info info;
|
||||
int rehash;
|
||||
|
||||
/* for each disk */
|
||||
one_invalid = 0;
|
||||
one_valid = 0;
|
||||
for (j = 0; j < diskmax; ++j) {
|
||||
struct snapraid_block* block = BLOCK_EMPTY;
|
||||
if (handle[j].disk)
|
||||
block = disk_block_get(handle[j].disk, i);
|
||||
|
||||
if (block_has_file(block)) {
|
||||
one_valid = 1;
|
||||
}
|
||||
if (block_has_invalid_parity(block)) {
|
||||
one_invalid = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* if none valid or none invalid, we don't need to update */
|
||||
if (!one_invalid || !one_valid) {
|
||||
if (!block_is_enabled(i, handle, diskmax))
|
||||
continue;
|
||||
}
|
||||
|
||||
/* one more block processed for autosave */
|
||||
++autosavedone;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue