[master] 78f18e8 Give the worker a "fetch_obj" to avoid passing it around as a separate parameter all the time.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Oct 24 14:55:56 CEST 2011
commit 78f18e855bf04ddc1cef31405bdc6f8e3e58b6cc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Oct 24 12:54:55 2011 +0000
Give the worker a "fetch_obj" to avoid passing it around as a separate
parameter all the time.
Also decontaminate FetchStorage to not need session
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index a8dff7b..46d4067 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -339,6 +339,7 @@ struct worker {
/* Fetch stuff */
struct vbc *vbc;
+ struct object *fetch_obj;
enum body_status body_status;
struct vfp *vfp;
struct vgz *vgz_rx;
@@ -700,7 +701,7 @@ int EXP_Touch(struct objcore *oc);
int EXP_NukeOne(struct worker *w, struct lru *lru);
/* cache_fetch.c */
-struct storage *FetchStorage(const struct sess *sp, ssize_t sz);
+struct storage *FetchStorage(struct worker *w, ssize_t sz);
int FetchHdr(struct sess *sp);
int FetchBody(struct sess *sp, struct object *obj);
int FetchReqBody(struct sess *sp);
@@ -950,8 +951,7 @@ 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 storage *STV_alloc(struct worker *w, const struct object *obj,
- size_t size);
+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);
void STV_open(void);
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index 5d8f8dc..00c7432 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -71,7 +71,7 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, ssize_t bytes)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
while (bytes > 0) {
- st = FetchStorage(sp, 0);
+ st = FetchStorage(sp->wrk, 0);
if (st == NULL)
return (-1);
w = vef_read(htc,
@@ -368,7 +368,7 @@ vfp_esi_end(struct sess *sp)
l = VSB_len(vsb);
assert(l > 0);
/* XXX: This is a huge waste of storage... */
- sp->obj->esidata = STV_alloc(sp->wrk, sp->obj, l);
+ sp->obj->esidata = STV_alloc(sp->wrk, l);
XXXAN(sp->obj->esidata);
memcpy(sp->obj->esidata->ptr, VSB_data(vsb), l);
sp->obj->esidata->len = l;
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index ccc2ec3..d71b2ec 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -66,7 +66,7 @@ vfp_nop_begin(struct sess *sp, size_t estimate)
WSP(sp, SLT_Debug, "Fetch %d byte segments:", fetchfrag);
}
if (estimate > 0)
- (void)FetchStorage(sp, estimate);
+ (void)FetchStorage(sp->wrk, estimate);
}
/*--------------------------------------------------------------------
@@ -86,7 +86,7 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
struct storage *st;
while (bytes > 0) {
- st = FetchStorage(sp, 0);
+ st = FetchStorage(sp->wrk, 0);
if (st == NULL) {
htc->error = "Could not get storage";
return (-1);
@@ -145,12 +145,15 @@ static struct vfp vfp_nop = {
*/
struct storage *
-FetchStorage(const struct sess *sp, ssize_t sz)
+FetchStorage(struct worker *w, ssize_t sz)
{
ssize_t l;
struct storage *st;
+ struct object *obj;
- st = VTAILQ_LAST(&sp->obj->store, storagehead);
+ obj = w->fetch_obj;
+ CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
+ st = VTAILQ_LAST(&obj->store, storagehead);
if (st != NULL && st->len < st->space)
return (st);
@@ -159,13 +162,13 @@ FetchStorage(const struct sess *sp, ssize_t sz)
l = sz;
if (l == 0)
l = params->fetch_chunksize * 1024LL;
- st = STV_alloc(sp->wrk, sp->obj, l);
+ st = STV_alloc(w, l);
if (st == NULL) {
errno = ENOMEM;
return (NULL);
}
AZ(st->len);
- VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
+ VTAILQ_INSERT_TAIL(&obj->store, st, list);
return (st);
}
@@ -487,6 +490,7 @@ FetchBody(struct sess *sp, struct object *obj)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
w = sp->wrk;
+ AZ(w->fetch_obj);
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(obj->http, HTTP_MAGIC);
@@ -498,6 +502,9 @@ FetchBody(struct sess *sp, struct object *obj)
AZ(w->vgz_rx);
AZ(VTAILQ_FIRST(&obj->store));
+
+ w->fetch_obj = obj;
+
switch (w->body_status) {
case BS_NONE:
cls = 0;
@@ -541,6 +548,8 @@ FetchBody(struct sess *sp, struct object *obj)
*/
AZ(vfp_nop_end(sp));
+ w->fetch_obj = NULL;
+
WSL(w, SLT_Fetch_Body, w->vbc->vsl_id, "%u(%s) cls %d mklen %u",
w->body_status, body_status(w->body_status),
cls, mklen);
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 787ff16..e40676c 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -259,7 +259,7 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg)
{
struct storage *st;
- st = FetchStorage(sp, 0);
+ st = FetchStorage(sp->wrk, 0);
if (st == NULL)
return (-1);
@@ -615,7 +615,7 @@ vfp_testgzip_bytes(struct sess *sp, struct http_conn *htc, ssize_t bytes)
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
AZ(vg->vz.avail_in);
while (bytes > 0) {
- st = FetchStorage(sp, 0);
+ st = FetchStorage(sp->wrk, 0);
if (st == NULL) {
htc->error = "Could not get storage";
return (-1);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index 93e2bf8..4048836 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -371,10 +371,10 @@ STV_Freestore(struct object *o)
/*-------------------------------------------------------------------*/
struct storage *
-STV_alloc(struct worker *w, const struct object *obj, size_t size)
+STV_alloc(struct worker *w, size_t size)
{
- return (stv_alloc(w, obj, size));
+ return (stv_alloc(w, w->fetch_obj, size));
}
void
More information about the varnish-commit
mailing list