--------------------- PatchSet 285 Date: 2002/12/08 03:28:14 Author: rbcollins Branch: unify-io Tag: (none) Log: more work towards close() Members: src/ufscommon.h:1.1.20.11->1.1.20.12 src/fs/aufs/store_asyncufs.h:1.2.12.12->1.2.12.13 src/fs/aufs/store_io_aufs.cc:1.3.12.15->1.3.12.16 src/fs/diskd/store_diskd.h:1.1.20.20->1.1.20.21 src/fs/diskd/store_io_diskd.cc:1.1.20.26->1.1.20.27 src/fs/ufs/store_io_ufs.cc:1.3.10.20->1.3.10.21 src/fs/ufs/store_ufs.h:1.1.20.13->1.1.20.14 Index: squid3/src/ufscommon.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.h,v retrieving revision 1.1.20.11 retrieving revision 1.1.20.12 diff -u -r1.1.20.11 -r1.1.20.12 --- squid3/src/ufscommon.h 7 Dec 2002 02:41:38 -0000 1.1.20.11 +++ squid3/src/ufscommon.h 8 Dec 2002 03:28:14 -0000 1.1.20.12 @@ -1,6 +1,6 @@ /* - * $Id: ufscommon.h,v 1.1.20.11 2002/12/07 02:41:38 rbcollins Exp $ + * $Id: ufscommon.h,v 1.1.20.12 2002/12/08 03:28:14 rbcollins Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -87,6 +87,7 @@ public: typedef RefCount Pointer; virtual void ioCompletedNotification() = 0; + virtual void closeCompleted() = 0; }; class DiskFile : public RefCountable { Index: squid3/src/fs/aufs/store_asyncufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_asyncufs.h,v retrieving revision 1.2.12.12 retrieving revision 1.2.12.13 diff -u -r1.2.12.12 -r1.2.12.13 --- squid3/src/fs/aufs/store_asyncufs.h 7 Dec 2002 02:41:39 -0000 1.2.12.12 +++ squid3/src/fs/aufs/store_asyncufs.h 8 Dec 2002 03:28:14 -0000 1.2.12.13 @@ -92,6 +92,7 @@ ~AUFSFile(); virtual void open (int, mode_t, IORequestor::Pointer); virtual void create (int, mode_t, IORequestor::Pointer); + void close(); virtual bool error() const; virtual int getFD() const { return fd;} private: @@ -103,6 +104,7 @@ void openDone(int fd, const char *buf, int aio_return, int aio_errno); IORequestor::Pointer ioRequestor; CBDATA_CLASS(AUFSFile); + void doClose(); }; class squidaiostate_t : public UFSStoreState { @@ -125,6 +127,7 @@ link_list *pending_writes; link_list *pending_reads; void ioCompletedNotification(); + void closeCompleted(); private: CBDATA_CLASS(squidaiostate_t); void openDone(); Index: squid3/src/fs/aufs/store_io_aufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_io_aufs.cc,v retrieving revision 1.3.12.15 retrieving revision 1.3.12.16 diff -u -r1.3.12.15 -r1.3.12.16 --- squid3/src/fs/aufs/store_io_aufs.cc 7 Dec 2002 02:41:39 -0000 1.3.12.15 +++ squid3/src/fs/aufs/store_io_aufs.cc 8 Dec 2002 03:28:14 -0000 1.3.12.16 @@ -125,6 +125,7 @@ AUFSFile::~AUFSFile() { safe_free (path_); + doClose(); } void @@ -205,6 +206,15 @@ t->ioCompletedNotification(); } +void AUFSFile::doClose() +{ + if (fd > -1) { + aioClose(fd); + fd_close(fd); + store_open_disk_fd--; + fd = -1; + } +} /* open for reading */ StoreIOState::Pointer @@ -479,9 +489,7 @@ if (fd < 0) return; debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); - aioClose(fd); - fd_close(fd); - store_open_disk_fd--; + aiostate->theFile = NULL; debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); } @@ -540,6 +548,12 @@ assert (0); } +void +squidaiostate_t::closeCompleted() +{ + assert (0); +} + void squidaiostate_t::openDone() { Index: squid3/src/fs/diskd/store_diskd.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_diskd.h,v retrieving revision 1.1.20.20 retrieving revision 1.1.20.21 diff -u -r1.1.20.20 -r1.1.20.21 --- squid3/src/fs/diskd/store_diskd.h 7 Dec 2002 13:44:52 -0000 1.1.20.20 +++ squid3/src/fs/diskd/store_diskd.h 8 Dec 2002 03:28:14 -0000 1.1.20.21 @@ -47,6 +47,7 @@ void closeDone (diomsg *); int mode; void notifyClient(); + bool canNotifyClient() const; }; class SharedMemory{ @@ -81,6 +82,7 @@ } flags; char *read_buf; void ioCompletedNotification(); + void closeCompleted(); private: CBDATA_CLASS(diskdstate_t); }; Index: squid3/src/fs/diskd/store_io_diskd.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_io_diskd.cc,v retrieving revision 1.1.20.26 retrieving revision 1.1.20.27 diff -u -r1.1.20.26 -r1.1.20.27 --- squid3/src/fs/diskd/store_io_diskd.cc 7 Dec 2002 13:44:52 -0000 1.1.20.26 +++ squid3/src/fs/diskd/store_io_diskd.cc 8 Dec 2002 03:28:14 -0000 1.1.20.27 @@ -1,6 +1,6 @@ /* - * $Id: store_io_diskd.cc,v 1.1.20.26 2002/12/07 13:44:52 rbcollins Exp $ + * $Id: store_io_diskd.cc,v 1.1.20.27 2002/12/08 03:28:14 rbcollins Exp $ * * DEBUG: section 79 Squid-side DISKD I/O functions. * AUTHOR: Duane Wessels @@ -284,11 +284,20 @@ return errorOccured; } +bool +DiskdFile::canNotifyClient() const +{ + if (!ioRequestor.getRaw()) { + debug (79,3)("DiskdFile::canNotifyClient: No ioRequestor to notify\n"); + return false; + } + return true; +} + void DiskdFile::notifyClient() { - if (!ioRequestor.getRaw()) { - debug (79,3)("DiskdFile::notifyClient: No ioRequestor to notify\n"); + if (!canNotifyClient()) { return; } ioRequestor->ioCompletedNotification(); @@ -417,19 +426,22 @@ } return; } - if (closing) { - closing = false; - debug(79, 3) ("storeDiskdCloseDone: dirno %d, fileno %08x status %d\n", - swap_dirn, swap_filen, theFile->error()); - if (theFile->error()) { - storeDiskdIOCallback(this, DISK_ERROR); - } else { - storeDiskdIOCallback(this, DISK_OK); - } - return; - } + assert (!closing); assert (0); } + +void +diskdstate_t::closeCompleted() +{ + assert (closing); + debug(79, 3) ("storeDiskdCloseDone: dirno %d, fileno %08x status %d\n", + swap_dirn, swap_filen, theFile->error()); + if (theFile->error()) { + storeDiskdIOCallback(this, DISK_ERROR); + } else { + storeDiskdIOCallback(this, DISK_OK); + } +} void storeDiskdClose(SwapDir * SD, storeIOState * sio) @@ -556,7 +568,8 @@ } else { diskd_stats.close.success++; } - notifyClient(); + if (canNotifyClient()) + ioRequestor->closeCompleted(); ioRequestor = NULL; } Index: squid3/src/fs/ufs/store_io_ufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/store_io_ufs.cc,v retrieving revision 1.3.10.20 retrieving revision 1.3.10.21 diff -u -r1.3.10.20 -r1.3.10.21 --- squid3/src/fs/ufs/store_io_ufs.cc 7 Dec 2002 02:41:39 -0000 1.3.10.20 +++ squid3/src/fs/ufs/store_io_ufs.cc 8 Dec 2002 03:28:14 -0000 1.3.10.21 @@ -1,6 +1,6 @@ /* - * $Id: store_io_ufs.cc,v 1.3.10.20 2002/12/07 02:41:39 rbcollins Exp $ + * $Id: store_io_ufs.cc,v 1.3.10.21 2002/12/08 03:28:14 rbcollins Exp $ * * DEBUG: section 79 Storage Manager UFS Interface * AUTHOR: Duane Wessels @@ -117,6 +117,7 @@ UFSFile::~UFSFile() { safe_free (path_); + doClose(); } void @@ -124,6 +125,7 @@ { /* Simulate async calls */ fd = file_open(path_ , flags); + ioRequestor = callback; if (fd < 0) { debug(79, 3) ("UFSFile::open: got failure (%d)\n", errno); } else { @@ -140,6 +142,25 @@ open(flags, mode, callback); } + +void UFSFile::doClose() +{ + if (fd > -1) { + file_close(fd); + store_open_disk_fd--; + fd = -1; + } +} + +void +UFSFile::close () +{ + debug (79,0)("UFSFile::close: %p closing for %p\n", this, ioRequestor.getRaw()); + doClose(); + assert (ioRequestor.getRaw()); + ioRequestor->closeCompleted(); +} + bool UFSFile::error() const { @@ -172,6 +193,12 @@ assert(0); } +void +ufsstate_t::closeCompleted() +{ + storeUfsIOCallback(this, theFile->error() ? 0 : -1); +} + StoreIOState::Pointer commonUFSOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) @@ -196,11 +223,10 @@ debug(79, 3) ("storeUfsClose: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, ufsstate->fd); + ufsstate->closing = true; if (ufsstate->flags.reading || ufsstate->flags.writing) { - ufsstate->closing = true; - return; + ((UFSFile *)ufsstate->theFile.getRaw())->close(); } - storeUfsIOCallback(sio, 0); } void @@ -292,7 +318,7 @@ } sio->offset_ += len; if (ufsstate->closing) - storeUfsIOCallback(sio, errflag); + ((UFSFile *)ufsstate->theFile.getRaw())->close(); } static void @@ -301,10 +327,8 @@ ufsstate_t *ufsstate = dynamic_cast(sio); void *cbdata; debug(79, 3) ("storeUfsIOCallback: errflag=%d\n", errflag); - if (ufsstate->fd > -1) { - file_close(ufsstate->fd); - store_open_disk_fd--; - } + /* We are finished with the file */ + ufsstate->theFile = NULL; if (cbdataReferenceValidDone(sio->callback_data, &cbdata)) sio->callback(cbdata, errflag, sio); sio->callback = NULL; Index: squid3/src/fs/ufs/store_ufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/Attic/store_ufs.h,v retrieving revision 1.1.20.13 retrieving revision 1.1.20.14 diff -u -r1.1.20.13 -r1.1.20.14 --- squid3/src/fs/ufs/store_ufs.h 7 Dec 2002 02:41:39 -0000 1.1.20.13 +++ squid3/src/fs/ufs/store_ufs.h 8 Dec 2002 03:28:14 -0000 1.1.20.14 @@ -15,11 +15,14 @@ ~UFSFile(); virtual void open (int, mode_t, IORequestor::Pointer); virtual void create (int, mode_t, IORequestor::Pointer); + virtual void close (); virtual bool error() const; virtual int getFD() const { return fd;} private: int fd; char const *path_; + IORequestor::Pointer ioRequestor; + void doClose(); }; class ufsstate_t : public UFSStoreState { @@ -35,6 +38,7 @@ unsigned int writing:1; } flags; void ioCompletedNotification(); + void closeCompleted(); private: CBDATA_CLASS(ufsstate_t); };