[master] 0d68e21d1 Use trivial VRT_Assign_Backend() to assign VCL_BACKEND to variables.

Poul-Henning Kamp phk at FreeBSD.org
Wed Nov 24 11:37:05 UTC 2021


commit 0d68e21d1c12984f0285c12d9898aa6bbba3198e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Nov 24 11:36:21 2021 +0000

    Use trivial VRT_Assign_Backend() to assign VCL_BACKEND to variables.
    
    (First part of #3599)

diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index f3e41716f..9a5fe36d1 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -137,7 +137,7 @@ VBO_GetBusyObj(const struct worker *wrk, const struct req *req)
 		XXXAN(bo->client_identity);
 	}
 
-	bo->director_req = req->director_hint;
+	VRT_Assign_Backend(&bo->director_req, req->director_hint);
 	bo->vcl = req->vcl;
 	VCL_Ref(bo->vcl);
 
@@ -180,6 +180,8 @@ VBO_ReleaseBusyObj(struct worker *wrk, struct busyobj **pbo)
 		    HSH_RUSH_POLICY);
 	}
 
+	VRT_Assign_Backend(&bo->director_req, NULL);
+	VRT_Assign_Backend(&bo->director_resp, NULL);
 	VCL_Rel(&bo->vcl);
 #ifdef ENABLE_WORKSPACE_EMULATOR
 	WS_Rollback(bo->ws, 0);
diff --git a/bin/varnishd/cache/cache_director.c b/bin/varnishd/cache/cache_director.c
index 173ad6604..5bb3ac7b7 100644
--- a/bin/varnishd/cache/cache_director.c
+++ b/bin/varnishd/cache/cache_director.c
@@ -140,7 +140,7 @@ VDI_GetHdr(struct busyobj *bo)
 
 	d = VDI_Resolve(ctx);
 	if (d != NULL) {
-		bo->director_resp = d;
+		VRT_Assign_Backend(&bo->director_resp, d);
 		AN(d->vdir->methods->gethdrs);
 		bo->director_state = DIR_S_HDRS;
 		i = d->vdir->methods->gethdrs(ctx, d);
@@ -214,7 +214,7 @@ VDI_Http1Pipe(struct req *req, struct busyobj *bo)
 		VSLb(bo->vsl, SLT_VCL_Error, "Backend does not support pipe");
 		return (SC_TX_ERROR);
 	}
-	bo->director_resp = d;
+	VRT_Assign_Backend(&bo->director_resp, d);
 	return (d->vdir->methods->http1pipe(ctx, d));
 }
 
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index e754014e7..0b383e594 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -876,7 +876,8 @@ cnt_recv_prep(struct req *req, const char *ci)
 		http_CollectHdr(req->http, H_Cache_Control);
 
 		/* By default we use the first backend */
-		req->director_hint = VCL_DefaultDirector(req->vcl);
+		VRT_Assign_Backend(&req->director_hint,
+		    VCL_DefaultDirector(req->vcl));
 
 		req->d_ttl = -1;
 		req->d_grace = -1;
@@ -1190,6 +1191,7 @@ CNT_Request(struct req *req)
 		VCL_TaskLeave(ctx, req->privs);
 		AN(req->vsl->wid);
 		VRB_Free(req);
+		VRT_Assign_Backend(&req->director_hint, NULL);
 		req->wrk = NULL;
 	}
 	assert(nxt == REQ_FSM_DISEMBARK || !WS_IsReserved(req->ws));
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index c73c28385..1f0edca4d 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -504,13 +504,22 @@ VRT_r_req_##nm(VRT_CTX)							\
 	return (ctx->req->elem);					\
 }
 
-REQ_VAR_L(backend_hint, director_hint, VCL_BACKEND,)
 REQ_VAR_R(backend_hint, director_hint, VCL_BACKEND)
+
 REQ_VAR_L(ttl, d_ttl, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
 REQ_VAR_R(ttl, d_ttl, VCL_DURATION)
 REQ_VAR_L(grace, d_grace, VCL_DURATION, if (!(arg>0.0)) arg = 0;)
 REQ_VAR_R(grace, d_grace, VCL_DURATION)
 
+VCL_VOID
+VRT_l_req_backend_hint(VRT_CTX, VCL_BACKEND be)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
+	VRT_Assign_Backend(&ctx->req->director_hint, be);
+}
+
 /*--------------------------------------------------------------------*/
 
 VCL_VOID
@@ -519,7 +528,7 @@ VRT_l_bereq_backend(VRT_CTX, VCL_BACKEND be)
 
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);
-	ctx->bo->director_req = be;
+	VRT_Assign_Backend(&ctx->bo->director_req, be);
 }
 
 VCL_BACKEND
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 3fd34e42e..194098c3f 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -251,6 +251,14 @@ VRT_DelDirector(VCL_BACKEND *bp)
 	vcldir_free(vdir);
 }
 
