From dridi.boukelmoune at gmail.com Mon Jul 6 06:36:21 2015 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Mon, 06 Jul 2015 08:36:21 +0200 Subject: [master] 6692ff9 Typo Message-ID: commit 6692ff9e83a824785a4e7db4ac3c8dd414622e0c Author: Dridi Boukelmoune Date: Mon Jul 6 08:02:22 2015 +0200 Typo diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 7ed2673..bd8a8c5 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -241,7 +241,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk, /* * If we recycled a backend connection, there is a finite chance * that the backend closed it before we got the bereq to it. - * In that case do a single automatic retry if req.boy allows. + * In that case do a single automatic retry if req.body allows. */ vbe_dir_finish(d, wrk, bo); AZ(bo->htc); From lkarsten at varnish-software.com Mon Jul 6 12:33:08 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Mon, 06 Jul 2015 14:33:08 +0200 Subject: [master] 1625f9c Reformat JSON output for 80 character width. Message-ID: commit 1625f9c778165a3e65909f5d4fdc9d9cfb320b6b Author: Lasse Karstensen Date: Mon Jul 6 14:22:46 2015 +0200 Reformat JSON output for 80 character width. This output was very wide and hard to get any sense out of without actually reading it closely. The things you are interested in, typically counter name, description and value, are now on separate lines. In addition the output should now fit nicely on any VT100 terminals in 80 character mode, I'm sure there are some still in use somewhere. JSON document layout (key names, hierarchy) is the same as before. diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c index cfa819f..871aca7 100644 --- a/bin/varnishstat/varnishstat.c +++ b/bin/varnishstat/varnishstat.c @@ -113,22 +113,23 @@ do_json_cb(void *priv, const struct VSC_point * const pt) else printf(",\n"); - printf("\t\""); + printf(" \""); /* build the JSON key name. */ if (sec->fantom->type[0]) printf("%s.", sec->fantom->type); if (sec->fantom->ident[0]) printf("%s.", sec->fantom->ident); - printf("%s\": {", pt->desc->name); + printf("%s\": {\n", pt->desc->name); + printf(" \"description\": \"%s\",\n", pt->desc->sdesc); + if (strcmp(sec->fantom->type, "")) - printf("\"type\": \"%s\", ", sec->fantom->type); + printf(" \"type\": \"%s\", ", sec->fantom->type); if (strcmp(sec->fantom->ident, "")) printf("\"ident\": \"%s\", ", sec->fantom->ident); - printf("\"value\": %ju, ", (uintmax_t)val); printf("\"flag\": \"%c\", ", pt->desc->semantics); - printf("\"format\": \"%c\", ", pt->desc->format); - printf("\"description\": \"%s\"", pt->desc->sdesc); - printf("}"); + printf("\"format\": \"%c\",\n", pt->desc->format); + printf(" \"value\": %ju", (uintmax_t)val); + printf("\n }"); if (*jp) printf("\n"); @@ -148,7 +149,7 @@ do_json(struct VSM_data *vd) now = time(NULL); (void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now)); - printf("\t\"timestamp\": \"%s\",\n", time_stamp); + printf(" \"timestamp\": \"%s\",\n", time_stamp); (void)VSC_Iter(vd, NULL, do_json_cb, &jp); printf("\n}\n"); fflush(stdout); From lkarsten at varnish-software.com Mon Jul 6 14:34:57 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Mon, 06 Jul 2015 16:34:57 +0200 Subject: [master] 9de59a0 Update the documented JSON output format. Message-ID: commit 9de59a05cebe9e90e011dca4c0e00b47e3289b99 Author: Lasse Karstensen Date: Mon Jul 6 16:34:07 2015 +0200 Update the documented JSON output format. diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst index 8bef6e6..9213baf 100644 --- a/doc/sphinx/reference/varnishstat.rst +++ b/doc/sphinx/reference/varnishstat.rst @@ -71,7 +71,7 @@ The following options are available: -x Displays the result as XML. --j +-j Displays the result as JSON. CURSES MODE @@ -181,10 +181,20 @@ With -j the output format is:: { "timestamp": "YYYY-MM-DDTHH:mm:SS", - "FIELD NAME": {"type": "FIELD TYPE", "ident": "FIELD IDENT", "value": FIELD VALUE, "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", "description": "FIELD DESCRIPTION"}, + "FIELD NAME": { + "description": "FIELD DESCRIPTION", + "type": "FIELD TYPE", "ident": "FIELD IDENT", "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", + "value": FIELD VALUE, + }, + "FIELD2 NAME": { + "description": "FIELD2 DESCRIPTION", + "type": "FIELD2 TYPE", "ident": "FIELD2 IDENT", "flag": "FIELD2 SEMANTICS", "format": "FIELD2 DISPLAY FORMAT", + "value": FIELD2 VALUE, + }, [..] } + Type and ident are optional. Timestamp is the time when the report was generated by varnishstat. From phk at FreeBSD.org Mon Jul 6 20:39:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 06 Jul 2015 22:39:46 +0200 Subject: [master] faf45b5 white space nit Message-ID: commit faf45b5429b8f6f8302db81472a2d716b5280e77 Author: Poul-Henning Kamp Date: Mon Jul 6 20:01:20 2015 +0000 white space nit diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c index 20a636c..b12cea3 100644 --- a/bin/varnishd/waiter/cache_waiter_ports.c +++ b/bin/varnishd/waiter/cache_waiter_ports.c @@ -263,7 +263,7 @@ const struct waiter_impl waiter_ports = { .name = "ports", .init = vws_init, .fini = vws_fini, - .enter = vws_enter, + .enter = vws_enter, .size = sizeof(struct vws), }; From phk at FreeBSD.org Mon Jul 6 20:39:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 06 Jul 2015 22:39:46 +0200 Subject: [master] 031bed0 Split Wait_HeapDelete() out from Wait_Call(). Message-ID: commit 031bed01836063a784c46df5ba077a61669c0a35 Author: Poul-Henning Kamp Date: Mon Jul 6 20:30:18 2015 +0000 Split Wait_HeapDelete() out from Wait_Call(). diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c index 7d23da5..b1d0801 100644 --- a/bin/varnishd/waiter/cache_waiter.c +++ b/bin/varnishd/waiter/cache_waiter.c @@ -67,15 +67,13 @@ waited_update(void *priv, void *p, unsigned u) /**********************************************************************/ void -Wait_Call(const struct waiter *w, - struct waited *wp, enum wait_event ev, double now) +Wait_Call(const struct waiter *w, struct waited *wp, + enum wait_event ev, double now) { CHECK_OBJ_NOTNULL(w, WAITER_MAGIC); CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); CHECK_OBJ_NOTNULL(wp->waitfor, WAITFOR_MAGIC); AN(wp->waitfor->func); - if (wp->idx != BINHEAP_NOIDX) - binheap_delete(w->heap, wp->idx); assert(wp->idx == BINHEAP_NOIDX); wp->waitfor->func(wp, ev, now); } @@ -91,6 +89,23 @@ Wait_HeapInsert(const struct waiter *w, struct waited *wp) binheap_insert(w->heap, wp); } +/* + * XXX: wp is const because otherwise FlexeLint complains. However, *wp + * XXX: will actually change as a result of calling this function, via + * XXX: the pointer stored in the bin-heap. I can see how this const + * XXX: could maybe confuse a compilers optimizer, but I do not expect + * XXX: any harm to come from it. Caveat Emptor. + */ + +void +Wait_HeapDelete(const struct waiter *w, const struct waited *wp) +{ + CHECK_OBJ_NOTNULL(w, WAITER_MAGIC); + CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); + if (wp->idx != BINHEAP_NOIDX) + binheap_delete(w->heap, wp->idx); +} + double Wait_HeapDue(const struct waiter *w, struct waited **wpp) { diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c index 47b036f..9eeec23 100644 --- a/bin/varnishd/waiter/cache_waiter_epoll.c +++ b/bin/varnishd/waiter/cache_waiter_epoll.c @@ -102,6 +102,7 @@ vwe_thread(void *priv) CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL)); vwe->nwaited--; + Wait_HeapDelete(w, wp); Wait_Call(w, wp, WAITER_TIMEOUT, now); } then = vwe->next - now; @@ -119,6 +120,7 @@ vwe_thread(void *priv) continue; } CAST_OBJ_NOTNULL(wp, ep->data.ptr, WAITED_MAGIC); + Wait_HeapDelete(w, wp); AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL)); vwe->nwaited--; if (ep->events & EPOLLIN) diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index baeed5c..63bf794 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -97,6 +97,7 @@ vwk_thread(void *priv) CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); EV_SET(ke, wp->fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); AZ(kevent(vwk->kq, ke, 1, NULL, 0, NULL)); + Wait_HeapDelete(w, wp); Wait_Call(w, wp, WAITER_TIMEOUT, now); } then = vwk->next - now; @@ -115,6 +116,7 @@ vwk_thread(void *priv) continue; } CAST_OBJ_NOTNULL(wp, ke[j].udata, WAITED_MAGIC); + Wait_HeapDelete(w, wp); vwk->nwaited--; if (kp->flags & EV_EOF) Wait_Call(w, wp, WAITER_REMCLOSE, now); diff --git a/bin/varnishd/waiter/cache_waiter_poll.c b/bin/varnishd/waiter/cache_waiter_poll.c index 471d9e7..72c97fb 100644 --- a/bin/varnishd/waiter/cache_waiter_poll.c +++ b/bin/varnishd/waiter/cache_waiter_poll.c @@ -156,15 +156,17 @@ vwp_main(void *priv) { int v; struct vwp *vwp; + struct waiter *w; struct waited *wp; double now, then; int i; THR_SetName("cache-poll"); CAST_OBJ_NOTNULL(vwp, priv, VWP_MAGIC); + w = vwp->waiter; while (1) { - then = Wait_HeapDue(vwp->waiter, &wp); + then = Wait_HeapDue(w, &wp); if (wp == NULL) i = -1; else @@ -179,18 +181,20 @@ vwp_main(void *priv) wp = vwp->idx[i]; CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); - if (v == 0 && Wait_HeapDue(vwp->waiter, NULL) > now) + if (v == 0 && Wait_HeapDue(w, NULL) > now) break; if (vwp->pollfd[i].revents) v--; then = Wait_When(wp); if (then <= now) { - Wait_Call(vwp->waiter, wp, WAITER_TIMEOUT, now); + Wait_HeapDelete(w, wp); + Wait_Call(w, wp, WAITER_TIMEOUT, now); vwp_del(vwp, i); } else if (vwp->pollfd[i].revents & POLLIN) { assert(wp->fd > 0); assert(wp->fd == vwp->pollfd[i].fd); - Wait_Call(vwp->waiter, wp, WAITER_ACTION, now); + Wait_HeapDelete(w, wp); + Wait_Call(w, wp, WAITER_ACTION, now); vwp_del(vwp, i); } else { i++; diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c index b12cea3..0a647ef 100644 --- a/bin/varnishd/waiter/cache_waiter_ports.c +++ b/bin/varnishd/waiter/cache_waiter_ports.c @@ -126,6 +126,7 @@ vws_port_ev(struct vws *vws, struct waiter *w, port_event_t *ev, double now) { * threadID=129476&tstart=0 */ vws_del(vws, wp->fd); + Wait_HeapDelete(w, wp); Wait_Call(w, wp, ev->portev_events & POLLERR ? WAITER_REMCLOSE : WAITER_ACTION, now); diff --git a/bin/varnishd/waiter/waiter_priv.h b/bin/varnishd/waiter/waiter_priv.h index f4e5261..c7d1d25 100644 --- a/bin/varnishd/waiter/waiter_priv.h +++ b/bin/varnishd/waiter/waiter_priv.h @@ -78,4 +78,5 @@ Wait_When(const struct waited *wp) void Wait_Call(const struct waiter *, struct waited *, enum wait_event ev, double now); void Wait_HeapInsert(const struct waiter *, struct waited *); +void Wait_HeapDelete(const struct waiter *, const struct waited *); double Wait_HeapDue(const struct waiter *, struct waited **); From phk at FreeBSD.org Mon Jul 6 20:39:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 06 Jul 2015 22:39:46 +0200 Subject: [master] 95aeadd Don't hold waiters mutex'en over Waiter_Call() since they are also held over Wait_Enter() processing, and that makes it impossible for the code using the waiter to avoid one deadlock or another. Message-ID: commit 95aeadd2d421aad7fccd3fcf666a8fe52920b457 Author: Poul-Henning Kamp Date: Mon Jul 6 20:37:29 2015 +0000 Don't hold waiters mutex'en over Waiter_Call() since they are also held over Wait_Enter() processing, and that makes it impossible for the code using the waiter to avoid one deadlock or another. Depending on what the call-back code does, this may increase or decrease contests for the waiters mutex. diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c index 9eeec23..e60d55a 100644 --- a/bin/varnishd/waiter/cache_waiter_epoll.c +++ b/bin/varnishd/waiter/cache_waiter_epoll.c @@ -84,9 +84,9 @@ vwe_thread(void *priv) THR_SetName("cache-epoll"); now = VTIM_real(); - Lck_Lock(&vwe->mtx); while (1) { while (1) { + Lck_Lock(&vwe->mtx); /* * XXX: We could avoid many syscalls here if we were * XXX: allowed to just close the fd's on timeout. @@ -103,6 +103,7 @@ vwe_thread(void *priv) AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL)); vwe->nwaited--; Wait_HeapDelete(w, wp); + Lck_Unlock(&vwe->mtx); Wait_Call(w, wp, WAITER_TIMEOUT, now); } then = vwe->next - now; @@ -113,14 +114,15 @@ vwe_thread(void *priv) assert(n >= 0); assert(n <= NEEV); now = VTIM_real(); - Lck_Lock(&vwe->mtx); for (ep = ev, i = 0; i < n; i++, ep++) { if (ep->data.ptr == vwe) { assert(read(vwe->pipe[0], &c, 1) == 1); continue; } CAST_OBJ_NOTNULL(wp, ep->data.ptr, WAITED_MAGIC); + Lck_Lock(&vwe->mtx); Wait_HeapDelete(w, wp); + Lck_Unlock(&vwe->mtx); AZ(epoll_ctl(vwe->epfd, EPOLL_CTL_DEL, wp->fd, NULL)); vwe->nwaited--; if (ep->events & EPOLLIN) @@ -135,7 +137,6 @@ vwe_thread(void *priv) if (vwe->nwaited == 0 && vwe->die) break; } - Lck_Unlock(&vwe->mtx); AZ(close(vwe->pipe[0])); AZ(close(vwe->pipe[1])); AZ(close(vwe->epfd)); diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index 63bf794..1b7e6a0 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -79,9 +79,9 @@ vwk_thread(void *priv) THR_SetName("cache-kqueue"); now = VTIM_real(); - Lck_Lock(&vwk->mtx); while (1) { while (1) { + Lck_Lock(&vwk->mtx); /* * XXX: We could avoid many syscalls here if we were * XXX: allowed to just close the fd's on timeout. @@ -98,6 +98,7 @@ vwk_thread(void *priv) EV_SET(ke, wp->fd, EVFILT_READ, EV_DELETE, 0, 0, NULL); AZ(kevent(vwk->kq, ke, 1, NULL, 0, NULL)); Wait_HeapDelete(w, wp); + Lck_Unlock(&vwk->mtx); Wait_Call(w, wp, WAITER_TIMEOUT, now); } then = vwk->next - now; @@ -108,7 +109,6 @@ vwk_thread(void *priv) assert(n >= 0); assert(n <= NKEV); now = VTIM_real(); - Lck_Lock(&vwk->mtx); for (kp = ke, j = 0; j < n; j++, kp++) { assert(kp->filter == EVFILT_READ); if (ke[j].udata == vwk) { @@ -116,7 +116,9 @@ vwk_thread(void *priv) continue; } CAST_OBJ_NOTNULL(wp, ke[j].udata, WAITED_MAGIC); + Lck_Lock(&vwk->mtx); Wait_HeapDelete(w, wp); + Lck_Unlock(&vwk->mtx); vwk->nwaited--; if (kp->flags & EV_EOF) Wait_Call(w, wp, WAITER_REMCLOSE, now); @@ -126,7 +128,6 @@ vwk_thread(void *priv) if (vwk->nwaited == 0 && vwk->die) break; } - Lck_Unlock(&vwk->mtx); AZ(close(vwk->pipe[0])); AZ(close(vwk->pipe[1])); AZ(close(vwk->kq)); From phk at FreeBSD.org Tue Jul 7 09:41:13 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 07 Jul 2015 11:41:13 +0200 Subject: [master] 573016e Rename the "misc" lock class to "waiter" Message-ID: commit 573016ec21be8b0eff97ab3032bfef4a45d02631 Author: Poul-Henning Kamp Date: Tue Jul 7 09:31:19 2015 +0000 Rename the "misc" lock class to "waiter" Give the backend tcp-pools their own lock class instead of mixing them up with the backend lock class. diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c index 3e99387..13a026c 100644 --- a/bin/varnishd/cache/cache_backend_tcp.c +++ b/bin/varnishd/cache/cache_backend_tcp.c @@ -158,7 +158,7 @@ VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6) if (ip6 != NULL) tp->ip6 = VSA_Clone(ip6); tp->refcnt = 1; - Lck_New(&tp->mtx, lck_backend); + Lck_New(&tp->mtx, lck_backend_tcp); VTAILQ_INIT(&tp->connlist); VTAILQ_INIT(&tp->killlist); VTAILQ_INSERT_HEAD(&pools, tp, list); diff --git a/bin/varnishd/waiter/cache_waiter_epoll.c b/bin/varnishd/waiter/cache_waiter_epoll.c index e60d55a..cb6dbdc 100644 --- a/bin/varnishd/waiter/cache_waiter_epoll.c +++ b/bin/varnishd/waiter/cache_waiter_epoll.c @@ -180,7 +180,7 @@ vwe_init(struct waiter *w) vwe->epfd = epoll_create(1); assert(vwe->epfd >= 0); - Lck_New(&vwe->mtx, lck_misc); + Lck_New(&vwe->mtx, lck_waiter); AZ(pipe(vwe->pipe)); ee.events = EPOLLIN | EPOLLRDHUP; ee.data.ptr = vwe; diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index 1b7e6a0..02d7adc 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -172,7 +172,7 @@ vwk_init(struct waiter *w) vwk->kq = kqueue(); assert(vwk->kq >= 0); - Lck_New(&vwk->mtx, lck_misc); + Lck_New(&vwk->mtx, lck_waiter); AZ(pipe(vwk->pipe)); EV_SET(&ke, vwk->pipe[0], EVFILT_READ, EV_ADD, 0, 0, vwk); AZ(kevent(vwk->kq, &ke, 1, NULL, 0, NULL)); diff --git a/include/tbl/locks.h b/include/tbl/locks.h index 7331493..8fe77fe 100644 --- a/include/tbl/locks.h +++ b/include/tbl/locks.h @@ -29,6 +29,7 @@ /*lint -save -e525 -e539 */ LOCK(backend) +LOCK(backend_tcp) LOCK(ban) LOCK(busyobj) LOCK(cli) @@ -38,7 +39,6 @@ LOCK(hcl) LOCK(hsl) LOCK(lru) LOCK(mempool) -LOCK(misc) LOCK(objhdr) LOCK(pipestat) LOCK(sess) @@ -49,6 +49,7 @@ LOCK(vbe) LOCK(vcapace) LOCK(vcl) LOCK(vxid) +LOCK(waiter) LOCK(wq) LOCK(wstat) /*lint -restore */ From phk at FreeBSD.org Tue Jul 7 09:41:13 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 07 Jul 2015 11:41:13 +0200 Subject: [master] c1f19f9 Add an offline, default-off lock-order "Witness" facility, to make sure I have not added any other lock-order reversals. Message-ID: commit c1f19f98c37f878a1846b6209c358f22e7eb5118 Author: Poul-Henning Kamp Date: Tue Jul 7 09:36:17 2015 +0000 Add an offline, default-off lock-order "Witness" facility, to make sure I have not added any other lock-order reversals. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index b96d765..522fad2 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -849,6 +849,7 @@ unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*); #define VXID(u) ((u) & VSL_IDENTMASK) uint32_t VXID_Get(struct worker *, uint32_t marker); extern volatile struct params * cache_param; +extern pthread_key_t witness_key; void THR_SetName(const char *name); const char* THR_GetName(void); void THR_SetBusyobj(const struct busyobj *); @@ -859,9 +860,9 @@ struct req * THR_GetRequest(void); /* cache_lck.c */ /* Internal functions, call only through macros below */ -void Lck__Lock(struct lock *lck, const char *p, const char *f, int l); -void Lck__Unlock(struct lock *lck, const char *p, const char *f, int l); -int Lck__Trylock(struct lock *lck, const char *p, const char *f, int l); +void Lck__Lock(struct lock *lck, const char *p, int l); +void Lck__Unlock(struct lock *lck, const char *p, int l); +int Lck__Trylock(struct lock *lck, const char *p, int l); void Lck__New(struct lock *lck, struct VSC_C_lck *, const char *); void Lck__Assert(const struct lock *lck, int held); @@ -871,9 +872,9 @@ void Lck_Delete(struct lock *lck); int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double); #define Lck_New(a, b) Lck__New(a, b, #b) -#define Lck_Lock(a) Lck__Lock(a, __func__, __FILE__, __LINE__) -#define Lck_Unlock(a) Lck__Unlock(a, __func__, __FILE__, __LINE__) -#define Lck_Trylock(a) Lck__Trylock(a, __func__, __FILE__, __LINE__) +#define Lck_Lock(a) Lck__Lock(a, __func__, __LINE__) +#define Lck_Unlock(a) Lck__Unlock(a, __func__, __LINE__) +#define Lck_Trylock(a) Lck__Trylock(a, __func__, __LINE__) #define Lck_AssertHeld(a) Lck__Assert(a, 1) #define LOCK(nam) extern struct VSC_C_lck *lck_##nam; diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c index caac924..c623ab7 100644 --- a/bin/varnishd/cache/cache_lck.c +++ b/bin/varnishd/cache/cache_lck.c @@ -37,6 +37,7 @@ #include #include +#include #include "cache.h" @@ -59,16 +60,63 @@ static VTAILQ_HEAD(, ilck) ilck_head = VTAILQ_HEAD_INITIALIZER(ilck_head); static pthread_mutex_t lck_mtx; +/*--------------------------------------------------------------------*/ + +static void +Lck_Witness_Lock(const struct ilck *il, const char *p, int l, const char *try) +{ + char *q, t[10]; + int emit; + + AN(p); + q = pthread_getspecific(witness_key); + if (q == NULL) { + q = calloc(1, 1024); + AN(q); + AZ(pthread_setspecific(witness_key, q)); + } + emit = *q != '\0'; + strcat(q, " "); + strcat(q, il->w); + strcat(q, try); + strcat(q, ","); + strcat(q, p); + strcat(q, ","); + bprintf(t, "%d", l); + strcat(q, t); + if (emit) + VSL(SLT_Witness, 0, "%s", q); +} + +static void +Lck_Witness_Unlock(const struct ilck *il) +{ + char *q, *r; + + q = pthread_getspecific(witness_key); + if (q == NULL) + return; + r = strrchr(q, ' '); + if (r == NULL) + r = q; + else + *r++ = '\0'; + if (memcmp(r, il->w, strlen(il->w))) + VSL(SLT_Witness, 0, "Unlock %s @ %s <%s>", il->w, r, q); + else + *r = '\0'; +} + +/*--------------------------------------------------------------------*/ + void __match_proto__() -Lck__Lock(struct lock *lck, const char *p, const char *f, int l) +Lck__Lock(struct lock *lck, const char *p, int l) { struct ilck *ilck; - (void)p; - (void)f; - (void)l; - CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + if (DO_DEBUG(DBG_WITNESS)) + Lck_Witness_Lock(ilck, p, l, ""); AZ(pthread_mutex_lock(&ilck->mtx)); AZ(ilck->held); ilck->stat->locks++; @@ -77,12 +125,11 @@ Lck__Lock(struct lock *lck, const char *p, const char *f, int l) } void __match_proto__() -Lck__Unlock(struct lock *lck, const char *p, const char *f, int l) +Lck__Unlock(struct lock *lck, const char *p, int l) { struct ilck *ilck; (void)p; - (void)f; (void)l; CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); @@ -101,19 +148,19 @@ Lck__Unlock(struct lock *lck, const char *p, const char *f, int l) */ memset(&ilck->owner, 0, sizeof ilck->owner); AZ(pthread_mutex_unlock(&ilck->mtx)); + if (DO_DEBUG(DBG_WITNESS)) + Lck_Witness_Unlock(ilck); } int __match_proto__() -Lck__Trylock(struct lock *lck, const char *p, const char *f, int l) +Lck__Trylock(struct lock *lck, const char *p, int l) { struct ilck *ilck; int r; - (void)p; - (void)f; - (void)l; - CAST_OBJ_NOTNULL(ilck, lck->priv, ILCK_MAGIC); + if (DO_DEBUG(DBG_WITNESS)) + Lck_Witness_Lock(ilck, p, l, "?"); r = pthread_mutex_trylock(&ilck->mtx); assert(r == 0 || r == EBUSY); if (r == 0) { diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index cb5175a..f95bc77 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -51,6 +51,7 @@ volatile struct params *cache_param; static pthread_key_t req_key; static pthread_key_t bo_key; +pthread_key_t witness_key; void THR_SetBusyobj(const struct busyobj *bo) @@ -199,6 +200,7 @@ child_main(void) AZ(pthread_key_create(&req_key, NULL)); AZ(pthread_key_create(&bo_key, NULL)); + AZ(pthread_key_create(&witness_key, NULL)); AZ(pthread_key_create(&name_key, NULL)); THR_SetName("cache-main"); diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 17b5790..f2817d8 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -70,6 +70,7 @@ extern int vtc_stop; /* Abandon current test, no error */ extern pthread_t vtc_thread; extern int iflg; extern unsigned vtc_maxdur; +extern int vtc_witness; void init_sema(void); void init_server(void); diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c index a2b34e0..ce50c6b 100644 --- a/bin/varnishtest/vtc_main.c +++ b/bin/varnishtest/vtc_main.c @@ -88,6 +88,7 @@ static int vtc_fail; static int leave_temp; static char *tmppath; static char *cwd = NULL; +int vtc_witness = 0; /********************************************************************** * Parse a -D option argument into a name/val pair, and insert @@ -414,7 +415,7 @@ main(int argc, char * const *argv) setbuf(stdout, NULL); setbuf(stderr, NULL); - while ((ch = getopt(argc, argv, "D:ij:klLn:qt:v")) != -1) { + while ((ch = getopt(argc, argv, "D:ij:klLn:qt:vW")) != -1) { switch (ch) { case 'D': if (!parse_D_opt(optarg)) { @@ -452,6 +453,9 @@ main(int argc, char * const *argv) if (vtc_verbosity < 2) vtc_verbosity++; break; + case 'W': + vtc_witness++; + break; default: usage(); } diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index c6cb52f..ce666e3 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -394,6 +394,8 @@ varnish_launch(struct varnish *v) VSB_printf(vsb, "cd ${pwd} &&"); VSB_printf(vsb, " exec ${varnishd} %s -d -n %s", v->jail, v->workdir); + if (vtc_witness) + VSB_cat(vsb, " -p debug=+witness"); VSB_printf(vsb, " -l 2m,1m,-"); VSB_printf(vsb, " -p auto_restart=off"); VSB_printf(vsb, " -p syslog_cli_traffic=off"); diff --git a/bin/varnishtest/witness.py b/bin/varnishtest/witness.py new file mode 100644 index 0000000..081429e --- /dev/null +++ b/bin/varnishtest/witness.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# +# This script is in the public domain +# +# Run instructions: +# varnishtest -W -iv -j > _.w +# python witness.py +# dot -Tpng /tmp/_.dot > /tmp/_.png + +from __future__ import print_function + +d = dict() +a = dict() + +fi = open("_w") +fo = open("/tmp/_.dot", "w") + +fo.write('''digraph { + #rotate="90" + #page="8.2,11.7" + size="8.2,11.7" + rankdir="LR" + node [fontname="Inconsolata", fontsize="10"] + edge [fontname="Inconsolata", fontsize="10"] +''') + +for i in fi: + l = "ROOT" + j = i.split() + if len(j) < 8: + continue + if j[1][0] != 'v': + continue + if j[3] != "vsl|": + continue + if j[5] != "Witness": + continue + t = j[7:] + tt = str(t) + if tt in d: + continue + d[tt] = True + for e in t: + f = e.split(",") + x = '"%s" -> "%s" [label="%s(%s)"]\n' % (l, f[0], f[1], f[2]) + if not x in a: + a[x] = True + fo.write(x) + l = f[0] + +fo.write("}\n") + diff --git a/doc/sphinx/phk/brinch-hansens-arrows.rst b/doc/sphinx/phk/brinch-hansens-arrows.rst new file mode 100644 index 0000000..cba1f44 --- /dev/null +++ b/doc/sphinx/phk/brinch-hansens-arrows.rst @@ -0,0 +1,60 @@ +.. _phk_brinch_hansens_arrows: + +===================== +Brinch-Hansens Arrows +===================== + +As you may have noticed, I am a bit of a IT-history nerd, and we do have +some rather important early IT history in Denmark. + +If you have a solid CS background, you have undoubtedly heard about +both dining philosophers and Brinch-Hansens work in multiprogramming. + +Multiprogramming is fundamentally hard, because you cannot have one +thread holding lock A trying to get lock B, while another holds +lock B trying to get lock A. + +Brinch-Hansen did a lot of both theoretical and practical work in the +area of multiprogramming and being both good at it and one of the +pioneers, he was awardede the ACM Turing Prize for it. + +You can read more about him here: +`Brinch-Hansen Archive `_ + +Along the way he came up with a trivial and practical way to guarantee +that a given multiprogramming system was free of deadlocks: Draw +the locking order and make sure all the arrows point to the right. + +When we started working with multi-core systems in FreeBSD, we were +sure to have deadlocks in our future, and we adobted and expanded +a facility called "WITNESS" originally written for BSDI, which +keeps an eye on Brinch-Hansens arrows in real time. + +Historically I have been pretty good at avoiding deadlocks, it seems +to come natural to me to think about locking order, but not everybody +feels that way about them, and WITNESS have caught a lot of "Ohh, +didn't think about *that*" situations over the years. + +It is no accident that Varnish has a very simple locking structure, +but as we add more and more flexibility and extensibility to Varnish +it grows a little here and there, and I managed to introduce a +lock-order reversal the other day - my first in about five years I +think. + +Since I'm obviously getting old and slipping up here, I though it +was about time I carried out the Brinch-Hansen check on Varnish. + +I briefly pondered porting WITNESS into Varnish, but it's 3k lines +and we have extremely good code coverage in our regression tests +so I decided to KISS and do it as post-processing. + +I have added default-off debug code to emit VSL "Witness" records, +taught varnishtest how to enable that code, and added a small python +script to process the records into a nice plot: + +.. image:: brinch_hansens_arrows_1.svg + +And yo and behold: All the arrows point to the right. + +*phk* + diff --git a/doc/sphinx/phk/brinch_hansens_arrows_1.svg b/doc/sphinx/phk/brinch_hansens_arrows_1.svg new file mode 100644 index 0000000..86e47e5 --- /dev/null +++ b/doc/sphinx/phk/brinch_hansens_arrows_1.svg @@ -0,0 +1,381 @@ + + + + + + +%3 + + +ROOT + +ROOT + + +lck_cli + +lck_cli + + +ROOT->lck_cli + + +cli_cb_before(81) + + +lck_vbe + +lck_vbe + + +ROOT->lck_vbe + + +VBE_Delete(172) + + +lck_exp + +lck_exp + + +ROOT->lck_exp + + +exp_thread(588) + + +lck_backend + +lck_backend + + +ROOT->lck_backend + + +vbe_dir_finish(185) + + +ROOT->lck_backend + + +vbp_thread(361) + + +lck_objhdr + +lck_objhdr + + +ROOT->lck_objhdr + + +hcb_deref(401) + + +ROOT->lck_objhdr + + +hcl_lookup(141) + + +ROOT->lck_objhdr + + +hcb_lookup(438) + + +ROOT->lck_objhdr + + +HSH_Unbusy(702) + + +ROOT->lck_objhdr + + +HSH_DerefObjCore(778) + + +lck_ban + +lck_ban + + +ROOT->lck_ban + + +ban_lurker_getfirst(1019) + + +lck_lru + +lck_lru + + +ROOT->lck_lru + + +EXP_NukeOne(333) + + +lck_smp + +lck_smp + + +ROOT->lck_smp + + +smp_open(328) + + +lck_cli->lck_vbe + + +VRT_new_backend(100) + + +lck_cli->lck_vbe + + +backend_find(243) + + +lck_cli->lck_vbe + + +VBE_Delete(172) + + +lck_vcl + +lck_vcl + + +lck_cli->lck_vcl + + +VCL_AddBackend(195) + + +lck_cli->lck_vcl + + +VCL_Load(466) + + +lck_cli->lck_vcl + + +ccf_config_use(617) + + +lck_cli->lck_vcl + + +VCL_Get(134) + + +lck_cli->lck_vcl + + +VCL_Rel(177) + + +lck_cli->lck_vcl + + +ccf_config_discard(579) + + +lck_cli->lck_backend + + +vbp_update_backend(158) + + +lck_cli->lck_backend + + +VBP_Control(525) + + +lck_cli->lck_backend + + +VBP_Remove(578) + + +lck_cli->lck_ban + + +BAN_Insert(533) + + +lck_cli->lck_ban + + +BAN_Insert(572) + + +lck_cli->lck_ban + + +BAN_TailRef(210) + + +lck_cli->lck_ban + + +BAN_TailDeref(225) + + +lck_cli->lck_ban + + +ccf_ban_list(1312) + + +lck_cli->lck_smp + + +debug_persistent(653) + + +lck_backend_tcp + +lck_backend_tcp + + +lck_vbe->lck_backend_tcp + + +VBT_Rel(193) + + +lck_wstat + +lck_wstat + + +lck_exp->lck_wstat + + +Pool_Sumstat(72) + + +lck_backend->lck_backend_tcp + + +VBT_Recycle(264) + + +lck_wq + +lck_wq + + +lck_backend->lck_wq + + +Pool_Task_Any(98) + + +lck_backend->lck_wq + + +Pool_Task(231) + + +lck_waiter + +lck_waiter + + +lck_backend_tcp->lck_waiter + + +vwk_enter(147) + + +lck_objhdr->lck_exp + + +exp_mail_it(145) + + +lck_hcb + +lck_hcb + + +lck_objhdr->lck_hcb + + +hcb_deref(405) + + +lck_objhdr->lck_ban + + +BAN_CheckObject(927) + + +lck_objhdr->lck_ban + + +BAN_CheckObject(948) + + +lck_objhdr->lck_lru + + +EXP_Rearm(299) + + +lck_objhdr->lck_wq + + +Pool_Task(231) + + +lck_objhdr->lck_smp + + +smp_oc_getobj(425) + + +lck_objhdr? + +lck_objhdr? + + +lck_ban->lck_objhdr? + + +ban_lurker_getfirst(1029) + + +lck_lru->lck_objhdr? + + +EXP_NukeOne(352) + + +lck_smp->lck_ban + + +BAN_Reload(773) + + +lck_smp->lck_ban + + +BAN_TailRef(210) + + + diff --git a/doc/sphinx/phk/index.rst b/doc/sphinx/phk/index.rst index 425d4e5..7dae4e4 100644 --- a/doc/sphinx/phk/index.rst +++ b/doc/sphinx/phk/index.rst @@ -8,6 +8,7 @@ You may or may not want to know what Poul-Henning thinks. .. toctree:: :maxdepth: 1 + brinch-hansens-arrows.rst ssl_again.rst persistent.rst dough.rst diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h index 31eef0c..9e5b684 100644 --- a/include/tbl/debug_bits.h +++ b/include/tbl/debug_bits.h @@ -41,4 +41,5 @@ DEBUG_BIT(LURKER, lurker, "VSL Ban lurker") DEBUG_BIT(ESI_CHOP, esi_chop, "Chop ESI fetch to bits") DEBUG_BIT(FLUSH_HEAD, flush_head, "Flush after http1 head") DEBUG_BIT(VTC_MODE, vtc_mode, "Varnishtest Mode") +DEBUG_BIT(WITNESS, witness, "Emit WITNESS lock records") /*lint -restore */ diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index fff29d5..d592016 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -518,5 +518,9 @@ SLTM(VfpAcct, 0, "Fetch filter accounting", NODEF_NOTICE ) +SLTM(Witness, 0, "Lock order witness records", + "Diagnostic recording of locking order.\n" +) + #undef NODEF_NOTICE /*lint -restore */ From phk at FreeBSD.org Tue Jul 7 09:41:13 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 07 Jul 2015 11:41:13 +0200 Subject: [master] b4ce7a1 Make sure the witness code is exercised. Message-ID: commit b4ce7a1ab335ad599946c2260aca8840d3aaedf0 Author: Poul-Henning Kamp Date: Tue Jul 7 09:40:57 2015 +0000 Make sure the witness code is exercised. diff --git a/bin/varnishtest/tests/b00000.vtc b/bin/varnishtest/tests/b00000.vtc index ce81478..5b464a9 100644 --- a/bin/varnishtest/tests/b00000.vtc +++ b/bin/varnishtest/tests/b00000.vtc @@ -12,6 +12,7 @@ varnish v1 -vcl+backend { } -start varnish v1 -cliok "param.set debug +workspace" +varnish v1 -cliok "param.set debug +witness" varnish v1 -expect n_object == 0 varnish v1 -expect sess_conn == 0 From fgsch at lodoss.net Tue Jul 7 11:22:47 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 07 Jul 2015 13:22:47 +0200 Subject: [master] 7fed882 Correct format Message-ID: commit 7fed882e6956a2faf9f44e51efbdc714874b1ff0 Author: Federico G. Schwindt Date: Tue Jul 7 12:17:56 2015 +0100 Correct format diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst index 9213baf..e2c1fc8 100644 --- a/doc/sphinx/reference/varnishstat.rst +++ b/doc/sphinx/reference/varnishstat.rst @@ -184,12 +184,12 @@ With -j the output format is:: "FIELD NAME": { "description": "FIELD DESCRIPTION", "type": "FIELD TYPE", "ident": "FIELD IDENT", "flag": "FIELD SEMANTICS", "format": "FIELD DISPLAY FORMAT", - "value": FIELD VALUE, + "value": FIELD VALUE }, "FIELD2 NAME": { "description": "FIELD2 DESCRIPTION", "type": "FIELD2 TYPE", "ident": "FIELD2 IDENT", "flag": "FIELD2 SEMANTICS", "format": "FIELD2 DISPLAY FORMAT", - "value": FIELD2 VALUE, + "value": FIELD2 VALUE }, [..] } From fgsch at lodoss.net Tue Jul 7 11:29:11 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 07 Jul 2015 13:29:11 +0200 Subject: [master] 8e2d5ac Typos Message-ID: commit 8e2d5ac61f0e8cdfc0650c718abf13f148772b64 Author: Federico G. Schwindt Date: Tue Jul 7 12:26:35 2015 +0100 Typos Partially from minusf via github diff --git a/doc/sphinx/users-guide/run_security.rst b/doc/sphinx/users-guide/run_security.rst index e34b0a7..5b9dfad 100644 --- a/doc/sphinx/users-guide/run_security.rst +++ b/doc/sphinx/users-guide/run_security.rst @@ -45,9 +45,9 @@ The important decisions to make are: CLI interface access ^^^^^^^^^^^^^^^^^^^^ -The command line interface can be accessed three ways. +The command line interface can be accessed in three ways. -`Varnishd` can be told til listen and offer CLI connections +`Varnishd` can be told to listen and offer CLI connections on a TCP socket. You can bind the socket to pretty much anything the kernel will accept:: @@ -227,12 +227,12 @@ HTTP requests ------------- We have gone to great lengths to make Varnish resistant to anything -coming in throught the socket where HTTP requests are received, and +coming in through the socket where HTTP requests are received, and you should, generally speaking, not need to protect it any further. The caveat is that since VCL is a programming language which lets you decide exactly what to do with HTTP requests, you can also decide -to do stupid and potentially dangerous things with them, including opening youself up +to do stupid and potentially dangerous things with them, including opening yourself up to various kinds of attacks and subversive activities. If you have "administrative" HTTP requests, for instance PURGE From lkarsten at varnish-software.com Tue Jul 7 19:31:55 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 07 Jul 2015 21:31:55 +0200 Subject: [master] 331fab1 Move the built HTML documentation to doc/html/. Message-ID: commit 331fab1f8cb1d1615b19af2ba141803dd51a9d52 Author: Lasse Karstensen Date: Tue Jul 7 21:26:11 2015 +0200 Move the built HTML documentation to doc/html/. I think it makes sense to ship a built HTML copy in the tarball, as well as the RST sources. The old cleanup code was a tad eager and made phk miss his svg. Hopefully this way is a bit more future proof. automake is our friend. We might have to update some packaging files later on. (and perhaps the git push hook.) diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am index 0ec3328..c03a448 100644 --- a/doc/sphinx/Makefile.am +++ b/doc/sphinx/Makefile.am @@ -117,9 +117,7 @@ EXTRA_DIST = \ dist-hook: $(MAKE) html rm -rf $(BUILDDIR)/doctrees - cp -r $(BUILDDIR) $(distdir) -# Remove any extra non-rst files we may have copied over. - find $(distdir) -mindepth 2 -type f ! -name \*.rst | grep -v '/build/' | xargs rm -f + cp -r $(BUILDDIR)/html $(distdir)/../ distclean-local: rm -rf $(BUILDDIR) From lkarsten at varnish-software.com Tue Jul 7 19:31:55 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 07 Jul 2015 21:31:55 +0200 Subject: [master] 45a598e Do not output progress while working. Message-ID: commit 45a598edbbcd783b8e5b4c5f51277ec19c495d28 Author: Lasse Karstensen Date: Tue Jul 7 21:29:52 2015 +0200 Do not output progress while working. The amount of output does (did) not correspond with the importance of this task. Now at least we'll see the warnings clearly. diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am index c03a448..618a54c 100644 --- a/doc/sphinx/Makefile.am +++ b/doc/sphinx/Makefile.am @@ -3,7 +3,7 @@ # You can set these variables from the command line. SPHINXOPTS = -SPHINXBUILD = sphinx-build -W -N +SPHINXBUILD = sphinx-build -W -q -N PAPER = a4 BUILDDIR = build From lkarsten at varnish-software.com Tue Jul 7 20:09:08 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 07 Jul 2015 22:09:08 +0200 Subject: [master] 93c725e Add final part of the sphinx distcheck fix. Message-ID: commit 93c725ebe103051f110de5cf0d2c71099d670460 Author: Lasse Karstensen Date: Tue Jul 7 22:06:59 2015 +0200 Add final part of the sphinx distcheck fix. There is potential for improvement in this whole documentation build business of ours. diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am index 618a54c..6d71c14 100644 --- a/doc/sphinx/Makefile.am +++ b/doc/sphinx/Makefile.am @@ -35,7 +35,7 @@ clean: link_srcdir: if test "x$(srcdir)" != "x$(builddir)" && test ! -f index.rst ; then \ d=`pwd`/$(builddir) ; \ - cd $(srcdir) && find . -name \*.rst -type f | cpio -ldmp $${d} ; \ + cd $(srcdir) && find . -type f | cpio -ldmp $${d} ; \ fi # work around for make html called within doc/sphinx From phk at FreeBSD.org Tue Jul 7 20:17:41 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 07 Jul 2015 22:17:41 +0200 Subject: [master] 9ea9825 Send dynamically created backends a warm event if their VCL is warm. Message-ID: commit 9ea9825718082296a3f937c2fcd13c1f6f6f6feb Author: Poul-Henning Kamp Date: Tue Jul 7 20:15:44 2015 +0000 Send dynamically created backends a warm event if their VCL is warm. Based on patch from: Dridi diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 057dea4..e7301ac 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -140,7 +140,6 @@ void VBE_Event(struct backend *be, enum vcl_event_e ev) { - ASSERT_CLI(); CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); if (ev == VCL_EVENT_WARM) { diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 6df2a2f..7d87cb0 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -195,6 +195,11 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be) Lck_Lock(&vcl_mtx); VTAILQ_INSERT_TAIL(&vcl->backend_list, be, vcl_list); Lck_Unlock(&vcl_mtx); + + if (vcl->temp == vcl_temp_warm) { + /* Only when adding backend to already warm VCL */ + VBE_Event(be, VCL_EVENT_WARM); + } } void From phk at FreeBSD.org Tue Jul 7 22:46:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:46:24 +0200 Subject: [master] 0fe9fb9 Clarifying comments, and move a function call to a more natural location. Message-ID: commit 0fe9fb938a8bfb54f7814f91cb2e74d2176d8862 Author: Poul-Henning Kamp Date: Tue Jul 7 20:41:40 2015 +0000 Clarifying comments, and move a function call to a more natural location. diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index e7301ac..b05acea 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -51,7 +51,7 @@ static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); static struct lock backends_mtx; /*-------------------------------------------------------------------- - * Create/Delete a new director::backend instance. + * Create a new static or dynamic director::backend instance. */ struct director * @@ -117,6 +117,11 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt) return (b->director); } +/*-------------------------------------------------------------------- + * Delete a dynamic director::backend instance. Undeleted dynamic and + * static instances are GC'ed when the VCL is discarded (in cache_vcl.c) + */ + void VRT_delete_backend(VRT_CTX, struct director **dp) { @@ -130,6 +135,7 @@ VRT_delete_backend(VRT_CTX, struct director **dp) CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); VCL_DelBackend(ctx->vcl, be); + VBE_Delete(be); } /*--------------------------------------------------------------------- diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 7d87cb0..3ab89ff 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -210,7 +210,6 @@ VCL_DelBackend(struct vcl *vcl, struct backend *be) Lck_Lock(&vcl_mtx); VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list); Lck_Unlock(&vcl_mtx); - VBE_Delete(be); } static void From phk at FreeBSD.org Tue Jul 7 22:46:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:46:24 +0200 Subject: [master] 9a08b88 Convert the admin_health enum to a "const char* enum" to reduce conversions between enum and text. Message-ID: commit 9a08b88ff55714a3fda4bc8b86b17608bab2d625 Author: Poul-Henning Kamp Date: Tue Jul 7 21:04:13 2015 +0000 Convert the admin_health enum to a "const char* enum" to reduce conversions between enum and text. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index bd8a8c5..79c4ae2 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -66,10 +66,10 @@ VBE_Healthy(const struct backend *backend, double *changed) if (changed != NULL) *changed = backend->health_changed; - if (backend->admin_health == ah_probe && !backend->healthy) + if (backend->admin_health == vbe_ah_probe && !backend->healthy) return (0); - if (backend->admin_health == ah_sick) + if (backend->admin_health == vbe_ah_sick) return (0); return (1); @@ -346,16 +346,8 @@ vbe_panic(const struct director *d, struct vsb *vsb) VSB_printf(vsb, " ipv6 = %s\n", bp->ipv6_addr); VSB_printf(vsb, " port = %s\n", bp->port); VSB_printf(vsb, " hosthdr = %s\n", bp->hosthdr); - VSB_printf(vsb, " health=%s, admin_health=", - bp->healthy ? "healthy" : "sick"); - if (bp->admin_health == ah_probe) - VSB_printf(vsb, "probe"); - else if (bp->admin_health == ah_sick) - VSB_printf(vsb, "sick"); - else if (bp->admin_health == ah_healthy) - VSB_printf(vsb, "healthy"); - else - VSB_printf(vsb, "*invalid*"); + VSB_printf(vsb, " health=%s, admin_health=%s", + bp->healthy ? "healthy" : "sick", bp->admin_health); VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed); } diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index cc27de6..9443ac2 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -46,12 +46,9 @@ struct tcp_pool; * An instance of a backend from a VCL program. */ -enum admin_health { - ah_invalid = 0, - ah_healthy, - ah_sick, - ah_probe -}; +extern const char * const vbe_ah_healthy; +extern const char * const vbe_ah_sick; +extern const char * const vbe_ah_probe; struct backend { unsigned magic; @@ -71,7 +68,7 @@ struct backend { struct vbp_target *probe; unsigned healthy; - enum admin_health admin_health; + const char *admin_health; double health_changed; struct VSC_C_vbe *vsc; diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index b05acea..a22af3c 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -50,6 +50,10 @@ static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); static struct lock backends_mtx; +const char * const vbe_ah_healthy = "healthy"; +const char * const vbe_ah_sick = "sick"; +const char * const vbe_ah_probe = "probe"; + /*-------------------------------------------------------------------- * Create a new static or dynamic director::backend instance. */ @@ -91,7 +95,7 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt) b->healthy = 1; b->health_changed = VTIM_real(); - b->admin_health = ah_probe; + b->admin_health = vbe_ah_probe; vbp = vrt->probe; if (vbp == NULL) @@ -196,17 +200,17 @@ VBE_Delete(struct backend *be) * String to admin_health */ -static enum admin_health +static const char * vbe_str2adminhealth(const char *wstate) { - if (strcasecmp(wstate, "healthy") == 0) - return (ah_healthy); - if (strcasecmp(wstate, "sick") == 0) - return (ah_sick); - if (strcmp(wstate, "auto") == 0) - return (ah_probe); - return (ah_invalid); +#define FOO(x, y) if (strcasecmp(wstate, #x) == 0) return (vbe_ah_##y) + FOO(healthy, healthy); + FOO(sick, sick); + FOO(probe, probe); + FOO(auto, probe); + return (NULL); +#undef FOO } /*--------------------------------------------------------------------- @@ -275,14 +279,7 @@ do_list(struct cli *cli, struct backend *b, void *priv) VCLI_Out(cli, "\n%-30s", b->display_name); - if (b->admin_health == ah_probe) - VCLI_Out(cli, " %-10s", "probe"); - else if (b->admin_health == ah_sick) - VCLI_Out(cli, " %-10s", "sick"); - else if (b->admin_health == ah_healthy) - VCLI_Out(cli, " %-10s", "healthy"); - else - VCLI_Out(cli, " %-10s", "invalid"); + VCLI_Out(cli, " %-10s", b->admin_health); if (b->probe == NULL) VCLI_Out(cli, " %s", "Healthy (no probe)"); @@ -327,14 +324,16 @@ cli_backend_list(struct cli *cli, const char * const *av, void *priv) static int __match_proto__() do_set_health(struct cli *cli, struct backend *b, void *priv) { - enum admin_health state; + const char **ah; unsigned prev; (void)cli; - state = *(enum admin_health*)priv; + AN(priv); + ah = priv; + AN(*ah); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); prev = VBE_Healthy(b, NULL); - b->admin_health = state; + b->admin_health = *ah; if (prev != VBE_Healthy(b, NULL)) b->health_changed = VTIM_real(); @@ -344,7 +343,7 @@ do_set_health(struct cli *cli, struct backend *b, void *priv) static void cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) { - enum admin_health state; + const char *ah; int n; (void)av; @@ -352,13 +351,13 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) ASSERT_CLI(); AN(av[2]); AN(av[3]); - state = vbe_str2adminhealth(av[3]); - if (state == ah_invalid) { + ah = vbe_str2adminhealth(av[3]); + if (ah == NULL) { VCLI_Out(cli, "Invalid state %s", av[3]); VCLI_SetResult(cli, CLIS_PARAM); return; } - n = backend_find(cli, av[2], do_set_health, &state); + n = backend_find(cli, av[2], do_set_health, &ah); if (n == 0) { VCLI_Out(cli, "No Backends matches"); VCLI_SetResult(cli, CLIS_PARAM); From phk at FreeBSD.org Tue Jul 7 22:46:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:46:24 +0200 Subject: [master] 4c7c283 Polish admin_health stuff a little bit Message-ID: commit 4c7c28382d01efb27455fd85ca7dadd2dea26a13 Author: Poul-Henning Kamp Date: Tue Jul 7 21:17:26 2015 +0000 Polish admin_health stuff a little bit diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 522fad2..0cfbd40 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -1053,7 +1053,7 @@ void VCL_Ref(struct vcl *); void VCL_Refresh(struct vcl **); void VCL_Rel(struct vcl **); void VCL_AddBackend(struct vcl *, struct backend *); -void VCL_DelBackend(struct vcl *, struct backend *); +void VCL_DelBackend(struct vcl *, const struct backend *); const char *VCL_Return_Name(unsigned); #define VCL_MET_MAC(l,u,b) \ diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 79c4ae2..bf7b537 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -55,27 +55,6 @@ } while (0) /*-------------------------------------------------------------------- - * Test if backend is healthy and report when it last changed - */ - -unsigned -VBE_Healthy(const struct backend *backend, double *changed) -{ - CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC); - - if (changed != NULL) - *changed = backend->health_changed; - - if (backend->admin_health == vbe_ah_probe && !backend->healthy) - return (0); - - if (backend->admin_health == vbe_ah_sick) - return (0); - - return (1); -} - -/*-------------------------------------------------------------------- * Get a connection to the backend */ diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 9443ac2..06f50e1 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -46,10 +46,6 @@ struct tcp_pool; * An instance of a backend from a VCL program. */ -extern const char * const vbe_ah_healthy; -extern const char * const vbe_ah_sick; -extern const char * const vbe_ah_probe; - struct backend { unsigned magic; #define BACKEND_MAGIC 0x64c4c7c6 diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index a22af3c..aba8e8b 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -50,9 +50,9 @@ static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); static struct lock backends_mtx; -const char * const vbe_ah_healthy = "healthy"; -const char * const vbe_ah_sick = "sick"; -const char * const vbe_ah_probe = "probe"; +static const char * const vbe_ah_healthy = "healthy"; +static const char * const vbe_ah_sick = "sick"; +static const char * const vbe_ah_probe = "probe"; /*-------------------------------------------------------------------- * Create a new static or dynamic director::backend instance. @@ -205,7 +205,7 @@ vbe_str2adminhealth(const char *wstate) { #define FOO(x, y) if (strcasecmp(wstate, #x) == 0) return (vbe_ah_##y) - FOO(healthy, healthy); + FOO(healthy, healthy); FOO(sick, sick); FOO(probe, probe); FOO(auto, probe); @@ -213,6 +213,30 @@ vbe_str2adminhealth(const char *wstate) #undef FOO } +/*-------------------------------------------------------------------- + * Test if backend is healthy and report when it last changed + */ + +unsigned +VBE_Healthy(const struct backend *backend, double *changed) +{ + CHECK_OBJ_NOTNULL(backend, BACKEND_MAGIC); + + if (changed != NULL) + *changed = backend->health_changed; + + if (backend->admin_health == vbe_ah_probe) + return (backend->healthy); + + if (backend->admin_health == vbe_ah_sick) + return (0); + + if (backend->admin_health == vbe_ah_healthy) + return (1); + + WRONG("Wrong admin health"); +} + /*--------------------------------------------------------------------- * A general function for finding backends and doing things with them. * diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 3ab89ff..0a5eac9 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -203,7 +203,7 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be) } void -VCL_DelBackend(struct vcl *vcl, struct backend *be) +VCL_DelBackend(struct vcl *vcl, const struct backend *be) { CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC); CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); From phk at FreeBSD.org Tue Jul 7 22:46:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:46:24 +0200 Subject: [master] 09b01e7 Count the backend n_conn down when fd's are returned. Message-ID: commit 09b01e7d747e60d06845cf2ea57cd0b506098f49 Author: Poul-Henning Kamp Date: Tue Jul 7 21:44:55 2015 +0000 Count the backend n_conn down when fd's are returned. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index bf7b537..29f22f7 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -165,6 +165,8 @@ vbe_dir_finish(const struct director *d, struct worker *wrk, VSC_C_main->backend_recycle++; VBT_Recycle(wrk, bp->tcp_pool, &vbc); } + assert(bp->n_conn > 0); + bp->n_conn--; #define ACCT(foo) bp->vsc->foo += bo->acct.foo; #include "tbl/acct_fields_bereq.h" #undef ACCT From phk at FreeBSD.org Tue Jul 7 22:46:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:46:24 +0200 Subject: [master] 2899efd Relive the VMODs of the responsibility of tracking dynamic backends connection count. Message-ID: commit 2899efd1055dab6b8ba47caace51e580ae3b56cd Author: Poul-Henning Kamp Date: Tue Jul 7 22:43:35 2015 +0000 Relive the VMODs of the responsibility of tracking dynamic backends connection count. Instead we mark the dynamic backends unhealthy with the status "deleted", hide it from CLI displays, prevent new connections from being opened and clean the backend up when the connection count goes to zero. Radically different from patch from: Dridi diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 0cfbd40..6574278 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -675,6 +675,7 @@ void VCA_Shutdown(void); /* cache_backend_cfg.c */ void VBE_InitCfg(void); +void VBE_Poll(void); /* cache_backend_poll.c */ void VBP_Init(void); @@ -1052,8 +1053,6 @@ void VCL_Poll(void); void VCL_Ref(struct vcl *); void VCL_Refresh(struct vcl **); void VCL_Rel(struct vcl **); -void VCL_AddBackend(struct vcl *, struct backend *); -void VCL_DelBackend(struct vcl *, const struct backend *); const char *VCL_Return_Name(unsigned); #define VCL_MET_MAC(l,u,b) \ diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 06f50e1..97e70c1 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -57,7 +57,7 @@ struct backend { VRT_BACKEND_FIELDS() - const struct vcl *vcl; + struct vcl *vcl; char *display_name; unsigned n_conn; @@ -109,13 +109,14 @@ void VBE_Event(struct backend *, enum vcl_event_e); #endif void VBE_Delete(struct backend *be); -/* cache_backend_poll.c */ +/* cache_backend_probe.c */ void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, struct tcp_pool *); void VBP_Remove(struct backend *b); void VBP_Control(const struct backend *b, int stop); void VBP_Status(struct cli *cli, const struct backend *, int details); +/* cache_backend_tcp.c */ struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6); void VBT_Rel(struct tcp_pool **tpp); @@ -125,3 +126,7 @@ void VBT_Close(struct tcp_pool *tp, struct vbc **vbc); struct vbc *VBT_Get(struct tcp_pool *, double tmo, const struct backend *, struct worker *); void VBT_Wait(struct worker *, struct vbc *); + +/* cache_vcl.c */ +void VCL_AddBackend(struct vcl *, struct backend *); +void VCL_DelBackend(const struct backend *); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index aba8e8b..23d0d44 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -53,6 +53,7 @@ static struct lock backends_mtx; static const char * const vbe_ah_healthy = "healthy"; static const char * const vbe_ah_sick = "sick"; static const char * const vbe_ah_probe = "probe"; +static const char * const vbe_ah_deleted = "deleted"; /*-------------------------------------------------------------------- * Create a new static or dynamic director::backend instance. @@ -131,6 +132,7 @@ VRT_delete_backend(VRT_CTX, struct director **dp) { struct director *d; struct backend *be; + int r; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); AN(dp); @@ -138,8 +140,20 @@ VRT_delete_backend(VRT_CTX, struct director **dp) *dp = NULL; CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); - VCL_DelBackend(ctx->vcl, be); - VBE_Delete(be); + Lck_Lock(&be->mtx); + be->admin_health = vbe_ah_deleted; + be->health_changed = VTIM_real(); + r = be->n_conn; + if (r > 0) { + /* move to front of list for fast access */ + VTAILQ_REMOVE(&backends, be, list); + VTAILQ_INSERT_HEAD(&backends, be, list); + } + Lck_Unlock(&be->mtx); + if (r == 0) { + VCL_DelBackend(be); + VBE_Delete(be); + } } /*--------------------------------------------------------------------- @@ -231,6 +245,9 @@ VBE_Healthy(const struct backend *backend, double *changed) if (backend->admin_health == vbe_ah_sick) return (0); + if (backend->admin_health == vbe_ah_deleted) + return (0); + if (backend->admin_health == vbe_ah_healthy) return (1); @@ -275,6 +292,8 @@ backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv) AZ(VSB_finish(vsb)); Lck_Lock(&backends_mtx); VTAILQ_FOREACH(b, &backends, list) { + if (b->admin_health == vbe_ah_deleted) + continue; if (fnmatch(VSB_data(vsb), b->display_name, 0)) continue; found++; @@ -357,7 +376,8 @@ do_set_health(struct cli *cli, struct backend *b, void *priv) AN(*ah); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); prev = VBE_Healthy(b, NULL); - b->admin_health = *ah; + if (b->admin_health != vbe_ah_deleted) + b->admin_health = *ah; if (prev != VBE_Healthy(b, NULL)) b->health_changed = VTIM_real(); @@ -404,6 +424,27 @@ static struct cli_proto backend_cmds[] = { /*---------------------------------------------------------------------*/ void +VBE_Poll(void) +{ + struct backend *be; + Lck_Lock(&backends_mtx); + while (1) { + be = VTAILQ_FIRST(&backends); + if (be == NULL) + break; + if (be->admin_health != vbe_ah_deleted) + break; + if (be->n_conn > 0) + break; + VCL_DelBackend(be); + VBE_Delete(be); + } + Lck_Unlock(&backends_mtx); +} + +/*---------------------------------------------------------------------*/ + +void VBE_InitCfg(void) { diff --git a/bin/varnishd/cache/cache_cli.c b/bin/varnishd/cache/cache_cli.c index 5fbad58..3ba8cdd 100644 --- a/bin/varnishd/cache/cache_cli.c +++ b/bin/varnishd/cache/cache_cli.c @@ -78,6 +78,7 @@ cli_cb_before(const struct cli *cli) ASSERT_CLI(); VSL(SLT_CLI, 0, "Rd %s", cli->cmd); VCL_Poll(); + VBE_Poll(); Lck_Lock(&cli_mtx); } diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 0a5eac9..b450361 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -47,6 +47,7 @@ #include "vcli.h" #include "vcli_priv.h" +static const char * const vcl_temp_init = "init"; static const char * const vcl_temp_cold = "cold"; static const char * const vcl_temp_warm = "warm"; static const char * const vcl_temp_cooling = "cooling"; @@ -199,14 +200,18 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be) if (vcl->temp == vcl_temp_warm) { /* Only when adding backend to already warm VCL */ VBE_Event(be, VCL_EVENT_WARM); - } + } else if (vcl->temp != vcl_temp_init) + WRONG("Dynamic Backends can only be added to warm VCLs"); } void -VCL_DelBackend(struct vcl *vcl, const struct backend *be) +VCL_DelBackend(const struct backend *be) { - CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC); + struct vcl *vcl; + CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); + vcl = be->vcl; + CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC); Lck_Lock(&vcl_mtx); VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list); Lck_Unlock(&vcl_mtx); @@ -395,7 +400,7 @@ vcl_set_state(struct vcl *vcl, const char *state) } break; case '1': - if (vcl->temp != vcl_temp_cold) + if (vcl->temp == vcl_temp_cooling) vcl->temp = vcl_temp_warm; else { vcl->temp = vcl_temp_warm; @@ -440,7 +445,7 @@ VCL_Load(struct cli *cli, const char *name, const char *fn, const char *state) XXXAN(vcl->loaded_name); VTAILQ_INIT(&vcl->backend_list); - vcl->temp = vcl_temp_cold; + vcl->temp = vcl_temp_init; INIT_OBJ(&ctx, VRT_CTX_MAGIC); ctx.method = VCL_MET_INIT; From phk at FreeBSD.org Tue Jul 7 22:49:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 00:49:52 +0200 Subject: [master] 35716c7 Add testcase for this ticket, the error was fixed in the previous commit. Message-ID: commit 35716c713ca505a135101e40f32670ca5671bfd1 Author: Poul-Henning Kamp Date: Tue Jul 7 22:49:22 2015 +0000 Add testcase for this ticket, the error was fixed in the previous commit. Fixes: #1755 diff --git a/bin/varnishtest/tests/r01755.vtc b/bin/varnishtest/tests/r01755.vtc new file mode 100644 index 0000000..87828a4 --- /dev/null +++ b/bin/varnishtest/tests/r01755.vtc @@ -0,0 +1,29 @@ +varnishtest "The (struct backend).n_conn counter is never decremented" + +server s1 { + rxreq + txresp + + rxreq + txresp +} -start + +varnish v1 -vcl { + backend s1 { + .host = "${s1_addr}"; + .port = "${s1_port}"; + .max_connections = 1; + } +} -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + + txreq -url "/bar" + rxresp + expect resp.status == 200 +} -run + +varnish v1 -expect backend_busy == 0 From phk at FreeBSD.org Wed Jul 8 20:15:43 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 08 Jul 2015 22:15:43 +0200 Subject: [master] 5781f95 Drop the backend mutex while mopping up deleted dynamic backends. Message-ID: commit 5781f95bf20fbb8bd07c9a3cf1e04b9c61e4815c Author: Poul-Henning Kamp Date: Wed Jul 8 20:15:18 2015 +0000 Drop the backend mutex while mopping up deleted dynamic backends. Spotted by: Dridi diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 23d0d44..a9199d3 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -427,8 +427,8 @@ void VBE_Poll(void) { struct backend *be; - Lck_Lock(&backends_mtx); while (1) { + Lck_Lock(&backends_mtx); be = VTAILQ_FIRST(&backends); if (be == NULL) break; @@ -436,6 +436,7 @@ VBE_Poll(void) break; if (be->n_conn > 0) break; + Lck_Unlock(&backends_mtx); VCL_DelBackend(be); VBE_Delete(be); } From dridi.boukelmoune at gmail.com Thu Jul 9 00:01:21 2015 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 09 Jul 2015 02:01:21 +0200 Subject: [master] 94a5f27 Add a debug.sleep(DURATION) synchronization helper Message-ID: commit 94a5f275aed3bfd1a49b486e76be31d4a64ac0c3 Author: Dridi Boukelmoune Date: Mon Jul 6 08:24:54 2015 +0200 Add a debug.sleep(DURATION) synchronization helper diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index 67edd62..305deaa 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -105,3 +105,7 @@ Register the vmod to receive expiry callbacks $Function VOID init_fail() Function to fail vcl_init{} + +$Function VOID sleep(DURATION) + +Block the current worker thread. diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index f9f3361..ce2e22b 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -36,6 +36,7 @@ #include "vcl.h" #include "vrt.h" #include "vsb.h" +#include "vtim.h" #include "vcc_if.h" struct priv_vcl { @@ -269,3 +270,11 @@ event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) priv->free = priv_vcl_free; return (0); } + +VCL_VOID __match_proto__(td_debug_sleep) +vmod_sleep(VRT_CTX, VCL_DURATION t) +{ + + CHECK_OBJ_ORNULL(ctx, VRT_CTX_MAGIC); + VTIM_sleep(t); +} From dridi.boukelmoune at gmail.com Thu Jul 9 00:01:21 2015 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Thu, 09 Jul 2015 02:01:21 +0200 Subject: [master] d07f3e3 Add the refcount to a backend panic message Message-ID: commit d07f3e38abdfa3361f40e5d66c4f5ca6cc5d41ef Author: Dridi Boukelmoune Date: Mon Jul 6 08:42:21 2015 +0200 Add the refcount to a backend panic message diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 29f22f7..611c089 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -330,6 +330,7 @@ vbe_panic(const struct director *d, struct vsb *vsb) VSB_printf(vsb, " health=%s, admin_health=%s", bp->healthy ? "healthy" : "sick", bp->admin_health); VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed); + VSB_printf(vsb, " refcount = %d\n", bp->refcount); } /*--------------------------------------------------------------------*/ From phk at FreeBSD.org Fri Jul 10 07:33:32 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 10 Jul 2015 09:33:32 +0200 Subject: [master] cfa2211 Polish flexelint stuff for vmods Message-ID: commit cfa22119fa24894976911a99e75c67d9ebaa6eac Author: Poul-Henning Kamp Date: Fri Jul 10 06:44:29 2015 +0000 Polish flexelint stuff for vmods diff --git a/bin/flint.lnt b/bin/flint.lnt index 1da0545..ce30d3a 100644 --- a/bin/flint.lnt +++ b/bin/flint.lnt @@ -4,27 +4,6 @@ -printf(2, VSB_printf) - -/////////////////////////////////////////////////////////////////////// -// Weirdness relating to varnish includes etc. - --header(../../config.h) -+libh ../../config.h --efile(451, ../../config.h) // No include guard - --efile(451, "tbl/*.h") // No include guard - -/////////////////////////////////////////////////////////////////////// -// assert() support, common to libvarnish and libvarnishapi --sem(VAS_Fail, r_no) --emacro(506, assert) // constant value boolean --emacro(827, assert) // loop not reachable --emacro(774, assert) // booelan always true --emacro(731, assert) // booelan arg to eq/non-eq --emacro(731, xxxassert) // arg to eq/non-eq --emacro(527, WRONG) // unreachable code - - /////////////////////////////////////////////////////////////////////// // miniobj @@ -40,22 +19,6 @@ -emacro(755, VWMB) // glob macro not ref /////////////////////////////////////////////////////////////////////// -// VSB - --esym(759, VSB_*) // header decl could be moved --esym(765, VSB_*) // exten could be made static --esym(714, VSB_*) // symb not ref --sem(VSB_new, @p == (1p ? 1p : malloc(1))) --sem(VSB_delete, custodial(1)) - --esym(534, VSB_cat) // Ignore retval --esym(534, VSB_bcat) --esym(534, VSB_putc) --esym(534, VSB_printf) --esym(534, VSB_vprintf) --esym(534, VSB_putc) - -/////////////////////////////////////////////////////////////////////// // System library/POSIX related /////////////////////////////////////////////////////////////////////// @@ -65,19 +28,6 @@ // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) --esym(534, printf) // Ignore retval --esym(534, fprintf) --esym(534, sprintf) - --esym(534, memset) --esym(534, memcpy) --esym(534, memmove) - --esym(534, strcat) --esym(534, strcpy) --esym(534, strlcpy) --esym(534, strncpy) - +typename(844) -etype(844, struct pthread *) -sem(pthread_create, custodial(4)) diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt index 5181c9e..70ec5b6 100644 --- a/bin/varnishd/flint.lnt +++ b/bin/varnishd/flint.lnt @@ -118,7 +118,6 @@ -e455 // thread lock -e458 // unprotected read --e763 // Redundant declaration for symbol '...' previously declared -e728 // Symbol ... not explicitly initialized -e716 // while(1) ... -e785 // Too few initializers for aggregate @@ -149,7 +148,6 @@ // cache_vcl.c -esym(528, vcl_call_method) // Not referenced -esym(528, vcl_handlingname) // Not referenced --e641 // Converting enum 'cli_status_e' to int -e441 // for clause irregularity: loop variable '___' not found in 2nd for expression diff --git a/flint.lnt b/flint.lnt index 5366617..9530745 100644 --- a/flint.lnt +++ b/flint.lnt @@ -2,8 +2,66 @@ * Toplevel control file for FlexeLint */ +/////////////////////////////////////////////////////////////////////// +// build/config related + -efile(451, "tbl/*.h") // No include guard --esym(785,VSL_tags) // Sparse array + +-efile(451, ../../config.h) // No include guard +-header(../../config.h) ++libh(../../config.h) + +/////////////////////////////////////////////////////////////////////// +// General stylistic issues +-e726 // Extraneous comma ignored +-e641 // Converting enum '...' to int +-e763 // // Redundant declaration for symbol '...' previously declared + +/////////////////////////////////////////////////////////////////////// +// Ignored return values in system libraries + +-esym(534, printf) +-esym(534, fprintf) +-esym(534, sprintf) + +-esym(534, memset) +-esym(534, memcpy) +-esym(534, memmove) + +-esym(534, strcat) +-esym(534, strcpy) +-esym(534, strlcpy) +-esym(534, strncpy) + +/////////////////////////////////////////////////////////////////////// +// + +-sem(VAS_Fail, r_no) // does not return +-emacro(506, assert) // constant value boolean +-emacro(827, assert) // loop not reachable +-emacro(774, assert) // booelan always true +-emacro(731, assert) // booelan arg to eq/non-eq +-emacro(731, xxxassert) // arg to eq/non-eq +-emacro(527, WRONG) // unreachable code + +/////////////////////////////////////////////////////////////////////// +// + +-esym(759, VSB_*) // header decl could be moved +-esym(765, VSB_*) // exten could be made static +-esym(714, VSB_*) // symb not ref +-sem(VSB_new, @p == (1p ? 1p : malloc(1))) +-sem(VSB_delete, custodial(1)) + +// ignore retval +-esym(534, VSB_cat) +-esym(534, VSB_bcat) +-esym(534, VSB_putc) +-esym(534, VSB_printf) +-esym(534, VSB_vprintf) +-esym(534, VSB_putc) + + /////////////////////////////////////////////////////////////////////// // @@ -25,3 +83,6 @@ -emacro(740, VTAILQ_LAST) // Unusual pointer cast (incompatible indirect types) -emacro(740, VTAILQ_PREV) // Unusual pointer cast (incompatible indirect types) +/////////////////////////////////////////////////////////////////////// + +-esym(785,VSL_tags) // Sparse array diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index a5eb8bb..ce27df2 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -217,6 +217,7 @@ class Vmod(object): vfn = 'Vmod_%s_Func' % self.nam + fo.write("/*lint -esym(754, %s::*) */\n" % vfn) fo.write("\nstatic const struct %s Vmod_Func =" % vfn) fo.write(self.c_initializer()) fo.write("\n") @@ -235,7 +236,7 @@ class Vmod(object): fo.write("\n") nm = "Vmod_" + self.nam + "_Data" - fo.write("extern const struct vmod_data " + nm + ";\n\n") + fo.write("/*lint -esym(759, %s) */\n" % nm) fo.write("const struct vmod_data " + nm + " = {\n") fo.write("\t.vrt_major = VRT_MAJOR_VERSION,\n"); fo.write("\t.vrt_minor = VRT_MINOR_VERSION,\n"); @@ -288,7 +289,8 @@ class Vmod(object): return s def c_strspec(self): - s = "static const char * const Vmod_Spec[] = {\n" + s = "/*lint -save -e786 -e840 */\n" + s += "static const char * const Vmod_Spec[] = {\n" for o in self.objs: s += o.c_strspec(self.nam) + ",\n\n" @@ -304,6 +306,7 @@ class Vmod(object): s += "\t0\n" s += "};\n" + s += "/*lint -restore */\n" return s def doc(self, l): @@ -898,8 +901,9 @@ def runmain(inputvcc, outputname="vcc_if"): write_c_file_warning(fc) write_c_file_warning(fh) - fh.write('struct vmod_priv;\n') - fh.write("\n") + fh.write('struct vmod_priv;\n\n') + + fh.write('extern const struct vmod_data Vmod_%s_Data;\n\n' % vx[0].nam) vx[0].c_proto(fh) diff --git a/lib/libvmod_debug/flint.sh b/lib/libvmod_debug/flint.sh new file mode 100755 index 0000000..b4bc3e7 --- /dev/null +++ b/lib/libvmod_debug/flint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +flexelint \ + -u \ + ../../flint.lnt \ + -I. \ + -I../.. \ + -I../../include \ + -I../../bin/varnishd \ + *.c diff --git a/lib/libvmod_std/flint.sh b/lib/libvmod_std/flint.sh new file mode 100755 index 0000000..b4bc3e7 --- /dev/null +++ b/lib/libvmod_std/flint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +flexelint \ + -u \ + ../../flint.lnt \ + -I. \ + -I../.. \ + -I../../include \ + -I../../bin/varnishd \ + *.c From phk at FreeBSD.org Fri Jul 10 07:33:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 10 Jul 2015 09:33:33 +0200 Subject: [master] 10c54c3 More FlexeLint polishing Message-ID: commit 10c54c3ce8e4e961614f9c1e5667607f41601644 Author: Poul-Henning Kamp Date: Fri Jul 10 07:07:58 2015 +0000 More FlexeLint polishing diff --git a/bin/flint.lnt b/bin/flint.lnt index ce30d3a..0bc6639 100644 --- a/bin/flint.lnt +++ b/bin/flint.lnt @@ -22,9 +22,6 @@ // System library/POSIX related /////////////////////////////////////////////////////////////////////// -// vararg simulation is imperfect (XXX: why ??) --emacro((???), va_arg) // 415, 416, 416, 661, 662, 796, 797 ... - // Fix strchr() semtics, it can only return NULL if arg2 != 0 -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt index 70ec5b6..5904b1e 100644 --- a/bin/varnishd/flint.lnt +++ b/bin/varnishd/flint.lnt @@ -63,11 +63,9 @@ //-sem (pthread_mutex_lock, thread_lock) -sem (pthread_mutex_trylock, thread_lock) -sem (VBE_DropRefLocked, thread_unlock) --e459 // unlocked access from func-ptr -e454 // mutex not released (...ReleaseLocked) -e457 // unprotected access -e777 // float equality comparison --e679 // Suspicious Truncation in arithmetic expression combining with pointer -esym(458, params) // unlocked access @@ -133,7 +131,6 @@ -emacro(506, isnan, isfinite) // constant value boolean -emacro(736, isfinite) // loss of precision --emacro(747, isnan) // significant coersion -emacro(774, HTTPH) // always false -emacro(527, ARGV_ERR) // unreachable @@ -153,12 +150,9 @@ // Review all below this line /////////////////////////////////////////////// --e732 // 183 Loss of sign (___) (___ to ___) -e737 // 143 Loss of sign in promotion from ___ to ___ -e713 // 42 Loss of precision (___) (___ to ___) -e574 // 48 Signed-unsigned mix with relational --e712 // 96 Loss of precision (___) (___ to ___) --e747 // 297 Significant prototype coercion (___) ___ to ___ -e840 // Use of nul character in a string literal (see: vcc_if.c) -e663 // Suspicious array to pointer conversion -e778 // Constant expression evaluates to 0 in operation '___' diff --git a/flint.lnt b/flint.lnt index 9530745..000968a 100644 --- a/flint.lnt +++ b/flint.lnt @@ -15,11 +15,16 @@ // General stylistic issues -e726 // Extraneous comma ignored -e641 // Converting enum '...' to int --e763 // // Redundant declaration for symbol '...' previously declared +-e763 // Redundant declaration for symbol '...' previously declared + +// +e958 // padding /////////////////////////////////////////////////////////////////////// -// Ignored return values in system libraries +// System/Posix/Iso-C library related + +-emacro(747, isnan) // significant coersion +// ignore retval -esym(534, printf) -esym(534, fprintf) -esym(534, sprintf) @@ -86,3 +91,13 @@ /////////////////////////////////////////////////////////////////////// -esym(785,VSL_tags) // Sparse array + +/////////////////////////////////////////////////////////////////////// +// Noise reduction, review periodically + +-e459 // unlocked access from func-ptr +-e679 // Suspicious Truncation in arithmetic expression combining with pointer +-e712 // Loss of precision (___) (___ to ___) +-e732 // Loss of sign (___) (___ to ___) +-e747 // Significant prototype coercion (___) ___ to ___ + From phk at FreeBSD.org Fri Jul 10 07:33:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 10 Jul 2015 09:33:33 +0200 Subject: [master] bc48754 Improve some struct packings Message-ID: commit bc487541f53f09e63235986de44a67300ff550f6 Author: Poul-Henning Kamp Date: Fri Jul 10 07:33:19 2015 +0000 Improve some struct packings diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 6574278..2df4481 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -227,13 +227,13 @@ struct http_conn { enum sess_close doclose; unsigned maxbytes; unsigned maxhdr; + enum body_status body_status; struct ws *ws; char *rxbuf_b; char *rxbuf_e; char *pipeline_b; char *pipeline_e; ssize_t content_length; - enum body_status body_status; struct vfp_ctx vfc[1]; void *priv; @@ -518,6 +518,9 @@ struct req { unsigned magic; #define REQ_MAGIC 0x2751aaa1 + enum req_step req_step; + volatile enum req_body_state_e req_body_status; + enum sess_close doclose; int restarts; int esi_level; struct req *top; /* esi_level == 0 request */ @@ -526,6 +529,9 @@ struct req { #include "tbl/req_flags.h" #undef REQ_FLAG + uint16_t err_code; + const char *err_reason; + struct sess *sp; struct worker *wrk; struct pool_task task; @@ -533,10 +539,8 @@ struct req { const struct transport *transport; void *transport_priv; - enum req_step req_step; VTAILQ_ENTRY(req) w_list; - volatile enum req_body_state_e req_body_status; struct objcore *body_oc; /* The busy objhead we sleep on */ @@ -549,14 +553,10 @@ struct req { uint8_t digest[DIGEST_LEN]; - enum sess_close doclose; double d_ttl; ssize_t req_bodybytes; /* Parsed req bodybytes */ - uint16_t err_code; - const char *err_reason; - const struct director *director_hint; struct vcl *vcl; @@ -582,6 +582,11 @@ struct req { struct objcore *objcore; struct objcore *stale_oc; + /* Deliver pipeline */ + struct vdp_entry_s vdp; + struct vdp_entry *vdp_nxt; + unsigned vdp_errval; + /* Delivery mode */ unsigned res_mode; #define RES_LEN (1<<1) @@ -592,11 +597,6 @@ struct req { #define RES_GUNZIP (1<<6) #define RES_PIPE (1<<7) - /* Deliver pipeline */ - struct vdp_entry_s vdp; - struct vdp_entry *vdp_nxt; - unsigned vdp_errval; - /* Transaction VSL buffer */ struct vsl_log vsl[1]; diff --git a/include/vsb.h b/include/vsb.h index 4b0099f..72a2a99 100644 --- a/include/vsb.h +++ b/include/vsb.h @@ -37,8 +37,8 @@ struct vsb { unsigned magic; #define VSB_MAGIC 0x4a82dd8a - char *s_buf; /* storage buffer */ int s_error; /* current error code */ + char *s_buf; /* storage buffer */ ssize_t s_size; /* size of storage buffer */ ssize_t s_len; /* current length of string */ #define VSB_FIXEDLEN 0x00000000 /* fixed length buffer (default) */ From dridi.boukelmoune at gmail.com Fri Jul 10 16:07:07 2015 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Fri, 10 Jul 2015 18:07:07 +0200 Subject: [master] 7fd5d87 Typo Message-ID: commit 7fd5d87f5de0faec5cc3ec6afb1f3e926d61357f Author: Dridi Boukelmoune Date: Fri Jul 10 17:56:51 2015 +0200 Typo diff --git a/bin/varnishtest/witness.py b/bin/varnishtest/witness.py index 081429e..6723ef0 100644 --- a/bin/varnishtest/witness.py +++ b/bin/varnishtest/witness.py @@ -12,7 +12,7 @@ from __future__ import print_function d = dict() a = dict() -fi = open("_w") +fi = open("_.w") fo = open("/tmp/_.dot", "w") fo.write('''digraph { From dridi.boukelmoune at gmail.com Fri Jul 10 16:07:07 2015 From: dridi.boukelmoune at gmail.com (Dridi Boukelmoune) Date: Fri, 10 Jul 2015 18:07:07 +0200 Subject: [master] 5ec70b3 Mention the witness facility in varnishtest(1) Message-ID: commit 5ec70b34f39a2d682b2b16ac0b2f7f5a29faa071 Author: Dridi Boukelmoune Date: Fri Jul 10 18:04:19 2015 +0200 Mention the witness facility in varnishtest(1) diff --git a/doc/sphinx/reference/varnishtest.rst b/doc/sphinx/reference/varnishtest.rst index f75a621..14c4ee4 100644 --- a/doc/sphinx/reference/varnishtest.rst +++ b/doc/sphinx/reference/varnishtest.rst @@ -50,6 +50,8 @@ The following options are available: -v Verbose mode: always report test log +-W Enable the witness facility for locking + -h Show help file File to use as a script From fgsch at lodoss.net Fri Jul 10 17:08:30 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:08:30 +0200 Subject: [master] c66fc9f Drop x- prefix following RFC6648 Message-ID: commit c66fc9f3066dff1106d8d58cb5b3a189d9b6a1c7 Author: Federico G. Schwindt Date: Fri Jul 10 17:17:04 2015 +0100 Drop x- prefix following RFC6648 diff --git a/doc/sphinx/users-guide/purging.rst b/doc/sphinx/users-guide/purging.rst index 43df304..578bf50 100644 --- a/doc/sphinx/users-guide/purging.rst +++ b/doc/sphinx/users-guide/purging.rst @@ -121,11 +121,11 @@ object is not available in the `ban lurker` thread. You can use the following template to write `ban lurker` friendly bans:: sub vcl_backend_response { - set beresp.http.x-url = bereq.url; + set beresp.http.url = bereq.url; } sub vcl_deliver { - unset resp.http.x-url; # Optional + unset resp.http.url; # Optional } sub vcl_recv { @@ -133,15 +133,15 @@ You can use the following template to write `ban lurker` friendly bans:: if (client.ip !~ purge) { return(synth(403, "Not allowed")); } - ban("obj.http.x-url ~ " + req.url); # Assumes req.url is a regex. This might be a bit too simple + ban("obj.http.url ~ " + req.url); # Assumes req.url is a regex. This might be a bit too simple } } To inspect the current ban list, issue the ``ban.list`` command in the CLI. This will produce a status of all current bans:: - 0xb75096d0 1318329475.377475 10 obj.http.x-url ~ test - 0xb7509610 1318329470.785875 20G obj.http.x-url ~ test + 0xb75096d0 1318329475.377475 10 obj.http.url ~ test + 0xb7509610 1318329470.785875 20G obj.http.url ~ test The ban list contains the ID of the ban, the timestamp when the ban entered the ban list. A count of the objects that has reached this point diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc index 91fbe30..0ad385f 100644 --- a/lib/libvmod_std/vmod.vcc +++ b/lib/libvmod_std/vmod.vcc @@ -46,14 +46,14 @@ $Function STRING toupper(STRING_LIST s) Description Converts the string *s* to uppercase. Example - set beresp.http.x-scream = std.toupper("yes!"); + set beresp.http.scream = std.toupper("yes!"); $Function STRING tolower(STRING_LIST s) Description Converts the string *s* to lowercase. Example - set beresp.http.x-nice = std.tolower("VerY"); + set beresp.http.nice = std.tolower("VerY"); $Function VOID set_ip_tos(INT tos) @@ -73,7 +73,7 @@ $Function REAL random(REAL lo, REAL hi) Description Returns a random real number between *lo* and *hi*. Example - set beresp.http.x-random-number = std.random(1, 100); + set beresp.http.random-number = std.random(1, 100); $Function VOID log(STRING_LIST s) @@ -102,7 +102,7 @@ Description function the caching in the function doesn't take this into account. Also, files are not re-read. Example - set beresp.http.x-served-by = std.fileread("/etc/hostname"); + set beresp.http.served-by = std.fileread("/etc/hostname"); $Function VOID collect(HEADER hdr) @@ -131,7 +131,7 @@ Description Converts the string *s* to an integer. If conversion fails, *fallback* will be returned. Example - | if (std.integer(req.http.x-foo, 0) > 5) { + | if (std.integer(req.http.foo, 0) > 5) { | ... | } @@ -152,7 +152,7 @@ Description Converts the string *s* to a real. If conversion fails, *fallback* will be returned. Example - | if (std.real(req.http.x-foo, 0.0) > 5.5) { + | if (std.real(req.http.foo, 0.0) > 5.5) { | ... | } @@ -161,21 +161,21 @@ $Function TIME real2time(REAL r) Description Converts the real *r* to a time. Example - set req.http.x-time = std.real2time(1140618699.00); + set req.http.time = std.real2time(1140618699.00); $Function INT time2integer(TIME t) Description Converts the time *t* to a integer. Example - set req.http.x-int = std.time2integer(now); + set req.http.int = std.time2integer(now); $Function REAL time2real(TIME t) Description Converts the time *t* to a real. Example - set req.http.x-real = std.time2real(now); + set req.http.real = std.time2real(now); $Function BOOL healthy(BACKEND be) @@ -231,11 +231,11 @@ Description Note that the comparison is case sensitive. Example - | if (std.strstr(req.url, req.http.x-restrict)) { + | if (std.strstr(req.url, req.http.restrict)) { | ... | } - This will check if the content of req.http.x-restrict occurs + This will check if the content of req.http.restrict occurs anywhere in req.url. $Function TIME time(STRING s, TIME fallback) From fgsch at lodoss.net Fri Jul 10 17:08:30 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:08:30 +0200 Subject: [master] 8d7a165 Typos Message-ID: commit 8d7a165903fd2d7f941f3f17433a36df45a44ef2 Author: Federico G. Schwindt Date: Fri Jul 10 17:22:17 2015 +0100 Typos diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 6494524..05b04da 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -39,7 +39,7 @@ OPTIONS 80 (http) is used. An additional protocol type can be set for the listening socket with PROTO. Valid protocol types are: HTTP/1 (default), and PROXY. - Multiple listening adresses can be specificed by using multiple -a arguments. + Multiple listening addresses can be specified by using multiple -a arguments. -b @@ -252,7 +252,7 @@ specific options. Available jails are: the master process whenever possible. The optional `user` argument specifies which alternative user to - use. It defauls to ``varnish`` + use. It defaults to ``varnish`` The optional `ccgroup` argument specifies a group to add to varnish subprocesses requiring access to a c-compiler. There is no default. @@ -347,7 +347,7 @@ Varnish and bundled tools will, in most cases, exit with one of the following codes * `0` OK -* `1` Some error which could be system-dependend and/or transient +* `1` Some error which could be system-dependent and/or transient * `2` Serious configuration / parameter error - retrying with the same configuration / parameters is most likely useless From fgsch at lodoss.net Fri Jul 10 17:08:30 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:08:30 +0200 Subject: [master] 9c7f0d5 Reword Message-ID: commit 9c7f0d516c99e9b1608f3d629e973440bc4adf9d Author: Federico G. Schwindt Date: Fri Jul 10 17:25:25 2015 +0100 Reword Partially from minusf via github diff --git a/doc/sphinx/users-guide/run_security.rst b/doc/sphinx/users-guide/run_security.rst index 5b9dfad..d83ea18 100644 --- a/doc/sphinx/users-guide/run_security.rst +++ b/doc/sphinx/users-guide/run_security.rst @@ -65,10 +65,10 @@ memory. By using a "localhost" address, you restrict CLI access to the local machine. -You can also bind the CLI port to an IP number reachable across +You can also bind the CLI port to an IP address reachable across the net, and let other machines connect directly. -This gives you no secrecy, ie, the CLI commands will +This gives you no secrecy, i.e. the CLI commands will go across the network as ASCII text with no encryption, but the -S/PSK authentication requires the remote end to know the shared secret. @@ -88,10 +88,8 @@ to your central Varnish management facility. .. XXX:Maybe a sample command here with a brief explanation? benc -The connection is also in this case without secrecy, but -the remote end must still satisfy -S/PSK authentication. - -.. XXX:Without encryption instead of secrecy? benc +The connection in this case is also without encryption, but +the remote end must still authenticate using -S/PSK. Finally, if you run varnishd with the '-d' option, you get a CLI command on stdin/stdout, but since you started the process, it From fgsch at lodoss.net Fri Jul 10 17:17:42 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:17:42 +0200 Subject: [master] 7f5a147 Sync with upstream Message-ID: commit 7f5a1475d1fdfa1a3751a8bc6013170e53143453 Author: Federico G. Schwindt Date: Fri Jul 10 18:17:02 2015 +0100 Sync with upstream diff --git a/etc/devicedetect.vcl b/etc/devicedetect.vcl index be311c5..870d718 100644 --- a/etc/devicedetect.vcl +++ b/etc/devicedetect.vcl @@ -24,7 +24,7 @@ # detectdevice.vcl - regex based device detection for Varnish # https://github.com/varnish/varnish-devicedetect/ # -# Author: Lasse Karstensen +# Author: Lasse Karstensen sub devicedetect { unset req.http.X-UA-Device; @@ -39,7 +39,10 @@ sub devicedetect { /* If the cookie header is now empty, or just whitespace, unset it. */ if (req.http.Cookie ~ "^ *$") { unset req.http.Cookie; } } else { - if (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|)bot" || + if (req.http.User-Agent ~ "\(compatible; Googlebot-Mobile/2.1; \+http://www.google.com/bot.html\)" || + (req.http.User-Agent ~ "iPhone" && req.http.User-Agent ~ "\(compatible; Googlebot/2.1; \+http://www.google.com/bot.html")) { + set req.http.X-UA-Device = "mobile-bot"; } + elsif (req.http.User-Agent ~ "(?i)(ads|google|bing|msn|yandex|baidu|ro|career|)bot" || req.http.User-Agent ~ "(?i)(baidu|jike|symantec)spider" || req.http.User-Agent ~ "(?i)scanner" || req.http.User-Agent ~ "(?i)(web)crawler") { @@ -51,13 +54,14 @@ sub devicedetect { elsif (req.http.User-Agent ~ "(?i)android.*(mobile|mini)") { set req.http.X-UA-Device = "mobile-android"; } // android 3/honeycomb was just about tablet-only, and any phones will probably handle a bigger page layout. elsif (req.http.User-Agent ~ "(?i)android 3") { set req.http.X-UA-Device = "tablet-android"; } - /* see http://my.opera.com/community/openweb/idopera/ */ + /* Opera Mobile */ elsif (req.http.User-Agent ~ "Opera Mobi") { set req.http.X-UA-Device = "mobile-smartphone"; } // May very well give false positives towards android tablets. Suggestions welcome. elsif (req.http.User-Agent ~ "(?i)android") { set req.http.X-UA-Device = "tablet-android"; } elsif (req.http.User-Agent ~ "PlayBook; U; RIM Tablet") { set req.http.X-UA-Device = "tablet-rim"; } elsif (req.http.User-Agent ~ "hp-tablet.*TouchPad") { set req.http.X-UA-Device = "tablet-hp"; } elsif (req.http.User-Agent ~ "Kindle/3") { set req.http.X-UA-Device = "tablet-kindle"; } + elsif (req.http.User-Agent ~ "Touch.+Tablet PC") { set req.http.X-UA-Device = "tablet-microsoft"; } elsif (req.http.User-Agent ~ "Mobile.+Firefox") { set req.http.X-UA-Device = "mobile-firefoxos"; } elsif (req.http.User-Agent ~ "^HTC" || req.http.User-Agent ~ "Fennec" || From fgsch at lodoss.net Fri Jul 10 17:29:03 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:29:03 +0200 Subject: [master] 8a165ad Update URLs Message-ID: commit 8a165adb5a893cea2e9ca76208d4d728d7800275 Author: Federico G. Schwindt Date: Fri Jul 10 18:20:37 2015 +0100 Update URLs diff --git a/doc/sphinx/installation/install.rst b/doc/sphinx/installation/install.rst index f5886cb..398e9af 100644 --- a/doc/sphinx/installation/install.rst +++ b/doc/sphinx/installation/install.rst @@ -36,7 +36,7 @@ on `repo.varnish-cache.org `_. See the online `_ for more information. Varnish is included in the `EPEL -`_ repository, however due to +`_ repository, however due to incompatible syntax changes in newer versions of Varnish, only older versions are available. diff --git a/doc/sphinx/phk/dough.rst b/doc/sphinx/phk/dough.rst index 65b53f8..b629e8b 100644 --- a/doc/sphinx/phk/dough.rst +++ b/doc/sphinx/phk/dough.rst @@ -260,7 +260,7 @@ Poul-Henning, 2014-04-11 .. _Varnish Moral License: http://phk.freebsd.dk/VML -.. _solicited the FreeBSD community: http://people.freebsd.org/~phk/funding.html +.. _solicited the FreeBSD community: https://people.freebsd.org/~phk/funding.html .. _Extremely Large Telescope: http://www.eso.org/public/teles-instr/e-elt/ diff --git a/doc/sphinx/phk/platforms.rst b/doc/sphinx/phk/platforms.rst index 6f448e6..18ee017 100644 --- a/doc/sphinx/phk/platforms.rst +++ b/doc/sphinx/phk/platforms.rst @@ -47,7 +47,7 @@ Platform specific bug reports gets acted on. *Linux* Obviously you can forget about running Varnish on your -`WRT54G `_ +`WRT54G `_ but if you have a real computer, you can expect Varnish to work "ok or better" on any distro that has a package available. diff --git a/doc/sphinx/phk/sphinx.rst b/doc/sphinx/phk/sphinx.rst index b6e23f7..d001826 100644 --- a/doc/sphinx/phk/sphinx.rst +++ b/doc/sphinx/phk/sphinx.rst @@ -64,7 +64,7 @@ link at the bottom of the left menu: (link to random python doc page:) - http://docs.python.org/py3k/reference/expressions.html + https://docs.python.org/py3k/reference/expressions.html Dependency wise, that means you can edit docs with no special tools, you need python+docutils+sphinx to format HTML and a LaTex diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c index 664332b..e3bd2eb 100644 --- a/lib/libvarnish/binary_heap.c +++ b/lib/libvarnish/binary_heap.c @@ -29,7 +29,7 @@ * Implementation of a binary heap API * * See also: - * http://portal.acm.org/citation.cfm?doid=1785414.1785434 + * http://dl.acm.org/citation.cfm?doid=1785414.1785434 * (or: http://queue.acm.org/detail.cfm?id=1814327) */ diff --git a/varnish.m4 b/varnish.m4 index b7ad6f9..fcf6b2d 100644 --- a/varnish.m4 +++ b/varnish.m4 @@ -48,7 +48,7 @@ PKG_CHECK_EXISTS([varnishapi],[],[ is in your PATH or set the PKG_CONFIG environment variable to the full path to pkg-config. -To get pkg-config, see .]) +To get pkg-config, see .]) else AC_MSG_FAILURE( [pkg-config was unable to locate the varnishapi configuration data. From fgsch at lodoss.net Fri Jul 10 17:29:03 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 10 Jul 2015 19:29:03 +0200 Subject: [master] 6834a80 Log if we retried too many times from v_b_e too Message-ID: commit 6834a80205fa9803e70e341b0f087f97dc702288 Author: Federico G. Schwindt Date: Fri Jul 10 18:26:06 2015 +0100 Log if we retried too many times from v_b_e too diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 0d7ba9f..12703bd 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -808,9 +808,12 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo) VDI_Finish(bo->wrk, bo); } - if (wrk->handling == VCL_RET_RETRY && - bo->retries++ < cache_param->max_retries) - return (F_STP_RETRY); + if (wrk->handling == VCL_RET_RETRY) { + if (bo->retries++ < cache_param->max_retries) + return (F_STP_RETRY); + VSLb(bo->vsl, SLT_VCL_Error, + "Too many retries, delivering 503"); + } return (F_STP_FAIL); } From phk at FreeBSD.org Sat Jul 11 20:19:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 11 Jul 2015 22:19:35 +0200 Subject: [master] f6a7903 Mark [u]sleep() to not check return value by default Message-ID: commit f6a7903640ba5b3b91abcecbdbed0aa99766fbd1 Author: Poul-Henning Kamp Date: Sat Jul 11 20:13:46 2015 +0000 Mark [u]sleep() to not check return value by default diff --git a/flint.lnt b/flint.lnt index 000968a..434c54a 100644 --- a/flint.lnt +++ b/flint.lnt @@ -38,6 +38,9 @@ -esym(534, strlcpy) -esym(534, strncpy) +-esym(534, sleep) +-esym(534, usleep) + /////////////////////////////////////////////////////////////////////// // From phk at FreeBSD.org Sat Jul 11 20:19:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 11 Jul 2015 22:19:35 +0200 Subject: [master] 17fbc57 Make NEEDLESS_RETURN part of vdef.h Message-ID: commit 17fbc579e3409fc6be3d8a7f79caa0d3b5076abb Author: Poul-Henning Kamp Date: Sat Jul 11 20:16:58 2015 +0000 Make NEEDLESS_RETURN part of vdef.h diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h index a97986c..7b2c371 100644 --- a/bin/varnishd/common/common.h +++ b/bin/varnishd/common/common.h @@ -103,8 +103,6 @@ void mgt_child_inherit(int fd, const char *what); exit(2); \ } while (0) -#define NEEDLESS_RETURN(foo) return (foo) - /* cache/cache_vcl.c */ int VCL_TestLoad(const char *); diff --git a/include/vdef.h b/include/vdef.h index 5d52ddb..f6592b3 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -78,5 +78,6 @@ */ #define __match_proto__(xxx) /*lint -e{818} */ +#define NEEDLESS_RETURN(foo) return (foo) #endif /* VDEF_H_INCLUDED */ diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index e662bee..989ee0a 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -51,8 +51,6 @@ #include "vsl_api.h" #include "vxp.h" -#define NEEDLESS_RETURN(foo) return(foo) - struct vslq_query { unsigned magic; #define VSLQ_QUERY_MAGIC 0x122322A5 From phk at FreeBSD.org Sat Jul 11 20:19:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 11 Jul 2015 22:19:35 +0200 Subject: [master] b8d70b0 Polish Message-ID: commit b8d70b078bcf403402644f69259c7f7cdb463662 Author: Poul-Henning Kamp Date: Sat Jul 11 20:19:24 2015 +0000 Polish diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index f44d220..1309df0 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -438,8 +438,8 @@ cmd_shell(CMD_ARGS) r = system(av[1]); s = WEXITSTATUS(r); if (s != 0) - vtc_log(vl, 0, "CMD '%s' failed with status %d", - av[1], s); + vtc_log(vl, 0, "CMD '%s' failed with status %d (%s)", + av[1], s, strerror(errno)); } /********************************************************************** @@ -635,7 +635,7 @@ exec_file(const char *fn, const char *script, const char *tmpdir, FILE *f; struct extmacro *m; - signal(SIGPIPE, SIG_IGN); + (void)signal(SIGPIPE, SIG_IGN); vtc_loginit(logbuf, loglen); vltop = vtc_logopen("top"); diff --git a/bin/varnishtest/vtc_process.c b/bin/varnishtest/vtc_process.c index 157bfa9..fffe9bf 100644 --- a/bin/varnishtest/vtc_process.c +++ b/bin/varnishtest/vtc_process.c @@ -43,8 +43,6 @@ #include "vtc.h" -#include "vss.h" - struct process { unsigned magic; #define PROCESS_MAGIC 0x1617b43e @@ -225,7 +223,7 @@ process_start(struct process *p) */ static void -process_wait(struct process *p) +process_wait(const struct process *p) { void *v; @@ -238,37 +236,34 @@ process_wait(struct process *p) */ static void -process_kill(struct process *p, const char *sig) +process_kill(const struct process *p, const char *sig) { - int s, l; + int s; char buf[64]; CHECK_OBJ_NOTNULL(p, PROCESS_MAGIC); AN(sig); - if (!p->running || !p->pid) { + if (!p->running || !p->pid) vtc_log(p->vl, 0, "Cannot signal a non-running process"); - return; - } - vtc_log(p->vl, 4, "CMD: kill -%s %d", sig, p->pid); + bprintf(buf, "kill -%s %d", sig, p->pid); + vtc_log(p->vl, 4, "CMD: %s", buf); - l = snprintf(buf, sizeof buf, "kill -%s %d", sig, p->pid); - AN(l < sizeof buf); s = system(buf); if (s != 0) vtc_log(p->vl, 0, "Failed to send signal (exit status: %d)", s); } static inline void -process_stop(struct process *p) +process_stop(const struct process *p) { process_kill(p, "TERM"); } static inline void -process_terminate(struct process *p) +process_terminate(const struct process *p) { process_kill(p, "TERM"); @@ -282,14 +277,12 @@ process_terminate(struct process *p) */ static void -process_write(struct process *p, const char *text) +process_write(const struct process *p, const char *text) { int r, len; - if (!p->running || !p->pid) { + if (!p->running || !p->pid) vtc_log(p->vl, 0, "Cannot write to a non-running process"); - return; - } len = strlen(text); vtc_log(p->vl, 4, "Writing %d bytes", len); @@ -303,10 +296,8 @@ static void process_close(struct process *p) { - if (!p->running || !p->pid) { + if (!p->running || !p->pid) vtc_log(p->vl, 0, "Cannot close on a non-running process"); - return; - } AZ(close(p->fds[1])); p->fds[1] = -1; From phk at FreeBSD.org Sat Jul 11 20:25:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 11 Jul 2015 22:25:52 +0200 Subject: [master] f9fccc0 Try fixing the u00001 instability by retrying polls which fail with EINTR. Message-ID: commit f9fccc0430ca1c963da1f8c67316bd1737bd5e7e Author: Poul-Henning Kamp Date: Sat Jul 11 20:24:54 2015 +0000 Try fixing the u00001 instability by retrying polls which fail with EINTR. I suspect the underlying issue is that SIGCHLD is being sent to a random thread and that happens to be the s1 thread on some platforms. diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 5a291dc..ec1350a 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -387,6 +387,8 @@ http_rxchar(struct http *hp, int n, int eof) pfd[0].events = POLLIN; pfd[0].revents = 0; i = poll(pfd, 1, hp->timeout); + if (i < 0 && errno == EINTR) + continue; if (i == 0) vtc_log(hp->vl, hp->fatal, "HTTP rx timeout (fd:%d %u ms)", @@ -1215,6 +1217,8 @@ cmd_http_expect_close(CMD_ARGS) fds[0].events = POLLIN | POLLERR; fds[0].revents = 0; i = poll(fds, 1, hp->timeout); + if (i < 0 && errno == EINTR) + continue; if (i == 0) vtc_log(vl, hp->fatal, "Expected close: timeout"); if (i != 1 || !(fds[0].revents & (POLLIN|POLLERR))) From phk at FreeBSD.org Sun Jul 12 09:10:44 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 12 Jul 2015 11:10:44 +0200 Subject: [master] 74c49a2 Eliminate the backend refcount, n_conn serves as refcount and is all we need. Message-ID: commit 74c49a2e89c24312fda5aefc7b690271bdc47ffa Author: Poul-Henning Kamp Date: Sun Jul 12 08:19:59 2015 +0000 Eliminate the backend refcount, n_conn serves as refcount and is all we need. Send warm dynamic backends "COLD" event before deleting them. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 611c089..0591ec7 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -103,7 +103,6 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) AN(vc->addr); Lck_Lock(&bp->mtx); - bp->refcount++; bp->n_conn++; bp->vsc->conn++; Lck_Unlock(&bp->mtx); @@ -330,7 +329,7 @@ vbe_panic(const struct director *d, struct vsb *vsb) VSB_printf(vsb, " health=%s, admin_health=%s", bp->healthy ? "healthy" : "sick", bp->admin_health); VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed); - VSB_printf(vsb, " refcount = %d\n", bp->refcount); + VSB_printf(vsb, " n_conn = %u\n", bp->n_conn); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 97e70c1..49fc110 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -52,7 +52,6 @@ struct backend { VTAILQ_ENTRY(backend) list; VTAILQ_ENTRY(backend) vcl_list; - int refcount; struct lock mtx; VRT_BACKEND_FIELDS() @@ -129,4 +128,4 @@ void VBT_Wait(struct worker *, struct vbc *); /* cache_vcl.c */ void VCL_AddBackend(struct vcl *, struct backend *); -void VCL_DelBackend(const struct backend *); +void VCL_DelBackend(struct backend *); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index a9199d3..8b89625 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -70,13 +70,11 @@ VRT_new_backend(VRT_CTX, const struct vrt_backend *vrt) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC); - assert(vrt->ipv4_suckaddr != NULL || vrt->ipv6_suckaddr != NULL); vcl = ctx->vcl; AN(vcl); AN(vrt->vcl_name); - assert(vrt->ipv4_suckaddr != NULL || vrt->ipv6_suckaddr != NULL); /* Create new backend */ ALLOC_OBJ(b, BACKEND_MAGIC); diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index b450361..c10d949 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -205,7 +205,7 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be) } void -VCL_DelBackend(const struct backend *be) +VCL_DelBackend(struct backend *be) { struct vcl *vcl; @@ -215,6 +215,8 @@ VCL_DelBackend(const struct backend *be) Lck_Lock(&vcl_mtx); VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list); Lck_Unlock(&vcl_mtx); + if (vcl->temp == vcl_temp_warm) + VBE_Event(be, VCL_EVENT_COLD); } static void From phk at FreeBSD.org Sun Jul 12 09:10:44 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 12 Jul 2015 11:10:44 +0200 Subject: [master] 4e8f14c Having researched it rather comprehensively, I have decided that there is no sane way to refcount (dynamic) backends in relation to VCL use at this point in the 4.1 release cycle. Message-ID: commit 4e8f14c495a34728f75856b070a09cfa3c87e64f Author: Poul-Henning Kamp Date: Sun Jul 12 09:07:02 2015 +0000 Having researched it rather comprehensively, I have decided that there is no sane way to refcount (dynamic) backends in relation to VCL use at this point in the 4.1 release cycle. Solve the problem, for now, by cooling dynamic backends off for a minute before actually removing them. Varnish 5 will have to look at proper refcounting of (all) VCL objects. diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 49fc110..17b90f0 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -50,6 +50,8 @@ struct backend { unsigned magic; #define BACKEND_MAGIC 0x64c4c7c6 + unsigned n_conn; + VTAILQ_ENTRY(backend) list; VTAILQ_ENTRY(backend) vcl_list; struct lock mtx; @@ -59,7 +61,6 @@ struct backend { struct vcl *vcl; char *display_name; - unsigned n_conn; struct vbp_target *probe; unsigned healthy; @@ -71,6 +72,8 @@ struct backend { struct tcp_pool *tcp_pool; struct director director[1]; + + double cooled; }; /*--------------------------------------------------------------------- diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 8b89625..3db5dbd 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -48,6 +48,8 @@ #include "cache_backend.h" static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); +static VTAILQ_HEAD(, backend) cool_backends = + VTAILQ_HEAD_INITIALIZER(cool_backends); static struct lock backends_mtx; static const char * const vbe_ah_healthy = "healthy"; @@ -130,7 +132,6 @@ VRT_delete_backend(VRT_CTX, struct director **dp) { struct director *d; struct backend *be; - int r; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); AN(dp); @@ -141,17 +142,10 @@ VRT_delete_backend(VRT_CTX, struct director **dp) Lck_Lock(&be->mtx); be->admin_health = vbe_ah_deleted; be->health_changed = VTIM_real(); - r = be->n_conn; - if (r > 0) { - /* move to front of list for fast access */ - VTAILQ_REMOVE(&backends, be, list); - VTAILQ_INSERT_HEAD(&backends, be, list); - } + be->cooled = VTIM_real() + 60.; + VTAILQ_REMOVE(&backends, be, list); + VTAILQ_INSERT_TAIL(&cool_backends, be, list); Lck_Unlock(&be->mtx); - if (r == 0) { - VCL_DelBackend(be); - VBE_Delete(be); - } } /*--------------------------------------------------------------------- @@ -191,7 +185,10 @@ VBE_Delete(struct backend *be) VBP_Remove(be); Lck_Lock(&backends_mtx); - VTAILQ_REMOVE(&backends, be, list); + if (be->cooled > 0) + VTAILQ_REMOVE(&cool_backends, be, list); + else + VTAILQ_REMOVE(&backends, be, list); VSC_C_main->n_backend--; VBT_Rel(&be->tcp_pool); Lck_Unlock(&backends_mtx); @@ -425,18 +422,21 @@ void VBE_Poll(void) { struct backend *be; + double now = VTIM_real(); + + Lck_Lock(&backends_mtx); while (1) { - Lck_Lock(&backends_mtx); - be = VTAILQ_FIRST(&backends); + be = VTAILQ_FIRST(&cool_backends); if (be == NULL) break; - if (be->admin_health != vbe_ah_deleted) + if (be->cooled > now) break; if (be->n_conn > 0) - break; + continue; Lck_Unlock(&backends_mtx); VCL_DelBackend(be); VBE_Delete(be); + Lck_Lock(&backends_mtx); } Lck_Unlock(&backends_mtx); } From phk at FreeBSD.org Sun Jul 12 09:10:44 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 12 Jul 2015 11:10:44 +0200 Subject: [master] 5811a87 Add Dridi's test-suite for dynamic backends, with some semi-heavy modifications relating to the object refcount issue. Message-ID: commit 5811a87e33056e8aeb8bce3fcfdc0c5023b67a43 Author: Poul-Henning Kamp Date: Sun Jul 12 09:10:03 2015 +0000 Add Dridi's test-suite for dynamic backends, with some semi-heavy modifications relating to the object refcount issue. diff --git a/bin/varnishtest/tests/d00007.vtc b/bin/varnishtest/tests/d00007.vtc new file mode 100644 index 0000000..298fbf7 --- /dev/null +++ b/bin/varnishtest/tests/d00007.vtc @@ -0,0 +1,28 @@ +varnishtest "Test dynamic backends" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + set req.backend_hint = s1.backend(); + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run diff --git a/bin/varnishtest/tests/d00008.vtc b/bin/varnishtest/tests/d00008.vtc new file mode 100644 index 0000000..a30edd8 --- /dev/null +++ b/bin/varnishtest/tests/d00008.vtc @@ -0,0 +1,52 @@ +varnishtest "Test dynamic backends hot swap" + +server s1 { + rxreq + expect req.url == "/foo" + txresp +} -start + +server s2 { + rxreq + expect req.url == "/bar" + txresp +} -start + +varnish v1 -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + if (req.method == "SWAP") { + s1.refresh(req.http.X-Addr, req.http.X-Port); + return (synth(200)); + } + set req.backend_hint = s1.backend(); + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + + txreq -req "SWAP" -hdr "X-Addr: ${s2_addr}" -hdr "X-Port: ${s2_port}" + rxresp + expect resp.status == 200 + + txreq -url "/bar" + rxresp + expect resp.status == 200 +} -run + +delay 1 + +varnish v1 -cli backend.list +# varnish v1 -expect MAIN.n_backend == 2 diff --git a/bin/varnishtest/tests/d00009.vtc b/bin/varnishtest/tests/d00009.vtc new file mode 100644 index 0000000..c888d20 --- /dev/null +++ b/bin/varnishtest/tests/d00009.vtc @@ -0,0 +1,58 @@ +varnishtest "Test dynamic backends hot swap while being used" + +server s1 { + rxreq + expect req.url == "/foo" + sema r1 sync 2 + sema r2 sync 2 + txresp +} -start + +server s2 { + rxreq + expect req.url == "/bar" + sema r2 sync 2 + txresp +} -start + +varnish v1 -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + if (req.method == "SWAP") { + s1.refresh(req.http.X-Addr, req.http.X-Port); + return (synth(200)); + } + set req.backend_hint = s1.backend(); + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 +} -start + +client c2 { + sema r1 sync 2 + txreq -req "SWAP" -hdr "X-Addr: ${s2_addr}" -hdr "X-Port: ${s2_port}" + rxresp + expect resp.status == 200 + + txreq -url "/bar" + rxresp + expect resp.status == 200 +} -run + +client c1 -wait + +varnish v1 -cli backend.list +# varnish v1 -expect MAIN.n_backend == 2 diff --git a/bin/varnishtest/tests/d00010.vtc b/bin/varnishtest/tests/d00010.vtc new file mode 100644 index 0000000..1db0ea7 --- /dev/null +++ b/bin/varnishtest/tests/d00010.vtc @@ -0,0 +1,59 @@ +varnishtest "Test dynamic backends hot swap during a pipe" + +server s1 { + rxreq + expect req.url == "/foo" + sema r1 sync 2 + sema r2 sync 2 + txresp +} -start + +server s2 { + rxreq + expect req.url == "/bar" + sema r2 sync 2 + txresp +} -start + +varnish v1 -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + if (req.method == "SWAP") { + s1.refresh(req.http.X-Addr, req.http.X-Port); + return (synth(200)); + } + set req.backend_hint = s1.backend(); + return (pipe); + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 +} -start + +client c2 { + sema r1 sync 2 + txreq -req "SWAP" -hdr "X-Addr: ${s2_addr}" -hdr "X-Port: ${s2_port}" + rxresp + expect resp.status == 200 + + txreq -url "/bar" + rxresp + expect resp.status == 200 +} -run + +client c1 -wait + +varnish v1 -cli backend.list +#varnish v1 -expect MAIN.n_backend == 2 diff --git a/bin/varnishtest/tests/d00011.vtc b/bin/varnishtest/tests/d00011.vtc new file mode 100644 index 0000000..01d45a1 --- /dev/null +++ b/bin/varnishtest/tests/d00011.vtc @@ -0,0 +1,62 @@ +varnishtest "Test a dynamic backend hot swap after it was picked by a bereq" + +server s1 { +} -start + +server s2 { + rxreq + txresp +} -start + +varnish v1 -vcl { + import ${vmod_std}; + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + if (req.method == "SWAP") { + s1.refresh(req.http.X-Addr, req.http.X-Port); + return (synth(200)); + } + } + + sub vcl_backend_fetch { + set bereq.backend = s1.backend(); + # hot swap should happen while we sleep + debug.sleep(2s); + if (std.healthy(bereq.backend)) { + return(abandon); + } else { + set bereq.backend = s1.backend(); + } + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq + sema r2 sync 2 + rxresp + expect resp.status == 200 +} + +client c2 { + sema r2 sync 2 + delay 0.1 + txreq -req "SWAP" -hdr "X-Addr: ${s2_addr}" -hdr "X-Port: ${s2_port}" + rxresp + expect resp.status == 200 +} + +client c1 -start +client c2 -run +client c1 -wait + +varnish v1 -cli backend.list +#varnish v1 -expect MAIN.n_backend == 2 diff --git a/bin/varnishtest/tests/d00012.vtc b/bin/varnishtest/tests/d00012.vtc new file mode 100644 index 0000000..74aaa8d --- /dev/null +++ b/bin/varnishtest/tests/d00012.vtc @@ -0,0 +1,77 @@ +varnishtest "Test a dynamic backend discard during a request" + +# vcl.discard testing inspired by v00006.vtc from commit e1f7207 + +server s1 { + rxreq + expect req.url == "/foo" + sema r1 sync 2 + txresp +} -start + +varnish v1 -arg "-p thread_pools=1" -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + set req.backend_hint = s1.backend(); + } +} -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 +} -start + +varnish v1 -expect MAIN.n_backend == 2 +# expected: vcl1.dummy, vcl1.s1 + +server s2 { + rxreq + expect req.url == "/bar" + txresp +} -start + +varnish v1 -vcl { + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s2 = debug.dyn("${s2_addr}", "${s2_port}"); + } + + sub vcl_recv { + set req.backend_hint = s2.backend(); + } +} + +varnish v1 -cli "vcl.discard vcl1" +sema r1 sync 2 + +client c1 -wait +delay 2 + +varnish v1 -expect MAIN.n_backend == 4 +# expected: vcl1.dummy, vcl1.s1, vcl2.dummy, vcl2.s2 + +varnish v1 -expect n_vcl_avail == 1 +varnish v1 -expect n_vcl_discard == 1 + +client c1 { + txreq -url "/bar" + rxresp + expect resp.status == 200 +} -run + +varnish v1 -cli "vcl.list" +#varnish v1 -expect MAIN.n_backend == 2 +# expected: vcl2.dummy, vcl2.s2 +varnish v1 -expect n_vcl_avail == 1 +varnish v1 -expect n_vcl_discard == 0 diff --git a/bin/varnishtest/tests/d00013.vtc b/bin/varnishtest/tests/d00013.vtc new file mode 100644 index 0000000..25ab33f --- /dev/null +++ b/bin/varnishtest/tests/d00013.vtc @@ -0,0 +1,59 @@ +varnishtest "Test a dynamic backend hot swap after it was hinted to a req" + +server s1 { +} -start + +server s2 { + rxreq + txresp +} -start + +varnish v1 -vcl { + import ${vmod_std}; + import ${vmod_debug}; + + backend dummy { .host = "${bad_ip}"; } + + sub vcl_init { + new s1 = debug.dyn("${s1_addr}", "${s1_port}"); + } + + sub vcl_recv { + if (req.method == "SWAP") { + s1.refresh(req.http.X-Addr, req.http.X-Port); + return (synth(200)); + } + set req.backend_hint = s1.backend(); + # hot swap should happen while we sleep + debug.sleep(2s); + if (std.healthy(req.backend_hint)) { + return(synth(800)); + } else { + set req.backend_hint = s1.backend(); + } + } +} -start + +varnish v1 -expect MAIN.n_backend == 2 + +client c1 { + txreq + sema r2 sync 2 + rxresp + expect resp.status == 200 +} + +client c2 { + sema r2 sync 2 + delay 0.1 + txreq -req "SWAP" -hdr "X-Addr: ${s2_addr}" -hdr "X-Port: ${s2_port}" + rxresp + expect resp.status == 200 +} + +client c1 -start +client c2 -run +client c1 -wait + +varnish v1 -cli backend.list +#varnish v1 -expect MAIN.n_backend == 2 diff --git a/lib/libvmod_debug/Makefile.am b/lib/libvmod_debug/Makefile.am index d189102..9115713 100644 --- a/lib/libvmod_debug/Makefile.am +++ b/lib/libvmod_debug/Makefile.am @@ -17,14 +17,15 @@ libvmod_debug_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version libvmod_debug_la_SOURCES = \ vmod_debug.c \ - vmod_debug_obj.c + vmod_debug_obj.c \ + vmod_debug_dyn.c nodist_libvmod_debug_la_SOURCES = \ vcc_if.c \ vcc_if.h # BUILT_SOURCES is only a hack and dependency tracking does not help for the first build -vmod_debug.lo vmod_debug_obj.lo: vcc_if.h +vmod_debug.lo vmod_debug_obj.lo vmod_debug_dyn.lo: vcc_if.h vcc_if.c vcc_if.h vmod_debug.rst vmod_debug.man.rst: $(vmodtool) $(vmod_srcdir)/vmod.vcc @PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index 305deaa..3a60814 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -108,4 +108,16 @@ Function to fail vcl_init{} $Function VOID sleep(DURATION) -Block the current worker thread. +Sleep the current worker thread. + +$Object dyn(STRING addr, STRING port) + +Dynamically create a single-backend director + +$Method BACKEND .backend() + +Return the dynamic backend. + +$Method VOID .refresh(STRING addr, STRING port) + +Dynamically refresh & (always!) replace the backend by a new one. diff --git a/lib/libvmod_debug/vmod_debug_dyn.c b/lib/libvmod_debug/vmod_debug_dyn.c new file mode 100644 index 0000000..7e4afea --- /dev/null +++ b/lib/libvmod_debug/vmod_debug_dyn.c @@ -0,0 +1,165 @@ +/*- + * Copyright (c) 2015 Varnish Software AS + * All rights reserved. + * + * Author: Dridi Boukelmoune + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" + +#include +#include +#include + +#include +#include + +#include "vcl.h" +#include "vrt.h" + +#include "cache/cache.h" +#include "cache/cache_director.h" +#include "cache/cache_backend.h" + +#include "vsa.h" +#include "vcc_if.h" + +struct vmod_debug_dyn { + unsigned magic; +#define VMOD_DEBUG_DYN_MAGIC 0x9b77ccbd + pthread_mutex_t mtx; + char *vcl_name; + struct director *dir; +}; + +static void +dyn_dir_init(VRT_CTX, struct vmod_debug_dyn *dyn, + VCL_STRING addr, VCL_STRING port) +{ + struct addrinfo hints, *res = NULL; + struct suckaddr *sa; + struct director *dir, *dir2; + struct vrt_backend vrt; + + CHECK_OBJ_NOTNULL(dyn, VMOD_DEBUG_DYN_MAGIC); + XXXAN(addr); + XXXAN(port); + + INIT_OBJ(&vrt, VRT_BACKEND_MAGIC); + vrt.port = port; + vrt.vcl_name = dyn->vcl_name; + vrt.hosthdr = vrt.ipv4_addr; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + AZ(getaddrinfo(vrt.ipv4_addr, vrt.port, &hints, &res)); + XXXAZ(res->ai_next); + + sa = VSA_Malloc(res->ai_addr, res->ai_addrlen); + AN(sa); + if (VSA_Get_Proto(sa) == AF_INET) { + vrt.ipv4_addr = addr; + vrt.ipv4_suckaddr = sa; + } else if (VSA_Get_Proto(sa) == AF_INET6) { + vrt.ipv6_addr = addr; + vrt.ipv6_suckaddr = sa; + } else + WRONG("Wrong proto family"); + + freeaddrinfo(res); + + dir = VRT_new_backend(ctx, &vrt); + AN(dir); + + /* + * NB: A real dynamic backend should not replace the previous + * instance if the new one is identical. We do it here because + * the d* tests requires a replacement. + */ + AZ(pthread_mutex_lock(&dyn->mtx)); + dir2 = dyn->dir; + dyn->dir = dir; + AZ(pthread_mutex_unlock(&dyn->mtx)); + + if (dir2 != NULL) + VRT_delete_backend(ctx, &dir2); + + free(sa); +} + +VCL_VOID +vmod_dyn__init(VRT_CTX, struct vmod_debug_dyn **dynp, + const char *vcl_name, VCL_STRING addr, VCL_STRING port) +{ + struct vmod_debug_dyn *dyn; + + ASSERT_CLI(); + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + AN(dynp); + AZ(*dynp); + AN(vcl_name); + + ALLOC_OBJ(dyn, VMOD_DEBUG_DYN_MAGIC); + AN(dyn); + REPLACE(dyn->vcl_name, vcl_name); + + AZ(pthread_mutex_init(&dyn->mtx, NULL)); + + dyn_dir_init(ctx, dyn, addr, port); + XXXAN(dyn->dir); + *dynp = dyn; +} + +VCL_VOID +vmod_dyn__fini(struct vmod_debug_dyn **dynp) +{ + struct vmod_debug_dyn *dyn; + + AN(dynp); + CAST_OBJ_NOTNULL(dyn, *dynp, VMOD_DEBUG_DYN_MAGIC); + /* at this point all backends will be deleted by the vcl */ + free(dyn->vcl_name); + AZ(pthread_mutex_destroy(&dyn->mtx)); + FREE_OBJ(dyn); + *dynp = NULL; +} + +VCL_BACKEND __match_proto__() +vmod_dyn_backend(VRT_CTX, struct vmod_debug_dyn *dyn) +{ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(dyn, VMOD_DEBUG_DYN_MAGIC); + AN(dyn->dir); + return (dyn->dir); +} + +VCL_VOID +vmod_dyn_refresh(VRT_CTX, struct vmod_debug_dyn *dyn, + VCL_STRING addr, VCL_STRING port) +{ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(dyn, VMOD_DEBUG_DYN_MAGIC); + dyn_dir_init(ctx, dyn, addr, port); +} From nils.goroll at uplex.de Sun Jul 12 21:29:54 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Sun, 12 Jul 2015 23:29:54 +0200 Subject: [master] a87b589 wrap the vxid on VSL_IDENTMASK Message-ID: commit a87b589b00e788a4294c1b2be68e26a7b4f3fc77 Author: Nils Goroll Date: Sun Jul 12 23:28:16 2015 +0200 wrap the vxid on VSL_IDENTMASK We spilled into the client marker bit when reaching 1<<30 diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index f95bc77..22d3870 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -129,7 +129,7 @@ VXID_Get(struct worker *wrk, uint32_t mask) Lck_Lock(&vxid_lock); v->next = vxid_base; v->count = vxid_chunk; - vxid_base += v->count; + vxid_base = (vxid_base + v->count) && VSL_IDENTMASK; Lck_Unlock(&vxid_lock); } v->count--; From nils.goroll at uplex.de Sun Jul 12 21:57:15 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Sun, 12 Jul 2015 23:57:15 +0200 Subject: [master] 0dd8c0b Fix: wrap the vxid on VSL_IDENTMASK Message-ID: commit 0dd8c0b864a9574df0f2891824b4581d0e846613 Author: Nils Goroll Date: Sun Jul 12 23:51:29 2015 +0200 Fix: wrap the vxid on VSL_IDENTMASK WHOA - sorry diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 22d3870..e47f685 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -129,7 +129,7 @@ VXID_Get(struct worker *wrk, uint32_t mask) Lck_Lock(&vxid_lock); v->next = vxid_base; v->count = vxid_chunk; - vxid_base = (vxid_base + v->count) && VSL_IDENTMASK; + vxid_base = (vxid_base + v->count) & VSL_IDENTMASK; Lck_Unlock(&vxid_lock); } v->count--; From fgsch at lodoss.net Mon Jul 13 14:42:02 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 13 Jul 2015 16:42:02 +0200 Subject: [master] 335708c Consistency Message-ID: commit 335708cd604720f46a2cb8a51848495f4dea7d61 Author: Federico G. Schwindt Date: Mon Jul 13 12:53:29 2015 +0100 Consistency diff --git a/lib/libvmod_directors/vmod.vcc b/lib/libvmod_directors/vmod.vcc index 2e958a7..cfcf2e3 100644 --- a/lib/libvmod_directors/vmod.vcc +++ b/lib/libvmod_directors/vmod.vcc @@ -132,8 +132,8 @@ Description to this director. Example - vdir.add_backend(backend1, 10); - vdir.add_backend(backend2, 5); + vdir.add_backend(backend1, 10.0); + vdir.add_backend(backend2, 5.0); # 2/3 to backend1, 1/3 to backend2. From nils.goroll at uplex.de Mon Jul 13 14:56:07 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 13 Jul 2015 16:56:07 +0200 Subject: [4.0] ca37d86 Add a VXID() macro to strip client/backend bit from VXIDs. Message-ID: commit ca37d86639b90351f98484f2e6eee17a5f3638fa Author: Nils Goroll Date: Tue Jul 22 13:45:45 2014 +0000 Add a VXID() macro to strip client/backend bit from VXIDs. backport of master cfb309cad60e0239bc7168082d73b4ab6b53744a Original commit Author: Poul-Henning Kamp diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 0fb6206..c22878d 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -1054,6 +1054,7 @@ unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*); #undef HTTPH /* cache_main.c */ +#define VXID(u) ((u) & VSL_IDENTMASK) uint32_t VXID_Get(struct vxid_pool *v); extern volatile struct params * cache_param; void THR_SetName(const char *name); diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index fee1240..45cfb32 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -64,8 +64,8 @@ ved_include(struct req *preq, const char *src, const char *host) req->req_body_status = REQ_BODY_NONE; AZ(req->vsl->wid); req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER; - VSLb(req->vsl, SLT_Begin, "req %u esi", preq->vsl->wid & VSL_IDENTMASK); - VSLb(preq->vsl, SLT_Link, "req %u esi", req->vsl->wid & VSL_IDENTMASK); + VSLb(req->vsl, SLT_Begin, "req %u esi", VXID(preq->vsl->wid)); + VSLb(preq->vsl, SLT_Link, "req %u esi", VXID(req->vsl->wid)); req->esi_level = preq->esi_level + 1; HTTP_Copy(req->http0, preq->http0); diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c index a893ecc..e55b6dd 100644 --- a/bin/varnishd/cache/cache_expire.c +++ b/bin/varnishd/cache/cache_expire.c @@ -334,8 +334,7 @@ EXP_NukeOne(struct busyobj *bo, struct lru *lru) exp_mail_it(oc); - VSLb(bo->vsl, SLT_ExpKill, "LRU x=%u", - oc_getxid(bo->stats, oc) & VSL_IDENTMASK); + VSLb(bo->vsl, SLT_ExpKill, "LRU x=%u", VXID(oc_getxid(bo->stats, oc))); AN(bo->stats); AN(oc); (void)HSH_DerefObjCore(bo->stats, &oc); @@ -535,7 +534,7 @@ exp_expire(struct exp_priv *ep, double now) o = oc_getobj(&ep->wrk->stats, oc); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f", - oc_getxid(&ep->wrk->stats, oc) & VSL_IDENTMASK, + VXID(oc_getxid(&ep->wrk->stats, oc)), EXP_Ttl(NULL, o) - now); (void)HSH_DerefObjCore(&ep->wrk->stats, &oc); return (0); diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index fbb7110..973be8d 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -148,7 +148,7 @@ vbf_beresp2obj(struct busyobj *bo) VSB_delete(vary); } - obj->vxid = bo->vsl->wid; + obj->vxid = VXID(bo->vsl->wid); WS_Assert(bo->ws_o); /* Filter into object */ @@ -257,10 +257,10 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo) // XXX: BereqEnd + BereqAcct ? wid = VXID_Get(&wrk->vxid_pool); - VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid); + VSLb(bo->vsl, SLT_Link, "bereq %u retry", VXID(wid)); VSLb(bo->vsl, SLT_End, "%s", ""); VSL_Flush(bo->vsl, 0); - owid = bo->vsl->wid & VSL_IDENTMASK; + owid = VXID(bo->vsl->wid); bo->vsl->wid = wid | VSL_BACKENDMARKER; VSLb(bo->vsl, SLT_Begin, "bereq %u retry", owid); VSLb_ts_busyobj(bo, "Start", bo->t_prev); @@ -291,8 +291,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) else AZ(bo->req); - http_PrintfHeader(bo->bereq, - "X-Varnish: %u", bo->vsl->wid & VSL_IDENTMASK); + http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(bo->vsl->wid)); VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws); @@ -915,10 +914,8 @@ VBF_Fetch(struct worker *wrk, struct req *req, struct objcore *oc, default: WRONG("Wrong fetch mode"); } - VSLb(bo->vsl, SLT_Begin, "bereq %u %s", - req->vsl->wid & VSL_IDENTMASK, how); - VSLb(req->vsl, SLT_Link, "bereq %u %s", - bo->vsl->wid & VSL_IDENTMASK, how); + VSLb(bo->vsl, SLT_Begin, "bereq %u %s", VXID(req->vsl->wid), how); + VSLb(req->vsl, SLT_Link, "bereq %u %s", VXID(bo->vsl->wid), how); bo_fetch = bo; bo->refcount = 2; diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c index f1a6889..1a6c416 100644 --- a/bin/varnishd/cache/cache_http1_fsm.c +++ b/bin/varnishd/cache/cache_http1_fsm.c @@ -309,10 +309,8 @@ http1_dissect(struct worker *wrk, struct req *req) AZ(req->vsl->wid); req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER; - VSLb(req->vsl, SLT_Begin, "req %u rxreq", - req->sp->vxid & VSL_IDENTMASK); - VSL(SLT_Link, req->sp->vxid, "req %u rxreq", - req->vsl->wid & VSL_IDENTMASK); + VSLb(req->vsl, SLT_Begin, "req %u rxreq", VXID(req->sp->vxid)); + VSL(SLT_Link, req->sp->vxid, "req %u rxreq", VXID(req->vsl->wid)); AZ(isnan(req->t_first)); /* First byte timestamp set by http1_wait */ AZ(isnan(req->t_req)); /* Complete req rcvd set by http1_wait */ req->t_prev = req->t_first; diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 6d97386..994a426 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -376,7 +376,7 @@ pan_sess(const struct sess *sp) VSB_printf(pan_vsp, " sp = %p {\n", sp); VSB_printf(pan_vsp, " fd = %d, vxid = %u,\n", - sp->fd, sp->vxid & VSL_IDENTMASK); + sp->fd, VXID(sp->vxid)); VSB_printf(pan_vsp, " client = %s %s,\n", sp->client_addr_str, sp->client_port_str); switch (sp->sess_step) { diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 40551f7..de33be3 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -108,11 +108,11 @@ cnt_deliver(struct worker *wrk, struct req *req) if (req->wrk->stats.cache_hit) http_PrintfHeader(req->resp, - "X-Varnish: %u %u", req->vsl->wid & VSL_IDENTMASK, - req->obj->vxid & VSL_IDENTMASK); + "X-Varnish: %u %u", VXID(req->vsl->wid), + req->obj->vxid); else http_PrintfHeader(req->resp, - "X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK); + "X-Varnish: %u", VXID(req->vsl->wid)); /* We base Age calculation upon the last timestamp taken during client request processing. This gives some inaccuracy, but @@ -231,8 +231,7 @@ cnt_synth(struct worker *wrk, struct req *req) VTIM_format(now, date); http_PrintfHeader(h, "Date: %s", date); http_SetHeader(h, "Server: Varnish"); - http_PrintfHeader(req->resp, - "X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK); + http_PrintfHeader(req->resp, "X-Varnish: %u", VXID(req->vsl->wid)); http_PutResponse(h, "HTTP/1.1", req->err_code, req->err_reason); AZ(req->synth_body); @@ -610,10 +609,9 @@ cnt_pipe(struct worker *wrk, struct req *req) wrk->stats.s_pipe++; bo = VBO_GetBusyObj(wrk, req); HTTP_Setup(bo->bereq, bo->ws, bo->vsl, SLT_BereqMethod); - VSLb(bo->vsl, SLT_Begin, "bereq %u pipe", req->vsl->wid & VSL_IDENTMASK); + VSLb(bo->vsl, SLT_Begin, "bereq %u pipe", VXID(req->vsl->wid)); http_FilterReq(bo->bereq, req->http, 0); // XXX: 0 ? - http_PrintfHeader(bo->bereq, - "X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK); + http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(req->vsl->wid)); http_SetHeader(bo->bereq, "Connection: close"); VCL_pipe_method(req->vcl, wrk, req, bo, req->http->ws); @@ -622,7 +620,7 @@ cnt_pipe(struct worker *wrk, struct req *req) INCOMPL(); assert(wrk->handling == VCL_RET_PIPE); - VSLb(req->vsl, SLT_Link, "bereq %u pipe", bo->vsl->wid & VSL_IDENTMASK); + VSLb(req->vsl, SLT_Link, "bereq %u pipe", VXID(bo->vsl->wid)); PipeRequest(req, bo); assert(WRW_IsReleased(wrk)); http_Teardown(bo->bereq); @@ -662,10 +660,10 @@ cnt_restart(struct worker *wrk, struct req *req) wid = VXID_Get(&wrk->vxid_pool); // XXX: ReqEnd + ReqAcct ? VSLb_ts_req(req, "Restart", W_TIM_real(wrk)); - VSLb(req->vsl, SLT_Link, "req %u restart", wid); + VSLb(req->vsl, SLT_Link, "req %u restart", VXID(wid)); VSLb(req->vsl, SLT_End, "%s", ""); VSL_Flush(req->vsl, 0); - owid = req->vsl->wid & VSL_IDENTMASK; + owid = VXID(req->vsl->wid); req->vsl->wid = wid | VSL_CLIENTMARKER; VSLb(req->vsl, SLT_Begin, "req %u restart", owid); VSLb_ts_req(req, "Start", req->t_prev); diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 45614c8..e875786 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -490,8 +490,7 @@ VRT_r_req_xid(VRT_CTX) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); - return (WS_Printf(ctx->req->http->ws, "%u", - ctx->req->vsl->wid & VSL_IDENTMASK)); + return (WS_Printf(ctx->req->http->ws, "%u", VXID(ctx->req->vsl->wid))); } const char * @@ -501,8 +500,7 @@ VRT_r_bereq_xid(VRT_CTX) CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC); - return (WS_Printf(ctx->bo->bereq->ws, "%u", - ctx->bo->vsl->wid & VSL_IDENTMASK)); + return (WS_Printf(ctx->bo->bereq->ws, "%u", VXID(ctx->bo->vsl->wid))); } /*--------------------------------------------------------------------*/ From nils.goroll at uplex.de Mon Jul 13 14:56:07 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 13 Jul 2015 16:56:07 +0200 Subject: [4.0] 171f3ac wrap the vxid on VSL_IDENTMASK Message-ID: commit 171f3ac585f2bda639f526c31ad0689aecb8f8b4 Author: Nils Goroll Date: Mon Jul 13 16:51:30 2015 +0200 wrap the vxid on VSL_IDENTMASK We spilled into the client marker bit when reaching 1<<30 Master commits: a87b589b00e788a4294c1b2be68e26a7b4f3fc77 0dd8c0b864a9574df0f2891824b4581d0e846613 diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index bfa2619..4781f9c 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -123,7 +123,7 @@ VXID_Get(struct vxid_pool *v) Lck_Lock(&vxid_lock); v->next = vxid_base; v->count = vxid_chunk; - vxid_base += v->count; + vxid_base = (vxid_base + v->count) & VSL_IDENTMASK; Lck_Unlock(&vxid_lock); } v->count--; From nils.goroll at uplex.de Tue Jul 14 02:12:31 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 04:12:31 +0200 Subject: [master] dc5e096 Add a debug bit to always keep the vsm file Message-ID: commit dc5e096ac1f60b900761d938ae4fc16fd06c8e1e Author: Nils Goroll Date: Tue Jul 14 04:06:20 2015 +0200 Add a debug bit to always keep the vsm file diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 450ec9c..3a6890a 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -94,6 +94,12 @@ MGT_FEATURE(enum feature_bits x) return (mgt_param.feature_bits[(unsigned)x>>3] & (0x80U >> ((unsigned)x & 7))); } +static inline int +MGT_DO_DEBUG(enum debug_bits x) +{ + return (mgt_param.debug_bits[(unsigned)x>>3] & + (0x80U >> ((unsigned)x & 7))); +} static void mgt_reap_child(void); @@ -528,7 +534,7 @@ mgt_reap_child(void) mgt_SHM_Destroy(1); VSC_C_mgt->child_panic = ++static_VSC_C_mgt.child_panic; } else { - mgt_SHM_Destroy(0); + mgt_SHM_Destroy(MGT_DO_DEBUG(DBG_VSM_KEEP)); } mgt_SHM_Create(); mgt_SHM_Commit(); diff --git a/include/tbl/debug_bits.h b/include/tbl/debug_bits.h index 9e5b684..fa0d32f 100644 --- a/include/tbl/debug_bits.h +++ b/include/tbl/debug_bits.h @@ -42,4 +42,5 @@ DEBUG_BIT(ESI_CHOP, esi_chop, "Chop ESI fetch to bits") DEBUG_BIT(FLUSH_HEAD, flush_head, "Flush after http1 head") DEBUG_BIT(VTC_MODE, vtc_mode, "Varnishtest Mode") DEBUG_BIT(WITNESS, witness, "Emit WITNESS lock records") +DEBUG_BIT(VSM_KEEP, vsm_keep, "Keep the VSM file on restart") /*lint -restore */ From nils.goroll at uplex.de Tue Jul 14 02:12:31 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 04:12:31 +0200 Subject: [master] 3f1dacd use debug=+vsm_keep with leave_temp (varnishtest -L / -l options) Message-ID: commit 3f1dacddf73294b1d6424196ecec74f4b46cf7f9 Author: Nils Goroll Date: Tue Jul 14 04:07:24 2015 +0200 use debug=+vsm_keep with leave_temp (varnishtest -L / -l options) diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c index ce50c6b..df8787c 100644 --- a/bin/varnishtest/vtc_main.c +++ b/bin/varnishtest/vtc_main.c @@ -85,9 +85,9 @@ static int vtc_continue; /* Continue on error */ static int vtc_verbosity = 1; /* Verbosity Level */ static int vtc_good; static int vtc_fail; -static int leave_temp; static char *tmppath; static char *cwd = NULL; +int leave_temp; int vtc_witness = 0; /********************************************************************** diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index ce666e3..05ee65b 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -52,6 +52,8 @@ #include "vtcp.h" #include "vtim.h" +extern int leave_temp; + struct varnish { unsigned magic; #define VARNISH_MAGIC 0x208cd8e3 @@ -396,6 +398,8 @@ varnish_launch(struct varnish *v) v->jail, v->workdir); if (vtc_witness) VSB_cat(vsb, " -p debug=+witness"); + if (leave_temp) + VSB_cat(vsb, " -p debug=+vsm_keep"); VSB_printf(vsb, " -l 2m,1m,-"); VSB_printf(vsb, " -p auto_restart=off"); VSB_printf(vsb, " -p syslog_cli_traffic=off"); From nils.goroll at uplex.de Tue Jul 14 14:49:42 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 16:49:42 +0200 Subject: [master] 4ef5ae5 vtc: allow VSL arguments in logexpect Message-ID: commit 4ef5ae57a0cf2d3c29c5d2c7dbd65d301ce07150 Author: Nils Goroll Date: Tue Jul 14 15:34:18 2015 +0200 vtc: allow VSL arguments in logexpect diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index b05470d..1e787fc 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -33,6 +33,16 @@ * -g * -q * + * vsl arguments (vsl_arg.c) + * -b Only display backend records + * -c Only display client records + * -C Caseless regular expressions + * -i Include tags + * -I <[taglist:]regex> Include by regex + * -L Incomplete transaction limit + * -T Transaction end timeout + * + * * logexpect lN -v [-g ] [-d 0|1] [-q query] { * expect * } @@ -124,7 +134,8 @@ logexp_delete(struct logexp *le) { CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC); AZ(le->run); - AZ(le->vsl); + AN(le->vsl); + VSL_Delete(le->vsl); AZ(le->vslq); logexp_delete_tests(le); free(le->name); @@ -150,7 +161,9 @@ logexp_new(const char *name) le->d_arg = 0; le->g_arg = VSL_g_vxid; le->vsm = VSM_New(); + le->vsl = VSL_New(); AN(le->vsm); + AN(le->vsl); VTAILQ_INSERT_TAIL(&logexps, le, list); return (le); @@ -299,10 +312,6 @@ logexp_close(struct logexp *le) if (le->vslq) VSLQ_Delete(&le->vslq); AZ(le->vslq); - if (le->vsl) { - VSL_Delete(le->vsl); - le->vsl = NULL; - } VSM_Close(le->vsm); } @@ -312,7 +321,7 @@ logexp_start(struct logexp *le) struct VSL_cursor *c; CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC); - AZ(le->vsl); + AN(le->vsl); AZ(le->vslq); if (le->n_arg == NULL) { @@ -328,7 +337,6 @@ logexp_start(struct logexp *le) vtc_log(le->vl, 0, "VSM_Open: %s", VSM_Error(le->vsm)); return; } - le->vsl = VSL_New(); AN(le->vsl); c = VSL_CursorVSM(le->vsl, le->vsm, (le->d_arg ? 0 : VSL_COPT_TAIL) | VSL_COPT_BATCH); @@ -579,6 +587,14 @@ cmd_logexp(CMD_ARGS) continue; } if (**av == '-') { + if (av[1] != NULL) { + if (VSL_Arg(le->vsl, av[0][1], av[1])) { + av++; + continue; + } + vtc_log(le->vl, 0, VSL_Error(le->vsl)); + return; + } vtc_log(le->vl, 0, "Unknown logexp argument: %s", *av); return; } From nils.goroll at uplex.de Tue Jul 14 15:07:06 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 17:07:06 +0200 Subject: [master] 90e87e3 Assert that literal vxids we parse never have the client/server bit set Message-ID: commit 90e87e30fb92e525016ce1975fa61ad744bdc41d Author: Nils Goroll Date: Tue Jul 14 17:05:52 2015 +0200 Assert that literal vxids we parse never have the client/server bit set This is an additional safeguard against regressions of #1762 diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index 459d0b7..bc108f4 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -700,6 +700,7 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype, *ptype = VSL_t_unknown; if (i == 1) return (1); + assert((vxid & ~VSL_IDENTMASK) == 0); *pvxid = vxid; if (i == 2) return (2); From nils.goroll at uplex.de Tue Jul 14 15:14:58 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 17:14:58 +0200 Subject: [4.0] a373d26 vtc: allow VSL arguments in logexpect Message-ID: commit a373d26c4e80829c52e53acf4f960899e7f58c3c Author: Nils Goroll Date: Tue Jul 14 15:34:18 2015 +0200 vtc: allow VSL arguments in logexpect diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index a2b6323..8f2a93e 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -33,6 +33,16 @@ * -g * -q * + * vsl arguments (vsl_arg.c) + * -b Only display backend records + * -c Only display client records + * -C Caseless regular expressions + * -i Include tags + * -I <[taglist:]regex> Include by regex + * -L Incomplete transaction limit + * -T Transaction end timeout + * + * * logexpect lN -v [-g ] [-d 0|1] [-q query] { * expect * } @@ -127,7 +137,8 @@ logexp_delete(struct logexp *le) { CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC); AZ(le->run); - AZ(le->vsl); + AN(le->vsl); + VSL_Delete(le->vsl); AZ(le->vslq); logexp_delete_tests(le); free(le->name); @@ -153,7 +164,9 @@ logexp_new(const char *name) le->d_arg = 0; le->g_arg = VSL_g_vxid; le->vsm = VSM_New(); + le->vsl = VSL_New(); AN(le->vsm); + AN(le->vsl); VTAILQ_INSERT_TAIL(&logexps, le, list); return (le); @@ -299,10 +312,6 @@ logexp_close(struct logexp *le) if (le->vslq) VSLQ_Delete(&le->vslq); AZ(le->vslq); - if (le->vsl) { - VSL_Delete(le->vsl); - le->vsl = NULL; - } VSM_Close(le->vsm); } @@ -312,7 +321,7 @@ logexp_start(struct logexp *le) struct VSL_cursor *c; CHECK_OBJ_NOTNULL(le, LOGEXP_MAGIC); - AZ(le->vsl); + AN(le->vsl); AZ(le->vslq); if (le->n_arg == NULL) { @@ -328,7 +337,6 @@ logexp_start(struct logexp *le) vtc_log(le->vl, 0, "VSM_Open: %s", VSM_Error(le->vsm)); return; } - le->vsl = VSL_New(); AN(le->vsl); c = VSL_CursorVSM(le->vsl, le->vsm, (le->d_arg ? 0 : VSL_COPT_TAIL) | VSL_COPT_BATCH); @@ -584,6 +592,14 @@ cmd_logexp(CMD_ARGS) continue; } if (**av == '-') { + if (av[1] != NULL) { + if (VSL_Arg(le->vsl, av[0][1], av[1])) { + av++; + continue; + } + vtc_log(le->vl, 0, VSL_Error(le->vsl)); + return; + } vtc_log(le->vl, 0, "Unknown logexp argument: %s", *av); return; } From nils.goroll at uplex.de Tue Jul 14 15:14:58 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 17:14:58 +0200 Subject: [4.0] 9119bfd Assert that literal vxids we parse never have the client/server bit set Message-ID: commit 9119bfd659bc51a60d9f0bc1c84a6fd29b889b97 Author: Nils Goroll Date: Tue Jul 14 17:05:52 2015 +0200 Assert that literal vxids we parse never have the client/server bit set This is an additional safeguard against regressions of #1762 diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index 7f393b3..539e34c 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -696,6 +696,7 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype, *ptype = VSL_t_unknown; if (i == 1) return (1); + assert((vxid & ~VSL_IDENTMASK) == 0); *pvxid = vxid; if (i == 2) return (2); From nils.goroll at uplex.de Tue Jul 14 15:34:41 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 17:34:41 +0200 Subject: [master] 65f9cb7 dont use VSL_Error as a format string Message-ID: commit 65f9cb7ae68a8641a0fd5a804354df11c9af9ef1 Author: Nils Goroll Date: Tue Jul 14 17:34:38 2015 +0200 dont use VSL_Error as a format string diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index 1e787fc..bd567ee 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -592,7 +592,7 @@ cmd_logexp(CMD_ARGS) av++; continue; } - vtc_log(le->vl, 0, VSL_Error(le->vsl)); + vtc_log(le->vl, 0, "%s", VSL_Error(le->vsl)); return; } vtc_log(le->vl, 0, "Unknown logexp argument: %s", *av); From nils.goroll at uplex.de Tue Jul 14 15:35:41 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 17:35:41 +0200 Subject: [4.0] 8e3f919 dont use VSL_Error as a format string Message-ID: commit 8e3f91928d66ad972c68af18e0b752b08625698e Author: Nils Goroll Date: Tue Jul 14 17:34:38 2015 +0200 dont use VSL_Error as a format string diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index 8f2a93e..8dc2ace 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -597,7 +597,7 @@ cmd_logexp(CMD_ARGS) av++; continue; } - vtc_log(le->vl, 0, VSL_Error(le->vsl)); + vtc_log(le->vl, 0, "%s", VSL_Error(le->vsl)); return; } vtc_log(le->vl, 0, "Unknown logexp argument: %s", *av); From nils.goroll at uplex.de Tue Jul 14 16:59:24 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 18:59:24 +0200 Subject: [4.0] 9bffd9e Add a regression test for #1762 Message-ID: commit 9bffd9eac5baa4ef0e3a7f5d1fcab455d5980d61 Author: Nils Goroll Date: Tue Jul 14 18:52:44 2015 +0200 Add a regression test for #1762 Further investigating into root cause scenarios resulted in the following insights: * the bad vxid must have got into vtx->key.vxid by way of `vtx_parse_link` * which is only called for `SLT_Begin` (`vtx_scan_begin()`) and `SLT_Link` (`vtx_scan_link()`) (actually this was known before, but I am now confident that these are the only cases) There is no case in the code as of 4.0.3 release where `SLT_Begin` is emitted with an unmasked vxid, so the issue must be root casue in an `SLT_Link` link record. In both cases where unmasked vxids are emitted for `SLT_Link`, the id comes directly from `VXID_Get()`: * `cache_fetch.c` wid = VXID_Get(&wrk->vxid_pool); VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid); * `cache_req_fsm.c` wid = VXID_Get(&wrk->vxid_pool); // XXX: ReqEnd + ReqAcct ? VSLb_ts_req(req, "Restart", W_TIM_real(wrk)); VSLb(req->vsl, SLT_Link, "req %u restart", wid); So unless I have overseen anything significant, the root cause must have been a vxid spill, which was fixed with 0dd8c0b864a9574df0f2891824b4581d0e846613 (master) / 171f3ac585f2bda639f526c31ad0689aecb8f8b4 (4.0) `VXID()` masking would have avoided the issue to surface. This insight is consistent with two observations: * the issue only surfaced after `varnishd` running for longer periods of time * the issue didn't go away after a restart of the vsl client, a `varnishd` restart was required This gives confidence that the issue has really been understood completely and that the root cause has been fixed. diff --git a/bin/varnishtest/tests/r01762.vtc b/bin/varnishtest/tests/r01762.vtc new file mode 100644 index 0000000..8a3fbd4 --- /dev/null +++ b/bin/varnishtest/tests/r01762.vtc @@ -0,0 +1,106 @@ +varnishtest "test vsl api handling of incomplete vtxes combined with bad vxids" + +server s1 { + rxreq + txresp + + accept + rxreq + delay 5 + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + if (bereq.url == "/retry" && + bereq.retries == 0) { + return (retry); + } + } + sub vcl_deliver { + if (req.url == "/restart" && + req.restarts == 0) { + return (restart); + } + } + +} -start + +# xid spill into client marker emitting a bad SLT_Link for bereq retry +# triggering vtx_force by way of a timeout +# +# VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid); + +varnish v1 -cliok "param.set debug +syncvsl" +# vxid wrap at 1<<30 +varnish v1 -cliok "debug.xid 1073741823" + +logexpect l1 -v v1 -g request -T 2 { + expect 0 1 Begin "req 0" + expect * = ReqStart + expect 0 = ReqMethod GET + expect 0 = ReqURL / + expect 0 = ReqProtocol HTTP/1.1 + expect * = ReqHeader "Foo: bar" + expect * = Link "bereq 2 fetch" + expect * = VSL "timeout" + expect * = End "synth" + + expect 0 2 Begin "bereq 1" + expect * 2 Link "bereq 3 retry" + expect * = End + + expect 0 3 Begin "bereq 2 retry" + expect * = End +} -start + +client c1 { + txreq -url "/retry" -hdr "Foo: bar" + rxresp + expect resp.status == 200 +} -run + +logexpect l1 -wait + + +################################################################################ + +# case xid spill into client marker emitting a bad SLT_Link for restart +# +# VSLb(req->vsl, SLT_Link, "req %u restart", wid); + + +server s1 { + rxreq + txresp +} -start + +varnish v1 -cliok "param.set debug +syncvsl" +# vxid wrap at 1<<30 +varnish v1 -cliok "debug.xid 1073741823" + +logexpect l1 -v v1 -g request { + expect 0 1 Begin "req 0" + expect * = ReqStart + expect 0 = ReqMethod GET + expect 0 = ReqURL / + expect 0 = ReqProtocol HTTP/1.1 + expect * = ReqHeader "Foo: bar" + expect * = Link "bereq 2 fetch" + expect * = Link "req 3 restart" + expect * = End + + expect 0 2 Begin "bereq 1" + expect * = End + + expect 0 3 Begin "req 1 restart" + expect * = End +} -start + +client c1 { + txreq -url "/restart" -hdr "Foo: bar" + rxresp + expect resp.status == 200 +} -run + +logexpect l1 -wait From nils.goroll at uplex.de Tue Jul 14 16:59:30 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 14 Jul 2015 18:59:30 +0200 Subject: [master] 20362bf Add a regression test for #1762 Message-ID: commit 20362bf807eb6b0772ccdeb221b05173484d5dc3 Author: Nils Goroll Date: Tue Jul 14 18:52:44 2015 +0200 Add a regression test for #1762 Further investigating into root cause scenarios resulted in the following insights: * the bad vxid must have got into vtx->key.vxid by way of `vtx_parse_link` * which is only called for `SLT_Begin` (`vtx_scan_begin()`) and `SLT_Link` (`vtx_scan_link()`) (actually this was known before, but I am now confident that these are the only cases) There is no case in the code as of 4.0.3 release where `SLT_Begin` is emitted with an unmasked vxid, so the issue must be root casue in an `SLT_Link` link record. In both cases where unmasked vxids are emitted for `SLT_Link`, the id comes directly from `VXID_Get()`: * `cache_fetch.c` wid = VXID_Get(&wrk->vxid_pool); VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid); * `cache_req_fsm.c` wid = VXID_Get(&wrk->vxid_pool); // XXX: ReqEnd + ReqAcct ? VSLb_ts_req(req, "Restart", W_TIM_real(wrk)); VSLb(req->vsl, SLT_Link, "req %u restart", wid); So unless I have overseen anything significant, the root cause must have been a vxid spill, which was fixed with 0dd8c0b864a9574df0f2891824b4581d0e846613 (master) / 171f3ac585f2bda639f526c31ad0689aecb8f8b4 (4.0) `VXID()` masking would have avoided the issue to surface. This insight is consistent with two observations: * the issue only surfaced after `varnishd` running for longer periods of time * the issue didn't go away after a restart of the vsl client, a `varnishd` restart was required This gives confidence that the issue has really been understood completely and that the root cause has been fixed. diff --git a/bin/varnishtest/tests/r01762.vtc b/bin/varnishtest/tests/r01762.vtc new file mode 100644 index 0000000..8a3fbd4 --- /dev/null +++ b/bin/varnishtest/tests/r01762.vtc @@ -0,0 +1,106 @@ +varnishtest "test vsl api handling of incomplete vtxes combined with bad vxids" + +server s1 { + rxreq + txresp + + accept + rxreq + delay 5 + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + if (bereq.url == "/retry" && + bereq.retries == 0) { + return (retry); + } + } + sub vcl_deliver { + if (req.url == "/restart" && + req.restarts == 0) { + return (restart); + } + } + +} -start + +# xid spill into client marker emitting a bad SLT_Link for bereq retry +# triggering vtx_force by way of a timeout +# +# VSLb(bo->vsl, SLT_Link, "bereq %u retry", wid); + +varnish v1 -cliok "param.set debug +syncvsl" +# vxid wrap at 1<<30 +varnish v1 -cliok "debug.xid 1073741823" + +logexpect l1 -v v1 -g request -T 2 { + expect 0 1 Begin "req 0" + expect * = ReqStart + expect 0 = ReqMethod GET + expect 0 = ReqURL / + expect 0 = ReqProtocol HTTP/1.1 + expect * = ReqHeader "Foo: bar" + expect * = Link "bereq 2 fetch" + expect * = VSL "timeout" + expect * = End "synth" + + expect 0 2 Begin "bereq 1" + expect * 2 Link "bereq 3 retry" + expect * = End + + expect 0 3 Begin "bereq 2 retry" + expect * = End +} -start + +client c1 { + txreq -url "/retry" -hdr "Foo: bar" + rxresp + expect resp.status == 200 +} -run + +logexpect l1 -wait + + +################################################################################ + +# case xid spill into client marker emitting a bad SLT_Link for restart +# +# VSLb(req->vsl, SLT_Link, "req %u restart", wid); + + +server s1 { + rxreq + txresp +} -start + +varnish v1 -cliok "param.set debug +syncvsl" +# vxid wrap at 1<<30 +varnish v1 -cliok "debug.xid 1073741823" + +logexpect l1 -v v1 -g request { + expect 0 1 Begin "req 0" + expect * = ReqStart + expect 0 = ReqMethod GET + expect 0 = ReqURL / + expect 0 = ReqProtocol HTTP/1.1 + expect * = ReqHeader "Foo: bar" + expect * = Link "bereq 2 fetch" + expect * = Link "req 3 restart" + expect * = End + + expect 0 2 Begin "bereq 1" + expect * = End + + expect 0 3 Begin "req 1 restart" + expect * = End +} -start + +client c1 { + txreq -url "/restart" -hdr "Foo: bar" + rxresp + expect resp.status == 200 +} -run + +logexpect l1 -wait From martin at varnish-software.com Thu Jul 16 11:53:55 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Thu, 16 Jul 2015 13:53:55 +0200 Subject: [master] 082f259 Attempt to quell strange coverity report Message-ID: commit 082f2596000a18f66fa2c3286c311fbc9135d049 Author: Martin Blix Grydeland Date: Thu Jul 16 13:45:28 2015 +0200 Attempt to quell strange coverity report Add extra variables of the right enum types in an attempt to quell a coverity report about enum type missmatch when reusing the same integer counter. diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index bc108f4..3245e48 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -681,7 +681,9 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype, { char type[16], reason[16]; unsigned vxid; - int i, j; + int i; + enum VSL_transaction_e et; + enum VSL_reason_e er; AN(str); AN(ptype); @@ -691,26 +693,30 @@ vtx_parse_link(const char *str, enum VSL_transaction_e *ptype, i = sscanf(str, "%15s %u %15s", type, &vxid, reason); if (i < 1) return (0); - for (j = 0; j < VSL_t__MAX; j++) - if (!strcmp(type, vsl_t_names[j])) + + /* transaction type */ + for (et = 0; et < VSL_t__MAX; et++) + if (!strcmp(type, vsl_t_names[et])) break; - if (j < VSL_t__MAX) - *ptype = j; - else - *ptype = VSL_t_unknown; + if (et >= VSL_t__MAX) + et = VSL_t_unknown; + *ptype = et; if (i == 1) return (1); + + /* vxid */ assert((vxid & ~VSL_IDENTMASK) == 0); *pvxid = vxid; if (i == 2) return (2); - for (j = 0; j < VSL_r__MAX; j++) - if (!strcmp(reason, vsl_r_names[j])) + + /* transaction reason */ + for (er = 0; er < VSL_r__MAX; er++) + if (!strcmp(reason, vsl_r_names[er])) break; - if (j < VSL_r__MAX) - *preason = j; - else - *preason = VSL_r_unknown; + if (er >= VSL_r__MAX) + er = VSL_r_unknown; + *preason = er; return (3); } From fgsch at lodoss.net Mon Jul 20 23:50:34 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 21 Jul 2015 01:50:34 +0200 Subject: [master] 0bdcee4 Spelling and minor fixes Message-ID: commit 0bdcee4f4a7c38f0e718d53b246b76c952966fc4 Author: Federico G. Schwindt Date: Tue Jul 21 00:50:02 2015 +0100 Spelling and minor fixes diff --git a/doc/sphinx/installation/help.rst b/doc/sphinx/installation/help.rst index 14746e7..22cd106 100644 --- a/doc/sphinx/installation/help.rst +++ b/doc/sphinx/installation/help.rst @@ -65,7 +65,7 @@ usually quite focused on source-code and such. Everybody on the `-dev` list is also on `-misc`, so cross-posting only serves to annoy those people. -We also maintain a community wiki_ for Varnish, there you will find information on planned events, meetings, current backlog, troube tickets , and links to resources and documentation. +We also maintain a community wiki_ for Varnish, there you will find information on planned events, meetings, current backlog, trouble tickets , and links to resources and documentation. .. XXX: we should introduce the wiki (if we care about it) before .. we start referring to it (below). Make a wiki chapter? diff --git a/doc/sphinx/reference/index.rst b/doc/sphinx/reference/index.rst index ec73438..8eb11ed 100644 --- a/doc/sphinx/reference/index.rst +++ b/doc/sphinx/reference/index.rst @@ -32,9 +32,9 @@ The Varnish Reference Manual . - counters explained . common filtering options for shmlog tools . varnishlog .. - . varnsihtop .. - . varnsihncsa .. - . varnsihhist .. + . varnishtop .. + . varnishncsa .. + . varnishhist .. The CLI: . connections: -T -S -M . varnishadm diff --git a/doc/sphinx/reference/varnishadm.rst b/doc/sphinx/reference/varnishadm.rst index 76f5d3f..f671d8f 100644 --- a/doc/sphinx/reference/varnishadm.rst +++ b/doc/sphinx/reference/varnishadm.rst @@ -50,7 +50,7 @@ OPTIONS The syntax and operation of the actual CLI interface is described in -the :ref:`varnish-cli(7)` manual page. Parameteres are described in +the :ref:`varnish-cli(7)` manual page. Parameters are described in :ref:`varnishd(1)` manual page. Additionally, a summary of commands can be obtained by issuing the diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst index e2c1fc8..e833706 100644 --- a/doc/sphinx/reference/varnishstat.rst +++ b/doc/sphinx/reference/varnishstat.rst @@ -58,7 +58,7 @@ The following options are available: any seconds. If zero the connection is attempted only once and will fail immediately if unsuccessful. If set to "off", the connection will not fail, allowing the utility to start and - wait indefinetely for the Varnish instance to appear. + wait indefinitely for the Varnish instance to appear. Defaults to 5 seconds. -V diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 2246dd6..b6d7702 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -306,15 +306,14 @@ To match an IP address against an ACL, simply use the match operator:: VCL objects ----------- -A VCL object can be made with the *new* keyword. - -Example:: +A VCL object can be instantiated with the *new* keyword:: sub vcl_init { new b = directors.round_robin() b.add_backend(node1); } +This is only available in vcl_init. Subroutines ----------- @@ -379,9 +378,6 @@ hash_data(input) Adds an input to the hash input. In the built-in VCL hash_data() is called on the host and URL of the *request*. Available in vcl_hash. -new() - Instanciate a new VCL object. Available in vcl_init. - rollback() Restore *req* HTTP headers to their original state. This function is deprecated. Use std.rollback() instead. diff --git a/doc/sphinx/reference/vsm.rst b/doc/sphinx/reference/vsm.rst index cdae8e7..13afbdd 100644 --- a/doc/sphinx/reference/vsm.rst +++ b/doc/sphinx/reference/vsm.rst @@ -34,7 +34,7 @@ tricky in ways a regular logfile is not. When you open a file in "append" mode, the operating system guarantees that whatever you write will not overwrite existing data in the file. -The neat result of this is that multiple procesess or threads writing +The neat result of this is that multiple processes or threads writing to the same file does not even need to know about each other, it all works just as you would expect. From phk at FreeBSD.org Sun Jul 26 15:40:31 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 26 Jul 2015 17:40:31 +0200 Subject: [master] 1ff5897 Make -a argument checking a two step process: Message-ID: commit 1ff5897b6d18954fc209b68270c637a510f30e79 Author: Poul-Henning Kamp Date: Sun Jul 26 09:39:13 2015 +0000 Make -a argument checking a two step process: We always do the DNS resolution when we hit -a arguments, but the test that we can bind to the address is postponed until after the -C argument processing. Fixes: #1767 diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 05f340a..27c3a33 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -37,8 +37,8 @@ struct listen_sock { #define LISTEN_SOCK_MAGIC 0x999e4b57 VTAILQ_ENTRY(listen_sock) list; int sock; - const char *name; - const struct suckaddr *addr; + char *name; + struct suckaddr *addr; enum sess_step first_step; const char *proto_name; }; diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 2b680c6..18356dc 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -42,6 +42,7 @@ extern int exit_status; /* mgt_acceptor.c */ void MAC_Arg(const char *); +void MAC_Validate(void); void MAC_reopen_sockets(struct cli *); int MAC_sockets_ready(struct cli *); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index b85c391..a956b27 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -112,9 +112,8 @@ MAC_sockets_ready(struct cli *cli) struct mac_help { unsigned magic; #define MAC_HELP_MAGIC 0x1e00a9d9 - const char *name; int good; - const char **err; + const char *name; const char *proto_name; enum sess_step first_step; }; @@ -124,47 +123,55 @@ mac_callback(void *priv, const struct suckaddr *sa) { struct mac_help *mh; struct listen_sock *ls; - int fail; - char abuf[VTCP_ADDRBUFSIZE], pbuf[VTCP_PORTBUFSIZE]; - char nbuf[VTCP_ADDRBUFSIZE+VTCP_PORTBUFSIZE+2]; CAST_OBJ_NOTNULL(mh, priv, MAC_HELP_MAGIC); ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); AN(ls); ls->sock = -1; - ls->addr = sa; - ls->proto_name = mh->proto_name; - ls->first_step = mh->first_step; - VJ_master(JAIL_MASTER_PRIVPORT); - fail = mac_opensocket(ls, NULL); - VJ_master(JAIL_MASTER_LOW); - if (ls->sock < 0) { - *(mh->err) = strerror(fail); - FREE_OBJ(ls); - return (0); - } - if (VSA_Port(sa) == 0) { - /* - * If the port number is zero, we adopt whatever port number - * this VTCP_bind() found us, as if specified by argument. - */ - ls->addr = VTCP_my_suckaddr(ls->sock); - VTCP_myname(ls->sock, abuf, sizeof abuf, pbuf, sizeof pbuf); - bprintf(nbuf, "%s:%s", abuf, pbuf); - ls->name = strdup(nbuf); - } else { - ls->addr = VSA_Clone(sa); - ls->name = strdup(mh->name); - } + ls->addr = VSA_Clone(sa); AN(ls->addr); + ls->name = strdup(mh->name); AN(ls->name); + ls->proto_name = mh->proto_name; + ls->first_step = mh->first_step; VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); mh->good++; return (0); } void +MAC_Validate(void) +{ + struct listen_sock *ls; + int fail; + char abuf[VTCP_ADDRBUFSIZE], pbuf[VTCP_PORTBUFSIZE]; + char nbuf[VTCP_ADDRBUFSIZE+VTCP_PORTBUFSIZE+2]; + + VTAILQ_FOREACH(ls, &heritage.socks, list) { + VJ_master(JAIL_MASTER_PRIVPORT); + fail = mac_opensocket(ls, NULL); + VJ_master(JAIL_MASTER_LOW); + if (ls->sock < 0) + ARGV_ERR("Cannot open socket: %s: %s\n", + ls->name, strerror(fail)); + if (VSA_Port(ls->addr) == 0) { + /* + * If the port number is zero, we adopt whatever + * port number this VTCP_bind() found us, as if + * specified by argument. + */ + free(ls->addr); + ls->addr = VTCP_my_suckaddr(ls->sock); + VTCP_myname(ls->sock, abuf, sizeof abuf, + pbuf, sizeof pbuf); + bprintf(nbuf, "%s:%s", abuf, pbuf); + REPLACE(ls->name, nbuf); + } + } +} + +void MAC_Arg(const char *arg) { char **av; @@ -192,11 +199,9 @@ MAC_Arg(const char *arg) ARGV_ERR("Unknown protocol '%s'\n", av[2]); } - mh->err = &err; error = VSS_resolver(av[1], "80", mac_callback, mh, &err); - if (mh->good == 0 || err != NULL) - ARGV_ERR("Could not bind to address %s: %s\n", av[1], err); + if (mh->good == 0 || error) + ARGV_ERR("socket %s didn't resolve \n", av[1]); VAV_Free(av); - AZ(error); FREE_OBJ(mh); } diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 56c51b7..0ae5338 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -497,7 +497,7 @@ main(int argc, char * const *argv) /* Create a cli for convenience in otherwise CLI functions */ INIT_OBJ(cli, CLI_MAGIC); cli[0].sb = VSB_new_auto(); - XXXAN(cli[0].sb); + AN(cli[0].sb); cli[0].result = CLIS_OK; clilim = 32768; cli[0].limit = &clilim; @@ -510,11 +510,6 @@ main(int argc, char * const *argv) init_params(cli); cli_check(cli); - if (argc == 1) { - jailed++; - VJ_Init(NULL); - } - while ((o = getopt(argc, argv, "a:b:Cdf:Fh:i:j:l:M:n:P:p:r:S:s:T:t:VW:x:")) != -1) { /* @@ -632,6 +627,9 @@ main(int argc, char * const *argv) } } + if (!jailed) + VJ_Init(NULL); + argc -= optind; argv += optind; if (argc != 0) @@ -705,7 +703,9 @@ main(int argc, char * const *argv) ARGV_ERR("-C only good with -b or -f\n"); if (VTAILQ_EMPTY(&heritage.socks)) - MAC_Arg("*:80"); + MAC_Arg(":80"); + + MAC_Validate(); assert(! VTAILQ_EMPTY(&heritage.socks)); diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 2acb66b..f2efcce 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -4,7 +4,11 @@ varnishtest "Check that we fail to start if any listen address does not work" # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. # All bad listen addresses -err_shell "Could not bind to address 192.0.2.255:0" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +err_shell "could not be resolved to an IP address" { + ${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 +} # old style address list -err_shell "Unknown protocol" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +err_shell "Unknown protocol" { + ${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 +} From phk at FreeBSD.org Sun Jul 26 15:40:31 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sun, 26 Jul 2015 17:40:31 +0200 Subject: [master] 4df51cf Try to sort out the delivery of resp.body for special resp.status cases. Message-ID: commit 4df51cf26691e875682a39b279cd03f7e202fae8 Author: Poul-Henning Kamp Date: Sun Jul 26 14:40:22 2015 +0000 Try to sort out the delivery of resp.body for special resp.status cases. Treat C-L or A-E in 204 backend responses as fetch_error. This hopefully fixes #1761 diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 2df4481..6719345 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -655,7 +655,7 @@ struct sess { * or may not, be talking a "real" HTTP protocol itself. */ -typedef void vtr_deliver_f (struct req *, struct busyobj *); +typedef void vtr_deliver_f (struct req *, struct busyobj *, int wantbody); struct transport { unsigned magic; diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 9aeba38..aa011b6 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -703,7 +703,7 @@ ved_vdp_bytes(struct req *req, enum vdp_action act, void **priv, /*--------------------------------------------------------------------*/ static void __match_proto__(vtr_deliver_f) -VED_Deliver(struct req *req, struct busyobj *bo) +VED_Deliver(struct req *req, struct busyobj *bo, int wantbody) { int i; struct ecx *ecx; @@ -714,6 +714,9 @@ VED_Deliver(struct req *req, struct busyobj *bo) CAST_OBJ_NOTNULL(ecx, req->transport_priv, ECX_MAGIC); + if (wantbody == 0) + return; + req->res_mode |= RES_ESI_CHILD; i = ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED); if (ecx->isgzip && i && !(req->res_mode & RES_ESI)) { diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 12703bd..aa1f4cf 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -345,7 +345,11 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) * [RFC2616 10.2.5 p60] */ wrk->stats->fetch_204++; - bo->htc->body_status = BS_NONE; + if (http_GetHdr(bo->beresp, H_Content_Length, NULL) || + http_GetHdr(bo->beresp, H_Transfer_Encoding, NULL)) + bo->htc->body_status = BS_ERROR; + else + bo->htc->body_status = BS_NONE; } else if (http_IsStatus(bo->beresp, 304)) { /* * 304 is "Not Modified" it has no body. diff --git a/bin/varnishd/cache/cache_range.c b/bin/varnishd/cache/cache_range.c index 23c9925..6122984 100644 --- a/bin/varnishd/cache/cache_range.c +++ b/bin/varnishd/cache/cache_range.c @@ -191,7 +191,10 @@ VRG_dorange(struct req *req, const char *r) "Content-Range: bytes */%jd", (intmax_t)req->resp_len); http_PutResponse(req->resp, "HTTP/1.1", 416, NULL); - req->resp_len = -1; - req->wantbody = 0; + /* + * XXX: We ought to produce a body explaining things. + * XXX: That really calls for us to hit vcl_synth{} + */ + req->resp_len = 0; } } diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index b0fe1e7..46f777e 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -51,9 +51,23 @@ static void cnt_vdp(struct req *req, struct busyobj *bo) { const char *r; + uint16_t status; + int wantbody; + CHECK_OBJ_NOTNULL(req->transport, TRANSPORT_MAGIC); req->res_mode = 0; - if (bo != NULL) + wantbody = 1; + status = http_GetStatus(req->resp); + if (!strcmp(req->http0->hd[HTTP_HDR_METHOD].b, "HEAD")) { + wantbody = 0; + } else if (status < 200 || status == 204) { + req->resp_len = 0; + http_Unset(req->resp, H_Content_Length); + wantbody = 0; + } else if (status == 304) { + http_Unset(req->resp, H_Content_Length); + wantbody = 0; + } else if (bo != NULL) req->resp_len = http_GetContentLength(req->resp); else req->resp_len = ObjGetLen(req->wrk, req->objcore); @@ -62,7 +76,7 @@ cnt_vdp(struct req *req, struct busyobj *bo) * Determine ESI status first. Not dependent on wantbody, because * we want ESI to supress C-L in HEAD too. */ - if (!req->disable_esi && + if (!req->disable_esi && req->resp_len != 0 && wantbody && ObjGetattr(req->wrk, req->objcore, OA_ESIDATA, NULL) != NULL) { req->res_mode |= RES_ESI; RFC2616_Weaken_Etag(req->resp); @@ -70,7 +84,6 @@ cnt_vdp(struct req *req, struct busyobj *bo) VDP_push(req, VDP_ESI, NULL, 0); } - if (cache_param->http_gzip_support && ObjCheckFlag(req->wrk, req->objcore, OF_GZIPED) && !RFC2616_Req_Gzip(req->http)) { @@ -80,18 +93,15 @@ cnt_vdp(struct req *req, struct busyobj *bo) /* * Range comes after the others and pushes on bottom because - * it can generate a correct C-L header. + * it can (maybe) generate a correct C-L header. */ - if (cache_param->http_range_support && - http_IsStatus(req->resp, 200)) { + if (cache_param->http_range_support && http_IsStatus(req->resp, 200)) { http_SetHeader(req->resp, "Accept-Ranges: bytes"); - if (req->wantbody && - http_GetHdr(req->http, H_Range, &r)) + if (wantbody && http_GetHdr(req->http, H_Range, &r)) VRG_dorange(req, r); } - CHECK_OBJ_NOTNULL(req->transport, TRANSPORT_MAGIC); - req->transport->deliver(req, bo); + req->transport->deliver(req, bo, wantbody); } /*-------------------------------------------------------------------- @@ -174,13 +184,8 @@ cnt_deliver(struct worker *wrk, struct req *req) if (!(req->objcore->flags & OC_F_PASS) && req->esi_level == 0 && http_IsStatus(req->resp, 200) - && req->http->conds && RFC2616_Do_Cond(req)) { + && req->http->conds && RFC2616_Do_Cond(req)) http_PutResponse(req->resp, "HTTP/1.1", 304, NULL); - req->wantbody = 0; - } - - if (http_IsStatus(req->resp, 304)) - req->wantbody = 0; /* Grab a ref to the bo if there is one, and hand it down */ bo = HSH_RefBusy(req->objcore); @@ -690,11 +695,6 @@ cnt_recv(struct worker *wrk, struct req *req) assert(wrk->handling == VCL_RET_LOOKUP); SHA256_Final(req->digest, &sha256ctx); - if (!strcmp(req->http->hd[HTTP_HDR_METHOD].b, "HEAD")) - req->wantbody = 0; - else - req->wantbody = 1; - switch(recv_handling) { case VCL_RET_PURGE: req->req_step = R_STP_PURGE; diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c index f0762df..324947b 100644 --- a/bin/varnishd/http1/cache_http1_deliver.c +++ b/bin/varnishd/http1/cache_http1_deliver.c @@ -62,7 +62,7 @@ v1d_bytes(struct req *req, enum vdp_action act, void **priv, */ void __match_proto__(vtr_deliver_f) -V1D_Deliver(struct req *req, struct busyobj *bo) +V1D_Deliver(struct req *req, struct busyobj *bo, int wantbody) { enum objiter_status ois; @@ -70,20 +70,18 @@ V1D_Deliver(struct req *req, struct busyobj *bo) CHECK_OBJ_ORNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC); - if ((req->objcore->flags & OC_F_PRIVATE) && - !strcasecmp(http_GetMethod(req->http0), "HEAD")) { - /* HEAD+pass is allowed to send the C-L through unmolested. */ - } else { + if (wantbody) { http_Unset(req->resp, H_Content_Length); - if (req->resp_len >= 0 && !http_IsStatus(req->resp, 304)) + if (req->resp_len >= 0) http_PrintfHeader(req->resp, "Content-Length: %jd", req->resp_len); } - if (http_GetHdr(req->resp, H_Content_Length, NULL)) + if (req->resp_len == 0) + wantbody = 0; + else if (http_GetHdr(req->resp, H_Content_Length, NULL)) req->res_mode |= RES_LEN; - - else if (req->wantbody) { + else if (wantbody) { if (req->http->protover == 11) { req->res_mode |= RES_CHUNKED; http_SetHeader(req->resp, "Transfer-Encoding: chunked"); @@ -112,7 +110,7 @@ V1D_Deliver(struct req *req, struct busyobj *bo) (void)V1L_Flush(req->wrk); ois = OIS_DONE; - if (req->wantbody) { + if (wantbody) { if (req->res_mode & RES_CHUNKED) V1L_Chunked(req->wrk); ois = VDP_DeliverObj(req); diff --git a/bin/varnishtest/tests/c00034.vtc b/bin/varnishtest/tests/c00034.vtc index 0170b22..b1698cd 100644 --- a/bin/varnishtest/tests/c00034.vtc +++ b/bin/varnishtest/tests/c00034.vtc @@ -31,6 +31,8 @@ client c1 { rxresp expect resp.status == 416 expect resp.bodylen == 0 + expect resp.http.content-length == "0" + expect resp.http.transfer-encoding == "" expect resp.http.content-range == "bytes */100" txreq -hdr "Range: bytes=0- 9" diff --git a/bin/varnishtest/tests/g00001.vtc b/bin/varnishtest/tests/g00001.vtc index ccdc39e..a1343fe 100644 --- a/bin/varnishtest/tests/g00001.vtc +++ b/bin/varnishtest/tests/g00001.vtc @@ -22,6 +22,8 @@ client c1 { expect resp.bodylen == "3" } -run +delay .1 + client c1 { txreq -proto HTTP/1.0 rxresp @@ -29,6 +31,8 @@ client c1 { expect resp.http.content-encoding == } -run +delay .1 + client c1 { txreq -req HEAD rxresp -no_obj diff --git a/bin/varnishtest/tests/r01746.vtc b/bin/varnishtest/tests/r01746.vtc index 30c6137..46793f8 100644 --- a/bin/varnishtest/tests/r01746.vtc +++ b/bin/varnishtest/tests/r01746.vtc @@ -6,8 +6,7 @@ server s1 { rxreq expect req.url == /b txresp -status 204 -nolen \ - -hdr "Content-encoding: gzip" \ - -hdr "content-length: 10" + -hdr "Content-encoding: gzip" } -start varnish v1 -vcl+backend { diff --git a/include/tbl/req_flags.h b/include/tbl/req_flags.h index 389cc51..55bdc74 100644 --- a/include/tbl/req_flags.h +++ b/include/tbl/req_flags.h @@ -34,5 +34,4 @@ REQ_FLAG(disable_esi, 0, 0, "") REQ_FLAG(hash_ignore_busy, 1, 1, "") REQ_FLAG(hash_always_miss, 1, 1, "") REQ_FLAG(is_hit, 0, 0, "") -REQ_FLAG(wantbody, 0, 0, "") /*lint -restore */ From phk at FreeBSD.org Mon Jul 27 07:20:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 27 Jul 2015 09:20:24 +0200 Subject: [master] 82a09dc minor polish Message-ID: commit 82a09dcd12269368517aa40acdf3f24cdf30f52f Author: Poul-Henning Kamp Date: Mon Jul 27 07:20:07 2015 +0000 minor polish diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index aa1f4cf..539fee1 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -883,7 +883,7 @@ static enum fetch_step vbf_stp_done(void) { WRONG("Just plain wrong"); - return (F_STP_DONE); + NEEDLESS_RETURN(F_STP_DONE); } static void __match_proto__(task_func_t) diff --git a/lib/libvcc/vcc_storage.c b/lib/libvcc/vcc_storage.c index 89e63b0..b78d2f4 100644 --- a/lib/libvcc/vcc_storage.c +++ b/lib/libvcc/vcc_storage.c @@ -76,11 +76,10 @@ vcc_Stv_mkvar(struct vcc *tl, const struct token *t, enum var_type fmt) AN(v); v->name = TlDupTok(tl, t); - v->r_methods = 0 -#define VCL_MET_MAC(l,u,b) | VCL_MET_##u + v->r_methods = 0; +#define VCL_MET_MAC(l,u,b) v->r_methods |= VCL_MET_##u; #include "tbl/vcl_returns.h" #undef VCL_MET_MAC - ; v->fmt = fmt; return (v); From fgsch at lodoss.net Tue Jul 28 22:00:59 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Wed, 29 Jul 2015 00:00:59 +0200 Subject: [master] 9c63dbb Correct parameter name Message-ID: commit 9c63dbba81423ba581597163915a2392e562fc36 Author: Federico G. Schwindt Date: Tue Jul 28 22:59:37 2015 +0100 Correct parameter name This does say something about how much is used though. diff --git a/doc/sphinx/phk/persistent.rst b/doc/sphinx/phk/persistent.rst index 6c1d29c..536e406 100644 --- a/doc/sphinx/phk/persistent.rst +++ b/doc/sphinx/phk/persistent.rst @@ -16,7 +16,7 @@ it, and we don't presently have the development resources to fix that. If you think you have these circumstances, you need to specify - -sdeprecated_persistence + -sdeprecated_persistent in order to use it. From fgsch at lodoss.net Tue Jul 28 22:35:10 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Wed, 29 Jul 2015 00:35:10 +0200 Subject: [master] bdf1235 Parameters cleanup Message-ID: commit bdf1235857c9734d6ec21db10c119dcdc4b48442 Author: Federico G. Schwindt Date: Tue Jul 28 23:30:38 2015 +0100 Parameters cleanup Add missing ones, make the order consistent and remove deprecated options. More to come. diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 0ae5338..37b1985 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -141,15 +141,15 @@ usage(void) #define FMT " %-28s # %s\n" fprintf(stderr, "usage: varnishd [options]\n"); - fprintf(stderr, FMT, "-a address:port", "HTTP listen address and port" - " (default: *:80)"); + fprintf(stderr, FMT, "-a address:port,proto", + "HTTP listen address and port (default: *:80)"); fprintf(stderr, FMT, "-b address:port", "backend address and port"); fprintf(stderr, FMT, "", " -b "); fprintf(stderr, FMT, "", " -b ':'"); fprintf(stderr, FMT, "-C", "print VCL code compiled to C language"); fprintf(stderr, FMT, "-d", "debug"); - fprintf(stderr, FMT, "-f file", "VCL script"); fprintf(stderr, FMT, "-F", "Run in foreground"); + fprintf(stderr, FMT, "-f file", "VCL script"); fprintf(stderr, FMT, "-h kind[,hashoptions]", "Hash specification"); fprintf(stderr, FMT, "", " -h critbit [default]"); fprintf(stderr, FMT, "", " -h simple_list"); @@ -162,15 +162,17 @@ usage(void) #endif fprintf(stderr, FMT, "", " -j unix[,user=][,ccgroup=]"); fprintf(stderr, FMT, "", " -j none"); - fprintf(stderr, FMT, "-l shl,free,fill", "Size of shared memory file"); + fprintf(stderr, FMT, "-l shl,free", "Size of shared memory file"); fprintf(stderr, FMT, "", " shl: space for SHL records [80m]"); fprintf(stderr, FMT, "", " free: space for other allocations [1m]"); - fprintf(stderr, FMT, "", " fill: prefill new file [+]"); - fprintf(stderr, FMT, "-M address:port", "Reverse CLI destination."); + fprintf(stderr, FMT, "-M address:port", "Reverse CLI destination"); fprintf(stderr, FMT, "-n dir", "varnishd working directory"); fprintf(stderr, FMT, "-P file", "PID file"); fprintf(stderr, FMT, "-p param=value", "set parameter"); - fprintf(stderr, FMT, "-r param[,param...]", "make parameter read-only"); + fprintf(stderr, FMT, + "-r param[,param...]", "make parameter read-only"); + fprintf(stderr, FMT, "-S secret-file", + "Secret file for CLI authentication"); fprintf(stderr, FMT, "-s [name=]kind[,options]", "Backend storage specification"); fprintf(stderr, FMT, "", " -s malloc[,]"); @@ -181,12 +183,10 @@ usage(void) fprintf(stderr, FMT, "", " -s file,,"); fprintf(stderr, FMT, "", " -s file,,,"); - fprintf(stderr, FMT, "", " -s persist{experimental}"); - fprintf(stderr, FMT, "-S secret-file", - "Secret file for CLI authentication"); + fprintf(stderr, FMT, "", " -s persistent (experimental)"); fprintf(stderr, FMT, "-T address:port", "Telnet listen address and port"); - fprintf(stderr, FMT, "-t", "Default TTL"); + fprintf(stderr, FMT, "-t TTL", "Default TTL"); fprintf(stderr, FMT, "-V", "version"); fprintf(stderr, FMT, "-W waiter", "Waiter implementation"); #if defined(HAVE_KQUEUE) @@ -541,12 +541,12 @@ main(int argc, char * const *argv) case 'd': d_flag++; break; - case 'f': - f_arg = optarg; - break; case 'F': F_flag = 1 - F_flag; break; + case 'f': + f_arg = optarg; + break; case 'h': h_arg = optarg; break; @@ -591,19 +591,19 @@ main(int argc, char * const *argv) MCF_ParamProtect(cli, optarg); cli_check(cli); break; + case 'S': + S_arg = optarg; + break; case 's': s_arg_given = 1; STV_Config(optarg); break; - case 't': - MCF_ParamSet(cli, "default_ttl", optarg); - break; - case 'S': - S_arg = optarg; - break; case 'T': T_arg = optarg; break; + case 't': + MCF_ParamSet(cli, "default_ttl", optarg); + break; case 'V': /* XXX: we should print the ident here */ VCS_Message("varnishd"); diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 05b04da..33d60f6 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -15,7 +15,7 @@ HTTP accelerator daemon SYNOPSIS ======== -varnishd [-a address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-f config] [-F] [-g group] [-h type[,options]] [-i identity] [-l shl[,free[,fill]]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...] [-s [name=]kind[,options]] [-S secret-file] [-T address[:port]] [-t TTL] [-u user] [-V] +varnishd [-a address[:port][,PROTO]] [-b host[:port]] [-C] [-d] [-F] [-f config] [-h type[,options]] [-i identity] [-j jail[,jailoptions]] [-l shl[,free]] [-M address:port] [-n name] [-P file] [-p param=value] [-r param[,param...]] [-S secret-file] [-s [name=]kind[,options]] [-T address[:port]] [-t TTL] [-V] [-W waiter] DESCRIPTION =========== @@ -58,6 +58,10 @@ OPTIONS started explicitly with a CLI command. Terminating the parent process will also terminate the child. +-F + + Do not fork, run in the foreground. + -f config Use the specified VCL configuration file instead of the builtin @@ -66,16 +70,6 @@ OPTIONS When neither a -f nor a -b argument are given, `varnishd` will not start the worker process but process cli commands. --F - - Do not fork, run in the foreground. - --g group - - Specifies the name of an unprivileged group to which the child - process should switch before it starts accepting connections. This - is a shortcut for specifying the group run-time parameter. - -h Specifies the hash algorithm. See `Hash Algorithm Options`_ for a @@ -90,12 +84,12 @@ OPTIONS Specify the jailing technology to use. --l +-l Specifies size of shmlog file. shl is the store for the shared - memory log records [80M], free is the store for other allocations - [1M] and fill determines how the log is [+]. Scaling suffixes like - 'k', 'M' can be used up to (E)xabytes. Default is 80 Megabytes. + memory log records [80M] and free is the store for other allocations + [1M]. Scaling suffixes like 'k', 'M' can be used up to (E)xabytes. + Default is 81 Megabytes. -M @@ -129,6 +123,12 @@ OPTIONS *vcc_allow_inline_c* read only as these can potentially be used to escalate privileges from the CLI. +-S file + + Path to a file containing a secret used for authorizing access to + the management port. If not provided a new secret will be drawn + from the system PRNG. + -s <[name=]type[,options]> Use the specified storage backend, see `Storage Backend Options`_. @@ -136,12 +136,6 @@ OPTIONS This option can be used multiple times to specify multiple storage files. Names are referenced in logs, VCL, statistics, etc. --S file - - Path to a file containing a secret used for authorizing access to - the management port. If not provided a new secret will be drawn - from the system PRNG. - -T Offer a management interface on the specified address and port. See @@ -152,19 +146,14 @@ OPTIONS Specifies the default time to live (TTL) for cached objects. This is a shortcut for specifying the *default_ttl* run-time parameter. --u user - - Specifies the name of an unprivileged user to which the child - process should switch before it starts accepting connections. This - is a shortcut for specifying the user runtime parameter. - - If specifying both a user and a group, the user should be specified - first. - -V Display the version number and exit. +-W + + Specifies the waiter type to use. + .. _opt_h: Hash Algorithm Options From fgsch at lodoss.net Tue Jul 28 23:00:25 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Wed, 29 Jul 2015 01:00:25 +0200 Subject: [master] ed88811 Forgotten parameter in previous commit Message-ID: commit ed888115b2182d422c1d7240f4f2d82a7eb4dd2c Author: Federico G. Schwindt Date: Tue Jul 28 23:56:58 2015 +0100 Forgotten parameter in previous commit diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 33d60f6..378daff 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -150,7 +150,7 @@ OPTIONS Display the version number and exit. --W +-W waiter Specifies the waiter type to use. From martin at varnish-software.com Wed Jul 29 15:15:44 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Wed, 29 Jul 2015 17:15:44 +0200 Subject: [master] 8af37f4 Install the vtim.h header for use with external vmods Message-ID: commit 8af37f4cec29a963f29484c787dc3ae5086bc46c Author: Martin Blix Grydeland Date: Tue Jul 28 11:52:50 2015 +0200 Install the vtim.h header for use with external vmods diff --git a/include/Makefile.am b/include/Makefile.am index 2d4593e..8d21912 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -57,7 +57,8 @@ nobase_pkginclude_HEADERS += \ vrt_obj.h \ vsa.h \ vsb.h \ - vsha256.h + vsha256.h \ + vtim.h # Private headers nobase_noinst_HEADERS = \ @@ -86,7 +87,6 @@ nobase_noinst_HEADERS = \ vsub.h \ vss.h \ vtcp.h \ - vtim.h \ vtree.h \ vut.h \ vut_options.h From martin at varnish-software.com Wed Jul 29 15:15:44 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Wed, 29 Jul 2015 17:15:44 +0200 Subject: [master] 3ba970e Teach vmodtool.py's tokenizer quotes Message-ID: commit 3ba970ecf269fc10dd1e210db27870284147dcad Author: Martin Blix Grydeland Date: Wed Jul 29 14:38:50 2015 +0200 Teach vmodtool.py's tokenizer quotes diff --git a/bin/varnishtest/tests/m00019.vtc b/bin/varnishtest/tests/m00019.vtc index f7b2386..89ad9b0 100644 --- a/bin/varnishtest/tests/m00019.vtc +++ b/bin/varnishtest/tests/m00019.vtc @@ -22,12 +22,12 @@ client c1 { txreq rxresp expect resp.bodylen == "6" - expect resp.http.foo1 == "1 2 3" - expect resp.http.foo2 == "1 2 3" - expect resp.http.foo3 == "1 2 3" - expect resp.http.foo4 == "1 2 3" - expect resp.http.foo5 == "1 2 3" - expect resp.http.foo6 == "1 2 3" + expect resp.http.foo1 == "1 2 3 ," + expect resp.http.foo2 == "1 2 3 ," + expect resp.http.foo3 == "1 2 3 ," + expect resp.http.foo4 == "1 2 3 ," + expect resp.http.foo5 == "1 2 3 ," + expect resp.http.foo6 == "1 2 3 ," } -run delay .1 diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index ce27df2..4db94a3 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -739,6 +739,22 @@ class FileSection(object): return l = re.sub("[ \t]*#.*$", "", l) l = re.sub("[ \t]*\n", "", l) + + if re.match("['\"]", l): + m = re.match("(['\"]).*?(\\1)", l) + if not m: + raise FormatError("Unbalanced quote", + "Unbalanced quote on line %d" % ln) + self.tl.append(Token(ln, 0, l[:m.end()])) + self.l.insert(0, (ln, l[m.end():])) + return + + m = re.search("['\"]", l) + if m: + rest = l[m.start():] + self.l.insert(0, (ln, rest)) + l = l[:m.start()] + l = re.sub("([(){},=])", r' \1 ', l) if l == "": return diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index 3a60814..8b32e92 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -94,7 +94,8 @@ $Function VOID rot52(HTTP hdr) Encrypt the HTTP header with quad-ROT13 encryption, (this is approx 33% better than triple-DES). -$Function STRING argtest(STRING one, REAL two=2, STRING three="3") +$Function STRING argtest(STRING one, REAL two=2, STRING three="3", + STRING comma=",") $Function INT vre_limit() diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index ce2e22b..4d86baa 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -177,11 +177,12 @@ vmod_rot52(VRT_CTX, VCL_HTTP hp) } VCL_STRING -vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three) +vmod_argtest(VRT_CTX, VCL_STRING one, VCL_REAL two, VCL_STRING three, + VCL_STRING comma) { char buf[100]; - bprintf(buf, "%s %g %s", one, two, three); + bprintf(buf, "%s %g %s %s", one, two, three, comma); return WS_Copy(ctx->ws, buf, -1); } From lkarsten at varnish-software.com Fri Jul 31 07:02:50 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Fri, 31 Jul 2015 09:02:50 +0200 Subject: [master] f398f62 Lint. Message-ID: commit f398f62aaf0ad303660b4c403ffa388895d77405 Author: Lasse Karstensen Date: Thu Jul 30 12:41:11 2015 +0200 Lint. diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index a353c81..e41654d 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -179,7 +179,7 @@ VRB_Free(struct req *req) CHECK_OBJ_NOTNULL(req, REQ_MAGIC); if (req->body_oc != NULL) { - ObjFreeObj(req->wrk,req->body_oc); + ObjFreeObj(req->wrk, req->body_oc); FREE_OBJ(req->body_oc); req->body_oc = NULL; } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index f3ab04a..07123fb 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -530,7 +530,7 @@ ses_close_acct(enum sess_close reason) } /*-------------------------------------------------------------------- - * Close a sessions connection. + * Close a session's connection. * XXX: Technically speaking we should catch a t_end timestamp here * XXX: for SES_Delete() to use. */ From lkarsten at varnish-software.com Fri Jul 31 07:02:50 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Fri, 31 Jul 2015 09:02:50 +0200 Subject: [master] 559390d Correct wrong offset. Message-ID: commit 559390d049bdbb1fddb1a177589eda10a1118f41 Author: Lasse Karstensen Date: Thu Jul 30 18:03:04 2015 +0200 Correct wrong offset. "2eq" instead of "Req" didn't look right. diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c index 0b2d1b9..60fdd44 100644 --- a/bin/varnishd/cache/cache_ws.c +++ b/bin/varnishd/cache/cache_ws.c @@ -78,7 +78,7 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len) ws->e = ws->s + len; *ws->e = 0x15; ws->f = ws->s; - assert(id[0] & 0x40); + assert(id[0] & 0x20); assert(strlen(id) < sizeof ws->id); strcpy(ws->id, id); WS_Assert(ws); @@ -90,7 +90,7 @@ WS_MarkOverflow(struct ws *ws) { CHECK_OBJ_NOTNULL(ws, WS_MAGIC); - ws->id[0] &= ~0x40; // cheesy toupper() + ws->id[0] &= ~0x20; // cheesy toupper() } static void @@ -98,7 +98,7 @@ ws_ClearOverflow(struct ws *ws) { CHECK_OBJ_NOTNULL(ws, WS_MAGIC); - ws->id[0] |= 0x40; // cheesy tolower() + ws->id[0] |= 0x20; // cheesy tolower() } /* @@ -255,7 +255,7 @@ WS_Overflowed(const struct ws *ws) { CHECK_OBJ_NOTNULL(ws, WS_MAGIC); - if (ws->id[0] & 0x40) + if (ws->id[0] & 0x20) return (0); return (1); } From lkarsten at varnish-software.com Fri Jul 31 09:35:55 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Fri, 31 Jul 2015 11:35:55 +0200 Subject: [master] 1479325 Add req_top to the list of changes. Message-ID: commit 14793254fb0281e86f1f17da9b30b6946ee1d872 Author: Lasse Karstensen Date: Fri Jul 31 11:35:53 2015 +0200 Add req_top to the list of changes. diff --git a/doc/sphinx/whats-new/changes.rst b/doc/sphinx/whats-new/changes.rst index 2dd4a16..b7fd4da 100644 --- a/doc/sphinx/whats-new/changes.rst +++ b/doc/sphinx/whats-new/changes.rst @@ -102,6 +102,16 @@ Surrogate keys Not yet documented. +Passing data between ESI requests +================================= + +A new `req_top` identifier is available in VCL, which is a reference +to `req` in the top-level ESI request. + +This is useful to pass data back and forth between the main ESI request +and any ESI subrequests it lead to. + + Other noteworthy small changes ============================== From phk at FreeBSD.org Fri Jul 31 12:42:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 31 Jul 2015 14:42:08 +0200 Subject: [master] 21ed397 Lock backend counter. Message-ID: commit 21ed397dd1cba4988e43879fd5b54fea02fd4475 Author: Poul-Henning Kamp Date: Mon Jul 27 07:29:35 2015 +0000 Lock backend counter. Submitted by: fgs diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 0591ec7..75adf78 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -105,6 +105,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) Lck_Lock(&bp->mtx); bp->n_conn++; bp->vsc->conn++; + bp->vsc->req++; Lck_Unlock(&bp->mtx); VTCP_myname(vc->fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1); @@ -112,7 +113,6 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) VSLb(bo->vsl, SLT_BackendOpen, "%d %s %s %s %s %s", vc->fd, bp->display_name, abuf2, pbuf2, abuf1, pbuf1); - bp->vsc->req++; INIT_OBJ(bo->htc, HTTP_CONN_MAGIC); bo->htc->priv = vc; bo->htc->fd = vc->fd; From phk at FreeBSD.org Fri Jul 31 12:42:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 31 Jul 2015 14:42:08 +0200 Subject: [master] ccf1c0d Add an auto-indent facility to vsb's. Message-ID: commit ccf1c0d78154cd57f684003218849c457ff21c24 Author: Poul-Henning Kamp Date: Fri Jul 31 08:07:45 2015 +0000 Add an auto-indent facility to vsb's. diff --git a/include/vsb.h b/include/vsb.h index 72a2a99..eefaa12 100644 --- a/include/vsb.h +++ b/include/vsb.h @@ -48,6 +48,7 @@ struct vsb { #define VSB_FINISHED 0x00020000 /* set by VSB_finish() */ #define VSB_DYNSTRUCT 0x00080000 /* vsb must be freed */ int s_flags; /* flags */ + int s_indent; /* Ident level */ }; #ifdef __cplusplus @@ -75,6 +76,7 @@ char *VSB_data(const struct vsb *); ssize_t VSB_len(const struct vsb *); void VSB_delete(struct vsb *); void VSB_quote(struct vsb *s, const char *p, int len, int how); +void VSB_indent(struct vsb *, int); #ifdef __cplusplus }; #endif From phk at FreeBSD.org Fri Jul 31 12:42:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 31 Jul 2015 14:42:08 +0200 Subject: [master] fb06777 Implementation of VSB auto-indent facility Message-ID: commit fb06777292fe29f5571a2a406dc374ee450355c2 Author: Poul-Henning Kamp Date: Fri Jul 31 08:08:27 2015 +0000 Implementation of VSB auto-indent facility diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c index 1332844..be147c2 100644 --- a/lib/libvarnish/vsb.c +++ b/lib/libvarnish/vsb.c @@ -114,7 +114,6 @@ CTASSERT(powerof2(VSB_MAXEXTENDSIZE)); CTASSERT(powerof2(VSB_MAXEXTENDINCR)); #endif - static int VSB_extendsize(int size) { @@ -156,6 +155,21 @@ VSB_extend(struct vsb *s, int addlen) return (0); } +static void +_vsb_indent(struct vsb *s) +{ + if (s->s_indent == 0 || s->s_error != 0 || + s->s_buf[s->s_len - 1] != '\n') + return; + if (VSB_FREESPACE(s) <= s->s_indent && + VSB_extend(s, s->s_indent) < 0) { + s->s_error = ENOMEM; + return; + } + memset(s->s_buf + s->s_len, ' ', s->s_indent); + s->s_len += s->s_indent; +} + /* * Initialize the internals of an vsb. * If buf is non-NULL, it points to a static or already-allocated string @@ -231,6 +245,7 @@ VSB_clear(struct vsb *s) VSB_CLEARFLAG(s, VSB_FINISHED); s->s_error = 0; s->s_len = 0; + s->s_indent = 0; } /* @@ -247,6 +262,7 @@ VSB_put_byte(struct vsb *s, int c) if (s->s_error != 0) return; + _vsb_indent(s); if (VSB_FREESPACE(s) <= 0) { if (VSB_extend(s, 1) < 0) s->s_error = ENOMEM; @@ -270,6 +286,7 @@ VSB_bcat(struct vsb *s, const void *buf, size_t len) if (s->s_error != 0) return (-1); + _vsb_indent(s); for (; str < end; str++) { VSB_put_byte(s, *str); if (s->s_error != 0) @@ -316,6 +333,7 @@ VSB_vprintf(struct vsb *s, const char *fmt, va_list ap) if (s->s_error != 0) return (-1); + _vsb_indent(s); /* * For the moment, there is no way to get vsnprintf(3) to hand @@ -515,3 +533,18 @@ VSB_quote(struct vsb *s, const char *p, int len, int how) } (void)VSB_putc(s, '"'); } + +/* + * Indentation + */ + +void +VSB_indent(struct vsb * s, int i) +{ + + assert_VSB_integrity(s); + if (s->s_indent + i < 0) + s->s_error = EINVAL; + else + s->s_indent += i; +} From phk at FreeBSD.org Fri Jul 31 12:42:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Fri, 31 Jul 2015 14:42:08 +0200 Subject: [master] 55e253f Roto-till the panic/backtrace output to use the VSB auto-indent. Message-ID: commit 55e253fd0405a96dcd77f31fbda416506515fb7d Author: Poul-Henning Kamp Date: Fri Jul 31 08:08:43 2015 +0000 Roto-till the panic/backtrace output to use the VSB auto-indent. Based largely on patch from: Martin I wonder if we should make the panic output (readable) JSON format ? diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 75adf78..092abb3 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -319,17 +319,17 @@ vbe_panic(const struct director *d, struct vsb *vsb) CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); - VSB_printf(vsb, " display_name = %s\n", bp->display_name); + VSB_printf(vsb, "display_name = %s\n", bp->display_name); if (bp->ipv4_addr != NULL) - VSB_printf(vsb, " ipv4 = %s\n", bp->ipv4_addr); + VSB_printf(vsb, "ipv4 = %s\n", bp->ipv4_addr); if (bp->ipv6_addr != NULL) - VSB_printf(vsb, " ipv6 = %s\n", bp->ipv6_addr); - VSB_printf(vsb, " port = %s\n", bp->port); - VSB_printf(vsb, " hosthdr = %s\n", bp->hosthdr); - VSB_printf(vsb, " health=%s, admin_health=%s", + VSB_printf(vsb, "ipv6 = %s\n", bp->ipv6_addr); + VSB_printf(vsb, "port = %s\n", bp->port); + VSB_printf(vsb, "hosthdr = %s\n", bp->hosthdr); + VSB_printf(vsb, "health=%s, admin_health=%s", bp->healthy ? "healthy" : "sick", bp->admin_health); VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed); - VSB_printf(vsb, " n_conn = %u\n", bp->n_conn); + VSB_printf(vsb, "n_conn = %u\n", bp->n_conn); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c index f7e0479..b6d0944 100644 --- a/bin/varnishd/cache/cache_director.c +++ b/bin/varnishd/cache/cache_director.c @@ -187,10 +187,15 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm) { if (d == NULL) return; - VSB_printf(vsb, " %s = %p {\n", nm, d); - VSB_printf(vsb, " vcl_name = %s\n", d->vcl_name); - VSB_printf(vsb, " name = %s\n", d->name); + VSB_printf(vsb, "%s = %p {\n", nm, d); + VSB_indent(vsb, 2); + VSB_printf(vsb, "vcl_name = %s\n", d->vcl_name); + VSB_printf(vsb, "type = %s {\n", d->name); + VSB_indent(vsb, 2); if (d->panic != NULL) d->panic(d, vsb); - VSB_printf(vsb, " }\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "}\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "}\n"); } diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index bfe3e70..873c5e0 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -58,10 +58,10 @@ * (gdb) printf "%s", panicstr */ -static struct vsb pan_vsp_storage, *pan_vsp; +static struct vsb pan_vsb_storage, *pan_vsb; static pthread_mutex_t panicstr_mtx = PTHREAD_MUTEX_INITIALIZER; -static void pan_sess(const struct sess *sp); +static void pan_sess(struct vsb *, const struct sess *); /*--------------------------------------------------------------------*/ @@ -110,252 +110,206 @@ sess_close_2str(enum sess_close sc, int want_desc) /*--------------------------------------------------------------------*/ static void -pan_ws(const struct ws *ws, int indent) +pan_ws(struct vsb *vsb, const struct ws *ws) { - VSB_printf(pan_vsp, "%*sws = %p {", indent, "", ws); - if (!VALID_OBJ(ws, WS_MAGIC)) { - if (ws != NULL) - VSB_printf(pan_vsp, " BAD_MAGIC(0x%08x) ", ws->magic); - } else { - if (WS_Overflowed(ws)) - VSB_printf(pan_vsp, " OVERFLOW"); - VSB_printf(pan_vsp, - "\n%*sid = \"%s\",\n", indent + 2, "", ws->id); - VSB_printf(pan_vsp, - "%*s{s,f,r,e} = {%p", indent + 2, "", ws->s); - if (ws->f > ws->s) - VSB_printf(pan_vsp, ",+%ld", (long) (ws->f - ws->s)); - else - VSB_printf(pan_vsp, ",%p", ws->f); - if (ws->r > ws->s) - VSB_printf(pan_vsp, ",+%ld", (long) (ws->r - ws->s)); - else - VSB_printf(pan_vsp, ",%p", ws->r); - if (ws->e > ws->s) - VSB_printf(pan_vsp, ",+%ld", (long) (ws->e - ws->s)); - else - VSB_printf(pan_vsp, ",%p", ws->e); - } - VSB_printf(pan_vsp, "},\n"); - VSB_printf(pan_vsp, "%*s},\n", indent, "" ); + VSB_printf(vsb, "ws = %p {\n", ws); + VSB_indent(vsb, 2); + if (WS_Overflowed(ws)) + VSB_printf(vsb, " OVERFLOW"); + VSB_printf(vsb, "id = \"%s\",\n", ws->id); + VSB_printf(vsb, "{s,f,r,e} = {%p", ws->s); + if (ws->f > ws->s) + VSB_printf(vsb, ",+%ld", (long) (ws->f - ws->s)); + else + VSB_printf(vsb, ",%p", ws->f); + if (ws->r > ws->s) + VSB_printf(vsb, ",+%ld", (long) (ws->r - ws->s)); + else + VSB_printf(vsb, ",%p", ws->r); + if (ws->e > ws->s) + VSB_printf(vsb, ",+%ld", (long) (ws->e - ws->s)); + else + VSB_printf(vsb, ",%p", ws->e); + VSB_printf(vsb, "},\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ static void -pan_htc(const struct http_conn *htc) +pan_htc(struct vsb *vsb, const struct http_conn *htc) { - VSB_printf(pan_vsp, " http_conn = %p {\n", htc); - VSB_printf(pan_vsp, " fd = %d,\n", htc->fd); - VSB_printf(pan_vsp, " },\n"); + VSB_printf(vsb, "http_conn = %p {\n", htc); + VSB_indent(vsb, 2); + VSB_printf(vsb, "fd = %d,\n", htc->fd); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ -#if 0 static void -pan_storage(const struct storage *st) -{ - int i, j; - -#define MAX_BYTES (4*16) -#define show(ch) (((ch) > 31 && (ch) < 127) ? (ch) : '.') - - VSB_printf(pan_vsp, " %u {\n", st->len); - for (i = 0; i < MAX_BYTES && i < st->len; i += 16) { - VSB_printf(pan_vsp, " "); - for (j = 0; j < 16; ++j) { - if (i + j < st->len) - VSB_printf(pan_vsp, "%02x ", st->ptr[i + j]); - else - VSB_printf(pan_vsp, " "); - } - VSB_printf(pan_vsp, "|"); - for (j = 0; j < 16; ++j) - if (i + j < st->len) - VSB_printf(pan_vsp, - "%c", show(st->ptr[i + j])); - VSB_printf(pan_vsp, "|\n"); - } - if (st->len > MAX_BYTES) - VSB_printf(pan_vsp, - " [%u more]\n", st->len - MAX_BYTES); - VSB_printf(pan_vsp, " },\n"); - -#undef show -#undef MAX_BYTES -} -#endif - -/*--------------------------------------------------------------------*/ - -static void -pan_http(const char *id, const struct http *h, int indent) +pan_http(struct vsb *vsb, const char *id, const struct http *h) { int i; - VSB_printf(pan_vsp, "%*shttp[%s] = {\n", indent, "", id); - VSB_printf(pan_vsp, "%*sws = %p[%s]\n", indent + 2, "", - h->ws, h->ws ? h->ws->id : ""); + VSB_printf(vsb, "http[%s] = %p {\n", id, h); + VSB_indent(vsb, 2); + VSB_printf(vsb, "ws[%s] = %p\n", h->ws ? h->ws->id : "", h->ws); + VSB_printf(vsb, "hdrs {\n"); + VSB_indent(vsb, 2); for (i = 0; i < h->nhd; ++i) { if (h->hd[i].b == NULL && h->hd[i].e == NULL) continue; - VSB_printf(pan_vsp, "%*s\"%.*s\",\n", indent + 4, "", - (int)(h->hd[i].e - h->hd[i].b), - h->hd[i].b); + VSB_printf(vsb, "\"%.*s\",\n", + (int)(h->hd[i].e - h->hd[i].b), h->hd[i].b); } - VSB_printf(pan_vsp, "%*s},\n", indent, ""); -} - - -/*--------------------------------------------------------------------*/ - -#if 0 -static void -pan_object(const char *typ, const struct object *o) -{ - const struct storage *st; - - VSB_printf(pan_vsp, " obj (%s) = %p {\n", typ, o); - VSB_printf(pan_vsp, " vxid = %u,\n", VXID(vbe32dec(o->oa_vxid))); - pan_http("obj", o->http, 4); - VSB_printf(pan_vsp, " len = %jd,\n", (intmax_t)o->body->len); - VSB_printf(pan_vsp, " store = {\n"); - VTAILQ_FOREACH(st, &o->body->list, list) - pan_storage(st); - VSB_printf(pan_vsp, " },\n"); - VSB_printf(pan_vsp, " },\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } -#endif /*--------------------------------------------------------------------*/ static void -pan_objcore(const char *typ, const struct objcore *oc) +pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc) { - VSB_printf(pan_vsp, " objcore (%s) = %p {\n", typ, oc); - VSB_printf(pan_vsp, " refcnt = %d\n", oc->refcnt); - VSB_printf(pan_vsp, " flags = 0x%x\n", oc->flags); - VSB_printf(pan_vsp, " objhead = %p\n", oc->objhead); - VSB_printf(pan_vsp, " stevedore = %p", oc->stobj->stevedore); + VSB_printf(vsb, "objcore[%s] = %p {\n", typ, oc); + VSB_indent(vsb, 2); + VSB_printf(vsb, "refcnt = %d\n", oc->refcnt); + VSB_printf(vsb, "flags = 0x%x\n", oc->flags); + VSB_printf(vsb, "objhead = %p\n", oc->objhead); + VSB_printf(vsb, "stevedore = %p", oc->stobj->stevedore); if (oc->stobj->stevedore != NULL) { - VSB_printf(pan_vsp, " (%s", oc->stobj->stevedore->name); + VSB_printf(vsb, " (%s", oc->stobj->stevedore->name); if (strlen(oc->stobj->stevedore->ident)) - VSB_printf(pan_vsp, " %s", oc->stobj->stevedore->ident); - VSB_printf(pan_vsp, ")"); + VSB_printf(vsb, " %s", oc->stobj->stevedore->ident); + VSB_printf(vsb, ")"); } - VSB_printf(pan_vsp, "\n"); - VSB_printf(pan_vsp, " }\n"); + VSB_printf(vsb, "\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "}\n"); } /*--------------------------------------------------------------------*/ static void -pan_wrk(const struct worker *wrk) +pan_wrk(struct vsb *vsb, const struct worker *wrk) { const char *hand; unsigned m, u; const char *p; - VSB_printf(pan_vsp, " worker = %p {\n", wrk); - VSB_printf(pan_vsp, " stack = {0x%jx -> 0x%jx}\n", + VSB_printf(vsb, "worker = %p {\n", wrk); + VSB_indent(vsb, 2); + VSB_printf(vsb, "stack = {0x%jx -> 0x%jx}\n", (uintmax_t)wrk->stack_start, (uintmax_t)wrk->stack_end); - pan_ws(wrk->aws, 4); + pan_ws(vsb, wrk->aws); m = wrk->cur_method; - VSB_printf(pan_vsp, " VCL::method = "); + VSB_printf(vsb, "VCL::method = "); if (m == 0) { - VSB_printf(pan_vsp, "none,\n"); + VSB_printf(vsb, "none,\n"); return; } if (!(m & 1)) - VSB_printf(pan_vsp, "*"); + VSB_printf(vsb, "inside "); m &= ~1; hand = VCL_Method_Name(m); if (hand != NULL) - VSB_printf(pan_vsp, "%s,\n", hand); + VSB_printf(vsb, "%s,\n", hand); else - VSB_printf(pan_vsp, "0x%x,\n", m); + VSB_printf(vsb, "0x%x,\n", m); + hand = VCL_Return_Name(wrk->handling); if (hand != NULL) - VSB_printf(pan_vsp, " VCL::return = %s,\n", hand); + VSB_printf(vsb, "VCL::return = %s,\n", hand); else - VSB_printf(pan_vsp, " VCL::return = 0x%x,\n", wrk->handling); - VSB_printf(pan_vsp, " VCL::methods = {"); + VSB_printf(vsb, "VCL::return = 0x%x,\n", wrk->handling); + VSB_printf(vsb, "VCL::methods = {"); m = wrk->seen_methods; p = ""; for (u = 1; m ; u <<= 1) { if (m & u) { - VSB_printf(pan_vsp, "%s%s", p, VCL_Method_Name(u)); + VSB_printf(vsb, "%s%s", p, VCL_Method_Name(u)); m &= ~u; p = ", "; } } - VSB_printf(pan_vsp, "},\n },\n"); + VSB_printf(vsb, "},\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } static void -pan_busyobj(const struct busyobj *bo) +pan_busyobj(struct vsb *vsb, const struct busyobj *bo) { struct vfp_entry *vfe; + const char *p; - VSB_printf(pan_vsp, " busyobj = %p {\n", bo); - pan_ws(bo->ws, 4); - VSB_printf(pan_vsp, " refcnt = %u\n", bo->refcount); - VSB_printf(pan_vsp, " retries = %d\n", bo->retries); - VSB_printf(pan_vsp, " failed = %d\n", bo->vfc->failed); - VSB_printf(pan_vsp, " state = %d\n", (int)bo->state); - VSB_printf(pan_vsp, " flags = {\n"); -#define BO_FLAG(l, r, w, d) if(bo->l) VSB_printf(pan_vsp, " " #l "\n"); + VSB_printf(vsb, "busyobj = %p {\n", bo); + VSB_indent(vsb, 2); + pan_ws(vsb, bo->ws); + VSB_printf(vsb, "refcnt = %u\n", bo->refcount); + VSB_printf(vsb, "retries = %d, ", bo->retries); + VSB_printf(vsb, "failed = %d, ", bo->vfc->failed); + VSB_printf(vsb, "state = %d\n", (int)bo->state); + VSB_printf(vsb, "flags = {"); + p = ""; +#define BO_FLAG(l, r, w, d) \ + if(bo->l) { VSB_printf(vsb, "%s" #l, p); p = ", "; } #include "tbl/bo_flags.h" #undef BO_FLAG - VSB_printf(pan_vsp, " }\n"); + VSB_printf(vsb, "}\n"); if (bo->htc != NULL) { - VSB_printf(pan_vsp, " bodystatus = %d (%s),\n", + VSB_printf(vsb, "bodystatus = %d (%s),\n", bo->htc->body_status, body_status_2str(bo->htc->body_status)); } if (!VTAILQ_EMPTY(&bo->vfc->vfp)) { - VSB_printf(pan_vsp, " filters ="); + VSB_printf(vsb, "filters ="); VTAILQ_FOREACH(vfe, &bo->vfc->vfp, list) - VSB_printf(pan_vsp, " %s=%d", + VSB_printf(vsb, " %s=%d", vfe->vfp->name, (int)vfe->closed); - VSB_printf(pan_vsp, "\n"); + VSB_printf(vsb, "\n"); } if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC)) - pan_htc(bo->htc); - VDI_Panic(bo->director_req, pan_vsp, "director_req"); + pan_htc(vsb, bo->htc); + VDI_Panic(bo->director_req, vsb, "director_req"); if (bo->director_resp == bo->director_req) - VSB_printf(pan_vsp, " director_resp = director_req\n"); + VSB_printf(vsb, "director_resp = director_req\n"); else - VDI_Panic(bo->director_resp, pan_vsp, "director_resp"); + VDI_Panic(bo->director_resp, vsb, "director_resp"); if (bo->bereq != NULL && bo->bereq->ws != NULL) - pan_http("bereq", bo->bereq, 4); + pan_http(vsb, "bereq", bo->bereq); if (bo->beresp != NULL && bo->beresp->ws != NULL) - pan_http("beresp", bo->beresp, 4); + pan_http(vsb, "beresp", bo->beresp); if (bo->fetch_objcore) - pan_objcore("FETCH", bo->fetch_objcore); + pan_objcore(vsb, "fetch", bo->fetch_objcore); if (bo->stale_oc) - pan_objcore("IMS", bo->stale_oc); - VSB_printf(pan_vsp, " }\n"); + pan_objcore(vsb, "ims", bo->stale_oc); + VSB_indent(vsb, -2); + VSB_printf(vsb, "}\n"); } /*--------------------------------------------------------------------*/ static void -pan_req(const struct req *req) +pan_req(struct vsb *vsb, const struct req *req) { const char *stp; - VSB_printf(pan_vsp, "req = %p {\n", req); + VSB_printf(vsb, "req = %p {\n", req); + VSB_indent(vsb, 2); - VSB_printf(pan_vsp, " sp = %p, vxid = %u,", - req->sp, VXID(req->vsl->wid)); + VSB_printf(vsb, "vxid = %u, ", VXID(req->vsl->wid)); switch (req->req_step) { #define REQ_STEP(l, u, arg) case R_STP_##u: stp = "R_STP_" #u; break; @@ -364,64 +318,65 @@ pan_req(const struct req *req) default: stp = NULL; } if (stp != NULL) - VSB_printf(pan_vsp, " step = %s,\n", stp); + VSB_printf(vsb, "step = %s,\n", stp); else - VSB_printf(pan_vsp, " step = 0x%x,\n", req->req_step); + VSB_printf(vsb, "step = 0x%x,\n", req->req_step); - VSB_printf(pan_vsp, " req_body = %s,\n", + VSB_printf(vsb, "req_body = %s,\n", reqbody_status_2str(req->req_body_status)); if (req->err_code) - VSB_printf(pan_vsp, + VSB_printf(vsb, " err_code = %d, err_reason = %s,\n", req->err_code, req->err_reason ? req->err_reason : "(null)"); - VSB_printf(pan_vsp, " restarts = %d, esi_level = %d,\n", + VSB_printf(vsb, "restarts = %d, esi_level = %d,\n", req->restarts, req->esi_level); if (req->sp != NULL) - pan_sess(req->sp); + pan_sess(vsb, req->sp); if (req->wrk != NULL) - pan_wrk(req->wrk); + pan_wrk(vsb, req->wrk); - pan_ws(req->ws, 2); - pan_http("req", req->http, 2); + pan_ws(vsb, req->ws); + pan_http(vsb, "req", req->http); if (req->resp->ws != NULL) - pan_http("resp", req->resp, 2); + pan_http(vsb, "resp", req->resp); - VCL_Panic(pan_vsp, req->vcl); + VCL_Panic(vsb, req->vcl); if (req->objcore != NULL) { - pan_objcore("REQ", req->objcore); + pan_objcore(vsb, "REQ", req->objcore); if (req->objcore->busyobj != NULL) - pan_busyobj(req->objcore->busyobj); + pan_busyobj(vsb, req->objcore->busyobj); } - VSB_printf(pan_vsp, " flags = {\n"); -#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(pan_vsp, " " #l ",\n"); + VSB_printf(vsb, "flags = {\n"); +#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(vsb, " " #l ",\n"); #include "tbl/req_flags.h" #undef REQ_FLAG - VSB_printf(pan_vsp, " }\n"); + VSB_printf(vsb, "}\n"); - VSB_printf(pan_vsp, "},\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ static void -pan_sess(const struct sess *sp) +pan_sess(struct vsb *vsb, const struct sess *sp) { const char *stp; char *ci; char *cp; - VSB_printf(pan_vsp, " sp = %p {\n", sp); - VSB_printf(pan_vsp, " fd = %d, vxid = %u,\n", - sp->fd, VXID(sp->vxid)); + VSB_printf(vsb, "sp = %p {\n", sp); + VSB_indent(vsb, 2); + VSB_printf(vsb, "fd = %d, vxid = %u,\n", sp->fd, VXID(sp->vxid)); AZ(SES_Get_client_ip(sp, &ci)); AZ(SES_Get_client_port(sp, &cp)); - VSB_printf(pan_vsp, " client = %s %s,\n", ci, cp); + VSB_printf(vsb, "client = %s %s,\n", ci, cp); switch (sp->sess_step) { #define SESS_STEP(l, u) case S_STP_##u: stp = "S_STP_" #u; break; #include "tbl/steps.h" @@ -429,17 +384,18 @@ pan_sess(const struct sess *sp) default: stp = NULL; } if (stp != NULL) - VSB_printf(pan_vsp, " step = %s,\n", stp); + VSB_printf(vsb, "step = %s,\n", stp); else - VSB_printf(pan_vsp, " step = 0x%x,\n", sp->sess_step); + VSB_printf(vsb, "step = 0x%x,\n", sp->sess_step); - VSB_printf(pan_vsp, " },\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ static void -pan_backtrace(void) +pan_backtrace(struct vsb *vsb) { void *array[10]; size_t size; @@ -450,24 +406,25 @@ pan_backtrace(void) size = backtrace (array, 10); if (size == 0) return; - VSB_printf(pan_vsp, "Backtrace:\n"); + VSB_printf(vsb, "Backtrace:\n"); + VSB_indent(vsb, 2); for (i = 0; i < size; i++) { - VSB_printf (pan_vsp, " "); - if (Symbol_Lookup(pan_vsp, array[i]) < 0) { + if (Symbol_Lookup(vsb, array[i]) < 0) { strings = backtrace_symbols(&array[i], 1); if (strings == NULL || strings[0] == NULL) { - VSB_printf(pan_vsp, "%p: (?)", array[i]); + VSB_printf(vsb, "%p: (?)", array[i]); } else { p = strrchr(strings[0], '/'); if (p == NULL) p = strings[0]; else p++; - VSB_printf(pan_vsp, "%p: %s", array[i], p); + VSB_printf(vsb, "%p: %s", array[i], p); } } - VSB_printf (pan_vsp, "\n"); + VSB_printf (vsb, "\n"); } + VSB_indent(vsb, -2); } /*--------------------------------------------------------------------*/ @@ -497,59 +454,59 @@ pan_ic(const char *func, const char *file, int line, const char *cond, switch(kind) { case VAS_WRONG: - VSB_printf(pan_vsp, + VSB_printf(pan_vsb, "Wrong turn at %s:%d:\n%s\n", file, line, cond); break; case VAS_VCL: - VSB_printf(pan_vsp, + VSB_printf(pan_vsb, "Panic from VCL:\n %s\n", cond); break; case VAS_MISSING: - VSB_printf(pan_vsp, + VSB_printf(pan_vsb, "Missing errorhandling code in %s(), %s line %d:\n" " Condition(%s) not true.", func, file, line, cond); break; case VAS_INCOMPLETE: - VSB_printf(pan_vsp, + VSB_printf(pan_vsb, "Incomplete code in %s(), %s line %d:\n", func, file, line); break; default: case VAS_ASSERT: - VSB_printf(pan_vsp, + VSB_printf(pan_vsb, "Assert error in %s(), %s line %d:\n" " Condition(%s) not true.\n", func, file, line, cond); break; } if (err) - VSB_printf(pan_vsp, "errno = %d (%s)\n", err, strerror(err)); + VSB_printf(pan_vsb, "errno = %d (%s)\n", err, strerror(err)); q = THR_GetName(); if (q != NULL) - VSB_printf(pan_vsp, "thread = (%s)\n", q); + VSB_printf(pan_vsb, "thread = (%s)\n", q); - VSB_printf(pan_vsp, "version = %s\n", VCS_version); - VSB_printf(pan_vsp, "ident = %s,%s\n", + VSB_printf(pan_vsb, "version = %s\n", VCS_version); + VSB_printf(pan_vsb, "ident = %s,%s\n", VSB_data(vident) + 1, Waiter_GetName()); - pan_backtrace(); + pan_backtrace(pan_vsb); if (!FEATURE(FEATURE_SHORT_PANIC)) { req = THR_GetRequest(); if (req != NULL) { - pan_req(req); + pan_req(pan_vsb, req); VSL_Flush(req->vsl, 0); } bo = THR_GetBusyobj(); if (bo != NULL) { - pan_busyobj(bo); + pan_busyobj(pan_vsb, bo); VSL_Flush(bo->vsl, 0); } } - VSB_printf(pan_vsp, "\n"); - VSB_bcat(pan_vsp, "", 1); /* NUL termination */ + VSB_printf(pan_vsb, "\n"); + VSB_bcat(pan_vsb, "", 1); /* NUL termination */ if (FEATURE(FEATURE_NO_COREDUMP)) exit(4); @@ -585,10 +542,10 @@ PAN_Init(void) { VAS_Fail = pan_ic; - pan_vsp = &pan_vsp_storage; + pan_vsb = &pan_vsb_storage; AN(heritage.panic_str); AN(heritage.panic_str_len); - AN(VSB_new(pan_vsp, heritage.panic_str, heritage.panic_str_len, + AN(VSB_new(pan_vsb, heritage.panic_str, heritage.panic_str_len, VSB_FIXEDLEN)); CLI_AddFuncs(debug_cmds); } diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index c10d949..dd49cda 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -86,12 +86,16 @@ VCL_Panic(struct vsb *vsb, const struct vcl *vcl) AN(vsb); if (vcl == NULL) return; - VSB_printf(vsb, " vcl = {\n"); - VSB_printf(vsb, " srcname = {\n"); + VSB_printf(vsb, "vcl = {\n"); + VSB_indent(vsb, 2); + VSB_printf(vsb, "srcname = {\n"); + VSB_indent(vsb, 2); for (i = 0; i < vcl->conf->nsrc; ++i) - VSB_printf(vsb, " \"%s\",\n", vcl->conf->srcname[i]); - VSB_printf(vsb, " },\n"); - VSB_printf(vsb, " },\n"); + VSB_printf(vsb, "\"%s\",\n", vcl->conf->srcname[i]); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ From martin at varnish-software.com Fri Jul 31 13:51:33 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 15:51:33 +0200 Subject: [master] 2223ff4 Fix prototype match Message-ID: commit 2223ff49c9be8110538839538592d88f709a49e0 Author: Martin Blix Grydeland Date: Thu Jul 30 15:31:10 2015 +0200 Fix prototype match diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index 4d86baa..3dddbac 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -249,7 +249,7 @@ priv_vcl_free(void *priv) AZ(priv_vcl); } -int __match_proto__(vmod_init_f) +int __match_proto__(vmod_event_f) event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e) { struct priv_vcl *priv_vcl; From martin at varnish-software.com Fri Jul 31 13:51:33 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 15:51:33 +0200 Subject: [master] 2b85c12 Fix buffer underflow in _vsb_indent Message-ID: commit 2b85c12f59265c51f1100e7ee0bed31d9ec0f8ab Author: Martin Blix Grydeland Date: Fri Jul 31 15:49:37 2015 +0200 Fix buffer underflow in _vsb_indent If s_indent > 0 and the buffer is empty, it would check s_buf[-1] for the '\n' character. Now it will indent either on previous character being a newline, or on empty buffer. This allows indenting also the very first line of a buffer. diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c index be147c2..eba639e 100644 --- a/lib/libvarnish/vsb.c +++ b/lib/libvarnish/vsb.c @@ -159,7 +159,7 @@ static void _vsb_indent(struct vsb *s) { if (s->s_indent == 0 || s->s_error != 0 || - s->s_buf[s->s_len - 1] != '\n') + (s->s_len > 0 && s->s_buf[s->s_len - 1] != '\n')) return; if (VSB_FREESPACE(s) <= s->s_indent && VSB_extend(s, s->s_indent) < 0) { From martin at varnish-software.com Fri Jul 31 14:49:53 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 16:49:53 +0200 Subject: [master] cc0a64f Call VCL_Panic also from pan_busyobj Message-ID: commit cc0a64fbb56a436c19088ae0fb33ea9c62b868e5 Author: Martin Blix Grydeland Date: Thu Jul 2 16:59:15 2015 +0200 Call VCL_Panic also from pan_busyobj diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 873c5e0..983bffa 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -295,6 +295,7 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) pan_objcore(vsb, "fetch", bo->fetch_objcore); if (bo->stale_oc) pan_objcore(vsb, "ims", bo->stale_oc); + VCL_Panic(vsb, bo->vcl); VSB_indent(vsb, -2); VSB_printf(vsb, "}\n"); } From martin at varnish-software.com Fri Jul 31 14:49:53 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 16:49:53 +0200 Subject: [master] f8d6400 Make pan_htc more useful Message-ID: commit f8d6400507805d84bd80dc2b59fedca9b8cde7d0 Author: Martin Blix Grydeland Date: Thu Jul 9 15:52:17 2015 +0200 Make pan_htc more useful diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 983bffa..7072209 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -145,6 +145,19 @@ pan_htc(struct vsb *vsb, const struct http_conn *htc) VSB_printf(vsb, "http_conn = %p {\n", htc); VSB_indent(vsb, 2); VSB_printf(vsb, "fd = %d,\n", htc->fd); + VSB_printf(vsb, "doclose = %s,\n", sess_close_2str(htc->doclose, 0)); + VSB_printf(vsb, "ws = %p,\n", htc->ws); + VSB_printf(vsb, "{rxbuf_b, rxbuf_e} = {%p, %p},\n", + htc->rxbuf_b, htc->rxbuf_e); + VSB_printf(vsb, "{pipeline_b, pipeline_e} = {%p, %p},\n", + htc->pipeline_b, htc->pipeline_e); + VSB_printf(vsb, "content_length = %jd,\n", htc->content_length); + VSB_printf(vsb, "body_status = %s,\n", + body_status_2str(htc->body_status)); + VSB_printf(vsb, "first_byte_timeout = %f,\n", + htc->first_byte_timeout); + VSB_printf(vsb, "between_bytes_timeout = %f,\n", + htc->between_bytes_timeout); VSB_indent(vsb, -2); VSB_printf(vsb, "},\n"); } @@ -267,11 +280,9 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) #undef BO_FLAG VSB_printf(vsb, "}\n"); - if (bo->htc != NULL) { - VSB_printf(vsb, "bodystatus = %d (%s),\n", - bo->htc->body_status, - body_status_2str(bo->htc->body_status)); - } + if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC)) + pan_htc(vsb, bo->htc); + if (!VTAILQ_EMPTY(&bo->vfc->vfp)) { VSB_printf(vsb, "filters ="); VTAILQ_FOREACH(vfe, &bo->vfc->vfp, list) @@ -280,8 +291,6 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) VSB_printf(vsb, "\n"); } - if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC)) - pan_htc(vsb, bo->htc); VDI_Panic(bo->director_req, vsb, "director_req"); if (bo->director_resp == bo->director_req) VSB_printf(vsb, "director_resp = director_req\n"); From martin at varnish-software.com Fri Jul 31 14:49:53 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 16:49:53 +0200 Subject: [master] 06ebc9e Call pan_htc also from pan_req Message-ID: commit 06ebc9ede143ebcd407c11a7b775fcbde3f9e44b Author: Martin Blix Grydeland Date: Fri Jul 31 16:39:12 2015 +0200 Call pan_htc also from pan_req This dumps some useful bits about the state of the client connection. diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 7072209..c30c64d 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -350,6 +350,8 @@ pan_req(struct vsb *vsb, const struct req *req) pan_wrk(vsb, req->wrk); pan_ws(vsb, req->ws); + if (VALID_OBJ(req->htc, HTTP_CONN_MAGIC)) + pan_htc(vsb, req->htc); pan_http(vsb, "req", req->http); if (req->resp->ws != NULL) pan_http(vsb, "resp", req->resp); From martin at varnish-software.com Fri Jul 31 14:49:53 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 16:49:53 +0200 Subject: [master] a40f2fd Fix indentation Message-ID: commit a40f2fdb91d65e50e29bfcac9ea4f98c0b276710 Author: Martin Blix Grydeland Date: Fri Jul 31 16:41:21 2015 +0200 Fix indentation diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index c30c64d..e7250be 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -337,7 +337,7 @@ pan_req(struct vsb *vsb, const struct req *req) if (req->err_code) VSB_printf(vsb, - " err_code = %d, err_reason = %s,\n", req->err_code, + "err_code = %d, err_reason = %s,\n", req->err_code, req->err_reason ? req->err_reason : "(null)"); VSB_printf(vsb, "restarts = %d, esi_level = %d,\n", From martin at varnish-software.com Fri Jul 31 15:55:52 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 17:55:52 +0200 Subject: [master] 94468b4 Fix indentation Message-ID: commit 94468b4600c37e0eac8dc87e9d979a6b129f9f36 Author: Martin Blix Grydeland Date: Thu Jul 2 16:15:50 2015 +0200 Fix indentation diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index e7250be..c848d9b 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -116,7 +116,7 @@ pan_ws(struct vsb *vsb, const struct ws *ws) VSB_printf(vsb, "ws = %p {\n", ws); VSB_indent(vsb, 2); if (WS_Overflowed(ws)) - VSB_printf(vsb, " OVERFLOW"); + VSB_printf(vsb, "OVERFLOW "); VSB_printf(vsb, "id = \"%s\",\n", ws->id); VSB_printf(vsb, "{s,f,r,e} = {%p", ws->s); if (ws->f > ws->s) @@ -365,10 +365,12 @@ pan_req(struct vsb *vsb, const struct req *req) } VSB_printf(vsb, "flags = {\n"); -#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(vsb, " " #l ",\n"); + VSB_indent(vsb, 2); +#define REQ_FLAG(l, r, w, d) if(req->l) VSB_printf(vsb, #l ",\n"); #include "tbl/req_flags.h" #undef REQ_FLAG - VSB_printf(vsb, "}\n"); + VSB_indent(vsb, -2); + VSB_printf(vsb, "},\n"); VSB_indent(vsb, -2); VSB_printf(vsb, "},\n"); From martin at varnish-software.com Fri Jul 31 15:55:52 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 31 Jul 2015 17:55:52 +0200 Subject: [master] 38f0cd8 O comma CD Message-ID: commit 38f0cd8251f540ac963f91c319519260b5efa473 Author: Martin Blix Grydeland Date: Thu Jul 2 16:21:59 2015 +0200 O comma CD Add commas to panic line endinges consistently diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 092abb3..0718757 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -319,17 +319,17 @@ vbe_panic(const struct director *d, struct vsb *vsb) CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); - VSB_printf(vsb, "display_name = %s\n", bp->display_name); + VSB_printf(vsb, "display_name = %s,\n", bp->display_name); if (bp->ipv4_addr != NULL) - VSB_printf(vsb, "ipv4 = %s\n", bp->ipv4_addr); + VSB_printf(vsb, "ipv4 = %s,\n", bp->ipv4_addr); if (bp->ipv6_addr != NULL) - VSB_printf(vsb, "ipv6 = %s\n", bp->ipv6_addr); - VSB_printf(vsb, "port = %s\n", bp->port); - VSB_printf(vsb, "hosthdr = %s\n", bp->hosthdr); + VSB_printf(vsb, "ipv6 = %s,\n", bp->ipv6_addr); + VSB_printf(vsb, "port = %s,\n", bp->port); + VSB_printf(vsb, "hosthdr = %s,\n", bp->hosthdr); VSB_printf(vsb, "health=%s, admin_health=%s", bp->healthy ? "healthy" : "sick", bp->admin_health); - VSB_printf(vsb, ", changed=%.1f\n", bp->health_changed); - VSB_printf(vsb, "n_conn = %u\n", bp->n_conn); + VSB_printf(vsb, ", changed=%.1f,\n", bp->health_changed); + VSB_printf(vsb, "n_conn = %u,\n", bp->n_conn); } /*--------------------------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c index b6d0944..9dac151 100644 --- a/bin/varnishd/cache/cache_director.c +++ b/bin/varnishd/cache/cache_director.c @@ -189,13 +189,13 @@ VDI_Panic(const struct director *d, struct vsb *vsb, const char *nm) return; VSB_printf(vsb, "%s = %p {\n", nm, d); VSB_indent(vsb, 2); - VSB_printf(vsb, "vcl_name = %s\n", d->vcl_name); + VSB_printf(vsb, "vcl_name = %s,\n", d->vcl_name); VSB_printf(vsb, "type = %s {\n", d->name); VSB_indent(vsb, 2); if (d->panic != NULL) d->panic(d, vsb); VSB_indent(vsb, -2); - VSB_printf(vsb, "}\n"); + VSB_printf(vsb, "},\n"); VSB_indent(vsb, -2); - VSB_printf(vsb, "}\n"); + VSB_printf(vsb, "},\n"); } diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index c848d9b..5a8a59a 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -171,7 +171,7 @@ pan_http(struct vsb *vsb, const char *id, const struct http *h) VSB_printf(vsb, "http[%s] = %p {\n", id, h); VSB_indent(vsb, 2); - VSB_printf(vsb, "ws[%s] = %p\n", h->ws ? h->ws->id : "", h->ws); + VSB_printf(vsb, "ws[%s] = %p,\n", h->ws ? h->ws->id : "", h->ws); VSB_printf(vsb, "hdrs {\n"); VSB_indent(vsb, 2); for (i = 0; i < h->nhd; ++i) { @@ -194,9 +194,9 @@ pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc) VSB_printf(vsb, "objcore[%s] = %p {\n", typ, oc); VSB_indent(vsb, 2); - VSB_printf(vsb, "refcnt = %d\n", oc->refcnt); - VSB_printf(vsb, "flags = 0x%x\n", oc->flags); - VSB_printf(vsb, "objhead = %p\n", oc->objhead); + VSB_printf(vsb, "refcnt = %d,\n", oc->refcnt); + VSB_printf(vsb, "flags = 0x%x,\n", oc->flags); + VSB_printf(vsb, "objhead = %p,\n", oc->objhead); VSB_printf(vsb, "stevedore = %p", oc->stobj->stevedore); if (oc->stobj->stevedore != NULL) { VSB_printf(vsb, " (%s", oc->stobj->stevedore->name); @@ -204,9 +204,9 @@ pan_objcore(struct vsb *vsb, const char *typ, const struct objcore *oc) VSB_printf(vsb, " %s", oc->stobj->stevedore->ident); VSB_printf(vsb, ")"); } - VSB_printf(vsb, "\n"); + VSB_printf(vsb, ",\n"); VSB_indent(vsb, -2); - VSB_printf(vsb, "}\n"); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/ @@ -220,7 +220,7 @@ pan_wrk(struct vsb *vsb, const struct worker *wrk) VSB_printf(vsb, "worker = %p {\n", wrk); VSB_indent(vsb, 2); - VSB_printf(vsb, "stack = {0x%jx -> 0x%jx}\n", + VSB_printf(vsb, "stack = {0x%jx -> 0x%jx},\n", (uintmax_t)wrk->stack_start, (uintmax_t)wrk->stack_end); pan_ws(vsb, wrk->aws); @@ -268,17 +268,17 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) VSB_printf(vsb, "busyobj = %p {\n", bo); VSB_indent(vsb, 2); pan_ws(vsb, bo->ws); - VSB_printf(vsb, "refcnt = %u\n", bo->refcount); + VSB_printf(vsb, "refcnt = %u,\n", bo->refcount); VSB_printf(vsb, "retries = %d, ", bo->retries); VSB_printf(vsb, "failed = %d, ", bo->vfc->failed); - VSB_printf(vsb, "state = %d\n", (int)bo->state); + VSB_printf(vsb, "state = %d,\n", (int)bo->state); VSB_printf(vsb, "flags = {"); p = ""; #define BO_FLAG(l, r, w, d) \ if(bo->l) { VSB_printf(vsb, "%s" #l, p); p = ", "; } #include "tbl/bo_flags.h" #undef BO_FLAG - VSB_printf(vsb, "}\n"); + VSB_printf(vsb, "},\n"); if (VALID_OBJ(bo->htc, HTTP_CONN_MAGIC)) pan_htc(vsb, bo->htc); @@ -293,7 +293,7 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) VDI_Panic(bo->director_req, vsb, "director_req"); if (bo->director_resp == bo->director_req) - VSB_printf(vsb, "director_resp = director_req\n"); + VSB_printf(vsb, "director_resp = director_req,\n"); else VDI_Panic(bo->director_resp, vsb, "director_resp"); if (bo->bereq != NULL && bo->bereq->ws != NULL) @@ -306,7 +306,7 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo) pan_objcore(vsb, "ims", bo->stale_oc); VCL_Panic(vsb, bo->vcl); VSB_indent(vsb, -2); - VSB_printf(vsb, "}\n"); + VSB_printf(vsb, "},\n"); } /*--------------------------------------------------------------------*/