static GSList *hosts_to_cache (void) { GSList *hosts = NULL; GSList *allhosts; GSList *tmp; struct host *h; time_t curtime = time (NULL); allhosts = all_hosts (); for (tmp = allhosts; tmp; tmp = tmp->next) { h = (struct host *) tmp->data; if (h->name && h->refreshed && h->refreshed < curtime + HOST_CACHE_MAX_AGE*2) { hosts = g_slist_prepend (hosts, h); host_ref (h); } } host_list_free (allhosts); hosts = g_slist_sort (hosts, (GCompareFunc) host_cache_sorting_helper); if (g_slist_length (hosts) > HOST_CACHE_MAX_SIZE) { tmp = g_slist_nth (hosts, HOST_CACHE_MAX_SIZE - 1); host_list_free (tmp->next); tmp->next = NULL; } return hosts; }
static int test_list(const fence_callbacks_t *cb, const backend_context_t ctx) { size_t i; int result; struct hostlist hostlist = {0, NULL}; result = cb->hostlist(&host_list_append, &hostlist, ctx); if (result) { goto exit; } result = 1; for (i = 0; i < hostlist.len; i++) { struct host *h = &hostlist.hosts[i]; if (strcmp(h->hostname, TEST_DOMAIN) == 0) { printf(" Found host uuid=%s; %s\n", h->uuid, h->running ? "RUNNING" : "SHUTOFF"); if (h->running == running) { result = 0; } break; } } exit: host_list_free(&hostlist); return result; }
void host_cache_clear (void) { if (host_cache) { host_list_free (host_cache); host_cache = NULL; } }