Revision: 14600
Author: ajcorrea
Date: Thu Apr 15 21:39:40 2010
Log: Added two new cache manager functions (Issue #60)

- flushdns  -> Flush all DNS (IP Cache) entries from memory cache.
- flushfqdn -> Flush all FQDN entries from memory cache.

Examples:
bash# squidclient mgr:flushdns

Issue #60 link: http://code.google.com/p/lusca-cache/issues/detail?id=60


http://code.google.com/p/lusca-cache/source/detail?r=14600

Modified:
 /branches/LUSCA_HEAD/libsqname/fqdncache.c
 /branches/LUSCA_HEAD/libsqname/fqdncache.h
 /branches/LUSCA_HEAD/libsqname/ipcache.c
 /branches/LUSCA_HEAD/libsqname/ipcache.h
 /branches/LUSCA_HEAD/src/cache_manager.c

=======================================
--- /branches/LUSCA_HEAD/libsqname/fqdncache.c  Wed Mar 24 20:34:17 2010
+++ /branches/LUSCA_HEAD/libsqname/fqdncache.c  Thu Apr 15 21:39:40 2010
@@ -112,6 +112,8 @@
 static FREE fqdncacheFreeEntry;
 static void fqdncacheAddEntry(fqdncache_entry * f);

+int fqdncacheFlushAll(void);
+
 hash_table *fqdn_table = NULL;

 static long fqdncache_low = 180;
@@ -518,4 +520,22 @@
     fqdncacheAddEntry(fce);
     fqdncacheLockEntry(fce);
 }
-
+int
+fqdncacheFlushAll(void)
+{
+    /* code from libsqname/fqdncache.c */
+    dlink_node *m;
+    dlink_node *prev = NULL;
+    fqdncache_entry *f;
+    int removed = 0;
+
+    for (m = fqdncache_lru_list.tail; m; m = prev) {
+        prev = m->prev;
+        f = m->data;
+        if (f->flags.fromhosts) /* dont flush entries from /etc/hosts */
+            continue;
+        fqdncacheRelease(f);
+        removed++;
+    }
+    return removed;
+}
=======================================
--- /branches/LUSCA_HEAD/libsqname/fqdncache.h  Wed Sep 10 05:40:34 2008
+++ /branches/LUSCA_HEAD/libsqname/fqdncache.h  Thu Apr 15 21:39:40 2010
@@ -51,6 +51,6 @@
 extern void fqdncache_restart(void);
 extern EVH fqdncache_purgelru;
 extern void fqdncacheAddEntryFromHosts(char *addr, wordlist * hostnames);
-
+extern int fqdncacheFlushAll(void);

 #endif
=======================================
--- /branches/LUSCA_HEAD/libsqname/ipcache.c    Wed Mar 24 20:34:17 2010
+++ /branches/LUSCA_HEAD/libsqname/ipcache.c    Thu Apr 15 21:39:40 2010
@@ -110,6 +110,8 @@
 static void ipcacheUnlockEntry(ipcache_entry *);
 static void ipcacheRelease(ipcache_entry *);

+int ipcacheFlushAll(void);
+
 static ipcache_addrs static_addrs;
 hash_table *ip_table = NULL;

@@ -682,4 +684,22 @@
     ipcacheLockEntry(i);
     return 0;
 }
-
+int
+ipcacheFlushAll(void)
+{
+    /* code from libsqname/ipcache.c */
+    dlink_node *m;
+    dlink_node *prev = NULL;
+    ipcache_entry *i;
+    int removed = 0;
+
+    for (m = ipcache_lru_list.tail; m; m = prev) {
+        prev = m->prev;
+        i = m->data;
+       if (i->flags.fromhosts) /* dont flush entries from /etc/hosts */
+           continue;
+        ipcacheRelease(i);
+        removed++;
+    }
+    return removed;
+}
=======================================
--- /branches/LUSCA_HEAD/libsqname/ipcache.h    Wed Sep 10 05:40:34 2008
+++ /branches/LUSCA_HEAD/libsqname/ipcache.h    Thu Apr 15 21:39:40 2010
@@ -64,7 +64,7 @@
 extern ipcache_addrs *ipcacheCheckNumeric(const char *name);
 extern void ipcache_restart(void);
 extern int ipcacheAddEntryFromHosts(const char *name, const char *ipaddr);
-
+extern int ipcacheFlushAll(void);


 #endif
=======================================
--- /branches/LUSCA_HEAD/src/cache_manager.c    Thu Aug 21 16:49:16 2008
+++ /branches/LUSCA_HEAD/src/cache_manager.c    Thu Apr 15 21:39:40 2010
@@ -330,6 +330,24 @@
     }
     return NULL;
 }
+static void
+cachemgrFlushIpcache(StoreEntry * sentry)
+{
+    debug(16, 0) ("IP cache flushed by cachemgr...\n");
+    int removed;
+    removed = ipcacheFlushAll();
+    debug(16, 0) (" removed %d entries\n", removed);
+ storeAppendPrintf(sentry, "IP cache flushed ...\n removed %d entries\n", removed);
+}
+static void
+cachemgrFlushFqdn(StoreEntry * sentry)
+{
+    debug(16, 0) ("FQDN cache flushed by cachemgr...\n");
+    int removed;
+    removed = fqdncacheFlushAll();
+    debug(16, 0) (" removed %d entries\n", removed);
+ storeAppendPrintf(sentry, "FQDN cache flushed ...\n removed %d entries\n", removed);
+}

 void
 cachemgrInit(void)
@@ -346,4 +364,11 @@
     cachemgrRegister("offline_toggle",
        "Toggle offline_mode setting",
        cachemgrOfflineToggle, 1, 1);
-}
+    cachemgrRegister("flushdns",
+        "Flush ALL DNS Cache Entries",
+        cachemgrFlushIpcache, 0, 1);
+    cachemgrRegister("flushfqdn",
+        "Flush ALL FQDN Cache Entries",
+        cachemgrFlushFqdn, 0, 1);
+
+}

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to