]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
The "maxobjsize" parameter moved to an optional cache_dir option.
authorhno <>
Sat, 10 Feb 2001 23:40:40 +0000 (23:40 +0000)
committerhno <>
Sat, 10 Feb 2001 23:40:40 +0000 (23:40 +0000)
This was done by implementing a generic option parser for cache_dir
where each FS-type can include their own options if needed.

squid.conf syntax changes:

maxobjsize argument now an option
the Q1 and Q2 arguments to diskd now options

Generic cache_dir syntax

  cache_dir type path [fs-parameters] [optins]

Common options available to all stores

   max-size=n (the former maxobjsize argument)
   read-only

diskd options
   Q1=n, Q2=n (the former Q1 and Q2 arguments)

Implementation details:

Each option is defined by a struct cache_dir_option with the members
  name   option name
  parse  function that parses the option argument

The parse functions are called with the arguments
  parse_function(SwapDir *sd, const char *optionname,
  const char *optionvalue, int reconfiguring)

The FS cache_dir parser (both initial and reconfigure) must call
parse_cachedir_options after parsing all it's FS-specific arguments.

  parse_cachedir_options(SwapDir *sd, struct cache_dir_option *options,
  int reconfiguring)

options is an array of FS-specific options, terminated with a entry where
name is NULL.

The list of common options shared by all stores is defined in cache_cf.c

src/cache_cf.cc
src/cf.data.pre
src/fs/aufs/store_dir_aufs.cc
src/fs/coss/store_dir_coss.cc
src/fs/diskd/store_dir_diskd.cc
src/fs/null/store_null.cc
src/fs/ufs/store_dir_ufs.cc
src/protos.h
src/store_dir.cc
src/structs.h

index 6c00e90f3ecd3754346453c883f126d1ce13a97e..0231ecc12fbac3dfd567af026d55daf618acc978 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cache_cf.cc,v 1.374 2001/02/07 18:56:51 hno Exp $
+ * $Id: cache_cf.cc,v 1.375 2001/02/10 16:40:40 hno Exp $
  *
  * DEBUG: section 3     Configuration File Parsing
  * AUTHOR: Harvest Derived
@@ -1033,13 +1033,10 @@ parse_cachedir(cacheSwap * swap)
     SwapDir *sd;
     int i;
     int fs;
-    ssize_t maxobjsize;
 
     if ((type_str = strtok(NULL, w_space)) == NULL)
        self_destruct();
 
-    maxobjsize = (ssize_t) GetInteger();
-
     if ((path_str = strtok(NULL, w_space)) == NULL)
        self_destruct();
 
@@ -1070,7 +1067,6 @@ parse_cachedir(cacheSwap * swap)
            }
            sd = swap->swapDirs + i;
            storefs_list[fs].reconfigurefunc(sd, i, path_str);
-           sd->max_objsize = maxobjsize;
            update_maxobjsize();
            return;
        }
@@ -1085,17 +1081,94 @@ parse_cachedir(cacheSwap * swap)
     }
     allocate_new_swapdir(swap);
     sd = swap->swapDirs + swap->n_configured;
-    storefs_list[fs].parsefunc(sd, swap->n_configured, path_str);
-    /* XXX should we dupe the string here, in case it gets trodden on? */
     sd->type = storefs_list[fs].typestr;
-    sd->max_objsize = maxobjsize;
     /* defaults in case fs implementation fails to set these */
+    sd->max_objsize = -1;
     sd->fs.blksize = 1024;
+    /* parse the FS parameters and options */
+    storefs_list[fs].parsefunc(sd, swap->n_configured, path_str);
     swap->n_configured++;
     /* Update the max object size */
     update_maxobjsize();
 }
 
