From 38be4497805aa3e939df4820d6f5065572afaf61 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 14 Jan 2008 09:14:56 +0000 Subject: [PATCH] Add VCC support for: Variables that can take relative, currently limited to negative, time intervals. vcl_prefetch{} method obj.prefetch variable. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2341 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/include/vcl.h | 1 + varnish-cache/include/vcl_returns.h | 8 +++++--- varnish-cache/include/vrt_obj.h | 2 ++ varnish-cache/lib/libvcl/vcc_action.c | 3 +++ varnish-cache/lib/libvcl/vcc_compile.h | 2 ++ varnish-cache/lib/libvcl/vcc_fixed_token.c | 3 +++ .../lib/libvcl/vcc_gen_fixed_token.tcl | 1 + varnish-cache/lib/libvcl/vcc_gen_obj.tcl | 6 ++++++ varnish-cache/lib/libvcl/vcc_obj.c | 7 +++++++ varnish-cache/lib/libvcl/vcc_parse.c | 17 +++++++++++++++++ 10 files changed, 47 insertions(+), 3 deletions(-) diff --git a/varnish-cache/include/vcl.h b/varnish-cache/include/vcl.h index b6bb447e..8973590b 100644 --- a/varnish-cache/include/vcl.h +++ b/varnish-cache/include/vcl.h @@ -41,6 +41,7 @@ struct VCL_conf { vcl_func_f *hit_func; vcl_func_f *fetch_func; vcl_func_f *deliver_func; + vcl_func_f *prefetch_func; vcl_func_f *timeout_func; vcl_func_f *discard_func; }; diff --git a/varnish-cache/include/vcl_returns.h b/varnish-cache/include/vcl_returns.h index 76ad3f6a..d69c8d65 100644 --- a/varnish-cache/include/vcl_returns.h +++ b/varnish-cache/include/vcl_returns.h @@ -44,6 +44,7 @@ VCL_MET_MAC(miss,MISS,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH) VCL_MET_MAC(hit,HIT,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) VCL_MET_MAC(fetch,FETCH,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_INSERT)) VCL_MET_MAC(deliver,DELIVER,(VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_DELIVER)) +VCL_MET_MAC(prefetch,PREFETCH,(VCL_RET_FETCH|VCL_RET_PASS)) VCL_MET_MAC(timeout,TIMEOUT,(VCL_RET_FETCH|VCL_RET_DISCARD)) VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_KEEP)) #else @@ -55,7 +56,8 @@ VCL_MET_MAC(discard,DISCARD,(VCL_RET_DISCARD|VCL_RET_KEEP)) #define VCL_MET_HIT (1 << 5) #define VCL_MET_FETCH (1 << 6) #define VCL_MET_DELIVER (1 << 7) -#define VCL_MET_TIMEOUT (1 << 8) -#define VCL_MET_DISCARD (1 << 9) +#define VCL_MET_PREFETCH (1 << 8) +#define VCL_MET_TIMEOUT (1 << 9) +#define VCL_MET_DISCARD (1 << 10) #endif -#define N_METHODS 10 +#define N_METHODS 11 diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index f8a9cd4a..ca2d8737 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -40,6 +40,8 @@ unsigned VRT_r_obj_cacheable(const struct sess *); void VRT_l_obj_cacheable(const struct sess *, unsigned); double VRT_r_obj_ttl(const struct sess *); void VRT_l_obj_ttl(const struct sess *, double); +double VRT_r_obj_prefetch(const struct sess *); +void VRT_l_obj_prefetch(const struct sess *, double); double VRT_r_obj_lastuse(const struct sess *); const char * VRT_r_resp_proto(const struct sess *); void VRT_l_resp_proto(const struct sess *, const char *, ...); diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index b225ca2f..6ea661e4 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -156,6 +156,7 @@ parse_set(struct tokenlist *tl) case SIZE: case RATE: case TIME: + case RTIME: case FLOAT: if (tl->t->tok != '=') Fb(tl, 0, "%s %c ", vp->rname, *tl->t->b); @@ -171,6 +172,8 @@ parse_set(struct tokenlist *tl) case '=': if (vp->fmt == TIME) vcc_TimeVal(tl); + else if (vp->fmt == RTIME) + vcc_RTimeVal(tl); else if (vp->fmt == SIZE) vcc_SizeVal(tl); else if (vp->fmt == RATE) diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 56f8407f..c8977b5b 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -95,6 +95,7 @@ enum var_type { SIZE, RATE, TIME, + RTIME, STRING, IP, HOSTNAME, @@ -174,6 +175,7 @@ extern struct var vcc_vars[]; /* vcc_parse.c */ void vcc_Parse(struct tokenlist *tl); void vcc_RateVal(struct tokenlist *tl); +void vcc_RTimeVal(struct tokenlist *tl); void vcc_TimeVal(struct tokenlist *tl); void vcc_SizeVal(struct tokenlist *tl); unsigned vcc_UintVal(struct tokenlist *tl); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 21d68c15..638f89f3 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -374,6 +374,7 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, " vcl_func_f *hit_func;\n"); vsb_cat(sb, " vcl_func_f *fetch_func;\n"); vsb_cat(sb, " vcl_func_f *deliver_func;\n"); + vsb_cat(sb, " vcl_func_f *prefetch_func;\n"); vsb_cat(sb, " vcl_func_f *timeout_func;\n"); vsb_cat(sb, " vcl_func_f *discard_func;\n"); vsb_cat(sb, "};\n"); @@ -551,6 +552,8 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "void VRT_l_obj_cacheable(const struct sess *, unsigned);\n"); vsb_cat(sb, "double VRT_r_obj_ttl(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_obj_ttl(const struct sess *, double);\n"); + vsb_cat(sb, "double VRT_r_obj_prefetch(const struct sess *);\n"); + vsb_cat(sb, "void VRT_l_obj_prefetch(const struct sess *, double);\n"); vsb_cat(sb, "double VRT_r_obj_lastuse(const struct sess *);\n"); vsb_cat(sb, "const char * VRT_r_resp_proto(const struct sess *);\n"); vsb_cat(sb, "void VRT_l_resp_proto(const struct sess *, const char *, ...);\n"); diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index 578d70db..71bb8265 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -42,6 +42,7 @@ set methods { {hit {error restart pass deliver}} {fetch {error restart pass insert}} {deliver {error restart deliver}} + {prefetch {fetch pass}} {timeout {fetch discard}} {discard {discard keep}} } diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 669d478f..1e88b93f 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -157,6 +157,11 @@ set spobj { { hit fetch discard timeout} "const struct sess *" } + { obj.prefetch + RW RTIME + { fetch prefetch } + "const struct sess *" + } { obj.lastuse RO TIME { hit fetch deliver discard timeout} @@ -205,6 +210,7 @@ set tt(STRING) "const char *" set tt(BOOL) "unsigned" set tt(BACKEND) "struct backend *" set tt(TIME) "double" +set tt(RTIME) "double" set tt(INT) "int" set tt(HDR_RESP) "const char *" set tt(HDR_OBJ) "const char *" diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index 6ea90a03..a89e6853 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -182,6 +182,13 @@ struct var vcc_vars[] = { 0, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, + { "obj.prefetch", RTIME, 12, + "VRT_r_obj_prefetch(sp)", + "VRT_l_obj_prefetch(sp, ", + V_RW, + 0, + VCL_MET_FETCH | VCL_MET_PREFETCH + }, { "obj.lastuse", TIME, 11, "VRT_r_obj_lastuse(sp)", NULL, diff --git a/varnish-cache/lib/libvcl/vcc_parse.c b/varnish-cache/lib/libvcl/vcc_parse.c index cd9fe721..e601a98b 100644 --- a/varnish-cache/lib/libvcl/vcc_parse.c +++ b/varnish-cache/lib/libvcl/vcc_parse.c @@ -183,6 +183,23 @@ vcc_DoubleVal(struct tokenlist *tl) /*--------------------------------------------------------------------*/ +void +vcc_RTimeVal(struct tokenlist *tl) +{ + double v, sc; + int sign = 1; + + if (tl->t->tok == '-') { + sign *= -1; + vcc_NextToken(tl); + } + v = vcc_DoubleVal(tl); + ERRCHK(tl); + ExpectErr(tl, ID); + sc = TimeUnit(tl); + Fb(tl, 0, "(%d * %g * %g)", sign, v, sc); +} + void vcc_TimeVal(struct tokenlist *tl) { -- 2.39.5