void storeCreateSwapDirectories(void) { int i; SwapDir *sd; pid_t pid; int status; for (i = 0; i < Config.cacheSwap.n_configured; i++) { if (fork()) continue; sd = &Config.cacheSwap.swapDirs[i]; sd->newfs(sd); exit(0); } do { #ifdef _SQUID_NEXT_ pid = wait3(&status, WNOHANG, NULL); #else pid = waitpid(-1, &status, 0); #endif } while (pid > 0 || (pid < 0 && errno == EINTR)); }
/* * storeOpen() is purely for reading .. */ storeIOState * storeOpen(StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { int load; storeIOState *sio; SwapDir *SD = &Config.cacheSwap.swapDirs[e->swap_dirn]; store_io_stats.open.calls++; load = SD->checkload(SD, ST_OP_OPEN); if (load < 0 || load > 1000) { store_io_stats.open.loadav_fail++; return NULL; } sio = SD->obj.open(SD, e, file_callback, callback, callback_data); if (sio == NULL) { store_io_stats.open.open_fail++; } else { store_io_stats.open.success++; } return sio; }
static int swdaeSwapDirLeastLoad(cache_select_t *cache, const StoreEntry *e) { squid_off_t objsize; int most_free = 0, cur_free; squid_off_t least_objsize = -1; int least_load = INT_MAX; int load; int dirn = 0; int dirn_no = -1; int i; SwapDir *sd; /* Calculate the object size */ objsize = objectLen(e); if (objsize != -1) objsize += e->mem_obj->swap_hdr_sz; for (i = 0; i < cache->dir.count; i++) { cache->dirn = cache->dirn % cache->dir.count; dirn = (int)cache->dir.items[cache->dirn]; cache->dirn++; if (0 > dirn || dirn >= Config.cacheSwap.n_configured) continue; sd = &Config.cacheSwap.swapDirs[dirn]; sd->flags.selected = 0; if (sd->flags.read_only) { debug(172, 5)("%s %s %s read_only\n", PMOD_NAME, __func__,sd->path); continue; } if (sd->cur_size > sd->max_size) { debug(172, 5)("%s %s %s cur_size > sd->max_size\n", PMOD_NAME, __func__, sd->path); continue; } if (!swdaeSwapDirSwapDirSize(dirn, objsize)) { debug(172,5)("%s %s objsize isn't Suitable %s %s\n", PMOD_NAME, __func__, sd->path, storeUrl(e)); continue; } if (sd->checkobj(sd, e) == 0) { debug(172,5)("%s %s %s checkobj(sd,e) == 0\n",PMOD_NAME, __func__, sd->path); continue; } load = sd->checkload(sd, ST_OP_CREATE); if (load < 0 || load > 2000) { debug(172, 5)("%s %s %s Load too high %s\n", PMOD_NAME, __func__, sd->path, storeUrl(e)); continue; } if (load > least_load) continue; cur_free = sd->max_size - sd->cur_size; /* If the load is equal, then look in more details */ if (load == least_load) { /* closest max_objsize fit */ if (least_objsize != -1) if (sd->max_objsize > least_objsize || sd->max_objsize == -1) continue; /* most free */ if (cur_free < most_free) continue; } least_load = load; least_objsize = sd->max_objsize; most_free = cur_free; dirn_no = dirn; } if (dirn_no >= 0) { sd = &Config.cacheSwap.swapDirs[dirn_no]; debug(172,5)("%s %s Select [%s] store %s\n", PMOD_NAME, __func__, sd->path, storeUrl(e)); Config.cacheSwap.swapDirs[dirn_no].flags.selected = 1; }else { debug(172,5)("%s %s Select Null store %s\n",PMOD_NAME, __func__, storeUrl(e)); } return dirn_no; }