[master] f066db7 Take the 'zero' element out of the VSC structures again, and syntax check the JSON payload.

Poul-Henning Kamp phk at FreeBSD.org
Tue May 23 21:41:06 CEST 2017


commit f066db70d86b1a1701c98cbdb0eb7fdd0c236697
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue May 23 19:32:01 2017 +0000

    Take the 'zero' element out of the VSC structures again, and syntax
    check the JSON payload.

diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c
index 0b31cef..976b647 100644
--- a/bin/varnishd/cache/cache_backend_cfg.c
+++ b/bin/varnishd/cache/cache_backend_cfg.c
@@ -186,10 +186,8 @@ VBE_Event(struct backend *be, enum vcl_event_e ev)
 	if (be->probe != NULL && ev == VCL_EVENT_COLD)
 		VBP_Control(be, 0);
 
-	if (ev == VCL_EVENT_COLD) {
-		VSM_Free(be->vsc);
-		be->vsc = NULL;
-	}
+	if (ev == VCL_EVENT_COLD)
+		VSC_vbe_Destroy(&be->vsc);
 }
 
 void
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index b021150..45197e8 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -160,7 +160,7 @@ mpl_guard(void *priv)
 				FREE_OBJ(mi);
 				mi = NULL;
 			}
-			VSM_Free(mpl->vsc);
+			VSC_mempool_Destroy(&mpl->vsc);
 			Lck_Unlock(&mpl->mtx);
 			Lck_Delete(&mpl->mtx);
 			FREE_OBJ(mpl);
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index 5429a14..84a6b47 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -472,6 +472,18 @@ VSL_End(struct vsl_log *vsl)
 
 /*--------------------------------------------------------------------*/
 
