From phk at FreeBSD.org Thu Aug 1 07:40:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 1 Aug 2019 07:40:10 +0000 (UTC) Subject: [master] 3c22a6162 Prefix VSM lines which add segments with a '+' Message-ID: <20190801074010.6D9C7A7A82@lists.varnish-cache.org> commit 3c22a61625b5eda186aa8c90178c086e8b003f55 Author: Poul-Henning Kamp Date: Wed Jul 31 19:55:42 2019 +0000 Prefix VSM lines which add segments with a '+' diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index 498045d4e..8e22756f0 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -132,7 +132,7 @@ vsmw_fmt_index(const struct vsmw *vsmw, const struct vsmwseg *seg) CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC); - VSB_printf(vsmw->vsb, "%s %zu %zu %s %s\n", + VSB_printf(vsmw->vsb, "+ %s %zu %zu %s %s\n", seg->cluster->fn, seg->off, seg->len, diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 364ad3aee..51f9ccdf1 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -459,7 +459,7 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) int ac; struct vsm_seg *vg2; - av = VAV_Parse(line, &ac, 0); + av = VAV_Parse(line + 1, &ac, 0); if (av[0] != NULL || ac < 4 || ac > 6) { (void)(vsm_diag(vd, @@ -508,14 +508,19 @@ vsm_vlu_func(void *priv, const char *line) CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AN(line); - if (line[0] == '#') { + switch (line[0]) { + case '#': i = vsm_vlu_hash(vd, vs, line); VTAILQ_FOREACH(vs->vg, &vs->segs, list) vs->vg->flags &= ~VSM_FLAG_MARKSCAN; if (!(vs->retval & VSM_MGT_RESTARTED)) vs->vg = VTAILQ_FIRST(&vs->segs); - } else { + break; + case '+': i = vsm_vlu_plus(vd, vs, line); + break; + default: + break; } return (i); } From phk at FreeBSD.org Thu Aug 1 07:40:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 1 Aug 2019 07:40:10 +0000 (UTC) Subject: [master] 5f97b89a1 Avoid lock/unlock/lock/unlock for cluster delete Message-ID: <20190801074010.835DFA7A85@lists.varnish-cache.org> commit 5f97b89a136a76932c41bf42d91a823a4a4e2e02 Author: Poul-Henning Kamp Date: Thu Aug 1 07:33:40 2019 +0000 Avoid lock/unlock/lock/unlock for cluster delete diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index 8e22756f0..6d8a17e4a 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -281,7 +281,6 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) { struct vsmw_cluster *vc; - vsmw_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); TAKE_OBJ_NOTNULL(vc, vsmcp, VSMW_CLUSTER_MAGIC); @@ -294,10 +293,8 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) */ vsmw_delseg(vsmw, vc->cseg, 1); vc->cseg = NULL; - if (vc->refs > 0) { - vsmw_unlock(); + if (vc->refs > 0) return; - } } AZ(munmap(vc->ptr, vc->len)); @@ -307,7 +304,6 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) assert (errno == ENOENT); REPLACE(vc->fn, NULL); FREE_OBJ(vc); - vsmw_unlock(); } /*--------------------------------------------------------------------*/ @@ -369,26 +365,24 @@ void VSMW_Free(struct vsmw *vsmw, void **pp) { struct vsmwseg *seg; - void *p; + struct vsmw_cluster *cp; vsmw_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); AN(pp); - p = *pp; - AN(p); - *pp = NULL; VTAILQ_FOREACH(seg, &vsmw->segs, list) - if (seg->ptr == p) + if (seg->ptr == *pp) break; AN(seg); + *pp = NULL; - if (!--seg->cluster->refs && seg->cluster->cseg == NULL) { - vsmw_unlock(); - VSMW_DestroyCluster(vsmw, &seg->cluster); - vsmw_lock(); - } + cp = seg->cluster; vsmw_delseg(vsmw, seg, 1); + + if (!--cp->refs && cp->cseg == NULL) + VSMW_DestroyCluster(vsmw, &cp); + vsmw_unlock(); } From phk at FreeBSD.org Thu Aug 1 08:02:09 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 1 Aug 2019 08:02:09 +0000 (UTC) Subject: [master] a0e4bab90 Introduce '-' records in VSM _.index files, to reduce VFS workload. Message-ID: <20190801080209.C6840A83B6@lists.varnish-cache.org> commit a0e4bab90da04b2ffcf8a5416d5bf8886daab0a9 Author: Poul-Henning Kamp Date: Thu Aug 1 08:00:56 2019 +0000 Introduce '-' records in VSM _.index files, to reduce VFS workload. diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index 6d8a17e4a..4a01064e9 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -112,6 +112,8 @@ struct vsmw { struct vsb *vsb; pid_t pid; time_t birth; + uint64_t nsegs; + uint64_t nsubs; }; /*--------------------------------------------------------------------*/ @@ -127,12 +129,14 @@ vsmw_idx_head(const struct vsmw *vsmw, int fd) } static void -vsmw_fmt_index(const struct vsmw *vsmw, const struct vsmwseg *seg) +vsmw_fmt_index(const struct vsmw *vsmw, const struct vsmwseg *seg, char act) { CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC); - VSB_printf(vsmw->vsb, "+ %s %zu %zu %s %s\n", + AN(seg->cluster); + VSB_printf(vsmw->vsb, "%c %s %zu %zu %s %s\n", + act, seg->cluster->fn, seg->off, seg->len, @@ -166,18 +170,31 @@ vsmw_mkent(const struct vsmw *vsmw, const char *pfx) /*--------------------------------------------------------------------*/ static void -vsmw_addseg(struct vsmw *vsmw, struct vsmwseg *seg) +vsmw_append_record(struct vsmw *vsmw, struct vsmwseg *seg, char act) { int fd; - VTAILQ_INSERT_TAIL(&vsmw->segs, seg, list); + CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); + CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC); fd = openat(vsmw->vdirfd, vsmw->idx, O_APPEND | O_WRONLY); assert(fd >= 0); VSB_clear(vsmw->vsb); - vsmw_fmt_index(vsmw, seg); + vsmw_fmt_index(vsmw, seg, act); AZ(VSB_finish(vsmw->vsb)); XXXAZ(VSB_tofile(fd, vsmw->vsb)); // XXX handle ENOSPC? #2764 closefd(&fd); + vsmw->nsegs++; +} + +/*--------------------------------------------------------------------*/ + +static void +vsmw_addseg(struct vsmw *vsmw, struct vsmwseg *seg) +{ + + VTAILQ_INSERT_TAIL(&vsmw->segs, seg, list); + vsmw_append_record(vsmw, seg, '+'); + vsmw->nsegs++; } /*--------------------------------------------------------------------*/ @@ -187,16 +204,19 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) { char *t = NULL; int fd; + struct vsmwseg *s2; CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC); VTAILQ_REMOVE(&vsmw->segs, seg, list); - REPLACE(seg->class, NULL); - REPLACE(seg->id, NULL); - FREE_OBJ(seg); - if (fixidx) { + vsmw->nsegs--; + if (vsmw->nsubs < vsmw->nsegs || !fixidx) { + vsmw_append_record(vsmw, seg, '-'); + vsmw->nsubs++; + } else { + vsmw->nsubs = 0; vsmw_mkent(vsmw, vsmw->idx); REPLACE(t, VSB_data(vsmw->vsb)); AN(t); @@ -205,14 +225,17 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) assert(fd >= 0); vsmw_idx_head(vsmw, fd); VSB_clear(vsmw->vsb); - VTAILQ_FOREACH(seg, &vsmw->segs, list) - vsmw_fmt_index(vsmw, seg); + VTAILQ_FOREACH(s2, &vsmw->segs, list) + vsmw_fmt_index(vsmw, s2, '+'); AZ(VSB_finish(vsmw->vsb)); XXXAZ(VSB_tofile(fd, vsmw->vsb)); // XXX handle ENOSPC? #2764 closefd(&fd); AZ(renameat(vsmw->vdirfd, t, vsmw->vdirfd, vsmw->idx)); REPLACE(t, NULL); } + REPLACE(seg->class, NULL); + REPLACE(seg->id, NULL); + FREE_OBJ(seg); } /*--------------------------------------------------------------------*/ diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 51f9ccdf1..55d5186a6 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -463,7 +463,7 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) if (av[0] != NULL || ac < 4 || ac > 6) { (void)(vsm_diag(vd, - "vsm_refresh_set2: bad index (%d/%s)", + "vsm_vlu_plus: bad index (%d/%s)", ac, av[0])); VAV_Free(av); return(-1); @@ -496,6 +496,39 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) return (0); } +static int +vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) +{ + char **av; + int ac; + struct vsm_seg *vg, *vg2; + + av = VAV_Parse(line + 1, &ac, 0); + + if (av[0] != NULL || ac < 4 || ac > 6) { + (void)(vsm_diag(vd, + "vsm_vlu_minus: bad index (%d/%s)", + ac, av[0])); + VAV_Free(av); + return(-1); + } + + VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { + if (vsm_cmp_av(&vg->av[1], &av[1])) + continue; + VTAILQ_REMOVE(&vs->segs, vg, list); + if (vg->refs) { + vg->flags |= VSM_FLAG_STALE; + VTAILQ_INSERT_TAIL(&vs->stale, vg, list); + } else { + VAV_Free(vg->av); + FREE_OBJ(vg); + } + break; + } + return (0); +} + static int v_matchproto_(vlu_f) vsm_vlu_func(void *priv, const char *line) { @@ -519,6 +552,9 @@ vsm_vlu_func(void *priv, const char *line) case '+': i = vsm_vlu_plus(vd, vs, line); break; + case '-': + i = vsm_vlu_minus(vd, vs, line); + break; default: break; } From fgsch at lodoss.net Fri Aug 2 11:31:09 2019 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 2 Aug 2019 11:31:09 +0000 (UTC) Subject: [master] 87b335bcd Plug minor leak Message-ID: <20190802113110.010A9A2ECC@lists.varnish-cache.org> commit 87b335bcdddf006ec703e0f167605c40df059589 Author: Federico G. Schwindt Date: Fri Aug 2 12:24:20 2019 +0100 Plug minor leak diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 55d5186a6..c220a31ee 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -526,6 +526,7 @@ vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) } break; } + VAV_Free(av); return (0); } From fgsch at lodoss.net Fri Aug 2 11:31:10 2019 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Fri, 2 Aug 2019 11:31:10 +0000 (UTC) Subject: [master] 63bb0b489 Dump non-printable chars as hex instead of octal Message-ID: <20190802113110.1509FA2ED0@lists.varnish-cache.org> commit 63bb0b489754ef3a228a2d84b0e648e157580f4e Author: Federico G. Schwindt Date: Fri Aug 2 12:25:19 2019 +0100 Dump non-printable chars as hex instead of octal diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c index 76935d6a8..1bdd5699c 100644 --- a/bin/varnishtest/vtc_log.c +++ b/bin/varnishtest/vtc_log.c @@ -227,7 +227,8 @@ vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len) if (len < 0) len = strlen(str); VSB_quote_pfx(vl->vsb, buf, str, - len > MAX_DUMP ? MAX_DUMP : len, VSB_QUOTE_UNSAFE); + len > MAX_DUMP ? MAX_DUMP : len, + VSB_QUOTE_UNSAFE | VSB_QUOTE_ESCHEX); if (len > MAX_DUMP) VSB_printf(vl->vsb, "%s [...] (%d)\n", buf, len - MAX_DUMP); From phk at FreeBSD.org Mon Aug 5 08:38:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 08:38:11 +0000 (UTC) Subject: [master] 93e6dd706 Constify Message-ID: <20190805083811.3563BA7305@lists.varnish-cache.org> commit 93e6dd706074d5f5815bd03e76d63fa30f6666c9 Author: Poul-Henning Kamp Date: Mon Aug 5 05:43:37 2019 +0000 Constify diff --git a/bin/varnishd/http2/cache_http2.h b/bin/varnishd/http2/cache_http2.h index a7a1001f5..430ab060c 100644 --- a/bin/varnishd/http2/cache_http2.h +++ b/bin/varnishd/http2/cache_http2.h @@ -223,8 +223,8 @@ void H2_Send_Frame(struct worker *, struct h2_sess *, h2_frame type, uint8_t flags, uint32_t len, uint32_t stream, const void *); -void H2_Send_RST(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2, - uint32_t stream, h2_error h2e); +void H2_Send_RST(struct worker *wrk, struct h2_sess *h2, + const struct h2_req *r2, uint32_t stream, h2_error h2e); void H2_Send(struct worker *, struct h2_req *, h2_frame type, uint8_t flags, uint32_t len, const void *, uint64_t *acct); diff --git a/bin/varnishd/http2/cache_http2_send.c b/bin/varnishd/http2/cache_http2_send.c index 87b3ceb00..37f052d26 100644 --- a/bin/varnishd/http2/cache_http2_send.c +++ b/bin/varnishd/http2/cache_http2_send.c @@ -392,7 +392,7 @@ h2_send(struct worker *wrk, struct h2_req *r2, h2_frame ftyp, uint8_t flags, } void -H2_Send_RST(struct worker *wrk, struct h2_sess *h2, struct h2_req *r2, +H2_Send_RST(struct worker *wrk, struct h2_sess *h2, const struct h2_req *r2, uint32_t stream, h2_error h2e) { char b[4]; From phk at FreeBSD.org Mon Aug 5 08:38:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 08:38:11 +0000 (UTC) Subject: [master] 6f2fee0a5 Fix locking mistake introduced in 5f97b89 Message-ID: <20190805083811.49B95A7308@lists.varnish-cache.org> commit 6f2fee0a5b257586773ea790bd8f07a1a1c6258f Author: Poul-Henning Kamp Date: Mon Aug 5 08:27:34 2019 +0000 Fix locking mistake introduced in 5f97b89 diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index 4a01064e9..a747cf970 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -70,9 +70,29 @@ vsmw_dummy_lock(void) { } +static int vsmw_haslock; vsm_lock_f *vsmw_lock = vsmw_dummy_lock; vsm_lock_f *vsmw_unlock = vsmw_dummy_lock; +#define vsmw_assert_lock() AN(vsmw_haslock) + +#define vsmw_do_lock() vsmw_do_lock_(__func__, __LINE__) + +#define vsmw_do_lock_(f, l) \ + do { \ + vsmw_lock(); \ + AZ(vsmw_haslock); \ + vsmw_haslock = 1; \ + } while(0) + +#define vsmw_do_unlock() vsmw_do_unlock_(__func__, __LINE__) +#define vsmw_do_unlock_(f, l) \ + do { \ + AN(vsmw_haslock); \ + vsmw_haslock = 0; \ + vsmw_unlock(); \ + } while(0) + /*--------------------------------------------------------------------*/ struct vsmw_cluster { @@ -153,6 +173,7 @@ vsmw_mkent(const struct vsmw *vsmw, const char *pfx) uint64_t rn; AN(pfx); + vsmw_assert_lock(); while (1) { VSB_clear(vsmw->vsb); VSB_printf(vsmw->vsb, "_.%s", pfx); @@ -192,6 +213,7 @@ static void vsmw_addseg(struct vsmw *vsmw, struct vsmwseg *seg) { + vsmw_assert_lock(); VTAILQ_INSERT_TAIL(&vsmw->segs, seg, list); vsmw_append_record(vsmw, seg, '+'); vsmw->nsegs++; @@ -206,6 +228,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) int fd; struct vsmwseg *s2; + vsmw_assert_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC); @@ -283,7 +306,7 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx) struct vsmw_cluster *vc; struct vsmwseg *seg; - vsmw_lock(); + vsmw_do_lock(); vc = vsmw_newcluster(vsmw, len, pfx); ALLOC_OBJ(seg, VSMWSEG_MAGIC); @@ -295,12 +318,12 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx) REPLACE(seg->id, ""); vsmw_addseg(vsmw, seg); - vsmw_unlock(); + vsmw_do_unlock(); return (vc); } -void -VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) +static void +vsmw_DestroyCluster_locked(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) { struct vsmw_cluster *vc; @@ -329,6 +352,15 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) FREE_OBJ(vc); } +void +VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) +{ + + vsmw_do_lock(); + vsmw_DestroyCluster_locked(vsmw, vsmcp); + vsmw_do_unlock(); +} + /*--------------------------------------------------------------------*/ void * @@ -338,7 +370,7 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc, { struct vsmwseg *seg; - vsmw_lock(); + vsmw_do_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); (void)vc; @@ -365,7 +397,7 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc, vsmw_addseg(vsmw, seg); - vsmw_unlock(); + vsmw_do_unlock(); return (seg->ptr); } @@ -390,7 +422,7 @@ VSMW_Free(struct vsmw *vsmw, void **pp) struct vsmwseg *seg; struct vsmw_cluster *cp; - vsmw_lock(); + vsmw_do_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); AN(pp); VTAILQ_FOREACH(seg, &vsmw->segs, list) @@ -404,9 +436,8 @@ VSMW_Free(struct vsmw *vsmw, void **pp) vsmw_delseg(vsmw, seg, 1); if (!--cp->refs && cp->cseg == NULL) - VSMW_DestroyCluster(vsmw, &cp); - - vsmw_unlock(); + vsmw_DestroyCluster_locked(vsmw, &cp); + vsmw_do_unlock(); } /*--------------------------------------------------------------------*/ @@ -421,7 +452,7 @@ VSMW_New(int vdirfd, int mode, const char *idxname) assert(mode > 0); AN(idxname); - vsmw_lock(); + vsmw_do_lock(); ALLOC_OBJ(vsmw, VSMW_MAGIC); AN(vsmw); @@ -443,7 +474,7 @@ VSMW_New(int vdirfd, int mode, const char *idxname) vsmw_idx_head(vsmw, fd); closefd(&fd); - vsmw_unlock(); + vsmw_do_unlock(); return (vsmw); } @@ -453,7 +484,7 @@ VSMW_Destroy(struct vsmw **pp) struct vsmw *vsmw; struct vsmwseg *seg, *s2; - vsmw_lock(); + vsmw_do_lock(); TAKE_OBJ_NOTNULL(vsmw, pp, VSMW_MAGIC); VTAILQ_FOREACH_SAFE(seg, &vsmw->segs, list, s2) vsmw_delseg(vsmw, seg, 0); @@ -463,5 +494,5 @@ VSMW_Destroy(struct vsmw **pp) VSB_destroy(&vsmw->vsb); closefd(&vsmw->vdirfd); FREE_OBJ(vsmw); - vsmw_unlock(); + vsmw_do_unlock(); } From phk at FreeBSD.org Mon Aug 5 08:38:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 08:38:11 +0000 (UTC) Subject: [master] 8a58838a3 Add vct_is{upper|lower}() Message-ID: <20190805083811.64F92A730B@lists.varnish-cache.org> commit 8a58838a3575407e6140b16bb0a49870988e8444 Author: Poul-Henning Kamp Date: Mon Aug 5 08:29:43 2019 +0000 Add vct_is{upper|lower}() diff --git a/include/vct.h b/include/vct.h index 44021f72d..e9cf9be86 100644 --- a/include/vct.h +++ b/include/vct.h @@ -45,6 +45,8 @@ #define VCT_IDENT (VCT_ALPHA | VCT_DIGIT | VCT_ID) #define VCT_VT (1<<12) #define VCT_SPACE (VCT_LWS | VCT_VT) +#define VCT_UPPER (1<<13) +#define VCT_LOWER (1<<14) extern const uint16_t vct_typtab[256]; @@ -65,6 +67,8 @@ vct_is(int x, uint16_t y) #define vct_isspace(x) vct_is(x, VCT_SPACE) #define vct_isdigit(x) vct_is(x, VCT_DIGIT) #define vct_isalpha(x) vct_is(x, VCT_ALPHA) +#define vct_islower(x) vct_is(x, VCT_LOWER) +#define vct_isupper(x) vct_is(x, VCT_UPPER) #define vct_isalnum(x) vct_is(x, VCT_ALPHA | VCT_DIGIT) #define vct_issep(x) vct_is(x, VCT_SEPARATOR) #define vct_issepctl(x) vct_is(x, VCT_SEPARATOR | VCT_CTL) diff --git a/lib/libvarnish/vct.c b/lib/libvarnish/vct.c index a86e2e427..2bb540687 100644 --- a/lib/libvarnish/vct.c +++ b/lib/libvarnish/vct.c @@ -41,8 +41,8 @@ /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */ -#define VCT_UPALPHA VCT_ALPHA -#define VCT_LOALPHA VCT_ALPHA +#define VCT_UPALPHA (VCT_ALPHA | VCT_UPPER) +#define VCT_LOALPHA (VCT_ALPHA | VCT_LOWER) const uint16_t vct_typtab[256] = { [0x00] = VCT_CTL, From phk at FreeBSD.org Mon Aug 5 08:38:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 08:38:11 +0000 (UTC) Subject: [master] 1e4b687b0 Whitespace OCD Message-ID: <20190805083811.7DB44A7311@lists.varnish-cache.org> commit 1e4b687b0aa0a3c587ecdae124c03e01e2a6653f Author: Poul-Henning Kamp Date: Mon Aug 5 08:30:17 2019 +0000 Whitespace OCD diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index a747cf970..c37b0d22e 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -78,7 +78,7 @@ vsm_lock_f *vsmw_unlock = vsmw_dummy_lock; #define vsmw_do_lock() vsmw_do_lock_(__func__, __LINE__) -#define vsmw_do_lock_(f, l) \ +#define vsmw_do_lock_(f, l) \ do { \ vsmw_lock(); \ AZ(vsmw_haslock); \ @@ -86,7 +86,7 @@ vsm_lock_f *vsmw_unlock = vsmw_dummy_lock; } while(0) #define vsmw_do_unlock() vsmw_do_unlock_(__func__, __LINE__) -#define vsmw_do_unlock_(f, l) \ +#define vsmw_do_unlock_(f, l) \ do { \ AN(vsmw_haslock); \ vsmw_haslock = 0; \ From phk at FreeBSD.org Mon Aug 5 08:38:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 08:38:11 +0000 (UTC) Subject: [master] 99d13d215 Add STRING.upper and STRING.lower Message-ID: <20190805083811.982D5A7315@lists.varnish-cache.org> commit 99d13d2152f8b7e35b61e61850096fe8d7e3f725 Author: Poul-Henning Kamp Date: Mon Aug 5 08:30:30 2019 +0000 Add STRING.upper and STRING.lower Relevant for #3023 diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index 5e68b07d8..d943fe205 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -36,6 +36,7 @@ #include "cache_objhead.h" #include "vav.h" #include "vcl.h" +#include "vct.h" #include "vrt_obj.h" #include "vsa.h" #include "vtcp.h" @@ -183,6 +184,7 @@ VPI_BundleStrands(int n, struct strands *s, char const **d, const char *f, ...) { va_list ap; + assert(n > 0); s->n = n; s->p = d; *d++ = f; @@ -480,6 +482,57 @@ VRT_CollectStrands(VRT_CTX, VCL_STRANDS s) return (b); } +/*-------------------------------------------------------------------- + * upper/lower-case STRANDS (onto workspace) + */ + +#include + +VCL_STRING +VRT_UpperLowerStrands(VRT_CTX, VCL_STRANDS s, int up) +{ + unsigned u; + char *b, *e, *r; + const char *p, *q = NULL; + int i, copy = 0; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC); + AN(s); + u = WS_ReserveAll(ctx->ws); + r = b = WS_Front(ctx->ws); + e = b + u; + for (i = 0; i < s->n; i++) { + if (s->p[i] == NULL || s->p[i][0] == '\0') + continue; + if (q != NULL) + copy = 1; + p = q = s->p[i]; + for(p = q = s->p[i]; *p != '\0'; p++) { + if ((up && vct_islower(*p)) || + (!up && vct_isupper(*p))) { + *b++ = *p ^ 0x20; + copy = 1; + } else { + *b++ = *p; + } + if (b == e) { + WS_Release(ctx->ws, 0); + VRT_fail(ctx, "Workspace overflow"); + return (NULL); + } + } + } + if (!copy) { + WS_Release(ctx->ws, 0); + return (q); + } + *b++ = '\0'; + assert(b <= e); + WS_ReleaseP(ctx->ws, b); + return (r); +} + /*--------------------------------------------------------------------*/ VCL_VOID diff --git a/bin/varnishtest/tests/v00058.vtc b/bin/varnishtest/tests/v00058.vtc index cef91e8b7..c7f39e628 100644 --- a/bin/varnishtest/tests/v00058.vtc +++ b/bin/varnishtest/tests/v00058.vtc @@ -174,3 +174,36 @@ client c1 { varnish v1 -expect client_resp_500 == 1 varnish v1 -expect ws_client_overflow == 2 + +# Test $STRINGS.{upper|lower} + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_deliver { + set resp.http.l-proto = resp.proto.lower; + set resp.http.u-proto = resp.proto.upper; + set resp.http.l-req = req.url.lower; + set resp.http.u-req = req.url.upper; + set resp.http.l-mod = (req.url + "bar").lower; + set resp.http.u-mod = (req.url + "bar").upper; + set resp.http.uu-mod = (req.url + "bar").upper.upper; + set resp.http.ul-mod = (req.url + "bar").upper.lower; + } +} + +client c1 { + txreq -url /foo + rxresp + expect resp.http.l-proto == "http/1.1" + expect resp.http.u-proto == "HTTP/1.1" + expect resp.http.l-req == "/foo" + expect resp.http.u-req == "/FOO" + expect resp.http.l-mod == "/foobar" + expect resp.http.u-mod == "/FOOBAR" + expect resp.http.uu-mod == "/FOOBAR" + expect resp.http.ul-mod == "/foobar" +} -run diff --git a/include/vrt.h b/include/vrt.h index a288cb2fd..2a741c125 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -52,6 +52,7 @@ * binary/load-time compatible, increment MAJOR version * * unreleased (planned for 2019-09-15) + * VRT_UpperLowerStrands added. * VRT_synth_page now takes STRANDS argument * VRT_hashdata() now takes STRANDS argument * VCL_BOOL VRT_Strands2Bool(VCL_STRANDS) added. @@ -538,6 +539,7 @@ VCL_BOOL VRT_Strands2Bool(VCL_STRANDS); char *VRT_Strands(char *, size_t, VCL_STRANDS); VCL_STRING VRT_StrandsWS(struct ws *, const char *, VCL_STRANDS); VCL_STRING VRT_CollectStrands(VRT_CTX, VCL_STRANDS); +VCL_STRING VRT_UpperLowerStrands(VRT_CTX, VCL_STRANDS s, int up); VCL_STRING VRT_BACKEND_string(VCL_BACKEND); VCL_STRING VRT_BOOL_string(VCL_BOOL); diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 6776a3f86..b1ed9b64e 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -803,7 +803,7 @@ vcc_expr5(struct vcc *tl, struct expr **e, vcc_type_t fmt) /*-------------------------------------------------------------------- * SYNTAX: * Expr4: - * Expr5 + * Expr5 [ '.' type_method() ]* */ static const struct vcc_methods { @@ -818,6 +818,9 @@ static const struct vcc_methods { { STEVEDORE, vtype, #nm, "VRT_stevedore_" #nm "(\v1)"}, #include "tbl/vrt_stv_var.h" + { STRINGS, STRING, "upper", "VRT_UpperLowerStrands(ctx, \vT, 1)" }, + { STRINGS, STRING, "lower", "VRT_UpperLowerStrands(ctx, \vT, 0)" }, + { NULL, NULL, NULL, NULL}, }; @@ -851,6 +854,11 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt) } vcc_NextToken(tl); *e = vcc_expr_edit(tl, vm->type_to, vm->impl, *e, NULL); + ERRCHK(tl); + if ((*e)->fmt == STRING) { + (*e)->fmt = STRINGS; + (*e)->nstr = 1; + } } } From phk at FreeBSD.org Mon Aug 5 10:37:09 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 10:37:09 +0000 (UTC) Subject: [master] 925a949eb Properly count vsm segments and rebuild _.index when retired segments dominate the _.index file. Message-ID: <20190805103709.7B34DA9FFA@lists.varnish-cache.org> commit 925a949ebcc85f28ce8605b040936d972c6f3e7a Author: Poul-Henning Kamp Date: Mon Aug 5 10:25:36 2019 +0000 Properly count vsm segments and rebuild _.index when retired segments dominate the _.index file. diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index c37b0d22e..feb94cff9 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -204,7 +204,6 @@ vsmw_append_record(struct vsmw *vsmw, struct vsmwseg *seg, char act) AZ(VSB_finish(vsmw->vsb)); XXXAZ(VSB_tofile(fd, vsmw->vsb)); // XXX handle ENOSPC? #2764 closefd(&fd); - vsmw->nsegs++; } /*--------------------------------------------------------------------*/ @@ -235,7 +234,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) VTAILQ_REMOVE(&vsmw->segs, seg, list); vsmw->nsegs--; - if (vsmw->nsubs < vsmw->nsegs || !fixidx) { + if (vsmw->nsubs * 2 < vsmw->nsegs || !fixidx) { vsmw_append_record(vsmw, seg, '-'); vsmw->nsubs++; } else { From phk at FreeBSD.org Mon Aug 5 10:37:09 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 5 Aug 2019 10:37:09 +0000 (UTC) Subject: [master] 368c3ba56 Test VSM _.index rewrites when more than half of the space is inert Message-ID: <20190805103709.90319A9FFD@lists.varnish-cache.org> commit 368c3ba5694afebb622eb2633a0848f9fa86d19f Author: Poul-Henning Kamp Date: Mon Aug 5 10:36:04 2019 +0000 Test VSM _.index rewrites when more than half of the space is inert diff --git a/bin/varnishtest/tests/c00083.vtc b/bin/varnishtest/tests/c00083.vtc new file mode 100644 index 000000000..67f52b612 --- /dev/null +++ b/bin/varnishtest/tests/c00083.vtc @@ -0,0 +1,85 @@ +varnishtest "Test VSM _.index rewrite when too many deletes" + +varnish v1 -vcl { + backend default { .host = "${bad_ip}"; } +} -start + +process p1 { + nlines=`wc -l < ${tmpdir}/v1/_.vsm_child/_.index` + nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_child/_.index` + echo NLINES $nlines NMINUS $nminus +} -dump -run + +# The child process starts out with approx 37 VSM segments +# so it takes 20 backends to cause a _.index rewrite. +# Make it 25 to be safe. +varnish v1 -vcl { + backend b00 { .host = "${bad_ip}"; } + backend b01 { .host = "${bad_ip}"; } + backend b02 { .host = "${bad_ip}"; } + backend b03 { .host = "${bad_ip}"; } + backend b04 { .host = "${bad_ip}"; } + backend b05 { .host = "${bad_ip}"; } + backend b06 { .host = "${bad_ip}"; } + backend b07 { .host = "${bad_ip}"; } + backend b08 { .host = "${bad_ip}"; } + backend b09 { .host = "${bad_ip}"; } + backend b10 { .host = "${bad_ip}"; } + backend b11 { .host = "${bad_ip}"; } + backend b12 { .host = "${bad_ip}"; } + backend b13 { .host = "${bad_ip}"; } + backend b14 { .host = "${bad_ip}"; } + backend b15 { .host = "${bad_ip}"; } + backend b16 { .host = "${bad_ip}"; } + backend b17 { .host = "${bad_ip}"; } + backend b18 { .host = "${bad_ip}"; } + backend b19 { .host = "${bad_ip}"; } + backend b20 { .host = "${bad_ip}"; } + backend b21 { .host = "${bad_ip}"; } + backend b22 { .host = "${bad_ip}"; } + backend b23 { .host = "${bad_ip}"; } + backend b24 { .host = "${bad_ip}"; } + + sub vcl_recv { + set req.backend_hint = b00; + set req.backend_hint = b01; + set req.backend_hint = b02; + set req.backend_hint = b03; + set req.backend_hint = b04; + set req.backend_hint = b05; + set req.backend_hint = b06; + set req.backend_hint = b07; + set req.backend_hint = b08; + set req.backend_hint = b09; + set req.backend_hint = b10; + set req.backend_hint = b11; + set req.backend_hint = b12; + set req.backend_hint = b13; + set req.backend_hint = b14; + set req.backend_hint = b15; + set req.backend_hint = b16; + set req.backend_hint = b17; + set req.backend_hint = b18; + set req.backend_hint = b19; + set req.backend_hint = b20; + set req.backend_hint = b21; + set req.backend_hint = b22; + set req.backend_hint = b23; + set req.backend_hint = b24; + } +} + +varnish v1 -cliok vcl.list + +process p1 -run + +varnish v1 -cliok "vcl.use vcl1" +varnish v1 -cliok "vcl.discard vcl2" + +# Check that the _.index rewrite did happen +process p1 { + nlines=`wc -l < ${tmpdir}/v1/_.vsm_child/_.index` + nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_child/_.index` + echo NLINES $nlines NMINUS $nminus + test $nminus -lt 25 +} -run From martin at varnish-software.com Mon Aug 5 11:06:08 2019 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 5 Aug 2019 11:06:08 +0000 (UTC) Subject: [master] fb02b2993 Fix vcl.show for labels Message-ID: <20190805110608.A64FAACB81@lists.varnish-cache.org> commit fb02b2993bedfbeac37b7cb488f35d285b971b52 Author: Martin Blix Grydeland Date: Fri Aug 2 13:28:36 2019 +0200 Fix vcl.show for labels When executing vcl.show for labels, show the VCL the label points to instead of asserting. diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index c50e44dd3..9adb3f431 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -876,6 +876,11 @@ vcl_cli_show(struct cli *cli, const char * const *av, void *priv) return; } CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC); + if (vcl->label) { + vcl = vcl->label; + CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC); + AZ(vcl->label); + } CHECK_OBJ_NOTNULL(vcl->conf, VCL_CONF_MAGIC); if (verbose) { for (i = 0; i < vcl->conf->nsrc; i++) diff --git a/bin/varnishtest/tests/s00005.vtc b/bin/varnishtest/tests/s00005.vtc index 0fa00990f..3ed6c0193 100644 --- a/bin/varnishtest/tests/s00005.vtc +++ b/bin/varnishtest/tests/s00005.vtc @@ -40,6 +40,8 @@ varnish v1 -cliok "vcl.label foo vcl2" varnish v1 -cliok "vcl.label bar vcl2" varnish v1 -cliok "vcl.list" varnish v1 -clijson "vcl.list -j" +varnish v1 -cliok "vcl.show foo" +varnish v1 -cliok "vcl.show -v bar" varnish v1 -clierr 300 "vcl.discard vcl2" varnish v1 -cliok "vcl.discard bar" varnish v1 -cliok "vcl.label foo vcl1" From hermunn at varnish-software.com Mon Aug 5 11:12:08 2019 From: hermunn at varnish-software.com (Pål Hermunn Johansen) Date: Mon, 5 Aug 2019 11:12:08 +0000 (UTC) Subject: [master] c91c1bb5c Document 1 second TTL on (synthetic) error objects Message-ID: <20190805111208.F2749ACE9A@lists.varnish-cache.org> commit c91c1bb5cde04d82c84e6f8e6a0ba0ee1a009a08 Author: P?l Hermunn Johansen Date: Thu Aug 1 13:49:08 2019 +0200 Document 1 second TTL on (synthetic) error objects The behavior described here is old (see cache_fetch.c), but has not been cleanly documented in the docs. Fixes: #3024 diff --git a/doc/sphinx/users-guide/vcl-built-in-subs.rst b/doc/sphinx/users-guide/vcl-built-in-subs.rst index fd5a58104..8d99efd59 100644 --- a/doc/sphinx/users-guide/vcl-built-in-subs.rst +++ b/doc/sphinx/users-guide/vcl-built-in-subs.rst @@ -509,8 +509,17 @@ Returning with `abandon`_ does not leave a cache object. If returning with ``deliver`` and a ``beresp.ttl > 0s``, a synthetic cache object is generated in VCL, whose body may be constructed using -the ``synthetic()`` function. This may be useful to increase the -efficiency of failing backend requests. +the ``synthetic()`` function. + +When there is a waiting list on the object, the default ``ttl`` will +be positive (currently one second), set before entering +``vcl_backend_error``. This is to avoid request serialization and +hammering on a potentially failing backend. + +Since these synthetic objects are cached in these special +circumstances, be cautious with putting private information there. If +you really must, then you need to explicitly set ``beresp.ttl`` to +zero in ``vcl_backend_error``. The `vcl_backend_error` subroutine may terminate with calling ``return()`` with one of the following keywords: From fgsch at lodoss.net Mon Aug 5 11:57:08 2019 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 5 Aug 2019 11:57:08 +0000 (UTC) Subject: [master] 4503928e6 Document gunzip Message-ID: <20190805115708.A25EDADD1B@lists.varnish-cache.org> commit 4503928e6513a8500296962524e6fcefdff21a27 Author: Federico G. Schwindt Date: Mon Aug 5 12:53:40 2019 +0100 Document gunzip Fixes #3030. diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 2df6cab45..e2f63d84c 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -755,6 +755,11 @@ cmd_http_rxresphdrs(CMD_ARGS) #define OVERHEAD 64L +/* SECTION: client-server.spec.gunzip + * + * gunzip + * Gunzip the body in place. + */ static void cmd_http_gunzip(CMD_ARGS) { From fgsch at lodoss.net Mon Aug 5 14:28:09 2019 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 5 Aug 2019 14:28:09 +0000 (UTC) Subject: [master] cd5ddaa64 Add gunzip for http2 Message-ID: <20190805142809.94E30B0C7F@lists.varnish-cache.org> commit cd5ddaa64e0d3f5c2bca2b7998922e73b9d878e7 Author: Federico G. Schwindt Date: Mon Aug 5 13:24:42 2019 +0100 Add gunzip for http2 While here also implement -gziplen and -gzipbody. Fixes #3031. diff --git a/bin/varnishtest/Makefile.am b/bin/varnishtest/Makefile.am index b9c1def06..dc67a98c0 100644 --- a/bin/varnishtest/Makefile.am +++ b/bin/varnishtest/Makefile.am @@ -38,6 +38,7 @@ varnishtest_SOURCES = \ vtc.c \ vtc_barrier.c \ vtc_client.c \ + vtc_gzip.c \ vtc_haproxy.c \ vtc_h2_dectbl.h \ vtc_h2_enctbl.h \ diff --git a/bin/varnishtest/tests/a02026.vtc b/bin/varnishtest/tests/a02026.vtc new file mode 100644 index 000000000..71bcca94d --- /dev/null +++ b/bin/varnishtest/tests/a02026.vtc @@ -0,0 +1,29 @@ +varnishtest "Test -gzipbody and -gziplen" + +server s1 { + stream 1 { + rxreq + txresp -gzipbody "foo" + } -run + + stream 3 { + rxreq + txresp -gziplen 10 + } -run +} -start + +client c1 -connect ${s1_sock} { + stream 1 { + txreq + rxresp + gunzip + expect resp.body == "foo" + } -run + + stream 3 { + txreq + rxresp + gunzip + expect resp.bodylen == 10 + } -run +} -run diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 50f5e8f1a..61c8dcb2d 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -130,6 +130,10 @@ void start_h2(struct http *hp); void stop_h2(struct http *hp); void b64_settings(const struct http *hp, const char *s); +/* vtc_gzip.c */ +void vtc_gzip(struct http *, const char *, char **, unsigned *); +void vtc_gunzip(struct http *, char *, unsigned *); + /* vtc_subr.c */ struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg); void vtc_expect(struct vtclog *, const char *, const char *, const char *, diff --git a/bin/varnishtest/vtc_gzip.c b/bin/varnishtest/vtc_gzip.c new file mode 100644 index 000000000..9eeb67a51 --- /dev/null +++ b/bin/varnishtest/vtc_gzip.c @@ -0,0 +1,134 @@ +/*- + * Copyright (c) 2008-2019 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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 +#include +#include + +#include "vtc.h" +#include "vtc_http.h" +#include "vgz.h" + +#define OVERHEAD 64L + + +void +vtc_gzip(struct http *hp, const char *input, char **body, unsigned *bodylen) +{ + unsigned l; + z_stream vz; +#ifdef VGZ_EXTENSIONS + int i; +#endif + + memset(&vz, 0, sizeof vz); + + l = strlen(input); + *body = calloc(1, l + OVERHEAD); + AN(*body); + + vz.next_in = TRUST_ME(input); + vz.avail_in = l; + + vz.next_out = TRUST_ME(*body); + vz.avail_out = l + OVERHEAD; + + assert(Z_OK == deflateInit2(&vz, + hp->gziplevel, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY)); + assert(Z_STREAM_END == deflate(&vz, Z_FINISH)); + *bodylen = vz.total_out; +#ifdef VGZ_EXTENSIONS + i = vz.stop_bit & 7; + if (hp->gzipresidual >= 0 && hp->gzipresidual != i) + vtc_log(hp->vl, hp->fatal, + "Wrong gzip residual got %d wanted %d", + i, hp->gzipresidual); + vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", + (uintmax_t)vz.start_bit, + (uintmax_t)vz.start_bit >> 3, (uintmax_t)vz.start_bit & 7); + vtc_log(hp->vl, 4, "lastbit = %ju %ju/%ju", + (uintmax_t)vz.last_bit, + (uintmax_t)vz.last_bit >> 3, (uintmax_t)vz.last_bit & 7); + vtc_log(hp->vl, 4, "stopbit = %ju %ju/%ju", + (uintmax_t)vz.stop_bit, + (uintmax_t)vz.stop_bit >> 3, (uintmax_t)vz.stop_bit & 7); + assert(Z_OK == deflateEnd(&vz)); +#endif +} + +void +vtc_gunzip(struct http *hp, char *body, unsigned *bodylen) +{ + z_stream vz; + char *p; + unsigned l; + int i; + + memset(&vz, 0, sizeof vz); + + AN(body); + if (body[0] != (char)0x1f || body[1] != (char)0x8b) + vtc_log(hp->vl, hp->fatal, + "Gunzip error: body lacks gzip magic"); + vz.next_in = TRUST_ME(body); + vz.avail_in = *bodylen; + + l = *bodylen * 10; + p = calloc(1, l); + AN(p); + + vz.next_out = TRUST_ME(p); + vz.avail_out = l; + + assert(Z_OK == inflateInit2(&vz, 31)); + i = inflate(&vz, Z_FINISH); + assert(vz.total_out < l); + *bodylen = vz.total_out; + memcpy(body, p, *bodylen); + free(p); + vtc_log(hp->vl, 3, "new bodylen %u", *bodylen); + vtc_dump(hp->vl, 4, "body", body, *bodylen); + bprintf(hp->bodylen, "%u", *bodylen); +#ifdef VGZ_EXTENSIONS + vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", + (uintmax_t)vz.start_bit, + (uintmax_t)vz.start_bit >> 3, (uintmax_t)vz.start_bit & 7); + vtc_log(hp->vl, 4, "lastbit = %ju %ju/%ju", + (uintmax_t)vz.last_bit, + (uintmax_t)vz.last_bit >> 3, (uintmax_t)vz.last_bit & 7); + vtc_log(hp->vl, 4, "stopbit = %ju %ju/%ju", + (uintmax_t)vz.stop_bit, + (uintmax_t)vz.stop_bit >> 3, (uintmax_t)vz.stop_bit & 7); +#endif + if (i != Z_STREAM_END) + vtc_log(hp->vl, hp->fatal, + "Gunzip error = %d (%s) in:%jd out:%jd", + i, vz.msg, (intmax_t)vz.total_in, (intmax_t)vz.total_out); + assert(Z_OK == inflateEnd(&vz)); + body[*bodylen] = '\0'; +} diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index e2f63d84c..8078ea645 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -749,12 +749,6 @@ cmd_http_rxresphdrs(CMD_ARGS) "Multiple Content-Length headers.\n"); } -/********************************************************************** - * Ungzip rx'ed body - */ - -#define OVERHEAD 64L - /* SECTION: client-server.spec.gunzip * * gunzip @@ -763,107 +757,14 @@ cmd_http_rxresphdrs(CMD_ARGS) static void cmd_http_gunzip(CMD_ARGS) { - int i; - z_stream vz; struct http *hp; - char *p; - unsigned l; (void)av; (void)cmd; (void)vl; - CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); - memset(&vz, 0, sizeof vz); - - AN(hp->body); - if (hp->body[0] != (char)0x1f || hp->body[1] != (char)0x8b) - vtc_log(hp->vl, hp->fatal, - "Gunzip error: Body lacks gzip magics"); - vz.next_in = TRUST_ME(hp->body); - vz.avail_in = hp->bodyl; - - l = hp->bodyl * 10; - p = calloc(1, l); - AN(p); - - vz.next_out = TRUST_ME(p); - vz.avail_out = l; - - assert(Z_OK == inflateInit2(&vz, 31)); - i = inflate(&vz, Z_FINISH); - assert(vz.total_out < l); - hp->bodyl = vz.total_out; - memcpy(hp->body, p, hp->bodyl); - free(p); - vtc_log(hp->vl, 3, "new bodylen %u", hp->bodyl); - vtc_dump(hp->vl, 4, "body", hp->body, hp->bodyl); - bprintf(hp->bodylen, "%u", hp->bodyl); -#ifdef VGZ_EXTENSIONS - vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", - (uintmax_t)vz.start_bit, - (uintmax_t)vz.start_bit >> 3, (uintmax_t)vz.start_bit & 7); - vtc_log(hp->vl, 4, "lastbit = %ju %ju/%ju", - (uintmax_t)vz.last_bit, - (uintmax_t)vz.last_bit >> 3, (uintmax_t)vz.last_bit & 7); - vtc_log(hp->vl, 4, "stopbit = %ju %ju/%ju", - (uintmax_t)vz.stop_bit, - (uintmax_t)vz.stop_bit >> 3, (uintmax_t)vz.stop_bit & 7); -#endif - if (i != Z_STREAM_END) - vtc_log(hp->vl, hp->fatal, - "Gunzip error = %d (%s) in:%jd out:%jd", - i, vz.msg, (intmax_t)vz.total_in, (intmax_t)vz.total_out); - assert(Z_OK == inflateEnd(&vz)); - hp->body[hp->bodyl] = '\0'; -} - -/********************************************************************** - * Create a gzip'ed body - */ - -static void -gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen) -{ - int l; - z_stream vz; -#ifdef VGZ_EXTENSIONS - int i; -#endif - - memset(&vz, 0, sizeof vz); - - l = strlen(txt); - *body = calloc(1, l + OVERHEAD); - AN(*body); - - vz.next_in = TRUST_ME(txt); - vz.avail_in = l; - - vz.next_out = TRUST_ME(*body); - vz.avail_out = l + OVERHEAD; - - assert(Z_OK == deflateInit2(&vz, - hp->gziplevel, Z_DEFLATED, 31, 9, Z_DEFAULT_STRATEGY)); - assert(Z_STREAM_END == deflate(&vz, Z_FINISH)); - *bodylen = vz.total_out; -#ifdef VGZ_EXTENSIONS - i = vz.stop_bit & 7; - if (hp->gzipresidual >= 0 && hp->gzipresidual != i) - vtc_log(hp->vl, hp->fatal, - "Wrong gzip residual got %d wanted %d", - i, hp->gzipresidual); - vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", - (uintmax_t)vz.start_bit, - (uintmax_t)vz.start_bit >> 3, (uintmax_t)vz.start_bit & 7); - vtc_log(hp->vl, 4, "lastbit = %ju %ju/%ju", - (uintmax_t)vz.last_bit, - (uintmax_t)vz.last_bit >> 3, (uintmax_t)vz.last_bit & 7); - vtc_log(hp->vl, 4, "stopbit = %ju %ju/%ju", - (uintmax_t)vz.stop_bit, - (uintmax_t)vz.stop_bit >> 3, (uintmax_t)vz.stop_bit & 7); - assert(Z_OK == deflateEnd(&vz)); -#endif + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + vtc_gunzip(hp, hp->body, (unsigned *)&hp->bodyl); } /********************************************************************** @@ -947,7 +848,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, assert(body == nullbody); free(body); b = synth_body(av[1], 1); - gzip_body(hp, b, &body, &bodylen); + vtc_gzip(hp, b, &body, (unsigned *)&bodylen); free(b); VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl); // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen); @@ -955,7 +856,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, } else if (!strcmp(*av, "-gzipbody")) { assert(body == nullbody); free(body); - gzip_body(hp, av[1], &body, &bodylen); + vtc_gzip(hp, av[1], &body, (unsigned *)&bodylen); VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl); // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen); av++; diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c index 74cea13bb..d915b7e51 100644 --- a/bin/varnishtest/vtc_http2.c +++ b/bin/varnishtest/vtc_http2.c @@ -43,6 +43,7 @@ #include "vtc_http.h" #include "vfil.h" +#include "vgz.h" #include "hpack.h" #include "vend.h" @@ -1334,6 +1335,13 @@ cmd_sendhex(CMD_ARGS) * Do the same thing as ``-body`` but generate an string of INT length * for you. * + * \-gzipbody STRING (txreq, txresp) + * Gzip STRING and send it as body. + * + * \-gziplen NUMBER (txreq, txresp) + * Combine -body and -gzipbody: create a body of length NUMBER, + * gzip it and send as body. + * * \-nostrend (txreq, txresp) * Don't set the END_STREAM flag automatically, making the peer expect * a body after the headers. @@ -1386,7 +1394,7 @@ cmd_tx11obj(CMD_ARGS) /*XXX: do we need a better api? yes we do */ struct hpk_hdr hdr; char *cmd_str = *av; - char *p; + char *b, *p; (void)cmd; CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC); @@ -1540,7 +1548,28 @@ cmd_tx11obj(CMD_ARGS) bodylen = strlen(body); f.flags &= ~END_STREAM; av++; - }else if (AV_IS("-dep")) { + } + else if (!strcmp(*av, "-gzipbody")) { + AZ(body); + vtc_gzip(s->hp, av[1], &body, + (unsigned *)&bodylen); + AN(body); + ENC(hdr, ":content-encoding", "gzip"); + f.flags &= ~END_STREAM; + av++; + } + else if (!strcmp(*av, "-gziplen")) { + AZ(body); + b = synth_body(av[1], 1); + vtc_gzip(s->hp, b, &body, + (unsigned *)&bodylen); + AN(body); + free(b); + ENC(hdr, ":content-encoding", "gzip"); + f.flags &= ~END_STREAM; + av++; + } + else if (AV_IS("-dep")) { STRTOU32_CHECK(stid, av, p, vl, "-dep", 0); f.flags |= PRIORITY; } @@ -2438,6 +2467,27 @@ cmd_expect(CMD_ARGS) AZ(pthread_mutex_unlock(&s->hp->mtx)); } +/* SECTION: stream.spec.gunzip gunzip + * + * Same as the ``gunzip`` command for HTTP/1. + */ +static void +cmd_gunzip(CMD_ARGS) +{ + struct http *hp; + struct stream *s; + + (void)av; + (void)cmd; + (void)vl; + + CAST_OBJ_NOTNULL(s, priv, STREAM_MAGIC); + hp = s->hp; + CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + + vtc_gunzip(s->hp, s->body, (unsigned *)&s->bodylen); +} + /* SECTION: stream.spec.write_body * * write_body STRING @@ -2469,6 +2519,7 @@ static const struct cmds stream_cmds[] = { #define CMD_STREAM(n) { #n, cmd_##n }, /* spec */ CMD_STREAM(expect) + CMD_STREAM(gunzip) CMD_STREAM(rxcont) CMD_STREAM(rxdata) CMD_STREAM(rxframe) From nils.goroll at uplex.de Mon Aug 5 14:30:15 2019 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 5 Aug 2019 14:30:15 +0000 (UTC) Subject: [master] dea77acca avoid null pointer deref in panic code Message-ID: <20190805143015.6C19CB0E7A@lists.varnish-cache.org> commit dea77acca891aff4f46fc60f61f37d018e3c22a2 Author: Nils Goroll Date: Sun Jul 21 13:03:38 2019 +0200 avoid null pointer deref in panic code diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 60a521ece..8a9c88775 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -533,7 +533,7 @@ pan_req(struct vsb *vsb, const struct req *req) if (VALID_OBJ(req->htc, HTTP_CONN_MAGIC)) pan_htc(vsb, req->htc); pan_http(vsb, "req", req->http); - if (req->resp->ws != NULL) + if (req->resp != NULL && req->resp->ws != NULL) pan_http(vsb, "resp", req->resp); if (req->vdc != NULL) pan_vdp(vsb, req->vdc); From phk at FreeBSD.org Tue Aug 6 09:15:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:11 +0000 (UTC) Subject: [master] 957dee5c7 Dont prefix function pointers with '*' Message-ID: <20190806091511.999399B481@lists.varnish-cache.org> commit 957dee5c7709a586d566cbb22c253d03829d6636 Author: Poul-Henning Kamp Date: Tue Aug 6 08:05:00 2019 +0000 Dont prefix function pointers with '*' diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index 79cff3ee8..fea8a955f 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -577,7 +577,7 @@ class Stanza(object): fmt_cstruct( fo, '.' + proto.cname() + ' =', - '*' + self.vcc.sympfx + proto.cname() + ',' + self.vcc.sympfx + proto.cname() + ',' ) def cstruct(self, unused_fo, unused_define): @@ -703,7 +703,7 @@ class EventStanza(Stanza): else: fmt_cstruct(fo, "._event =", - '*' + self.vcc.sympfx + self.event_func + ',') + self.vcc.sympfx + self.event_func + ',') def json(self, jl): jl.append(["$EVENT", "%s._event" % self.vcc.csn]) From phk at FreeBSD.org Tue Aug 6 09:15:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:11 +0000 (UTC) Subject: [master] c5d0a9559 FlexeLinting: 'oper' is an incredibly bad global name. Message-ID: <20190806091511.AED979B486@lists.varnish-cache.org> commit c5d0a9559835c639ceef54d8c6a99834ebbefe74 Author: Poul-Henning Kamp Date: Tue Aug 6 08:16:56 2019 +0000 FlexeLinting: 'oper' is an incredibly bad global name. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 16e9351d7..dc4751d2c 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -70,8 +70,6 @@ static const char * const arg_name[BAN_ARGARRSZ + 1] = { [BAN_ARGARRSZ] = NULL }; -extern const char * const oper[BAN_OPERARRSZ + 1]; - /*-------------------------------------------------------------------- * Storage handling of bans */ @@ -806,7 +804,7 @@ ban_render(struct cli *cli, const uint8_t *bs, int quote) else VCLI_Out(cli, "%s", arg_name[BAN_ARGIDX(bt.arg1)]); - VCLI_Out(cli, " %s ", oper[BAN_OPERIDX(bt.oper)]); + VCLI_Out(cli, " %s ", ban_oper[BAN_OPERIDX(bt.oper)]); if (BANS_HAS_ARG2_DOUBLE(bt.arg1)) { vdur_render(buf, bt.arg2_double); diff --git a/bin/varnishd/cache/cache_ban.h b/bin/varnishd/cache/cache_ban.h index c4d04fa23..cd82aad38 100644 --- a/bin/varnishd/cache/cache_ban.h +++ b/bin/varnishd/cache/cache_ban.h @@ -145,6 +145,7 @@ extern struct ban * volatile ban_start; extern pthread_cond_t ban_lurker_cond; extern uint64_t bans_persisted_bytes; extern uint64_t bans_persisted_fragmentation; +extern const char * const ban_oper[BAN_OPERARRSZ + 1]; void ban_mark_completed(struct ban *); unsigned ban_len(const uint8_t *banspec); diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c index 228d18c4b..4c08fd639 100644 --- a/bin/varnishd/cache/cache_ban_build.c +++ b/bin/varnishd/cache/cache_ban_build.c @@ -76,7 +76,7 @@ static const unsigned arg_opervalid[BAN_ARGARRSZ + 1] = { static const char *arg_operhelp[BAN_ARGARRSZ + 1]; // operators -const char * const oper[BAN_OPERARRSZ + 1] = { +const char * const ban_oper[BAN_OPERARRSZ + 1] = { #define OPER(op, str) [BAN_OPERIDX(op)] = (str), #include "tbl/ban_oper.h" [BAN_OPERARRSZ] = NULL @@ -205,7 +205,7 @@ ban_parse_oper(const char *p) int i; for (i = 0; i < BAN_OPERARRSZ; i++) { - if (!strcmp(p, oper[i])) + if (!strcmp(p, ban_oper[i])) return (_BANS_OPER_OFF + i); } return (-1); @@ -396,14 +396,14 @@ ban_build_arg_operhelp(struct vsb *vsb, int arg) if ((mask & (1U << i)) == 0) continue; if (p == NULL) - p = oper[i]; + p = ban_oper[i]; else if (n == NULL) - n = oper[i]; + n = ban_oper[i]; else { VSB_cat(vsb, p); VSB_cat(vsb, ", "); p = n; - n = oper[i]; + n = ban_oper[i]; } } From phk at FreeBSD.org Tue Aug 6 09:15:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:11 +0000 (UTC) Subject: [master] 4b6958587 Silence Flexlint 9075 ("No prior declaration") for the bogo-structures. Message-ID: <20190806091511.C7EA59B48B@lists.varnish-cache.org> commit 4b695858761b2acc3a30ad92a5a6788db084d7a6 Author: Poul-Henning Kamp Date: Tue Aug 6 08:17:42 2019 +0000 Silence Flexlint 9075 ("No prior declaration") for the bogo-structures. diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index 2606ae274..83b102176 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -882,6 +882,8 @@ xyzzy_get_ip(VRT_CTX, struct vmod_priv *priv) * For testing import code on bad vmod files (m00003.vtc) */ +//lint -save -e9075 external symbol '...' defined without a prior declaration + const struct vmod_data Vmod_wrong0_Data = { .vrt_major = 0, .vrt_minor = 0, @@ -918,3 +920,5 @@ const struct vmod_data Vmod_wrong3_Data = { .proto = "blablabla", .abi = "abiblabla", }; + +//lint -restore From phk at FreeBSD.org Tue Aug 6 09:15:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:11 +0000 (UTC) Subject: [master] 338550eda FlexeLinting: Default is always last in switch, and there is one. Message-ID: <20190806091511.E8F739B490@lists.varnish-cache.org> commit 338550eda003a320a4a6d8b80eea7ab8066c9c8a Author: Poul-Henning Kamp Date: Tue Aug 6 08:19:07 2019 +0000 FlexeLinting: Default is always last in switch, and there is one. diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 8a9c88775..2580b4ada 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -725,8 +725,8 @@ pan_ic(const char *func, const char *file, int line, const char *cond, "Incomplete code in %s(), %s line %d:\n", func, file, line); break; - default: case VAS_ASSERT: + default: VSB_printf(pan_vsb, "Assert error in %s(), %s line %d:\n" " Condition(%s) not true.\n", diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c index e2bffa216..e411f6aaf 100644 --- a/bin/varnishd/cache/cache_rfc2616.c +++ b/bin/varnishd/cache/cache_rfc2616.c @@ -126,9 +126,6 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin, h_date = VTIM_parse(p); switch (http_GetStatus(hp)) { - default: - *ttl = -1.; - break; case 302: /* Moved Temporarily */ case 307: /* Temporary Redirect */ /* @@ -192,7 +189,10 @@ RFC2616_Ttl(struct busyobj *bo, vtim_real now, vtim_real *t_origin, */ *ttl = (int)(h_expires - h_date); } - + break; + default: + *ttl = -1.; + break; } /* diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 5a1c0ca29..3a0b57f61 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -691,7 +691,8 @@ MCF_InitParams(struct cli *cli) /*--------------------------------------------------------------------*/ void -MCF_ParamConf(enum mcf_which_e which, const char *param, const char *fmt, ...) +MCF_ParamConf(enum mcf_which_e which, const char * const param, + const char *fmt, ...) { struct parspec *pp; struct vsb *vsb; @@ -718,6 +719,8 @@ MCF_ParamConf(enum mcf_which_e which, const char *param, const char *fmt, ...) pp->max = strdup(VSB_data(vsb)); AN(pp->max); break; + default: + WRONG("bad 'which'"); } VSB_delete(vsb); } From phk at FreeBSD.org Tue Aug 6 09:15:12 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:12 +0000 (UTC) Subject: [master] 6f63b8ef0 Flexelinting: Macros named _something are reserved for the compiler Message-ID: <20190806091512.0CF599B496@lists.varnish-cache.org> commit 6f63b8ef054ce89fc17926ecdf6e6d9badffb957 Author: Poul-Henning Kamp Date: Tue Aug 6 08:32:50 2019 +0000 Flexelinting: Macros named _something are reserved for the compiler diff --git a/bin/varnishd/cache/cache_ban.h b/bin/varnishd/cache/cache_ban.h index cd82aad38..4288f1297 100644 --- a/bin/varnishd/cache/cache_ban.h +++ b/bin/varnishd/cache/cache_ban.h @@ -77,7 +77,7 @@ #define BANS_FLAG_NODEDUP (1<<5) #define BANS_OPER_EQ 0x10 -#define _BANS_OPER_OFF BANS_OPER_EQ +#define BANS_OPER_OFF_ BANS_OPER_EQ #define BANS_OPER_NEQ 0x11 #define BANS_OPER_MATCH 0x12 #define BANS_OPER_NMATCH 0x13 @@ -85,14 +85,14 @@ #define BANS_OPER_GTE 0x15 #define BANS_OPER_LT 0x16 #define BANS_OPER_LTE 0x17 -#define _BANS_OPER_LIM (BANS_OPER_LTE + 1) +#define BANS_OPER_LIM_ (BANS_OPER_LTE + 1) -#define BAN_OPERIDX(x) ((x) - _BANS_OPER_OFF) -#define BAN_OPERARRSZ (_BANS_OPER_LIM - _BANS_OPER_OFF) -#define ASSERT_BAN_OPER(x) assert((x) >= _BANS_OPER_OFF && (x) < _BANS_OPER_LIM) +#define BAN_OPERIDX(x) ((x) - BANS_OPER_OFF_) +#define BAN_OPERARRSZ (BANS_OPER_LIM_ - BANS_OPER_OFF_) +#define ASSERT_BAN_OPER(x) assert((x) >= BANS_OPER_OFF_ && (x) < BANS_OPER_LIM_) #define BANS_ARG_URL 0x18 -#define _BANS_ARG_OFF BANS_ARG_URL +#define BANS_ARG_OFF_ BANS_ARG_URL #define BANS_ARG_REQHTTP 0x19 #define BANS_ARG_OBJHTTP 0x1a #define BANS_ARG_OBJSTATUS 0x1b @@ -100,11 +100,11 @@ #define BANS_ARG_OBJAGE 0x1d #define BANS_ARG_OBJGRACE 0x1e #define BANS_ARG_OBJKEEP 0x1f -#define _BANS_ARG_LIM (BANS_ARG_OBJKEEP + 1) +#define BANS_ARG_LIM (BANS_ARG_OBJKEEP + 1) -#define BAN_ARGIDX(x) ((x) - _BANS_ARG_OFF) -#define BAN_ARGARRSZ (_BANS_ARG_LIM - _BANS_ARG_OFF) -#define ASSERT_BAN_ARG(x) assert((x) >= _BANS_ARG_OFF && (x) < _BANS_ARG_LIM) +#define BAN_ARGIDX(x) ((x) - BANS_ARG_OFF_) +#define BAN_ARGARRSZ (BANS_ARG_LIM - BANS_ARG_OFF_) +#define ASSERT_BAN_ARG(x) assert((x) >= BANS_ARG_OFF_ && (x) < BANS_ARG_LIM) // has an arg1_spec (BANS_FLAG_HTTP at build time) #define BANS_HAS_ARG1_SPEC(arg) \ diff --git a/bin/varnishd/cache/cache_ban_build.c b/bin/varnishd/cache/cache_ban_build.c index 4c08fd639..441f71b93 100644 --- a/bin/varnishd/cache/cache_ban_build.c +++ b/bin/varnishd/cache/cache_ban_build.c @@ -206,7 +206,7 @@ ban_parse_oper(const char *p) for (i = 0; i < BAN_OPERARRSZ; i++) { if (!strcmp(p, ban_oper[i])) - return (_BANS_OPER_OFF + i); + return (BANS_OPER_OFF_ + i); } return (-1); } @@ -251,7 +251,7 @@ BAN_AddTest(struct ban_proto *bp, } op = ban_parse_oper(a2); - if (op < _BANS_OPER_OFF || + if (op < BANS_OPER_OFF_ || ((1U << BAN_OPERIDX(op)) & arg_opervalid[BAN_ARGIDX(pv->tag)]) == 0) return (ban_error(bp, "expected conditional (%s) got \"%s\"", @@ -424,7 +424,7 @@ BAN_Build_Init(void) { struct vsb *vsb = VSB_new_auto(); int i; - for (i = _BANS_ARG_OFF; i < _BANS_ARG_LIM; i ++) { + for (i = BANS_ARG_OFF_; i < BANS_ARG_LIM; i ++) { VSB_clear(vsb); ban_build_arg_operhelp(vsb, i); AZ(VSB_finish(vsb)); diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c index 9de023190..3fd7fc605 100644 --- a/lib/libvmod_directors/vmod_shard.c +++ b/lib/libvmod_directors/vmod_shard.c @@ -93,11 +93,11 @@ #define arg_healthy ((uint32_t)1 << 6) #define arg_param ((uint32_t)1 << 7) #define arg_resolve ((uint32_t)1 << 8) -#define _arg_mask ((arg_resolve << 1) - 1) +#define arg_mask_ ((arg_resolve << 1) - 1) /* allowed in shard_param.set */ -#define _arg_mask_set (arg_param - 1) +#define arg_mask_set_ (arg_param - 1) /* allowed in shard_param */ -#define _arg_mask_param ( _arg_mask_set \ +#define arg_mask_param_ ( arg_mask_set_ \ & ~arg_key \ & ~arg_key_blob ) @@ -143,7 +143,7 @@ static const struct vmod_directors_shard_param shard_param_default = { .defaults = NULL, .scope = SCOPE_VMOD, - .mask = _arg_mask_param, + .mask = arg_mask_param_, .by = BY_HASH, .healthy = CHOSEN, .rampup = 1, @@ -429,13 +429,13 @@ shard_param_merge(struct vmod_directors_shard_param *to, const struct vmod_directors_shard_param *from) { CHECK_OBJ_NOTNULL(to, VMOD_SHARD_SHARD_PARAM_MAGIC); - assert((to->mask & ~_arg_mask_param) == 0); + assert((to->mask & ~arg_mask_param_) == 0); - if (to->mask == _arg_mask_param) + if (to->mask == arg_mask_param_) return; CHECK_OBJ_NOTNULL(from, VMOD_SHARD_SHARD_PARAM_MAGIC); - assert((from->mask & ~_arg_mask_param) == 0); + assert((from->mask & ~arg_mask_param_) == 0); if ((to->mask & arg_by) == 0 && (from->mask & arg_by) != 0) { to->by = from->by; @@ -457,7 +457,7 @@ shard_param_merge(struct vmod_directors_shard_param *to, to->mask |= from->mask; - if (to->mask == _arg_mask_param) + if (to->mask == arg_mask_param_) return; AN(from->defaults); @@ -495,7 +495,7 @@ shard_blob_key(VCL_BLOB key_blob) #define tobit(args, name) ((args)->valid_##name ? arg_##name : 0) static uint32_t -shard_backend_arg_mask(const struct VARGS(shard_backend) * const a) +shard_backendarg_mask_(const struct VARGS(shard_backend) * const a) { return (tobit(a, by) | tobit(a, key) | @@ -535,7 +535,7 @@ shard_param_args(VRT_CTX, CHECK_OBJ_NOTNULL(p, VMOD_SHARD_SHARD_PARAM_MAGIC); AN(p->vcl_name); - assert((args & ~_arg_mask_set) == 0); + assert((args & ~arg_mask_set_) == 0); by = (args & arg_by) ? parse_by_e(by_s) : BY_HASH; healthy = (args & arg_healthy) ? parse_healthy_e(healthy_s) : CHOSEN; @@ -631,7 +631,7 @@ shard_param_args(VRT_CTX, if (args & arg_healthy) p->healthy = healthy; - p->mask = args & _arg_mask_param; + p->mask = args & arg_mask_param_; return (p); } @@ -643,11 +643,11 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, struct vmod_directors_shard_param *pp = NULL; const struct vmod_directors_shard_param *ppt; enum resolve_e resolve; - uint32_t args = shard_backend_arg_mask(a); + uint32_t args = shard_backendarg_mask_(a); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(vshard, VMOD_SHARD_SHARD_MAGIC); - assert((args & ~_arg_mask) == 0); + assert((args & ~arg_mask_) == 0); if (args & arg_resolve) resolve = parse_resolve_e(a->resolve); @@ -703,7 +703,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, } pp = shard_param_args(ctx, pp, "shard.backend()", - args & _arg_mask_set, + args & arg_mask_set_, a->by, a->key, a->key_blob, a->alt, a->warmup, a->rampup, a->healthy); if (pp == NULL) @@ -987,7 +987,7 @@ vmod_shard_param_set(VRT_CTX, struct vmod_directors_shard_param *p, { uint32_t args = shard_param_set_mask(a); - assert((args & ~_arg_mask_set) == 0); + assert((args & ~arg_mask_set_) == 0); p = shard_param_prep(ctx, p, "shard_param.set()"); if (p == NULL) From phk at FreeBSD.org Tue Aug 6 09:15:12 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:12 +0000 (UTC) Subject: [master] d29aa566f Add some of FlexeLints "elective" messages. Message-ID: <20190806091512.270019B49E@lists.varnish-cache.org> commit d29aa566f811335b7108e13812df8b6e174fb685 Author: Poul-Henning Kamp Date: Tue Aug 6 09:06:53 2019 +0000 Add some of FlexeLints "elective" messages. diff --git a/flint.lnt b/flint.lnt index c043f969d..60b530678 100644 --- a/flint.lnt +++ b/flint.lnt @@ -5,6 +5,46 @@ //d__flexelint_v9__=1 +fan +/////////////////////////////////////////////////////////////////////// +// electives +//+e9* +-e904 +-e935 +-e955 +//+e958 // report internal struct padding +//+e959 // report struct tail/size padding +-e960 +-e964 +-e970 +-e9012 +-e9021 +-e9022 +-e9024 +-e9026 +-e9034 +-e9042 +-e9067 ++e9071 // defined macro '...' is reserved to the compiler ++e9075 // external symbol without declaration +-esym(9075, main) +-e9085 +-e9107 +-e9109 +-e9113 +-e9131 +-e9132 +-e9133 +-e9136 +-e9140 +-e9141 +-e9147 // we dont use & on func_pointers +-e9149 +-e9158 +-e9159 +-e9165 +/////////////////////////////////////////////////////////////////////// + + -emacro((835),*) // A zero has been given as ___ argument to operator '___ /////////////////////////////////////////////////////////////////////// From phk at FreeBSD.org Tue Aug 6 09:15:12 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 09:15:12 +0000 (UTC) Subject: [master] 11c385ea7 FlexeLinting: remove pointless and slightly wrong terminating entry Message-ID: <20190806091512.3F03E9B4A4@lists.varnish-cache.org> commit 11c385ea730b7563399e12aca20154ab65527f2f Author: Poul-Henning Kamp Date: Tue Aug 6 09:07:32 2019 +0000 FlexeLinting: remove pointless and slightly wrong terminating entry diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c index 7ea66d7e1..8fc6f61b9 100644 --- a/bin/varnishd/mgt/mgt_param_bits.c +++ b/bin/varnishd/mgt/mgt_param_bits.c @@ -109,7 +109,6 @@ bit_tweak(struct vsb *vsb, uint8_t *p, unsigned l, const char *arg, static const char * const VSL_tags[256] = { # define SLTM(foo,flags,sdesc,ldesc) [SLT_##foo] = #foo, # include "tbl/vsl_tags.h" - NULL }; static int From phk at FreeBSD.org Tue Aug 6 11:57:09 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 6 Aug 2019 11:57:09 +0000 (UTC) Subject: [master] a17c1c999 Slightly better layout of generated C source for arg structs Message-ID: <20190806115709.C4505A24AA@lists.varnish-cache.org> commit a17c1c999b6d8d0d01ee5972b3f29f3237e3ba34 Author: Poul-Henning Kamp Date: Tue Aug 6 11:19:34 2019 +0000 Slightly better layout of generated C source for arg structs diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index b1ed9b64e..054b2ef56 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -570,7 +570,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, } if (sa != NULL) - e1 = vcc_mk_expr(rfmt, "%s(ctx%s,\v+ &(%s){\n", + e1 = vcc_mk_expr(rfmt, "%s(ctx%s,\v+\n&(%s)\v+ {\n", cfunc, extra, sa); else e1 = vcc_mk_expr(rfmt, "%s(ctx%s\v+", cfunc, extra); @@ -607,7 +607,7 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv, free(fa); } if (sa != NULL) { - *e = vcc_expr_edit(tl, e1->fmt, "\v1\n})\v-", e1, NULL); + *e = vcc_expr_edit(tl, e1->fmt, "\v1\v-\n}\v-\n)", e1, NULL); } else { *e = vcc_expr_edit(tl, e1->fmt, "\v1\v-\n)", e1, NULL); } From fgsch at lodoss.net Tue Aug 6 13:31:08 2019 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 6 Aug 2019 13:31:08 +0000 (UTC) Subject: [master] b62cff9b7 return miss is no longer available in hit Message-ID: <20190806133108.9E435A468D@lists.varnish-cache.org> commit b62cff9b772abc802df4379766658686fe8f3cb6 Author: Federico G. Schwindt Date: Tue Aug 6 14:29:20 2019 +0100 return miss is no longer available in hit Also update svg and dot files. Reported on irc by idl0r. diff --git a/doc/graphviz/cache_req_fsm.dot b/doc/graphviz/cache_req_fsm.dot index bf777fdcd..2b84550a2 100644 --- a/doc/graphviz/cache_req_fsm.dot +++ b/doc/graphviz/cache_req_fsm.dot @@ -121,7 +121,7 @@ digraph cache_req_fsm { ] lookup2 [ shape=record - label="{cnt_lookup:|{vcl_hit\{\}|{req.*|obj.*}}|{fail|deliver|pass|restart|synth|miss}}" + label="{cnt_lookup:|{vcl_hit\{\}|{req.*|obj.*}}|{fail|deliver|pass|restart|synth}}" ] } lookup:busy:s -> lookup:top:ne [label=" waitinglist", diff --git a/doc/graphviz/cache_req_fsm.svg b/doc/graphviz/cache_req_fsm.svg index 97da4c954..8c2315d7e 100644 --- a/doc/graphviz/cache_req_fsm.svg +++ b/doc/graphviz/cache_req_fsm.svg @@ -1,505 +1,573 @@ - - - + + cache_req_fsm - -cluster_backend - + + +cluster_backend + -acceptor - -Request received + +acceptor + +Request received -recv - -cnt_recv: - -vcl_recv{} - -req.* - -fail - -hash - -purge - -pass - -pipe - -restart - -synth - -vcl + +recv + +cnt_recv: + +vcl_recv{} + +req.* + +fail + +hash + +purge + +pass + +pipe + +restart + +synth + +vcl -acceptor->recv - - + +acceptor->recv + + -label_select - -LABEL + +label_select + +LABEL -label_select->recv - - + +label_select->recv + + -ESI_REQ - -ESI request + +ESI_REQ + +ESI request -ESI_REQ->recv - - + +ESI_REQ->recv + + -RESTART -RESTART + +RESTART +RESTART -restart - -cnt_restart: - -fail - -ok? - -max_restarts? + +restart + +cnt_restart: + +fail + +ok? + +max_restarts? -RESTART->restart - - + +RESTART->restart + + -hash - -cnt_recv: - -vcl_hash{} - -req.* - -lookup + +hash + +cnt_recv: + +vcl_hash{} + +req.* + +lookup -recv:hash->hash - - + +recv:hash->hash + + -recv:pipe->hash - - + +recv:pipe->hash + + -recv:pass->hash - - + +recv:pass->hash + + -recv:purge:s->hash - - + +recv:s->hash + + -vcl_label -switch to vcl -LABEL + +vcl_label +switch to vcl +LABEL -recv:vcl:s->vcl_label - - + +recv:s->vcl_label + + -SYNTH -SYNTH + +SYNTH +SYNTH -synth - -cnt_synth: - -vcl_synth{} - -req.* - -resp.* - -fail - -deliver - -restart + +synth + +cnt_synth: + +vcl_synth{} + +req.* + +resp.* + +fail + +deliver + +restart -SYNTH->synth - - + +SYNTH->synth + + -FAIL -FAIL + +FAIL +FAIL -FAIL->synth - - + +FAIL->synth + + -deliver - -cnt_deliver: - -Filter obj.->resp. - -vcl_deliver{} - -req.* - -resp.* - -fail - -restart - -deliver - -synth + +deliver + +cnt_deliver: + +Filter obj.->resp. + +vcl_deliver{} + +req.* + +resp.* + +fail + +restart + +deliver + +synth -V1D_Deliver - -V1D_Deliver + +V1D_Deliver + +V1D_Deliver -deliver:deliver:s->V1D_Deliver - - + +deliver:s->V1D_Deliver + + -deliver:deliver:s->V1D_Deliver - - + +deliver:s->V1D_Deliver + + -deliver:deliver:s->V1D_Deliver - - + +deliver:s->V1D_Deliver + + -DONE - -DONE + +DONE + +DONE -V1D_Deliver->DONE - - + +V1D_Deliver->DONE + + -stream - -stream? -body + +stream + +stream? +body -stream->V1D_Deliver - - + +stream->V1D_Deliver + + -synth:del:s->V1D_Deliver - - + +synth:s->V1D_Deliver + + -see backend graph -see backend graph + +see backend graph +see backend graph -BGFETCH - -BGFETCH + +BGFETCH + +BGFETCH -FETCH - -FETCH + +FETCH + +FETCH -FETCH_DONE - -FETCH_DONE + +FETCH_DONE + +FETCH_DONE -FETCH->FETCH_DONE - - + +FETCH->FETCH_DONE + + -FETCH_FAIL - -FETCH_FAIL + +FETCH_FAIL + +FETCH_FAIL -FETCH->FETCH_FAIL - - + +FETCH->FETCH_FAIL + + -FETCH_DONE->deliver - - + +FETCH_DONE->deliver + + -FETCH_DONE->deliver - - + +FETCH_DONE->deliver + + -FETCH_FAIL->synth - - + +FETCH_FAIL->synth + + -lookup2 - -cnt_lookup: - -vcl_hit{} - -req.* - -obj.* - -fail - -deliver - -pass - -restart - -synth - -miss + +lookup2 + +cnt_lookup: + +vcl_hit{} + +req.* + +obj.* + +fail + +deliver + +pass + +restart + +synth -lookup2:deliver:s->deliver:n - - + +lookup2:s->deliver:n + + -lookup2:deliver:s->BGFETCH - - -parallel -if obj expired + +lookup2:s->BGFETCH + + +parallel +if obj expired -pass - -cnt_pass: - -vcl_pass{} - -req.* - -fail - -fetch - -synth - -restart + +pass + +cnt_pass: + +vcl_pass{} + +req.* + +fail + +fetch + +synth + +restart -lookup2:pass:s->pass - - + +lookup2:s->pass + + -lookup - -cnt_lookup: - -hash lookup - -hit? - -miss? - -hit-for-miss? - -hit-for-pass? - -busy? + +lookup + +cnt_lookup: + +hash lookup + +hit? + +miss? + +hit-for-miss? + +hit-for-pass? + +busy? -lookup:h:s->lookup2 - - + +lookup:s->lookup2 + + -lookup:busy:s->lookup:top:ne - - - waitinglist + +lookup:s->lookup:ne + + + waitinglist -miss - -cnt_miss: - -vcl_miss{} - -req.* - -fail - -fetch - -synth - -restart - -pass + +miss + +cnt_miss: + +vcl_miss{} + +req.* + +fail + +fetch + +synth + +restart + +pass -lookup:miss:s->miss - - + +lookup:s->miss + + -lookup:hfm:s->miss - - - req. - is_hitmiss + +lookup:s->miss + + + req. + is_hitmiss -lookup:hfp:s->pass - - - req. - is_hitpass + +lookup:s->pass + + + req. + is_hitpass -miss:fetch:s->FETCH - - + +miss:s->FETCH + + -miss:pass:s->pass - - + +miss:s->pass + + -pass:fetch:s->FETCH - - + +pass:s->FETCH + + -pipe - -cnt_pipe: - -filter req.*->bereq.* - -vcl_pipe{} - -req.* - -bereq.* - -fail - -pipe - -synth + +pipe + +cnt_pipe: + +filter req.*->bereq.* + +vcl_pipe{} + +req.* + +bereq.* + +fail + +pipe + +synth -pipe_do - -send bereq, -copy bytes until close + +pipe_do + +send bereq, +copy bytes until close -pipe:pipe->pipe_do - - + +pipe:pipe->pipe_do + + -pipe_do->DONE - - + +pipe_do->DONE + + -restart:ok:s->recv - - + +restart:s->recv + + -err_restart -SYNTH + +err_restart +SYNTH -restart:max:s->err_restart - - + +restart:s->err_restart + + -hash:lookup:w->lookup - - + +hash:w->lookup + + -hash:lookup:s->pass - - + +hash:s->pass + + -hash:lookup:e->pipe - - + +hash:e->pipe + + -purge - -cnt_purge: - -vcl_purge{} - -req.* - -fail - -synth - -restart + +purge + +cnt_purge: + +vcl_purge{} + +req.* + +fail + +synth + +restart -hash:lookup:s->purge:top:n - - + +hash:s->purge:n + + diff --git a/doc/sphinx/users-guide/vcl-built-in-subs.rst b/doc/sphinx/users-guide/vcl-built-in-subs.rst index 8d99efd59..94f62c9da 100644 --- a/doc/sphinx/users-guide/vcl-built-in-subs.rst +++ b/doc/sphinx/users-guide/vcl-built-in-subs.rst @@ -267,10 +267,6 @@ with one of the following keywords: ``pass`` see `pass`_ - ``miss`` - Synchronously refresh the object from the backend despite the - cache hit. Control will eventually pass to :ref:`vcl_miss`. - ``deliver`` Deliver the object. If it is stale, a background fetch to refresh it is triggered. From guillaume at varnish-software.com Tue Aug 6 16:55:08 2019 From: guillaume at varnish-software.com (Guillaume Quintard) Date: Tue, 6 Aug 2019 16:55:08 +0000 (UTC) Subject: [master] d760826b4 Include headers to compile on musl Message-ID: <20190806165508.35EA1A89FB@lists.varnish-cache.org> commit d760826b43b7e35975437c7c6d069450d8caf511 Author: Guillaume Quintard Date: Tue Aug 6 09:53:14 2019 -0700 Include headers to compile on musl diff --git a/lib/libvarnish/vte.c b/lib/libvarnish/vte.c index f71a147b8..fa6be82be 100644 --- a/lib/libvarnish/vte.c +++ b/lib/libvarnish/vte.c @@ -31,6 +31,7 @@ #include #include +#include /* for MUSL (ssize_t) */ #include "vdef.h" #include "vqueue.h" From phk at FreeBSD.org Wed Aug 7 08:23:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 08:23:11 +0000 (UTC) Subject: [master] 6125e1426 Remove the detour over a C-enum for the shard "by" argument. Message-ID: <20190807082311.319E363889@lists.varnish-cache.org> commit 6125e14266babadb6668524c7cab78ba73b6967d Author: Poul-Henning Kamp Date: Wed Aug 7 07:57:17 2019 +0000 Remove the detour over a C-enum for the shard "by" argument. Also collect in one single place that HASH is the default. diff --git a/bin/varnishtest/tests/d00030.vtc b/bin/varnishtest/tests/d00030.vtc index 497b3c7cf..3c29f33e7 100644 --- a/bin/varnishtest/tests/d00030.vtc +++ b/bin/varnishtest/tests/d00030.vtc @@ -111,7 +111,7 @@ varnish v1 -errvcl {key and key_blob arguments are invalid with by=URL} { } } -varnish v1 -errvcl {key and key_blob arguments are invalid with by=HASH (default)} { +varnish v1 -errvcl {key and key_blob arguments are invalid with by=HASH} { import directors; import blob; diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h index 021fa1257..56d2e6633 100644 --- a/lib/libvmod_directors/shard_dir.h +++ b/lib/libvmod_directors/shard_dir.h @@ -27,13 +27,6 @@ * SUCH DAMAGE. */ -enum by_e { - _BY_E_INVALID = 0, -#define VMODENUM(x) BY_ ## x, -#include "tbl_by.h" - _BY_E_MAX -}; - enum healthy_e { _HEALTHY_E_INVALID = 0, #define VMODENUM(x) x, diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c index 3fd7fc605..a940ff346 100644 --- a/lib/libvmod_directors/vmod_shard.c +++ b/lib/libvmod_directors/vmod_shard.c @@ -127,7 +127,7 @@ struct vmod_directors_shard_param { enum vmod_directors_shard_param_scope scope; /* parameters */ - enum by_e by; + VCL_ENUM by; enum healthy_e healthy; uint32_t mask; VCL_BOOL rampup; @@ -144,13 +144,14 @@ static const struct vmod_directors_shard_param shard_param_default = { .scope = SCOPE_VMOD, .mask = arg_mask_param_, - .by = BY_HASH, .healthy = CHOSEN, .rampup = 1, .alt = 0, .warmup = -1, }; +#define default_by(ptr) (ptr == NULL ? VENUM(HASH) : ptr) + static struct vmod_directors_shard_param * shard_param_stack(struct vmod_directors_shard_param *p, const struct vmod_directors_shard_param *pa, const char *who); @@ -181,14 +182,6 @@ struct vmod_directors_shard { VCL_BACKEND dir; }; -static enum by_e -parse_by_e(VCL_ENUM e) -{ -#define VMODENUM(n) if (e == VENUM(n)) return(BY_ ## n); -#include "tbl_by.h" - WRONG("illegal by enum"); -} - static enum healthy_e parse_healthy_e(VCL_ENUM e) { @@ -205,12 +198,6 @@ parse_resolve_e(VCL_ENUM e) WRONG("illegal resolve enum"); } -static const char * const by_str[_BY_E_MAX] = { - [_BY_E_INVALID] = "*INVALID*", -#define VMODENUM(n) [BY_ ## n] = #n, -#include "tbl_by.h" -}; - static const char * const healthy_str[_HEALTHY_E_MAX] = { [_HEALTHY_E_INVALID] = "*INVALID*", #define VMODENUM(n) [n] = #n, @@ -393,15 +380,15 @@ shard_get_key(VRT_CTX, const struct vmod_directors_shard_param *p) struct http *http; struct strands s[1]; const char *sp[1]; + VCL_ENUM by = default_by(p->by); - switch (p->by) { - case BY_HASH: - if (ctx->bo) { - CHECK_OBJ(ctx->bo, BUSYOBJ_MAGIC); - return (vbe32dec(ctx->bo->digest)); - } - /* FALLTHROUGH */ - case BY_URL: + if (by == VENUM(KEY) || by == VENUM(BLOB)) + return (p->key); + if (by == VENUM(HASH) && ctx->bo != NULL) { + CHECK_OBJ(ctx->bo, BUSYOBJ_MAGIC); + return (vbe32dec(ctx->bo->digest)); + } + if (by == VENUM(HASH) || by == VENUM(URL)) { if (ctx->http_req) { AN(http = ctx->http_req); } else { @@ -412,12 +399,8 @@ shard_get_key(VRT_CTX, const struct vmod_directors_shard_param *p) s->n = 1; s->p = sp; return (sharddir_sha256(s)); - case BY_KEY: - case BY_BLOB: - return (p->key); - default: - WRONG("by enum"); } + WRONG("by enum"); } /* @@ -439,7 +422,7 @@ shard_param_merge(struct vmod_directors_shard_param *to, if ((to->mask & arg_by) == 0 && (from->mask & arg_by) != 0) { to->by = from->by; - if (from->by == BY_KEY || from->by == BY_BLOB) + if (from->by == VENUM(KEY) || from->by == VENUM(BLOB)) to->key = from->key; } @@ -529,7 +512,6 @@ shard_param_args(VRT_CTX, uint32_t args, VCL_ENUM by_s, VCL_INT key_int, VCL_BLOB key_blob, VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy_s) { - enum by_e by; enum healthy_e healthy; CHECK_OBJ_NOTNULL(p, VMOD_SHARD_SHARD_PARAM_MAGIC); @@ -537,73 +519,57 @@ shard_param_args(VRT_CTX, assert((args & ~arg_mask_set_) == 0); - by = (args & arg_by) ? parse_by_e(by_s) : BY_HASH; + if (!(args & arg_by)) + by_s = NULL; + by_s = default_by(by_s); healthy = (args & arg_healthy) ? parse_healthy_e(healthy_s) : CHOSEN; /* by_s / key_int / key_blob */ - if (args & arg_by) { - switch (by) { - case BY_KEY: - if ((args & arg_key) == 0) { - VRT_fail(ctx, "%s %s: " - "missing key argument with by=%s", - who, p->vcl_name, by_s); - return (NULL); - } - if (key_int < 0 || key_int > UINT32_MAX) { - VRT_fail(ctx, "%s %s: " - "invalid key argument %jd with by=%s", - who, p->vcl_name, - (intmax_t)key_int, by_s); - return (NULL); - } - assert(key_int >= 0); - assert(key_int <= UINT32_MAX); - p->key = (uint32_t)key_int; - break; - case BY_BLOB: - if ((args & arg_key_blob) == 0) { - VRT_fail(ctx, "%s %s: " - "missing key_blob argument with by=%s", - who, p->vcl_name, by_s); - return (NULL); - } - if (key_blob == NULL || key_blob->len == 0 || - key_blob->blob == NULL) { - sharddir_err(ctx, SLT_Error, "%s %s: " - "by=BLOB but no or empty key_blob " - "- using key 0", - who, p->vcl_name); - p->key = 0; - } else - p->key = shard_blob_key(key_blob); - break; - case BY_HASH: - case BY_URL: - if (args & (arg_key|arg_key_blob)) { - VRT_fail(ctx, "%s %s: " - "key and key_blob arguments are " - "invalid with by=%s", - who, p->vcl_name, by_s); - return (NULL); - } - break; - default: - WRONG("by enum"); + if (by_s == VENUM(KEY)) { + if ((args & arg_key) == 0) { + VRT_fail(ctx, "%s %s: " + "missing key argument with by=%s", + who, p->vcl_name, by_s); + return (NULL); } - p->by = by; - } else { - /* (args & arg_by) == 0 */ - p->by = BY_HASH; - + if (key_int < 0 || key_int > UINT32_MAX) { + VRT_fail(ctx, "%s %s: " + "invalid key argument %jd with by=%s", + who, p->vcl_name, + (intmax_t)key_int, by_s); + return (NULL); + } + assert(key_int >= 0); + assert(key_int <= UINT32_MAX); + p->key = (uint32_t)key_int; + } else if (by_s == VENUM(BLOB)) { + if ((args & arg_key_blob) == 0) { + VRT_fail(ctx, "%s %s: " + "missing key_blob argument with by=%s", + who, p->vcl_name, by_s); + return (NULL); + } + if (key_blob == NULL || key_blob->len == 0 || + key_blob->blob == NULL) { + sharddir_err(ctx, SLT_Error, "%s %s: " + "by=BLOB but no or empty key_blob " + "- using key 0", + who, p->vcl_name); + p->key = 0; + } else + p->key = shard_blob_key(key_blob); + } else if (by_s == VENUM(HASH) || by_s == VENUM(URL)) { if (args & (arg_key|arg_key_blob)) { VRT_fail(ctx, "%s %s: " "key and key_blob arguments are " - "invalid with by=HASH (default)", - who, p->vcl_name); + "invalid with by=%s", + who, p->vcl_name, by_s); return (NULL); } + } else { + WRONG("by enum"); } + p->by = by_s; if (args & arg_alt) { if (alt < 0) { @@ -1040,8 +1006,7 @@ vmod_shard_param_get_by(VRT_CTX, pp = vmod_shard_param_read(ctx, p, p, &pstk, "shard_param.get_by()"); if (pp == NULL) return (NULL); - assert(pp->by > _BY_E_INVALID); - return (by_str[pp->by]); + return (default_by(pp->by)); } VCL_INT v_matchproto_(td_directors_shard_param_get_key) From phk at FreeBSD.org Wed Aug 7 08:23:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 08:23:11 +0000 (UTC) Subject: [master] 56d9cf802 Eliminate the detour over C-enum for 'resolve' argument Message-ID: <20190807082311.479186388C@lists.varnish-cache.org> commit 56d9cf802616fcffa21b708d0120fcd4f1ba2970 Author: Poul-Henning Kamp Date: Wed Aug 7 08:06:45 2019 +0000 Eliminate the detour over C-enum for 'resolve' argument diff --git a/lib/libvmod_directors/Makefile.am b/lib/libvmod_directors/Makefile.am index 706e24a30..73fccf7d5 100644 --- a/lib/libvmod_directors/Makefile.am +++ b/lib/libvmod_directors/Makefile.am @@ -13,9 +13,7 @@ libvmod_directors_la_SOURCES = \ shard_cfg.h \ shard_dir.c \ shard_dir.h \ - tbl_by.h \ - tbl_healthy.h \ - tbl_resolve.h + tbl_healthy.h # Use vmodtool.py generated automake boilerplate include $(srcdir)/automake_boilerplate.am diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h index 56d2e6633..d67b6a7bf 100644 --- a/lib/libvmod_directors/shard_dir.h +++ b/lib/libvmod_directors/shard_dir.h @@ -34,11 +34,6 @@ enum healthy_e { _HEALTHY_E_MAX }; -enum resolve_e { -#define VMODENUM(x) x, -#include "tbl_resolve.h" -}; - struct vbitmap; struct shard_circlepoint { diff --git a/lib/libvmod_directors/tbl_by.h b/lib/libvmod_directors/tbl_by.h deleted file mode 100644 index 97cb8287b..000000000 --- a/lib/libvmod_directors/tbl_by.h +++ /dev/null @@ -1,5 +0,0 @@ -VMODENUM(HASH) -VMODENUM(URL) -VMODENUM(KEY) -VMODENUM(BLOB) -#undef VMODENUM diff --git a/lib/libvmod_directors/tbl_resolve.h b/lib/libvmod_directors/tbl_resolve.h deleted file mode 100644 index c7c6d825d..000000000 --- a/lib/libvmod_directors/tbl_resolve.h +++ /dev/null @@ -1,3 +0,0 @@ -VMODENUM(NOW) -VMODENUM(LAZY) -#undef VMODENUM diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c index a940ff346..906214551 100644 --- a/lib/libvmod_directors/vmod_shard.c +++ b/lib/libvmod_directors/vmod_shard.c @@ -190,14 +190,6 @@ parse_healthy_e(VCL_ENUM e) WRONG("illegal healthy enum"); } -static enum resolve_e -parse_resolve_e(VCL_ENUM e) -{ -#define VMODENUM(n) if (e == VENUM(n)) return(n); -#include "tbl_resolve.h" - WRONG("illegal resolve enum"); -} - static const char * const healthy_str[_HEALTHY_E_MAX] = { [_HEALTHY_E_INVALID] = "*INVALID*", #define VMODENUM(n) [n] = #n, @@ -608,7 +600,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, struct vmod_directors_shard_param pstk; struct vmod_directors_shard_param *pp = NULL; const struct vmod_directors_shard_param *ppt; - enum resolve_e resolve; + VCL_ENUM resolve; uint32_t args = shard_backendarg_mask_(a); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); @@ -616,14 +608,13 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, assert((args & ~arg_mask_) == 0); if (args & arg_resolve) - resolve = parse_resolve_e(a->resolve); + resolve = a->resolve; else if (ctx->method & VCL_MET_TASK_H) - resolve = LAZY; + resolve = VENUM(LAZY); else - resolve = NOW; + resolve = VENUM(NOW); - switch (resolve) { - case LAZY: + if (resolve == VENUM(LAZY)) { if ((args & ~arg_resolve) == 0) { AN(vshard->dir); return (vshard->dir); @@ -643,8 +634,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, if (pp == NULL) return (NULL); pp->vcl_name = vshard->shardd->name; - break; - case NOW: + } else if (resolve == VENUM(NOW)) { if (ctx->method & VCL_MET_TASK_H) { VRT_fail(ctx, "shard .backend resolve=NOW can not be " @@ -653,8 +643,7 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, } pp = shard_param_stack(&pstk, vshard->shardd->param, vshard->shardd->name); - break; - default: + } else { WRONG("resolve enum"); } @@ -675,10 +664,10 @@ vmod_shard_backend(VRT_CTX, struct vmod_directors_shard *vshard, if (pp == NULL) return (NULL); - if (resolve == LAZY) + if (resolve == VENUM(LAZY)) return (vshard->dir); - assert(resolve == NOW); + assert(resolve == VENUM(NOW)); shard_param_merge(pp, pp->defaults); return (sharddir_pick_be(ctx, vshard->shardd, shard_get_key(ctx, pp), pp->alt, pp->warmup, From phk at FreeBSD.org Wed Aug 7 08:23:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 08:23:11 +0000 (UTC) Subject: [master] d00de5d7c Also eliminat C-enum detour for 'healthy' arguments Message-ID: <20190807082311.61B6F63891@lists.varnish-cache.org> commit d00de5d7ca7e8aa8653de26e77bc4c9f66cec759 Author: Poul-Henning Kamp Date: Wed Aug 7 08:22:27 2019 +0000 Also eliminat C-enum detour for 'healthy' arguments diff --git a/lib/libvmod_directors/Makefile.am b/lib/libvmod_directors/Makefile.am index 73fccf7d5..646357100 100644 --- a/lib/libvmod_directors/Makefile.am +++ b/lib/libvmod_directors/Makefile.am @@ -12,8 +12,7 @@ libvmod_directors_la_SOURCES = \ shard_cfg.c \ shard_cfg.h \ shard_dir.c \ - shard_dir.h \ - tbl_healthy.h + shard_dir.h # Use vmodtool.py generated automake boilerplate include $(srcdir)/automake_boilerplate.am diff --git a/lib/libvmod_directors/shard_dir.c b/lib/libvmod_directors/shard_dir.c index 4c707dc5e..db2c5be78 100644 --- a/lib/libvmod_directors/shard_dir.c +++ b/lib/libvmod_directors/shard_dir.c @@ -43,6 +43,7 @@ #include "vsha256.h" #include "vend.h" +#include "vcc_if.h" #include "shard_dir.h" struct shard_be_info { @@ -323,7 +324,7 @@ sharddir_any_healthy(VRT_CTX, struct sharddir *shardd, VCL_TIME *changed) static VCL_BACKEND sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, - VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, enum healthy_e healthy, + VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy, struct shard_state *state) { VCL_BACKEND be; @@ -345,7 +346,8 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, key, state->idx, shardd->hashcircle[state->idx].host); if (alt > 0) { - if (shard_next(state, alt - 1, healthy == ALL ? 1 : 0) == -1) { + if (shard_next(state, alt - 1, + healthy == VENUM(ALL) ? 1 : 0) == -1) { if (state->previous.hostid != -1) { be = sharddir_backend(shardd, state->previous.hostid); @@ -356,7 +358,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, } } - if (shard_next(state, 0, healthy == IGNORE ? 0 : 1) == -1) { + if (shard_next(state, 0, healthy == VENUM(IGNORE) ? 0 : 1) == -1) { if (state->previous.hostid != -1) { be = sharddir_backend(shardd, state->previous.hostid); AN(be); @@ -372,7 +374,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, warmup = shardd->warmup; /* short path for cases we dont want ramup/warmup or can't */ - if (alt > 0 || healthy == IGNORE || (!rampup && warmup == 0) || + if (alt > 0 || healthy == VENUM(IGNORE) || (!rampup && warmup == 0) || shard_next(state, 0, 1) == -1) return (be); @@ -415,7 +417,7 @@ sharddir_pick_be_locked(VRT_CTX, const struct sharddir *shardd, uint32_t key, VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *shardd, uint32_t key, VCL_INT alt, - VCL_REAL warmup, VCL_BOOL rampup, enum healthy_e healthy) + VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy) { VCL_BACKEND be; struct shard_state state[1]; diff --git a/lib/libvmod_directors/shard_dir.h b/lib/libvmod_directors/shard_dir.h index d67b6a7bf..6d70a7603 100644 --- a/lib/libvmod_directors/shard_dir.h +++ b/lib/libvmod_directors/shard_dir.h @@ -27,13 +27,6 @@ * SUCH DAMAGE. */ -enum healthy_e { - _HEALTHY_E_INVALID = 0, -#define VMODENUM(x) x, -#include "tbl_healthy.h" - _HEALTHY_E_MAX -}; - struct vbitmap; struct shard_circlepoint { @@ -116,7 +109,7 @@ void sharddir_wrlock(struct sharddir *shardd); void sharddir_unlock(struct sharddir *shardd); VCL_BOOL sharddir_any_healthy(VRT_CTX, struct sharddir *, VCL_TIME *); VCL_BACKEND sharddir_pick_be(VRT_CTX, struct sharddir *, uint32_t, VCL_INT, - VCL_REAL, VCL_BOOL, enum healthy_e); + VCL_REAL, VCL_BOOL, VCL_ENUM healthy); /* in shard_cfg.c */ void shardcfg_delete(const struct sharddir *shardd); diff --git a/lib/libvmod_directors/tbl_healthy.h b/lib/libvmod_directors/tbl_healthy.h deleted file mode 100644 index 7be0e44a7..000000000 --- a/lib/libvmod_directors/tbl_healthy.h +++ /dev/null @@ -1,4 +0,0 @@ -VMODENUM(CHOSEN) -VMODENUM(IGNORE) -VMODENUM(ALL) -#undef VMODENUM diff --git a/lib/libvmod_directors/vmod_shard.c b/lib/libvmod_directors/vmod_shard.c index 906214551..a5e07e14e 100644 --- a/lib/libvmod_directors/vmod_shard.c +++ b/lib/libvmod_directors/vmod_shard.c @@ -128,7 +128,7 @@ struct vmod_directors_shard_param { /* parameters */ VCL_ENUM by; - enum healthy_e healthy; + VCL_ENUM healthy; uint32_t mask; VCL_BOOL rampup; VCL_INT alt; @@ -144,13 +144,13 @@ static const struct vmod_directors_shard_param shard_param_default = { .scope = SCOPE_VMOD, .mask = arg_mask_param_, - .healthy = CHOSEN, .rampup = 1, .alt = 0, .warmup = -1, }; #define default_by(ptr) (ptr == NULL ? VENUM(HASH) : ptr) +#define default_healthy(ptr) (ptr == NULL ? VENUM(CHOSEN) : ptr) static struct vmod_directors_shard_param * shard_param_stack(struct vmod_directors_shard_param *p, @@ -182,20 +182,6 @@ struct vmod_directors_shard { VCL_BACKEND dir; }; -static enum healthy_e -parse_healthy_e(VCL_ENUM e) -{ -#define VMODENUM(n) if (e == VENUM(n)) return(n); -#include "tbl_healthy.h" - WRONG("illegal healthy enum"); -} - -static const char * const healthy_str[_HEALTHY_E_MAX] = { - [_HEALTHY_E_INVALID] = "*INVALID*", -#define VMODENUM(n) [n] = #n, -#include "tbl_healthy.h" -}; - static void shard__assert(void) { @@ -504,7 +490,6 @@ shard_param_args(VRT_CTX, uint32_t args, VCL_ENUM by_s, VCL_INT key_int, VCL_BLOB key_blob, VCL_INT alt, VCL_REAL warmup, VCL_BOOL rampup, VCL_ENUM healthy_s) { - enum healthy_e healthy; CHECK_OBJ_NOTNULL(p, VMOD_SHARD_SHARD_PARAM_MAGIC); AN(p->vcl_name); @@ -514,7 +499,6 @@ shard_param_args(VRT_CTX, if (!(args & arg_by)) by_s = NULL; by_s = default_by(by_s); - healthy = (args & arg_healthy) ? parse_healthy_e(healthy_s) : CHOSEN; /* by_s / key_int / key_blob */ if (by_s == VENUM(KEY)) { @@ -587,7 +571,7 @@ shard_param_args(VRT_CTX, p->rampup = !!rampup; if (args & arg_healthy) - p->healthy = healthy; + p->healthy = healthy_s; p->mask = args & arg_mask_param_; return (p); @@ -1063,9 +1047,7 @@ vmod_shard_param_get_healthy(VRT_CTX, "shard_param.get_healthy()"); if (pp == NULL) return (NULL); - assert(pp->healthy > _HEALTHY_E_INVALID); - return (healthy_str[pp->healthy]); - + return (default_healthy(pp->healthy)); } static const struct vmod_directors_shard_param * From phk at FreeBSD.org Wed Aug 7 08:23:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 08:23:11 +0000 (UTC) Subject: [master] ee31c0b95 Merge branch 'master' of github.com:varnishcache/varnish-cache Message-ID: <20190807082311.7E30763896@lists.varnish-cache.org> commit ee31c0b95131fbf4d99034eaad2afc58aeea90f0 Merge: d00de5d7c d760826b4 Author: Poul-Henning Kamp Date: Wed Aug 7 08:22:46 2019 +0000 Merge branch 'master' of github.com:varnishcache/varnish-cache From phk at FreeBSD.org Wed Aug 7 09:10:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 09:10:11 +0000 (UTC) Subject: [master] 222fd882f Remove (now) unused includes. Message-ID: <20190807091011.87B7864E67@lists.varnish-cache.org> commit 222fd882fae374f70cdce44f408d7639c584fe3d Author: Poul-Henning Kamp Date: Wed Aug 7 08:38:18 2019 +0000 Remove (now) unused includes. diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 8078ea645..2a411a97a 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -42,7 +42,6 @@ #include "vct.h" #include "vfil.h" -#include "vgz.h" #include "vnum.h" #include "vrnd.h" #include "vtcp.h" diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c index d915b7e51..4f76c27cf 100644 --- a/bin/varnishtest/vtc_http2.c +++ b/bin/varnishtest/vtc_http2.c @@ -43,7 +43,6 @@ #include "vtc_http.h" #include "vfil.h" -#include "vgz.h" #include "hpack.h" #include "vend.h" From phk at FreeBSD.org Wed Aug 7 09:10:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 09:10:11 +0000 (UTC) Subject: [master] bbff727de Merge from VTEST: Message-ID: <20190807091011.9B61964E6D@lists.varnish-cache.org> commit bbff727de37a20c56de1be18a13d2a81b5af7191 Author: Poul-Henning Kamp Date: Wed Aug 7 08:47:37 2019 +0000 Merge from VTEST: Author: Fr?d?ric L?caille Date: Mon Jul 15 15:20:07 2019 +0200 Open and close a TCP socket to simulate an unreachable server. This is done for each haproxy instance. The socket address (resp. port) may be referenced by ${_closed_addr} (resp. ${_closed_port}) variable where is the haproxy instance name. diff --git a/bin/varnishtest/vtc_haproxy.c b/bin/varnishtest/vtc_haproxy.c index ccd0fba80..b24af08ca 100644 --- a/bin/varnishtest/vtc_haproxy.c +++ b/bin/varnishtest/vtc_haproxy.c @@ -89,6 +89,7 @@ struct haproxy { char *workdir; struct vsb *msgs; + char closed_sock[256]; /* Closed TCP socket */ VTAILQ_HEAD(,envar) envars; }; @@ -494,6 +495,9 @@ haproxy_new(const char *name) struct haproxy *h; struct vsb *vsb; char buf[PATH_MAX]; + int closed_sock; + char addr[128], port[128]; + const char *err; ALLOC_OBJ(h, HAPROXY_MAGIC); AN(h); @@ -523,6 +527,21 @@ haproxy_new(const char *name) h->cfg_fn = strdup(buf); AN(h->cfg_fn); + /* Create a new TCP socket to reserve an IP:port and close it asap. + * May be useful to simulate an unreachable server. + */ + bprintf(h->closed_sock, "%s_closed", h->name); + closed_sock = VTCP_listen_on("localhost:0", NULL, 100, &err); + if (err != NULL) + vtc_fatal(h->vl, + "Create listen socket failed: %s", err); + assert(closed_sock > 0); + VTCP_myname(closed_sock, addr, sizeof addr, port, sizeof port); + macro_def(h->vl, h->closed_sock, "sock", "%s %s", addr, port); + macro_def(h->vl, h->closed_sock, "addr", "%s", addr); + macro_def(h->vl, h->closed_sock, "port", "%s", port); + VTCP_close(&closed_sock); + h->cli = haproxy_cli_new(h); AN(h->cli); From phk at FreeBSD.org Wed Aug 7 09:10:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 09:10:11 +0000 (UTC) Subject: [master] ea6fb878b Be consistent about bodylen being a long Message-ID: <20190807091011.B714964E75@lists.varnish-cache.org> commit ea6fb878bb1e5b6d7bef2fa404ec16fa14aaf700 Author: Poul-Henning Kamp Date: Wed Aug 7 08:59:28 2019 +0000 Be consistent about bodylen being a long diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 61c8dcb2d..2a8480b14 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -131,8 +131,8 @@ void stop_h2(struct http *hp); void b64_settings(const struct http *hp, const char *s); /* vtc_gzip.c */ -void vtc_gzip(struct http *, const char *, char **, unsigned *); -void vtc_gunzip(struct http *, char *, unsigned *); +void vtc_gzip(const struct http *, const char *, char **, unsigned *); +void vtc_gunzip(struct http *, char *, long *); /* vtc_subr.c */ struct vsb *vtc_hex_to_bin(struct vtclog *vl, const char *arg); diff --git a/bin/varnishtest/vtc_gzip.c b/bin/varnishtest/vtc_gzip.c index 9eeb67a51..a0b35bc1a 100644 --- a/bin/varnishtest/vtc_gzip.c +++ b/bin/varnishtest/vtc_gzip.c @@ -26,6 +26,8 @@ * SUCH DAMAGE. */ +#include "config.h" + #include #include #include @@ -38,7 +40,7 @@ void -vtc_gzip(struct http *hp, const char *input, char **body, unsigned *bodylen) +vtc_gzip(const struct http *hp, const char *input, char **body, unsigned *bodylen) { unsigned l; z_stream vz; @@ -82,7 +84,7 @@ vtc_gzip(struct http *hp, const char *input, char **body, unsigned *bodylen) } void -vtc_gunzip(struct http *hp, char *body, unsigned *bodylen) +vtc_gunzip(struct http *hp, char *body, long *bodylen) { z_stream vz; char *p; @@ -111,9 +113,9 @@ vtc_gunzip(struct http *hp, char *body, unsigned *bodylen) *bodylen = vz.total_out; memcpy(body, p, *bodylen); free(p); - vtc_log(hp->vl, 3, "new bodylen %u", *bodylen); + vtc_log(hp->vl, 3, "new bodylen %ld", *bodylen); vtc_dump(hp->vl, 4, "body", body, *bodylen); - bprintf(hp->bodylen, "%u", *bodylen); + bprintf(hp->bodylen, "%ld", *bodylen); #ifdef VGZ_EXTENSIONS vtc_log(hp->vl, 4, "startbit = %ju %ju/%ju", (uintmax_t)vz.start_bit, diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 2a411a97a..6bbbb79fd 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -763,7 +763,7 @@ cmd_http_gunzip(CMD_ARGS) (void)vl; CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); - vtc_gunzip(hp, hp->body, (unsigned *)&hp->bodyl); + vtc_gunzip(hp, hp->body, &hp->bodyl); } /********************************************************************** diff --git a/bin/varnishtest/vtc_http.h b/bin/varnishtest/vtc_http.h index d9241ff2b..0091eaa1a 100644 --- a/bin/varnishtest/vtc_http.h +++ b/bin/varnishtest/vtc_http.h @@ -47,7 +47,7 @@ struct http { char *rem_port; char *rem_path; char *body; - unsigned bodyl; + long bodyl; char bodylen[20]; char chunklen[20]; diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c index 4f76c27cf..0c88ba5c7 100644 --- a/bin/varnishtest/vtc_http2.c +++ b/bin/varnishtest/vtc_http2.c @@ -2484,7 +2484,7 @@ cmd_gunzip(CMD_ARGS) hp = s->hp; CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); - vtc_gunzip(s->hp, s->body, (unsigned *)&s->bodylen); + vtc_gunzip(s->hp, s->body, &s->bodylen); } /* SECTION: stream.spec.write_body From phk at FreeBSD.org Wed Aug 7 09:10:11 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 7 Aug 2019 09:10:11 +0000 (UTC) Subject: [master] 739e4d58e Also be consistent about bodylen being long on gzip side Message-ID: <20190807091011.D579764E7D@lists.varnish-cache.org> commit 739e4d58e417a492e28fab5bd39b12fc46aaced1 Author: Poul-Henning Kamp Date: Wed Aug 7 09:08:26 2019 +0000 Also be consistent about bodylen being long on gzip side diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index 2a8480b14..e1f167daa 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -131,7 +131,7 @@ void stop_h2(struct http *hp); void b64_settings(const struct http *hp, const char *s); /* vtc_gzip.c */ -void vtc_gzip(const struct http *, const char *, char **, unsigned *); +void vtc_gzip(const struct http *, const char *, char **, long *); void vtc_gunzip(struct http *, char *, long *); /* vtc_subr.c */ diff --git a/bin/varnishtest/vtc_gzip.c b/bin/varnishtest/vtc_gzip.c index a0b35bc1a..ab42c68c6 100644 --- a/bin/varnishtest/vtc_gzip.c +++ b/bin/varnishtest/vtc_gzip.c @@ -40,7 +40,7 @@ void -vtc_gzip(const struct http *hp, const char *input, char **body, unsigned *bodylen) +vtc_gzip(const struct http *hp, const char *input, char **body, long *bodylen) { unsigned l; z_stream vz; diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 6bbbb79fd..b8b9de4a7 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -774,7 +774,7 @@ static char* const * http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, char *body, unsigned nohost) { - int bodylen = 0; + long bodylen = 0; char *b, *c; char *nullbody; char *m; @@ -847,7 +847,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, assert(body == nullbody); free(body); b = synth_body(av[1], 1); - vtc_gzip(hp, b, &body, (unsigned *)&bodylen); + vtc_gzip(hp, b, &body, &bodylen); free(b); VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl); // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen); @@ -855,7 +855,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, } else if (!strcmp(*av, "-gzipbody")) { assert(body == nullbody); free(body); - vtc_gzip(hp, av[1], &body, (unsigned *)&bodylen); + vtc_gzip(hp, av[1], &body, &bodylen); VSB_printf(hp->vsb, "Content-Encoding: gzip%s", nl); // vtc_hexdump(hp->vl, 4, "gzip", (void*)body, bodylen); av++; @@ -869,7 +869,7 @@ http_tx_parse_args(char * const *av, struct vtclog *vl, struct http *hp, free(m); } if (body != NULL && !nolen) - VSB_printf(hp->vsb, "Content-Length: %d%s", bodylen, nl); + VSB_printf(hp->vsb, "Content-Length: %ld%s", bodylen, nl); VSB_cat(hp->vsb, nl); if (body != NULL) { VSB_bcat(hp->vsb, body, bodylen); diff --git a/bin/varnishtest/vtc_http2.c b/bin/varnishtest/vtc_http2.c index 0c88ba5c7..0e7bdea7f 100644 --- a/bin/varnishtest/vtc_http2.c +++ b/bin/varnishtest/vtc_http2.c @@ -1381,7 +1381,7 @@ cmd_tx11obj(CMD_ARGS) int method_done = 1; int path_done = 1; int scheme_done = 1; - int bodylen = 0; + long bodylen = 0; ssize_t len; uint32_t stid = 0, pstid; uint32_t weight = 16; @@ -1550,8 +1550,7 @@ cmd_tx11obj(CMD_ARGS) } else if (!strcmp(*av, "-gzipbody")) { AZ(body); - vtc_gzip(s->hp, av[1], &body, - (unsigned *)&bodylen); + vtc_gzip(s->hp, av[1], &body, &bodylen); AN(body); ENC(hdr, ":content-encoding", "gzip"); f.flags &= ~END_STREAM; @@ -1560,8 +1559,7 @@ cmd_tx11obj(CMD_ARGS) else if (!strcmp(*av, "-gziplen")) { AZ(body); b = synth_body(av[1], 1); - vtc_gzip(s->hp, b, &body, - (unsigned *)&bodylen); + vtc_gzip(s->hp, b, &body, &bodylen); AN(body); free(b); ENC(hdr, ":content-encoding", "gzip"); From denes.matetelki at gmail.com Thu Aug 1 13:55:10 2019 From: denes.matetelki at gmail.com (Denes Matetelki) Date: Thu, 1 Aug 2019 13:55:10 +0000 (UTC) Subject: [master] e7828205c Docfix: varnishlog and varnishncsa exits from SIGHUP in the foreground Message-ID: <20190801135510.AB5E5B1177@lists.varnish-cache.org> commit e7828205c4257cac249604f14c2bed78787c318d Author: Denes Matetelki Date: Mon Jul 22 14:07:44 2019 +0200 Docfix: varnishlog and varnishncsa exits from SIGHUP in the foreground Be a bit more elaborate on the expected behaviour diff --git a/doc/sphinx/reference/varnishlog.rst b/doc/sphinx/reference/varnishlog.rst index d94c333b0..f93d5d623 100644 --- a/doc/sphinx/reference/varnishlog.rst +++ b/doc/sphinx/reference/varnishlog.rst @@ -30,7 +30,8 @@ SIGNALS * SIGHUP - Rotate the log file (see -w option) + Rotate the log file (see -w option) in daemon mode, + abort the loop and die gracefully when running in the foreground. * SIGUSR1 diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst index 9c959d3ae..09eac91bd 100644 --- a/doc/sphinx/reference/varnishncsa.rst +++ b/doc/sphinx/reference/varnishncsa.rst @@ -196,10 +196,13 @@ Supported formatters are: SIGNALS ======= -SIGHUP - Rotate the log file (see -w option). +* SIGHUP + + Rotate the log file (see -w option) in daemon mode, + abort the loop and die gracefully when running in the foreground. + +* SIGUSR1 -SIGUSR1 Flush any outstanding transactions. NOTES From denes.matetelki at gmail.com Thu Aug 1 14:13:11 2019 From: denes.matetelki at gmail.com (Denes Matetelki) Date: Thu, 1 Aug 2019 14:13:11 +0000 (UTC) Subject: [master] 1af1ff4f8 Typo. A director having two backends with the same IP is confusing Message-ID: <20190801141311.8A38FB174E@lists.varnish-cache.org> commit 1af1ff4f8ddb360859cb946f1c282add66f41bd0 Author: Denes Matetelki Date: Mon Jul 22 13:55:46 2019 +0200 Typo. A director having two backends with the same IP is confusing diff --git a/doc/sphinx/users-guide/vcl-backends.rst b/doc/sphinx/users-guide/vcl-backends.rst index 7867140eb..24d0dec7d 100644 --- a/doc/sphinx/users-guide/vcl-backends.rst +++ b/doc/sphinx/users-guide/vcl-backends.rst @@ -131,7 +131,7 @@ call certain actions in `vcl_init`.:: .host = "192.168.0.10"; } backend server2 { - .host = "192.168.0.10"; + .host = "192.168.0.11"; } sub vcl_init { From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] c1e9a3adb More Flexelint 9xx tuning Message-ID: <20190813111010.0DD64BE555@lists.varnish-cache.org> commit c1e9a3adb485cae1a8e9cf757569f1f9d9ce79d2 Author: Poul-Henning Kamp Date: Wed Aug 7 11:49:17 2019 +0000 More Flexelint 9xx tuning diff --git a/flint.lnt b/flint.lnt index 60b530678..7b24a4aeb 100644 --- a/flint.lnt +++ b/flint.lnt @@ -10,24 +10,35 @@ //+e9* -e904 -e935 --e955 +-e955 +-e956 //+e958 // report internal struct padding //+e959 // report struct tail/size padding -e960 +-e961 +-efile(966, "/usr/include/*") // unused indir include +-efile(966, "../../include/tbl/*") -e964 -e970 +-e971 -e9012 -e9021 -e9022 +-e9023 -e9024 -e9026 -e9034 +-e9037 -e9042 +-e9048 +-e9050 +-e9051 -e9067 +e9071 // defined macro '...' is reserved to the compiler +e9075 // external symbol without declaration -esym(9075, main) -e9085 +-e9105 -e9107 -e9109 -e9113 @@ -52,6 +63,7 @@ -efile(451, "tbl/*.h") // No include guard -efile(537, "tbl/*.h") // Repeated include +-efile(967, "tbl/*.h") // No include guard -efile(451, "../../include/vut_options.h") // No include guard -efile(451, "../../include/vapi/vapi_options.h") // No include guard From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 5902f53ee Refactor code a bit Message-ID: <20190813111010.23506BE558@lists.varnish-cache.org> commit 5902f53ee142c80041b20cd844f4a9b78723b6d0 Author: Poul-Henning Kamp Date: Wed Aug 7 12:16:40 2019 +0000 Refactor code a bit diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index c220a31ee..7e9f950ec 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -285,6 +285,25 @@ vsm_delset(struct vsm_set **p) FREE_OBJ(vs); } +static void +vsm_wash_set(struct vsm_set *vs, int all) +{ + struct vsm_seg *vg, *vg2; + + VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { + if (all || (vg->flags & VSM_FLAG_MARKSCAN) == 0) { + VTAILQ_REMOVE(&vs->segs, vg, list); + if (vg->refs) { + vg->flags |= VSM_FLAG_STALE; + VTAILQ_INSERT_TAIL(&vs->stale, vg, list); + } else { + VAV_Free(vg->av); + FREE_OBJ(vg); + } + } + } +} + /*--------------------------------------------------------------------*/ struct vsm * @@ -393,8 +412,6 @@ VSM_ResetError(struct vsm *vd) /*-------------------------------------------------------------------- */ -#define VSM_NUKE_ALL (1U << 16) - static int vsm_cmp_av(char * const *a1, char * const *a2) { @@ -563,7 +580,7 @@ vsm_vlu_func(void *priv, const char *line) } static unsigned -vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) +vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) { struct stat st; int i; @@ -576,7 +593,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) if (fstatat(vd->dfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW)) { closefd(&vs->dfd); vs->id1 = vs->id2 = 0; - return (VSM_MGT_RESTARTED|VSM_NUKE_ALL); + vsm_wash_set(vs, 1); + return (VSM_MGT_RESTARTED|VSM_MGT_CHANGED); } if (st.st_ino != vs->dst.st_ino || st.st_dev != vs->dst.st_dev || @@ -593,7 +611,8 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) vs->retval |= VSM_MGT_RESTARTED; if (vs->dfd < 0) { vs->id1 = vs->id2 = 0; - return (vs->retval|VSM_NUKE_ALL); + vsm_wash_set(vs, 1); + return (vs->retval|VSM_MGT_CHANGED); } AZ(fstat(vs->dfd, &vs->dst)); } @@ -631,34 +650,10 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs) } while (!i); assert(i == -2); VLU_Destroy(&vlu); + vsm_wash_set(vs, 0); return (vs->retval); } -static unsigned -vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) -{ - unsigned retval; - struct vsm_seg *vg, *vg2; - - retval = vsm_refresh_set2(vd, vs); - if (retval & VSM_NUKE_ALL) - retval |= VSM_MGT_CHANGED; - VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { - if ((vg->flags & VSM_FLAG_MARKSCAN) == 0 || - (retval & VSM_NUKE_ALL)) { - VTAILQ_REMOVE(&vs->segs, vg, list); - if (vg->refs) { - vg->flags |= VSM_FLAG_STALE; - VTAILQ_INSERT_TAIL(&vs->stale, vg, list); - } else { - VAV_Free(vg->av); - FREE_OBJ(vg); - } - } - } - return (retval & ~VSM_NUKE_ALL); -} - /*--------------------------------------------------------------------*/ unsigned From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 32f503efe Refactor & Polish Message-ID: <20190813111010.3D612BE55B@lists.varnish-cache.org> commit 32f503efea667eb7fc856a4a14e521c382c547cf Author: Poul-Henning Kamp Date: Wed Aug 7 13:34:22 2019 +0000 Refactor & Polish diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 7e9f950ec..79411d783 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -113,6 +113,10 @@ struct vsm_set { // _.index reading state unsigned retval; struct vsm_seg *vg; + + unsigned flag_running; + unsigned flag_changed; + unsigned flag_restarted; }; struct vsm { @@ -122,9 +126,9 @@ struct vsm { struct vsb *diag; uintptr_t serial; - int dfd; - struct stat dst; - char *dname; + int wdfd; + struct stat wdst; + char *wdname; struct vsm_set *mgt; struct vsm_set *child; @@ -186,7 +190,7 @@ vsm_mapseg(struct vsm *vd, struct vsm_seg *vg) vsb = VSB_new_auto(); AN(vsb); - VSB_printf(vsb, "%s/%s/%s", vd->dname, vg->set->dname, vg->av[1]); + VSB_printf(vsb, "%s/%s/%s", vd->wdname, vg->set->dname, vg->av[1]); AZ(VSB_finish(vsb)); fd = open(VSB_data(vsb), O_RDONLY); // XXX: openat @@ -315,10 +319,18 @@ VSM_New(void) AN(vd); vd->mgt = vsm_newset(VSM_MGT_DIRNAME); + vd->mgt->flag_running = VSM_MGT_RUNNING; + vd->mgt->flag_changed = VSM_MGT_CHANGED; + vd->mgt->flag_restarted = VSM_MGT_RESTARTED; + vd->child = vsm_newset(VSM_CHILD_DIRNAME); + vd->child->flag_running = VSM_WRK_RUNNING; + vd->child->flag_changed = VSM_WRK_CHANGED; + vd->child->flag_restarted = VSM_WRK_RESTARTED; + vd->mgt->vsm = vd; vd->child->vsm = vd; - vd->dfd = -1; + vd->wdfd = -1; vd->patience = 5; if (getenv("VSM_NOPID") != NULL) vd->couldkill = -1; @@ -353,7 +365,7 @@ VSM_Arg(struct vsm *vd, char flag, const char *arg) return (vsm_diag(vd, "Invalid instance name: %s", strerror(errno))); AN(p); - REPLACE(vd->dname, p); + REPLACE(vd->wdname, p); free(p); break; default: @@ -372,11 +384,11 @@ VSM_Destroy(struct vsm **vdp) TAKE_OBJ_NOTNULL(vd, vdp, VSM_MAGIC); VSM_ResetError(vd); - REPLACE(vd->dname, NULL); + REPLACE(vd->wdname, NULL); if (vd->diag != NULL) VSB_destroy(&vd->diag); - if (vd->dfd >= 0) - closefd(&vd->dfd); + if (vd->wdfd >= 0) + closefd(&vd->wdfd); vsm_delset(&vd->mgt); vsm_delset(&vd->child); FREE_OBJ(vd); @@ -564,7 +576,7 @@ vsm_vlu_func(void *priv, const char *line) i = vsm_vlu_hash(vd, vs, line); VTAILQ_FOREACH(vs->vg, &vs->segs, list) vs->vg->flags &= ~VSM_FLAG_MARKSCAN; - if (!(vs->retval & VSM_MGT_RESTARTED)) + if (!(vs->retval & vs->flag_restarted)) vs->vg = VTAILQ_FIRST(&vs->segs); break; case '+': @@ -590,29 +602,27 @@ vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) CHECK_OBJ_NOTNULL(vs, VSM_SET_MAGIC); vs->retval = 0; if (vs->dfd >= 0) { - if (fstatat(vd->dfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW)) { - closefd(&vs->dfd); - vs->id1 = vs->id2 = 0; - vsm_wash_set(vs, 1); - return (VSM_MGT_RESTARTED|VSM_MGT_CHANGED); - } - if (st.st_ino != vs->dst.st_ino || + if (fstatat(vd->wdfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW) || + st.st_ino != vs->dst.st_ino || st.st_dev != vs->dst.st_dev || - st.st_mode != vs->dst.st_mode) { + st.st_mode != vs->dst.st_mode || + st.st_nlink == 0) { closefd(&vs->dfd); vs->id1 = vs->id2 = 0; + vsm_wash_set(vs, 1); + vs->retval |= vs->flag_restarted; } } if (vs->dfd < 0) { if (vs->fd >= 0) closefd(&vs->fd); - vs->dfd = openat(vd->dfd, vs->dname, O_RDONLY); - vs->retval |= VSM_MGT_RESTARTED; + vs->dfd = openat(vd->wdfd, vs->dname, O_RDONLY); if (vs->dfd < 0) { vs->id1 = vs->id2 = 0; vsm_wash_set(vs, 1); - return (vs->retval|VSM_MGT_CHANGED); + vs->retval |= vs->flag_restarted; + return (vs->retval); } AZ(fstat(vs->dfd, &vs->dst)); } @@ -630,14 +640,14 @@ vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) if (vs->fd >= 0) { if (vd->couldkill < 1 || !kill(vs->id1, 0)) - vs->retval |= VSM_MGT_RUNNING; + vs->retval |= vs->flag_running; return (vs->retval); } - vs->retval |= VSM_MGT_CHANGED; + vs->retval |= vs->flag_changed; vs->fd = openat(vs->dfd, "_.index", O_RDONLY); if (vs->fd < 0) - return (vs->retval|VSM_MGT_RESTARTED); + return (vs->retval|vs->flag_restarted); AZ(fstat(vs->fd, &vs->fst)); @@ -659,38 +669,41 @@ vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) unsigned VSM_Status(struct vsm *vd) { - unsigned retval = 0, u; + unsigned retval = 0; struct stat st; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); /* See if the -n workdir changed */ - if (vd->dfd >= 0) { - AZ(fstat(vd->dfd, &st)); - if (st.st_ino != vd->dst.st_ino || - st.st_dev != vd->dst.st_dev || - st.st_mode != vd->dst.st_mode || + if (vd->wdfd >= 0) { + AZ(fstat(vd->wdfd, &st)); + if (st.st_ino != vd->wdst.st_ino || + st.st_dev != vd->wdst.st_dev || + st.st_mode != vd->wdst.st_mode || st.st_nlink == 0) { - closefd(&vd->dfd); - retval |= VSM_MGT_CHANGED; - retval |= VSM_WRK_CHANGED; + closefd(&vd->wdfd); + vsm_wash_set(vd->mgt, 1); + vsm_wash_set(vd->child, 1); } } /* Open workdir */ - if (vd->dfd < 0) { - vd->dfd = open(vd->dname, O_RDONLY); - if (vd->dfd < 0) + if (vd->wdfd < 0) { + retval |= VSM_MGT_RESTARTED | VSM_MGT_CHANGED; + retval |= VSM_WRK_RESTARTED | VSM_MGT_CHANGED; + vd->wdfd = open(vd->wdname, O_RDONLY); + if (vd->wdfd < 0) (void)vsm_diag(vd, "VSM_Status: Cannot open workdir"); else - AZ(fstat(vd->dfd, &vd->dst)); + AZ(fstat(vd->wdfd, &vd->wdst)); } - u = vsm_refresh_set(vd, vd->mgt); - retval |= u; - if (u & VSM_MGT_RUNNING) - retval |= vsm_refresh_set(vd, vd->child) << 8; + if (vd->wdfd >= 0) { + retval |= vsm_refresh_set(vd, vd->mgt); + if (retval & VSM_MGT_RUNNING) + retval |= vsm_refresh_set(vd, vd->child); + } return (retval); } @@ -710,12 +723,12 @@ VSM_Attach(struct vsm *vd, int progress) else t0 = VTIM_mono() + vd->patience; - if (vd->dname == NULL) { + if (vd->wdname == NULL) { /* Use default (hostname) */ i = VSM_Arg(vd, 'n', ""); if (i < 0) return (i); - AN(vd->dname); + AN(vd->wdname); } AZ(vd->attached); From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 17b30b617 Add a VLU_Reset() function Message-ID: <20190813111010.5A894BE560@lists.varnish-cache.org> commit 17b30b617831737896650027eb9dff5f06478c36 Author: Poul-Henning Kamp Date: Thu Aug 8 08:24:13 2019 +0000 Add a VLU_Reset() function diff --git a/include/vlu.h b/include/vlu.h index 47cf705f5..8ce98dd3f 100644 --- a/include/vlu.h +++ b/include/vlu.h @@ -34,6 +34,7 @@ typedef int (vlu_f)(void *, const char *); struct vlu *VLU_New(vlu_f *, void *, unsigned); +void VLU_Reset(struct vlu *); int VLU_Fd(struct vlu *, int); void VLU_Destroy(struct vlu **); int VLU_File(int, vlu_f *, void *, unsigned); diff --git a/lib/libvarnish/vlu.c b/lib/libvarnish/vlu.c index 536b792d4..7b4eb90db 100644 --- a/lib/libvarnish/vlu.c +++ b/lib/libvarnish/vlu.c @@ -72,6 +72,13 @@ VLU_New(vlu_f *func, void *priv, unsigned bufsize) return (l); } +void +VLU_Reset(struct vlu *l) +{ + CHECK_OBJ_NOTNULL(l, LINEUP_MAGIC); + l->bufp = 0; +} + void VLU_Destroy(struct vlu **lp) { From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 9bf8ee9ce Destroy the childs Param and Panicstr VSMs properly Message-ID: <20190813111010.75A41BE56B@lists.varnish-cache.org> commit 9bf8ee9ce4d70d12f4fd8439dcb16d41037fc266 Author: Poul-Henning Kamp Date: Thu Aug 8 11:08:34 2019 +0000 Destroy the childs Param and Panicstr VSMs properly diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c index 90e966f0e..574513413 100644 --- a/bin/varnishd/mgt/mgt_shmem.c +++ b/bin/varnishd/mgt/mgt_shmem.c @@ -142,6 +142,6 @@ mgt_SHM_ChildDestroy(void) AZ(system("rm -rf " VSM_CHILD_DIRNAME)); VJ_master(JAIL_MASTER_LOW); } - heritage.panic_str = NULL; - heritage.param = NULL; + VSMW_Free(mgt_vsmw, (void**)&heritage.panic_str); + VSMW_Free(mgt_vsmw, (void**)&heritage.param); } From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] ea995d696 Only emit the '-' line when the cluster is empty. Message-ID: <20190813111010.8F00EBE575@lists.varnish-cache.org> commit ea995d6966fcd2da2b2783b779371f557e8301c8 Author: Poul-Henning Kamp Date: Thu Aug 8 14:12:21 2019 +0000 Only emit the '-' line when the cluster is empty. diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index feb94cff9..9454c4e6a 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -106,6 +106,7 @@ struct vsmw_cluster { void *ptr; size_t next; int refs; + int named; }; struct vsmwseg { @@ -221,7 +222,7 @@ vsmw_addseg(struct vsmw *vsmw, struct vsmwseg *seg) /*--------------------------------------------------------------------*/ static void -vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) +vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg) { char *t = NULL; int fd; @@ -234,11 +235,10 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) VTAILQ_REMOVE(&vsmw->segs, seg, list); vsmw->nsegs--; - if (vsmw->nsubs * 2 < vsmw->nsegs || !fixidx) { + if (vsmw->nsubs < 10 || vsmw->nsubs * 2 < vsmw->nsegs) { vsmw_append_record(vsmw, seg, '-'); vsmw->nsubs++; } else { - vsmw->nsubs = 0; vsmw_mkent(vsmw, vsmw->idx); REPLACE(t, VSB_data(vsmw->vsb)); AN(t); @@ -254,6 +254,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx) closefd(&fd); AZ(renameat(vsmw->vdirfd, t, vsmw->vdirfd, vsmw->idx)); REPLACE(t, NULL); + vsmw->nsubs = 0; } REPLACE(seg->class, NULL); REPLACE(seg->id, NULL); @@ -315,6 +316,8 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx) seg->cluster = vc; REPLACE(seg->class, ""); REPLACE(seg->id, ""); + vc->refs++; + vc->named = 1; vsmw_addseg(vsmw, seg); vsmw_do_unlock(); @@ -322,28 +325,19 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx) } static void -vsmw_DestroyCluster_locked(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) +vsmw_DestroyCluster_locked(struct vsmw *vsmw, struct vsmw_cluster *vc) { - struct vsmw_cluster *vc; CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); - TAKE_OBJ_NOTNULL(vc, vsmcp, VSMW_CLUSTER_MAGIC); + CHECK_OBJ_NOTNULL(vc, VSMW_CLUSTER_MAGIC); + + AZ(vc->refs); - if (vc->cseg != NULL) { - /* - * Backends go on the cool list, so the VGC cluster is - * destroyed before they are. Solve this by turning the - * cluster into an anonymous cluster which dies with the - * refcount on it. - */ - vsmw_delseg(vsmw, vc->cseg, 1); - vc->cseg = NULL; - if (vc->refs > 0) - return; - } AZ(munmap(vc->ptr, vc->len)); + if (vc->named) + vsmw_delseg(vsmw, vc->cseg); + vc->cseg = 0; - AZ(vc->refs); VTAILQ_REMOVE(&vsmw->clusters, vc, list); if (unlinkat(vsmw->vdirfd, vc->fn, 0)) assert (errno == ENOENT); @@ -354,9 +348,13 @@ vsmw_DestroyCluster_locked(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) void VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp) { + struct vsmw_cluster *vc; + + TAKE_OBJ_NOTNULL(vc, vsmcp, VSMW_CLUSTER_MAGIC); vsmw_do_lock(); - vsmw_DestroyCluster_locked(vsmw, vsmcp); + if (--vc->refs == 0) + vsmw_DestroyCluster_locked(vsmw, vc); vsmw_do_unlock(); } @@ -371,7 +369,6 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc, vsmw_do_lock(); CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC); - (void)vc; ALLOC_OBJ(seg, VSMWSEG_MAGIC); AN(seg); @@ -431,11 +428,13 @@ VSMW_Free(struct vsmw *vsmw, void **pp) *pp = NULL; cp = seg->cluster; + CHECK_OBJ_NOTNULL(cp, VSMW_CLUSTER_MAGIC); + assert(cp->refs > 0); - vsmw_delseg(vsmw, seg, 1); + vsmw_delseg(vsmw, seg); - if (!--cp->refs && cp->cseg == NULL) - vsmw_DestroyCluster_locked(vsmw, &cp); + if (!--cp->refs) + vsmw_DestroyCluster_locked(vsmw, cp); vsmw_do_unlock(); } @@ -486,7 +485,7 @@ VSMW_Destroy(struct vsmw **pp) vsmw_do_lock(); TAKE_OBJ_NOTNULL(vsmw, pp, VSMW_MAGIC); VTAILQ_FOREACH_SAFE(seg, &vsmw->segs, list, s2) - vsmw_delseg(vsmw, seg, 0); + vsmw_delseg(vsmw, seg); if (unlinkat(vsmw->vdirfd, vsmw->idx, 0)) assert (errno == ENOENT); REPLACE(vsmw->idx, NULL); From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 29d940014 Never allocate at offset zero in a cluster, this makes it faster for clients what the _index entry is about. Message-ID: <20190813111010.A7568BE579@lists.varnish-cache.org> commit 29d940014dccab1cb820db1cdf3a907558f5b059 Author: Poul-Henning Kamp Date: Tue Aug 13 07:38:51 2019 +0000 Never allocate at offset zero in a cluster, this makes it faster for clients what the _index entry is about. diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c index 9454c4e6a..ee69eea56 100644 --- a/bin/varnishd/common/common_vsmw.c +++ b/bin/varnishd/common/common_vsmw.c @@ -137,6 +137,9 @@ struct vsmw { uint64_t nsubs; }; +/* Allocations in clusters never start at offset zero */ +#define VSM_CLUSTER_OFFSET 16 + /*--------------------------------------------------------------------*/ static void @@ -307,7 +310,9 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx) struct vsmwseg *seg; vsmw_do_lock(); - vc = vsmw_newcluster(vsmw, len, pfx); + vc = vsmw_newcluster(vsmw, len + VSM_CLUSTER_OFFSET, pfx); + AN(vc); + vc->next += VSM_CLUSTER_OFFSET; ALLOC_OBJ(seg, VSMWSEG_MAGIC); AN(seg); From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] 947147ee6 Polishing/Refactoring Message-ID: <20190813111010.C0668BE57D@lists.varnish-cache.org> commit 947147ee65a8b6ea8e6ff1a52810b5604490ee0a Author: Poul-Henning Kamp Date: Tue Aug 13 09:47:10 2019 +0000 Polishing/Refactoring diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 79411d783..13ccf67bb 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -82,6 +82,7 @@ struct vsm_seg { #define VSM_FLAG_STALE (1U<<2) #define VSM_FLAG_CLUSTER (1U<<3) VTAILQ_ENTRY(vsm_seg) list; + VTAILQ_ENTRY(vsm_seg) clist; struct vsm_set *set; struct vsm_seg *cluster; char **av; @@ -233,18 +234,26 @@ vsm_unmapseg(struct vsm_seg *vg) /*--------------------------------------------------------------------*/ static void -vsm_delseg(struct vsm_seg *vg) +vsm_delseg(struct vsm_seg *vg, int refsok) { CHECK_OBJ_NOTNULL(vg, VSM_SEG_MAGIC); + if (refsok && vg->refs) { + AZ(vg->flags & VSM_FLAG_STALE); + vg->flags |= VSM_FLAG_STALE; + VTAILQ_REMOVE(&vg->set->segs, vg, list); + VTAILQ_INSERT_TAIL(&vg->set->stale, vg, list); + return; + } + if (vg->s != NULL) vsm_unmapseg(vg); if (vg->flags & VSM_FLAG_STALE) VTAILQ_REMOVE(&vg->set->stale, vg, list); else if (vg->flags & VSM_FLAG_CLUSTER) - VTAILQ_REMOVE(&vg->set->clusters, vg, list); + VTAILQ_REMOVE(&vg->set->clusters, vg, clist); else VTAILQ_REMOVE(&vg->set->segs, vg, list); VAV_Free(vg->av); @@ -281,11 +290,11 @@ vsm_delset(struct vsm_set **p) if (vs->dfd >= 0) closefd(&vs->dfd); while (!VTAILQ_EMPTY(&vs->stale)) - vsm_delseg(VTAILQ_FIRST(&vs->stale)); + vsm_delseg(VTAILQ_FIRST(&vs->stale), 0); while (!VTAILQ_EMPTY(&vs->segs)) - vsm_delseg(VTAILQ_FIRST(&vs->segs)); + vsm_delseg(VTAILQ_FIRST(&vs->segs), 0); while (!VTAILQ_EMPTY(&vs->clusters)) - vsm_delseg(VTAILQ_FIRST(&vs->clusters)); + vsm_delseg(VTAILQ_FIRST(&vs->clusters), 0); FREE_OBJ(vs); } @@ -295,16 +304,8 @@ vsm_wash_set(struct vsm_set *vs, int all) struct vsm_seg *vg, *vg2; VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { - if (all || (vg->flags & VSM_FLAG_MARKSCAN) == 0) { - VTAILQ_REMOVE(&vs->segs, vg, list); - if (vg->refs) { - vg->flags |= VSM_FLAG_STALE; - VTAILQ_INSERT_TAIL(&vs->stale, vg, list); - } else { - VAV_Free(vg->av); - FREE_OBJ(vg); - } - } + if (all || (vg->flags & VSM_FLAG_MARKSCAN) == 0) + vsm_delseg(vg, 1); } } @@ -441,15 +442,14 @@ vsm_cmp_av(char * const *a1, char * const *a2) } static struct vsm_seg * -vsm_findcluster(const struct vsm_seg *vga) +vsm_findcluster(const struct vsm_set *vs, const char *cnam) { - const struct vsm_set *vs = vga->set; struct vsm_seg *vg; AN(vs); - AN(vga->av[1]); - VTAILQ_FOREACH(vg, &vs->clusters, list) { + AN(cnam); + VTAILQ_FOREACH(vg, &vs->clusters, clist) { AN(vg->av[1]); - if (!strcmp(vga->av[1], vg->av[1])) + if (!strcmp(cnam, vg->av[1])) return (vg); } return (NULL); @@ -498,7 +498,14 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) return(-1); } - if (vs->vg == NULL) { + while (vs->vg != NULL && vsm_cmp_av(&vs->vg->av[1], &av[1])) + vs->vg = VTAILQ_NEXT(vs->vg, list); + if (vs->vg != NULL) { + VAV_Free(av); + /* entry compared equal, so it survives */ + vs->vg->flags |= VSM_FLAG_MARKSCAN; + vs->vg = VTAILQ_NEXT(vs->vg, list); + } else { ALLOC_OBJ(vg2, VSM_SEG_MAGIC); AN(vg2); vg2->av = av; @@ -507,19 +514,10 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) vg2->serial = ++vd->serial; if (ac == 4) { vg2->flags |= VSM_FLAG_CLUSTER; - VTAILQ_INSERT_TAIL(&vs->clusters, vg2, list); + VTAILQ_INSERT_TAIL(&vs->clusters, vg2, clist); } else { VTAILQ_INSERT_TAIL(&vs->segs, vg2, list); - vg2->cluster = vsm_findcluster(vg2); - } - } else { - while (vs->vg != NULL && vsm_cmp_av(&vs->vg->av[1], &av[1])) - vs->vg = VTAILQ_NEXT(vs->vg, list); - VAV_Free(av); - if (vs->vg != NULL) { - /* entry compared equal, so it survives */ - vs->vg->flags |= VSM_FLAG_MARKSCAN; - vs->vg = VTAILQ_NEXT(vs->vg, list); + vg2->cluster = vsm_findcluster(vs, vg2->av[1]); } } return (0); @@ -530,7 +528,7 @@ vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) { char **av; int ac; - struct vsm_seg *vg, *vg2; + struct vsm_seg *vg; av = VAV_Parse(line + 1, &ac, 0); @@ -542,18 +540,11 @@ vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) return(-1); } - VTAILQ_FOREACH_SAFE(vg, &vs->segs, list, vg2) { - if (vsm_cmp_av(&vg->av[1], &av[1])) - continue; - VTAILQ_REMOVE(&vs->segs, vg, list); - if (vg->refs) { - vg->flags |= VSM_FLAG_STALE; - VTAILQ_INSERT_TAIL(&vs->stale, vg, list); - } else { - VAV_Free(vg->av); - FREE_OBJ(vg); + VTAILQ_FOREACH(vg, &vs->segs, list) { + if (!vsm_cmp_av(&vg->av[1], &av[1])) { + vsm_delseg(vg, 1); + break; } - break; } VAV_Free(av); return (0); @@ -925,7 +916,7 @@ VSM_Unmap(struct vsm *vd, struct vsm_fantom *vf) vsm_unmapseg(vg); } if (vg->flags & VSM_FLAG_STALE) - vsm_delseg(vg); + vsm_delseg(vg, 0); return (0); } From phk at FreeBSD.org Tue Aug 13 11:10:10 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:10:10 +0000 (UTC) Subject: [master] e8d2ab8fb Try to get the VSM cluster inconsistency fixed for good. Message-ID: <20190813111010.DC85BBE581@lists.varnish-cache.org> commit e8d2ab8fb2ac89fd4d630c0ed0dfbdc0bc395997 Author: Poul-Henning Kamp Date: Tue Aug 13 11:08:18 2019 +0000 Try to get the VSM cluster inconsistency fixed for good. Obsoletes: #3039 diff --git a/bin/varnishtest/tests/c00083.vtc b/bin/varnishtest/tests/c00083.vtc index 67f52b612..3f79baae2 100644 --- a/bin/varnishtest/tests/c00083.vtc +++ b/bin/varnishtest/tests/c00083.vtc @@ -4,15 +4,47 @@ varnish v1 -vcl { backend default { .host = "${bad_ip}"; } } -start +delay 1 + process p1 { nlines=`wc -l < ${tmpdir}/v1/_.vsm_child/_.index` nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_child/_.index` - echo NLINES $nlines NMINUS $nminus + echo CHILD NLINES $nlines NMINUS $nminus } -dump -run +# Useful for debugging +process p2 {tail -F ${tmpdir}/v1/_.vsm_child/_.index} -dump -start +process p3 {tail -F ${tmpdir}/v1/_.vsm_mgt/_.index} -dump -start + +varnish v1 -vcl { + backend b00 { .host = "${bad_ip}"; } + backend b01 { .host = "${bad_ip}"; } + backend b02 { .host = "${bad_ip}"; } + backend b03 { .host = "${bad_ip}"; } + + sub vcl_recv { + set req.backend_hint = b00; + set req.backend_hint = b01; + set req.backend_hint = b02; + set req.backend_hint = b03; + } +} + +varnish v1 -cliok vcl.list + +process p1 -run + +varnish v1 -cliok "vcl.use vcl1" +varnish v1 -cliok "vcl.discard vcl2" + +delay 1 + +process p1 -run + # The child process starts out with approx 37 VSM segments -# so it takes 20 backends to cause a _.index rewrite. -# Make it 25 to be safe. +# and spent 10 lines on vcl2, so it takes ~ 15 backends to +# cause a _.index rewrite. +# Make it 20 to be on the safe side. varnish v1 -vcl { backend b00 { .host = "${bad_ip}"; } backend b01 { .host = "${bad_ip}"; } @@ -34,11 +66,6 @@ varnish v1 -vcl { backend b17 { .host = "${bad_ip}"; } backend b18 { .host = "${bad_ip}"; } backend b19 { .host = "${bad_ip}"; } - backend b20 { .host = "${bad_ip}"; } - backend b21 { .host = "${bad_ip}"; } - backend b22 { .host = "${bad_ip}"; } - backend b23 { .host = "${bad_ip}"; } - backend b24 { .host = "${bad_ip}"; } sub vcl_recv { set req.backend_hint = b00; @@ -61,25 +88,54 @@ varnish v1 -vcl { set req.backend_hint = b17; set req.backend_hint = b18; set req.backend_hint = b19; - set req.backend_hint = b20; - set req.backend_hint = b21; - set req.backend_hint = b22; - set req.backend_hint = b23; - set req.backend_hint = b24; } } varnish v1 -cliok vcl.list +delay 1 + process p1 -run varnish v1 -cliok "vcl.use vcl1" -varnish v1 -cliok "vcl.discard vcl2" +varnish v1 -cliok "vcl.discard vcl3" + +delay 1 # Check that the _.index rewrite did happen + process p1 { nlines=`wc -l < ${tmpdir}/v1/_.vsm_child/_.index` nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_child/_.index` - echo NLINES $nlines NMINUS $nminus - test $nminus -lt 25 + echo CHILD NLINES $nlines NMINUS $nminus + # cat ${tmpdir}/v1/_.vsm_child/_.index + test $nminus -lt 20 } -run + +# Now check the management process VSM + +process p1 { + nlines=`wc -l < ${tmpdir}/v1/_.vsm_mgt/_.index` + nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_mgt/_.index` + echo MGT NLINES $nlines NMINUS $nminus + # cat ${tmpdir}/v1/_.vsm_child/_.index + test $nminus -eq 0 +} -run + +varnish v1 -cliok "stop" + +delay 1 + +process p1 { + nlines=`wc -l < ${tmpdir}/v1/_.vsm_mgt/_.index` + nminus=`grep -c '^-' ${tmpdir}/v1/_.vsm_mgt/_.index` + echo MGT NLINES $nlines NMINUS $nminus + # cat ${tmpdir}/v1/_.vsm_child/_.index + test $nminus -eq 2 +} -run + +varnish v1 -cliok "start" + +delay 1 + +process p1 -run diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c index 1fc844f27..3bfb9ec56 100644 --- a/bin/varnishtop/varnishtop.c +++ b/bin/varnishtop/varnishtop.c @@ -353,6 +353,7 @@ main(int argc, char **argv) ident = VSM_Dup(vut->vsm, "Arg", "-i"); else ident = strdup(""); + AN(ident); vut->dispatch_f = accumulate; vut->dispatch_priv = NULL; if (once) { diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index e0194e8c9..8725124a7 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -423,6 +423,7 @@ VSC_Iter(struct vsc *vsc, struct vsm *vsm, VSC_iter_f *fiter, void *priv) AN(vsm); sp = VTAILQ_FIRST(&vsc->segs); VSM_FOREACH(&ifantom, vsm) { + AN(ifantom.class); if (strcmp(ifantom.class, VSC_CLASS) && strcmp(ifantom.class, VSC_DOC_CLASS)) continue; diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 13ccf67bb..270d601b2 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -239,6 +239,11 @@ vsm_delseg(struct vsm_seg *vg, int refsok) CHECK_OBJ_NOTNULL(vg, VSM_SEG_MAGIC); + if (vg->flags & VSM_FLAG_CLUSTER) { + vg->flags &= ~VSM_FLAG_CLUSTER; + VTAILQ_REMOVE(&vg->set->clusters, vg, clist); + } + if (refsok && vg->refs) { AZ(vg->flags & VSM_FLAG_STALE); vg->flags |= VSM_FLAG_STALE; @@ -252,8 +257,6 @@ vsm_delseg(struct vsm_seg *vg, int refsok) if (vg->flags & VSM_FLAG_STALE) VTAILQ_REMOVE(&vg->set->stale, vg, list); - else if (vg->flags & VSM_FLAG_CLUSTER) - VTAILQ_REMOVE(&vg->set->clusters, vg, clist); else VTAILQ_REMOVE(&vg->set->segs, vg, list); VAV_Free(vg->av); @@ -293,13 +296,12 @@ vsm_delset(struct vsm_set **p) vsm_delseg(VTAILQ_FIRST(&vs->stale), 0); while (!VTAILQ_EMPTY(&vs->segs)) vsm_delseg(VTAILQ_FIRST(&vs->segs), 0); - while (!VTAILQ_EMPTY(&vs->clusters)) - vsm_delseg(VTAILQ_FIRST(&vs->clusters), 0); + assert(VTAILQ_EMPTY(&vs->clusters)); FREE_OBJ(vs); } static void -vsm_wash_set(struct vsm_set *vs, int all) +vsm_wash_set(const struct vsm_set *vs, int all) { struct vsm_seg *vg, *vg2; @@ -486,13 +488,12 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) { char **av; int ac; - struct vsm_seg *vg2; + struct vsm_seg *vg; av = VAV_Parse(line + 1, &ac, 0); if (av[0] != NULL || ac < 4 || ac > 6) { - (void)(vsm_diag(vd, - "vsm_vlu_plus: bad index (%d/%s)", + (void)(vsm_diag(vd, "vsm_vlu_plus: bad index (%d/%s)", ac, av[0])); VAV_Free(av); return(-1); @@ -506,25 +507,26 @@ vsm_vlu_plus(struct vsm *vd, struct vsm_set *vs, const char *line) vs->vg->flags |= VSM_FLAG_MARKSCAN; vs->vg = VTAILQ_NEXT(vs->vg, list); } else { - ALLOC_OBJ(vg2, VSM_SEG_MAGIC); - AN(vg2); - vg2->av = av; - vg2->set = vs; - vg2->flags = VSM_FLAG_MARKSCAN; - vg2->serial = ++vd->serial; + ALLOC_OBJ(vg, VSM_SEG_MAGIC); + AN(vg); + vg->av = av; + vg->set = vs; + vg->flags = VSM_FLAG_MARKSCAN; + vg->serial = ++vd->serial; + VTAILQ_INSERT_TAIL(&vs->segs, vg, list); if (ac == 4) { - vg2->flags |= VSM_FLAG_CLUSTER; - VTAILQ_INSERT_TAIL(&vs->clusters, vg2, clist); - } else { - VTAILQ_INSERT_TAIL(&vs->segs, vg2, list); - vg2->cluster = vsm_findcluster(vs, vg2->av[1]); + vg->flags |= VSM_FLAG_CLUSTER; + VTAILQ_INSERT_TAIL(&vs->clusters, vg, clist); + } else if (*vg->av[2] != '0') { + vg->cluster = vsm_findcluster(vs, vg->av[1]); + AN(vg->cluster); } } return (0); } static int -vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) +vsm_vlu_minus(struct vsm *vd, const struct vsm_set *vs, const char *line) { char **av; int ac; @@ -533,19 +535,25 @@ vsm_vlu_minus(struct vsm *vd, struct vsm_set *vs, const char *line) av = VAV_Parse(line + 1, &ac, 0); if (av[0] != NULL || ac < 4 || ac > 6) { - (void)(vsm_diag(vd, - "vsm_vlu_minus: bad index (%d/%s)", + (void)(vsm_diag(vd, "vsm_vlu_minus: bad index (%d/%s)", ac, av[0])); VAV_Free(av); return(-1); } - VTAILQ_FOREACH(vg, &vs->segs, list) { + /* Clustered segments cannot come before their cluster */ + if (*av[2] != '0') + vg = vsm_findcluster(vs, av[1]); + else + vg = VTAILQ_FIRST(&vs->segs); + + for (;vg != NULL; vg = VTAILQ_NEXT(vg, list)) { if (!vsm_cmp_av(&vg->av[1], &av[1])) { vsm_delseg(vg, 1); break; } } + AN(vg); VAV_Free(av); return (0); } @@ -788,28 +796,36 @@ VSM__iter0(const struct vsm *vd, struct vsm_fantom *vf) int VSM__itern(struct vsm *vd, struct vsm_fantom *vf) { - struct vsm_seg *vg, *vg2; + struct vsm_seg *vg; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); AN(vd->attached); AN(vf); if (vf->priv == 0) { - vg2 = VTAILQ_FIRST(&vd->mgt->segs); + vg = VTAILQ_FIRST(&vd->mgt->segs); + if (vg == NULL) + return (0); } else { vg = vsm_findseg(vd, vf); if (vg == NULL) return (vsm_diag(vd, "VSM_FOREACH: inconsistency")); - vg2 = VTAILQ_NEXT(vg, list); - if (vg2 == NULL && vg->set == vd->mgt) - vg2 = VTAILQ_FIRST(&vd->child->segs); + while (1) { + if (vg->set == vd->mgt && VTAILQ_NEXT(vg, list) == NULL) + vg = VTAILQ_FIRST(&vd->child->segs); + else + vg = VTAILQ_NEXT(vg, list); + if (vg == NULL) + return (0); + if (!(vg->flags & VSM_FLAG_CLUSTER)) + break; + } } - if (vg2 == NULL) - return (0); memset(vf, 0, sizeof *vf); - vf->priv = vg2->serial; - vf->class = vg2->av[4]; - vf->ident = vg2->av[5]; + vf->priv = vg->serial; + vf->class = vg->av[4]; + vf->ident = vg->av[5]; + AN(vf->class); return (1); } From phk at FreeBSD.org Tue Aug 13 11:38:06 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 11:38:06 +0000 (UTC) Subject: [master] 34b01c480 Comment out 'tail -F', SunOS does not support it. Message-ID: <20190813113806.D34F4BF7C0@lists.varnish-cache.org> commit 34b01c480c5299e99798b34147a91d33ee3e171e Author: Poul-Henning Kamp Date: Tue Aug 13 11:36:44 2019 +0000 Comment out 'tail -F', SunOS does not support it. diff --git a/bin/varnishtest/tests/c00083.vtc b/bin/varnishtest/tests/c00083.vtc index 3f79baae2..6b5ff7e69 100644 --- a/bin/varnishtest/tests/c00083.vtc +++ b/bin/varnishtest/tests/c00083.vtc @@ -13,8 +13,8 @@ process p1 { } -dump -run # Useful for debugging -process p2 {tail -F ${tmpdir}/v1/_.vsm_child/_.index} -dump -start -process p3 {tail -F ${tmpdir}/v1/_.vsm_mgt/_.index} -dump -start +#process p2 {tail -F ${tmpdir}/v1/_.vsm_child/_.index} -dump -start +#process p3 {tail -F ${tmpdir}/v1/_.vsm_mgt/_.index} -dump -start varnish v1 -vcl { backend b00 { .host = "${bad_ip}"; } From phk at FreeBSD.org Tue Aug 13 13:11:06 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 13 Aug 2019 13:11:06 +0000 (UTC) Subject: [master] 666d8427d Don't close the _.index fd, but continue reading until the file is recreated by varnishd. Message-ID: <20190813131106.32A2F5986@lists.varnish-cache.org> commit 666d8427d206e45d0b16d308f21f052aeb61f897 Author: Poul-Henning Kamp Date: Tue Aug 13 13:09:14 2019 +0000 Don't close the _.index fd, but continue reading until the file is recreated by varnishd. Martin spotted that I lost this in the previous commit. diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 270d601b2..53ceb387b 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -70,6 +70,8 @@ const struct vsm_valid VSM_invalid[1] = {{"invalid"}}; const struct vsm_valid VSM_valid[1] = {{"valid"}}; +static vlu_f vsm_vlu_func; + /*--------------------------------------------------------------------*/ struct vsm_set; @@ -112,6 +114,7 @@ struct vsm_set { uintmax_t id1, id2; // _.index reading state + struct vlu *vlu; unsigned retval; struct vsm_seg *vg; @@ -277,6 +280,8 @@ vsm_newset(const char *dirname) VTAILQ_INIT(&vs->clusters); vs->dname = dirname; vs->dfd = vs->fd = -1; + vs->vlu = VLU_New(vsm_vlu_func, vs, 0); + AN(vs->vlu); return (vs); } @@ -297,6 +302,7 @@ vsm_delset(struct vsm_set **p) while (!VTAILQ_EMPTY(&vs->segs)) vsm_delseg(VTAILQ_FIRST(&vs->segs), 0); assert(VTAILQ_EMPTY(&vs->clusters)); + VLU_Destroy(&vs->vlu); FREE_OBJ(vs); } @@ -590,76 +596,79 @@ vsm_vlu_func(void *priv, const char *line) return (i); } +static void +vsm_readlines(struct vsm_set *vs) +{ + int i; + + do { + i = VLU_Fd(vs->vlu, vs->fd); + } while (!i); + assert(i == -2); +} + static unsigned vsm_refresh_set(struct vsm *vd, struct vsm_set *vs) { struct stat st; - int i; - struct vlu *vlu; CHECK_OBJ_NOTNULL(vd, VSM_MAGIC); CHECK_OBJ_NOTNULL(vs, VSM_SET_MAGIC); vs->retval = 0; - if (vs->dfd >= 0) { - if (fstatat(vd->wdfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW) || - st.st_ino != vs->dst.st_ino || - st.st_dev != vs->dst.st_dev || - st.st_mode != vs->dst.st_mode || - st.st_nlink == 0) { - closefd(&vs->dfd); - vs->id1 = vs->id2 = 0; - vsm_wash_set(vs, 1); - vs->retval |= vs->flag_restarted; - } + if (vs->dfd >= 0 && ( + fstatat(vd->wdfd, vs->dname, &st, AT_SYMLINK_NOFOLLOW) || + st.st_ino != vs->dst.st_ino || + st.st_dev != vs->dst.st_dev || + st.st_mode != vs->dst.st_mode || + st.st_nlink == 0)) { + closefd(&vs->dfd); } if (vs->dfd < 0) { if (vs->fd >= 0) closefd(&vs->fd); vs->dfd = openat(vd->wdfd, vs->dname, O_RDONLY); - if (vs->dfd < 0) { - vs->id1 = vs->id2 = 0; - vsm_wash_set(vs, 1); - vs->retval |= vs->flag_restarted; - return (vs->retval); - } - AZ(fstat(vs->dfd, &vs->dst)); } + if (vs->dfd < 0) { + vs->id1 = vs->id2 = 0; + vsm_wash_set(vs, 1); + return (vs->retval | vs->flag_restarted); + } + + AZ(fstat(vs->dfd, &vs->dst)); + if (vs->fd >= 0 && ( fstatat(vs->dfd, "_.index", &st, AT_SYMLINK_NOFOLLOW) || st.st_ino != vs->fst.st_ino || st.st_dev != vs->fst.st_dev || st.st_mode != vs->fst.st_mode || - st.st_size != vs->fst.st_size || + st.st_size < vs->fst.st_size || st.st_nlink < 1 || memcmp(&st.st_mtime, &vs->fst.st_mtime, sizeof st.st_mtime))) { closefd(&vs->fd); } if (vs->fd >= 0) { - if (vd->couldkill < 1 || !kill(vs->id1, 0)) - vs->retval |= vs->flag_running; - return (vs->retval); + vs->vg = NULL; + vsm_readlines(vs); + } else { + VTAILQ_FOREACH(vs->vg, &vs->segs, list) + vs->vg->flags &= ~VSM_FLAG_MARKSCAN; + vs->vg = VTAILQ_FIRST(&vs->segs); + vs->fd = openat(vs->dfd, "_.index", O_RDONLY); + if (vs->fd < 0) + return (vs->retval|vs->flag_restarted); + VLU_Reset(vs->vlu); + AZ(fstat(vs->fd, &vs->fst)); + vsm_readlines(vs); + vsm_wash_set(vs, 0); } - vs->retval |= vs->flag_changed; - vs->fd = openat(vs->dfd, "_.index", O_RDONLY); - if (vs->fd < 0) - return (vs->retval|vs->flag_restarted); - - AZ(fstat(vs->fd, &vs->fst)); - - vlu = VLU_New(vsm_vlu_func, vs, 0); - AN(vlu); + vs->fst.st_size = lseek(vs->fd, 0L, SEEK_CUR); - vs->vg = NULL; - do { - i = VLU_Fd(vlu, vs->fd); - } while (!i); - assert(i == -2); - VLU_Destroy(&vlu); - vsm_wash_set(vs, 0); + if (vd->couldkill < 1 || !kill(vs->id1, 0)) + vs->retval |= vs->flag_running; return (vs->retval); } From phk at FreeBSD.org Wed Aug 14 07:41:07 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 14 Aug 2019 07:41:07 +0000 (UTC) Subject: [master] 82ad74ad2 move backend error state reason and code struct field to end of struct Message-ID: <20190814074107.9BEB9A4A5B@lists.varnish-cache.org> commit 82ad74ad29504481267c3e986b6b8e5465c389a3 Author: Andrew Wiik Date: Mon Aug 12 13:05:07 2019 -0400 move backend error state reason and code struct field to end of struct diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index a204200c1..778db6861 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -412,9 +412,6 @@ struct busyobj { struct http_conn *htc; - uint16_t err_code; - const char *err_reason; - struct pool_task fetch_task; #define BO_FLAG(l, r, w, d) unsigned l:1; @@ -442,6 +439,9 @@ struct busyobj { uint8_t digest[DIGEST_LEN]; struct vrt_privs privs[1]; + + uint16_t err_code; + const char *err_reason; }; From phk at FreeBSD.org Wed Aug 14 08:27:06 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 14 Aug 2019 08:27:06 +0000 (UTC) Subject: [master] 67ea0c83c Distinguish $TYPE.property from $TYPE.method() by insisting in () Message-ID: <20190814082706.3573AA5ADF@lists.varnish-cache.org> commit 67ea0c83c3eb7df9e971fa8011cc0cbe2814ca57 Author: Poul-Henning Kamp Date: Wed Aug 14 08:25:50 2019 +0000 Distinguish $TYPE.property from $TYPE.method() by insisting in () STRING.upper() and STRING.lower() are methods. Relevant to: #3023 diff --git a/bin/varnishtest/tests/v00058.vtc b/bin/varnishtest/tests/v00058.vtc index c7f39e628..76fec5ec6 100644 --- a/bin/varnishtest/tests/v00058.vtc +++ b/bin/varnishtest/tests/v00058.vtc @@ -184,14 +184,14 @@ server s1 { varnish v1 -vcl+backend { sub vcl_deliver { - set resp.http.l-proto = resp.proto.lower; - set resp.http.u-proto = resp.proto.upper; - set resp.http.l-req = req.url.lower; - set resp.http.u-req = req.url.upper; - set resp.http.l-mod = (req.url + "bar").lower; - set resp.http.u-mod = (req.url + "bar").upper; - set resp.http.uu-mod = (req.url + "bar").upper.upper; - set resp.http.ul-mod = (req.url + "bar").upper.lower; + set resp.http.l-proto = resp.proto.lower(); + set resp.http.u-proto = resp.proto.upper(); + set resp.http.l-req = req.url.lower(); + set resp.http.u-req = req.url.upper(); + set resp.http.l-mod = (req.url + "bar").lower(); + set resp.http.u-mod = (req.url + "bar").upper(); + set resp.http.uu-mod = (req.url + "bar").upper().upper(); + set resp.http.ul-mod = (req.url + "bar").upper().lower(); } } diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 054b2ef56..29d82a23d 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -803,7 +803,13 @@ vcc_expr5(struct vcc *tl, struct expr **e, vcc_type_t fmt) /*-------------------------------------------------------------------- * SYNTAX: * Expr4: - * Expr5 [ '.' type_method() ]* + * Expr5 [ '.' (type_attribute | type_method()) ]* + * + * type_attributes is information already existing, requiring no + * processing or resource usage. + * + * type_methods are calls and may do (significant processing, change things, + * eat workspace etc. */ static const struct vcc_methods { @@ -811,15 +817,16 @@ static const struct vcc_methods { vcc_type_t type_to; const char *method; const char *impl; + int func; } vcc_methods[] = { //{ BACKEND, BOOL, "healthy", "VRT_Healthy(ctx, \v1, 0)" }, #define VRTSTVVAR(nm, vtype, ctype, dval) \ - { STEVEDORE, vtype, #nm, "VRT_stevedore_" #nm "(\v1)"}, + { STEVEDORE, vtype, #nm, "VRT_stevedore_" #nm "(\v1)", 0}, #include "tbl/vrt_stv_var.h" - { STRINGS, STRING, "upper", "VRT_UpperLowerStrands(ctx, \vT, 1)" }, - { STRINGS, STRING, "lower", "VRT_UpperLowerStrands(ctx, \vT, 0)" }, + { STRINGS, STRING, "upper", "VRT_UpperLowerStrands(ctx, \vT, 1)", 1 }, + { STRINGS, STRING, "lower", "VRT_UpperLowerStrands(ctx, \vT, 0)", 1 }, { NULL, NULL, NULL, NULL}, }; @@ -859,6 +866,12 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt) (*e)->fmt = STRINGS; (*e)->nstr = 1; } + if (vm->func) { + ExpectErr(tl, '('); + vcc_NextToken(tl); + ExpectErr(tl, ')'); + vcc_NextToken(tl); + } } } From phk at FreeBSD.org Wed Aug 14 08:47:06 2019 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 14 Aug 2019 08:47:06 +0000 (UTC) Subject: [master] d9ccdb7c6 Doc-fixino for vcl.label Message-ID: <20190814084706.75FBDA638E@lists.varnish-cache.org> commit d9ccdb7c628c6292c6c58cd1aed57a1e90e2f81d Author: Poul-Henning Kamp Date: Wed Aug 14 08:45:51 2019 +0000 Doc-fixino for vcl.label diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 2798eceb6..403ef54f2 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -690,6 +690,7 @@ void mgt_DumpRstCli(void) { const struct cli_cmd_desc *cp; + const char *p; int i, j; qsort(cmds, ncmds, sizeof cmds[0], cli_cmp); @@ -697,7 +698,10 @@ mgt_DumpRstCli(void) cp = cmds[i]; if (!strncmp(cp->request, "debug.", 6)) continue; - printf(".. _ref_cli_%s:\n\n", cp->syntax); + printf(".. _ref_cli_"); + for (p = cp->request; *p; p++) + putchar(*p == '.' ? '_' : *p); + printf(":\n\n"); printf("%s\n", cp->syntax); for (j = 0; j < strlen(cp->syntax); j++) printf("~"); diff --git a/doc/sphinx/users-guide/vcl-built-in-subs.rst b/doc/sphinx/users-guide/vcl-built-in-subs.rst index 94f62c9da..810ffedad 100644 --- a/doc/sphinx/users-guide/vcl-built-in-subs.rst +++ b/doc/sphinx/users-guide/vcl-built-in-subs.rst @@ -110,7 +110,7 @@ of the following keywords: Switch to vcl labelled *label*. This will continue vcl processing in this vcl's :ref:`vcl_recv` as if it was the active vcl. - See the :ref:`varnishadm(1)` ``vcl.label`` command. + See the :ref:`ref_cli_vcl_label` command. .. _vcl_pipe: @@ -537,8 +537,8 @@ with one of the following keywords: :ref:`vcl_synth` on the client side is called with ``resp.status`` preset to 503. -vcl.load / vcl.discard ----------------------- +During vcl.load / vcl.discard +----------------------------- .. _vcl_init: diff --git a/include/tbl/cli_cmds.h b/include/tbl/cli_cmds.h index d1b9f2afa..3493736c0 100644 --- a/include/tbl/cli_cmds.h +++ b/include/tbl/cli_cmds.h @@ -141,7 +141,9 @@ CLI_CMD(VCL_LABEL, "vcl.label", "vcl.label