r4959 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Wed Jun 16 12:19:34 CEST 2010


Author: phk
Date: 2010-06-16 12:19:34 +0200 (Wed, 16 Jun 2010)
New Revision: 4959

Modified:
   trunk/varnish-cache/bin/varnishd/common.h
   trunk/varnish-cache/bin/varnishd/mgt_cli.c
   trunk/varnish-cache/bin/varnishd/mgt_shmem.c
   trunk/varnish-cache/bin/varnishd/storage_malloc.c
   trunk/varnish-cache/bin/varnishd/vsm.c
Log:
Move VSM allocation to common code



Modified: trunk/varnish-cache/bin/varnishd/common.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/common.h	2010-06-16 09:51:06 UTC (rev 4958)
+++ trunk/varnish-cache/bin/varnishd/common.h	2010-06-16 10:19:34 UTC (rev 4959)
@@ -73,6 +73,9 @@
 extern struct vsm_head		*vsm_head;
 extern void			*vsm_end;
 
+void *VSM_Alloc(unsigned size, const char *class, const char *type,
+    const char *ident);
+
 struct vsm_chunk *vsm_iter_0(void);
 void vsm_iter_n(struct vsm_chunk **pp);
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-06-16 09:51:06 UTC (rev 4958)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c	2010-06-16 10:19:34 UTC (rev 4959)
@@ -511,7 +511,7 @@
 
 	/* Save in shmem */
 	i = strlen(S_arg);
-	p = mgt_SHM_Alloc(i + 1, "Arg", "-S", "");
+	p = VSM_Alloc(i + 1, "Arg", "-S", "");
 	AN(p);
 	strcpy(p, S_arg);
 
@@ -546,7 +546,7 @@
 
 	/* Save in shmem */
 	i = strlen(T_arg);
-	p = mgt_SHM_Alloc(i + 1, "Arg", "-T", "");
+	p = VSM_Alloc(i + 1, "Arg", "-T", "");
 	AN(p);
 	strcpy(p, T_arg);
 

Modified: trunk/varnish-cache/bin/varnishd/mgt_shmem.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-16 09:51:06 UTC (rev 4958)
+++ trunk/varnish-cache/bin/varnishd/mgt_shmem.c	2010-06-16 10:19:34 UTC (rev 4959)
@@ -118,58 +118,6 @@
 
 static int vsl_fd = -1;
 
-/*--------------------------------------------------------------------*/
-
-void *
-mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
-{
-	struct vsm_chunk *sha, *sha2;
-	unsigned seq;
-
-	ASSERT_MGT();
-	AN(loghead);
-	/* Round up to pointersize */
-	size += sizeof(sha) - 1;
-	size &= ~(sizeof(sha) - 1);
-
-	size += sizeof *sha;
-	sha = &loghead->head;
-	while (1) {
-		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
-
-		if (strcmp(sha->class, "Free")) {
-			sha = VSM_NEXT(sha);
-			continue;
-		}
-		assert(size <= sha->len);
-
-		sha2 = (void*)((uintptr_t)sha + size);
-
-		seq = loghead->alloc_seq;
-		loghead->alloc_seq = 0;
-		VWMB();
-
-		memset(sha2, 0, sizeof *sha2);
-		sha2->magic = VSM_CHUNK_MAGIC;
-		sha2->len = sha->len - size;
-		bprintf(sha2->class, "%s", "Free");
-
-		sha->len = size;
-		bprintf(sha->class, "%s", class);
-		bprintf(sha->type, "%s", type);
-		bprintf(sha->ident, "%s", ident);
-
-		VWMB();
-		if (seq != 0)
-			do
-				loghead->alloc_seq = seq++;
-			while (loghead->alloc_seq == 0);
-
-		return (VSM_PTR(sha));
-	}
-	return (NULL);
-}
-
 /*--------------------------------------------------------------------
  * Check that we are not started with the same -n argument as an already
  * running varnishd
@@ -342,16 +290,16 @@
 	vsm_head = loghead;
 	vsm_end = (uint8_t*)loghead + size;
 
-	VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats,
+	VSL_stats = VSM_Alloc(sizeof *VSL_stats,
 	    VSC_CLASS, VSC_TYPE_MAIN, "");
 	AN(VSL_stats);
 
-	pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", "");
+	pp = VSM_Alloc(sizeof *pp, "Params", "", "");
 	AN(pp);
 	*pp = *params;
 	params = pp;
 
-	vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS, "", "");
+	vsl_log_start = VSM_Alloc(s1, VSL_CLASS, "", "");
 	AN(vsl_log_start);
 	vsl_log_start[1] = VSL_ENDMARKER;
 	VWMB();

Modified: trunk/varnish-cache/bin/varnishd/storage_malloc.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-06-16 09:51:06 UTC (rev 4958)
+++ trunk/varnish-cache/bin/varnishd/storage_malloc.c	2010-06-16 10:19:34 UTC (rev 4959)
@@ -187,7 +187,7 @@
 	struct sma_sc *sma_sc;
 
 	CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
-	sma_sc->stats = mgt_SHM_Alloc(sizeof *sma_sc->stats,
+	sma_sc->stats = VSM_Alloc(sizeof *sma_sc->stats,
 	    VSC_CLASS, VSC_TYPE_SMA, st->ident);
 	memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
 }

Modified: trunk/varnish-cache/bin/varnishd/vsm.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/vsm.c	2010-06-16 09:51:06 UTC (rev 4958)
+++ trunk/varnish-cache/bin/varnishd/vsm.c	2010-06-16 10:19:34 UTC (rev 4959)
@@ -35,11 +35,14 @@
 SVNID("$Id$")
 
 #include <unistd.h>
+#include <string.h>
+#include <stdio.h>
 
 #include "miniobj.h"
 #include "libvarnish.h"
 #include "common.h"
 #include "vsm.h"
+#include "vmb.h"
 
 struct vsm_head		*vsm_head;
 void			*vsm_end;
@@ -68,3 +71,55 @@
 	}
 	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
 }
+
+/*--------------------------------------------------------------------*/
+
+void *
+VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
+{
+	struct vsm_chunk *sha, *sha2;
+	unsigned seq;
+
+	CHECK_OBJ_NOTNULL(vsm_head, VSM_HEAD_MAGIC);
+
+	/* Round up to pointersize */
+	size += sizeof(void *) - 1;
+	size &= ~(sizeof(void *) - 1);
+
+	size += sizeof *sha;		/* Make space for the header */
+
+	VSM_ITER(sha) {
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+
+		if (strcmp(sha->class, "Free"))
+			continue;
+
+		xxxassert(size <= sha->len);
+
+		sha2 = (void*)((uintptr_t)sha + size);
+
+		/* Mark as inconsistent while we write string fields */
+		seq = vsm_head->alloc_seq;
+		vsm_head->alloc_seq = 0;
+		VWMB();
+
+		memset(sha2, 0, sizeof *sha2);
+		sha2->magic = VSM_CHUNK_MAGIC;
+		sha2->len = sha->len - size;
+		bprintf(sha2->class, "%s", "Free");
+
+		sha->len = size;
+		bprintf(sha->class, "%s", class);
+		bprintf(sha->type, "%s", type);
+		bprintf(sha->ident, "%s", ident);
+
+		VWMB();
+		if (seq != 0)
+			do
+				loghead->alloc_seq = seq++;
+			while (loghead->alloc_seq == 0);
+
+		return (VSM_PTR(sha));
+	}
+	return (NULL);
+}




More information about the varnish-commit mailing list