[master] 25e7b9a17 cache_req_fsm: Refactor: move busy objcore reference to struct req

Nils Goroll nils.goroll at uplex.de
Mon Nov 25 17:30:04 UTC 2024


commit 25e7b9a170160603dac61c95f5ab4969e47d51c5
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Nov 1 15:46:32 2024 +0100

    cache_req_fsm: Refactor: move busy objcore reference to struct req
    
    This is in preparation of simplifications and to be able disembark during
    delivery.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index d9cd0094f..9346f0980 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -537,6 +537,7 @@ struct req {
 	struct ws		ws[1];
 	struct objcore		*objcore;
 	struct objcore		*stale_oc;
+	struct boc		*boc;		/* valid during cnt_transmit */
 
 	/* resp.body */
 	struct vdp_ctx		*vdc;
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 9dfebfd99..56b15fcd4 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -429,7 +429,6 @@ cnt_synth(struct worker *wrk, struct req *req)
 static enum req_fsm_nxt v_matchproto_(req_state_f)
 cnt_transmit(struct worker *wrk, struct req *req)
 {
-	struct boc *boc;
 	uint16_t status;
 	int sendbody, head;
 	intmax_t clval;
@@ -440,17 +439,18 @@ cnt_transmit(struct worker *wrk, struct req *req)
 	CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
 	AZ(req->stale_oc);
 	AZ(req->res_mode);
+	AZ(req->boc);
 
 	/* Grab a ref to the bo if there is one (=streaming) */
-	boc = HSH_RefBoc(req->objcore);
-	if (boc && boc->state < BOS_STREAM)
+	req->boc = HSH_RefBoc(req->objcore);
+	if (req->boc && req->boc->state < BOS_STREAM)
 		ObjWaitState(req->objcore, BOS_STREAM);
 	clval = http_GetContentLength(req->resp);
 	/* RFC 7230, 3.3.3 */
 	status = http_GetStatus(req->resp);
 	head = http_method_eq(req->http0->hd[HTTP_HDR_METHOD].b, HEAD);
 
-	if (boc != NULL || (req->objcore->flags & (OC_F_FAILED)))
+	if (req->boc != NULL || (req->objcore->flags & (OC_F_FAILED)))
 		req->resp_len = clval;
 	else
 		req->resp_len = ObjGetLen(req->wrk, req->objcore);
@@ -470,7 +470,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
 		VSLb(req->vsl, SLT_Error, "Failure to push processors");
 		req->doclose = SC_OVERLOAD;
 		req->acct.resp_bodybytes +=
-			VDP_Close(req->vdc, req->objcore, boc);
+			VDP_Close(req->vdc, req->objcore, req->boc);
 	} else {
 		if (status < 200 || status == 204) {
 			// rfc7230,l,1691,1695
@@ -497,7 +497,7 @@ cnt_transmit(struct worker *wrk, struct req *req)
 		}
 		if (req->resp_len == 0)
 			sendbody = 0;
-		req->transport->deliver(req, boc, sendbody);
+		req->transport->deliver(req, req->boc, sendbody);
 	}
 
 	VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
@@ -508,8 +508,10 @@ cnt_transmit(struct worker *wrk, struct req *req)
 		req->doclose = SC_TX_ERROR;
 	}
 
-	if (boc != NULL)
+	if (req->boc != NULL) {
 		HSH_DerefBoc(wrk, req->objcore);
+		req->boc = NULL;
+	}
 
 	(void)HSH_DerefObjCore(wrk, &req->objcore, HSH_RUSH_POLICY);
 	http_Teardown(req->resp);


More information about the varnish-commit mailing list