Adds the new -F, --force-full option to force a full sync.

This commit is contained in:
Andrea Mazzoleni 2014-06-15 19:01:07 +02:00
parent 8c750d0039
commit c6a3742b40
8 changed files with 109 additions and 10 deletions

View file

@ -65,6 +65,7 @@ void usage(void)
printf(" " SWITCH_GETOPT_LONG("-U, --force-uuid ", "-U") " Force commands on disks with uuid changed\n");
printf(" " SWITCH_GETOPT_LONG("-D, --force-device ", "-D") " Force commands on disks with same device id\n");
printf(" " SWITCH_GETOPT_LONG("-N, --force-nocopy ", "-N") " Force commands disabling the copy detection\n");
printf(" " SWITCH_GETOPT_LONG("-F, --force-full ", "-F") " Force commands requiring a full sync\n");
printf(" " SWITCH_GETOPT_LONG("-s, --start BLKSTART ", "-s") " Start from the specified block number\n");
printf(" " SWITCH_GETOPT_LONG("-t, --count BLKCOUNT ", "-t") " Count of block to process\n");
printf(" " SWITCH_GETOPT_LONG("-v, --verbose ", "-v") " Verbose\n");
@ -251,6 +252,7 @@ struct option long_options[] = {
{ "force-uuid", 0, 0, 'U' },
{ "force-device", 0, 0, 'D' },
{ "force-nocopy", 0, 0, 'N' },
{ "force-full", 0, 0, 'F' },
{ "audit-only", 0, 0, 'a' },
{ "pre-hash", 0, 0, 'h' },
{ "speed-test", 0, 0, 'T' },
@ -330,7 +332,7 @@ struct option long_options[] = {
};
#endif
#define OPTIONS "c:f:d:mep:o:s:t:i:l:ZEUDNahTC:vqHVG"
#define OPTIONS "c:f:d:mep:o:s:t:i:l:ZEUDNFahTC:vqHVG"
volatile int global_interrupt = 0;
@ -516,6 +518,9 @@ int main(int argc, char* argv[])
case 'N' :
opt.force_nocopy = 1;
break;
case 'F' :
opt.force_full = 1;
break;
case 'a' :
opt.auditonly = 1;
break;
@ -693,6 +698,34 @@ int main(int argc, char* argv[])
exit(EXIT_FAILURE);
/* 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);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
if (opt.force_full && opt.force_nocopy) {
/* LCOV_EXCL_START */
fprintf(stderr, "You cannot use the -F, --force-full and -N, --force-nocopy options at the same time\n");
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
if (opt.prehash && opt.force_nocopy) {
/* LCOV_EXCL_START */
fprintf(stderr, "You cannot use the -h, --pre-hash and -N, --force-nocopy options at the same time\n");
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
switch (operation) {

View file

@ -1363,6 +1363,15 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE
block_state_set(block, BLOCK_STATE_CHG);
}
/* if we want a full sync, marks block as invalid parity */
/* note that we do this after the force_nocopy option */
/* to avoid to mixup the two things */
if (state->opt.force_full
&& block_state_get(block) == BLOCK_STATE_BLK) {
/* convert from BLK to REP */
block_state_set(block, BLOCK_STATE_REP);
}
/* we must not overwrite existing blocks */
if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
/* LCOV_EXCL_START */
@ -2861,6 +2870,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST
block_state_set(block, BLOCK_STATE_CHG);
}
/* if we want a full sync, marks block as invalid parity */
/* note that we do this after the force_nocopy option */
/* to avoid to mixup the two things */
if (state->opt.force_full
&& block_state_get(block) == BLOCK_STATE_BLK) {
/* convert from BLK to REP */
block_state_set(block, BLOCK_STATE_REP);
}
/* we must not overwrite existing blocks */
if (disk_block_get(disk, v_pos) != BLOCK_EMPTY) {
/* LCOV_EXCL_START */

View file

@ -66,6 +66,7 @@ struct snapraid_option {
int force_uuid; /**< Forced dangerous operations of synching disks with uuid changed. */
int force_device; /**< Forced dangerous operations of using disks with save device id. */
int force_nocopy; /**< Force dangerous operations of synching files without using copy detection. */
int force_full; /**< Force a full sync when using an old content file. */
int expect_unrecoverable; /**< Expect presence of unrecoverable error in checking or fixing. */
int expect_recoverable; /**< Expect presence of recoverable error in checking. */
int skip_device; /**< Skip devices matching checks. */

View file

@ -1017,12 +1017,18 @@ int state_sync(struct snapraid_state* state, block_off_t blockstart, block_off_t
/* LCOV_EXCL_STOP */
}
/* if the file is too small */
if (out_size < loaded_size) {
/* LCOV_EXCL_START */
fprintf(stderr, "DANGER! The %s file %s is smaller than the expected %" PRId64 ".\n", lev_name(l), state->parity_path[l], loaded_size);
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
/* if we do a full sync, having a wrong parity size is expected */
if (!state->opt.force_full) {
/* if the file is too small */
if (out_size < loaded_size) {
/* LCOV_EXCL_START */
fprintf(stderr, "DANGER! The %s file %s is smaller than the expected %" PRId64 ".\n", lev_name(l), state->parity_path[l], loaded_size);
fprintf(stderr, "If this happens because you are using an old content file,\n");
fprintf(stderr, "you can 'sync' anyway using 'snapraid --force-full sync'\n");
fprintf(stderr, "to force a full rebuild of the parity.\n");
exit(EXIT_FAILURE);
/* LCOV_EXCL_STOP */
}
}
/* change the size of the parity file, truncating or extending it */