--------------------- PatchSet 264 Date: 2002/12/06 02:47:07 Author: rbcollins Branch: unify-io Tag: (none) Log: another step Members: src/fs/aufs/store_asyncufs.h:1.2.12.8->1.2.12.9 src/fs/aufs/store_io_aufs.cc:1.3.12.9->1.3.12.10 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.8 retrieving revision 1.2.12.9 diff -u -r1.2.12.8 -r1.2.12.9 --- squid3/src/fs/aufs/store_asyncufs.h 5 Dec 2002 23:27:33 -0000 1.2.12.8 +++ squid3/src/fs/aufs/store_asyncufs.h 6 Dec 2002 02:47:07 -0000 1.2.12.9 @@ -86,6 +86,8 @@ class AUFSFile : public DiskFile { public: virtual void deleteSelf() const; + void * operator new (size_t); + void operator delete (void *); AUFSFile (char const *path, AufsIO *); ~AUFSFile(); virtual void open (int, mode_t, IORequestor::Pointer); @@ -93,7 +95,13 @@ virtual int getFD() const { return fd;} private: int fd; + bool errorOccured; char const *path_; + AufsIO* IO; + static AIOCB OpenDone; + void openDone(int fd, const char *buf, int aio_return, int aio_errno); + IORequestor::Pointer ioRequestor; + CBDATA_CLASS(AUFSFile); }; class squidaiostate_t : public UFSStoreState { @@ -120,6 +128,7 @@ void ioCompletedNotification(); private: CBDATA_CLASS(squidaiostate_t); + void openDone(); }; struct _queued_write { 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.9 retrieving revision 1.3.12.10 diff -u -r1.3.12.9 -r1.3.12.10 --- squid3/src/fs/aufs/store_io_aufs.cc 5 Dec 2002 23:27:33 -0000 1.3.12.9 +++ squid3/src/fs/aufs/store_io_aufs.cc 6 Dec 2002 02:47:07 -0000 1.3.12.10 @@ -59,7 +59,7 @@ callback_data = cbdataReference(callback_data_); e = anEntry; fd = -1; - flags.opening = 1; + opening = true; } AufsIO AufsIO::Instance; @@ -94,10 +94,31 @@ return new AUFSFile (path, this); } +CBDATA_CLASS_INIT(AUFSFile); +void * +AUFSFile::operator new (size_t) +{ + CBDATA_INIT_TYPE(AUFSFile); + AUFSFile *result = cbdataAlloc(AUFSFile); + /* Mark result as being owned - we want the refcounter to do the delete + * call */ + cbdataReference(result); + return result; +} + +void +AUFSFile::operator delete (void *address) +{ + AUFSFile *t = static_cast(address); + cbdataFree(address); + /* And allow the memory to be freed */ + cbdataReferenceDone (t); +} + void AUFSFile::deleteSelf() const {delete this;} -AUFSFile::AUFSFile (char const *aPath, AufsIO *IO) { +AUFSFile::AUFSFile (char const *aPath, AufsIO *anIO):errorOccured (false), IO(anIO) { assert (aPath); debug (79,0)("UFSFile::UFSFile: %s\n", aPath); path_ = xstrdup (aPath); @@ -111,22 +132,67 @@ void AUFSFile::open (int flags, mode_t mode, IORequestor::Pointer callback) { - assert (0); +#if !ASYNC_OPEN + fd = file_open(path_, flags); + if (fd < 0) { + debug(79, 3) ("storeAufsOpen: got failure (%d)\n", errno); + errorOccured = true; + return; + } +#endif + Opening_FD++; + ioRequestor = callback; +#if ASYNC_OPEN + aioOpen(path_, flags, mode, AUFSFile::OpenDone, this); +#else + openDone(fd, fd, 0); +#endif } bool AUFSFile::error() const { - return true; + return errorOccured; +} + +void +AUFSFile::OpenDone(int fd, void *cbdata, const char *buf, int aio_return, int aio_errno) +{ + AUFSFile *myFile = static_cast(cbdata); + myFile->openDone (fd, buf, aio_return, aio_errno); +} + +void +AUFSFile::openDone(int unused, const char *unused2, int anFD, int errflag) +{ + debug(79, 3) ("AUFSFile::openDone: FD %d, errflag %d\n", anFD, errflag); + Opening_FD--; + + fd = anFD; + if (errflag || fd < 0) { + errno = errflag; + debug(79, 0) ("AUFSFile::openDone: %s\n", xstrerror()); + debug(79, 1) ("\t%s\n", path_); + errorOccured = true; + } else { + store_open_disk_fd++; + commSetCloseOnExec(fd); + fd_open(fd, FD_FILE, path_); + } + + debug(79, 3) ("AUFSFile::openDone: exiting\n"); + + IORequestor::Pointer t = ioRequestor; + ioRequestor = NULL; + t->ioCompletedNotification(); } + /* open for reading */ StoreIOState::Pointer storeAufsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { - char *path = commonUfsDirFullPath(SD, e->swap_filen, NULL); - debug(79, 3) ("storeAufsOpen: fileno %08X\n", e->swap_filen); if (SD->IO->shedLoad()) { SD->IO->openFailed(); @@ -137,7 +203,20 @@ StoreIOState::Pointer sio = ((UFSStrategy *)SD->IO)->createState (SD, e, callback, callback_data); sio->mode |= O_RDONLY; - //squidaiostate_t *aio = dynamic_cast (sio.getRaw()); + squidaiostate_t *aio = dynamic_cast (sio.getRaw()); + assert (aio); + + char *path = commonUfsDirFullPath(SD, e->swap_filen, NULL); + DiskFile::Pointer myFile = ((UFSStrategy *)SD->IO)->newFile(path); + + aio->theFile = myFile; + aio->opening = true; + + myFile->open (sio->mode, 0644, aio); + if (myFile->error()) + return NULL; + +#if 0 #if !ASYNC_OPEN int fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) { @@ -151,6 +230,7 @@ #else storeAufsOpenDone(fd, sio, fd, 0); #endif +#endif return sio; } @@ -234,7 +314,7 @@ if (aiostate->fd < 0) { struct _queued_read *q; debug(79, 3) ("storeAufsRead: queueing read because FD < 0\n"); - assert(aiostate->flags.opening); + assert(aiostate->opening); assert(aiostate->pending_reads == NULL); q = (struct _queued_read *)memPoolAlloc(aufs_qread_pool); q->buf = buf; @@ -270,7 +350,7 @@ if (aiostate->fd < 0) { /* disk file not opened yet */ struct _queued_write *q; - assert(aiostate->flags.opening); + assert(aiostate->opening); q = (struct _queued_write *)memPoolAlloc(aufs_qwrite_pool); q->buf = buf; q->size = size; @@ -349,7 +429,7 @@ squidaiostate_t *aiostate = dynamic_cast(sio); debug(79, 3) ("storeAufsOpenDone: FD %d, errflag %d\n", fd, errflag); Opening_FD--; - aiostate->flags.opening = 0; + aiostate->opening = false; if (errflag || fd < 0) { errno = errflag; debug(79, 0) ("storeAufsOpenDone: %s\n", xstrerror()); @@ -487,7 +567,7 @@ } debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); aiostate->fd = -1; - if (aiostate->flags.opening) + if (aiostate->opening) Opening_FD--; if (fd < 0) return; @@ -506,7 +586,7 @@ if (aiostate->flags.writing) return 1; - if (aiostate->flags.opening && FILE_MODE(sio->mode) == O_WRONLY) + if (aiostate->opening && FILE_MODE(sio->mode) == O_WRONLY) return 1; if (aiostate->flags.reading) return 1; @@ -540,5 +620,31 @@ void squidaiostate_t::ioCompletedNotification() { + if (opening) { + opening = false; + openDone(); + return; + } assert (0); } + +void +squidaiostate_t::openDone() +{ + opening = false; + if (theFile->error()) { + storeAufsIOCallback(this, DISK_ERROR); + return; + } + fd = theFile->getFD(); + if (FILE_MODE(mode) == O_WRONLY) { + if (storeAufsKickWriteQueue(this)) + return; + } else if ((FILE_MODE(mode) == O_RDONLY) && !flags.close_request) { + if (storeAufsKickReadQueue(this)) + return; + } + if (flags.close_request) + storeAufsIOCallback(this, theFile->error() ? -1 : 0); + debug(79, 3) ("squidaiostate_t::openDone: exiting\n"); +}