[master] 16c8251 Pass the vmod.object::init function the VCL name of the object being created.

Poul-Henning Kamp phk at varnish-cache.org
Thu Mar 7 10:19:52 CET 2013


commit 16c8251dd9b8f6ca4645a4a35608428ce61e4a69
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Mar 7 08:50:21 2013 +0000

    Pass the vmod.object::init function the VCL name of the object being
    created.
    
    Split the demo-rr director into its own file

diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index 50e912d..5fdae74 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -220,7 +220,7 @@ parse_new(struct vcc *tl)
 
 	vcc_NextToken(tl);
 
-	bprintf(buf1, ", &%s", sy1->name);
+	bprintf(buf1, ", &%s, \"%s\"", sy1->name, sy1->name);
 	vcc_Eval_Func(tl, s_init, buf1, "ASDF", s_init + strlen(s_init) + 1);
 	Ff(tl, 0, "\t%s((struct req*)0, &%s);\n", s_fini, sy1->name);
 	ExpectErr(tl, ';');
diff --git a/lib/libvcl/vmodtool.py b/lib/libvcl/vmodtool.py
index 0a8bb12..ddec683 100755
--- a/lib/libvcl/vmodtool.py
+++ b/lib/libvcl/vmodtool.py
@@ -300,7 +300,7 @@ class obj(object):
 
 	def set_modnam(self, modnam):
 		self.st = "struct vmod_" + modnam + "_" + self.nam
-		self.init.set_pfx(", " + self.st + " **")
+		self.init.set_pfx(", " + self.st + " **, const char *")
 		self.fini.set_pfx(", " + self.st + " **")
 		for m in self.methods:
 			m.set_pfx(", " + self.st + " *")
diff --git a/lib/libvmod_debug/Makefile.am b/lib/libvmod_debug/Makefile.am
index 7e2c849..a4f9fb7 100644
--- a/lib/libvmod_debug/Makefile.am
+++ b/lib/libvmod_debug/Makefile.am
@@ -15,7 +15,8 @@ libvmod_debug_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version
 
 libvmod_debug_la_SOURCES = \
 	vmod_debug.c \
-	vmod_debug_obj.c
+	vmod_debug_obj.c \
+	vmod_debug_rr.c
 
 nodist_libvmod_debug_la_SOURCES = \
 	vcc_if.c \
diff --git a/lib/libvmod_debug/vmod_debug_obj.c b/lib/libvmod_debug/vmod_debug_obj.c
index 3ec94e1..2b628fa 100644
--- a/lib/libvmod_debug/vmod_debug_obj.c
+++ b/lib/libvmod_debug/vmod_debug_obj.c
@@ -42,11 +42,13 @@ struct vmod_debug_obj {
 };
 
 VCL_VOID
-vmod_obj__init(struct req *req, struct vmod_debug_obj **op, VCL_STRING s)
+vmod_obj__init(struct req *req, struct vmod_debug_obj **op,
+    const char *vcl_name, VCL_STRING s)
 {
 	struct vmod_debug_obj *o;
 
 	(void)req;
+	(void)vcl_name;
 	(void)s;
 	AN(op);
 	AZ(*op);
@@ -86,86 +88,3 @@ vmod_obj_date(struct req *req, struct vmod_debug_obj *o)
 	assert(o->foobar == 42);
 	return (21.4);
 }
