From 1314f12d64e9d3fea942e9281bd58d789acd960a Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 15 Mar 2012 22:58:04 +0100 Subject: [PATCH] Changes come comments. No functionality change. --- check.c | 2 +- elem.h | 5 ++--- state.c | 14 ++++++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/check.c b/check.c index 83cec906..e0405958 100644 --- a/check.c +++ b/check.c @@ -314,7 +314,7 @@ static int repair(struct snapraid_state* state, unsigned pos, unsigned diskmax, memset(buffer[failed[j].index], 0, state->block_size); /* note that from now the buffer is definitively lost */ /* we can do this only because it's the last retry of recovering */ - + /* mark that we have restored an old state */ failed[j].is_outofdate = 1; } diff --git a/elem.h b/elem.h index 8a5a5bfe..f8923456 100644 --- a/elem.h +++ b/elem.h @@ -69,6 +69,8 @@ struct snapraid_file; /** * The block has both the hash and the parity computed. * This is the normal state of a saved block. + * Note that if exists at least one BLOCK_STATE_BLK in a disk, all the other + * blocks at the same address in other disks can be only BLOCK_EMPTY or BLOCK_STATE_BLK. */ #define BLOCK_STATE_BLK 0 @@ -80,9 +82,6 @@ struct snapraid_file; /** * The block has the hash computed, but the parity is invalid. * This happens when the parity is invalidated by a change in another block. - * Note that this state is almost reduntant because we can detect that the parity is invalid - * also checking the other disks, where for sure exists a block the BLOCK_STATE_CHG/NEW state - * or a BLOCK_DELETED block. */ #define BLOCK_STATE_INV 2 diff --git a/state.c b/state.c index 592bda8d..74b50cfa 100644 --- a/state.c +++ b/state.c @@ -563,7 +563,7 @@ static void state_content_check(struct snapraid_state* state, const char* path) } } - /* check the parity validity invariant */ + /* check the parity validity */ for(j=0;1;++j) { /* for all the blocks */ int at_least_one = 0; int parity_is_valid = 0; @@ -578,6 +578,7 @@ static void state_content_check(struct snapraid_state* state, const char* path) if (j < size) { struct snapraid_block* block = tommy_array_get(&disk->blockarr, j); + /* mark if at least one block is addressed */ at_least_one = 1; if (block == BLOCK_EMPTY) { @@ -585,16 +586,17 @@ static void state_content_check(struct snapraid_state* state, const char* path) } else if (block == BLOCK_DELETED) { parity_is_invalid = 1; } else { - switch (block_state_get(block)) { - case BLOCK_STATE_BLK : parity_is_valid = 1; break; - case BLOCK_STATE_NEW : parity_is_invalid = 1; break; - case BLOCK_STATE_INV : parity_is_invalid = 1; break; - case BLOCK_STATE_CHG : parity_is_invalid = 1; break; + unsigned state = block_state_get(block); + if (state == BLOCK_STATE_BLK) { + parity_is_valid = 1; + } else { + parity_is_invalid = 1; } } } } + /* we cannot have different blocks reporting both valid and invalid parity */ if (parity_is_valid && parity_is_invalid) { fprintf(stderr, "Internal inconsistency in parity validity at block %u\n", j); exit(EXIT_FAILURE);