diff options
author | Mattias Andrée <maandree@kth.se> | 2024-09-21 20:51:41 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-09-21 20:51:41 +0200 |
commit | ea295cb799b2eeb962b7afb6362bfbb1281c7ae8 (patch) | |
tree | b482889fa4c698ffe3b42e37f48cf8011815440d | |
parent | misc (diff) | |
download | deadshred-ea295cb799b2eeb962b7afb6362bfbb1281c7ae8.tar.gz deadshred-ea295cb799b2eeb962b7afb6362bfbb1281c7ae8.tar.bz2 deadshred-ea295cb799b2eeb962b7afb6362bfbb1281c7ae8.tar.xz |
Periodically save progress
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | deadshred.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/deadshred.c b/deadshred.c index 24d02fa..8b8a74c 100644 --- a/deadshred.c +++ b/deadshred.c @@ -24,6 +24,7 @@ static const char *clkcstr = "CLOCK_MONOTONIC_COARSE"; static struct timespec max_success = {-1, 0}; static struct timespec start_time; +#define MAP_SAVE_INTERVAL 3600 static const struct timespec status_print_interval = {0, MILLISECONDS(500)}; static const struct timespec poll_timeout = {1, 0}; static int auxthread_pipe[2]; @@ -110,7 +111,7 @@ auxthread_loop(void *input) { struct pollfd pfd = {.fd = auxthread_pipe[0], .events = POLLIN}; ssize_t r; - int terminate = 0; + int terminate = 0, save_map = 0; int map_fd = ((struct auxthread_input *)input)->map_fd; const char *map_fname = ((struct auxthread_input *)input)->map_fname; struct status s = ((struct auxthread_input *)input)->initial_status; @@ -171,7 +172,7 @@ auxthread_loop(void *input) goto read_spans_again; } - update_map(map_fd, &s, map_fname); + save_map = 1; goto have_time; } if (clock_gettime(clck, &s.now)) @@ -183,6 +184,10 @@ auxthread_loop(void *input) } print_status(0, &s); wravg_update_time(&s); + if (save_map) { + save_map = 0; + update_map(map_fd, &s, map_fname); + } } while (!terminate); free(s.spans); @@ -199,6 +204,8 @@ shredspan(int fd, struct span *span, const char *fname, int have_map) int bad = span->bad > 0; int first_fail = 1; int was_successful = 0; + int need_save = 0; + int need_save_in = -1; const char *random_data; off = (status.direction == FORWARDS ? span->start : span->end); @@ -217,6 +224,9 @@ shredspan(int fd, struct span *span, const char *fname, int have_map) if (clock_gettime(clck, &status.now)) eprintf("clock_gettime %s:", clkcstr); if (was_successful) { + need_save |= !need_save_in; + if (need_save_in < 0) + need_save_in = MAP_SAVE_INTERVAL; was_successful = 0; status.last_success = status.now; } @@ -225,11 +235,16 @@ shredspan(int fd, struct span *span, const char *fname, int have_map) size_t spans_transfer_size; size_t spans_offset = 0; size_t status_off = 0; + if (need_save_in > 0) + need_save_in--; libsimple_sumtimespec(&when, &status.now, &status_print_interval); - if (have_map && 0) /* TODO periodically 1 instead 0 */ + if (have_map && need_save) { + need_save = 0; + need_save_in = -1; status.nspans -= status.span_off; - else + } else { status.nspans = 0; + } spans_transfer_size = status.nspans * sizeof(*status.spans); spans_transfer_size += spans_offset = status.span_off * sizeof(*status.spans); write_status_again: |