+static void
+parse_cachedir_option_readonly(SwapDir * sd, const char *option, const char *value, int reconfiguring)
+{
+    int read_only = 0;
+    if (value)
+       read_only = atoi(value);
+    else
+       read_only = 1;
+    sd->flags.read_only = read_only;
+}
+
+static void
+parse_cachedir_option_maxsize(SwapDir * sd, const char *option, const char *value, int reconfiguring)
+{
+    ssize_t size;
+
+    if (!value)
+       self_destruct();
+
+    size = atoi(value);
+
+    if (reconfiguring && sd->max_objsize != size)
+       debug(3, 1) ("Cache dir '%s' max object size now %d\n", size);
+
+    sd->max_objsize = size;
+}
+
+static struct cache_dir_option common_cachedir_options[] =
+{
+    {"read-only", parse_cachedir_option_readonly},
+    {"max-size", parse_cachedir_option_maxsize},
+    {NULL, NULL}
+};
+
+void
+parse_cachedir_options(SwapDir * sd, struct cache_dir_option *options, int reconfiguring)
+{
+    int old_read_only = sd->flags.read_only;
+    char *name, *value;
+    struct cache_dir_option *option, *op;
+
+    while ((name = strtok(NULL, w_space)) != NULL) {
+       value = strchr(name, '=');
+       if (value)
+           *value++ = '\0';    /* cut on = */
+       option = NULL;
+       if (options) {
+           for (op = options; !option && op->name; op++) {
+               if (strcmp(op->name, name) == 0) {
+                   option = op;
+                   break;
+               }
+           }
+       }
+       for (op = common_cachedir_options; !option && op->name; op++) {
+           if (strcmp(op->name, name) == 0) {
+               option = op;
+               break;
+           }
+       }
+       if (!option || !option->parse)
+           self_destruct();
+       option->parse(sd, name, value, reconfiguring);
+    }
+    /*
+     * Handle notifications about reconfigured single-options with no value
+     * where the removal of the option cannot be easily detected in the
+     * parsing...
+     */
+    if (reconfiguring) {
+       if (old_read_only != sd->flags.read_only) {
+           debug(3, 1) ("Cache dir '%s' now %s\n",
+               sd->path, sd->flags.read_only ? "Read-Only" : "Read-Write");
+       }
+    }
+}
+
 static void
 free_cachedir(cacheSwap * swap)
 {
index 5c562f51104e0bbb6f233db7fb3692f8ada757fc..580f94c7fb2e17681797ba58318b48faec3d7e93 100644 (file)
@@ -1,6 +1,6 @@
 
 #
-# $Id: cf.data.pre,v 1.213 2001/02/09 19:35:10 hno Exp $
+# $Id: cf.data.pre,v 1.214 2001/02/10 16:40:40 hno Exp $
 #
 #
 # SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -678,16 +678,12 @@ COMMENT_END
 NAME: cache_dir
 TYPE: cachedir
 DEFAULT: none
-DEFAULT_IF_NONE: ufs -1 @DEFAULT_SWAP_DIR@ 100 16 256
+DEFAULT_IF_NONE: ufs @DEFAULT_SWAP_DIR@ 100 16 256
 LOC: Config.cacheSwap
 DOC_START
        Usage:
        
-       cache_dir Type Maxobjsize Directory-Name Mbytes Level-1 Level2 [...]
-
-       DISKD Usage:
-
-       cache_dir diskd Maxobjsize Directory-Name MB L1 L2 Q1 Q2
+       cache_dir Type Directory-Name Fs-specific-data [options]
 
        You can specify multiple cache_dir lines to spread the
        cache among different disk partitions.
@@ -698,18 +694,18 @@ DOC_START
        want to try "aufs" as the type.  Async IO support may be
        buggy, however, so beware.
 
-       Maxobjsize refers to the max object size this storedir supports.
-       It is used to initially choose the storedir to dump the object.
-       -1 means 'any size'.
-
        'Directory' is a top-level directory where cache swap
        files will be stored.  If you want to use an entire disk
        for caching, then this can be the mount-point directory.
        The directory must exist and be writable by the Squid
        process.  Squid will NOT create this directory for you.
 
-       If no 'cache_dir' lines are specified, the following
-       default will be used: @DEFAULT_SWAP_DIR@.
+       The ufs store type:
+
+       "ufs" is the old well-known Squid storage format that has always
+       been there.
+
+       cache_dir ufs Directory-Name Mbytes L1 L2 [options]
 
        'Mbytes' is the amount of disk space (MB) to use under this
        directory.  The default is 100 MB.  Change this to suit your
@@ -722,12 +718,43 @@ DOC_START
        will be created under each first-level directory.  The default
        is 256.
 
-       For the diskd type, Q1 specifies the number of unacknowledged
-       I/O requests when Squid stops opening new files.  If this
-       many messages are in the queues, Squid won't open new files.
+       The aufs store type:
+
+       "aufs" uses the same storage format as "ufs", utilizing
+       POSIX-threads to avoid blocking the main Squid process on
+       disk-I/O. This was formerly known in Squid as async-io.
+
+       cache_dir aufs Directory-Name Mbytes L1 L2 [options]
+
+       see argument descriptions under ufs above
+
+       The diskd store type:
+
+       "diskd" uses the same storage format as "ufs", utilizing a
+       separate process to avoid blocking the main Squid process on
+       disk-I/O.
+
+       cache_dir diskd Directory-Name Mbytes L1 L2 [options] [Q1=n] [Q2=n]
+
+       see argument descriptions under ufs above
+
+       Q1 specifies the number of unacknowledged I/O requests when Squid
+       stops opening new files. If this many messages are in the queues,
+       Squid won't open new files. Default is 64
+
        Q2 specifies the number of unacknowledged messages when Squid
        starts blocking.  If this many messages are in the queues,
-       Squid blocks until it recevies some replies.
+       Squid blocks until it recevies some replies. Default is 72
+
+       Common options:
+
+       read-only, this cache_dir is read only.
+
+       max-size=n, refers to the max object size this storedir supports.
+       It is used to initially choose the storedir to dump the object.
+       Note: To make optimal use of the max-size limits you should order
+       the cache_dir lines with the smallest max-size value first and the
+       ones with no max-size specification last.
 DOC_END
 
 
index f78edf9d50c7d094c53516a355e29e397f522fb1..92f7933504098d66975d5e78373285081de731a2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_aufs.cc,v 1.29 2001/02/07 18:56:53 hno Exp $
+ * $Id: store_dir_aufs.cc,v 1.30 2001/02/10 16:40:41 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -120,7 +120,7 @@ static int storeAufsDirValidFileno(SwapDir *, sfileno, int);
 
 /* The MAIN externally visible function */
 STSETUP storeFsSetup_aufs;
+
 /*
  * These functions were ripped straight out of the heart of store_dir.c.
  * They assume that the given filenum is on a asyncufs partiton, which may or
@@ -1491,6 +1491,15 @@ storeAufsDirStats(SwapDir * SD, StoreEntry * sentry)
 #endif /* OLD_UNUSED_CODE */
 }
 
