--------------------- PatchSet 242 Date: 2002/12/03 11:06:59 Author: rbcollins Branch: unify-io Tag: (none) Log: the single most distruptive change - all the store state objects inherit from StoreIOState, so now we can starting pushing data up and down the hierarchy Members: src/IOStrategy.cc:1.1->1.1.2.1 src/Makefile.am:1.10.10.3->1.10.10.4 src/StoreClient.h:1.2->1.2.20.1 src/StoreIOState.cc:1.1->1.1.2.1 src/StoreIOState.h:1.1->1.1.2.1 src/SwapDir.h:1.1.2.4->1.1.2.5 src/authenticate.cc:1.2->1.2.16.1 src/defines.h:1.3->1.3.10.1 src/protos.h:1.9->1.9.10.1 src/stat.cc:1.5->1.5.10.1 src/store_client.cc:1.3->1.3.16.1 src/store_io.cc:1.3.10.2->1.3.10.3 src/store_swapin.cc:1.2->1.2.16.1 src/store_swapout.cc:1.2.16.2->1.2.16.3 src/structs.h:1.9.10.3->1.9.10.4 src/typedefs.h:1.6.10.3->1.6.10.4 src/fs/aufs/store_asyncufs.h:1.2.12.2->1.2.12.3 src/fs/aufs/store_dir_aufs.cc:1.2.12.3->1.2.12.4 src/fs/aufs/store_io_aufs.cc:1.3.12.4->1.3.12.5 src/fs/coss/store_coss.h:1.3.10.2->1.3.10.3 src/fs/coss/store_dir_coss.cc:1.4.10.3->1.4.10.4 src/fs/coss/store_io_coss.cc:1.3.10.3->1.3.10.4 src/fs/diskd/store_dir_diskd.cc:1.2.16.3->1.2.16.4 src/fs/diskd/store_diskd.h:1.1.20.2->1.1.20.3 src/fs/diskd/store_io_diskd.cc:1.1.20.3->1.1.20.4 src/fs/ufs/store_dir_ufs.cc:1.1.20.3->1.1.20.4 src/fs/ufs/store_io_ufs.cc:1.3.10.3->1.3.10.4 src/fs/ufs/store_ufs.h:1.1.20.2->1.1.20.3 --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/IOStrategy.cc Wed Feb 14 12:14:18 2007 @@ -0,0 +1,39 @@ + +/* + * $Id: IOStrategy.cc,v 1.1.2.1 2002/12/03 11:06:59 rbcollins Exp $ + * + * DEBUG: section ?? Swap Dir base object + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" +#include "IOStrategy.h" + + Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.10.10.3 retrieving revision 1.10.10.4 diff -u -r1.10.10.3 -r1.10.10.4 --- squid3/src/Makefile.am 3 Dec 2002 00:47:02 -0000 1.10.10.3 +++ squid3/src/Makefile.am 3 Dec 2002 11:06:59 -0000 1.10.10.4 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.10.10.3 2002/12/03 00:47:02 rbcollins Exp $ +# $Id: Makefile.am,v 1.10.10.4 2002/12/03 11:06:59 rbcollins Exp $ # # Uncomment and customize the following to suit your needs: # @@ -179,6 +179,7 @@ icp_v3.cc \ ident.cc \ internal.cc \ + IOStrategy.cc \ IOStrategy.h \ ipc.cc \ ipcache.cc \ @@ -215,6 +216,8 @@ Store.h \ store_io.cc \ StoreIOBuffer.h \ + StoreIOState.cc \ + StoreIOState.h \ store_client.cc \ StoreClient.h \ store_digest.cc \ Index: squid3/src/StoreClient.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/StoreClient.h,v retrieving revision 1.2 retrieving revision 1.2.20.1 diff -u -r1.2 -r1.2.20.1 --- squid3/src/StoreClient.h 14 Oct 2002 09:09:09 -0000 1.2 +++ squid3/src/StoreClient.h 3 Dec 2002 11:06:59 -0000 1.2.20.1 @@ -1,6 +1,6 @@ /* - * $Id: StoreClient.h,v 1.2 2002/10/14 09:09:09 squidadm Exp $ + * $Id: StoreClient.h,v 1.2.20.1 2002/12/03 11:06:59 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -60,7 +60,7 @@ void *owner; #endif StoreEntry *entry; /* ptr to the parent StoreEntry, argh! */ - storeIOState *swapin_sio; + StoreIOState::Pointer swapin_sio; struct { unsigned int disk_io_pending:1; unsigned int store_copying:1; --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/StoreIOState.cc Wed Feb 14 12:14:18 2007 @@ -0,0 +1,62 @@ + +/* + * $Id: StoreIOState.cc,v 1.1.2.1 2002/12/03 11:06:59 rbcollins Exp $ + * + * DEBUG: section ?? Swap Dir base object + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" +#include "StoreIOState.h" + +void * +storeIOState::operator new (size_t amount) +{ + assert(0); + return (void *)1; +} + +void +storeIOState::operator delete (void *address){assert (0);} + + +off_t +storeIOState::offset() const +{ + return offset_; +} + +storeIOState::~storeIOState() +{ + if (read.callback_data) + cbdataReferenceDone(read.callback_data); + if (callback_data) + cbdataReferenceDone(callback_data); +} --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/StoreIOState.h Wed Feb 14 12:14:18 2007 @@ -0,0 +1,71 @@ + +/* + * $Id: StoreIOState.h,v 1.1.2.1 2002/12/03 11:06:59 rbcollins Exp $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_STOREIOSTATE_H +#define SQUID_STOREIOSTATE_H + +#include "RefCount.h" + +class storeIOState : public RefCountable{ +public: + /* storeIOState does not get mempooled - it's children do */ + void *operator new (size_t amount); + void operator delete (void *address); + void deleteSelf() const = 0; + virtual ~storeIOState(); + + + off_t offset() const; + sdirno swap_dirn; + 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; + void *callback_data; + struct { + STRCB *callback; + void *callback_data; + } read; + struct { + unsigned int closing:1; /* debugging aid */ + } flags; +}; + +class StoreIOState { + typedef RefCount Pointer; +}; + +#endif /* SQUID_STOREIOSTATE_H */ Index: squid3/src/SwapDir.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/SwapDir.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/SwapDir.h 3 Dec 2002 02:05:28 -0000 1.1.2.4 +++ squid3/src/SwapDir.h 3 Dec 2002 11:06:59 -0000 1.1.2.5 @@ -1,6 +1,6 @@ /* - * $Id: SwapDir.h,v 1.1.2.4 2002/12/03 02:05:28 rbcollins Exp $ + * $Id: SwapDir.h,v 1.1.2.5 2002/12/03 11:06:59 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -48,6 +48,14 @@ typedef int STCALLBACK(SwapDir *); typedef void STSYNC(SwapDir *); +#include "StoreIOState.h" + +typedef StoreIOState::Pointer STOBJCREATE(SwapDir *, StoreEntry *, STFNCB *, STIOCB *, void *); +typedef StoreIOState::Pointer STOBJOPEN(SwapDir *, StoreEntry *, STFNCB *, STIOCB *, void *); +typedef void STOBJCLOSE(SwapDir *, storeIOState *); +typedef void STOBJREAD(SwapDir *, storeIOState *, char *, size_t, off_t, STRCB *, void *); +typedef void STOBJWRITE(SwapDir *, storeIOState *, char *, size_t, off_t, FREE *); +typedef void STOBJUNLINK(SwapDir *, StoreEntry *); class IOStrategy; struct SwapDir { Index: squid3/src/authenticate.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/authenticate.cc,v retrieving revision 1.2 retrieving revision 1.2.16.1 diff -u -r1.2 -r1.2.16.1 --- squid3/src/authenticate.cc 15 Oct 2002 09:27:20 -0000 1.2 +++ squid3/src/authenticate.cc 3 Dec 2002 11:06:59 -0000 1.2.16.1 @@ -1,6 +1,6 @@ /* - * $Id: authenticate.cc,v 1.2 2002/10/15 09:27:20 squidadm Exp $ + * $Id: authenticate.cc,v 1.2.16.1 2002/12/03 11:06:59 rbcollins Exp $ * * DEBUG: section 29 Authenticator * AUTHOR: Robert Collins @@ -207,7 +207,7 @@ assert (byteCount == sizeof (AuthUser)); if (!pool) pool = memPoolCreate("Authenticate User Data", sizeof (auth_user_t)); - return static_cast (memPoolAlloc(pool)); + return memPoolAlloc(pool); } AuthUser::AuthUser (const char *scheme) : Index: squid3/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/defines.h,v retrieving revision 1.3 retrieving revision 1.3.10.1 diff -u -r1.3 -r1.3.10.1 --- squid3/src/defines.h 18 Nov 2002 03:12:57 -0000 1.3 +++ squid3/src/defines.h 3 Dec 2002 11:06:59 -0000 1.3.10.1 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.3 2002/11/18 03:12:57 squidadm Exp $ + * $Id: defines.h,v 1.3.10.1 2002/12/03 11:06:59 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -291,6 +291,8 @@ #endif #define cbdataReference(var) (cbdataInternalLock(var), var) #define cbdataReferenceDone(var) do {if (var) {cbdataInternalUnlock(var); var = NULL;}} while(0) +#define CBDATA_CLASS(type) static cbdata_type CBDATA_##type +#define CBDATA_CLASS_INIT(type) cbdata_type type::CBDATA_##type = CBDATA_UNKNOWN #define CBDATA_TYPE(type) static cbdata_type CBDATA_##type = CBDATA_UNKNOWN #define CBDATA_GLOBAL_TYPE(type) cbdata_type CBDATA_##type #define CBDATA_INIT_TYPE(type) (CBDATA_##type ? CBDATA_UNKNOWN : (CBDATA_##type = cbdataInternalAddType(CBDATA_##type, #type, sizeof(type), NULL))) Index: squid3/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/protos.h,v retrieving revision 1.9 retrieving revision 1.9.10.1 diff -u -r1.9 -r1.9.10.1 --- squid3/src/protos.h 18 Nov 2002 03:12:57 -0000 1.9 +++ squid3/src/protos.h 3 Dec 2002 11:06:59 -0000 1.9.10.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.9 2002/11/18 03:12:57 squidadm Exp $ + * $Id: protos.h,v 1.9.10.1 2002/12/03 11:06:59 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -852,13 +852,12 @@ SQUIDCEXTERN void storeReplSetup(void); /* store_io.c */ -SQUIDCEXTERN storeIOState *storeCreate(StoreEntry *, STFNCB *, STIOCB *, void *); -SQUIDCEXTERN storeIOState *storeOpen(StoreEntry *, STFNCB *, STIOCB *, void *); -SQUIDCEXTERN void storeClose(storeIOState *); -SQUIDCEXTERN void storeRead(storeIOState *, char *, size_t, off_t, STRCB *, void *); -SQUIDCEXTERN void storeWrite(storeIOState *, char *, size_t, off_t, FREE *); +SQUIDCEXTERN StoreIOState::Pointer storeCreate(StoreEntry *, STFNCB *, STIOCB *, void *); +SQUIDCEXTERN StoreIOState::Pointer storeOpen(StoreEntry *, STFNCB *, STIOCB *, void *); +SQUIDCEXTERN void storeClose(StoreIOState::Pointer); +SQUIDCEXTERN void storeRead(StoreIOState::Pointer, char *, size_t, off_t, STRCB *, void *); +SQUIDCEXTERN void storeWrite(StoreIOState::Pointer, char *, size_t, off_t, FREE *); SQUIDCEXTERN void storeUnlink(StoreEntry *); -SQUIDCEXTERN off_t storeOffset(storeIOState *); /* * store_log.c Index: squid3/src/stat.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/stat.cc,v retrieving revision 1.5 retrieving revision 1.5.10.1 diff -u -r1.5 -r1.5.10.1 --- squid3/src/stat.cc 18 Nov 2002 03:12:57 -0000 1.5 +++ squid3/src/stat.cc 3 Dec 2002 11:06:59 -0000 1.5.10.1 @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.5 2002/11/18 03:12:57 squidadm Exp $ + * $Id: stat.cc,v 1.5.10.1 2002/12/03 11:06:59 rbcollins Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -278,9 +278,9 @@ storeAppendPrintf(s, "\tinmem_hi: %d\n", (int) mem->inmem_hi); storeAppendPrintf(s, "\tswapout: %d bytes queued\n", (int) mem->swapout.queue_offset); - if (mem->swapout.sio) + if (mem->swapout.sio.getRaw()) storeAppendPrintf(s, "\tswapout: %d bytes written\n", - (int) storeOffset(mem->swapout.sio)); + (int) mem->swapout.sio->offset()); for (i = 0, node = mem->clients.head; node; node = node->next, i++) storeClientDumpStats((store_client *)node->data, s, i); } Index: squid3/src/store_client.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store_client.cc,v retrieving revision 1.3 retrieving revision 1.3.16.1 diff -u -r1.3 -r1.3.16.1 --- squid3/src/store_client.cc 15 Oct 2002 09:27:20 -0000 1.3 +++ squid3/src/store_client.cc 3 Dec 2002 11:06:59 -0000 1.3.16.1 @@ -1,6 +1,6 @@ /* - * $Id: store_client.cc,v 1.3 2002/10/15 09:27:20 squidadm Exp $ + * $Id: store_client.cc,v 1.3.16.1 2002/12/03 11:06:59 rbcollins Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -301,7 +301,7 @@ * if needed. */ - if (STORE_DISK_CLIENT == sc->type && NULL == sc->swapin_sio) { + if (STORE_DISK_CLIENT == sc->type && sc->swapin_sio.getRaw() == NULL) { debug(20, 3) ("storeClientCopy3: Need to open swap in file\n"); /* gotta open the swapin file */ if (storeTooManyDiskFilesOpen()) { @@ -311,7 +311,7 @@ } else if (!sc->flags.disk_io_pending) { /* Don't set store_io_pending here */ storeSwapInStart(sc); - if (NULL == sc->swapin_sio) { + if (sc->swapin_sio == NULL) { storeClientCallback(sc, -1); return; } @@ -357,7 +357,7 @@ sc); } else { if (sc->entry->swap_status == SWAPOUT_WRITING) - assert(storeOffset(mem->swapout.sio) > sc->copyInto.offset + (off_t)mem->swap_hdr_sz); + assert(mem->swapout.sio->offset() > sc->copyInto.offset + (off_t)mem->swap_hdr_sz); storeRead(sc->swapin_sio, sc->copyInto.data, sc->copyInto.length, @@ -542,9 +542,9 @@ mem->nclients--; if (e->store_status == STORE_OK && e->swap_status != SWAPOUT_DONE) storeSwapOut(e); - if (sc->swapin_sio) { + if (sc->swapin_sio.getRaw()) { storeClose(sc->swapin_sio); - cbdataReferenceDone(sc->swapin_sio); + sc->swapin_sio = NULL; statCounter.swap.ins++; } if (NULL != sc->callback) { @@ -581,7 +581,7 @@ if (sc->type != STORE_MEM_CLIENT) continue; if (sc->type == STORE_DISK_CLIENT) - if (NULL != sc->swapin_sio) + if (sc->swapin_sio.getRaw()) continue; if (sc->copyInto.offset < lowest) lowest = sc->copyInto.offset; Index: squid3/src/store_io.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store_io.cc,v retrieving revision 1.3.10.2 retrieving revision 1.3.10.3 diff -u -r1.3.10.2 -r1.3.10.3 --- squid3/src/store_io.cc 2 Dec 2002 15:25:38 -0000 1.3.10.2 +++ squid3/src/store_io.cc 3 Dec 2002 11:07:00 -0000 1.3.10.3 @@ -19,13 +19,12 @@ * to what will be stored in this object, to allow the filesystem * to select different polices depending on object size or type. */ -storeIOState * +StoreIOState::Pointer storeCreate(StoreEntry * e, STIOCB * file_callback, STIOCB * close_callback, void *callback_data) { ssize_t objsize; sdirno dirn; SwapDir *SD; - storeIOState *sio; store_io_stats.create.calls++; /* This is just done for logging purposes */ @@ -47,8 +46,8 @@ SD = INDEXSD(dirn); /* Now that we have a fs to use, call its storeCreate function */ - sio = SD->obj.create(SD, e, file_callback, close_callback, callback_data); - if (NULL == sio) + StoreIOState::Pointer sio = SD->obj.create(SD, e, file_callback, close_callback, callback_data); + if (sio == NULL) store_io_stats.create.create_fail++; else store_io_stats.create.success++; @@ -59,7 +58,7 @@ /* * storeOpen() is purely for reading .. */ -storeIOState * +StoreIOState::Pointer storeOpen(StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { @@ -68,27 +67,27 @@ } void -storeClose(storeIOState * sio) +storeClose(StoreIOState::Pointer sio) { SwapDir *SD = INDEXSD(sio->swap_dirn); if (sio->flags.closing) return; sio->flags.closing = 1; - SD->obj.close(SD, sio); + SD->obj.close(SD, sio.getRaw()); } void -storeRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) +storeRead(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { SwapDir *SD = INDEXSD(sio->swap_dirn); - SD->obj.read(SD, sio, buf, size, offset, callback, callback_data); + SD->obj.read(SD, sio.getRaw(), buf, size, offset, callback, callback_data); } void -storeWrite(storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) +storeWrite(StoreIOState::Pointer sio, char *buf, size_t size, off_t offset, FREE * free_func) { SwapDir *SD = INDEXSD(sio->swap_dirn); - SD->obj.write(SD, sio, buf, size, offset, free_func); + SD->obj.write(SD, sio.getRaw(), buf, size, offset, free_func); } void @@ -98,12 +97,6 @@ SD->obj.unlink(SD, e); } -off_t -storeOffset(storeIOState * sio) -{ - return sio->offset; -} - /* * Make this non-static so we can register * it from storeInit(); Index: squid3/src/store_swapin.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store_swapin.cc,v retrieving revision 1.2 retrieving revision 1.2.16.1 diff -u -r1.2 -r1.2.16.1 --- squid3/src/store_swapin.cc 15 Oct 2002 09:27:20 -0000 1.2 +++ squid3/src/store_swapin.cc 3 Dec 2002 11:07:00 -0000 1.2.16.1 @@ -1,6 +1,6 @@ /* - * $Id: store_swapin.cc,v 1.2 2002/10/15 09:27:20 squidadm Exp $ + * $Id: store_swapin.cc,v 1.2.16.1 2002/12/03 11:07:00 rbcollins Exp $ * * DEBUG: section 20 Storage Manager Swapin Functions * AUTHOR: Duane Wessels @@ -44,7 +44,6 @@ storeSwapInStart(store_client * sc) { StoreEntry *e = sc->entry; - storeIOState *sio; assert(e->mem_status == NOT_IN_MEMORY); if (!EBIT_TEST(e->flags, ENTRY_VALIDATED)) { /* We're still reloading and haven't validated this entry yet */ @@ -64,8 +63,7 @@ assert(e->mem_obj != NULL); debug(20, 3) ("storeSwapInStart: Opening fileno %08X\n", e->swap_filen); - sio = storeOpen(e, storeSwapInFileNotify, storeSwapInFileClosed, sc); - sc->swapin_sio = cbdataReference(sio); + sc->swapin_sio = storeOpen(e, storeSwapInFileNotify, storeSwapInFileClosed, sc); } static void @@ -80,7 +78,7 @@ sio, errflag); if (errflag) result.flags.error = 1; - cbdataReferenceDone(sc->swapin_sio); + sc->swapin_sio = NULL; if ((callback = sc->callback)) { assert(errflag <= 0); sc->callback = NULL; Index: squid3/src/store_swapout.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/store_swapout.cc,v retrieving revision 1.2.16.2 retrieving revision 1.2.16.3 diff -u -r1.2.16.2 -r1.2.16.3 --- squid3/src/store_swapout.cc 2 Dec 2002 15:25:38 -0000 1.2.16.2 +++ squid3/src/store_swapout.cc 3 Dec 2002 11:07:00 -0000 1.2.16.3 @@ -1,6 +1,6 @@ /* - * $Id: store_swapout.cc,v 1.2.16.2 2002/12/02 15:25:38 rbcollins Exp $ + * $Id: store_swapout.cc,v 1.2.16.3 2002/12/03 11:07:00 rbcollins Exp $ * * DEBUG: section 20 Storage Manager Swapout Functions * AUTHOR: Duane Wessels @@ -52,7 +52,7 @@ int swap_hdr_sz = 0; tlv *tlv_list; char *buf; - storeIOState *sio; + StoreIOState::Pointer sio; assert(mem); /* Build the swap metadata, so the filesystem will know how much * metadata there is to store @@ -68,8 +68,8 @@ c = cbdataAlloc(generic_cbdata); c->data = e; sio = storeCreate(e, storeSwapOutFileNotify, storeSwapOutFileClosed, c); - mem->swapout.sio = cbdataReference(sio); - if (NULL == mem->swapout.sio) { + mem->swapout.sio = sio; + if (mem->swapout.sio == NULL) { e->swap_status = SWAPOUT_NONE; cbdataFree(c); xfree(buf); @@ -129,9 +129,9 @@ (int) mem->inmem_hi); debug(20, 7) ("storeSwapOut: swapout.queue_offset = %d\n", (int) mem->swapout.queue_offset); - if (mem->swapout.sio) - debug(20, 7) ("storeSwapOut: storeOffset() = %d\n", - (int) storeOffset(mem->swapout.sio)); + if (mem->swapout.sio.getRaw()) + debug(20, 7) ("storeSwapOut: offset() = %d\n", + (int) mem->swapout.sio->offset()); assert(mem->inmem_hi >= mem->swapout.queue_offset); lowest_offset = storeLowestMemReaderOffset(e); debug(20, 7) ("storeSwapOut: lowest_offset = %d\n", @@ -228,7 +228,7 @@ return; /* ENTRY_CACHABLE will be cleared and we'll never get here again */ } - if (NULL == mem->swapout.sio) + if (mem->swapout.sio == NULL) return; do { /* @@ -269,7 +269,7 @@ if (swapout_size < SM_PAGE_SIZE) break; } while (swapout_size > 0); - if (NULL == mem->swapout.sio) + if (mem->swapout.sio == NULL) /* oops, we're not swapping out any more */ return; if (e->store_status == STORE_OK) { @@ -289,7 +289,7 @@ MemObject *mem = e->mem_obj; assert(mem != NULL); debug(20, 3) ("storeSwapOutFileClose: %s\n", e->getMD5Text()); - debug(20, 3) ("storeSwapOutFileClose: sio = %p\n", mem->swapout.sio); + debug(20, 3) ("storeSwapOutFileClose: sio = %p\n", mem->swapout.sio.getRaw()); if (mem->swapout.sio == NULL) return; storeClose(mem->swapout.sio); @@ -331,7 +331,7 @@ statCounter.swap.outs++; } debug(20, 3) ("storeSwapOutFileClosed: %s:%d\n", __FILE__, __LINE__); - cbdataReferenceDone(mem->swapout.sio); + mem->swapout.sio = NULL; storeUnlockObject(e); } @@ -342,7 +342,7 @@ storeSwapOutObjectBytesOnDisk(const MemObject * mem) { /* - * NOTE: storeOffset() represents the disk file size, + * NOTE: offset() represents the disk file size, * not the amount of object data on disk. * * If we don't have at least 'swap_hdr_sz' bytes @@ -352,10 +352,9 @@ * meaning we haven't even opened the swapout file * yet. */ - off_t nwritten; if (mem->swapout.sio == NULL) return 0; - nwritten = storeOffset(mem->swapout.sio); + off_t nwritten = mem->swapout.sio->offset(); if (nwritten <= (off_t)mem->swap_hdr_sz) return 0; return nwritten - mem->swap_hdr_sz; @@ -368,7 +367,7 @@ storeSwapOutAble(const StoreEntry * e) { dlink_node *node; - if (e->mem_obj->swapout.sio != NULL) + if (e->mem_obj->swapout.sio.getRaw() != NULL) return 1; if (e->mem_obj->inmem_lo > 0) return 0; Index: squid3/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/structs.h,v retrieving revision 1.9.10.3 retrieving revision 1.9.10.4 diff -u -r1.9.10.3 -r1.9.10.4 --- squid3/src/structs.h 3 Dec 2002 00:08:45 -0000 1.9.10.3 +++ squid3/src/structs.h 3 Dec 2002 11:07:00 -0000 1.9.10.4 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.9.10.3 2002/12/03 00:08:45 rbcollins Exp $ + * $Id: structs.h,v 1.9.10.4 2002/12/03 11:07:00 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1323,6 +1323,10 @@ void (*Done) (RemovalPurgeWalker * walker); }; +/* TODO: Move this include and the memobject header to another file + * - see the fix_ranges branch + */ +#include "StoreIOState.h" /* This structure can be freed while object is purged out from memory */ struct _MemObject { method_t method; @@ -1335,7 +1339,7 @@ struct { off_t queue_offset; /* relative to in-mem data */ mem_node *memnode; /* which node we're currently paging out */ - storeIOState *sio; + StoreIOState::Pointer sio; } swapout; HttpReply *reply; request_t *request; @@ -1400,25 +1404,6 @@ struct _link_list *next; }; -struct _storeIOState { - sdirno swap_dirn; - 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; - void *callback_data; - struct { - STRCB *callback; - void *callback_data; - } read; - struct { - unsigned int closing:1; /* debugging aid */ - } flags; - void *fsstate; -}; struct _request_t { method_t method; Index: squid3/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/typedefs.h,v retrieving revision 1.6.10.3 retrieving revision 1.6.10.4 diff -u -r1.6.10.3 -r1.6.10.4 --- squid3/src/typedefs.h 3 Dec 2002 00:47:02 -0000 1.6.10.3 +++ squid3/src/typedefs.h 3 Dec 2002 11:07:00 -0000 1.6.10.4 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.6.10.3 2002/12/03 00:47:02 rbcollins Exp $ + * $Id: typedefs.h,v 1.6.10.4 2002/12/03 11:07:00 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -168,7 +168,7 @@ typedef struct _helper_request helper_request; typedef struct _helper_stateful_request helper_stateful_request; typedef struct _generic_cbdata generic_cbdata; -typedef struct _storeIOState storeIOState; +class storeIOState; typedef struct _queued_read queued_read; typedef struct _queued_write queued_write; typedef struct _link_list link_list; @@ -246,12 +246,6 @@ typedef void IDNSCB(void *, rfc1035_rr *, int); -typedef storeIOState *STOBJCREATE(SwapDir *, StoreEntry *, STFNCB *, STIOCB *, void *); -typedef storeIOState *STOBJOPEN(SwapDir *, StoreEntry *, STFNCB *, STIOCB *, void *); -typedef void STOBJCLOSE(SwapDir *, storeIOState *); -typedef void STOBJREAD(SwapDir *, storeIOState *, char *, size_t, off_t, STRCB *, void *); -typedef void STOBJWRITE(SwapDir *, storeIOState *, char *, size_t, off_t, FREE *); -typedef void STOBJUNLINK(SwapDir *, StoreEntry *); typedef void STLOGOPEN(SwapDir *); typedef void STLOGCLOSE(SwapDir *); 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.2 retrieving revision 1.2.12.3 diff -u -r1.2.12.2 -r1.2.12.3 --- squid3/src/fs/aufs/store_asyncufs.h 3 Dec 2002 02:05:29 -0000 1.2.12.2 +++ squid3/src/fs/aufs/store_asyncufs.h 3 Dec 2002 11:07:00 -0000 1.2.12.3 @@ -80,7 +80,14 @@ void aioSync(SwapDir *); int aioQueueSize(void); -struct _squidaiostate_t { +class squidaiostate_t : public storeIOState { + public: + virtual void deleteSelf() const {delete this;} + void * operator new (size_t); + void operator delete (void *); + squidaiostate_t(); + ~squidaiostate_t(); + int fd; struct { unsigned int close_request:1; @@ -94,6 +101,8 @@ char *read_buf; link_list *pending_writes; link_list *pending_reads; + private: + CBDATA_CLASS(squidaiostate_t); }; struct _queued_write { @@ -111,16 +120,14 @@ void *callback_data; }; -typedef struct _squidaiostate_t squidaiostate_t; - /* The squidaio_state memory pools */ -extern MemPool *squidaio_state_pool; extern MemPool *aufs_qread_pool; extern MemPool *aufs_qwrite_pool; /* * Store IO stuff */ +#include "SwapDir.h" extern STOBJCREATE storeAufsCreate; extern STOBJOPEN storeAufsOpen; extern STOBJCLOSE storeAufsClose; Index: squid3/src/fs/aufs/store_dir_aufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/aufs/Attic/store_dir_aufs.cc,v retrieving revision 1.2.12.3 retrieving revision 1.2.12.4 diff -u -r1.2.12.3 -r1.2.12.4 --- squid3/src/fs/aufs/store_dir_aufs.cc 3 Dec 2002 00:47:03 -0000 1.2.12.3 +++ squid3/src/fs/aufs/store_dir_aufs.cc 3 Dec 2002 11:07:00 -0000 1.2.12.4 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.2.12.3 2002/12/03 00:47:03 rbcollins Exp $ + * $Id: store_dir_aufs.cc,v 1.2.12.4 2002/12/03 11:07:00 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -41,7 +41,6 @@ #include "SwapDir.h" #include "IOStrategy.h" -MemPool *squidaio_state_pool = NULL; MemPool *aufs_qread_pool = NULL; MemPool *aufs_qwrite_pool = NULL; static int asyncufs_initialised = 0; @@ -229,7 +228,6 @@ storeAufsDirDone(void) { aioDone(); - memPoolDestroy(&squidaio_state_pool); memPoolDestroy(&aufs_qread_pool); memPoolDestroy(&aufs_qwrite_pool); asyncufs_initialised = 0; @@ -251,7 +249,6 @@ storefs->reconfigurefunc = storeAufsDirReconfigure; storefs->donefunc = storeAufsDirDone; storefs->newfunc = storeAufsNew; - squidaio_state_pool = memPoolCreate("AUFS IO State data", sizeof(squidaiostate_t)); aufs_qread_pool = memPoolCreate("AUFS Queued read data", sizeof(queued_read)); aufs_qwrite_pool = memPoolCreate("AUFS Queued write data", 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.4 retrieving revision 1.3.12.5 diff -u -r1.3.12.4 -r1.3.12.5 --- squid3/src/fs/aufs/store_io_aufs.cc 3 Dec 2002 02:05:29 -0000 1.3.12.4 +++ squid3/src/fs/aufs/store_io_aufs.cc 3 Dec 2002 11:07:00 -0000 1.3.12.5 @@ -23,28 +23,35 @@ static AIOCB storeAufsOpenDone; static int storeAufsNeedCompletetion(storeIOState *); static int storeAufsKickWriteQueue(storeIOState * sio); -static CBDUNL storeAufsIOFreeEntry; - -CBDATA_TYPE(storeIOState); /* === PUBLIC =========================================================== */ -squidaiostate_t * -newAIOState() +CBDATA_CLASS_INIT(squidaiostate_t); + +void * +squidaiostate_t::operator new (size_t) { - squidaiostate_t *result = (squidaiostate_t *)memPoolAlloc(squidaio_state_pool); - result->fd = -1; - result->flags.opening = 1; + CBDATA_INIT_TYPE(squidaiostate_t); + squidaiostate_t *result = cbdataAlloc(squidaiostate_t); + /* Mark result as being owned - we want the refcounter to do the delete + * call */ + cbdataReference(result); return result; } - -storeIOState * -newSIO(void *fsState) + +void +squidaiostate_t::operator delete (void *address) { - CBDATA_INIT_TYPE_FREECB(storeIOState, storeAufsIOFreeEntry); - storeIOState *sio = cbdataAlloc(storeIOState); - sio->fsstate = fsState; - return sio; + squidaiostate_t *t = static_cast(address); + cbdataFree(address); + /* And allow the memory to be freed */ + cbdataReferenceDone (t); +} + +squidaiostate_t::squidaiostate_t() +{ + fd = -1; + flags.opening = 1; } AufsIO AufsIO::Instance; @@ -68,7 +75,7 @@ } /* open for reading */ -storeIOState * +StoreIOState::Pointer storeAufsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { @@ -80,7 +87,7 @@ #endif debug(79, 3) ("storeAufsOpen: fileno %08X\n", f); if (SD->IO->shedLoad()) - return false; + return NULL; #if !ASYNC_OPEN fd = file_open(path, O_RDONLY | O_BINARY); if (fd < 0) { @@ -88,7 +95,7 @@ return NULL; } #endif - storeIOState *sio = newSIO(newAIOState()); + storeIOState *sio = new squidaiostate_t; sio->swap_filen = f; sio->swap_dirn = SD->index; sio->mode = O_RDONLY | O_BINARY; @@ -105,7 +112,7 @@ } /* open for creating */ -storeIOState * +StoreIOState::Pointer storeAufsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { char *path; @@ -136,7 +143,7 @@ return NULL; } #endif - storeIOState *sio = newSIO(newAIOState()); + storeIOState *sio = new squidaiostate_t; sio->swap_filen = filn; sio->swap_dirn = dirn; sio->mode = O_WRONLY | O_BINARY; @@ -162,7 +169,7 @@ void storeAufsClose(SwapDir * SD, storeIOState * sio) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast (sio); debug(79, 3) ("storeAufsClose: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); if (storeAufsNeedCompletetion(sio)) { @@ -177,7 +184,7 @@ void storeAufsRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); assert(!aiostate->flags.reading); @@ -200,7 +207,7 @@ aiostate->read_buf = buf; debug(79, 3) ("storeAufsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); - sio->offset = offset; + sio->offset_ = offset; aiostate->flags.reading = 1; #if ASYNC_READ aioRead(aiostate->fd, offset, size, storeAufsReadDone, sio); @@ -214,7 +221,7 @@ void storeAufsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); debug(79, 3) ("storeAufsWrite: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, aiostate->fd); if (aiostate->fd < 0) { @@ -265,7 +272,7 @@ static int storeAufsKickWriteQueue(storeIOState * sio) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); struct _queued_write *q = (struct _queued_write *)linklistShift(&aiostate->pending_writes); if (NULL == q) return 0; @@ -279,7 +286,7 @@ static int storeAufsKickReadQueue(storeIOState * sio) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast (sio); struct _queued_read *q = (struct _queued_read *)linklistShift(&(aiostate->pending_reads)); void *cbdata; if (NULL == q) @@ -296,7 +303,7 @@ storeAufsOpenDone(int unused, void *my_data, const char *unused2, int fd, int errflag) { storeIOState *sio = (storeIOState *)my_data; - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); debug(79, 3) ("storeAufsOpenDone: FD %d, errflag %d\n", fd, errflag); Opening_FD--; aiostate->flags.opening = 0; @@ -332,7 +339,7 @@ #endif { storeIOState *sio = (storeIOState *)my_data; - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); STRCB *callback = sio->read.callback; void *cbdata; ssize_t rlen; @@ -346,7 +353,7 @@ rlen = -1; } else { rlen = (ssize_t) len; - sio->offset += len; + sio->offset_ += len; } #if ASYNC_READ /* translate errflag from errno to Squid disk error */ @@ -383,7 +390,7 @@ { static int loop_detect = 0; storeIOState *sio = (storeIOState *)my_data; - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); debug(79, 3) ("storeAufsWriteDone: dirno %d, fileno %08X, FD %d, len %ld, err=%d\n", sio->swap_dirn, sio->swap_filen, fd, (long int) len, errflag); #if ASYNC_WRITE @@ -402,7 +409,7 @@ loop_detect--; return; } - sio->offset += len; + sio->offset_ += len; #if ASYNC_WRITE if (!storeAufsKickWriteQueue(sio)) 0; @@ -425,7 +432,7 @@ storeAufsIOCallback(storeIOState * sio, int errflag) { STIOCB *callback = sio->callback; - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); int fd = aiostate->fd; debug(79, 3) ("storeAufsIOCallback: errflag=%d\n", errflag); debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); @@ -437,7 +444,6 @@ } debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); aiostate->fd = -1; - cbdataFree(sio); if (aiostate->flags.opening) Opening_FD--; if (fd < 0) @@ -453,7 +459,7 @@ static int storeAufsNeedCompletetion(storeIOState * sio) { - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; + squidaiostate_t *aiostate = dynamic_cast(sio); if (aiostate->flags.writing) return 1; @@ -473,25 +479,17 @@ * The actuall SIO is managed by cbdata so we do not need * to bother with that. */ -static void -storeAufsIOFreeEntry(void *siop) +squidaiostate_t::~squidaiostate_t() { - storeIOState *sio = (storeIOState *) siop; - squidaiostate_t *aiostate = (squidaiostate_t *) sio->fsstate; struct _queued_write *qw; struct _queued_read *qr; - while ((qw = (struct _queued_write *)linklistShift(&aiostate->pending_writes))) { + while ((qw = (struct _queued_write *)linklistShift(&pending_writes))) { if (qw->free_func) qw->free_func(qw->buf); memPoolFree(aufs_qwrite_pool, qw); } - while ((qr = (struct _queued_read *)linklistShift(&aiostate->pending_reads))) { + while ((qr = (struct _queued_read *)linklistShift(&pending_reads))) { cbdataReferenceDone(qr->callback_data); memPoolFree(aufs_qread_pool, qr); } - if (sio->read.callback_data) - cbdataReferenceDone(sio->read.callback_data); - if (sio->callback_data) - cbdataReferenceDone(sio->callback_data); - memPoolFree(squidaio_state_pool, aiostate); } 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.2 retrieving revision 1.3.10.3 diff -u -r1.3.10.2 -r1.3.10.3 --- squid3/src/fs/coss/store_coss.h 3 Dec 2002 02:05:29 -0000 1.3.10.2 +++ squid3/src/fs/coss/store_coss.h 3 Dec 2002 11:07:00 -0000 1.3.10.3 @@ -59,7 +59,14 @@ /* Per-storeiostate info */ -struct _cossstate { +class CossState : public storeIOState { +public: + virtual void deleteSelf() const {delete this;} + void * operator new (size_t); + void operator delete (void *); + CossState(); + ~CossState(); + char *readbuffer; char *requestbuf; size_t requestlen; @@ -69,19 +76,20 @@ unsigned int reading:1; unsigned int writing:1; } flags; +private: + static MemPool *Pool; }; typedef struct _cossmembuf CossMemBuf; typedef struct _cossinfo CossInfo; -typedef struct _cossstate CossState; typedef struct _cossindex CossIndexNode; /* Whether the coss system has been setup or not */ extern int coss_initialised; extern MemPool *coss_membuf_pool; -extern MemPool *coss_state_pool; extern MemPool *coss_index_pool; +#include "SwapDir.h" /* * Store IO stuff */ Index: squid3/src/fs/coss/store_dir_coss.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_dir_coss.cc,v retrieving revision 1.4.10.3 retrieving revision 1.4.10.4 diff -u -r1.4.10.3 -r1.4.10.4 --- squid3/src/fs/coss/store_dir_coss.cc 3 Dec 2002 00:47:03 -0000 1.4.10.3 +++ squid3/src/fs/coss/store_dir_coss.cc 3 Dec 2002 11:07:00 -0000 1.4.10.4 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.4.10.3 2002/12/03 00:47:03 rbcollins Exp $ + * $Id: store_dir_coss.cc,v 1.4.10.4 2002/12/03 11:07:00 rbcollins Exp $ * * DEBUG: section 47 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -46,7 +46,6 @@ int n_coss_dirs = 0; /* static int last_coss_pick_index = -1; */ int coss_initialised = 0; -MemPool *coss_state_pool = NULL; MemPool *coss_index_pool = NULL; typedef struct _RebuildState RebuildState; @@ -886,7 +885,6 @@ static void storeCossDirDone(void) { - memPoolDestroy(&coss_state_pool); /* memPoolDestroy(&coss_index_pool); XXX Should be here? */ coss_initialised = 0; } @@ -908,7 +906,6 @@ storefs->reconfigurefunc = storeCossDirReconfigure; storefs->donefunc = storeCossDirDone; storefs->newfunc = storeCossNew; - coss_state_pool = memPoolCreate("COSS IO State data", sizeof(CossState)); coss_index_pool = memPoolCreate("COSS index data", sizeof(CossIndexNode)); coss_initialised = 1; } 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.3 retrieving revision 1.3.10.4 diff -u -r1.3.10.3 -r1.3.10.4 --- squid3/src/fs/coss/store_io_coss.cc 3 Dec 2002 02:05:30 -0000 1.3.10.3 +++ squid3/src/fs/coss/store_io_coss.cc 3 Dec 2002 11:07:00 -0000 1.3.10.4 @@ -1,6 +1,6 @@ /* - * $Id: store_io_coss.cc,v 1.3.10.3 2002/12/03 02:05:30 rbcollins Exp $ + * $Id: store_io_coss.cc,v 1.3.10.4 2002/12/03 11:07:00 rbcollins Exp $ * * DEBUG: section 79 Storage Manager COSS Interface * AUTHOR: Eric Stern @@ -50,9 +50,7 @@ static void storeCossWriteMemBufDone(int fd, int errflag, size_t len, void *my_data); static CossMemBuf *storeCossCreateMemBuf(SwapDir * SD, size_t start, sfileno curfn, int *collision); -static CBDUNL storeCossIOFreeEntry; -CBDATA_TYPE(storeIOState); CBDATA_TYPE(CossMemBuf); /* === PUBLIC =========================================================== */ @@ -70,6 +68,28 @@ /* Do nothing, we use a single instance */ } + +MemPool *CossState::Pool = NULL; + +void * +CossState::operator new (size_t) +{ + if (!Pool) + Pool = memPoolCreate("Squid COSS State Data", sizeof (CossState)); + return memPoolAlloc(Pool); +} + +void +CossState::operator delete (void *address) +{ + memPoolFree (Pool, address); +} + +CossState::CossState() +{ +} + + /* * This routine sucks. I want to rewrite it when possible, and I also think * that we should check after creatmembuf() to see if the object has a @@ -148,17 +168,13 @@ } -storeIOState * +StoreIOState::Pointer storeCossCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { CossState *cstate; - storeIOState *sio; - - CBDATA_INIT_TYPE_FREECB(storeIOState, storeCossIOFreeEntry); - sio = cbdataAlloc(storeIOState); - cstate = (CossState *)memPoolAlloc(coss_state_pool); - sio->fsstate = cstate; - sio->offset = 0; + StoreIOState::Pointer sio = new CossState; + cstate = dynamic_cast(sio.getRaw()); + sio->offset_ = 0; sio->mode = O_WRONLY | O_BINARY; /* @@ -189,15 +205,14 @@ /* Now add it into the index list */ storeCossAdd(SD, e); - storeCossMemBufLock(SD, sio); + storeCossMemBufLock(SD, sio.getRaw()); return sio; } -storeIOState * +StoreIOState::Pointer storeCossOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { - storeIOState *sio; char *p; CossState *cstate; sfileno f = e->swap_filen; @@ -205,14 +220,12 @@ debug(79, 3) ("storeCossOpen: offset %d\n", f); - CBDATA_INIT_TYPE_FREECB(storeIOState, storeCossIOFreeEntry); - sio = cbdataAlloc(storeIOState); - cstate = (CossState *)memPoolAlloc(coss_state_pool); + StoreIOState::Pointer sio = new CossState; + cstate = dynamic_cast(sio.getRaw()); - sio->fsstate = cstate; sio->swap_filen = f; sio->swap_dirn = SD->index; - sio->offset = 0; + sio->offset_ = 0; sio->mode = O_RDONLY | O_BINARY; sio->callback = callback; sio->file_callback = file_callback; @@ -245,20 +258,19 @@ sio->swap_filen = storeCossAllocate(SD, e, COSS_ALLOC_REALLOC); if (sio->swap_filen == -1) { /* We have to clean up neatly .. */ - cbdataFree(sio); cs->numcollisions++; debug(79, 2) ("storeCossOpen: Reallocation of %d/%d failed\n", e->swap_dirn, e->swap_filen); /* XXX XXX XXX Will squid call storeUnlink for this object? */ return NULL; } /* Notify the upper levels that we've changed file number */ - sio->file_callback(sio->callback_data, 0, sio); + sio->file_callback(sio->callback_data, 0, sio.getRaw()); /* * lock the buffer so it doesn't get swapped out on us * this will get unlocked in storeCossReadDone */ - storeCossMemBufLock(SD, sio); + storeCossMemBufLock(SD, sio.getRaw()); /* * Do the index magic to keep the disk and memory LRUs identical @@ -288,7 +300,7 @@ storeCossRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { char *p; - CossState *cstate = (CossState *) sio->fsstate; + CossState *cstate = dynamic_cast(sio); CossInfo *cs = (CossInfo *) SD->fsdata; assert(sio->read.callback == NULL); @@ -296,7 +308,7 @@ sio->read.callback = callback; sio->read.callback_data = cbdataReference(callback_data); debug(79, 3) ("storeCossRead: offset %ld\n", (long int) offset); - sio->offset = offset; + sio->offset_ = offset; cstate->flags.reading = 1; if ((offset + size) > sio->st_size) size = sio->st_size - offset; @@ -335,12 +347,12 @@ */ assert(sio->e->mem_obj->object_sz != -1); - debug(79, 3) ("storeCossWrite: offset %ld, len %lu\n", (long int) sio->offset, (unsigned long int) size); - diskoffset = sio->swap_filen + sio->offset; + debug(79, 3) ("storeCossWrite: offset %ld, len %lu\n", (long int) sio->offset_, (unsigned long int) size); + diskoffset = sio->swap_filen + sio->offset_; dest = storeCossMemPointerFromDiskOffset(SD, diskoffset, &membuf); assert(dest != NULL); xmemcpy(dest, buf, size); - sio->offset += size; + sio->offset_ += size; if (free_func) (free_func) (buf); } @@ -356,7 +368,7 @@ STRCB *callback = sio->read.callback; void *cbdata; SwapDir *SD = INDEXSD(sio->swap_dirn); - CossState *cstate = (CossState *) sio->fsstate; + CossState *cstate = dynamic_cast(sio); ssize_t rlen; debug(79, 3) ("storeCossReadDone: fileno %d, FD %d, len %d\n", @@ -372,7 +384,7 @@ xmemcpy(cstate->readbuffer, p, sio->st_size); storeCossMemBufUnlock(SD, sio); } - sio->offset += len; + sio->offset_ += len; xmemcpy(cstate->requestbuf, &cstate->readbuffer[cstate->requestoffset], cstate->requestlen); rlen = (size_t) cstate->requestlen; @@ -386,7 +398,7 @@ static void storeCossIOCallback(storeIOState * sio, int errflag) { - CossState *cstate = (CossState *) sio->fsstate; + CossState *cstate = dynamic_cast(sio); STIOCB *callback = sio->callback; void *cbdata; debug(79, 3) ("storeCossIOCallback: errflag=%d\n", errflag); @@ -575,8 +587,6 @@ /* * Clean up any references from the SIO before it get's released. */ -static void -storeCossIOFreeEntry(void *sio) +CossState::~CossState() { - memPoolFree(coss_state_pool, ((storeIOState *) sio)->fsstate); } Index: squid3/src/fs/diskd/store_dir_diskd.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/diskd/Attic/store_dir_diskd.cc,v retrieving revision 1.2.16.3 retrieving revision 1.2.16.4 diff -u -r1.2.16.3 -r1.2.16.4 --- squid3/src/fs/diskd/store_dir_diskd.cc 3 Dec 2002 00:47:03 -0000 1.2.16.3 +++ squid3/src/fs/diskd/store_dir_diskd.cc 3 Dec 2002 11:07:01 -0000 1.2.16.4 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_diskd.cc,v 1.2.16.3 2002/12/03 00:47:03 rbcollins Exp $ + * $Id: store_dir_diskd.cc,v 1.2.16.4 2002/12/03 11:07:01 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -48,7 +48,6 @@ diskd_stats_t diskd_stats; -MemPool *diskd_state_pool = NULL; static int diskd_initialised = 0; static STINIT storeDiskdDirInit; @@ -501,7 +500,6 @@ static void storeDiskdDirDone(void) { - memPoolDestroy(&diskd_state_pool); diskd_initialised = 0; } @@ -521,7 +519,6 @@ storefs->reconfigurefunc = storeDiskdDirReconfigure; storefs->donefunc = storeDiskdDirDone; storefs->newfunc = storeDiskdNew; - diskd_state_pool = memPoolCreate("DISKD IO State data", sizeof(diskdstate_t)); memset(&diskd_stats, '\0', sizeof(diskd_stats)); cachemgrRegister("diskd", "DISKD Stats", storeDiskdStats, 0, 1); debug(47, 1) ("diskd started\n"); 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.2 retrieving revision 1.1.20.3 diff -u -r1.1.20.2 -r1.1.20.3 --- squid3/src/fs/diskd/store_diskd.h 3 Dec 2002 02:05:30 -0000 1.1.20.2 +++ squid3/src/fs/diskd/store_diskd.h 3 Dec 2002 11:07:01 -0000 1.1.20.3 @@ -34,7 +34,14 @@ int magic2; }; -struct _diskdstate_t { +class diskdstate_t : public storeIOState { + public: + virtual void deleteSelf() const {delete this;} + void * operator new (size_t); + void operator delete (void *); + diskdstate_t(); + ~diskdstate_t(); + int id; struct { unsigned int close_request:1; @@ -42,6 +49,8 @@ unsigned int writing:1; } flags; char *read_buf; + private: + CBDATA_CLASS(diskdstate_t); }; enum { @@ -57,7 +66,7 @@ mtyp_t mtype; int id; int seq_no; - void *callback_data; + void * callback_data; int size; int offset; int status; @@ -82,18 +91,15 @@ typedef struct _diskd_stats diskd_stats_t; typedef struct _diskdinfo_t diskdinfo_t; -typedef struct _diskdstate_t diskdstate_t; static const int msg_snd_rcv_sz = sizeof(diomsg) - sizeof(mtyp_t); -/* The diskd_state memory pool */ -extern MemPool *diskd_state_pool; - extern void storeDiskdShmPut(SwapDir *, off_t); extern void *storeDiskdShmGet(SwapDir *, off_t *); extern void storeDiskdHandle(diomsg * M); extern int storeDiskdDirCallback(SwapDir *); +#include "SwapDir.h" /* * Store IO stuff 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.3 retrieving revision 1.1.20.4 diff -u -r1.1.20.3 -r1.1.20.4 --- squid3/src/fs/diskd/store_io_diskd.cc 3 Dec 2002 02:05:30 -0000 1.1.20.3 +++ squid3/src/fs/diskd/store_io_diskd.cc 3 Dec 2002 11:07:01 -0000 1.1.20.4 @@ -1,6 +1,6 @@ /* - * $Id: store_io_diskd.cc,v 1.1.20.3 2002/12/03 02:05:30 rbcollins Exp $ + * $Id: store_io_diskd.cc,v 1.1.20.4 2002/12/03 11:07:01 rbcollins Exp $ * * DEBUG: section 79 Squid-side DISKD I/O functions. * AUTHOR: Duane Wessels @@ -44,11 +44,8 @@ #include "store_diskd.h" #include "SwapDir.h" -static int storeDiskdSend(int, SwapDir *, int, storeIOState *, int, int, off_t); -static void storeDiskdIOCallback(storeIOState * sio, int errflag); -static CBDUNL storeDiskdIOFreeEntry; - -CBDATA_TYPE(storeIOState); +static int storeDiskdSend(int, SwapDir *, int, StoreIOState::Pointer, int, int, off_t); +static void storeDiskdIOCallback(StoreIOState::Pointer, int errflag); /* === PUBLIC =========================================================== */ DiskdIO DiskdIO::Instance; @@ -64,13 +61,38 @@ /* do nothing, we use a single instance */ } -storeIOState * +CBDATA_CLASS_INIT(diskdstate_t); + +void * +diskdstate_t::operator new (size_t) +{ + CBDATA_INIT_TYPE(diskdstate_t); + diskdstate_t *result = cbdataAlloc(diskdstate_t); + /* Mark result as being owned - we want the refcounter to do the delete + * call */ + cbdataReference(result); + return result; +} + +void +diskdstate_t::operator delete (void *address) +{ + diskdstate_t *t = static_cast(address); + cbdataFree(address); + /* And allow the memory to be freed */ + cbdataReferenceDone (t); +} + +diskdstate_t::diskdstate_t() +{ +} + +StoreIOState::Pointer storeDiskdOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { sfileno f = e->swap_filen; int x; - storeIOState *sio; char *buf; diskdstate_t *diskdstate; off_t shm_offset; @@ -84,9 +106,8 @@ diskd_stats.open_fail_queue_len++; return NULL; } - CBDATA_INIT_TYPE_FREECB(storeIOState, storeDiskdIOFreeEntry); - sio = cbdataAlloc(storeIOState); - sio->fsstate = diskdstate = (diskdstate_t *)memPoolAlloc(diskd_state_pool); + StoreIOState::Pointer sio = new diskdstate_t; + diskdstate = dynamic_cast(sio.getRaw()); sio->swap_filen = f; sio->swap_dirn = SD->index; @@ -113,20 +134,19 @@ debug(79, 1) ("storeDiskdSend OPEN: %s\n", xstrerror()); storeDiskdShmPut(SD, shm_offset); cbdataReferenceDone(sio->callback_data); - cbdataFree(sio); + sio->deleteSelf(); return NULL; } diskd_stats.open.ops++; return sio; } -storeIOState * +StoreIOState::Pointer storeDiskdCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { sfileno f; int x; - storeIOState *sio; char *buf; off_t shm_offset; diskdinfo_t *diskdinfo = (diskdinfo_t *)SD->fsdata; @@ -141,11 +161,10 @@ /* Allocate a number */ f = commonUfsDirMapBitAllocate(SD); debug(79, 3) ("storeDiskdCreate: fileno %08X\n", f); - - CBDATA_INIT_TYPE_FREECB(storeIOState, storeDiskdIOFreeEntry); - sio = cbdataAlloc(storeIOState); - sio->fsstate = diskdstate = (diskdstate_t *)memPoolAlloc(diskd_state_pool); - + + StoreIOState::Pointer sio = new diskdstate_t; + diskdstate = dynamic_cast(sio.getRaw()); + sio->swap_filen = f; sio->swap_dirn = SD->index; sio->mode = O_WRONLY | O_CREAT | O_TRUNC; @@ -171,7 +190,7 @@ debug(79, 1) ("storeDiskdSend OPEN: %s\n", xstrerror()); storeDiskdShmPut(SD, shm_offset); cbdataReferenceDone(sio->callback_data); - cbdataFree(sio); + sio->deleteSelf(); return NULL; } commonUfsDirReplAdd(SD, e); @@ -184,7 +203,7 @@ storeDiskdClose(SwapDir * SD, storeIOState * sio) { int x; - diskdstate_t *diskdstate = (diskdstate_t *)sio->fsstate; + diskdstate_t *diskdstate = dynamic_cast(sio); debug(79, 3) ("storeDiskdClose: dirno %d, fileno %08X\n", SD->index, sio->swap_filen); x = storeDiskdSend(_MQD_CLOSE, @@ -208,11 +227,9 @@ int x; off_t shm_offset; char *rbuf; - diskdstate_t *diskdstate = (diskdstate_t *)sio->fsstate; + diskdstate_t *diskdstate = dynamic_cast(sio); debug(79, 3) ("storeDiskdRead: dirno %d, fileno %08X\n", sio->swap_dirn, sio->swap_filen); assert(!diskdstate->flags.close_request); - if (!cbdataReferenceValid(sio)) - return; if (diskdstate->flags.reading) { debug(79, 1) ("storeDiskdRead: already reading!\n"); return; @@ -222,7 +239,7 @@ sio->read.callback = callback; sio->read.callback_data = cbdataReference(callback_data); diskdstate->read_buf = buf; /* the one passed from above */ - sio->offset = offset; + sio->offset_ = offset; diskdstate->flags.reading = 1; rbuf = (char *)storeDiskdShmGet(SD, &shm_offset); assert(rbuf); @@ -247,13 +264,9 @@ int x; char *sbuf; off_t shm_offset; - diskdstate_t *diskdstate = (diskdstate_t *)sio->fsstate; + diskdstate_t *diskdstate = dynamic_cast(sio);; debug(79, 3) ("storeDiskdWrite: dirno %d, fileno %08X\n", SD->index, sio->swap_filen); assert(!diskdstate->flags.close_request); - if (!cbdataReferenceValid(sio)) { - free_func(buf); - return; - } diskdstate->flags.writing = 1; sbuf = (char *)storeDiskdShmGet(SD, &shm_offset); xmemcpy(sbuf, buf, size); @@ -316,7 +329,7 @@ static void storeDiskdOpenDone(diomsg * M) { - storeIOState *sio = (storeIOState *)M->callback_data; + storeIOState *sio = static_cast(M->callback_data); statCounter.syscalls.disk.opens++; debug(79, 3) ("storeDiskdOpenDone: dirno %d, fileno %08x status %d\n", sio->swap_dirn, sio->swap_filen, M->status); @@ -331,7 +344,7 @@ static void storeDiskdCloseDone(diomsg * M) { - storeIOState *sio = (storeIOState *)M->callback_data; + storeIOState *sio = static_cast(M->callback_data); statCounter.syscalls.disk.closes++; debug(79, 3) ("storeDiskdCloseDone: dirno %d, fileno %08x status %d\n", sio->swap_dirn, sio->swap_filen, M->status); @@ -347,11 +360,11 @@ static void storeDiskdReadDone(diomsg * M) { - storeIOState *sio = (storeIOState *)M->callback_data; + storeIOState *sio = static_cast(M->callback_data); STRCB *callback = sio->read.callback; void *cbdata; SwapDir *sd = INDEXSD(sio->swap_dirn); - diskdstate_t *diskdstate = (diskdstate_t *)sio->fsstate; + diskdstate_t *diskdstate = dynamic_cast(sio); diskdinfo_t *diskdinfo = (diskdinfo_t *)sd->fsdata; char *their_buf = diskdstate->read_buf; char *sbuf; @@ -368,7 +381,7 @@ diskd_stats.read.success++; sbuf = diskdinfo->shm.buf + M->shm_offset; len = M->status; - sio->offset += len; + sio->offset_ += len; assert(callback); sio->read.callback = NULL; if (cbdataReferenceValidDone(sio->read.callback_data, &cbdata)) { @@ -387,8 +400,8 @@ static void storeDiskdWriteDone(diomsg * M) { - storeIOState *sio = (storeIOState *)M->callback_data; - diskdstate_t *diskdstate = (diskdstate_t *)sio->fsstate; + storeIOState *sio = static_cast(M->callback_data); + diskdstate_t *diskdstate = dynamic_cast(sio); statCounter.syscalls.disk.writes++; diskdstate->flags.writing = 0; debug(79, 3) ("storeDiskdWriteDone: dirno %d, fileno %08x status %d\n", @@ -399,7 +412,7 @@ return; } diskd_stats.write.success++; - sio->offset += M->status; + sio->offset_ += M->status; } static void @@ -417,8 +430,7 @@ void storeDiskdHandle(diomsg * M) { - if (cbdataReferenceValid(M->callback_data)) { - switch (M->mtype) { + switch (M->mtype) { case _MQD_OPEN: storeDiskdOpenDone(M); break; @@ -438,40 +450,22 @@ assert(0); break; } - } else { - debug(79, 3) ("storeDiskdHandle: Invalid callback_data %p\n", - M->callback_data); - /* - * The read operation has its own callback. If we don't - * call storeDiskdReadDone(), then we must make sure the - * callback_data gets unlocked! - */ - if (_MQD_READ == M->mtype) { - /* XXX This cannot be the correct approach. This - * is most likely the wrong place for this. It should - * be done before the sio becomes invalid, not here. - */ - storeIOState *sio = (storeIOState *)M->callback_data; - cbdataReferenceDone(sio->read.callback_data); - } - } - cbdataReferenceDone(M->callback_data); + M->callback_data = NULL; } static void -storeDiskdIOCallback(storeIOState * sio, int errflag) +storeDiskdIOCallback(StoreIOState::Pointer sio, int errflag) { void *cbdata; STIOCB *callback = sio->callback; debug(79, 3) ("storeUfsIOCallback: errflag=%d\n", errflag); sio->callback = NULL; if (cbdataReferenceValidDone(sio->callback_data, &cbdata)) - callback(cbdata, errflag, sio); - cbdataFree(sio); + callback(cbdata, errflag, sio.getRaw()); } static int -storeDiskdSend(int mtype, SwapDir * sd, int id, storeIOState * sio, int size, int offset, off_t shm_offset) +storeDiskdSend(int mtype, SwapDir * sd, int id, StoreIOState::Pointer sio, int size, int offset, off_t shm_offset) { int x; diomsg M; @@ -480,7 +474,7 @@ static int seq_no = 0; diskdinfo_t *diskdinfo = (diskdinfo_t *)sd->fsdata; M.mtype = mtype; - M.callback_data = cbdataReference(sio); + M.callback_data = sio.getRaw(); M.size = size; M.offset = offset; M.status = -1; @@ -496,7 +490,7 @@ diskdinfo->away++; } else { debug(79, 1) ("storeDiskdSend: msgsnd: %s\n", xstrerror()); - cbdataReferenceDone(M.callback_data); + M.callback_data = NULL; assert(++send_errors < 100); } /* @@ -526,8 +520,4 @@ * We can't pass memFree() as a free function here, because we need to free * the fsstate variable .. */ -static void -storeDiskdIOFreeEntry(void *sio) -{ - memPoolFree(diskd_state_pool, ((storeIOState *) sio)->fsstate); -} +diskdstate_t::~diskdstate_t(){} Index: squid3/src/fs/ufs/store_dir_ufs.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/ufs/store_dir_ufs.cc,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_dir_ufs.cc 3 Dec 2002 00:47:03 -0000 1.1.20.3 +++ squid3/src/fs/ufs/store_dir_ufs.cc 3 Dec 2002 11:07:01 -0000 1.1.20.4 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.1.20.3 2002/12/03 00:47:03 rbcollins Exp $ + * $Id: store_dir_ufs.cc,v 1.1.20.4 2002/12/03 11:07:01 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -40,7 +40,6 @@ #include "ufscommon.h" #include "SwapDir.h" -MemPool *ufs_state_pool = NULL; static int ufs_initialised = 0; static STDUMP storeUfsDirDump; @@ -209,7 +208,6 @@ static void storeUfsDirDone(void) { - memPoolDestroy(&ufs_state_pool); ufs_initialised = 0; } @@ -229,6 +227,5 @@ storefs->reconfigurefunc = storeUfsDirReconfigure; storefs->donefunc = storeUfsDirDone; storefs->newfunc = storeUfsNew; - ufs_state_pool = memPoolCreate("UFS IO State data", sizeof(ufsstate_t)); ufs_initialised = 1; } 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.3 retrieving revision 1.3.10.4 diff -u -r1.3.10.3 -r1.3.10.4 --- squid3/src/fs/ufs/store_io_ufs.cc 3 Dec 2002 02:05:30 -0000 1.3.10.3 +++ squid3/src/fs/ufs/store_io_ufs.cc 3 Dec 2002 11:07:01 -0000 1.3.10.4 @@ -1,6 +1,6 @@ /* - * $Id: store_io_ufs.cc,v 1.3.10.3 2002/12/03 02:05:30 rbcollins Exp $ + * $Id: store_io_ufs.cc,v 1.3.10.4 2002/12/03 11:07:01 rbcollins Exp $ * * DEBUG: section 79 Storage Manager UFS Interface * AUTHOR: Duane Wessels @@ -43,9 +43,6 @@ static DRCB storeUfsReadDone; static DWCB storeUfsWriteDone; static void storeUfsIOCallback(storeIOState * sio, int errflag); -static CBDUNL storeUfsIOFreeEntry; - -CBDATA_TYPE(storeIOState); /* === PUBLIC =========================================================== */ @@ -61,13 +58,38 @@ /* Do nothing, we use a single instance */ } -storeIOState * +CBDATA_CLASS_INIT(ufsstate_t); + +void * +ufsstate_t::operator new (size_t) +{ + CBDATA_INIT_TYPE(ufsstate_t); + ufsstate_t *result = cbdataAlloc(ufsstate_t); + /* Mark result as being owned - we want the refcounter to do the delete + * call */ + cbdataReference(result); + return result; +} + +void +ufsstate_t::operator delete (void *address) +{ + ufsstate_t *t = static_cast(address); + cbdataFree(address); + /* And allow the memory to be freed */ + cbdataReferenceDone (t); +} + +ufsstate_t::ufsstate_t() +{ +} + +StoreIOState::Pointer storeUfsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { sfileno f = e->swap_filen; char *path = commonUfsDirFullPath(SD, f, NULL); - storeIOState *sio; struct stat sb; int fd; debug(79, 3) ("storeUfsOpen: fileno %08X\n", f); @@ -77,9 +99,7 @@ return NULL; } debug(79, 3) ("storeUfsOpen: opened FD %d\n", fd); - CBDATA_INIT_TYPE_FREECB(storeIOState, storeUfsIOFreeEntry); - sio = cbdataAlloc(storeIOState); - sio->fsstate = memPoolAlloc(ufs_state_pool); + StoreIOState::Pointer sio = new ufsstate_t; sio->swap_filen = f; sio->swap_dirn = SD->index; @@ -87,10 +107,11 @@ sio->callback = callback; sio->callback_data = cbdataReference(callback_data); sio->e = e; - ((ufsstate_t *) (sio->fsstate))->fd = fd; - ((ufsstate_t *) (sio->fsstate))->flags.writing = 0; - ((ufsstate_t *) (sio->fsstate))->flags.reading = 0; - ((ufsstate_t *) (sio->fsstate))->flags.close_request = 0; + ufsstate_t *ufs = dynamic_cast(sio.getRaw()); + ufs->fd = fd; + 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++; @@ -99,10 +120,9 @@ return sio; } -storeIOState * +StoreIOState::Pointer storeUfsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data) { - storeIOState *sio; int fd; int mode = (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); char *path; @@ -124,9 +144,7 @@ return NULL; } debug(79, 3) ("storeUfsCreate: opened FD %d\n", fd); - CBDATA_INIT_TYPE_FREECB(storeIOState, storeUfsIOFreeEntry); - sio = cbdataAlloc(storeIOState); - sio->fsstate = memPoolAlloc(ufs_state_pool); + StoreIOState::Pointer sio = new ufsstate_t; sio->swap_filen = filn; sio->swap_dirn = dirn; @@ -134,10 +152,11 @@ sio->callback = callback; sio->callback_data = cbdataReference(callback_data); sio->e = (StoreEntry *) e; - ((ufsstate_t *) (sio->fsstate))->fd = fd; - ((ufsstate_t *) (sio->fsstate))->flags.writing = 0; - ((ufsstate_t *) (sio->fsstate))->flags.reading = 0; - ((ufsstate_t *) (sio->fsstate))->flags.close_request = 0; + ufsstate_t *ufs = dynamic_cast(sio.getRaw()); + ufs->fd = fd; + ufs->flags.writing = 0; + ufs->flags.reading = 0; + ufs->flags.close_request = 0; store_open_disk_fd++; /* now insert into the replacement policy */ @@ -148,7 +167,7 @@ void storeUfsClose(SwapDir * SD, storeIOState * sio) { - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); debug(79, 3) ("storeUfsClose: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, ufsstate->fd); @@ -162,7 +181,7 @@ void storeUfsRead(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); assert(sio->read.callback == NULL); assert(sio->read.callback_data == NULL); @@ -170,7 +189,7 @@ sio->read.callback_data = cbdataReference(callback_data); debug(79, 3) ("storeUfsRead: dirno %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, ufsstate->fd); - sio->offset = offset; + sio->offset_ = offset; ufsstate->flags.reading = 1; file_read(ufsstate->fd, buf, @@ -183,7 +202,7 @@ void storeUfsWrite(SwapDir * SD, storeIOState * sio, char *buf, size_t size, off_t offset, FREE * free_func) { - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); debug(79, 3) ("storeUfsWrite: dirn %d, fileno %08X, FD %d\n", sio->swap_dirn, sio->swap_filen, ufsstate->fd); ufsstate->flags.writing = 1; file_write(ufsstate->fd, @@ -210,7 +229,7 @@ storeUfsReadDone(int fd, const char *buf, int len, int errflag, void *my_data) { storeIOState *sio = (storeIOState *)my_data; - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); STRCB *callback; void *cbdata; ssize_t rlen; @@ -223,7 +242,7 @@ rlen = -1; } else { rlen = (ssize_t) len; - sio->offset += len; + sio->offset_ += len; } assert(sio->read.callback); assert(sio->read.callback_data); @@ -237,7 +256,7 @@ storeUfsWriteDone(int fd, int errflag, size_t len, void *my_data) { storeIOState *sio = (storeIOState *)my_data; - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); debug(79, 3) ("storeUfsWriteDone: dirno %d, fileno %08X, FD %d, len %ld\n", sio->swap_dirn, sio->swap_filen, fd, (long int) len); ufsstate->flags.writing = 0; @@ -246,7 +265,7 @@ storeUfsIOCallback(sio, errflag); return; } - sio->offset += len; + sio->offset_ += len; if (ufsstate->flags.close_request) storeUfsIOCallback(sio, errflag); } @@ -254,7 +273,7 @@ static void storeUfsIOCallback(storeIOState * sio, int errflag) { - ufsstate_t *ufsstate = (ufsstate_t *) sio->fsstate; + ufsstate_t *ufsstate = dynamic_cast(sio); void *cbdata; debug(79, 3) ("storeUfsIOCallback: errflag=%d\n", errflag); if (ufsstate->fd > -1) { @@ -271,8 +290,5 @@ /* * Clean up any references from the SIO before it get's released. */ -static void -storeUfsIOFreeEntry(void *sio) -{ - memPoolFree(ufs_state_pool, ((storeIOState *) sio)->fsstate); -} +ufsstate_t::~ufsstate_t() +{} 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.2 retrieving revision 1.1.20.3 diff -u -r1.1.20.2 -r1.1.20.3 --- squid3/src/fs/ufs/store_ufs.h 3 Dec 2002 02:05:30 -0000 1.1.20.2 +++ squid3/src/fs/ufs/store_ufs.h 3 Dec 2002 11:07:01 -0000 1.1.20.3 @@ -7,20 +7,25 @@ #ifndef __STORE_UFS_H__ #define __STORE_UFS_H__ -struct _ufsstate_t { +class ufsstate_t : public storeIOState { + public: + virtual void deleteSelf() const {delete this;} + void * operator new (size_t); + void operator delete (void *); + ufsstate_t(); + ~ufsstate_t(); int fd; struct { unsigned int close_request:1; unsigned int reading:1; unsigned int writing:1; } flags; + private: + CBDATA_CLASS(ufsstate_t); }; -typedef struct _ufsstate_t ufsstate_t; - -/* The ufs_state memory pool */ -extern MemPool *ufs_state_pool; +#include "SwapDir.h" /* * Store IO stuff */