From 0489c98bb0b8fb1d15c907abc1d1c94a418c14be Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Thu, 26 Sep 2013 21:14:47 +0200 Subject: [PATCH] Fixes the percentage computation in scrub. --- scrub.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/scrub.c b/scrub.c index d9bf198d..ad6eab2d 100644 --- a/scrub.c +++ b/scrub.c @@ -100,10 +100,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par continue; } - /* if we reached the count limit */ - if (countmax >= countlimit) { - /* skip it */ - continue; + /* if the time is less than the limit, always include */ + /* otherwise, check if we reaced the count max */ + if (blocktime == timelimit) { + /* if we reached the count limit */ + if (countmax >= countlimit) { + /* skip it */ + continue; + } } } @@ -153,10 +157,14 @@ static int state_scrub_process(struct snapraid_state* state, struct snapraid_par continue; } - /* if we reached the count limit */ - if (recountmax >= countlimit) { - /* skip it */ - continue; + /* if the time is less than the limit, always include */ + /* otherwise, check if we reaced the count max */ + if (blocktime == timelimit) { + /* if we reached the count limit */ + if (recountmax >= countlimit) { + /* skip it */ + continue; + } } } @@ -463,7 +471,7 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) recentlimit = now; } else if (percentage != -1 || olderthan != -1) { if (percentage != -1) - countlimit = blockmax * percentage / 100; + countlimit = (blockmax * percentage + 99) / 100; else countlimit = blockmax; if (olderthan != -1) @@ -512,8 +520,9 @@ int state_scrub(struct snapraid_state* state, int percentage, int olderthan) timelimit = info_get_time(infomap[countlimit - 1]); /* don't scrub too recent blocks */ - if (timelimit > recentlimit) + if (timelimit > recentlimit) { timelimit = recentlimit; + } } else { /* we don't have a time limit based on quota */ timelimit = recentlimit;