+static struct cache_dir_option options[] =
+{
+#if NOT_YET_DONE
+    {"L1", storeAufsDirParseL1},
+    {"L2", storeAufsDirParseL2},
+#endif
+    {NULL, NULL}
+};
+
 /*
  * storeAufsDirReconfigure
  *
@@ -1499,12 +1508,10 @@ storeAufsDirStats(SwapDir * SD, StoreEntry * sentry)
 static void
 storeAufsDirReconfigure(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
-    unsigned int read_only = 0;
 
     i = GetInteger();
     size = i << 10;            /* Mbytes to kbytes */
@@ -1518,9 +1525,6 @@ storeAufsDirReconfigure(SwapDir * sd, int index, char *path)
     l2 = i;
     if (l2 <= 0)
        fatal("storeAufsDirReconfigure: invalid level 2 directories value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     /* just reconfigure it */
     if (size == sd->max_size)
@@ -1530,10 +1534,9 @@ storeAufsDirReconfigure(SwapDir * sd, int index, char *path)
        debug(3, 1) ("Cache dir '%s' size changed to %d KB\n",
            path, size);
     sd->max_size = size;
-    if (sd->flags.read_only != read_only)
-       debug(3, 1) ("Cache dir '%s' now %s\n",
-           path, read_only ? "Read-Only" : "Read-Write");
-    sd->flags.read_only = read_only;
+
+    parse_cachedir_options(sd, options, 0);
+
     return;
 }
 
