Commit 71fe2939 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Push struct session entirely out of FetchBody().

This should make it possible to get a different worker thread to pull
the body in from the backend, without cloning the session structure,
with all the trouble that would cause.
parent 3e4b8291
...@@ -704,7 +704,7 @@ int EXP_NukeOne(struct worker *w, struct lru *lru); ...@@ -704,7 +704,7 @@ int EXP_NukeOne(struct worker *w, struct lru *lru);
/* cache_fetch.c */ /* cache_fetch.c */
struct storage *FetchStorage(struct worker *w, ssize_t sz); struct storage *FetchStorage(struct worker *w, ssize_t sz);
int FetchHdr(struct sess *sp); int FetchHdr(struct sess *sp);
int FetchBody(const struct sess *sp, struct object *obj); int FetchBody(struct worker *w, struct object *obj);
int FetchReqBody(struct sess *sp); int FetchReqBody(struct sess *sp);
void Fetch_Init(void); void Fetch_Init(void);
......
...@@ -846,7 +846,7 @@ cnt_fetchbody(struct sess *sp) ...@@ -846,7 +846,7 @@ cnt_fetchbody(struct sess *sp)
} }
/* Use unmodified headers*/ /* Use unmodified headers*/
i = FetchBody(sp, sp->obj); i = FetchBody(sp->wrk, sp->obj);
sp->wrk->h_content_length = NULL; sp->wrk->h_content_length = NULL;
...@@ -910,7 +910,7 @@ cnt_streambody(struct sess *sp) ...@@ -910,7 +910,7 @@ cnt_streambody(struct sess *sp)
AssertObjCorePassOrBusy(sp->obj->objcore); AssertObjCorePassOrBusy(sp->obj->objcore);
i = FetchBody(sp, sp->obj); i = FetchBody(sp->wrk, sp->obj);
sp->wrk->h_content_length = NULL; sp->wrk->h_content_length = NULL;
......
...@@ -198,24 +198,24 @@ fetch_number(const char *nbr, int radix) ...@@ -198,24 +198,24 @@ fetch_number(const char *nbr, int radix)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int static int
fetch_straight(const struct sess *sp, struct http_conn *htc, const char *b) fetch_straight(struct worker *w, struct http_conn *htc, const char *b)
{ {
int i; int i;
ssize_t cl; ssize_t cl;
assert(sp->wrk->body_status == BS_LENGTH); assert(w->body_status == BS_LENGTH);
cl = fetch_number(b, 10); cl = fetch_number(b, 10);
sp->wrk->vfp->begin(sp->wrk, cl > 0 ? cl : 0); w->vfp->begin(w, cl > 0 ? cl : 0);
if (cl < 0) { if (cl < 0) {
WSP(sp, SLT_FetchError, "straight length field bogus"); WSLB(w, SLT_FetchError, "straight length field bogus");
return (-1); return (-1);
} else if (cl == 0) } else if (cl == 0)
return (0); return (0);
i = sp->wrk->vfp->bytes(sp->wrk, htc, cl); i = w->vfp->bytes(w, htc, cl);
if (i <= 0) { if (i <= 0) {
WSP(sp, SLT_FetchError, "straight read_error: %d %d (%s)", WSLB(w, SLT_FetchError, "straight read_error: %d %d (%s)",
i, errno, htc->error); i, errno, htc->error);
return (-1); return (-1);
} }
...@@ -227,7 +227,7 @@ fetch_straight(const struct sess *sp, struct http_conn *htc, const char *b) ...@@ -227,7 +227,7 @@ fetch_straight(const struct sess *sp, struct http_conn *htc, const char *b)
#define CERR() do { \ #define CERR() do { \
if (i != 1) { \ if (i != 1) { \
WSP(sp, SLT_FetchError, \ WSLB(w, SLT_FetchError, \
"chunked read_error: %d (%s)", \ "chunked read_error: %d (%s)", \
errno, htc->error); \ errno, htc->error); \
return (-1); \ return (-1); \
...@@ -235,15 +235,15 @@ fetch_straight(const struct sess *sp, struct http_conn *htc, const char *b) ...@@ -235,15 +235,15 @@ fetch_straight(const struct sess *sp, struct http_conn *htc, const char *b)
} while (0) } while (0)
static int static int
fetch_chunked(const struct sess *sp, struct http_conn *htc) fetch_chunked(struct worker *w, struct http_conn *htc)
{ {
int i; int i;
char buf[20]; /* XXX: 20 is arbitrary */ char buf[20]; /* XXX: 20 is arbitrary */
unsigned u; unsigned u;
ssize_t cl; ssize_t cl;
sp->wrk->vfp->begin(sp->wrk, 0); w->vfp->begin(w, 0);
assert(sp->wrk->body_status == BS_CHUNKED); assert(w->body_status == BS_CHUNKED);
do { do {
/* Skip leading whitespace */ /* Skip leading whitespace */
do { do {
...@@ -262,7 +262,7 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc) ...@@ -262,7 +262,7 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc)
} }
if (u >= sizeof buf) { if (u >= sizeof buf) {
WSP(sp, SLT_FetchError, "chunked header too long"); WSLB(w, SLT_FetchError, "chunked header too long");
return (-1); return (-1);
} }
...@@ -273,17 +273,17 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc) ...@@ -273,17 +273,17 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc)
} }
if (buf[u] != '\n') { if (buf[u] != '\n') {
WSP(sp, SLT_FetchError, "chunked header char syntax"); WSLB(w, SLT_FetchError, "chunked header char syntax");
return (-1); return (-1);
} }
buf[u] = '\0'; buf[u] = '\0';
cl = fetch_number(buf, 16); cl = fetch_number(buf, 16);
if (cl < 0) { if (cl < 0) {
WSP(sp, SLT_FetchError, "chunked header nbr syntax"); WSLB(w, SLT_FetchError, "chunked header nbr syntax");
return (-1); return (-1);
} else if (cl > 0) { } else if (cl > 0) {
i = sp->wrk->vfp->bytes(sp->wrk, htc, cl); i = w->vfp->bytes(w, htc, cl);
CERR(); CERR();
} }
i = HTC_Read(htc, buf, 1); i = HTC_Read(htc, buf, 1);
...@@ -293,7 +293,7 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc) ...@@ -293,7 +293,7 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc)
CERR(); CERR();
} }
if (buf[0] != '\n') { if (buf[0] != '\n') {
WSP(sp, SLT_FetchError, "chunked tail syntax"); WSLB(w, SLT_FetchError, "chunked tail syntax");
return (-1); return (-1);
} }
} while (cl > 0); } while (cl > 0);
...@@ -305,15 +305,15 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc) ...@@ -305,15 +305,15 @@ fetch_chunked(const struct sess *sp, struct http_conn *htc)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int static int
fetch_eof(const struct sess *sp, struct http_conn *htc) fetch_eof(struct worker *w, struct http_conn *htc)
{ {
int i; int i;
assert(sp->wrk->body_status == BS_EOF); assert(w->body_status == BS_EOF);
sp->wrk->vfp->begin(sp->wrk, 0); w->vfp->begin(w, 0);
i = sp->wrk->vfp->bytes(sp->wrk, htc, SSIZE_MAX); i = w->vfp->bytes(w, htc, SSIZE_MAX);
if (i < 0) { if (i < 0) {
WSP(sp, SLT_FetchError, "eof read_error: %d (%s)", WSLB(w, SLT_FetchError, "eof read_error: %d (%s)",
errno, htc->error); errno, htc->error);
return (-1); return (-1);
} }
...@@ -480,24 +480,21 @@ FetchHdr(struct sess *sp) ...@@ -480,24 +480,21 @@ FetchHdr(struct sess *sp)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
int int
FetchBody(const struct sess *sp, struct object *obj) FetchBody(struct worker *w, struct object *obj)
{ {
int cls; int cls;
struct storage *st; struct storage *st;
struct worker *w;
int mklen; int mklen;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC);
w = sp->wrk;
AZ(w->fetch_obj); AZ(w->fetch_obj);
CHECK_OBJ_NOTNULL(w->vbc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(obj, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(obj->http, HTTP_MAGIC); CHECK_OBJ_NOTNULL(obj->http, HTTP_MAGIC);
if (w->vfp == NULL) if (w->vfp == NULL)
w->vfp = &vfp_nop; w->vfp = &vfp_nop;
AN(sp->director);
AssertObjCorePassOrBusy(obj->objcore); AssertObjCorePassOrBusy(obj->objcore);
AZ(w->vgz_rx); AZ(w->vgz_rx);
...@@ -515,20 +512,20 @@ FetchBody(const struct sess *sp, struct object *obj) ...@@ -515,20 +512,20 @@ FetchBody(const struct sess *sp, struct object *obj)
mklen = 1; mklen = 1;
break; break;
case BS_LENGTH: case BS_LENGTH:
cls = fetch_straight(sp, w->htc, cls = fetch_straight(w, w->htc,
w->h_content_length); w->h_content_length);
mklen = 1; mklen = 1;
XXXAZ(w->vfp->end(sp->wrk)); XXXAZ(w->vfp->end(w));
break; break;
case BS_CHUNKED: case BS_CHUNKED:
cls = fetch_chunked(sp, w->htc); cls = fetch_chunked(w, w->htc);
mklen = 1; mklen = 1;
XXXAZ(w->vfp->end(sp->wrk)); XXXAZ(w->vfp->end(w));
break; break;
case BS_EOF: case BS_EOF:
cls = fetch_eof(sp, w->htc); cls = fetch_eof(w, w->htc);
mklen = 1; mklen = 1;
XXXAZ(w->vfp->end(sp->wrk)); XXXAZ(w->vfp->end(w));
break; break;
case BS_ERROR: case BS_ERROR:
cls = 1; cls = 1;
...@@ -546,11 +543,11 @@ FetchBody(const struct sess *sp, struct object *obj) ...@@ -546,11 +543,11 @@ FetchBody(const struct sess *sp, struct object *obj)
* sitting on w->storage, we will always call vfp_nop_end() * sitting on w->storage, we will always call vfp_nop_end()
* to get it trimmed or thrown out if empty. * to get it trimmed or thrown out if empty.
*/ */
AZ(vfp_nop_end(sp->wrk)); AZ(vfp_nop_end(w));
w->fetch_obj = NULL; w->fetch_obj = NULL;
WSL(w, SLT_Fetch_Body, w->vbc->vsl_id, "%u(%s) cls %d mklen %u", WSLB(w, SLT_Fetch_Body, "%u(%s) cls %d mklen %u",
w->body_status, body_status(w->body_status), w->body_status, body_status(w->body_status),
cls, mklen); cls, mklen);
...@@ -575,7 +572,7 @@ FetchBody(const struct sess *sp, struct object *obj) ...@@ -575,7 +572,7 @@ FetchBody(const struct sess *sp, struct object *obj)
if (cls == 0 && w->do_close) if (cls == 0 && w->do_close)
cls = 1; cls = 1;
WSL(w, SLT_Length, w->vbc->vsl_id, "%u", obj->len); WSLB(w, SLT_Length, "%u", obj->len);
{ {
/* Sanity check fetch methods accounting */ /* Sanity check fetch methods accounting */
...@@ -584,7 +581,7 @@ FetchBody(const struct sess *sp, struct object *obj) ...@@ -584,7 +581,7 @@ FetchBody(const struct sess *sp, struct object *obj)
uu = 0; uu = 0;
VTAILQ_FOREACH(st, &obj->store, list) VTAILQ_FOREACH(st, &obj->store, list)
uu += st->len; uu += st->len;
if (sp->objcore == NULL || (sp->objcore->flags & OC_F_PASS)) if (w->do_stream)
/* Streaming might have started freeing stuff */ /* Streaming might have started freeing stuff */
assert (uu <= obj->len); assert (uu <= obj->len);
else else
...@@ -593,7 +590,7 @@ FetchBody(const struct sess *sp, struct object *obj) ...@@ -593,7 +590,7 @@ FetchBody(const struct sess *sp, struct object *obj)
if (mklen > 0) { if (mklen > 0) {
http_Unset(obj->http, H_Content_Length); http_Unset(obj->http, H_Content_Length);
http_PrintfHeader(w, sp->vsl_id, obj->http, http_PrintfHeader(w, w->vbc->vsl_id, obj->http,
"Content-Length: %jd", (intmax_t)obj->len); "Content-Length: %jd", (intmax_t)obj->len);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment