Commit c7611af5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the last bits of file descriptor awareness out of the "abstract"

director layer.
parent e3862554
......@@ -355,6 +355,60 @@ VBE_DiscardHealth(const struct director *vdi)
VBP_Remove(vs->backend, vs->vrt->probe);
}
/* Close a connection ------------------------------------------------*/
void
VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
{
struct backend *bp;
struct vbc *vc;
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
VSLb(vc->vsl, SLT_BackendClose, "%d %s", vc->fd, bp->display_name);
vc->vsl = NULL;
VTCP_close(&vc->fd);
VBE_DropRefConn(bp, acct_bereq);
vc->backend = NULL;
VBE_ReleaseConn(vc);
}
/* Recycle a connection ----------------------------------------------*/
static void
vbe_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
{
struct backend *bp;
struct vbc *vc;
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
VSLb(vc->vsl, SLT_BackendReuse, "%d %s", vc->fd, bp->display_name);
vc->vsl = NULL;
Lck_Lock(&bp->mtx);
VSC_C_main->backend_recycle++;
VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
VBE_DropRefLocked(bp, acct_bereq);
}
/*--------------------------------------------------------------------
*
*/
......@@ -453,9 +507,9 @@ vdi_simple_finish(const struct director *d, struct worker *wrk,
if (bo->vbc != NULL) {
if (bo->doclose != SC_NULL)
VDI_CloseFd(&bo->vbc, &bo->acct);
VBE_CloseFd(&bo->vbc, &bo->acct);
else
VDI_RecycleFd(&bo->vbc, &bo->acct);
vbe_RecycleFd(&bo->vbc, &bo->acct);
}
}
......
......@@ -142,6 +142,7 @@ struct vbc {
void VBE_ReleaseConn(struct vbc *vc);
void VBE_UseHealth(const struct director *vdi);
void VBE_DiscardHealth(const struct director *vdi);
void VBE_CloseFd(struct vbc **vbp, const struct acct_bereq *);
/* cache_backend_cfg.c */
void VBE_DropRefConn(struct backend *, const struct acct_bereq *);
......@@ -167,8 +168,6 @@ void VDI_Finish(const struct director *d, struct worker *wrk,
struct vbc *VDI_GetFd(const struct director *d, struct worker *wrk,
struct busyobj *);
int VDI_Healthy(const struct director *);
void VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *);
void VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *);
void VDI_AddHostHeader(struct http *to, const struct vbc *vbc);
void VBE_Poll(void);
void VDI_Init(void);
......
......@@ -26,7 +26,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Abstract backend API
* Abstract director API
*
* The abstract director API does not know how we talk to the backend or
* if there even is one in the usual meaning of the word.
*
*/
......@@ -35,60 +38,6 @@
#include "cache.h"
#include "cache_backend.h"
#include "vtcp.h"
/* Close a connection ------------------------------------------------*/
void
VDI_CloseFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
{
struct backend *bp;
struct vbc *vc;
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
VSLb(vc->vsl, SLT_BackendClose, "%d %s", vc->fd, bp->display_name);
vc->vsl = NULL;
VTCP_close(&vc->fd);
VBE_DropRefConn(bp, acct_bereq);
vc->backend = NULL;
VBE_ReleaseConn(vc);
}
/* Recycle a connection ----------------------------------------------*/
void
VDI_RecycleFd(struct vbc **vbp, const struct acct_bereq *acct_bereq)
{
struct backend *bp;
struct vbc *vc;
AN(vbp);
vc = *vbp;
*vbp = NULL;
CHECK_OBJ_NOTNULL(vc, VBC_MAGIC);
CHECK_OBJ_NOTNULL(vc->backend, BACKEND_MAGIC);
assert(vc->fd >= 0);
bp = vc->backend;
VSLb(vc->vsl, SLT_BackendReuse, "%d %s", vc->fd, bp->display_name);
vc->vsl = NULL;
Lck_Lock(&bp->mtx);
VSC_C_main->backend_recycle++;
VTAILQ_INSERT_HEAD(&bp->connlist, vc, list);
VBE_DropRefLocked(bp, acct_bereq);
}
/* Resolve director --------------------------------------------------*/
......
......@@ -143,7 +143,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)",
errno, strerror(errno));
VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk));
VDI_CloseFd(&bo->vbc, &bo->acct);
VBE_CloseFd(&bo->vbc, &bo->acct);
/* XXX: other cleanup ? */
return (retry);
}
......@@ -169,7 +169,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
VSLb(bo->vsl, SLT_FetchError,
"http %sread error: overflow",
first ? "first " : "");
VDI_CloseFd(&bo->vbc, &bo->acct);
VBE_CloseFd(&bo->vbc, &bo->acct);
/* XXX: other cleanup ? */
return (-1);
}
......@@ -177,7 +177,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
bo->acct.beresp_hdrbytes += Tlen(htc->rxbuf);
VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF",
first ? "first " : "");
VDI_CloseFd(&bo->vbc, &bo->acct);
VBE_CloseFd(&bo->vbc, &bo->acct);
/* XXX: other cleanup ? */
return (retry);
}
......@@ -194,7 +194,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo)
if (HTTP1_DissectResponse(hp, htc)) {
VSLb(bo->vsl, SLT_FetchError, "http format error");
VDI_CloseFd(&bo->vbc, &bo->acct);
VBE_CloseFd(&bo->vbc, &bo->acct);
/* XXX: other cleanup ? */
return (-1);
}
......
......@@ -141,7 +141,7 @@ PipeRequest(struct req *req, struct busyobj *bo)
if (i) {
pipecharge(req, &acct_pipe, vc->backend->vsc);
SES_Close(req->sp, SC_TX_PIPE);
VDI_CloseFd(&vc, NULL);
VBE_CloseFd(&vc, NULL);
return;
}
......@@ -183,7 +183,7 @@ PipeRequest(struct req *req, struct busyobj *bo)
VSLb_ts_req(req, "PipeSess", W_TIM_real(wrk));
pipecharge(req, &acct_pipe, vc->backend->vsc);
SES_Close(req->sp, SC_TX_PIPE);
VDI_CloseFd(&vc, NULL);
VBE_CloseFd(&vc, NULL);
bo->vbc = NULL;
}
......
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