@@ -1621,12 +1624,10 @@ storeAufsCleanupDoubleCheck(SwapDir * sd, StoreEntry * e)
 static void
 storeAufsDirParse(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
-    unsigned int read_only = 0;
     aioinfo_t *aioinfo;
 
     i = GetInteger();
@@ -1641,9 +1642,6 @@ storeAufsDirParse(SwapDir * sd, int index, char *path)
     l2 = i;
     if (l2 <= 0)
        fatal("storeAufsDirParse: invalid level 2 directories value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     aioinfo = xmalloc(sizeof(aioinfo_t));
     if (aioinfo == NULL)
@@ -1658,7 +1656,6 @@ storeAufsDirParse(SwapDir * sd, int index, char *path)
     aioinfo->swaplog_fd = -1;
     aioinfo->map = NULL;       /* Debugging purposes */
     aioinfo->suggest = 0;
-    sd->flags.read_only = read_only;
     sd->init = storeAufsDirInit;
     sd->newfs = storeAufsDirNewfs;
     sd->dump = storeAufsDirDump;
@@ -1684,6 +1681,8 @@ storeAufsDirParse(SwapDir * sd, int index, char *path)
     sd->log.clean.nextentry = storeAufsDirCleanLogNextEntry;
     sd->log.clean.done = storeAufsDirWriteCleanDone;
 
+    parse_cachedir_options(sd, options, 0);
+
     /* Initialise replacement policy stuff */
     sd->repl = createRemovalPolicy(Config.replPolicy);
 }
index 9306de2e250a617c6be72309147d6379c34659da..606d1382d1f4685fbbfb6d1e5090c061b9dc0a58 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_coss.cc,v 1.18 2001/02/07 18:56:54 hno Exp $
+ * $Id: store_dir_coss.cc,v 1.19 2001/02/10 16:40:41 hno Exp $
  *
  * DEBUG: section 81    Store COSS Directory Routines
  * AUTHOR: Eric Stern
@@ -710,19 +710,14 @@ storeCossDirStats(SwapDir * SD, StoreEntry * sentry)
 static void
 storeCossDirParse(SwapDir * sd, int index, char *path)
 {
-    char *token;
     unsigned int i;
     unsigned int size;
-    unsigned int read_only = 0;
     CossInfo *cs;
 
     i = GetInteger();
     size = i << 10;            /* Mbytes to Kbytes */
     if (size <= 0)
        fatal("storeCossDirParse: invalid size value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     cs = xmalloc(sizeof(CossInfo));
     if (cs == NULL)
@@ -735,7 +730,6 @@ storeCossDirParse(SwapDir * sd, int index, char *path)
 
     cs->fd = -1;
     cs->swaplog_fd = -1;
-    sd->flags.read_only = read_only;
 
     sd->init = storeCossDirInit;
     sd->newfs = storeCossDirNewfs;
@@ -773,24 +767,21 @@ storeCossDirParse(SwapDir * sd, int index, char *path)
     cs->current_membuf = cs->membufs;
     cs->index.head = NULL;
     cs->index.tail = NULL;
+
+    parse_cachedir_options(sd, NULL, 0);
 }
 
 
 static void
 storeCossDirReconfigure(SwapDir * sd, int index, char *path)
 {
-    char *token;
     unsigned int i;
     unsigned int size;
-    unsigned int read_only = 0;
 
     i = GetInteger();
     size = i << 10;            /* Mbytes to Kbytes */
     if (size <= 0)
        fatal("storeCossDirParse: invalid size value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     if (size == sd->max_size)
        debug(3, 1) ("Cache COSS dir '%s' size remains unchanged at %d KB\n", path, size);
@@ -798,11 +789,7 @@ storeCossDirReconfigure(SwapDir * sd, int index, char *path)
        debug(3, 1) ("Cache COSS dir '%s' size changed to %d KB\n", path, size);
        sd->max_size = size;
     }
-
-    if (read_only != sd->flags.read_only) {
-       debug(3, 1) ("Cache COSS dir '%s' now %s\n", path, read_only ? "Read-Only" : "Read-Write");
-       sd->flags.read_only = read_only;
-    }
+    parse_cachedir_options(sd, NULL, 1);
 }
 
 void
index ef15255e1411273b715c29034e05a5479d5349e8..db1b807cee45c45ca4b475a843afb221d0923e29 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_diskd.cc,v 1.39 2001/02/07 18:56:54 hno Exp $
+ * $Id: store_dir_diskd.cc,v 1.40 2001/02/10 16:40:42 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -1707,6 +1707,37 @@ storeDiskdDirStats(SwapDir * SD, StoreEntry * sentry)
     storeAppendPrintf(sentry, "Pending operations: %d\n", diskdinfo->away);
 }
 
+static void 
+storeDiskdDirParseQ1(SwapDir * sd, const char *name, const char *value, int reconfiguring)
+{
+    diskdinfo_t *diskdinfo = sd->fsdata;
+    int old_magic1 = diskdinfo->magic1;
+    diskdinfo->magic1 = atoi(value);
+    if (reconfiguring && old_magic1 != diskdinfo->magic1)
+       debug(3, 1) ("cache_dir '%s' new Q1 value '%d'\n", diskdinfo->magic1);
+}
+
+static void 
+storeDiskdDirParseQ2(SwapDir * sd, const char *name, const char *value, int reconfiguring)
+{
+    diskdinfo_t *diskdinfo = sd->fsdata;
+    int old_magic2 = diskdinfo->magic2;
+    diskdinfo->magic2 = atoi(value);
+    if (reconfiguring && old_magic2 != diskdinfo->magic2)
+       debug(3, 1) ("cache_dir '%s' new Q2 value '%d'\n", diskdinfo->magic2);
+}
+
+struct cache_dir_option options[] =
+{
+#if NOT_YET
+    {"L1", storeDiskdDirParseL1},
+    {"L2", storeDiskdDirParseL2},
+#endif
+    {"Q1", storeDiskdDirParseQ1},
+    {"Q2", storeDiskdDirParseQ2},
+    {NULL, NULL}
+};
+
 /*
  * storeDiskdDirReconfigure
  *
@@ -1715,13 +1746,11 @@ storeDiskdDirStats(SwapDir * SD, StoreEntry * sentry)
 static void
 storeDiskdDirReconfigure(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
     int magic1, magic2;
-    unsigned int read_only = 0;
     diskdinfo_t *diskdinfo;
 
     i = GetInteger();
@@ -1744,9 +1773,6 @@ storeDiskdDirReconfigure(SwapDir * sd, int index, char *path)
     magic2 = i;
     if (magic2 <= 0)
        fatal("storeDiskdDirParse: invalid magic2 value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     /* just reconfigure it */
     if (size == sd->max_size)
@@ -1756,14 +1782,10 @@ storeDiskdDirReconfigure(SwapDir * sd, int index, char *path)
        debug(3, 1) ("Cache dir '%s' size changed to %d KB\n",
            path, size);
     sd->max_size = size;
-    if (sd->flags.read_only != read_only)
-       debug(3, 1) ("Cache dir '%s' now %s\n",
-           path, read_only ? "Read-Only" : "Read-Write");
     diskdinfo = sd->fsdata;
     diskdinfo->magic1 = magic1;
     diskdinfo->magic2 = magic2;
-    sd->flags.read_only = read_only;
-    return;
+    parse_cachedir_options(sd, options, 1);
 }
 
 void
