]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Started implementing diff cache dir sizes
authorwessels <>
Sat, 29 Mar 1997 11:45:13 +0000 (11:45 +0000)
committerwessels <>
Sat, 29 Mar 1997 11:45:13 +0000 (11:45 +0000)
12 files changed:
src/cache_cf.cc
src/client_side.cc
src/filemap.cc
src/ftp.cc
src/main.cc
src/neighbors.cc
src/peer_select.cc
src/squid.h
src/ssl.cc
src/stat.cc
src/store.cc
src/tunnel.cc

index 91154fdc03b7f2649279a10cfe9d7aafdd406777..7ac64ecc549dbde9366daa2d93d4eb4d7117337b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cache_cf.cc,v 1.176 1997/03/04 05:16:24 wessels Exp $
+ * $Id: cache_cf.cc,v 1.177 1997/03/29 04:45:13 wessels Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -199,8 +199,6 @@ struct SquidConfig Config;
 #define DefaultAvgObjectSize   20      /* 20k */
 #define DefaultObjectsPerBucket        50
 
-#define DefaultLevelOneDirs    16
-#define DefaultLevelTwoDirs    256
 #define DefaultOptionsLogUdp   1       /* on */
 #define DefaultOptionsEnablePurge 0    /* default off */
 
@@ -855,6 +853,31 @@ parseHttpAnonymizer(int *iptr)
        *iptr = ANONYMIZER_STANDARD;
 }
 
+static void
+parseCacheDir(void)
+{
+    char *token;
+    char *dir;
+    int i;
+    int size;
+    int l1;
+    int l2;
+    int readonly = 0;
+    if ((token = strtok(NULL, w_space)) == NULL)
+       self_destruct();
+    dir = token;
+    GetInteger(i);
+    size = i;
+    GetInteger(i);
+    l1 = i;
+    GetInteger(i);
+    l2 = i;
+    if ((token = strtok(NULL, w_space)))
+       if (!strcasecmp(token, "read-only"))
+           readonly = 1;
+    storeAddSwapDisk(dir, size, l1, l2, readonly);
+}
+
 int
 parseConfigFile(const char *file_name)
 {
@@ -913,7 +936,7 @@ parseConfigFile(const char *file_name)
            parseIntegerValue(&Config.neighborTimeout);
 
        else if (!strcmp(token, "cache_dir"))
-           parseWordlist(&Config.cache_dirs);
+           parseCacheDir();
 
        else if (!strcmp(token, "cache_log"))
            parsePathname(&Config.Log.log);
@@ -1182,11 +1205,6 @@ parseConfigFile(const char *file_name)
        else if (!strcmp(token, "viz_hack_addr"))
            parseVizHackLine();
 
-       else if (!strcmp(token, "swap_level1_dirs"))
-           parseIntegerValue(&Config.levelOneDirs);
-       else if (!strcmp(token, "swap_level2_dirs"))
-           parseIntegerValue(&Config.levelTwoDirs);
-
        else if (!strcmp(token, "netdb_high"))
            parseIntegerValue(&Config.Netdb.high);
        else if (!strcmp(token, "netdb_low"))
@@ -1288,7 +1306,6 @@ configFreeMemory(void)
     safe_free(Config.errHtmlText);
     peerDestroy(Config.sslProxy);
     peerDestroy(Config.passProxy);
-    wordlistDestroy(&Config.cache_dirs);
     wordlistDestroy(&Config.hierarchy_stoplist);
     wordlistDestroy(&Config.mcast_group_list);
     wordlistDestroy(&Config.dns_testname_list);
@@ -1392,8 +1409,6 @@ configSetFactoryDefaults(void)
     Config.Store.maxObjectSize = DefaultMaxObjectSize;
     Config.Store.avgObjectSize = DefaultAvgObjectSize;
     Config.Store.objectsPerBucket = DefaultObjectsPerBucket;
-    Config.levelOneDirs = DefaultLevelOneDirs;
-    Config.levelTwoDirs = DefaultLevelTwoDirs;
     Config.Options.log_udp = DefaultOptionsLogUdp;
     Config.Options.res_defnames = DefaultOptionsResDefnames;
     Config.Options.anonymizer = DefaultOptionsAnonymizer;
index 4d50f92794282bca53041c6317cf038264132723..2bdbb7296deef165a75720c0c1076655cd395668 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.94 1997/03/04 05:16:26 wessels Exp $
+ * $Id: client_side.cc,v 1.95 1997/03/29 04:45:14 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -117,11 +117,11 @@ clientAccessCheck(icpStateData * icpState, PF handler)
     }
 #endif /* USE_PROXY_AUTH */
     if (checkAccelOnly(icpState)) {
-        clientAccessCheckDone(0, icpState);
+       clientAccessCheckDone(0, icpState);
        return;
     }
     browser = mime_get_header(icpState->request_hdr, "User-Agent"),
