--------------------- PatchSet 2146 Date: 2001/04/29 10:50:11 Author: darius Branch: sfs Tag: (none) Log: Batch of changes - starting to convert the structures across, and look more closely at read ops. aufs code is lagging behind ufs code, but that's ok for now. Members: src/fs/ufs/fs_aufs.c:1.1.2.1->1.1.2.2 src/fs/ufs/fs_structs.h:1.1.2.1->1.1.2.2 src/fs/ufs/fs_ufs.c:1.1.2.2->1.1.2.3 src/fs/ufs/store_io_ufs.c:1.5.4.2->1.5.4.3 Index: squid/src/fs/ufs/fs_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/Attic/fs_aufs.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/ufs/fs_aufs.c 14 Apr 2001 09:46:36 -0000 1.1.2.1 +++ squid/src/fs/ufs/fs_aufs.c 29 Apr 2001 10:50:11 -0000 1.1.2.2 @@ -4,8 +4,8 @@ aio_buildOpenRequest(char *path, int flags, int mode, STIOCB * callback, void *callback_data) { - aio_request_t *requestp; - aio_ctrl_t *ctrlp; + ufs_request_t *requestp; + ufs_ctrl_t *ctrlp; if (!aio_initialised) aio_init(); @@ -51,3 +51,34 @@ } ufs_cleanupRequest(requestp); } + +ufs_request_t * +aio_buildReadRequest() +{ +} + +void +aio_read(ufs_request_t *requestp) +{ + /* This code stolen from the store_io_aufs.c code. Note, this changes + * the timing of this snippet slightly, but hopefully not enough to + * count. Still got to think through the whole "pending requests" + * thing *frown* + * Obviously, this is just a placeholder snippet, not functional code. */ + if (fsstate->fd < 0) { + struct _queued_read *q; + debug(78, 3) ("storeUfsRead: queueing read because FD < 0\n"); + assert(fsstate->flags.opening); + assert(fsstate->pending_reads == NULL); + assert(fsstate->async); + q = memPoolAlloc(ufs_qread_pool); + q->buf = buf; + q->size = size; + q->offset = offset; + q->callback = callback; + q->callback_data = callback_data; + linklistPush(&(fsstate->pending_reads), q); + return; + } + +} Index: squid/src/fs/ufs/fs_structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/Attic/fs_structs.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/ufs/fs_structs.h 14 Apr 2001 09:46:36 -0000 1.1.2.1 +++ squid/src/fs/ufs/fs_structs.h 29 Apr 2001 10:50:11 -0000 1.1.2.2 @@ -1,3 +1,5 @@ +/* Request Types - fairly self explanatory, these are set in the request_t + * "objects". */ enum _ufs_request_type { _OP_NONE = 0, _OP_OPEN, @@ -11,7 +13,9 @@ _OP_STAT }; -typedef struct ufs_request_t { +/* ufs_request_t is the structure that defines a request "object". One of + * these is created for every request squid makes of the fs. */ +struct _ufs_request_t { struct ufs_request_t *next; enum _ufs_request_type request_type; int cancelled; @@ -29,4 +33,73 @@ struct stat *tmpstatp; struct stat *statp; storeIOState *sio; -} aio_request_t; +}; + +/* _ufs_fsinfo_t defines the fs-specific information hanging off the SwapDir + * structure (called "fsdata"). */ +struct _ufs_fsinfo_t { + int swaplog_fd; + int l1; + int l2; + fileMap *map; + int suggest; + int async; +}; + +/* _ufs_state_t records the state of any particular request. It resides in + * ithe StoreIOState structure, called fsstate. */ +struct _ufs_state_t { + int fd; + struct { + unsigned int close_request:1; + unsigned int reading:1; + unsigned int writing:1; + unsigned int opening:1; + unsigned int write_kicking:1; + unsigned int read_kicking:1; + unsigned int inreaddone:1; + } flags; + const char *read_buf; + link_list *pending_writes; + link_list *pending_reads; +}; + +typedef struct _ufs_request_type ufs_request_type; +typedef struct _ufs_request_t ufs_request_t; +typedef struct _ufs_fsinfo_t ufs_fsinfo_t; +typedef struct _ufs_state_t ufs_state_t; + +/* The ufs_state memory pools. These are/were mostly used by aufs, but + * that may change slightly with the new layout, not sure yet. */ +extern MemPool *ufs_state_pool; +extern MemPool *ufs_qread_pool; +extern MemPool *ufs_qwrite_pool; + +/* + * Notes on the various data structures used within ufs: + * + * Incoming requests usually carry a SwapDir pointer, pointing at the swap + * directory we're using, and either a StoreEntry pointer (for open/close/ + * unlink), or a storeIOState pointer (for read and write). They will generate + * ufs_request_t structures, which are then passed into the "submitRequest" + * style functions. From there, things diverge slightly - at the moment, + * aufs also creates a "ctrlp" structure, which is used to hold the real + * callback, while the aufs-specific callback is stored in the request. This + * should change before the code is useable, I suspect. + * + * I'm trying to set a standard naming convention within ufs itself - in + * most cases, you'll see functions called "io_*", which are the vanilla + * non-async versions, and "aio_*", which are the async versions. I'm not + * sure that's appropriate atm, especially in light of the existence of + * the aio libaries/functions in glibc, but we'll see. + * + * Structures defined in here usually have an "_ufs_" prefix, to indicate + * they belong to the ufs file system. Note, however, elsewhere they're not + * referred to with the _ufs_* prefix, but as their base name - I need to + * make static definitions in each file for the data structures needed, just + * because it looks cleaner. C not being my prime language, I'm still a touch + * shaky on this. + * + * ufs_request_pool exists, and is a memory pool for ufs_request_t structures. + * This needs to be setup as a global thing, not a per-fs thing. + * */ Index: squid/src/fs/ufs/fs_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/Attic/fs_ufs.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/fs/ufs/fs_ufs.c 22 Apr 2001 08:57:45 -0000 1.1.2.2 +++ squid/src/fs/ufs/fs_ufs.c 29 Apr 2001 10:50:11 -0000 1.1.2.3 @@ -4,7 +4,7 @@ /* doCallback handles executing any given callback - short, simple, and used * in lots of places */ void -io_doCallback(aio_request_t *requestp) +io_doCallback(ufs_request_t *requestp) { STIOCB *done_handler; void *their_data; @@ -34,27 +34,27 @@ io_buildOpenRequest(char *path, int flags, int mode, STIOCB *callback, void *callback_data) { - aio_request_t *requestp; + ufs_request_t *requestp; - requestp = memPoolAlloc(aio_request_pool); - requestp->path = (char *) aio_xstrdup(path); + requestp = memPoolAlloc(ufs_request_pool); + requestp->path = (char *) xstrdup(path); requestp->oflag = flags; requestp->mode = mode; - requestp->request_type = _AIO_OP_OPEN; + requestp->request_type = _OP_OPEN; requestp->cancelled = 0; return (void *)requestp; } /* io_open actions an open request, from ufs_storeOpen and ufs_storeCreate */ void -io_open(aio_request_t *requestp) +io_open(ufs_request_t *requestp) { ufs_do_open(requestp); io_openDone(requestp); } void -io_openDone(aio_request_t *requestp) +io_openDone(ufs_request_t *requestp) { storeIOState *sio = (storeIOState *)requestp->sio; aiostate_t *aiostate = (aiostate_t *) sio->fsstate; @@ -83,9 +83,9 @@ void * io_buildCloseRequest(int fd) { - aio_request_t *requestp; + ufs_request_t *requestp; - requestp = memPoolAlloc(aio_request_pool); + requestp = memPoolAlloc(ufs_request_pool); requestp->fd = fd; requestp->request_type = _AIO_OP_CLOSE; requestp->cancelled = 0; @@ -94,7 +94,7 @@ /* io_close actions a close request */ void -io_close(aio_request_t *requestp) +io_close(ufs_request_t *requestp) { ufs_do_close(requestp); io_closeDone(requestp); @@ -102,7 +102,7 @@ /* This is mainly here to maintain symmetry. */ void -io_closeDone(aio_request_t *requestp) +io_closeDone(ufs_request_t *requestp) { fd_close(requestp->fd); io_cleanupRequest(requestp); @@ -114,7 +114,7 @@ * should not be - we _should_ be reading data straight into squid's own * buffers, not into our own temporary buffers. */ void -io_cleanupRequest(aio_request_t *requestp) +io_cleanupRequest(ufs_request_t *requestp) { int cancelled = requestp->cancelled; @@ -124,14 +124,14 @@ case _AIO_OP_STAT: if (!cancelled && requestp->ret == 0) xmemcpy(requestp->statp, requestp->tmpstatp, sizeof(struct stat)); - aio_xfree(requestp->tmpstatp, sizeof(struct stat)); - aio_xstrfree(requestp->path); + xfree(requestp->tmpstatp, sizeof(struct stat)); + xstrfree(requestp->path); break; case _AIO_OP_OPEN: if (cancelled && requestp->ret >= 0) /* The open() was cancelled but completed */ close(requestp->ret); - aio_xstrfree(requestp->path); + xstrfree(requestp->path); break; case _AIO_OP_CLOSE: if (cancelled && requestp->ret < 0) @@ -141,20 +141,20 @@ case _AIO_OP_UNLINK: case _AIO_OP_TRUNCATE: case _AIO_OP_OPENDIR: - aio_xstrfree(requestp->path); + xstrfree(requestp->path); break; case _AIO_OP_READ: if (!cancelled && requestp->ret > 0) xmemcpy(requestp->bufferp, requestp->tmpbufp, requestp->ret); - aio_xfree(requestp->tmpbufp, requestp->buflen); + xfree(requestp->tmpbufp, requestp->buflen); break; case _AIO_OP_WRITE: - aio_xfree(requestp->tmpbufp, requestp->buflen); + xfree(requestp->tmpbufp, requestp->buflen); break; default: break; } - memPoolFree(aio_request_pool, requestp); + memPoolFree(ufs_request_pool, requestp); } static int Index: squid/src/fs/ufs/store_io_ufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/ufs/store_io_ufs.c,v retrieving revision 1.5.4.2 retrieving revision 1.5.4.3 diff -u -r1.5.4.2 -r1.5.4.3 --- squid/src/fs/ufs/store_io_ufs.c 22 Apr 2001 08:57:45 -0000 1.5.4.2 +++ squid/src/fs/ufs/store_io_ufs.c 29 Apr 2001 10:50:11 -0000 1.5.4.3 @@ -77,6 +77,7 @@ storeUfsClose(SwapDir * SD, storeIOState * sio) { fsstate_t *fsstate = (fsstate_t *) sio->fsstate; + void *requestp; debug(79, 3) ("storeUfsClose: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, fsstate->fd); @@ -90,7 +91,8 @@ fsinfo->submitClose(requestp); } -/* Unlink */ +/* Not done past here - Darius */ + void storeUfsUnlink(SwapDir * SD, StoreEntry * e) { @@ -101,47 +103,31 @@ storeufsDirUnlinkFile(SD, e->swap_filen); } -/* Not done past here - Darius */ - -/* Read */ void -storeAufsRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) +storeUfsRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, + off_t offset, STRCB * callback, void *callback_data) { - aiostate_t *aiostate = (aiostate_t *) sio->fsstate; + /* This stuff needs a lot of sorting out, it's here that the + * two-level callback thing starts to bite */ + fsstate_t *fsstate = (fsstate_t *) sio->fsstate; assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); - assert(!aiostate->flags.reading); - if (aiostate->fd < 0) { - struct _queued_read *q; - debug(78, 3) ("storeAufsRead: queueing read because FD < 0\n"); - assert(aiostate->flags.opening); - assert(aiostate->pending_reads == NULL); - q = memPoolAlloc(aio_qread_pool); - q->buf = buf; - q->size = size; - q->offset = offset; - q->callback = callback; - q->callback_data = callback_data; - linklistPush(&(aiostate->pending_reads), q); - return; - } + assert(!fsstate->flags.reading); sio->read.callback = callback; sio->read.callback_data = callback_data; - aiostate->read_buf = buf; + fsstate->read_buf = buf; cbdataLock(callback_data); debug(78, 3) ("storeAufsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); sio->offset = offset; - aiostate->flags.reading = 1; -#if ASYNC_READ - aioRead(aiostate->fd, offset, buf, size, storeAufsReadDone, sio); -#else - file_read(aiostate->fd, offset, buf, size, storeAufsReadDone, sio); -#endif + fsstate->flags.reading = 1; + requestp = fsinfo->buildReadRequest(fsstate->fd,offset,buf,size); + fsinfo->submitRead(requestp); } void -storeAufsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) +storeUfsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, + off_t offset, FREE * free_func) { aiostate_t *aiostate = (aiostate_t *) sio->fsstate; debug(78, 3) ("storeAufsWrite: dirno %d, fileno %08X, FD %d\n",