[master] d9c1916 Add a per-method specific pointer to the vrt-context, and use it to slim down req/busyobj a tiny bit.
Poul-Henning Kamp
phk at FreeBSD.org
Thu May 14 11:43:27 CEST 2015
commit d9c19168e544747d0f8d08499a484a883231318c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu May 14 09:42:46 2015 +0000
Add a per-method specific pointer to the vrt-context, and use
it to slim down req/busyobj a tiny bit.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e51fbb4..7986cb3 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -98,7 +98,6 @@ enum {
/*--------------------------------------------------------------------*/
-struct SHA256Context;
struct VSC_C_lck;
struct ban;
struct busyobj;
@@ -518,8 +517,6 @@ struct busyobj {
struct vsl_log vsl[1];
- struct vsb *synth_body;
-
uint8_t digest[DIGEST_LEN];
struct vrt_privs privs[1];
};
@@ -592,8 +589,6 @@ struct req {
struct ws ws[1];
struct objcore *objcore;
struct objcore *stale_oc;
- /* Lookup stuff */
- struct SHA256Context *sha256ctx;
/* ESI delivery stuff */
ssize_t l_crc;
@@ -619,9 +614,6 @@ struct req {
/* Temporary accounting */
struct acct_req acct;
-
- /* Synth content in vcl_synth */
- struct vsb *synth_body;
};
/*--------------------------------------------------------------------
@@ -1086,7 +1078,7 @@ const char *VCL_Method_Name(unsigned);
#define VCL_MET_MAC(l,u,b) \
void VCL_##l##_method(struct VCL_conf *, struct worker *, struct req *, \
- struct busyobj *bo);
+ struct busyobj *bo, void *specific);
#include "tbl/vcl_returns.h"
#undef VCL_MET_MAC
diff --git a/bin/varnishd/cache/cache_deliver_proc.c b/bin/varnishd/cache/cache_deliver_proc.c
index 34769c0..9006af8 100644
--- a/bin/varnishd/cache/cache_deliver_proc.c
+++ b/bin/varnishd/cache/cache_deliver_proc.c
@@ -115,7 +115,6 @@ VDP_DeliverObj(struct req *req)
oi = ObjIterBegin(req->wrk, req->objcore);
XXXAN(oi);
- AZ(req->synth_body);
do {
ois = ObjIter(req->objcore, oi, &ptr, &len);
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 24df6f6..b29eb25 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -274,7 +274,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(bo->vsl->wid));
- VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo);
+ VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, NULL);
bo->uncacheable = bo->do_pass;
if (wrk->handling == VCL_RET_ABANDON)
@@ -426,7 +426,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
bo->vfc->http = bo->beresp;
bo->vfc->esi_req = bo->bereq;
- VCL_backend_response_method(bo->vcl, wrk, NULL, bo);
+ VCL_backend_response_method(bo->vcl, wrk, NULL, bo, NULL);
if (wrk->handling == VCL_RET_ABANDON) {
bo->doclose = SC_RESP_CLOSE;
@@ -770,6 +770,7 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
ssize_t l, ll, o;
double now;
uint8_t *ptr;
+ struct vsb *synth_body;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -780,9 +781,8 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
AN(bo->fetch_objcore->flags & OC_F_BUSY);
- AZ(bo->synth_body);
- bo->synth_body = VSB_new_auto();
- AN(bo->synth_body);
+ synth_body = VSB_new_auto();
+ AN(synth_body);
// XXX: reset all beresp flags ?
@@ -796,13 +796,12 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
bo->fetch_objcore->exp.grace = 0;
bo->fetch_objcore->exp.keep = 0;
- VCL_backend_error_method(bo->vcl, wrk, NULL, bo);
+ VCL_backend_error_method(bo->vcl, wrk, NULL, bo, synth_body);
- AZ(VSB_finish(bo->synth_body));
+ AZ(VSB_finish(synth_body));
if (wrk->handling == VCL_RET_RETRY) {
- VSB_delete(bo->synth_body);
- bo->synth_body = NULL;
+ VSB_delete(synth_body);
bo->doclose = SC_RESP_CLOSE;
if (bo->director_state != DIR_S_NULL)
@@ -822,22 +821,23 @@ vbf_stp_error(struct worker *wrk, struct busyobj *bo)
bo->vfc->http = bo->beresp;
bo->vfc->esi_req = bo->bereq;
- if (vbf_beresp2obj(bo))
+ if (vbf_beresp2obj(bo)) {
+ VSB_delete(synth_body);
return (F_STP_FAIL);
+ }
- ll = VSB_len(bo->synth_body);
+ ll = VSB_len(synth_body);
o = 0;
while (ll > 0) {
l = ll;
if (VFP_GetStorage(bo->vfc, &l, &ptr) != VFP_OK)
break;
- memcpy(ptr, VSB_data(bo->synth_body) + o, l);
+ memcpy(ptr, VSB_data(synth_body) + o, l);
VBO_extend(bo, l);
ll -= l;
o += l;
}
- VSB_delete(bo->synth_body);
- bo->synth_body = NULL;
+ VSB_delete(synth_body);
HSH_Unbusy(wrk, bo->fetch_objcore);
VBO_setstate(bo, BOS_FINISHED);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 8a15757..03a4f77 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -187,16 +187,16 @@ HSH_DeleteObjHead(struct worker *wrk, struct objhead *oh)
}
void
-HSH_AddString(struct req *req, const char *str)
+HSH_AddString(struct req *req, void *ctx, const char *str)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- AN(req->sha256ctx);
+ AN(ctx);
if (str != NULL) {
- SHA256_Update(req->sha256ctx, str, strlen(str));
+ SHA256_Update(ctx, str, strlen(str));
VSLb(req->vsl, SLT_Hash, "%s", str);
} else
- SHA256_Update(req->sha256ctx, &str, sizeof str);
+ SHA256_Update(ctx, &str, 1);
}
/*---------------------------------------------------------------------
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 8e48880..c4594a7 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -133,7 +133,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
!RFC2616_Req_Gzip(req->http))
RFC2616_Weaken_Etag(req->resp);
- VCL_deliver_method(req->vcl, wrk, req, NULL);
+ VCL_deliver_method(req->vcl, wrk, req, NULL, NULL);
VSLb_ts_req(req, "Process", W_TIM_real(wrk));
/* Stop the insanity before it turns "Hotel California" on us */
@@ -211,6 +211,7 @@ cnt_synth(struct worker *wrk, struct req *req)
{
struct http *h;
double now;
+ struct vsb *synth_body;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
@@ -231,23 +232,21 @@ cnt_synth(struct worker *wrk, struct req *req)
http_PrintfHeader(req->resp, "X-Varnish: %u", VXID(req->vsl->wid));
http_PutResponse(h, "HTTP/1.1", req->err_code, req->err_reason);
- AZ(req->synth_body);
- req->synth_body = VSB_new_auto();
- AN(req->synth_body);
+ synth_body = VSB_new_auto();
+ AN(synth_body);
- VCL_synth_method(req->vcl, wrk, req, NULL);
+ VCL_synth_method(req->vcl, wrk, req, NULL, synth_body);
http_Unset(h, H_Content_Length);
- AZ(VSB_finish(req->synth_body));
+ AZ(VSB_finish(synth_body));
/* Discard any lingering request body before delivery */
(void)VRB_Ignore(req);
if (wrk->handling == VCL_RET_RESTART) {
HTTP_Setup(h, req->ws, req->vsl, SLT_RespMethod);
- VSB_delete(req->synth_body);
- req->synth_body = NULL;
+ VSB_delete(synth_body);
req->req_step = R_STP_RESTART;
return (REQ_FSM_MORE);
}
@@ -262,21 +261,20 @@ cnt_synth(struct worker *wrk, struct req *req)
ssize_t sz, szl;
uint8_t *ptr;
- szl = VSB_len(req->synth_body);
+ szl = VSB_len(synth_body);
assert(szl >= 0);
if (szl > 0) {
sz = szl;
AN(ObjGetSpace(wrk, req->objcore, &sz, &ptr));
assert(sz >= szl);
- memcpy(ptr, VSB_data(req->synth_body), szl);
+ memcpy(ptr, VSB_data(synth_body), szl);
ObjExtend(wrk, req->objcore, szl);
}
- VSB_delete(req->synth_body);
- req->synth_body = NULL;
cnt_vdp(req, NULL);
(void)HSH_DerefObjCore(wrk, &req->objcore);
}
+ VSB_delete(synth_body);
VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
@@ -388,7 +386,7 @@ cnt_lookup(struct worker *wrk, struct req *req)
VSLb(req->vsl, SLT_Hit, "%u", ObjGetXID(wrk, req->objcore));
- VCL_hit_method(req->vcl, wrk, req, NULL);
+ VCL_hit_method(req->vcl, wrk, req, NULL, NULL);
switch (wrk->handling) {
case VCL_RET_DELIVER:
@@ -463,7 +461,7 @@ cnt_miss(struct worker *wrk, struct req *req)
CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC);
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
- VCL_miss_method(req->vcl, wrk, req, NULL);
+ VCL_miss_method(req->vcl, wrk, req, NULL, NULL);
switch (wrk->handling) {
case VCL_RET_FETCH:
wrk->stats->cache_miss++;
@@ -504,7 +502,7 @@ cnt_pass(struct worker *wrk, struct req *req)
CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC);
AZ(req->objcore);
- VCL_pass_method(req->vcl, wrk, req, NULL);
+ VCL_pass_method(req->vcl, wrk, req, NULL, NULL);
switch (wrk->handling) {
case VCL_RET_SYNTH:
req->req_step = R_STP_SYNTH;
@@ -550,7 +548,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(req->vsl->wid));
http_SetHeader(bo->bereq, "Connection: close");
- VCL_pipe_method(req->vcl, wrk, req, bo);
+ VCL_pipe_method(req->vcl, wrk, req, bo, NULL);
if (wrk->handling == VCL_RET_SYNTH)
INCOMPL();
@@ -651,7 +649,7 @@ cnt_recv(struct worker *wrk, struct req *req)
http_CollectHdr(req->http, H_Cache_Control);
- VCL_recv_method(req->vcl, wrk, req, NULL);
+ VCL_recv_method(req->vcl, wrk, req, NULL, NULL);
/* Attempts to cache req.body may fail */
if (req->req_body_status == REQ_BODY_FAIL) {
@@ -672,12 +670,10 @@ cnt_recv(struct worker *wrk, struct req *req)
}
}
- req->sha256ctx = &sha256ctx; /* so HSH_AddString() can find it */
- SHA256_Init(req->sha256ctx);
- VCL_hash_method(req->vcl, wrk, req, NULL);
+ SHA256_Init(&sha256ctx);
+ VCL_hash_method(req->vcl, wrk, req, NULL, &sha256ctx);
assert(wrk->handling == VCL_RET_LOOKUP);
- SHA256_Final(req->digest, req->sha256ctx);
- req->sha256ctx = NULL;
+ SHA256_Final(req->digest, &sha256ctx);
if (!strcmp(req->http->hd[HTTP_HDR_METHOD].b, "HEAD"))
req->wantbody = 0;
@@ -743,7 +739,7 @@ cnt_purge(struct worker *wrk, struct req *req)
AZ(HSH_DerefObjCore(wrk, &boc));
- VCL_purge_method(req->vcl, wrk, req, NULL);
+ VCL_purge_method(req->vcl, wrk, req, NULL, NULL);
switch (wrk->handling) {
case VCL_RET_RESTART:
req->req_step = R_STP_RESTART;
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index ac051d1..a453cf3 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -461,7 +461,7 @@ ccf_config_show(struct cli *cli, const char * const *av, void *priv)
static void
vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
- unsigned method, vcl_func_f *func)
+ void *specific, unsigned method, vcl_func_f *func)
{
char *aws;
struct vsl_log *vsl = NULL;
@@ -492,6 +492,7 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
}
assert(ctx.now != 0);
ctx.vsl = vsl;
+ ctx.specific = specific;
ctx.method = method;
ctx.handling = &wrk->handling;
aws = WS_Snapshot(wrk->aws);
@@ -514,13 +515,13 @@ vcl_call_method(struct worker *wrk, struct req *req, struct busyobj *bo,
#define VCL_MET_MAC(func, upper, bitmap) \
void \
VCL_##func##_method(struct VCL_conf *vcl, struct worker *wrk, \
- struct req *req, struct busyobj *bo) \
+ struct req *req, struct busyobj *bo, void *specific) \
{ \
\
CHECK_OBJ_NOTNULL(vcl, VCL_CONF_MAGIC); \
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); \
- vcl_call_method(wrk, req, bo, VCL_MET_ ## upper, \
- vcl->func##_func); \
+ vcl_call_method(wrk, req, bo, specific, \
+ VCL_MET_ ## upper, vcl->func##_func); \
AN((1U << wrk->handling) & bitmap); \
}
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 63d2502..5a12c63 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -264,20 +264,21 @@ VRT_hashdata(VRT_CTX, const char *str, ...)
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
- HSH_AddString(ctx->req, str);
+ AN(ctx->specific);
+ HSH_AddString(ctx->req, ctx->specific, str);
va_start(ap, str);
while (1) {
p = va_arg(ap, const char *);
if (p == vrt_magic_string_end)
break;
- HSH_AddString(ctx->req, p);
+ HSH_AddString(ctx->req, ctx->specific, p);
}
va_end(ap);
/*
* Add a 'field-separator' to make it more difficult to
* manipulate the hash.
*/
- HSH_AddString(ctx->req, NULL);
+ HSH_AddString(ctx->req, ctx->specific, NULL);
}
/*--------------------------------------------------------------------*/
@@ -386,16 +387,7 @@ VRT_synth_page(VRT_CTX, const char *str, ...)
const char *p;
struct vsb *vsb;
- CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- if (ctx->method == VCL_MET_BACKEND_ERROR) {
- CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
- vsb = ctx->bo->synth_body;
- } else {
- CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
- vsb = ctx->req->synth_body;
- }
- AN(vsb);
-
+ CAST_OBJ_NOTNULL(vsb, ctx->specific, VSB_MAGIC);
va_start(ap, str);
p = str;
while (p != vrt_magic_string_end) {
diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h
index 6f546ff..47a68cb 100644
--- a/bin/varnishd/hash/hash_slinger.h
+++ b/bin/varnishd/hash/hash_slinger.h
@@ -67,7 +67,7 @@ enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **,
int wait_for_busy, int always_insert);
void HSH_Ref(struct objcore *o);
void HSH_Init(const struct hash_slinger *slinger);
-void HSH_AddString(struct req *, const char *str);
+void HSH_AddString(struct req *, void *ctx, const char *str);
void HSH_Insert(struct worker *, const void *hash, struct objcore *);
void HSH_Purge(struct worker *, struct objhead *, double ttl, double grace,
double keep);
diff --git a/include/vrt.h b/include/vrt.h
index 5e4882e..97c4e92 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -107,6 +107,13 @@ struct vrt_ctx {
struct http *http_beresp;
double now;
+
+ /*
+ * method specific argument:
+ * hash: struct SHA256ctx
+ * synth+error: struct vsb *
+ */
+ void *specific;
};
#define VRT_CTX const struct vrt_ctx *ctx
More information about the varnish-commit
mailing list