From: wessels <> Date: Wed, 2 Apr 1997 11:39:55 +0000 (+0000) Subject: it compiles, but need to fix swaplogs X-Git-Tag: SQUID_3_0_PRE1~5058 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0c04c38986533caca99c4b7a7893b0d1a240a1b4;p=thirdparty%2Fsquid.git it compiles, but need to fix swaplogs --- diff --git a/src/Makefile.in b/src/Makefile.in index 2bbdbb6b5d..da4b07c37d 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.66 1997/02/25 19:18:19 wessels Exp $ +# $Id: Makefile.in,v 1.67 1997/04/02 04:39:55 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -112,6 +112,7 @@ OBJS = \ stmem.o \ store.o \ store_clean.o \ + store_dir.o \ storetoString.o \ tools.o \ url.o \ diff --git a/src/squid.h b/src/squid.h index 8267378348..795d3eab3c 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.101 1997/03/29 04:45:20 wessels Exp $ + * $Id: squid.h,v 1.102 1997/04/02 04:39:58 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -233,6 +233,7 @@ typedef struct _aclCheck_t aclCheck_t; typedef struct _request request_t; typedef struct _MemObject MemObject; typedef struct _cachemgr_passwd cachemgr_passwd; +typedef struct _filemap fileMap; /* 32 bit integer compatability hack */ #if SIZEOF_INT == 4 @@ -287,6 +288,7 @@ typedef int (*QS) (const void *, const void *); #include "stat.h" #include "stmem.h" #include "store.h" +#include "store_dir.h" #include "tools.h" #include "http.h" #include "ftp.h" diff --git a/src/store.cc b/src/store.cc index c2182452a6..8b34f77342 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.215 1997/03/29 04:45:22 wessels Exp $ + * $Id: store.cc,v 1.216 1997/04/02 04:39:59 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -237,7 +237,7 @@ typedef struct swapout_ctrl_t { } swapout_ctrl_t; /* initializtion flag */ -int store_rebuilding = STORE_REBUILDING_SLOW; +int store_rebuilding = STORE_REBUILDING_DIRTY; /* Static Functions */ static const char *storeDescribeStatus _PARAMS((const StoreEntry *)); @@ -332,7 +332,7 @@ static int store_maintain_buckets; static int scan_revolutions; static struct _bucketOrder *MaintBucketsOrder = NULL; -/* Slow/Fast rebuild status parameter */ +/* Dirty/Clean rebuild status parameter */ static int store_validating = 1; static MemObject * @@ -904,7 +904,10 @@ storeAddDiskRestore(const char *url, int file_number, int size, time_t expires, e->expires = expires; e->lastmod = lastmod; e->ping_status = PING_NONE; - BIT_RESET(e->flag, ENTRY_VALIDATED); + if (store_rebuilding == STORE_REBUILDING_CLEAN) + BIT_SET(e->flag, ENTRY_VALIDATED); + else + BIT_RESET(e->flag, ENTRY_VALIDATED); return e; } @@ -1489,7 +1492,7 @@ storeDoRebuildFromDisk(void *data) rebuildData->dupcount++; } /* Is the swap file number already taken? */ - if (file_map_bit_test(sfileno)) { + if (storeDirMapBitTest(sfileno)) { /* Yes it is, we can't use this swapfile */ debug(20, 2, "storeRebuildFromDisk: Line %d Active clash: file #%d\n", rebuildData->linecount, @@ -1560,13 +1563,8 @@ storeCleanup(void *data) validnum++; if ((validnum % 4096) == 0) debug(20, 1, " %7d Entries Validated so far.\n", validnum); - if (BIT_TEST(e->flag, ENTRY_VALIDATED)) { - xfree(curr->key); - xfree(curr); - eventAdd("storeCleanup", storeCleanup, NULL, 0); - return; - } - storeValidate(e, storeCleanupComplete, e); + if (!BIT_TEST(e->flag, ENTRY_VALIDATED)) + storeValidate(e, storeCleanupComplete, e); xfree(curr->key); xfree(curr); eventAdd("storeCleanup", storeCleanup, NULL, 0); @@ -1669,25 +1667,22 @@ storeStartRebuildFromDisk(void) int i; struct storeRebuild_data *data; time_t last_clean; - if (stat(swaplog_file, &sb) < 0) { debug(20, 1, "storeRebuildFromDisk: No log file\n"); store_rebuilding = STORE_NOT_REBUILDING; return; } data = xcalloc(1, sizeof(*data)); - for (i = 0; i < ncache_dirs; i++) debug(20, 1, "Rebuilding storage from disk image in %s\n", storeSwapDir(i)); data->start = getCurrentTime(); - /* Check if log is clean */ sprintf(tmp_filename, "%s-last-clean", swaplog_file); if (stat(tmp_filename, &sb) >= 0) { last_clean = sb.st_mtime; if (stat(swaplog_file, &sb) >= 0) store_rebuilding = (sb.st_mtime <= last_clean) ? - STORE_REBUILDING_FAST : STORE_REBUILDING_SLOW; + STORE_REBUILDING_CLEAN : STORE_REBUILDING_DIRTY; } /* Remove timestamp in case we crash during rebuild */ safeunlink(tmp_filename, 1); @@ -1710,14 +1705,11 @@ storeStartRebuildFromDisk(void) fatal(tmp_error_buf); } debug(20, 3, "data->log %d is now '%s'\n", fileno(data->log), swaplog_file); - if (store_rebuilding == STORE_REBUILDING_FAST) { - store_validating = 0; - debug(20, 1, "Rebuilding in FAST MODE.\n"); - } + debug(20, 1, "Rebuilding in %s log.\n", + store_rebuilding == STORE_REBUILDING_CLEAN ? "CLEAN" : "DIRTY"); + store_validating = store_rebuilding == STORE_REBUILDING_CLEAN ? 0 : 1; memset(data->line_in, '\0', 4096); - /* data->speed = store_rebuilding == STORE_REBUILDING_FAST ? 50 : 5; */ data->speed = 50; - /* Start reading the log file */ if (opt_foreground_rebuild) { data->speed = 1 << 30; @@ -1927,7 +1919,7 @@ storeGetMemSpace(int size) pages_needed = (size / SM_PAGE_SIZE) + 1; if (sm_stats.n_pages_in_use + pages_needed < store_pages_high) return; - if (store_rebuilding == STORE_REBUILDING_FAST) + if (store_rebuilding == STORE_REBUILDING_CLEAN) return; debug(20, 2, "storeGetMemSpace: Starting, need %d pages\n", pages_needed); @@ -2222,7 +2214,7 @@ storeRelease(StoreEntry * e) if ((hentry = (StoreEntry *) hash_lookup(store_table, hkey))) storeExpireNow(hentry); } - if (store_rebuilding == STORE_REBUILDING_FAST) { + if (store_rebuilding == STORE_REBUILDING_CLEAN) { debug(20, 2, "storeRelease: Delaying release until store is rebuilt: '%s'\n", e->key ? e->key : e->url ? e->url : "NO URL"); storeExpireNow(e); @@ -2505,7 +2497,6 @@ void storeInit(void) { int dir_created = 0; - wordlist *w = NULL; char *fname = NULL; storeInitHashValues(); storeCreateHashTable(urlcmp); @@ -2583,7 +2574,7 @@ storeMaintainSwapSpace(void *unused) eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1); /* We can't delete objects while rebuilding swap */ - if (store_rebuilding == STORE_REBUILDING_FAST) + if (store_rebuilding == STORE_REBUILDING_CLEAN) return; /* Purges expired objects, check one bucket on each calling */ diff --git a/src/store_dir.cc b/src/store_dir.cc index 0a69aff9ad..280cb746d6 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -7,9 +7,11 @@ #define DefaultLevelOneDirs 16 #define DefaultLevelTwoDirs 256 +/* GLOBALS */ +int ncache_dirs = 0; +/* LOCALS */ static int SwapDirsAllocated = 0; -static int ncache_dirs; /* return full name to swapfile */ char * @@ -29,6 +31,23 @@ storeSwapFullPath(int fn, char *fullpath) return fullpath; } +/* return full name to swapfile */ +char * +storeSwapSubSubDir(int fn, char *fullpath) +{ + LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); + int dirn = (fn >> SWAP_DIR_SHIFT) % ncache_dirs; + int filn = fn & SWAP_FILE_MASK; + if (!fullpath) + fullpath = fullfilename; + fullpath[0] = '\0'; + sprintf(fullpath, "%s/%02X/%02X", + SwapDirs[dirn].path, + filn % SwapDirs[dirn].l1, + filn / SwapDirs[dirn].l1 % SwapDirs[dirn].l2); + return fullpath; +} + /* add directory to swap disk */ int storeAddSwapDisk(const char *path, int size, int l1, int l2, int read_only) @@ -74,12 +93,12 @@ storeVerifyOrCreateDir(const char *path) } } debug(20, 1, "Created directory %s\n", path); - if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode) == 0) - return 1; - sprintf(tmp_error_buf, - "Failed to create directory %s: %s", path, xstrerror()); - fatal(tmp_error_buf); - /* NOTREACHED */ + if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode) != 0) { + sprintf(tmp_error_buf, + "Failed to create directory %s: %s", path, xstrerror()); + fatal(tmp_error_buf); + } + return 1; } int @@ -133,13 +152,21 @@ storeMostFreeSwapDir(void) return dirn; } +int +storeDirMapBitTest(int fn) +{ + int dirn = fn >> SWAP_DIR_SHIFT; + int filn = fn & SWAP_FILE_MASK; + return file_map_bit_test(SwapDirs[dirn].map, filn); +} + void storeDirMapBitSet(int fn) { int dirn = fn >> SWAP_DIR_SHIFT; int filn = fn & SWAP_FILE_MASK; - file_map_bit_set(SwapDir[dirn].map, filn); - SwapDir[dirn].suggest++; + file_map_bit_set(SwapDirs[dirn].map, filn); + SwapDirs[dirn].suggest++; } void @@ -147,9 +174,9 @@ storeDirMapBitReset(int fn) { int dirn = fn >> SWAP_DIR_SHIFT; int filn = fn & SWAP_FILE_MASK; - file_map_bit_reset(SwapDir[dirn].map, filn); - if (fn < SwapDir[dirn].suggest) - SwapDir[dirn].suggest = fn; + file_map_bit_reset(SwapDirs[dirn].map, filn); + if (fn < SwapDirs[dirn].suggest) + SwapDirs[dirn].suggest = fn; } int @@ -166,5 +193,5 @@ storeSwapDir(int dirn) { if (dirn < 0 || dirn >= ncache_dirs) fatal_dump("storeSwapDir: bad index"); - return SwapDir[dirn].path; + return SwapDirs[dirn].path; }