@@ -1852,13 +1874,10 @@ storeDiskdCleanupDoubleCheck(SwapDir * sd, StoreEntry * e)
 static void
 storeDiskdDirParse(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
-    int magic1, magic2;
-    unsigned int read_only = 0;
     diskdinfo_t *diskdinfo;
 
     i = GetInteger();
@@ -1874,18 +1893,6 @@ storeDiskdDirParse(SwapDir * sd, int index, char *path)
     if (l2 <= 0)
        fatal("storeDiskdDirParse: invalid level 2 directories value");
     i = GetInteger();
-    magic1 = i;
-    if (magic1 <= 0)
-       fatal("storeDiskdDirParse: invalid magic1 value");
-    i = GetInteger();
-    magic2 = i;
-    if (magic2 <= 0)
-       fatal("storeDiskdDirParse: invalid magic2 value");
-
-
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     sd->fsdata = diskdinfo = xcalloc(1, sizeof(*diskdinfo));
     sd->index = index;
@@ -1896,9 +1903,8 @@ storeDiskdDirParse(SwapDir * sd, int index, char *path)
     diskdinfo->swaplog_fd = -1;
     diskdinfo->map = NULL;     /* Debugging purposes */
     diskdinfo->suggest = 0;
-    diskdinfo->magic1 = magic1;
-    diskdinfo->magic2 = magic2;
-    sd->flags.read_only = read_only;
+    diskdinfo->magic1 = 64;
+    diskdinfo->magic2 = 72;
     sd->init = storeDiskdDirInit;
     sd->newfs = storeDiskdDirNewfs;
     sd->dump = storeDiskdDirDump;
@@ -1924,6 +1930,8 @@ storeDiskdDirParse(SwapDir * sd, int index, char *path)
     sd->log.clean.nextentry = storeDiskdDirCleanLogNextEntry;
     sd->log.clean.done = storeDiskdDirWriteCleanDone;
 
+    parse_cachedir_options(sd, options, 0);
+
     /* Initialise replacement policy stuff */
     sd->repl = createRemovalPolicy(Config.replPolicy);
 }