+struct vsc_segs {
+	unsigned		magic;
+#define VSC_SEGS_MAGIC		0x9b355991
+
+	VTAILQ_ENTRY(vsc_segs)	list;
+	void			*seg;
+	void			*ptr;
+};
+
+static VTAILQ_HEAD(,vsc_segs)	vsc_seglist =
+    VTAILQ_HEAD_INITIALIZER(vsc_seglist);
+
 void *
 VSC_Alloc(const char *nm, size_t sd,
     size_t sj, const unsigned char *zj, size_t szj,
@@ -479,33 +491,50 @@ VSC_Alloc(const char *nm, size_t sd,
 {
 	char *p;
 	z_stream vz;
+	struct vsc_segs *vsg;
 
 	(void)nm;
 	(void)fmt;
 	(void)va;
 
-	p = VSM_Alloc(sd + sj, VSC_CLASS, nm, fmt);
+
+	p = VSM_Alloc(8 + sd + sj, VSC_CLASS, nm, fmt);
 	AN(p);
 
 	memset(p, 0, sd);
-	vbe64enc(p, sd);		// fills .zero
+	vbe64enc(p, sd);
 
 	memset(&vz, 0, sizeof vz);
 	assert(Z_OK == inflateInit2(&vz, 31));
 	vz.next_in = TRUST_ME(zj);
 	vz.avail_in = szj;
-	vz.next_out = (void*)(p + sd);
+	vz.next_out = (void*)(p + 8 + sd);
 	vz.avail_out = sj;
 	assert(Z_STREAM_END == inflate(&vz, Z_FINISH));
 	assert(Z_OK == inflateEnd(&vz));
-	return (p);
+	ALLOC_OBJ(vsg, VSC_SEGS_MAGIC);
+	vsg->seg = p;
+	vsg->ptr = p + 8;
+	VTAILQ_INSERT_TAIL(&vsc_seglist, vsg, list);
+	return (p + 8);
 }
 
 void
 VSC_Destroy(const char *nm, void *p)
 {
+	struct vsc_segs *vsg;
+
 	(void)nm;
-	(void)p;
+	VTAILQ_FOREACH(vsg, &vsc_seglist, list) {
+		if (vsg->ptr != p)
+			continue;
+		VSM_Free(vsg->seg);
+		VTAILQ_REMOVE(&vsc_seglist, vsg, list);
+		FREE_OBJ(vsg);
+		return;
+		
+	}
+	WRONG("Freeing unknown VSC");
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index f0797a7..809c006 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -47,6 +47,7 @@
 #include "hash/hash_slinger.h"
 #include "vav.h"
 #include "vcli_serve.h"
+#include "vend.h"
 #include "vev.h"
 #include "vfil.h"
 #include "vin.h"
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index 420b925..083b741 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -214,7 +214,6 @@ sma_open(struct stevedore *st)
 	CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
 	Lck_New(&sma_sc->sma_mtx, lck_sma);
 	sma_sc->stats = VSC_sma_New(st->ident);
-	memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
 	if (sma_sc->sma_max != SIZE_MAX)
 		sma_sc->stats->g_space = sma_sc->sma_max;
 }
diff --git a/include/vapi/vsc_int.h b/include/vapi/vsc_int.h
index 9d20665..352c8ba 100644
--- a/include/vapi/vsc_int.h
+++ b/include/vapi/vsc_int.h
@@ -43,7 +43,7 @@ enum VSC_level_e {
 #include "tbl/vsc_types.h"
 
 /* Define the vsc type structs */
-#define VSC_DO(u,l,t,h)			struct VSC_C_##l { uint64_t zero;
+#define VSC_DO(u,l,t,h)			struct VSC_C_##l {
 #define VSC_F(n,t,l,s,f,v,d,e)			t n;
 #define VSC_DONE(u,l,t)			};
 #include "tbl/vsc_all.h"
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 725a5f7..e58f64f 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -34,6 +34,7 @@
 
 #include <fnmatch.h>
 #include <stdint.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -41,7 +42,9 @@
 #include "vas.h"
 #include "miniobj.h"
 #include "vqueue.h"
+#include "vjsn.h"
 #include "vsb.h"
+#include "vend.h"
 
 #include "vapi/vsc.h"
 #include "vapi/vsm.h"
@@ -246,7 +249,7 @@ VSC_Get(const struct VSM_data *vd, struct VSM_fantom *fantom, const char *type,
 	if (VSM_invalid == VSM_StillValid(vd, fantom) &&
 	    !VSM_Get(vd, fantom, VSC_CLASS, type, ident))
 		return (NULL);
-	return ((void*)fantom->b);
+	return ((void*)((char*)fantom->b + 8));
 }
 
 /*--------------------------------------------------------------------*/
@@ -300,7 +303,7 @@ vsc_add_pt(struct vsc *vsc, const volatile void *ptr,
 		struct VSC_C_##l *st;					\
 									\
 		CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);			\
-		st = vf->fantom.b;
+		st = (void*)((char*)vf->fantom.b + 8);
 
 #define VSC_F(nn,tt,ll,ss,ff,vv,dd,ee)					\
 		vsc_add_pt(vsc, &st->nn, descs++, vf);
@@ -314,9 +317,25 @@ vsc_add_pt(struct vsc *vsc, const volatile void *ptr,
  */
 
 static void
+vsc_build_old_vf_list(struct vsc *vsc)
+{
+#define VSC_TYPE_F(n,t,l,e,d)						\
+	if (!strcmp(vsc->iter_fantom.type, t))				\
+		vsc_add_vf(vsc, &vsc->iter_fantom,			\
+		    &VSC_type_desc_##n, VSC_type_order_##n);
+#include "tbl/vsc_types.h"
+}
+
+#include <stdio.h>
+
+static void
 vsc_build_vf_list(struct VSM_data *vd)
 {
+	uint64_t u;
 	struct vsc *vsc = vsc_setup(vd);
+	struct vjsn *vj;
+	const char *p;
+	const char *e;
 
 	vsc_delete_pt_list(&vsc->pt_list);
 	vsc_delete_vf_list(&vsc->vf_list);
@@ -324,11 +343,20 @@ vsc_build_vf_list(struct VSM_data *vd)
 	VSM_FOREACH(&vsc->iter_fantom, vd) {
 		if (strcmp(vsc->iter_fantom.class, VSC_CLASS))
 			continue;
-#define VSC_TYPE_F(n,t,l,e,d)						\
-		if (!strcmp(vsc->iter_fantom.type, t))			\
-			vsc_add_vf(vsc, &vsc->iter_fantom,		\
-			    &VSC_type_desc_##n, VSC_type_order_##n);
-#include "tbl/vsc_types.h"
+		u = vbe64dec(vsc->iter_fantom.b);
+		vsc_build_old_vf_list(vsc);
+		if (u == 0) {
+			fprintf(stderr, "%s has no JSON\n", vsc->iter_fantom.type);
+			exit(2);
+		}
+		p = (char*)vsc->iter_fantom.b + 8 + u;
+		vj = vjsn_parse(p, &e);
+		if (e != NULL) {
+			fprintf(stderr, "%s\n", p);
+			fprintf(stderr, "JSON ERROR %s\n", e);
+		}
+		AZ(e);
+		//vjsn_dump(vj, stdout);
 	}
 }
 
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index ee70033..29aeb5c 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -89,7 +89,7 @@ class vscset(object):
 			ed["level"] = i.param["level"]
 			ed["1line"] = i.param["oneliner"].strip()
 			ed["docs"] = i.getdoc()
-		s=json.dumps(dd, separators=(",",":"))
+		s=json.dumps(dd, separators=(",",":")) + "\0"
 		fo.write("\nstatic const size_t vsc_%s_jsonlen = %dL;\n" %
 		    (self.name, len(s)))
 		z = gzip_str(s)
@@ -116,14 +116,13 @@ class vscset(object):
 		fo = open(fon, "w")
 		genhdr(fo, self.name)
 		fo.write(self.struct + " {\n")
-		fo.write("\tuint64_t\tzero;\n")
 		for i in self.mbrs:
 			fo.write("\tuint64_t\t%s;\n" % i.arg)
 		fo.write("};\n")
 		fo.write("\n");
 		fo.write(self.struct + " *VSC_" + self.name + "_New")
 		fo.write("(const char *fmt, ...);\n");
-		fo.write("void VSCL_" + self.name + "_Destroy")
+		fo.write("void VSC_" + self.name + "_Destroy")
 		fo.write("(" + self.struct + "**);\n")
 
 	def emit_c(self):
@@ -162,7 +161,7 @@ class vscset(object):
 		fo.write("}\n")
 		fo.write("\n")
 		fo.write("void\n")
-		fo.write("VSCL_" + self.name + "_Destroy")
+		fo.write("VSC_" + self.name + "_Destroy")
 		fo.write("(" + self.struct + "**pp)\n")
 		fo.write("{\n")
 		fo.write("\n")
@@ -285,8 +284,6 @@ class vsc_file(object):
 		for i in self.c:
 			i.vscset(self.vscset)
 
-		print(self.vscset)
-
 	def emit_h(self):
 		for i in self.vscset:
 			i.emit_h()



More information about the varnish-commit mailing list