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.
/*
- * $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
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);
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",
* 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)
if (sscanf(token, "%d", &i) != 1)
self_destruct();
ptr->restore_bps = i;
- GetInteger(i);
+ i = GetInteger();
ptr->max_bytes = i;
ptr++;
}
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;
+ }
}
}
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
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);
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) {
static void
parse_int(int *var)
{
- char *token;
int i;
- GetInteger(i);
+ i = GetInteger();
*var = i;
}
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) {
static void
parse_size_t(size_t * var)
{
- char *token;
int i;
- GetInteger(i);
+ i = GetInteger();
*var = (size_t) i;
}
static void
parse_ushort(u_short * var)
{
- char *token;
int i;
- GetInteger(i);
+ i = GetInteger();
if (i < 0)
i = 0;
*var = (u_short) i;
/*
- * $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/
NETDB_EX_RTT,
NETDB_EX_HOPS
};
+
+typedef enum {
+ SWAPDIR_UFS,
+ SWAPDIR_UFS_ASYNC,
+ SWAPDIR_MAX
+} swapdir_t;
/*
- * $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/
#endif
extern request_flags null_request_flags;
extern int store_open_disk_fd; /* 0 */
+extern const char *SwapDirType[];
/*
- * $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/
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);
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
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 */
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 *);
/*
/*
- * $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
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
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);
}
* 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++;
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 */
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) {
/*
- * $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
*/
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);
/* 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);
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",
/*
- * $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
#include "squid.h"
+const char *SwapDirType[] =
+{
+ "ufs",
+ "!ERROR!"
+};
+
void
storeDirInit(void)
{
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
/*
- * $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
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;
/*
- * $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
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);
/*
- * $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/
};
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 {
/*
- * $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/
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);