index 9887bfbacd68cfd27bde4201ff67f45a07ae4517..8e194e0d6af6c0a610fa9f39c37806197ce8a903 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_null.cc,v 1.1 2001/02/07 17:42:37 hno Exp $
+ * $Id: store_null.cc,v 1.2 2001/02/10 16:40:42 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -113,6 +113,7 @@ storeNullDirParse(SwapDir * sd, int index, char *path)
     sd->checkobj = storeNullDirCheckObj;
     sd->log.clean.start = storeNullDirWriteCleanStart;
     sd->log.clean.done = storeNullDirWriteCleanDone;
+    parse_cachedir_options(sd, NULL, 0);
 }
 
 /* Setup and register the store module */
@@ -126,4 +127,3 @@ storeFsSetup_null(storefs_entry_t * storefs)
     storefs->donefunc = storeNullDirDone;
     null_initialised = 1;
 }
-
index df7d21de8908de4654834c7b3ab76dad90961b1f..d7a86b9ce15744300e68dd0fa9005880782df506 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_ufs.cc,v 1.28 2001/02/07 18:56:55 hno Exp $
+ * $Id: store_dir_ufs.cc,v 1.29 2001/02/10 16:40:43 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -1483,6 +1483,15 @@ storeUfsDirStats(SwapDir * SD, StoreEntry * sentry)
 #endif /* OLD_UNUSED_CODE */
 }
 
+static struct cache_dir_option options[] =
+{
+#if NOT_YET_DONE
+    {"L1", storeAufsDirParseL1},
+    {"L2", storeAufsDirParseL2},
+#endif
+    {NULL, NULL}
+};
+
 /*
  * storeUfsDirReconfigure
  *
@@ -1491,12 +1500,10 @@ storeUfsDirStats(SwapDir * SD, StoreEntry * sentry)
 static void
 storeUfsDirReconfigure(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
-    unsigned int read_only = 0;
 
     i = GetInteger();
     size = i << 10;            /* Mbytes to kbytes */
@@ -1510,9 +1517,6 @@ storeUfsDirReconfigure(SwapDir * sd, int index, char *path)
     l2 = i;
     if (l2 <= 0)
        fatal("storeUfsDirReconfigure: invalid level 2 directories value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     /* just reconfigure it */
     if (size == sd->max_size)
@@ -1522,11 +1526,8 @@ storeUfsDirReconfigure(SwapDir * sd, int index, char *path)
        debug(3, 1) ("Cache dir '%s' size changed to %d KB\n",
            path, size);
     sd->max_size = size;
-    if (sd->flags.read_only != read_only)
-       debug(3, 1) ("Cache dir '%s' now %s\n",
-           path, read_only ? "Read-Only" : "Read-Write");
-    sd->flags.read_only = read_only;
-    return;
+
+    parse_cachedir_options(sd, options, 1);
 }
 
 void
