--------------------- PatchSet 382 Date: 2002/12/14 21:04:14 Author: rbcollins Branch: unify-io Tag: (none) Log: make CleanLog a direct child of SwapDir, and implement the commonUFS implementation thereof. Members: src/SwapDir.h:1.1.2.31->1.1.2.32 src/ufscommon.cc:1.4.10.33->1.4.10.34 Index: squid3/src/SwapDir.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/SwapDir.h,v retrieving revision 1.1.2.31 retrieving revision 1.1.2.32 diff -u -r1.1.2.31 -r1.1.2.32 --- squid3/src/SwapDir.h 14 Dec 2002 11:41:08 -0000 1.1.2.31 +++ squid3/src/SwapDir.h 14 Dec 2002 21:04:14 -0000 1.1.2.32 @@ -1,6 +1,6 @@ /* - * $Id: SwapDir.h,v 1.1.2.31 2002/12/14 11:41:08 rbcollins Exp $ + * $Id: SwapDir.h,v 1.1.2.32 2002/12/14 21:04:14 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -79,12 +79,13 @@ virtual void openLog(); virtual void closeLog(); virtual void logEntry(const StoreEntry & e, int op) const; + class CleanLog { + public: + virtual ~CleanLog(){} + virtual const StoreEntry *nextEntry() = 0; + virtual void write(StoreEntry const &) = 0; + }; struct { - class CleanLog { - public: - const StoreEntry *nextEntry(); - void write(StoreEntry const &); - }; struct { STLOGCLEANNEXTENTRY *nextentry; STLOGCLEANWRITE *write; Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.33 retrieving revision 1.4.10.34 diff -u -r1.4.10.33 -r1.4.10.34 --- squid3/src/ufscommon.cc 14 Dec 2002 11:41:08 -0000 1.4.10.33 +++ squid3/src/ufscommon.cc 14 Dec 2002 21:04:14 -0000 1.4.10.34 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.33 2002/12/14 11:41:08 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.34 2002/12/14 21:04:14 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -896,7 +896,11 @@ return fp; } -struct _clean_state { +class UFSCleanLog : public SwapDir::CleanLog { + public: + UFSCleanLog(SwapDir *); + virtual const StoreEntry *nextEntry(); + virtual void write(StoreEntry const &); char *cur; char *newLog; char *cln; @@ -904,6 +908,7 @@ off_t outbuf_offset; int fd; RemovalPolicyWalker *walker; + SwapDir *sd; }; #define CLEAN_BUF_SZ 16384 @@ -913,10 +918,16 @@ * opening some log files and allocating write buffers. Return 0 if * we succeed, and assign the 'func' and 'data' return pointers. */ + +UFSCleanLog::UFSCleanLog(SwapDir *aSwapDir) : cur(NULL),newLog(NULL),cln(NULL),outbuf(NULL), + outbuf_offset(0), fd(-1),walker(NULL), sd(aSwapDir) +{ +} + int UFSSwapDir::writeCleanStart() { - struct _clean_state *state = (struct _clean_state *)xcalloc(1, sizeof(*state)); + UFSCleanLog *state = new UFSCleanLog(this); #if HAVE_FCHMOD struct stat sb; #endif @@ -942,7 +953,7 @@ fchmod(state->fd, sb.st_mode); #endif log.clean.write = commonUfsDirWriteCleanEntry; - log.clean.state = state; + log.clean.state = (void *)state; return 0; } @@ -952,10 +963,16 @@ const StoreEntry * commonUfsDirCleanLogNextEntry(SwapDir * sd) { + UFSCleanLog *state = (UFSCleanLog *)sd->log.clean.state; + return state->nextEntry(); +} + +const StoreEntry * +UFSCleanLog::nextEntry() +{ const StoreEntry *entry = NULL; - struct _clean_state *state = (struct _clean_state *)sd->log.clean.state; - if (state->walker) - entry = state->walker->Next(state->walker); + if (walker) + entry = walker->Next(walker); return entry; } @@ -965,20 +982,27 @@ void commonUfsDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e) { + UFSCleanLog *state = (UFSCleanLog *)sd->log.clean.state; + state->write (*e); +} + +void +UFSCleanLog::write(StoreEntry const &e) +{ storeSwapLogData s; static size_t ss = sizeof(storeSwapLogData); - struct _clean_state *state = (struct _clean_state *)sd->log.clean.state; memset(&s, '\0', ss); s.op = (char) SWAP_LOG_ADD; - s.swap_filen = e->swap_filen; - s.timestamp = e->timestamp; - s.lastref = e->lastref; - s.expires = e->expires; - s.lastmod = e->lastmod; - s.swap_file_sz = e->swap_file_sz; - s.refcount = e->refcount; - s.flags = e->flags; - xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS); + s.swap_filen = e.swap_filen; + s.timestamp = e.timestamp; + s.lastref = e.lastref; + s.expires = e.expires; + s.lastmod = e.lastmod; + s.swap_file_sz = e.swap_file_sz; + s.refcount = e.refcount; + s.flags = e.flags; + xmemcpy(&s.key, e.key, MD5_DIGEST_CHARS); + UFSCleanLog *state = this; xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -990,7 +1014,7 @@ file_close(state->fd); state->fd = -1; unlink(state->newLog); - safe_free(state); + delete state; sd->log.clean.state = NULL; sd->log.clean.write = NULL; return; @@ -1002,8 +1026,8 @@ void UFSSwapDir::writeCleanDone() { + UFSCleanLog *state = (UFSCleanLog *)log.clean.state; int fd; - struct _clean_state *state = (struct _clean_state *)log.clean.state; if (NULL == state) return; if (state->fd < 0) @@ -1051,7 +1075,7 @@ if (state->fd >= 0) file_close(state->fd); state->fd = -1; - safe_free(state); + delete state; log.clean.state = NULL; log.clean.write = NULL; }