[master] 1be5d26 Rename "pipe" to "http1 pipe", (VTLA: V1P)
Poul-Henning Kamp
phk at FreeBSD.org
Wed Oct 1 21:05:14 CEST 2014
commit 1be5d26d9e22f8631aff89a087906c6176cef033
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Oct 1 18:21:24 2014 +0000
Rename "pipe" to "http1 pipe", (VTLA: V1P)
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 64fd313..ab7705d 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -28,6 +28,7 @@ varnishd_SOURCES = \
cache/cache_http.c \
cache/cache_http1_fetch.c \
cache/cache_http1_fsm.c \
+ cache/cache_http1_pipe.c \
cache/cache_http1_proto.c \
cache/cache_http1_vfp.c \
cache/cache_lck.c \
@@ -35,7 +36,6 @@ varnishd_SOURCES = \
cache/cache_mempool.c \
cache/cache_obj.c \
cache/cache_panic.c \
- cache/cache_pipe.c \
cache/cache_pool.c \
cache/cache_req_body.c \
cache/cache_req_fsm.c \
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 4c9568f..99cb5ca 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -746,6 +746,10 @@ unsigned V1D_FlushReleaseAcct(struct req *req);
void V1D_Deliver(struct req *, struct busyobj *);
void V1D_Deliver_Synth(struct req *req);
+/* cache_http1_pipe.c */
+void V1P_Init(void);
+void V1P_Process(struct req *req, struct busyobj *bo);
+
/* cache_req_body.c */
int VRB_Ignore(struct req *req);
int VRB_Cache(struct req *req, ssize_t maxsize);
@@ -1010,10 +1014,6 @@ void PAN_Init(void);
const char *body_status_2str(enum body_status e);
const char *sess_close_2str(enum sess_close sc, int want_desc);
-/* cache_pipe.c */
-void Pipe_Init(void);
-void PipeRequest(struct req *req, struct busyobj *bo);
-
/* cache_pool.c */
void Pool_Init(void);
void Pool_Accept(void);
diff --git a/bin/varnishd/cache/cache_http1_pipe.c b/bin/varnishd/cache/cache_http1_pipe.c
new file mode 100644
index 0000000..6a67566
--- /dev/null
+++ b/bin/varnishd/cache/cache_http1_pipe.c
@@ -0,0 +1,197 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at 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.
+ *
+ * XXX: charge bytes to srcaddr
+ */
+
+#include "config.h"
+
+#include <poll.h>
+#include <stdio.h>
+
+#include "cache.h"
+
+#include "cache_backend.h"
+#include "cache_director.h"
+#include "vtcp.h"
+#include "vtim.h"
+
+static struct lock pipestat_mtx;
+
+struct acct_pipe {
+ uint64_t req;
+ uint64_t bereq;
+ uint64_t in;
+ uint64_t out;
+};
+
+static int
+rdf(int fd0, int fd1, uint64_t *pcnt)
+{
+ int i, j;
+ char buf[BUFSIZ], *p;
+
+ i = read(fd0, buf, sizeof buf);
+ if (i <= 0)
+ return (1);
+ for (p = buf; i > 0; i -= j, p += j) {
+ j = write(fd1, p, i);
+ if (j <= 0)
+ return (1);
+ *pcnt += j;
+ if (i != j)
+ (void)usleep(100000); /* XXX hack */
+ }
+ return (0);
+}
+
+static void
+pipecharge(struct req *req, const struct acct_pipe *a, struct VSC_C_vbe *b)
+{
+
+ VSLb(req->vsl, SLT_PipeAcct, "%ju %ju %ju %ju",
+ (uintmax_t)a->req,
+ (uintmax_t)a->bereq,
+ (uintmax_t)a->in,
+ (uintmax_t)a->out);
+
+ Lck_Lock(&pipestat_mtx);
+ VSC_C_main->s_pipe_hdrbytes += a->req;
+ VSC_C_main->s_pipe_in += a->in;
+ VSC_C_main->s_pipe_out += a->out;
+ if (b != NULL) {
+ b->pipe_hdrbytes += a->bereq;
+ b->pipe_out += a->in;
+ b->pipe_in += a->out;
+ }
+ Lck_Unlock(&pipestat_mtx);
+}
+
+void
+V1P_Process(struct req *req, struct busyobj *bo)
+{
+ struct vbc *vc;
+ struct worker *wrk;
+ struct pollfd fds[2];
+ int i;
+ struct acct_pipe acct_pipe;
+ ssize_t hdrbytes;
+
+ CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+ CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
+ wrk = req->wrk;
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+ req->res_mode = RES_PIPE;
+
+ memset(&acct_pipe, 0, sizeof acct_pipe);
+ acct_pipe.req = req->acct.req_hdrbytes;
+ req->acct.req_hdrbytes = 0;
+
+ vc = VDI_GetFd(bo->director_req, wrk, bo);
+ if (vc == NULL) {
+ pipecharge(req, &acct_pipe, NULL);
+ SES_Close(req->sp, SC_OVERLOAD);
+ return;
+ }
+ bo->vbc = vc; /* For panic dumping */
+ (void)VTCP_blocking(vc->fd);
+
+ WRW_Reserve(wrk, &vc->fd, bo->vsl, req->t_req);
+ hdrbytes = HTTP1_Write(wrk, bo->bereq, HTTP1_Req);
+
+ if (req->htc->pipeline_b != NULL)
+ (void)WRW_Write(wrk, req->htc->pipeline_b,
+ req->htc->pipeline_e - req->htc->pipeline_b);
+
+ i = WRW_FlushRelease(wrk, &acct_pipe.bereq);
+ if (acct_pipe.bereq > hdrbytes) {
+ acct_pipe.in = acct_pipe.bereq - hdrbytes;
+ acct_pipe.bereq = hdrbytes;
+ }
+
+ VSLb_ts_req(req, "Pipe", W_TIM_real(wrk));
+
+ if (i) {
+ pipecharge(req, &acct_pipe, vc->backend->vsc);
+ SES_Close(req->sp, SC_TX_PIPE);
+ VBE_CloseFd(&vc, NULL);
+ return;
+ }
+
+ memset(fds, 0, sizeof fds);
+
+ // XXX: not yet (void)VTCP_linger(vc->fd, 0);
+ fds[0].fd = vc->fd;
+ fds[0].events = POLLIN | POLLERR;
+
+ // XXX: not yet (void)VTCP_linger(req->sp->fd, 0);
+ fds[1].fd = req->sp->fd;
+ fds[1].events = POLLIN | POLLERR;
+
+ while (fds[0].fd > -1 || fds[1].fd > -1) {
+ fds[0].revents = 0;
+ fds[1].revents = 0;
+ i = poll(fds, 2, (int)(cache_param->pipe_timeout * 1e3));
+ if (i < 1)
+ break;
+ if (fds[0].revents &&
+ rdf(vc->fd, req->sp->fd, &acct_pipe.out)) {
+ if (fds[1].fd == -1)
+ break;
+ (void)shutdown(vc->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, vc->fd, &acct_pipe.in)) {
+ if (fds[0].fd == -1)
+ break;
+ (void)shutdown(req->sp->fd, SHUT_RD);
+ (void)shutdown(vc->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);
+ SES_Close(req->sp, SC_TX_PIPE);
+ VBE_CloseFd(&vc, NULL);
+ bo->vbc = NULL;
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+V1P_Init(void)
+{
+
+ Lck_New(&pipestat_mtx, lck_pipestat);
+}
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index d949059..1406e57 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -225,7 +225,7 @@ child_main(void)
VBE_InitCfg();
VBP_Init();
Pool_Init();
- Pipe_Init();
+ V1P_Init();
EXP_Init();
HSH_Init(heritage.hash);
diff --git a/bin/varnishd/cache/cache_pipe.c b/bin/varnishd/cache/cache_pipe.c
deleted file mode 100644
index a27e3de..0000000
--- a/bin/varnishd/cache/cache_pipe.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at 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.
- *
- * XXX: charge bytes to srcaddr
- */
-
-#include "config.h"
-
-#include <poll.h>
-#include <stdio.h>
-
-#include "cache.h"
-
-#include "cache_backend.h"
-#include "cache_director.h"
-#include "vtcp.h"
-#include "vtim.h"
-
-static struct lock pipestat_mtx;
-
-struct acct_pipe {
- uint64_t req;
- uint64_t bereq;
- uint64_t in;
- uint64_t out;
-};
-
-static int
-rdf(int fd0, int fd1, uint64_t *pcnt)
-{
- int i, j;
- char buf[BUFSIZ], *p;
-
- i = read(fd0, buf, sizeof buf);
- if (i <= 0)
- return (1);
- for (p = buf; i > 0; i -= j, p += j) {
- j = write(fd1, p, i);
- if (j <= 0)
- return (1);
- *pcnt += j;
- if (i != j)
- (void)usleep(100000); /* XXX hack */
- }
- return (0);
-}
-
-static void
-pipecharge(struct req *req, const struct acct_pipe *a, struct VSC_C_vbe *b)
-{
-
- VSLb(req->vsl, SLT_PipeAcct, "%ju %ju %ju %ju",
- (uintmax_t)a->req,
- (uintmax_t)a->bereq,
- (uintmax_t)a->in,
- (uintmax_t)a->out);
-
- Lck_Lock(&pipestat_mtx);
- VSC_C_main->s_pipe_hdrbytes += a->req;
- VSC_C_main->s_pipe_in += a->in;
- VSC_C_main->s_pipe_out += a->out;
- if (b != NULL) {
- b->pipe_hdrbytes += a->bereq;
- b->pipe_out += a->in;
- b->pipe_in += a->out;
- }
- Lck_Unlock(&pipestat_mtx);
-}
-
-void
-PipeRequest(struct req *req, struct busyobj *bo)
-{
- struct vbc *vc;
- struct worker *wrk;
- struct pollfd fds[2];
- int i;
- struct acct_pipe acct_pipe;
- ssize_t hdrbytes;
-
- CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
- CHECK_OBJ_NOTNULL(req->sp, SESS_MAGIC);
- wrk = req->wrk;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
-
- req->res_mode = RES_PIPE;
-
- memset(&acct_pipe, 0, sizeof acct_pipe);
- acct_pipe.req = req->acct.req_hdrbytes;
- req->acct.req_hdrbytes = 0;
-
- vc = VDI_GetFd(bo->director_req, wrk, bo);
- if (vc == NULL) {
- pipecharge(req, &acct_pipe, NULL);
- SES_Close(req->sp, SC_OVERLOAD);
- return;
- }
- bo->vbc = vc; /* For panic dumping */
- (void)VTCP_blocking(vc->fd);
-
- WRW_Reserve(wrk, &vc->fd, bo->vsl, req->t_req);
- hdrbytes = HTTP1_Write(wrk, bo->bereq, HTTP1_Req);
-
- if (req->htc->pipeline_b != NULL)
- (void)WRW_Write(wrk, req->htc->pipeline_b,
- req->htc->pipeline_e - req->htc->pipeline_b);
-
- i = WRW_FlushRelease(wrk, &acct_pipe.bereq);
- if (acct_pipe.bereq > hdrbytes) {
- acct_pipe.in = acct_pipe.bereq - hdrbytes;
- acct_pipe.bereq = hdrbytes;
- }
-
- VSLb_ts_req(req, "Pipe", W_TIM_real(wrk));
-
- if (i) {
- pipecharge(req, &acct_pipe, vc->backend->vsc);
- SES_Close(req->sp, SC_TX_PIPE);
- VBE_CloseFd(&vc, NULL);
- return;
- }
-
- memset(fds, 0, sizeof fds);
-
- // XXX: not yet (void)VTCP_linger(vc->fd, 0);
- fds[0].fd = vc->fd;
- fds[0].events = POLLIN | POLLERR;
-
- // XXX: not yet (void)VTCP_linger(req->sp->fd, 0);
- fds[1].fd = req->sp->fd;
- fds[1].events = POLLIN | POLLERR;
-
- while (fds[0].fd > -1 || fds[1].fd > -1) {
- fds[0].revents = 0;
- fds[1].revents = 0;
- i = poll(fds, 2, (int)(cache_param->pipe_timeout * 1e3));
- if (i < 1)
- break;
- if (fds[0].revents &&
- rdf(vc->fd, req->sp->fd, &acct_pipe.out)) {
- if (fds[1].fd == -1)
- break;
- (void)shutdown(vc->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, vc->fd, &acct_pipe.in)) {
- if (fds[0].fd == -1)
- break;
- (void)shutdown(req->sp->fd, SHUT_RD);
- (void)shutdown(vc->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);
- SES_Close(req->sp, SC_TX_PIPE);
- VBE_CloseFd(&vc, NULL);
- bo->vbc = NULL;
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-Pipe_Init(void)
-{
-
- Lck_New(&pipestat_mtx, lck_pipestat);
-}
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index c9bdb35..4649231 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -499,7 +499,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
INCOMPL();
assert(wrk->handling == VCL_RET_PIPE);
- PipeRequest(req, bo);
+ V1P_Process(req, bo);
assert(WRW_IsReleased(wrk));
http_Teardown(bo->bereq);
THR_SetBusyobj(NULL);
More information about the varnish-commit
mailing list