@@ -1615,12 +1616,10 @@ storeUfsCleanupDoubleCheck(SwapDir * sd, StoreEntry * e)
 static void
 storeUfsDirParse(SwapDir * sd, int index, char *path)
 {
-    char *token;
     int i;
     int size;
     int l1;
     int l2;
-    unsigned int read_only = 0;
     ufsinfo_t *ufsinfo;
 
     i = GetInteger();
@@ -1635,9 +1634,6 @@ storeUfsDirParse(SwapDir * sd, int index, char *path)
     l2 = i;
     if (l2 <= 0)
        fatal("storeUfsDirParse: invalid level 2 directories value");
-    if ((token = strtok(NULL, w_space)))
-       if (!strcasecmp(token, "read-only"))
-           read_only = 1;
 
     ufsinfo = xmalloc(sizeof(ufsinfo_t));
     if (ufsinfo == NULL)
@@ -1652,7 +1648,6 @@ storeUfsDirParse(SwapDir * sd, int index, char *path)
     ufsinfo->swaplog_fd = -1;
     ufsinfo->map = NULL;       /* Debugging purposes */
     ufsinfo->suggest = 0;
-    sd->flags.read_only = read_only;
     sd->init = storeUfsDirInit;
     sd->newfs = storeUfsDirNewfs;
     sd->dump = storeUfsDirDump;
@@ -1678,6 +1673,8 @@ storeUfsDirParse(SwapDir * sd, int index, char *path)
     sd->log.clean.nextentry = storeUfsDirCleanLogNextEntry;
     sd->log.clean.done = storeUfsDirWriteCleanDone;
 
+    parse_cachedir_options(sd, options, 1);
+
     /* Initialise replacement policy stuff */
     sd->repl = createRemovalPolicy(Config.replPolicy);
 }
index ccc28a8d2457638c4f10ae3cb67d3307e87b67a8..56c6b3d7cc7d861c0d722a9c4c10807be8f6d06b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.397 2001/02/07 18:56:52 hno Exp $
+ * $Id: protos.h,v 1.398 2001/02/10 16:40:40 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -93,6 +93,8 @@ extern void parse_eol(char *volatile *var);
 extern void parse_wordlist(wordlist ** list);
 extern void requirePathnameExists(const char *name, const char *path);
 extern void parse_time_t(time_t * var);
+extern void parse_cachedir_options(SwapDir * sd, struct cache_dir_option *options, int reconfiguring);
+
 
 /*
  * cbdata.c
index c11947d192fc0c0b52855f91caba73330473ff16..80f58d9eba6f6569ef08e202e9373a7b6c021c2a 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir.cc,v 1.125 2001/01/12 00:37:22 wessels Exp $
+ * $Id: store_dir.cc,v 1.126 2001/02/10 16:40:40 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -124,33 +124,35 @@ storeDirValidSwapDirSize(int swapdir, ssize_t objsize)
 
 /*
  * This new selection scheme simply does round-robin on all SwapDirs.
- * A SwapDir is skipped if it is over the max_size (100%) limit.  If
- * all SwapDir's are above the limit, then the first dirn that we
- * checked is returned.  Note that 'dirn' is guaranteed to advance even
- * if all SwapDirs are full.
- * 
- * XXX This function does NOT account for the read_only flag!
+ * A SwapDir is skipped if it is over the max_size (100%) limit, or
+ * overloaded.
  */
 static int
