[master] 92d43d1 Add FetchStorage() which will feed storage segments into objects via sp->wrk->storage.
Poul-Henning Kamp
phk at project.varnish-software.com
Sat Jan 22 08:09:49 CET 2011
commit 92d43d17feadf595077c78d4b20623758e12b7af
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sat Jan 22 07:09:03 2011 +0000
Add FetchStorage() which will feed storage segments into objects
via sp->wrk->storage.
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 9cacf45..c5359e0 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -619,6 +619,7 @@ void EXP_Touch(struct object *o, double tnow);
int EXP_NukeOne(const struct sess *sp, const struct lru *lru);
/* cache_fetch.c */
+int FetchStorage(const struct sess *sp);
int FetchHdr(struct sess *sp);
int FetchBody(struct sess *sp);
int FetchReqBody(struct sess *sp);
diff --git a/bin/varnishd/cache_esi_fetch.c b/bin/varnishd/cache_esi_fetch.c
index 116b96e..ef99413 100644
--- a/bin/varnishd/cache_esi_fetch.c
+++ b/bin/varnishd/cache_esi_fetch.c
@@ -55,14 +55,8 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
while (bytes > 0) {
- if (sp->wrk->storage == NULL) {
- l = params->fetch_chunksize * 1024LL;
- sp->wrk->storage = STV_alloc(sp, l);
- }
- if (sp->wrk->storage == NULL) {
- errno = ENOMEM;
+ if (FetchStorage(sp))
return (-1);
- }
st = sp->wrk->storage;
l = st->space - st->len;
if (l > bytes)
@@ -83,12 +77,6 @@ vfp_esi_bytes_uu(struct sess *sp, struct http_conn *htc, size_t bytes)
VEP_parse(sp, (const char *)st->ptr + st->len, w);
st->len += w;
sp->obj->len += w;
- if (st->len == st->space) {
- VTAILQ_INSERT_TAIL(&sp->obj->store,
- sp->wrk->storage, list);
- sp->wrk->storage = NULL;
- st = NULL;
- }
bytes -= w;
}
return (1);
@@ -205,14 +193,6 @@ vfp_esi_bytes_ug(struct sess *sp, struct http_conn *htc, size_t bytes)
CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
while (bytes > 0) {
- if (sp->wrk->storage == NULL) {
- l = params->fetch_chunksize * 1024LL;
- sp->wrk->storage = STV_alloc(sp, l);
- }
- if (sp->wrk->storage == NULL) {
- errno = ENOMEM;
- return (-1);
- }
l = sizeof ibuf;
if (l > bytes)
l = bytes;
diff --git a/bin/varnishd/cache_fetch.c b/bin/varnishd/cache_fetch.c
index 1e8c337..b7f798f 100644
--- a/bin/varnishd/cache_fetch.c
+++ b/bin/varnishd/cache_fetch.c
@@ -91,16 +91,8 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
struct storage *st;
while (bytes > 0) {
- if (sp->wrk->storage == NULL) {
- l = fetchfrag;
- if (l == 0)
- l = params->fetch_chunksize * 1024LL;
- sp->wrk->storage = STV_alloc(sp, l);
- }
- if (sp->wrk->storage == NULL) {
- errno = ENOMEM;
+ if (FetchStorage(sp))
return (-1);
- }
st = sp->wrk->storage;
l = st->space - st->len;
if (l > bytes)
@@ -110,12 +102,6 @@ vfp_nop_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
return (w);
st->len += w;
sp->obj->len += w;
- if (st->len == st->space) {
- VTAILQ_INSERT_TAIL(&sp->obj->store,
- sp->wrk->storage, list);
- sp->wrk->storage = NULL;
- st = NULL;
- }
bytes -= w;
}
return (1);
@@ -157,6 +143,33 @@ static struct vfp vfp_nop = {
};
/*--------------------------------------------------------------------
+ * Fetch Storage
+ */
+
+int
+FetchStorage(const struct sess *sp)
+{
+ ssize_t l;
+
+ if (sp->wrk->storage != NULL &&
+ sp->wrk->storage->len == sp->wrk->storage->space) {
+ VTAILQ_INSERT_TAIL(&sp->obj->store, sp->wrk->storage, list);
+ sp->wrk->storage = NULL;
+ }
+ if (sp->wrk->storage == NULL) {
+ l = fetchfrag;
+ if (l == 0)
+ l = params->fetch_chunksize * 1024LL;
+ sp->wrk->storage = STV_alloc(sp, l);
+ }
+ if (sp->wrk->storage == NULL) {
+ errno = ENOMEM;
+ return (-1);
+ }
+ return (0);
+}
+
+/*--------------------------------------------------------------------
* Convert a string to a size_t safely
*/
diff --git a/bin/varnishd/cache_gzip.c b/bin/varnishd/cache_gzip.c
index 08df961..f77157c 100644
--- a/bin/varnishd/cache_gzip.c
+++ b/bin/varnishd/cache_gzip.c
@@ -231,21 +231,10 @@ VGZ_ObufStorage(const struct sess *sp, struct vgz *vg)
{
struct storage *st;
+ if (FetchStorage(sp))
+ return (-1);
+
st = sp->wrk->storage;
- if (st != NULL && st->len == st->space) {
- VTAILQ_INSERT_TAIL(&sp->obj->store, st, list);
- sp->wrk->storage = NULL;
- st = NULL;
- vg->obuf = NULL;
- }
- if (st == NULL) {
- st = STV_alloc(sp, params->fetch_chunksize * 1024LL);
- if (st == NULL) {
- errno = ENOMEM;
- return (-1);
- }
- sp->wrk->storage = st;
- }
vg->obuf = st;
VGZ_Obuf(vg, st->ptr + st->len, st->space - st->len);
More information about the varnish-commit
mailing list