From: wessels <> Date: Sat, 22 May 1999 13:42:01 +0000 (+0000) Subject: Continuing the process of supporting multiple filesystem types. Now X-Git-Tag: SQUID_3_0_PRE1~2185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0e4e0e7d10a5f46b03ad9e31ab0ff156643edbb8;p=thirdparty%2Fsquid.git Continuing the process of supporting multiple filesystem types. Now the I/O operations are function pointers in the SwapDir structure. Moved UFS-specific parsing out of cache_cf.c and into store_dir_ufs.c. Then had to make some cache_cf.c functions global. Removed some remaining bits of USE_ASYNC_IO code. --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index b7f9206c19..25cbcdb3b5 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.329 1999/05/10 19:27:50 wessels Exp $ + * $Id: cache_cf.cc,v 1.330 1999/05/22 07:42:01 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -58,8 +58,6 @@ static const char *const list_sep = ", \t\n\r"; static int http_header_first = 0; -static void self_destruct(void); - static void configDoConfigure(void); static void parse_refreshpattern(refresh_t **); static int parseTimeUnits(const char *unit); @@ -79,7 +77,7 @@ static void dump_http_header(StoreEntry * entry, const char *name, HttpHeaderMas static void parse_http_header(HttpHeaderMask * header); static void free_http_header(HttpHeaderMask * header); -static void +void self_destruct(void) { fatalf("Bungled %s line %d: %s", @@ -157,12 +155,17 @@ intlistFind(intlist * list, int i) * defined */ -#define GetInteger(var) \ - token = strtok(NULL, w_space); \ - if( token == NULL) \ - self_destruct(); \ - if (sscanf(token, "%d", &var) != 1) \ - self_destruct(); +int +GetInteger(void) +{ + char *token = strtok(NULL, w_space); + int i; + if (token == NULL) + self_destruct(); + if (sscanf(token, "%d", &i) != 1) + self_destruct(); + return i; +} int parseConfigFile(const char *file_name) @@ -664,7 +667,7 @@ parse_delay_pool_rates(delayConfig * cfg) if (sscanf(token, "%d", &i) != 1) self_destruct(); ptr->restore_bps = i; - GetInteger(i); + i = GetInteger(); ptr->max_bytes = i; ptr++; } @@ -752,12 +755,15 @@ dump_cachedir(StoreEntry * entry, const char *name, cacheSwap swap) int i; for (i = 0; i < swap.n_configured; i++) { s = swap.swapDirs + i; - storeAppendPrintf(entry, "%s %s %d %d %d\n", - name, - s->path, - s->max_size >> 10, - s->l1, - s->l2); + switch (s->type) { + case SWAPDIR_UFS: + storeUfsDirDump(entry, name, s); + break; + default: + debug(0, 0) ("dump_cachedir doesn't know about type %d\n", + (int) s->type); + break; + } } } @@ -773,71 +779,34 @@ check_null_string(char *s) return s == NULL; } -static void -parse_cachedir(cacheSwap * swap) +void +allocate_new_swapdir(cacheSwap * swap) { - char *token; - char *path; - int i; - int size; - int l1; - int l2; - unsigned int read_only = 0; - SwapDir *tmp = NULL; - if ((path = strtok(NULL, w_space)) == NULL) - self_destruct(); - GetInteger(i); - size = i << 10; /* Mbytes to kbytes */ - if (size <= 0) - fatal("parse_cachedir: invalid size value"); - GetInteger(i); - l1 = i; - if (l1 <= 0) - fatal("parse_cachedir: invalid level 1 directories value"); - GetInteger(i); - l2 = i; - if (l2 <= 0) - fatal("parse_cachedir: invalid level 2 directories value"); - if ((token = strtok(NULL, w_space))) - if (!strcasecmp(token, "read-only")) - read_only = 1; - for (i = 0; i < swap->n_configured; i++) { - tmp = swap->swapDirs + i; - if (!strcmp(path, tmp->path)) { - /* just reconfigure it */ - if (size == tmp->max_size) - debug(3, 1) ("Cache dir '%s' size remains unchanged at %d KB\n", - path, size); - else - debug(3, 1) ("Cache dir '%s' size changed to %d KB\n", - path, size); - tmp->max_size = size; - if (tmp->flags.read_only != read_only) - debug(3, 1) ("Cache dir '%s' now %s\n", - path, read_only ? "Read-Only" : "Read-Write"); - tmp->flags.read_only = read_only; - return; - } - } if (swap->swapDirs == NULL) { swap->n_allocated = 4; swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir)); } if (swap->n_allocated == swap->n_configured) { + SwapDir *tmp; swap->n_allocated <<= 1; tmp = xcalloc(swap->n_allocated, sizeof(SwapDir)); xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir)); xfree(swap->swapDirs); swap->swapDirs = tmp; } - tmp = swap->swapDirs + swap->n_configured; - tmp->path = xstrdup(path); - tmp->max_size = size; - tmp->l1 = l1; - tmp->l2 = l2; - tmp->flags.read_only = read_only; - tmp->swaplog_fd = -1; - swap->n_configured++; +} + +static void +parse_cachedir(cacheSwap * swap) +{ + char *type_str; + if ((type_str = strtok(NULL, w_space)) == NULL) + self_destruct(); + if (0 == strcasecmp(type_str, "ufs")) { + storeUfsDirParse(swap); + } else { + fatalf("Unknown cache_dir type '%s'\n", type_str); + } } static void @@ -850,9 +819,14 @@ free_cachedir(cacheSwap * swap) return; for (i = 0; i < swap->n_configured; i++) { s = swap->swapDirs + i; - if (s->swaplog_fd > -1) { - file_close(s->swaplog_fd); - s->swaplog_fd = -1; + switch (s->type) { + case SWAPDIR_UFS: + storeUfsDirFree(s); + break; + default: + debug(0, 0) ("dump_cachedir doesn't know about type %d\n", + (int) s->type); + break; } xfree(s->path); filemapFreeMemory(s->map); @@ -936,9 +910,9 @@ parse_peer(peer ** head) if ((token = strtok(NULL, w_space)) == NULL) self_destruct(); p->type = parseNeighborType(token); - GetInteger(i); + i = GetInteger(); p->http_port = (u_short) i; - GetInteger(i); + i = GetInteger(); p->icp.port = (u_short) i; if (strcmp(p->host, me) == 0) { for (u = Config.Port.http; u; u = u->next) { @@ -1245,9 +1219,8 @@ dump_int(StoreEntry * entry, const char *name, int var) static void parse_int(int *var) { - char *token; int i; - GetInteger(i); + i = GetInteger(); *var = i; } @@ -1338,11 +1311,11 @@ parse_refreshpattern(refresh_t ** head) if (token == NULL) self_destruct(); pattern = xstrdup(token); - GetInteger(i); /* token: min */ + i = GetInteger(); /* token: min */ min = (time_t) (i * 60); /* convert minutes to seconds */ - GetInteger(i); /* token: pct */ + i = GetInteger(); /* token: pct */ pct = (double) i / 100.0; - GetInteger(i); /* token: max */ + i = GetInteger(); /* token: max */ max = (time_t) (i * 60); /* convert minutes to seconds */ /* Options */ while ((token = strtok(NULL, w_space)) != NULL) { @@ -1484,9 +1457,8 @@ dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) static void parse_size_t(size_t * var) { - char *token; int i; - GetInteger(i); + i = GetInteger(); *var = (size_t) i; } @@ -1528,10 +1500,9 @@ free_ushort(u_short * u) static void parse_ushort(u_short * var) { - char *token; int i; - GetInteger(i); + i = GetInteger(); if (i < 0) i = 0; *var = (u_short) i; diff --git a/src/enums.h b/src/enums.h index b16b64be86..4a0912ec79 100644 --- a/src/enums.h +++ b/src/enums.h @@ -1,6 +1,6 @@ /* - * $Id: enums.h,v 1.152 1999/05/19 19:57:42 wessels Exp $ + * $Id: enums.h,v 1.153 1999/05/22 07:42:03 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -625,3 +625,9 @@ enum { NETDB_EX_RTT, NETDB_EX_HOPS }; + +typedef enum { + SWAPDIR_UFS, + SWAPDIR_UFS_ASYNC, + SWAPDIR_MAX +} swapdir_t; diff --git a/src/globals.h b/src/globals.h index f6cdc182a9..570bd83b0c 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1,6 +1,6 @@ /* - * $Id: globals.h,v 1.80 1999/04/26 21:04:44 wessels Exp $ + * $Id: globals.h,v 1.81 1999/05/22 07:42:04 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -151,3 +151,4 @@ extern int refresh_nocache_hack; /* 0 */ #endif extern request_flags null_request_flags; extern int store_open_disk_fd; /* 0 */ +extern const char *SwapDirType[]; diff --git a/src/protos.h b/src/protos.h index e9c8ebed24..3840312f9b 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.329 1999/05/19 21:57:49 wessels Exp $ + * $Id: protos.h,v 1.330 1999/05/22 07:42:05 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -91,6 +91,9 @@ extern void aioCheckCallbacks(void); extern void aioSync(void); #endif +/* + * cache_cf.c + */ extern int parseConfigFile(const char *file_name); extern void intlistDestroy(intlist **); extern int intlistFind(intlist * list, int i); @@ -99,6 +102,10 @@ extern wordlist *wordlistDup(const wordlist *); extern void wordlistDestroy(wordlist **); extern void configFreeMemory(void); extern void wordlistCat(const wordlist *, MemBuf * mb); +extern void allocate_new_swapdir(cacheSwap *); +extern void self_destruct(void); +extern int GetInteger(void); + extern void cbdataInit(void); #if CBDATA_DEBUG @@ -849,11 +856,11 @@ extern int storeTooManyDiskFilesOpen(void); extern void storeEntryReset(StoreEntry *); /* store_io.c */ -extern storeIOState *storeOpen(sfileno f, mode_t mode, STIOCB * callback, void *callback_data); -extern void storeClose(storeIOState * sio); -extern void storeRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data); -extern void storeWrite(storeIOState * sio, char *buf, size_t size, off_t offset, FREE *); -extern void storeUnlink(int fileno); +extern STOPEN storeOpen; +extern STCLOSE storeClose; +extern STREAD storeRead; +extern STWRITE storeWrite; +extern STUNLINK storeUnlink; extern off_t storeOffset(storeIOState *); /* store_io_ufs.c */ @@ -944,6 +951,9 @@ extern void storeUfsDirCloseTmpSwapLog(int dirn); extern void storeUfsDirInit(void); extern void storeUfsDirOpenSwapLogs(void); extern void storeUfsDirSwapLog(const StoreEntry *, int op); +extern void storeUfsDirParse(cacheSwap * swap); +extern void storeUfsDirDump(StoreEntry * entry, const char *name, SwapDir * s); +extern void storeUfsDirFree(SwapDir *); /* diff --git a/src/store.cc b/src/store.cc index 7d10817f3f..0f0043bc82 100644 --- a/src/store.cc +++ b/src/store.cc @@ -1,6 +1,6 @@ /* - * $Id: store.cc,v 1.500 1999/05/22 02:31:18 wessels Exp $ + * $Id: store.cc,v 1.501 1999/05/22 07:42:07 wessels Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -135,11 +135,6 @@ destroy_MemObject(StoreEntry * e) assert(mem->swapout.sio == NULL); stmemFree(&mem->data_hdr); mem->inmem_hi = 0; - /* XXX account log_url */ -#if USE_ASYNC_IO - while (mem->clients != NULL) - storeUnregister(e, mem->clients->callback_data); -#endif /* * There is no way to abort FD-less clients, so they might * still have mem->clients set if mem->fd == -1 @@ -150,7 +145,7 @@ destroy_MemObject(StoreEntry * e) mem->request = NULL; ctx_exit(ctx); /* must exit before we free mem->url */ safe_free(mem->url); - safe_free(mem->log_url); + safe_free(mem->log_url); /* XXX account log_url */ memFree(mem, MEM_MEMOBJECT); } @@ -505,10 +500,6 @@ storeCheckCachable(StoreEntry * e) * out the object yet. */ return 1; -#if USE_ASYNC_IO - } else if (aio_overloaded()) { - debug(20, 2) ("storeCheckCachable: NO: Async-IO overloaded\n"); -#endif } else if (storeTooManyDiskFilesOpen()) { debug(20, 2) ("storeCheckCachable: NO: too many disk files open\n"); store_check_cachable_hist.no.too_many_open_files++; @@ -623,16 +614,7 @@ storeAbort(StoreEntry * e) InvokeHandlers(e); /* Do we need to close the swapout file? */ /* Not if we never started swapping out */ - /* But we may need to cancel an open/stat in progress if using ASYNC */ -#if USE_ASYNC_IO - aioCancel(-1, e); -#endif if (e->swap_file_number > -1) { -#if USE_ASYNC_IO - /* Need to cancel any pending ASYNC writes right now */ - if (mem->swapout.fd >= 0) - aioCancel(mem->swapout.fd, NULL); -#endif storeSwapOutFileClose(e); } storeUnlockObject(e); /* unlock */ @@ -771,12 +753,6 @@ storeRelease(StoreEntry * e) storeReleaseRequest(e); return; } -#if USE_ASYNC_IO - /* - * Make sure all forgotten async ops are cancelled - */ - aioCancel(-1, e); -#endif if (store_rebuilding) { storeSetPrivateKey(e); if (e->mem_obj) { diff --git a/src/store_client.cc b/src/store_client.cc index 2273ff6128..5f2a1a40ee 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -1,6 +1,6 @@ /* - * $Id: store_client.cc,v 1.70 1999/05/21 22:23:25 wessels Exp $ + * $Id: store_client.cc,v 1.71 1999/05/22 07:42:10 wessels Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -230,14 +230,6 @@ storeClientCopy2(StoreEntry * e, store_client * sc) */ if (storeClientNoMoreToSend(e, sc)) { /* There is no more to send! */ -#if USE_ASYNC_IO - if (sc->flags.disk_io_pending) { - if (sc->swapin_fd >= 0) - aioCancel(sc->swapin_fd, NULL); - else - aioCancel(-1, sc); - } -#endif sc->flags.disk_io_pending = 0; sc->callback = NULL; callback(sc->callback_data, sc->copy_buf, 0); @@ -248,14 +240,6 @@ storeClientCopy2(StoreEntry * e, store_client * sc) /* What the client wants is in memory */ debug(20, 3) ("storeClientCopy2: Copying from memory\n"); sz = stmemCopy(&mem->data_hdr, sc->copy_offset, sc->copy_buf, sc->copy_size); -#if USE_ASYNC_IO - if (sc->flags.disk_io_pending) { - if (sc->swapin_fd >= 0) - aioCancel(sc->swapin_fd, NULL); - else - aioCancel(-1, sc); - } -#endif sc->flags.disk_io_pending = 0; sc->callback = NULL; callback(sc->callback_data, sc->copy_buf, sz); @@ -439,10 +423,6 @@ storeUnregister(StoreEntry * e, void *data) storeClose(sc->swapin_sio); /* XXX this probably leaks file_read handler structures */ } -#if USE_ASYNC_IO - else - aioCancel(-1, sc); -#endif if ((callback = sc->callback) != NULL) { /* callback with ssize = -1 to indicate unexpected termination */ debug(20, 3) ("storeUnregister: store_client for %s has a callback\n", diff --git a/src/store_dir.cc b/src/store_dir.cc index 3923dd68c9..a436b21ad7 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir.cc,v 1.91 1999/05/04 19:22:29 wessels Exp $ + * $Id: store_dir.cc,v 1.92 1999/05/22 07:42:11 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -35,6 +35,12 @@ #include "squid.h" +const char *SwapDirType[] = +{ + "ufs", + "!ERROR!" +}; + void storeDirInit(void) { diff --git a/src/store_io.cc b/src/store_io.cc index f1a3a1dad6..7a4720c5ed 100644 --- a/src/store_io.cc +++ b/src/store_io.cc @@ -5,34 +5,39 @@ storeIOState * storeOpen(sfileno f, mode_t mode, STIOCB * callback, void *callback_data) { + SwapDir *SD = &Config.cacheSwap.swapDirs[f >> SWAP_DIR_SHIFT]; assert(mode == O_RDONLY || mode == O_WRONLY); - return storeUfsOpen(f, mode, callback, callback_data); + return SD->open(f, mode, callback, callback_data); } void storeClose(storeIOState * sio) { + SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_file_number >> SWAP_DIR_SHIFT]; assert(!sio->flags.closing); sio->flags.closing = 1; - storeUfsClose(sio); + SD->close(sio); } void storeRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { - storeUfsRead(sio, buf, size, offset, callback, callback_data); + SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_file_number >> SWAP_DIR_SHIFT]; + SD->read(sio, buf, size, offset, callback, callback_data); } void storeWrite(storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) { - storeUfsWrite(sio, buf, size, offset, free_func); + SwapDir *SD = &Config.cacheSwap.swapDirs[sio->swap_file_number >> SWAP_DIR_SHIFT]; + SD->write(sio, buf, size, offset, free_func); } void storeUnlink(sfileno f) { - storeUfsUnlink(f); + SwapDir *SD = &Config.cacheSwap.swapDirs[f >> SWAP_DIR_SHIFT]; + SD->unlink(f); } off_t diff --git a/src/store_rebuild.cc b/src/store_rebuild.cc index 9ae20273fc..d23ed5ab60 100644 --- a/src/store_rebuild.cc +++ b/src/store_rebuild.cc @@ -1,6 +1,6 @@ /* - * $Id: store_rebuild.cc,v 1.60 1999/05/04 21:58:43 wessels Exp $ + * $Id: store_rebuild.cc,v 1.61 1999/05/22 07:42:14 wessels Exp $ * * DEBUG: section 20 Store Rebuild Routines * AUTHOR: Duane Wessels @@ -527,10 +527,10 @@ storeGetNextFile(rebuild_dir * d, int *sfileno, int *size) store_open_disk_fd++; } d->in_dir = 0; - if (++d->curlvl2 < Config.cacheSwap.swapDirs[d->dirn].l2) + if (++d->curlvl2 < Config.cacheSwap.swapDirs[d->dirn].u.ufs.l2) continue; d->curlvl2 = 0; - if (++d->curlvl1 < Config.cacheSwap.swapDirs[d->dirn].l1) + if (++d->curlvl1 < Config.cacheSwap.swapDirs[d->dirn].u.ufs.l1) continue; d->curlvl1 = 0; d->done = 1; diff --git a/src/store_swapout.cc b/src/store_swapout.cc index 94c3d70a2e..c044458d89 100644 --- a/src/store_swapout.cc +++ b/src/store_swapout.cc @@ -1,6 +1,6 @@ /* - * $Id: store_swapout.cc,v 1.50 1999/05/22 02:31:20 wessels Exp $ + * $Id: store_swapout.cc,v 1.51 1999/05/22 07:42:15 wessels Exp $ * * DEBUG: section 20 Storage Manager Swapout Functions * AUTHOR: Duane Wessels @@ -99,16 +99,7 @@ storeSwapOut(StoreEntry * e) if (mem->swapout.sio) debug(20, 7) ("storeSwapOut: storeOffset() = %d\n", (int) storeOffset(mem->swapout.sio)); -#if USE_ASYNC_IO - if (mem->inmem_hi < mem->swapout.queue_offset) { - storeAbort(e); - assert(EBIT_TEST(e->flags, RELEASE_REQUEST)); - storeSwapOutFileClose(e); - return; - } -#else assert(mem->inmem_hi >= mem->swapout.queue_offset); -#endif lowest_offset = storeLowestMemReaderOffset(e); debug(20, 7) ("storeSwapOut: lowest_offset = %d\n", (int) lowest_offset); diff --git a/src/structs.h b/src/structs.h index 1a7f4053ca..fdb6474667 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.290 1999/05/19 21:57:52 wessels Exp $ + * $Id: structs.h,v 1.291 1999/05/22 07:42:16 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1260,18 +1260,28 @@ struct _StoreEntry { }; struct _SwapDir { - char *path; - int l1; - int l2; + swapdir_t type; + fileMap *map; int cur_size; int max_size; + char *path; int suggest; - fileMap *map; - int swaplog_fd; struct { unsigned int selected:1; unsigned int read_only:1; } flags; + STOPEN *open; + STCLOSE *close; + STREAD *read; + STWRITE *write; + STUNLINK *unlink; + union { + struct { + int l1; + int l2; + int swaplog_fd; + } ufs; + } u; }; struct _request_flags { diff --git a/src/typedefs.h b/src/typedefs.h index f62a355620..06534f440d 100644 --- a/src/typedefs.h +++ b/src/typedefs.h @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.90 1999/05/19 22:36:45 wessels Exp $ + * $Id: typedefs.h,v 1.91 1999/05/22 07:42:17 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -211,6 +211,12 @@ typedef void HLPCB(void *, char *buf); typedef void HLPCMDOPTS(int *argc, char **argv); typedef void IDNSCB(void *, rfc1035_rr *, int); +typedef storeIOState *STOPEN(sfileno, mode_t, STIOCB *, void *); +typedef void STCLOSE(storeIOState *); +typedef void STREAD(storeIOState *, char *, size_t, off_t, STRCB *, void *); +typedef void STWRITE(storeIOState *, char *, size_t, off_t, FREE *); +typedef void STUNLINK(sfileno); + typedef double hbase_f(double); typedef void StatHistBinDumper(StoreEntry *, int idx, double val, double size, int count);