Skip to content

Commit f2ba5ab

Browse files
committed
cache_http1_line: Make the v1l VDP a bit less special
V1L is used to send HTTP headers and the body, so it is used directly from delivery/fetch first and then as a VDP. From the times before VDPs, the V1L VDP still had its private pointer in struct wrk. This commit is to move the private pointer to the VDP entry. The caller remains responsible for calling V1L_Close() to keep V1L independent of VDP.
1 parent 19cd238 commit f2ba5ab

File tree

9 files changed

+74
-79
lines changed

9 files changed

+74
-79
lines changed

bin/varnishd/cache/cache.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ struct worker {
252252

253253
vtim_real lastused;
254254

255-
struct v1l *v1l;
256-
257255
pthread_cond_t cond;
258256

259257
struct ws aws[1];

bin/varnishd/cache/cache_varnishd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ htc_complete_f HTTP1_Complete;
300300
uint16_t HTTP1_DissectRequest(struct http_conn *, struct http *);
301301
uint16_t HTTP1_DissectResponse(struct http_conn *, struct http *resp,
302302
const struct http *req);
303-
unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*);
303+
struct v1l;
304+
unsigned HTTP1_Write(struct v1l *v1l, const struct http *hp, const int*);
304305

305306
/* cache_main.c */
306307
vxid_t VXID_Get(const struct worker *, uint64_t marker);

