--------------------- PatchSet 246 Date: 2002/12/04 12:06:48 Author: rbcollins Branch: unify-io Tag: (none) Log: snapshotting stable ufs object based open Members: src/StoreIOState.h:1.1.2.1->1.1.2.2 src/fs/aufs/store_asyncufs.h:1.2.12.4->1.2.12.5 src/fs/coss/store_coss.h:1.3.10.3->1.3.10.4 src/fs/coss/store_io_coss.cc:1.3.10.4->1.3.10.5 src/fs/diskd/store_diskd.h:1.1.20.4->1.1.20.5 src/fs/ufs/store_io_ufs.cc:1.3.10.5->1.3.10.6 src/fs/ufs/store_ufs.h:1.1.20.3->1.1.20.4 Index: squid3/src/StoreIOState.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/StoreIOState.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid3/src/StoreIOState.h 3 Dec 2002 11:06:59 -0000 1.1.2.1 +++ squid3/src/StoreIOState.h 4 Dec 2002 12:06:48 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: StoreIOState.h,v 1.1.2.1 2002/12/03 11:06:59 rbcollins Exp $ + * $Id: StoreIOState.h,v 1.1.2.2 2002/12/04 12:06:48 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -36,8 +36,15 @@ #include "RefCount.h" -class storeIOState : public RefCountable{ +class IORequestor : public virtual RefCountable{ + public: + typedef RefCount Pointer; + virtual void ioCompletedNotification() = 0; +}; + +class storeIOState : public virtual RefCountable, public IORequestor{ public: + /* storeIOState does not get mempooled - it's children do */ void *operator new (size_t amount); void operator delete (void *address); @@ -50,7 +57,6 @@ sfileno swap_filen; StoreEntry *e; /* Need this so the FS layers can play god */ mode_t mode; - size_t st_size; /* do stat(2) after read open */ off_t offset_; /* current on-disk offset pointer */ STFNCB *file_callback; /* called on delayed sfileno assignments */ STIOCB *callback; 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.4 retrieving revision 1.2.12.5 diff -u -r1.2.12.4 -r1.2.12.5 --- squid3/src/fs/aufs/store_asyncufs.h 3 Dec 2002 12:25:58 -0000 1.2.12.4 +++ squid3/src/fs/aufs/store_asyncufs.h 4 Dec 2002 12:06:49 -0000 1.2.12.5 @@ -103,6 +103,7 @@ char *read_buf; link_list *pending_writes; link_list *pending_reads; + void ioCompletedNotification() {assert (0);} private: CBDATA_CLASS(squidaiostate_t); }; Index: squid3/src/fs/coss/store_coss.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_coss.h,v retrieving revision 1.3.10.3 retrieving revision 1.3.10.4 diff -u -r1.3.10.3 -r1.3.10.4 --- squid3/src/fs/coss/store_coss.h 3 Dec 2002 11:07:00 -0000 1.3.10.3 +++ squid3/src/fs/coss/store_coss.h 4 Dec 2002 12:06:50 -0000 1.3.10.4 @@ -76,6 +76,8 @@ unsigned int reading:1; unsigned int writing:1; } flags; + size_t st_size; + void ioCompletedNotification(){assert(0);} private: static MemPool *Pool; }; Index: squid3/src/fs/coss/store_io_coss.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_io_coss.cc,v retrieving revision 1.3.10.4 retrieving revision 1.3.10.5 diff -u -r1.3.10.4 -r1.3.10.5 --- squid3/src/fs/coss/store_io_coss.cc 3 Dec 2002 11:07:00 -0000 1.3.10.4 +++ squid3/src/fs/coss/store_io_coss.cc 4 Dec 2002 12:06:51 -0000 1.3.10.5 @@ -1,6 +1,6 @@ /* - * $Id: store_io_coss.cc,v 1.3.10.4 2002/12/03 11:07:00 rbcollins Exp $ + * $Id: store_io_coss.cc,v 1.3.10.5 2002/12/04 12:06:51 rbcollins Exp $ * * DEBUG: section 79 Storage Manager COSS Interface * AUTHOR: Eric Stern @@ -187,10 +187,10 @@ * this one is kinda strange - Eric called storeCossAllocate(), then * storeCossOpen(O_RDONLY) .. weird. Anyway, I'm allocating this now. */ - sio->st_size = objectLen(e) + e->mem_obj->swap_hdr_sz; + cstate->st_size = objectLen(e) + e->mem_obj->swap_hdr_sz; sio->swap_dirn = SD->index; sio->swap_filen = storeCossAllocate(SD, e, COSS_ALLOC_ALLOCATE); - debug(79, 3) ("storeCossCreate: offset %d, size %ld, end %ld\n", sio->swap_filen, (long int) sio->st_size, (long int) (sio->swap_filen + sio->st_size)); + debug(79, 3) ("storeCossCreate: offset %d, size %ld, end %ld\n", sio->swap_filen, (long int) cstate->st_size, (long int) (sio->swap_filen + cstate->st_size)); sio->callback = callback; sio->file_callback = file_callback; @@ -230,7 +230,7 @@ sio->callback = callback; sio->file_callback = file_callback; sio->callback_data = cbdataReference(callback_data); - sio->st_size = e->swap_file_sz; + cstate->st_size = e->swap_file_sz; sio->e = e; cstate->flags.writing = 0; @@ -240,8 +240,8 @@ p = storeCossMemPointerFromDiskOffset(SD, f, NULL); /* make local copy so we don't have to lock membuf */ if (p) { - cstate->readbuffer = (char *)xmalloc(sio->st_size); - xmemcpy(cstate->readbuffer, p, sio->st_size); + cstate->readbuffer = (char *)xmalloc(cstate->st_size); + xmemcpy(cstate->readbuffer, p, cstate->st_size); } else { /* Do the allocation */ /* this is the first time we've been called on a new sio @@ -310,8 +310,8 @@ debug(79, 3) ("storeCossRead: offset %ld\n", (long int) offset); sio->offset_ = offset; cstate->flags.reading = 1; - if ((offset + size) > sio->st_size) - size = sio->st_size - offset; + if ((offset + size) > cstate->st_size) + size = cstate->st_size - offset; cstate->requestlen = size; cstate->requestbuf = buf; cstate->requestoffset = offset; @@ -320,7 +320,7 @@ /* Remember we need to translate the block offset to a disk offset! */ a_file_read(&cs->aq, cs->fd, p, - sio->st_size, + cstate->st_size, cstate->reqdiskoffset, storeCossReadDone, sio); @@ -328,7 +328,7 @@ } else { storeCossReadDone(cs->fd, cstate->readbuffer, - sio->st_size, + cstate->st_size, 0, sio); } @@ -379,9 +379,9 @@ rlen = -1; } else { if (cstate->readbuffer == NULL) { - cstate->readbuffer = (char *)xmalloc(sio->st_size); + cstate->readbuffer = (char *)xmalloc(cstate->st_size); p = storeCossMemPointerFromDiskOffset(SD, sio->swap_filen, NULL); - xmemcpy(cstate->readbuffer, p, sio->st_size); + xmemcpy(cstate->readbuffer, p, cstate->st_size); storeCossMemBufUnlock(SD, sio); } sio->offset_ += len; 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.4 retrieving revision 1.1.20.5 diff -u -r1.1.20.4 -r1.1.20.5 --- squid3/src/fs/diskd/store_diskd.h 3 Dec 2002 12:25:58 -0000 1.1.20.4 +++ squid3/src/fs/diskd/store_diskd.h 4 Dec 2002 12:06:51 -0000 1.1.20.5 @@ -49,6 +49,7 @@ unsigned int writing:1; } flags; char *read_buf; + void ioCompletedNotification(){assert(0);} private: CBDATA_CLASS(diskdstate_t); }; 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.5 retrieving revision 1.3.10.6 diff -u -r1.3.10.5 -r1.3.10.6 --- squid3/src/fs/ufs/store_io_ufs.cc 4 Dec 2002 09:05:46 -0000 1.3.10.5 +++ squid3/src/fs/ufs/store_io_ufs.cc 4 Dec 2002 12:06:51 -0000 1.3.10.6 @@ -1,6 +1,6 @@ /* - * $Id: store_io_ufs.cc,v 1.3.10.5 2002/12/04 09:05:46 rbcollins Exp $ + * $Id: store_io_ufs.cc,v 1.3.10.6 2002/12/04 12:06:51 rbcollins Exp $ * * DEBUG: section 79 Storage Manager UFS Interface * AUTHOR: Duane Wessels @@ -84,20 +84,73 @@ { } +void +UFSFile::deleteSelf() const {delete this;} + +UFSFile::UFSFile (char const *aPath) +{ + assert (aPath); + debug (79,0)("UFSFile::UFSFile: %s\n", aPath); + path_ = xstrdup (aPath); +} + +UFSFile::~UFSFile() +{ + safe_free (path_); +} + +void +UFSFile::open (int flags, mode_t mode, IORequestor::Pointer callback) +{ + /* Simulate async calls */ + fd = file_open(path_ , flags); + if (fd < 0) { + debug(79, 3) ("UFSFile::open: got failure (%d)\n", errno); + } + debug(79, 3) ("UFSFile::open: opened FD %d\n", fd); + callback->ioCompletedNotification(); +} + +void +ufsstate_t::doOpenCallback() +{ + assert (0); + STIOCB *aCallback; + void *cbdata; + + debug(79, 3) ("storeUfsOpenDone: dirno %d, fileno %08X, FD %d\n", + swap_dirn, swap_filen, fd); + if (fd < 0) { + debug(79, 3) ("storeUfsOpen: got failure\n"); + } + assert(callback); + assert(callback_data); + aCallback = callback; + callback = NULL; + if (cbdataReferenceValidDone(callback_data, &cbdata)) + aCallback(cbdata, -1, dynamic_cast(this)); +} + +void +ufsstate_t::ioCompletedNotification() +{ + if (flags.opening) { + flags.opening = 0; + fd = theFile->getFD(); + /* There is no 'opened' callback */ +// doOpenCallback(); + return; + } + assert(0); +} + StoreIOState::Pointer storeUfsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { char *path = commonUfsDirFullPath(SD, e->swap_filen, NULL); - struct stat sb; - int fd; debug(79, 3) ("storeUfsOpen: fileno %08X\n", e->swap_filen); - fd = file_open(path, O_RDONLY | O_BINARY); - if (fd < 0) { - debug(79, 3) ("storeUfsOpen: got failure (%d)\n", errno); - return NULL; - } - debug(79, 3) ("storeUfsOpen: opened FD %d\n", fd); + DiskFile::Pointer myFile = new UFSFile (path); StoreIOState::Pointer sio = new ufsstate_t; sio->swap_filen = e->swap_filen; @@ -107,13 +160,13 @@ sio->callback_data = cbdataReference(callback_data); sio->e = e; ufsstate_t *ufs = dynamic_cast(sio.getRaw()); - ufs->fd = fd; + ufs->theFile = myFile; + ufs->flags.opening = 1; ufs->flags.writing = 0; ufs->flags.reading = 0; ufs->flags.close_request = 0; - if (fstat(fd, &sb) == 0) - sio->st_size = sb.st_size; store_open_disk_fd++; + myFile->open (O_RDONLY | O_BINARY, 0644, sio.getRaw()); /* We should update the heap/dlink position here ! */ return sio; 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.3 retrieving revision 1.1.20.4 diff -u -r1.1.20.3 -r1.1.20.4 --- squid3/src/fs/ufs/store_ufs.h 3 Dec 2002 11:07:01 -0000 1.1.20.3 +++ squid3/src/fs/ufs/store_ufs.h 4 Dec 2002 12:06:51 -0000 1.1.20.4 @@ -7,7 +7,29 @@ #ifndef __STORE_UFS_H__ #define __STORE_UFS_H__ -class ufsstate_t : public storeIOState { +class DiskFile : public RefCountable { + public: + typedef RefCount Pointer; + virtual void deleteSelf() const = 0; + virtual void open (int, mode_t, IORequestor::Pointer) = 0; + /* During miogration only */ + virtual int getFD() const {return -1;} +}; + +class UFSFile : public DiskFile { + public: + virtual void deleteSelf() const; + UFSFile (char const *path); + ~UFSFile(); + virtual void open (int, mode_t, IORequestor::Pointer); + virtual int getFD() const { return fd;} + private: + int fd; + char const *path_; +}; + +#include "ufscommon.h" +class ufsstate_t : public UFSStoreState { public: virtual void deleteSelf() const {delete this;} void * operator new (size_t); @@ -16,11 +38,15 @@ ~ufsstate_t(); int fd; struct { + unsigned int opening:1; unsigned int close_request:1; unsigned int reading:1; unsigned int writing:1; } flags; + DiskFile::Pointer theFile; + void ioCompletedNotification(); private: + void doOpenCallback(); CBDATA_CLASS(ufsstate_t); };