Commit 7043f697 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Fully privatize struct vbc.

parent dd01df1a
...@@ -118,7 +118,6 @@ struct transport; ...@@ -118,7 +118,6 @@ struct transport;
struct req; struct req;
struct sess; struct sess;
struct suckaddr; struct suckaddr;
struct vbc;
struct vrt_priv; struct vrt_priv;
struct vsb; struct vsb;
struct waitinglist; struct waitinglist;
...@@ -236,7 +235,7 @@ struct http_conn { ...@@ -236,7 +235,7 @@ struct http_conn {
ssize_t content_length; ssize_t content_length;
enum body_status body_status; enum body_status body_status;
struct vfp_ctx vfc[1]; struct vfp_ctx vfc[1];
struct vbc *vbc; void *priv;
/* Timeouts */ /* Timeouts */
double first_byte_timeout; double first_byte_timeout;
......
...@@ -79,7 +79,7 @@ VBE_Healthy(const struct backend *backend, double *changed) ...@@ -79,7 +79,7 @@ VBE_Healthy(const struct backend *backend, double *changed)
* Get a connection to the backend * Get a connection to the backend
*/ */
static int static struct vbc *
vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
{ {
struct vbc *vc; struct vbc *vc;
...@@ -95,20 +95,20 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) ...@@ -95,20 +95,20 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
if (!VBE_Healthy(bp, NULL)) { if (!VBE_Healthy(bp, NULL)) {
// XXX: per backend stats ? // XXX: per backend stats ?
VSC_C_main->backend_unhealthy++; VSC_C_main->backend_unhealthy++;
return (-1); return (NULL);
} }
if (bp->max_connections > 0 && bp->n_conn >= bp->max_connections) { if (bp->max_connections > 0 && bp->n_conn >= bp->max_connections) {
// XXX: per backend stats ? // XXX: per backend stats ?
VSC_C_main->backend_busy++; VSC_C_main->backend_busy++;
return (-1); return (NULL);
} }
AZ(bo->htc); AZ(bo->htc);
bo->htc = WS_Alloc(bo->ws, sizeof *bo->htc); bo->htc = WS_Alloc(bo->ws, sizeof *bo->htc);
if (bo->htc == NULL) if (bo->htc == NULL)
/* XXX: counter ? */ /* XXX: counter ? */
return (-1); return (NULL);
bo->htc->doclose = SC_NULL; bo->htc->doclose = SC_NULL;
FIND_TMO(connect_timeout, tmod, bo, bp); FIND_TMO(connect_timeout, tmod, bo, bp);
...@@ -117,7 +117,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) ...@@ -117,7 +117,7 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
// XXX: Per backend stats ? // XXX: Per backend stats ?
VSC_C_main->backend_fail++; VSC_C_main->backend_fail++;
bo->htc = NULL; bo->htc = NULL;
return (-1); return (NULL);
} }
assert(vc->fd >= 0); assert(vc->fd >= 0);
...@@ -136,13 +136,13 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo) ...@@ -136,13 +136,13 @@ vbe_dir_getfd(struct worker *wrk, struct backend *bp, struct busyobj *bo)
bp->vsc->req++; bp->vsc->req++;
INIT_OBJ(bo->htc, HTTP_CONN_MAGIC); INIT_OBJ(bo->htc, HTTP_CONN_MAGIC);
bo->htc->vbc = vc; bo->htc->priv = vc;
bo->htc->fd = vc->fd; bo->htc->fd = vc->fd;
FIND_TMO(first_byte_timeout, FIND_TMO(first_byte_timeout,
bo->htc->first_byte_timeout, bo, bp); bo->htc->first_byte_timeout, bo, bp);
FIND_TMO(between_bytes_timeout, FIND_TMO(between_bytes_timeout,
bo->htc->between_bytes_timeout, bo, bp); bo->htc->between_bytes_timeout, bo, bp);
return (vc->fd); return (vc);
} }
static unsigned __match_proto__(vdi_healthy_f) static unsigned __match_proto__(vdi_healthy_f)
...@@ -162,6 +162,7 @@ vbe_dir_finish(const struct director *d, struct worker *wrk, ...@@ -162,6 +162,7 @@ vbe_dir_finish(const struct director *d, struct worker *wrk,
struct busyobj *bo) struct busyobj *bo)
{ {
struct backend *bp; struct backend *bp;
struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
...@@ -169,27 +170,25 @@ vbe_dir_finish(const struct director *d, struct worker *wrk, ...@@ -169,27 +170,25 @@ vbe_dir_finish(const struct director *d, struct worker *wrk,
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC);
CHECK_OBJ_ORNULL(bo->htc->vbc, VBC_MAGIC); CAST_OBJ_NOTNULL(vbc, bo->htc->priv, VBC_MAGIC);
if (bo->htc->vbc == NULL) bo->htc->priv = NULL;
return; if (vbc->state != VBC_STATE_USED)
if (bo->htc->vbc->state != VBC_STATE_USED) VBT_Wait(wrk, vbc);
VBT_Wait(wrk, bo->htc->vbc);
if (bo->htc->doclose != SC_NULL) { if (bo->htc->doclose != SC_NULL) {
VSLb(bo->vsl, SLT_BackendClose, "%d %s", bo->htc->vbc->fd, VSLb(bo->vsl, SLT_BackendClose, "%d %s", vbc->fd,
bp->display_name); bp->display_name);
VBT_Close(bp->tcp_pool, &bo->htc->vbc); VBT_Close(bp->tcp_pool, &vbc);
Lck_Lock(&bp->mtx); Lck_Lock(&bp->mtx);
} else { } else {
VSLb(bo->vsl, SLT_BackendReuse, "%d %s", bo->htc->vbc->fd, VSLb(bo->vsl, SLT_BackendReuse, "%d %s", vbc->fd,
bp->display_name); bp->display_name);
Lck_Lock(&bp->mtx); Lck_Lock(&bp->mtx);
VSC_C_main->backend_recycle++; VSC_C_main->backend_recycle++;
VBT_Recycle(wrk, bp->tcp_pool, &bo->htc->vbc); VBT_Recycle(wrk, bp->tcp_pool, &vbc);
} }
#define ACCT(foo) bp->vsc->foo += bo->acct.foo; #define ACCT(foo) bp->vsc->foo += bo->acct.foo;
#include "tbl/acct_fields_bereq.h" #include "tbl/acct_fields_bereq.h"
#undef ACCT #undef ACCT
bo->htc->vbc = NULL;
Lck_Unlock(&bp->mtx); Lck_Unlock(&bp->mtx);
bo->htc = NULL; bo->htc = NULL;
} }
...@@ -200,6 +199,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk, ...@@ -200,6 +199,7 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
{ {
int i, extrachance = 1; int i, extrachance = 1;
struct backend *bp; struct backend *bp;
struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
...@@ -215,34 +215,34 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk, ...@@ -215,34 +215,34 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
http_PrintfHeader(bo->bereq, "Host: %s", bp->hosthdr); http_PrintfHeader(bo->bereq, "Host: %s", bp->hosthdr);
do { do {
i = vbe_dir_getfd(wrk, bp, bo); vbc = vbe_dir_getfd(wrk, bp, bo);
if (i < 0) { if (vbc == NULL) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection"); VSLb(bo->vsl, SLT_FetchError, "no backend connection");
return (-1); return (-1);
} }
AN(bo->htc); AN(bo->htc);
if (bo->htc->vbc->state != VBC_STATE_STOLEN) if (vbc->state != VBC_STATE_STOLEN)
extrachance = 0; extrachance = 0;
i = V1F_SendReq(wrk, bo, &bo->acct.bereq_hdrbytes, 0); i = V1F_SendReq(wrk, bo, &bo->acct.bereq_hdrbytes, 0);
if (bo->htc->vbc->state != VBC_STATE_USED) if (vbc->state != VBC_STATE_USED)
VBT_Wait(wrk, bo->htc->vbc); VBT_Wait(wrk, vbc);
assert(bo->htc->vbc->state == VBC_STATE_USED); assert(vbc->state == VBC_STATE_USED);
if (!i) if (i == 0)
i = V1F_FetchRespHdr(bo); i = V1F_FetchRespHdr(bo);
if (i == 0) {
AN(bo->htc->priv);
return (0);
}
/* /*
* If we recycled a backend connection, there is a finite chance * If we recycled a backend connection, there is a finite chance
* that the backend closed it before we got the bereq to it. * that the backend closed it before we got the bereq to it.
* In that case do a single automatic retry if req.boy allows. * In that case do a single automatic retry if req.boy allows.
*/ */
if (i == 0) {
AN(bo->htc->vbc);
return (0);
}
vbe_dir_finish(d, wrk, bo); vbe_dir_finish(d, wrk, bo);
AZ(bo->htc); AZ(bo->htc);
if (i < 0) if (i < 0)
...@@ -275,14 +275,15 @@ static const struct suckaddr * __match_proto__(vdi_getip_f) ...@@ -275,14 +275,15 @@ static const struct suckaddr * __match_proto__(vdi_getip_f)
vbe_dir_getip(const struct director *d, struct worker *wrk, vbe_dir_getip(const struct director *d, struct worker *wrk,
struct busyobj *bo) struct busyobj *bo)
{ {
struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC);
CHECK_OBJ_NOTNULL(bo->htc->vbc, VBC_MAGIC); CAST_OBJ_NOTNULL(vbc, bo->htc->priv, VBC_MAGIC);
return (bo->htc->vbc->addr); return (vbc->addr);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -290,9 +291,10 @@ vbe_dir_getip(const struct director *d, struct worker *wrk, ...@@ -290,9 +291,10 @@ vbe_dir_getip(const struct director *d, struct worker *wrk,
static void static void
vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo) vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
{ {
int i, fd; int i;
struct backend *bp; struct backend *bp;
struct v1p_acct v1a; struct v1p_acct v1a;
struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
...@@ -300,23 +302,25 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo) ...@@ -300,23 +302,25 @@ vbe_dir_http1pipe(const struct director *d, struct req *req, struct busyobj *bo)
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC); CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
memset(&v1a, 0, sizeof v1a); memset(&v1a, 0, sizeof v1a);
req->res_mode = RES_PIPE;
fd = vbe_dir_getfd(req->wrk, bp, bo);
/* This is hackish... */ /* This is hackish... */
v1a.req = req->acct.req_hdrbytes; v1a.req = req->acct.req_hdrbytes;
req->acct.req_hdrbytes = 0; req->acct.req_hdrbytes = 0;
if (fd < 0) { req->res_mode = RES_PIPE;
vbc = vbe_dir_getfd(req->wrk, bp, bo);
if (vbc == NULL) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection"); VSLb(bo->vsl, SLT_FetchError, "no backend connection");
SES_Close(req->sp, SC_RX_TIMEOUT); SES_Close(req->sp, SC_RX_TIMEOUT);
} else { } else {
i = V1F_SendReq(req->wrk, bo, &v1a.bereq, 1); i = V1F_SendReq(req->wrk, bo, &v1a.bereq, 1);
VSLb_ts_req(req, "Pipe", W_TIM_real(req->wrk)); VSLb_ts_req(req, "Pipe", W_TIM_real(req->wrk));
if (bo->htc->vbc->state == VBC_STATE_STOLEN) if (vbc->state == VBC_STATE_STOLEN)
VBT_Wait(req->wrk, bo->htc->vbc); VBT_Wait(req->wrk, vbc);
if (i == 0) if (i == 0)
V1P_Process(req, fd, &v1a); V1P_Process(req, vbc->fd, &v1a);
VSLb_ts_req(req, "PipeSess", W_TIM_real(req->wrk)); VSLb_ts_req(req, "PipeSess", W_TIM_real(req->wrk));
SES_Close(req->sp, SC_TX_PIPE); SES_Close(req->sp, SC_TX_PIPE);
bo->htc->doclose = SC_TX_PIPE; bo->htc->doclose = SC_TX_PIPE;
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
*/ */
struct vbp_target; struct vbp_target;
struct vbc;
struct vrt_ctx; struct vrt_ctx;
struct vrt_backend_probe; struct vrt_backend_probe;
struct tcp_pool; struct tcp_pool;
...@@ -82,9 +81,10 @@ struct backend { ...@@ -82,9 +81,10 @@ struct backend {
struct director director[1]; struct director director[1];
}; };
/* -------------------------------------------------------------------*/ /*---------------------------------------------------------------------
* Backend connection -- private to cache_backend*.c
*/
/* Backend connection */
struct vbc { struct vbc {
unsigned magic; unsigned magic;
#define VBC_MAGIC 0x0c5e6592 #define VBC_MAGIC 0x0c5e6592
...@@ -102,6 +102,10 @@ struct vbc { ...@@ -102,6 +102,10 @@ struct vbc {
pthread_cond_t *cond; pthread_cond_t *cond;
}; };
/*---------------------------------------------------------------------
* Prototypes
*/
/* cache_backend.c */ /* cache_backend.c */
void VBE_fill_director(struct backend *be); void VBE_fill_director(struct backend *be);
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
#include "hash/hash_slinger.h" #include "hash/hash_slinger.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
#include "cache_http1.h" #include "cache_http1.h"
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
...@@ -39,8 +39,6 @@ ...@@ -39,8 +39,6 @@
#include "vrt.h" #include "vrt.h"
#include "cache_http1.h" #include "cache_http1.h"
#include "cache/cache_director.h"
#include "cache/cache_backend.h"
static struct lock pipestat_mtx; static struct lock pipestat_mtx;
......
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