-    aclNBCheck(Config.accessList.HTTP,
+       aclNBCheck(Config.accessList.HTTP,
        icpState->request,
        icpState->peer.sin_addr,
        browser,
@@ -133,7 +133,7 @@ clientAccessCheck(icpStateData * icpState, PF handler)
 void
 clientAccessCheckDone(int answer, void *data)
 {
-    icpStateData * icpState = data;
+    icpStateData *icpState = data;
     int fd = icpState->fd;
     char *buf = NULL;
     char *redirectUrl = NULL;
index 914d4094529c31a59c9c131bf0af039772db5f1f..575d207b77fad814d53b29a792e7a7962669df54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: filemap.cc,v 1.15 1996/11/06 23:14:32 wessels Exp $
+ * $Id: filemap.cc,v 1.16 1997/03/29 04:45:15 wessels Exp $
  *
  * DEBUG: section 8     Swap File Bitmap
  * AUTHOR: Harvest Derived
  */
 
 #include "squid.h"
+#include "filemap.h"
 
 /* Number of bits in a long */
 #if SIZEOF_LONG == 8
 #define ALL_ONES (unsigned long) 0xFFFFFFFF
 #endif
 
-extern int storeGetSwapSpace _PARAMS((int));
-extern void fatal_dump _PARAMS((const char *));
-
-static fileMap *fm = NULL;
-
 fileMap *
 file_map_create(int n)
 {
-    fm = xcalloc(1, sizeof(fileMap));
+    fileMap *fm = xcalloc(1, sizeof(fileMap));
     fm->max_n_files = n;
     fm->nwords = n >> LONG_BIT_SHIFT;
     debug(8, 1, "file_map_create: creating space for %d files\n", n);
@@ -139,22 +135,14 @@ file_map_create(int n)
        fm->nwords, sizeof(unsigned long));
     fm->file_map = xcalloc(fm->nwords, sizeof(unsigned long));
     meta_data.misc += fm->nwords * sizeof(unsigned long);
-    return (fm);
+    return fm;
 }
 
 int
-file_map_bit_set(int file_number)
+file_map_bit_set(fileMap * fm, int file_number)
 {
     unsigned long bitmask = (1L << (file_number & LONG_BIT_MASK));
-
-#ifdef XTRA_DEBUG
-    if (fm->file_map[file_number >> LONG_BIT_SHIFT] & bitmask)
-       debug(8, 0, "file_map_bit_set: WARNING: file number %d is already set!\n",
-           file_number);
-#endif
-
     fm->file_map[file_number >> LONG_BIT_SHIFT] |= bitmask;
-
     fm->n_files_in_map++;
     if (!fm->toggle && (fm->n_files_in_map > ((fm->max_n_files * 7) >> 3))) {
        fm->toggle++;
@@ -167,16 +155,15 @@ file_map_bit_set(int file_number)
 }
 
 void
-file_map_bit_reset(int file_number)
+file_map_bit_reset(fileMap * fm, int file_number)
 {
     unsigned long bitmask = (1L << (file_number & LONG_BIT_MASK));
-
     fm->file_map[file_number >> LONG_BIT_SHIFT] &= ~bitmask;
     fm->n_files_in_map--;
 }
 
 int
-file_map_bit_test(int file_number)
+file_map_bit_test(fileMap * fm, int file_number)
 {
     unsigned long bitmask = (1L << (file_number & LONG_BIT_MASK));
     /* be sure the return value is an int, not a u_long */
@@ -184,15 +171,14 @@ file_map_bit_test(int file_number)
 }
 
 int
-file_map_allocate(int suggestion)
+file_map_allocate(fileMap * fm, int suggestion)
 {
     int word;
     int bit;
     int count;
-
-    if (!file_map_bit_test(suggestion)) {
+    if (!file_map_bit_test(fm, suggestion)) {
        fm->last_file_number_allocated = suggestion;
-       return file_map_bit_set(suggestion);
+       return file_map_bit_set(fm, suggestion);
     }
     word = suggestion >> LONG_BIT_SHIFT;
     for (count = 0; count < fm->nwords; count++) {
@@ -200,23 +186,19 @@ file_map_allocate(int suggestion)
            break;
        word = (word + 1) % fm->nwords;
     }
-
     for (bit = 0; bit < BITS_IN_A_LONG; bit++) {
        suggestion = ((unsigned long) word << LONG_BIT_SHIFT) | bit;
-       if (!file_map_bit_test(suggestion)) {
+       if (!file_map_bit_test(fm, suggestion)) {
            fm->last_file_number_allocated = suggestion;
-           return file_map_bit_set(suggestion);
+           return file_map_bit_set(fm, suggestion);
        }
     }
-
-    debug(8, 0, "file_map_allocate: All %d files are in use!\n", fm->max_n_files);
-    debug(8, 0, "You need to recompile with a larger value for MAX_SWAP_FILE\n");
-    fatal_dump(NULL);
-    return (0);                        /* NOTREACHED */
+    fatal_dump("file_map_allocate: Exceeded filemap limit");
+    return 0;                  /* NOTREACHED */
 }
 
 void
-filemapFreeMemory(void)
+filemapFreeMemory(fileMap * fm)
 {
     safe_free(fm->file_map);
     safe_free(fm);
index ba5915a4c8b89a524228972b26ec772bb569352f..33f4eae47ca368cfb7dd5621adac5f9bd2e5f501 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ftp.cc,v 1.97 1997/03/04 05:16:28 wessels Exp $
+ * $Id: ftp.cc,v 1.98 1997/03/29 04:45:16 wessels Exp $
  *
  * DEBUG: section 9     File Transfer Protocol (FTP)
  * AUTHOR: Harvest Derived
@@ -567,7 +567,7 @@ ftpStartComplete(void *data, int status)
 {
     LOCAL_ARRAY(char, realm, 8192);
     ftp_ctrl_t *ctrlp = data;
-    request_t * request = ctrlp->request;
+    request_t *request = ctrlp->request;
     StoreEntry *entry = ctrlp->entry;
     char *url = entry->url;
     FtpStateData *ftpData = xcalloc(1, sizeof(FtpStateData));
index 837da78572f6bd138cf66e4eb53acbe68ea35443..3610eedec56f6818cffee3e890a3cbe85f1dca1e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.cc,v 1.138 1997/03/04 05:16:36 wessels Exp $
+ * $Id: main.cc,v 1.139 1997/03/29 04:45:17 wessels Exp $
  *
  * DEBUG: section 1     Startup and Main Loop
  * AUTHOR: Harvest Derived
@@ -111,7 +111,6 @@ int theInIcpConnection = -1;
 int theOutIcpConnection = -1;
 int vizSock = -1;
 int do_reuse = 1;
-int opt_unlink_on_reload = 0;
 int opt_reload_hit_only = 0;   /* only UDP_HIT during store relaod */
 int opt_catch_signals = 1;
 int opt_dns_tests = 1;
@@ -193,7 +192,7 @@ mainParseOptions(int argc, char *argv[])
     extern char *optarg;
     int c;
 
-    while ((c = getopt(argc, argv, "CDFRUVYXa:bf:hik:m:su:vz?")) != -1) {
+    while ((c = getopt(argc, argv, "CDFRVYXa:bf:hik:m:su:vz?")) != -1) {
        switch (c) {
        case 'C':
            opt_catch_signals = 0;
@@ -207,9 +206,6 @@ mainParseOptions(int argc, char *argv[])
        case 'R':
            do_reuse = 0;
            break;
-       case 'U':
-           opt_unlink_on_reload = 1;
-           break;
        case 'V':
            vhost_mode = 1;
            break;
@@ -578,8 +574,8 @@ mainInitialize(void)
        if (Config.effectiveUser) {
            /* we were probably started as root, so cd to a swap
             * directory in case we dump core */
-           if (chdir(swappath(0)) < 0) {
-               debug(50, 0, "%s: %s\n", swappath(0), xstrerror());
+           if (chdir(storeSwapDir(0)) < 0) {
+               debug(50, 0, "%s: %s\n", storeSwapDir(0), xstrerror());
                fatal_dump("Cannot cd to swap directory?");
            }
        }
index 8c0a466d0b6e5435303b456fdf39204db9631b0d..0810f24044d84ae77b7cc94ea37dd2c0fa654b93 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: neighbors.cc,v 1.129 1997/03/04 05:16:37 wessels Exp $
+ * $Id: neighbors.cc,v 1.130 1997/03/29 04:45:18 wessels Exp $
  *
  * DEBUG: section 15    Neighbor Routines
  * AUTHOR: Harvest Derived
@@ -188,9 +188,9 @@ whichPeer(const struct sockaddr_in *from)
 
 void
 hierarchyNote(request_t * request,
-       hier_code code,
-       icp_ping_data *icpdata,
-       const char *cache_host)
+    hier_code code,
+    icp_ping_data * icpdata,
+    const char *cache_host)
 {
     if (request) {
        request->hierarchy.code = code;
@@ -446,10 +446,10 @@ neighbors_open(int fd)
 
 int
 neighborsUdpPing(request_t * request,
-       StoreEntry * entry,
-       IRCB callback,
-       void *callback_data,
-       int *exprep)
+    StoreEntry * entry,
+    IRCB callback,
+    void *callback_data,
+    int *exprep)
 {
     char *host = request->host;
     char *url = entry->url;
index ad5b209fe015749e5cba19fbfd96181c38694db5..8fcdbc14e7a71d232130922bbad14272a1c417c1 100644 (file)
@@ -1,5 +1,6 @@
+
 /*
- * $Id: peer_select.cc,v 1.7 1997/03/02 05:35:08 wessels Exp $
+ * $Id: peer_select.cc,v 1.8 1997/03/29 04:45:19 wessels Exp $
  *
  * DEBUG: section 44    Peer Selection Algorithm
  * AUTHOR: Duane Wessels
index e418cc9db5d6ffb52630149ac439fc300b98a3b1..82673783488f4046c679578d1a4cd148d9ad30eb 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: squid.h,v 1.100 1997/03/04 05:16:42 wessels Exp $
+ * $Id: squid.h,v 1.101 1997/03/29 04:45:20 wessels Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -272,7 +272,6 @@ typedef int (*QS) (const void *, const void *);
 #include "debug.h"
 #include "disk.h"
 #include "fdstat.h"
-#include "filemap.h"
 #include "hash.h"
 #include "proto.h"             /* must go before neighbors.h */
 #include "peer_select.h"       /* must go before neighbors.h */
@@ -321,7 +320,6 @@ extern int theOutIcpConnection;     /* main.c */
 extern int vizSock;
 extern volatile int shutdown_pending;  /* main.c */
 extern volatile int reread_pending;    /* main.c */
-extern int opt_unlink_on_reload;       /* main.c */
 extern int opt_reload_hit_only;        /* main.c */
 extern int opt_dns_tests;      /* main.c */
 extern int opt_foreground_rebuild;     /* main.c */
index 60af0658bfa9560a3327fbf30752e2bb3d3385c6..8e10064078de64fc33895250053211a5dfcfcaf1 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: ssl.cc,v 1.42 1997/03/04 05:16:42 wessels Exp $
+ * $Id: ssl.cc,v 1.43 1997/03/29 04:45:20 wessels Exp $
  *
  * DEBUG: section 26    Secure Sockets Layer Proxy
  * AUTHOR: Duane Wessels
@@ -456,7 +456,7 @@ sslStart(int fd, const char *url, request_t * request, char *mime_hdr, int *size
        sslClientClosed,
        (void *) sslState);
     peerSelect(request,
-       NULL,   
+       NULL,
        sslPeerSelectComplete,
        sslPeerSelectFail,
        sslState);
@@ -484,7 +484,7 @@ sslProxyConnected(int fd, void *data)
 }
 
 static void
-sslPeerSelectComplete (peer * p, void *data)
+sslPeerSelectComplete(peer * p, void *data)
 {
     SslStateData *sslState = data;
     request_t *request = sslState->request;
@@ -507,7 +507,7 @@ sslPeerSelectComplete (peer * p, void *data)
 }
 
 static void
-sslPeerSelectFail (peer * p, void *data)
+sslPeerSelectFail(peer * p, void *data)
 {
     SslStateData *sslState = data;
     squid_error_request(sslState->url, ERR_CANNOT_FETCH, 400);
index 7d92709576d12dccf526f0cc3cc4ea4a45dd8701..93cbe2a6dcd8a27dcb12556406c06bb5a1009c51 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: stat.cc,v 1.129 1997/03/04 05:16:43 wessels Exp $
+ * $Id: stat.cc,v 1.130 1997/03/29 04:45:21 wessels Exp $
  *
  * DEBUG: section 18    Cache Manager Statistics
  * AUTHOR: Harvest Derived
@@ -1134,7 +1134,7 @@ log_append(const cacheinfo * obj,
            ident,
            hier_strings[hier_code],
            hier_host,
-           ns,ne,nr,tt,
+           ns, ne, nr, tt,
            content_type);
 #if LOG_FULL_HEADERS
     if (Config.logMimeHdrs) {
index 31569844fc31eb8cb0ab837416159fbd3b8ccbd4..c2182452a6b274008c9ca92880428b6c69014bfb 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.214 1997/03/04 05:16:44 wessels Exp $
+ * $Id: store.cc,v 1.215 1997/03/29 04:45:22 wessels Exp $
  *
  * DEBUG: section 20    Storeage Manager
  * AUTHOR: Harvest Derived
  */
 
 #include "squid.h"             /* goes first */
+#include "filemap.h"
+#include "store_dir.h"
 
 #define REBUILD_TIMESTAMP_DELTA_MAX 2
-#define MAX_SWAP_FILE          (1<<21)
 #define SWAP_BUF               DISK_PAGE_SIZE
 
 #define WITH_MEMOBJ    1
@@ -240,13 +241,11 @@ int store_rebuilding = STORE_REBUILDING_SLOW;
 
 /* Static Functions */
 static const char *storeDescribeStatus _PARAMS((const StoreEntry *));
-static char *storeSwapFullPath _PARAMS((int, char *));
 static HashID storeCreateHashTable _PARAMS((int (*)_PARAMS((const char *, const char *))));
 static int compareLastRef _PARAMS((StoreEntry **, StoreEntry **));
 static int compareSize _PARAMS((StoreEntry **, StoreEntry **));
 static int compareBucketOrder _PARAMS((struct _bucketOrder *,
        struct _bucketOrder *));
-static int storeAddSwapDisk _PARAMS((const char *));
 static int storeCheckExpired _PARAMS((const StoreEntry *));
 static int storeCheckPurgeMem _PARAMS((const StoreEntry *));
 static int storeClientListSearch _PARAMS((const MemObject *, int));
@@ -283,7 +282,6 @@ static void destroy_MemObjectData _PARAMS((MemObject *));
 static void destroy_StoreEntry _PARAMS((StoreEntry *));
 static void storeDeleteBehind _PARAMS((StoreEntry *));
 static void storePurgeMem _PARAMS((StoreEntry *));
-static void storeSanityCheck _PARAMS((void));
 static void storeSetMemStatus _PARAMS((StoreEntry *, mem_status_t));
 static void storeStartRebuildFromDisk _PARAMS((void));
 static void storeSwapLog _PARAMS((const StoreEntry *));
@@ -327,11 +325,6 @@ static char key_temp_buffer[MAX_URL + 100];
 static char swaplog_file[SQUID_MAXPATHLEN];
 static char tmp_filename[SQUID_MAXPATHLEN];
 
-/* patch cache_dir to accomodate multiple disk storage */
-static char **CacheDirs = NULL;
-static int CacheDirsAllocated = 0;
-int ncache_dirs = 0;
-
 /* expiration parameters and stats */
 static int store_buckets;
 static int store_maintain_rate;
@@ -901,7 +894,7 @@ storeAddDiskRestore(const char *url, int file_number, int size, time_t expires,
     storeSetMemStatus(e, NOT_IN_MEMORY);
     e->swap_status = SWAP_OK;
     e->swap_file_number = file_number;
-    file_map_bit_set(file_number);
+    storeDirMapBitSet(file_number);
     e->object_len = size;
     e->lock_count = 0;
     BIT_RESET(e->flag, CLIENT_ABORT_REQUEST);
@@ -1090,53 +1083,6 @@ storeAppendPrintf(va_alist)
     va_end(args);
 }
 
-/* add directory to swap disk */
-static int
-storeAddSwapDisk(const char *path)
-{
-    char **tmp = NULL;
-    int i;
-    if (strlen(path) > (SQUID_MAXPATHLEN - 32))
-       fatal_dump("cache_dir pathname is too long");
-    if (CacheDirs == NULL) {
-       CacheDirsAllocated = 4;
-       CacheDirs = xcalloc(CacheDirsAllocated, sizeof(char *));
-    }
-    if (CacheDirsAllocated == ncache_dirs) {
-       CacheDirsAllocated <<= 1;
-       tmp = xcalloc(CacheDirsAllocated, sizeof(char *));
-       for (i = 0; i < ncache_dirs; i++)
-           *(tmp + i) = *(CacheDirs + i);
-       xfree(CacheDirs);
-       CacheDirs = tmp;
-    }
-    *(CacheDirs + ncache_dirs) = xstrdup(path);
-    return ++ncache_dirs;
-}
-
-/* return the nth swap directory */
-const char *
-swappath(int n)
-{
-    return *(CacheDirs + (n % ncache_dirs));
-}
-
-/* return full name to swapfile */
-static char *
-storeSwapFullPath(int fn, char *fullpath)
-{
-    LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN);
-    if (!fullpath)
-       fullpath = fullfilename;
-    fullpath[0] = '\0';
-    sprintf(fullpath, "%s/%02X/%02X/%08X",
-       swappath(fn),
-       (fn / ncache_dirs) % Config.levelOneDirs,
-       (fn / ncache_dirs) / Config.levelOneDirs % Config.levelTwoDirs,
-       fn);
-    return fullpath;
-}
-
 /* swapping in handle */
 static int
 storeSwapInHandle(int fd_notused, const char *buf, int len, int flag, StoreEntry * e)
@@ -1322,7 +1268,7 @@ storeSwapOutHandle(int fd, int flag, StoreEntry * e)
        put_free_8k_page(mem->e_swap_buf);
        file_close(fd);
        if (e->swap_file_number != -1) {
-           file_map_bit_reset(e->swap_file_number);
+           storeDirMapBitReset(e->swap_file_number);
            safeunlink(storeSwapFullPath(e->swap_file_number, NULL), 0);
            e->swap_file_number = -1;
        }
@@ -1373,7 +1319,7 @@ storeSwapOutHandle(int fd, int flag, StoreEntry * e)
        put_free_8k_page(mem->e_swap_buf);
        file_close(fd);
        if (e->swap_file_number != -1) {
-           file_map_bit_reset(e->swap_file_number);
+           storeDirMapBitReset(e->swap_file_number);
            safeunlink(storeSwapFullPath(e->swap_file_number, NULL), 0);
            e->swap_file_number = -1;
        }
@@ -1395,10 +1341,7 @@ storeSwapOutStart(StoreEntry * e)
 {
     swapout_ctrl_t *ctrlp;
     LOCAL_ARRAY(char, swapfilename, SQUID_MAXPATHLEN);
-    /* Suggest a new swap file number */
-    swapfileno = (swapfileno + 1) % (MAX_SWAP_FILE);
-    /* Record the number returned */
-    swapfileno = file_map_allocate(swapfileno);
+    swapfileno = storeDirMapAllocate();
     storeSwapFullPath(swapfileno, swapfilename);
     ctrlp = xmalloc(sizeof(swapout_ctrl_t));
     ctrlp->swapfilename = xstrdup(swapfilename);
@@ -1416,22 +1359,18 @@ storeSwapOutStart(StoreEntry * e)
 static void
 storeSwapOutStartComplete(void *data, int fd)
 {
-    swapout_ctrl_t *ctrlp = (swapout_ctrl_t *) data;
+    swapout_ctrl_t *ctrlp = data;
+    int oldswapstatus = ctrlp->oldswapstatus;
+    char *swapfilename = ctrlp->swapfilename;
+    StoreEntry *e = ctrlp->e;
+    int swapno = ctrlp->swapfileno;
     int x;
-    int oldswapstatus;
     MemObject *mem;
-    char *swapfilename;
-    StoreEntry *e;
-    int swapno;
-    swapfilename = ctrlp->swapfilename;
-    e = ctrlp->e;
-    oldswapstatus = ctrlp->oldswapstatus;
-    swapno = ctrlp->swapfileno;
     xfree(ctrlp);
     if (fd < 0) {
        debug(20, 0, "storeSwapOutStart: Unable to open swapfile: %s\n",
            swapfilename);
-       file_map_bit_reset(swapno);
+       storeDirMapBitReset(swapno);
        e->swap_file_number = -1;
        if (e->swap_status == SWAPPING_OUT)
            e->swap_status = oldswapstatus;
@@ -1456,7 +1395,7 @@ storeSwapOutStartComplete(void *data, int fd)
        debug(20, 1, "storeCopy returned %d for '%s'\n", x, e->key);
        e->swap_file_number = -1;
        file_close(fd);
-       file_map_bit_reset(e->swap_file_number);
+       storeDirMapBitReset(e->swap_file_number);
        e->swap_file_number = -1;
        safeunlink(swapfilename, 1);
        if (e->swap_status == SWAPPING_OUT)
@@ -1529,9 +1468,9 @@ storeDoRebuildFromDisk(void *data)
            continue;
        if (sfileno < 0)
            continue;
-       storeSwapFullPath(sfileno, swapfile);
-       if (sfileno < 0 || sfileno >= MAX_SWAP_FILE)
+       if (sfileno >= MAX_FILES_PER_DIR)
            continue;
+       storeSwapFullPath(sfileno, swapfile);
        timestamp = (time_t) scan1;
        expires = (time_t) scan2;
        lastmod = (time_t) scan3;
@@ -1541,8 +1480,6 @@ storeDoRebuildFromDisk(void *data)
            if (e->timestamp > timestamp) {
                /* already have a newer object in memory, throw old one away */
                debug(20, 3, "storeRebuildFromDisk: Replaced: %s\n", url);
-               if (opt_unlink_on_reload)
-                   safeunlink(swapfile, 1);
                rebuildData->dupcount++;
                continue;
            }
@@ -1635,7 +1572,6 @@ storeCleanup(void *data)
     eventAdd("storeCleanup", storeCleanup, NULL, 0);
 }
 
-
 static void
 storeCleanupComplete(void *data, int status)
 {
@@ -1742,7 +1678,7 @@ storeStartRebuildFromDisk(void)
     data = xcalloc(1, sizeof(*data));
 
     for (i = 0; i < ncache_dirs; i++)
-       debug(20, 1, "Rebuilding storage from disk image in %s\n", swappath(i));
+       debug(20, 1, "Rebuilding storage from disk image in %s\n", storeSwapDir(i));
     data->start = getCurrentTime();
 
     /* Check if log is clean */
@@ -2300,7 +2236,7 @@ storeRelease(StoreEntry * e)
 
     if (e->swap_status == SWAP_OK && (e->swap_file_number > -1)) {
        (void) safeunlink(storeSwapFullPath(e->swap_file_number, NULL), 1);
-       file_map_bit_reset(e->swap_file_number);
+       storeDirMapBitReset(e->swap_file_number);
        e->swap_file_number = -1;
        store_swap_size -= (e->object_len + 1023) >> 10;
        HTTPCacheInfo->proto_purgeobject(HTTPCacheInfo,
@@ -2313,16 +2249,6 @@ storeRelease(StoreEntry * e)
     return 1;
 }
 
-
-/* return if the current key is the original one. */
-int
-storeOriginalKey(const StoreEntry * e)
-{
-    if (!e)
-       return 1;
-    return !(e->flag & KEY_CHANGE);
-}
-
 /* return 1 if a store entry is locked */
 static int
 storeEntryLocked(const StoreEntry * e)
@@ -2517,82 +2443,6 @@ storeEntryValidLength(const StoreEntry * e)
     return 1;
 }
 
-static int
-storeVerifySwapDirs(int clean)
-{
-    int inx;
-    const char *path = NULL;
-    struct stat sb;
-    int directory_created = 0;
-    char *cmdbuf = NULL;
-
-    for (inx = 0; inx < ncache_dirs; inx++) {
-       path = swappath(inx);
-       debug(20, 9, "storeVerifySwapDirs: Creating swap space in %s\n", path);
-       if (stat(path, &sb) < 0) {
-           /* we need to create a directory for swap file here. */
-           if (mkdir(path, 0777) < 0) {
-               if (errno != EEXIST) {
-                   sprintf(tmp_error_buf, "Failed to create swap directory %s: %s",
-                       path,
-                       xstrerror());
-                   fatal(tmp_error_buf);
-               }
-           }
-           if (stat(path, &sb) < 0) {
-               sprintf(tmp_error_buf,
-                   "Failed to verify swap directory %s: %s",
-                   path, xstrerror());
-               fatal(tmp_error_buf);
-           }
-           debug(20, 1, "storeVerifySwapDirs: Created swap directory %s\n", path);
-           directory_created = 1;
-       }
-       if (clean && opt_unlink_on_reload) {
-           debug(20, 1, "storeVerifySwapDirs: Zapping all objects on disk storage.\n");
-           cmdbuf = xcalloc(1, BUFSIZ);
-           sprintf(cmdbuf, "cd %s; /bin/rm -rf %s [0-9A-F][0-9A-F]",
-               path, swaplog_file);
-           debug(20, 1, "storeVerifySwapDirs: Running '%s'\n", cmdbuf);
-           system(cmdbuf);     /* XXX should avoid system(3) */
-           xfree(cmdbuf);
-       }
-    }
-    return directory_created;
-}
-
-static void
-storeCreateSwapSubDirs(void)
-{
-    int i, j, k;
-    LOCAL_ARRAY(char, name, MAXPATHLEN);
-    for (j = 0; j < ncache_dirs; j++) {
-       for (i = 0; i < Config.levelOneDirs; i++) {
-           sprintf(name, "%s/%02X", swappath(j), i);
-           debug(20, 1, "Making directories in %s\n", name);
-           if (mkdir(name, 0755) < 0) {
-               if (errno != EEXIST) {
-                   sprintf(tmp_error_buf,
-                       "Failed to make swap directory %s: %s",
-                       name, xstrerror());
-                   fatal(tmp_error_buf);
-               }
-           }
-           for (k = 0; k < Config.levelTwoDirs; k++) {
-               sprintf(name, "%s/%02X/%02X", swappath(j), i, k);
-               if (mkdir(name, 0755) < 0) {
-                   if (errno != EEXIST) {
-                       sprintf(tmp_error_buf,
-                           "Failed to make swap directory %s: %s",
-                           name, xstrerror());
-                       fatal(tmp_error_buf);
-                   }
-               }
-           }
-       }
-    }
-}
-
 #if HAVE_RANDOM
 #define squid_random random
 #elif HAVE_LRAND48
@@ -2657,7 +2507,6 @@ storeInit(void)
     int dir_created = 0;
     wordlist *w = NULL;
     char *fname = NULL;
-    file_map_create(MAX_SWAP_FILE);
     storeInitHashValues();
     storeCreateHashTable(urlcmp);
     if (strcmp((fname = Config.Log.store), "none") == 0)
@@ -2666,14 +2515,13 @@ storeInit(void)
        storelog_fd = file_open(fname, NULL, O_WRONLY | O_CREAT, NULL, NULL);
     if (storelog_fd < 0)
        debug(20, 1, "Store logging disabled\n");
-    for (w = Config.cache_dirs; w; w = w->next)
-       storeAddSwapDisk(w->key);
-    storeSanityCheck();
-    dir_created = storeVerifySwapDirs(opt_zap_disk_store);
+    if (ncache_dirs < 1)
+       fatal("No cache_dir's specified in config file");
+    dir_created = storeVerifySwapDirs();
     if (Config.Log.swap)
        xstrncpy(swaplog_file, Config.Log.swap, SQUID_MAXPATHLEN);
     else
-       sprintf(swaplog_file, "%s/log", swappath(0));
+       sprintf(swaplog_file, "%s/log", storeSwapDir(0));
     swaplog_fd = file_open(swaplog_file, NULL, O_WRONLY | O_CREAT, NULL, NULL);
     debug(20, 3, "swaplog_fd %d is now '%s'\n", swaplog_fd, swaplog_file);
     if (swaplog_fd < 0) {
@@ -2684,8 +2532,6 @@ storeInit(void)
        storeStartRebuildFromDisk();
     else
        store_rebuilding = STORE_NOT_REBUILDING;
-    if (dir_created || opt_zap_disk_store)
-       storeCreateSwapSubDirs();
 }
 
 void
@@ -2708,39 +2554,6 @@ storeConfigure(void)
     store_pages_low = store_mem_low / SM_PAGE_SIZE;
 }
 
-/* 
- *  storeSanityCheck - verify that all swap storage areas exist, and
- *  are writable; otherwise, force -z.
- */
-static void
-storeSanityCheck(void)
-{
-    LOCAL_ARRAY(char, name, 4096);
-    int i;
-
-    if (ncache_dirs < 1)
-       storeAddSwapDisk(DefaultSwapDir);
-
-    for (i = 0; i < Config.levelOneDirs; i++) {
-       sprintf(name, "%s/%02X", swappath(i), i);
-       errno = 0;
-       if (access(name, W_OK)) {
-           /* A very annoying problem occurs when access() fails because
-            * the system file table is full.  To prevent squid from
-            * deleting your entire disk cache on a whim, insist that the
-            * errno indicates that the directory doesn't exist */
-           if (errno != ENOENT)
-               continue;
-           debug(20, 0, "WARNING: Cannot write to swap directory '%s'\n",
-               name);
-           debug(20, 0, "Forcing a *full restart* (e.g., %s -z)...\n",
-               appname);
-           opt_zap_disk_store = 1;
-           return;
-       }
-    }
-}
-
 int
 urlcmp(const char *url1, const char *url2)
 {
index 2329a684283e6fe24f1067149aa0a8a3a664a9a8..ed22eedadc8405147439de13654acd7e4669f4f7 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: tunnel.cc,v 1.42 1997/03/04 05:16:42 wessels Exp $
+ * $Id: tunnel.cc,v 1.43 1997/03/29 04:45:20 wessels Exp $
  *
  * DEBUG: section 26    Secure Sockets Layer Proxy
  * AUTHOR: Duane Wessels
@@ -456,7 +456,7 @@ sslStart(int fd, const char *url, request_t * request, char *mime_hdr, int *size
        sslClientClosed,
        (void *) sslState);
     peerSelect(request,
-       NULL,   
+       NULL,
        sslPeerSelectComplete,
        sslPeerSelectFail,
        sslState);
@@ -484,7 +484,7 @@ sslProxyConnected(int fd, void *data)
 }
 
 static void
-sslPeerSelectComplete (peer * p, void *data)
+sslPeerSelectComplete(peer * p, void *data)
 {
     SslStateData *sslState = data;
     request_t *request = sslState->request;
@@ -507,7 +507,7 @@ sslPeerSelectComplete (peer * p, void *data)
 }
 
 static void
-sslPeerSelectFail (peer * p, void *data)
+sslPeerSelectFail(peer * p, void *data)
 {
     SslStateData *sslState = data;
     squid_error_request(sslState->url, ERR_CANNOT_FETCH, 400);