[master] ef1b8cb Don't hand out zero VXIDs we need that as a magic value.

Poul-Henning Kamp phk at varnish-cache.org
Mon Jul 2 15:32:01 CEST 2012


commit ef1b8cb1b27d1e2092c147a966fc15f0e203dd68
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jul 2 13:31:42 2012 +0000

    Don't hand out zero VXIDs we need that as a magic value.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ae42dd0..2162413 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -937,7 +937,7 @@ void *VSM_Alloc(unsigned size, const char *class, const char *type,
 void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len);
 void VSM_Free(void *ptr);
 #ifdef VSL_ENDMARKER
-void VSL(enum VSL_tag_e tag, int id, const char *fmt, ...)
+void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...)
     __printflike(3, 4);
 void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...)
     __printflike(3, 4);
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index 94f2c8f..c48a3d9 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -87,30 +87,29 @@ THR_GetName(void)
 /*--------------------------------------------------------------------
  * VXID's are unique transaction numbers allocated with a minimum of
  * locking overhead via pools in the worker threads.
+ *
+ * VXID's are mostly for use in VSL and for that reason we never return
+ * zero vxid, in order to reserve that for "unassociated" VSL records.
  */
 
 static uint32_t vxid_base;
 static struct lock vxid_lock;
 
-static void
-vxid_More(struct vxid_pool *v)
-{
-
-	Lck_Lock(&vxid_lock);
-	v->next = vxid_base;
-	v->count = 32768;
-	vxid_base = v->count;
-	Lck_Unlock(&vxid_lock);
-}
-
 uint32_t
 VXID_Get(struct vxid_pool *v)
 {
-	if (v->count == 0)
-		vxid_More(v);
-	AN(v->count);
-	v->count--;
-	return (v->next++);
+	do {
+		if (v->count == 0) {
+			Lck_Lock(&vxid_lock);
+			v->next = vxid_base;
+			v->count = 32768;
+			vxid_base = v->count;
+			Lck_Unlock(&vxid_lock);
+		}
+		v->count--;
+		v->next++;
+	} while (v->next == 0);
+	return (v->next);
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 85a603f..fb63e75 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -61,12 +61,12 @@ vsl_w0(uint32_t type, uint32_t length)
 /*--------------------------------------------------------------------*/
 
 static inline void
-vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, unsigned id)
+vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, uint32_t vxid)
 {
 
 	assert(((uintptr_t)p & 0x3) == 0);
 
-	p[1] = id;
+	p[1] = vxid;
 	VMB();
 	p[0] = vsl_w0(tag, len);
 }
@@ -133,7 +133,7 @@ vsl_get(unsigned len, unsigned records, unsigned flushes)
  */
 
 static void
-vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len)
+vslr(enum VSL_tag_e tag, uint32_t vxid, const char *b, unsigned len)
 {
 	uint32_t *p;
 	unsigned mlen;
@@ -147,13 +147,13 @@ vslr(enum VSL_tag_e tag, int id, const char *b, unsigned len)
 	p = vsl_get(len, 1, 0);
 
 	memcpy(p + 2, b, len);
-	vsl_hdr(tag, p, len, id);
+	vsl_hdr(tag, p, len, vxid);
 }
 
 /*--------------------------------------------------------------------*/
 
 void
-VSL(enum VSL_tag_e tag, int id, const char *fmt, ...)
+VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...)
 {
 	va_list ap;
 	unsigned n, mlen = cache_param->shm_reclen;
@@ -167,12 +167,12 @@ VSL(enum VSL_tag_e tag, int id, const char *fmt, ...)
 	va_start(ap, fmt);
 
 	if (strchr(fmt, '%') == NULL) {
-		vslr(tag, id, fmt, strlen(fmt));
+		vslr(tag, vxid, fmt, strlen(fmt));
 	} else {
 		n = vsnprintf(buf, mlen, fmt, ap);
 		if (n > mlen)
 			n = mlen;
-		vslr(tag, id, buf, n);
+		vslr(tag, vxid, buf, n);
 	}
 	va_end(ap);
 }



More information about the varnish-commit mailing list