Checks that filter disks match at least one disk.

This commit is contained in:
Andrea Mazzoleni 2013-10-30 21:45:53 +01:00
parent 164477e4be
commit 185d3a4a18
5 changed files with 31 additions and 33 deletions

3
TODO
View file

@ -5,9 +5,6 @@ This is the list of TODO items for SnapRAID.
- Next
* When using the -d option, ensure that the specified disk name really
exists.
* Detect files moved from one disk to another. We won't be able to reuse
parity, but we can reuse the hash to check that the file was moved
correctly.

34
check.c
View file

@ -1002,9 +1002,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix,
}
fprintf(stdlog, "status:unrecoverable:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
printf("Unrecoverable '%s'\n", path);
}
printf("unrecoverable %s\n", path);
/* and do not set the time if damaged */
continue;
@ -1017,9 +1015,7 @@ static int state_check_process(struct snapraid_state* state, int check, int fix,
}
fprintf(stdlog, "status:recovered:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
printf("recovered %s\n", path);
}
printf("recovered %s\n", path);
inode = handle[j].st.st_ino;
@ -1059,20 +1055,14 @@ static int state_check_process(struct snapraid_state* state, int check, int fix,
if (file_flag_has(file, FILE_IS_DAMAGED)) {
if (!check) {
fprintf(stdlog, "status:damaged:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
printf("damaged %s\n", path);
}
printf("damaged %s\n", path);
} else {
fprintf(stdlog, "status:unrecoverable:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
printf("unrecoverable %s\n", path);
}
printf("unrecoverable %s\n", path);
}
} else if (file_flag_has(file, FILE_IS_FIXED)) {
fprintf(stdlog, "status:recoverable:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
printf("recoverable %s\n", path);
}
printf("recoverable %s\n", path);
} else {
fprintf(stdlog, "status:correct:%s:%s\n", handle[j].disk->name, file->sub);
if (state->opt.verbose) {
@ -1205,9 +1195,7 @@ close_and_continue:
++recovered_error;
fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, file->sub);
if (state->opt.verbose) {
printf("recovered %s%s\n", disk->dir, file->sub);
}
printf("recovered %s%s\n", disk->dir, file->sub);
}
}
@ -1370,9 +1358,7 @@ close_and_continue:
}
fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, link->sub);
if (state->opt.verbose) {
printf("recovered %s%s\n", disk->dir, link->sub);
}
printf("recovered %s%s\n", disk->dir, link->sub);
}
}
@ -1437,10 +1423,8 @@ close_and_continue:
fprintf(stdlog, "dir_fixed:%s:%s: Fixed dir error\n", disk->name, dir->sub);
++recovered_error;
fprintf(stdlog, "status:ok:%s:%s\n", disk->name, dir->sub);
if (state->opt.verbose) {
printf("recovered %s%s\n", disk->dir, dir->sub);
}
fprintf(stdlog, "status:recovered:%s:%s\n", disk->name, dir->sub);
printf("recovered %s%s\n", disk->dir, dir->sub);
}
}
}

View file

@ -554,7 +554,7 @@ int main(int argc, char* argv[])
state_init(&state);
/* read the configuration file */
state_config(&state, conf, command, &opt);
state_config(&state, conf, command, &opt, &filterlist_disk);
#if HAVE_LOCKFILE
/* create the lock file */

23
state.c
View file

@ -112,7 +112,7 @@ void state_done(struct snapraid_state* state)
/**
* Checks the configuration.
*/
static void state_config_check(struct snapraid_state* state, const char* path)
static void state_config_check(struct snapraid_state* state, const char* path, tommy_list* filterlist_disk)
{
tommy_node* i;
unsigned l;
@ -273,9 +273,26 @@ static void state_config_check(struct snapraid_state* state, const char* path)
if (state->level > 2) {
fprintf(stderr, "WARNING! Your CPU doesn't have a fast implementation beyond RAID6.\n");
}
/* ensure that specified filter disks are valid ones */
for(i=tommy_list_head(filterlist_disk);i!=0;i=i->next) {
tommy_node* j;
struct snapraid_filter* filter = i->data;
for(j=state->disklist;j!=0;j=j->next) {
struct snapraid_disk* disk = j->data;
if (fnmatch(filter->pattern, disk->name, FNM_CASEINSENSITIVE_FOR_WIN) == 0)
break;
}
if (j == 0) {
fprintf(stderr, "Option -d, --filter-disk %s doesn't match any disk.\n", filter->pattern);
exit(EXIT_FAILURE);
}
}
}
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt)
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk)
{
STREAM* f;
unsigned line;
@ -628,7 +645,7 @@ void state_config(struct snapraid_state* state, const char* path, const char* co
sclose(f);
state_config_check(state, path);
state_config_check(state, path, filterlist_disk);
/* select the default hash */
if (state->opt.force_murmur3) {

View file

@ -138,7 +138,7 @@ void state_done(struct snapraid_state* state);
/**
* Reads the configuration file.
*/
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt);
void state_config(struct snapraid_state* state, const char* path, const char* command, struct snapraid_option* opt, tommy_list* filterlist_disk);
/**
* Reads the state.