Commit 01b46ff8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move req allocation/deallocation to its own source file

parent b38d28f3
......@@ -34,6 +34,7 @@ varnishd_SOURCES = \
cache/cache_obj.c \
cache/cache_panic.c \
cache/cache_pool.c \
cache/cache_req.c \
cache/cache_req_body.c \
cache/cache_req_fsm.c \
cache/cache_rfc2616.c \
......
......@@ -118,7 +118,6 @@ struct pool;
struct poolparam;
struct req;
struct sess;
struct sesspool;
struct suckaddr;
struct vbc;
struct vrt_backend;
......@@ -638,6 +637,15 @@ struct req {
* works, is not realistic without a lot of code changes.
*/
struct sesspool {
unsigned magic;
#define SESSPOOL_MAGIC 0xd916e202
struct pool *pool;
struct mempool *mpl_req;
struct mempool *mpl_sess;
struct waiter *http1_waiter;
};
enum sess_attr {
#define SESS_ATTR(UP, low, typ, len) SA_##UP,
......@@ -975,6 +983,10 @@ task_func_t VPX_Proto_Sess;
/* cache_range.c [VRG] */
void VRG_dorange(struct req *req, struct busyobj *bo, const char *r);
/* cache_req.c */
struct req *Req_New(const struct worker *, struct sess *);
void Req_Release(struct req *);
/* cache_session.c [SES] */
struct sess *SES_New(struct sesspool *);
void SES_Close(struct sess *sp, enum sess_close reason);
......@@ -983,8 +995,6 @@ void SES_Delete(struct sess *sp, enum sess_close reason, double now);
struct sesspool *SES_NewPool(struct pool *pp, unsigned pool_no);
void SES_DeletePool(struct sesspool *sp);
int SES_Reschedule_Req(struct req *);
struct req *SES_GetReq(const struct worker *, struct sess *);
void SES_ReleaseReq(struct req *);
task_func_t SES_Proto_Sess;
task_func_t SES_Proto_Req;
......
......@@ -75,7 +75,7 @@ ved_include(struct req *preq, const char *src, const char *host)
if (preq->esi_level >= cache_param->max_esi_depth)
return;
req = SES_GetReq(wrk, preq->sp);
req = Req_New(wrk, preq->sp);
req->req_body_status = REQ_BODY_NONE;
AZ(req->vsl->wid);
req->vsl->wid = VXID_Get(wrk, VSL_CLIENTMARKER);
......@@ -166,7 +166,7 @@ ved_include(struct req *preq, const char *src, const char *host)
req->wrk = NULL;
THR_SetRequest(preq);
SES_ReleaseReq(req);
Req_Release(req);
}
/*--------------------------------------------------------------------*/
......
......@@ -547,7 +547,7 @@ hsh_rush(struct worker *wrk, struct objhead *oh)
sp = req->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
CNT_AcctLogCharge(wrk->stats, req);
SES_ReleaseReq(req);
Req_Release(req);
SES_Delete(sp, SC_OVERLOAD, NAN);
req = VTAILQ_FIRST(&wl->list);
if (req == NULL)
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2011 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Request management
*
*/
#include "config.h"
#include <errno.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include "cache.h"
/*--------------------------------------------------------------------
* Alloc/Free a request
*/
struct req *
Req_New(const struct worker *wrk, struct sess *sp)
{
struct sesspool *pp;
struct req *req;
uint16_t nhttp;
unsigned sz, hl;
char *p, *e;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->sesspool;
CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
AN(pp->pool);
req = MPL_Get(pp->mpl_req, &sz);
AN(req);
req->magic = REQ_MAGIC;
req->sp = sp;
req->top = req; // esi overrides
e = (char*)req + sz;
p = (char*)(req + 1);
p = (void*)PRNDUP(p);
assert(p < e);
nhttp = (uint16_t)cache_param->http_max_hdr;
hl = HTTP_estimate(nhttp);
req->http = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
req->http0 = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
req->resp = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
sz = cache_param->vsl_buffer;
VSL_Setup(req->vsl, p, sz);
p += sz;
p = (void*)PRNDUP(p);
assert(p < e);
WS_Init(req->ws, "req", p, e - p);
req->req_bodybytes = 0;
req->t_first = NAN;
req->t_prev = NAN;
req->t_req = NAN;
req->vdp_nxt = 0;
VTAILQ_INIT(&req->vdp);
return (req);
}
void
Req_Release(struct req *req)
{
struct sess *sp;
struct sesspool *pp;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
/* Make sure the request counters have all been zeroed */
#define ACCT(foo) \
AZ(req->acct.foo);
#include "tbl/acct_fields_req.h"
#undef ACCT
AZ(req->vcl);
if (req->vsl->wid)
VSL_End(req->vsl);
sp = req->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->sesspool;
CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
AN(pp->pool);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
MPL_AssertSane(req);
VSL_Flush(req->vsl, 0);
req->sp = NULL;
MPL_Free(pp->mpl_req, req);
}
......@@ -54,18 +54,6 @@
/*--------------------------------------------------------------------*/
struct sesspool {
unsigned magic;
#define SESSPOOL_MAGIC 0xd916e202
struct pool *pool;
struct mempool *mpl_req;
struct mempool *mpl_sess;
struct waiter *http1_waiter;
};
/*--------------------------------------------------------------------*/
static int
ses_get_attr(const struct sess *sp, enum sess_attr a, void **dst)
{
......@@ -381,7 +369,7 @@ SES_Proto_Sess(struct worker *wrk, void *arg)
* involve a request...
*/
(void)VTCP_blocking(sp->fd);
req = SES_GetReq(wrk, sp);
req = Req_New(wrk, sp);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
req->htc->fd = sp->fd;
SES_RxInit(req->htc, req->ws,
......@@ -570,104 +558,6 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now)
MPL_Free(pp->mpl_sess, sp);
}
/*--------------------------------------------------------------------
* Alloc/Free a request
*/
struct req *
SES_GetReq(const struct worker *wrk, struct sess *sp)
{
struct sesspool *pp;
struct req *req;
uint16_t nhttp;
unsigned sz, hl;
char *p, *e;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->sesspool;
CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
AN(pp->pool);
req = MPL_Get(pp->mpl_req, &sz);
AN(req);
req->magic = REQ_MAGIC;
req->sp = sp;
req->top = req; // esi overrides
e = (char*)req + sz;
p = (char*)(req + 1);
p = (void*)PRNDUP(p);
assert(p < e);
nhttp = (uint16_t)cache_param->http_max_hdr;
hl = HTTP_estimate(nhttp);
req->http = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
req->http0 = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
req->resp = HTTP_create(p, nhttp);
p += hl;
p = (void*)PRNDUP(p);
assert(p < e);
sz = cache_param->vsl_buffer;
VSL_Setup(req->vsl, p, sz);
p += sz;
p = (void*)PRNDUP(p);
assert(p < e);
WS_Init(req->ws, "req", p, e - p);
req->req_bodybytes = 0;
req->t_first = NAN;
req->t_prev = NAN;
req->t_req = NAN;
req->vdp_nxt = 0;
VTAILQ_INIT(&req->vdp);
return (req);
}
void
SES_ReleaseReq(struct req *req)
{
struct sess *sp;
struct sesspool *pp;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
/* Make sure the request counters have all been zeroed */
#define ACCT(foo) \
AZ(req->acct.foo);
#include "tbl/acct_fields_req.h"
#undef ACCT
AZ(req->vcl);
if (req->vsl->wid)
VSL_End(req->vsl);
sp = req->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->sesspool;
CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC);
AN(pp->pool);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
MPL_AssertSane(req);
VSL_Flush(req->vsl, 0);
req->sp = NULL;
MPL_Free(pp->mpl_req, req);
}
/*--------------------------------------------------------------------
* Create and delete pools
*/
......
......@@ -101,7 +101,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req)
if (sp->fd < 0) {
wrk->stats->sess_closed++;
AZ(req->vcl);
SES_ReleaseReq(req);
Req_Release(req);
SES_Delete(sp, SC_NULL, NAN);
return (1);
}
......@@ -267,7 +267,7 @@ HTTP1_Session(struct worker *wrk, struct req *req)
req->acct.req_hdrbytes +=
req->htc->rxbuf_e - req->htc->rxbuf_b;
CNT_AcctLogCharge(wrk->stats, req);
SES_ReleaseReq(req);
Req_Release(req);
switch(hs) {
case HTC_S_CLOSE:
SES_Delete(sp, SC_REM_CLOSE, 0.0);
......@@ -287,7 +287,7 @@ HTTP1_Session(struct worker *wrk, struct req *req)
}
if (hs == HTC_S_IDLE) {
wrk->stats->sess_herd++;
SES_ReleaseReq(req);
Req_Release(req);
SES_Wait(sp);
return;
}
......
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