aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2018-02-05 15:29:41 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2018-02-05 23:11:56 +0200
commit3eff9532e5116eab0b465c356fc798ec62e16df7 (patch)
tree4023205648cd8d400cce6a23ee9702a0ebf518e9
parent16c8dfa0c3ffabd61bb07d8b47e63983b8eb94da (diff)
downloadvarnish-mib-3eff9532e5116eab0b465c356fc798ec62e16df7.tar.gz
varnish-mib-3eff9532e5116eab0b465c356fc798ec62e16df7.tar.bz2
Initial rewrite for varnish 5.2
* src/betab.c (backend_dfn): Change type of the vpt array. All uses updated. (backend_clear): No need to release vpt entries now. * src/varnish_mib.mib2c (VarnishMib::MIBTable): Change data table to keep entries of const volatile uint64_t *. (varnish_var_lookup, varnish_get_oid, dict_install): Reflect that change. (vd): Rename to vsm. (dict_load): Change arguments to VSC_Iter (post_config): VSC_New takes no arguments.
-rw-r--r--src/betab.c9
-rw-r--r--src/varnish_mib.mib2c66
2 files changed, 33 insertions, 42 deletions
diff --git a/src/betab.c b/src/betab.c
index 2979f8b..83d77e3 100644
--- a/src/betab.c
+++ b/src/betab.c
@@ -76,28 +76,25 @@ struct backend_dfn {
char vbeIPv4[4];
size_t vbeIPv4_len;
char vbeIPv6[16];
size_t vbeIPv6_len;
u_long vbePort;
- struct VSC_point *vpt[VBE_MAX];
+ const volatile uint64_t *vpt[VBE_MAX];
VTAILQ_ENTRY(backend_dfn) list;
};
static VTAILQ_HEAD(, backend_dfn) backends
= VTAILQ_HEAD_INITIALIZER(backends);
void
backend_clear(void)
{
while (!VTAILQ_EMPTY(&backends)) {
struct backend_dfn *dfn = VTAILQ_FIRST(&backends);
- int i;
- for (i = 0; i < VBE_MAX; i++)
- VSC_Destroy_Point(&dfn->vpt[i]);
VTAILQ_REMOVE(&backends, dfn, list);
free(dfn->vbeIdent);
SNMP_FREE(dfn);
}
}
@@ -124,13 +121,13 @@ backend_register(char const *name, size_t len, char const *param,
dfn->vbeIdent[len] = 0;
dfn->vbeIdent_len = len;
VTAILQ_INSERT_TAIL(&backends, dfn, list);
}
for (i = 0; betab_trans[i].param; i++) {
if (strcmp(betab_trans[i].param, param) == 0) {
- dfn->vpt[i] = VSC_Clone_Point(vpt);
+ dfn->vpt[i] = vpt->ptr;
break;
}
}
}
int
@@ -159,13 +156,13 @@ backendTable_load(netsnmp_cache *cache, void *vmagic)
memcpy(ent->vbeIPv6, dfn->vbeIPv6, ent->vbeIPv6_len);
ent->vbeIPv6_len = dfn->vbeIPv6_len;
ent->vbePort = dfn->vbePort;
for (i = 0; i < VBE_MAX; i++) {
U64 *u = (U64*)((char*)ent + betab_trans[i].off);
- uint64_t n = *(const volatile uint64_t*)dfn->vpt[i]->ptr;
+ uint64_t n = *dfn->vpt[i];
u->high = n >> 32;
u->low = n & 0xffffffff;
}
row = netsnmp_tdata_create_row();
if (!row)
diff --git a/src/varnish_mib.mib2c b/src/varnish_mib.mib2c
index 2b12090..b061022 100644
--- a/src/varnish_mib.mib2c
+++ b/src/varnish_mib.mib2c
@@ -117,13 +117,13 @@ $vars{'varnish_translate_table'} = {
vclAvail => [ DICT => 'MAIN.n_vcl_avail' ],
vclDiscard => [ DICT => 'MAIN.n_vcl_discard' ],
vclFail => [ DICT => 'MAIN.vcl_fail' ],
};
$vars{'varnish_hash_table'} = new VarnishMib::MIBTable(
- 'struct VSC_point *',
+ 'const volatile uint64_t *',
$vars{'varnish_translate_table'},
prefix => 'vmib_', max_collisions => 0
);
my @reset_names;
@@ -199,37 +199,37 @@ int varnish_ban(netsnmp_agent_request_info *reqinfo,
@open ${name}@
/* THIS FILE IS GENERATED AUTOMATICALLY. PLEASE DO NOT EDIT. */
#include "varnish_mib.h"
#include "backend.h"
-static struct vsm *vd;
+static struct vsm *vsm;
static struct vsc *vsc;
static void dict_load(struct vsc *vsc);
int
post_config(int majorID, int minorID, void *serverarg, void *clientarg)
{
- vd = VSM_New();
- if (!vd) {
+ vsm = VSM_New();
+ if (!vsm) {
snmp_log(LOG_ERR, "VSM_New: %s\n", strerror(errno));
return 1;
}
- vsc = VSC_New(vd);
+ vsc = VSC_New();
if (!vsc) {
snmp_log(LOG_ERR, "VSC_New: %s\n", strerror(errno));
return 1;
}
- if (VSM_Attach(vd, 2))
- snmp_log(LOG_ERR, "%s\n", VSM_Error(vd));
+ if (VSM_Attach(vsm, 2))
+ snmp_log(LOG_ERR, "%s\n", VSM_Error(vsm));
dict_load(vsc);
- backend_collect_addr(vd);
+ backend_collect_addr(vsm);
return 0;
}
void
varnish_snmp_init(void)
{
@@ -245,25 +245,25 @@ varnish_snmp_deinit(void)
/* FIXME? */
}
struct vsm *
varnish_get_vsm_data(void)
{
- if (vd) {
- if (VSM_Status(vd) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) {
- DEBUGMSGTL(("$modulename", "reopening vd\n"));
+ if (vsm) {
+ if (VSM_Status(vsm) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) {
+ DEBUGMSGTL(("$modulename", "reopening vsm\n"));
dict_load(vsc);
- backend_collect_addr(vd);
+ backend_collect_addr(vsm);
}
}
- return vd;
+ return vsm;
}
${varnish_hash_table}
-static struct VSC_point **
+static const volatile uint64_t **
varnish_var_lookup(char const *str)
{
if (str) {
int i, h;
h = string_hash(str, vmib_hash_table_size);
@@ -276,39 +276,34 @@ varnish_var_lookup(char const *str)
break;
}
}
return NULL;
}
-static inline struct VSC_point *
+static inline const volatile uint64_t *
varnish_get_oid(int i)
{
return vmib_data_table[i];
}
static void
dict_clear(void)
{
int i;
for (i = 0; i < MAX_VMIB_OID; i++)
- if (vmib_data_table[i])
- VSC_Destroy_Point(&vmib_data_table[i]);
+ vmib_data_table[i] = NULL;
}
-static struct VSC_point const *
+static void
dict_install(struct VSC_point const *pt)
{
- struct VSC_point **ent;
+ const volatile uint64_t **ent;
ent = varnish_var_lookup(pt->name);
- if (!ent)
- return NULL;
- if (*ent)
- VSC_Destroy_Point(ent);
- *ent = VSC_Clone_Point(pt);
- return *ent;
+ if (ent)
+ *ent = pt->ptr;
}
static int
load_cb(void *priv, const struct VSC_point *vpt)
{
AZ(strcmp(vpt->ctype, "uint64_t"));
@@ -316,23 +311,22 @@ load_cb(void *priv, const struct VSC_point *vpt)
char const *name = vpt->name + 4;
char *p = strrchr(name, '.');
if (p) {
backend_register(name, p - name, p + 1, vpt);
}
}
- vpt = dict_install(vpt);
+ dict_install(vpt);
return 0;
}
static void
dict_load(struct vsc *vsc)
{
- struct vsm_fantom fantom = VSM_FANTOM_NULL;
dict_clear();
backend_clear();
- VSC_Iter(vsc, &fantom, load_cb, NULL);
+ VSC_Iter(vsc, vsm, load_cb, NULL);
}
/* Variable handlers.
An instance handler only hands us one request at a time, unwrapping
any eventual GETNEXT requests.
@@ -358,18 +352,18 @@ handle_$i(netsnmp_mib_handler *handler,
return SNMP_ERR_NOSUCHNAME;
switch (reqinfo->mode) {
case MODE_GET:
@if $varnish_type eq 'DICT'@
{
- struct VSC_point *ent = varnish_get_oid($i);
+ const volatile uint64_t *ent = varnish_get_oid($i);
uint64_t val;
if (!ent)
return SNMP_ERR_NOSUCHNAME;
- val = *(uint64_t*)ent->ptr;
+ val = *ent;
@if $i.type eq 'ASN_COUNTER64'@
{
struct counter64 ctr;
ctr.high = val >> 32;
ctr.low = val & 0xffffffff;
snmp_set_var_typed_value(requests->requestvb, $i.type,
@@ -443,48 +437,48 @@ handle_$i(netsnmp_mib_handler *handler,
if (ret != SNMP_ERR_NOERROR)
netsnmp_set_request_error(reqinfo, requests, ret);
break;
case MODE_SET_RESERVE2:
@if $varnish_set_reserve2 ne ''@
- if ($varnish_set_reserve2 (reqinfo, requests, vd)) {
+ if ($varnish_set_reserve2 (reqinfo, requests, vsm)) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
@end@
break;
case MODE_SET_FREE:
@if $varnish_set_free ne ''@
# Free resources allocated in RESERVE1 and/or
# RESERVE2. Something failed somewhere, and the states
# below won't be called.
- $varnish_set_free(reqinfo, requests, vd);
+ $varnish_set_free(reqinfo, requests, vsm);
@end@
break;
case MODE_SET_ACTION:
@if $varnish_set_action ne ''@
- ret = $varnish_set_action(reqinfo, requests, vd);
+ ret = $varnish_set_action(reqinfo, requests, vsm);
if (ret != SNMP_ERR_NOERROR)
netsnmp_set_request_error(reqinfo, requests, ret);
@end@
break;
case MODE_SET_COMMIT:
@if $varnish_set_commit ne ''@
# delete temporary storage
- if ($varnish_set_commit(reqinfo, requests, vd))
+ if ($varnish_set_commit(reqinfo, requests, vsm))
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
@end@
break;
case MODE_SET_UNDO:
@if $varnish_set_undo ne ''@
# UNDO and return to previous value for the object
- if ($varnish_set_undo(reqinfo, requests, vd))
+ if ($varnish_set_undo(reqinfo, requests, vsm))
netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
@end@
break;
@end@
default:
@@ -677,13 +671,13 @@ initialize_table_$i(void)
@end@
/** Initializes the $name module */
void
init_$modulename(void)
{
- if (vd) {
+ if (vsm) {
snmp_log(LOG_ERR, "%s: can't be loaded twice\n", "$modulename");
abort();
}
@foreach $i scalar@
@startperl@
&{$vars{'varnish_translate'}}($vars{'i'});

Return to:

Send suggestions and report system problems to the System administrator.