static int hookSwdaeBeforeSysInit(void) { cache_select_t *cache = NULL; g_CheckReply_Flags = 0; cc_mod_param *mod_param = NULL; int pcount = 0; int all_count = 0; int i = 0; int k = 0; int dirn = 0; memset(g_CacheDirForbidDisk, 0, MAX_CACHE_DIE); for (i = 0; i < mod->mod_params.count; i++) { if ((mod_param = mod->mod_params.items[i]) && (cache = mod_param->param)) { pcount = 0; for (k = 0; k < cache->dir.count; k++) { dirn = (int)cache->dir.items[k]; if (dirn >= 0 && dirn < Config.cacheSwap.n_configured) { pcount++; all_count++; g_CacheDirForbidDisk[dirn] = 1; debug(172,1)("%s %s private dir %s\n", PMOD_NAME, __func__, storeSwapDir(dirn)); } } if (0 == pcount) { cache->dir.count = 0; } if (cache->dir.count > 0 && cache->ch_p) { g_CheckReply_Flags = 1; } } } debug(172,1)("%s %s g_CheckReply_Flags = %d\n", PMOD_NAME, __func__, g_CheckReply_Flags); g_SelectDiskMethod = SELECT_LEAST_LOAD; char *s_method = Config.store_dir_select_algorithm; if (s_method && 0 == strcasecmp(s_method, "round-robin")) { g_SelectDiskMethod = SELECT_ROUND_ROBIN; } debug(172,1)("%s %s %s %d\n", PMOD_NAME, __func__, s_method, g_SelectDiskMethod); return 0; }
static void netdbSaveState(void *foo) { LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN); Logfile *lf; netdbEntry *n; net_db_name *x; struct timeval start = current_time; int count = 0; snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0)); /* * This was nicer when we were using stdio, but thanks to * Solaris bugs, its a bad idea. fopen can fail if more than * 256 FDs are open. */ /* * unlink() is here because there is currently no way to make * logfileOpen() use O_TRUNC. */ unlink(path); lf = logfileOpen(path, 4096, 0); if (NULL == lf) { debug(50, 1) ("netdbSaveState: %s: %s\n", path, xstrerror()); return; } hash_first(addr_table); while ((n = (netdbEntry *) hash_next(addr_table))) { if (n->pings_recv == 0) continue; logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d", n->network, n->pings_sent, n->pings_recv, n->hops, n->rtt, (int) n->next_ping_time, (int) n->last_use_time); for (x = n->hosts; x; x = x->next) logfilePrintf(lf, " %s", hashKeyStr(&x->hash)); logfilePrintf(lf, "\n"); count++; #undef RBUF_SZ } logfileClose(lf); getCurrentTime(); debug(38, 1) ("NETDB state saved; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1); }
static void netdbReloadState(void) { LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN); char *buf; char *t; char *s; int fd; int l; struct stat sb; netdbEntry *n; netdbEntry N; struct in_addr addr; int count = 0; struct timeval start = current_time; snprintf(path, SQUID_MAXPATHLEN, "%s/netdb_state", storeSwapDir(0)); /* * This was nicer when we were using stdio, but thanks to * Solaris bugs, its a bad idea. fopen can fail if more than * 256 FDs are open. */ fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) return; if (fstat(fd, &sb) < 0) { file_close(fd); return; } t = buf = xcalloc(1, (size_t) sb.st_size + 1); l = FD_READ_METHOD(fd, buf, (int) sb.st_size); file_close(fd); if (l <= 0) return; while ((s = strchr(t, '\n'))) { char *q; assert(s - buf < l); *s = '\0'; memset(&N, '\0', sizeof(netdbEntry)); q = strtok(t, w_space); t = s + 1; if (NULL == q) continue; if (!safe_inet_addr(q, &addr)) continue; if (netdbLookupAddr(addr) != NULL) /* no dups! */ continue; if ((q = strtok(NULL, w_space)) == NULL) continue; N.pings_sent = atoi(q); if ((q = strtok(NULL, w_space)) == NULL) continue; N.pings_recv = atoi(q); if (N.pings_recv == 0) continue; /* give this measurement low weight */ N.pings_sent = 1; N.pings_recv = 1; if ((q = strtok(NULL, w_space)) == NULL) continue; N.hops = atof(q); if ((q = strtok(NULL, w_space)) == NULL) continue; N.rtt = atof(q); if ((q = strtok(NULL, w_space)) == NULL) continue; N.next_ping_time = (time_t) atoi(q); if ((q = strtok(NULL, w_space)) == NULL) continue; N.last_use_time = (time_t) atoi(q); n = memAllocate(MEM_NETDBENTRY); xmemcpy(n, &N, sizeof(netdbEntry)); netdbHashInsert(n, addr); while ((q = strtok(NULL, w_space)) != NULL) { if (netdbLookupHost(q) != NULL) /* no dups! */ continue; netdbHostInsert(n, q); } count++; } xfree(buf); getCurrentTime(); debug(38, 1) ("NETDB state reloaded; %d entries, %d msec\n", count, tvSubMsec(start, current_time)); }