From: wessels <> Date: Tue, 15 Jul 1997 03:11:00 +0000 (+0000) Subject: wrestling with units on byte variables X-Git-Tag: SQUID_3_0_PRE1~4895 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9906e7243b9de1e11c1e9129ae0b110e5e51ca55;p=thirdparty%2Fsquid.git wrestling with units on byte variables --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 26b7134cee..b085f4fae0 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.203 1997/07/14 19:56:14 wessels Exp $ + * $Id: cache_cf.cc,v 1.204 1997/07/14 21:11:00 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -40,6 +40,11 @@ static const char *const T_MONTH_STR = "month"; static const char *const T_YEAR_STR = "year"; static const char *const T_DECADE_STR = "decade"; +static const char *const B_BYTES_STR = "bytes"; +static const char *const B_KBYTES_STR = "KB"; +static const char *const B_MBYTES_STR = "MB"; +static const char *const B_GBYTES_STR = "GB"; + static const char *const list_sep = ", \t\n\r"; static char fatal_str[BUFSIZ]; @@ -56,10 +61,11 @@ static void parse_wordlist _PARAMS((wordlist **)); static void default_all _PARAMS((void)); static int parse_line _PARAMS((char *)); static cache_peer *configFindPeer _PARAMS((const char *name)); +static void parseBytesLine _PARAMS((size_t *bptr, const char *units)); +static size_t parseBytesUnits _PARAMS((const char *unit)); /* These come from cf_gen.c */ static void default_all _PARAMS((void)); -static void dump_all _PARAMS((void)); static void free_all _PARAMS((void)); static void @@ -165,11 +171,6 @@ parseConfigFile(const char *file_name) } } - /* Scale values */ - Config.maxRequestSize <<= 10; /* 1k */ - Config.Store.maxObjectSize <<= 10; /* 1k */ - Config.Mem.maxSize <<= 10; /* 1m */ - /* Sanity checks */ if (Config.Swap.maxSize < (Config.Mem.maxSize >> 10)) { printf("WARNING: cache_swap (%d kbytes) is less than cache_mem (%d bytes).\n", Config.Swap.maxSize, Config.Mem.maxSize); @@ -289,6 +290,41 @@ parseTimeUnits(const char *unit) return 0; } +static void +parseBytesLine(size_t *bptr, const char *units) +{ + char *token; + double d; + size_t m; + size_t u; + if ((u = parseBytesUnits(units)) == 0) + self_destruct(); + if ((token = strtok(NULL, w_space)) == NULL) + self_destruct(); + d = atof(token); + m = u; /* default to 'units' if none specified */ + if ((token = strtok(NULL, w_space)) != NULL) { + if ((m = parseBytesUnits(token)) == 0) + self_destruct(); + } + *bptr = m * d / u; +} + +static size_t +parseBytesUnits(const char *unit) +{ + if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) + return 1; + if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) + return 1<<10; + if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) + return 1<<20; + if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) + return 1<<30; + debug(3, 1) ("parseBytesUnits: unknown bytes unit '%s'\n", unit); + return 0; +} + /***************************************************************************** * Max *****************************************************************************/ @@ -417,6 +453,7 @@ parse_cachedir(struct _cacheSwap *swap) tmp->map = file_map_create(MAX_FILES_PER_DIR); tmp->swaplog_fd = -1; swap->n_configured++; + Config.Swap.maxSize += size; } static void @@ -941,7 +978,40 @@ free_time_t(time_t *var) { *var = 0; } - + +static void +dump_size_t(size_t var) +{ + printf("%d bytes", (int) var); +} + +static void +dump_kb_size_t(size_t var) +{ + printf("%d KB", (int) var); +} + +static void +parse_size_t(size_t *var) +{ + parseBytesLine(var, B_BYTES_STR); +} + +static void +parse_kb_size_t(size_t *var) +{ + parseBytesLine(var, B_KBYTES_STR); +} + +static void +free_size_t(size_t *var) +{ + *var = 0; +} + +#define free_kb_size_t free_size_t +#define free_mb_size_t free_size_t +#define free_gb_size_t free_size_t static void dump_ushort(u_short var) diff --git a/src/cf.data.pre b/src/cf.data.pre index 3eb41fcee4..8008eb27ea 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -357,9 +357,9 @@ DOC_END NAME: cache_mem -COMMENT: (in megabytes) -TYPE: int -DEFAULT: 8 +COMMENT: (bytes) +TYPE: size_t +DEFAULT: 8 MB LOC: Config.Mem.maxSize DOC_START Maximum amout of VM used to store objects in memory. @@ -386,7 +386,7 @@ DOC_START The default is 8 Megabytes. -cache_mem 8 +cache_mem 8 MB DOC_END @@ -437,14 +437,15 @@ DOC_END NAME: maximum_object_size -TYPE: int -DEFAULT: 4096 +COMMENT: (KB) +TYPE: kb_size_t +DEFAULT: 4096 KB LOC: Config.Store.maxObjectSize DOC_START Objects larger than this size will NOT be saved on disk. The value is specified in kilobytes, and the default is 4MB. -maximum_object_size 4096 +maximum_object_size 4096 KB DOC_END @@ -827,15 +828,16 @@ DOC_END NAME: request_size -TYPE: int -DEFAULT: 100 +COMMENT: (KB) +TYPE: kb_size_t +DEFAULT: 100 KB LOC: Config.maxRequestSize DOC_START Maximum allowed request size in kilobytes. If people are using POST to upload files, then set this to the largest acceptable filesize plus a few extra kbytes. -request_size 100 +request_size 100 KB DOC_END @@ -893,8 +895,8 @@ DOC_END NAME: quick_abort_min -COMMENT: (kbytes) -TYPE: int +COMMENT: (KB) +TYPE: kb_size_t DEFAULT: -1 LOC: Config.quickAbort.min DOC_NONE @@ -907,8 +909,8 @@ LOC: Config.quickAbort.pct DOC_NONE NAME: quick_abort_max -COMMENT: (kbytes) -TYPE: int +COMMENT: (KB) +TYPE: kb_size_t DEFAULT: 0 LOC: Config.quickAbort.max DOC_START diff --git a/src/cf_gen.cc b/src/cf_gen.cc index 1ad31de43e..d6036a8cf7 100644 --- a/src/cf_gen.cc +++ b/src/cf_gen.cc @@ -1,5 +1,5 @@ /* - * $Id: cf_gen.cc,v 1.6 1997/07/14 19:56:15 wessels Exp $ + * $Id: cf_gen.cc,v 1.7 1997/07/14 21:11:01 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Max Okumoto @@ -76,6 +76,7 @@ typedef struct Entry { static const char WS[] = " \t"; +static const char NS[] = ""; static int gen_default(Entry *, FILE *); static void gen_parse(Entry *, FILE *); static void gen_dump(Entry *, FILE *); @@ -94,6 +95,7 @@ main(int argc, char *argv[]) Entry *curr = NULL; enum State state; int rc = 0; + char *ptr = NULL; /*-------------------------------------------------------------------* * Parse input file @@ -139,49 +141,35 @@ main(int argc, char *argv[]) case s1: if ((strlen(buff) == 0) || (!strncmp(buff, "#", 1))) { /* ignore empty and comment lines */ - } else if (!strncmp(buff, "COMMENT:", 8)) { - char *ptr = buff+8; - while(isspace(*ptr)) - ptr++; + ptr = buff + 8; + while (isspace(*ptr)) + ptr++; curr->comment = strdup(ptr); } else if (!strncmp(buff, "DEFAULT:", 8)) { - char *ptr; - - if ((ptr = strtok(buff + 8, WS)) == NULL) { - printf("Error on line %d\n", linenum); - exit(1); - } + ptr = buff + 8; + while (isspace(*ptr)) + ptr++; curr->default_value = strdup(ptr); - } else if (!strncmp(buff, "LOC:", 4)) { - char *ptr; - if ((ptr = strtok(buff + 4, WS)) == NULL) { printf("Error on line %d\n", linenum); exit(1); } curr->loc = strdup(ptr); - } else if (!strncmp(buff, "TYPE:", 5)) { - char *ptr; - if ((ptr = strtok(buff + 5, WS)) == NULL) { printf("Error on line %d\n", linenum); exit(1); } curr->type = strdup(ptr); - } else if (!strcmp(buff, "DOC_START")) { state = sDOC; - } else if (!strcmp(buff, "DOC_NONE")) { /* add to list of entries */ curr->next = entries; entries = curr; - state = sSTART; - } else { printf("Error on line %d\n", linenum); exit(1); @@ -291,10 +279,10 @@ gen_default(Entry * head, FILE * fp) "default_line(const char *s)\n" "{\n" "\tLOCAL_ARRAY(char, tmp_line, BUFSIZ);\n" - "\txstrncpy(tmp_line, s, BUFSIZ);\n" - "\txstrncpy(config_input_line, s, BUFSIZ);\n" + "\txstrncpy(tmp_line, s, BUFSIZ);\n" + "\txstrncpy(config_input_line, s, BUFSIZ);\n" "\tconfig_lineno++;\n" - "\tparse_line(tmp_line);\n" + "\tparse_line(tmp_line);\n" "}\n" ); @@ -423,7 +411,7 @@ gen_conf(Entry * head, FILE * fp) fprintf(fp, "# TAG: %s", entry->name); if (entry->comment) - fprintf(fp, "\t%s", entry->comment); + fprintf(fp, "\t%s", entry->comment); fprintf(fp, "\n"); for (line = entry->doc; line != NULL; line = line->next) { fprintf(fp, "#%s\n", line->data); diff --git a/src/ftp.cc b/src/ftp.cc index 91e2391dda..ce518cf500 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $Id: ftp.cc,v 1.129 1997/06/26 22:41:41 wessels Exp $ + * $Id: ftp.cc,v 1.130 1997/07/14 21:11:02 wessels Exp $ * * DEBUG: section 9 File Transfer Protocol (FTP) * AUTHOR: Harvest Derived @@ -1000,6 +1000,7 @@ ftpReadControlReply(int fd, void *data) } if (len == 0) { debug(9, 1) ("Read 0 bytes from FTP control socket?\n"); + assert(len); BIT_RESET(entry->flag, ENTRY_CACHABLE); storeReleaseRequest(entry); storeAbort(entry, ERR_READ_ERROR, xstrerror(), 0); diff --git a/src/protos.h b/src/protos.h index b4bd74848c..b20e2627a1 100644 --- a/src/protos.h +++ b/src/protos.h @@ -54,6 +54,7 @@ extern void intlistDestroy _PARAMS((intlist **)); extern void wordlistDestroy _PARAMS((wordlist **)); extern void configFreeMemory _PARAMS((void)); extern char *cachemgr_getpassword _PARAMS((cachemgr_passwd **, char *)); +extern void dump_all _PARAMS((void)); extern void cbdataInit _PARAMS((void)); extern void cbdataAdd _PARAMS((void *p)); diff --git a/src/store.cc b/src/store.cc index 769e328a83..6f6dd0d3e1 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.267 1997/07/14 19:53:12 wessels Exp $ + * $Id: store.cc,v 1.268 1997/07/14 21:11:04 wessels Exp $ * * DEBUG: section 20 Storeage Manager * AUTHOR: Harvest Derived @@ -2274,6 +2274,8 @@ storeInitHashValues(void) store_maintain_buckets == 1 ? null_string : "s", store_maintain_rate, store_maintain_rate == 1 ? null_string : "s"); + debug(20,1)("Max Mem size: %d KB\n", Config.Mem.maxSize>>10); + debug(20,1)("Max Swap size: %d KB\n", Config.Swap.maxSize); } void diff --git a/src/structs.h b/src/structs.h index dd44da826c..4fdbd0e112 100644 --- a/src/structs.h +++ b/src/structs.h @@ -101,7 +101,7 @@ struct _cache_peer { struct _SquidConfig { struct { - int maxSize; + size_t maxSize; int highWaterMark; int lowWaterMark; } Mem , Swap; @@ -110,9 +110,9 @@ struct _SquidConfig { u_short relayPort; } Wais; struct { - int min; + size_t min; int pct; - int max; + size_t max; } quickAbort; time_t referenceAge; time_t negativeTtl; @@ -128,7 +128,7 @@ struct _SquidConfig { time_t connect; time_t request; } Timeout; - int maxRequestSize; + size_t maxRequestSize; struct { ushortlist *http; u_short icp; @@ -188,8 +188,8 @@ struct _SquidConfig { struct in_addr udp_outgoing; struct in_addr client_netmask; } Addrs; - int tcpRcvBufsz; - int udpMaxHitObjsz; + size_t tcpRcvBufsz; + size_t udpMaxHitObjsz; wordlist *cache_stoplist; wordlist *hierarchy_stoplist; wordlist *mcast_group_list; @@ -199,7 +199,7 @@ struct _SquidConfig { cache_peer *sslProxy; cache_peer *passProxy; struct { - int size; + size_t size; int low; int high; } ipcache; @@ -207,8 +207,8 @@ struct _SquidConfig { cachemgr_passwd *passwd_list; struct { int objectsPerBucket; - int avgObjectSize; - int maxObjectSize; + size_t avgObjectSize; + size_t maxObjectSize; } Store; struct { int high;