[master] f6e0586 Make varnishtest work again with new VSL api

Martin Blix Grydeland martin at varnish-cache.org
Wed May 15 14:46:14 CEST 2013


commit f6e05865f900e0c9392fce875d33ea9b36a1052a
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Apr 29 15:13:39 2013 +0200

    Make varnishtest work again with new VSL api

diff --git a/bin/Makefile.am b/bin/Makefile.am
index 8e481e5..02bfe66 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -3,7 +3,7 @@
 # Disabling building of the tools while api is in flux
 
 #SUBDIRS = varnishadm varnishd varnishlog varnishncsa varnishreplay varnishtest
-SUBDIRS = varnishadm varnishd varnishlog
+SUBDIRS = varnishadm varnishd varnishlog varnishtest
 
 if HAVE_CURSES
 #SUBDIRS += varnishhist varnishstat varnishtop
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 4e6f8d4..64b24b8 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -48,6 +48,7 @@
 #include "vcli.h"
 #include "vss.h"
 #include "vtcp.h"
+#include "vtim.h"
 
 struct varnish {
 	unsigned		magic;
@@ -172,44 +173,76 @@ wait_running(const struct varnish *v)
 }
 
 /**********************************************************************
- * Varnishlog gatherer + thread
+ * Varnishlog gatherer thread
  */
 
-static int
-h_addlog(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len,
-    unsigned spec, const char *ptr, uint64_t bitmap)
+static void *
+varnishlog_thread(void *priv)
 {
 	struct varnish *v;
-	int type;
+	struct VSL_data *vsl;
+	struct VSM_data *vsm;
+	struct VSL_cursor *c;
+	enum VSL_tag_e tag;
+	uint32_t vxid;
+	unsigned len;
+	const char *data;
+	int type, i;
 
-	(void) bitmap;
-
-	type = (spec & VSL_S_CLIENT) ? 'c' :
-	    (spec & VSL_S_BACKEND) ? 'b' : '-';
 	CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC);
 
-	v->vsl_tag_count[tag]++;
+	vsl = VSL_New();
+	AN(vsl);
+	vsm = VSM_New();
+	AN(vsm);
+	(void)VSM_n_Arg(vsm, v->workdir);
 
-	vtc_log(v->vl, 4, "vsl| %5u %-12s %c %.*s", fd,
-	    VSL_tags[tag], type, len, ptr);
-	v->vsl_sleep = 100;
-	return (0);
-}
+	c = NULL;
+	while (v->pid) {
+		if (c == NULL) {
+			VTIM_sleep(0.1);
+			if (VSM_Open(vsm)) {
+				VSM_ResetError(vsm);
+				continue;
+			}
+			c = VSL_CursorVSM(vsl, vsm, 1);
+			if (c == NULL) {
+				VSL_ResetError(vsl);
+				continue;
+			}
+		}
+		AN(c);
 
-static void *
-varnishlog_thread(void *priv)
-{
-	struct varnish *v;
-	struct VSM_data	*vsl;
+		i = VSL_Next(c);
+		if (i == 0) {
+			/* Nothing to do but wait */
+			VTIM_sleep(0.01);
+			continue;
+		} else if (i == -2) {
+			/* Abandoned - try reconnect */
+			VSL_DeleteCursor(c);
+			c = NULL;
+			VSM_Close(vsm);
+			continue;
+		} else if (i != 1)
+			break;
 
-	CAST_OBJ_NOTNULL(v, priv, VARNISH_MAGIC);
-	vsl = VSM_New();
-	(void)VSL_Arg(vsl, 'n', v->workdir);
-	while (v->pid) {
-		if (VSL_Dispatch(vsl, h_addlog, v) <= 0)
-			usleep(100000);
+		tag = VSL_TAG(c->ptr);
+		vxid = VSL_ID(c->ptr);
+		len = VSL_LEN(c->ptr);
+		type = VSL_CLIENT(c->ptr) ? 'c' : VSL_BACKEND(c->ptr) ?
+		    'b' : '-';
+		data = VSL_CDATA(c->ptr);
+		v->vsl_tag_count[tag]++;
+		vtc_log(v->vl, 4, "vsl| %10u %-15s %c %.*s", vxid,
+		    VSL_tags[tag], type, (int)len, data);
 	}
-	VSM_Delete(vsl);
+
+	if (c)
+		VSL_DeleteCursor(c);
+	VSL_Delete(vsl);
+	VSM_Delete(vsm);
+
 	return (NULL);
 }
 
@@ -449,7 +482,7 @@ varnish_launch(struct varnish *v)
 		vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r);
 	free(r);
 
-	(void)VSL_Arg(v->vd, 'n', v->workdir);
+	(void)VSM_n_Arg(v->vd, v->workdir);
 	AZ(VSM_Open(v->vd));
 }
 



More information about the varnish-commit mailing list