[master] efd6a98 Consequence change of obj/objcore move from sp to wrk:
Poul-Henning Kamp
phk at varnish-cache.org
Tue Nov 29 13:39:16 CET 2011
commit efd6a9801ac6664d6d166880d73c75356dc47aeb
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Nov 29 12:38:36 2011 +0000
Consequence change of obj/objcore move from sp to wrk:
Take sess out of STV_NewObject
eliminate a lot of sp->wrk with a local wrk variable
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index db001ba..8371278 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -948,8 +948,8 @@ unsigned RFC2616_Req_Gzip(const struct sess *sp);
int RFC2616_Do_Cond(const struct sess *sp);
/* stevedore.c */
-struct object *STV_NewObject(struct sess *sp, const char *hint, unsigned len,
- struct exp *, uint16_t nhttp);
+struct object *STV_NewObject(struct worker *wrk, const char *hint, unsigned len,
+ uint16_t nhttp);
struct storage *STV_alloc(struct worker *w, size_t size);
void STV_trim(struct storage *st, size_t size);
void STV_free(struct storage *st);
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 28c4760..13db2e3 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -442,22 +442,22 @@ cnt_error(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- 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;
-
w = sp->wrk;
- if (sp->wrk->obj == NULL) {
+ w->do_esi = 0;
+ w->is_gzip = 0;
+ w->is_gunzip = 0;
+ w->do_gzip = 0;
+ w->do_gunzip = 0;
+ w->do_stream = 0;
+
+ if (w->obj == NULL) {
HSH_Prealloc(sp);
EXP_Clr(&w->exp);
- sp->wrk->obj = STV_NewObject(sp, NULL, cache_param->http_resp_size,
- &w->exp, (uint16_t)cache_param->http_max_hdr);
+ w->obj = STV_NewObject(w, NULL, cache_param->http_resp_size,
+ (uint16_t)cache_param->http_max_hdr);
if (sp->wrk->obj == NULL)
- sp->wrk->obj = STV_NewObject(sp, TRANSIENT_STORAGE,
- cache_param->http_resp_size, &w->exp,
+ w->obj = STV_NewObject(w, TRANSIENT_STORAGE,
+ cache_param->http_resp_size,
(uint16_t)cache_param->http_max_hdr);
if (sp->wrk->obj == NULL) {
sp->doclose = "Out of objects";
@@ -684,15 +684,18 @@ cnt_fetchbody(struct sess *sp)
unsigned l;
struct vsb *vary = NULL;
int varyl = 0, pass;
+ struct worker *wrk;
+
+ wrk = sp->wrk;
assert(sp->handling == VCL_RET_HIT_FOR_PASS ||
sp->handling == VCL_RET_DELIVER);
- if (sp->wrk->objcore == NULL) {
+ if (wrk->objcore == NULL) {
/* This is a pass from vcl_recv */
pass = 1;
/* VCL may have fiddled this, but that doesn't help */
- sp->wrk->exp.ttl = -1.;
+ wrk->exp.ttl = -1.;
} else if (sp->handling == VCL_RET_HIT_FOR_PASS) {
/* pass from vcl_fetch{} -> hit-for-pass */
/* XXX: the bereq was not filtered pass... */
@@ -715,63 +718,61 @@ cnt_fetchbody(struct sess *sp)
*
*/
- AZ(sp->wrk->vfp);
+ AZ(wrk->vfp);
/* We do nothing unless the param is set */
if (!cache_param->http_gzip_support)
- sp->wrk->do_gzip = sp->wrk->do_gunzip = 0;
+ wrk->do_gzip = wrk->do_gunzip = 0;
- sp->wrk->is_gzip =
- http_HdrIs(sp->wrk->beresp, H_Content_Encoding, "gzip");
+ wrk->is_gzip = http_HdrIs(wrk->beresp, H_Content_Encoding, "gzip");
- sp->wrk->is_gunzip =
- !http_GetHdr(sp->wrk->beresp, H_Content_Encoding, NULL);
+ wrk->is_gunzip = !http_GetHdr(wrk->beresp, H_Content_Encoding, NULL);
/* It can't be both */
- assert(sp->wrk->is_gzip == 0 || sp->wrk->is_gunzip == 0);
+ assert(wrk->is_gzip == 0 || wrk->is_gunzip == 0);
/* We won't gunzip unless it is gzip'ed */
- if (sp->wrk->do_gunzip && !sp->wrk->is_gzip)
- sp->wrk->do_gunzip = 0;
+ if (wrk->do_gunzip && !wrk->is_gzip)
+ wrk->do_gunzip = 0;
/* If we do gunzip, remove the C-E header */
- if (sp->wrk->do_gunzip)
- http_Unset(sp->wrk->beresp, H_Content_Encoding);
+ if (wrk->do_gunzip)
+ http_Unset(wrk->beresp, H_Content_Encoding);
/* We wont gzip unless it is ungziped */
- if (sp->wrk->do_gzip && !sp->wrk->is_gunzip)
- sp->wrk->do_gzip = 0;
+ if (wrk->do_gzip && !wrk->is_gunzip)
+ wrk->do_gzip = 0;
/* If we do gzip, add the C-E header */
- if (sp->wrk->do_gzip)
- http_SetHeader(sp->wrk, sp->vsl_id, sp->wrk->beresp,
+ if (wrk->do_gzip)
+ http_SetHeader(wrk, sp->vsl_id, wrk->beresp,
"Content-Encoding: gzip");
/* But we can't do both at the same time */
- assert(sp->wrk->do_gzip == 0 || sp->wrk->do_gunzip == 0);
+ assert(wrk->do_gzip == 0 || wrk->do_gunzip == 0);
/* ESI takes precedence and handles gzip/gunzip itself */
- if (sp->wrk->do_esi)
- sp->wrk->vfp = &vfp_esi;
- else if (sp->wrk->do_gunzip)
- sp->wrk->vfp = &vfp_gunzip;
- else if (sp->wrk->do_gzip)
- sp->wrk->vfp = &vfp_gzip;
- else if (sp->wrk->is_gzip)
- sp->wrk->vfp = &vfp_testgzip;
-
- if (sp->wrk->do_esi || sp->esi_level > 0)
- sp->wrk->do_stream = 0;
+ if (wrk->do_esi)
+ wrk->vfp = &vfp_esi;
+ else if (wrk->do_gunzip)
+ wrk->vfp = &vfp_gunzip;
+ else if (wrk->do_gzip)
+ wrk->vfp = &vfp_gzip;
+ else if (wrk->is_gzip)
+ wrk->vfp = &vfp_testgzip;
+
+ if (wrk->do_esi || sp->esi_level > 0)
+ wrk->do_stream = 0;
if (!sp->wantbody)
- sp->wrk->do_stream = 0;
+ wrk->do_stream = 0;
- l = http_EstimateWS(sp->wrk->beresp,
+ l = http_EstimateWS(wrk->beresp,
pass ? HTTPH_R_PASS : HTTPH_A_INS, &nhttp);
/* Create Vary instructions */
- if (sp->wrk->objcore != NULL) {
- CHECK_OBJ_NOTNULL(sp->wrk->objcore, OBJCORE_MAGIC);
- vary = VRY_Create(sp, sp->wrk->beresp);
+ if (wrk->objcore != NULL) {
+ CHECK_OBJ_NOTNULL(wrk->objcore, OBJCORE_MAGIC);
+ vary = VRY_Create(sp, wrk->beresp);
if (vary != NULL) {
varyl = VSB_len(vary);
assert(varyl > 0);
@@ -785,110 +786,107 @@ cnt_fetchbody(struct sess *sp)
*/
l += strlen("Content-Length: XxxXxxXxxXxxXxxXxx") + sizeof(void *);
- if (sp->wrk->exp.ttl < cache_param->shortlived || sp->wrk->objcore == NULL)
- sp->wrk->storage_hint = TRANSIENT_STORAGE;
+ if (wrk->exp.ttl < cache_param->shortlived || wrk->objcore == NULL)
+ wrk->storage_hint = TRANSIENT_STORAGE;
- sp->wrk->obj = STV_NewObject(sp, sp->wrk->storage_hint, l,
- &sp->wrk->exp, nhttp);
- if (sp->wrk->obj == NULL) {
+ wrk->obj = STV_NewObject(wrk, wrk->storage_hint, l, nhttp);
+ if (wrk->obj == NULL) {
/*
* Try to salvage the transaction by allocating a
* shortlived object on Transient storage.
*/
- sp->wrk->obj = STV_NewObject(sp, TRANSIENT_STORAGE, l,
- &sp->wrk->exp, nhttp);
- if (sp->wrk->exp.ttl > cache_param->shortlived)
- sp->wrk->exp.ttl = cache_param->shortlived;
- sp->wrk->exp.grace = 0.0;
- sp->wrk->exp.keep = 0.0;
+ wrk->obj = STV_NewObject(wrk, TRANSIENT_STORAGE, l, nhttp);
+ if (wrk->exp.ttl > cache_param->shortlived)
+ wrk->exp.ttl = cache_param->shortlived;
+ wrk->exp.grace = 0.0;
+ wrk->exp.keep = 0.0;
}
- if (sp->wrk->obj == NULL) {
+ if (wrk->obj == NULL) {
sp->err_code = 503;
sp->step = STP_ERROR;
- VDI_CloseFd(sp->wrk);
+ VDI_CloseFd(wrk);
return (0);
}
- CHECK_OBJ_NOTNULL(sp->wrk->obj, OBJECT_MAGIC);
+ CHECK_OBJ_NOTNULL(wrk->obj, OBJECT_MAGIC);
- sp->wrk->storage_hint = NULL;
+ wrk->storage_hint = NULL;
- if (sp->wrk->do_gzip || (sp->wrk->is_gzip && !sp->wrk->do_gunzip))
- sp->wrk->obj->gziped = 1;
+ if (wrk->do_gzip || (wrk->is_gzip && !wrk->do_gunzip))
+ wrk->obj->gziped = 1;
if (vary != NULL) {
- sp->wrk->obj->vary =
- (void *)WS_Alloc(sp->wrk->obj->http->ws, varyl);
- AN(sp->wrk->obj->vary);
- memcpy(sp->wrk->obj->vary, VSB_data(vary), varyl);
- VRY_Validate(sp->wrk->obj->vary);
+ wrk->obj->vary = (void *)WS_Alloc(wrk->obj->http->ws, varyl);
+ AN(wrk->obj->vary);
+ memcpy(wrk->obj->vary, VSB_data(vary), varyl);
+ VRY_Validate(wrk->obj->vary);
VSB_delete(vary);
}
- sp->wrk->obj->xid = sp->xid;
- sp->wrk->obj->response = sp->err_code;
- WS_Assert(sp->wrk->obj->ws_o);
+ wrk->obj->xid = sp->xid;
+ wrk->obj->response = sp->err_code;
+ WS_Assert(wrk->obj->ws_o);
/* Filter into object */
- hp = sp->wrk->beresp;
- hp2 = sp->wrk->obj->http;
+ hp = wrk->beresp;
+ hp2 = wrk->obj->http;
hp2->logtag = HTTP_Obj;
http_CopyResp(hp2, hp);
- http_FilterFields(sp->wrk, sp->vsl_id, hp2, hp,
+ http_FilterFields(wrk, sp->vsl_id, hp2, hp,
pass ? HTTPH_R_PASS : HTTPH_A_INS);
- http_CopyHome(sp->wrk, sp->vsl_id, hp2);
+ http_CopyHome(wrk, sp->vsl_id, hp2);
if (http_GetHdr(hp, H_Last_Modified, &b))
- sp->wrk->obj->last_modified = VTIM_parse(b);
+ wrk->obj->last_modified = VTIM_parse(b);
else
- sp->wrk->obj->last_modified = floor(sp->wrk->exp.entered);
+ wrk->obj->last_modified = floor(wrk->exp.entered);
- assert(WRW_IsReleased(sp->wrk));
+ assert(WRW_IsReleased(wrk));
/*
* If we can deliver a 304 reply, we don't bother streaming.
* Notice that vcl_deliver{} could still nuke the headers
* that allow the 304, in which case we return 200 non-stream.
*/
- if (sp->wrk->obj->response == 200 &&
+ if (wrk->obj->response == 200 &&
sp->http->conds &&
RFC2616_Do_Cond(sp))
- sp->wrk->do_stream = 0;
+ wrk->do_stream = 0;
- AssertObjCorePassOrBusy(sp->wrk->obj->objcore);
+ AssertObjCorePassOrBusy(wrk->obj->objcore);
- if (sp->wrk->do_stream) {
+ if (wrk->do_stream) {
sp->step = STP_PREPRESP;
return (0);
}
/* Use unmodified headers*/
- i = FetchBody(sp->wrk, sp->wrk->obj);
+ i = FetchBody(wrk, wrk->obj);
- sp->wrk->h_content_length = NULL;
+ wrk->h_content_length = NULL;
- http_Setup(sp->wrk->bereq, NULL);
- http_Setup(sp->wrk->beresp, NULL);
- sp->wrk->vfp = NULL;
- assert(WRW_IsReleased(sp->wrk));
- AZ(sp->wrk->vbc);
+ http_Setup(wrk->bereq, NULL);
+ http_Setup(wrk->beresp, NULL);
+ wrk->vfp = NULL;
+ assert(WRW_IsReleased(wrk));
+ AZ(wrk->vbc);
AN(sp->director);
if (i) {
HSH_Drop(sp);
- AZ(sp->wrk->obj);
+ AZ(wrk->obj);
sp->err_code = 503;
sp->step = STP_ERROR;
return (0);
}
- if (sp->wrk->obj->objcore != NULL) {
- EXP_Insert(sp->wrk->obj);
- AN(sp->wrk->obj->objcore);
- AN(sp->wrk->obj->objcore->ban);
+ if (wrk->obj->objcore != NULL) {
+ EXP_Insert(wrk->obj);
+ AN(wrk->obj->objcore);
+ AN(wrk->obj->objcore->ban);
HSH_Unbusy(sp);
}
- sp->wrk->acct_tmp.fetch++;
+ wrk->acct_tmp.fetch++;
sp->step = STP_PREPRESP;
return (0);
}
@@ -970,7 +968,7 @@ DOT shape=box
DOT label="first\nConfigure data structures"
DOT ]
DOT }
-DOT first -> wait
+DOT first -> wait
*/
static int
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 42479c3..1a4b8ac 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -117,7 +117,7 @@ LRU_Free(struct lru *lru)
*/
static struct stevedore *
-stv_pick_stevedore(const struct sess *sp, const char **hint)
+stv_pick_stevedore(struct worker *wrk, const char **hint)
{
struct stevedore *stv;
@@ -131,7 +131,8 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
return (stv_transient);
/* Hint was not valid, nuke it */
- WSP(sp, SLT_Debug, "Storage hint not usable");
+ WSL(wrk, SLT_Debug, wrk->htc->vsl_id,
+ "Storage hint not usable");
*hint = NULL;
}
/* pick a stevedore and bump the head along */
@@ -202,7 +203,6 @@ struct stv_objsecrets {
uint16_t nhttp;
unsigned lhttp;
unsigned wsl;
- struct exp *exp;
};
/*--------------------------------------------------------------------
@@ -214,7 +214,7 @@ struct stv_objsecrets {
*/
struct object *
-STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
+STV_MkObject(struct worker *wrk, void *ptr, unsigned ltot,
const struct stv_objsecrets *soc)
{
struct object *o;
@@ -242,15 +242,15 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
http_Setup(o->http, o->ws_o);
o->http->magic = HTTP_MAGIC;
- o->exp = *soc->exp;
+ o->exp = wrk->exp;
VTAILQ_INIT(&o->store);
- sp->wrk->stats.n_object++;
+ wrk->stats.n_object++;
- if (sp->wrk->objcore != NULL) {
- CHECK_OBJ_NOTNULL(sp->wrk->objcore, OBJCORE_MAGIC);
+ if (wrk->objcore != NULL) {
+ CHECK_OBJ_NOTNULL(wrk->objcore, OBJCORE_MAGIC);
- o->objcore = sp->wrk->objcore;
- sp->wrk->objcore = NULL; /* refcnt follows pointer. */
+ o->objcore = wrk->objcore;
+ wrk->objcore = NULL; /* refcnt follows pointer. */
BAN_NewObjCore(o->objcore);
o->objcore->methods = &default_oc_methods;
@@ -265,7 +265,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
*/
struct object *
-stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
+stv_default_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
const struct stv_objsecrets *soc)
{
struct object *o;
@@ -280,7 +280,7 @@ stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
return (NULL);
}
ltot = st->len = st->space;
- o = STV_MkObject(sp, st->ptr, ltot, soc);
+ o = STV_MkObject(wrk, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
return (o);
@@ -293,8 +293,8 @@ stv_default_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
*/
struct object *
-STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, struct exp *ep,
- uint16_t nhttp)
+STV_NewObject(struct worker *wrk, const char *hint, unsigned wsl,
+ uint16_t nhttp)
{
struct object *o;
struct stevedore *stv, *stv0;
@@ -302,6 +302,7 @@ STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, struct exp *ep,
struct stv_objsecrets soc;
int i;
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
assert(wsl > 0);
wsl = PRNDUP(wsl);
@@ -313,26 +314,25 @@ STV_NewObject(struct sess *sp, const char *hint, unsigned wsl, struct exp *ep,
soc.nhttp = nhttp;
soc.lhttp = lhttp;
soc.wsl = wsl;
- soc.exp = ep;
ltot = sizeof *o + wsl + lhttp;
- stv = stv0 = stv_pick_stevedore(sp, &hint);
+ stv = stv0 = stv_pick_stevedore(wrk, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, sp, ltot, &soc);
+ o = stv->allocobj(stv, wrk, ltot, &soc);
if (o == NULL && hint == NULL) {
do {
- stv = stv_pick_stevedore(sp, &hint);
+ stv = stv_pick_stevedore(wrk, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, sp, ltot, &soc);
+ o = stv->allocobj(stv, wrk, ltot, &soc);
} while (o == NULL && stv != stv0);
}
if (o == NULL) {
/* no luck; try to free some space and keep trying */
for (i = 0; o == NULL && i < cache_param->nuke_limit; i++) {
- if (EXP_NukeOne(sp->wrk, stv->lru) == -1)
+ if (EXP_NukeOne(wrk, stv->lru) == -1)
break;
- o = stv->allocobj(stv, sp, ltot, &soc);
+ o = stv->allocobj(stv, wrk, ltot, &soc);
}
}
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index a813a36..c8c3689 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -34,6 +34,7 @@
struct stv_objsecrets;
struct stevedore;
struct sess;
+struct worker;
struct lru;
typedef void storage_init_f(struct stevedore *, int ac, char * const *av);
@@ -41,8 +42,8 @@ typedef void storage_open_f(const struct stevedore *);
typedef struct storage *storage_alloc_f(struct stevedore *, size_t size);
typedef void storage_trim_f(struct storage *, size_t size);
typedef void storage_free_f(struct storage *);
-typedef struct object *storage_allocobj_f(struct stevedore *, struct sess *sp,
- unsigned ltot, const struct stv_objsecrets *);
+typedef struct object *storage_allocobj_f(struct stevedore *,
+ struct worker *wrk, unsigned ltot, const struct stv_objsecrets *);
typedef void storage_close_f(const struct stevedore *);
/* Prototypes for VCL variable responders */
@@ -89,7 +90,7 @@ extern struct stevedore *stv_transient;
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
const char *ctx);
-struct object *STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
+struct object *STV_MkObject(struct worker *wrk, void *ptr, unsigned ltot,
const struct stv_objsecrets *soc);
struct lru *LRU_Alloc(void);
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 838dc8c..15087b3 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -463,7 +463,7 @@ smp_allocx(struct stevedore *st, size_t min_size, size_t max_size,
*/
static struct object *
-smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
+smp_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
const struct stv_objsecrets *soc)
{
struct object *o;
@@ -474,11 +474,11 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
struct objcore *oc;
unsigned objidx;
- if (sp->wrk->objcore == NULL)
+ if (wrk->objcore == NULL)
return (NULL); /* from cnt_error */
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
- AN(sp->wrk->objcore);
- AN(sp->wrk->exp.ttl > 0.);
+ AN(wrk->objcore);
+ AN(wrk->exp.ttl > 0.);
ltot = IRNUP(sc, ltot);
@@ -489,7 +489,7 @@ smp_allocobj(struct stevedore *stv, struct sess *sp, unsigned ltot,
assert(st->space >= ltot);
ltot = st->len = st->space;
- o = STV_MkObject(sp, st->ptr, ltot, soc);
+ o = STV_MkObject(wrk, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
More information about the varnish-commit
mailing list