Commit f066db70 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Take the 'zero' element out of the VSC structures again, and syntax

check the JSON payload.
parent 5cc0e270
...@@ -186,10 +186,8 @@ VBE_Event(struct backend *be, enum vcl_event_e ev) ...@@ -186,10 +186,8 @@ VBE_Event(struct backend *be, enum vcl_event_e ev)
if (be->probe != NULL && ev == VCL_EVENT_COLD) if (be->probe != NULL && ev == VCL_EVENT_COLD)
VBP_Control(be, 0); VBP_Control(be, 0);
if (ev == VCL_EVENT_COLD) { if (ev == VCL_EVENT_COLD)
VSM_Free(be->vsc); VSC_vbe_Destroy(&be->vsc);
be->vsc = NULL;
}
} }
void void
......
...@@ -160,7 +160,7 @@ mpl_guard(void *priv) ...@@ -160,7 +160,7 @@ mpl_guard(void *priv)
FREE_OBJ(mi); FREE_OBJ(mi);
mi = NULL; mi = NULL;
} }
VSM_Free(mpl->vsc); VSC_mempool_Destroy(&mpl->vsc);
Lck_Unlock(&mpl->mtx); Lck_Unlock(&mpl->mtx);
Lck_Delete(&mpl->mtx); Lck_Delete(&mpl->mtx);
FREE_OBJ(mpl); FREE_OBJ(mpl);
......
...@@ -472,6 +472,18 @@ VSL_End(struct vsl_log *vsl) ...@@ -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 * void *
VSC_Alloc(const char *nm, size_t sd, VSC_Alloc(const char *nm, size_t sd,
size_t sj, const unsigned char *zj, size_t szj, size_t sj, const unsigned char *zj, size_t szj,
...@@ -479,33 +491,50 @@ VSC_Alloc(const char *nm, size_t sd, ...@@ -479,33 +491,50 @@ VSC_Alloc(const char *nm, size_t sd,
{ {
char *p; char *p;
z_stream vz; z_stream vz;
struct vsc_segs *vsg;
(void)nm; (void)nm;
(void)fmt; (void)fmt;
(void)va; (void)va;
p = VSM_Alloc(sd + sj, VSC_CLASS, nm, fmt);
p = VSM_Alloc(8 + sd + sj, VSC_CLASS, nm, fmt);
AN(p); AN(p);
memset(p, 0, sd); memset(p, 0, sd);
vbe64enc(p, sd); // fills .zero vbe64enc(p, sd);
memset(&vz, 0, sizeof vz); memset(&vz, 0, sizeof vz);
assert(Z_OK == inflateInit2(&vz, 31)); assert(Z_OK == inflateInit2(&vz, 31));
vz.next_in = TRUST_ME(zj); vz.next_in = TRUST_ME(zj);
vz.avail_in = szj; vz.avail_in = szj;
vz.next_out = (void*)(p + sd); vz.next_out = (void*)(p + 8 + sd);
vz.avail_out = sj; vz.avail_out = sj;
assert(Z_STREAM_END == inflate(&vz, Z_FINISH)); assert(Z_STREAM_END == inflate(&vz, Z_FINISH));
assert(Z_OK == inflateEnd(&vz)); 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 void
VSC_Destroy(const char *nm, void *p) VSC_Destroy(const char *nm, void *p)
{ {
struct vsc_segs *vsg;
(void)nm; (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");
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
#include "hash/hash_slinger.h" #include "hash/hash_slinger.h"
#include "vav.h" #include "vav.h"
#include "vcli_serve.h" #include "vcli_serve.h"
#include "vend.h"
#include "vev.h" #include "vev.h"
#include "vfil.h" #include "vfil.h"
#include "vin.h" #include "vin.h"
......
...@@ -214,7 +214,6 @@ sma_open(struct stevedore *st) ...@@ -214,7 +214,6 @@ sma_open(struct stevedore *st)
CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC); CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
Lck_New(&sma_sc->sma_mtx, lck_sma); Lck_New(&sma_sc->sma_mtx, lck_sma);
sma_sc->stats = VSC_sma_New(st->ident); sma_sc->stats = VSC_sma_New(st->ident);
memset(sma_sc->stats, 0, sizeof *sma_sc->stats);
if (sma_sc->sma_max != SIZE_MAX) if (sma_sc->sma_max != SIZE_MAX)
sma_sc->stats->g_space = sma_sc->sma_max; sma_sc->stats->g_space = sma_sc->sma_max;
} }
......
...@@ -43,7 +43,7 @@ enum VSC_level_e { ...@@ -43,7 +43,7 @@ enum VSC_level_e {
#include "tbl/vsc_types.h" #include "tbl/vsc_types.h"
/* Define the vsc type structs */ /* 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_F(n,t,l,s,f,v,d,e) t n;
#define VSC_DONE(u,l,t) }; #define VSC_DONE(u,l,t) };
#include "tbl/vsc_all.h" #include "tbl/vsc_all.h"
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <fnmatch.h> #include <fnmatch.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -41,7 +42,9 @@ ...@@ -41,7 +42,9 @@
#include "vas.h" #include "vas.h"
#include "miniobj.h" #include "miniobj.h"
#include "vqueue.h" #include "vqueue.h"
#include "vjsn.h"
#include "vsb.h" #include "vsb.h"
#include "vend.h"
#include "vapi/vsc.h" #include "vapi/vsc.h"
#include "vapi/vsm.h" #include "vapi/vsm.h"
...@@ -246,7 +249,7 @@ VSC_Get(const struct VSM_data *vd, struct VSM_fantom *fantom, const char *type, ...@@ -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) && if (VSM_invalid == VSM_StillValid(vd, fantom) &&
!VSM_Get(vd, fantom, VSC_CLASS, type, ident)) !VSM_Get(vd, fantom, VSC_CLASS, type, ident))
return (NULL); 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, ...@@ -300,7 +303,7 @@ vsc_add_pt(struct vsc *vsc, const volatile void *ptr,
struct VSC_C_##l *st; \ struct VSC_C_##l *st; \
\ \
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC); \ 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) \ #define VSC_F(nn,tt,ll,ss,ff,vv,dd,ee) \
vsc_add_pt(vsc, &st->nn, descs++, vf); vsc_add_pt(vsc, &st->nn, descs++, vf);
...@@ -313,10 +316,26 @@ vsc_add_pt(struct vsc *vsc, const volatile void *ptr, ...@@ -313,10 +316,26 @@ 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 static void
vsc_build_vf_list(struct VSM_data *vd) vsc_build_vf_list(struct VSM_data *vd)
{ {
uint64_t u;
struct vsc *vsc = vsc_setup(vd); struct vsc *vsc = vsc_setup(vd);
struct vjsn *vj;
const char *p;
const char *e;
vsc_delete_pt_list(&vsc->pt_list); vsc_delete_pt_list(&vsc->pt_list);
vsc_delete_vf_list(&vsc->vf_list); vsc_delete_vf_list(&vsc->vf_list);
...@@ -324,11 +343,20 @@ vsc_build_vf_list(struct VSM_data *vd) ...@@ -324,11 +343,20 @@ vsc_build_vf_list(struct VSM_data *vd)
VSM_FOREACH(&vsc->iter_fantom, vd) { VSM_FOREACH(&vsc->iter_fantom, vd) {
if (strcmp(vsc->iter_fantom.class, VSC_CLASS)) if (strcmp(vsc->iter_fantom.class, VSC_CLASS))
continue; continue;
#define VSC_TYPE_F(n,t,l,e,d) \ u = vbe64dec(vsc->iter_fantom.b);
if (!strcmp(vsc->iter_fantom.type, t)) \ vsc_build_old_vf_list(vsc);
vsc_add_vf(vsc, &vsc->iter_fantom, \ if (u == 0) {
&VSC_type_desc_##n, VSC_type_order_##n); fprintf(stderr, "%s has no JSON\n", vsc->iter_fantom.type);
#include "tbl/vsc_types.h" 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);
} }
} }
......
...@@ -89,7 +89,7 @@ class vscset(object): ...@@ -89,7 +89,7 @@ class vscset(object):
ed["level"] = i.param["level"] ed["level"] = i.param["level"]
ed["1line"] = i.param["oneliner"].strip() ed["1line"] = i.param["oneliner"].strip()
ed["docs"] = i.getdoc() 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" % fo.write("\nstatic const size_t vsc_%s_jsonlen = %dL;\n" %
(self.name, len(s))) (self.name, len(s)))
z = gzip_str(s) z = gzip_str(s)
...@@ -116,14 +116,13 @@ class vscset(object): ...@@ -116,14 +116,13 @@ class vscset(object):
fo = open(fon, "w") fo = open(fon, "w")
genhdr(fo, self.name) genhdr(fo, self.name)
fo.write(self.struct + " {\n") fo.write(self.struct + " {\n")
fo.write("\tuint64_t\tzero;\n")
for i in self.mbrs: for i in self.mbrs:
fo.write("\tuint64_t\t%s;\n" % i.arg) fo.write("\tuint64_t\t%s;\n" % i.arg)
fo.write("};\n") fo.write("};\n")
fo.write("\n"); fo.write("\n");
fo.write(self.struct + " *VSC_" + self.name + "_New") fo.write(self.struct + " *VSC_" + self.name + "_New")
fo.write("(const char *fmt, ...);\n"); 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") fo.write("(" + self.struct + "**);\n")
def emit_c(self): def emit_c(self):
...@@ -162,7 +161,7 @@ class vscset(object): ...@@ -162,7 +161,7 @@ class vscset(object):
fo.write("}\n") fo.write("}\n")
fo.write("\n") fo.write("\n")
fo.write("void\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("(" + self.struct + "**pp)\n")
fo.write("{\n") fo.write("{\n")
fo.write("\n") fo.write("\n")
...@@ -285,8 +284,6 @@ class vsc_file(object): ...@@ -285,8 +284,6 @@ class vsc_file(object):
for i in self.c: for i in self.c:
i.vscset(self.vscset) i.vscset(self.vscset)
print(self.vscset)
def emit_h(self): def emit_h(self):
for i in self.vscset: for i in self.vscset:
i.emit_h() i.emit_h()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment