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 @@ -79,7 +79,7 @@ struct backend_dfn { 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; }; @@ -92,9 +92,6 @@ 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); @@ -127,7 +124,7 @@ 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; } } @@ -162,7 +159,7 @@ 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 @@ -120,7 +120,7 @@ $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 ); @@ -202,7 +202,7 @@ int varnish_ban(netsnmp_agent_request_info *reqinfo, #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); @@ -210,23 +210,23 @@ 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; } @@ -248,19 +248,19 @@ varnish_snmp_deinit(void) 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) { @@ -279,7 +279,7 @@ varnish_var_lookup(char const *str) return NULL; } -static inline struct VSC_point * +static inline const volatile uint64_t * varnish_get_oid(int i) { return vmib_data_table[i]; @@ -290,22 +290,17 @@ 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 @@ -319,17 +314,16 @@ load_cb(void *priv, const struct VSC_point *vpt) 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. @@ -361,12 +355,12 @@ handle_$i(netsnmp_mib_handler *handler, 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; @@ -446,7 +440,7 @@ 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); } @@ -458,13 +452,13 @@ handle_$i(netsnmp_mib_handler *handler, # 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@ @@ -473,7 +467,7 @@ handle_$i(netsnmp_mib_handler *handler, 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; @@ -481,7 +475,7 @@ handle_$i(netsnmp_mib_handler *handler, 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; @@ -680,7 +674,7 @@ initialize_table_$i(void) void init_$modulename(void) { - if (vd) { + if (vsm) { snmp_log(LOG_ERR, "%s: can't be loaded twice\n", "$modulename"); abort(); } |