-storeDirSelectSwapDirRoundRobin(const StoreEntry * unused)
+storeDirSelectSwapDirRoundRobin(const StoreEntry * e)
 {
     static int dirn = 0;
     int i;
+    int load;
     SwapDir *sd;
-    /*
-     * yes, the '<=' is intentional.  If all dirs are full we want to
-     * make sure 'dirn' advances every time this gets called, otherwise
-     * we get stuck on one dir.
-     */
+    ssize_t objsize = (ssize_t) objectLen(e);
     for (i = 0; i <= Config.cacheSwap.n_configured; i++) {
        if (++dirn >= Config.cacheSwap.n_configured)
            dirn = 0;
        sd = &Config.cacheSwap.swapDirs[dirn];
+       if (sd->flags.read_only)
+           continue;
        if (sd->cur_size > sd->max_size)
            continue;
+       if (!storeDirValidSwapDirSize(i, objsize))
+           continue;
+       /* check for error or overload condition */
+       load = sd->checkobj(sd, e);
+       if (load < 0 || load > 1000) {
+           continue;
+       }
        return dirn;
     }
-    return dirn;
+    return -1;
 }
 
 /*
@@ -170,9 +172,9 @@ static int
 storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
 {
     ssize_t objsize;
-    ssize_t least_size;
-    ssize_t least_objsize;
-    int least_load = 1000;
+    ssize_t most_free = 0, cur_free;
+    ssize_t least_objsize = -1;
+    int least_load = INT_MAX;
     int load;
     int dirn = -1;
     int i;
@@ -182,31 +184,33 @@ storeDirSelectSwapDirLeastLoad(const StoreEntry * e)
     objsize = (ssize_t) objectLen(e);
     if (objsize != -1)
        objsize += e->mem_obj->swap_hdr_sz;
-    /* Initial defaults */
-    least_size = Config.cacheSwap.swapDirs[0].cur_size;
-    least_objsize = Config.cacheSwap.swapDirs[0].max_objsize;
     for (i = 0; i < Config.cacheSwap.n_configured; i++) {
        SD = &Config.cacheSwap.swapDirs[i];
        SD->flags.selected = 0;
-       if (SD->flags.read_only)
-           continue;
-       /* Valid for object size check */
-       if (!storeDirValidSwapDirSize(i, objsize))
-           continue;
        load = SD->checkobj(SD, e);
-       if (load < 0)
+       if (load < 0 || load > 1000) {
+           continue;
+       }
+       if (SD->flags.read_only)
            continue;
        if (SD->cur_size > SD->max_size)
            continue;
        if (load > least_load)
            continue;
-       if ((least_objsize > 0) && (objsize > least_objsize))
-           continue;
-       /* Only use leastsize if the load is equal */
-       if ((load == least_load) && (SD->cur_size > least_size))
-           continue;
+       cur_free = SD->max_size - SD->cur_size;
+       /* If the load is equal, then look in more details */
+       if (load == least_load) {
+           /* closest max_objsize fit */
+           if (least_objsize != -1)
+               if (SD->max_size > least_objsize || SD->max_size == -1)
+                   continue;
+           /* most free */
+           if (cur_free < most_free)
+               continue;
+       }
        least_load = load;
-       least_size = SD->cur_size;
+       least_objsize = SD->max_objsize;
+       most_free = cur_free;
        dirn = i;
     }
 
index 6b6f46d2726d3efc41661d9836f64f9d45718557..55fb2f1b9e1bfcfad6dc2e01cda379a4c81e2716 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.381 2001/02/09 19:35:11 hno Exp $
+ * $Id: structs.h,v 1.382 2001/02/10 16:40:41 hno Exp $
  *
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
@@ -248,7 +248,7 @@ struct _aclCheck_t {
     unsigned short my_port;
     request_t *request;
     /* for acls that look at reply data */
-    HttpReply * reply;
+    HttpReply *reply;
     ConnStateData *conn;       /* hack for ident and NTLM */
     char rfc931[USER_IDENT_SZ];
     auth_user_request_t *auth_user_request;
@@ -2100,3 +2100,8 @@ struct _Logfile {
        unsigned int fatal:1;
     } flags;
 };
+
+struct cache_dir_option {
+    char *name;
+    void (*parse) (SwapDir * sd, const char *option, const char *value, int reconfiguring);
+};