[master] 4c295286d Add VRT_StaticDirector() to disable refcounting.

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


commit 4c295286d89def5d70c80c98d0f002dba6d79efc
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Nov 24 12:23:25 2021 +0000

    Add VRT_StaticDirector() to disable refcounting.
    
    (Last part of #3599)

diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index ebf1b9e3c..9f286a55f 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -406,7 +406,7 @@ vbe_dir_event(const struct director *d, enum vcl_event_e ev)
 			VBP_Control(bp, 0);
 		VRT_VSC_Hide(bp->vsc_seg);
 	} else if (ev == VCL_EVENT_DISCARD) {
-		VRT_Assign_Backend(&bp->director, NULL);
+		VRT_DelDirector(&bp->director);
 	}
 }
 
diff --git a/bin/varnishd/cache/cache_director.h b/bin/varnishd/cache/cache_director.h
index 31c41e27b..9a12c6b3d 100644
--- a/bin/varnishd/cache/cache_director.h
+++ b/bin/varnishd/cache/cache_director.h
@@ -37,6 +37,8 @@ struct vcldir {
 	unsigned			magic;
 #define VCLDIR_MAGIC			0xbf726c7d
 	int				refcnt;
+	unsigned			flags;
+#define VDIR_FLG_NOREFCNT		1
 	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 35e83f3df..070822f36 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -226,6 +226,19 @@ VRT_AddDirector(VRT_CTX, const struct vdi_methods *m, void *priv,
 	return (vdir->dir);
 }
 
+void
+VRT_StaticDirector(VCL_BACKEND b)
+{
+	struct vcldir *vdir;
+
+	CHECK_OBJ_NOTNULL(b, DIRECTOR_MAGIC);
+	vdir = b->vdir;
+	CHECK_OBJ_NOTNULL(vdir, VCLDIR_MAGIC);
+	assert(vdir->refcnt == 1);
+	AZ(vdir->flags & VDIR_FLG_NOREFCNT);
+	vdir->flags |= VDIR_FLG_NOREFCNT;
+}
+
 static void
 retire_backend(VCL_BACKEND *bp)
 {
@@ -278,19 +291,23 @@ VRT_Assign_Backend(VCL_BACKEND *dst, VCL_BACKEND src)
 	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);
-		busy = --(*dst)->vdir->refcnt;
-		Lck_Unlock((*dst)->mtx);
-		if (!busy)
-			retire_backend(dst);
+		if (!((*dst)->vdir->flags & VDIR_FLG_NOREFCNT)) {
+			Lck_Lock((*dst)->mtx);
+			assert((*dst)->vdir->refcnt > 0);
+			busy = --(*dst)->vdir->refcnt;
+			Lck_Unlock((*dst)->mtx);
+			if (!busy)
+				retire_backend(dst);
+		}
 	}
 	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);
+		if (!(src->vdir->flags & VDIR_FLG_NOREFCNT)) {
+			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