From a5379ba3ab356b462c55bb50ef122dfbf72be3ea Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 30 Apr 2011 11:27:36 +0200 Subject: [PATCH] If the content file is not found, try with another copy. Only if all the copies are missing, assume it's the first run. --- state.c | 42 +++++++++++++++++++++++++++++++----------- test-raid5.conf | 1 + test-raid6.conf | 1 + 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/state.c b/state.c index 7c1636ee..0daaca43 100644 --- a/state.c +++ b/state.c @@ -195,24 +195,44 @@ void state_read(struct snapraid_state* state) unsigned line; unsigned count_file; unsigned count_block; - struct snapraid_content* content; + tommy_node* node; count_file = 0; count_block = 0; - content = tommy_list_head(&state->contentlist)->data; - pathcpy(path, sizeof(path), content->content); + /* iterate over all the available content files and load the first one present */ + f = 0; + node = tommy_list_head(&state->contentlist); + while (node) { + struct snapraid_content* content = node->data; + pathcpy(path, sizeof(path), content->content); - printf("Loading state from %s...\n", path); + printf("Loading state from %s...\n", path); - f = fopen(path, "rt"); + f = fopen(path, "rt"); + if (f != 0) { + /* if openend stop the search */ + break; + } else { + /* if it's real error of an existing file, abort */ + if (errno != ENOENT) { + fprintf(stderr, "Error opening the content file '%s'\n", path); + exit(EXIT_FAILURE); + } + + /* otherwise continue */ + if (node->next) { + fprintf(stderr, "Not found, trying with another copy...\n"); + } + } + + node = node->next; + } + + /* if not found, assume empty */ if (!f) { - /* if not found, assume empty */ - if (errno == ENOENT) - return; - - fprintf(stderr, "Error opening the content file '%s'\n", path); - exit(EXIT_FAILURE); + fprintf(stderr, "No content file found. Assuming empty.\n"); + return; } /* start with a MD5 default. */ diff --git a/test-raid5.conf b/test-raid5.conf index 8c02358f..355d1866 100644 --- a/test-raid5.conf +++ b/test-raid5.conf @@ -1,6 +1,7 @@ block_size 1 parity test/parity content test/content +content test/p-content disk d1 test/disk1/ disk d2 test/disk2/ disk d3 test/disk3/ diff --git a/test-raid6.conf b/test-raid6.conf index 982b7221..2b17f6aa 100644 --- a/test-raid6.conf +++ b/test-raid6.conf @@ -2,6 +2,7 @@ block_size 1 parity test/parity q-parity test/q-parity content test/content +content test/p-content content test/q-content disk d1 test/disk1/ disk d2 test/disk2/