[master] 8c872002c cache_http1_line: Refactor V1L_Open() to return struct v1l *
Nils Goroll
nils.goroll at uplex.de
Mon Nov 25 14:43:03 UTC 2024
commit 8c872002c75c9dd38c5f114720dd5f893449a03c
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Oct 31 10:00:03 2024 +0100
cache_http1_line: Refactor V1L_Open() to return struct v1l *
diff --git a/bin/varnishd/http1/cache_http1.h b/bin/varnishd/http1/cache_http1.h
index f758a74c9..8c161d5f5 100644
--- a/bin/varnishd/http1/cache_http1.h
+++ b/bin/varnishd/http1/cache_http1.h
@@ -61,7 +61,7 @@ void V1P_Charge(struct req *, const struct v1p_acct *, struct VSC_vbe *);
/* cache_http1_line.c */
void V1L_Chunked(const struct worker *w);
void V1L_EndChunk(const struct worker *w);
-void V1L_Open(struct worker *, struct ws *, int *fd, struct vsl_log *,
+struct v1l * V1L_Open(struct ws *, int *fd, struct vsl_log *,
vtim_real deadline, unsigned niov);
stream_close_t V1L_Flush(const struct worker *w);
stream_close_t V1L_Close(struct worker *w, uint64_t *cnt);
diff --git a/bin/varnishd/http1/cache_http1_deliver.c b/bin/varnishd/http1/cache_http1_deliver.c
index 15bc706b9..6bce2558c 100644
--- a/bin/varnishd/http1/cache_http1_deliver.c
+++ b/bin/varnishd/http1/cache_http1_deliver.c
@@ -46,8 +46,10 @@ v1d_error(struct req *req, struct boc *boc, const char *msg)
"HTTP/1.1 500 Internal Server Error\r\n"
"Server: Varnish\r\n"
"Connection: close\r\n\r\n";
+ uint64_t bytes;
- AZ(req->wrk->v1l);
+ if (req->wrk->v1l != NULL)
+ (void) V1L_Close(req->wrk, &bytes);
VSLbs(req->vsl, SLT_Error, TOSTRAND(msg));
VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
@@ -71,6 +73,7 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
int err = 0, chunked = 0;
stream_close_t sc;
uint64_t hdrbytes, bytes;
+ struct v1l *v1l;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_ORNULL(boc, BOC_MAGIC);
@@ -87,6 +90,20 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
} else if (!http_GetHdr(req->resp, H_Connection, NULL))
http_SetHeader(req->resp, "Connection: keep-alive");
+ CHECK_OBJ_NOTNULL(req->wrk, WORKER_MAGIC);
+
+ v1l = V1L_Open(req->wrk->aws, &req->sp->fd, req->vsl,
+ req->t_prev + SESS_TMO(req->sp, send_timeout),
+ cache_param->http1_iovs);
+
+ if (v1l == NULL) {
+ v1d_error(req, boc, "Failure to init v1d (workspace_thread overflow)");
+ return;
+ }
+
+ AZ(req->wrk->v1l);
+ req->wrk->v1l = v1l;
+
if (sendbody) {
if (!http_GetHdr(req->resp, H_Content_Length, NULL)) {
if (req->http->protover == 11) {
@@ -115,10 +132,6 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
return;
}
- V1L_Open(req->wrk, req->wrk->aws, &req->sp->fd, req->vsl,
- req->t_prev + SESS_TMO(req->sp, send_timeout),
- cache_param->http1_iovs);
-
if (WS_Overflowed(req->wrk->aws)) {
v1d_error(req, boc, "workspace_thread overflow");
return;
diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c
index 474175ce0..817f7a969 100644
--- a/bin/varnishd/http1/cache_http1_fetch.c
+++ b/bin/varnishd/http1/cache_http1_fetch.c
@@ -72,6 +72,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
struct vdp_ctx vdc[1] = {{ 0 }};
intmax_t cl;
const char *err = NULL;
+ struct v1l *v1l = NULL;
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
@@ -100,9 +101,8 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
if (bo->vdp_filter_list != NULL &&
VCL_StackVDP(vdc, bo->vcl, bo->vdp_filter_list, NULL, bo))
err = "Failure to push processors";
- else if (V1L_Open(wrk, wrk->aws, htc->rfd, bo->vsl, nan(""), 0),
- wrk->v1l == NULL) {
- /* ^^^^^^
+ else if ((v1l = V1L_Open(wrk->aws, htc->rfd, bo->vsl, nan(""), 0)) == NULL) {
+ /* ^^^^^^^^
* XXX: need a send_timeout for the backend side
* XXX: use cache_param->http1_iovs ?
*/
@@ -111,8 +111,11 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
else if (v1f_stackv1l(vdc, bo))
err = "Failure to push V1L";
+ AZ(wrk->v1l);
+ wrk->v1l = v1l;
+
if (err != NULL) {
- if (wrk->v1l != NULL)
+ if (v1l != NULL)
(void) V1L_Close(wrk, &bytes);
if (VALID_OBJ(vdc, VDP_CTX_MAGIC))
(void) VDP_Close(vdc, NULL, NULL);
@@ -122,6 +125,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
return (-1);
}
+
assert(cl >= -1);
if (cl < 0)
http_PrintfHeader(hp, "Transfer-Encoding: chunked");
diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c
index b1087d1e6..d18bd6d61 100644
--- a/bin/varnishd/http1/cache_http1_line.c
+++ b/bin/varnishd/http1/cache_http1_line.c
@@ -75,19 +75,16 @@ struct v1l {
* otherwise, up to niov
*/
-void
-V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
+struct v1l *
+V1L_Open(struct ws *ws, int *fd, struct vsl_log *vsl,
vtim_real deadline, unsigned niov)
{
struct v1l *v1l;
unsigned u;
uintptr_t ws_snap;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- AZ(wrk->v1l);
-
if (WS_Overflowed(ws))
- return;
+ return (NULL);
if (niov != 0)
assert(niov >= 3);
@@ -96,7 +93,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
v1l = WS_Alloc(ws, sizeof *v1l);
if (v1l == NULL)
- return;
+ return (NULL);
INIT_OBJ(v1l, V1L_MAGIC);
v1l->ws = ws;
@@ -107,7 +104,7 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
/* Must have at least 3 in case of chunked encoding */
WS_Release(ws, 0);
WS_MarkOverflow(ws);
- return;
+ return (NULL);
}
if (u > IOV_MAX)
u = IOV_MAX;
@@ -121,10 +118,8 @@ V1L_Open(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
v1l->vsl = vsl;
v1l->werr = SC_NULL;
- AZ(wrk->v1l);
- wrk->v1l = v1l;
-
WS_Release(ws, u * sizeof(struct iovec));
+ return (v1l);
}
stream_close_t
More information about the varnish-commit
mailing list