From 9b74284e35aa73d24439350ad95647ee1e6490ea Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 10 Mar 2014 21:17:10 +0100 Subject: [PATCH] Avoids to access parity disks when not needed. --- HISTORY | 2 ++ snapraid.c | 19 +++++++++++++++++++ state.c | 36 +++++++++++++++++++++--------------- state.h | 1 + 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/HISTORY b/HISTORY index a2de1bc9..db168569 100644 --- a/HISTORY +++ b/HISTORY @@ -25,6 +25,8 @@ SnapRAID HISTORY default value even if the other one is specified. * Moved the .lock file in the same dir of the first specified content file. This avoid to spin the parity disks in all commands. + * The "diff", "list", "dup", "status" and "pool" commands don't access + anymore the parity disks that can stay powered down. * New source code organization. The RAID engine is now an external component usable also in other projects. diff --git a/snapraid.c b/snapraid.c index acfe51f6..0faa6afa 100644 --- a/snapraid.c +++ b/snapraid.c @@ -211,6 +211,7 @@ void log_close(const char* log) #define OPT_TEST_FORCE_CONTENT_WRITE 273 #define OPT_TEST_FORCE_CONTENT_TEXT 274 #define OPT_TEST_SKIP_CONTENT_CHECK 275 +#define OPT_TEST_SKIP_PARITY_ACCESS 276 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -296,6 +297,9 @@ struct option long_options[] = { /* Relax the checks done at the content file */ { "test-skip-content-check", 0, 0, OPT_TEST_SKIP_CONTENT_CHECK }, + /* Skip the parity access */ + { "test-skip-parity-access", 0, 0, OPT_TEST_SKIP_PARITY_ACCESS }, + { 0, 0, 0, 0 } }; #endif @@ -535,6 +539,9 @@ int main(int argc, char* argv[]) case OPT_TEST_SKIP_CONTENT_CHECK : opt.skip_content_check = 1; break; + case OPT_TEST_SKIP_PARITY_ACCESS : + opt.skip_parity_access = 1; + break; case OPT_TEST_FORCE_MURMUR3 : opt.force_murmur3 = 1; break; @@ -696,6 +703,18 @@ int main(int argc, char* argv[]) } } + switch (operation) { + case OPERATION_DIFF : + case OPERATION_LIST : + case OPERATION_DUP : + case OPERATION_POOL : + case OPERATION_STATUS : + case OPERATION_REWRITE : + /* avoid to check and access parity disks if not needed */ + opt.skip_parity_access = 1; + break; + } + /* open the log file */ log_open(log); diff --git a/state.c b/state.c index 3309b8e5..8b8e3368 100644 --- a/state.c +++ b/state.c @@ -452,7 +452,6 @@ void state_config(struct snapraid_state* state, const char* path, const char* co ) { char device[PATH_MAX]; char* slash; - struct stat st; unsigned l; switch (tag[0]) { @@ -500,21 +499,28 @@ void state_config(struct snapraid_state* state, const char* path, const char* co pathimport(state->parity_path[l], sizeof(state->parity_path[l]), buffer); - /* get the device of the directory containing the parity file */ - pathimport(device, sizeof(device), buffer); - slash = strrchr(device, '/'); - if (slash) - *slash = 0; - else - pathcpy(device, sizeof(device), "."); - if (stat(device, &st) != 0) { - /* LCOV_EXCL_START */ - fprintf(stderr, "Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); - exit(EXIT_FAILURE); - /* LCOV_EXCL_STOP */ - } + if (state->opt.skip_parity_access) { + struct stat st; - state->parity_device[l] = st.st_dev; + /* get the device of the directory containing the parity file */ + pathimport(device, sizeof(device), buffer); + slash = strrchr(device, '/'); + if (slash) + *slash = 0; + else + pathcpy(device, sizeof(device), "."); + if (stat(device, &st) != 0) { + /* LCOV_EXCL_START */ + fprintf(stderr, "Error accessing 'parity' dir '%s' specification in '%s' at line %u\n", device, path, line); + exit(EXIT_FAILURE); + /* LCOV_EXCL_STOP */ + } + + state->parity_device[l] = st.st_dev; + } else { + /* if parity is skipped, uses a fake device */ + state->parity_device[l] = -1LL - l; + } /* adjust the level */ if (state->level < l + 1) diff --git a/state.h b/state.h index 82c4e3aa..8117a9ab 100644 --- a/state.h +++ b/state.h @@ -74,6 +74,7 @@ struct snapraid_option { int skip_lock; /**< Skip the lock file protection. */ int skip_self; /**< Skip the self-test. */ int skip_content_check; /**< Relax some content file checks. */ + int skip_parity_access; /**< Skip the parity access for commands that don't need it. */ int kill_after_sync; /**< Kill the process after sync without saving the final state. */ int force_murmur3; /**< Force Murmur3 choice. */ int force_spooky2; /**< Force Spooky2 choice. */