[master] 6e9b8d6d7 Transplant the backend lock up to the director layer and expose it in the public side of the API so the backend layer can get at it.

Poul-Henning Kamp phk at FreeBSD.org
Tue Apr 20 21:10:12 UTC 2021


commit 6e9b8d6d7ca93d365914c044307fab455d4ec750
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 20 20:32:33 2021 +0000

    Transplant the backend lock up to the director layer and
    expose it in the public side of the API so the backend layer
    can get at it.

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index b67773f12..7141e5a89 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -171,11 +171,11 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
 	AN(fdp);
 	assert(*fdp >= 0);
 
-	Lck_Lock(&bp->mtx);
+	Lck_Lock(bp->director->mtx);
 	bp->n_conn++;
 	bp->vsc->conn++;
 	bp->vsc->req++;
-	Lck_Unlock(&bp->mtx);
+	Lck_Unlock(bp->director->mtx);
 
 	err = 0;
 	if (bp->proxy_header != 0)
@@ -190,11 +190,11 @@ vbe_dir_getfd(VRT_CTX, struct worker *wrk, VCL_BACKEND dir, struct backend *bp,
 		bo->htc = NULL;
 		VCP_Close(&pfd);
 		AZ(pfd);
-		Lck_Lock(&bp->mtx);
+		Lck_Lock(bp->director->mtx);
 		bp->n_conn--;
 		bp->vsc->conn--;
 		bp->vsc->req--;
-		Lck_Unlock(&bp->mtx);
+		Lck_Unlock(bp->director->mtx);
 		return (NULL);
 	}
 	bo->acct.bereq_hdrbytes += err;
@@ -245,12 +245,12 @@ vbe_dir_finish(VRT_CTX, VCL_BACKEND d)
 		    VRT_BACKEND_string(d));
 		VCP_Close(&pfd);
 		AZ(pfd);
-		Lck_Lock(&bp->mtx);
+		Lck_Lock(bp->director->mtx);
 	} else {
 		assert (PFD_State(pfd) == PFD_STATE_USED);
 		VSLb(bo->vsl, SLT_BackendClose, "%d %s recycle", *PFD_Fd(pfd),
 		    VRT_BACKEND_string(d));
-		Lck_Lock(&bp->mtx);
+		Lck_Lock(bp->director->mtx);
 		VSC_C_main->backend_recycle++;
 		VCP_Recycle(bo->wrk, &pfd);
 	}
@@ -260,7 +260,7 @@ vbe_dir_finish(VRT_CTX, VCL_BACKEND d)
 	bp->vsc->conn--;
 #define ACCT(foo)	bp->vsc->foo += bo->acct.foo;
 #include "tbl/acct_fields_bereq.h"
-	Lck_Unlock(&bp->mtx);
+	Lck_Unlock(bp->director->mtx);
 	bo->htc = NULL;
 }
 
@@ -446,7 +446,7 @@ vbe_free(struct backend *be)
 #undef DN
 	free(be->endpoint);
 
-	Lck_Delete(&be->mtx);
+	Lck_Delete(be->director->mtx);
 	FREE_OBJ(be);
 }
 
@@ -593,7 +593,6 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
 	ALLOC_OBJ(be, BACKEND_MAGIC);
 	if (be == NULL)
 		return (NULL);
-	Lck_New(&be->mtx, lck_backend);
 
 	vep = be->endpoint = VRT_Endpoint_Clone(vep);
 #define DA(x)	do { if (vrt->x != NULL) REPLACE((be->x), (vrt->x)); } while (0)
@@ -675,9 +674,9 @@ VRT_delete_backend(VRT_CTX, VCL_BACKEND *dp)
 	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
 	TAKE_OBJ_NOTNULL(d, dp, DIRECTOR_MAGIC);
 	CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC);
-	Lck_Lock(&be->mtx);
+	Lck_Lock(be->director->mtx);
 	VRT_DisableDirector(be->director);
-	Lck_Unlock(&be->mtx);
+	Lck_Unlock(be->director->mtx);
 	Lck_Lock(&backends_mtx);
 	AZ(be->cooled);
 	be->cooled = VTIM_real() + 60.;
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index b2c211d9e..7eabfebc3 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -55,7 +55,6 @@ struct backend {
 	unsigned		n_conn;
 
 	VTAILQ_ENTRY(backend)	list;
-	struct lock		mtx;
 
 	struct vrt_endpoint	*endpoint;
 
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index e164e1678..eefbd9335 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -36,6 +36,7 @@
 struct vcldir {
 	unsigned			magic;
 #define VCLDIR_MAGIC			0xbf726c7d
+	struct lock			dlck;
 	struct director			*dir;
 	struct vcl			*vcl;
 	const struct vdi_methods	*methods;
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 023ba0022..a862163ef 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -142,6 +142,8 @@ static void
 vcldir_free(struct vcldir *vdir)
 {
 
+	CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
+	Lck_Delete(&vdir->dlck);
 	free(vdir->cli_name);
 	FREE_OBJ(vdir->dir);
 	FREE_OBJ(vdir);
@@ -192,6 +194,9 @@ VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
 	vdir->admin_health = VDI_AH_AUTO;
 	vdir->health_changed = VTIM_real();
 
+	Lck_New(&vdir->dlck, lck_director);
+	vdir->dir->mtx = &vdir->dlck;
+
 	/* NB: at this point we look at the VCL temperature after getting
 	 * through the trouble of creating the director even though it might
 	 * not be legal to do so. Because we change the VCL temperature before
diff --git a/include/tbl/locks.h b/include/tbl/locks.h
index 8240ae2b3..3de8e33e6 100644
--- a/include/tbl/locks.h
+++ b/include/tbl/locks.h
@@ -31,10 +31,10 @@
 
 /*lint -save -e525 -e539 */
 
-LOCK(backend)
 LOCK(ban)
 LOCK(busyobj)
 LOCK(cli)
+LOCK(director)
 LOCK(exp)
 LOCK(hcb)
 LOCK(lru)
diff --git a/include/vrt.h b/include/vrt.h
index f469d2dab..10528a3e5 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -202,6 +202,7 @@
 struct busyobj;
 struct director;
 struct http;
+struct lock;
 struct req;
 struct stevedore;
 struct suckaddr;
@@ -621,6 +622,7 @@ struct director {
 	void				*priv;
 	char				*vcl_name;
 	struct vcldir			*vdir;
+	struct lock			*mtx;
 };
 
 VCL_BOOL VRT_Healthy(VRT_CTX, VCL_BACKEND, VCL_TIME *);


More information about the varnish-commit mailing list