--------------------- PatchSet 343 Date: 2002/12/13 08:50:39 Author: rbcollins Branch: unify-io Tag: (none) Log: move ufs init routine to it's final home Members: src/ufscommon.cc:1.4.10.7->1.4.10.8 src/ufscommon.h:1.1.20.30->1.1.20.31 src/fs/ufs/store_dir_ufs.cc:1.1.20.8->1.1.20.9 Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.7 retrieving revision 1.4.10.8 diff -u -r1.4.10.7 -r1.4.10.8 --- squid3/src/ufscommon.cc 13 Dec 2002 08:22:57 -0000 1.4.10.7 +++ squid3/src/ufscommon.cc 13 Dec 2002 08:50:39 -0000 1.4.10.8 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.7 2002/12/13 08:22:57 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.8 2002/12/13 08:50:39 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -70,7 +70,6 @@ static int commonUfsFilenoBelongsHere(int fn, int F0, int F1, int F2); static char *commonUfsDirSwapSubDir(SwapDir *, int subdirn); static int commonUfsDirCreateDirectory(const char *path, int); -static int commonUfsDirVerifyCacheDirs(SwapDir * sd); static int commonUfsDirVerifyDirectory(const char *path); static void commonUfsDirCreateSwapSubDirs(SwapDir *); static int commonUfsDirMapBitTest(SwapDir * SD, sfileno filn); @@ -88,7 +87,6 @@ u_int32_t refcount, u_int16_t flags, int clean); -static void commonUfsDirRebuild(SwapDir * sd); static void commonUfsDirCloseTmpSwapLog(SwapDir * sd); static FILE *commonUfsDirOpenTmpSwapLog(SwapDir *, int *, int *); #if 0 @@ -107,13 +105,11 @@ #endif static QS rev_int_sort; static void commonUfsDirMapBitSet(SwapDir * SD, sfileno filn); -static EVH commonUfsDirCleanEvent; static int commonUfsDirClean(int swap_index); static int commonUfsDirIs(SwapDir * sd); #if 0 static int commonUfsCleanupDoubleCheck(SwapDir *, StoreEntry *); #endif -static void commonUfsDirInitBitmap(SwapDir *); static int commonUfsDirValidFileno(SwapDir * SD, sfileno filn, int flag); static int commonUfsDirMapBitTest(SwapDir * SD, sfileno filn); void commonUfsDirMapBitReset(SwapDir * SD, sfileno filn); @@ -181,9 +177,9 @@ * configured, we allocate a new bitmap and 'grow' the old one into it. */ void -commonUfsDirInitBitmap(SwapDir * sd) +UFSSwapDir::initBitmap() { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) sd->fsdata; + squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; if (ioinfo->map == NULL) { /* First time */ @@ -252,21 +248,20 @@ * then Squid exits, complains about swap directories not * existing, and instructs the admin to run 'squid -z' */ -int -commonUfsDirVerifyCacheDirs(SwapDir * sd) +bool +UFSSwapDir::verifyCacheDirs() { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) sd->fsdata; + squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; int j; - const char *path = sd->path; if (commonUfsDirVerifyDirectory(path) < 0) - return -1; + return true; for (j = 0; j < ioinfo->l1; j++) { - path = commonUfsDirSwapSubDir(sd, j); - if (commonUfsDirVerifyDirectory(path) < 0) - return -1; + char const *aPath = commonUfsDirSwapSubDir(this, j); + if (commonUfsDirVerifyDirectory(aPath) < 0) + return true; } - return 0; + return false; } void @@ -357,26 +352,6 @@ } void -UFSSwapDir::init() -{ - static int started_clean_event = 0; - static const char *errmsg = - "\tFailed to verify one of the swap directories, Check cache.log\n" - "\tfor details. Run 'squid -z' to create swap directories\n" - "\tif needed, or if running Squid for the first time."; - commonUfsDirInitBitmap(this); - if (commonUfsDirVerifyCacheDirs(this) < 0) - fatal(errmsg); - commonUfsDirOpenSwapLog(this); - commonUfsDirRebuild(this); - if (!started_clean_event) { - eventAdd("storeDirClean", commonUfsDirCleanEvent, NULL, 15.0, 1); - started_clean_event = 1; - } - (void) storeDirGetBlkSize(this->path, &fs.blksize); -} - -void commonUfsDirRebuildFromDirectory(void *data) { RebuildState *rb = (RebuildState *)data; @@ -826,7 +801,7 @@ CBDATA_TYPE(RebuildState); void -commonUfsDirRebuild(SwapDir * sd) +UFSSwapDir::rebuild() { RebuildState *rb; int clean = 0; @@ -835,7 +810,7 @@ EVH *func = NULL; CBDATA_INIT_TYPE(RebuildState); rb = cbdataAlloc(RebuildState); - rb->sd = sd; + rb->sd = this; rb->speed = opt_foreground_rebuild ? 1 << 30 : 50; /* * If the swap.state file exists in the cache_dir, then @@ -843,7 +818,7 @@ * use commonUfsDirRebuildFromDirectory() to open up each file * and suck in the meta data. */ - fp = commonUfsDirOpenTmpSwapLog(sd, &clean, &zero); + fp = commonUfsDirOpenTmpSwapLog(this, &clean, &zero); if (fp == NULL || zero) { if (fp != NULL) fclose(fp); @@ -856,7 +831,7 @@ if (!clean) rb->flags.need_to_validate = 1; debug(47, 1) ("Rebuilding storage in %s (%s)\n", - sd->path, clean ? "CLEAN" : "DIRTY"); + path, clean ? "CLEAN" : "DIRTY"); store_dirs_rebuilding++; eventAdd("storeRebuild", func, rb, 0.0, 1); } @@ -1225,14 +1200,14 @@ } void -commonUfsDirCleanEvent(void *unused) +UFSSwapDir::CleanEvent(void *unused) { static int swap_index = 0; int i; int j = 0; int n = 0; /* - * Assert that there are AUFS cache_dirs configured, otherwise + * Assert that there are UFS cache_dirs configured, otherwise * we should never be called. */ assert(n_dirs); @@ -1240,7 +1215,7 @@ SwapDir *sd; squidufsinfo_t *ioinfo; /* - * Initialize the little array that translates AUFS cache_dir + * Initialize the little array that translates UFS cache_dir * number into the Config.cacheSwap.swapDirs array index. */ dir_index = (int *)xcalloc(n_dirs, sizeof(*dir_index)); @@ -1255,7 +1230,7 @@ assert(n == n_dirs); /* * Start the commonUfsDirClean() swap_index with a random - * value. j equals the total number of AUFS level 2 + * value. j equals the total number of UFS level 2 * swap directories */ swap_index = (int) (squid_random() % j); @@ -1264,7 +1239,7 @@ n = commonUfsDirClean(swap_index); swap_index++; } - eventAdd("storeDirClean", commonUfsDirCleanEvent, NULL, + eventAdd("storeDirClean", CleanEvent, NULL, 15.0 * exp(-0.25 * n), 1); } Index: squid3/src/ufscommon.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.h,v retrieving revision 1.1.20.30 retrieving revision 1.1.20.31 diff -u -r1.1.20.30 -r1.1.20.31 --- squid3/src/ufscommon.h 13 Dec 2002 08:22:57 -0000 1.1.20.30 +++ squid3/src/ufscommon.h 13 Dec 2002 08:50:39 -0000 1.1.20.31 @@ -1,6 +1,6 @@ /* - * $Id: ufscommon.h,v 1.1.20.30 2002/12/13 08:22:57 rbcollins Exp $ + * $Id: ufscommon.h,v 1.1.20.31 2002/12/13 08:50:39 rbcollins Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -84,6 +84,11 @@ class UFSSwapDir : public SwapDir { public: virtual void init(); +private: + static EVH CleanEvent; + void initBitmap(); + bool verifyCacheDirs(); + void rebuild(); }; #include "RefCount.h" Index: squid3/src/fs/ufs/store_dir_ufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/store_dir_ufs.cc,v retrieving revision 1.1.20.8 retrieving revision 1.1.20.9 diff -u -r1.1.20.8 -r1.1.20.9 --- squid3/src/fs/ufs/store_dir_ufs.cc 13 Dec 2002 08:22:58 -0000 1.1.20.8 +++ squid3/src/fs/ufs/store_dir_ufs.cc 13 Dec 2002 08:50:39 -0000 1.1.20.9 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.1.20.8 2002/12/13 08:22:58 rbcollins Exp $ + * $Id: store_dir_ufs.cc,v 1.1.20.9 2002/12/13 08:50:39 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -202,6 +202,26 @@ /* * Initial setup / end destruction */ +void +UFSSwapDir::init() +{ + static int started_clean_event = 0; + static const char *errmsg = + "\tFailed to verify one of the swap directories, Check cache.log\n" + "\tfor details. Run 'squid -z' to create swap directories\n" + "\tif needed, or if running Squid for the first time."; + initBitmap(); + if (verifyCacheDirs()) + fatal(errmsg); + commonUfsDirOpenSwapLog(this); + rebuild(); + if (!started_clean_event) { + eventAdd("UFS storeDirClean", CleanEvent, NULL, 15.0, 1); + started_clean_event = 1; + } + (void) storeDirGetBlkSize(path, &fs.blksize); +} + static void storeUfsDirDone(void) {