From phk at varnish-cache.org Mon Nov 5 09:41:20 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 05 Nov 2012 10:41:20 +0100 Subject: [master] 31ed885 Tailored assertions for priv_addset and setppriv, assert that setppriv(PRIV_OFF) succeeds when waiving privileges. Message-ID: commit 31ed885261920c0a220aad8004ef6db681a8d62c Author: Poul-Henning Kamp Date: Mon Nov 5 09:40:37 2012 +0000 Tailored assertions for priv_addset and setppriv, assert that setppriv(PRIV_OFF) succeeds when waiving privileges. fixes varnish builds on any Solaris OS older than onnv_140 due to too strict assertions from [c613b135570f87535839e3a94630880d16910f4f] add history of solaris privileges better comments Submitted by: Nils Goroll diff --git a/bin/varnishd/mgt/mgt_sandbox_solaris.c b/bin/varnishd/mgt/mgt_sandbox_solaris.c index 728eca0..eaeab8a 100644 --- a/bin/varnishd/mgt/mgt_sandbox_solaris.c +++ b/bin/varnishd/mgt/mgt_sandbox_solaris.c @@ -52,13 +52,132 @@ /*-------------------------------------------------------------------- * SOLARIS PRIVILEGES: Note on use of symbolic PRIV_* constants * - * For privileges which existed in Solaris 10 FCS, we may use the constants from - * sys/priv_names.h + * We assume backwards compatibility only for Solaris Releases after the + * OpenSolaris Launch. For privileges which existed at the time of the + * OpenSolaris Launch, we use the constants from sys/priv_names.h and assert + * that priv_addset must succeed. * - * For privileges which have been added later, we need to use strings in order - * not to break builds of varnish on these platforms. To remain binary - * compatible, we need to silently ignore errors from priv_addset when using - * these strings. + * For privileges which have been added later, we need to use priv strings in + * order not to break builds of varnish on these platforms. To remain binary + * compatible, we can't assert that priv_addset succeeds, but we may assert that + * it either succeeds or fails with EINVAL. + */ + +/* for priv_delset() and priv_addset() */ +static inline int +priv_setop_check(int a) { + if (a == 0) + return (1); + if (errno == EINVAL) + return (1); + return (0); +} + +#define priv_setop_assert(a) assert(priv_setop_check(a)) + +/* + * we try to add all possible privileges to waive them later. + * + * when doing so, we need to expect EPERM + */ + +/* for setppriv */ +static inline int +setppriv_check(int a) { + if (a == 0) + return (1); + if (errno == EPERM) + return (1); + return (0); +} + +#define setppriv_assert(a) assert(setppriv_check(a)) + + +/* + * brief histroy of introduction of privileges since OpenSolaris Launch + * + * (from hg log -gp usr/src/uts/common/os/priv_defs) + * + * ARC cases are not necessarily accurate (induced from commit msg) + * (marked with ?) + * + * privileges used here marked with * + * + * + * ARC case hg commit first release + * + * PSARC/2006/155? 37f4a3e2bd99 onnv_37 + * - file_downgrade_sl + * - file_upgrade_sl + * - net_bindmlp + * - net_mac_aware + * - sys_trans_label + * - win_colormap + * - win_config + * - win_dac_read + * - win_dac_write + * - win_devices + * - win_dga + * - win_downgrade_sl + * - win_fontpath + * - win_mac_read + * - win_mac_write + * - win_selection + * - win_upgrade_sl + * + * PSARC/2006/218 5dbf296c1e57 onnv_39 + * - graphics_access + * - graphics_map + * + * PSARC/2006/366 aaf16568054b onnv_57 + * - net_config + * + * PSARC/2007/315? 3047ad28a67b onnv_77 + * - file_flag_set + * + * PSARC/2007/560? 3047ad28a67b onnv_77 + * - sys_smb + * + * PSARC 2008/046 47f6aa7a8077 onnv_85 + * - contract_identify + * + * PSARC 2008/289 79a9dac325d9 onnv_92 + * - virt_manage + * - xvm_control + * + * PSARC 2008/473 eff7960d93cd onnv_98 + * - sys_dl_config + * + * PSARC/2006/475 faf256d5c16c onnv_103 + * - net_observability + * + * PSARC/2009/317 8e29565352fc onnv_117 + * - sys_ppp_config + * + * PSARC/2009/373 3be00c4a6835 onnv_125 + * - sys_iptun_config + * + * PSARC/2008/252 e209937a4f19 onnv_128 + * - net_mac_implicit + * + * PSARC/2009/685 8eca52188202 onnv_132 + * * net_access + * + * PSARC/2009/378 63678502e95e onnv_140 + * * file_read + * * file_write + * + * PSARC/2010/181 15439b11d535 onnv_142 + * - sys_res_bind + * + * unknown unknown Solaris11 + * - sys_flow_config + * - sys_share + * + * + * SOLARIS PRIVILEGES: Note on introtiction of new privileges (forward + * compatibility) * * For optimal build and binary forward comatibility, we could use subtractive * set specs like @@ -103,14 +222,13 @@ mgt_sandbox_solaris_add_inheritable(priv_set_t *pset, enum sandbox_e who) switch (who) { case SANDBOX_VCC: /* for /etc/resolv.conf and /etc/hosts */ - AZ(priv_addset(pset, "file_read")); + priv_setop_assert(priv_addset(pset, "file_read")); break; case SANDBOX_CC: - AZ(priv_addset(pset, "proc_exec")); - AZ(priv_addset(pset, "proc_fork")); - /* PSARC/2009/378 - 63678502e95e - onnv_140 */ - AZ(priv_addset(pset, "file_read")); - AZ(priv_addset(pset, "file_write")); + priv_setop_assert(priv_addset(pset, PRIV_PROC_EXEC)); + priv_setop_assert(priv_addset(pset, PRIV_PROC_FORK)); + priv_setop_assert(priv_addset(pset, "file_read")); + priv_setop_assert(priv_addset(pset, "file_write")); break; case SANDBOX_VCLLOAD: break; @@ -132,20 +250,16 @@ mgt_sandbox_solaris_add_effective(priv_set_t *pset, enum sandbox_e who) { switch (who) { case SANDBOX_VCC: - /* PSARC/2009/378 - 63678502e95e - onnv_140 */ - AZ(priv_addset(pset, "file_write")); + priv_setop_assert(priv_addset(pset, "file_write")); break; case SANDBOX_CC: break; case SANDBOX_VCLLOAD: - /* PSARC/2009/378 - 63678502e95e - onnv_140 */ - AZ(priv_addset(pset, "file_read")); + priv_setop_assert(priv_addset(pset, "file_read")); case SANDBOX_WORKER: - /* PSARC/2009/685 - 8eca52188202 - onnv_132 */ - AZ(priv_addset(pset, "net_access")); - /* PSARC/2009/378 - 63678502e95e - onnv_140 */ - AZ(priv_addset(pset, "file_read")); - AZ(priv_addset(pset, "file_write")); + priv_setop_assert(priv_addset(pset, "net_access")); + priv_setop_assert(priv_addset(pset, "file_read")); + priv_setop_assert(priv_addset(pset, "file_write")); break; default: REPORT(LOG_ERR, "INCOMPLETE AT: %s(%d)\n", __func__, __LINE__); @@ -218,9 +332,10 @@ mgt_sandbox_solaris_init(enum sandbox_e who) mgt_sandbox_solaris_add_permitted(priv_all, who); mgt_sandbox_solaris_add_initial(priv_all, who); - setppriv(PRIV_ON, PRIV_PERMITTED, priv_all); - setppriv(PRIV_ON, PRIV_EFFECTIVE, priv_all); - setppriv(PRIV_ON, PRIV_INHERITABLE, priv_all); + /* try to get all possible privileges, expect EPERM here */ + setppriv_assert(setppriv(PRIV_ON, PRIV_PERMITTED, priv_all)); + setppriv_assert(setppriv(PRIV_ON, PRIV_EFFECTIVE, priv_all)); + setppriv_assert(setppriv(PRIV_ON, PRIV_INHERITABLE, priv_all)); priv_freeset(priv_all); } @@ -292,18 +407,10 @@ mgt_sandbox_solaris_waive(enum sandbox_e who) priv_inverse(effective); priv_inverse(permitted); -#define SETPPRIV(which, set) \ - if (setppriv(PRIV_OFF, which, set)) \ - REPORT(LOG_ERR, \ - "Sandbox warning: " \ - " Waiving privileges failed on %s: errno=%d (%s)", \ - #which, errno, strerror(errno)); - - SETPPRIV(PRIV_LIMIT, permitted); - SETPPRIV(PRIV_PERMITTED, permitted); - SETPPRIV(PRIV_EFFECTIVE, effective); - SETPPRIV(PRIV_INHERITABLE, inheritable); -#undef SETPPRIV + AZ(setppriv(PRIV_OFF, PRIV_LIMIT, permitted)); + AZ(setppriv(PRIV_OFF, PRIV_PERMITTED, permitted)); + AZ(setppriv(PRIV_OFF, PRIV_EFFECTIVE, effective)); + AZ(setppriv(PRIV_OFF, PRIV_INHERITABLE, inheritable)); priv_freeset(inheritable); priv_freeset(effective); From martin at varnish-cache.org Mon Nov 5 12:41:20 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Mon, 05 Nov 2012 13:41:20 +0100 Subject: [master] 650b13e Fix varnishncsa memory leaks on duplicate headers Message-ID: commit 650b13ed728e5d74eddbe64de585e8738efda603 Author: Martin Blix Grydeland Date: Wed Sep 12 15:26:20 2012 +0200 Fix varnishncsa memory leaks on duplicate headers diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index 88c73eb..0dbebfe 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -140,13 +140,18 @@ isprefix(const char *str, const char *prefix, const char *end, /* * Returns a copy of the first consecutive sequence of non-space - * characters in the string. + * characters in the string in dst. dst will be free'd first if non-NULL. */ -static char * -trimfield(const char *str, const char *end) +static void +trimfield(char **dst, const char *str, const char *end) { size_t len; - char *p; + + /* free if already set */ + if (*dst != NULL) { + free(*dst); + *dst = NULL; + } /* skip leading space */ while (str < end && *str && *str == ' ') @@ -158,22 +163,26 @@ trimfield(const char *str, const char *end) break; /* copy and return */ - p = malloc(len + 1); - assert(p != NULL); - memcpy(p, str, len); - p[len] = '\0'; - return (p); + *dst = malloc(len + 1); + assert(*dst != NULL); + memcpy(*dst, str, len); + (*dst)[len] = '\0'; } /* * Returns a copy of the entire string with leading and trailing spaces - * trimmed. + * trimmed in dst. dst will be free'd first if non-NULL. */ -static char * -trimline(const char *str, const char *end) +static void +trimline(char **dst, const char *str, const char *end) { size_t len; - char *p; + + /* free if already set */ + if (*dst != NULL) { + free(*dst); + *dst = NULL; + } /* skip leading space */ while (str < end && *str && *str == ' ') @@ -188,11 +197,10 @@ trimline(const char *str, const char *end) --len; /* copy and return */ - p = malloc(len + 1); - assert(p != NULL); - memcpy(p, str, len); - p[len] = '\0'; - return (p); + *dst = malloc(len + 1); + assert(*dst != NULL); + memcpy(*dst, str, len); + (*dst)[len] = '\0'; } static char * @@ -288,9 +296,9 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } lp->active = 1; if (isprefix(ptr, "default", end, &next)) - lp->df_h = trimfield(next, end); + trimfield(&lp->df_h, next, end); else - lp->df_h = trimfield(ptr, end); + trimfield(&lp->df_h, ptr, end); break; case SLT_BereqRequest: @@ -300,7 +308,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_m = trimline(ptr, end); + trimline(&lp->df_m, ptr, end); break; case SLT_BereqURL: { @@ -314,10 +322,10 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } qs = memchr(ptr, '?', len); if (qs) { - lp->df_U = trimline(ptr, qs); - lp->df_q = trimline(qs, end); + trimline(&lp->df_U, ptr, qs); + trimline(&lp->df_q, qs, end); } else { - lp->df_U = trimline(ptr, end); + trimline(&lp->df_U, ptr, end); } break; } @@ -329,7 +337,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_H = trimline(ptr, end); + trimline(&lp->df_H, ptr, end); break; case SLT_BerespStatus: @@ -339,14 +347,14 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_s = trimline(ptr, end); + trimline(&lp->df_s, ptr, end); break; case SLT_BerespHeader: if (!lp->active) break; if (isprefix(ptr, "content-length:", end, &next)) - lp->df_b = trimline(next, end); + trimline(&lp->df_b, next, end); else if (isprefix(ptr, "date:", end, &next) && strptime(next, "%a, %d %b %Y %T", &lp->df_t) == NULL) { clean_logline(lp); @@ -361,16 +369,16 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, break; if (isprefix(ptr, "authorization:", end, &next) && isprefix(next, "basic", end, &next)) { - lp->df_u = trimline(next, end); + trimline(&lp->df_u, next, end); } else { struct hdr *h; size_t l; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); l = strlen(split); - h->key = trimline(ptr, split-1); - h->value = trimline(split+1, split+l-1); + trimline(&h->key, ptr, split-1); + trimline(&h->value, split+1, split+l-1); VTAILQ_INSERT_HEAD(&lp->req_headers, h, list); } break; @@ -409,7 +417,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); } lp->active = 1; - lp->df_h = trimfield(ptr, end); + trimfield(&lp->df_h, ptr, end); break; case SLT_ReqRequest: @@ -419,7 +427,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_m = trimline(ptr, end); + trimline(&lp->df_m, ptr, end); break; case SLT_ReqURL: { @@ -433,10 +441,10 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } qs = memchr(ptr, '?', len); if (qs) { - lp->df_U = trimline(ptr, qs); - lp->df_q = trimline(qs, end); + trimline(&lp->df_U, ptr, qs); + trimline(&lp->df_q, qs, end); } else { - lp->df_U = trimline(ptr, end); + trimline(&lp->df_U, ptr, end); } break; } @@ -448,7 +456,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_H = trimline(ptr, end); + trimline(&lp->df_H, ptr, end); break; case SLT_ObjStatus: @@ -457,7 +465,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, if (lp->df_s != NULL) clean_logline(lp); else - lp->df_s = trimline(ptr, end); + trimline(&lp->df_s, ptr, end); break; case SLT_ObjHeader: @@ -470,15 +478,14 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, if (tag == SLT_ReqHeader && isprefix(ptr, "authorization:", end, &next) && isprefix(next, "basic", end, &next)) { - free(lp->df_u); - lp->df_u = trimline(next, end); + trimline(&lp->df_u, next, end); } else { struct hdr *h; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); - h->key = trimline(ptr, split); - h->value = trimline(split+1, end); + trimline(&h->key, ptr, split); + trimline(&h->value, split+1, end); if (tag == SLT_ReqHeader) VTAILQ_INSERT_HEAD(&lp->req_headers, h, list); else @@ -495,12 +502,12 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, break; struct hdr *h; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); - h->key = trimline(ptr, split); - h->value = trimline(split+1, end); + trimline(&h->key, ptr, split); + trimline(&h->value, split+1, end); VTAILQ_INSERT_HEAD(&lp->vcl_log, h, list); break; @@ -532,7 +539,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_b = trimline(ptr, end); + trimline(&lp->df_b, ptr, end); break; case SLT_SessClose: @@ -556,6 +563,8 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } + if (lp->df_ttfb != NULL) + free(lp->df_ttfb); lp->df_ttfb = strdup(ttfb); t = l; localtime_r(&t, &lp->df_t); From martin at varnish-cache.org Mon Nov 5 12:44:20 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Mon, 05 Nov 2012 13:44:20 +0100 Subject: [3.0] 424743b Fix varnishncsa memory leaks on duplicate headers Message-ID: commit 424743bb37f498b42d905a5e4ff30e160e0ceaa4 Author: Martin Blix Grydeland Date: Wed Sep 12 15:26:20 2012 +0200 Fix varnishncsa memory leaks on duplicate headers diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index ff07ed5..f66bb18 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -136,13 +136,18 @@ isprefix(const char *str, const char *prefix, const char *end, /* * Returns a copy of the first consecutive sequence of non-space - * characters in the string. + * characters in the string in dst. dst will be free'd first if non-NULL. */ -static char * -trimfield(const char *str, const char *end) +static void +trimfield(char **dst, const char *str, const char *end) { size_t len; - char *p; + + /* free if already set */ + if (*dst != NULL) { + free(*dst); + *dst = NULL; + } /* skip leading space */ while (str < end && *str && *str == ' ') @@ -154,22 +159,26 @@ trimfield(const char *str, const char *end) break; /* copy and return */ - p = malloc(len + 1); - assert(p != NULL); - memcpy(p, str, len); - p[len] = '\0'; - return (p); + *dst = malloc(len + 1); + assert(*dst != NULL); + memcpy(*dst, str, len); + (*dst)[len] = '\0'; } /* * Returns a copy of the entire string with leading and trailing spaces - * trimmed. + * trimmed in dst. dst will be free'd first if non-NULL. */ -static char * -trimline(const char *str, const char *end) +static void +trimline(char **dst, const char *str, const char *end) { size_t len; - char *p; + + /* free if already set */ + if (*dst != NULL) { + free(*dst); + *dst = NULL; + } /* skip leading space */ while (str < end && *str && *str == ' ') @@ -184,11 +193,10 @@ trimline(const char *str, const char *end) --len; /* copy and return */ - p = malloc(len + 1); - assert(p != NULL); - memcpy(p, str, len); - p[len] = '\0'; - return (p); + *dst = malloc(len + 1); + assert(*dst != NULL); + memcpy(*dst, str, len); + (*dst)[len] = '\0'; } static char * @@ -284,9 +292,9 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } lp->active = 1; if (isprefix(ptr, "default", end, &next)) - lp->df_h = trimfield(next, end); + trimfield(&lp->df_h, next, end); else - lp->df_h = trimfield(ptr, end); + trimfield(&lp->df_h, ptr, end); break; case SLT_TxRequest: @@ -296,7 +304,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_m = trimline(ptr, end); + trimline(&lp->df_m, ptr, end); break; case SLT_TxURL: { @@ -310,10 +318,10 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } qs = index(ptr, '?'); if (qs) { - lp->df_U = trimline(ptr, qs); - lp->df_q = trimline(qs, end); + trimline(&lp->df_U, ptr, qs); + trimline(&lp->df_q, qs, end); } else { - lp->df_U = trimline(ptr, end); + trimline(&lp->df_U, ptr, end); } break; } @@ -325,7 +333,7 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_H = trimline(ptr, end); + trimline(&lp->df_H, ptr, end); break; case SLT_RxStatus: @@ -335,14 +343,14 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_s = trimline(ptr, end); + trimline(&lp->df_s, ptr, end); break; case SLT_RxHeader: if (!lp->active) break; if (isprefix(ptr, "content-length:", end, &next)) - lp->df_b = trimline(next, end); + trimline(&lp->df_b, next, end); else if (isprefix(ptr, "date:", end, &next) && strptime(next, "%a, %d %b %Y %T", &lp->df_t) == NULL) { clean_logline(lp); @@ -357,16 +365,16 @@ collect_backend(struct logline *lp, enum VSL_tag_e tag, unsigned spec, break; if (isprefix(ptr, "authorization:", end, &next) && isprefix(next, "basic", end, &next)) { - lp->df_u = trimline(next, end); + trimline(&lp->df_u, next, end); } else { struct hdr *h; size_t l; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); l = strlen(split); - h->key = trimline(ptr, split-1); - h->value = trimline(split+1, split+l-1); + trimline(&h->key, ptr, split-1); + trimline(&h->value, split+1, split+l-1); VTAILQ_INSERT_HEAD(&lp->req_headers, h, list); } break; @@ -405,7 +413,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); } lp->active = 1; - lp->df_h = trimfield(ptr, end); + trimfield(&lp->df_h, ptr, end); break; case SLT_RxRequest: @@ -415,7 +423,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_m = trimline(ptr, end); + trimline(&lp->df_m, ptr, end); break; case SLT_RxURL: { @@ -429,10 +437,10 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, } qs = index(ptr, '?'); if (qs) { - lp->df_U = trimline(ptr, qs); - lp->df_q = trimline(qs, end); + trimline(&lp->df_U, ptr, qs); + trimline(&lp->df_q, qs, end); } else { - lp->df_U = trimline(ptr, end); + trimline(&lp->df_U, ptr, end); } break; } @@ -444,7 +452,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_H = trimline(ptr, end); + trimline(&lp->df_H, ptr, end); break; case SLT_TxStatus: @@ -453,7 +461,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, if (lp->df_s != NULL) clean_logline(lp); else - lp->df_s = trimline(ptr, end); + trimline(&lp->df_s, ptr, end); break; case SLT_TxHeader: @@ -466,15 +474,14 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, if (tag == SLT_RxHeader && isprefix(ptr, "authorization:", end, &next) && isprefix(next, "basic", end, &next)) { - free(lp->df_u); - lp->df_u = trimline(next, end); + trimline(&lp->df_u, next, end); } else { struct hdr *h; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); - h->key = trimline(ptr, split); - h->value = trimline(split+1, end); + trimline(&h->key, ptr, split); + trimline(&h->value, split+1, end); if (tag == SLT_RxHeader) VTAILQ_INSERT_HEAD(&lp->req_headers, h, list); else @@ -491,12 +498,12 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, break; struct hdr *h; - h = malloc(sizeof(struct hdr)); + h = calloc(1, sizeof(struct hdr)); AN(h); AN(split); - h->key = trimline(ptr, split); - h->value = trimline(split+1, end); + trimline(&h->key, ptr, split); + trimline(&h->value, split+1, end); VTAILQ_INSERT_HEAD(&lp->vcl_log, h, list); break; @@ -528,7 +535,7 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } - lp->df_b = trimline(ptr, end); + trimline(&lp->df_b, ptr, end); break; case SLT_SessionClose: @@ -550,6 +557,8 @@ collect_client(struct logline *lp, enum VSL_tag_e tag, unsigned spec, clean_logline(lp); break; } + if (lp->df_ttfb != NULL) + free(lp->df_ttfb); lp->df_ttfb = strdup(ttfb); t = l; localtime_r(&t, &lp->df_t); From phk at varnish-cache.org Mon Nov 5 15:23:51 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 05 Nov 2012 16:23:51 +0100 Subject: [master] 1a02024 Increase the 'client_workspace' for 32bit machines to be twice the size of the 'http_req_size' so that we don't run out of WS in case of client pipelining. Message-ID: commit 1a02024a9ece62d55d40deebd971e485775c5d9d Author: Poul-Henning Kamp Date: Mon Nov 5 15:22:02 2012 +0000 Increase the 'client_workspace' for 32bit machines to be twice the size of the 'http_req_size' so that we don't run out of WS in case of client pipelining. Fixes #1185 diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index a760b40..1b7f1e3 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -385,7 +385,7 @@ main(int argc, char * const *argv) * Adjust default parameters for 32 bit systems to conserve * VM space. */ - MCF_ParamSet(cli, "workspace_client", "16k"); + MCF_ParamSet(cli, "workspace_client", "24k"); cli_check(cli); MCF_ParamSet(cli, "workspace_backend", "16k"); From martin at varnish-cache.org Wed Nov 7 11:21:40 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Wed, 07 Nov 2012 12:21:40 +0100 Subject: [master] 042a2d6 Don't always check the sign after smp_append_sign(). Message-ID: commit 042a2d631c5f5a697cd0951eba276401f09bb957 Author: Martin Blix Grydeland Date: Wed Oct 3 15:08:14 2012 +0200 Don't always check the sign after smp_append_sign(). Remove the XXXAZ(smp_chk_sign) after smp_append_sign(), as it causes heavy unnecessary CPU usage after each sign update. No assertion reports have come from this test, so there is no reason to expect the signs not working. diff --git a/bin/varnishd/storage/storage_persistent_subr.c b/bin/varnishd/storage/storage_persistent_subr.c index 0b1b7da..0589af9 100644 --- a/bin/varnishd/storage/storage_persistent_subr.c +++ b/bin/varnishd/storage/storage_persistent_subr.c @@ -128,7 +128,6 @@ smp_append_sign(struct smp_signctx *ctx, const void *ptr, uint32_t len) SHA256_Update(&cx, &ctx->ss->length, sizeof(ctx->ss->length)); SHA256_Final(sign, &cx); memcpy(SIGN_END(ctx), sign, sizeof sign); -XXXAZ(smp_chk_sign(ctx)); } /*-------------------------------------------------------------------- From phk at varnish-cache.org Mon Nov 12 08:14:58 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 12 Nov 2012 09:14:58 +0100 Subject: [master] 7db894f Return false if req.backend.health is accessed in vcl_deliver{} where this information is no longer available. Message-ID: commit 7db894f93330eed1da99336f69a3073a9629eeab Author: Poul-Henning Kamp Date: Mon Nov 12 08:14:11 2012 +0000 Return false if req.backend.health is accessed in vcl_deliver{} where this information is no longer available. Fixes #1228 diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 535e5ee..76c17d6 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -555,6 +555,12 @@ unsigned VRT_r_req_backend_healthy(const struct req *req) { CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + /* + * XXX: Not optimal, but we do not have a backend in vcl_deliver + * XXX: and we have to return something. + */ + if (req->director == NULL) + return (0); CHECK_OBJ_NOTNULL(req->director, DIRECTOR_MAGIC); return (VDI_Healthy(req->director, req)); } diff --git a/bin/varnishtest/tests/r01228.vcl b/bin/varnishtest/tests/r01228.vcl new file mode 100644 index 0000000..55d5689 --- /dev/null +++ b/bin/varnishtest/tests/r01228.vcl @@ -0,0 +1,18 @@ +varnishtest "req.backend.healthy in vcl_deliver" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_deliver { + set resp.http.x-foo = req.backend.healthy; + } +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run From phk at varnish-cache.org Mon Nov 12 08:48:40 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 12 Nov 2012 09:48:40 +0100 Subject: [master] a6d082e Count reloaded bans in VSC::bans_req Message-ID: commit a6d082e96efc047da0ce33dd663e506347fe321f Author: Poul-Henning Kamp Date: Mon Nov 12 08:46:40 2012 +0000 Count reloaded bans in VSC::bans_req Replace some magic numbers by #defines and segregate the ban-string Base patch from: martin Fixes #1225 diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index aa8bca9..5f9c68a 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -44,10 +44,10 @@ * 1 byte - flags: 0x01: BAN_F_REQ * N tests * A test have this form: - * 1 byte - arg (see ban_vars.h col 3 "BAN_ARG_XXX") + * 1 byte - arg (see ban_vars.h col 3 "BANS_ARG_XXX") * (n bytes) - http header name, canonical encoding * lump - comparison arg - * 1 byte - operation (BAN_OPER_) + * 1 byte - operation (BANS_OPER_) * (lump) - compiled regexp * A lump is: * 4 bytes - be32: length @@ -106,18 +106,21 @@ static struct ban * volatile ban_start; static bgthread_t ban_lurker; /*-------------------------------------------------------------------- - * BAN string magic markers + * BAN string defines & magic markers */ -#define BAN_OPER_EQ 0x10 -#define BAN_OPER_NEQ 0x11 -#define BAN_OPER_MATCH 0x12 -#define BAN_OPER_NMATCH 0x13 +#define BANS_FLAGS 12 +#define BANS_FLAG_REQ 0x01 -#define BAN_ARG_URL 0x18 -#define BAN_ARG_REQHTTP 0x19 -#define BAN_ARG_OBJHTTP 0x1a -#define BAN_ARG_OBJSTATUS 0x1b +#define BANS_OPER_EQ 0x10 +#define BANS_OPER_NEQ 0x11 +#define BANS_OPER_MATCH 0x12 +#define BANS_OPER_NMATCH 0x13 + +#define BANS_ARG_URL 0x18 +#define BANS_ARG_REQHTTP 0x19 +#define BANS_ARG_OBJHTTP 0x1a +#define BANS_ARG_OBJSTATUS 0x1b /*-------------------------------------------------------------------- * Variables we can purge on @@ -261,13 +264,13 @@ ban_iter(const uint8_t **bs, struct ban_test *bt) memset(bt, 0, sizeof *bt); bt->arg1 = *(*bs)++; - if (bt->arg1 == BAN_ARG_REQHTTP || bt->arg1 == BAN_ARG_OBJHTTP) { + if (bt->arg1 == BANS_ARG_REQHTTP || bt->arg1 == BANS_ARG_OBJHTTP) { bt->arg1_spec = (const char *)*bs; (*bs) += (*bs)[0] + 2; } bt->arg2 = ban_get_lump(bs); bt->oper = *(*bs)++; - if (bt->oper == BAN_OPER_MATCH || bt->oper == BAN_OPER_NMATCH) + if (bt->oper == BANS_OPER_MATCH || bt->oper == BANS_OPER_NMATCH) bt->arg2_spec = ban_get_lump(bs); } @@ -345,19 +348,19 @@ BAN_AddTest(struct cli *cli, struct ban *b, const char *a1, const char *a2, ban_add_lump(b, a3, strlen(a3) + 1); if (!strcmp(a2, "~")) { - VSB_putc(b->vsb, BAN_OPER_MATCH); + VSB_putc(b->vsb, BANS_OPER_MATCH); i = ban_parse_regexp(cli, b, a3); if (i) return (i); } else if (!strcmp(a2, "!~")) { - VSB_putc(b->vsb, BAN_OPER_NMATCH); + VSB_putc(b->vsb, BANS_OPER_NMATCH); i = ban_parse_regexp(cli, b, a3); if (i) return (i); } else if (!strcmp(a2, "==")) { - VSB_putc(b->vsb, BAN_OPER_EQ); + VSB_putc(b->vsb, BANS_OPER_EQ); } else if (!strcmp(a2, "!=")) { - VSB_putc(b->vsb, BAN_OPER_NEQ); + VSB_putc(b->vsb, BANS_OPER_NEQ); } else { VCLI_Out(cli, "expected conditional (~, !~, == or !=) got \"%s\"", a2); @@ -392,7 +395,7 @@ BAN_Insert(struct ban *b) t0 = VTIM_real(); memcpy(b->spec, &t0, sizeof t0); - b->spec[12] = (b->flags & BAN_F_REQ) ? 1 : 0; + b->spec[BANS_FLAGS] = (b->flags & BAN_F_REQ) ? BANS_FLAG_REQ : 0; memcpy(b->spec + 13, VSB_data(b->vsb), ln); ln += 13; vbe32enc(b->spec + 8, ln); @@ -551,8 +554,10 @@ BAN_Reload(const uint8_t *ban, unsigned len) AN(b2->spec); memcpy(b2->spec, ban, len); b2->flags |= gone; - if (ban[12]) + if (ban[BANS_FLAGS] & BANS_FLAG_REQ) { + VSC_C_main->bans_req++; b2->flags |= BAN_F_REQ; + } if (b == NULL) VTAILQ_INSERT_TAIL(&ban_head, b2, list); else @@ -623,18 +628,18 @@ ban_evaluate(const uint8_t *bs, const struct http *objhttp, ban_iter(&bs, &bt); arg1 = NULL; switch (bt.arg1) { - case BAN_ARG_URL: + case BANS_ARG_URL: AN(reqhttp); arg1 = reqhttp->hd[HTTP_HDR_URL].b; break; - case BAN_ARG_REQHTTP: + case BANS_ARG_REQHTTP: AN(reqhttp); (void)http_GetHdr(reqhttp, bt.arg1_spec, &arg1); break; - case BAN_ARG_OBJHTTP: + case BANS_ARG_OBJHTTP: (void)http_GetHdr(objhttp, bt.arg1_spec, &arg1); break; - case BAN_ARG_OBJSTATUS: + case BANS_ARG_OBJSTATUS: arg1 = buf; sprintf(buf, "%d", objhttp->status); break; @@ -643,21 +648,21 @@ ban_evaluate(const uint8_t *bs, const struct http *objhttp, } switch (bt.oper) { - case BAN_OPER_EQ: + case BANS_OPER_EQ: if (arg1 == NULL || strcmp(arg1, bt.arg2)) return (0); break; - case BAN_OPER_NEQ: + case BANS_OPER_NEQ: if (arg1 != NULL && !strcmp(arg1, bt.arg2)) return (0); break; - case BAN_OPER_MATCH: + case BANS_OPER_MATCH: if (arg1 == NULL || pcre_exec(bt.arg2_spec, NULL, arg1, strlen(arg1), 0, 0, NULL, 0) < 0) return (0); break; - case BAN_OPER_NMATCH: + case BANS_OPER_NMATCH: if (arg1 != NULL && pcre_exec(bt.arg2_spec, NULL, arg1, strlen(arg1), 0, 0, NULL, 0) >= 0) @@ -1060,14 +1065,14 @@ ban_render(struct cli *cli, const uint8_t *bs) while (bs < be) { ban_iter(&bs, &bt); switch (bt.arg1) { - case BAN_ARG_URL: + case BANS_ARG_URL: VCLI_Out(cli, "req.url"); break; - case BAN_ARG_REQHTTP: + case BANS_ARG_REQHTTP: VCLI_Out(cli, "req.http.%.*s", bt.arg1_spec[0] - 1, bt.arg1_spec + 1); break; - case BAN_ARG_OBJHTTP: + case BANS_ARG_OBJHTTP: VCLI_Out(cli, "obj.http.%.*s", bt.arg1_spec[0] - 1, bt.arg1_spec + 1); break; @@ -1075,10 +1080,10 @@ ban_render(struct cli *cli, const uint8_t *bs) INCOMPL(); } switch (bt.oper) { - case BAN_OPER_EQ: VCLI_Out(cli, " == "); break; - case BAN_OPER_NEQ: VCLI_Out(cli, " != "); break; - case BAN_OPER_MATCH: VCLI_Out(cli, " ~ "); break; - case BAN_OPER_NMATCH: VCLI_Out(cli, " !~ "); break; + case BANS_OPER_EQ: VCLI_Out(cli, " == "); break; + case BANS_OPER_NEQ: VCLI_Out(cli, " != "); break; + case BANS_OPER_MATCH: VCLI_Out(cli, " ~ "); break; + case BANS_OPER_NMATCH: VCLI_Out(cli, " !~ "); break; default: INCOMPL(); } diff --git a/bin/varnishtest/tests/r01225.vtc b/bin/varnishtest/tests/r01225.vtc new file mode 100644 index 0000000..5ae42b3 --- /dev/null +++ b/bin/varnishtest/tests/r01225.vtc @@ -0,0 +1,62 @@ +varnishtest "Test bans_req counter on persistent reload - #1225" + +shell "rm -f ${tmpdir}/_.per" + +server s1 { + rxreq + expect req.url == "/" + txresp -hdr "Foo: foo" +} -start + +varnish v1 \ + -arg "-pfeature=+wait_silo" \ + -storage "-spersistent,${tmpdir}/_.per,10m" \ + -arg "-pban_lurker_sleep=0.01" \ + -vcl+backend { } -start + +varnish v1 -cliok ban.list + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.foo == "foo" +} -run + +# Count of 1 here (magic ban only) +varnish v1 -expect bans == 1 +varnish v1 -cliok "ban req.url == /" +varnish v1 -cliok ban.list + +# Count of 2 here (our + magic ban) +varnish v1 -expect bans == 2 +varnish v1 -expect bans_req == 1 +varnish v1 -stop +server s1 -wait + +server s1 { + rxreq + expect req.url == "/" + txresp -hdr "Foo: bar" +} -start + +varnish v1 -start + +varnish v1 -cliok ban.list + +# Count of >2 here, ours plus magic bans from 2 startups +varnish v1 -expect bans >= 2 + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.foo == "bar" +} -run + +varnish v1 -cliok ban.list +# Count of 1 here +varnish v1 -expect bans == 1 +varnish v1 -expect bans_req == 0 + +varnish v1 -stop diff --git a/include/tbl/ban_vars.h b/include/tbl/ban_vars.h index 65b17e0..abf083e 100644 --- a/include/tbl/ban_vars.h +++ b/include/tbl/ban_vars.h @@ -32,7 +32,7 @@ #define PVAR_HTTP 1 #define PVAR_REQ 2 -PVAR("req.url", PVAR_REQ, BAN_ARG_URL) -PVAR("req.http.", PVAR_REQ|PVAR_HTTP, BAN_ARG_REQHTTP) -PVAR("obj.http.", PVAR_HTTP, BAN_ARG_OBJHTTP) -PVAR("obj.status", 0, BAN_ARG_OBJSTATUS) +PVAR("req.url", PVAR_REQ, BANS_ARG_URL) +PVAR("req.http.", PVAR_REQ|PVAR_HTTP, BANS_ARG_REQHTTP) +PVAR("obj.http.", PVAR_HTTP, BANS_ARG_OBJHTTP) +PVAR("obj.status", 0, BANS_ARG_OBJSTATUS) From phk at varnish-cache.org Mon Nov 12 09:59:32 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 12 Nov 2012 10:59:32 +0100 Subject: [master] bdb02ef Polish up cache_ban inspired by Martins 04/15 patch. Message-ID: commit bdb02ef14f7717f50f2f18c5c0aab3f19923c043 Author: Poul-Henning Kamp Date: Mon Nov 12 09:58:44 2012 +0000 Polish up cache_ban inspired by Martins 04/15 patch. Add a function for comparing ban-strings, mostly to have a place to put the explanatory comment. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 5f9c68a..d692211 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -109,7 +109,10 @@ static bgthread_t ban_lurker; * BAN string defines & magic markers */ +#define BANS_TIMESTAMP 0 +#define BANS_LENGTH 8 #define BANS_FLAGS 12 +#define BANS_HEAD_LEN 13 #define BANS_FLAG_REQ 0x01 #define BANS_OPER_EQ 0x10 @@ -213,7 +216,7 @@ ban_time(const uint8_t *banspec) { double t; - assert(sizeof t == 8); + assert(sizeof t == (BANS_LENGTH - BANS_TIMESTAMP)); memcpy(&t, banspec, sizeof t); return (t); } @@ -223,10 +226,24 @@ ban_len(const uint8_t *banspec) { unsigned u; - u = vbe32dec(banspec + 8); + u = vbe32dec(banspec + BANS_LENGTH); return (u); } +static int +ban_equal(const uint8_t *bs1, const uint8_t *bs2) +{ + unsigned u; + + /* + * Compare two ban-strings. + * The memcmp() is safe because the first field we compare is the + * length and that is part of the fixed header structure. + */ + u = vbe32dec(bs1 + BANS_LENGTH); + return (!memcmp(bs1 + BANS_LENGTH, bs2 + BANS_LENGTH, u - BANS_LENGTH)); +} + /*-------------------------------------------------------------------- * Access a lump of bytes in a ban test spec */ @@ -390,15 +407,15 @@ BAN_Insert(struct ban *b) ln = VSB_len(b->vsb); assert(ln >= 0); - b->spec = malloc(ln + 13L); /* XXX */ + b->spec = malloc(ln + BANS_HEAD_LEN); XXXAN(b->spec); t0 = VTIM_real(); - memcpy(b->spec, &t0, sizeof t0); + memcpy(b->spec + BANS_TIMESTAMP, &t0, sizeof t0); b->spec[BANS_FLAGS] = (b->flags & BAN_F_REQ) ? BANS_FLAG_REQ : 0; - memcpy(b->spec + 13, VSB_data(b->vsb), ln); - ln += 13; - vbe32enc(b->spec + 8, ln); + memcpy(b->spec + BANS_HEAD_LEN, VSB_data(b->vsb), ln); + ln += BANS_HEAD_LEN; + vbe32enc(b->spec + BANS_LENGTH, ln); VSB_delete(b->vsb); b->vsb = NULL; @@ -430,8 +447,7 @@ BAN_Insert(struct ban *b) bi = VTAILQ_NEXT(bi, list); if (bi->flags & BAN_F_GONE) continue; - /* Safe because the length is part of the fixed size hdr */ - if (memcmp(b->spec + 8, bi->spec + 8, ln - 8)) + if (!ban_equal(b->spec, bi->spec)) continue; bi->flags |= BAN_F_GONE; VSC_C_main->bans_gone++; @@ -538,7 +554,7 @@ BAN_Reload(const uint8_t *ban, unsigned len) } if (t1 < t0) break; - if (!memcmp(b->spec + 8, ban + 8, len - 8)) { + if (ban_equal(b->spec, ban)) { gone |= BAN_F_GONE; VSC_C_main->bans_dups++; VSC_C_main->bans_gone++; @@ -567,7 +583,7 @@ BAN_Reload(const uint8_t *ban, unsigned len) for (b = VTAILQ_NEXT(b2, list); b != NULL; b = VTAILQ_NEXT(b, list)) { if (b->flags & BAN_F_GONE) continue; - if (!memcmp(b->spec + 8, ban + 8, len - 8)) { + if (ban_equal(b->spec, ban)) { b->flags |= BAN_F_GONE; VSC_C_main->bans_dups++; VSC_C_main->bans_gone++; @@ -1061,7 +1077,7 @@ ban_render(struct cli *cli, const uint8_t *bs) const uint8_t *be; be = bs + ban_len(bs); - bs += 13; + bs += BANS_HEAD_LEN; while (bs < be) { ban_iter(&bs, &bt); switch (bt.arg1) { From phk at varnish-cache.org Mon Nov 12 11:05:10 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 12 Nov 2012 12:05:10 +0100 Subject: [master] 23e9967 Centralize GONE'ing of bans, and also mark their spec GONE, including truncating the length. Message-ID: commit 23e9967f5a0e282c5f060067197740ce69473be6 Author: Poul-Henning Kamp Date: Mon Nov 12 11:04:35 2012 +0000 Centralize GONE'ing of bans, and also mark their spec GONE, including truncating the length. Inspired by: patches and talks from martin diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index d692211..2f142df 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -72,6 +72,7 @@ #include "vcli.h" #include "vcli_priv.h" #include "vend.h" +#include "vmb.h" #include "vtim.h" struct ban { @@ -114,6 +115,7 @@ static bgthread_t ban_lurker; #define BANS_FLAGS 12 #define BANS_HEAD_LEN 13 #define BANS_FLAG_REQ 0x01 +#define BANS_FLAG_GONE 0x02 #define BANS_OPER_EQ 0x10 #define BANS_OPER_NEQ 0x11 @@ -244,6 +246,18 @@ ban_equal(const uint8_t *bs1, const uint8_t *bs2) return (!memcmp(bs1 + BANS_LENGTH, bs2 + BANS_LENGTH, u - BANS_LENGTH)); } +static void +ban_mark_gone(struct ban *b) +{ + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + b->flags |= BAN_F_GONE; + b->spec[BANS_FLAGS] |= BANS_FLAG_GONE; + VWMB(); + vbe32enc(b->spec + BANS_LENGTH, 0); + VSC_C_main->bans_gone++; +} + /*-------------------------------------------------------------------- * Access a lump of bytes in a ban test spec */ @@ -449,8 +463,7 @@ BAN_Insert(struct ban *b) continue; if (!ban_equal(b->spec, bi->spec)) continue; - bi->flags |= BAN_F_GONE; - VSC_C_main->bans_gone++; + ban_mark_gone(bi); VSC_C_main->bans_dups++; } be->refcount--; @@ -584,9 +597,8 @@ BAN_Reload(const uint8_t *ban, unsigned len) if (b->flags & BAN_F_GONE) continue; if (ban_equal(b->spec, ban)) { - b->flags |= BAN_F_GONE; + ban_mark_gone(b); VSC_C_main->bans_dups++; - VSC_C_main->bans_gone++; } } Lck_Unlock(&ban_mtx); @@ -950,10 +962,8 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass) } Lck_AssertHeld(&ban_mtx); if (!(b->flags & BAN_F_REQ)) { - if (!(b->flags & BAN_F_GONE)) { - b->flags |= BAN_F_GONE; - VSC_C_main->bans_gone++; - } + if (!(b->flags & BAN_F_GONE)) + ban_mark_gone(b); if (DO_DEBUG(DBG_LURKER)) VSLb(vsl, SLT_Debug, "lurker BAN %f now gone", ban_time(b->spec)); From tfheen at varnish-cache.org Tue Nov 13 07:07:38 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Tue, 13 Nov 2012 08:07:38 +0100 Subject: [master] 57d212e No point in referencing ancient history Message-ID: commit 57d212eadbc37be4b0eb008fe07b3a863f2b0993 Author: Tollef Fog Heen Date: Mon Nov 12 09:40:39 2012 +0100 No point in referencing ancient history diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 60daaa3..50c339b 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -291,9 +291,8 @@ To match an IP address against an ACL, simply use the match operator: Regular Expressions ------------------- -In Varnish 2.1.0 Varnish switched to using PCRE - Perl-compatible -regular expressions. For a complete description of PCRE please see the -PCRE(3) man page. +Varnish uses PCRE - Perl-compatible regular expressions. For a +complete description of PCRE please see the pcre(3) man page. To send flags to the PCRE engine, such as to turn on *case insensitivity* add the flag within parens following a question mark, From tfheen at varnish-cache.org Tue Nov 13 07:07:38 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Tue, 13 Nov 2012 08:07:38 +0100 Subject: [master] 7cfe196 Use a red-black tree for storing the varnishtop entries Message-ID: commit 7cfe1967512f5f7afefbb923170f91d3f862b9c4 Author: Tollef Fog Heen Date: Tue Nov 13 08:03:44 2012 +0100 Use a red-black tree for storing the varnishtop entries When using varnishtop -1 on a large log file, the old linked list approach was very slow. Using a tree increases performance significantly. In a test, old was 15 minutes, 52 seconds, new code changes that to about 1.8 seconds. diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c index 04b97d7..7cf1568 100644 --- a/bin/varnishtop/varnishtop.c +++ b/bin/varnishtop/varnishtop.c @@ -48,7 +48,7 @@ #include "vapi/vsm.h" #include "vas.h" #include "vcs.h" -#include "vqueue.h" +#include "vtree.h" #include "vsb.h" #if 0 @@ -62,11 +62,14 @@ struct top { char *rec_data; int clen; unsigned hash; - VTAILQ_ENTRY(top) list; + VRB_ENTRY(top) entry; double count; }; -static VTAILQ_HEAD(tophead, top) top_head = VTAILQ_HEAD_INITIALIZER(top_head); +static int top_cmp(const struct top *tp, const struct top *tp2); + +static VRB_HEAD(top_tree, top) top_tree_head = VRB_INITIALIZER(&top_tree_head); +VRB_PROTOTYPE(top_tree, top, entry, top_cmp); static unsigned ntop; @@ -78,12 +81,40 @@ static int f_flag = 0; static unsigned maxfieldlen = 0; +VRB_GENERATE(top_tree, top, entry, top_cmp); + +static int top_cmp(const struct top *tp, const struct top *tp2) +{ + if (tp->count == tp2->count || tp->count == 0.0) { + if (tp->hash == tp2->hash) { + if (tp->tag == tp2->tag) { + if (tp->clen == tp2->clen) { + return (memcmp(tp->rec_data, tp2->rec_data, tp->clen)); + } else { + return (tp->clen - tp2->clen); + } + } else { + return (tp->tag - tp2->tag); + } + } else { + return (tp->hash - tp2->hash); + } + } else { + if (tp->count > tp2->count) + return -1; + else + return 1; + } +} + + static int accumulate(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, unsigned spec, const char *ptr, uint64_t bm) { - struct top *tp, *tp2; + struct top *tp, t; const char *q; + char *rd; unsigned int u; int i; @@ -102,21 +133,22 @@ accumulate(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, } u += *q; } + t.hash = u; + t.tag = tag; + t.clen = len; + rd = malloc(len); + AN(rd); + memcpy(rd, ptr, len); + t.rec_data = rd; AZ(pthread_mutex_lock(&mtx)); - VTAILQ_FOREACH(tp, &top_head, list) { - if (tp->hash != u) - continue; - if (tp->tag != tag) - continue; - if (tp->clen != len) - continue; - if (memcmp(ptr, tp->rec_data, len)) - continue; + tp = VRB_FIND(top_tree, &top_tree_head, &t); + if (tp) { + VRB_REMOVE(top_tree, &top_tree_head, tp); tp->count += 1.0; - break; - } - if (tp == NULL) { + /* Reinsert to rebalance */ + VRB_INSERT(top_tree, &top_tree_head, tp); + } else { ntop++; tp = calloc(sizeof *tp, 1); assert(tp != NULL); @@ -128,21 +160,7 @@ accumulate(void *priv, enum VSL_tag_e tag, unsigned fd, unsigned len, tp->tag = tag; memcpy(tp->rec_data, ptr, len); tp->rec_data[len] = '\0'; - VTAILQ_INSERT_TAIL(&top_head, tp, list); - } - while (1) { - tp2 = VTAILQ_PREV(tp, tophead, list); - if (tp2 == NULL || tp2->count >= tp->count) - break; - VTAILQ_REMOVE(&top_head, tp2, list); - VTAILQ_INSERT_AFTER(&top_head, tp, tp2, list); - } - while (1) { - tp2 = VTAILQ_NEXT(tp, list); - if (tp2 == NULL || tp2->count <= tp->count) - break; - VTAILQ_REMOVE(&top_head, tp2, list); - VTAILQ_INSERT_BEFORE(tp, tp2, list); + VRB_INSERT(top_tree, &top_tree_head, tp); } AZ(pthread_mutex_unlock(&mtx)); @@ -170,7 +188,8 @@ update(const struct VSM_data *vd, int period) AC(erase()); AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd))); AC(mvprintw(0, 0, "list length %u", ntop)); - VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { + for (tp = VRB_MIN(top_tree, &top_tree_head); tp != NULL; tp = tp2) { + tp2 = VRB_NEXT(top_tree, &top_tree_head, tp); if (++l < LINES) { len = tp->clen; if (len > COLS - 20) @@ -183,7 +202,7 @@ update(const struct VSM_data *vd, int period) } tp->count += (1.0/3.0 - tp->count) / (double)n; if (tp->count * 10 < t || l > LINES * 10) { - VTAILQ_REMOVE(&top_head, tp, list); + VRB_REMOVE(top_tree, &top_tree_head, tp); free(tp->rec_data); free(tp); ntop--; @@ -276,10 +295,12 @@ static void dump(void) { struct top *tp, *tp2; - - VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) { + printf("%d\n", ntop); + printf("%p\n", VRB_MIN(top_tree, &top_tree_head)); + for (tp = VRB_MIN(top_tree, &top_tree_head); tp != NULL; tp = tp2) { + tp2 = VRB_NEXT(top_tree, &top_tree_head, tp); if (tp->count <= 1.0) - break; + break; printf("%9.2f %s %*.*s\n", tp->count, VSL_tags[tp->tag], tp->clen, tp->clen, tp->rec_data); diff --git a/bin/varnishtop/vtree.h b/bin/varnishtop/vtree.h new file mode 100644 index 0000000..3b57f20 --- /dev/null +++ b/bin/varnishtop/vtree.h @@ -0,0 +1,763 @@ +/* $NetBSD: tree.h,v 1.8 2004/03/28 19:38:30 provos Exp $ */ +/* $OpenBSD: tree.h,v 1.7 2002/10/17 21:51:54 art Exp $ */ +/* $FreeBSD: release/9.0.0/sys/sys/tree.h 189204 2009-03-01 04:57:23Z bms $ */ + +/*- + * Copyright 2002 Niels Provos + * All rights reserved. + * + * 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 ``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 THE AUTHOR 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. + */ + +#ifndef _VTREE_H_ +#define _VTREE_H_ + +/* + * This file defines data structures for different types of trees: + * splay trees and red-black trees. + * + * A splay tree is a self-organizing data structure. Every operation + * on the tree causes a splay to happen. The splay moves the requested + * node to the root of the tree and partly rebalances it. + * + * This has the benefit that request locality causes faster lookups as + * the requested nodes move to the top of the tree. On the other hand, + * every lookup causes memory writes. + * + * The Balance Theorem bounds the total access time for m operations + * and n inserts on an initially empty tree as O((m + n)lg n). The + * amortized cost for a sequence of m accesses to a splay tree is O(lg n); + * + * A red-black tree is a binary search tree with the node color as an + * extra attribute. It fulfills a set of conditions: + * - every search path from the root to a leaf consists of the + * same number of black nodes, + * - each red node (except for the root) has a black parent, + * - each leaf node is black. + * + * Every operation on a red-black tree is bounded as O(lg n). + * The maximum height of a red-black tree is 2lg (n+1). + */ + +#define VSPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} + +#define VSPLAY_INITIALIZER(root) \ + { NULL } + +#define VSPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define VSPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} + +#define VSPLAY_LEFT(elm, field) (elm)->field.spe_left +#define VSPLAY_RIGHT(elm, field) (elm)->field.spe_right +#define VSPLAY_ROOT(head) (head)->sph_root +#define VSPLAY_EMPTY(head) (VSPLAY_ROOT(head) == NULL) + +/* VSPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold VSPLAY_{RIGHT,LEFT} */ +#define VSPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + VSPLAY_LEFT((head)->sph_root, field) = VSPLAY_RIGHT(tmp, field); \ + VSPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define VSPLAY_ROTATE_LEFT(head, tmp, field) do { \ + VSPLAY_RIGHT((head)->sph_root, field) = VSPLAY_LEFT(tmp, field); \ + VSPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (/*CONSTCOND*/ 0) + +#define VSPLAY_LINKLEFT(head, tmp, field) do { \ + VSPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = VSPLAY_LEFT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define VSPLAY_LINKRIGHT(head, tmp, field) do { \ + VSPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = VSPLAY_RIGHT((head)->sph_root, field); \ +} while (/*CONSTCOND*/ 0) + +#define VSPLAY_ASSEMBLE(head, node, left, right, field) do { \ + VSPLAY_RIGHT(left, field) = VSPLAY_LEFT((head)->sph_root, field); \ + VSPLAY_LEFT(right, field) = VSPLAY_RIGHT((head)->sph_root, field);\ + VSPLAY_LEFT((head)->sph_root, field) = VSPLAY_RIGHT(node, field); \ + VSPLAY_RIGHT((head)->sph_root, field) = VSPLAY_LEFT(node, field); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ + +#define VSPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_VSPLAY(struct name *, struct type *); \ +void name##_VSPLAY_MINMAX(struct name *, int); \ +struct type *name##_VSPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_VSPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_VSPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (VSPLAY_EMPTY(head)) \ + return(NULL); \ + name##_VSPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_VSPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_VSPLAY(head, elm); \ + if (VSPLAY_RIGHT(elm, field) != NULL) { \ + elm = VSPLAY_RIGHT(elm, field); \ + while (VSPLAY_LEFT(elm, field) != NULL) { \ + elm = VSPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_VSPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_VSPLAY_MINMAX(head, val); \ + return (VSPLAY_ROOT(head)); \ +} + +/* Main splay operation. + * Moves node close to the key of elm to top + */ +#define VSPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_VSPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (VSPLAY_EMPTY(head)) { \ + VSPLAY_LEFT(elm, field) = VSPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_VSPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + VSPLAY_LEFT(elm, field) = VSPLAY_LEFT((head)->sph_root, field);\ + VSPLAY_RIGHT(elm, field) = (head)->sph_root; \ + VSPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + VSPLAY_RIGHT(elm, field) = VSPLAY_RIGHT((head)->sph_root, field);\ + VSPLAY_LEFT(elm, field) = (head)->sph_root; \ + VSPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_VSPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (VSPLAY_EMPTY(head)) \ + return (NULL); \ + name##_VSPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (VSPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = VSPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = VSPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = VSPLAY_LEFT((head)->sph_root, field);\ + name##_VSPLAY(head, elm); \ + VSPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_VSPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + VSPLAY_LEFT(&__node, field) = VSPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root)) != 0) { \ + if (__comp < 0) { \ + __tmp = VSPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + VSPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (VSPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + VSPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = VSPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + VSPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (VSPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + VSPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + VSPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_VSPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + VSPLAY_LEFT(&__node, field) = VSPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = VSPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + VSPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (VSPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + VSPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = VSPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + VSPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (VSPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + VSPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + VSPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} + +#define VSPLAY_NEGINF -1 +#define VSPLAY_INF 1 + +#define VSPLAY_INSERT(name, x, y) name##_VSPLAY_INSERT(x, y) +#define VSPLAY_REMOVE(name, x, y) name##_VSPLAY_REMOVE(x, y) +#define VSPLAY_FIND(name, x, y) name##_VSPLAY_FIND(x, y) +#define VSPLAY_NEXT(name, x, y) name##_VSPLAY_NEXT(x, y) +#define VSPLAY_MIN(name, x) (VSPLAY_EMPTY(x) ? NULL \ + : name##_VSPLAY_MIN_MAX(x, VSPLAY_NEGINF)) +#define VSPLAY_MAX(name, x) (VSPLAY_EMPTY(x) ? NULL \ + : name##_VSPLAY_MIN_MAX(x, VSPLAY_INF)) + +#define VSPLAY_FOREACH(x, name, head) \ + for ((x) = VSPLAY_MIN(name, head); \ + (x) != NULL; \ + (x) = VSPLAY_NEXT(name, head, x)) + +/* Macros that define a red-black tree */ +#define VRB_HEAD(name, type) \ +struct name { \ + struct type *rbh_root; /* root of the tree */ \ +} + +#define VRB_INITIALIZER(root) \ + { NULL } + +#define VRB_INIT(root) do { \ + (root)->rbh_root = NULL; \ +} while (/*CONSTCOND*/ 0) + +#define VRB_BLACK 0 +#define VRB_RED 1 +#define VRB_ENTRY(type) \ +struct { \ + struct type *rbe_left; /* left element */ \ + struct type *rbe_right; /* right element */ \ + struct type *rbe_parent; /* parent element */ \ + int rbe_color; /* node color */ \ +} + +#define VRB_LEFT(elm, field) (elm)->field.rbe_left +#define VRB_RIGHT(elm, field) (elm)->field.rbe_right +#define VRB_PARENT(elm, field) (elm)->field.rbe_parent +#define VRB_COLOR(elm, field) (elm)->field.rbe_color +#define VRB_ROOT(head) (head)->rbh_root +#define VRB_EMPTY(head) (VRB_ROOT(head) == NULL) + +#define VRB_SET(elm, parent, field) do { \ + VRB_PARENT(elm, field) = parent; \ + VRB_LEFT(elm, field) = VRB_RIGHT(elm, field) = NULL; \ + VRB_COLOR(elm, field) = VRB_RED; \ +} while (/*CONSTCOND*/ 0) + +#define VRB_SET_BLACKRED(black, red, field) do { \ + VRB_COLOR(black, field) = VRB_BLACK; \ + VRB_COLOR(red, field) = VRB_RED; \ +} while (/*CONSTCOND*/ 0) + +#ifndef VRB_AUGMENT +#define VRB_AUGMENT(x) do {} while (0) +#endif + +#define VRB_ROTATE_LEFT(head, elm, tmp, field) do { \ + (tmp) = VRB_RIGHT(elm, field); \ + if ((VRB_RIGHT(elm, field) = VRB_LEFT(tmp, field)) != NULL) { \ + VRB_PARENT(VRB_LEFT(tmp, field), field) = (elm); \ + } \ + VRB_AUGMENT(elm); \ + if ((VRB_PARENT(tmp, field) = VRB_PARENT(elm, field)) != NULL) { \ + if ((elm) == VRB_LEFT(VRB_PARENT(elm, field), field)) \ + VRB_LEFT(VRB_PARENT(elm, field), field) = (tmp); \ + else \ + VRB_RIGHT(VRB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + VRB_LEFT(tmp, field) = (elm); \ + VRB_PARENT(elm, field) = (tmp); \ + VRB_AUGMENT(tmp); \ + if ((VRB_PARENT(tmp, field))) \ + VRB_AUGMENT(VRB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +#define VRB_ROTATE_RIGHT(head, elm, tmp, field) do { \ + (tmp) = VRB_LEFT(elm, field); \ + if ((VRB_LEFT(elm, field) = VRB_RIGHT(tmp, field)) != NULL) { \ + VRB_PARENT(VRB_RIGHT(tmp, field), field) = (elm); \ + } \ + VRB_AUGMENT(elm); \ + if ((VRB_PARENT(tmp, field) = VRB_PARENT(elm, field)) != NULL) { \ + if ((elm) == VRB_LEFT(VRB_PARENT(elm, field), field)) \ + VRB_LEFT(VRB_PARENT(elm, field), field) = (tmp); \ + else \ + VRB_RIGHT(VRB_PARENT(elm, field), field) = (tmp); \ + } else \ + (head)->rbh_root = (tmp); \ + VRB_RIGHT(tmp, field) = (elm); \ + VRB_PARENT(elm, field) = (tmp); \ + VRB_AUGMENT(tmp); \ + if ((VRB_PARENT(tmp, field))) \ + VRB_AUGMENT(VRB_PARENT(tmp, field)); \ +} while (/*CONSTCOND*/ 0) + +/* Generates prototypes and inline functions */ +#define VRB_PROTOTYPE(name, type, field, cmp) \ + VRB_PROTOTYPE_INTERNAL(name, type, field, cmp,) +#define VRB_PROTOTYPE_STATIC(name, type, field, cmp) \ + VRB_PROTOTYPE_INTERNAL(name, type, field, cmp, __unused static) +#define VRB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \ +attr void name##_VRB_INSERT_COLOR(struct name *, struct type *); \ +attr void name##_VRB_REMOVE_COLOR(struct name *, struct type *, struct type *);\ +attr struct type *name##_VRB_REMOVE(struct name *, struct type *); \ +attr struct type *name##_VRB_INSERT(struct name *, struct type *); \ +attr struct type *name##_VRB_FIND(struct name *, struct type *); \ +attr struct type *name##_VRB_NFIND(struct name *, struct type *); \ +attr struct type *name##_VRB_NEXT(struct type *); \ +attr struct type *name##_VRB_PREV(struct type *); \ +attr struct type *name##_VRB_MINMAX(struct name *, int); \ + \ + +/* Main rb operation. + * Moves node close to the key of elm to top + */ +#define VRB_GENERATE(name, type, field, cmp) \ + VRB_GENERATE_INTERNAL(name, type, field, cmp,) +#define VRB_GENERATE_STATIC(name, type, field, cmp) \ + VRB_GENERATE_INTERNAL(name, type, field, cmp, __unused static) +#define VRB_GENERATE_INTERNAL(name, type, field, cmp, attr) \ +attr void \ +name##_VRB_INSERT_COLOR(struct name *head, struct type *elm) \ +{ \ + struct type *parent, *gparent, *tmp; \ + while ((parent = VRB_PARENT(elm, field)) != NULL && \ + VRB_COLOR(parent, field) == VRB_RED) { \ + gparent = VRB_PARENT(parent, field); \ + if (parent == VRB_LEFT(gparent, field)) { \ + tmp = VRB_RIGHT(gparent, field); \ + if (tmp && VRB_COLOR(tmp, field) == VRB_RED) { \ + VRB_COLOR(tmp, field) = VRB_BLACK; \ + VRB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (VRB_RIGHT(parent, field) == elm) { \ + VRB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + VRB_SET_BLACKRED(parent, gparent, field); \ + VRB_ROTATE_RIGHT(head, gparent, tmp, field); \ + } else { \ + tmp = VRB_LEFT(gparent, field); \ + if (tmp && VRB_COLOR(tmp, field) == VRB_RED) { \ + VRB_COLOR(tmp, field) = VRB_BLACK; \ + VRB_SET_BLACKRED(parent, gparent, field);\ + elm = gparent; \ + continue; \ + } \ + if (VRB_LEFT(parent, field) == elm) { \ + VRB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = parent; \ + parent = elm; \ + elm = tmp; \ + } \ + VRB_SET_BLACKRED(parent, gparent, field); \ + VRB_ROTATE_LEFT(head, gparent, tmp, field); \ + } \ + } \ + VRB_COLOR(head->rbh_root, field) = VRB_BLACK; \ +} \ + \ +attr void \ +name##_VRB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \ +{ \ + struct type *tmp; \ + while ((elm == NULL || VRB_COLOR(elm, field) == VRB_BLACK) && \ + elm != VRB_ROOT(head)) { \ + if (VRB_LEFT(parent, field) == elm) { \ + tmp = VRB_RIGHT(parent, field); \ + if (VRB_COLOR(tmp, field) == VRB_RED) { \ + VRB_SET_BLACKRED(tmp, parent, field); \ + VRB_ROTATE_LEFT(head, parent, tmp, field);\ + tmp = VRB_RIGHT(parent, field); \ + } \ + if ((VRB_LEFT(tmp, field) == NULL || \ + VRB_COLOR(VRB_LEFT(tmp, field), field) == VRB_BLACK) &&\ + (VRB_RIGHT(tmp, field) == NULL || \ + VRB_COLOR(VRB_RIGHT(tmp, field), field) == VRB_BLACK)) {\ + VRB_COLOR(tmp, field) = VRB_RED; \ + elm = parent; \ + parent = VRB_PARENT(elm, field); \ + } else { \ + if (VRB_RIGHT(tmp, field) == NULL || \ + VRB_COLOR(VRB_RIGHT(tmp, field), field) == VRB_BLACK) {\ + struct type *oleft; \ + if ((oleft = VRB_LEFT(tmp, field)) \ + != NULL) \ + VRB_COLOR(oleft, field) = VRB_BLACK;\ + VRB_COLOR(tmp, field) = VRB_RED; \ + VRB_ROTATE_RIGHT(head, tmp, oleft, field);\ + tmp = VRB_RIGHT(parent, field); \ + } \ + VRB_COLOR(tmp, field) = VRB_COLOR(parent, field);\ + VRB_COLOR(parent, field) = VRB_BLACK; \ + if (VRB_RIGHT(tmp, field)) \ + VRB_COLOR(VRB_RIGHT(tmp, field), field) = VRB_BLACK;\ + VRB_ROTATE_LEFT(head, parent, tmp, field);\ + elm = VRB_ROOT(head); \ + break; \ + } \ + } else { \ + tmp = VRB_LEFT(parent, field); \ + if (VRB_COLOR(tmp, field) == VRB_RED) { \ + VRB_SET_BLACKRED(tmp, parent, field); \ + VRB_ROTATE_RIGHT(head, parent, tmp, field);\ + tmp = VRB_LEFT(parent, field); \ + } \ + if ((VRB_LEFT(tmp, field) == NULL || \ + VRB_COLOR(VRB_LEFT(tmp, field), field) == VRB_BLACK) &&\ + (VRB_RIGHT(tmp, field) == NULL || \ + VRB_COLOR(VRB_RIGHT(tmp, field), field) == VRB_BLACK)) {\ + VRB_COLOR(tmp, field) = VRB_RED; \ + elm = parent; \ + parent = VRB_PARENT(elm, field); \ + } else { \ + if (VRB_LEFT(tmp, field) == NULL || \ + VRB_COLOR(VRB_LEFT(tmp, field), field) == VRB_BLACK) {\ + struct type *oright; \ + if ((oright = VRB_RIGHT(tmp, field)) \ + != NULL) \ + VRB_COLOR(oright, field) = VRB_BLACK;\ + VRB_COLOR(tmp, field) = VRB_RED; \ + VRB_ROTATE_LEFT(head, tmp, oright, field);\ + tmp = VRB_LEFT(parent, field); \ + } \ + VRB_COLOR(tmp, field) = VRB_COLOR(parent, field);\ + VRB_COLOR(parent, field) = VRB_BLACK; \ + if (VRB_LEFT(tmp, field)) \ + VRB_COLOR(VRB_LEFT(tmp, field), field) = VRB_BLACK;\ + VRB_ROTATE_RIGHT(head, parent, tmp, field);\ + elm = VRB_ROOT(head); \ + break; \ + } \ + } \ + } \ + if (elm) \ + VRB_COLOR(elm, field) = VRB_BLACK; \ +} \ + \ +attr struct type * \ +name##_VRB_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *child, *parent, *old = elm; \ + int color; \ + if (VRB_LEFT(elm, field) == NULL) \ + child = VRB_RIGHT(elm, field); \ + else if (VRB_RIGHT(elm, field) == NULL) \ + child = VRB_LEFT(elm, field); \ + else { \ + struct type *left; \ + elm = VRB_RIGHT(elm, field); \ + while ((left = VRB_LEFT(elm, field)) != NULL) \ + elm = left; \ + child = VRB_RIGHT(elm, field); \ + parent = VRB_PARENT(elm, field); \ + color = VRB_COLOR(elm, field); \ + if (child) \ + VRB_PARENT(child, field) = parent; \ + if (parent) { \ + if (VRB_LEFT(parent, field) == elm) \ + VRB_LEFT(parent, field) = child; \ + else \ + VRB_RIGHT(parent, field) = child; \ + VRB_AUGMENT(parent); \ + } else \ + VRB_ROOT(head) = child; \ + if (VRB_PARENT(elm, field) == old) \ + parent = elm; \ + (elm)->field = (old)->field; \ + if (VRB_PARENT(old, field)) { \ + if (VRB_LEFT(VRB_PARENT(old, field), field) == old)\ + VRB_LEFT(VRB_PARENT(old, field), field) = elm;\ + else \ + VRB_RIGHT(VRB_PARENT(old, field), field) = elm;\ + VRB_AUGMENT(VRB_PARENT(old, field)); \ + } else \ + VRB_ROOT(head) = elm; \ + VRB_PARENT(VRB_LEFT(old, field), field) = elm; \ + if (VRB_RIGHT(old, field)) \ + VRB_PARENT(VRB_RIGHT(old, field), field) = elm; \ + if (parent) { \ + left = parent; \ + do { \ + VRB_AUGMENT(left); \ + } while ((left = VRB_PARENT(left, field)) != NULL); \ + } \ + goto color; \ + } \ + parent = VRB_PARENT(elm, field); \ + color = VRB_COLOR(elm, field); \ + if (child) \ + VRB_PARENT(child, field) = parent; \ + if (parent) { \ + if (VRB_LEFT(parent, field) == elm) \ + VRB_LEFT(parent, field) = child; \ + else \ + VRB_RIGHT(parent, field) = child; \ + VRB_AUGMENT(parent); \ + } else \ + VRB_ROOT(head) = child; \ +color: \ + if (color == VRB_BLACK) \ + name##_VRB_REMOVE_COLOR(head, parent, child); \ + return (old); \ +} \ + \ +/* Inserts a node into the RB tree */ \ +attr struct type * \ +name##_VRB_INSERT(struct name *head, struct type *elm) \ +{ \ + struct type *tmp; \ + struct type *parent = NULL; \ + int comp = 0; \ + tmp = VRB_ROOT(head); \ + while (tmp) { \ + parent = tmp; \ + comp = (cmp)(elm, parent); \ + if (comp < 0) \ + tmp = VRB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = VRB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + VRB_SET(elm, parent, field); \ + if (parent != NULL) { \ + if (comp < 0) \ + VRB_LEFT(parent, field) = elm; \ + else \ + VRB_RIGHT(parent, field) = elm; \ + VRB_AUGMENT(parent); \ + } else \ + VRB_ROOT(head) = elm; \ + name##_VRB_INSERT_COLOR(head, elm); \ + return (NULL); \ +} \ + \ +/* Finds the node with the same key as elm */ \ +attr struct type * \ +name##_VRB_FIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = VRB_ROOT(head); \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) \ + tmp = VRB_LEFT(tmp, field); \ + else if (comp > 0) \ + tmp = VRB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (NULL); \ +} \ + \ +/* Finds the first node greater than or equal to the search key */ \ +attr struct type * \ +name##_VRB_NFIND(struct name *head, struct type *elm) \ +{ \ + struct type *tmp = VRB_ROOT(head); \ + struct type *res = NULL; \ + int comp; \ + while (tmp) { \ + comp = cmp(elm, tmp); \ + if (comp < 0) { \ + res = tmp; \ + tmp = VRB_LEFT(tmp, field); \ + } \ + else if (comp > 0) \ + tmp = VRB_RIGHT(tmp, field); \ + else \ + return (tmp); \ + } \ + return (res); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_VRB_NEXT(struct type *elm) \ +{ \ + if (VRB_RIGHT(elm, field)) { \ + elm = VRB_RIGHT(elm, field); \ + while (VRB_LEFT(elm, field)) \ + elm = VRB_LEFT(elm, field); \ + } else { \ + if (VRB_PARENT(elm, field) && \ + (elm == VRB_LEFT(VRB_PARENT(elm, field), field))) \ + elm = VRB_PARENT(elm, field); \ + else { \ + while (VRB_PARENT(elm, field) && \ + (elm == VRB_RIGHT(VRB_PARENT(elm, field), field)))\ + elm = VRB_PARENT(elm, field); \ + elm = VRB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +/* ARGSUSED */ \ +attr struct type * \ +name##_VRB_PREV(struct type *elm) \ +{ \ + if (VRB_LEFT(elm, field)) { \ + elm = VRB_LEFT(elm, field); \ + while (VRB_RIGHT(elm, field)) \ + elm = VRB_RIGHT(elm, field); \ + } else { \ + if (VRB_PARENT(elm, field) && \ + (elm == VRB_RIGHT(VRB_PARENT(elm, field), field))) \ + elm = VRB_PARENT(elm, field); \ + else { \ + while (VRB_PARENT(elm, field) && \ + (elm == VRB_LEFT(VRB_PARENT(elm, field), field)))\ + elm = VRB_PARENT(elm, field); \ + elm = VRB_PARENT(elm, field); \ + } \ + } \ + return (elm); \ +} \ + \ +attr struct type * \ +name##_VRB_MINMAX(struct name *head, int val) \ +{ \ + struct type *tmp = VRB_ROOT(head); \ + struct type *parent = NULL; \ + while (tmp) { \ + parent = tmp; \ + if (val < 0) \ + tmp = VRB_LEFT(tmp, field); \ + else \ + tmp = VRB_RIGHT(tmp, field); \ + } \ + return (parent); \ +} + +#define VRB_NEGINF -1 +#define VRB_INF 1 + +#define VRB_INSERT(name, x, y) name##_VRB_INSERT(x, y) +#define VRB_REMOVE(name, x, y) name##_VRB_REMOVE(x, y) +#define VRB_FIND(name, x, y) name##_VRB_FIND(x, y) +#define VRB_NFIND(name, x, y) name##_VRB_NFIND(x, y) +#define VRB_NEXT(name, x, y) name##_VRB_NEXT(y) +#define VRB_PREV(name, x, y) name##_VRB_PREV(y) +#define VRB_MIN(name, x) name##_VRB_MINMAX(x, VRB_NEGINF) +#define VRB_MAX(name, x) name##_VRB_MINMAX(x, VRB_INF) + +#define VRB_FOREACH(x, name, head) \ + for ((x) = VRB_MIN(name, head); \ + (x) != NULL; \ + (x) = name##_VRB_NEXT(x)) + +#define VRB_FOREACH_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_VRB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define VRB_FOREACH_SAFE(x, name, head, y) \ + for ((x) = VRB_MIN(name, head); \ + ((x) != NULL) && ((y) = name##_VRB_NEXT(x), (x) != NULL); \ + (x) = (y)) + +#define VRB_FOREACH_REVERSE(x, name, head) \ + for ((x) = VRB_MAX(name, head); \ + (x) != NULL; \ + (x) = name##_VRB_PREV(x)) + +#define VRB_FOREACH_REVERSE_FROM(x, name, y) \ + for ((x) = (y); \ + ((x) != NULL) && ((y) = name##_VRB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#define VRB_FOREACH_REVERSE_SAFE(x, name, head, y) \ + for ((x) = VRB_MAX(name, head); \ + ((x) != NULL) && ((y) = name##_VRB_PREV(x), (x) != NULL); \ + (x) = (y)) + +#endif /* _VTREE_H_ */ From martin at varnish-cache.org Tue Nov 13 14:49:24 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Tue, 13 Nov 2012 15:49:24 +0100 Subject: [master] 7fe1673 Don't hide the last ban in the list on the CLI ban.list output Message-ID: commit 7fe1673e16410f085e379f776f81d86af41f1f2f Author: Martin Blix Grydeland Date: Wed Oct 31 15:55:13 2012 +0100 Don't hide the last ban in the list on the CLI ban.list output The ban.list output would hide the very last ban on the list unless the lurker debug flag was set. This hides useful debugging information (how many objects are stuck on the last ban), without giving any apparent benefit. Remove the hide code. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 2f142df..bf671bc 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -1132,8 +1132,6 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv) VCLI_Out(cli, "Present bans:\n"); VTAILQ_FOREACH(b, &ban_head, list) { - if (b == bl && !DO_DEBUG(DBG_LURKER)) - break; VCLI_Out(cli, "%10.6f %5u%s\t", ban_time(b->spec), bl == b ? b->refcount - 1 : b->refcount, b->flags & BAN_F_GONE ? "G" : " "); From lkarsten at varnish-cache.org Fri Nov 16 11:58:26 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 16 Nov 2012 12:58:26 +0100 Subject: [3.0] aec42d8 Clarify which timeout was reached Message-ID: commit aec42d8b559b67a3547f399b41cee180a202c458 Author: Lasse Karstensen Date: Fri Nov 16 12:46:16 2012 +0100 Clarify which timeout was reached When looking at varnishlog it looks like it is send_timeout that was reached, but in fact it is idle_send_timeout. Clarify the language so the user understands which parameter to adjust. diff --git a/bin/varnishd/cache_wrw.c b/bin/varnishd/cache_wrw.c index 90af92a..2a855b4 100644 --- a/bin/varnishd/cache_wrw.c +++ b/bin/varnishd/cache_wrw.c @@ -142,7 +142,7 @@ WRW_Flush(struct worker *w) } WSL(w, SLT_Debug, *wrw->wfd, - "Hit send timeout, wrote = %ld/%ld; retrying", + "Hit idle send timeout, wrote = %ld/%ld; retrying", i, wrw->liov); for (int j = 0; j < wrw->niov; j++) { From lkarsten at varnish-cache.org Fri Nov 16 12:00:56 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 16 Nov 2012 13:00:56 +0100 Subject: [master] fc7732d Clarify which timeout was reached Message-ID: commit fc7732d2c9d5c2e474d97441381d0787ba53b567 Author: Lasse Karstensen Date: Fri Nov 16 13:00:38 2012 +0100 Clarify which timeout was reached When looking at varnishlog it looks like it is send_timeout that was reached, but in fact it is idle_send_timeout. Clarify the language so the user understands which parameter to adjust. diff --git a/bin/varnishd/cache/cache_wrw.c b/bin/varnishd/cache/cache_wrw.c index 2324318..adf2f11 100644 --- a/bin/varnishd/cache/cache_wrw.c +++ b/bin/varnishd/cache/cache_wrw.c @@ -190,7 +190,7 @@ WRW_Flush(const struct worker *wrk) } VSLb(wrw->vsl, SLT_Debug, - "Hit send timeout, wrote = %zd/%zd; retrying", + "Hit idle send timeout, wrote = %zd/%zd; retrying", i, wrw->liov); wrw_prune(wrw, i); From tfheen at varnish-cache.org Mon Nov 19 10:05:11 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 11:05:11 +0100 Subject: [master] 89bf18a Minor cleanups in varnishtop Message-ID: commit 89bf18a82bccd94470c4d3c561ec0c9e7b02e92e Author: Tollef Fog Heen Date: Mon Nov 19 11:04:34 2012 +0100 Minor cleanups in varnishtop Some minor cleanups, no functional changes. Thanks to Federico Schwindt for pointing this out. diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c index 7cf1568..e217f28 100644 --- a/bin/varnishtop/varnishtop.c +++ b/bin/varnishtop/varnishtop.c @@ -66,7 +66,8 @@ struct top { double count; }; -static int top_cmp(const struct top *tp, const struct top *tp2); +static int +top_cmp(const struct top *tp, const struct top *tp2); static VRB_HEAD(top_tree, top) top_tree_head = VRB_INITIALIZER(&top_tree_head); VRB_PROTOTYPE(top_tree, top, entry, top_cmp); @@ -83,22 +84,18 @@ static unsigned maxfieldlen = 0; VRB_GENERATE(top_tree, top, entry, top_cmp); -static int top_cmp(const struct top *tp, const struct top *tp2) +static int +top_cmp(const struct top *tp, const struct top *tp2) { if (tp->count == tp2->count || tp->count == 0.0) { - if (tp->hash == tp2->hash) { - if (tp->tag == tp2->tag) { - if (tp->clen == tp2->clen) { - return (memcmp(tp->rec_data, tp2->rec_data, tp->clen)); - } else { - return (tp->clen - tp2->clen); - } - } else { - return (tp->tag - tp2->tag); - } - } else { + if (tp->hash != tp2->hash) return (tp->hash - tp2->hash); - } + if (tp->tag != tp2->tag) + return (tp->tag - tp2->tag); + if (tp->clen != tp2->clen) + return (tp->clen - tp2->clen); + else + return (memcmp(tp->rec_data, tp2->rec_data, tp->clen)); } else { if (tp->count > tp2->count) return -1; From tfheen at varnish-cache.org Mon Nov 19 10:06:34 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 11:06:34 +0100 Subject: [3.0] 5de7b57 Fix the CLI ref documentation (including a bug in the built in docs). Message-ID: commit 5de7b5727643ffbfa1bcaec2f56350ec1a36aa41 Author: Per Buer Date: Thu Aug 23 10:19:01 2012 +0200 Fix the CLI ref documentation (including a bug in the built in docs). diff --git a/bin/varnishd/cache_backend_cfg.c b/bin/varnishd/cache_backend_cfg.c index 47df12f..a5f1721 100644 --- a/bin/varnishd/cache_backend_cfg.c +++ b/bin/varnishd/cache_backend_cfg.c @@ -500,7 +500,7 @@ static struct cli_proto backend_cmds[] = { { "backend.list", "backend.list", "\tList all backends\n", 0, 1, "", cli_backend_list }, { "backend.set_health", "backend.set_health matcher state", - "\tShow a backend\n", 2, 2, "", cli_backend_set_health }, + "\tSet health status on a backend\n", 2, 2, "", cli_backend_set_health }, { NULL } }; diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index 668ceab..ff86cb3 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -79,74 +79,76 @@ be entered with the \\xnn syntax. Commands -------- -help [command] - Display a list of available commands. +.. glossary:: + :sorted: + help [command] + Display a list of available commands. If the command is specified, display help for this command. -param.set param value + param.set param value Set the parameter specified by param to the specified value. See Run-Time Parameters for a list of parame? ters. -param.show [-l] [param] + param.show [-l] [param] Display a list if run-time parameters and their values. - + If the -l option is specified, the list includes a brief explanation of each parameter. - + If a param is specified, display only the value and explanation for this parameter. -ping [timestamp] + ping [timestamp] Ping the Varnish cache process, keeping the connection alive. -ban *field operator argument* [&& field operator argument [...]] + ban *field operator argument* [&& field operator argument [...]] Immediately invalidate all documents matching the ban expression. See *Ban Expressions* for more documentation and examples. -ban.list + ban.list All requests for objects from the cache are matched against items on the ban list. If an object in the cache is older than a matching ban list item, it is considered "banned", and will be fetched from the backend instead. - + When a ban expression is older than all the objects in the cache, it is removed from the list. - + ban.list displays the ban list. The output looks something like this (broken into two lines): - + 0x7fea4fcb0580 1303835108.618863 131G req.http.host ~ www.myhost.com && req.url ~ /some/url - + The first field is the address of the ban. - + The second is the time of entry into the list, given as a high precision timestamp. - + The third field describes many objects point to this ban. When an object is compared to a ban the object is marked with a reference to the newest ban it was tested against. This isn't really useful unless you're debugging. - + A "G" marks that the ban is "Gone". Meaning it has been marked as a duplicate or it is no longer valid. It stays in the list for effiency reasons. - + Then follows the actual ban it self. -ban.url regexp + ban.url regexp Immediately invalidate all documents whose URL matches the specified regular expression. Please note that the Host part of the URL is ignored, so if you have several virtual hosts all of them will be banned. Use *ban* to specify a complete ban if you need to narrow it down. -quit + quit Close the connection to the varnish admin port. -start + start Start the Varnish cache process if it is not already running. stats @@ -157,37 +159,49 @@ stats utility. status + status Check the status of the Varnish cache process. -stop + stop Stop the Varnish cache process. -vcl.discard configname + vcl.discard configname Discard the configuration specified by configname. This will have no effect if the specified configuration has a non-zero reference count. -vcl.inline configname vcl + vcl.inline configname vcl Create a new configuration named configname with the VCL code specified by vcl, which must be a quoted string. -vcl.list + vcl.list List available configurations and their respective reference counts. The active configuration is indicated with an asterisk ("*"). -vcl.load configname filename + vcl.load configname filename Create a new configuration named configname with the contents of the specified file. -vcl.show configname + vcl.show configname Display the source code for the specified configuration. -vcl.use configname + vcl.use configname Start using the configuration specified by configname for all new requests. Existing requests will con? tinue using whichever configuration was in use when they arrived. + storage.list + Lists the defined storage backends. + + backend.list + Lists the defined backends including health state. + + backend.set_health matcher state + Sets the health state on a specific backend. This is useful if + you want to take a certain backend out of sirculations. + + Ban Expressions --------------- From tfheen at varnish-cache.org Mon Nov 19 12:29:44 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 13:29:44 +0100 Subject: [master] ae52a41 PATCH: fix some warnings during configure/compilation Message-ID: commit ae52a41451d36bb331903f1485a80af0d972fba6 Author: Federico G. Schwindt Date: Fri Nov 16 13:15:59 2012 +0000 PATCH: fix some warnings during configure/compilation Hi, The diff below fixes one warning during configure and two during compilation on OpenBSD (and maybe elsewhere): checking pthread_np.h usability... no checking pthread_np.h presence... yes configure: WARNING: pthread_np.h: present but cannot be compiled configure: WARNING: pthread_np.h: check for missing prerequisite headers? configure: WARNING: pthread_np.h: see the Autoconf documentation configure: WARNING: pthread_np.h: section "Present But Cannot Be Compiled" configure: WARNING: pthread_np.h: proceeding with the compiler's result configure: WARNING: ## -------------------------------------------- ## configure: WARNING: ## Report this to varnish-dev at varnish-cache.org ## configure: WARNING: ## -------------------------------------------- ## varnishadm.c:190: warning: implicit declaration of function 'add_history' cache/cache_main.c:82: warning: implicit declaration of function 'pthread_set_name_np' Comments? OK? f.- diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index 3dc7c79..3e47af2 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -41,6 +41,9 @@ # else # include # endif +# ifdef HAVE_READLINE_HISTORY_H +# include +# endif #endif #include diff --git a/configure.ac b/configure.ac index 87fdaf6..003f682 100644 --- a/configure.ac +++ b/configure.ac @@ -148,6 +148,7 @@ PKG_CHECK_MODULES([LIBEDIT], [libedit], [AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit])], [AC_CHECK_HEADERS([readline/readline.h]) AC_CHECK_HEADERS([edit/readline/readline.h]) + AC_CHECK_HEADERS([readline/history.h]) AC_CHECK_LIB(edit, el_init, [ AC_DEFINE([HAVE_LIBEDIT], [1], [Define we have libedit]) LIBEDIT_CFLAGS="" @@ -171,7 +172,7 @@ AC_CHECK_HEADERS([sys/vfs.h]) AC_CHECK_HEADERS([endian.h]) AC_CHECK_HEADERS([execinfo.h]) AC_CHECK_HEADERS([netinet/in.h]) -AC_CHECK_HEADERS([pthread_np.h]) +AC_CHECK_HEADERS([pthread_np.h], [], [], [#include ]) AC_CHECK_HEADERS([stddef.h]) AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([unistd.h]) From tfheen at varnish-cache.org Mon Nov 19 12:39:29 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 13:39:29 +0100 Subject: [master] 2038df5 Add vtree.h to _SOURCES Message-ID: commit 2038df57b0e8ae6ca1cece58e767af118f33da56 Author: Tollef Fog Heen Date: Mon Nov 19 13:39:27 2012 +0100 Add vtree.h to _SOURCES diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am index 630fbf7..88def2f 100644 --- a/bin/varnishtop/Makefile.am +++ b/bin/varnishtop/Makefile.am @@ -8,7 +8,8 @@ dist_man_MANS = varnishtop.1 varnishtop_SOURCES = varnishtop.c \ $(top_builddir)/lib/libvarnish/vas.c \ - $(top_builddir)/lib/libvarnish/version.c + $(top_builddir)/lib/libvarnish/version.c \ + vtree.h varnishtop_LDADD = \ $(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \ From tfheen at varnish-cache.org Mon Nov 19 13:05:42 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 14:05:42 +0100 Subject: [master] 70bce6b Only use readline/history.h if no edit/readline/redline.h Message-ID: commit 70bce6bfbd1d86d7a43e26a22812670e9bdc4a8f Author: Tollef Fog Heen Date: Mon Nov 19 14:04:55 2012 +0100 Only use readline/history.h if no edit/readline/redline.h it seems edit/readline/readline.h and readline/history.h are incompatible on FreeBSD, so only include one. Hopefully this works on OpenBSD still. diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index 3e47af2..e353d7f 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -38,12 +38,12 @@ # include # elif HAVE_READLINE_READLINE_H # include +# ifdef HAVE_READLINE_HISTORY_H +# include +# endif # else # include # endif -# ifdef HAVE_READLINE_HISTORY_H -# include -# endif #endif #include From phk at varnish-cache.org Mon Nov 19 13:13:14 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 19 Nov 2012 14:13:14 +0100 Subject: [master] b570062 Reenable CLANG Message-ID: commit b57006283551ab3f020055f811cbcf1328caad63 Author: Poul-Henning Kamp Date: Mon Nov 19 13:12:26 2012 +0000 Reenable CLANG diff --git a/autogen.des b/autogen.des index 3a706f3..aeb74d5 100755 --- a/autogen.des +++ b/autogen.des @@ -9,11 +9,12 @@ make -k distclean > /dev/null 2>&1 || true # Prefer CLANG if we have it, and have not given preferences if [ -f /usr/bin/clang -a "x${CC}" = "x" ] ; then CC=clang + CFLAGS="${CFLAGS} -Qunused-arguments" # XXX: clang complains about -g in linker invocations # XXX: so fall back to gcc for now... - CC=gcc - export CC + # CC=gcc + export CC CFLAGS fi rm -f configure From phk at varnish-cache.org Mon Nov 19 13:13:15 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 19 Nov 2012 14:13:15 +0100 Subject: [master] bf16286 White space fixes Message-ID: commit bf16286cc0a03ba9819d9a3f17bf7989f826be1b Author: Poul-Henning Kamp Date: Mon Nov 19 13:13:06 2012 +0000 White space fixes diff --git a/bin/varnishd/mgt/mgt_sandbox_solaris.c b/bin/varnishd/mgt/mgt_sandbox_solaris.c index eaeab8a..c3dc8a5 100644 --- a/bin/varnishd/mgt/mgt_sandbox_solaris.c +++ b/bin/varnishd/mgt/mgt_sandbox_solaris.c @@ -134,7 +134,7 @@ setppriv_check(int a) { * - net_config * * PSARC/2007/315? 3047ad28a67b onnv_77 - * - file_flag_set + * - file_flag_set * * PSARC/2007/560? 3047ad28a67b onnv_77 * - sys_smb @@ -159,8 +159,8 @@ setppriv_check(int a) { * - sys_iptun_config * * PSARC/2008/252 e209937a4f19 onnv_128 - * - net_mac_implicit - * + * - net_mac_implicit + * * PSARC/2009/685 8eca52188202 onnv_132 * * net_access * @@ -177,7 +177,7 @@ setppriv_check(int a) { * * * SOLARIS PRIVILEGES: Note on introtiction of new privileges (forward - * compatibility) + * compatibility) * * For optimal build and binary forward comatibility, we could use subtractive * set specs like diff --git a/bin/varnishtop/vtree.h b/bin/varnishtop/vtree.h index 3b57f20..7692d12 100644 --- a/bin/varnishtop/vtree.h +++ b/bin/varnishtop/vtree.h @@ -86,7 +86,7 @@ struct { \ VSPLAY_RIGHT(tmp, field) = (head)->sph_root; \ (head)->sph_root = tmp; \ } while (/*CONSTCOND*/ 0) - + #define VSPLAY_ROTATE_LEFT(head, tmp, field) do { \ VSPLAY_RIGHT((head)->sph_root, field) = VSPLAY_LEFT(tmp, field); \ VSPLAY_LEFT(tmp, field) = (head)->sph_root; \ From martin at varnish-cache.org Mon Nov 19 13:59:30 2012 From: martin at varnish-cache.org (Martin Blix Grydeland) Date: Mon, 19 Nov 2012 14:59:30 +0100 Subject: [master] 5a28588 Delay the accept task until all initialization has been completed. Message-ID: commit 5a28588f03b542240d1a80624f2737e2ed815639 Author: Martin Blix Grydeland Date: Mon Nov 19 11:06:36 2012 +0100 Delay the accept task until all initialization has been completed. This resolves the race where the pools might accept connections and start processing them before a lot of the initialization routines has finished. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 6d4fe86..1383ffb 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -940,6 +940,7 @@ void PipeRequest(struct req *req); /* cache_pool.c */ void Pool_Init(void); +void Pool_Accept(void); void Pool_Work_Thread(void *priv, struct worker *w); int Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how); diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index ac36308..468401b 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -228,6 +228,8 @@ child_main(void) if (FEATURE(FEATURE_WAIT_SILO)) SMP_Ready(); + Pool_Accept(); + CLI_Run(); STV_close(); diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 0e0d9dd..4e7bd7c 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -76,6 +76,7 @@ struct pool { static struct lock pool_mtx; static pthread_t thr_pool_herder; +static unsigned pool_accepting = 0; /*-------------------------------------------------------------------- */ @@ -128,6 +129,12 @@ pool_accept(struct worker *wrk, void *arg) CHECK_OBJ_NOTNULL(ps->lsock, LISTEN_SOCK_MAGIC); assert(sizeof *wa == WS_Reserve(wrk->aws, sizeof *wa)); wa = (void*)wrk->aws->f; + + /* Delay until we are ready (flag is set when all + * initialization has finished) */ + while (!pool_accepting) + VTIM_sleep(.1); + while (1) { memset(wa, 0, sizeof *wa); wa->magic = WRK_ACCEPT_MAGIC; @@ -484,6 +491,14 @@ pool_poolherder(void *priv) /*--------------------------------------------------------------------*/ void +Pool_Accept(void) +{ + + ASSERT_CLI(); + pool_accepting = 1; +} + +void Pool_Init(void) { From tfheen at varnish-cache.org Mon Nov 19 14:11:08 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Mon, 19 Nov 2012 15:11:08 +0100 Subject: [master] 20f8301 Include config.h earlier, needed for Solaris Message-ID: commit 20f83016d28442562ba4bcce05ecb8112d82e51f Author: Tollef Fog Heen Date: Mon Nov 19 14:55:46 2012 +0100 Include config.h earlier, needed for Solaris diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c index badb621..5f06750 100644 --- a/bin/varnishd/cache/cache_mempool.c +++ b/bin/varnishd/cache/cache_mempool.c @@ -28,11 +28,11 @@ * Generic memory pool */ +#include "config.h" #include #include #include -#include "config.h" #include "cache.h" From phk at varnish-cache.org Mon Nov 19 21:42:20 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Mon, 19 Nov 2012 22:42:20 +0100 Subject: [master] 10590c1 Go over the generation of VSL records with some spit & polish Message-ID: commit 10590c104c9cc2a03dc5e502f56bee162323d810 Author: Poul-Henning Kamp Date: Mon Nov 19 21:41:49 2012 +0000 Go over the generation of VSL records with some spit & polish diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index 228dde8..e7ae53e 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -50,6 +50,10 @@ static uint32_t *vsl_ptr; struct VSC_C_main *VSC_C_main; +/*-------------------------------------------------------------------- + * Check if the VSL_tag is masked by parameter bitmap + */ + static inline int vsl_tag_is_masked(enum VSL_tag_e tag) { @@ -62,28 +66,27 @@ vsl_tag_is_masked(enum VSL_tag_e tag) return (*bm & b); } -static inline uint32_t -vsl_w0(uint32_t type, uint32_t length) -{ - - assert(length < 0x10000); - return (((type & 0xff) << 24) | length); -} - -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Lay down a header fields, and return pointer to the next record + */ -static inline void +static inline uint32_t * vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, uint32_t vxid) { assert(((uintptr_t)p & 0x3) == 0); + assert(tag > SLT_Bogus); + assert(tag < SLT_Reserved); + AZ(len & ~VSL_LENMASK); p[1] = vxid; - VMB(); - p[0] = vsl_w0(tag, len); + p[0] = ((((unsigned)tag & 0xff) << 24) | len); + return (VSL_END(p, len)); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Wrap the VSL buffer + */ static void vsl_wrap(void) @@ -140,8 +143,7 @@ vsl_get(unsigned len, unsigned records, unsigned flushes) } /*-------------------------------------------------------------------- - * This variant copies a byte-range directly to the log, without - * taking the detour over sprintf() + * Stick a finished record into VSL. */ static void @@ -159,10 +161,22 @@ vslr(enum VSL_tag_e tag, uint32_t vxid, const char *b, unsigned len) p = vsl_get(len, 1, 0); memcpy(p + 2, b, len); - vsl_hdr(tag, p, len, vxid); + + /* + * vsl_hdr() writes p[1] again, but we want to make sure it + * has hit memory because we work on the live buffer here. + */ + p[1] = vxid; + VWMB(); + (void)vsl_hdr(tag, p, len, vxid); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Add a unbuffered record to VSL + * + * NB: This variant should be used sparingly and only for low volume + * NB: since it significantly adds to the mutex load on the VSL. + */ void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) @@ -171,20 +185,21 @@ VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) unsigned n, mlen = cache_param->shm_reclen; char buf[mlen]; + AN(fmt); if (vsl_tag_is_masked(tag)) return; - AN(fmt); - va_start(ap, fmt); + if (strchr(fmt, '%') == NULL) { vslr(tag, vxid, fmt, strlen(fmt)); } else { + va_start(ap, fmt); n = vsnprintf(buf, mlen, fmt, ap); + va_end(ap); if (n > mlen) n = mlen; vslr(tag, vxid, buf, n); } - va_end(ap); } /*--------------------------------------------------------------------*/ @@ -210,24 +225,24 @@ VSL_Flush(struct vsl_log *vsl, int overflow) vsl->wlr = 0; } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * VSL-buffered-txt + */ -static void -wslr(struct vsl_log *vsl, enum VSL_tag_e tag, int id, txt t) +void +VSLbt(struct vsl_log *vsl, enum VSL_tag_e tag, txt t) { unsigned l, mlen; Tcheck(t); - if (id == -1) - id = vsl->wid; + if (vsl_tag_is_masked(tag)) + return; mlen = cache_param->shm_reclen; /* Truncate */ l = Tlen(t); - if (l > mlen) { + if (l > mlen) l = mlen; - t.e = t.b + l; - } assert(vsl->wlp < vsl->wle); @@ -236,51 +251,10 @@ wslr(struct vsl_log *vsl, enum VSL_tag_e tag, int id, txt t) VSL_Flush(vsl, 1); assert(VSL_END(vsl->wlp, l) < vsl->wle); memcpy(VSL_DATA(vsl->wlp), t.b, l); - vsl_hdr(tag, vsl->wlp, l, id); - vsl->wlp = VSL_END(vsl->wlp, l); + vsl->wlp = vsl_hdr(tag, vsl->wlp, l, vsl->wid); assert(vsl->wlp < vsl->wle); vsl->wlr++; - if (DO_DEBUG(DBG_SYNCVSL)) - VSL_Flush(vsl, 0); -} -/*--------------------------------------------------------------------*/ - -static void -wsl(struct vsl_log *, enum VSL_tag_e tag, int id, const char *fmt, va_list ap) - __printflike(4, 0); - -static void -wsl(struct vsl_log *vsl, enum VSL_tag_e tag, int id, const char *fmt, - va_list ap) -{ - char *p; - unsigned n, mlen; - txt t; - - AN(fmt); - mlen = cache_param->shm_reclen; - - if (strchr(fmt, '%') == NULL) { - t.b = TRUST_ME(fmt); - t.e = strchr(t.b, '\0'); - wslr(vsl, tag, id, t); - } else { - assert(vsl->wlp < vsl->wle); - - /* Wrap if we cannot fit a full size record */ - if (VSL_END(vsl->wlp, mlen) >= vsl->wle) - VSL_Flush(vsl, 1); - - p = VSL_DATA(vsl->wlp); - n = vsnprintf(p, mlen, fmt, ap); - if (n > mlen) - n = mlen; /* we truncate long fields */ - vsl_hdr(tag, vsl->wlp, n, id); - vsl->wlp = VSL_END(vsl->wlp, n); - assert(vsl->wlp < vsl->wle); - vsl->wlr++; - } if (DO_DEBUG(DBG_SYNCVSL)) VSL_Flush(vsl, 0); } @@ -292,32 +266,55 @@ wsl(struct vsl_log *vsl, enum VSL_tag_e tag, int id, const char *fmt, void VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...) { + char *p; + const char *u, *f; + unsigned n, mlen; va_list ap; + txt t; AN(fmt); if (vsl_tag_is_masked(tag)) return; + + /* + * If there are no printf-expansions, don't waste time expanding them + */ + f = NULL; + for (u = fmt; *u != '\0'; u++) + if (*u == '%') + f = u; + if (f == NULL) { + t.b = TRUST_ME(fmt); + t.e = TRUST_ME(u); + VSLbt(vsl, tag, t); + return; + } + + mlen = cache_param->shm_reclen; + + /* Wrap if we cannot fit a full size record */ + if (VSL_END(vsl->wlp, mlen) >= vsl->wle) + VSL_Flush(vsl, 1); + + p = VSL_DATA(vsl->wlp); va_start(ap, fmt); - wsl(vsl, tag, vsl->wid, fmt, ap); + n = vsnprintf(p, mlen, fmt, ap); va_end(ap); + if (n > mlen) + n = mlen; /* we truncate long fields */ + vsl->wlp = vsl_hdr(tag, vsl->wlp, n, vsl->wid); + assert(vsl->wlp < vsl->wle); + vsl->wlr++; + + if (DO_DEBUG(DBG_SYNCVSL)) + VSL_Flush(vsl, 0); } /*-------------------------------------------------------------------- - * VSL-buffered-txt + * Allocate a VSL buffer */ void -VSLbt(struct vsl_log *vsl, enum VSL_tag_e tag, txt t) -{ - - if (vsl_tag_is_masked(tag)) - return; - wslr(vsl, tag, -1, t); -} - -/*--------------------------------------------------------------------*/ - -void VSL_Setup(struct vsl_log *vsl, void *ptr, size_t len) { diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h index 6f192e9..24f2037 100644 --- a/include/vapi/vsl_int.h +++ b/include/vapi/vsl_int.h @@ -46,18 +46,22 @@ * * Each logrecord consist of: * [n] = ((type & 0xff) << 24) | (length & 0xffff) - * [n + 1] = identifier + * [n + 1] = ((marker & 0x03) << 30) | (identifier & 0x3fffffff) * [n + 2] ... [m] = content + * + * Notice that the constants in these macros cannot be changed without + * changing corresponding magic numbers in varnishd/cache/cache_shmlog.c */ #define VSL_CLIENTMARKER (1U<<30) #define VSL_BACKENDMARKER (1U<<31) #define VSL_IDENTMASK (~(3U<<30)) +#define VSL_LENMASK 0xffff #define VSL_WORDS(len) (((len) + 3) / 4) #define VSL_END(ptr, len) ((ptr) + 2 + VSL_WORDS(len)) #define VSL_NEXT(ptr) VSL_END(ptr, VSL_LEN(ptr)) -#define VSL_LEN(ptr) ((ptr)[0] & 0xffff) +#define VSL_LEN(ptr) ((ptr)[0] & VSL_LENMASK) #define VSL_TAG(ptr) ((ptr)[0] >> 24) #define VSL_ID(ptr) (((ptr)[1]) & VSL_IDENTMASK) #define VSL_CLIENT(ptr) (((ptr)[1]) & VSL_CLIENTMARKER) From phk at varnish-cache.org Tue Nov 20 07:56:50 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 08:56:50 +0100 Subject: [master] 09e8a28 Add an extra '_' to identify SLT__Bogus and SLT__Reserved as magic Message-ID: commit 09e8a28b5d983dc0f15cf44dfa68d4ce4ce04ea1 Author: Poul-Henning Kamp Date: Tue Nov 20 07:56:31 2012 +0000 Add an extra '_' to identify SLT__Bogus and SLT__Reserved as magic diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index e7ae53e..a741035 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -60,7 +60,8 @@ vsl_tag_is_masked(enum VSL_tag_e tag) volatile uint8_t *bm = &cache_param->vsl_mask[0]; uint8_t b; - assert(tag < SLT_Reserved); + assert(tag > SLT__Bogus); + assert(tag < SLT__Reserved); bm += ((unsigned)tag >> 3); b = (0x80 >> ((unsigned)tag & 7)); return (*bm & b); @@ -75,8 +76,8 @@ vsl_hdr(enum VSL_tag_e tag, uint32_t *p, unsigned len, uint32_t vxid) { assert(((uintptr_t)p & 0x3) == 0); - assert(tag > SLT_Bogus); - assert(tag < SLT_Reserved); + assert(tag > SLT__Bogus); + assert(tag < SLT__Reserved); AZ(len & ~VSL_LENMASK); p[1] = vxid; diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c index a5996a2..faeff24 100644 --- a/bin/varnishd/mgt/mgt_param_bits.c +++ b/bin/varnishd/mgt/mgt_param_bits.c @@ -137,12 +137,12 @@ tweak_vsl_mask(struct cli *cli, const struct parspec *par, const char *arg) (void)bit(mgt_param.vsl_mask, SLT_Hash, BSET); } else { bit_tweak(cli, mgt_param.vsl_mask, - SLT_Reserved, arg, VSL_tags, + SLT__Reserved, arg, VSL_tags, "VSL tag", "-"); } } else { s = ""; - for (j = 0; j < (unsigned)SLT_Reserved; j++) { + for (j = 0; j < (unsigned)SLT__Reserved; j++) { if (bit(mgt_param.vsl_mask, j, BTST)) { VCLI_Out(cli, "%s-%s", s, VSL_tags[j]); s = ","; diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h index 24f2037..012a975 100644 --- a/include/vapi/vsl_int.h +++ b/include/vapi/vsl_int.h @@ -68,19 +68,19 @@ #define VSL_BACKEND(ptr) (((ptr)[1]) & VSL_BACKENDMARKER) #define VSL_DATA(ptr) ((char*)((ptr)+2)) -#define VSL_ENDMARKER (((uint32_t)SLT_Reserved << 24) | 0x454545) /* "EEE" */ -#define VSL_WRAPMARKER (((uint32_t)SLT_Reserved << 24) | 0x575757) /* "WWW" */ +#define VSL_ENDMARKER (((uint32_t)SLT__Reserved << 24) | 0x454545) /* "EEE" */ +#define VSL_WRAPMARKER (((uint32_t)SLT__Reserved << 24) | 0x575757) /* "WWW" */ /* * The identifiers in shmlogtag are "SLT_" + XML tag. A script may be run * on this file to extract the table rather than handcode it */ enum VSL_tag_e { - SLT_Bogus = 0, + SLT__Bogus = 0, #define SLTM(foo,sdesc,ldesc) SLT_##foo, #include "tbl/vsl_tags.h" #undef SLTM - SLT_Reserved = 255 + SLT__Reserved = 255 }; #endif /* VAPI_VSL_FMT_H_INCLUDED */ From phk at varnish-cache.org Tue Nov 20 08:12:58 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 09:12:58 +0100 Subject: [master] d86979e Emit SLT__Batch records which tells us that the next N bytes all belong to the same batch of VSL records and therefore have the same vxid. Message-ID: commit d86979e07896e6f3a05e36847eb8439a1e79c552 Author: Poul-Henning Kamp Date: Tue Nov 20 08:10:44 2012 +0000 Emit SLT__Batch records which tells us that the next N bytes all belong to the same batch of VSL records and therefore have the same vxid. This will allow us to optimize libvarnishapi, in particular when doing ordered/transaction mode. diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index a741035..23add4f 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -217,11 +217,12 @@ VSL_Flush(struct vsl_log *vsl, int overflow) assert(l >= 8); - p = vsl_get(l - 8, vsl->wlr, overflow); + p = vsl_get(l, vsl->wlr, overflow); - memcpy(p + 1, vsl->wlb + 1, l - 4); + memcpy(p + 2, vsl->wlb, l); + p[1] = l; VWMB(); - p[0] = vsl->wlb[0]; + p[0] = ((((unsigned)SLT__Batch & 0xff) << 24) | 0); vsl->wlp = vsl->wlb; vsl->wlr = 0; } diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h index 012a975..d50f9fc 100644 --- a/include/vapi/vsl_int.h +++ b/include/vapi/vsl_int.h @@ -80,7 +80,8 @@ enum VSL_tag_e { #define SLTM(foo,sdesc,ldesc) SLT_##foo, #include "tbl/vsl_tags.h" #undef SLTM - SLT__Reserved = 255 + SLT__Reserved = 254, + SLT__Batch = 255 }; #endif /* VAPI_VSL_FMT_H_INCLUDED */ diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c index 1c36b3f..cb9e6eb 100644 --- a/lib/libvarnishapi/vsl.c +++ b/lib/libvarnishapi/vsl.c @@ -270,7 +270,9 @@ VSL_NextSLT(struct VSM_data *vd, uint32_t **pp, uint64_t *bits) } t = VSL_TAG(p); - if (vbit_test(vsl->vbm_select, t)) { + if (t == SLT__Batch) { + continue; + } else if (vbit_test(vsl->vbm_select, t)) { /* nothing */ } else if (vbit_test(vsl->vbm_supress, t)) { continue; From phk at varnish-cache.org Tue Nov 20 09:19:07 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 10:19:07 +0100 Subject: [master] 9880dcb Remove a stray newline Message-ID: commit 9880dcbac168846749a968496611a0ce594f6565 Author: Poul-Henning Kamp Date: Tue Nov 20 09:18:59 2012 +0000 Remove a stray newline diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index a760436..62209a5 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -328,7 +328,7 @@ vca_acct(void *arg) i = VTCP_filter_http(ls->sock); if (i) VSL(SLT_Error, ls->sock, - "Kernel filtering: sock=%d, ret=%d %s\n", + "Kernel filtering: sock=%d, ret=%d %s", ls->sock, i, strerror(errno)); } } From phk at varnish-cache.org Tue Nov 20 10:09:28 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 11:09:28 +0100 Subject: [master] 720986b Add new SLT_Link records to link request VXIDs to session VXIDs and backend VXIDs to request VXIDs. Message-ID: commit 720986b3e445c5d72bc92e1adebdd6c8a3b72ce3 Author: Poul-Henning Kamp Date: Tue Nov 20 10:08:40 2012 +0000 Add new SLT_Link records to link request VXIDs to session VXIDs and backend VXIDs to request VXIDs. Still TBD: where ESI fits into this. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 1383ffb..727073b 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -760,7 +760,7 @@ double BAN_Time(const struct ban *ban); /* cache_busyobj.c */ void VBO_Init(void); -struct busyobj *VBO_GetBusyObj(struct worker *wrk); +struct busyobj *VBO_GetBusyObj(struct worker *, const struct req *); void VBO_DerefBusyObj(struct worker *wrk, struct busyobj **busyobj); void VBO_Free(struct busyobj **vbo); diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 014e564..17ec871 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -87,7 +87,7 @@ VBO_Free(struct busyobj **bop) } struct busyobj * -VBO_GetBusyObj(struct worker *wrk) +VBO_GetBusyObj(struct worker *wrk, const struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; @@ -129,6 +129,7 @@ VBO_GetBusyObj(struct worker *wrk) sz = cache_param->vsl_buffer; VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_BACKENDMARKER; + VSLb(bo->vsl, SLT_Link, "req %u", req->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index edd986c..0a209a8 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -267,7 +267,7 @@ cnt_error(struct worker *wrk, struct req *req) AZ(req->obj); AZ(req->busyobj); - bo = VBO_GetBusyObj(wrk); + bo = VBO_GetBusyObj(wrk, req); req->busyobj = bo; AZ(bo->stats); bo->stats = &wrk->stats; @@ -807,7 +807,7 @@ cnt_lookup(struct worker *wrk, struct req *req) /* If we inserted a new object it's a miss */ if (oc->flags & OC_F_BUSY) { AZ(req->busyobj); - bo = VBO_GetBusyObj(wrk); + bo = VBO_GetBusyObj(wrk, req); req->busyobj = bo; /* One ref for req, one for FetchBody */ bo->refcount = 2; @@ -943,7 +943,7 @@ cnt_pass(struct worker *wrk, struct req *req) AZ(req->obj); AZ(req->busyobj); - req->busyobj = VBO_GetBusyObj(wrk); + req->busyobj = VBO_GetBusyObj(wrk, req); bo = req->busyobj; bo->refcount = 2; HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq); @@ -1002,7 +1002,7 @@ cnt_pipe(struct worker *wrk, struct req *req) AZ(req->busyobj); req->acct_req.pipe++; - req->busyobj = VBO_GetBusyObj(wrk); + req->busyobj = VBO_GetBusyObj(wrk, req); bo = req->busyobj; HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq); http_FilterReq(req, 0); @@ -1090,7 +1090,6 @@ cnt_recv(const struct worker *wrk, struct req *req) AZ(req->obj); AZ(req->busyobj); - /* Assign XID and log */ VSLb(req->vsl, SLT_ReqStart, "%s %s", req->sp->addr, req->sp->port); if (req->err_code) { diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 5caf03f..5fae4dd 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -386,6 +386,7 @@ SES_GetReq(struct worker *wrk, struct sess *sp) sz = cache_param->workspace_thread; VSL_Setup(req->vsl, p, sz); req->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_CLIENTMARKER; + VSLb(req->vsl, SLT_Link, "sess %u", sp->vxid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 9d970e1..dd12f91 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -156,3 +156,11 @@ SLTM(VCL_Log, "Log statement from VCL", "") SLTM(VCL_Error, "", "") SLTM(Gzip, "G(un)zip performed on object", "") + +SLTM(Link, "Linkage between different VXIDs", + "Links this records VXID to its parent VXID\n" + "The first field gives the type of the parent:\n" + " req Request\n" + " sess Session\n" + "The second field gives the VXID if the parent.\n" +) From phk at varnish-cache.org Tue Nov 20 10:54:13 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 11:54:13 +0100 Subject: [master] 8ae7647 Link ESI subrequests to both their session and their parent request. Message-ID: commit 8ae7647db77d351fa0162f596a4d1817edf71687 Author: Poul-Henning Kamp Date: Tue Nov 20 10:53:54 2012 +0000 Link ESI subrequests to both their session and their parent request. diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 404409f..66862f4 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -60,6 +60,7 @@ ved_include(struct req *preq, const char *src, const char *host) wrk_ws_wm = WS_Snapshot(wrk->aws); /* XXX ? */ req = SES_GetReq(wrk, preq->sp); + VSLb(req->vsl, SLT_Link, "req %u", preq->vsl->wid & VSL_IDENTMASK); req->esi_level = preq->esi_level + 1; HTTP_Copy(req->http0, preq->http0); From phk at varnish-cache.org Tue Nov 20 11:41:12 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Tue, 20 Nov 2012 12:41:12 +0100 Subject: [master] 725c8c2 Add forward SLT_Link records from req->esireq and req->bereq Message-ID: commit 725c8c2bdd02470c8903910ed5a865eb5d6d052a Author: Poul-Henning Kamp Date: Tue Nov 20 11:40:44 2012 +0000 Add forward SLT_Link records from req->esireq and req->bereq Prodded by: Martin diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 727073b..bc07923 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -760,7 +760,7 @@ double BAN_Time(const struct ban *ban); /* cache_busyobj.c */ void VBO_Init(void); -struct busyobj *VBO_GetBusyObj(struct worker *, const struct req *); +struct busyobj *VBO_GetBusyObj(struct worker *, struct req *); void VBO_DerefBusyObj(struct worker *wrk, struct busyobj **busyobj); void VBO_Free(struct busyobj **vbo); diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 17ec871..0691b83 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -87,7 +87,7 @@ VBO_Free(struct busyobj **bop) } struct busyobj * -VBO_GetBusyObj(struct worker *wrk, const struct req *req) +VBO_GetBusyObj(struct worker *wrk, struct req *req) { struct busyobj *bo = NULL; uint16_t nhttp; @@ -130,6 +130,7 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req) VSL_Setup(bo->vsl, p, sz); bo->vsl->wid = VXID_Get(&wrk->vxid_pool) | VSL_BACKENDMARKER; VSLb(bo->vsl, SLT_Link, "req %u", req->vsl->wid & VSL_IDENTMASK); + VSLb(req->vsl, SLT_Link, "bereq %u", bo->vsl->wid & VSL_IDENTMASK); p += sz; p = (void*)PRNDUP(p); assert(p < bo->end); diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 66862f4..be87d2b 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -61,6 +61,7 @@ ved_include(struct req *preq, const char *src, const char *host) req = SES_GetReq(wrk, preq->sp); VSLb(req->vsl, SLT_Link, "req %u", preq->vsl->wid & VSL_IDENTMASK); + VSLb(preq->vsl, SLT_Link, "esireq %u", req->vsl->wid & VSL_IDENTMASK); req->esi_level = preq->esi_level + 1; HTTP_Copy(req->http0, preq->http0); diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index dd12f91..bdf840d 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -162,5 +162,7 @@ SLTM(Link, "Linkage between different VXIDs", "The first field gives the type of the parent:\n" " req Request\n" " sess Session\n" + " bereq Backend request\n" + " esireq ESI subrequest\n" "The second field gives the VXID if the parent.\n" ) From phk at varnish-cache.org Wed Nov 21 09:38:34 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 21 Nov 2012 10:38:34 +0100 Subject: [master] 814c60b Better function description Message-ID: commit 814c60b9ee356e9679437b6d581dfe9b4593c523 Author: Poul-Henning Kamp Date: Wed Nov 21 09:38:22 2012 +0000 Better function description diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index 23add4f..060773b 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -313,7 +313,7 @@ VSLb(struct vsl_log *vsl, enum VSL_tag_e tag, const char *fmt, ...) } /*-------------------------------------------------------------------- - * Allocate a VSL buffer + * Setup a VSL buffer, allocate space if none provided. */ void From phk at varnish-cache.org Wed Nov 21 10:22:15 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Wed, 21 Nov 2012 11:22:15 +0100 Subject: [master] 40863ac Allow a backend to resolve to multiple identical IP addresses. Message-ID: commit 40863ac3d0a79e5969563361cf69a33abf3ff086 Author: Poul-Henning Kamp Date: Wed Nov 21 10:21:40 2012 +0000 Allow a backend to resolve to multiple identical IP addresses. (This can happen with /etc/hosts) Inspired by patch from: Tollef diff --git a/bin/varnishtest/tests/v00002.vtc b/bin/varnishtest/tests/v00002.vtc index 93f2f31..c17dc0b 100644 --- a/bin/varnishtest/tests/v00002.vtc +++ b/bin/varnishtest/tests/v00002.vtc @@ -110,7 +110,7 @@ varnish v1 -errvcl {Unknown director policy: 'anarchy' at} { director r1 anarchy { .host = "127.0.0.1"; } } -varnish v1 -errvcl {Backend host "v00002.freebsd.dk": resolves to multiple IPv4 addresses.} { +varnish v1 -errvcl {Backend host "v00002.freebsd.dk": resolves to multiple ipv4 addresses.} { /* too many IP numbers */ backend b1 { .host = "v00002.freebsd.dk"; } } diff --git a/lib/libvcl/vcc_backend.c b/lib/libvcl/vcc_backend.c index 78cb0b2..a480edd 100644 --- a/lib/libvcl/vcc_backend.c +++ b/lib/libvcl/vcc_backend.c @@ -77,7 +77,7 @@ emit_sockaddr(struct vcc *tl, void *sa, unsigned sal) AN(sa); AN(sal); assert(sal < 256); - Fh(tl, 0, "\nstatic const unsigned char sockaddr%u[%d] = {\n", + Fh(tl, 0, "\nstatic const unsigned char sockaddr_%u[%d] = {\n", tl->unique, sal + 1); Fh(tl, 0, " %3u, /* Length */\n", sal); u = sa; @@ -100,16 +100,28 @@ emit_sockaddr(struct vcc *tl, void *sa, unsigned sal) * and put it in an official sockaddr when we load the VCL. */ +struct foo_proto { + const char *name; + int family; + struct sockaddr_storage sa; + socklen_t l; +}; + void Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) { + struct foo_proto protos[3], *pp; struct addrinfo *res, *res0, *res1, hint; - int n4, n6, error, retval, x; - const char *emit, *multiple; + int error, retval, x; char hbuf[NI_MAXHOST]; char *hop, *pop; AN(t_host->dec); + + memset(protos, 0, sizeof protos); + protos[0].name = "ipv4"; protos[0].family = PF_INET; + protos[1].name = "ipv6"; protos[1].family = PF_INET6; + retval = 0; memset(&hint, 0, sizeof hint); hint.ai_family = PF_UNSPEC; @@ -139,33 +151,32 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) vcc_ErrWhere(tl, t_host); return; } - AZ(error); - n4 = n6 = 0; - multiple = NULL; for (res = res0; res; res = res->ai_next) { - emit = NULL; - if (res->ai_family == PF_INET) { - if (n4++ == 0) - emit = "ipv4"; - else - multiple = "IPv4"; - } else if (res->ai_family == PF_INET6) { - if (n6++ == 0) - emit = "ipv6"; - else - multiple = "IPv6"; - } else + for (pp = protos; pp->name != NULL; pp++) + if (res->ai_family == pp->family) + break; + if (pp->name == NULL) { + /* Unknown proto, ignore */ continue; + } + if (pp->l == res->ai_addrlen && + !memcmp(&pp->sa, res->ai_addr, pp->l)) { + /* + * Same address we already emitted. + * This can happen using /etc/hosts + */ + continue; + } - if (multiple != NULL) { + if (pp->l > 0) { VSB_printf(tl->sb, "Backend host %.*s: resolves to " "multiple %s addresses.\n" "Only one address is allowed.\n" "Please specify which exact address " "you want to use, we found these:\n", - PF(t_host), multiple); + PF(t_host), pp->name); for (res1 = res0; res1 != NULL; res1 = res1->ai_next) { error = getnameinfo(res1->ai_addr, res1->ai_addrlen, hbuf, sizeof hbuf, @@ -173,17 +184,21 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) AZ(error); VSB_printf(tl->sb, "\t%s\n", hbuf); } + freeaddrinfo(res0); vcc_ErrWhere(tl, t_host); return; } - AN(emit); + + pp->l = res->ai_addrlen; + memcpy(&pp->sa, res->ai_addr, pp->l); + x = emit_sockaddr(tl, res->ai_addr, res->ai_addrlen); - Fb(tl, 0, "\t.%s_sockaddr = sockaddr%u,\n", emit, x); + Fb(tl, 0, "\t.%s_sockaddr = sockaddr_%u,\n", pp->name, x); error = getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST); AZ(error); - Fb(tl, 0, "\t.%s_addr = \"%s\",\n", emit, hbuf); + Fb(tl, 0, "\t.%s_addr = \"%s\",\n", pp->name, hbuf); retval++; } if (res0 != NULL) { From phk at varnish-cache.org Thu Nov 22 09:03:12 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 22 Nov 2012 10:03:12 +0100 Subject: [master] 810b3a6 Stylistic alignment of #defines. Message-ID: commit 810b3a6363ea4a00ed0ad447e4959e0f659ad1b4 Author: Poul-Henning Kamp Date: Thu Nov 22 09:01:27 2012 +0000 Stylistic alignment of #defines. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index bf671bc..de23150 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -110,21 +110,21 @@ static bgthread_t ban_lurker; * BAN string defines & magic markers */ -#define BANS_TIMESTAMP 0 -#define BANS_LENGTH 8 -#define BANS_FLAGS 12 -#define BANS_HEAD_LEN 13 -#define BANS_FLAG_REQ 0x01 -#define BANS_FLAG_GONE 0x02 - -#define BANS_OPER_EQ 0x10 -#define BANS_OPER_NEQ 0x11 -#define BANS_OPER_MATCH 0x12 +#define BANS_TIMESTAMP 0 +#define BANS_LENGTH 8 +#define BANS_FLAGS 12 +#define BANS_HEAD_LEN 13 +#define BANS_FLAG_REQ 0x01 +#define BANS_FLAG_GONE 0x02 + +#define BANS_OPER_EQ 0x10 +#define BANS_OPER_NEQ 0x11 +#define BANS_OPER_MATCH 0x12 #define BANS_OPER_NMATCH 0x13 #define BANS_ARG_URL 0x18 -#define BANS_ARG_REQHTTP 0x19 -#define BANS_ARG_OBJHTTP 0x1a +#define BANS_ARG_REQHTTP 0x19 +#define BANS_ARG_OBJHTTP 0x1a #define BANS_ARG_OBJSTATUS 0x1b /*-------------------------------------------------------------------- From phk at varnish-cache.org Thu Nov 22 12:09:33 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 22 Nov 2012 13:09:33 +0100 Subject: [master] 53bdce4 Don't waste time allocating a VSB when we reload bans, and in particular don't forget about it so it hangs around with the ban, doing nothing. Message-ID: commit 53bdce4e1b9d6d411466e55d9ac2bbf6a9b602b2 Author: Poul-Henning Kamp Date: Thu Nov 22 12:08:55 2012 +0000 Don't waste time allocating a VSB when we reload bans, and in particular don't forget about it so it hangs around with the ban, doing nothing. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index de23150..8ef4962 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -146,20 +146,31 @@ static const struct pvar { * Storage handling of bans */ +static struct ban * +ban_alloc(void) +{ + struct ban *b; + + ALLOC_OBJ(b, BAN_MAGIC); + if (b != NULL) + VTAILQ_INIT(&b->objcore); + return (b); +} + struct ban * BAN_New(void) { struct ban *b; - ALLOC_OBJ(b, BAN_MAGIC); - if (b == NULL) - return (b); - b->vsb = VSB_new_auto(); - if (b->vsb == NULL) { - FREE_OBJ(b); - return (NULL); + b = ban_alloc(); + if (b != NULL) { + b->vsb = VSB_new_auto(); + if (b->vsb == NULL) { + FREE_OBJ(b); + return (NULL); + } + VTAILQ_INIT(&b->objcore); } - VTAILQ_INIT(&b->objcore); return (b); } @@ -577,7 +588,7 @@ BAN_Reload(const uint8_t *ban, unsigned len) VSC_C_main->bans++; VSC_C_main->bans_added++; - b2 = BAN_New(); + b2 = ban_alloc(); AN(b2); b2->spec = malloc(len); AN(b2->spec); From phk at varnish-cache.org Thu Nov 22 12:22:20 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 22 Nov 2012 13:22:20 +0100 Subject: [master] 3a02001 Make the pass variable a local static of the function which needs it. Message-ID: commit 3a02001bc35914ee4b20b3aed3d4e7a0e9d6800b Author: Poul-Henning Kamp Date: Thu Nov 22 12:22:05 2012 +0000 Make the pass variable a local static of the function which needs it. diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 8ef4962..105a06f 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -844,12 +844,13 @@ ban_CheckLast(void) */ static int -ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass) +ban_lurker_work(struct worker *wrk, struct vsl_log *vsl) { struct ban *b, *b0, *b2; struct objhead *oh; struct objcore *oc, *oc2; struct object *o; + static unsigned pass = 1 << LURK_SHIFT; int i; AN(pass & BAN_F_LURK); @@ -984,6 +985,10 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl, unsigned pass) if (b == b0) break; } + pass += (1 << LURK_SHIFT); + pass &= BAN_F_LURK; + if (pass == 0) + pass += (1 << LURK_SHIFT); return (1); } @@ -991,7 +996,6 @@ static void * __match_proto__(bgthread_t) ban_lurker(struct worker *wrk, void *priv) { struct ban *bf; - unsigned pass = (1 << LURK_SHIFT); struct vsl_log vsl; int i = 0; @@ -1018,14 +1022,10 @@ ban_lurker(struct worker *wrk, void *priv) VTIM_sleep(1.0); } - i = ban_lurker_work(wrk, &vsl, pass); + i = ban_lurker_work(wrk, &vsl); VSL_Flush(&vsl, 0); WRK_SumStat(wrk); if (i) { - pass += (1 << LURK_SHIFT); - pass &= BAN_F_LURK; - if (pass == 0) - pass += (1 << LURK_SHIFT); VTIM_sleep(cache_param->ban_lurker_sleep); } else { VTIM_sleep(1.0); From phk at varnish-cache.org Thu Nov 22 12:57:30 2012 From: phk at varnish-cache.org (Poul-Henning Kamp) Date: Thu, 22 Nov 2012 13:57:30 +0100 Subject: [master] a6b9848 Eliminated duplicated code for trimming the tail of the banlist. Message-ID: commit a6b98489174224c65357728036ca9f963d47ac86 Author: Poul-Henning Kamp Date: Thu Nov 22 12:56:54 2012 +0000 Eliminated duplicated code for trimming the tail of the banlist. Original patch by: martin diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 105a06f..688842b 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -846,7 +846,7 @@ ban_CheckLast(void) static int ban_lurker_work(struct worker *wrk, struct vsl_log *vsl) { - struct ban *b, *b0, *b2; + struct ban *b, *b0; struct objhead *oh; struct objcore *oc, *oc2; struct object *o; @@ -856,18 +856,6 @@ ban_lurker_work(struct worker *wrk, struct vsl_log *vsl) AN(pass & BAN_F_LURK); AZ(pass & ~BAN_F_LURK); - /* First route the last ban(s) */ - do { - Lck_Lock(&ban_mtx); - b2 = ban_CheckLast(); - if (b2 != NULL) - /* Notify stevedores */ - STV_BanInfo(BI_DROP, b2->spec, ban_len(b2->spec)); - Lck_Unlock(&ban_mtx); - if (b2 != NULL) - BAN_Free(b2); - } while (b2 != NULL); - /* * Find out if we have any bans we can do something about * If we find any, tag them with our pass number. @@ -1004,7 +992,7 @@ ban_lurker(struct worker *wrk, void *priv) (void)priv; while (1) { - while (cache_param->ban_lurker_sleep == 0.0) { + do { /* * Ban-lurker is disabled: * Clean the last ban, if possible, and sleep @@ -1018,18 +1006,19 @@ ban_lurker(struct worker *wrk, void *priv) Lck_Unlock(&ban_mtx); if (bf != NULL) BAN_Free(bf); - else - VTIM_sleep(1.0); - } - - i = ban_lurker_work(wrk, &vsl); - VSL_Flush(&vsl, 0); - WRK_SumStat(wrk); - if (i) { - VTIM_sleep(cache_param->ban_lurker_sleep); - } else { - VTIM_sleep(1.0); + } while (bf != NULL); + + if (cache_param->ban_lurker_sleep != 0.0) { + do { + i = ban_lurker_work(wrk, &vsl); + VSL_Flush(&vsl, 0); + WRK_SumStat(wrk); + if (i) + VTIM_sleep( + cache_param->ban_lurker_sleep); + } while (i); } + VTIM_sleep(0.609); // Random, non-magic } NEEDLESS_RETURN(NULL); } From lkarsten at varnish-cache.org Thu Nov 22 14:05:38 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:05:38 +0100 Subject: [master] 8c857ed Merge virtualised into a new platform specific notes section. Add transparent hugepages info from ticket 1054. Message-ID: commit 8c857ed88cbacc7630f8103de2cd7b65d37e7e57 Author: Lasse Karstensen Date: Thu Nov 22 15:05:34 2012 +0100 Merge virtualised into a new platform specific notes section. Add transparent hugepages info from ticket 1054. diff --git a/doc/sphinx/installation/index.rst b/doc/sphinx/installation/index.rst index 916ecde..15b61eb 100644 --- a/doc/sphinx/installation/index.rst +++ b/doc/sphinx/installation/index.rst @@ -16,5 +16,6 @@ move traffic. help.rst bugs.rst upgrade.rst + platformnotes.rst diff --git a/doc/sphinx/installation/platformnotes.rst b/doc/sphinx/installation/platformnotes.rst new file mode 100644 index 0000000..4f76f9e --- /dev/null +++ b/doc/sphinx/installation/platformnotes.rst @@ -0,0 +1,37 @@ + +Platform specific notes +------------------------ + +Transparent hugepages on Redhat Linux 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +On RHEL6 Transparent Hugepage kernel support is enabled by default. +This is known to cause sporadic crashes of Varnish. + +It is recommended to disable transparent hugepages on affected systems:: + + $ echo "never" > /sys/kernel/mm/redhat_transparent_hugepage/enabled + +On Debian/Ubuntu systems running 3.2 kernels the default value is "madvise" and does not need to changed. + + +OpenVZ +~~~~~~ + +It is possible, but not recommended for high performance, to run +Varnish on virtualised hardware. Reduced disk and network -performance +will reduce the performance a bit so make sure your system has good IO +performance. + +If you are running on 64bit OpenVZ (or Parallels VPS), you must reduce +the maximum stack size before starting Varnish. + +The default allocates to much memory per thread, which will make varnish fail +as soon as the number of threads (traffic) increases. + +Reduce the maximum stack size by running:: + + ulimit -s 256 + +in the Varnish startup script. + diff --git a/doc/sphinx/users-guide/index.rst b/doc/sphinx/users-guide/index.rst index f3f4a2c..bfedbae 100644 --- a/doc/sphinx/users-guide/index.rst +++ b/doc/sphinx/users-guide/index.rst @@ -36,7 +36,6 @@ separate topic. purging compression esi - virtualized websockets devicedetection handling_misbehaving_servers diff --git a/doc/sphinx/users-guide/virtualized.rst b/doc/sphinx/users-guide/virtualized.rst deleted file mode 100644 index 5fc59b6..0000000 --- a/doc/sphinx/users-guide/virtualized.rst +++ /dev/null @@ -1,25 +0,0 @@ - -XXX: What is this doing here? - -Running Varnish in a virtualized environment --------------------------------------------- - -It is possible, but not recommended for high performance, to run -Varnish on virtualized hardware. Reduced disk- and network performance -will reduce the performance a bit so make sure your system has good IO -performance. - -OpenVZ -~~~~~~ - -If you are running on 64bit OpenVZ (or Parallels VPS), you must reduce -the maximum stack size before starting Varnish. The default allocates -to much memory per thread, which will make varnish fail as soon as the -number of threads (==traffic) increases. - -Reduce the maximum stack size by running:: - - ulimit -s 256 - -in the startup script. - From lkarsten at varnish-cache.org Thu Nov 22 14:06:12 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:06:12 +0100 Subject: [3.0] 7e0bcc1 Add section on transparent hugepages. Move virtualised into platformnotes Message-ID: commit 7e0bcc1eff27572d8d10b0abe8507bce186b9e6a Author: Lasse Karstensen Date: Thu Nov 22 13:57:57 2012 +0100 Add section on transparent hugepages. Move virtualised into platformnotes diff --git a/doc/sphinx/tutorial/platformnotes.rst b/doc/sphinx/tutorial/platformnotes.rst new file mode 100644 index 0000000..ffe5406 --- /dev/null +++ b/doc/sphinx/tutorial/platformnotes.rst @@ -0,0 +1,38 @@ + +Platform specific notes +------------------------ + +Transparent hugepages on Redhat Linux 6 +~~~~~~~~~~~~ + +On RHEL6 Transparent Hugepage kernel support is enabled by default. +This is known to cause sporadic crashes of Varnish. + +It is recommended to disable transparent hugepages on affected systems: + + $ echo "never" > /sys/kernel/mm/redhat_transparent_hugepage/enabled + +On Debian/Ubuntu systems running 3.2 kernels the value is "madvise", which does +not need to be changed. + + +OpenVZ +~~~~~~ + +It is possible, but not recommended for high performance, to run +Varnish on virtualised hardware. Reduced disk and network -performance +will reduce the performance a bit so make sure your system has good IO +performance. + +If you are running on 64bit OpenVZ (or Parallels VPS), you must reduce +the maximum stack size before starting Varnish. + +The default allocates to much memory per thread, which will make varnish fail +as soon as the number of threads (traffic) increases. + +Reduce the maximum stack size by running:: + + ulimit -s 256 + +in the Varnish startup script. + diff --git a/doc/sphinx/tutorial/virtualised.rst b/doc/sphinx/tutorial/virtualised.rst deleted file mode 100644 index ea8ade5..0000000 --- a/doc/sphinx/tutorial/virtualised.rst +++ /dev/null @@ -1,23 +0,0 @@ - -Running Varnish in a virtualized environment --------------------------------------------- - -It is possible, but not recommended for high performance, to run -Varnish on virtualised hardware. Reduced disk- and network performance -will reduce the performance a bit so make sure your system has good IO -performance. - -OpenVZ -~~~~~~ - -If you are running on 64bit OpenVZ (or Parallels VPS), you must reduce -the maximum stack size before starting Varnish. The default allocates -to much memory per thread, which will make varnish fail as soon as the -number of threads (==traffic) increases. - -Reduce the maximum stack size by running:: - - ulimit -s 256 - -in the startup script. - From lkarsten at varnish-cache.org Thu Nov 22 14:06:12 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:06:12 +0100 Subject: [3.0] 9ac4e87 Add into index. Formatting of commandline Message-ID: commit 9ac4e87c9e9ed1dd42311d0af143c6ecaec4d3f8 Author: Lasse Karstensen Date: Thu Nov 22 14:01:36 2012 +0100 Add into index. Formatting of commandline diff --git a/doc/sphinx/tutorial/index.rst b/doc/sphinx/tutorial/index.rst index d41bfbb..e30b40f 100644 --- a/doc/sphinx/tutorial/index.rst +++ b/doc/sphinx/tutorial/index.rst @@ -28,7 +28,7 @@ separate topic. Good luck. purging compression esi - virtualised + platformnotes websockets devicedetection advanced_backend_servers diff --git a/doc/sphinx/tutorial/platformnotes.rst b/doc/sphinx/tutorial/platformnotes.rst index ffe5406..4f76f9e 100644 --- a/doc/sphinx/tutorial/platformnotes.rst +++ b/doc/sphinx/tutorial/platformnotes.rst @@ -3,17 +3,16 @@ Platform specific notes ------------------------ Transparent hugepages on Redhat Linux 6 -~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On RHEL6 Transparent Hugepage kernel support is enabled by default. This is known to cause sporadic crashes of Varnish. -It is recommended to disable transparent hugepages on affected systems: +It is recommended to disable transparent hugepages on affected systems:: $ echo "never" > /sys/kernel/mm/redhat_transparent_hugepage/enabled -On Debian/Ubuntu systems running 3.2 kernels the value is "madvise", which does -not need to be changed. +On Debian/Ubuntu systems running 3.2 kernels the default value is "madvise" and does not need to changed. OpenVZ From lkarsten at varnish-cache.org Thu Nov 22 14:06:12 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:06:12 +0100 Subject: [3.0] 3fa646e Merge branch '3.0' of ssh://git.varnish-cache.org/git/varnish-cache into 3.0 Message-ID: commit 3fa646ec43d24fcd113dedd8439f8ba61dc7d3c8 Merge: 9ac4e87 5de7b57 Author: Lasse Karstensen Date: Thu Nov 22 15:06:02 2012 +0100 Merge branch '3.0' of ssh://git.varnish-cache.org/git/varnish-cache into 3.0 From lkarsten at varnish-cache.org Thu Nov 22 14:08:40 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:08:40 +0100 Subject: [3.0] 66ec78d RHEL6 is not RH6. Message-ID: commit 66ec78d6e8fbcf431908d05280821c06f0bbfead Author: Lasse Karstensen Date: Thu Nov 22 15:08:36 2012 +0100 RHEL6 is not RH6. diff --git a/doc/sphinx/tutorial/platformnotes.rst b/doc/sphinx/tutorial/platformnotes.rst index 4f76f9e..3ad486c 100644 --- a/doc/sphinx/tutorial/platformnotes.rst +++ b/doc/sphinx/tutorial/platformnotes.rst @@ -2,8 +2,8 @@ Platform specific notes ------------------------ -Transparent hugepages on Redhat Linux 6 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Transparent hugepages on Redhat Enterprise Linux 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On RHEL6 Transparent Hugepage kernel support is enabled by default. This is known to cause sporadic crashes of Varnish. From lkarsten at varnish-cache.org Thu Nov 22 14:09:35 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Thu, 22 Nov 2012 15:09:35 +0100 Subject: [master] bdfcd1a RHEL6 is not RH6. Message-ID: commit bdfcd1a5e6d3632581e9ac823d04451b3ac4871c Author: Lasse Karstensen Date: Thu Nov 22 15:09:32 2012 +0100 RHEL6 is not RH6. diff --git a/doc/sphinx/installation/platformnotes.rst b/doc/sphinx/installation/platformnotes.rst index 4f76f9e..3ad486c 100644 --- a/doc/sphinx/installation/platformnotes.rst +++ b/doc/sphinx/installation/platformnotes.rst @@ -2,8 +2,8 @@ Platform specific notes ------------------------ -Transparent hugepages on Redhat Linux 6 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Transparent hugepages on Redhat Enterprise Linux 6 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ On RHEL6 Transparent Hugepage kernel support is enabled by default. This is known to cause sporadic crashes of Varnish. From lkarsten at varnish-cache.org Fri Nov 23 09:26:12 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 23 Nov 2012 10:26:12 +0100 Subject: [master] a55e7e2 docs: Finish up deleting virtualized and adding platformnotes.rst Message-ID: commit a55e7e2545f532dc9cbb7db64bdd7bcf7f224d40 Author: Lasse Karstensen Date: Fri Nov 23 10:26:08 2012 +0100 docs: Finish up deleting virtualized and adding platformnotes.rst diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am index 76657ec..8d9927d 100644 --- a/doc/sphinx/Makefile.am +++ b/doc/sphinx/Makefile.am @@ -98,6 +98,7 @@ EXTRA_DIST = \ installation/install.rst \ installation/prerequisites.rst \ installation/upgrade.rst \ + installation/platformnotes.rst \ phk/autocrap.rst \ phk/backends.rst \ phk/barriers.rst \ @@ -163,7 +164,6 @@ EXTRA_DIST = \ users-guide/vcl-subs.rst \ users-guide/vcl-syntax.rst \ users-guide/vcl-variables.rst \ - users-guide/virtualized.rst \ users-guide/websockets.rst diff --git a/doc/sphinx/users-guide/operation.rst b/doc/sphinx/users-guide/operation.rst index c7c74f9..4cc85fa 100644 --- a/doc/sphinx/users-guide/operation.rst +++ b/doc/sphinx/users-guide/operation.rst @@ -14,4 +14,3 @@ Operation esi vary cookies - virtualized \ No newline at end of file From lkarsten at varnish-cache.org Fri Nov 23 09:35:49 2012 From: lkarsten at varnish-cache.org (Lasse Karstensen) Date: Fri, 23 Nov 2012 10:35:49 +0100 Subject: [master] 85aac30 Fix RST parse error Message-ID: commit 85aac306aebe55501c952be4482573a552784085 Author: Lasse Karstensen Date: Fri Nov 23 10:35:46 2012 +0100 Fix RST parse error diff --git a/doc/sphinx/phk/spdy.rst b/doc/sphinx/phk/spdy.rst index 327518a..68bf000 100644 --- a/doc/sphinx/phk/spdy.rst +++ b/doc/sphinx/phk/spdy.rst @@ -90,7 +90,7 @@ I already can hear some of you amazing VCL wizards say "Well, if you inline-C grab a refcount, then restart and ..." but lets be honest, that's not how it should look. -You should be able to do something like: +You should be able to do something like:: if (req.proto == "SPDY" && req.url ~ "index.html") { req.obj1 = lookup(backend1, "/main.css") From tfheen at varnish-cache.org Fri Nov 23 09:39:20 2012 From: tfheen at varnish-cache.org (Tollef Fog Heen) Date: Fri, 23 Nov 2012 10:39:20 +0100 Subject: [master] 952e1ce Don't use glossary in rst2man page, sort CLI command list Message-ID: commit 952e1ce5ae27c76ed9681efcd71337ccdb86e45d Author: Tollef Fog Heen Date: Fri Nov 23 10:37:47 2012 +0100 Don't use glossary in rst2man page, sort CLI command list rst2man doesn't support the `glossary` markup, it's a sphinxism. Avoid using that and sort the list manually instead. diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index a4ec1b9..43fd590 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -76,121 +76,118 @@ be entered with the \\xnn syntax. Commands -------- -.. glossary:: - :sorted: - - help [command] - Display a list of available commands. - If the command is specified, display help for this command. - - param.set param value - Set the parameter specified by param to the specified value. - See Run-Time Parameters for a list of parame? ters. - - param.show [-l] [param] - Display a list if run-time parameters and their values. - - If the -l option is specified, the list includes a brief - explanation of each parameter. - - If a param is specified, display only the value and explanation - for this parameter. +backend.list + Lists the defined backends including health state. - ping [timestamp] - Ping the Varnish cache process, keeping the connection alive. +backend.set_health matcher state + Sets the health state on a specific backend. This is useful if + you want to take a certain backend out of sirculations. - ban *field operator argument* [&& field operator argument [...]] +ban *field operator argument* [&& field operator argument [...]] Immediately invalidate all documents matching the ban expression. See *Ban Expressions* for more documentation and examples. - ban.list +ban.list All requests for objects from the cache are matched against items on the ban list. If an object in the cache is older than a matching ban list item, it is considered "banned", and will be fetched from the backend instead. - + When a ban expression is older than all the objects in the cache, it is removed from the list. - + ban.list displays the ban list. The output looks something like - this (broken into two lines): - - 0x7fea4fcb0580 1303835108.618863 131G req.http.host ~ - www.myhost.com && req.url ~ /some/url - - The first field is the address of the ban. - + this:: + + 0x7fea4fcb0580 1303835108.618863 131G req.url ~ /some/url + + The first field is the address of the ban. + The second is the time of entry into the list, given as a high precision timestamp. - + The third field describes many objects point to this ban. When an object is compared to a ban the object is marked with a reference to the newest ban it was tested against. This isn't really useful unless you're debugging. - + A "G" marks that the ban is "Gone". Meaning it has been marked as a duplicate or it is no longer valid. It stays in the list for effiency reasons. - + Then follows the actual ban it self. - ban.url regexp +ban.url regexp Immediately invalidate all documents whose URL matches the specified regular expression. Please note that the Host part of the URL is ignored, so if you have several virtual hosts all of them will be banned. Use *ban* to specify a complete ban if you need to narrow it down. - quit +help [command] + Display a list of available commands. + If the command is specified, display help for this command. + +param.set param value + Set the parameter specified by param to the specified value. + See Run-Time Parameters for a list of parame? ters. + +param.show [-l] [param] + Display a list if run-time parameters and their values. + + If the -l option is specified, the list includes a brief + explanation of each parameter. + + If a param is specified, display only the value and explanation + for this parameter. + +ping [timestamp] + Ping the Varnish cache process, keeping the connection alive. + +quit Close the connection to the varnish admin port. - start +start Start the Varnish cache process if it is not already running. - status +status Check the status of the Varnish cache process. - stop +stop Stop the Varnish cache process. - vcl.discard configname +storage.list + Lists the defined storage backends. + +vcl.discard configname Discard the configuration specified by configname. This will have no effect if the specified configuration has a non-zero reference count. - vcl.inline configname vcl +vcl.inline configname vcl Create a new configuration named configname with the VCL code specified by vcl, which must be a quoted string. - vcl.list +vcl.list List available configurations and their respective reference counts. The active configuration is indicated with an asterisk ("*"). - vcl.load configname filename +vcl.load configname filename Create a new configuration named configname with the contents of the specified file. - vcl.show configname +vcl.show configname Display the source code for the specified configuration. - vcl.use configname +vcl.use configname Start using the configuration specified by configname for all new requests. Existing requests will con? tinue using whichever configuration was in use when they arrived. - storage.list - Lists the defined storage backends. - backend.list - Lists the defined backends including health state. - - backend.set_health matcher state - Sets the health state on a specific backend. This is useful if - you want to take a certain backend out of sirculations. - Ban Expressions ---------------