mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-28 19:06:42 -05:00
Change "diff" to return an error if a "sync" is required
This commit is contained in:
parent
7e06c8eefa
commit
83d967e2c0
11 changed files with 104 additions and 16 deletions
|
|
@ -78,6 +78,39 @@ block_off_t parity_used_size(struct snapraid_state* state)
|
|||
return parity_block;
|
||||
}
|
||||
|
||||
int parity_is_invalid(struct snapraid_state* state)
|
||||
{
|
||||
block_off_t blockmax;
|
||||
block_off_t i;
|
||||
|
||||
blockmax = parity_allocated_size(state);
|
||||
|
||||
for (i = 0; i < blockmax; ++i) {
|
||||
tommy_node* node_disk;
|
||||
int one_invalid;
|
||||
int one_valid;
|
||||
|
||||
/* for each disk */
|
||||
one_invalid = 0;
|
||||
one_valid = 0;
|
||||
for (node_disk = state->disklist; node_disk != 0; node_disk = node_disk->next) {
|
||||
struct snapraid_disk* disk = node_disk->data;
|
||||
struct snapraid_block* block = disk_block_get(disk, i);
|
||||
|
||||
if (block_has_file(block))
|
||||
one_valid = 1;
|
||||
if (block_has_invalid_parity(block))
|
||||
one_invalid = 1;
|
||||
}
|
||||
|
||||
/* if both valid and invalid, we need to update */
|
||||
if (one_invalid && one_valid)
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void parity_overflow(struct snapraid_state* state, data_off_t size)
|
||||
{
|
||||
tommy_node* i;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,20 @@ block_off_t parity_allocated_size(struct snapraid_state* state);
|
|||
*/
|
||||
block_off_t parity_used_size(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Checks if the parity needs to be updated with a "sync".
|
||||
*
|
||||
* This is the same logic used in "status" to detect an incomplete "sync",
|
||||
* that ignores invalid block, if they are not used by a file in any disk.
|
||||
* This means that DELETED blocks won't necessarely imply an invalid parity.
|
||||
*/
|
||||
int parity_is_invalid(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* If parity has some
|
||||
*/
|
||||
int parity_is_invalid(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Reports all the files outside the specified parity size.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "support.h"
|
||||
#include "elem.h"
|
||||
#include "state.h"
|
||||
#include "parity.h"
|
||||
|
||||
struct snapraid_scan {
|
||||
struct snapraid_state* state; /**< State used. */
|
||||
|
|
@ -1340,7 +1341,7 @@ static int scan_dir(struct snapraid_scan* scan, int is_diff, const char* dir, co
|
|||
return processed;
|
||||
}
|
||||
|
||||
void state_scan(struct snapraid_state* state, int is_diff)
|
||||
static int state_diffscan(struct snapraid_state* state, int is_diff)
|
||||
{
|
||||
tommy_node* i;
|
||||
tommy_node* j;
|
||||
|
|
@ -1743,5 +1744,27 @@ void state_scan(struct snapraid_state* state, int is_diff)
|
|||
msg_flush();
|
||||
|
||||
tommy_list_foreach(&scanlist, (tommy_foreach_func*)free);
|
||||
|
||||
if (is_diff) {
|
||||
/* check for file difference */
|
||||
if (!no_difference)
|
||||
return -1;
|
||||
|
||||
/* check also for incomplete "sync" */
|
||||
if (parity_is_invalid(state))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int state_diff(struct snapraid_state* state)
|
||||
{
|
||||
return state_diffscan(state, 1);
|
||||
}
|
||||
|
||||
void state_scan(struct snapraid_state* state)
|
||||
{
|
||||
(void)state_diffscan(state, 0); /* ignore return value */
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -957,7 +957,14 @@ int main(int argc, char* argv[])
|
|||
if (operation == OPERATION_DIFF) {
|
||||
state_read(&state);
|
||||
|
||||
state_scan(&state, 1);
|
||||
ret = state_diff(&state);
|
||||
|
||||
/* abort if required */
|
||||
if (ret != 0) {
|
||||
/* LCOV_EXCL_START */
|
||||
exit(EXIT_FAILURE);
|
||||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
} else if (operation == OPERATION_SYNC) {
|
||||
|
||||
/* in the next state read ensures to clear all the past hashes in case */
|
||||
|
|
@ -970,7 +977,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
state_read(&state);
|
||||
|
||||
state_scan(&state, 0);
|
||||
state_scan(&state);
|
||||
|
||||
/* refresh the size info before the content write */
|
||||
state_refresh(&state);
|
||||
|
|
|
|||
|
|
@ -191,10 +191,15 @@ void state_read(struct snapraid_state* state);
|
|||
*/
|
||||
void state_write(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Diff all the disks.
|
||||
*/
|
||||
int state_diff(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Scans all the disks to update the state.
|
||||
*/
|
||||
void state_scan(struct snapraid_state* state, int is_diff);
|
||||
void state_scan(struct snapraid_state* state);
|
||||
|
||||
/**
|
||||
* Sets the nanosecond timestamp of all files that have a zero value.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue