Skip to content

Commit

Permalink
cache_http1_line: Refactor V1L_Open() to return struct v1l *
Browse files Browse the repository at this point in the history
  • Loading branch information
nigoroll committed Oct 31, 2024
1 parent 1084cfc commit 19cd238
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bin/varnishd/http1/cache_http1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 18 additions & 5 deletions bin/varnishd/http1/cache_http1_deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions bin/varnishd/http1/cache_http1_fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 ?
*/
Expand All @@ -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);
Expand All @@ -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");
Expand Down
17 changes: 6 additions & 11 deletions bin/varnishd/http1/cache_http1_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 19cd238

Please sign in to comment.