[master] 8941ae92d Reference count directors.

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


commit 8941ae92dc95d6ff28833037077d5dd3a757feb1
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Nov 24 11:49:55 2021 +0000

    Reference count directors.
    
    (2nd part of #3599)

diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index eefbd9335..31c41e27b 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
+	int				refcnt;
 	struct lock			dlck;
 	struct director			*dir;
 	struct vcl			*vcl;
diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index 194098c3f..4144c13f2 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -197,6 +197,7 @@ VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
 	vdir->admin_health = VDI_AH_AUTO;
 	vdir->health_changed = VTIM_real();
 
+	vdir->refcnt++;
 	Lck_New(&vdir->dlck, lck_director);
 	vdir->dir->mtx = &vdir->dlck;
 
@@ -238,6 +239,11 @@ VRT_DelDirector(VCL_BACKEND *bp)
 	vcl = vdir->vcl;
 	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
 
+	Lck_Lock(d->mtx);
+	assert(vdir->refcnt == 1);
+	--vdir->refcnt;
+	Lck_Unlock(d->mtx);
+
 	Lck_Lock(&vcl_mtx);
 	temp = vcl->temp;
 	VTAILQ_REMOVE(&vcl->director_list, vdir, list);
@@ -256,6 +262,22 @@ VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src)
 {
 
 	AN(dst);
+	CHECK_OBJ_ORNULL((*dst), DIRECTOR_MAGIC);
+	CHECK_OBJ_ORNULL(src, DIRECTOR_MAGIC);
+	if (*dst != NULL) {
+		CHECK_OBJ_NOTNULL((*dst)->vdir, VCLDIR_MAGIC);
+		Lck_Lock((*dst)->mtx);
+		assert((*dst)->vdir->refcnt > 0);
+		--(*dst)->vdir->refcnt;
+		Lck_Unlock((*dst)->mtx);
+	}
+	if (src != NULL) {
+		CHECK_OBJ_NOTNULL(src->vdir, VCLDIR_MAGIC);
+		Lck_Lock(src->mtx);
+		assert(src->vdir->refcnt > 0);
+		src->vdir->refcnt++;
+		Lck_Unlock(src->mtx);
+	}
 	*dst = src;
 }
 


More information about the varnish-commit mailing list