[master] 33a2242 Push struct worker out of STV_NewObject()
Poul-Henning Kamp
phk at varnish-cache.org
Sun Feb 19 10:39:54 CET 2012
commit 33a22425a74a3fd670f0f3e4cc20362aaa70541b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Feb 19 09:39:38 2012 +0000
Push struct worker out of STV_NewObject()
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c9cef7b..3797047 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1005,8 +1005,8 @@ unsigned RFC2616_Req_Gzip(const struct sess *sp);
int RFC2616_Do_Cond(const struct sess *sp);
/* stevedore.c */
-struct object *STV_NewObject(struct worker *wrk, const char *hint, unsigned len,
- uint16_t nhttp);
+struct object *STV_NewObject(struct busyobj *, struct objcore **,
+ const char *hint, unsigned len, uint16_t nhttp);
struct storage *STV_alloc(struct busyobj *, 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 bb01b52..338b3ab 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -475,9 +475,12 @@ cnt_error(struct sess *sp, struct worker *wrk, struct req *req)
wrk->busyobj = VBO_GetBusyObj(wrk);
wrk->busyobj->vsl->wid = sp->vsl_id;
- req->obj = STV_NewObject(wrk, TRANSIENT_STORAGE,
- cache_param->http_resp_size,
+ AZ(wrk->busyobj->stats);
+ wrk->busyobj->stats = &wrk->stats;
+ req->obj = STV_NewObject(wrk->busyobj, &req->objcore,
+ TRANSIENT_STORAGE, cache_param->http_resp_size,
(uint16_t)cache_param->http_max_hdr);
+ wrk->busyobj->stats = NULL;
if (req->obj == NULL) {
req->doclose = "Out of objects";
req->director = NULL;
@@ -786,18 +789,24 @@ cnt_prepfetch(struct sess *sp, struct worker *wrk, struct req *req)
req->objcore == NULL)
req->storage_hint = TRANSIENT_STORAGE;
- req->obj = STV_NewObject(wrk, req->storage_hint, l, nhttp);
+ assert(bo == wrk->busyobj);
+ AZ(bo->stats);
+ bo->stats = &wrk->stats;
+ req->obj = STV_NewObject(bo, &req->objcore, req->storage_hint, l,
+ nhttp);
if (req->obj == NULL) {
/*
* Try to salvage the transaction by allocating a
* shortlived object on Transient storage.
*/
- req->obj = STV_NewObject(wrk, TRANSIENT_STORAGE, l, nhttp);
+ req->obj = STV_NewObject(bo, &req->objcore, TRANSIENT_STORAGE,
+ l, nhttp);
if (bo->exp.ttl > cache_param->shortlived)
bo->exp.ttl = cache_param->shortlived;
bo->exp.grace = 0.0;
bo->exp.keep = 0.0;
}
+ bo->stats = NULL;
if (req->obj == NULL) {
req->err_code = 503;
sp->step = STP_ERROR;
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 3a9f614..3c62d8d 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -227,13 +227,15 @@ struct stv_objsecrets {
*/
struct object *
-STV_MkObject(struct worker *wrk, void *ptr, unsigned ltot,
+STV_MkObject(struct busyobj *bo, struct objcore **ocp, void *ptr, unsigned ltot,
const struct stv_objsecrets *soc)
{
struct object *o;
unsigned l;
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(soc, STV_OBJ_SECRETES_MAGIC);
+ AN(ocp);
assert(PAOK(ptr));
assert(PAOK(soc->wsl));
@@ -253,17 +255,17 @@ STV_MkObject(struct worker *wrk, void *ptr, unsigned ltot,
WS_Assert(o->ws_o);
assert(o->ws_o->e <= (char*)ptr + ltot);
- http_Setup(o->http, o->ws_o, wrk->busyobj->vsl);
+ http_Setup(o->http, o->ws_o, bo->vsl);
o->http->magic = HTTP_MAGIC;
- o->exp = wrk->busyobj->exp;
+ o->exp = bo->exp;
VTAILQ_INIT(&o->store);
- wrk->stats.n_object++;
+ bo->stats->n_object++;
- if (wrk->sp->req->objcore != NULL) {
- CHECK_OBJ_NOTNULL(wrk->sp->req->objcore, OBJCORE_MAGIC);
+ if (*ocp != NULL) {
+ CHECK_OBJ_NOTNULL((*ocp), OBJCORE_MAGIC);
- o->objcore = wrk->sp->req->objcore;
- wrk->sp->req->objcore = NULL; /* refcnt follows pointer. */
+ o->objcore = *ocp;
+ *ocp = NULL; /* refcnt follows pointer. */
BAN_NewObjCore(o->objcore);
o->objcore->methods = &default_oc_methods;
@@ -278,13 +280,15 @@ STV_MkObject(struct worker *wrk, void *ptr, unsigned ltot,
*/
struct object *
-stv_default_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
- const struct stv_objsecrets *soc)
+stv_default_allocobj(struct stevedore *stv, struct busyobj *bo,
+ struct objcore **ocp, unsigned ltot, const struct stv_objsecrets *soc)
{
struct object *o;
struct storage *st;
CHECK_OBJ_NOTNULL(soc, STV_OBJ_SECRETES_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ AN(ocp);
st = stv->alloc(stv, ltot);
if (st == NULL)
return (NULL);
@@ -293,7 +297,7 @@ stv_default_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
return (NULL);
}
ltot = st->len = st->space;
- o = STV_MkObject(wrk, st->ptr, ltot, soc);
+ o = STV_MkObject(bo, ocp, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
return (o);
@@ -306,8 +310,8 @@ stv_default_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
*/
struct object *
-STV_NewObject(struct worker *wrk, const char *hint, unsigned wsl,
- uint16_t nhttp)
+STV_NewObject(struct busyobj *bo, struct objcore **ocp, const char *hint,
+ unsigned wsl, uint16_t nhttp)
{
struct object *o;
struct stevedore *stv, *stv0;
@@ -315,7 +319,8 @@ STV_NewObject(struct worker *wrk, const char *hint, unsigned wsl,
struct stv_objsecrets soc;
int i;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+ AN(ocp);
assert(wsl > 0);
wsl = PRNDUP(wsl);
@@ -330,27 +335,23 @@ STV_NewObject(struct worker *wrk, const char *hint, unsigned wsl,
ltot = sizeof *o + wsl + lhttp;
- stv = stv0 = stv_pick_stevedore(wrk->vsl, &hint);
+ stv = stv0 = stv_pick_stevedore(bo->vsl, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, wrk, ltot, &soc);
+ o = stv->allocobj(stv, bo, ocp, ltot, &soc);
if (o == NULL && hint == NULL) {
do {
- stv = stv_pick_stevedore(wrk->vsl, &hint);
+ stv = stv_pick_stevedore(bo->vsl, &hint);
AN(stv->allocobj);
- o = stv->allocobj(stv, wrk, ltot, &soc);
+ o = stv->allocobj(stv, bo, ocp, ltot, &soc);
} while (o == NULL && stv != stv0);
}
if (o == NULL) {
- /* XXX: lend busyobj wrk's stats while we nuke */
- AZ(wrk->busyobj->stats);
- wrk->busyobj->stats = &wrk->stats;
/* no luck; try to free some space and keep trying */
for (i = 0; o == NULL && i < cache_param->nuke_limit; i++) {
- if (EXP_NukeOne(wrk->busyobj, stv->lru) == -1)
+ if (EXP_NukeOne(bo, stv->lru) == -1)
break;
- o = stv->allocobj(stv, wrk, ltot, &soc);
+ o = stv->allocobj(stv, bo, ocp, ltot, &soc);
}
- wrk->busyobj->stats = NULL;
}
if (o == NULL)
diff --git a/bin/varnishd/storage/storage.h b/bin/varnishd/storage/storage.h
index c8c3689..80839a6 100644
--- a/bin/varnishd/storage/storage.h
+++ b/bin/varnishd/storage/storage.h
@@ -34,6 +34,8 @@
struct stv_objsecrets;
struct stevedore;
struct sess;
+struct busyobj;
+struct objcore;
struct worker;
struct lru;
@@ -42,8 +44,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 worker *wrk, unsigned ltot, const struct stv_objsecrets *);
+typedef struct object *storage_allocobj_f(struct stevedore *, struct busyobj *,
+ struct objcore **, unsigned ltot, const struct stv_objsecrets *);
typedef void storage_close_f(const struct stevedore *);
/* Prototypes for VCL variable responders */
@@ -90,8 +92,8 @@ 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 worker *wrk, void *ptr, unsigned ltot,
- const struct stv_objsecrets *soc);
+struct object *STV_MkObject(struct busyobj *bo, struct objcore **ocp,
+ void *ptr, unsigned ltot, const struct stv_objsecrets *soc);
struct lru *LRU_Alloc(void);
void LRU_Free(struct lru *lru);
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index ff01838..c49ceac 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -460,8 +460,8 @@ smp_allocx(struct stevedore *st, size_t min_size, size_t max_size,
*/
static struct object *
-smp_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
- const struct stv_objsecrets *soc)
+smp_allocobj(struct stevedore *stv, struct busyobj *bo, struct objcore **ocp,
+ unsigned ltot, const struct stv_objsecrets *soc)
{
struct object *o;
struct storage *st;
@@ -471,11 +471,11 @@ smp_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
struct objcore *oc;
unsigned objidx;
- if (wrk->sp->req->objcore == NULL)
+ AN(ocp);
+ if (*ocp == NULL)
return (NULL); /* from cnt_error */
CAST_OBJ_NOTNULL(sc, stv->priv, SMP_SC_MAGIC);
- AN(wrk->sp->req->objcore);
- AN(wrk->busyobj->exp.ttl > 0.);
+ AN(bo->exp.ttl > 0.);
ltot = IRNUP(sc, ltot);
@@ -486,7 +486,7 @@ smp_allocobj(struct stevedore *stv, struct worker *wrk, unsigned ltot,
assert(st->space >= ltot);
ltot = st->len = st->space;
- o = STV_MkObject(wrk, st->ptr, ltot, soc);
+ o = STV_MkObject(bo, ocp, st->ptr, ltot, soc);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
o->objstore = st;
More information about the varnish-commit
mailing list