[5.2] 3b36ac8 Make VSC not own the VSM it operates on.
PÃ¥l Hermunn Johansen
hermunn at varnish-software.com
Fri Sep 15 11:17:11 UTC 2017
commit 3b36ac8e2795026969bca3c2e97d7f7733c86553
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Thu Sep 7 09:38:54 2017 +0000
Make VSC not own the VSM it operates on.
diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c
index 1f24b25..88d2c66 100644
--- a/bin/varnishstat/varnishstat.c
+++ b/bin/varnishstat/varnishstat.c
@@ -74,7 +74,7 @@ do_xml_cb(void *priv, const struct VSC_point * const pt)
}
static void
-do_xml(struct vsc *vsc)
+do_xml(struct vsm *vsm, struct vsc *vsc)
{
char time_stamp[20];
time_t now;
@@ -83,7 +83,7 @@ do_xml(struct vsc *vsc)
now = time(NULL);
(void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now));
printf("<varnishstat timestamp=\"%s\">\n", time_stamp);
- (void)VSC_Iter(vsc, NULL, do_xml_cb, NULL);
+ (void)VSC_Iter(vsc, vsm, NULL, do_xml_cb, NULL);
printf("</varnishstat>\n");
}
@@ -124,7 +124,7 @@ do_json_cb(void *priv, const struct VSC_point * const pt)
}
static void
-do_json(struct vsc *vsc)
+do_json(struct vsm *vsm, struct vsc *vsc)
{
char time_stamp[20];
time_t now;
@@ -137,7 +137,7 @@ do_json(struct vsc *vsc)
(void)strftime(time_stamp, 20, "%Y-%m-%dT%H:%M:%S", localtime(&now));
printf(" \"timestamp\": \"%s\",\n", time_stamp);
- (void)VSC_Iter(vsc, NULL, do_json_cb, &jp);
+ (void)VSC_Iter(vsc, vsm, NULL, do_json_cb, &jp);
printf("\n}\n");
}
@@ -194,15 +194,15 @@ do_once_cb(void *priv, const struct VSC_point * const pt)
}
static void
-do_once(struct vsc *vsc)
+do_once(struct vsm *vsm, struct vsc *vsc)
{
struct once_priv op;
memset(&op, 0, sizeof op);
op.pad = 18;
- (void)VSC_Iter(vsc, NULL, do_once_cb_first, &op);
- (void)VSC_Iter(vsc, NULL, do_once_cb, &op);
+ (void)VSC_Iter(vsc, vsm, NULL, do_once_cb_first, &op);
+ (void)VSC_Iter(vsc, vsm, NULL, do_once_cb, &op);
}
/*--------------------------------------------------------------------*/
@@ -226,13 +226,13 @@ do_list_cb(void *priv, const struct VSC_point * const pt)
}
static void
-list_fields(struct vsc *vsc)
+list_fields(struct vsm *vsm, struct vsc *vsc)
{
printf("Varnishstat -f option fields:\n");
printf("Field name Description\n");
printf("---------- -----------\n");
- (void)VSC_Iter(vsc, NULL, do_list_cb, NULL);
+ (void)VSC_Iter(vsc, vsm, NULL, do_list_cb, NULL);
}
/*--------------------------------------------------------------------*/
@@ -261,7 +261,7 @@ main(int argc, char * const *argv)
VUT_Init(progname, argc, argv, &vopt_spec);
vd = VSM_New();
AN(vd);
- vsc = VSC_New(vd);
+ vsc = VSC_New();
AN(vsc);
while ((opt = getopt(argc, argv, vopt_spec.vopt_optstring)) != -1) {
@@ -284,8 +284,11 @@ main(int argc, char * const *argv)
case 'j':
json = 1;
break;
+ case 'f':
+ AN(VSC_Arg(vsc, opt, optarg));
+ break;
default:
- i = VSC_Arg(vsc, opt, optarg);
+ i = VSM_Arg(vd, opt, optarg);
if (i < 0)
VUT_Error(1, "%s", VSM_Error(vd));
if (!i)
@@ -305,13 +308,13 @@ main(int argc, char * const *argv)
if (curses)
do_curses(vd, vsc, 1.0);
else if (xml)
- do_xml(vsc);
+ do_xml(vd, vsc);
else if (json)
- do_json(vsc);
+ do_json(vd, vsc);
else if (once)
- do_once(vsc);
+ do_once(vd, vsc);
else if (f_list)
- list_fields(vsc);
+ list_fields(vd, vsc);
else
assert(0);
diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c
index 104af2b..f2e34bd 100644
--- a/bin/varnishstat/varnishstat_curses.c
+++ b/bin/varnishstat/varnishstat_curses.c
@@ -313,7 +313,7 @@ build_pt_list_cb(void *priv, const struct VSC_point *vpt)
}
static void
-build_pt_list(struct vsc *vsc, struct vsm_fantom *fantom)
+build_pt_list(struct vsc *vsc, struct vsm *vsm, struct vsm_fantom *fantom)
{
struct pt_priv pt_priv;
int i;
@@ -334,7 +334,7 @@ build_pt_list(struct vsc *vsc, struct vsm_fantom *fantom)
main_cache_hit = NULL;
main_cache_miss = NULL;
- (void)VSC_Iter(vsc, fantom, build_pt_list_cb, &pt_priv);
+ (void)VSC_Iter(vsc, vsm, fantom, build_pt_list_cb, &pt_priv);
delete_pt_list();
AN(VTAILQ_EMPTY(&ptlist));
AZ(n_ptlist);
@@ -1073,7 +1073,7 @@ do_curses(struct vsm *vd, struct vsc *vsc, double delay)
(VSM_Status(vd) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED))) {
init_hitrate();
delete_pt_list();
- build_pt_list(vsc, &f_iter);
+ build_pt_list(vsc, vd, &f_iter);
initial = 0;
}
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 45218bc..e81c054 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -523,13 +523,13 @@ varnish_launch(struct varnish *v)
v->vsm_vsc = VSM_New();
AN(v->vsm_vsc);
- v->vsc = VSC_New(v->vsm_vsc);
+ v->vsc = VSC_New();
AN(v->vsc);
- (void)VSC_Arg(v->vsc, 'n', v->workdir);
+ assert(VSM_Arg(v->vsm_vsc, 'n', v->workdir) > 0);
AZ(VSM_Attach(v->vsm_vsc, -1));
v->vsm_vsl = VSM_New();
- (void)VSM_Arg(v->vsm_vsl, 'n', v->workdir);
+ assert(VSM_Arg(v->vsm_vsl, 'n', v->workdir) > 0);
AZ(VSM_Attach(v->vsm_vsl, -1));
AZ(pthread_create(&v->tp_vsl, NULL, varnishlog_thread, v));
@@ -850,7 +850,7 @@ varnish_vsc(const struct varnish *v, const char *arg)
dp.arg = arg;
(void)VSM_Status(v->vsm_vsc);
- (void)VSC_Iter(v->vsc, NULL, do_stat_dump_cb, &dp);
+ (void)VSC_Iter(v->vsc, v->vsm_vsc, NULL, do_stat_dump_cb, &dp);
}
/**********************************************************************
@@ -916,7 +916,7 @@ varnish_expect(const struct varnish *v, char * const *av)
for (i = 0; i < 50; i++, (void)usleep(100000)) {
(void)VSM_Status(v->vsm_vsc);
- good = VSC_Iter(v->vsc, NULL, do_expect_cb, &sp);
+ good = VSC_Iter(v->vsc, v->vsm_vsc, NULL, do_expect_cb, &sp);
if (!good) {
good = -2;
continue;
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index 97c85e1..986259b 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -45,7 +45,7 @@ struct vsm_fantom;
* VSC level access functions
*/
-struct vsc *VSC_New(struct vsm *);
+struct vsc *VSC_New(void);
void VSC_Destroy(struct vsc **);
int VSC_Arg(struct vsc *, char arg, const char *opt);
@@ -84,7 +84,8 @@ void VSC_Destroy_Point(struct VSC_point **);
typedef int VSC_iter_f(void *priv, const struct VSC_point *const pt);
-int VSC_Iter(struct vsc *, struct vsm_fantom *, VSC_iter_f *func, void *priv);
+int VSC_Iter(struct vsc *, struct vsm *, struct vsm_fantom *,
+ VSC_iter_f *func, void *priv);
/*
* Iterate over all statistics counters, calling "func" for
* each counter not suppressed by any "-f" arguments.
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index de998cf..47a5ccd 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -63,7 +63,6 @@ struct vsc {
unsigned magic;
#define VSC_MAGIC 0x3373554a
- struct vsm *vsm;
struct vsc_sf_head sf_list_include;
struct vsc_sf_head sf_list_exclude;
};
@@ -116,15 +115,13 @@ VSC_Destroy_Point(struct VSC_point **p)
/*--------------------------------------------------------------------*/
struct vsc *
-VSC_New(struct vsm *vsm)
+VSC_New(void)
{
struct vsc *vsc;
- AN(vsm);
ALLOC_OBJ(vsc, VSC_MAGIC);
if (vsc == NULL)
return (vsc);
- vsc->vsm = vsm;
VTAILQ_INIT(&vsc->sf_list_include);
VTAILQ_INIT(&vsc->sf_list_exclude);
return (vsc);
@@ -196,11 +193,7 @@ VSC_Arg(struct vsc *vsc, char arg, const char *opt)
switch (arg) {
case 'f': return (vsc_f_arg(vsc, opt));
- case 'n':
- case 't':
- return (VSM_Arg(vsc->vsm, arg, opt));
- default:
- return (0);
+ default: return (0);
}
}
@@ -345,7 +338,8 @@ vsc_iter_fantom(const struct vsc *vsc, const struct vsm_fantom *fantom,
*/
int __match_proto__() // We don't want vsc to be const
-VSC_Iter(struct vsc *vsc, struct vsm_fantom *f, VSC_iter_f *func, void *priv)
+VSC_Iter(struct vsc *vsc, struct vsm *vsm, struct vsm_fantom *f,
+ VSC_iter_f *func, void *priv)
{
struct vsm_fantom ifantom;
uint64_t u;
@@ -353,12 +347,13 @@ VSC_Iter(struct vsc *vsc, struct vsm_fantom *f, VSC_iter_f *func, void *priv)
struct vsb *vsb;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
+ AN(vsm);
vsb = VSB_new_auto();
AN(vsb);
- VSM_FOREACH(&ifantom, vsc->vsm) {
+ VSM_FOREACH(&ifantom, vsm) {
if (strcmp(ifantom.class, VSC_CLASS))
continue;
- AZ(VSM_Map(vsc->vsm, &ifantom));
+ AZ(VSM_Map(vsm, &ifantom));
u = vbe64dec(ifantom.b);
if (u == 0) {
VRMB();
@@ -370,7 +365,7 @@ VSC_Iter(struct vsc *vsc, struct vsm_fantom *f, VSC_iter_f *func, void *priv)
if (f != NULL) {
*f = ifantom;
} else {
- AZ(VSM_Unmap(vsc->vsm, &ifantom));
+ AZ(VSM_Unmap(vsm, &ifantom));
}
if (i)
break;
More information about the varnish-commit
mailing list