?? store_dir_diskd.c
字號:
if (flag) if (filn > diskdinfo->map->max_n_files) return 0; return 1;}voidstoreDiskdDirMaintain(SwapDir * SD){ diskdinfo_t *diskdinfo = SD->fsdata; StoreEntry *e = NULL; int removed = 0; int max_scan; int max_remove; double f; RemovalPurgeWalker *walker; /* We can't delete objects while rebuilding swap */ if (store_dirs_rebuilding) { return; } else { f = (double) (SD->cur_size - SD->low_size) / (SD->max_size - SD->low_size); f = f < 0.0 ? 0.0 : f > 1.0 ? 1.0 : f; max_scan = (int) (f * 400.0 + 100.0); max_remove = (int) (f * 70.0 + 10.0); /* * This is kinda cheap, but so we need this priority hack? */ } debug(20, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n", f, max_scan, max_remove); walker = SD->repl->PurgeInit(SD->repl, max_scan); while (1) { if (SD->cur_size < SD->low_size && diskdinfo->map->n_files_in_map < FILEMAP_MAX) break; if (removed >= max_remove) break; e = walker->Next(walker); if (!e) break; /* no more objects */ removed++; storeRelease(e); } walker->Done(walker); debug(20, (removed ? 2 : 3)) ("storeDiskdDirMaintain: %s removed %d/%d f=%.03f max_scan=%d\n", SD->path, removed, max_remove, f, max_scan);}/* * storeDiskdDirCheckObj * * This routine is called by storeDirSelectSwapDir to see if the given * object is able to be stored on this filesystem. DISKD filesystems will * happily store anything as long as the LRU time isn't too small. */intstoreDiskdDirCheckObj(SwapDir * SD, const StoreEntry * e){ diskdinfo_t *diskdinfo = SD->fsdata; /* Check the queue length */ if (diskdinfo->away >= diskdinfo->magic1) return 0; return 1;}intstoreDiskdDirCheckLoadAv(SwapDir * SD, store_op_t op){ diskdinfo_t *diskdinfo = SD->fsdata; /* Calculate the storedir load relative to magic2 on a scale of 0 .. 1000 */ /* the parse function guarantees magic2 is positive */ if (diskdinfo->away >= diskdinfo->magic1) return -1; return DISKD_LOAD_BASE + (diskdinfo->away * DISKD_LOAD_QUEUE_WEIGHT / diskdinfo->magic2);}/* * storeDiskdDirRefObj * * This routine is called whenever an object is referenced, so we can * maintain replacement information within the storage fs. */voidstoreDiskdDirRefObj(SwapDir * SD, StoreEntry * e){ debug(47, 3) ("storeDiskdDirRefObj: referencing %p %d/%d\n", e, e->swap_dirn, e->swap_filen); if (SD->repl->Referenced) SD->repl->Referenced(SD->repl, e, &e->repl);}/* * storeDiskdDirUnrefObj * This routine is called whenever the last reference to an object is * removed, to maintain replacement information within the storage fs. */voidstoreDiskdDirUnrefObj(SwapDir * SD, StoreEntry * e){ debug(47, 3) ("storeDiskdDirUnrefObj: referencing %p %d/%d\n", e, e->swap_dirn, e->swap_filen); if (SD->repl->Dereferenced) SD->repl->Dereferenced(SD->repl, e, &e->repl);}/* * storeDiskdDirUnlinkFile * * This is a *synchronous* unlink which is currently used in the rebuild * process. This is bad, but it'll have to stay until the dir rebuild * uses storeDiskdUnlink() .. */voidstoreDiskdDirUnlinkFile(SwapDir * SD, sfileno f){ debug(79, 3) ("storeDiskdDirUnlinkFile: unlinking fileno %08X\n", f); /* storeDiskdDirMapBitReset(SD, f); */#if USE_UNLINKD unlinkdUnlink(storeDiskdDirFullPath(SD, f, NULL));#elif USE_TRUNCATE truncate(storeDiskdDirFullPath(SD, f, NULL), 0);#else unlink(storeDiskdDirFullPath(SD, f, NULL));#endif}/* * Add and remove the given StoreEntry from the replacement policy in * use. */voidstoreDiskdDirReplAdd(SwapDir * SD, StoreEntry * e){ debug(20, 4) ("storeDiskdDirReplAdd: added node %p to dir %d\n", e, SD->index); SD->repl->Add(SD->repl, e, &e->repl);}voidstoreDiskdDirReplRemove(StoreEntry * e){ SwapDir *SD; if (e->swap_dirn < 0) return; SD = INDEXSD(e->swap_dirn); debug(20, 4) ("storeDiskdDirReplRemove: remove node %p from dir %d\n", e, SD->index); SD->repl->Remove(SD->repl, e, &e->repl);}/* * SHM manipulation routines */void *storeDiskdShmGet(SwapDir * sd, int *shm_offset){ char *buf = NULL; diskdinfo_t *diskdinfo = sd->fsdata; int i; for (i = 0; i < diskdinfo->shm.nbufs; i++) { if (CBIT_TEST(diskdinfo->shm.inuse_map, i)) continue; CBIT_SET(diskdinfo->shm.inuse_map, i); *shm_offset = i * SHMBUF_BLKSZ; buf = diskdinfo->shm.buf + (*shm_offset); break; } assert(buf); assert(buf >= diskdinfo->shm.buf); assert(buf < diskdinfo->shm.buf + (diskdinfo->shm.nbufs * SHMBUF_BLKSZ)); diskd_stats.shmbuf_count++; if (diskd_stats.max_shmuse < diskd_stats.shmbuf_count) diskd_stats.max_shmuse = diskd_stats.shmbuf_count; return buf;}voidstoreDiskdShmPut(SwapDir * sd, int offset){ int i; diskdinfo_t *diskdinfo = sd->fsdata; assert(offset >= 0); assert(offset < diskdinfo->shm.nbufs * SHMBUF_BLKSZ); i = offset / SHMBUF_BLKSZ; assert(i < diskdinfo->shm.nbufs); assert(CBIT_TEST(diskdinfo->shm.inuse_map, i)); CBIT_CLR(diskdinfo->shm.inuse_map, i); diskd_stats.shmbuf_count--;}/* ========== LOCAL FUNCTIONS ABOVE, GLOBAL FUNCTIONS BELOW ========== */voidstoreDiskdDirStats(SwapDir * SD, StoreEntry * sentry){ diskdinfo_t *diskdinfo = SD->fsdata;#ifdef HAVE_STATVFS fsblkcnt_t totl_kb = 0; fsblkcnt_t free_kb = 0; fsfilcnt_t totl_in = 0; fsfilcnt_t free_in = 0;#else int totl_kb = 0; int free_kb = 0; int totl_in = 0; int free_in = 0;#endif int x; storeAppendPrintf(sentry, "First level subdirectories: %d\n", diskdinfo->l1); storeAppendPrintf(sentry, "Second level subdirectories: %d\n", diskdinfo->l2); storeAppendPrintf(sentry, "Maximum Size: %d KB\n", SD->max_size); storeAppendPrintf(sentry, "Current Size: %d KB\n", SD->cur_size); storeAppendPrintf(sentry, "Percent Used: %0.2f%%\n", 100.0 * SD->cur_size / SD->max_size); storeAppendPrintf(sentry, "Current load metric: %d / %d\n", storeDiskdDirCheckLoadAv(SD, ST_OP_CREATE), MAX_LOAD_VALUE); storeAppendPrintf(sentry, "Filemap bits in use: %d of %d (%d%%)\n", diskdinfo->map->n_files_in_map, diskdinfo->map->max_n_files, percent(diskdinfo->map->n_files_in_map, diskdinfo->map->max_n_files)); x = storeDirGetUFSStats(SD->path, &totl_kb, &free_kb, &totl_in, &free_in); if (0 == x) {#ifdef HAVE_STATVFS storeAppendPrintf(sentry, "Filesystem Space in use: %" PRIu64 "/%" PRIu64 " KB (%.0f%%)\n", (uint64_t) (totl_kb - free_kb), (uint64_t) totl_kb, dpercent(totl_kb - free_kb, totl_kb)); storeAppendPrintf(sentry, "Filesystem Inodes in use: %" PRIu64 "/%" PRIu64 " (%.0f%%)\n", (uint64_t) (totl_in - free_in), (uint64_t) totl_in, dpercent(totl_in - free_in, totl_in));#else storeAppendPrintf(sentry, "Filesystem Space in use: %d/%d KB (%d%%)\n", totl_kb - free_kb, totl_kb, percent(totl_kb - free_kb, totl_kb)); storeAppendPrintf(sentry, "Filesystem Inodes in use: %d/%d (%d%%)\n", totl_in - free_in, totl_in, percent(totl_in - free_in, totl_in));#endif } storeAppendPrintf(sentry, "Flags:"); if (SD->flags.selected) storeAppendPrintf(sentry, " SELECTED"); if (SD->flags.read_only) storeAppendPrintf(sentry, " READ-ONLY"); storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "Pending operations: %d\n", diskdinfo->away);}static voidstoreDiskdDirParseQ1(SwapDir * sd, const char *name, const char *value, int reconfiguring){ diskdinfo_t *diskdinfo = sd->fsdata; int old_magic1 = diskdinfo->magic1; diskdinfo->magic1 = atoi(value); if (!reconfiguring) return; if (old_magic1 < diskdinfo->magic1) { /* * This is because shm.nbufs is computed at startup, when * we call shmget(). We can't increase the Q1/Q2 parameters * beyond their initial values because then we might have * more "Q2 messages" than shared memory chunks, and this * will cause an assertion in storeDiskdShmGet(). */ debug(3, 1) ("WARNING: cannot increase cache_dir '%s' Q1 value while Squid is running.\n", sd->path); diskdinfo->magic1 = old_magic1; return; } if (old_magic1 != diskdinfo->magic1) debug(3, 1) ("cache_dir '%s' new Q1 value '%d'\n", sd->path, diskdinfo->magic1);}static voidstoreDiskdDirDumpQ1(StoreEntry * e, const char *option, SwapDir * sd){ diskdinfo_t *diskdinfo = sd->fsdata; storeAppendPrintf(e, " Q1=%d", diskdinfo->magic1);}static voidstoreDiskdDirParseQ2(SwapDir * sd, const char *name, const char *value, int reconfiguring){ diskdinfo_t *diskdinfo = sd->fsdata; int old_magic2 = diskdinfo->magic2; diskdinfo->magic2 = atoi(value); if (!reconfiguring) return; if (old_magic2 < diskdinfo->magic2) { /* See comments in Q1 function above */ debug(3, 1) ("WARNING: cannot increase cache_dir '%s' Q2 value while Squid is running.\n", sd->path); diskdinfo->magic2 = old_magic2; return; } if (old_magic2 != diskdinfo->magic2) debug(3, 1) ("cache_dir '%s' new Q2 value '%d'\n", sd->path, diskdinfo->magic2);}static voidstoreDiskdDirDumpQ2(StoreEntry * e, const char *option, SwapDir * sd){ diskdinfo_t *diskdinfo = sd->fsdata; storeAppendPrintf(e, " Q2=%d", diskdinfo->magic2);}static struct cache_dir_option options[] ={#if NOT_YET {"L1", storeDiskdDirParseL1, storeDiskdDirDumpL1}, {"L2", storeDiskdDirParseL2, storeDiskdDirDumpL2},#endif {"Q1", storeDiskdDirParseQ1, storeDiskdDirDumpQ1}, {"Q2", storeDiskdDirParseQ2, storeDiskdDirDumpQ2}, {NULL, NULL}};/* * storeDiskdDirReconfigure * * This routine is called when the given swapdir needs reconfiguring */static voidstoreDiskdDirReconfigure(SwapDir * sd, int index, char *path){ int i; int size; int l1; int l2; i = GetInteger(); size = i << 10; /* Mbytes to kbytes */ if (size <= 0) fatal("storeDiskdDirReconfigure: invalid size value"); i = GetInteger(); l1 = i; if (l1 <= 0) fatal("storeDiskdDirReconfigure: invalid level 1 directories value"); i = GetInteger(); l2 = i; if (l2 <= 0) fatal("storeDiskdDirReconfigure: invalid level 2 directories value"); /* just reconfigure it */ if (size == sd->max_size) debug(3, 1) ("Cache dir '%s' size remains unchanged at %d KB\n", path, size); else debug(3, 1) ("Cache dir '%s' size changed to %d KB\n", path, size); sd->max_size = size; parse_cachedir_options(sd, options, 1);}voidstoreDiskdDirDump(StoreEntry * entry, SwapDir * s){ diskdinfo_t *diskdinfo = s->fsdata; storeAppendPrintf(entry, " %d %d %d", s->max_size >> 10, diskdinfo->l1, diskdinfo->l2); dump_cachedir_options(entry, options, s);}/* * Only "free" the filesystem specific stuff here */static voidstoreDiskdDirFree(SwapDir * s){ diskdinfo_t *diskdinfo = s->fsdata; if (diskdinfo->swaplog_fd > -1) { file_close(diskdinfo->swaplog_fd); diskdinfo->swaplog_fd = -1; } filemapFreeMemory(diskdinfo->map); xfree(diskdinfo); s->fsdata = NULL; /* Will aid debugging... */}char *storeDiskdDirFullPath(SwapDir * SD, sfileno filn, char *fullpath){ LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); diskdinfo_t *diskdinfo = SD->fsdata; int L1 = diskdinfo->l1; int L2 = diskdinfo->l2; if (!fullpath) fullpath = fullfilename; fullpath[0] = '\0'; snprintf(fullpath, SQUID_MAXPATHLEN, "%s/%02X/%02X/%08X", SD->path, ((filn / L2) / L2) % L1, (filn / L2) % L2, filn); return fullpath;}/* * storeDiskdCleanupDoubleCheck * * This is called by storeCleanup() if -S was given on the command line. */static intstoreDiskdCleanupDoubleCheck(SwapDir * sd, StoreEntry * e){ struct stat sb; if (stat(storeDiskdDirFullPath(sd, e->swap_filen, NULL), &sb) < 0) { debug(20, 0) ("storeDiskdCleanupDoubleCheck: MISSING SWAP FILE\n"); debug(20, 0) ("storeDiskdCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); debug(20, 0) ("storeDiskdCleanupDoubleCheck: PATH %s\n", storeDiskdDirFullPath(sd, e->swap_filen, NULL)); storeEntryDump(e, 0); return -1; } if (e->swap_file_sz != sb.st_size) { debug(20, 0) ("storeDiskdCleanupDoubleCheck: SIZE MISMATCH\n"); debug(20, 0) ("storeDiskdCleanupDoubleCheck: FILENO %08X\n", e->swap_filen); debug(20, 0) ("storeDiskdCleanupDoubleCheck: PATH %s\n", storeDiskdDirFullPath(sd, e->swap_filen, NULL)); debug(20,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -