From 33cf866699498ed2be7669d19715910a87a76fa6 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 29 Jun 2013 18:34:10 +0200 Subject: [PATCH] Adds test for scrub. --- Makefile.am | 7 +++++++ scrub.c | 14 ++++++++++---- snapraid.c | 7 +++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index ddfc53ac..95480da5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -158,6 +158,13 @@ endif echo --- Dry $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf dry $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf dry + echo --- Scrub some times + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf --test-force-scrub 100 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf status + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf --test-force-scrub 1000 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf status + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf --test-force-scrub 10000 scrub + $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -v -c $(srcdir)/test-raid6.conf status echo --- Make a hole in the disk array mv test/disk2 test/disk2.old mkdir test/disk2 diff --git a/scrub.c b/scrub.c index e9bdc2e0..30552dbc 100644 --- a/scrub.c +++ b/scrub.c @@ -331,11 +331,17 @@ int state_scrub(struct snapraid_state* state) blockmax = parity_size(state); - /* by default scrub 1/12 of the array */ - countlimit = blockmax / 12; + if (state->opt.force_scrub) { + /* scrub the specified amount of blocks */ + countlimit = state->opt.force_scrub; + recentlimit = now; + } else { + /* by default scrub 1/12 of the array */ + countlimit = blockmax / 12; - /* by default use a 10 day time limit */ - recentlimit = now - 10 * 24 * 3600; + /* by default use a 10 day time limit */ + recentlimit = now - 10 * 24 * 3600; + } /* identify the time limit */ /* we sort all the block times, and we identify the time limit for which we reach the quota */ diff --git a/snapraid.c b/snapraid.c index 7071c95b..9aa9847d 100644 --- a/snapraid.c +++ b/snapraid.c @@ -91,6 +91,7 @@ void usage(void) #define OPT_TEST_FORCE_ORDER_INODE 268 #define OPT_TEST_FORCE_ORDER_ALPHA 269 #define OPT_TEST_FORCE_ORDER_DIR 270 +#define OPT_TEST_FORCE_SCRUB 271 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -154,6 +155,9 @@ struct option long_options[] = { { "test-force-order-alpha", 0, 0, OPT_TEST_FORCE_ORDER_ALPHA }, { "test-force-order-dir", 0, 0, OPT_TEST_FORCE_ORDER_DIR }, + /* Force scrub of the specified number of blocks */ + { "test-force-scrub", 1, 0, OPT_TEST_FORCE_SCRUB }, + { 0, 0, 0, 0 } }; #endif @@ -351,6 +355,9 @@ int main(int argc, char* argv[]) case OPT_TEST_FORCE_ORDER_DIR : opt.force_order = SORT_DIR; break; + case OPT_TEST_FORCE_SCRUB : + opt.force_scrub = atoi(optarg); + break; default: fprintf(stderr, "Unknown option '%c'\n", (char)c); exit(EXIT_FAILURE);