From: robertc <> Date: Fri, 24 Jan 2003 03:59:10 +0000 (+0000) Subject: Summary: Bugfixes for store rebuilding and diskd linking X-Git-Tag: SQUID_3_0_PRE1~436 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=822b78b598a6b9dd6fdb36a35791fb00deecd378;p=thirdparty%2Fsquid.git Summary: Bugfixes for store rebuilding and diskd linking Keywords: diskd wouldn't link if virtual methods were called from RebuildState::*. Splitting out the diomsg struct needed by diskd solves this. Store rebuilding occasionally calls methods on foreign swapdirs, we must use the swapdir for that store entry, not our own. --- diff --git a/src/fs/diskd/dio.h b/src/fs/diskd/dio.h new file mode 100644 index 0000000000..52a5d80236 --- /dev/null +++ b/src/fs/diskd/dio.h @@ -0,0 +1,36 @@ +/* + * dio.h + * + * Internal declarations for the diskd routines + */ + +#ifndef __STORE_DIO_H__ +#define __STORE_DIO_H__ + +typedef struct _diomsg diomsg; + +enum { + _MQD_NOP, + _MQD_OPEN, + _MQD_CREATE, + _MQD_CLOSE, + _MQD_READ, + _MQD_WRITE, + _MQD_UNLINK +}; + +struct _diomsg { + mtyp_t mtype; + int id; + int seq_no; + void * callback_data; + int size; + int offset; + int status; + bool newstyle; + int shm_offset; +}; + +static const int msg_snd_rcv_sz = sizeof(diomsg) - sizeof(mtyp_t); + +#endif diff --git a/src/fs/diskd/diskd.cc b/src/fs/diskd/diskd.cc index 0db90ec59c..dc4c4c6a20 100644 --- a/src/fs/diskd/diskd.cc +++ b/src/fs/diskd/diskd.cc @@ -1,5 +1,5 @@ /* - * $Id: diskd.cc,v 1.13 2003/01/23 00:38:15 robertc Exp $ + * $Id: diskd.cc,v 1.14 2003/01/23 20:59:10 robertc Exp $ * * DEBUG: section -- External DISKD process implementation. * AUTHOR: Harvest Derived @@ -39,7 +39,7 @@ #include #include -#include "store_diskd.h" +#include "dio.h" #undef assert #include diff --git a/src/fs/diskd/store_diskd.h b/src/fs/diskd/store_diskd.h index a1a9f4ed7a..0e721e39db 100644 --- a/src/fs/diskd/store_diskd.h +++ b/src/fs/diskd/store_diskd.h @@ -84,27 +84,7 @@ class diskdstate_t : public UFSStoreState { void doCallback(int); }; -enum { - _MQD_NOP, - _MQD_OPEN, - _MQD_CREATE, - _MQD_CLOSE, - _MQD_READ, - _MQD_WRITE, - _MQD_UNLINK -}; - -struct _diomsg { - mtyp_t mtype; - int id; - int seq_no; - void * callback_data; - int size; - int offset; - int status; - bool newstyle; - int shm_offset; -}; +#include "dio.h" struct _diskd_stats { int open_fail_queue_len; @@ -124,9 +104,6 @@ struct _diskd_stats { typedef struct _diskd_stats diskd_stats_t; - -static const int msg_snd_rcv_sz = sizeof(diomsg) - sizeof(mtyp_t); - extern void storeDiskdHandle(diomsg * M); #include "SwapDir.h" diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index 8ae03a0362..a24e5f48cf 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_ufs.cc,v 1.54 2003/01/23 00:38:22 robertc Exp $ + * $Id: store_dir_ufs.cc,v 1.55 2003/01/23 20:59:11 robertc Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -645,7 +645,7 @@ void UFSSwapDir::rebuild() { int clean = 0; - int zero = 0; + int zeroLengthLog = 0; FILE *fp; EVH *func = NULL; RebuildState *rb = new RebuildState; @@ -657,8 +657,8 @@ UFSSwapDir::rebuild() * use commonUfsDirRebuildFromDirectory() to open up each file * and suck in the meta data. */ - fp = openTmpSwapLog(&clean, &zero); - if (fp == NULL || zero) { + fp = openTmpSwapLog(&clean, &zeroLengthLog); + if (fp == NULL || zeroLengthLog) { if (fp != NULL) fclose(fp); func = RebuildState::RebuildFromDirectory; diff --git a/src/ufscommon.cc b/src/ufscommon.cc index 409821943a..8e72f494c4 100644 --- a/src/ufscommon.cc +++ b/src/ufscommon.cc @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cc,v 1.7 2003/01/23 00:37:27 robertc Exp $ + * $Id: ufscommon.cc,v 1.8 2003/01/23 20:59:10 robertc Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -108,7 +108,7 @@ void RebuildState::rebuildFromDirectory() { LOCAL_ARRAY(char, hdr_buf, SM_PAGE_SIZE); - StoreEntry *e = NULL; + currentEntry(NULL); StoreEntry tmpe; cache_key key[MD5_DIGEST_CHARS]; struct stat sb; @@ -241,10 +241,22 @@ RebuildState::RebuildFromSwapLog(void *data) rb->rebuildFromSwapLog(); } +StoreEntry * +RebuildState::currentEntry() const +{ + return e; +} + +void +RebuildState::currentEntry(StoreEntry *newValue) +{ + e = newValue; +} + void RebuildState::rebuildFromSwapLog() { - StoreEntry *e = NULL; + currentEntry (NULL); double x; /* load a number of objects per invocation */ for (int count = 0; count < speed; count++) { @@ -280,7 +292,8 @@ RebuildState::rebuildFromSwapLog() (void) 0; } else if (s.op == SWAP_LOG_DEL) { /* Delete unless we already have a newer copy */ - if ((e = storeGet(s.key)) != NULL && s.lastref > e->lastref) { + currentEntry (storeGet(s.key)); + if (currentEntry() != NULL && s.lastref > e->lastref) { /* * Make sure we don't unlink the file, it might be * in use by a subsequent entry. Also note that @@ -288,15 +301,17 @@ RebuildState::rebuildFromSwapLog() * because adding to store_swap_size happens in * the cleanup procedure. */ - storeExpireNow(e); - storeReleaseRequest(e); - if (e->swap_filen > -1) { - sd->replacementRemove(e); - sd->mapBitReset(e->swap_filen); - e->swap_filen = -1; - e->swap_dirn = -1; + storeExpireNow(currentEntry()); + storeReleaseRequest(currentEntry()); + if (currentEntry()->swap_filen > -1) { + UFSSwapDir *sdForThisEntry = dynamic_cast(INDEXSD(currentEntry()->swap_dirn)); + assert (sdForThisEntry); + sdForThisEntry->replacementRemove(currentEntry()); + sdForThisEntry->mapBitReset(currentEntry()->swap_filen); + currentEntry()->swap_filen = -1; + currentEntry()->swap_dirn = -1; } - storeRelease(e); + storeRelease(currentEntry()); counts.objcount--; counts.cancelcount++; } @@ -323,28 +338,28 @@ RebuildState::rebuildFromSwapLog() counts.badflags++; continue; } - e = storeGet(s.key); + currentEntry(storeGet(s.key)); int used; /* is swapfile already in use? */ used = sd->mapBitTest(s.swap_filen); /* If this URL already exists in the cache, does the swap log * appear to have a newer entry? Compare 'lastref' from the * swap log to e->lastref. */ /* is the log entry newer than current entry? */ - int disk_entry_newer = e ? (s.lastref > e->lastref ? 1 : 0) : 0; + int disk_entry_newer = currentEntry() ? (s.lastref > currentEntry()->lastref ? 1 : 0) : 0; if (used && !disk_entry_newer) { /* log entry is old, ignore it */ counts.clashcount++; continue; - } else if (used && e && e->swap_filen == s.swap_filen && e->swap_dirn == sd->index) { + } else if (used && currentEntry() && currentEntry()->swap_filen == s.swap_filen && currentEntry()->swap_dirn == sd->index) { /* swapfile taken, same URL, newer, update meta */ - if (e->store_status == STORE_OK) { - e->lastref = s.timestamp; - e->timestamp = s.timestamp; - e->expires = s.expires; - e->lastmod = s.lastmod; - e->flags = s.flags; - e->refcount += s.refcount; - sd->dereference(*e); + if (currentEntry()->store_status == STORE_OK) { + currentEntry()->lastref = s.timestamp; + currentEntry()->timestamp = s.timestamp; + currentEntry()->expires = s.expires; + currentEntry()->lastmod = s.lastmod; + currentEntry()->flags = s.flags; + currentEntry()->refcount += s.refcount; + sd->dereference(*currentEntry()); } else { debug_trap("commonUfsDirRebuildFromSwapLog: bad condition"); debug(47, 1) ("\tSee %s:%d\n", __FILE__, __LINE__); @@ -370,24 +385,25 @@ RebuildState::rebuildFromSwapLog() assert(flags.need_to_validate); counts.clashcount++; continue; - } else if (e && !disk_entry_newer) { + } else if (currentEntry() && !disk_entry_newer) { /* key already exists, current entry is newer */ /* keep old, ignore new */ counts.dupcount++; continue; - } else if (e) { + } else if (currentEntry()) { /* key already exists, this swapfile not being used */ /* junk old, load new */ - storeExpireNow(e); - storeReleaseRequest(e); - if (e->swap_filen > -1) { - sd->replacementRemove(e); + storeExpireNow(currentEntry()); + storeReleaseRequest(currentEntry()); + if (currentEntry()->swap_filen > -1) { + UFSSwapDir *sdForThisEntry = dynamic_cast(INDEXSD(currentEntry()->swap_dirn)); + sdForThisEntry->replacementRemove(currentEntry()); /* Make sure we don't actually unlink the file */ - sd->mapBitReset(e->swap_filen); - e->swap_filen = -1; - e->swap_dirn = -1; + sdForThisEntry->mapBitReset(currentEntry()->swap_filen); + currentEntry()->swap_filen = -1; + currentEntry()->swap_dirn = -1; } - storeRelease(e); + storeRelease(currentEntry()); counts.dupcount++; } else { /* URL doesnt exist, swapfile not in use */ @@ -396,7 +412,7 @@ RebuildState::rebuildFromSwapLog() } /* update store_swap_size */ counts.objcount++; - e = sd->addDiskRestore(s.key, + currentEntry(sd->addDiskRestore(s.key, s.swap_filen, s.swap_file_sz, s.expires, @@ -405,8 +421,8 @@ RebuildState::rebuildFromSwapLog() s.lastmod, s.refcount, s.flags, - (int) flags.clean); - storeDirSwapLog(e, SWAP_LOG_ADD); + (int) flags.clean)); + storeDirSwapLog(currentEntry(), SWAP_LOG_ADD); } eventAdd("storeRebuild", RebuildFromSwapLog, this, 0.0, 1); } diff --git a/src/ufscommon.cci b/src/ufscommon.cci index 406dbd087b..56314c2f1a 100644 --- a/src/ufscommon.cci +++ b/src/ufscommon.cci @@ -1,5 +1,5 @@ /* - * $Id: ufscommon.cci,v 1.1 2003/01/23 00:37:27 robertc Exp $ + * $Id: ufscommon.cci,v 1.2 2003/01/23 20:59:10 robertc Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -32,3 +32,5 @@ * */ +RebuildState::RebuildState () : e(NULL){} + diff --git a/src/ufscommon.h b/src/ufscommon.h index e7a8138d50..df07246174 100644 --- a/src/ufscommon.h +++ b/src/ufscommon.h @@ -1,6 +1,6 @@ /* - * $Id: ufscommon.h,v 1.3 2003/01/23 00:37:27 robertc Exp $ + * $Id: ufscommon.h,v 1.4 2003/01/23 20:59:10 robertc Exp $ * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -227,6 +227,7 @@ public: static EVH RebuildFromDirectory; static EVH RebuildFromSwapLog; + _SQUID_INLINE_ RebuildState(); ~RebuildState(); UFSSwapDir *sd; int n_read; @@ -252,6 +253,9 @@ private: void rebuildFromDirectory(); void rebuildFromSwapLog(); int getNextFile(sfileno *, int *size); + StoreEntry *currentEntry() const; + void currentEntry(StoreEntry *); + StoreEntry *e; }; #ifdef _USE_INLINE_