--------------------- PatchSet 383 Date: 2002/12/14 21:14:49 Author: rbcollins Branch: unify-io Tag: (none) Log: ditto for coss Members: src/ufscommon.cc:1.4.10.34->1.4.10.35 src/fs/coss/store_dir_coss.cc:1.4.10.28->1.4.10.29 Index: squid3/src/ufscommon.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ufscommon.cc,v retrieving revision 1.4.10.34 retrieving revision 1.4.10.35 diff -u -r1.4.10.34 -r1.4.10.35 --- squid3/src/ufscommon.cc 14 Dec 2002 21:04:14 -0000 1.4.10.34 +++ squid3/src/ufscommon.cc 14 Dec 2002 21:14:49 -0000 1.4.10.35 @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.4.10.34 2002/12/14 21:04:14 rbcollins Exp $ + * $Id: ufscommon.cc,v 1.4.10.35 2002/12/14 21:14:49 rbcollins Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -937,7 +937,7 @@ state->fd = file_open(state->newLog, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (state->fd < 0) { xfree(state->newLog); - xfree(state); + delete state; return -1; } state->cur = xstrdup(logFile(NULL)); 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.28 retrieving revision 1.4.10.29 diff -u -r1.4.10.28 -r1.4.10.29 --- squid3/src/fs/coss/store_dir_coss.cc 14 Dec 2002 11:41:09 -0000 1.4.10.28 +++ squid3/src/fs/coss/store_dir_coss.cc 14 Dec 2002 21:14:50 -0000 1.4.10.29 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.4.10.28 2002/12/14 11:41:09 rbcollins Exp $ + * $Id: store_dir_coss.cc,v 1.4.10.29 2002/12/14 21:14:50 rbcollins Exp $ * * DEBUG: section 47 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -413,7 +413,7 @@ int fd; if (stat(swaplog_path, &log_sb) < 0) { debug(50, 1) ("Cache COSS Dir #%d: No log file\n", sd->index); - safe_free(swaplog_path); +safe_free(swaplog_path); safe_free(clean_path); safe_free(new_path); return NULL; @@ -449,7 +449,11 @@ return fp; } -struct _clean_state { +class CossCleanLog : public SwapDir::CleanLog { + public: + CossCleanLog(SwapDir *); + virtual const StoreEntry *nextEntry(); + virtual void write(StoreEntry const &); char *cur; char *newLog; char *cln; @@ -457,9 +461,16 @@ off_t outbuf_offset; int fd; dlink_node *current; + SwapDir *sd; }; #define CLEAN_BUF_SZ 16384 + +CossCleanLog::CossCleanLog(SwapDir *aSwapDir) : cur(NULL),newLog(NULL),cln(NULL),outbuf(NULL), + outbuf_offset(0), fd(-1),current(NULL), sd(aSwapDir) +{ +} + /* * Begin the process to write clean cache state. For COSS this means * opening some log files and allocating write buffers. Return 0 if @@ -469,7 +480,7 @@ CossSwapDir::writeCleanStart() { CossInfo *cs = (CossInfo *) fsdata; - struct _clean_state *state = (struct _clean_state *)xcalloc(1, sizeof(*state)); + CossCleanLog *state = new CossCleanLog(this); #if HAVE_FCHMOD struct stat sb; #endif @@ -477,7 +488,7 @@ state->fd = file_open(state->newLog, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); if (state->fd < 0) { xfree(state->newLog); - xfree(state); + delete state; return -1; } log.clean.write = NULL; @@ -503,14 +514,18 @@ static const StoreEntry * storeCossDirCleanLogNextEntry(SwapDir * sd) { - struct _clean_state *state = (struct _clean_state *)sd->log.clean.state; + CossCleanLog *state = (CossCleanLog *)sd->log.clean.state; + return state->nextEntry(); +} + +const StoreEntry * +CossCleanLog::nextEntry() +{ const StoreEntry *entry; - if (!state) - return NULL; - if (!state->current) + if (!current) return NULL; - entry = (const StoreEntry *) state->current->data; - state->current = state->current->prev; + entry = (const StoreEntry *) current->data; + current = current->prev; return entry; } @@ -520,20 +535,28 @@ static void storeCossDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e) { + CossCleanLog *state = (CossCleanLog *)sd->log.clean.state; + assert (e); + state->write (*e); +} + +void +CossCleanLog::write(StoreEntry const &e) +{ + CossCleanLog *state = this; 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); xmemcpy(state->outbuf + state->outbuf_offset, &s, ss); state->outbuf_offset += ss; /* buffered write */ @@ -545,7 +568,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; @@ -558,7 +581,7 @@ CossSwapDir::writeCleanDone() { int fd; - struct _clean_state *state = (struct _clean_state *)log.clean.state; + CossCleanLog *state = (CossCleanLog *)log.clean.state; if (NULL == state) return; if (state->fd < 0) @@ -605,7 +628,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; }