r4803 - in trunk/varnish-cache: bin/varnishd include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Mon May 17 15:22:53 CEST 2010


Author: phk
Date: 2010-05-17 15:22:53 +0200 (Mon, 17 May 2010)
New Revision: 4803

Modified:
   trunk/varnish-cache/bin/varnishd/mgt_shmem.c
   trunk/varnish-cache/include/shmlog.h
   trunk/varnish-cache/include/stats.h
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/shmlog.c
Log:
Move the stats into an allocated chunk of shmem.



Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-05-17 12:30:54 UTC (rev 4802)
+++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-05-17 13:22:53 UTC (rev 4803)
@@ -77,7 +77,7 @@
 		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
 
 		if (strcmp(sha->type, "Free")) {
-			sha = (void*)((uintptr_t)sha + sha->len);
+			sha = SHA_NEXT(sha);
 			continue;
 		}
 		assert(size <= sha->len);
@@ -288,7 +288,6 @@
 	loghead->master_pid = getpid();
 	xxxassert(loghead != MAP_FAILED);
 	(void)mlock((void*)loghead, size);
-	VSL_stats = &loghead->stats;
 
 	/* Initialize pool */
 	loghead->alloc_seq = 0;
@@ -300,7 +299,11 @@
 	bprintf(loghead->head.type, "%s", "Free");
 	MEMORY_BARRIER();
 
+	VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_STAT_TYPE, "");
+	AN(VSL_stats);
+
 	pp = mgt_SHM_Alloc(sizeof *pp, "Params", "");
+	AN(pp);
 	*pp = *params;
 	params = pp;
 

Modified: trunk/varnish-cache/include/shmlog.h
===================================================================
--- trunk/varnish-cache/include/shmlog.h	2010-05-17 12:30:54 UTC (rev 4802)
+++ trunk/varnish-cache/include/shmlog.h	2010-05-17 13:22:53 UTC (rev 4803)
@@ -55,6 +55,9 @@
 	char			ident[8];
 };
 
+#define SHA_NEXT(sha)		((void*)((uintptr_t)(sha) + (sha)->len))
+#define SHA_PTR(sha)		((void*)((uintptr_t)((sha) + 1)))
+
 struct shmloghead {
 #define SHMLOGHEAD_MAGIC	4185512500U	/* From /dev/random */
 	unsigned		magic;
@@ -77,8 +80,6 @@
 	/* Current write position relative to the beginning of start */
 	unsigned		ptr;
 
-	struct varnish_stats	stats;
-
 	/* Panic message buffer */
 	char			panicstr[64 * 1024];
 

Modified: trunk/varnish-cache/include/stats.h
===================================================================
--- trunk/varnish-cache/include/stats.h	2010-05-17 12:30:54 UTC (rev 4802)
+++ trunk/varnish-cache/include/stats.h	2010-05-17 13:22:53 UTC (rev 4803)
@@ -31,6 +31,8 @@
 
 #include <stdint.h>
 
+#define VSL_STAT_TYPE		"Stats"
+
 struct varnish_stats {
 #define MAC_STAT(n, t, l, f, e)	t n;
 #include "stat_field.h"

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-05-17 12:30:54 UTC (rev 4802)
+++ trunk/varnish-cache/include/varnishapi.h	2010-05-17 13:22:53 UTC (rev 4803)
@@ -57,6 +57,7 @@
 int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
 int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
 void VSL_Close(struct VSL_data *vd);
+int VSL_Open(struct VSL_data *vd);
 void VSL_Delete(struct VSL_data *vd);
 struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
 const char *VSL_Name(struct VSL_data *vd);

Modified: trunk/varnish-cache/lib/libvarnishapi/shmlog.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2010-05-17 12:30:54 UTC (rev 4802)
+++ trunk/varnish-cache/lib/libvarnishapi/shmlog.c	2010-05-17 13:22:53 UTC (rev 4803)
@@ -123,8 +123,8 @@
 
 /*--------------------------------------------------------------------*/
 
-static int
-vsl_shmem_map(struct VSL_data *vd)
+int
+VSL_Open(struct VSL_data *vd)
 {
 	int i;
 	struct shmloghead slh;
@@ -180,7 +180,6 @@
 	vd->magic = VSL_MAGIC;
 	vd->vsl_fd = -1;
 
-
 	/* XXX: Allocate only if log access */
 	vd->vbm_client = vbit_init(4096);
 	vd->vbm_backend = vbit_init(4096);
@@ -233,7 +232,7 @@
 	if (vd->r_fd != -1)
 		return (0);
 
-	if (vsl_shmem_map(vd))
+	if (VSL_Open(vd))
 		return (-1);
 
 	vd->head = vd->vsl_lh;
@@ -611,13 +610,36 @@
 	}
 }
 
+/*--------------------------------------------------------------------*/
+
+static
+struct shmalloc *
+vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
+{
+	struct shmalloc *sha;
+
+	assert (vd->vsl_lh != NULL);
+	for(sha = &vd->vsl_lh->head; ; sha = SHA_NEXT(sha)) {
+		CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
+		if (strcmp(sha->type, type)) 
+			continue;
+		if (ident != NULL && strcmp(sha->ident, ident))
+			continue;
+		return (sha);
+	}
+	return (NULL);
+}
+
 struct varnish_stats *
 VSL_OpenStats(struct VSL_data *vd)
 {
+	struct shmalloc *sha;
 
-	if (vsl_shmem_map(vd))
+	if (VSL_Open(vd))
 		return (NULL);
-	return (&vd->vsl_lh->stats);
+	sha = vsl_find_alloc(vd, VSL_STAT_TYPE, "");
+	assert(sha != NULL);
+	return (SHA_PTR(sha));
 }
 
 void




More information about the varnish-commit mailing list