--------------------- PatchSet 405 Date: 2002/12/15 12:19:50 Author: rbcollins Branch: unify-io Tag: (none) Log: and more methodisation Members: src/ufscommon.cc:1.4.10.43->1.4.10.44 src/ufscommon.h:1.1.20.60->1.1.20.61 src/fs/aufs/store_asyncufs.h:1.2.12.42->1.2.12.43 src/fs/aufs/store_dir_aufs.cc:1.2.12.36->1.2.12.37 src/fs/aufs/store_io_aufs.cc:1.3.12.39->1.3.12.40 src/fs/diskd/store_dir_diskd.cc:1.2.16.44->1.2.16.45 src/fs/diskd/store_diskd.h:1.1.20.44->1.1.20.45 src/fs/diskd/store_io_diskd.cc:1.1.20.43->1.1.20.44 src/fs/ufs/store_dir_ufs.cc:1.1.20.39->1.1.20.40 src/fs/ufs/store_io_ufs.cc:1.3.10.47->1.3.10.48 src/fs/ufs/store_ufs.h:1.1.20.31->1.1.20.32 Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.43 retrieving revision 1.4.10.44 diff -u -r1.4.10.43 -r1.4.10.44 --- squid3/src/ufscommon.cc 15 Dec 2002 07:27:02 -0000 1.4.10.43 +++ squid3/src/ufscommon.cc 15 Dec 2002 12:19:50 -0000 1.4.10.44 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.43 2002/12/15 07:27:02 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.44 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -110,112 +110,21 @@ static int n_dirs = 0; static int *dir_index = NULL; -static int commonUfsDirVerifyDirectory(const char *path); static QS rev_int_sort; -int -UFSSwapDir::mapBitTest(sfileno filn) -{ - return file_map_bit_test(map, filn); -} - -void -UFSSwapDir::mapBitSet(sfileno filn) -{ - file_map_bit_set(map, filn); -} - -void -UFSSwapDir::mapBitReset(sfileno filn) -{ - /* - * We have to test the bit before calling file_map_bit_reset. - * file_map_bit_reset doesn't do bounds checking. It assumes - * filn is a valid file number, but it might not be because - * the map is dynamic in size. Also clearing an already clear - * bit puts the map counter of-of-whack. - */ - if (file_map_bit_test(map, filn)) - file_map_bit_reset(map, filn); -} - -int -UFSSwapDir::mapBitAllocate() -{ - int fn; - fn = file_map_allocate(map, suggest); - file_map_bit_set(map, fn); - suggest = fn + 1; - return fn; -} - -/* - * Initialise the asyncufs bitmap - * - * If there already is a bitmap, and the numobjects is larger than currently - * configured, we allocate a new bitmap and 'grow' the old one into it. - */ -void -UFSSwapDir::initBitmap() -{ - if (map == NULL) { - /* First time */ - map = file_map_create(); - } else if (map->max_n_files) { - /* it grew, need to expand */ - /* XXX We don't need it anymore .. */ - } - /* else it shrunk, and we leave the old one in place */ -} - -char * -UFSSwapDir::swapSubDir(int subdirn)const -{ - LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); - assert(0 <= subdirn && subdirn < l1); - snprintf(fullfilename, SQUID_MAXPATHLEN, "%s/%02X", path, subdirn); - return fullfilename; -} - -int -UFSSwapDir::createDirectory(const char *path, int should_exist) -{ - int created = 0; - struct stat st; - getCurrentTime(); - if (0 == stat(path, &st)) { - if (S_ISDIR(st.st_mode)) { - debug(47, should_exist ? 3 : 1) ("%s exists\n", path); - } else { - fatalf("Swap directory %s is not a directory.", path); - } -#ifdef _SQUID_MSWIN_ - } else if (0 == mkdir(path)) { -#else - } else if (0 == mkdir(path, 0755)) { -#endif - debug(47, should_exist ? 1 : 3) ("%s created\n", path); - created = 1; - } else { - fatalf("Failed to make swap directory %s: %s", - path, xstrerror()); - } - return created; -} - -int -commonUfsDirVerifyDirectory(const char *path) +bool +UFSSwapDir::pathIsDirectory(const char *path)const { struct stat sb; if (stat(path, &sb) < 0) { debug(47, 0) ("%s: %s\n", path, xstrerror()); - return -1; + return false; } if (S_ISDIR(sb.st_mode) == 0) { debug(47, 0) ("%s is not a directory\n", path); - return -1; + return false; } - return 0; + return true; } /* @@ -228,11 +137,11 @@ { int j; - if (commonUfsDirVerifyDirectory(path) < 0) + if (!pathIsDirectory(path)) return true; for (j = 0; j < l1; j++) { char const *aPath = swapSubDir(j); - if (commonUfsDirVerifyDirectory(aPath) < 0) + if (!pathIsDirectory(aPath)) return true; } return false; @@ -389,7 +298,7 @@ if (tlv_list == NULL) { debug(47, 1) ("commonUfsDirRebuildFromDirectory: failed to get meta data\n"); /* XXX shouldn't this be a call to commonUfsUnlink ? */ - commonUfsDirUnlinkFile(sd, filn); + sd->unlinkFile (filn); continue; } debug(47, 3) ("commonUfsDirRebuildFromDirectory: successful swap meta unpacking\n"); @@ -413,7 +322,7 @@ tlv_list = NULL; if (storeKeyNull(key)) { debug(47, 1) ("commonUfsDirRebuildFromDirectory: NULL key\n"); - commonUfsDirUnlinkFile(sd, filn); + sd->unlinkFile(filn); continue; } tmpe.key = key; @@ -425,11 +334,11 @@ } else if (tmpe.swap_file_sz != (size_t)sb.st_size) { debug(47, 1) ("commonUfsDirRebuildFromDirectory: SIZE MISMATCH %ld!=%ld\n", (long int) tmpe.swap_file_sz, (long int) sb.st_size); - commonUfsDirUnlinkFile(sd, filn); + sd->unlinkFile(filn); continue; } if (EBIT_TEST(tmpe.flags, KEY_PRIVATE)) { - commonUfsDirUnlinkFile(sd, filn); + sd->unlinkFile(filn); counts.badflags++; continue; } @@ -518,7 +427,7 @@ storeExpireNow(e); storeReleaseRequest(e); if (e->swap_filen > -1) { - commonUfsDirReplRemove(e); + sd->replacementRemove(e); sd->mapBitReset(e->swap_filen); e->swap_filen = -1; e->swap_dirn = -1; @@ -608,7 +517,7 @@ storeExpireNow(e); storeReleaseRequest(e); if (e->swap_filen > -1) { - commonUfsDirReplRemove(e); + sd->replacementRemove(e); /* Make sure we don't actually unlink the file */ sd->mapBitReset(e->swap_filen); e->swap_filen = -1; @@ -772,7 +681,7 @@ EBIT_CLR(e->flags, ENTRY_VALIDATED); mapBitSet(e->swap_filen); storeHashInsert(e, key); /* do it after we clear KEY_PRIVATE */ - commonUfsDirReplAdd(this, e); + replacementAdd (e); return e; } @@ -1262,84 +1171,46 @@ return 1; } -#if 0 /* - * commonUfsDirCheckObj - * - * This routine is called by storeDirSelectSwapDir to see if the given - * object is able to be stored on this filesystem. AUFS filesystems will - * happily store anything as long as the LRU time isn't too small. - */ -int -commonUfsDirCheckObj(SwapDir * SD, const StoreEntry * e) -{ - int loadav; - int ql; - -#if OLD_UNUSED_CODE - if (commonUfsDirExpiredReferenceAge(SD) < 300) { - debug(47, 3) ("commonUfsDirCheckObj: NO: LRU Age = %d\n", - commonUfsDirExpiredReferenceAge(SD)); - /* store_check_cachable_hist.no.lru_age_too_low++; */ - return -1; - } -#endif - ql = aioQueueSize(); - if (ql == 0) - loadav = 0; - loadav = ql * 1000 / MAGIC1; - debug(47, 9) ("commonUfsDirCheckObj: load=%d\n", loadav); - return loadav; -} -#endif - -/* - * commonUfsDirUnlinkFile + * UFSSwapDir::unlinkFile * * This routine unlinks a file and pulls it out of the bitmap. * It used to be in commonUfsUnlink(), however an interface change * forced this bit of code here. Eeek. */ void -commonUfsDirUnlinkFile(SwapDir * SD, sfileno f) -{ - ((UFSSwapDir*)SD)->unlinkFile(f); -} - -void UFSSwapDir::unlinkFile(sfileno f) { - debug(79, 3) ("commonUfsDirUnlinkFile: unlinking fileno %08X\n", f); + debug(79, 3) ("UFSSwapDir::unlinkFile: unlinking fileno %08X\n", f); /* commonUfsDirMapBitReset(this, f); */ - assert(io.storeDirUnlinkFile); - io.storeDirUnlinkFile(fullPath(f, NULL)); + unlinkFile(fullPath(f, NULL)); } - /* * Add and remove the given StoreEntry from the replacement policy in * use. */ void -commonUfsDirReplAdd(SwapDir * SD, StoreEntry * e) +UFSSwapDir::replacementAdd(StoreEntry * e) { - debug(47, 4) ("commonUfsDirReplAdd: added node %p to dir %d\n", e, - SD->index); - SD->repl->Add(SD->repl, e, &e->repl); + debug(47, 4) ("UFSSwapDir::replacementAdd: added node %p to dir %d\n", e, + index); + repl->Add(repl, e, &e->repl); } void -commonUfsDirReplRemove(StoreEntry * e) +UFSSwapDir::replacementRemove(StoreEntry * e) { SwapDir *SD; if (e->swap_dirn < 0) return; SD = INDEXSD(e->swap_dirn); - debug(47, 4) ("commonUfsDirReplRemove: remove node %p from dir %d\n", e, - SD->index); - SD->repl->Remove(SD->repl, e, &e->repl); + assert (dynamic_cast(SD) == this); + debug(47, 4) ("UFSSwapDir::replacementRemove: remove node %p from dir %d\n", e, + index); + repl->Remove(repl, e, &e->repl); } Index: squid3/src/ufscommon.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.h,v retrieving revision 1.1.20.60 retrieving revision 1.1.20.61 diff -u -r1.1.20.60 -r1.1.20.61 --- squid3/src/ufscommon.h 15 Dec 2002 07:27:02 -0000 1.1.20.60 +++ squid3/src/ufscommon.h 15 Dec 2002 12:19:50 -0000 1.1.20.61 @@ -1,6 +1,6 @@ /* - * $Id: ufscommon.h,v 1.1.20.60 2002/12/15 07:27:02 rbcollins Exp $ + * $Id: ufscommon.h,v 1.1.20.61 2002/12/15 12:19:50 rbcollins Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -39,22 +39,8 @@ #define DefaultLevelTwoDirs 256 #define STORE_META_BUFSZ 4096 -typedef struct _iospecific_t iospecific_t; -struct _iospecific_t { - void (*storeDirUnlinkFile) (char *); -}; - /* Common UFS routines */ FREE storeSwapLogDataFree; -void commonUfsDirUnlinkFile(SwapDir * SD, sfileno f); -void commonUfsDirMaintain(SwapDir * SD); -void commonUfsDirRefObj(SwapDir * SD, StoreEntry * e); -void commonUfsDirUnrefObj(SwapDir * SD, StoreEntry * e); -void commonUfsDirReplAdd(SwapDir * SD, StoreEntry * e); -void commonUfsDirReplRemove(StoreEntry * e); -void commonUfsDirStats(SwapDir * SD, StoreEntry * sentry); -void commonUfsDirFree(SwapDir * s); -int commonUfsCleanupDoubleCheck(SwapDir * sd, StoreEntry * e); #include "SwapDir.h" class UFSStrategy; @@ -86,6 +72,7 @@ virtual void logEntry(const StoreEntry & e, int op) const; void unlinkFile(sfileno f); + virtual void unlinkFile (char const *) = 0; // move down when unlink is a virtual method //protected: UFSStrategy *IO; @@ -114,13 +101,15 @@ bool validL2(int) const; bool validL1(int) const; + void replacementAdd(StoreEntry *e); + void replacementRemove(StoreEntry *e); protected: fileMap *map; - iospecific_t io; int suggest; int l1; int l2; private: + bool pathIsDirectory(const char *path)const; int swaplog_fd; static EVH CleanEvent; void initBitmap(); Index: squid3/src/fs/aufs/store_asyncufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_asyncufs.h,v retrieving revision 1.2.12.42 retrieving revision 1.2.12.43 diff -u -r1.2.12.42 -r1.2.12.43 --- squid3/src/fs/aufs/store_asyncufs.h 15 Dec 2002 08:23:07 -0000 1.2.12.42 +++ squid3/src/fs/aufs/store_asyncufs.h 15 Dec 2002 12:19:50 -0000 1.2.12.43 @@ -161,6 +161,7 @@ virtual void sync(); virtual void parse (int index, char *path); virtual void reconfigure(int, char *); + virtual void unlinkFile(char const *); }; #include "IOStrategy.h" 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.36 retrieving revision 1.2.12.37 diff -u -r1.2.12.36 -r1.2.12.37 --- squid3/src/fs/aufs/store_dir_aufs.cc 15 Dec 2002 08:23:07 -0000 1.2.12.36 +++ squid3/src/fs/aufs/store_dir_aufs.cc 15 Dec 2002 12:19:50 -0000 1.2.12.37 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.2.12.36 2002/12/15 08:23:07 rbcollins Exp $ + * $Id: store_dir_aufs.cc,v 1.2.12.37 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -45,9 +45,6 @@ MemPool *aufs_qwrite_pool = NULL; static int asyncufs_initialised = 0; -static void storeAufsDirIOUnlinkFile(char *path); - - /* The MAIN externally visible function */ STSETUP storeFsSetup_aufs; @@ -81,7 +78,7 @@ } void -storeAufsDirIOUnlinkFile(char *path) +AUFSSwapDir::unlinkFile(char const *path) { #if USE_TRUNCATE_NOT_UNLINK aioTruncate(path, NULL, NULL); @@ -172,7 +169,6 @@ index = anIndex; path = xstrdup(aPath); max_size = size; - io.storeDirUnlinkFile = storeAufsDirIOUnlinkFile; parse_cachedir_options(this, options, 0); Index: squid3/src/fs/aufs/store_io_aufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_io_aufs.cc,v retrieving revision 1.3.12.39 retrieving revision 1.3.12.40 diff -u -r1.3.12.39 -r1.3.12.40 --- squid3/src/fs/aufs/store_io_aufs.cc 14 Dec 2002 05:07:15 -0000 1.3.12.39 +++ squid3/src/fs/aufs/store_io_aufs.cc 15 Dec 2002 12:19:50 -0000 1.3.12.40 @@ -279,9 +279,9 @@ AUFSSwapDir::unlink(StoreEntry & e) { debug(79, 3) ("storeAufsUnlink: dirno %d, fileno %08X\n", index, e.swap_filen); - commonUfsDirReplRemove(&e); + replacementRemove(&e); mapBitReset(e.swap_filen); - unlinkFile(e.swap_filen); + UFSSwapDir::unlinkFile(e.swap_filen); } /* === STATIC =========================================================== */ 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.44 retrieving revision 1.2.16.45 diff -u -r1.2.16.44 -r1.2.16.45 --- squid3/src/fs/diskd/store_dir_diskd.cc 15 Dec 2002 08:23:07 -0000 1.2.16.44 +++ squid3/src/fs/diskd/store_dir_diskd.cc 15 Dec 2002 12:19:50 -0000 1.2.16.45 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.2.16.44 2002/12/15 08:23:07 rbcollins Exp $ + * $Id: store_dir_diskd.cc,v 1.2.16.45 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -51,7 +51,6 @@ static int diskd_initialised = 0; static void storeDiskdStats(StoreEntry * sentry); -static void storeDiskdDirIOUnlinkFile(char *path); /* The only externally visible interface */ STSETUP storeFsSetup_diskd; @@ -220,7 +219,7 @@ } void -storeDiskdDirIOUnlinkFile(char *path) +DiskdSwapDir::unlinkFile(char const *path) { #if USE_UNLINKD unlinkdUnlink(path); @@ -381,7 +380,6 @@ index = anIndex; path = xstrdup(aPath); max_size = size; - io.storeDirUnlinkFile = storeDiskdDirIOUnlinkFile; parse_cachedir_options(this, options, 0); Index: squid3/src/fs/diskd/store_diskd.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_diskd.h,v retrieving revision 1.1.20.44 retrieving revision 1.1.20.45 diff -u -r1.1.20.44 -r1.1.20.45 --- squid3/src/fs/diskd/store_diskd.h 15 Dec 2002 08:23:07 -0000 1.1.20.44 +++ squid3/src/fs/diskd/store_diskd.h 15 Dec 2002 12:19:50 -0000 1.1.20.45 @@ -141,6 +141,7 @@ virtual void sync(); virtual void parse (int index, char *path); virtual void reconfigure (int, char *); + virtual void unlinkFile(char const *); }; #define SHMBUF_BLKSZ SM_PAGE_SIZE Index: squid3/src/fs/diskd/store_io_diskd.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_io_diskd.cc,v retrieving revision 1.1.20.43 retrieving revision 1.1.20.44 diff -u -r1.1.20.43 -r1.1.20.44 --- squid3/src/fs/diskd/store_io_diskd.cc 14 Dec 2002 05:07:16 -0000 1.1.20.43 +++ squid3/src/fs/diskd/store_io_diskd.cc 15 Dec 2002 12:19:50 -0000 1.1.20.44 @@ -1,6 +1,6 @@ /* - * $Id: store_io_diskd.cc,v 1.1.20.43 2002/12/14 05:07:16 rbcollins Exp $ + * $Id: store_io_diskd.cc,v 1.1.20.44 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 79 Squid-side DISKD I/O functions. * AUTHOR: Duane Wessels @@ -518,12 +518,12 @@ debug(79, 3) ("storeDiskdUnlink: dirno %d, fileno %08X\n", index, e.swap_filen); - commonUfsDirReplRemove(&e); + replacementRemove(&e); mapBitReset(e.swap_filen); if (IO->shedLoad()) { /* Damn, we need to issue a sync unlink here :( */ debug(79, 2) ("storeDiskUnlink: Out of queue space, sync unlink\n"); - unlinkFile(e.swap_filen); + UFSSwapDir::unlinkFile(e.swap_filen); return; } /* We can attempt a diskd unlink */ 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.39 retrieving revision 1.1.20.40 diff -u -r1.1.20.39 -r1.1.20.40 --- squid3/src/fs/ufs/store_dir_ufs.cc 15 Dec 2002 08:23:07 -0000 1.1.20.39 +++ squid3/src/fs/ufs/store_dir_ufs.cc 15 Dec 2002 12:19:50 -0000 1.1.20.40 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.1.20.39 2002/12/15 08:23:07 rbcollins Exp $ + * $Id: store_dir_ufs.cc,v 1.1.20.40 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -42,7 +42,6 @@ #include "SwapDir.h" static int ufs_initialised = 0; -static void storeUfsDirIOUnlinkFile(char *path); STSETUP storeFsSetup_ufs; @@ -61,7 +60,7 @@ } void -storeUfsDirIOUnlinkFile(char *path) +UfsSwapDir::unlinkFile(char const *path) { #if USE_UNLINKD unlinkdUnlink(path); @@ -155,7 +154,6 @@ index = anIndex; path = xstrdup(aPath); max_size = size; - io.storeDirUnlinkFile = storeUfsDirIOUnlinkFile; parse_cachedir_options(this, options, 1); @@ -234,14 +232,14 @@ void UFSSwapDir::dumpEntry(StoreEntry &e) const { - debug(47, 0) ("commonUfsCleanupDoubleCheck: FILENO %08X\n", e.swap_filen); - debug(47, 0) ("commonUfsCleanupDoubleCheck: PATH %s\n", + debug(47, 0) ("UFSSwapDir::dumpEntry: FILENO %08X\n", e.swap_filen); + debug(47, 0) ("UFSSwapDir::dumpEntry: PATH %s\n", fullPath(e.swap_filen, NULL)); storeEntryDump(&e, 0); } /* - * commonUfsCleanupDoubleCheck + * UFSSwapDir::doubleCheck * * This is called by storeCleanup() if -S was given on the command line. */ @@ -250,13 +248,13 @@ { struct stat sb; if (stat(fullPath(e.swap_filen, NULL), &sb) < 0) { - debug(47, 0) ("commonUfsCleanupDoubleCheck: MISSING SWAP FILE\n"); + debug(47, 0) ("UFSSwapDir::doubleCheck: MISSING SWAP FILE\n"); dumpEntry(e); return true; } if ((off_t)e.swap_file_sz != sb.st_size) { - debug(47, 0) ("commonUfsCleanupDoubleCheck: SIZE MISMATCH\n"); - debug(47, 0) ("commonUfsCleanupDoubleCheck: ENTRY SIZE: %ld, FILE SIZE: %ld\n", + debug(47, 0) ("UFSSwapDir::doubleCheck: SIZE MISMATCH\n"); + debug(47, 0) ("UFSSwapDir::doubleCheck: ENTRY SIZE: %ld, FILE SIZE: %ld\n", (long int) e.swap_file_sz, (long int) sb.st_size); dumpEntry(e); return true; @@ -336,12 +334,12 @@ storeRelease(e); } walker->Done(walker); - debug(47, (removed ? 2 : 3)) ("commonUfsDirMaintain: %s removed %d/%d f=%.03f max_scan=%d\n", + debug(47, (removed ? 2 : 3)) ("UFSSwapDir::maintainfs: %s removed %d/%d f=%.03f max_scan=%d\n", path, removed, max_remove, f, max_scan); } /* - * commonUfsDirRefObj + * UFSSwapDir::reference * * This routine is called whenever an object is referenced, so we can * maintain replacement information within the storage fs. @@ -349,21 +347,21 @@ void UFSSwapDir::reference(StoreEntry &e) { - debug(47, 3) ("commonUfsDirRefObj: referencing %p %d/%d\n", &e, e.swap_dirn, + debug(47, 3) ("UFSSwapDir::reference: referencing %p %d/%d\n", &e, e.swap_dirn, e.swap_filen); if (repl->Referenced) repl->Referenced(repl, &e, &e.repl); } /* - * commonUfsDirUnrefObj + * UFSSwapDir::dereference * This routine is called whenever the last reference to an object is * removed, to maintain replacement information within the storage fs. */ void UFSSwapDir::dereference(StoreEntry & e) { - debug(47, 3) ("commonUfsDirUnrefObj: referencing %p %d/%d\n", &e, e.swap_dirn, + debug(47, 3) ("UFSSwapDir::dereference: referencing %p %d/%d\n", &e, e.swap_dirn, e.swap_filen); if (repl->Dereferenced) repl->Dereferenced(repl, &e, &e.repl); @@ -380,3 +378,94 @@ { return IO->open (this, &e, file_callback, callback, callback_data); } + +int +UFSSwapDir::mapBitTest(sfileno filn) +{ + return file_map_bit_test(map, filn); +} + +void +UFSSwapDir::mapBitSet(sfileno filn) +{ + file_map_bit_set(map, filn); +} + +void +UFSSwapDir::mapBitReset(sfileno filn) +{ + /* + * We have to test the bit before calling file_map_bit_reset. + * file_map_bit_reset doesn't do bounds checking. It assumes + * filn is a valid file number, but it might not be because + * the map is dynamic in size. Also clearing an already clear + * bit puts the map counter of-of-whack. + */ + if (file_map_bit_test(map, filn)) + file_map_bit_reset(map, filn); +} + +int +UFSSwapDir::mapBitAllocate() +{ + int fn; + fn = file_map_allocate(map, suggest); + file_map_bit_set(map, fn); + suggest = fn + 1; + return fn; +} + +/* + * Initialise the asyncufs bitmap + * + * If there already is a bitmap, and the numobjects is larger than currently + * configured, we allocate a new bitmap and 'grow' the old one into it. + */ +void +UFSSwapDir::initBitmap() +{ + if (map == NULL) { + /* First time */ + map = file_map_create(); + } else if (map->max_n_files) { + /* it grew, need to expand */ + /* XXX We don't need it anymore .. */ + } + /* else it shrunk, and we leave the old one in place */ +} + +char * +UFSSwapDir::swapSubDir(int subdirn)const +{ + LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); + assert(0 <= subdirn && subdirn < l1); + snprintf(fullfilename, SQUID_MAXPATHLEN, "%s/%02X", path, subdirn); + return fullfilename; +} + +int +UFSSwapDir::createDirectory(const char *path, int should_exist) +{ + int created = 0; + struct stat st; + getCurrentTime(); + if (0 == stat(path, &st)) { + if (S_ISDIR(st.st_mode)) { + debug(47, should_exist ? 3 : 1) ("%s exists\n", path); + } else { + fatalf("Swap directory %s is not a directory.", path); + } +#ifdef _SQUID_MSWIN_ + } else if (0 == mkdir(path)) { +#else + } else if (0 == mkdir(path, 0755)) { +#endif + debug(47, should_exist ? 1 : 3) ("%s created\n", path); + created = 1; + } else { + fatalf("Failed to make swap directory %s: %s", + path, xstrerror()); + } + return created; +} + Index: squid3/src/fs/ufs/store_io_ufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/store_io_ufs.cc,v retrieving revision 1.3.10.47 retrieving revision 1.3.10.48 diff -u -r1.3.10.47 -r1.3.10.48 --- squid3/src/fs/ufs/store_io_ufs.cc 14 Dec 2002 09:40:24 -0000 1.3.10.47 +++ squid3/src/fs/ufs/store_io_ufs.cc 15 Dec 2002 12:19:50 -0000 1.3.10.48 @@ -1,6 +1,6 @@ /* - * $Id: store_io_ufs.cc,v 1.3.10.47 2002/12/14 09:40:24 rbcollins Exp $ + * $Id: store_io_ufs.cc,v 1.3.10.48 2002/12/15 12:19:50 rbcollins Exp $ * * DEBUG: section 79 Storage Manager UFS Interface * AUTHOR: Duane Wessels @@ -293,9 +293,9 @@ UfsSwapDir::unlink(StoreEntry & e) { debug(79, 3) ("storeUfsUnlink: fileno %08X\n", e.swap_filen); - commonUfsDirReplRemove(&e); + replacementRemove(&e); mapBitReset(e.swap_filen); - unlinkFile(e.swap_filen); + UFSSwapDir::unlinkFile(e.swap_filen); } /* === STATIC =========================================================== */ @@ -572,6 +572,6 @@ } /* now insert into the replacement policy */ - commonUfsDirReplAdd(SD, e); + ((UFSSwapDir *)SD)->replacementAdd(e); return sio; } Index: squid3/src/fs/ufs/store_ufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/Attic/store_ufs.h,v retrieving revision 1.1.20.31 retrieving revision 1.1.20.32 diff -u -r1.1.20.31 -r1.1.20.32 --- squid3/src/fs/ufs/store_ufs.h 15 Dec 2002 08:23:07 -0000 1.1.20.31 +++ squid3/src/fs/ufs/store_ufs.h 15 Dec 2002 12:19:50 -0000 1.1.20.32 @@ -63,6 +63,7 @@ virtual int canStore(StoreEntry const&)const; virtual void parse (int index, char *path); virtual void reconfigure (int, char *); + virtual void unlinkFile (char const *); }; #include "IOStrategy.h"