r4937 - in trunk/varnish-cache: bin/varnishstat bin/varnishtest include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Tue Jun 8 13:34:54 CEST 2010


Author: phk
Date: 2010-06-08 13:34:54 +0200 (Tue, 08 Jun 2010)
New Revision: 4937

Modified:
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/vsc.c
   trunk/varnish-cache/lib/libvarnishapi/vslapi.h
   trunk/varnish-cache/lib/libvarnishapi/vsm.c
Log:
Redo the VSC api new-style.



Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-08 11:34:54 UTC (rev 4937)
@@ -197,6 +197,7 @@
 	int delay = 1, once = 0, xml = 0;
 
 	vd = VSM_New();
+	VSC_Setup(vd);
 
 	while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) {
 		switch (c) {
@@ -207,7 +208,7 @@
 			(void)VSC_Arg(vd, c, optarg);
 			break;
 		case 'l':
-			if (VSM_Open(vd, 1))
+			if (VSC_Open(vd, 1))
 				exit(1);
 			list_fields(vd);
 			exit(0);
@@ -227,11 +228,10 @@
 		}
 	}
 
-	if (VSM_Open(vd, 1))
+	if (VSC_Open(vd, 1))
 		exit(1);
 
-	if ((VSL_stats = VSM_OpenStats(vd)) == NULL)
-		exit(1);
+	VSL_stats = VSC_Main(vd);
 
 	if (xml)
 		do_xml(vd);

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-08 11:34:54 UTC (rev 4937)
@@ -67,8 +67,6 @@
 	struct vtclog		*vl1;
 	VTAILQ_ENTRY(varnish)	list;
 
-	struct vsc_main	*stats;
-
 	struct vsb		*storage;
 
 	struct vsb		*args;
@@ -262,6 +260,7 @@
 	char *r;
 
 	v->vd = VSM_New();
+	VSC_Setup(v->vd);
 
 	/* Create listener socket */
 	nap = VSS_resolve("127.0.0.1", "0", &ap);
@@ -362,11 +361,8 @@
 		vtc_log(v->vl, 0, "CLI auth command failed: %u %s", u, r);
 	free(r);
 
-	if (v->stats != NULL)
-		VSM_Close(v->vd);
 	(void)VSL_Log_Arg(v->vd, 'n', v->workdir);
-	AZ(VSM_Open(v->vd, 1));
-	v->stats = VSM_OpenStats(v->vd);
+	AZ(VSC_Open(v->vd, 1));
 }
 
 /**********************************************************************

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/include/varnishapi.h	2010-06-08 11:34:54 UTC (rev 4937)
@@ -125,9 +125,12 @@
  * VSC level access functions
  */
 
+void VSC_Setup(struct VSM_data *vd);
 int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
-struct vsc_main *VSM_OpenStats(struct VSM_data *vd);
+int VSC_Open(struct VSM_data *vd, int diag);
 
+struct vsc_main *VSC_Main(struct VSM_data *vd);
+
 struct vsc_point {
 	const char *class;		/* stat struct type		*/
 	const char *ident;		/* stat struct ident		*/
@@ -146,7 +149,6 @@
  * VSL level access functions
  */
 
-/* shmlog.c */
 typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd,
     unsigned len, unsigned spec, const char *ptr);
 #define VSL_S_CLIENT	(1 << 0)

Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsc.c	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/lib/libvarnishapi/vsc.c	2010-06-08 11:34:54 UTC (rev 4937)
@@ -49,20 +49,75 @@
 
 #include "vslapi.h"
 
+struct vsc_sf {
+	unsigned		magic;
+#define VSL_SF_MAGIC		0x558478dd
+	VTAILQ_ENTRY(vsc_sf)	next;
+	int			flags;
+#define VSL_SF_EXCL		(1 << 0)
+#define VSL_SF_CL_WC		(1 << 1)
+#define VSL_SF_ID_WC		(1 << 2)
+#define VSL_SF_NM_WC		(1 << 3)
+	char			*class;
+	char			*ident;
+	char			*name;
+};
+
+struct vsc {
+	unsigned		magic;
+#define VSC_MAGIC		0x3373554a
+
+	int			sf_init;
+	VTAILQ_HEAD(, vsc_sf)	sf_list;
+
+};
+
+
 /*--------------------------------------------------------------------*/
 
