]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Complete rewrite of the removal policy list, to work along the
authorhno <>
Tue, 27 Jun 2000 14:41:30 +0000 (14:41 +0000)
committerhno <>
Tue, 27 Jun 2000 14:41:30 +0000 (14:41 +0000)
same lines as the filesystem list. Now a list of calls to
storeReplAdd() is generated, which adds the policies to a dynamic
list, and storeCreateRemovalPolicy searches this list for the
requested policy name.

This also allows for a seemless integration of loadable modules
at any time. All that is needed to have filesystems or policies
in loadable modules is to write the few lines of code required
to bring in the shared object, and to call the appropriate
registering function (storeFsAdd or storeReplAdd).

src/globals.h
src/protos.h
src/repl_modules.sh
src/store.cc
src/structs.h
src/typedefs.h

index 71afbea562d91a26e10658d313fe06faf3dc5813..2e9c27b2677328d40fbadc978392081f5af79bc4 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: globals.h,v 1.93 2000/06/25 22:28:42 wessels Exp $
+ * $Id: globals.h,v 1.94 2000/06/27 08:41:30 hno Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -146,6 +146,7 @@ extern request_flags null_request_flags;
 extern int store_open_disk_fd; /* 0 */
 extern const char *SwapDirType[];
 extern storefs_entry_t *storefs_list;  /* NULL */
+extern storerepl_entry_t *storerepl_list;      /* NULL */
 extern int store_swap_low;     /* 0 */
 extern int store_swap_high;    /* 0 */
 extern int store_pages_max;    /* 0 */
index 2bc231cf861cae475ed573e7b671e8d0812b5e98..44d712ee044748f59cd73ce977c2b0d5d7b41ee9 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: protos.h,v 1.374 2000/06/26 04:57:16 wessels Exp $
+ * $Id: protos.h,v 1.375 2000/06/27 08:41:30 hno Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -852,10 +852,14 @@ extern void storeSwapFileNumberSet(StoreEntry * e, sfileno filn);
 extern void storeFsInit(void);
 extern void storeFsDone(void);
 extern void storeFsAdd(char *, STSETUP *);
+extern void storeReplAdd(char *, REMOVALPOLICYCREATE *);
 
 /* store_modules.c */
 extern void storeFsSetup(void);
 
+/* repl_modules.c */
+extern void storeReplSetup(void);
+
 /* store_io.c */
 extern storeIOState *storeCreate(StoreEntry *, STFNCB *, STIOCB *, void *);
 extern storeIOState *storeOpen(StoreEntry *, STFNCB *, STIOCB *, void *);
index c806ce4380dbb32c6f4ab9355d5fc36dec0e4e74..4427b48035211ded01f7397143e970cd408c7ebb 100755 (executable)
@@ -1,30 +1,15 @@
 #!/bin/sh
-
-# NOTE: echo '\n' is not portable.  Some shells interpret and
-# change it to an actual newline character.  The ugly hack here
-# is to use two echo commands:
-#      echo -n 'blah\'
-#      echo 'n'
-# This is probably more portable in Perl.
-
-echo "/* automatically generated `date` by"
-echo " *   $0 $*"
-echo ' * do not edit'
-echo ' */'
-echo '#include "squid.h"'
-echo ''
+echo "/* automatically generated by $0 $*"
+echo " * do not edit"
+echo " */"
+echo "#include \"squid.h\""
+echo ""
 for module in "$@"; do
-   echo "REMOVALPOLICYCREATE createRemovalPolicy_${module};"
+   echo "extern REMOVALPOLICYCREATE createRemovalPolicy_${module};"
 done
-echo ''
-echo 'RemovalPolicy *'
-echo 'createRemovalPolicy(RemovalPolicySettings *settings)'
-echo '{'
+echo "void storeReplSetup(void)"
+echo "{"
 for module in "$@"; do
-   echo "        if (strcmp(settings->type, \"${module}\") == 0)"
-   echo "            return createRemovalPolicy_${module}(settings->args);"
+   echo "      storeReplAdd(\"$module\", createRemovalPolicy_${module});"
 done
-   echo -n '        debug(20, 1) ("Unknown policy %s\'
-   echo 'n", settings->type);'
-   echo '        return NULL;'
-echo '}'
+echo "}"
index f1babdd6d56b435189c20dfda03054b92f69f2b7..c00f0f8c65ade26c4a534cf4f1861b1a2e46723c 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.527 2000/06/26 04:57:16 wessels Exp $
+ * $Id: store.cc,v 1.528 2000/06/27 08:41:30 hno Exp $
  *
  * DEBUG: section 20    Storage Manager
  * AUTHOR: Harvest Derived
@@ -1222,6 +1222,7 @@ storeEntryReset(StoreEntry * e)
 void
 storeFsInit(void)
 {
+    storeReplSetup();
     storeFsSetup();
 }
 
@@ -1260,6 +1261,39 @@ storeFsAdd(char *type, STSETUP * setup)
     setup(&storefs_list[i]);
 }
 
+/*
+ * called to add another store removal policy module
+ */
+void
+storeReplAdd(char *type, REMOVALPOLICYCREATE * create)
+{
+    int i;
+    /* find the number of currently known repl types */
+    for (i = 0; storerepl_list && storerepl_list[i].typestr; i++) {
+       assert(strcmp(storerepl_list[i].typestr, type) != 0);
+    }
+    /* add the new type */
+    storerepl_list = xrealloc(storerepl_list, (i + 2) * sizeof(storerepl_entry_t));
+    memset(&storerepl_list[i + 1], 0, sizeof(storerepl_entry_t));
+    storerepl_list[i].typestr = type;
+    storerepl_list[i].create = create;
+}
+
+/*
+ * Create a removal policy instance
+ */
+RemovalPolicy *
+createRemovalPolicy(RemovalPolicySettings * settings)
+{
+    storerepl_entry_t *r;
+    for (r = storerepl_list; r && r->typestr; r++) {
+       if (strcmp(r->typestr, settings->type) == 0)
+           return r->create(settings->args);
+    }
+    debug(20,1)("Unknown policy %s\n", settings->type);
+    return NULL;
+}
+
 #if 0
 void
 storeSwapFileNumberSet(StoreEntry * e, sfileno filn)
index 34451f00375f0b8c121211f4241a296348fa5c66..516a5bad9375ea981172b730359bdb4eef7f9a39 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.345 2000/06/26 05:11:13 wessels Exp $
+ * $Id: structs.h,v 1.346 2000/06/27 08:41:31 hno Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -1895,6 +1895,15 @@ struct _storefs_entry {
     STFSSHUTDOWN *donefunc;
 };
 
+/*
+ * This defines an repl type
+ */
+
+struct _storerepl_entry {
+    char *typestr;
+    REMOVALPOLICYCREATE *create;
+};
+
 /*
  * Async disk IO - this defines a async disk io queue
  */
index c9388b436c9184f6650dc26a480126df20dabbaf..010fb7034f0215474772fb46052bcb8cf624eb2f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: typedefs.h,v 1.106 2000/06/26 04:57:17 wessels Exp $
+ * $Id: typedefs.h,v 1.107 2000/06/27 08:41:31 hno Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -169,6 +169,7 @@ typedef struct _generic_cbdata generic_cbdata;
 typedef struct _storeIOState storeIOState;
 typedef struct _link_list link_list;
 typedef struct _storefs_entry storefs_entry_t;
+typedef struct _storerepl_entry storerepl_entry_t;
 typedef struct _diskd_queue diskd_queue;
 typedef struct _Logfile Logfile;
 typedef struct _RemovalPolicy RemovalPolicy;