[experimental-ims] 009eb1c Give VSL records a backend and client tag (2^30 fd's is enough for everybody!) and tag them at generation, rather than having varnishapi try to deduce each VSL's relationship.

Geoff Simmons geoff at varnish-cache.org
Mon Jan 9 21:52:01 CET 2012


commit 009eb1c50e5dc3f6f1419636621327348ce22eb2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Sep 30 15:09:35 2011 +0000

    Give VSL records a backend and client tag (2^30 fd's is enough for
    everybody!) and tag them at generation, rather than having varnishapi
    try to deduce each VSL's relationship.
    
    Please yell if you have records in your varnishlog output which need
    tagging or which are tagged wrong.

diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 6c80714..5c793e9 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -199,6 +199,7 @@ struct http_conn {
 #define HTTP_CONN_MAGIC		0x3e19edd1
 
 	int			fd;
+	unsigned		vsl_id;
 	unsigned		maxbytes;
 	unsigned		maxhdr;
 	struct ws		*ws;
@@ -542,7 +543,7 @@ struct sess {
 	unsigned		magic;
 #define SESS_MAGIC		0x2c2f9c5a
 	int			fd;
-	int			id;
+	unsigned		vsl_id;
 	unsigned		xid;
 
 	int			restarts;
@@ -632,6 +633,7 @@ struct vbc {
 	VTAILQ_ENTRY(vbc)	list;
 	struct backend		*backend;
 	struct vdi_simple	*vdis;
+	unsigned		vsl_id;
 	int			fd;
 
 	struct sockaddr_storage	*addr;
@@ -756,7 +758,8 @@ const char *http_StatusMessage(unsigned);
 unsigned http_EstimateWS(const struct http *fm, unsigned how, uint16_t *nhd);
 void HTTP_Init(void);
 void http_ClrHeader(struct http *to);
-unsigned http_Write(struct worker *w, const struct http *hp, int resp);
+unsigned http_Write(struct worker *w, unsigned vsl_id, const struct http *hp,
+    int resp);
 void http_CopyResp(struct http *to, const struct http *fm);
 void http_SetResp(struct http *to, const char *proto, uint16_t status,
     const char *response);
@@ -792,8 +795,8 @@ void http_Unset(struct http *hp, const char *hdr);
 void http_CollectHdr(struct http *hp, const char *hdr);
 
 /* cache_httpconn.c */
-void HTC_Init(struct http_conn *htc, struct ws *ws, int fd, unsigned maxbytes,
-    unsigned maxhdr);
+void HTC_Init(struct http_conn *htc, struct ws *ws, int fd, unsigned vsl_id,
+    unsigned maxbytes, unsigned maxhdr);
 int HTC_Reinit(struct http_conn *htc);
 int HTC_Rx(struct http_conn *htc);
 ssize_t HTC_Read(struct http_conn *htc, void *d, size_t len);
@@ -887,10 +890,10 @@ void WSL_Flush(struct worker *w, int overflow);
 	} while (0)
 
 #define WSP(sess, tag, ...)					\
-	WSL((sess)->wrk, tag, (sess)->fd, __VA_ARGS__)
+	WSL((sess)->wrk, tag, (sess)->vsl_id, __VA_ARGS__)
 
 #define WSPR(sess, tag, txt)					\
-	WSLR((sess)->wrk, tag, (sess)->fd, txt)
+	WSLR((sess)->wrk, tag, (sess)->vsl_id, txt)
 
 #define INCOMPL() do {							\
 	VSL(SLT_Debug, 0, "INCOMPLETE AT: %s(%d)", __func__, __LINE__); \
diff --git a/bin/varnishd/cache_acceptor.c b/bin/varnishd/cache_acceptor.c
index 1d73a1a..ba28a39 100644
--- a/bin/varnishd/cache_acceptor.c
+++ b/bin/varnishd/cache_acceptor.c
@@ -277,7 +277,7 @@ VCA_SetupSess(struct worker *w)
 	sp = w->sp;
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	sp->fd = wa->acceptsock;
-	sp->id = wa->acceptsock;
+	sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ;
 	wa->acceptsock = -1;
 	sp->t_open = TIM_real();
 	sp->t_end = sp->t_open;
diff --git a/bin/varnishd/cache_backend.c b/bin/varnishd/cache_backend.c
index 3d6a405..d2bc860 100644
--- a/bin/varnishd/cache_backend.c
+++ b/bin/varnishd/cache_backend.c
@@ -118,8 +118,6 @@ vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr_storage *sa,
 {
 	int s, i, tmo;
 	double tmod;
-	char abuf1[VTCP_ADDRBUFSIZE], abuf2[VTCP_ADDRBUFSIZE];
-	char pbuf1[VTCP_PORTBUFSIZE], pbuf2[VTCP_PORTBUFSIZE];
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(vs, VDI_SIMPLE_MAGIC);
@@ -139,11 +137,6 @@ vbe_TryConnect(const struct sess *sp, int pf, const struct sockaddr_storage *sa,
 		return (-1);
 	}
 
-	VTCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
-	VTCP_name(sa, salen, abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
-	WSL(sp->wrk, SLT_BackendOpen, s, "%s %s %s %s %s",
-	    vs->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2);
-
 	return (s);
 }
 
@@ -154,6 +147,8 @@ bes_conn_try(const struct sess *sp, struct vbc *vc, const struct vdi_simple *vs)
 {
 	int s;
 	struct backend *bp = vs->backend;
+	char abuf1[VTCP_ADDRBUFSIZE], abuf2[VTCP_ADDRBUFSIZE];
+	char pbuf1[VTCP_PORTBUFSIZE], pbuf2[VTCP_PORTBUFSIZE];
 
 	CHECK_OBJ_NOTNULL(vs, VDI_SIMPLE_MAGIC);
 
@@ -191,7 +186,15 @@ bes_conn_try(const struct sess *sp, struct vbc *vc, const struct vdi_simple *vs)
 		Lck_Unlock(&bp->mtx);
 		vc->addr = NULL;
 		vc->addrlen = 0;
+	} else {
+		vc->vsl_id = s | VSL_BACKENDMARKER;
+		VTCP_myname(s, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
+		VTCP_name(vc->addr, vc->addrlen,
+		    abuf2, sizeof abuf2, pbuf2, sizeof pbuf2);
+		WSL(sp->wrk, SLT_BackendOpen, vc->vsl_id, "%s %s %s %s %s",
+		    vs->backend->vcl_name, abuf1, pbuf1, abuf2, pbuf2);
 	}
+
 }
 
 /*--------------------------------------------------------------------
diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index 32a4215..38ec4f2 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -341,7 +341,7 @@ cnt_done(struct sess *sp)
 			WSP(sp, SLT_Length, "%ju",
 			    (uintmax_t)sp->req_bodybytes);
 		}
-		WSL(sp->wrk, SLT_ReqEnd, sp->id, "%u %.9f %.9f %.9f %.9f %.9f",
+		WSP(sp, SLT_ReqEnd, "%u %.9f %.9f %.9f %.9f %.9f",
 		    sp->xid, sp->t_req, sp->t_end, dh, dp, da);
 	}
 	sp->xid = 0;
@@ -818,9 +818,9 @@ cnt_fetchbody(struct sess *sp)
 
 	hp2->logtag = HTTP_Obj;
 	http_CopyResp(hp2, hp);
-	http_FilterFields(sp->wrk, sp->fd, hp2, hp,
+	http_FilterFields(sp->wrk, sp->vsl_id, hp2, hp,
 	    pass ? HTTPH_R_PASS : HTTPH_A_INS);
-	http_CopyHome(sp->wrk, sp->fd, hp2);
+	http_CopyHome(sp->wrk, sp->vsl_id, hp2);
 
 	if (http_GetHdr(hp, H_Last_Modified, &b))
 		sp->obj->last_modified = TIM_parse(b);
@@ -968,7 +968,7 @@ cnt_first(struct sess *sp)
 	sp->ws_ses = WS_Snapshot(sp->ws);
 
 	/* Receive a HTTP protocol request */
-	HTC_Init(sp->htc, sp->ws, sp->fd, params->http_req_size,
+	HTC_Init(sp->htc, sp->ws, sp->fd, sp->vsl_id, params->http_req_size,
 	    params->http_req_hdr_len);
 	sp->wrk->lastused = sp->t_open;
 	sp->wrk->acct_tmp.sess++;
@@ -1537,12 +1537,11 @@ static void
 cnt_diag(struct sess *sp, const char *state)
 {
 	if (sp->wrk != NULL) {
-		WSL(sp->wrk, SLT_Debug, sp->id,
-		    "thr %p STP_%s sp %p obj %p vcl %p",
+		WSP(sp, SLT_Debug, "thr %p STP_%s sp %p obj %p vcl %p",
 		    pthread_self(), state, sp, sp->obj, sp->vcl);
 		WSL_Flush(sp->wrk, 0);
 	} else {
-		VSL(SLT_Debug, sp->id,
+		VSL(SLT_Debug, sp->vsl_id,
 		    "thr %p STP_%s sp %p obj %p vcl %p",
 		    pthread_self(), state, sp, sp->obj, sp->vcl);
 	}
diff --git a/bin/varnishd/cache_esi_deliver.c b/bin/varnishd/cache_esi_deliver.c
index ea4951f..8b2edba 100644
--- a/bin/varnishd/cache_esi_deliver.c
+++ b/bin/varnishd/cache_esi_deliver.c
@@ -105,7 +105,7 @@ ved_include(struct sess *sp, const char *src, const char *host)
 			break;
 		AZ(sp->wrk);
 		WSL_Flush(w, 0);
-		DSL(0x20, SLT_Debug, sp->id, "loop waiting for ESI");
+		DSL(0x20, SLT_Debug, sp->vsl_id, "loop waiting for ESI");
 		(void)usleep(10000);
 	}
 	sp->xid = sxid;
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index 73edaa1..6451f10 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -414,7 +414,7 @@ FetchHdr(struct sess *sp)
 
 	(void)VTCP_blocking(vc->fd);	/* XXX: we should timeout instead */
 	WRW_Reserve(w, &vc->fd);
-	(void)http_Write(w, hp, 0);	/* XXX: stats ? */
+	(void)http_Write(w, vc->vsl_id, hp, 0);	/* XXX: stats ? */
 
 	/* Deal with any message-body the request might have */
 	i = FetchReqBody(sp);
@@ -434,7 +434,7 @@ FetchHdr(struct sess *sp)
 
 	/* Receive response */
 
-	HTC_Init(w->htc, w->ws, vc->fd, params->http_resp_size,
+	HTC_Init(w->htc, w->ws, vc->fd, vc->vsl_id, params->http_resp_size,
 	    params->http_resp_hdr_len);
 
 	VTCP_set_read_timeout(vc->fd, vc->first_byte_timeout);
diff --git a/bin/varnishd/cache_hash.c b/bin/varnishd/cache_hash.c
index faf867a..58c3b6a 100644
--- a/bin/varnishd/cache_hash.c
+++ b/bin/varnishd/cache_hash.c
@@ -503,7 +503,7 @@ hsh_rush(struct objhead *oh)
 		CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 		AZ(sp->wrk);
 		VTAILQ_REMOVE(&wl->list, sp, list);
-		DSL(0x20, SLT_Debug, sp->id, "off waiting list");
+		DSL(0x20, SLT_Debug, sp->vsl_id, "off waiting list");
 		if (SES_Schedule(sp)) {
 			/*
 			 * We could not schedule the session, leave the
diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c
index f77ab74..587b6bb 100644
--- a/bin/varnishd/cache_http.c
+++ b/bin/varnishd/cache_http.c
@@ -77,10 +77,11 @@ http2shmlog(const struct http *hp, int t)
 }
 
 static void
-WSLH(struct worker *w, int fd, const struct http *hp, unsigned hdr)
+WSLH(struct worker *w, int vsl_id, const struct http *hp, unsigned hdr)
 {
 
-	WSLR(w, http2shmlog(hp, hdr), fd, hp->hd[hdr]);
+	AN(vsl_id & (VSL_CLIENTMARKER|VSL_BACKENDMARKER));
+	WSLR(w, http2shmlog(hp, hdr), vsl_id, hp->hd[hdr]);
 }
 
 /*--------------------------------------------------------------------*/
@@ -485,7 +486,7 @@ http_GetReq(const struct http *hp)
  */
 
 static uint16_t
-http_dissect_hdrs(struct worker *w, struct http *hp, int fd, char *p,
+http_dissect_hdrs(struct worker *w, struct http *hp, int vsl_id, char *p,
     const struct http_conn *htc)
 {
 	char *q, *r;
@@ -522,7 +523,7 @@ http_dissect_hdrs(struct worker *w, struct http *hp, int fd, char *p,
 
 		if (q - p > htc->maxhdr) {
 			VSC_C_main->losthdr++;
-			WSL(w, SLT_LostHeader, fd, "%.*s",
+			WSL(w, SLT_LostHeader, vsl_id, "%.*s",
 			    q - p > 20 ? 20 : q - p, p);
 			return (413);
 		}
@@ -544,11 +545,11 @@ http_dissect_hdrs(struct worker *w, struct http *hp, int fd, char *p,
 			hp->hdf[hp->nhd] = 0;
 			hp->hd[hp->nhd].b = p;
 			hp->hd[hp->nhd].e = q;
-			WSLH(w, fd, hp, hp->nhd);
+			WSLH(w, vsl_id, hp, hp->nhd);
 			hp->nhd++;
 		} else {
 			VSC_C_main->losthdr++;
-			WSL(w, SLT_LostHeader, fd, "%.*s",
+			WSL(w, SLT_LostHeader, vsl_id, "%.*s",
 			    q - p > 20 ? 20 : q - p, p);
 			return (413);
 		}
@@ -561,7 +562,7 @@ http_dissect_hdrs(struct worker *w, struct http *hp, int fd, char *p,
  */
 
 static uint16_t
-http_splitline(struct worker *w, int fd, struct http *hp,
+http_splitline(struct worker *w, int vsl_id, struct http *hp,
     const struct http_conn *htc, int h1, int h2, int h3)
 {
 	char *p, *q;
@@ -623,17 +624,17 @@ http_splitline(struct worker *w, int fd, struct http *hp,
 	p += vct_skipcrlf(p);
 
 	*hp->hd[h1].e = '\0';
-	WSLH(w, fd, hp, h1);
+	WSLH(w, vsl_id, hp, h1);
 
 	*hp->hd[h2].e = '\0';
-	WSLH(w, fd, hp, h2);
+	WSLH(w, vsl_id, hp, h2);
 
 	if (hp->hd[h3].e != NULL) {
 		*hp->hd[h3].e = '\0';
-		WSLH(w, fd, hp, h3);
+		WSLH(w, vsl_id, hp, h3);
 	}
 
-	return (http_dissect_hdrs(w, hp, fd, p, htc));
+	return (http_dissect_hdrs(w, hp, vsl_id, p, htc));
 }
 
 /*--------------------------------------------------------------------*/
@@ -668,7 +669,7 @@ http_DissectRequest(struct sess *sp)
 
 	hp->logtag = HTTP_Rx;
 
-	retval = http_splitline(sp->wrk, sp->fd, hp, htc,
+	retval = http_splitline(sp->wrk, sp->vsl_id, hp, htc,
 	    HTTP_HDR_REQ, HTTP_HDR_URL, HTTP_HDR_PROTO);
 	if (retval != 0) {
 		WSPR(sp, SLT_HttpGarbage, htc->rxbuf);
@@ -693,7 +694,7 @@ http_DissectResponse(struct worker *w, const struct http_conn *htc,
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	hp->logtag = HTTP_Rx;
 
-	if (http_splitline(w, htc->fd, hp, htc,
+	if (http_splitline(w, htc->vsl_id, hp, htc,
 	    HTTP_HDR_PROTO, HTTP_HDR_STATUS, HTTP_HDR_RESPONSE))
 		retval = 503;
 
@@ -719,7 +720,7 @@ http_DissectResponse(struct worker *w, const struct http_conn *htc,
 	}
 
 	if (retval != 0) {
-		WSLR(w, SLT_HttpGarbage, htc->fd, htc->rxbuf);
+		WSLR(w, SLT_HttpGarbage, htc->vsl_id, htc->rxbuf);
 		assert(retval >= 100 && retval <= 999);
 		hp->status = retval;
 	} else {
@@ -791,7 +792,7 @@ http_SetResp(struct http *to, const char *proto, uint16_t status,
 }
 
 static void
-http_copyheader(struct worker *w, int fd, struct http *to,
+http_copyheader(struct worker *w, int vsl_id, struct http *to,
     const struct http *fm, unsigned n)
 {
 
@@ -805,7 +806,7 @@ http_copyheader(struct worker *w, int fd, struct http *to,
 		to->nhd++;
 	} else  {
 		VSC_C_main->losthdr++;
-		WSLR(w, SLT_LostHeader, fd, fm->hd[n]);
+		WSLR(w, SLT_LostHeader, vsl_id, fm->hd[n]);
 	}
 }
 
@@ -842,7 +843,7 @@ http_EstimateWS(const struct http *fm, unsigned how, uint16_t *nhd)
 /*--------------------------------------------------------------------*/
 
 void
-http_FilterFields(struct worker *w, int fd, struct http *to,
+http_FilterFields(struct worker *w, int vsl_id, struct http *to,
     const struct http *fm, unsigned how)
 {
 	unsigned u;
@@ -861,7 +862,7 @@ http_FilterFields(struct worker *w, int fd, struct http *to,
 			continue;
 #include "http_headers.h"
 #undef HTTPH
-		http_copyheader(w, fd, to, fm, u);
+		http_copyheader(w, vsl_id, to, fm, u);
 	}
 }
 
@@ -882,8 +883,8 @@ http_FilterHeader(const struct sess *sp, unsigned how)
 		http_SetH(hp, HTTP_HDR_PROTO, "HTTP/1.1");
 	else
 		http_copyh(hp, sp->http, HTTP_HDR_PROTO);
-	http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
-	http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
+	http_FilterFields(sp->wrk, sp->vsl_id, hp, sp->http, how);
+	http_PrintfHeader(sp->wrk, sp->vsl_id, hp, "X-Varnish: %u", sp->xid);
 }
 
 /*--------------------------------------------------------------------
@@ -892,7 +893,7 @@ http_FilterHeader(const struct sess *sp, unsigned how)
  */
 
 void
-http_CopyHome(struct worker *w, int fd, const struct http *hp)
+http_CopyHome(struct worker *w, int vsl_id, const struct http *hp)
 {
 	unsigned u, l;
 	char *p;
@@ -901,20 +902,20 @@ http_CopyHome(struct worker *w, int fd, const struct http *hp)
 		if (hp->hd[u].b == NULL)
 			continue;
 		if (hp->hd[u].b >= hp->ws->s && hp->hd[u].e <= hp->ws->e) {
-			WSLH(w, fd, hp, u);
+			WSLH(w, vsl_id, hp, u);
 			continue;
 		}
 		l = Tlen(hp->hd[u]);
 		p = WS_Alloc(hp->ws, l + 1);
 		if (p != NULL) {
-			WSLH(w, fd, hp, u);
+			WSLH(w, vsl_id, hp, u);
 			memcpy(p, hp->hd[u].b, l + 1L);
 			hp->hd[u].b = p;
 			hp->hd[u].e = p + l;
 		} else {
 			/* XXX This leaves a slot empty */
 			VSC_C_main->losthdr++;
-			WSLR(w, SLT_LostHeader, fd, hp->hd[u]);
+			WSLR(w, SLT_LostHeader, vsl_id, hp->hd[u]);
 			hp->hd[u].b = NULL;
 			hp->hd[u].e = NULL;
 		}
@@ -938,13 +939,13 @@ http_ClrHeader(struct http *to)
 /*--------------------------------------------------------------------*/
 
 void
-http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr)
+http_SetHeader(struct worker *w, int vsl_id, struct http *to, const char *hdr)
 {
 
 	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
 	if (to->nhd >= to->shd) {
 		VSC_C_main->losthdr++;
-		WSL(w, SLT_LostHeader, fd, "%s", hdr);
+		WSL(w, SLT_LostHeader, vsl_id, "%s", hdr);
 		return;
 	}
 	http_SetH(to, to->nhd++, hdr);
@@ -953,7 +954,7 @@ http_SetHeader(struct worker *w, int fd, struct http *to, const char *hdr)
 /*--------------------------------------------------------------------*/
 
 static void
-http_PutField(struct worker *w, int fd, const struct http *to, int field,
+http_PutField(struct worker *w, int vsl_id, const struct http *to, int field,
     const char *string)
 {
 	char *p;
@@ -963,7 +964,7 @@ http_PutField(struct worker *w, int fd, const struct http *to, int field,
 	l = strlen(string);
 	p = WS_Alloc(to->ws, l + 1);
 	if (p == NULL) {
-		WSL(w, SLT_LostHeader, fd, "%s", string);
+		WSL(w, SLT_LostHeader, vsl_id, "%s", string);
 		to->hd[field].b = NULL;
 		to->hd[field].e = NULL;
 		to->hdf[field] = 0;
@@ -976,11 +977,11 @@ http_PutField(struct worker *w, int fd, const struct http *to, int field,
 }
 
 void
-http_PutProtocol(struct worker *w, int fd, const struct http *to,
+http_PutProtocol(struct worker *w, int vsl_id, const struct http *to,
     const char *protocol)
 {
 
-	http_PutField(w, fd, to, HTTP_HDR_PROTO, protocol);
+	http_PutField(w, vsl_id, to, HTTP_HDR_PROTO, protocol);
 }
 
 void
@@ -992,15 +993,15 @@ http_PutStatus(struct http *to, uint16_t status)
 }
 
 void
-http_PutResponse(struct worker *w, int fd, const struct http *to,
+http_PutResponse(struct worker *w, int vsl_id, const struct http *to,
     const char *response)
 {
 
-	http_PutField(w, fd, to, HTTP_HDR_RESPONSE, response);
+	http_PutField(w, vsl_id, to, HTTP_HDR_RESPONSE, response);
 }
 
 void
-http_PrintfHeader(struct worker *w, int fd, struct http *to,
+http_PrintfHeader(struct worker *w, int vsl_id, struct http *to,
     const char *fmt, ...)
 {
 	va_list ap;
@@ -1013,7 +1014,7 @@ http_PrintfHeader(struct worker *w, int fd, struct http *to,
 	va_end(ap);
 	if (n + 1 >= l || to->nhd >= to->shd) {
 		VSC_C_main->losthdr++;
-		WSL(w, SLT_LostHeader, fd, "%s", to->ws->f);
+		WSL(w, SLT_LostHeader, vsl_id, "%s", to->ws->f);
 		WS_Release(to->ws, 0);
 	} else {
 		to->hd[to->nhd].b = to->ws->f;
@@ -1063,14 +1064,13 @@ HTTP_Copy(struct http *to, const struct http * const fm)
 /*--------------------------------------------------------------------*/
 
 unsigned
-http_Write(struct worker *w, const struct http *hp, int resp)
+http_Write(struct worker *w, unsigned vsl_id, const struct http *hp, int resp)
 {
 	unsigned u, l;
-	int fd = *(w->wrw.wfd);
 
 	if (resp) {
 		l = WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], " ");
-		WSLH(w, fd, hp, HTTP_HDR_PROTO);
+		WSLH(w, vsl_id, hp, HTTP_HDR_PROTO);
 
 		hp->hd[HTTP_HDR_STATUS].b = WS_Alloc(w->ws, 4);
 		AN(hp->hd[HTTP_HDR_STATUS].b);
@@ -1079,18 +1079,18 @@ http_Write(struct worker *w, const struct http *hp, int resp)
 		hp->hd[HTTP_HDR_STATUS].e = hp->hd[HTTP_HDR_STATUS].b + 3;
 
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_STATUS], " ");
-		WSLH(w, fd, hp, HTTP_HDR_STATUS);
+		WSLH(w, vsl_id, hp, HTTP_HDR_STATUS);
 
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_RESPONSE], "\r\n");
-		WSLH(w, fd, hp, HTTP_HDR_RESPONSE);
+		WSLH(w, vsl_id, hp, HTTP_HDR_RESPONSE);
 	} else {
 		AN(hp->hd[HTTP_HDR_URL].b);
 		l = WRW_WriteH(w, &hp->hd[HTTP_HDR_REQ], " ");
-		WSLH(w, fd, hp, HTTP_HDR_REQ);
+		WSLH(w, vsl_id, hp, HTTP_HDR_REQ);
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_URL], " ");
-		WSLH(w, fd, hp, HTTP_HDR_URL);
+		WSLH(w, vsl_id, hp, HTTP_HDR_URL);
 		l += WRW_WriteH(w, &hp->hd[HTTP_HDR_PROTO], "\r\n");
-		WSLH(w, fd, hp, HTTP_HDR_PROTO);
+		WSLH(w, vsl_id, hp, HTTP_HDR_PROTO);
 	}
 	for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) {
 		if (hp->hd[u].b == NULL)
@@ -1098,7 +1098,7 @@ http_Write(struct worker *w, const struct http *hp, int resp)
 		AN(hp->hd[u].b);
 		AN(hp->hd[u].e);
 		l += WRW_WriteH(w, &hp->hd[u], "\r\n");
-		WSLH(w, fd, hp, u);
+		WSLH(w, vsl_id, hp, u);
 	}
 	l += WRW_Write(w, "\r\n", -1);
 	return (l);
diff --git a/bin/varnishd/cache_httpconn.c b/bin/varnishd/cache_httpconn.c
index 9d6d926..3ba5d7f 100644
--- a/bin/varnishd/cache_httpconn.c
+++ b/bin/varnishd/cache_httpconn.c
@@ -79,13 +79,14 @@ htc_header_complete(txt *t)
 /*--------------------------------------------------------------------*/
 
 void
-HTC_Init(struct http_conn *htc, struct ws *ws, int fd, unsigned maxbytes,
-    unsigned maxhdr)
+HTC_Init(struct http_conn *htc, struct ws *ws, int fd, unsigned vsl_id,
+    unsigned maxbytes, unsigned maxhdr)
 {
 
 	htc->magic = HTTP_CONN_MAGIC;
 	htc->ws = ws;
 	htc->fd = fd;
+	htc->vsl_id = vsl_id;
 	htc->maxbytes = maxbytes;
 	htc->maxhdr = maxhdr;
 	htc->error = "No error recorded";
diff --git a/bin/varnishd/cache_panic.c b/bin/varnishd/cache_panic.c
index b243832..8ca1b4f 100644
--- a/bin/varnishd/cache_panic.c
+++ b/bin/varnishd/cache_panic.c
@@ -216,7 +216,8 @@ pan_sess(const struct sess *sp)
 
 	VSB_printf(vsp, "sp = %p {\n", sp);
 	VSB_printf(vsp,
-	    "  fd = %d, id = %d, xid = %u,\n", sp->fd, sp->id, sp->xid);
+	    "  fd = %d, id = %d, xid = %u,\n",
+	    sp->fd, sp->vsl_id & VSL_IDENTMASK, sp->xid);
 	VSB_printf(vsp, "  client = %s %s,\n",
 	    sp->addr ? sp->addr : "?.?.?.?",
 	    sp->port ? sp->port : "?");
diff --git a/bin/varnishd/cache_pipe.c b/bin/varnishd/cache_pipe.c
index 3968767..ea5189d 100644
--- a/bin/varnishd/cache_pipe.c
+++ b/bin/varnishd/cache_pipe.c
@@ -78,7 +78,8 @@ PipeSession(struct sess *sp)
 	(void)VTCP_blocking(vc->fd);
 
 	WRW_Reserve(w, &vc->fd);
-	sp->wrk->acct_tmp.hdrbytes += http_Write(w, sp->wrk->bereq, 0);
+	sp->wrk->acct_tmp.hdrbytes +=
+	    http_Write(w, sp->vsl_id, sp->wrk->bereq, 0);
 
 	if (sp->htc->pipeline.b != NULL)
 		sp->wrk->acct_tmp.bodybytes +=
diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c
index eb2e62d..e490bbf 100644
--- a/bin/varnishd/cache_response.c
+++ b/bin/varnishd/cache_response.c
@@ -296,7 +296,7 @@ RES_WriteObj(struct sess *sp)
 	 */
 	if (!(sp->wrk->res_mode & RES_ESI_CHILD))
 		sp->wrk->acct_tmp.hdrbytes +=
-		    http_Write(sp->wrk, sp->wrk->resp, 1);
+		    http_Write(sp->wrk, sp->vsl_id, sp->wrk->resp, 1);
 
 	if (!sp->wantbody)
 		sp->wrk->res_mode &= ~RES_CHUNKED;
@@ -352,7 +352,7 @@ RES_StreamStart(struct sess *sp)
 		    "Content-Length: %s", sp->wrk->h_content_length);
 
 	sp->wrk->acct_tmp.hdrbytes +=
-	    http_Write(sp->wrk, sp->wrk->resp, 1);
+	    http_Write(sp->wrk, sp->vsl_id, sp->wrk->resp, 1);
 
 	if (sp->wrk->res_mode & RES_CHUNKED)
 		WRW_Chunked(sp->wrk);
diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index bbc5706..4956154 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -303,7 +303,7 @@ SES_Close(struct sess *sp, const char *reason)
 	int i;
 
 	assert(sp->fd >= 0);
-	VSL(SLT_SessionClose, sp->id, "%s", reason);
+	VSL(SLT_SessionClose, sp->vsl_id, "%s", reason);
 	i = close(sp->fd);
 	assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */
 	sp->fd = -1;
@@ -352,7 +352,7 @@ SES_Delete(struct sess *sp, const char *reason)
 	assert(!isnan(b->first));
 	assert(!isnan(sp->t_end));
 
-	VSL(SLT_StatSess, sp->id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju",
+	VSL(SLT_StatSess, sp->vsl_id, "%s %s %.0f %ju %ju %ju %ju %ju %ju %ju",
 	    sp->addr, sp->port, sp->t_end - b->first,
 	    b->sess, b->req, b->pipe, b->pass,
 	    b->fetch, b->hdrbytes, b->bodybytes);
diff --git a/bin/varnishd/cache_waiter_kqueue.c b/bin/varnishd/cache_waiter_kqueue.c
index 6e2cb05..9575dc8 100644
--- a/bin/varnishd/cache_waiter_kqueue.c
+++ b/bin/varnishd/cache_waiter_kqueue.c
@@ -80,7 +80,7 @@ vwk_kq_sess(struct vwk *vwk, struct sess *sp, short arm)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	assert(sp->fd >= 0);
-	DSL(0x04, SLT_Debug, sp->fd, "KQ: EV_SET sp %p arm %x", sp, arm);
+	DSL(0x04, SLT_Debug, sp->vsl_id, "KQ: EV_SET sp %p arm %x", sp, arm);
 	EV_SET(&vwk->ki[vwk->nki], sp->fd, EVFILT_READ, arm, 0, 0, sp);
 	if (++vwk->nki == NKEV)
 		vwk_kq_flush(vwk);
@@ -112,12 +112,12 @@ vwk_kev(struct vwk *vwk, const struct kevent *kp)
 		return;
 	}
 	CAST_OBJ_NOTNULL(sp, kp->udata, SESS_MAGIC);
-	DSL(0x04, SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
+	DSL(0x04, SLT_Debug, sp->vsl_id, "KQ: sp %p kev data %lu flags 0x%x%s",
 	    sp, (unsigned long)kp->data, kp->flags,
 	    (kp->flags & EV_EOF) ? " EOF" : "");
 
-	assert(sp->id == kp->ident);
-	assert(sp->fd == sp->id);
+	assert((sp->vsl_id & VSL_IDENTMASK) == kp->ident);
+	assert((sp->vsl_id & VSL_IDENTMASK) == sp->fd);
 	if (kp->data > 0) {
 		i = HTC_Rx(sp->htc);
 		if (i == 0) {
@@ -132,7 +132,7 @@ vwk_kev(struct vwk *vwk, const struct kevent *kp)
 		SES_Delete(sp, "EOF");
 		return;
 	} else {
-		VSL(SLT_Debug, sp->id, "KQ: sp %p kev data %lu flags 0x%x%s",
+		VSL(SLT_Debug, sp->vsl_id, "KQ: sp %p kev data %lu flags 0x%x%s",
 		    sp, (unsigned long)kp->data, kp->flags,
 		    (kp->flags & EV_EOF) ? " EOF" : "");
 	}
diff --git a/include/vsl.h b/include/vsl.h
index 45406c0..7f771ce 100644
--- a/include/vsl.h
+++ b/include/vsl.h
@@ -50,12 +50,18 @@
  *	[n + 2] ... [m]	= content
  */
 
+#define VSL_CLIENTMARKER	(1U<<30)
+#define VSL_BACKENDMARKER	(1U<<31)
+#define VSL_IDENTMASK		(~(3U<<30))
+
 #define VSL_WORDS(len)		(((len) + 3) / 4)
 #define VSL_END(ptr, len)	((ptr) + 2 + VSL_WORDS(len))
 #define VSL_NEXT(ptr)		VSL_END(ptr, VSL_LEN(ptr))
 #define VSL_LEN(ptr)		((ptr)[0] & 0xffff)
 #define VSL_TAG(ptr)		((ptr)[0] >> 24)
-#define VSL_ID(ptr)		((ptr)[1])
+#define VSL_ID(ptr)		(((ptr)[1]) & VSL_IDENTMASK)
+#define VSL_CLIENT(ptr)		(((ptr)[1]) & VSL_CLIENTMARKER)
+#define VSL_BACKEND(ptr)	(((ptr)[1]) & VSL_BACKENDMARKER)
 #define VSL_DATA(ptr)		((char*)((ptr)+2))
 
 #define VSL_ENDMARKER	(((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index 8473d31..a34ea1e 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -75,8 +75,6 @@ VSL_Setup(struct VSM_data *vd)
 	vsl->regflags = 0;
 
 	/* XXX: Allocate only if log access */
-	vsl->vbm_client = vbit_init(4096);
-	vsl->vbm_backend = vbit_init(4096);
 	vsl->vbm_supress = vbit_init(256);
 	vsl->vbm_select = vbit_init(256);
 
@@ -102,8 +100,6 @@ VSL_Delete(struct VSM_data *vd)
 	vd->vsl = NULL;
 	CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
 
-	vbit_destroy(vsl->vbm_client);
-	vbit_destroy(vsl->vbm_backend);
 	vbit_destroy(vsl->vbm_supress);
 	vbit_destroy(vsl->vbm_select);
 	free(vsl->rbuf);
@@ -232,20 +228,6 @@ VSL_NextLog(const struct VSM_data *vd, uint32_t **pp, uint64_t *bits)
 			return (i);
 		u = VSL_ID(p);
 		t = VSL_TAG(p);
-		switch(t) {
-		case SLT_SessionOpen:
-		case SLT_ReqStart:
-			vbit_set(vsl->vbm_client, u);
-			vbit_clr(vsl->vbm_backend, u);
-			break;
-		case SLT_BackendOpen:
-		case SLT_BackendXID:
-			vbit_clr(vsl->vbm_client, u);
-			vbit_set(vsl->vbm_backend, u);
-			break;
-		default:
-			break;
-		}
 		if (vsl->skip) {
 			--vsl->skip;
 			continue;
@@ -260,9 +242,9 @@ VSL_NextLog(const struct VSM_data *vd, uint32_t **pp, uint64_t *bits)
 		}
 		if (vbit_test(vsl->vbm_supress, t))
 			continue;
-		if (vsl->b_opt && !vbit_test(vsl->vbm_backend, u))
+		if (vsl->b_opt && !VSL_BACKEND(p))
 			continue;
-		if (vsl->c_opt && !vbit_test(vsl->vbm_client, u))
+		if (vsl->c_opt && !VSL_CLIENT(p))
 			continue;
 		if (vsl->regincl != NULL) {
 			i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p),
@@ -319,10 +301,10 @@ VSL_Dispatch(struct VSM_data *vd, VSL_handler_f *func, void *priv)
 		u = VSL_ID(p);
 		l = VSL_LEN(p);
 		s = 0;
-		if (vbit_test(vsl->vbm_backend, u))
-			s |= VSL_S_BACKEND;
-		if (vbit_test(vsl->vbm_client, u))
+		if (VSL_CLIENT(p))
 			s |= VSL_S_CLIENT;
+		if (VSL_BACKEND(p))
+			s |= VSL_S_BACKEND;
 		if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p), bitmap))
 			return (1);
 	}
diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h
index e1684fd..aa3d0f4 100644
--- a/lib/libvarnishapi/vsl_api.h
+++ b/lib/libvarnishapi/vsl_api.h
@@ -64,13 +64,6 @@ struct vsl {
 #define F_NON_BLOCKING		(1 << 1)
 
 	/*
-	 * These two bitmaps mark fd's as belonging to client or backend
-	 * transactions respectively.
-	 */
-	struct vbitmap		*vbm_client;
-	struct vbitmap		*vbm_backend;
-
-	/*
 	 * Bit map of programatically selected tags, that cannot be suppressed.
 	 * This way programs can make sure they will see certain tags, even
 	 * if the user tries to supress them with -x/-X



More information about the varnish-commit mailing list