+void
+VSC_Setup(struct VSM_data *vd)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	AZ(vd->vsc);
+	// XXX: AZ(vd->vsm);
+	ALLOC_OBJ(vd->vsc, VSC_MAGIC);
+	AN(vd->vsc);
+	VTAILQ_INIT(&vd->vsc->sf_list);
+}
+
+void
+vsc_delete(struct VSM_data *vd)
+{
+	struct vsc_sf *sf;
+	struct vsc *vsc = vd->vsc;
+
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+	while(!VTAILQ_EMPTY(&vsc->sf_list)) {
+		sf = VTAILQ_FIRST(&vsc->sf_list);
+		VTAILQ_REMOVE(&vsc->sf_list, sf, next);
+		free(sf->class);
+		free(sf->ident);
+		free(sf->name);
+		free(sf);
+	}
+}
+
+/*--------------------------------------------------------------------*/
+
 static int
-vsc_sf_arg(struct VSM_data *vd, const char *opt)
+vsc_sf_arg(struct vsc *vsc, const char *opt)
 {
 	struct vsc_sf *sf;
 	char **av, *q, *p;
 	int i;
 
-	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
 
-	if (VTAILQ_EMPTY(&vd->sf_list)) {
+	if (VTAILQ_EMPTY(&vsc->sf_list)) {
 		if (*opt == '^')
-			vd->sf_init = 1;
+			vsc->sf_init = 1;
 	}
 
 	av = ParseArgv(opt, ARGV_COMMA);
@@ -74,7 +129,7 @@
 	for (i = 1; av[i] != NULL; i++) {
 		ALLOC_OBJ(sf, VSL_SF_MAGIC);
 		AN(sf);
-		VTAILQ_INSERT_TAIL(&vd->sf_list, sf, next);
+		VTAILQ_INSERT_TAIL(&vsc->sf_list, sf, next);
 
 		p = av[i];
 		if (*p == '^') {
@@ -134,10 +189,13 @@
 int
 VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
 {
+	struct vsc *vsc;
 
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	vsc = vd->vsc;
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
 	switch (arg) {
-	case 'f': return (vsc_sf_arg(vd, opt));
+	case 'f': return (vsc_sf_arg(vsc, opt));
 	case 'n': return (VSM_n_Arg(vd, opt));
 	default:
 		return (0);
@@ -146,12 +204,27 @@
 
 /*--------------------------------------------------------------------*/
 
+int
+VSC_Open(struct VSM_data *vd, int diag)
+{
+	int i;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	AN(vd->vsc);
+
+	i = VSM_Open(vd, diag);
+	return (i);
+}
+
+/*--------------------------------------------------------------------*/
+
 struct vsc_main *
-VSM_OpenStats(struct VSM_data *vd)
+VSC_Main(struct VSM_data *vd)
 {
 	struct vsm_chunk *sha;
 
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	CHECK_OBJ_NOTNULL(vd->vsc, VSC_MAGIC);
 
 	sha = vsm_find_alloc(vd, VSC_CLASS, "", "");
 	assert(sha != NULL);
@@ -176,16 +249,20 @@
 }
 
 static int
-iter_call(const struct VSM_data *vd, vsc_iter_f *func, void *priv,
+iter_call(const struct vsc *vsc, vsc_iter_f *func, void *priv,
     const struct vsc_point *const sp)
 {
 	struct vsc_sf *sf;
-	int good = vd->sf_init;
+	int good;
 
-	if (VTAILQ_EMPTY(&vd->sf_list))
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+
+	if (VTAILQ_EMPTY(&vsc->sf_list))
 		return (func(priv, sp));
 
-	VTAILQ_FOREACH(sf, &vd->sf_list, next) {
+	good = vsc->sf_init;
+
+	VTAILQ_FOREACH(sf, &vsc->sf_list, next) {
 		if (iter_test(sf->class, sp->class, sf->flags & VSL_SF_CL_WC))
 			continue;
 		if (iter_test(sf->ident, sp->ident, sf->flags & VSL_SF_ID_WC))
@@ -203,13 +280,17 @@
 }
 
 static int
-iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func,
+iter_main(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
     void *priv)
 {
-	struct vsc_main *st = VSM_PTR(sha);
+	struct vsc_main *st;
 	struct vsc_point sp;
 	int i;
 
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+	CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+
+	st = VSM_PTR(sha);
 	sp.class = "";
 	sp.ident = "";
 #define VSC_F_MAIN(nn, tt, ll, ff, dd)					\
@@ -218,7 +299,7 @@
 	sp.flag = ff;							\
 	sp.desc = dd;							\
 	sp.ptr = &st->nn;						\
-	i = iter_call(vd, func, priv, &sp);				\
+	i = iter_call(vsc, func, priv, &sp);				\
 	if (i)								\
 		return(i);
 #include "vsc_fields.h"
@@ -227,13 +308,17 @@
 }
 
 static int
-iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsc_iter_f *func,
+iter_sma(const struct vsc *vsc, struct vsm_chunk *sha, vsc_iter_f *func,
     void *priv)
 {
-	struct vsc_sma *st = VSM_PTR(sha);
+	struct vsc_sma *st;
 	struct vsc_point sp;
 	int i;
 
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+	CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+	st = VSM_PTR(sha);
+
 	sp.class = VSC_TYPE_SMA;
 	sp.ident = sha->ident;
 #define VSC_F_SMA(nn, tt, ll, ff, dd)				\
@@ -242,7 +327,7 @@
 	sp.flag = ff;							\
 	sp.desc = dd;							\
 	sp.ptr = &st->nn;						\
-	i = iter_call(vd, func, priv, &sp);				\
+	i = iter_call(vsc, func, priv, &sp);				\
 	if (i)								\
 		return(i);
 #include "vsc_fields.h"
@@ -253,18 +338,23 @@
 int
 VSC_Iter(const struct VSM_data *vd, vsc_iter_f *func, void *priv)
 {
+	struct vsc *vsc;
 	struct vsm_chunk *sha;
 	int i;
 
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	vsc = vd->vsc;
+	CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+
 	i = 0;
 	VSM_FOREACH(sha, vd) {
 		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
 		if (strcmp(sha->class, VSC_CLASS))
 			continue;
 		if (!strcmp(sha->type, VSC_TYPE_MAIN))
-			i = iter_main(vd, sha, func, priv);
+			i = iter_main(vsc, sha, func, priv);
 		else if (!strcmp(sha->type, VSC_TYPE_SMA))
-			i = iter_sma(vd, sha, func, priv);
+			i = iter_sma(vsc, sha, func, priv);
 		else
 			i = -1;
 		if (i != 0)

Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 11:34:54 UTC (rev 4937)
@@ -33,19 +33,7 @@
 #define			SLEEP_USEC	(50*1000)
 #define			TIMEOUT_USEC	(5*1000*1000)
 
-struct vsc_sf {
-	unsigned		magic;
-#define VSL_SF_MAGIC		0x558478dd
-	VTAILQ_ENTRY(vsc_sf)	next;
-	int			flags;
-#define VSL_SF_EXCL		(1 << 0)
-#define VSL_SF_CL_WC		(1 << 1)
-#define VSL_SF_ID_WC		(1 << 2)
-#define VSL_SF_NM_WC		(1 << 3)
-	char			*class;
-	char			*ident;
-	char			*name;
-};
+struct vsc;
 
 struct VSM_data {
 	unsigned		magic;
@@ -67,8 +55,7 @@
 
 	/* Stuff relating the stats fields start here */
 
-	int			sf_init;
-	VTAILQ_HEAD(, vsc_sf)	sf_list;
+	struct vsc		*vsc;
 
 	/* Stuff relating the log records below here */
 
@@ -119,3 +106,6 @@
 
 struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class,
     const char *type, const char *ident);
+
+void vsc_delete(struct VSM_data *vd);
+

Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsm.c	2010-06-08 10:35:14 UTC (rev 4936)
+++ trunk/varnish-cache/lib/libvarnishapi/vsm.c	2010-06-08 11:34:54 UTC (rev 4937)
@@ -87,8 +87,6 @@
 	vd->rbuf = malloc(vd->rbuflen * 4);
 	assert(vd->rbuf != NULL);
 
-	VTAILQ_INIT(&vd->sf_list);
-
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	return (vd);
 }
@@ -139,7 +137,6 @@
 void
 VSM_Delete(struct VSM_data *vd)
 {
-	struct vsc_sf *sf;
 
 	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	VSM_Close(vd);
@@ -151,14 +148,7 @@
 	free(vd->rbuf);
 	free(vd->fname);
 
-	while(!VTAILQ_EMPTY(&vd->sf_list)) {
-		sf = VTAILQ_FIRST(&vd->sf_list);
-		VTAILQ_REMOVE(&vd->sf_list, sf, next);
-		free(sf->class);
-		free(sf->ident);
-		free(sf->name);
-		free(sf);
-	}
+	vsc_delete(vd);
 
 	free(vd);
 }




More information about the varnish-commit mailing list