[master] e60c07c Some VSC functions added
Martin Blix Grydeland
martin at varnish-cache.org
Wed May 15 14:46:13 CEST 2013
commit e60c07cec4e61b6e814ac1b41b3dd3c2ee7ee1b9
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Wed Mar 13 13:37:32 2013 +0100
Some VSC functions added
Add a VSC_Mgt() function to get direct access to the management counters
Add VSC_MgtValid(), VSC_MainValid(), VSC_IterValid() functions that
call VSM_StillValid on the fantom used to produce them.
Use the iter fantom when making the pointer lists, so VSM_IterValid()
returns the right result.
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index f2c4d15..4d21be2 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -59,6 +59,12 @@ int VSC_Arg(struct VSM_data *vd, int arg, const char *opt);
* 1 Handled.
*/
+struct VSC_C_mgt *VSC_Mgt(struct VSM_data *vd);
+ /*
+ * return Management stats structure
+ * returns NULL until management process has finished initialization.
+ */
+
struct VSC_C_main *VSC_Main(struct VSM_data *vd);
/*
* return Main stats structure
@@ -113,6 +119,37 @@ int VSC_Iter(struct VSM_data *vd, VSC_iter_f *func, void *priv);
* 0: Done
*/
+int VSC_MgtValid(struct VSM_data *vd);
+ /*
+ * Call VSM_StillValid on the fantom used to find the management
+ * counters
+ *
+ * Returns:
+ * 0: fantom is not valid any more
+ * 1: fantom is still the same.
+ * 2: a fantom with same dimensions exist.
+ */
+
+int VSC_MainValid(struct VSM_data *vd);
+ /*
+ * Call VSM_StillValid on the fantom used to find the main counters.
+ *
+ * Returns:
+ * 0: fantom is not valid any more
+ * 1: fantom is still the same.
+ * 2: a fantom with same dimensions exist.
+ */
+
+int VSC_IterValid(struct VSM_data *vd);
+ /*
+ * Call VSM_StillValid on the fantom used to produce the last
+ * VSC_Iter results.
+ *
+ * Returns:
+ * 0: fantom is not valid any more
+ * 1: fantom is still the same.
+ */
+
/**********************************************************************
* Precompiled VSC_type_desc's and VSC_desc's for all know VSCs.
*/
diff --git a/lib/libvarnishapi/libvarnishapi.map b/lib/libvarnishapi/libvarnishapi.map
index aef4221..6892b86 100644
--- a/lib/libvarnishapi/libvarnishapi.map
+++ b/lib/libvarnishapi/libvarnishapi.map
@@ -90,5 +90,9 @@ LIBVARNISHAPI_1.3 {
# Functions:
VSM_Abandoned;
VSM_ResetError;
+ VSC_Mgt;
+ VSC_MgtValid;
+ VSC_MainValid;
+ VSC_IterValid;
# Variables:
} LIBVARNISHAPI_1.0;
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index c2054c8..fc35d28 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -92,6 +92,7 @@ struct vsc {
VTAILQ_HEAD(, vsc_vf) vf_list;
VTAILQ_HEAD(, vsc_pt) pt_list;
VTAILQ_HEAD(, vsc_sf) sf_list;
+ struct VSM_fantom mgt_fantom;
struct VSM_fantom main_fantom;
struct VSM_fantom iter_fantom;
};
@@ -261,6 +262,19 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
/*--------------------------------------------------------------------*/
+struct VSC_C_mgt *
+VSC_Mgt(struct VSM_data *vd)
+{
+ struct vsc *vsc = vsc_setup(vd);
+
+ if (!VSM_StillValid(vd, &vsc->mgt_fantom) &&
+ !VSM_Get(vd, &vsc->mgt_fantom, VSC_CLASS, VSC_type_mgt, ""))
+ return (NULL);
+ return ((void*)vsc->mgt_fantom.b);
+}
+
+/*--------------------------------------------------------------------*/
+
struct VSC_C_main *
VSC_Main(struct VSM_data *vd)
{
@@ -276,7 +290,7 @@ VSC_Main(struct VSM_data *vd)
*/
static void
-vsc_add_vf(struct vsc *vsc, struct VSM_fantom *fantom,
+vsc_add_vf(struct vsc *vsc, const struct VSM_fantom *fantom,
const struct VSC_type_desc *desc, int order)
{
struct vsc_vf *vf, *vf2;
@@ -346,18 +360,17 @@ static void
vsc_build_vf_list(struct VSM_data *vd)
{
struct vsc *vsc = vsc_setup(vd);
- struct VSM_fantom fantom;
vsc_delete_pt_list(vsc);
vsc_delete_vf_list(vsc);
- VSM_FOREACH(&fantom, vd) {
- if (strcmp(fantom.class, VSC_CLASS))
+ 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(fantom.type, t)) \
- vsc_add_vf(vsc, &fantom, &VSC_type_desc_##n, \
- VSC_type_order_##n);
+ 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"
#undef VSC_TYPE_F
}
@@ -466,6 +479,47 @@ VSC_Iter(struct VSM_data *vd, VSC_iter_f *func, void *priv)
}
/*--------------------------------------------------------------------
+ */
+
+int
+VSC_MgtValid(struct VSM_data *vd)
+{
+ struct vsc *vsc = vsc_setup(vd);
+ fprintf(stderr, "VSC_MgtValid called priv=%ju\n",
+ vsc->mgt_fantom.priv);
+ return (VSM_StillValid(vd, &vsc->mgt_fantom));
+}
+
+int
+VSC_MainValid(struct VSM_data *vd)
+{
+ struct vsc *vsc = vsc_setup(vd);
+ fprintf(stderr, "VSC_MainValid called priv=%ju\n",
+ vsc->main_fantom.priv);
+ return (VSM_StillValid(vd, &vsc->main_fantom));
+}
+
+int
+VSC_IterValid(struct VSM_data *vd)
+{
+ struct vsc *vsc = vsc_setup(vd);
+ int v;
+ fprintf(stderr, "VSC_IterValid called priv=%ju\n",
+ vsc->iter_fantom.priv);
+ v = VSM_StillValid(vd, &vsc->iter_fantom);
+ if (v == 2) {
+ /* There's been changes, reiteration needed. Clear fantom
+ so subsequent calls will also fail */
+ memset(&vsc->iter_fantom, 0, sizeof vsc->iter_fantom);
+ v = 0;
+ }
+ fprintf(stderr, "VSC_IterValid returns %d priv=%ju\n", v,
+ vsc->iter_fantom.priv);
+
+ return (v);
+}
+
+/*--------------------------------------------------------------------
* Build the static type and point descriptions
*/
More information about the varnish-commit
mailing list