summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2018-02-05 15:29:41 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2018-02-05 21:11:56 (GMT)
commit3eff9532e5116eab0b465c356fc798ec62e16df7 (patch) (unidiff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -79,7 +79,7 @@ struct backend_dfn {
79 size_t vbeIPv6_len; 79 size_t vbeIPv6_len;
80 u_long vbePort; 80 u_long vbePort;
81 81
82 struct VSC_point *vpt[VBE_MAX]; 82 const volatile uint64_t *vpt[VBE_MAX];
83 83
84 VTAILQ_ENTRY(backend_dfn) list; 84 VTAILQ_ENTRY(backend_dfn) list;
85 }; 85 };
@@ -92,9 +92,6 @@ backend_clear(void)
92{ 92{
93 while (!VTAILQ_EMPTY(&backends)) { 93 while (!VTAILQ_EMPTY(&backends)) {
94 struct backend_dfn *dfn = VTAILQ_FIRST(&backends); 94 struct backend_dfn *dfn = VTAILQ_FIRST(&backends);
95 int i;
96 for (i = 0; i < VBE_MAX; i++)
97 VSC_Destroy_Point(&dfn->vpt[i]);
98 VTAILQ_REMOVE(&backends, dfn, list); 95 VTAILQ_REMOVE(&backends, dfn, list);
99 free(dfn->vbeIdent); 96 free(dfn->vbeIdent);
100 SNMP_FREE(dfn); 97 SNMP_FREE(dfn);
@@ -127,7 +124,7 @@ backend_register(char const *name, size_t len, char const *param,
127 } 124 }
128 for (i = 0; betab_trans[i].param; i++) { 125 for (i = 0; betab_trans[i].param; i++) {
129 if (strcmp(betab_trans[i].param, param) == 0) { 126 if (strcmp(betab_trans[i].param, param) == 0) {
130 dfn->vpt[i] = VSC_Clone_Point(vpt); 127 dfn->vpt[i] = vpt->ptr;
131 break; 128 break;
132 } 129 }
133 } 130 }
@@ -162,7 +159,7 @@ backendTable_load(netsnmp_cache *cache, void *vmagic)
162 159
163 for (i = 0; i < VBE_MAX; i++) { 160 for (i = 0; i < VBE_MAX; i++) {
164 U64 *u = (U64*)((char*)ent + betab_trans[i].off); 161 U64 *u = (U64*)((char*)ent + betab_trans[i].off);
165 uint64_t n = *(const volatile uint64_t*)dfn->vpt[i]->ptr; 162 uint64_t n = *dfn->vpt[i];
166 u->high = n >> 32; 163 u->high = n >> 32;
167 u->low = n & 0xffffffff; 164 u->low = n & 0xffffffff;
168 } 165 }
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'} = {
120}; 120};
121 121
122$vars{'varnish_hash_table'} = new VarnishMib::MIBTable( 122$vars{'varnish_hash_table'} = new VarnishMib::MIBTable(
123 'struct VSC_point *', 123 'const volatile uint64_t *',
124 $vars{'varnish_translate_table'}, 124 $vars{'varnish_translate_table'},
125 prefix => 'vmib_', max_collisions => 0 125 prefix => 'vmib_', max_collisions => 0
126 ); 126 );
@@ -202,7 +202,7 @@ int varnish_ban(netsnmp_agent_request_info *reqinfo,
202#include "varnish_mib.h" 202#include "varnish_mib.h"
203#include "backend.h" 203#include "backend.h"
204 204
205static struct vsm *vd; 205static struct vsm *vsm;
206static struct vsc *vsc; 206static struct vsc *vsc;
207 207
208static void dict_load(struct vsc *vsc); 208static void dict_load(struct vsc *vsc);
@@ -210,23 +210,23 @@ static void dict_load(struct vsc *vsc);
210int 210int
211post_config(int majorID, int minorID, void *serverarg, void *clientarg) 211post_config(int majorID, int minorID, void *serverarg, void *clientarg)
212{ 212{
213 vd = VSM_New(); 213 vsm = VSM_New();
214 if (!vd) { 214 if (!vsm) {
215 snmp_log(LOG_ERR, "VSM_New: %s\n", strerror(errno)); 215 snmp_log(LOG_ERR, "VSM_New: %s\n", strerror(errno));
216 return 1; 216 return 1;
217 } 217 }
218 218
219 vsc = VSC_New(vd); 219 vsc = VSC_New();
220 if (!vsc) { 220 if (!vsc) {
221 snmp_log(LOG_ERR, "VSC_New: %s\n", strerror(errno)); 221 snmp_log(LOG_ERR, "VSC_New: %s\n", strerror(errno));
222 return 1; 222 return 1;
223 } 223 }
224 224
225 if (VSM_Attach(vd, 2)) 225 if (VSM_Attach(vsm, 2))
226 snmp_log(LOG_ERR, "%s\n", VSM_Error(vd)); 226 snmp_log(LOG_ERR, "%s\n", VSM_Error(vsm));
227 227
228 dict_load(vsc); 228 dict_load(vsc);
229 backend_collect_addr(vd); 229 backend_collect_addr(vsm);
230 return 0; 230 return 0;
231} 231}
232 232
@@ -248,19 +248,19 @@ varnish_snmp_deinit(void)
248struct vsm * 248struct vsm *
249varnish_get_vsm_data(void) 249varnish_get_vsm_data(void)
250{ 250{
251 if (vd) { 251 if (vsm) {
252 if (VSM_Status(vd) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) { 252 if (VSM_Status(vsm) & (VSM_MGT_CHANGED|VSM_WRK_CHANGED)) {
253 DEBUGMSGTL(("$modulename", "reopening vd\n")); 253 DEBUGMSGTL(("$modulename", "reopening vsm\n"));
254 dict_load(vsc); 254 dict_load(vsc);
255 backend_collect_addr(vd); 255 backend_collect_addr(vsm);
256 } 256 }
257 } 257 }
258 return vd; 258 return vsm;
259} 259}
260 260
261${varnish_hash_table} 261${varnish_hash_table}
262 262
263static struct VSC_point ** 263static const volatile uint64_t **
264varnish_var_lookup(char const *str) 264varnish_var_lookup(char const *str)
265{ 265{
266 if (str) { 266 if (str) {
@@ -279,7 +279,7 @@ varnish_var_lookup(char const *str)
279 return NULL; 279 return NULL;
280} 280}
281 281
282static inline struct VSC_point * 282static inline const volatile uint64_t *
283varnish_get_oid(int i) 283varnish_get_oid(int i)
284{ 284{
285 return vmib_data_table[i]; 285 return vmib_data_table[i];
@@ -290,22 +290,17 @@ dict_clear(void)
290{ 290{
291 int i; 291 int i;
292 for (i = 0; i < MAX_VMIB_OID; i++) 292 for (i = 0; i < MAX_VMIB_OID; i++)
293 if (vmib_data_table[i]) 293 vmib_data_table[i] = NULL;
294 VSC_Destroy_Point(&vmib_data_table[i]);
295} 294}
296 295
297static struct VSC_point const * 296static void
298dict_install(struct VSC_point const *pt) 297dict_install(struct VSC_point const *pt)
299{ 298{
300 struct VSC_point **ent; 299 const volatile uint64_t **ent;
301 300
302 ent = varnish_var_lookup(pt->name); 301 ent = varnish_var_lookup(pt->name);
303 if (!ent) 302 if (ent)
304 return NULL; 303 *ent = pt->ptr;
305 if (*ent)
306 VSC_Destroy_Point(ent);
307 *ent = VSC_Clone_Point(pt);
308 return *ent;
309} 304}
310 305
311static int 306static int
@@ -319,17 +314,16 @@ load_cb(void *priv, const struct VSC_point *vpt)
319 backend_register(name, p - name, p + 1, vpt); 314 backend_register(name, p - name, p + 1, vpt);
320 } 315 }
321 } 316 }
322 vpt = dict_install(vpt); 317 dict_install(vpt);
323 return 0; 318 return 0;
324} 319}
325 320
326static void 321static void
327dict_load(struct vsc *vsc) 322dict_load(struct vsc *vsc)
328{ 323{
329 struct vsm_fantom fantom = VSM_FANTOM_NULL;
330 dict_clear(); 324 dict_clear();
331 backend_clear(); 325 backend_clear();
332 VSC_Iter(vsc, &fantom, load_cb, NULL); 326 VSC_Iter(vsc, vsm, load_cb, NULL);
333} 327}
334 328
335/* Variable handlers. 329/* Variable handlers.
@@ -361,12 +355,12 @@ handle_$i(netsnmp_mib_handler *handler,
361 case MODE_GET: 355 case MODE_GET:
362 @if $varnish_type eq 'DICT'@ 356 @if $varnish_type eq 'DICT'@
363 { 357 {
364 struct VSC_point *ent = varnish_get_oid($i); 358 const volatile uint64_t *ent = varnish_get_oid($i);
365 uint64_t val; 359 uint64_t val;
366 360
367 if (!ent) 361 if (!ent)
368 return SNMP_ERR_NOSUCHNAME; 362 return SNMP_ERR_NOSUCHNAME;
369 val = *(uint64_t*)ent->ptr; 363 val = *ent;
370 @if $i.type eq 'ASN_COUNTER64'@ 364 @if $i.type eq 'ASN_COUNTER64'@
371 { 365 {
372 struct counter64 ctr; 366 struct counter64 ctr;
@@ -446,7 +440,7 @@ handle_$i(netsnmp_mib_handler *handler,
446 440
447 case MODE_SET_RESERVE2: 441 case MODE_SET_RESERVE2:
448 @if $varnish_set_reserve2 ne ''@ 442 @if $varnish_set_reserve2 ne ''@
449 if ($varnish_set_reserve2 (reqinfo, requests, vd)) { 443 if ($varnish_set_reserve2 (reqinfo, requests, vsm)) {
450 netsnmp_set_request_error(reqinfo, requests, 444 netsnmp_set_request_error(reqinfo, requests,
451 SNMP_ERR_RESOURCEUNAVAILABLE); 445 SNMP_ERR_RESOURCEUNAVAILABLE);
452 } 446 }
@@ -458,13 +452,13 @@ handle_$i(netsnmp_mib_handler *handler,
458 # Free resources allocated in RESERVE1 and/or 452 # Free resources allocated in RESERVE1 and/or
459 # RESERVE2. Something failed somewhere, and the states 453 # RESERVE2. Something failed somewhere, and the states
460 # below won't be called. 454 # below won't be called.
461 $varnish_set_free(reqinfo, requests, vd); 455 $varnish_set_free(reqinfo, requests, vsm);
462 @end@ 456 @end@
463 break; 457 break;
464 458
465 case MODE_SET_ACTION: 459 case MODE_SET_ACTION:
466 @if $varnish_set_action ne ''@ 460 @if $varnish_set_action ne ''@
467 ret = $varnish_set_action(reqinfo, requests, vd); 461 ret = $varnish_set_action(reqinfo, requests, vsm);
468 if (ret != SNMP_ERR_NOERROR) 462 if (ret != SNMP_ERR_NOERROR)
469 netsnmp_set_request_error(reqinfo, requests, ret); 463 netsnmp_set_request_error(reqinfo, requests, ret);
470 @end@ 464 @end@
@@ -473,7 +467,7 @@ handle_$i(netsnmp_mib_handler *handler,
473 case MODE_SET_COMMIT: 467 case MODE_SET_COMMIT:
474 @if $varnish_set_commit ne ''@ 468 @if $varnish_set_commit ne ''@
475 # delete temporary storage 469 # delete temporary storage
476 if ($varnish_set_commit(reqinfo, requests, vd)) 470 if ($varnish_set_commit(reqinfo, requests, vsm))
477 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED); 471 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_COMMITFAILED);
478 @end@ 472 @end@
479 break; 473 break;
@@ -481,7 +475,7 @@ handle_$i(netsnmp_mib_handler *handler,
481 case MODE_SET_UNDO: 475 case MODE_SET_UNDO:
482 @if $varnish_set_undo ne ''@ 476 @if $varnish_set_undo ne ''@
483 # UNDO and return to previous value for the object 477 # UNDO and return to previous value for the object
484 if ($varnish_set_undo(reqinfo, requests, vd)) 478 if ($varnish_set_undo(reqinfo, requests, vsm))
485 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED); 479 netsnmp_set_request_error(reqinfo, requests, SNMP_ERR_UNDOFAILED);
486 @end@ 480 @end@
487 break; 481 break;
@@ -680,7 +674,7 @@ initialize_table_$i(void)
680void 674void
681init_$modulename(void) 675init_$modulename(void)
682{ 676{
683 if (vd) { 677 if (vsm) {
684 snmp_log(LOG_ERR, "%s: can't be loaded twice\n", "$modulename"); 678 snmp_log(LOG_ERR, "%s: can't be loaded twice\n", "$modulename");
685 abort(); 679 abort();
686 } 680 }

Return to:

Send suggestions and report system problems to the System administrator.