[experimental-ims] ef234ec Start descoping the fetch-from-backend stuff into struct busyobj.
Geoff Simmons
geoff at varnish-cache.org
Mon Jan 9 21:52:43 CET 2012
commit ef234ec9c32a7c0d209df5501858c100d37235b2
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 29 15:55:42 2011 +0000
Start descoping the fetch-from-backend stuff into struct busyobj.
The fetching worker has wrk->busyobj set
Push is_g[un]zip flags into busyobj as proof of concept.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 8371278..7ad7fbd 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -323,6 +323,7 @@ struct worker {
struct object *obj;
struct objcore *objcore;
+ struct busyobj *busyobj;
struct exp exp;
@@ -340,9 +341,7 @@ struct worker {
unsigned do_stream;
unsigned do_esi;
unsigned do_gzip;
- unsigned is_gzip;
unsigned do_gunzip;
- unsigned is_gunzip;
unsigned do_close;
char *h_content_length;
@@ -492,6 +491,8 @@ struct busyobj {
unsigned magic;
#define BUSYOBJ_MAGIC 0x23b95567
uint8_t *vary;
+ unsigned is_gzip;
+ unsigned is_gunzip;
};
/* Object structure --------------------------------------------------*/
@@ -967,6 +968,21 @@ void SMP_Init(void);
void SMP_Ready(void);
void SMP_NewBan(const uint8_t *ban, unsigned len);
+#define New_BusyObj(wrk) \
+ do { \
+ if (wrk->nbusyobj != NULL) { \
+ CHECK_OBJ_NOTNULL(wrk->nbusyobj, BUSYOBJ_MAGIC);\
+ wrk->busyobj = wrk->nbusyobj; \
+ wrk->nbusyobj = NULL; \
+ memset(wrk->busyobj, 0, sizeof *wrk->busyobj); \
+ wrk->busyobj->magic = BUSYOBJ_MAGIC; \
+ } else { \
+ ALLOC_OBJ(wrk->busyobj, BUSYOBJ_MAGIC); \
+ } \
+ CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC); \
+ AZ(wrk->nbusyobj); \
+ } while (0)
+
/*
* A normal pointer difference is signed, but we never want a negative value
* so this little tool will make sure we don't get that.
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 3832116..8f9e527 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -323,12 +323,12 @@ cnt_done(struct sess *sp)
sp->director = NULL;
sp->restarts = 0;
+ sp->wrk->busyobj = NULL;
+
sp->wrk->do_esi = 0;
sp->wrk->do_gunzip = 0;
sp->wrk->do_gzip = 0;
sp->wrk->do_stream = 0;
- sp->wrk->is_gunzip = 0;
- sp->wrk->is_gzip = 0;
SES_Charge(sp);
@@ -444,8 +444,6 @@ cnt_error(struct sess *sp)
w = sp->wrk;
w->do_esi = 0;
- w->is_gzip = 0;
- w->is_gunzip = 0;
w->do_gzip = 0;
w->do_gunzip = 0;
w->do_stream = 0;
@@ -552,6 +550,8 @@ cnt_fetch(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
AN(sp->director);
AZ(sp->wrk->vbc);
@@ -688,6 +688,8 @@ cnt_fetchbody(struct sess *sp)
wrk = sp->wrk;
+ CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+
assert(sp->handling == VCL_RET_HIT_FOR_PASS ||
sp->handling == VCL_RET_DELIVER);
@@ -724,15 +726,17 @@ cnt_fetchbody(struct sess *sp)
if (!cache_param->http_gzip_support)
wrk->do_gzip = wrk->do_gunzip = 0;
- wrk->is_gzip = http_HdrIs(wrk->beresp, H_Content_Encoding, "gzip");
+ wrk->busyobj->is_gzip =
+ http_HdrIs(wrk->beresp, H_Content_Encoding, "gzip");
- wrk->is_gunzip = !http_GetHdr(wrk->beresp, H_Content_Encoding, NULL);
+ wrk->busyobj->is_gunzip =
+ !http_GetHdr(wrk->beresp, H_Content_Encoding, NULL);
/* It can't be both */
- assert(wrk->is_gzip == 0 || wrk->is_gunzip == 0);
+ assert(wrk->busyobj->is_gzip == 0 || wrk->busyobj->is_gunzip == 0);
/* We won't gunzip unless it is gzip'ed */
- if (wrk->do_gunzip && !wrk->is_gzip)
+ if (wrk->do_gunzip && !wrk->busyobj->is_gzip)
wrk->do_gunzip = 0;
/* If we do gunzip, remove the C-E header */
@@ -740,7 +744,7 @@ cnt_fetchbody(struct sess *sp)
http_Unset(wrk->beresp, H_Content_Encoding);
/* We wont gzip unless it is ungziped */
- if (wrk->do_gzip && !wrk->is_gunzip)
+ if (wrk->do_gzip && !wrk->busyobj->is_gunzip)
wrk->do_gzip = 0;
/* If we do gzip, add the C-E header */
@@ -758,7 +762,7 @@ cnt_fetchbody(struct sess *sp)
wrk->vfp = &vfp_gunzip;
else if (wrk->do_gzip)
wrk->vfp = &vfp_gzip;
- else if (wrk->is_gzip)
+ else if (wrk->busyobj->is_gzip)
wrk->vfp = &vfp_testgzip;
if (wrk->do_esi || sp->esi_level > 0)
@@ -811,7 +815,7 @@ cnt_fetchbody(struct sess *sp)
wrk->storage_hint = NULL;
- if (wrk->do_gzip || (wrk->is_gzip && !wrk->do_gunzip))
+ if (wrk->do_gzip || (wrk->busyobj->is_gzip && !wrk->do_gunzip))
wrk->obj->gziped = 1;
if (vary != NULL) {
@@ -910,6 +914,7 @@ cnt_streambody(struct sess *sp)
uint8_t obuf[sp->wrk->res_mode & RES_GUNZIP ?
cache_param->gzip_stack_buffer : 1];
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
memset(&sctx, 0, sizeof sctx);
sctx.magic = STREAM_CTX_MAGIC;
AZ(sp->wrk->sctx);
@@ -1020,29 +1025,34 @@ DOT hit -> prepresp [label="deliver",style=bold,color=green]
static int
cnt_hit(struct sess *sp)
{
+ struct worker *wrk;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- CHECK_OBJ_NOTNULL(sp->wrk->obj, OBJECT_MAGIC);
+ wrk = sp->wrk;
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+
+ CHECK_OBJ_NOTNULL(wrk->obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
- assert(!(sp->wrk->obj->objcore->flags & OC_F_PASS));
+ assert(!(wrk->obj->objcore->flags & OC_F_PASS));
- AZ(sp->wrk->do_stream);
+ AZ(wrk->do_stream);
VCL_hit_method(sp);
if (sp->handling == VCL_RET_DELIVER) {
/* Dispose of any body part of the request */
(void)FetchReqBody(sp);
- AZ(sp->wrk->bereq->ws);
- AZ(sp->wrk->beresp->ws);
+ AZ(wrk->bereq->ws);
+ AZ(wrk->beresp->ws);
sp->step = STP_PREPRESP;
return (0);
}
/* Drop our object, we won't need it */
- (void)HSH_Deref(sp->wrk, NULL, &sp->wrk->obj);
- sp->wrk->objcore = NULL;
+ (void)HSH_Deref(wrk, NULL, &wrk->obj);
+ wrk->objcore = NULL;
+ wrk->busyobj = NULL;
switch(sp->handling) {
case VCL_RET_PASS:
@@ -1145,6 +1155,7 @@ cnt_lookup(struct sess *sp)
sp->vary_e = NULL;
sp->wrk->objcore = oc;
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
sp->step = STP_MISS;
return (0);
}
@@ -1205,6 +1216,7 @@ cnt_miss(struct sess *sp)
AZ(sp->wrk->obj);
AN(sp->wrk->objcore);
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
WS_Reset(sp->wrk->ws, NULL);
http_Setup(sp->wrk->bereq, sp->wrk->ws);
http_FilterHeader(sp, HTTPH_R_FETCH);
@@ -1222,7 +1234,10 @@ cnt_miss(struct sess *sp)
sp->wrk->connect_timeout = 0;
sp->wrk->first_byte_timeout = 0;
sp->wrk->between_bytes_timeout = 0;
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
+
VCL_miss_method(sp);
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
switch(sp->handling) {
case VCL_RET_ERROR:
AZ(HSH_Deref(sp->wrk, sp->wrk->objcore, NULL));
@@ -1236,6 +1251,7 @@ cnt_miss(struct sess *sp)
sp->step = STP_PASS;
return (0);
case VCL_RET_FETCH:
+ CHECK_OBJ_NOTNULL(sp->wrk->busyobj, BUSYOBJ_MAGIC);
sp->step = STP_FETCH;
return (0);
case VCL_RET_RESTART:
@@ -1304,6 +1320,7 @@ cnt_pass(struct sess *sp)
sp->wrk->acct_tmp.pass++;
sp->sendbody = 1;
sp->step = STP_FETCH;
+ New_BusyObj(sp->wrk);
return (0);
}
@@ -1411,8 +1428,6 @@ cnt_recv(struct sess *sp)
/* Zap these, in case we came here through restart */
sp->wrk->do_esi = 0;
- sp->wrk->is_gzip = 0;
- sp->wrk->is_gunzip = 0;
sp->wrk->do_gzip = 0;
sp->wrk->do_gunzip = 0;
sp->wrk->do_stream = 0;
@@ -1595,9 +1610,7 @@ CNT_Session(struct sess *sp)
sp->step == STP_RECV);
AZ(w->do_stream);
- AZ(w->is_gzip);
AZ(w->do_gzip);
- AZ(w->is_gunzip);
AZ(w->do_gunzip);
AZ(w->do_esi);
AZ(w->obj);
@@ -1654,9 +1667,7 @@ CNT_Session(struct sess *sp)
AZ(w->obj);
AZ(w->objcore);
AZ(w->do_stream);
- AZ(w->is_gzip);
AZ(w->do_gzip);
- AZ(w->is_gunzip);
AZ(w->do_gunzip);
AZ(w->do_esi);
#define ACCT(foo) AZ(w->acct_tmp.foo);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 5ac8e71..6c8a16f 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -92,8 +92,6 @@ ved_include(struct sess *sp, const char *src, const char *host)
http_Unset(sp->http, H_Content_Length);
sp->wrk->do_esi = 0;
- sp->wrk->is_gzip = 0;
- sp->wrk->is_gunzip = 0;
sp->wrk->do_gzip = 0;
sp->wrk->do_gunzip = 0;
sp->wrk->do_stream = 0;
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 5ec8f6b..35166e7 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -298,19 +298,20 @@ vfp_esi_begin(struct worker *w, size_t estimate)
struct vef_priv *vef;
CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
AZ(w->vgz_rx);
- if (w->is_gzip && w->do_gunzip) {
+ if (w->busyobj->is_gzip && w->do_gunzip) {
w->vgz_rx = VGZ_NewUngzip(w, "U F E");
VEP_Init(w, NULL);
- } else if (w->is_gunzip && w->do_gzip) {
+ } else if (w->busyobj->is_gunzip && w->do_gzip) {
ALLOC_OBJ(vef, VEF_MAGIC);
AN(vef);
vef->vgz = VGZ_NewGzip(w, "G F E");
AZ(w->vef_priv);
w->vef_priv = vef;
VEP_Init(w, vfp_vep_callback);
- } else if (w->is_gzip) {
+ } else if (w->busyobj->is_gzip) {
w->vgz_rx = VGZ_NewUngzip(w, "U F E");
ALLOC_OBJ(vef, VEF_MAGIC);
AN(vef);
@@ -336,11 +337,11 @@ vfp_esi_bytes(struct worker *w, struct http_conn *htc, ssize_t bytes)
AZ(w->fetch_failed);
AN(w->vep);
assert(w->htc == htc);
- if (w->is_gzip && w->do_gunzip)
+ if (w->busyobj->is_gzip && w->do_gunzip)
i = vfp_esi_bytes_gu(w, htc, bytes);
- else if (w->is_gunzip && w->do_gzip)
+ else if (w->busyobj->is_gunzip && w->do_gzip)
i = vfp_esi_bytes_ug(w, htc, bytes);
- else if (w->is_gzip)
+ else if (w->busyobj->is_gzip)
i = vfp_esi_bytes_gg(w, htc, bytes);
else
i = vfp_esi_bytes_uu(w, htc, bytes);
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index a2fc985..1f1795c 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -456,14 +456,14 @@ HSH_Lookup(struct sess *sp, struct objhead **poh)
AN(oc->flags & OC_F_BUSY);
oc->refcnt = 1;
- /* XXX: clear w->nbusyobj before use */
+ New_BusyObj(w);
+
VRY_Validate(sp->vary_b);
if (sp->vary_l != NULL)
- w->nbusyobj->vary = sp->vary_b;
+ w->busyobj->vary = sp->vary_b;
else
- w->nbusyobj->vary = NULL;
- oc->busyobj = w->nbusyobj;
- w->nbusyobj = NULL;
+ w->busyobj->vary = NULL;
+ oc->busyobj = w->busyobj;
/*
* Busy objects go on the tail, so they will not trip up searches.
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index f6f1ff5..641fe99 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -206,6 +206,16 @@ pan_wrk(const struct worker *wrk)
VSB_printf(pan_vsp, " },\n");
}
+static void
+pan_busyobj(const struct busyobj *bo)
+{
+
+ VSB_printf(pan_vsp, " busyobj = %p {\n", bo);
+ if (bo->is_gzip) VSB_printf(pan_vsp, " is_gzip\n");
+ if (bo->is_gunzip) VSB_printf(pan_vsp, " is_gunzip\n");
+ VSB_printf(pan_vsp, " },\n");
+}
+
/*--------------------------------------------------------------------*/
static void
@@ -249,10 +259,9 @@ pan_sess(const struct sess *sp)
if (sp->wrk->do_gunzip) VSB_printf(pan_vsp, " do_gunzip");
if (sp->wrk->do_esi) VSB_printf(pan_vsp, " do_esi");
if (sp->wrk->do_close) VSB_printf(pan_vsp, " do_close");
- if (sp->wrk->is_gzip) VSB_printf(pan_vsp, " is_gzip");
- if (sp->wrk->is_gunzip) VSB_printf(pan_vsp, " is_gunzip");
VSB_printf(pan_vsp, "\n");
VSB_printf(pan_vsp, " bodystatus = %d\n", sp->wrk->body_status);
+ pan_busyobj(sp->wrk->busyobj);
pan_ws(sp->ws, 2);
pan_http("req", sp->http, 2);
More information about the varnish-commit
mailing list