+void
+VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src)
+{
+
+	AN(dst);
+	*dst = src;
+}
+
 void
 VRT_DisableDirector(VCL_BACKEND d)
 {
diff --git a/include/vrt.h b/include/vrt.h
index a0d4f10ff..5e99b242d 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -53,6 +53,9 @@
  * Whenever something is deleted or changed in a way which is not
  * binary/load-time compatible, increment MAJOR version
  *
+ * Next (2021-03-15)
+ *	VRT_Assign_Backend added
+ *
  * 14.0 (2021-09-15)
  *	VIN_n_Arg() no directly returns the directory name.
  *	VSB_new() and VSB_delete() removed
@@ -682,6 +685,7 @@ VCL_BACKEND VRT_AddDirector(VRT_CTX, const struct vdi_methods *,
 void VRT_DisableDirector(VCL_BACKEND);
 VCL_BACKEND VRT_LookupDirector(VRT_CTX, VCL_STRING);
 void VRT_DelDirector(VCL_BACKEND *);
+void VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src);
 
 /***********************************************************************
  * vmod_priv related
diff --git a/vmod/vmod_directors.c b/vmod/vmod_directors.c
index 09f18719e..2130c4b55 100644
--- a/vmod/vmod_directors.c
+++ b/vmod/vmod_directors.c
@@ -96,10 +96,13 @@ void
 vdir_delete(struct vdir **vdp)
 {
 	struct vdir *vd;
+	unsigned u;
 
 	TAKE_OBJ_NOTNULL(vd, vdp, VDIR_MAGIC);
 
 	AZ(vd->dir);
+	for (u = 0; u < vd->n_backend; u++)
+		VRT_Assign_Backend(&vd->backend[u], NULL);
 	free(vd->backend);
 	free(vd->weight);
 	AZ(pthread_rwlock_destroy(&vd->mtx));
@@ -147,7 +150,8 @@ vdir_add_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, double weight)
 		vdir_expand(vd, vd->l_backend + 16);
 	assert(vd->n_backend < vd->l_backend);
 	u = vd->n_backend++;
-	vd->backend[u] = be;
+	vd->backend[u] = NULL;
+	VRT_Assign_Backend(&vd->backend[u], be);
 	vd->weight[u] = weight;
 	vdir_unlock(vd);
 }
@@ -173,6 +177,7 @@ vdir_remove_backend(VRT_CTX, struct vdir *vd, VCL_BACKEND be, unsigned *cur)
 		vdir_unlock(vd);
 		return;
 	}
+	VRT_Assign_Backend(&vd->backend[u], NULL);
 	n = (vd->n_backend - u) - 1;
 	memmove(&vd->backend[u], &vd->backend[u+1], n * sizeof(vd->backend[0]));
 	memmove(&vd->weight[u], &vd->weight[u+1], n * sizeof(vd->weight[0]));
diff --git a/vmod/vmod_directors_shard_cfg.c b/vmod/vmod_directors_shard_cfg.c
index 3d3c6de11..6df86b643 100644
--- a/vmod/vmod_directors_shard_cfg.c
+++ b/vmod/vmod_directors_shard_cfg.c
@@ -195,7 +195,8 @@ shard_change_task_backend(VRT_CTX, struct sharddir *shardd,
 		return (NULL);
 	}
 
-	b->backend = be;
+	b->backend = NULL;
+	VRT_Assign_Backend(&b->backend, be);
 	b->ident = ident != NULL && *ident != '\0' ? ident : NULL;
 	b->rampup = rampup;
 
@@ -333,6 +334,7 @@ shardcfg_backend_free(struct shard_backend *f)
 {
 	if (f->freeptr)
 		free (f->freeptr);
+	VRT_Assign_Backend(&f->backend, NULL);
 	memset(f, 0, sizeof(*f));
 }
 
@@ -466,8 +468,7 @@ shardcfg_backend_clear(struct sharddir *shardd)
 
 
 static void
-shardcfg_backend_del(struct backend_reconfig *re,
-    const struct shard_backend *spec)
+shardcfg_backend_del(struct backend_reconfig *re, struct shard_backend *spec)
 {
 	unsigned i, max = re->shardd->n_backend + re->hole_n;
 	struct shard_backend * const bb = re->shardd->backend;
@@ -485,6 +486,7 @@ shardcfg_backend_del(struct backend_reconfig *re,
 			re->hole_i = vmin(re->hole_i, i);
 		}
 	}
+	VRT_Assign_Backend(&spec->backend, NULL);
 }
 
 static void


More information about the varnish-commit mailing list