bin/varnishd/http1/cache_http1.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ stream_close_t V1P_Process(const struct req *, int fd, struct v1p_acct *,
5959
void V1P_Charge(struct req *, const struct v1p_acct *, struct VSC_vbe *);
6060

6161
/* cache_http1_line.c */
62-
void V1L_Chunked(const struct worker *w);
63-
void V1L_EndChunk(const struct worker *w);
62+
void V1L_Chunked(struct v1l *v1l);
63+
void V1L_EndChunk(struct v1l *v1l);
6464
struct v1l * V1L_Open(struct ws *, int *fd, struct vsl_log *,
6565
vtim_real deadline, unsigned niov);
66-
stream_close_t V1L_Flush(const struct worker *w);
67-
stream_close_t V1L_Close(struct worker *w, uint64_t *cnt);
68-
size_t V1L_Write(const struct worker *w, const void *ptr, ssize_t len);
66+
stream_close_t V1L_Flush(struct v1l *v1l);
67+
stream_close_t V1L_Close(struct v1l **v1lp, uint64_t *cnt);
68+
size_t V1L_Write(struct v1l *v1l, const void *ptr, ssize_t len);
6969
extern const struct vdp * const VDP_v1l;

bin/varnishd/http1/cache_http1_deliver.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@
4040
/*--------------------------------------------------------------------*/
4141

4242
static void
43-
v1d_error(struct req *req, struct boc *boc, const char *msg)
43+
v1d_error(struct req *req, struct boc *boc, struct v1l **v1lp, const char *msg)
4444
{
4545
static const char r_500[] =
4646
"HTTP/1.1 500 Internal Server Error\r\n"
4747
"Server: Varnish\r\n"
4848
"Connection: close\r\n\r\n";
4949
uint64_t bytes;
5050

51-
if (req->wrk->v1l != NULL)
52-
(void) V1L_Close(req->wrk, &bytes);
51+
AN(v1lp);
52+
if (*v1lp != NULL)
53+
(void) V1L_Close(v1lp, &bytes);
5354

5455
VSLbs(req->vsl, SLT_Error, TOSTRAND(msg));
5556
VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");
@@ -97,13 +98,10 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
9798
cache_param->http1_iovs);
9899

99100
if (v1l == NULL) {
100-
v1d_error(req, boc, "Failure to init v1d (workspace_thread overflow)");
101+
v1d_error(req, boc, &v1l, "Failure to init v1d (workspace_thread overflow)");
101102
return;
102103
}
103104

104-
AZ(req->wrk->v1l);
105-
req->wrk->v1l = v1l;
106-
107105
if (sendbody) {
108106
if (!http_GetHdr(req->resp, H_Content_Length, NULL)) {
109107
if (req->http->protover == 11) {
@@ -116,41 +114,40 @@ V1D_Deliver(struct req *req, struct boc *boc, int sendbody)
116114
}
117115
INIT_OBJ(ctx, VRT_CTX_MAGIC);
118116
VCL_Req2Ctx(ctx, req);
119-
if (VDP_Push(ctx, req->vdc, req->ws, VDP_v1l, NULL)) {
120-
v1d_error(req, boc, "Failure to push v1d processor");
117+
if (VDP_Push(ctx, req->vdc, req->ws, VDP_v1l, v1l)) {
118+
v1d_error(req, boc, &v1l, "Failure to push v1d processor");
121119
return;
122120
}
123121
}
124122

125123
if (WS_Overflowed(req->ws)) {
126-
v1d_error(req, boc, "workspace_client overflow");
124+
v1d_error(req, boc, &v1l, "workspace_client overflow");
127125
return;
128126
}
129127

130128
if (WS_Overflowed(req->sp->ws)) {
131-
v1d_error(req, boc, "workspace_session overflow");
129+
v1d_error(req, boc, &v1l, "workspace_session overflow");
132130
return;
133131
}
134132

135133
if (WS_Overflowed(req->wrk->aws)) {
136-
v1d_error(req, boc, "workspace_thread overflow");
134+
v1d_error(req, boc, &v1l, "workspace_thread overflow");
137135
return;
138136
}
139137

140-
hdrbytes = HTTP1_Write(req->wrk, req->resp, HTTP1_Resp);
138+
hdrbytes = HTTP1_Write(v1l, req->resp, HTTP1_Resp);
141139

142140
if (sendbody) {
143141
if (DO_DEBUG(DBG_FLUSH_HEAD))
144-
(void)V1L_Flush(req->wrk);
142+
(void)V1L_Flush(v1l);
145143
if (chunked)
146-
V1L_Chunked(req->wrk);
144+
V1L_Chunked(v1l);
147145
err = VDP_DeliverObj(req->vdc, req->objcore);
148146
if (!err && chunked)
149-
V1L_EndChunk(req->wrk);
147+
V1L_EndChunk(v1l);
150148
}
151149

152-
sc = V1L_Close(req->wrk, &bytes);
153-
AZ(req->wrk->v1l);
150+
sc = V1L_Close(&v1l, &bytes);
154151

155152
req->acct.resp_hdrbytes += hdrbytes;
156153
req->acct.resp_bodybytes += VDP_Close(req->vdc, req->objcore, boc);

bin/varnishd/http1/cache_http1_fetch.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
#include "cache_http1.h"
4444

4545
static int
46-
v1f_stackv1l(struct vdp_ctx *vdc, struct busyobj *bo)
46+
v1f_stackv1l(struct vdp_ctx *vdc, struct busyobj *bo, struct v1l *v1l)
4747
{
4848
struct vrt_ctx ctx[1];
4949

5050
INIT_OBJ(ctx, VRT_CTX_MAGIC);
5151
VCL_Bo2Ctx(ctx, bo);
52-
return (VDP_Push(ctx, vdc, ctx->ws, VDP_v1l, NULL));
52+
return (VDP_Push(ctx, vdc, ctx->ws, VDP_v1l, v1l));
5353
}
5454

5555
/*--------------------------------------------------------------------
@@ -108,15 +108,12 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
108108
*/
109109
err = "Failure to open V1L (workspace_thread overflow)";
110110
}
111-
else if (v1f_stackv1l(vdc, bo))
111+
else if (v1f_stackv1l(vdc, bo, v1l))
112112
err = "Failure to push V1L";
113113

114-
AZ(wrk->v1l);
115-
wrk->v1l = v1l;
116-
117114
if (err != NULL) {
118115
if (v1l != NULL)
119-
(void) V1L_Close(wrk, &bytes);
116+
(void) V1L_Close(&v1l, &bytes);
120117
if (VALID_OBJ(vdc, VDP_CTX_MAGIC))
121118
(void) VDP_Close(vdc, NULL, NULL);
122119
VSLb(bo->vsl, SLT_FetchError, "%s", err);
@@ -131,7 +128,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
131128
http_PrintfHeader(hp, "Transfer-Encoding: chunked");
132129

133130
VTCP_blocking(*htc->rfd); /* XXX: we should timeout instead */
134-
hdrbytes = HTTP1_Write(wrk, hp, HTTP1_Req);
131+
hdrbytes = HTTP1_Write(v1l, hp, HTTP1_Req);
135132

136133
/* Deal with any message-body the request might (still) have */
137134
i = 0;
@@ -144,7 +141,7 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
144141
} else if (bo->req != NULL &&
145142
bo->req->req_body_status != BS_NONE) {
146143
if (cl < 0)
147-
V1L_Chunked(wrk);
144+
V1L_Chunked(v1l);
148145
i = VRB_Iterate(wrk, bo->vsl, bo->req, VDP_ObjIterate, vdc);
149146

150147
if (bo->req->req_body_status != BS_CACHED)
@@ -167,10 +164,10 @@ V1F_SendReq(struct worker *wrk, struct busyobj *bo, uint64_t *ctr_hdrbytes,
167164
bo->req->doclose = SC_RX_BODY;
168165
}
169166
if (cl < 0)
170-
V1L_EndChunk(wrk);
167+
V1L_EndChunk(v1l);
171168
}
172169

173-
sc = V1L_Close(wrk, &bytes);
170+
sc = V1L_Close(&v1l, &bytes);
174171
CHECK_OBJ_NOTNULL(sc, STREAM_CLOSE_MAGIC);
175172

176173
/* Bytes accounting */

bin/varnishd/http1/cache_http1_fsm.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ http1_req(struct worker *wrk, void *arg)
8585
req->transport = &HTTP1_transport;
8686
assert(!WS_IsReserved(wrk->aws));
8787
HTTP1_Session(wrk, req);
88-
AZ(wrk->v1l);
8988
WS_Assert(wrk->aws);
9089
THR_SetRequest(NULL);
9190
}

bin/varnishd/http1/cache_http1_line.c

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct v1l {
6868
ssize_t cnt; /* Flushed byte count */
6969
struct ws *ws;
7070
uintptr_t ws_snap;
71+
void **vdp_priv;
7172
};
7273

7374
/*--------------------------------------------------------------------
@@ -123,17 +124,20 @@ V1L_Open(struct ws *ws, int *fd, struct vsl_log *vsl,
123124
}
124125

125126
stream_close_t
126-
V1L_Close(struct worker *wrk, uint64_t *cnt)
127+
V1L_Close(struct v1l **v1lp, uint64_t *cnt)
127128
{
128129
struct v1l *v1l;
129130
struct ws *ws;
130131
uintptr_t ws_snap;
131132
stream_close_t sc;
132133

133-
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
134134
AN(cnt);
135-
sc = V1L_Flush(wrk);
136-
TAKE_OBJ_NOTNULL(v1l, &wrk->v1l, V1L_MAGIC);
135+
TAKE_OBJ_NOTNULL(v1l, v1lp, V1L_MAGIC);
136+
if (v1l->vdp_priv != NULL) {
137+
assert(*v1l->vdp_priv == v1l);
138+
*v1l->vdp_priv = NULL;
139+
}
140+
sc = V1L_Flush(v1l);
137141
*cnt = v1l->cnt;
138142
ws = v1l->ws;
139143
ws_snap = v1l->ws_snap;
@@ -167,15 +171,12 @@ v1l_prune(struct v1l *v1l, size_t bytes)
167171
}
168172

169173
stream_close_t
170-
V1L_Flush(const struct worker *wrk)
174+
V1L_Flush(struct v1l *v1l)
171175
{
172176
ssize_t i;
173177
int err;
174-
struct v1l *v1l;
175178
char cbuf[32];
176179

177-
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
178-
v1l = wrk->v1l;
179180
CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC);
180181
CHECK_OBJ_NOTNULL(v1l->werr, STREAM_CLOSE_MAGIC);
181182
AN(v1l->wfd);
@@ -261,12 +262,9 @@ V1L_Flush(const struct worker *wrk)
261262
}
262263

263264
size_t
264-
V1L_Write(const struct worker *wrk, const void *ptr, ssize_t len)
265+
V1L_Write(struct v1l *v1l, const void *ptr, ssize_t len)
265266
{
266-
struct v1l *v1l;
267267

268-
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
269-
v1l = wrk->v1l;
270268
CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC);
271269
AN(v1l->wfd);
272270
if (len == 0 || *v1l->wfd < 0)
@@ -280,19 +278,16 @@ V1L_Write(const struct worker *wrk, const void *ptr, ssize_t len)
280278
v1l->niov++;
281279
v1l->cliov += len;
282280
if (v1l->niov >= v1l->siov) {
283-
(void)V1L_Flush(wrk);
281+
(void)V1L_Flush(v1l);
284282
VSC_C_main->http1_iovs_flush++;
285283
}
286284
return (len);
287285
}
288286

289287
void
290-
V1L_Chunked(const struct worker *wrk)
288+
V1L_Chunked(struct v1l *v1l)
291289
{
292-
struct v1l *v1l;
293290

294-
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
295-
v1l = wrk->v1l;
296291
CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC);
297292

298293
assert(v1l->ciov == v1l->siov);
@@ -302,7 +297,7 @@ V1L_Chunked(const struct worker *wrk)
302297
* a chunk tail, we might as well flush right away.
303298
*/
304299
if (v1l->niov + 3 >= v1l->siov) {
305-
(void)V1L_Flush(wrk);
300+
(void)V1L_Flush(v1l);
306301
VSC_C_main->http1_iovs_flush++;
307302
}
308303
v1l->siov--;
@@ -320,41 +315,53 @@ V1L_Chunked(const struct worker *wrk)
320315
*/
321316

322317
void
323-
V1L_EndChunk(const struct worker *wrk)
318+
V1L_EndChunk(struct v1l *v1l)
324319
{
325-
struct v1l *v1l;
326320

327-
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
328-
v1l = wrk->v1l;
329321
CHECK_OBJ_NOTNULL(v1l, V1L_MAGIC);
330322

331323
assert(v1l->ciov < v1l->siov);
332-
(void)V1L_Flush(wrk);
324+
(void)V1L_Flush(v1l);
333325
v1l->siov++;
334326
v1l->ciov = v1l->siov;
335327
v1l->niov = 0;
336328
v1l->cliov = 0;
337-
(void)V1L_Write(wrk, "0\r\n\r\n", -1);
329+
(void)V1L_Write(v1l, "0\r\n\r\n", -1);
338330
}
339331

340332
/*--------------------------------------------------------------------
341333
* VDP using V1L
342334
*/
343335

336+
/* remember priv pointer for V1L_Close() to clear */
337+
static int v_matchproto_(vdp_init_f)
338+
v1l_init(VRT_CTX, struct vdp_ctx *vdc, void **priv)
339+
{
340+
struct v1l *v1l;
341+
342+
(void) ctx;
343+
(void) vdc;
344+
AN(priv);
345+
CAST_OBJ_NOTNULL(v1l, *priv, V1L_MAGIC);
346+
347+
v1l->vdp_priv = priv;
348+
return (0);
349+
}
350+
344351
static int v_matchproto_(vdp_bytes_f)
345352
v1l_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
346353
const void *ptr, ssize_t len)
347354
{
348355
ssize_t wl = 0;
349356

350357
CHECK_OBJ_NOTNULL(vdc, VDP_CTX_MAGIC);
351-
(void)priv;
358+
AN(priv);
352359

353360
AZ(vdc->nxt); /* always at the bottom of the pile */
354361

355362
if (len > 0)
356-
wl = V1L_Write(vdc->wrk, ptr, len);
357-
if (act > VDP_NULL && V1L_Flush(vdc->wrk) != SC_NULL)
363+
wl = V1L_Write(*priv, ptr, len);
364+
if (act > VDP_NULL && V1L_Flush(*priv) != SC_NULL)
358365
return (-1);
359366
if (len != wl)
360367
return (-1);
@@ -363,5 +370,6 @@ v1l_bytes(struct vdp_ctx *vdc, enum vdp_action act, void **priv,
363370

364371
const struct vdp * const VDP_v1l = &(struct vdp){
365372
.name = "V1B",
373+
.init = v1l_init,
366374
.bytes = v1l_bytes,
367375
};

0 commit comments

Comments
 (0)