[master] cddc0974b Add VRT_LookupDirector for vcl runtime lookup by name

Nils Goroll nils.goroll at uplex.de
Tue Feb 26 14:42:03 UTC 2019


commit cddc0974b38c060d2df61ae98babee6e19f36d83
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Sun Feb 17 14:15:15 2019 +0100

    Add VRT_LookupDirector for vcl runtime lookup by name
    
    I did consider generalizing VCL_IterDirector which handles backend
    iterations for the CLI, but found the complications not worth the
    savings for such a trivial function.

diff --git a/bin/varnishd/cache/cache_vrt_vcl.c b/bin/varnishd/cache/cache_vrt_vcl.c
index c17c80e5d..3374f80f4 100644
--- a/bin/varnishd/cache/cache_vrt_vcl.c
+++ b/bin/varnishd/cache/cache_vrt_vcl.c
@@ -261,6 +261,35 @@ VRT_DisableDirector(VCL_BACKEND d)
 	vdir->health_changed = VTIM_real();
 }
 
+VCL_BACKEND
+VRT_LookupDirector(VRT_CTX, VCL_STRING name)
+{
+	struct vcl *vcl;
+	struct vcldir *vdir;
+	VCL_BACKEND dd, d = NULL;
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(name);
+
+	assert(ctx->method & VCL_MET_TASK_H);
+	ASSERT_CLI();
+
+	vcl = ctx->vcl;
+	CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+
+	Lck_Lock(&vcl_mtx);
+	VTAILQ_FOREACH(vdir, &vcl->director_list, list) {
+		dd = vdir->dir;
+		if (strcmp(dd->vcl_name, name))
+			continue;
+		d = dd;
+		break;
+	}
+	Lck_Unlock(&vcl_mtx);
+
+	return (d);
+}
+
 /*--------------------------------------------------------------------*/
 
 VCL_BACKEND
diff --git a/include/vrt.h b/include/vrt.h
index f6fc9ca26..72c9c4d78 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -62,6 +62,7 @@
  *	req->req_bodybytes removed
  *	    use: AZ(ObjGetU64(req->wrk, req->body_oc, OA_LEN, &u));
  *	struct vdi_methods .list callback signature changed
+ *	VRT_LookupDirector() added
  * 8.0 (2018-09-15)
  *	VRT_Strands() added
  *	VRT_StrandsWS() added
@@ -512,6 +513,7 @@ VCL_BACKEND VRT_AddDirector(VRT_CTX, const struct vdi_methods *,
     void *, const char *, ...) v_printflike_(4, 5);
 void VRT_SetHealth(VCL_BACKEND d, int health);
 void VRT_DisableDirector(VCL_BACKEND);
+VCL_BACKEND VRT_LookupDirector(VRT_CTX, VCL_STRING);
 void VRT_DelDirector(VCL_BACKEND *);
 
 /* Suckaddr related */


More information about the varnish-commit mailing list