From d01c480af4db614af94caab397947d632fb66511 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 8 Sep 2013 08:34:47 +0200 Subject: [PATCH] Prints sync progress in the status report. --- Makefile.am | 2 +- status.c | 75 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 54 insertions(+), 23 deletions(-) diff --git a/Makefile.am b/Makefile.am index 026cda31..9153c6d8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -229,7 +229,7 @@ endif $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid5.conf check $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf check $(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) --test-skip-self -c $(srcdir)/test-raid6.conf sync - echo --- Delete some files and create some new, sync and check in multiple steps + echo --- Delete some files and create some new, sync and check in multiple steps using text content rm test/disk1/4* rm test/disk2/5* rm test/disk3/6* diff --git a/status.c b/status.c index 0a5ca5be..a9ba7565 100644 --- a/status.c +++ b/status.c @@ -55,13 +55,14 @@ int state_status(struct snapraid_state* state) unsigned file_fragmented; unsigned extra_fragment; uint64_t file_size; + unsigned unsynched_blocks; /* get the present time */ now = time(0); blockmax = parity_size(state); - /* for each disk, recover empty files, symlinks and empty dirs */ + /* count fragments */ file_count = 0; file_size = 0; file_fragmented = 0; @@ -114,10 +115,33 @@ int state_status(struct snapraid_state* state) printf("\n"); - /* allocate a temp vector for all the blocks */ - infomap = malloc_nofail(blockmax * sizeof(snapraid_info)); + /* count unsynched blocks */ + unsynched_blocks = 0; + for(i=0;idisklist;node_disk!=0;node_disk=node_disk->next) { + struct snapraid_disk* disk = node_disk->data; + struct snapraid_block* block = disk_block_get(disk, i); + + if (block_has_file(block)) + one_valid = 1; + if (block_has_invalid_parity(block)) + one_invalid = 1; + } + + /* if both valid and invalid, we need to update */ + if (one_invalid && one_valid) { + ++unsynched_blocks; + } + } + + /* copy the info a temp vector, and count bad/rehash blocks */ + infomap = malloc_nofail(blockmax * sizeof(snapraid_info)); bad = 0; count = 0; rehash = 0; @@ -138,23 +162,21 @@ int state_status(struct snapraid_state* state) } if (!count) { - fprintf(stderr, "The array appears to be empty.\n"); + fprintf(stderr, "The array is empty.\n"); free(infomap); return 0; } - if (rehash) { - printf("You have a rehash in progress at %u%%.\n", (count - rehash) * 100 / count); - printf("\n"); - } - - /* sort it */ + /* sort the info to get the time info */ qsort(infomap, count, sizeof(snapraid_info), info_time_compare); - oldest = info_get_time(infomap[0]); median = info_get_time(infomap[count / 2]); newest = info_get_time(infomap[count - 1]); + dayoldest = day_ago(oldest, now); + daymedian = day_ago(median, now); + daynewest = day_ago(newest, now); + /* compute graph limits */ barpos = 0; barmax = 0; for(i=0;i