[master] 8b53dbeda cache_req: Refactor: Use REQ_FLAGS for esi and pipe marker

Nils Goroll nils.goroll at uplex.de
Mon Feb 10 16:29:06 UTC 2025


commit 8b53dbeda3fe45621ed47182ba1e4cb40aac2ff2
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Feb 10 17:06:22 2025 +0100

    cache_req: Refactor: Use REQ_FLAGS for esi and pipe marker
    
    No need to spend 4 bytes on just two bits...
    
    Note: RES_ESI could be replaced by "check if the ESI VDP is on the stack", but
    as long as we have the marker for pipe, we might as well keep it for ESI, too.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index ffa3d8577..c15f0833c 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -470,11 +470,6 @@ struct req {
 	unsigned		max_restarts;
 	unsigned		esi_level;
 
-	/* Delivery mode */
-	unsigned		res_mode;
-#define RES_ESI			(1<<4)
-#define RES_PIPE		(1<<7)
-
 	const struct req_step	*req_step;
 	struct reqtop		*top;	/* esi_level == 0 request */
 
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index c4f64f42e..645207b39 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -511,7 +511,7 @@ vbe_dir_http1pipe(VRT_CTX, VCL_BACKEND d)
 	v1a.req = ctx->req->acct.req_hdrbytes;
 	ctx->req->acct.req_hdrbytes = 0;
 
-	ctx->req->res_mode = RES_PIPE;
+	ctx->req->res_pipe = 1;
 
 	retval = SC_TX_ERROR;
 	pfd = vbe_dir_getfd(ctx, ctx->req->wrk, d, bp, 0);
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index 6a336b549..f739b22c3 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -290,7 +290,7 @@ ved_vdp_esi_init(VRT_CTX, struct vdp_ctx *vdc, void **priv)
 	*priv = ecx;
 	RFC2616_Weaken_Etag(vdc->hp);
 
-	ctx->req->res_mode |= RES_ESI;
+	ctx->req->res_esi = 1;
 	if (*vdc->clen != 0)
 		*vdc->clen = -1;
 	if (ctx->req->esi_level > 0) {
@@ -909,7 +909,7 @@ ved_deliver(struct req *req, int wantbody)
 	INIT_OBJ(ctx, VRT_CTX_MAGIC);
 	VCL_Req2Ctx(ctx, req);
 
-	if (ecx->isgzip && i && !(req->res_mode & RES_ESI)) {
+	if (ecx->isgzip && i && !req->res_esi) {
 		/* A gzipped include which is not ESI processed */
 
 		/* OA_GZIPBITS are not valid until BOS_FINISHED */
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index ac188560c..0511ae09b 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -55,7 +55,7 @@ Req_AcctLogCharge(struct VSC_main_wrk *ds, struct req *req)
 
 	a = &req->acct;
 
-	if (!IS_NO_VXID(req->vsl->wid) && !(req->res_mode & RES_PIPE)) {
+	if (!IS_NO_VXID(req->vsl->wid) && !req->res_pipe) {
 		VSLb(req->vsl, SLT_ReqAcct, "%ju %ju %ju %ju %ju %ju",
 		    (uintmax_t)a->req_hdrbytes,
 		    (uintmax_t)a->req_bodybytes,
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 89f71f0a9..1004cbc5f 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -440,7 +440,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
 	CHECK_OBJ_NOTNULL(req->transport, TRANSPORT_MAGIC);
 	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
 	AZ(req->stale_oc);
-	AZ(req->res_mode);
+	AZ(req->res_pipe | req->res_esi);
 	AZ(req->boc);
 	req->req_step = R_STP_FINISH;
 
@@ -533,7 +533,8 @@ cnt_finish(struct worker *wrk, struct req *req)
 	http_Teardown(req->resp);
 
 	req->vdp_filter_list = NULL;
-	req->res_mode = 0;
+	req->res_pipe = 0;
+	req->res_esi = 0;
 	return (REQ_FSM_DONE);
 }
 
diff --git a/include/tbl/req_flags.h b/include/tbl/req_flags.h
index 6a9e6acbb..dde208d16 100644
--- a/include/tbl/req_flags.h
+++ b/include/tbl/req_flags.h
@@ -41,6 +41,8 @@ REQ_FLAG(waitinglist,		0, 0, "")
 REQ_FLAG(want100cont,		0, 0, "")
 REQ_FLAG(late100cont,		0, 0, "")
 REQ_FLAG(req_reset,		0, 0, "")
+REQ_FLAG(res_esi,		0, 0, "")
+REQ_FLAG(res_pipe,		0, 0, "")
 #define REQ_BEREQ_FLAG(lower, vcl_r, vcl_w, doc) \
 	REQ_FLAG(lower, vcl_r, vcl_w, doc)
 #include "tbl/req_bereq_flags.h"


More information about the varnish-commit mailing list