[master] 6289a84 Make vdir->getfd() actually return a fd
Poul-Henning Kamp
phk at FreeBSD.org
Tue Oct 14 08:37:57 CEST 2014
commit 6289a84ddcafcabed21616b2bae9ef6773bdc25f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Oct 14 06:37:41 2014 +0000
Make vdir->getfd() actually return a fd
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 2e233e9..6d99562 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -343,7 +343,7 @@ VBE_DiscardHealth(const struct director *vdi)
*
*/
-static struct vbc * __match_proto__(vdi_getfd_f)
+static int __match_proto__(vdi_getfd_f)
vbe_dir_getfd(const struct director *d, struct busyobj *bo)
{
struct vbe_dir *vs;
@@ -356,7 +356,7 @@ vbe_dir_getfd(const struct director *d, struct busyobj *bo)
vc = vbe_GetVbe(bo, vs);
if (vc == NULL) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection");
- return (NULL);
+ return (-1);
}
if (bo->htc == NULL)
@@ -364,10 +364,9 @@ vbe_dir_getfd(const struct director *d, struct busyobj *bo)
memset(bo->htc, 0, sizeof *bo->htc);
bo->htc->magic = HTTP_CONN_MAGIC;
bo->htc->vbc = vc;
- bo->htc->fd = vc->fd;
FIND_TMO(first_byte_timeout, vc->first_byte_timeout, bo, vs->vrt);
FIND_TMO(between_bytes_timeout, vc->between_bytes_timeout, bo, vs->vrt);
- return (vc);
+ return (vc->fd);
}
static unsigned __match_proto__(vdi_healthy_f)
@@ -388,14 +387,13 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
struct busyobj *bo)
{
int i;
- struct vbc *vbc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
- vbc = vbe_dir_getfd(d, bo);
- if (vbc == NULL) {
+ i = vbe_dir_getfd(d, bo);
+ if (i < 0) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection");
return (-1);
}
@@ -411,8 +409,8 @@ vbe_dir_gethdrs(const struct director *d, struct worker *wrk,
AZ(bo->htc);
VSC_C_main->backend_retry++;
bo->doclose = SC_NULL;
- vbc = vbe_dir_getfd(d, bo);
- if (vbc == NULL) {
+ i = vbe_dir_getfd(d, bo);
+ if (i < 0) {
VSLb(bo->vsl, SLT_FetchError, "no backend connection");
bo->htc = NULL;
return (-1);
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 7a961ad..c79b3a8 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -125,7 +125,7 @@ VDI_Finish(const struct director *d, struct worker *wrk, struct busyobj *bo)
/* Get a connection --------------------------------------------------*/
-struct vbc *
+int
VDI_GetFd(const struct director *d, struct worker *wrk, struct busyobj *bo)
{
@@ -135,7 +135,7 @@ VDI_GetFd(const struct director *d, struct worker *wrk, struct busyobj *bo)
d = vdi_resolve(wrk, bo, d);
if (d == NULL)
- return (NULL);
+ return (-1);
AN(d->getfd);
return (d->getfd(d, bo));
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index f717aa4..cef951d 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -42,7 +42,7 @@
* backends to use.
*/
-typedef struct vbc *vdi_getfd_f(const struct director *, struct busyobj *);
+typedef int vdi_getfd_f(const struct director *, struct busyobj *);
typedef unsigned vdi_healthy_f(const struct director *, double *changed);
typedef const struct director *vdi_resolve_f(const struct director *,
struct worker *, struct busyobj *);
@@ -76,8 +76,7 @@ int VDI_GetBody(const struct director *d, struct worker *wrk,
struct busyobj *bo);
void VDI_Finish(const struct director *d, struct worker *wrk,
struct busyobj *bo);
-struct vbc *VDI_GetFd(const struct director *d, struct worker *wrk,
- struct busyobj *);
+int VDI_GetFd(const struct director *d, struct worker *wrk, struct busyobj *);
int VDI_Healthy(const struct director *);
struct suckaddr *VDI_Suckaddr(const struct director *d, struct worker *wrk,
struct busyobj *bo);
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index 84d91c4..f3fdb6a 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -95,10 +95,9 @@ pipecharge(struct req *req, const struct acct_pipe *a, struct VSC_C_vbe *b)
void
V1P_Process(struct req *req, struct busyobj *bo)
{
- struct vbc *vc;
struct worker *wrk;
struct pollfd fds[2];
- int i;
+ int i, fd;
struct acct_pipe acct_pipe;
ssize_t hdrbytes;
@@ -114,19 +113,18 @@ V1P_Process(struct req *req, struct busyobj *bo)
acct_pipe.req = req->acct.req_hdrbytes;
req->acct.req_hdrbytes = 0;
- vc = VDI_GetFd(bo->director_req, wrk, bo);
- if (vc == NULL) {
+ fd = VDI_GetFd(bo->director_req, wrk, bo);
+ if (fd < 0) {
pipecharge(req, &acct_pipe, NULL);
SES_Close(req->sp, SC_OVERLOAD);
return;
}
CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC);
- assert(bo->htc->fd >= 0);
bo->wrk = req->wrk;
bo->director_state = DIR_S_BODY;
- (void)VTCP_blocking(bo->htc->fd);
+ (void)VTCP_blocking(fd);
- WRW_Reserve(wrk, &bo->htc->fd, bo->vsl, req->t_req);
+ WRW_Reserve(wrk, &fd, bo->vsl, req->t_req);
hdrbytes = HTTP1_Write(wrk, bo->bereq, HTTP1_Req);
if (req->htc->pipeline_b != NULL)
@@ -143,7 +141,7 @@ V1P_Process(struct req *req, struct busyobj *bo)
if (i == 0) {
memset(fds, 0, sizeof fds);
- fds[0].fd = bo->htc->fd;
+ fds[0].fd = fd;
fds[0].events = POLLIN | POLLERR;
fds[1].fd = req->sp->fd;
fds[1].events = POLLIN | POLLERR;
@@ -156,27 +154,27 @@ V1P_Process(struct req *req, struct busyobj *bo)
if (i < 1)
break;
if (fds[0].revents &&
- rdf(bo->htc->fd, req->sp->fd, &acct_pipe.out)) {
+ rdf(fd, req->sp->fd, &acct_pipe.out)) {
if (fds[1].fd == -1)
break;
- (void)shutdown(bo->htc->fd, SHUT_RD);
+ (void)shutdown(fd, SHUT_RD);
(void)shutdown(req->sp->fd, SHUT_WR);
fds[0].events = 0;
fds[0].fd = -1;
}
if (fds[1].revents &&
- rdf(req->sp->fd, bo->htc->fd, &acct_pipe.in)) {
+ rdf(req->sp->fd, fd, &acct_pipe.in)) {
if (fds[0].fd == -1)
break;
(void)shutdown(req->sp->fd, SHUT_RD);
- (void)shutdown(bo->htc->fd, SHUT_WR);
+ (void)shutdown(fd, SHUT_WR);
fds[1].events = 0;
fds[1].fd = -1;
}
}
}
VSLb_ts_req(req, "PipeSess", W_TIM_real(wrk));
- pipecharge(req, &acct_pipe, vc->backend->vsc);
+ pipecharge(req, &acct_pipe, bo->htc->vbc->backend->vsc);
SES_Close(req->sp, SC_TX_PIPE);
bo->doclose = SC_TX_PIPE;
VDI_Finish(bo->director_resp, bo->wrk, bo);
More information about the varnish-commit
mailing list