Changes come comments. No functionality change.

This commit is contained in:
Andrea Mazzoleni 2012-03-15 22:58:04 +01:00
parent 04a8a94f9e
commit 1314f12d64
3 changed files with 11 additions and 10 deletions

View file

@ -314,7 +314,7 @@ static int repair(struct snapraid_state* state, unsigned pos, unsigned diskmax,
memset(buffer[failed[j].index], 0, state->block_size); memset(buffer[failed[j].index], 0, state->block_size);
/* note that from now the buffer is definitively lost */ /* note that from now the buffer is definitively lost */
/* we can do this only because it's the last retry of recovering */ /* we can do this only because it's the last retry of recovering */
/* mark that we have restored an old state */ /* mark that we have restored an old state */
failed[j].is_outofdate = 1; failed[j].is_outofdate = 1;
} }

5
elem.h
View file

@ -69,6 +69,8 @@ struct snapraid_file;
/** /**
* The block has both the hash and the parity computed. * The block has both the hash and the parity computed.
* This is the normal state of a saved block. * 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 #define BLOCK_STATE_BLK 0
@ -80,9 +82,6 @@ struct snapraid_file;
/** /**
* The block has the hash computed, but the parity is invalid. * The block has the hash computed, but the parity is invalid.
* This happens when the parity is invalidated by a change in another block. * 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 #define BLOCK_STATE_INV 2

14
state.c
View file

@ -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 */ for(j=0;1;++j) { /* for all the blocks */
int at_least_one = 0; int at_least_one = 0;
int parity_is_valid = 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) { if (j < size) {
struct snapraid_block* block = tommy_array_get(&disk->blockarr, j); struct snapraid_block* block = tommy_array_get(&disk->blockarr, j);
/* mark if at least one block is addressed */
at_least_one = 1; at_least_one = 1;
if (block == BLOCK_EMPTY) { 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) { } else if (block == BLOCK_DELETED) {
parity_is_invalid = 1; parity_is_invalid = 1;
} else { } else {
switch (block_state_get(block)) { unsigned state = block_state_get(block);
case BLOCK_STATE_BLK : parity_is_valid = 1; break; if (state == BLOCK_STATE_BLK) {
case BLOCK_STATE_NEW : parity_is_invalid = 1; break; parity_is_valid = 1;
case BLOCK_STATE_INV : parity_is_invalid = 1; break; } else {
case BLOCK_STATE_CHG : parity_is_invalid = 1; break; parity_is_invalid = 1;
} }
} }
} }
} }
/* we cannot have different blocks reporting both valid and invalid parity */
if (parity_is_valid && parity_is_invalid) { if (parity_is_valid && parity_is_invalid) {
fprintf(stderr, "Internal inconsistency in parity validity at block %u\n", j); fprintf(stderr, "Internal inconsistency in parity validity at block %u\n", j);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);