--------------------- PatchSet 2037 Date: 2001/04/22 08:57:45 Author: darius Branch: sfs Tag: (none) Log: More code, for the trivial bits - close and unlink. Read and write next, then smoothing all the data structures out. Members: src/fs/ufs/fs_ufs.c:1.1.2.1->1.1.2.2 src/fs/ufs/store_io_ufs.c:1.5.4.1->1.5.4.2 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.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/fs/ufs/fs_ufs.c 14 Apr 2001 09:46:36 -0000 1.1.2.1 +++ squid/src/fs/ufs/fs_ufs.c 22 Apr 2001 08:57:45 -0000 1.1.2.2 @@ -18,6 +18,14 @@ } cbdataUnlock(their_data); } + if (requestp->fd > 0) { + io_close(io_buildCloseRequest(requestp->fd)); + /* + close(requestp->fd); + fd_close(requestp->fd); + requestp->fd = -1; + */ + } } /* buildOpenRequest is called by ufs_storeCreate and ufs_storeOpen - it @@ -37,7 +45,7 @@ return (void *)requestp; } -/* ufsOpen actions an open request, from ufs_storeOpen and ufs_storeCreate */ +/* io_open actions an open request, from ufs_storeOpen and ufs_storeCreate */ void io_open(aio_request_t *requestp) { @@ -66,12 +74,40 @@ sio->e); } else { /* Here, I believe we need to make sure the file size is filled - * in in the sio */ + * in in the sio. Old ufs code did an fstat. */ } } io_cleanupRequest(requestp); } +void * +io_buildCloseRequest(int fd) +{ + aio_request_t *requestp; + + requestp = memPoolAlloc(aio_request_pool); + requestp->fd = fd; + requestp->request_type = _AIO_OP_CLOSE; + requestp->cancelled = 0; + return (void *)requestp; +} + +/* io_close actions a close request */ +void +io_close(aio_request_t *requestp) +{ + ufs_do_close(requestp); + io_closeDone(requestp); +} + +/* This is mainly here to maintain symmetry. */ +void +io_closeDone(aio_request_t *requestp) +{ + fd_close(requestp->fd); + io_cleanupRequest(requestp); +} + /* cleanupRequest de-allocates the various structures once we're completely * done with the request. Also copies any data accumulated back into * squid's purview. Note, there's some copying of data going on in here that @@ -120,3 +156,11 @@ } memPoolFree(aio_request_pool, requestp); } + +static int +ufsSomethingPending(storeIOState * sio) +{ + aiostate_t *aiostate = (aiostate_t *) sio->fsstate; + return (aiostate->flags.reading || aiostate->flags.writing || + aiostate->flags.opening || aiostate->flags.inreaddone); +} 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.1 retrieving revision 1.5.4.2 diff -u -r1.5.4.1 -r1.5.4.2 --- squid/src/fs/ufs/store_io_ufs.c 14 Apr 2001 09:46:37 -0000 1.5.4.1 +++ squid/src/fs/ufs/store_io_ufs.c 22 Apr 2001 08:57:45 -0000 1.5.4.2 @@ -59,6 +59,7 @@ { int flags = (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); int filen = fsNewFileNum(SD); + return _storeUfsOpen(SD,e,file_callback,callback,callback_data,flags,filen); } @@ -71,3 +72,116 @@ return _storeUfsOpen(SD,e,file_callback,callback,callback_data,flags,filen); } + +void +storeUfsClose(SwapDir * SD, storeIOState * sio) +{ + fsstate_t *fsstate = (fsstate_t *) sio->fsstate; + + debug(79, 3) ("storeUfsClose: dirno %d, fileno %08X, FD %d\n", + sio->swap_dirn, sio->swap_filen, fsstate->fd); + if (ufsSomethingPending(sio)) { + /* The IO callback routines will close a file if close_request is set + * - this is kinda useful here. */ + fsstate->flags.close_request = 1; + return; + } + requestp = fsinfo->buildCloseRequest(fsstate->fd); + fsinfo->submitClose(requestp); +} + +/* Unlink */ +void +storeUfsUnlink(SwapDir * SD, StoreEntry * e) +{ + debug(78, 3) ("storeUfsUnlink: dirno %d, fileno %08X\n", SD->index, + e->swap_filen); + storeufsDirReplRemove(e); + storeufsDirMapBitReset(SD, e->swap_filen); + 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) +{ + aiostate_t *aiostate = (aiostate_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; + } + sio->read.callback = callback; + sio->read.callback_data = callback_data; + aiostate->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 +} + +void +storeAufsWrite(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", + sio->swap_dirn, sio->swap_filen, aiostate->fd); + if (aiostate->fd < 0) { + /* disk file not opened yet */ + struct _queued_write *q; + assert(aiostate->flags.opening); + q = memPoolAlloc(aio_qwrite_pool); + q->buf = buf; + q->size = size; + q->offset = offset; + q->free_func = free_func; + linklistPush(&(aiostate->pending_writes), q); + return; + } +#if ASYNC_WRITE + if (aiostate->flags.writing) { + struct _queued_write *q; + debug(78, 3) ("storeAufsWrite: queuing write\n"); + q = memPoolAlloc(aio_qwrite_pool); + q->buf = buf; + q->size = size; + q->offset = offset; + q->free_func = free_func; + linklistPush(&(aiostate->pending_writes), q); + return; + } + aiostate->flags.writing = 1; + /* + * XXX it might be nice if aioWrite() gave is immediate + * feedback here about EWOULDBLOCK instead of in the + * callback function + * XXX Should never give EWOULDBLOCK under normal operations + * if it does then the MAGIC1/2 tuning is wrong. + */ + aioWrite(aiostate->fd, offset, buf, size, storeAufsWriteDone, sio, + free_func); +#else + file_write(aiostate->fd, offset, buf, size, storeAufsWriteDone, sio, + free_func); +#endif +}