-
-/*----------------------------------------------------------------------*/
-
-struct vmod_debug_rr_entry {
-	unsigned				magic;
-#define VMOD_DEBUG_RR_ENTRY_MAGIC		0xa80970cf
-	VTAILQ_ENTRY(vmod_debug_rr_entry)	list;
-	VCL_BACKEND				be;
-};
-
-struct vmod_debug_rr {
-	unsigned				magic;
-#define VMOD_DEBUG_RR_MAGIC			0x99f4b726
-	VTAILQ_HEAD(, vmod_debug_rr_entry)	listhead;
-	pthread_mutex_t				mtx;
-};
-
-VCL_VOID
-vmod_rr__init(struct req *req, struct vmod_debug_rr **rrp)
-{
-	struct vmod_debug_rr *rr;
-
-	(void)req;
-
-	AN(rrp);
-	AZ(*rrp);
-	ALLOC_OBJ(rr, VMOD_DEBUG_RR_MAGIC);
-	AN(rr);
-	*rrp = rr;
-	AZ(pthread_mutex_init(&rr->mtx, NULL));
-	VTAILQ_INIT(&rr->listhead);
-}
-
-VCL_VOID
-vmod_rr__fini(struct req *req, struct vmod_debug_rr **rrp)
-{
-	struct vmod_debug_rr *rr;
-	struct vmod_debug_rr_entry *ep;
-
-	(void)req;
-
-	rr = *rrp;
-	*rrp = NULL;
-	CHECK_OBJ_NOTNULL(rr, VMOD_DEBUG_RR_MAGIC);
-
-	AZ(pthread_mutex_destroy(&rr->mtx));
-	while (!VTAILQ_EMPTY(&rr->listhead)) {
-		ep = VTAILQ_FIRST(&rr->listhead);
-		VTAILQ_REMOVE(&rr->listhead, ep, list);
-		FREE_OBJ(ep);
-	}
-	FREE_OBJ(*rrp);
-}
-
-VCL_VOID
-vmod_rr_add_backend(struct req *req, struct vmod_debug_rr * rr, VCL_BACKEND be)
-{
-	struct vmod_debug_rr_entry *ep;
-	(void)req;
-
-	ALLOC_OBJ(ep, VMOD_DEBUG_RR_ENTRY_MAGIC);
-	AN(ep);
-	ep->be = be;
-	AZ(pthread_mutex_lock(&rr->mtx));
-	VTAILQ_INSERT_TAIL(&rr->listhead, ep, list);
-	AZ(pthread_mutex_unlock(&rr->mtx));
-}
-
-VCL_BACKEND
-vmod_rr_select(struct req *req, struct vmod_debug_rr *rr)
-{
-	struct vmod_debug_rr_entry *ep;
-
-	(void)req;
-
-	CHECK_OBJ_NOTNULL(rr, VMOD_DEBUG_RR_MAGIC);
-	AZ(pthread_mutex_lock(&rr->mtx));
-	ep = VTAILQ_FIRST(&rr->listhead);
-	VTAILQ_REMOVE(&rr->listhead, ep, list);
-	VTAILQ_INSERT_TAIL(&rr->listhead, ep, list);
-	AZ(pthread_mutex_unlock(&rr->mtx));
-	return (ep->be);
-}
diff --git a/lib/libvmod_debug/vmod_debug_rr.c b/lib/libvmod_debug/vmod_debug_rr.c
new file mode 100644
index 0000000..186e2a1
--- /dev/null
+++ b/lib/libvmod_debug/vmod_debug_rr.c
@@ -0,0 +1,118 @@
+/*-
+ * Copyright (c) 2013 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include "cache/cache.h"
+
+#include "vrt.h"
+#include "vcc_if.h"
+
+struct vmod_debug_rr_entry {
+	unsigned				magic;
+#define VMOD_DEBUG_RR_ENTRY_MAGIC		0xa80970cf
+	VTAILQ_ENTRY(vmod_debug_rr_entry)	list;
+	VCL_BACKEND				be;
+};
+
+struct vmod_debug_rr {
+	unsigned				magic;
+#define VMOD_DEBUG_RR_MAGIC			0x99f4b726
+	VTAILQ_HEAD(, vmod_debug_rr_entry)	listhead;
+	pthread_mutex_t				mtx;
+};
+
+VCL_VOID
+vmod_rr__init(struct req *req, struct vmod_debug_rr **rrp, const char *vcl_name)
+{
+	struct vmod_debug_rr *rr;
+
+	(void)req;
+	(void)vcl_name;
+
+	AN(rrp);
+	AZ(*rrp);
+	ALLOC_OBJ(rr, VMOD_DEBUG_RR_MAGIC);
+	AN(rr);
+	*rrp = rr;
+	AZ(pthread_mutex_init(&rr->mtx, NULL));
+	VTAILQ_INIT(&rr->listhead);
+}
+
+VCL_VOID
+vmod_rr__fini(struct req *req, struct vmod_debug_rr **rrp)
+{
+	struct vmod_debug_rr *rr;
+	struct vmod_debug_rr_entry *ep;
+
+	(void)req;
+
+	rr = *rrp;
+	*rrp = NULL;
+	CHECK_OBJ_NOTNULL(rr, VMOD_DEBUG_RR_MAGIC);
+
+	AZ(pthread_mutex_destroy(&rr->mtx));
+	while (!VTAILQ_EMPTY(&rr->listhead)) {
+		ep = VTAILQ_FIRST(&rr->listhead);
+		VTAILQ_REMOVE(&rr->listhead, ep, list);
+		FREE_OBJ(ep);
+	}
+	FREE_OBJ(*rrp);
+}
+
+VCL_VOID
+vmod_rr_add_backend(struct req *req, struct vmod_debug_rr * rr, VCL_BACKEND be)
+{
+	struct vmod_debug_rr_entry *ep;
+	(void)req;
+
+	ALLOC_OBJ(ep, VMOD_DEBUG_RR_ENTRY_MAGIC);
+	AN(ep);
+	ep->be = be;
+	AZ(pthread_mutex_lock(&rr->mtx));
+	VTAILQ_INSERT_TAIL(&rr->listhead, ep, list);
+	AZ(pthread_mutex_unlock(&rr->mtx));
+}
+
+VCL_BACKEND
+vmod_rr_select(struct req *req, struct vmod_debug_rr *rr)
+{
+	struct vmod_debug_rr_entry *ep;
+
+	(void)req;
+
+	CHECK_OBJ_NOTNULL(rr, VMOD_DEBUG_RR_MAGIC);
+	AZ(pthread_mutex_lock(&rr->mtx));
+	ep = VTAILQ_FIRST(&rr->listhead);
+	VTAILQ_REMOVE(&rr->listhead, ep, list);
+	VTAILQ_INSERT_TAIL(&rr->listhead, ep, list);
+	AZ(pthread_mutex_unlock(&rr->mtx));
+	return (ep->be);
+}



More information about the varnish-commit mailing list