diff --git a/src/analyze.c b/src/analyze.c index 2ed13a6..93c0ae5 100644 --- a/src/analyze.c +++ b/src/analyze.c @@ -60,7 +60,8 @@ void do_counting(struct conf_t *state) { struct range_t *restrict range_p = state->ranges; const struct leases_t *restrict l = state->leases; - unsigned long i, k, block_size; + unsigned long i; + double block_size; /* Walk through ranges */ for (i = 0; i < state->num_ranges; i++) { @@ -83,38 +84,22 @@ void do_counting(struct conf_t *state) range_p->backups++; break; } - if (range_p->shared_net) { - switch (l->type) { - case FREE: - range_p->shared_net->touched++; - break; - case ACTIVE: - range_p->shared_net->used++; - break; - case BACKUP: - range_p->shared_net->backups++; - break; - } - } } - /* Size of range, shared net & all networks */ + /* Size of range size. */ block_size = get_range_size(range_p); - if (range_p->shared_net) - range_p->shared_net->available += block_size; - range_p++; - } - /* FIXME: During count of other shared networks default network - * and all networks got mixed together semantically. The below - * fixes the problem, but is not elegant. */ - state->shared_networks->available = 0; - state->shared_networks->used = 0; - state->shared_networks->touched = 0; - range_p = state->ranges; - for (k = 0; k < state->num_ranges; k++) { - state->shared_networks->available += get_range_size(range_p); - state->shared_networks->used += range_p->count; - state->shared_networks->touched += range_p->touched; - state->shared_networks->backups += range_p->backups; + /* Count together ranges within shared network block. */ + range_p->shared_net->available += block_size; + range_p->shared_net->used += range_p->count; + range_p->shared_net->touched += range_p->touched; + range_p->shared_net->backups += range_p->backups; + /* When shared network is not 'all networks' add it as well. */ + if (range_p->shared_net != state->shared_networks) { + state->shared_networks->available += block_size; + state->shared_networks->used += range_p->count; + state->shared_networks->touched += range_p->touched; + state->shared_networks->backups += range_p->backups; + } + /* Next range. */ range_p++; } } diff --git a/tests/expected/mustach b/tests/expected/mustach index 39f5e6e..73358a8 100644 --- a/tests/expected/mustach +++ b/tests/expected/mustach @@ -110,8 +110,8 @@ Summary: percent: 43 touch_count: 43 touch_percent: 43 - backup_count: 3 - backup_percent: 3 + backup_count: 2 + backup_percent: 2 status: 0 --- skip ok --- @@ -185,7 +185,7 @@ Summary: percent: 43 touch_count: 43 touch_percent: 43 - backup_count: 3 - backup_percent: 3 + backup_count: 2 + backup_percent: 2 status: 0