]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: Bugfixes for store rebuilding and diskd linking
authorrobertc <>
Fri, 24 Jan 2003 03:59:10 +0000 (03:59 +0000)
committerrobertc <>
Fri, 24 Jan 2003 03:59:10 +0000 (03:59 +0000)
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.

src/fs/diskd/dio.h [new file with mode: 0644]
src/fs/diskd/diskd.cc
src/fs/diskd/store_diskd.h
src/fs/ufs/store_dir_ufs.cc
src/ufscommon.cc
src/ufscommon.cci
src/ufscommon.h

diff --git a/src/fs/diskd/dio.h b/src/fs/diskd/dio.h
new file mode 100644 (file)
index 0000000..52a5d80
--- /dev/null
@@ -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
index 0db90ec59c2228d245fb6dfc81572d306a43d077..dc4c4c6a206028235b3f8bd3cfb0a3fa4dec0bdb 100644 (file)
@@ -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 <sys/msg.h>
 #include <sys/shm.h>
 
-#include "store_diskd.h"
+#include "dio.h"
 
 #undef assert
 #include <assert.h>
index a1a9f4ed7aaf97fb658caaee2cd16eeea0019840..0e721e39db83f983bcbc439996e21109d48c6b7b 100644 (file)
@@ -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"
index 8ae03a0362728d7974857321852a51b0579c0b8f..a24e5f48cfa1c16de9a158b172b4c9c99b896176 100644 (file)
@@ -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;
index 409821943a69eacdb29e08ad3b681d3fa21ddf3b..8e72f494c44f92b39d43f92dbd8d0d411b7a27c9 100644 (file)
@@ -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<UFSSwapDir *>(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<UFSSwapDir *>(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);
 }
index 406dbd087bf866f552ed0e40cbf074e1889b3f5c..56314c2f1a7abf73495844621ccc5661da47997b 100644 (file)
@@ -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){}
+
index e7a8138d509034966d85efd961c07f833c35d2e8..df07246174824aed651844af15e54a124aaaaf4a 100644 (file)
@@ -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_