--------------------- PatchSet 402 Date: 2002/12/15 07:27:02 Author: rbcollins Branch: unify-io Tag: (none) Log: remove fsdata completely Members: src/ufscommon.cc:1.4.10.42->1.4.10.43 src/ufscommon.h:1.1.20.59->1.1.20.60 src/fs/aufs/store_dir_aufs.cc:1.2.12.34->1.2.12.35 src/fs/diskd/store_dir_diskd.cc:1.2.16.42->1.2.16.43 src/fs/ufs/store_dir_ufs.cc:1.1.20.37->1.1.20.38 Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.42 retrieving revision 1.4.10.43 diff -u -r1.4.10.42 -r1.4.10.43 --- squid3/src/ufscommon.cc 15 Dec 2002 06:57:45 -0000 1.4.10.42 +++ squid3/src/ufscommon.cc 15 Dec 2002 07:27:02 -0000 1.4.10.43 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.42 2002/12/15 06:57:45 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.43 2002/12/15 07:27:02 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -110,10 +110,8 @@ static int n_dirs = 0; static int *dir_index = NULL; -static int commonUfsFilenoBelongsHere(int fn, int F0, int F1, int F2); static int commonUfsDirVerifyDirectory(const char *path); static QS rev_int_sort; -static int commonUfsDirClean(int swap_index); int UFSSwapDir::mapBitTest(sfileno filn) @@ -173,10 +171,8 @@ char * UFSSwapDir::swapSubDir(int subdirn)const { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; - LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); - assert(0 <= subdirn && subdirn < ioinfo->l1); + assert(0 <= subdirn && subdirn < l1); snprintf(fullfilename, SQUID_MAXPATHLEN, "%s/%02X", path, subdirn); return fullfilename; } @@ -230,12 +226,11 @@ bool UFSSwapDir::verifyCacheDirs() { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; int j; if (commonUfsDirVerifyDirectory(path) < 0) return true; - for (j = 0; j < ioinfo->l1; j++) { + for (j = 0; j < l1; j++) { char const *aPath = swapSubDir(j); if (commonUfsDirVerifyDirectory(aPath) < 0) return true; @@ -246,18 +241,17 @@ void UFSSwapDir::createSwapSubDirs() { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; int i, k; int should_exist; LOCAL_ARRAY(char, name, MAXPATHLEN); - for (i = 0; i < ioinfo->l1; i++) { + for (i = 0; i < l1; i++) { snprintf(name, MAXPATHLEN, "%s/%02X", path, i); if (createDirectory(name, 0)) should_exist = 0; else should_exist = 1; debug(47, 1) ("Making directories in %s\n", name); - for (k = 0; k < ioinfo->l2; k++) { + for (k = 0; k < l2; k++) { snprintf(name, MAXPATHLEN, "%s/%02X/%02X", path, i, k); createDirectory(name, should_exist); } @@ -647,7 +641,6 @@ int RebuildState::getNextFile(sfileno * filn_p, int *size) { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) sd->fsdata; int fd = -1; int dirs_opened = 0; debug(47, 3) ("commonUfsDirGetNextFile: flag=%d, %d: /%02X/%02X\n", @@ -693,7 +686,7 @@ entry->d_name); continue; } - if (!commonUfsFilenoBelongsHere(fn, sd->index, curlvl1, curlvl2)) { + if (!UFSSwapDir::FilenoBelongsHere(fn, sd->index, curlvl1, curlvl2)) { debug(47, 3) ("commonUfsDirGetNextFile: %08X does not belong in %d/%d/%d\n", fn, sd->index, curlvl1, curlvl2); continue; @@ -716,10 +709,10 @@ closedir(td); td = NULL; in_dir = 0; - if (++curlvl2 < ioinfo->l2) + if (sd->validL2(++curlvl2)) continue; curlvl2 = 0; - if (++curlvl1 < ioinfo->l1) + if (sd->validL1(++curlvl1)) continue; curlvl1 = 0; done = 1; @@ -728,6 +721,18 @@ return fd; } +bool +UFSSwapDir::validL1(int anInt) const +{ + return anInt < l1; +} + +bool +UFSSwapDir::validL2(int anInt) const +{ + return anInt < l2; +} + /* Add a new object to the cache with empty memory copy and pointer to disk * use to rebuild store from disk. */ StoreEntry * @@ -1084,7 +1089,7 @@ } int -commonUfsDirClean(int swap_index) +UFSSwapDir::DirClean(int swap_index) { DIR *dp = NULL; struct dirent *de = NULL; @@ -1101,15 +1106,13 @@ int N0, N1, N2; int D0, D1, D2; UFSSwapDir *SD; - squidufsinfo_t *ioinfo; N0 = n_dirs; D0 = dir_index[swap_index % N0]; SD = dynamic_cast(INDEXSD(D0)); assert (SD); - ioinfo = (squidufsinfo_t *) SD->fsdata; - N1 = ioinfo->l1; + N1 = SD->l1; D1 = (swap_index / N0) % N1; - N2 = ioinfo->l2; + N2 = SD->l2; D2 = ((swap_index / N0) / N1) % N2; snprintf(p1, SQUID_MAXPATHLEN, "%s/%02X/%02X", SD->path, D1, D2); @@ -1135,7 +1138,7 @@ fn = swapfileno; /* XXX should remove this cruft ! */ if (SD->validFileno(fn, 1)) if (SD->mapBitTest(fn)) - if (commonUfsFilenoBelongsHere(fn, D0, D1, D2)) + if (UFSSwapDir::FilenoBelongsHere(fn, D0, D1, D2)) continue; #if USE_TRUNCATE if (!stat(de->d_name, &sb)) @@ -1178,7 +1181,6 @@ assert(n_dirs); if (NULL == dir_index) { SwapDir *sd; - squidufsinfo_t *ioinfo; /* * Initialize the little array that translates UFS cache_dir * number into the Config.cacheSwap.swapDirs array index. @@ -1191,8 +1193,7 @@ UFSSwapDir *usd = dynamic_cast(sd); assert (usd); dir_index[n++] = i; - ioinfo = (squidufsinfo_t *) usd->fsdata; - j += (ioinfo->l1 * ioinfo->l2); + j += (usd->l1 * usd->l2); } assert(n == n_dirs); /* @@ -1203,7 +1204,7 @@ swap_index = (int) (squid_random() % j); } if (0 == store_dirs_rebuilding) { - n = commonUfsDirClean(swap_index); + n = DirClean(swap_index); swap_index++; } eventAdd("storeDirClean", CleanEvent, NULL, @@ -1220,20 +1221,23 @@ /* * Does swapfile number 'fn' belong in cachedir #F0, * level1 dir #F1, level2 dir #F2? + * XXX: this is broken - it assumes all cache dirs use the same + * l1 and l2 scheme. -RBC 20021215. Partial fix is in place - + * if not UFSSwapDir return 0; */ int -commonUfsFilenoBelongsHere(int fn, int F0, int F1, int F2) +UFSSwapDir::FilenoBelongsHere(int fn, int F0, int F1, int F2) { int D1, D2; int L1, L2; int filn = fn; - squidufsinfo_t *ioinfo; assert(F0 < Config.cacheSwap.n_configured); assert (UFSSwapDir::IsUFSDir (INDEXSD(F0))); UFSSwapDir *sd = dynamic_cast(INDEXSD(F0)); - ioinfo = (squidufsinfo_t *) sd->fsdata; - L1 = ioinfo->l1; - L2 = ioinfo->l2; + if (!sd) + return 0; + L1 = sd->l1; + L2 = sd->l2; D1 = ((filn / L2) / L2) % L1; if (F1 != D1) return 0; @@ -1396,20 +1400,18 @@ void UFSSwapDir::dump(StoreEntry & entry) const { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; storeAppendPrintf(&entry, " %d %d %d", max_size >> 10, - ioinfo->l1, - ioinfo->l2); + l1, + l2); } char * UFSSwapDir::fullPath(sfileno filn, char *fullpath) const { LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; - int L1 = ioinfo->l1; - int L2 = ioinfo->l2; + int L1 = l1; + int L2 = l2; if (!fullpath) fullpath = fullfilename; fullpath[0] = '\0'; Index: squid3/src/ufscommon.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.h,v retrieving revision 1.1.20.59 retrieving revision 1.1.20.60 diff -u -r1.1.20.59 -r1.1.20.60 --- squid3/src/ufscommon.h 15 Dec 2002 06:57:46 -0000 1.1.20.59 +++ squid3/src/ufscommon.h 15 Dec 2002 07:27:02 -0000 1.1.20.60 @@ -1,6 +1,6 @@ /* - * $Id: ufscommon.h,v 1.1.20.59 2002/12/15 06:57:46 rbcollins Exp $ + * $Id: ufscommon.h,v 1.1.20.60 2002/12/15 07:27:02 rbcollins Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -44,13 +44,6 @@ void (*storeDirUnlinkFile) (char *); }; -typedef struct _squidufsinfo_t squidufsinfo_t; -struct _squidufsinfo_t { - int l1; - int l2; -// int suggest; -}; - /* Common UFS routines */ FREE storeSwapLogDataFree; void commonUfsDirUnlinkFile(SwapDir * SD, sfileno f); @@ -69,6 +62,8 @@ class UFSSwapDir : public SwapDir { public: static int IsUFSDir(SwapDir* sd); + static int DirClean(int swap_index); + static int FilenoBelongsHere(int fn, int F0, int F1, int F2); UFSSwapDir(); virtual void init(); @@ -115,10 +110,16 @@ int validFileno(sfileno filn, int flag) const; int mapBitAllocate(); void *fsdata; + + bool validL2(int) const; + bool validL1(int) const; + protected: fileMap *map; iospecific_t io; int suggest; + int l1; + int l2; private: int swaplog_fd; static EVH CleanEvent; Index: squid3/src/fs/aufs/store_dir_aufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_dir_aufs.cc,v retrieving revision 1.2.12.34 retrieving revision 1.2.12.35 diff -u -r1.2.12.34 -r1.2.12.35 --- squid3/src/fs/aufs/store_dir_aufs.cc 15 Dec 2002 06:57:46 -0000 1.2.12.34 +++ squid3/src/fs/aufs/store_dir_aufs.cc 15 Dec 2002 07:27:02 -0000 1.2.12.35 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.2.12.34 2002/12/15 06:57:46 rbcollins Exp $ + * $Id: store_dir_aufs.cc,v 1.2.12.35 2002/12/15 07:27:02 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -157,9 +157,6 @@ { int i; int size; - int l1; - int l2; - squidufsinfo_t *aioinfo; i = GetInteger(); size = i << 10; /* Mbytes to kbytes */ @@ -174,16 +171,9 @@ if (l2 <= 0) fatal("storeAufsDirParse: invalid level 2 directories value"); - aioinfo = (squidufsinfo_t *)xmalloc(sizeof(squidufsinfo_t)); - if (aioinfo == NULL) - fatal("storeAufsDirParse: couldn't xmalloc() squidufsinfo_t!\n"); - index = anIndex; path = xstrdup(aPath); max_size = size; - fsdata = aioinfo; - aioinfo->l1 = l1; - aioinfo->l2 = l2; io.storeDirUnlinkFile = storeAufsDirIOUnlinkFile; parse_cachedir_options(this, options, 0); Index: squid3/src/fs/diskd/store_dir_diskd.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_dir_diskd.cc,v retrieving revision 1.2.16.42 retrieving revision 1.2.16.43 diff -u -r1.2.16.42 -r1.2.16.43 --- squid3/src/fs/diskd/store_dir_diskd.cc 15 Dec 2002 06:57:46 -0000 1.2.16.42 +++ squid3/src/fs/diskd/store_dir_diskd.cc 15 Dec 2002 07:27:02 -0000 1.2.16.43 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.2.16.42 2002/12/15 06:57:46 rbcollins Exp $ + * $Id: store_dir_diskd.cc,v 1.2.16.43 2002/12/15 07:27:02 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -366,9 +366,6 @@ { int i; int size; - int l1; - int l2; - squidufsinfo_t *ufsinfo; i = GetInteger(); size = i << 10; /* Mbytes to kbytes */ @@ -383,12 +380,9 @@ if (l2 <= 0) fatal("storeDiskdDirParse: invalid level 2 directories value"); - fsdata = ufsinfo = (squidufsinfo_t *)xcalloc(1, sizeof(*ufsinfo)); index = anIndex; path = xstrdup(aPath); max_size = size; - ufsinfo->l1 = l1; - ufsinfo->l2 = l2; io.storeDirUnlinkFile = storeDiskdDirIOUnlinkFile; parse_cachedir_options(this, options, 0); 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.37 retrieving revision 1.1.20.38 diff -u -r1.1.20.37 -r1.1.20.38 --- squid3/src/fs/ufs/store_dir_ufs.cc 15 Dec 2002 06:57:46 -0000 1.1.20.37 +++ squid3/src/fs/ufs/store_dir_ufs.cc 15 Dec 2002 07:27:02 -0000 1.1.20.38 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.1.20.37 2002/12/15 06:57:46 rbcollins Exp $ + * $Id: store_dir_ufs.cc,v 1.1.20.38 2002/12/15 07:27:02 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -138,9 +138,6 @@ { int i; int size; - int l1; - int l2; - squidufsinfo_t *ufsinfo; i = GetInteger(); size = i << 10; /* Mbytes to kbytes */ @@ -155,16 +152,9 @@ if (l2 <= 0) fatal("storeUfsDirParse: invalid level 2 directories value"); - ufsinfo = (squidufsinfo_t *)xmalloc(sizeof(squidufsinfo_t)); - if (ufsinfo == NULL) - fatal("storeUfsDirParse: couldn't xmalloc() squidufsinfo_t!\n"); - index = anIndex; path = xstrdup(aPath); max_size = size; - fsdata = ufsinfo; - ufsinfo->l1 = l1; - ufsinfo->l2 = l2; io.storeDirUnlinkFile = storeUfsDirIOUnlinkFile; parse_cachedir_options(this, options, 1); @@ -208,15 +198,11 @@ UFSSwapDir::~UFSSwapDir() { - squidufsinfo_t *ioinfo = (squidufsinfo_t *) fsdata; if (swaplog_fd > -1) { file_close(swaplog_fd); swaplog_fd = -1; } filemapFreeMemory(map); - xfree(ioinfo); - /* This memory leaks. XXX: FIXME - fsdata needs to go away */ - fsdata = NULL; /* Will aid debugging... */ if (IO) IO->deleteSelf(); IO = NULL; @@ -282,14 +268,13 @@ void UFSSwapDir::statfs(StoreEntry & sentry) const { - squidufsinfo_t *ioinfo = (squidufsinfo_t *)fsdata; int totl_kb = 0; int free_kb = 0; int totl_in = 0; int free_in = 0; int x; - storeAppendPrintf(&sentry, "First level subdirectories: %d\n", ioinfo->l1); - storeAppendPrintf(&sentry, "Second level subdirectories: %d\n", ioinfo->l2); + storeAppendPrintf(&sentry, "First level subdirectories: %d\n", l1); + storeAppendPrintf(&sentry, "Second level subdirectories: %d\n", l2); storeAppendPrintf(&sentry, "Maximum Size: %d KB\n", max_size); storeAppendPrintf(&sentry, "Current Size: %d KB\n", cur_size); storeAppendPrintf(&sentry, "Percent Used: %0.2f%%\n",