diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-02-05 15:29:41 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2018-02-05 23:11:56 +0200 |
commit | 3eff9532e5116eab0b465c356fc798ec62e16df7 (patch) | |
tree | 4023205648cd8d400cce6a23ee9702a0ebf518e9 | |
parent | 16c8dfa0c3ffabd61bb07d8b47e63983b8eb94da (diff) | |
download | varnish-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.c | 9 | ||||
-rw-r--r-- | src/varnish_mib.mib2c | 66 |
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 @@ -80,5 +80,5 @@ struct backend_dfn { u_long vbePort; - struct VSC_point *vpt[VBE_MAX]; + const volatile uint64_t *vpt[VBE_MAX]; VTAILQ_ENTRY(backend_dfn) list; @@ -93,7 +93,4 @@ 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); @@ -128,5 +125,5 @@ backend_register(char const *name, size_t len, char const *param, 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; } @@ -163,5 +160,5 @@ backendTable_load(netsnmp_cache *cache, void *vmagic) 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; 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 @@ -121,5 +121,5 @@ $vars{'varnish_translate_table'} = { $vars{'varnish_hash_table'} = new VarnishMib::MIBTable( - 'struct VSC_point *', + 'const volatile uint64_t *', $vars{'varnish_translate_table'}, prefix => 'vmib_', max_collisions => 0 @@ -203,5 +203,5 @@ int varnish_ban(netsnmp_agent_request_info *reqinfo, #include "backend.h" -static struct vsm *vd; +static struct vsm *vsm; static struct vsc *vsc; @@ -211,11 +211,11 @@ 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)); @@ -223,9 +223,9 @@ post_config(int majorID, int minorID, void *serverarg, void *clientarg) } - 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; } @@ -249,17 +249,17 @@ 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) { @@ -280,5 +280,5 @@ varnish_var_lookup(char const *str) } -static inline struct VSC_point * +static inline const volatile uint64_t * varnish_get_oid(int i) { @@ -291,20 +291,15 @@ 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; } @@ -320,5 +315,5 @@ load_cb(void *priv, const struct VSC_point *vpt) } } - vpt = dict_install(vpt); + dict_install(vpt); return 0; } @@ -327,8 +322,7 @@ 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); } @@ -362,10 +356,10 @@ handle_$i(netsnmp_mib_handler *handler, @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'@ { @@ -447,5 +441,5 @@ handle_$i(netsnmp_mib_handler *handler, 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); @@ -459,5 +453,5 @@ handle_$i(netsnmp_mib_handler *handler, # 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; @@ -465,5 +459,5 @@ handle_$i(netsnmp_mib_handler *handler, 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); @@ -474,5 +468,5 @@ handle_$i(netsnmp_mib_handler *handler, @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@ @@ -482,5 +476,5 @@ handle_$i(netsnmp_mib_handler *handler, @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@ @@ -681,5 +675,5 @@ void init_$modulename(void) { - if (vd) { + if (vsm) { snmp_log(LOG_ERR, "%s: can't be loaded twice\n", "$modulename"); abort(); |