From: hno <> Date: Tue, 27 Jun 2000 14:41:30 +0000 (+0000) Subject: Complete rewrite of the removal policy list, to work along the X-Git-Tag: SQUID_3_0_PRE1~1908 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=22d38e05dc4fdd9f73bc14438d457a3df204295d;p=thirdparty%2Fsquid.git Complete rewrite of the removal policy list, to work along the 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). --- diff --git a/src/globals.h b/src/globals.h index 71afbea562..2e9c27b267 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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 */ diff --git a/src/protos.h b/src/protos.h index 2bc231cf86..44d712ee04 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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 *); diff --git a/src/repl_modules.sh b/src/repl_modules.sh index c806ce4380..4427b48035 100755 --- a/src/repl_modules.sh +++ b/src/repl_modules.sh @@ -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 "}" diff --git a/src/store.cc b/src/store.cc index f1babdd6d5..c00f0f8c65 100644 --- a/src/store.cc +++ b/src/store.cc @@ -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) diff --git a/src/structs.h b/src/structs.h index 34451f0037..516a5bad93 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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 */ diff --git a/src/typedefs.h b/src/typedefs.h index c9388b436c..010fb7034f 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -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;