Implement crash-safe --force-full sync with persistent BLOCK_STATE_REBUILD
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
Build / build-freebsd (push) Waiting to run
Build / build-musl (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-08-28 12:11:05 +02:00
parent 1dab466ee6
commit 6363d44074
11 changed files with 273 additions and 43 deletions

View file

@ -43,6 +43,7 @@
* CHG OLD/ZERO/INVALID present may be OLD or CURRENT
* REP NEW present may be OLD or NEW
* DELETED OLD/INVALID none may be OLD or zero
* REBUILD CURRENT present parity untrusted / rebuild pending
*
* BLK has a hash for the data that should currently be present and normally
* represents a synchronized contribution.
@ -520,6 +521,7 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
case BLOCK_STATE_CHG : desc = "change"; break;
case BLOCK_STATE_REP : desc = "replace"; break;
case BLOCK_STATE_BLK : desc = "block"; break;
case BLOCK_STATE_REBUILD : desc = "rebuild"; break;
/* LCOV_EXCL_START */
default : desc = "unknown"; break;
/* LCOV_EXCL_STOP */
@ -588,7 +590,7 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
* A CHG hash identifies the OLD contents, so fetching data by that hash would
* not prove that we recovered the current version required by this strategy.
*/
if ((block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP)
if ((block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP || block_state == BLOCK_STATE_REBUILD)
/* try to fetch the block using the known hash */
&& (state_import_fetch(state, rehash, failed[j].block, buffer[failed[j].index]) == 0
|| state_search_fetch(state, rehash, failed[j].file, failed[j].file_pos, failed[j].block, buffer[failed[j].index]) == 0)
@ -633,7 +635,7 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
* we have already checked their hash
*/
if (block_state != BLOCK_STATE_CHG) {
assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP);
assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP || block_state == BLOCK_STATE_REBUILD);
continue;
}
@ -780,7 +782,7 @@ static int repair(struct snapraid_state* state, int rehash, block_off_t pos, uns
* At this point, we can have only BLK ones
*/
assert(block_state == BLOCK_STATE_BLK);
assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REBUILD);
/* we have something we are interested to recover */
something_to_recover = 1;
@ -1602,7 +1604,7 @@ static int state_check_process(struct snapraid_state* state, int fix, struct sna
continue;
}
assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP);
assert(block_state == BLOCK_STATE_BLK || block_state == BLOCK_STATE_REP || block_state == BLOCK_STATE_REBUILD);
/* compute the hash of the block just read */
if (rehash) {