Makes fix to autodetect moved files and use them in recovering.

This commit is contained in:
Andrea Mazzoleni 2014-10-19 22:25:30 +02:00
parent 98deb4ba91
commit 447f1f1294
12 changed files with 132 additions and 66 deletions

View file

@ -92,10 +92,12 @@ struct snapraid_filter {
* data used to compute the parity, because the sync process was interrupted at an unknown point,
* and the parity may or may not be updated.
*
* For this reson we clear all such hashes when reading the state from an incomplete sync when
* starting a new sync, because sync is affected by sych hashes.
* Check and fix are instead able to work with unsynced hashes.
* Scrub is not affected because it ignores CHG/DELETED blocks.
* For this reson we clear all such hashes when reading the state from an incomplete sync before
* starting a new sync, because sync is affected by such hashes, as sync updates the parity, only
* if the new data read for CHG blocks has a mismatching hash.
* Clearing is done setting the ::clear_past_hash flag before reading the state.
* No clearing is done in other commands, as check and fix are instead able to work with unsynced
* hashes, and scrub ignores CHG/DELETED blocks.
*/
#define BLOCK_STATE_CHG 2
@ -103,6 +105,15 @@ struct snapraid_filter {
* The block is new and hashed.
* This happens when a new block overwrite a just removed block, or an empty space.
*
* Note that when the file copy heuristic is enabled, the REP blocks may be set
* using this euristic, meaning that the hash may be wrong.
*
* For this reason, when the ::force_nocopy flag is enabled in sync, we convert all the REP blocks
* to CHG, invalidating the stored hash.
* Clearing is done setting the ::clear_past_hash flag before reading the state.
* No cleaering is done in other commands, as they don't stop the process like in sync
* when there is a false silent error.
*
* The block hash field IS set, and it represents the hash of the new data.
* The parity for this disk is not updated.
*/
@ -120,10 +131,12 @@ struct snapraid_filter {
* data used to compute the parity, because the sync process was interrupted at an unknown point,
* and the parity may or may not be updated.
*
* For this reson we clear all such hashes when reading the state from an incomplete sync when
* starting a new sync, because sync is affected by sych hashes.
* Check and fix are instead able to work with unsynced hashes.
* Scrub is not affected because it ignores CHG/DELETED blocks.
* A now the sync process is not affected by DELETED hash, so clearing won't be really needed,
* but considering that we have to do it for CHG blocks, we do it also for DELETED ones,
* clearing all the past hashes.
* Clearing is done setting the ::clear_past_hash flag before reading the state.
* No clearing is done in other commands, as check and fix are instead able to work with unsynced
* hashes, and scrub ignores CHG/DELETED blocks.
*/
#define BLOCK_STATE_DELETED 4

View file

@ -238,3 +238,17 @@ void state_search(struct snapraid_state* state, const char* dir)
search_dir(state, dir);
}
void state_search_array(struct snapraid_state* state)
{
tommy_node* i;
/* import from all the disks */
for (i = state->disklist; i != 0; i = i->next) {
struct snapraid_disk* disk = i->data;
printf("Scanning disk %s...\n", disk->name);
search_dir(state, disk->dir);
}
}

View file

@ -55,5 +55,10 @@ int state_search_fetch(struct snapraid_state* state, int prevhash, struct snapra
*/
void state_search(struct snapraid_state* state, const char* dir);
/**
* Import files from all the data disks.
*/
void state_search_array(struct snapraid_state* state);
#endif

View file

@ -722,6 +722,20 @@ int main(int argc, char* argv[])
}
}
switch (operation) {
case OPERATION_SYNC :
case OPERATION_CHECK :
case OPERATION_FIX :
break;
default :
if (opt.force_nocopy) {
/* LCOV_EXCL_START */
fprintf(stderr, "You cannot use -N, --force-nocopy with the '%s' command\n", command);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
switch (operation) {
case OPERATION_SYNC :
break;
@ -733,13 +747,6 @@ int main(int argc, char* argv[])
/* LCOV_EXCL_STOP */
}
if (opt.force_nocopy) {
/* LCOV_EXCL_START */
fprintf(stderr, "You cannot use -N, --force-nocopy with the '%s' command\n", command);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
if (opt.force_full) {
/* LCOV_EXCL_START */
fprintf(stderr, "You cannot use -G, --force-full with the '%s' command\n", command);
@ -1027,10 +1034,18 @@ int main(int argc, char* argv[])
} else {
state_read(&state);
if (import_timestamp != 0)
state_search(&state, import_timestamp);
if (import_content != 0)
state_import(&state, import_content);
/* if we are also trying to recover */
if (!state.opt.auditonly) {
/* import the user specified dirs */
if (import_timestamp != 0)
state_search(&state, import_timestamp);
if (import_content != 0)
state_import(&state, import_content);
/* import from all the array */
if (!state.opt.force_nocopy)
state_search_array(&state);
}
/* apply the command line filter */
state_filter(&state, &filterlist_file, &filterlist_disk, filter_missing, filter_error);

View file

@ -1356,7 +1356,10 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE
/* if we are disabling the copy optimization */
/* we want also to clear any already previously stored information */
/* in other sync commands */
if (state->opt.force_nocopy
/* note that this is required only in sync, and we detect */
/* this using the clear_past_hash flag */
if (state->clear_past_hash
&& state->opt.force_nocopy
&& block_state_get(block) == BLOCK_STATE_REP
) {
/* set the hash value to INVALID */
@ -2880,7 +2883,10 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST
/* if we are disabling the copy optimization */
/* we want also to clear any already previously stored information */
/* in other sync commands */
if (state->opt.force_nocopy
/* note that this is required only in sync, and we detect */
/* this using the clear_past_hash flag */
if (state->clear_past_hash
&& state->opt.force_nocopy
&& block_state_get(block) == BLOCK_STATE_REP
) {
/* set the hash value to INVALID */

View file

@ -479,7 +479,7 @@ static int state_sync_process(struct snapraid_state* state, struct snapraid_pari
/* it could happens that all the blocks are EMPTY/BLK and CHG but with the hash */
/* still matching because the specific CHG block was not modified. */
/* Note that CHG/DELETED blocks already present in the content file loaded */
/* have the hash cleared, and then they won't never match the hash. */
/* have the hash cleared (::clear_past_hash flag), and then they won't never match the hash. */
/* We are treating only CHG blocks created at runtime. */
/* In such case, we can avoid to update parity, because it would be the same as before */
parity_needs_to_be_updated = 0;