--------------------- PatchSet 11497 Date: 2007/06/23 22:50:18 Author: hno Branch: SQUID_2_6 Tag: (none) Log: Author: Mark Bergsma MFC: Bug #1130: min-size option for cache_dir Add a 'min-size' cache_dir option to Squid 2.6 We also needed this feature so I wrote a patch for Squid 2.6. It also adds the object size bounds to the cachemgr store directory stats page. Members: src/cache_cf.c:1.463.2.2->1.463.2.3 src/cf.data.pre:1.382.2.5->1.382.2.6 src/store_dir.c:1.143.2.2->1.143.2.3 src/structs.h:1.507.2.5->1.507.2.6 Index: squid/src/cache_cf.c =================================================================== RCS file: /cvsroot/squid/squid/src/cache_cf.c,v retrieving revision 1.463.2.2 retrieving revision 1.463.2.3 diff -u -r1.463.2.2 -r1.463.2.3 --- squid/src/cache_cf.c 3 Jun 2007 00:40:32 -0000 1.463.2.2 +++ squid/src/cache_cf.c 23 Jun 2007 22:50:18 -0000 1.463.2.3 @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.c,v 1.463.2.2 2007/06/03 00:40:32 hno Exp $ + * $Id: cache_cf.c,v 1.463.2.3 2007/06/23 22:50:18 hno Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -58,6 +58,8 @@ static void parse_cachedir_option_readonly(SwapDir * sd, const char *option, const char *value, int reconfiguring); static void dump_cachedir_option_readonly(StoreEntry * e, const char *option, SwapDir * sd); +static void parse_cachedir_option_minsize(SwapDir * sd, const char *option, const char *value, int reconfiguring); +static void dump_cachedir_option_minsize(StoreEntry * e, const char *option, SwapDir * sd); static void parse_cachedir_option_maxsize(SwapDir * sd, const char *option, const char *value, int reconfiguring); static void dump_cachedir_option_maxsize(StoreEntry * e, const char *option, SwapDir * sd); static void parse_logformat(logformat ** logformat_definitions); @@ -71,6 +73,7 @@ static struct cache_dir_option common_cachedir_options[] = { {"read-only", parse_cachedir_option_readonly, dump_cachedir_option_readonly}, + {"min-size", parse_cachedir_option_minsize, dump_cachedir_option_minsize}, {"max-size", parse_cachedir_option_maxsize, dump_cachedir_option_maxsize}, {NULL, NULL} }; @@ -1422,6 +1425,7 @@ sd = swap->swapDirs + swap->n_configured; sd->type = storefs_list[fs].typestr; /* defaults in case fs implementation fails to set these */ + sd->min_objsize = 0; sd->max_objsize = -1; sd->fs.blksize = 1024; /* parse the FS parameters and options */ @@ -1450,6 +1454,29 @@ } static void +parse_cachedir_option_minsize(SwapDir * sd, const char *option, const char *value, int reconfiguring) +{ + squid_off_t size; + + if (!value) + self_destruct(); + + size = strto_off_t(value, NULL, 10); + + if (reconfiguring && sd->min_objsize != size) + debug(3, 1) ("Cache dir '%s' min object size now %ld\n", sd->path, (long int) size); + + sd->min_objsize = size; +} + +static void +dump_cachedir_option_minsize(StoreEntry * e, const char *option, SwapDir * sd) +{ + if (sd->min_objsize != 0) + storeAppendPrintf(e, " %s=%ld", option, (long int) sd->min_objsize); +} + +static void parse_cachedir_option_maxsize(SwapDir * sd, const char *option, const char *value, int reconfiguring) { squid_off_t size; Index: squid/src/cf.data.pre =================================================================== RCS file: /cvsroot/squid/squid/src/cf.data.pre,v retrieving revision 1.382.2.5 retrieving revision 1.382.2.6 diff -u -r1.382.2.5 -r1.382.2.6 --- squid/src/cf.data.pre 23 Jun 2007 21:32:35 -0000 1.382.2.5 +++ squid/src/cf.data.pre 23 Jun 2007 22:50:18 -0000 1.382.2.6 @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.382.2.5 2007/06/23 21:32:35 hno Exp $ +# $Id: cf.data.pre,v 1.382.2.6 2007/06/23 22:50:18 hno Exp $ # # # SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1195,6 +1195,11 @@ read-only, this cache_dir is read only. + min-size=n, refers to the min object size this storedir will accept. + It's used to restrict a storedir to only store large objects + (e.g. aufs) while other storedirs are optimized for smaller objects + (e.g. COSS). Defaults to 0. + 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 Index: squid/src/store_dir.c =================================================================== RCS file: /cvsroot/squid/squid/src/store_dir.c,v retrieving revision 1.143.2.2 retrieving revision 1.143.2.3 diff -u -r1.143.2.2 -r1.143.2.3 --- squid/src/store_dir.c 5 May 2007 22:41:21 -0000 1.143.2.2 +++ squid/src/store_dir.c 23 Jun 2007 22:50:18 -0000 1.143.2.3 @@ -1,6 +1,6 @@ /* - * $Id: store_dir.c,v 1.143.2.2 2007/05/05 22:41:21 hno Exp $ + * $Id: store_dir.c,v 1.143.2.3 2007/06/23 22:50:18 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -131,23 +131,18 @@ storeDirValidSwapDirSize(int swapdir, squid_off_t objsize) { /* - * If the swapdir's max_obj_size is -1, then it definitely can + * If the object size is -1, then if the storedir max_objsize isn't -1 + * we can't store it (min_objsize intentionally ignored here) */ - if (Config.cacheSwap.swapDirs[swapdir].max_objsize == -1) - return 1; - - /* - * If the object size is -1, then if the storedir isn't -1 we - * can't store it - */ - if ((objsize == -1) && - (Config.cacheSwap.swapDirs[swapdir].max_objsize != -1)) - return 0; + if (objsize == -1) + return Config.cacheSwap.swapDirs[swapdir].max_objsize == -1; /* - * Else, make sure that the max object size is larger than objsize + * Else, make sure that min_objsize <= objsize < max_objsize */ - if (Config.cacheSwap.swapDirs[swapdir].max_objsize > objsize) + if ((Config.cacheSwap.swapDirs[swapdir].min_objsize <= objsize) && + ((Config.cacheSwap.swapDirs[swapdir].max_objsize > objsize) || + (Config.cacheSwap.swapDirs[swapdir].max_objsize == -1))) return 1; else return 0; @@ -337,6 +332,11 @@ storeAppendPrintf(sentry, "FS Block Size %d Bytes\n", SD->fs.blksize); SD->statfs(SD, sentry); + storeAppendPrintf(sentry, "Accepted object sizes: %" PRINTF_OFF_T " - ", SD->min_objsize); + if (SD->max_objsize == -1) + storeAppendPrintf(sentry, "(unlimited) bytes\n"); + else + storeAppendPrintf(sentry, "%" PRINTF_OFF_T " bytes\n", SD->max_objsize); if (SD->repl) { storeAppendPrintf(sentry, "Removal policy: %s\n", SD->repl->_type); if (SD->repl->Stats) Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid/squid/src/structs.h,v retrieving revision 1.507.2.5 retrieving revision 1.507.2.6 diff -u -r1.507.2.5 -r1.507.2.6 --- squid/src/structs.h 26 Apr 2007 23:11:51 -0000 1.507.2.5 +++ squid/src/structs.h 23 Jun 2007 22:50:18 -0000 1.507.2.6 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.507.2.5 2007/04/26 23:11:51 hno Exp $ + * $Id: structs.h,v 1.507.2.6 2007/06/23 22:50:18 hno Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1755,6 +1755,7 @@ int max_size; char *path; int index; /* This entry's index into the swapDirs array */ + squid_off_t min_objsize; squid_off_t max_objsize; RemovalPolicy *repl; int removals;