[master] db649fe Add some sanity-asserts to vsl buffers

Poul-Henning Kamp phk at FreeBSD.org
Wed Oct 1 10:54:06 CEST 2014


commit db649fe6138a146d8396ca69e2d61133d0436f89
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 1 08:53:47 2014 +0000

    Add some sanity-asserts to vsl buffers

diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 66d7c89..04c24a8 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -53,6 +53,16 @@ static unsigned			vsl_seq;
 
 struct VSC_C_main       *VSC_C_main;
 
+
+static void
+vsl_sanity(const struct vsl_log *vsl)
+{
+	AN(vsl);
+	AN(vsl->wlp);
+	AN(vsl->wlb);
+	AN(vsl->wle);
+}
+
 /*--------------------------------------------------------------------
  * Check if the VSL_tag is masked by parameter bitmap
  */
@@ -238,6 +248,7 @@ VSL_Flush(struct vsl_log *vsl, int overflow)
 	uint32_t *p;
 	unsigned l;
 
+	vsl_sanity(vsl);
 	l = pdiff(vsl->wlb, vsl->wlp);
 	if (l == 0)
 		return;
@@ -264,6 +275,7 @@ VSLbt(struct vsl_log *vsl, enum VSL_tag_e tag, txt t)
 	unsigned l, mlen;
 	char *p;
 
+	vsl_sanity(vsl);
 	Tcheck(t);
 	if (vsl_tag_is_masked(tag))
 		return;
@@ -303,7 +315,7 @@ VSLbv(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, va_list ap)
 	unsigned n, mlen;
 	txt t;
 
-	AN(vsl);
+	vsl_sanity(vsl);
 	AN(fmt);
 	if (vsl_tag_is_masked(tag))
 		return;
@@ -346,6 +358,7 @@ VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...)
 {
 	va_list ap;
 
+	vsl_sanity(vsl);
 	va_start(ap, fmt);
 	VSLbv(vsl, tag, fmt, ap);
 	va_end(ap);
@@ -360,6 +373,7 @@ VSLb_ts(struct vsl_log *vsl, const char *event, double first, double *pprev,
 	   logging. This must be done carefully because some functions
 	   (e.g. WRW_Reserve) takes the last timestamp as it's inital
 	   value for timeout calculation. */
+	vsl_sanity(vsl);
 	assert(!isnan(now) && now != 0.);
 	VSLb(vsl, SLT_Timestamp, "%s: %.6f %.6f %.6f",
 	    event, now, now - first, now - *pprev);
@@ -385,6 +399,7 @@ VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len)
 	vsl->wle += len / sizeof(*vsl->wle);
 	vsl->wlr = 0;
 	vsl->wid = 0;
+	vsl_sanity(vsl);
 }
 
 /*--------------------------------------------------------------------*/
@@ -394,6 +409,7 @@ VSL_ChgId(struct vsl_log *vsl, const char *typ, const char *why, uint32_t vxid)
 {
 	uint32_t ovxid;
 
+	vsl_sanity(vsl);
 	ovxid = vsl->wid;
 	VSLb(vsl, SLT_Link, "%s %u %s", typ, VXID(vxid), why);
 	VSL_End(vsl);
@@ -409,6 +425,7 @@ VSL_End(struct vsl_log *vsl)
 	txt t;
 	char p[] = "";
 
+	vsl_sanity(vsl);
 	AN(vsl->wid);
 	t.b = p;
 	t.e = p;



More information about the varnish-commit mailing list