Print this page
patch tsoome-feedback
6659 nvlist_free(NULL) is a no-op
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fm/modules/common/eversholt/fme.c
+++ new/usr/src/cmd/fm/modules/common/eversholt/fme.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2012 Milan Jurik. All rights reserved.
25 25 *
26 26 * fme.c -- fault management exercise module
27 27 *
28 28 * this module provides the simulated fault management exercise.
29 29 */
30 30
31 31 #include <stdio.h>
32 32 #include <stdlib.h>
33 33 #include <string.h>
34 34 #include <strings.h>
35 35 #include <ctype.h>
36 36 #include <alloca.h>
37 37 #include <libnvpair.h>
38 38 #include <sys/fm/protocol.h>
39 39 #include <fm/fmd_api.h>
40 40 #include "alloc.h"
41 41 #include "out.h"
42 42 #include "stats.h"
43 43 #include "stable.h"
44 44 #include "literals.h"
45 45 #include "lut.h"
46 46 #include "tree.h"
47 47 #include "ptree.h"
48 48 #include "itree.h"
49 49 #include "ipath.h"
50 50 #include "fme.h"
51 51 #include "evnv.h"
52 52 #include "eval.h"
53 53 #include "config.h"
54 54 #include "platform.h"
55 55 #include "esclex.h"
56 56
57 57 /* imported from eft.c... */
58 58 extern hrtime_t Hesitate;
59 59 extern char *Serd_Override;
60 60 extern nv_alloc_t Eft_nv_hdl;
61 61 extern int Max_fme;
62 62 extern fmd_hdl_t *Hdl;
63 63
64 64 static int Istat_need_save;
65 65 static int Serd_need_save;
66 66 void istat_save(void);
67 67 void serd_save(void);
68 68
69 69 /* fme under construction is global so we can free it on module abort */
70 70 static struct fme *Nfmep;
71 71
72 72 static int Undiag_reason = UD_VAL_UNKNOWN;
73 73
74 74 static int Nextid = 0;
75 75
76 76 static int Open_fme_count = 0; /* Count of open FMEs */
77 77
78 78 /* list of fault management exercises underway */
79 79 static struct fme {
80 80 struct fme *next; /* next exercise */
81 81 unsigned long long ull; /* time when fme was created */
82 82 int id; /* FME id */
83 83 struct config *config; /* cooked configuration data */
84 84 struct lut *eventtree; /* propagation tree for this FME */
85 85 /*
86 86 * The initial error report that created this FME is kept in
87 87 * two forms. e0 points to the instance tree node and is used
88 88 * by fme_eval() as the starting point for the inference
89 89 * algorithm. e0r is the event handle FMD passed to us when
90 90 * the ereport first arrived and is used when setting timers,
91 91 * which are always relative to the time of this initial
92 92 * report.
93 93 */
94 94 struct event *e0;
95 95 fmd_event_t *e0r;
96 96
97 97 id_t timer; /* for setting an fmd time-out */
98 98
99 99 struct event *ecurrent; /* ereport under consideration */
100 100 struct event *suspects; /* current suspect list */
101 101 struct event *psuspects; /* previous suspect list */
102 102 int nsuspects; /* count of suspects */
103 103 int posted_suspects; /* true if we've posted a diagnosis */
104 104 int uniqobs; /* number of unique events observed */
105 105 int peek; /* just peeking, don't track suspects */
106 106 int overflow; /* true if overflow FME */
107 107 enum fme_state {
108 108 FME_NOTHING = 5000, /* not evaluated yet */
109 109 FME_WAIT, /* need to wait for more info */
110 110 FME_CREDIBLE, /* suspect list is credible */
111 111 FME_DISPROVED, /* no valid suspects found */
112 112 FME_DEFERRED /* don't know yet (k-count not met) */
113 113 } state;
114 114
115 115 unsigned long long pull; /* time passed since created */
116 116 unsigned long long wull; /* wait until this time for re-eval */
117 117 struct event *observations; /* observation list */
118 118 struct lut *globals; /* values of global variables */
119 119 /* fmd interfacing */
120 120 fmd_hdl_t *hdl; /* handle for talking with fmd */
121 121 fmd_case_t *fmcase; /* what fmd 'case' we associate with */
122 122 /* stats */
123 123 struct stats *Rcount;
124 124 struct stats *Hcallcount;
125 125 struct stats *Rcallcount;
126 126 struct stats *Ccallcount;
127 127 struct stats *Ecallcount;
128 128 struct stats *Tcallcount;
129 129 struct stats *Marrowcount;
130 130 struct stats *diags;
131 131 } *FMElist, *EFMElist, *ClosedFMEs;
132 132
133 133 static struct case_list {
134 134 fmd_case_t *fmcase;
135 135 struct case_list *next;
136 136 } *Undiagablecaselist;
137 137
138 138 static void fme_eval(struct fme *fmep, fmd_event_t *ffep);
139 139 static enum fme_state hypothesise(struct fme *fmep, struct event *ep,
140 140 unsigned long long at_latest_by, unsigned long long *pdelay);
141 141 static struct node *eventprop_lookup(struct event *ep, const char *propname);
142 142 static struct node *pathstring2epnamenp(char *path);
143 143 static void publish_undiagnosable(fmd_hdl_t *hdl, fmd_event_t *ffep,
144 144 fmd_case_t *fmcase, nvlist_t *detector, char *arg);
145 145 static char *undiag_2reason_str(int ud, char *arg);
146 146 static const char *undiag_2defect_str(int ud);
147 147 static void restore_suspects(struct fme *fmep);
148 148 static void save_suspects(struct fme *fmep);
149 149 static void destroy_fme(struct fme *f);
150 150 static void fme_receive_report(fmd_hdl_t *hdl, fmd_event_t *ffep,
151 151 const char *eventstring, const struct ipath *ipp, nvlist_t *nvl);
152 152 static void istat_counter_reset_cb(struct istat_entry *entp,
153 153 struct stats *statp, const struct ipath *ipp);
154 154 static void istat_counter_topo_chg_cb(struct istat_entry *entp,
155 155 struct stats *statp, void *unused);
156 156 static void serd_reset_cb(struct serd_entry *entp, void *unused,
157 157 const struct ipath *ipp);
158 158 static void serd_topo_chg_cb(struct serd_entry *entp, void *unused,
159 159 void *unused2);
160 160 static void destroy_fme_bufs(struct fme *fp);
161 161
162 162 static struct fme *
163 163 alloc_fme(void)
164 164 {
165 165 struct fme *fmep;
166 166
167 167 fmep = MALLOC(sizeof (*fmep));
168 168 bzero(fmep, sizeof (*fmep));
169 169 return (fmep);
170 170 }
171 171
172 172 /*
173 173 * fme_ready -- called when all initialization of the FME (except for
174 174 * stats) has completed successfully. Adds the fme to global lists
175 175 * and establishes its stats.
176 176 */
177 177 static struct fme *
178 178 fme_ready(struct fme *fmep)
179 179 {
180 180 char nbuf[100];
181 181
182 182 Nfmep = NULL; /* don't need to free this on module abort now */
183 183
184 184 if (EFMElist) {
185 185 EFMElist->next = fmep;
186 186 EFMElist = fmep;
187 187 } else
188 188 FMElist = EFMElist = fmep;
189 189
190 190 (void) sprintf(nbuf, "fme%d.Rcount", fmep->id);
191 191 fmep->Rcount = stats_new_counter(nbuf, "ereports received", 0);
192 192 (void) sprintf(nbuf, "fme%d.Hcall", fmep->id);
193 193 fmep->Hcallcount = stats_new_counter(nbuf, "calls to hypothesise()", 1);
194 194 (void) sprintf(nbuf, "fme%d.Rcall", fmep->id);
195 195 fmep->Rcallcount = stats_new_counter(nbuf,
196 196 "calls to requirements_test()", 1);
197 197 (void) sprintf(nbuf, "fme%d.Ccall", fmep->id);
198 198 fmep->Ccallcount = stats_new_counter(nbuf, "calls to causes_test()", 1);
199 199 (void) sprintf(nbuf, "fme%d.Ecall", fmep->id);
200 200 fmep->Ecallcount =
201 201 stats_new_counter(nbuf, "calls to effects_test()", 1);
202 202 (void) sprintf(nbuf, "fme%d.Tcall", fmep->id);
203 203 fmep->Tcallcount = stats_new_counter(nbuf, "calls to triggered()", 1);
204 204 (void) sprintf(nbuf, "fme%d.Marrow", fmep->id);
205 205 fmep->Marrowcount = stats_new_counter(nbuf,
206 206 "arrows marked by mark_arrows()", 1);
207 207 (void) sprintf(nbuf, "fme%d.diags", fmep->id);
208 208 fmep->diags = stats_new_counter(nbuf, "suspect lists diagnosed", 0);
209 209
210 210 out(O_ALTFP|O_VERB2, "newfme: config snapshot contains...");
211 211 config_print(O_ALTFP|O_VERB2, fmep->config);
212 212
213 213 return (fmep);
214 214 }
215 215
216 216 extern void ipath_dummy_lut(struct arrow *);
217 217 extern struct lut *itree_create_dummy(const char *, const struct ipath *);
218 218
219 219 /* ARGSUSED */
220 220 static void
221 221 set_needed_arrows(struct event *ep, struct event *ep2, struct fme *fmep)
222 222 {
223 223 struct bubble *bp;
224 224 struct arrowlist *ap;
225 225
226 226 for (bp = itree_next_bubble(ep, NULL); bp;
227 227 bp = itree_next_bubble(ep, bp)) {
228 228 if (bp->t != B_FROM)
229 229 continue;
230 230 for (ap = itree_next_arrow(bp, NULL); ap;
231 231 ap = itree_next_arrow(bp, ap)) {
232 232 ap->arrowp->pnode->u.arrow.needed = 1;
233 233 ipath_dummy_lut(ap->arrowp);
234 234 }
235 235 }
236 236 }
237 237
238 238 /* ARGSUSED */
239 239 static void
240 240 unset_needed_arrows(struct event *ep, struct event *ep2, struct fme *fmep)
241 241 {
242 242 struct bubble *bp;
243 243 struct arrowlist *ap;
244 244
245 245 for (bp = itree_next_bubble(ep, NULL); bp;
246 246 bp = itree_next_bubble(ep, bp)) {
247 247 if (bp->t != B_FROM)
248 248 continue;
249 249 for (ap = itree_next_arrow(bp, NULL); ap;
250 250 ap = itree_next_arrow(bp, ap))
251 251 ap->arrowp->pnode->u.arrow.needed = 0;
252 252 }
253 253 }
254 254
255 255 static void globals_destructor(void *left, void *right, void *arg);
256 256 static void clear_arrows(struct event *ep, struct event *ep2, struct fme *fmep);
257 257
258 258 static boolean_t
259 259 prune_propagations(const char *e0class, const struct ipath *e0ipp)
260 260 {
261 261 char nbuf[100];
262 262 unsigned long long my_delay = TIMEVAL_EVENTUALLY;
263 263 extern struct lut *Usednames;
264 264
265 265 Nfmep = alloc_fme();
266 266 Nfmep->id = Nextid;
267 267 Nfmep->state = FME_NOTHING;
268 268 Nfmep->eventtree = itree_create_dummy(e0class, e0ipp);
269 269 if ((Nfmep->e0 =
270 270 itree_lookup(Nfmep->eventtree, e0class, e0ipp)) == NULL) {
271 271 itree_free(Nfmep->eventtree);
272 272 FREE(Nfmep);
273 273 Nfmep = NULL;
274 274 return (B_FALSE);
275 275 }
276 276 Nfmep->ecurrent = Nfmep->observations = Nfmep->e0;
277 277 Nfmep->e0->count++;
278 278
279 279 (void) sprintf(nbuf, "fme%d.Rcount", Nfmep->id);
280 280 Nfmep->Rcount = stats_new_counter(nbuf, "ereports received", 0);
281 281 (void) sprintf(nbuf, "fme%d.Hcall", Nfmep->id);
282 282 Nfmep->Hcallcount =
283 283 stats_new_counter(nbuf, "calls to hypothesise()", 1);
284 284 (void) sprintf(nbuf, "fme%d.Rcall", Nfmep->id);
285 285 Nfmep->Rcallcount = stats_new_counter(nbuf,
286 286 "calls to requirements_test()", 1);
287 287 (void) sprintf(nbuf, "fme%d.Ccall", Nfmep->id);
288 288 Nfmep->Ccallcount =
289 289 stats_new_counter(nbuf, "calls to causes_test()", 1);
290 290 (void) sprintf(nbuf, "fme%d.Ecall", Nfmep->id);
291 291 Nfmep->Ecallcount =
292 292 stats_new_counter(nbuf, "calls to effects_test()", 1);
293 293 (void) sprintf(nbuf, "fme%d.Tcall", Nfmep->id);
294 294 Nfmep->Tcallcount = stats_new_counter(nbuf, "calls to triggered()", 1);
295 295 (void) sprintf(nbuf, "fme%d.Marrow", Nfmep->id);
296 296 Nfmep->Marrowcount = stats_new_counter(nbuf,
297 297 "arrows marked by mark_arrows()", 1);
298 298 (void) sprintf(nbuf, "fme%d.diags", Nfmep->id);
299 299 Nfmep->diags = stats_new_counter(nbuf, "suspect lists diagnosed", 0);
300 300
301 301 Nfmep->peek = 1;
302 302 lut_walk(Nfmep->eventtree, (lut_cb)unset_needed_arrows, (void *)Nfmep);
303 303 lut_free(Usednames, NULL, NULL);
304 304 Usednames = NULL;
305 305 lut_walk(Nfmep->eventtree, (lut_cb)clear_arrows, (void *)Nfmep);
306 306 (void) hypothesise(Nfmep, Nfmep->e0, Nfmep->ull, &my_delay);
307 307 itree_prune(Nfmep->eventtree);
308 308 lut_walk(Nfmep->eventtree, (lut_cb)set_needed_arrows, (void *)Nfmep);
309 309
310 310 stats_delete(Nfmep->Rcount);
311 311 stats_delete(Nfmep->Hcallcount);
312 312 stats_delete(Nfmep->Rcallcount);
313 313 stats_delete(Nfmep->Ccallcount);
314 314 stats_delete(Nfmep->Ecallcount);
315 315 stats_delete(Nfmep->Tcallcount);
316 316 stats_delete(Nfmep->Marrowcount);
317 317 stats_delete(Nfmep->diags);
318 318 itree_free(Nfmep->eventtree);
319 319 lut_free(Nfmep->globals, globals_destructor, NULL);
320 320 FREE(Nfmep);
321 321 return (B_TRUE);
322 322 }
323 323
324 324 static struct fme *
325 325 newfme(const char *e0class, const struct ipath *e0ipp, fmd_hdl_t *hdl,
326 326 fmd_case_t *fmcase, fmd_event_t *ffep, nvlist_t *nvl)
327 327 {
328 328 struct cfgdata *cfgdata;
329 329 int init_size;
330 330 extern int alloc_total();
331 331 nvlist_t *detector = NULL;
332 332 char *pathstr;
333 333 char *arg;
334 334
335 335 /*
336 336 * First check if e0ipp is actually in the topology so we can give a
337 337 * more useful error message.
338 338 */
339 339 ipathlastcomp(e0ipp);
340 340 pathstr = ipath2str(NULL, e0ipp);
341 341 cfgdata = config_snapshot();
342 342 platform_units_translate(0, cfgdata->cooked, NULL, NULL,
343 343 &detector, pathstr);
344 344 FREE(pathstr);
345 345 structconfig_free(cfgdata->cooked);
346 346 config_free(cfgdata);
347 347 if (detector == NULL) {
348 348 /* See if class permits silent discard on unknown component. */
349 349 if (lut_lookup(Ereportenames_discard, (void *)e0class, NULL)) {
350 350 out(O_ALTFP|O_VERB2, "Unable to map \"%s\" ereport "
351 351 "to component path, but silent discard allowed.",
352 352 e0class);
353 353 } else {
354 354 Undiag_reason = UD_VAL_BADEVENTPATH;
355 355 (void) nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR,
356 356 &detector);
357 357 arg = ipath2str(e0class, e0ipp);
358 358 publish_undiagnosable(hdl, ffep, fmcase, detector, arg);
359 359 FREE(arg);
360 360 }
361 361 return (NULL);
362 362 }
363 363
364 364 /*
365 365 * Next run a quick first pass of the rules with a dummy config. This
366 366 * allows us to prune those rules which can't possibly cause this
367 367 * ereport.
368 368 */
369 369 if (!prune_propagations(e0class, e0ipp)) {
370 370 /*
371 371 * The fault class must have been in the rules or we would
372 372 * not have registered for it (and got a "nosub"), and the
373 373 * pathname must be in the topology or we would have failed the
374 374 * previous test. So to get here means the combination of
375 375 * class and pathname in the ereport must be invalid.
376 376 */
377 377 Undiag_reason = UD_VAL_BADEVENTCLASS;
378 378 arg = ipath2str(e0class, e0ipp);
379 379 publish_undiagnosable(hdl, ffep, fmcase, detector, arg);
380 380 nvlist_free(detector);
381 381 FREE(arg);
382 382 return (NULL);
383 383 }
384 384
385 385 /*
386 386 * Now go ahead and create the real fme using the pruned rules.
387 387 */
388 388 init_size = alloc_total();
389 389 out(O_ALTFP|O_STAMP, "start config_snapshot using %d bytes", init_size);
390 390 nvlist_free(detector);
391 391 pathstr = ipath2str(NULL, e0ipp);
392 392 cfgdata = config_snapshot();
393 393 platform_units_translate(0, cfgdata->cooked, NULL, NULL,
394 394 &detector, pathstr);
395 395 FREE(pathstr);
396 396 platform_save_config(hdl, fmcase);
397 397 out(O_ALTFP|O_STAMP, "config_snapshot added %d bytes",
398 398 alloc_total() - init_size);
399 399
400 400 Nfmep = alloc_fme();
401 401
402 402 Nfmep->id = Nextid++;
403 403 Nfmep->config = cfgdata->cooked;
404 404 config_free(cfgdata);
405 405 Nfmep->posted_suspects = 0;
406 406 Nfmep->uniqobs = 0;
407 407 Nfmep->state = FME_NOTHING;
408 408 Nfmep->pull = 0ULL;
409 409 Nfmep->overflow = 0;
410 410
411 411 Nfmep->fmcase = fmcase;
412 412 Nfmep->hdl = hdl;
413 413
414 414 if ((Nfmep->eventtree = itree_create(Nfmep->config)) == NULL) {
415 415 Undiag_reason = UD_VAL_INSTFAIL;
416 416 arg = ipath2str(e0class, e0ipp);
417 417 publish_undiagnosable(hdl, ffep, fmcase, detector, arg);
418 418 nvlist_free(detector);
419 419 FREE(arg);
420 420 structconfig_free(Nfmep->config);
421 421 destroy_fme_bufs(Nfmep);
422 422 FREE(Nfmep);
423 423 Nfmep = NULL;
424 424 return (NULL);
425 425 }
426 426
427 427 itree_ptree(O_ALTFP|O_VERB2, Nfmep->eventtree);
428 428
429 429 if ((Nfmep->e0 =
430 430 itree_lookup(Nfmep->eventtree, e0class, e0ipp)) == NULL) {
431 431 Undiag_reason = UD_VAL_BADEVENTI;
432 432 arg = ipath2str(e0class, e0ipp);
433 433 publish_undiagnosable(hdl, ffep, fmcase, detector, arg);
434 434 nvlist_free(detector);
435 435 FREE(arg);
436 436 itree_free(Nfmep->eventtree);
437 437 structconfig_free(Nfmep->config);
438 438 destroy_fme_bufs(Nfmep);
439 439 FREE(Nfmep);
440 440 Nfmep = NULL;
441 441 return (NULL);
442 442 }
443 443
444 444 nvlist_free(detector);
445 445 return (fme_ready(Nfmep));
446 446 }
447 447
448 448 void
449 449 fme_fini(void)
450 450 {
451 451 struct fme *sfp, *fp;
452 452 struct case_list *ucasep, *nextcasep;
453 453
454 454 ucasep = Undiagablecaselist;
455 455 while (ucasep != NULL) {
456 456 nextcasep = ucasep->next;
457 457 FREE(ucasep);
458 458 ucasep = nextcasep;
459 459 }
460 460 Undiagablecaselist = NULL;
461 461
462 462 /* clean up closed fmes */
463 463 fp = ClosedFMEs;
464 464 while (fp != NULL) {
465 465 sfp = fp->next;
466 466 destroy_fme(fp);
467 467 fp = sfp;
468 468 }
469 469 ClosedFMEs = NULL;
470 470
471 471 fp = FMElist;
472 472 while (fp != NULL) {
473 473 sfp = fp->next;
474 474 destroy_fme(fp);
475 475 fp = sfp;
476 476 }
477 477 FMElist = EFMElist = NULL;
478 478
479 479 /* if we were in the middle of creating an fme, free it now */
480 480 if (Nfmep) {
481 481 destroy_fme(Nfmep);
482 482 Nfmep = NULL;
483 483 }
484 484 }
485 485
486 486 /*
487 487 * Allocated space for a buffer name. 20 bytes allows for
488 488 * a ridiculous 9,999,999 unique observations.
489 489 */
490 490 #define OBBUFNMSZ 20
491 491
492 492 /*
493 493 * serialize_observation
494 494 *
495 495 * Create a recoverable version of the current observation
496 496 * (f->ecurrent). We keep a serialized version of each unique
497 497 * observation in order that we may resume correctly the fme in the
498 498 * correct state if eft or fmd crashes and we're restarted.
499 499 */
500 500 static void
501 501 serialize_observation(struct fme *fp, const char *cls, const struct ipath *ipp)
502 502 {
503 503 size_t pkdlen;
504 504 char tmpbuf[OBBUFNMSZ];
505 505 char *pkd = NULL;
506 506 char *estr;
507 507
508 508 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", fp->uniqobs);
509 509 estr = ipath2str(cls, ipp);
510 510 fmd_buf_create(fp->hdl, fp->fmcase, tmpbuf, strlen(estr) + 1);
511 511 fmd_buf_write(fp->hdl, fp->fmcase, tmpbuf, (void *)estr,
512 512 strlen(estr) + 1);
513 513 FREE(estr);
514 514
515 515 if (fp->ecurrent != NULL && fp->ecurrent->nvp != NULL) {
516 516 (void) snprintf(tmpbuf,
517 517 OBBUFNMSZ, "observed%d.nvp", fp->uniqobs);
518 518 if (nvlist_xpack(fp->ecurrent->nvp,
519 519 &pkd, &pkdlen, NV_ENCODE_XDR, &Eft_nv_hdl) != 0)
520 520 out(O_DIE|O_SYS, "pack of observed nvl failed");
521 521 fmd_buf_create(fp->hdl, fp->fmcase, tmpbuf, pkdlen);
522 522 fmd_buf_write(fp->hdl, fp->fmcase, tmpbuf, (void *)pkd, pkdlen);
523 523 FREE(pkd);
524 524 }
525 525
526 526 fp->uniqobs++;
527 527 fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_NOBS, (void *)&fp->uniqobs,
528 528 sizeof (fp->uniqobs));
529 529 }
530 530
531 531 /*
532 532 * init_fme_bufs -- We keep several bits of state about an fme for
533 533 * use if eft or fmd crashes and we're restarted.
534 534 */
535 535 static void
536 536 init_fme_bufs(struct fme *fp)
537 537 {
538 538 fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_PULL, sizeof (fp->pull));
539 539 fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_PULL, (void *)&fp->pull,
540 540 sizeof (fp->pull));
541 541
542 542 fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_ID, sizeof (fp->id));
543 543 fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_ID, (void *)&fp->id,
544 544 sizeof (fp->id));
545 545
546 546 fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_NOBS, sizeof (fp->uniqobs));
547 547 fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_NOBS, (void *)&fp->uniqobs,
548 548 sizeof (fp->uniqobs));
549 549
550 550 fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_POSTD,
551 551 sizeof (fp->posted_suspects));
552 552 fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_POSTD,
553 553 (void *)&fp->posted_suspects, sizeof (fp->posted_suspects));
554 554 }
555 555
556 556 static void
557 557 destroy_fme_bufs(struct fme *fp)
558 558 {
559 559 char tmpbuf[OBBUFNMSZ];
560 560 int o;
561 561
562 562 platform_restore_config(fp->hdl, fp->fmcase);
563 563 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_CFGLEN);
564 564 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_CFG);
565 565 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_PULL);
566 566 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_ID);
567 567 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_POSTD);
568 568 fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_NOBS);
569 569
570 570 for (o = 0; o < fp->uniqobs; o++) {
571 571 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", o);
572 572 fmd_buf_destroy(fp->hdl, fp->fmcase, tmpbuf);
573 573 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d.nvp", o);
574 574 fmd_buf_destroy(fp->hdl, fp->fmcase, tmpbuf);
575 575 }
576 576 }
577 577
578 578 /*
579 579 * reconstitute_observations -- convert a case's serialized observations
580 580 * back into struct events. Returns zero if all observations are
581 581 * successfully reconstituted.
582 582 */
583 583 static int
584 584 reconstitute_observations(struct fme *fmep)
585 585 {
586 586 struct event *ep;
587 587 struct node *epnamenp = NULL;
588 588 size_t pkdlen;
589 589 char *pkd = NULL;
590 590 char *tmpbuf = alloca(OBBUFNMSZ);
591 591 char *sepptr;
592 592 char *estr;
593 593 int ocnt;
594 594 int elen;
595 595
596 596 for (ocnt = 0; ocnt < fmep->uniqobs; ocnt++) {
597 597 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", ocnt);
598 598 elen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf);
599 599 if (elen == 0) {
600 600 out(O_ALTFP,
601 601 "reconstitute_observation: no %s buffer found.",
602 602 tmpbuf);
603 603 Undiag_reason = UD_VAL_MISSINGOBS;
604 604 break;
605 605 }
606 606
607 607 estr = MALLOC(elen);
608 608 fmd_buf_read(fmep->hdl, fmep->fmcase, tmpbuf, estr, elen);
609 609 sepptr = strchr(estr, '@');
610 610 if (sepptr == NULL) {
611 611 out(O_ALTFP,
612 612 "reconstitute_observation: %s: "
613 613 "missing @ separator in %s.",
614 614 tmpbuf, estr);
615 615 Undiag_reason = UD_VAL_MISSINGPATH;
616 616 FREE(estr);
617 617 break;
618 618 }
619 619
620 620 *sepptr = '\0';
621 621 if ((epnamenp = pathstring2epnamenp(sepptr + 1)) == NULL) {
622 622 out(O_ALTFP,
623 623 "reconstitute_observation: %s: "
624 624 "trouble converting path string \"%s\" "
625 625 "to internal representation.",
626 626 tmpbuf, sepptr + 1);
627 627 Undiag_reason = UD_VAL_MISSINGPATH;
628 628 FREE(estr);
629 629 break;
630 630 }
631 631
632 632 /* construct the event */
633 633 ep = itree_lookup(fmep->eventtree,
634 634 stable(estr), ipath(epnamenp));
635 635 if (ep == NULL) {
636 636 out(O_ALTFP,
637 637 "reconstitute_observation: %s: "
638 638 "lookup of \"%s\" in itree failed.",
639 639 tmpbuf, ipath2str(estr, ipath(epnamenp)));
640 640 Undiag_reason = UD_VAL_BADOBS;
641 641 tree_free(epnamenp);
642 642 FREE(estr);
643 643 break;
644 644 }
645 645 tree_free(epnamenp);
646 646
647 647 /*
648 648 * We may or may not have a saved nvlist for the observation
649 649 */
650 650 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d.nvp", ocnt);
651 651 pkdlen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf);
652 652 if (pkdlen != 0) {
653 653 pkd = MALLOC(pkdlen);
654 654 fmd_buf_read(fmep->hdl,
655 655 fmep->fmcase, tmpbuf, pkd, pkdlen);
656 656 ASSERT(ep->nvp == NULL);
657 657 if (nvlist_xunpack(pkd,
658 658 pkdlen, &ep->nvp, &Eft_nv_hdl) != 0)
659 659 out(O_DIE|O_SYS, "pack of observed nvl failed");
660 660 FREE(pkd);
661 661 }
662 662
663 663 if (ocnt == 0)
664 664 fmep->e0 = ep;
665 665
666 666 FREE(estr);
667 667 fmep->ecurrent = ep;
668 668 ep->count++;
669 669
670 670 /* link it into list of observations seen */
671 671 ep->observations = fmep->observations;
672 672 fmep->observations = ep;
673 673 }
674 674
675 675 if (ocnt == fmep->uniqobs) {
676 676 (void) fme_ready(fmep);
677 677 return (0);
678 678 }
679 679
680 680 return (1);
681 681 }
682 682
683 683 /*
684 684 * restart_fme -- called during eft initialization. Reconstitutes
685 685 * an in-progress fme.
686 686 */
687 687 void
688 688 fme_restart(fmd_hdl_t *hdl, fmd_case_t *inprogress)
689 689 {
690 690 nvlist_t *defect;
691 691 struct case_list *bad;
692 692 struct fme *fmep;
693 693 struct cfgdata *cfgdata;
694 694 size_t rawsz;
695 695 struct event *ep;
696 696 char *tmpbuf = alloca(OBBUFNMSZ);
697 697 char *sepptr;
698 698 char *estr;
699 699 int elen;
700 700 struct node *epnamenp = NULL;
701 701 int init_size;
702 702 extern int alloc_total();
703 703 char *reason;
704 704
705 705 /*
706 706 * ignore solved or closed cases
707 707 */
708 708 if (fmd_case_solved(hdl, inprogress) ||
709 709 fmd_case_closed(hdl, inprogress))
710 710 return;
711 711
712 712 fmep = alloc_fme();
713 713 fmep->fmcase = inprogress;
714 714 fmep->hdl = hdl;
715 715
716 716 if (fmd_buf_size(hdl, inprogress, WOBUF_POSTD) == 0) {
717 717 out(O_ALTFP, "restart_fme: no saved posted status");
718 718 Undiag_reason = UD_VAL_MISSINGINFO;
719 719 goto badcase;
720 720 } else {
721 721 fmd_buf_read(hdl, inprogress, WOBUF_POSTD,
722 722 (void *)&fmep->posted_suspects,
723 723 sizeof (fmep->posted_suspects));
724 724 }
725 725
726 726 if (fmd_buf_size(hdl, inprogress, WOBUF_ID) == 0) {
727 727 out(O_ALTFP, "restart_fme: no saved id");
728 728 Undiag_reason = UD_VAL_MISSINGINFO;
729 729 goto badcase;
730 730 } else {
731 731 fmd_buf_read(hdl, inprogress, WOBUF_ID, (void *)&fmep->id,
732 732 sizeof (fmep->id));
733 733 }
734 734 if (Nextid <= fmep->id)
735 735 Nextid = fmep->id + 1;
736 736
737 737 out(O_ALTFP, "Replay FME %d", fmep->id);
738 738
739 739 if (fmd_buf_size(hdl, inprogress, WOBUF_CFGLEN) != sizeof (size_t)) {
740 740 out(O_ALTFP, "restart_fme: No config data");
741 741 Undiag_reason = UD_VAL_MISSINGINFO;
742 742 goto badcase;
743 743 }
744 744 fmd_buf_read(hdl, inprogress, WOBUF_CFGLEN, (void *)&rawsz,
745 745 sizeof (size_t));
746 746
747 747 if ((fmep->e0r = fmd_case_getprincipal(hdl, inprogress)) == NULL) {
748 748 out(O_ALTFP, "restart_fme: No event zero");
749 749 Undiag_reason = UD_VAL_MISSINGZERO;
750 750 goto badcase;
751 751 }
752 752
753 753 if (fmd_buf_size(hdl, inprogress, WOBUF_PULL) == 0) {
754 754 out(O_ALTFP, "restart_fme: no saved wait time");
755 755 Undiag_reason = UD_VAL_MISSINGINFO;
756 756 goto badcase;
757 757 } else {
758 758 fmd_buf_read(hdl, inprogress, WOBUF_PULL, (void *)&fmep->pull,
759 759 sizeof (fmep->pull));
760 760 }
761 761
762 762 if (fmd_buf_size(hdl, inprogress, WOBUF_NOBS) == 0) {
763 763 out(O_ALTFP, "restart_fme: no count of observations");
764 764 Undiag_reason = UD_VAL_MISSINGINFO;
765 765 goto badcase;
766 766 } else {
767 767 fmd_buf_read(hdl, inprogress, WOBUF_NOBS,
768 768 (void *)&fmep->uniqobs, sizeof (fmep->uniqobs));
769 769 }
770 770
771 771 (void) snprintf(tmpbuf, OBBUFNMSZ, "observed0");
772 772 elen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf);
773 773 if (elen == 0) {
774 774 out(O_ALTFP, "reconstitute_observation: no %s buffer found.",
775 775 tmpbuf);
776 776 Undiag_reason = UD_VAL_MISSINGOBS;
777 777 goto badcase;
778 778 }
779 779 estr = MALLOC(elen);
780 780 fmd_buf_read(fmep->hdl, fmep->fmcase, tmpbuf, estr, elen);
781 781 sepptr = strchr(estr, '@');
782 782 if (sepptr == NULL) {
783 783 out(O_ALTFP, "reconstitute_observation: %s: "
784 784 "missing @ separator in %s.",
785 785 tmpbuf, estr);
786 786 Undiag_reason = UD_VAL_MISSINGPATH;
787 787 FREE(estr);
788 788 goto badcase;
789 789 }
790 790 *sepptr = '\0';
791 791 if ((epnamenp = pathstring2epnamenp(sepptr + 1)) == NULL) {
792 792 out(O_ALTFP, "reconstitute_observation: %s: "
793 793 "trouble converting path string \"%s\" "
794 794 "to internal representation.", tmpbuf, sepptr + 1);
795 795 Undiag_reason = UD_VAL_MISSINGPATH;
796 796 FREE(estr);
797 797 goto badcase;
798 798 }
799 799 (void) prune_propagations(stable(estr), ipath(epnamenp));
800 800 tree_free(epnamenp);
801 801 FREE(estr);
802 802
803 803 init_size = alloc_total();
804 804 out(O_ALTFP|O_STAMP, "start config_restore using %d bytes", init_size);
805 805 cfgdata = MALLOC(sizeof (struct cfgdata));
806 806 cfgdata->cooked = NULL;
807 807 cfgdata->devcache = NULL;
808 808 cfgdata->devidcache = NULL;
809 809 cfgdata->tpcache = NULL;
810 810 cfgdata->cpucache = NULL;
811 811 cfgdata->raw_refcnt = 1;
812 812
813 813 if (rawsz > 0) {
814 814 if (fmd_buf_size(hdl, inprogress, WOBUF_CFG) != rawsz) {
815 815 out(O_ALTFP, "restart_fme: Config data size mismatch");
816 816 Undiag_reason = UD_VAL_CFGMISMATCH;
817 817 goto badcase;
818 818 }
819 819 cfgdata->begin = MALLOC(rawsz);
820 820 cfgdata->end = cfgdata->nextfree = cfgdata->begin + rawsz;
821 821 fmd_buf_read(hdl,
822 822 inprogress, WOBUF_CFG, cfgdata->begin, rawsz);
823 823 } else {
824 824 cfgdata->begin = cfgdata->end = cfgdata->nextfree = NULL;
825 825 }
826 826
827 827 config_cook(cfgdata);
828 828 fmep->config = cfgdata->cooked;
829 829 config_free(cfgdata);
830 830 out(O_ALTFP|O_STAMP, "config_restore added %d bytes",
831 831 alloc_total() - init_size);
832 832
833 833 if ((fmep->eventtree = itree_create(fmep->config)) == NULL) {
834 834 /* case not properly saved or irretrievable */
835 835 out(O_ALTFP, "restart_fme: NULL instance tree");
836 836 Undiag_reason = UD_VAL_INSTFAIL;
837 837 goto badcase;
838 838 }
839 839
840 840 itree_ptree(O_ALTFP|O_VERB2, fmep->eventtree);
841 841
842 842 if (reconstitute_observations(fmep) != 0)
843 843 goto badcase;
844 844
845 845 out(O_ALTFP|O_NONL, "FME %d replay observations: ", fmep->id);
846 846 for (ep = fmep->observations; ep; ep = ep->observations) {
847 847 out(O_ALTFP|O_NONL, " ");
848 848 itree_pevent_brief(O_ALTFP|O_NONL, ep);
849 849 }
850 850 out(O_ALTFP, NULL);
851 851
852 852 Open_fme_count++;
853 853
854 854 /* give the diagnosis algorithm a shot at the new FME state */
855 855 fme_eval(fmep, fmep->e0r);
856 856 return;
857 857
858 858 badcase:
859 859 if (fmep->eventtree != NULL)
860 860 itree_free(fmep->eventtree);
861 861 if (fmep->config)
862 862 structconfig_free(fmep->config);
863 863 destroy_fme_bufs(fmep);
864 864 FREE(fmep);
865 865
866 866 /*
867 867 * Since we're unable to restart the case, add it to the undiagable
868 868 * list and solve and close it as appropriate.
869 869 */
870 870 bad = MALLOC(sizeof (struct case_list));
871 871 bad->next = NULL;
872 872
873 873 if (Undiagablecaselist != NULL)
874 874 bad->next = Undiagablecaselist;
875 875 Undiagablecaselist = bad;
876 876 bad->fmcase = inprogress;
877 877
878 878 out(O_ALTFP|O_NONL, "[case %s (unable to restart), ",
879 879 fmd_case_uuid(hdl, bad->fmcase));
880 880
881 881 if (fmd_case_solved(hdl, bad->fmcase)) {
882 882 out(O_ALTFP|O_NONL, "already solved, ");
883 883 } else {
884 884 out(O_ALTFP|O_NONL, "solving, ");
885 885 defect = fmd_nvl_create_fault(hdl,
886 886 undiag_2defect_str(Undiag_reason), 100, NULL, NULL, NULL);
887 887 reason = undiag_2reason_str(Undiag_reason, NULL);
888 888 (void) nvlist_add_string(defect, UNDIAG_REASON, reason);
889 889 FREE(reason);
890 890 fmd_case_add_suspect(hdl, bad->fmcase, defect);
891 891 fmd_case_solve(hdl, bad->fmcase);
892 892 Undiag_reason = UD_VAL_UNKNOWN;
893 893 }
894 894
895 895 if (fmd_case_closed(hdl, bad->fmcase)) {
896 896 out(O_ALTFP, "already closed ]");
897 897 } else {
898 898 out(O_ALTFP, "closing ]");
899 899 fmd_case_close(hdl, bad->fmcase);
900 900 }
901 901 }
902 902
903 903 /*ARGSUSED*/
904 904 static void
905 905 globals_destructor(void *left, void *right, void *arg)
906 906 {
907 907 struct evalue *evp = (struct evalue *)right;
908 908 if (evp->t == NODEPTR)
909 909 tree_free((struct node *)(uintptr_t)evp->v);
910 910 evp->v = (uintptr_t)NULL;
911 911 FREE(evp);
912 912 }
913 913
914 914 void
915 915 destroy_fme(struct fme *f)
916 916 {
917 917 stats_delete(f->Rcount);
918 918 stats_delete(f->Hcallcount);
919 919 stats_delete(f->Rcallcount);
920 920 stats_delete(f->Ccallcount);
921 921 stats_delete(f->Ecallcount);
922 922 stats_delete(f->Tcallcount);
923 923 stats_delete(f->Marrowcount);
924 924 stats_delete(f->diags);
925 925
926 926 if (f->eventtree != NULL)
927 927 itree_free(f->eventtree);
928 928 if (f->config)
929 929 structconfig_free(f->config);
930 930 lut_free(f->globals, globals_destructor, NULL);
931 931 FREE(f);
932 932 }
933 933
934 934 static const char *
935 935 fme_state2str(enum fme_state s)
936 936 {
937 937 switch (s) {
938 938 case FME_NOTHING: return ("NOTHING");
939 939 case FME_WAIT: return ("WAIT");
940 940 case FME_CREDIBLE: return ("CREDIBLE");
941 941 case FME_DISPROVED: return ("DISPROVED");
942 942 case FME_DEFERRED: return ("DEFERRED");
943 943 default: return ("UNKNOWN");
944 944 }
945 945 }
946 946
947 947 static int
948 948 is_problem(enum nametype t)
949 949 {
950 950 return (t == N_FAULT || t == N_DEFECT || t == N_UPSET);
951 951 }
952 952
953 953 static int
954 954 is_defect(enum nametype t)
955 955 {
956 956 return (t == N_DEFECT);
957 957 }
958 958
959 959 static int
960 960 is_upset(enum nametype t)
961 961 {
962 962 return (t == N_UPSET);
963 963 }
964 964
965 965 static void
966 966 fme_print(int flags, struct fme *fmep)
967 967 {
968 968 struct event *ep;
969 969
970 970 out(flags, "Fault Management Exercise %d", fmep->id);
971 971 out(flags, "\t State: %s", fme_state2str(fmep->state));
972 972 out(flags|O_NONL, "\t Start time: ");
973 973 ptree_timeval(flags|O_NONL, &fmep->ull);
974 974 out(flags, NULL);
975 975 if (fmep->wull) {
976 976 out(flags|O_NONL, "\t Wait time: ");
977 977 ptree_timeval(flags|O_NONL, &fmep->wull);
978 978 out(flags, NULL);
979 979 }
980 980 out(flags|O_NONL, "\t E0: ");
981 981 if (fmep->e0)
982 982 itree_pevent_brief(flags|O_NONL, fmep->e0);
983 983 else
984 984 out(flags|O_NONL, "NULL");
985 985 out(flags, NULL);
986 986 out(flags|O_NONL, "\tObservations:");
987 987 for (ep = fmep->observations; ep; ep = ep->observations) {
988 988 out(flags|O_NONL, " ");
989 989 itree_pevent_brief(flags|O_NONL, ep);
990 990 }
991 991 out(flags, NULL);
992 992 out(flags|O_NONL, "\tSuspect list:");
993 993 for (ep = fmep->suspects; ep; ep = ep->suspects) {
994 994 out(flags|O_NONL, " ");
995 995 itree_pevent_brief(flags|O_NONL, ep);
996 996 }
997 997 out(flags, NULL);
998 998 if (fmep->eventtree != NULL) {
999 999 out(flags|O_VERB2, "\t Tree:");
1000 1000 itree_ptree(flags|O_VERB2, fmep->eventtree);
1001 1001 }
1002 1002 }
1003 1003
1004 1004 static struct node *
1005 1005 pathstring2epnamenp(char *path)
1006 1006 {
1007 1007 char *sep = "/";
1008 1008 struct node *ret;
1009 1009 char *ptr;
1010 1010
1011 1011 if ((ptr = strtok(path, sep)) == NULL)
1012 1012 out(O_DIE, "pathstring2epnamenp: invalid empty class");
1013 1013
1014 1014 ret = tree_iname(stable(ptr), NULL, 0);
1015 1015
1016 1016 while ((ptr = strtok(NULL, sep)) != NULL)
1017 1017 ret = tree_name_append(ret,
1018 1018 tree_iname(stable(ptr), NULL, 0));
1019 1019
1020 1020 return (ret);
1021 1021 }
1022 1022
1023 1023 /*
1024 1024 * for a given upset sp, increment the corresponding SERD engine. if the
1025 1025 * SERD engine trips, return the ename and ipp of the resulting ereport.
1026 1026 * returns true if engine tripped and *enamep and *ippp were filled in.
1027 1027 */
1028 1028 static int
1029 1029 serd_eval(struct fme *fmep, fmd_hdl_t *hdl, fmd_event_t *ffep,
1030 1030 fmd_case_t *fmcase, struct event *sp, const char **enamep,
1031 1031 const struct ipath **ippp)
1032 1032 {
1033 1033 struct node *serdinst;
1034 1034 char *serdname;
1035 1035 char *serdresource;
1036 1036 char *serdclass;
1037 1037 struct node *nid;
1038 1038 struct serd_entry *newentp;
1039 1039 int i, serdn = -1, serdincrement = 1, len = 0;
1040 1040 char *serdsuffix = NULL, *serdt = NULL;
1041 1041 struct evalue *ep;
1042 1042
1043 1043 ASSERT(sp->t == N_UPSET);
1044 1044 ASSERT(ffep != NULL);
1045 1045
1046 1046 if ((ep = (struct evalue *)lut_lookup(sp->serdprops,
1047 1047 (void *)"n", (lut_cmp)strcmp)) != NULL) {
1048 1048 ASSERT(ep->t == UINT64);
1049 1049 serdn = (int)ep->v;
1050 1050 }
1051 1051 if ((ep = (struct evalue *)lut_lookup(sp->serdprops,
1052 1052 (void *)"t", (lut_cmp)strcmp)) != NULL) {
1053 1053 ASSERT(ep->t == STRING);
1054 1054 serdt = (char *)(uintptr_t)ep->v;
1055 1055 }
1056 1056 if ((ep = (struct evalue *)lut_lookup(sp->serdprops,
1057 1057 (void *)"suffix", (lut_cmp)strcmp)) != NULL) {
1058 1058 ASSERT(ep->t == STRING);
1059 1059 serdsuffix = (char *)(uintptr_t)ep->v;
1060 1060 }
1061 1061 if ((ep = (struct evalue *)lut_lookup(sp->serdprops,
1062 1062 (void *)"increment", (lut_cmp)strcmp)) != NULL) {
1063 1063 ASSERT(ep->t == UINT64);
1064 1064 serdincrement = (int)ep->v;
1065 1065 }
1066 1066
1067 1067 /*
1068 1068 * obtain instanced SERD engine from the upset sp. from this
1069 1069 * derive serdname, the string used to identify the SERD engine.
1070 1070 */
1071 1071 serdinst = eventprop_lookup(sp, L_engine);
1072 1072
1073 1073 if (serdinst == NULL)
1074 1074 return (-1);
1075 1075
1076 1076 len = strlen(serdinst->u.stmt.np->u.event.ename->u.name.s) + 1;
1077 1077 if (serdsuffix != NULL)
1078 1078 len += strlen(serdsuffix);
1079 1079 serdclass = MALLOC(len);
1080 1080 if (serdsuffix != NULL)
1081 1081 (void) snprintf(serdclass, len, "%s%s",
1082 1082 serdinst->u.stmt.np->u.event.ename->u.name.s, serdsuffix);
1083 1083 else
1084 1084 (void) snprintf(serdclass, len, "%s",
1085 1085 serdinst->u.stmt.np->u.event.ename->u.name.s);
1086 1086 serdresource = ipath2str(NULL,
1087 1087 ipath(serdinst->u.stmt.np->u.event.epname));
1088 1088 len += strlen(serdresource) + 1;
1089 1089 serdname = MALLOC(len);
1090 1090 (void) snprintf(serdname, len, "%s@%s", serdclass, serdresource);
1091 1091 FREE(serdresource);
1092 1092
1093 1093 /* handle serd engine "id" property, if there is one */
1094 1094 if ((nid =
1095 1095 lut_lookup(serdinst->u.stmt.lutp, (void *)L_id, NULL)) != NULL) {
1096 1096 struct evalue *gval;
1097 1097 char suffixbuf[200];
1098 1098 char *suffix;
1099 1099 char *nserdname;
1100 1100 size_t nname;
1101 1101
1102 1102 out(O_ALTFP|O_NONL, "serd \"%s\" id: ", serdname);
1103 1103 ptree_name_iter(O_ALTFP|O_NONL, nid);
1104 1104
1105 1105 ASSERTinfo(nid->t == T_GLOBID, ptree_nodetype2str(nid->t));
1106 1106
1107 1107 if ((gval = lut_lookup(fmep->globals,
1108 1108 (void *)nid->u.globid.s, NULL)) == NULL) {
1109 1109 out(O_ALTFP, " undefined");
1110 1110 } else if (gval->t == UINT64) {
1111 1111 out(O_ALTFP, " %llu", gval->v);
1112 1112 (void) sprintf(suffixbuf, "%llu", gval->v);
1113 1113 suffix = suffixbuf;
1114 1114 } else {
1115 1115 out(O_ALTFP, " \"%s\"", (char *)(uintptr_t)gval->v);
1116 1116 suffix = (char *)(uintptr_t)gval->v;
1117 1117 }
1118 1118
1119 1119 nname = strlen(serdname) + strlen(suffix) + 2;
1120 1120 nserdname = MALLOC(nname);
1121 1121 (void) snprintf(nserdname, nname, "%s:%s", serdname, suffix);
1122 1122 FREE(serdname);
1123 1123 serdname = nserdname;
1124 1124 }
1125 1125
1126 1126 /*
1127 1127 * if the engine is empty, and we have an override for n/t then
1128 1128 * destroy and recreate it.
1129 1129 */
1130 1130 if ((serdn != -1 || serdt != NULL) && fmd_serd_exists(hdl, serdname) &&
1131 1131 fmd_serd_empty(hdl, serdname))
1132 1132 fmd_serd_destroy(hdl, serdname);
1133 1133
1134 1134 if (!fmd_serd_exists(hdl, serdname)) {
1135 1135 struct node *nN, *nT;
1136 1136 const char *s;
1137 1137 struct node *nodep;
1138 1138 struct config *cp;
1139 1139 char *path;
1140 1140 uint_t nval;
1141 1141 hrtime_t tval;
1142 1142 int i;
1143 1143 char *ptr;
1144 1144 int got_n_override = 0, got_t_override = 0;
1145 1145
1146 1146 /* no SERD engine yet, so create it */
1147 1147 nodep = serdinst->u.stmt.np->u.event.epname;
1148 1148 path = ipath2str(NULL, ipath(nodep));
1149 1149 cp = config_lookup(fmep->config, path, 0);
1150 1150 FREE((void *)path);
1151 1151
1152 1152 /*
1153 1153 * We allow serd paramaters to be overridden, either from
1154 1154 * eft.conf file values (if Serd_Override is set) or from
1155 1155 * driver properties (for "serd.io.device" engines).
1156 1156 */
1157 1157 if (Serd_Override != NULL) {
1158 1158 char *save_ptr, *ptr1, *ptr2, *ptr3;
1159 1159 ptr3 = save_ptr = STRDUP(Serd_Override);
1160 1160 while (*ptr3 != '\0') {
1161 1161 ptr1 = strchr(ptr3, ',');
1162 1162 *ptr1 = '\0';
1163 1163 if (strcmp(ptr3, serdclass) == 0) {
1164 1164 ptr2 = strchr(ptr1 + 1, ',');
1165 1165 *ptr2 = '\0';
1166 1166 nval = atoi(ptr1 + 1);
1167 1167 out(O_ALTFP, "serd override %s_n %d",
1168 1168 serdclass, nval);
1169 1169 ptr3 = strchr(ptr2 + 1, ' ');
1170 1170 if (ptr3)
1171 1171 *ptr3 = '\0';
1172 1172 ptr = STRDUP(ptr2 + 1);
1173 1173 out(O_ALTFP, "serd override %s_t %s",
1174 1174 serdclass, ptr);
1175 1175 got_n_override = 1;
1176 1176 got_t_override = 1;
1177 1177 break;
1178 1178 } else {
1179 1179 ptr2 = strchr(ptr1 + 1, ',');
1180 1180 ptr3 = strchr(ptr2 + 1, ' ');
1181 1181 if (ptr3 == NULL)
1182 1182 break;
1183 1183 }
1184 1184 ptr3++;
1185 1185 }
1186 1186 FREE(save_ptr);
1187 1187 }
1188 1188
1189 1189 if (cp && got_n_override == 0) {
1190 1190 /*
1191 1191 * convert serd engine class into property name
1192 1192 */
1193 1193 char *prop_name = MALLOC(strlen(serdclass) + 3);
1194 1194 for (i = 0; i < strlen(serdclass); i++) {
1195 1195 if (serdclass[i] == '.')
1196 1196 prop_name[i] = '_';
1197 1197 else
1198 1198 prop_name[i] = serdclass[i];
1199 1199 }
1200 1200 prop_name[i++] = '_';
1201 1201 prop_name[i++] = 'n';
1202 1202 prop_name[i] = '\0';
1203 1203 if (s = config_getprop(cp, prop_name)) {
1204 1204 nval = atoi(s);
1205 1205 out(O_ALTFP, "serd override %s_n %s",
1206 1206 serdclass, s);
1207 1207 got_n_override = 1;
1208 1208 }
1209 1209 prop_name[i - 1] = 't';
1210 1210 if (s = config_getprop(cp, prop_name)) {
1211 1211 ptr = STRDUP(s);
1212 1212 out(O_ALTFP, "serd override %s_t %s",
1213 1213 serdclass, s);
1214 1214 got_t_override = 1;
1215 1215 }
1216 1216 FREE(prop_name);
1217 1217 }
1218 1218
1219 1219 if (serdn != -1 && got_n_override == 0) {
1220 1220 nval = serdn;
1221 1221 out(O_ALTFP, "serd override %s_n %d", serdclass, serdn);
1222 1222 got_n_override = 1;
1223 1223 }
1224 1224 if (serdt != NULL && got_t_override == 0) {
1225 1225 ptr = STRDUP(serdt);
1226 1226 out(O_ALTFP, "serd override %s_t %s", serdclass, serdt);
1227 1227 got_t_override = 1;
1228 1228 }
1229 1229
1230 1230 if (!got_n_override) {
1231 1231 nN = lut_lookup(serdinst->u.stmt.lutp, (void *)L_N,
1232 1232 NULL);
1233 1233 ASSERT(nN->t == T_NUM);
1234 1234 nval = (uint_t)nN->u.ull;
1235 1235 }
1236 1236 if (!got_t_override) {
1237 1237 nT = lut_lookup(serdinst->u.stmt.lutp, (void *)L_T,
1238 1238 NULL);
1239 1239 ASSERT(nT->t == T_TIMEVAL);
1240 1240 tval = (hrtime_t)nT->u.ull;
1241 1241 } else {
1242 1242 const unsigned long long *ullp;
1243 1243 const char *suffix;
1244 1244 int len;
1245 1245
1246 1246 len = strspn(ptr, "0123456789");
1247 1247 suffix = stable(&ptr[len]);
1248 1248 ullp = (unsigned long long *)lut_lookup(Timesuffixlut,
1249 1249 (void *)suffix, NULL);
1250 1250 ptr[len] = '\0';
1251 1251 tval = strtoull(ptr, NULL, 0) * (ullp ? *ullp : 1ll);
1252 1252 FREE(ptr);
1253 1253 }
1254 1254 fmd_serd_create(hdl, serdname, nval, tval);
1255 1255 }
1256 1256
1257 1257 newentp = MALLOC(sizeof (*newentp));
1258 1258 newentp->ename = stable(serdclass);
1259 1259 FREE(serdclass);
1260 1260 newentp->ipath = ipath(serdinst->u.stmt.np->u.event.epname);
1261 1261 newentp->hdl = hdl;
1262 1262 if (lut_lookup(SerdEngines, newentp, (lut_cmp)serd_cmp) == NULL) {
1263 1263 SerdEngines = lut_add(SerdEngines, (void *)newentp,
1264 1264 (void *)newentp, (lut_cmp)serd_cmp);
1265 1265 Serd_need_save = 1;
1266 1266 serd_save();
1267 1267 } else {
1268 1268 FREE(newentp);
1269 1269 }
1270 1270
1271 1271
1272 1272 /*
1273 1273 * increment SERD engine. if engine fires, reset serd
1274 1274 * engine and return trip_strcode if required.
1275 1275 */
1276 1276 for (i = 0; i < serdincrement; i++) {
1277 1277 if (fmd_serd_record(hdl, serdname, ffep)) {
1278 1278 fmd_case_add_serd(hdl, fmcase, serdname);
1279 1279 fmd_serd_reset(hdl, serdname);
1280 1280
1281 1281 if (ippp) {
1282 1282 struct node *tripinst =
1283 1283 lut_lookup(serdinst->u.stmt.lutp,
1284 1284 (void *)L_trip, NULL);
1285 1285 ASSERT(tripinst != NULL);
1286 1286 *enamep = tripinst->u.event.ename->u.name.s;
1287 1287 *ippp = ipath(tripinst->u.event.epname);
1288 1288 out(O_ALTFP|O_NONL,
1289 1289 "[engine fired: %s, sending: ", serdname);
1290 1290 ipath_print(O_ALTFP|O_NONL, *enamep, *ippp);
1291 1291 out(O_ALTFP, "]");
1292 1292 } else {
1293 1293 out(O_ALTFP, "[engine fired: %s, no trip]",
1294 1294 serdname);
1295 1295 }
1296 1296 FREE(serdname);
1297 1297 return (1);
1298 1298 }
1299 1299 }
1300 1300
1301 1301 FREE(serdname);
1302 1302 return (0);
1303 1303 }
1304 1304
1305 1305 /*
1306 1306 * search a suspect list for upsets. feed each upset to serd_eval() and
1307 1307 * build up tripped[], an array of ereports produced by the firing of
1308 1308 * any SERD engines. then feed each ereport back into
1309 1309 * fme_receive_report().
1310 1310 *
1311 1311 * returns ntrip, the number of these ereports produced.
1312 1312 */
1313 1313 static int
1314 1314 upsets_eval(struct fme *fmep, fmd_event_t *ffep)
1315 1315 {
1316 1316 /* we build an array of tripped ereports that we send ourselves */
1317 1317 struct {
1318 1318 const char *ename;
1319 1319 const struct ipath *ipp;
1320 1320 } *tripped;
1321 1321 struct event *sp;
1322 1322 int ntrip, nupset, i;
1323 1323
1324 1324 /*
1325 1325 * count the number of upsets to determine the upper limit on
1326 1326 * expected trip ereport strings. remember that one upset can
1327 1327 * lead to at most one ereport.
1328 1328 */
1329 1329 nupset = 0;
1330 1330 for (sp = fmep->suspects; sp; sp = sp->suspects) {
1331 1331 if (sp->t == N_UPSET)
1332 1332 nupset++;
1333 1333 }
1334 1334
1335 1335 if (nupset == 0)
1336 1336 return (0);
1337 1337
1338 1338 /*
1339 1339 * get to this point if we have upsets and expect some trip
1340 1340 * ereports
1341 1341 */
1342 1342 tripped = alloca(sizeof (*tripped) * nupset);
1343 1343 bzero((void *)tripped, sizeof (*tripped) * nupset);
1344 1344
1345 1345 ntrip = 0;
1346 1346 for (sp = fmep->suspects; sp; sp = sp->suspects)
1347 1347 if (sp->t == N_UPSET &&
1348 1348 serd_eval(fmep, fmep->hdl, ffep, fmep->fmcase, sp,
1349 1349 &tripped[ntrip].ename, &tripped[ntrip].ipp) == 1)
1350 1350 ntrip++;
1351 1351
1352 1352 for (i = 0; i < ntrip; i++) {
1353 1353 struct event *ep, *nep;
1354 1354 struct fme *nfmep;
1355 1355 fmd_case_t *fmcase;
1356 1356 const struct ipath *ipp;
1357 1357 const char *eventstring;
1358 1358 int prev_verbose;
1359 1359 unsigned long long my_delay = TIMEVAL_EVENTUALLY;
1360 1360 enum fme_state state;
1361 1361
1362 1362 /*
1363 1363 * First try and evaluate a case with the trip ereport plus
1364 1364 * all the other ereports that cause the trip. If that fails
1365 1365 * to evaluate then try again with just this ereport on its own.
1366 1366 */
1367 1367 out(O_ALTFP|O_NONL, "fme_receive_report_serd: ");
1368 1368 ipath_print(O_ALTFP|O_NONL, tripped[i].ename, tripped[i].ipp);
1369 1369 out(O_ALTFP|O_STAMP, NULL);
1370 1370 ep = fmep->e0;
1371 1371 eventstring = ep->enode->u.event.ename->u.name.s;
1372 1372 ipp = ep->ipp;
1373 1373
1374 1374 /*
1375 1375 * create a duplicate fme and case
1376 1376 */
1377 1377 fmcase = fmd_case_open(fmep->hdl, NULL);
1378 1378 out(O_ALTFP|O_NONL, "duplicate fme for event [");
1379 1379 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1380 1380 out(O_ALTFP, " ]");
1381 1381
1382 1382 if ((nfmep = newfme(eventstring, ipp, fmep->hdl,
1383 1383 fmcase, ffep, ep->nvp)) == NULL) {
1384 1384 out(O_ALTFP|O_NONL, "[");
1385 1385 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1386 1386 out(O_ALTFP, " CANNOT DIAGNOSE]");
1387 1387 continue;
1388 1388 }
1389 1389
1390 1390 Open_fme_count++;
1391 1391 nfmep->pull = fmep->pull;
1392 1392 init_fme_bufs(nfmep);
1393 1393 out(O_ALTFP|O_NONL, "[");
1394 1394 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1395 1395 out(O_ALTFP, " created FME%d, case %s]", nfmep->id,
1396 1396 fmd_case_uuid(nfmep->hdl, nfmep->fmcase));
1397 1397 if (ffep) {
1398 1398 fmd_case_setprincipal(nfmep->hdl, nfmep->fmcase, ffep);
1399 1399 fmd_case_add_ereport(nfmep->hdl, nfmep->fmcase, ffep);
1400 1400 nfmep->e0r = ffep;
1401 1401 }
1402 1402
1403 1403 /*
1404 1404 * add the original ereports
1405 1405 */
1406 1406 for (ep = fmep->observations; ep; ep = ep->observations) {
1407 1407 eventstring = ep->enode->u.event.ename->u.name.s;
1408 1408 ipp = ep->ipp;
1409 1409 out(O_ALTFP|O_NONL, "adding event [");
1410 1410 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1411 1411 out(O_ALTFP, " ]");
1412 1412 nep = itree_lookup(nfmep->eventtree, eventstring, ipp);
1413 1413 if (nep->count++ == 0) {
1414 1414 nep->observations = nfmep->observations;
1415 1415 nfmep->observations = nep;
1416 1416 serialize_observation(nfmep, eventstring, ipp);
1417 1417 nep->nvp = evnv_dupnvl(ep->nvp);
1418 1418 }
1419 1419 if (ep->ffep && ep->ffep != ffep)
1420 1420 fmd_case_add_ereport(nfmep->hdl, nfmep->fmcase,
1421 1421 ep->ffep);
1422 1422 stats_counter_bump(nfmep->Rcount);
1423 1423 }
1424 1424
1425 1425 /*
1426 1426 * add the serd trigger ereport
1427 1427 */
1428 1428 if ((ep = itree_lookup(nfmep->eventtree, tripped[i].ename,
1429 1429 tripped[i].ipp)) == NULL) {
1430 1430 /*
1431 1431 * The trigger ereport is not in the instance tree. It
1432 1432 * was presumably removed by prune_propagations() as
1433 1433 * this combination of events is not present in the
1434 1434 * rules.
1435 1435 */
1436 1436 out(O_ALTFP, "upsets_eval: e0 not in instance tree");
1437 1437 Undiag_reason = UD_VAL_BADEVENTI;
1438 1438 goto retry_lone_ereport;
1439 1439 }
1440 1440 out(O_ALTFP|O_NONL, "adding event [");
1441 1441 ipath_print(O_ALTFP|O_NONL, tripped[i].ename, tripped[i].ipp);
1442 1442 out(O_ALTFP, " ]");
1443 1443 nfmep->ecurrent = ep;
1444 1444 ep->nvp = NULL;
1445 1445 ep->count = 1;
1446 1446 ep->observations = nfmep->observations;
1447 1447 nfmep->observations = ep;
1448 1448
1449 1449 /*
1450 1450 * just peek first.
1451 1451 */
1452 1452 nfmep->peek = 1;
1453 1453 prev_verbose = Verbose;
1454 1454 if (Debug == 0)
1455 1455 Verbose = 0;
1456 1456 lut_walk(nfmep->eventtree, (lut_cb)clear_arrows, (void *)nfmep);
1457 1457 state = hypothesise(nfmep, nfmep->e0, nfmep->ull, &my_delay);
1458 1458 nfmep->peek = 0;
1459 1459 Verbose = prev_verbose;
1460 1460 if (state == FME_DISPROVED) {
1461 1461 out(O_ALTFP, "upsets_eval: hypothesis disproved");
1462 1462 Undiag_reason = UD_VAL_UNSOLVD;
1463 1463 retry_lone_ereport:
1464 1464 /*
1465 1465 * However the trigger ereport on its own might be
1466 1466 * diagnosable, so check for that. Undo the new fme
1467 1467 * and case we just created and call fme_receive_report.
1468 1468 */
1469 1469 out(O_ALTFP|O_NONL, "[");
1470 1470 ipath_print(O_ALTFP|O_NONL, tripped[i].ename,
1471 1471 tripped[i].ipp);
1472 1472 out(O_ALTFP, " retrying with just trigger ereport]");
1473 1473 itree_free(nfmep->eventtree);
1474 1474 nfmep->eventtree = NULL;
1475 1475 structconfig_free(nfmep->config);
1476 1476 nfmep->config = NULL;
1477 1477 destroy_fme_bufs(nfmep);
1478 1478 fmd_case_close(nfmep->hdl, nfmep->fmcase);
1479 1479 fme_receive_report(fmep->hdl, ffep,
1480 1480 tripped[i].ename, tripped[i].ipp, NULL);
1481 1481 continue;
1482 1482 }
1483 1483
1484 1484 /*
1485 1485 * and evaluate
1486 1486 */
1487 1487 serialize_observation(nfmep, tripped[i].ename, tripped[i].ipp);
1488 1488 fme_eval(nfmep, ffep);
1489 1489 }
1490 1490
1491 1491 return (ntrip);
1492 1492 }
1493 1493
1494 1494 /*
1495 1495 * fme_receive_external_report -- call when an external ereport comes in
1496 1496 *
1497 1497 * this routine just converts the relevant information from the ereport
1498 1498 * into a format used internally and passes it on to fme_receive_report().
1499 1499 */
1500 1500 void
1501 1501 fme_receive_external_report(fmd_hdl_t *hdl, fmd_event_t *ffep, nvlist_t *nvl,
1502 1502 const char *class)
1503 1503 {
1504 1504 struct node *epnamenp;
1505 1505 fmd_case_t *fmcase;
1506 1506 const struct ipath *ipp;
1507 1507 nvlist_t *detector = NULL;
1508 1508
1509 1509 class = stable(class);
1510 1510
1511 1511 /* Get the component path from the ereport */
1512 1512 epnamenp = platform_getpath(nvl);
1513 1513
1514 1514 /* See if we ended up without a path. */
1515 1515 if (epnamenp == NULL) {
1516 1516 /* See if class permits silent discard on unknown component. */
1517 1517 if (lut_lookup(Ereportenames_discard, (void *)class, NULL)) {
1518 1518 out(O_ALTFP|O_VERB2, "Unable to map \"%s\" ereport "
1519 1519 "to component path, but silent discard allowed.",
1520 1520 class);
1521 1521 } else {
1522 1522 /*
1523 1523 * XFILE: Failure to find a component is bad unless
1524 1524 * 'discard_if_config_unknown=1' was specified in the
1525 1525 * ereport definition. Indicate undiagnosable.
1526 1526 */
1527 1527 Undiag_reason = UD_VAL_NOPATH;
1528 1528 fmcase = fmd_case_open(hdl, NULL);
1529 1529
1530 1530 /*
1531 1531 * We don't have a component path here (which means that
1532 1532 * the detector was not in hc-scheme and couldn't be
1533 1533 * converted to hc-scheme. Report the raw detector as
1534 1534 * the suspect resource if there is one.
1535 1535 */
1536 1536 (void) nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR,
1537 1537 &detector);
1538 1538 publish_undiagnosable(hdl, ffep, fmcase, detector,
1539 1539 (char *)class);
1540 1540 }
1541 1541 return;
1542 1542 }
1543 1543
1544 1544 ipp = ipath(epnamenp);
1545 1545 tree_free(epnamenp);
1546 1546 fme_receive_report(hdl, ffep, class, ipp, nvl);
1547 1547 }
1548 1548
1549 1549 /*ARGSUSED*/
1550 1550 void
1551 1551 fme_receive_repair_list(fmd_hdl_t *hdl, fmd_event_t *ffep, nvlist_t *nvl,
1552 1552 const char *eventstring)
1553 1553 {
1554 1554 char *uuid;
1555 1555 nvlist_t **nva;
1556 1556 uint_t nvc;
1557 1557 const struct ipath *ipp;
1558 1558
1559 1559 if (nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid) != 0 ||
1560 1560 nvlist_lookup_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST,
1561 1561 &nva, &nvc) != 0) {
1562 1562 out(O_ALTFP, "No uuid or fault list for list.repaired event");
1563 1563 return;
1564 1564 }
1565 1565
1566 1566 out(O_ALTFP, "Processing list.repaired from case %s", uuid);
1567 1567
1568 1568 while (nvc-- != 0) {
1569 1569 /*
1570 1570 * Reset any istat or serd engine associated with this path.
1571 1571 */
1572 1572 char *path;
1573 1573
1574 1574 if ((ipp = platform_fault2ipath(*nva++)) == NULL)
1575 1575 continue;
1576 1576
1577 1577 path = ipath2str(NULL, ipp);
1578 1578 out(O_ALTFP, "fme_receive_repair_list: resetting state for %s",
1579 1579 path);
1580 1580 FREE(path);
1581 1581
1582 1582 lut_walk(Istats, (lut_cb)istat_counter_reset_cb, (void *)ipp);
1583 1583 istat_save();
1584 1584
1585 1585 lut_walk(SerdEngines, (lut_cb)serd_reset_cb, (void *)ipp);
1586 1586 serd_save();
1587 1587 }
1588 1588 }
1589 1589
1590 1590 /*ARGSUSED*/
1591 1591 void
1592 1592 fme_receive_topology_change(void)
1593 1593 {
1594 1594 lut_walk(Istats, (lut_cb)istat_counter_topo_chg_cb, NULL);
1595 1595 istat_save();
1596 1596
1597 1597 lut_walk(SerdEngines, (lut_cb)serd_topo_chg_cb, NULL);
1598 1598 serd_save();
1599 1599 }
1600 1600
1601 1601 static int mark_arrows(struct fme *fmep, struct event *ep, int mark,
1602 1602 unsigned long long at_latest_by, unsigned long long *pdelay, int keep);
1603 1603
1604 1604 /* ARGSUSED */
1605 1605 static void
1606 1606 clear_arrows(struct event *ep, struct event *ep2, struct fme *fmep)
1607 1607 {
1608 1608 struct bubble *bp;
1609 1609 struct arrowlist *ap;
1610 1610
1611 1611 ep->cached_state = 0;
1612 1612 ep->keep_in_tree = 0;
1613 1613 for (bp = itree_next_bubble(ep, NULL); bp;
1614 1614 bp = itree_next_bubble(ep, bp)) {
1615 1615 if (bp->t != B_FROM)
1616 1616 continue;
1617 1617 bp->mark = 0;
1618 1618 for (ap = itree_next_arrow(bp, NULL); ap;
1619 1619 ap = itree_next_arrow(bp, ap))
1620 1620 ap->arrowp->mark = 0;
1621 1621 }
1622 1622 }
1623 1623
1624 1624 static void
1625 1625 fme_receive_report(fmd_hdl_t *hdl, fmd_event_t *ffep,
1626 1626 const char *eventstring, const struct ipath *ipp, nvlist_t *nvl)
1627 1627 {
1628 1628 struct event *ep;
1629 1629 struct fme *fmep = NULL;
1630 1630 struct fme *ofmep = NULL;
1631 1631 struct fme *cfmep, *svfmep;
1632 1632 int matched = 0;
1633 1633 nvlist_t *defect;
1634 1634 fmd_case_t *fmcase;
1635 1635 char *reason;
1636 1636
1637 1637 out(O_ALTFP|O_NONL, "fme_receive_report: ");
1638 1638 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1639 1639 out(O_ALTFP|O_STAMP, NULL);
1640 1640
1641 1641 /* decide which FME it goes to */
1642 1642 for (fmep = FMElist; fmep; fmep = fmep->next) {
1643 1643 int prev_verbose;
1644 1644 unsigned long long my_delay = TIMEVAL_EVENTUALLY;
1645 1645 enum fme_state state;
1646 1646 nvlist_t *pre_peek_nvp = NULL;
1647 1647
1648 1648 if (fmep->overflow) {
1649 1649 if (!(fmd_case_closed(fmep->hdl, fmep->fmcase)))
1650 1650 ofmep = fmep;
1651 1651
1652 1652 continue;
1653 1653 }
1654 1654
1655 1655 /*
1656 1656 * ignore solved or closed cases
1657 1657 */
1658 1658 if (fmep->posted_suspects ||
1659 1659 fmd_case_solved(fmep->hdl, fmep->fmcase) ||
1660 1660 fmd_case_closed(fmep->hdl, fmep->fmcase))
1661 1661 continue;
1662 1662
1663 1663 /* look up event in event tree for this FME */
1664 1664 if ((ep = itree_lookup(fmep->eventtree,
1665 1665 eventstring, ipp)) == NULL)
1666 1666 continue;
1667 1667
1668 1668 /* note observation */
1669 1669 fmep->ecurrent = ep;
1670 1670 if (ep->count++ == 0) {
1671 1671 /* link it into list of observations seen */
1672 1672 ep->observations = fmep->observations;
1673 1673 fmep->observations = ep;
1674 1674 ep->nvp = evnv_dupnvl(nvl);
1675 1675 } else {
1676 1676 /* use new payload values for peek */
1677 1677 pre_peek_nvp = ep->nvp;
1678 1678 ep->nvp = evnv_dupnvl(nvl);
1679 1679 }
1680 1680
1681 1681 /* tell hypothesise() not to mess with suspect list */
1682 1682 fmep->peek = 1;
1683 1683
1684 1684 /* don't want this to be verbose (unless Debug is set) */
1685 1685 prev_verbose = Verbose;
1686 1686 if (Debug == 0)
1687 1687 Verbose = 0;
1688 1688
1689 1689 lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep);
1690 1690 state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay);
1691 1691
1692 1692 fmep->peek = 0;
1693 1693
↓ open down ↓ |
1693 lines elided |
↑ open up ↑ |
1694 1694 /* put verbose flag back */
1695 1695 Verbose = prev_verbose;
1696 1696
1697 1697 if (state != FME_DISPROVED) {
1698 1698 /* found an FME that explains the ereport */
1699 1699 matched++;
1700 1700 out(O_ALTFP|O_NONL, "[");
1701 1701 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1702 1702 out(O_ALTFP, " explained by FME%d]", fmep->id);
1703 1703
1704 - if (pre_peek_nvp)
1705 - nvlist_free(pre_peek_nvp);
1704 + nvlist_free(pre_peek_nvp);
1706 1705
1707 1706 if (ep->count == 1)
1708 1707 serialize_observation(fmep, eventstring, ipp);
1709 1708
1710 1709 if (ffep) {
1711 1710 fmd_case_add_ereport(hdl, fmep->fmcase, ffep);
1712 1711 ep->ffep = ffep;
1713 1712 }
1714 1713
1715 1714 stats_counter_bump(fmep->Rcount);
1716 1715
1717 1716 /* re-eval FME */
1718 1717 fme_eval(fmep, ffep);
1719 1718 } else {
1720 1719
1721 1720 /* not a match, undo noting of observation */
1722 1721 fmep->ecurrent = NULL;
1723 1722 if (--ep->count == 0) {
1724 1723 /* unlink it from observations */
1725 1724 fmep->observations = ep->observations;
1726 1725 ep->observations = NULL;
1727 1726 nvlist_free(ep->nvp);
1728 1727 ep->nvp = NULL;
1729 1728 } else {
1730 1729 nvlist_free(ep->nvp);
1731 1730 ep->nvp = pre_peek_nvp;
1732 1731 }
1733 1732 }
1734 1733 }
1735 1734
1736 1735 if (matched)
1737 1736 return; /* explained by at least one existing FME */
1738 1737
1739 1738 /* clean up closed fmes */
1740 1739 cfmep = ClosedFMEs;
1741 1740 while (cfmep != NULL) {
1742 1741 svfmep = cfmep->next;
1743 1742 destroy_fme(cfmep);
1744 1743 cfmep = svfmep;
1745 1744 }
1746 1745 ClosedFMEs = NULL;
1747 1746
1748 1747 if (ofmep) {
1749 1748 out(O_ALTFP|O_NONL, "[");
1750 1749 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1751 1750 out(O_ALTFP, " ADDING TO OVERFLOW FME]");
1752 1751 if (ffep)
1753 1752 fmd_case_add_ereport(hdl, ofmep->fmcase, ffep);
1754 1753
1755 1754 return;
1756 1755
1757 1756 } else if (Max_fme && (Open_fme_count >= Max_fme)) {
1758 1757 out(O_ALTFP|O_NONL, "[");
1759 1758 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1760 1759 out(O_ALTFP, " MAX OPEN FME REACHED]");
1761 1760
1762 1761 fmcase = fmd_case_open(hdl, NULL);
1763 1762
1764 1763 /* Create overflow fme */
1765 1764 if ((fmep = newfme(eventstring, ipp, hdl, fmcase, ffep,
1766 1765 nvl)) == NULL) {
1767 1766 out(O_ALTFP|O_NONL, "[");
1768 1767 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1769 1768 out(O_ALTFP, " CANNOT OPEN OVERFLOW FME]");
1770 1769 return;
1771 1770 }
1772 1771
1773 1772 Open_fme_count++;
1774 1773
1775 1774 init_fme_bufs(fmep);
1776 1775 fmep->overflow = B_TRUE;
1777 1776
1778 1777 if (ffep)
1779 1778 fmd_case_add_ereport(hdl, fmep->fmcase, ffep);
1780 1779
1781 1780 Undiag_reason = UD_VAL_MAXFME;
1782 1781 defect = fmd_nvl_create_fault(hdl,
1783 1782 undiag_2defect_str(Undiag_reason), 100, NULL, NULL, NULL);
1784 1783 reason = undiag_2reason_str(Undiag_reason, NULL);
1785 1784 (void) nvlist_add_string(defect, UNDIAG_REASON, reason);
1786 1785 FREE(reason);
1787 1786 fmd_case_add_suspect(hdl, fmep->fmcase, defect);
1788 1787 fmd_case_solve(hdl, fmep->fmcase);
1789 1788 Undiag_reason = UD_VAL_UNKNOWN;
1790 1789 return;
1791 1790 }
1792 1791
1793 1792 /* open a case */
1794 1793 fmcase = fmd_case_open(hdl, NULL);
1795 1794
1796 1795 /* start a new FME */
1797 1796 if ((fmep = newfme(eventstring, ipp, hdl, fmcase, ffep, nvl)) == NULL) {
1798 1797 out(O_ALTFP|O_NONL, "[");
1799 1798 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1800 1799 out(O_ALTFP, " CANNOT DIAGNOSE]");
1801 1800 return;
1802 1801 }
1803 1802
1804 1803 Open_fme_count++;
1805 1804
1806 1805 init_fme_bufs(fmep);
1807 1806
1808 1807 out(O_ALTFP|O_NONL, "[");
1809 1808 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1810 1809 out(O_ALTFP, " created FME%d, case %s]", fmep->id,
1811 1810 fmd_case_uuid(hdl, fmep->fmcase));
1812 1811
1813 1812 ep = fmep->e0;
1814 1813 ASSERT(ep != NULL);
1815 1814
1816 1815 /* note observation */
1817 1816 fmep->ecurrent = ep;
1818 1817 if (ep->count++ == 0) {
1819 1818 /* link it into list of observations seen */
1820 1819 ep->observations = fmep->observations;
1821 1820 fmep->observations = ep;
1822 1821 ep->nvp = evnv_dupnvl(nvl);
1823 1822 serialize_observation(fmep, eventstring, ipp);
1824 1823 } else {
1825 1824 /* new payload overrides any previous */
1826 1825 nvlist_free(ep->nvp);
1827 1826 ep->nvp = evnv_dupnvl(nvl);
1828 1827 }
1829 1828
1830 1829 stats_counter_bump(fmep->Rcount);
1831 1830
1832 1831 if (ffep) {
1833 1832 fmd_case_add_ereport(hdl, fmep->fmcase, ffep);
1834 1833 fmd_case_setprincipal(hdl, fmep->fmcase, ffep);
1835 1834 fmep->e0r = ffep;
1836 1835 ep->ffep = ffep;
1837 1836 }
1838 1837
1839 1838 /* give the diagnosis algorithm a shot at the new FME state */
1840 1839 fme_eval(fmep, ffep);
1841 1840 }
1842 1841
1843 1842 void
1844 1843 fme_status(int flags)
1845 1844 {
1846 1845 struct fme *fmep;
1847 1846
1848 1847 if (FMElist == NULL) {
1849 1848 out(flags, "No fault management exercises underway.");
1850 1849 return;
1851 1850 }
1852 1851
1853 1852 for (fmep = FMElist; fmep; fmep = fmep->next)
1854 1853 fme_print(flags, fmep);
1855 1854 }
1856 1855
1857 1856 /*
1858 1857 * "indent" routines used mostly for nicely formatted debug output, but also
1859 1858 * for sanity checking for infinite recursion bugs.
1860 1859 */
1861 1860
1862 1861 #define MAX_INDENT 1024
1863 1862 static const char *indent_s[MAX_INDENT];
1864 1863 static int current_indent;
1865 1864
1866 1865 static void
1867 1866 indent_push(const char *s)
1868 1867 {
1869 1868 if (current_indent < MAX_INDENT)
1870 1869 indent_s[current_indent++] = s;
1871 1870 else
1872 1871 out(O_DIE, "unexpected recursion depth (%d)", current_indent);
1873 1872 }
1874 1873
1875 1874 static void
1876 1875 indent_set(const char *s)
1877 1876 {
1878 1877 current_indent = 0;
1879 1878 indent_push(s);
1880 1879 }
1881 1880
1882 1881 static void
1883 1882 indent_pop(void)
1884 1883 {
1885 1884 if (current_indent > 0)
1886 1885 current_indent--;
1887 1886 else
1888 1887 out(O_DIE, "recursion underflow");
1889 1888 }
1890 1889
1891 1890 static void
1892 1891 indent(void)
1893 1892 {
1894 1893 int i;
1895 1894 if (!Verbose)
1896 1895 return;
1897 1896 for (i = 0; i < current_indent; i++)
1898 1897 out(O_ALTFP|O_VERB|O_NONL, indent_s[i]);
1899 1898 }
1900 1899
1901 1900 #define SLNEW 1
1902 1901 #define SLCHANGED 2
1903 1902 #define SLWAIT 3
1904 1903 #define SLDISPROVED 4
1905 1904
1906 1905 static void
1907 1906 print_suspects(int circumstance, struct fme *fmep)
1908 1907 {
1909 1908 struct event *ep;
1910 1909
1911 1910 out(O_ALTFP|O_NONL, "[");
1912 1911 if (circumstance == SLCHANGED) {
1913 1912 out(O_ALTFP|O_NONL, "FME%d diagnosis changed. state: %s, "
1914 1913 "suspect list:", fmep->id, fme_state2str(fmep->state));
1915 1914 } else if (circumstance == SLWAIT) {
1916 1915 out(O_ALTFP|O_NONL, "FME%d set wait timer %ld ", fmep->id,
1917 1916 fmep->timer);
1918 1917 ptree_timeval(O_ALTFP|O_NONL, &fmep->wull);
1919 1918 } else if (circumstance == SLDISPROVED) {
1920 1919 out(O_ALTFP|O_NONL, "FME%d DIAGNOSIS UNKNOWN", fmep->id);
1921 1920 } else {
1922 1921 out(O_ALTFP|O_NONL, "FME%d DIAGNOSIS PRODUCED:", fmep->id);
1923 1922 }
1924 1923
1925 1924 if (circumstance == SLWAIT || circumstance == SLDISPROVED) {
1926 1925 out(O_ALTFP, "]");
1927 1926 return;
1928 1927 }
1929 1928
1930 1929 for (ep = fmep->suspects; ep; ep = ep->suspects) {
1931 1930 out(O_ALTFP|O_NONL, " ");
1932 1931 itree_pevent_brief(O_ALTFP|O_NONL, ep);
1933 1932 }
1934 1933 out(O_ALTFP, "]");
1935 1934 }
1936 1935
1937 1936 static struct node *
1938 1937 eventprop_lookup(struct event *ep, const char *propname)
1939 1938 {
1940 1939 return (lut_lookup(ep->props, (void *)propname, NULL));
1941 1940 }
1942 1941
1943 1942 #define MAXDIGITIDX 23
1944 1943 static char numbuf[MAXDIGITIDX + 1];
1945 1944
1946 1945 static int
1947 1946 node2uint(struct node *n, uint_t *valp)
1948 1947 {
1949 1948 struct evalue value;
1950 1949 struct lut *globals = NULL;
1951 1950
1952 1951 if (n == NULL)
1953 1952 return (1);
1954 1953
1955 1954 /*
1956 1955 * check value.v since we are being asked to convert an unsigned
1957 1956 * long long int to an unsigned int
1958 1957 */
1959 1958 if (! eval_expr(n, NULL, NULL, &globals, NULL, NULL, 0, &value) ||
1960 1959 value.t != UINT64 || value.v > (1ULL << 32))
1961 1960 return (1);
1962 1961
1963 1962 *valp = (uint_t)value.v;
1964 1963
1965 1964 return (0);
1966 1965 }
1967 1966
1968 1967 static nvlist_t *
1969 1968 node2fmri(struct node *n)
1970 1969 {
1971 1970 nvlist_t **pa, *f, *p;
1972 1971 struct node *nc;
1973 1972 uint_t depth = 0;
1974 1973 char *numstr, *nullbyte;
1975 1974 char *failure;
1976 1975 int err, i;
1977 1976
1978 1977 /* XXX do we need to be able to handle a non-T_NAME node? */
1979 1978 if (n == NULL || n->t != T_NAME)
1980 1979 return (NULL);
1981 1980
1982 1981 for (nc = n; nc != NULL; nc = nc->u.name.next) {
1983 1982 if (nc->u.name.child == NULL || nc->u.name.child->t != T_NUM)
1984 1983 break;
1985 1984 depth++;
1986 1985 }
1987 1986
1988 1987 if (nc != NULL) {
1989 1988 /* We bailed early, something went wrong */
1990 1989 return (NULL);
1991 1990 }
1992 1991
1993 1992 if ((err = nvlist_xalloc(&f, NV_UNIQUE_NAME, &Eft_nv_hdl)) != 0)
1994 1993 out(O_DIE|O_SYS, "alloc of fmri nvl failed");
1995 1994 pa = alloca(depth * sizeof (nvlist_t *));
1996 1995 for (i = 0; i < depth; i++)
1997 1996 pa[i] = NULL;
1998 1997
1999 1998 err = nvlist_add_string(f, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC);
2000 1999 err |= nvlist_add_uint8(f, FM_VERSION, FM_HC_SCHEME_VERSION);
2001 2000 err |= nvlist_add_string(f, FM_FMRI_HC_ROOT, "");
2002 2001 err |= nvlist_add_uint32(f, FM_FMRI_HC_LIST_SZ, depth);
2003 2002 if (err != 0) {
2004 2003 failure = "basic construction of FMRI failed";
2005 2004 goto boom;
2006 2005 }
2007 2006
2008 2007 numbuf[MAXDIGITIDX] = '\0';
2009 2008 nullbyte = &numbuf[MAXDIGITIDX];
2010 2009 i = 0;
2011 2010
2012 2011 for (nc = n; nc != NULL; nc = nc->u.name.next) {
2013 2012 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2014 2013 if (err != 0) {
2015 2014 failure = "alloc of an hc-pair failed";
2016 2015 goto boom;
2017 2016 }
2018 2017 err = nvlist_add_string(p, FM_FMRI_HC_NAME, nc->u.name.s);
2019 2018 numstr = ulltostr(nc->u.name.child->u.ull, nullbyte);
2020 2019 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
↓ open down ↓ |
305 lines elided |
↑ open up ↑ |
2021 2020 if (err != 0) {
2022 2021 failure = "construction of an hc-pair failed";
2023 2022 goto boom;
2024 2023 }
2025 2024 pa[i++] = p;
2026 2025 }
2027 2026
2028 2027 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2029 2028 if (err == 0) {
2030 2029 for (i = 0; i < depth; i++)
2031 - if (pa[i] != NULL)
2032 - nvlist_free(pa[i]);
2030 + nvlist_free(pa[i]);
2033 2031 return (f);
2034 2032 }
2035 2033 failure = "addition of hc-pair array to FMRI failed";
2036 2034
2037 2035 boom:
2038 2036 for (i = 0; i < depth; i++)
2039 - if (pa[i] != NULL)
2040 - nvlist_free(pa[i]);
2037 + nvlist_free(pa[i]);
2041 2038 nvlist_free(f);
2042 2039 out(O_DIE, "%s", failure);
2043 2040 /*NOTREACHED*/
2044 2041 return (NULL);
2045 2042 }
2046 2043
2047 2044 /* an ipath cache entry is an array of these, with s==NULL at the end */
2048 2045 struct ipath {
2049 2046 const char *s; /* component name (in stable) */
2050 2047 int i; /* instance number */
2051 2048 };
2052 2049
2053 2050 static nvlist_t *
2054 2051 ipath2fmri(struct ipath *ipath)
2055 2052 {
2056 2053 nvlist_t **pa, *f, *p;
2057 2054 uint_t depth = 0;
2058 2055 char *numstr, *nullbyte;
2059 2056 char *failure;
2060 2057 int err, i;
2061 2058 struct ipath *ipp;
2062 2059
2063 2060 for (ipp = ipath; ipp->s != NULL; ipp++)
2064 2061 depth++;
2065 2062
2066 2063 if ((err = nvlist_xalloc(&f, NV_UNIQUE_NAME, &Eft_nv_hdl)) != 0)
2067 2064 out(O_DIE|O_SYS, "alloc of fmri nvl failed");
2068 2065 pa = alloca(depth * sizeof (nvlist_t *));
2069 2066 for (i = 0; i < depth; i++)
2070 2067 pa[i] = NULL;
2071 2068
2072 2069 err = nvlist_add_string(f, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC);
2073 2070 err |= nvlist_add_uint8(f, FM_VERSION, FM_HC_SCHEME_VERSION);
2074 2071 err |= nvlist_add_string(f, FM_FMRI_HC_ROOT, "");
2075 2072 err |= nvlist_add_uint32(f, FM_FMRI_HC_LIST_SZ, depth);
2076 2073 if (err != 0) {
2077 2074 failure = "basic construction of FMRI failed";
2078 2075 goto boom;
2079 2076 }
2080 2077
2081 2078 numbuf[MAXDIGITIDX] = '\0';
2082 2079 nullbyte = &numbuf[MAXDIGITIDX];
2083 2080 i = 0;
2084 2081
2085 2082 for (ipp = ipath; ipp->s != NULL; ipp++) {
2086 2083 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2087 2084 if (err != 0) {
2088 2085 failure = "alloc of an hc-pair failed";
2089 2086 goto boom;
2090 2087 }
2091 2088 err = nvlist_add_string(p, FM_FMRI_HC_NAME, ipp->s);
2092 2089 numstr = ulltostr(ipp->i, nullbyte);
2093 2090 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
↓ open down ↓ |
43 lines elided |
↑ open up ↑ |
2094 2091 if (err != 0) {
2095 2092 failure = "construction of an hc-pair failed";
2096 2093 goto boom;
2097 2094 }
2098 2095 pa[i++] = p;
2099 2096 }
2100 2097
2101 2098 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2102 2099 if (err == 0) {
2103 2100 for (i = 0; i < depth; i++)
2104 - if (pa[i] != NULL)
2105 - nvlist_free(pa[i]);
2101 + nvlist_free(pa[i]);
2106 2102 return (f);
2107 2103 }
2108 2104 failure = "addition of hc-pair array to FMRI failed";
2109 2105
2110 2106 boom:
2111 2107 for (i = 0; i < depth; i++)
2112 - if (pa[i] != NULL)
2113 - nvlist_free(pa[i]);
2108 + nvlist_free(pa[i]);
2114 2109 nvlist_free(f);
2115 2110 out(O_DIE, "%s", failure);
2116 2111 /*NOTREACHED*/
2117 2112 return (NULL);
2118 2113 }
2119 2114
2120 2115 static uint8_t
2121 2116 percentof(uint_t part, uint_t whole)
2122 2117 {
2123 2118 unsigned long long p = part * 1000;
2124 2119
2125 2120 return ((p / whole / 10) + (((p / whole % 10) >= 5) ? 1 : 0));
2126 2121 }
2127 2122
2128 2123 struct rsl {
2129 2124 struct event *suspect;
2130 2125 nvlist_t *asru;
2131 2126 nvlist_t *fru;
2132 2127 nvlist_t *rsrc;
2133 2128 };
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
2134 2129
2135 2130 static void publish_suspects(struct fme *fmep, struct rsl *srl);
2136 2131
2137 2132 /*
2138 2133 * rslfree -- free internal members of struct rsl not expected to be
2139 2134 * freed elsewhere.
2140 2135 */
2141 2136 static void
2142 2137 rslfree(struct rsl *freeme)
2143 2138 {
2144 - if (freeme->asru != NULL)
2145 - nvlist_free(freeme->asru);
2146 - if (freeme->fru != NULL)
2147 - nvlist_free(freeme->fru);
2148 - if (freeme->rsrc != NULL && freeme->rsrc != freeme->asru)
2139 + nvlist_free(freeme->asru);
2140 + nvlist_free(freeme->fru);
2141 + if (freeme->rsrc != freeme->asru)
2149 2142 nvlist_free(freeme->rsrc);
2150 2143 }
2151 2144
2152 2145 /*
2153 2146 * rslcmp -- compare two rsl structures. Use the following
2154 2147 * comparisons to establish cardinality:
2155 2148 *
2156 2149 * 1. Name of the suspect's class. (simple strcmp)
2157 2150 * 2. Name of the suspect's ASRU. (trickier, since nvlist)
2158 2151 *
2159 2152 */
2160 2153 static int
2161 2154 rslcmp(const void *a, const void *b)
2162 2155 {
2163 2156 struct rsl *r1 = (struct rsl *)a;
2164 2157 struct rsl *r2 = (struct rsl *)b;
2165 2158 int rv;
2166 2159
2167 2160 rv = strcmp(r1->suspect->enode->u.event.ename->u.name.s,
2168 2161 r2->suspect->enode->u.event.ename->u.name.s);
2169 2162 if (rv != 0)
2170 2163 return (rv);
2171 2164
2172 2165 if (r1->rsrc == NULL && r2->rsrc == NULL)
2173 2166 return (0);
2174 2167 if (r1->rsrc == NULL)
2175 2168 return (-1);
2176 2169 if (r2->rsrc == NULL)
2177 2170 return (1);
2178 2171 return (evnv_cmpnvl(r1->rsrc, r2->rsrc, 0));
2179 2172 }
2180 2173
2181 2174 /*
2182 2175 * get_resources -- for a given suspect, determine what ASRU, FRU and
2183 2176 * RSRC nvlists should be advertised in the final suspect list.
2184 2177 */
2185 2178 void
2186 2179 get_resources(struct event *sp, struct rsl *rsrcs, struct config *croot)
2187 2180 {
2188 2181 struct node *asrudef, *frudef;
2189 2182 nvlist_t *asru, *fru;
2190 2183 nvlist_t *rsrc = NULL;
2191 2184 char *pathstr;
2192 2185
2193 2186 /*
2194 2187 * First find any ASRU and/or FRU defined in the
2195 2188 * initial fault tree.
2196 2189 */
2197 2190 asrudef = eventprop_lookup(sp, L_ASRU);
2198 2191 frudef = eventprop_lookup(sp, L_FRU);
2199 2192
2200 2193 /*
2201 2194 * Create FMRIs based on those definitions
2202 2195 */
2203 2196 asru = node2fmri(asrudef);
2204 2197 fru = node2fmri(frudef);
2205 2198 pathstr = ipath2str(NULL, sp->ipp);
2206 2199
2207 2200 /*
2208 2201 * Allow for platform translations of the FMRIs
2209 2202 */
2210 2203 platform_units_translate(is_defect(sp->t), croot, &asru, &fru, &rsrc,
2211 2204 pathstr);
2212 2205
2213 2206 FREE(pathstr);
2214 2207 rsrcs->suspect = sp;
2215 2208 rsrcs->asru = asru;
2216 2209 rsrcs->fru = fru;
2217 2210 rsrcs->rsrc = rsrc;
2218 2211 }
2219 2212
2220 2213 /*
2221 2214 * trim_suspects -- prior to publishing, we may need to remove some
2222 2215 * suspects from the list. If we're auto-closing upsets, we don't
2223 2216 * want any of those in the published list. If the ASRUs for multiple
2224 2217 * defects resolve to the same ASRU (driver) we only want to publish
2225 2218 * that as a single suspect.
2226 2219 */
2227 2220 static int
2228 2221 trim_suspects(struct fme *fmep, struct rsl *begin, struct rsl *begin2,
2229 2222 fmd_event_t *ffep)
2230 2223 {
2231 2224 struct event *ep;
2232 2225 struct rsl *rp = begin;
2233 2226 struct rsl *rp2 = begin2;
2234 2227 int mess_zero_count = 0;
2235 2228 int serd_rval;
2236 2229 uint_t messval;
2237 2230
2238 2231 /* remove any unwanted upsets and populate our array */
2239 2232 for (ep = fmep->psuspects; ep; ep = ep->psuspects) {
2240 2233 if (is_upset(ep->t))
2241 2234 continue;
2242 2235 serd_rval = serd_eval(fmep, fmep->hdl, ffep, fmep->fmcase, ep,
2243 2236 NULL, NULL);
2244 2237 if (serd_rval == 0)
2245 2238 continue;
2246 2239 if (node2uint(eventprop_lookup(ep, L_message),
2247 2240 &messval) == 0 && messval == 0) {
2248 2241 get_resources(ep, rp2, fmep->config);
2249 2242 rp2++;
2250 2243 mess_zero_count++;
2251 2244 } else {
2252 2245 get_resources(ep, rp, fmep->config);
2253 2246 rp++;
2254 2247 fmep->nsuspects++;
2255 2248 }
2256 2249 }
2257 2250 return (mess_zero_count);
2258 2251 }
2259 2252
2260 2253 /*
2261 2254 * addpayloadprop -- add a payload prop to a problem
2262 2255 */
2263 2256 static void
2264 2257 addpayloadprop(const char *lhs, struct evalue *rhs, nvlist_t *fault)
2265 2258 {
2266 2259 nvlist_t *rsrc, *hcs;
2267 2260
2268 2261 ASSERT(fault != NULL);
2269 2262 ASSERT(lhs != NULL);
2270 2263 ASSERT(rhs != NULL);
2271 2264
2272 2265 if (nvlist_lookup_nvlist(fault, FM_FAULT_RESOURCE, &rsrc) != 0)
2273 2266 out(O_DIE, "cannot add payloadprop \"%s\" to fault", lhs);
2274 2267
2275 2268 if (nvlist_lookup_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, &hcs) != 0) {
2276 2269 out(O_ALTFP|O_VERB2, "addpayloadprop: create hc_specific");
2277 2270 if (nvlist_xalloc(&hcs, NV_UNIQUE_NAME, &Eft_nv_hdl) != 0)
2278 2271 out(O_DIE,
2279 2272 "cannot add payloadprop \"%s\" to fault", lhs);
2280 2273 if (nvlist_add_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, hcs) != 0)
2281 2274 out(O_DIE,
2282 2275 "cannot add payloadprop \"%s\" to fault", lhs);
2283 2276 nvlist_free(hcs);
2284 2277 if (nvlist_lookup_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, &hcs) != 0)
2285 2278 out(O_DIE,
2286 2279 "cannot add payloadprop \"%s\" to fault", lhs);
2287 2280 } else
2288 2281 out(O_ALTFP|O_VERB2, "addpayloadprop: reuse hc_specific");
2289 2282
2290 2283 if (rhs->t == UINT64) {
2291 2284 out(O_ALTFP|O_VERB2, "addpayloadprop: %s=%llu", lhs, rhs->v);
2292 2285
2293 2286 if (nvlist_add_uint64(hcs, lhs, rhs->v) != 0)
2294 2287 out(O_DIE,
2295 2288 "cannot add payloadprop \"%s\" to fault", lhs);
2296 2289 } else {
2297 2290 out(O_ALTFP|O_VERB2, "addpayloadprop: %s=\"%s\"",
2298 2291 lhs, (char *)(uintptr_t)rhs->v);
2299 2292
2300 2293 if (nvlist_add_string(hcs, lhs, (char *)(uintptr_t)rhs->v) != 0)
2301 2294 out(O_DIE,
2302 2295 "cannot add payloadprop \"%s\" to fault", lhs);
2303 2296 }
2304 2297 }
2305 2298
2306 2299 static char *Istatbuf;
2307 2300 static char *Istatbufptr;
2308 2301 static int Istatsz;
2309 2302
2310 2303 /*
2311 2304 * istataddsize -- calculate size of istat and add it to Istatsz
2312 2305 */
2313 2306 /*ARGSUSED2*/
2314 2307 static void
2315 2308 istataddsize(const struct istat_entry *lhs, struct stats *rhs, void *arg)
2316 2309 {
2317 2310 int val;
2318 2311
2319 2312 ASSERT(lhs != NULL);
2320 2313 ASSERT(rhs != NULL);
2321 2314
2322 2315 if ((val = stats_counter_value(rhs)) == 0)
2323 2316 return; /* skip zero-valued stats */
2324 2317
2325 2318 /* count up the size of the stat name */
2326 2319 Istatsz += ipath2strlen(lhs->ename, lhs->ipath);
2327 2320 Istatsz++; /* for the trailing NULL byte */
2328 2321
2329 2322 /* count up the size of the stat value */
2330 2323 Istatsz += snprintf(NULL, 0, "%d", val);
2331 2324 Istatsz++; /* for the trailing NULL byte */
2332 2325 }
2333 2326
2334 2327 /*
2335 2328 * istat2str -- serialize an istat, writing result to *Istatbufptr
2336 2329 */
2337 2330 /*ARGSUSED2*/
2338 2331 static void
2339 2332 istat2str(const struct istat_entry *lhs, struct stats *rhs, void *arg)
2340 2333 {
2341 2334 char *str;
2342 2335 int len;
2343 2336 int val;
2344 2337
2345 2338 ASSERT(lhs != NULL);
2346 2339 ASSERT(rhs != NULL);
2347 2340
2348 2341 if ((val = stats_counter_value(rhs)) == 0)
2349 2342 return; /* skip zero-valued stats */
2350 2343
2351 2344 /* serialize the stat name */
2352 2345 str = ipath2str(lhs->ename, lhs->ipath);
2353 2346 len = strlen(str);
2354 2347
2355 2348 ASSERT(Istatbufptr + len + 1 < &Istatbuf[Istatsz]);
2356 2349 (void) strlcpy(Istatbufptr, str, &Istatbuf[Istatsz] - Istatbufptr);
2357 2350 Istatbufptr += len;
2358 2351 FREE(str);
2359 2352 *Istatbufptr++ = '\0';
2360 2353
2361 2354 /* serialize the stat value */
2362 2355 Istatbufptr += snprintf(Istatbufptr, &Istatbuf[Istatsz] - Istatbufptr,
2363 2356 "%d", val);
2364 2357 *Istatbufptr++ = '\0';
2365 2358
2366 2359 ASSERT(Istatbufptr <= &Istatbuf[Istatsz]);
2367 2360 }
2368 2361
2369 2362 void
2370 2363 istat_save()
2371 2364 {
2372 2365 if (Istat_need_save == 0)
2373 2366 return;
2374 2367
2375 2368 /* figure out how big the serialzed info is */
2376 2369 Istatsz = 0;
2377 2370 lut_walk(Istats, (lut_cb)istataddsize, NULL);
2378 2371
2379 2372 if (Istatsz == 0) {
2380 2373 /* no stats to save */
2381 2374 fmd_buf_destroy(Hdl, NULL, WOBUF_ISTATS);
2382 2375 return;
2383 2376 }
2384 2377
2385 2378 /* create the serialized buffer */
2386 2379 Istatbufptr = Istatbuf = MALLOC(Istatsz);
2387 2380 lut_walk(Istats, (lut_cb)istat2str, NULL);
2388 2381
2389 2382 /* clear out current saved stats */
2390 2383 fmd_buf_destroy(Hdl, NULL, WOBUF_ISTATS);
2391 2384
2392 2385 /* write out the new version */
2393 2386 fmd_buf_write(Hdl, NULL, WOBUF_ISTATS, Istatbuf, Istatsz);
2394 2387 FREE(Istatbuf);
2395 2388
2396 2389 Istat_need_save = 0;
2397 2390 }
2398 2391
2399 2392 int
2400 2393 istat_cmp(struct istat_entry *ent1, struct istat_entry *ent2)
2401 2394 {
2402 2395 if (ent1->ename != ent2->ename)
2403 2396 return (ent2->ename - ent1->ename);
2404 2397 if (ent1->ipath != ent2->ipath)
2405 2398 return ((char *)ent2->ipath - (char *)ent1->ipath);
2406 2399
2407 2400 return (0);
2408 2401 }
2409 2402
2410 2403 /*
2411 2404 * istat-verify -- verify the component associated with a stat still exists
2412 2405 *
2413 2406 * if the component no longer exists, this routine resets the stat and
2414 2407 * returns 0. if the component still exists, it returns 1.
2415 2408 */
2416 2409 static int
2417 2410 istat_verify(struct node *snp, struct istat_entry *entp)
2418 2411 {
2419 2412 struct stats *statp;
2420 2413 nvlist_t *fmri;
2421 2414
2422 2415 fmri = node2fmri(snp->u.event.epname);
2423 2416 if (platform_path_exists(fmri)) {
2424 2417 nvlist_free(fmri);
2425 2418 return (1);
2426 2419 }
2427 2420 nvlist_free(fmri);
2428 2421
2429 2422 /* component no longer in system. zero out the associated stats */
2430 2423 if ((statp = (struct stats *)
2431 2424 lut_lookup(Istats, entp, (lut_cmp)istat_cmp)) == NULL ||
2432 2425 stats_counter_value(statp) == 0)
2433 2426 return (0); /* stat is already reset */
2434 2427
2435 2428 Istat_need_save = 1;
2436 2429 stats_counter_reset(statp);
2437 2430 return (0);
2438 2431 }
2439 2432
2440 2433 static void
2441 2434 istat_bump(struct node *snp, int n)
2442 2435 {
2443 2436 struct stats *statp;
2444 2437 struct istat_entry ent;
2445 2438
2446 2439 ASSERT(snp != NULL);
2447 2440 ASSERTinfo(snp->t == T_EVENT, ptree_nodetype2str(snp->t));
2448 2441 ASSERT(snp->u.event.epname != NULL);
2449 2442
2450 2443 /* class name should be hoisted into a single stable entry */
2451 2444 ASSERT(snp->u.event.ename->u.name.next == NULL);
2452 2445 ent.ename = snp->u.event.ename->u.name.s;
2453 2446 ent.ipath = ipath(snp->u.event.epname);
2454 2447
2455 2448 if (!istat_verify(snp, &ent)) {
2456 2449 /* component no longer exists in system, nothing to do */
2457 2450 return;
2458 2451 }
2459 2452
2460 2453 if ((statp = (struct stats *)
2461 2454 lut_lookup(Istats, &ent, (lut_cmp)istat_cmp)) == NULL) {
2462 2455 /* need to create the counter */
2463 2456 int cnt = 0;
2464 2457 struct node *np;
2465 2458 char *sname;
2466 2459 char *snamep;
2467 2460 struct istat_entry *newentp;
2468 2461
2469 2462 /* count up the size of the stat name */
2470 2463 np = snp->u.event.ename;
2471 2464 while (np != NULL) {
2472 2465 cnt += strlen(np->u.name.s);
2473 2466 cnt++; /* for the '.' or '@' */
2474 2467 np = np->u.name.next;
2475 2468 }
2476 2469 np = snp->u.event.epname;
2477 2470 while (np != NULL) {
2478 2471 cnt += snprintf(NULL, 0, "%s%llu",
2479 2472 np->u.name.s, np->u.name.child->u.ull);
2480 2473 cnt++; /* for the '/' or trailing NULL byte */
2481 2474 np = np->u.name.next;
2482 2475 }
2483 2476
2484 2477 /* build the stat name */
2485 2478 snamep = sname = alloca(cnt);
2486 2479 np = snp->u.event.ename;
2487 2480 while (np != NULL) {
2488 2481 snamep += snprintf(snamep, &sname[cnt] - snamep,
2489 2482 "%s", np->u.name.s);
2490 2483 np = np->u.name.next;
2491 2484 if (np)
2492 2485 *snamep++ = '.';
2493 2486 }
2494 2487 *snamep++ = '@';
2495 2488 np = snp->u.event.epname;
2496 2489 while (np != NULL) {
2497 2490 snamep += snprintf(snamep, &sname[cnt] - snamep,
2498 2491 "%s%llu", np->u.name.s, np->u.name.child->u.ull);
2499 2492 np = np->u.name.next;
2500 2493 if (np)
2501 2494 *snamep++ = '/';
2502 2495 }
2503 2496 *snamep++ = '\0';
2504 2497
2505 2498 /* create the new stat & add it to our list */
2506 2499 newentp = MALLOC(sizeof (*newentp));
2507 2500 *newentp = ent;
2508 2501 statp = stats_new_counter(NULL, sname, 0);
2509 2502 Istats = lut_add(Istats, (void *)newentp, (void *)statp,
2510 2503 (lut_cmp)istat_cmp);
2511 2504 }
2512 2505
2513 2506 /* if n is non-zero, set that value instead of bumping */
2514 2507 if (n) {
2515 2508 stats_counter_reset(statp);
2516 2509 stats_counter_add(statp, n);
2517 2510 } else
2518 2511 stats_counter_bump(statp);
2519 2512 Istat_need_save = 1;
2520 2513
2521 2514 ipath_print(O_ALTFP|O_VERB2, ent.ename, ent.ipath);
2522 2515 out(O_ALTFP|O_VERB2, " %s to value %d", n ? "set" : "incremented",
2523 2516 stats_counter_value(statp));
2524 2517 }
2525 2518
2526 2519 /*ARGSUSED*/
2527 2520 static void
2528 2521 istat_destructor(void *left, void *right, void *arg)
2529 2522 {
2530 2523 struct istat_entry *entp = (struct istat_entry *)left;
2531 2524 struct stats *statp = (struct stats *)right;
2532 2525 FREE(entp);
2533 2526 stats_delete(statp);
2534 2527 }
2535 2528
2536 2529 /*
2537 2530 * Callback used in a walk of the Istats to reset matching stat counters.
2538 2531 */
2539 2532 static void
2540 2533 istat_counter_reset_cb(struct istat_entry *entp, struct stats *statp,
2541 2534 const struct ipath *ipp)
2542 2535 {
2543 2536 char *path;
2544 2537
2545 2538 if (entp->ipath == ipp) {
2546 2539 path = ipath2str(entp->ename, ipp);
2547 2540 out(O_ALTFP, "istat_counter_reset_cb: resetting %s", path);
2548 2541 FREE(path);
2549 2542 stats_counter_reset(statp);
2550 2543 Istat_need_save = 1;
2551 2544 }
2552 2545 }
2553 2546
2554 2547 /*ARGSUSED*/
2555 2548 static void
2556 2549 istat_counter_topo_chg_cb(struct istat_entry *entp, struct stats *statp,
2557 2550 void *unused)
2558 2551 {
2559 2552 char *path;
2560 2553 nvlist_t *fmri;
2561 2554
2562 2555 fmri = ipath2fmri((struct ipath *)(entp->ipath));
2563 2556 if (!platform_path_exists(fmri)) {
2564 2557 path = ipath2str(entp->ename, entp->ipath);
2565 2558 out(O_ALTFP, "istat_counter_topo_chg_cb: not present %s", path);
2566 2559 FREE(path);
2567 2560 stats_counter_reset(statp);
2568 2561 Istat_need_save = 1;
2569 2562 }
2570 2563 nvlist_free(fmri);
2571 2564 }
2572 2565
2573 2566 void
2574 2567 istat_fini(void)
2575 2568 {
2576 2569 lut_free(Istats, istat_destructor, NULL);
2577 2570 }
2578 2571
2579 2572 static char *Serdbuf;
2580 2573 static char *Serdbufptr;
2581 2574 static int Serdsz;
2582 2575
2583 2576 /*
2584 2577 * serdaddsize -- calculate size of serd and add it to Serdsz
2585 2578 */
2586 2579 /*ARGSUSED*/
2587 2580 static void
2588 2581 serdaddsize(const struct serd_entry *lhs, struct stats *rhs, void *arg)
2589 2582 {
2590 2583 ASSERT(lhs != NULL);
2591 2584
2592 2585 /* count up the size of the stat name */
2593 2586 Serdsz += ipath2strlen(lhs->ename, lhs->ipath);
2594 2587 Serdsz++; /* for the trailing NULL byte */
2595 2588 }
2596 2589
2597 2590 /*
2598 2591 * serd2str -- serialize a serd engine, writing result to *Serdbufptr
2599 2592 */
2600 2593 /*ARGSUSED*/
2601 2594 static void
2602 2595 serd2str(const struct serd_entry *lhs, struct stats *rhs, void *arg)
2603 2596 {
2604 2597 char *str;
2605 2598 int len;
2606 2599
2607 2600 ASSERT(lhs != NULL);
2608 2601
2609 2602 /* serialize the serd engine name */
2610 2603 str = ipath2str(lhs->ename, lhs->ipath);
2611 2604 len = strlen(str);
2612 2605
2613 2606 ASSERT(Serdbufptr + len + 1 <= &Serdbuf[Serdsz]);
2614 2607 (void) strlcpy(Serdbufptr, str, &Serdbuf[Serdsz] - Serdbufptr);
2615 2608 Serdbufptr += len;
2616 2609 FREE(str);
2617 2610 *Serdbufptr++ = '\0';
2618 2611 ASSERT(Serdbufptr <= &Serdbuf[Serdsz]);
2619 2612 }
2620 2613
2621 2614 void
2622 2615 serd_save()
2623 2616 {
2624 2617 if (Serd_need_save == 0)
2625 2618 return;
2626 2619
2627 2620 /* figure out how big the serialzed info is */
2628 2621 Serdsz = 0;
2629 2622 lut_walk(SerdEngines, (lut_cb)serdaddsize, NULL);
2630 2623
2631 2624 if (Serdsz == 0) {
2632 2625 /* no serd engines to save */
2633 2626 fmd_buf_destroy(Hdl, NULL, WOBUF_SERDS);
2634 2627 return;
2635 2628 }
2636 2629
2637 2630 /* create the serialized buffer */
2638 2631 Serdbufptr = Serdbuf = MALLOC(Serdsz);
2639 2632 lut_walk(SerdEngines, (lut_cb)serd2str, NULL);
2640 2633
2641 2634 /* clear out current saved stats */
2642 2635 fmd_buf_destroy(Hdl, NULL, WOBUF_SERDS);
2643 2636
2644 2637 /* write out the new version */
2645 2638 fmd_buf_write(Hdl, NULL, WOBUF_SERDS, Serdbuf, Serdsz);
2646 2639 FREE(Serdbuf);
2647 2640 Serd_need_save = 0;
2648 2641 }
2649 2642
2650 2643 int
2651 2644 serd_cmp(struct serd_entry *ent1, struct serd_entry *ent2)
2652 2645 {
2653 2646 if (ent1->ename != ent2->ename)
2654 2647 return (ent2->ename - ent1->ename);
2655 2648 if (ent1->ipath != ent2->ipath)
2656 2649 return ((char *)ent2->ipath - (char *)ent1->ipath);
2657 2650
2658 2651 return (0);
2659 2652 }
2660 2653
2661 2654 void
2662 2655 fme_serd_load(fmd_hdl_t *hdl)
2663 2656 {
2664 2657 int sz;
2665 2658 char *sbuf;
2666 2659 char *sepptr;
2667 2660 char *ptr;
2668 2661 struct serd_entry *newentp;
2669 2662 struct node *epname;
2670 2663 nvlist_t *fmri;
2671 2664 char *namestring;
2672 2665
2673 2666 if ((sz = fmd_buf_size(hdl, NULL, WOBUF_SERDS)) == 0)
2674 2667 return;
2675 2668 sbuf = alloca(sz);
2676 2669 fmd_buf_read(hdl, NULL, WOBUF_SERDS, sbuf, sz);
2677 2670 ptr = sbuf;
2678 2671 while (ptr < &sbuf[sz]) {
2679 2672 sepptr = strchr(ptr, '@');
2680 2673 *sepptr = '\0';
2681 2674 namestring = ptr;
2682 2675 sepptr++;
2683 2676 ptr = sepptr;
2684 2677 ptr += strlen(ptr);
2685 2678 ptr++; /* move past the '\0' separating paths */
2686 2679 epname = pathstring2epnamenp(sepptr);
2687 2680 fmri = node2fmri(epname);
2688 2681 if (platform_path_exists(fmri)) {
2689 2682 newentp = MALLOC(sizeof (*newentp));
2690 2683 newentp->hdl = hdl;
2691 2684 newentp->ipath = ipath(epname);
2692 2685 newentp->ename = stable(namestring);
2693 2686 SerdEngines = lut_add(SerdEngines, (void *)newentp,
2694 2687 (void *)newentp, (lut_cmp)serd_cmp);
2695 2688 } else
2696 2689 Serd_need_save = 1;
2697 2690 tree_free(epname);
2698 2691 nvlist_free(fmri);
2699 2692 }
2700 2693 /* save it back again in case some of the paths no longer exist */
2701 2694 serd_save();
2702 2695 }
2703 2696
2704 2697 /*ARGSUSED*/
2705 2698 static void
2706 2699 serd_destructor(void *left, void *right, void *arg)
2707 2700 {
2708 2701 struct serd_entry *entp = (struct serd_entry *)left;
2709 2702 FREE(entp);
2710 2703 }
2711 2704
2712 2705 /*
2713 2706 * Callback used in a walk of the SerdEngines to reset matching serd engines.
2714 2707 */
2715 2708 /*ARGSUSED*/
2716 2709 static void
2717 2710 serd_reset_cb(struct serd_entry *entp, void *unused, const struct ipath *ipp)
2718 2711 {
2719 2712 char *path;
2720 2713
2721 2714 if (entp->ipath == ipp) {
2722 2715 path = ipath2str(entp->ename, ipp);
2723 2716 out(O_ALTFP, "serd_reset_cb: resetting %s", path);
2724 2717 fmd_serd_reset(entp->hdl, path);
2725 2718 FREE(path);
2726 2719 Serd_need_save = 1;
2727 2720 }
2728 2721 }
2729 2722
2730 2723 /*ARGSUSED*/
2731 2724 static void
2732 2725 serd_topo_chg_cb(struct serd_entry *entp, void *unused, void *unused2)
2733 2726 {
2734 2727 char *path;
2735 2728 nvlist_t *fmri;
2736 2729
2737 2730 fmri = ipath2fmri((struct ipath *)(entp->ipath));
2738 2731 if (!platform_path_exists(fmri)) {
2739 2732 path = ipath2str(entp->ename, entp->ipath);
2740 2733 out(O_ALTFP, "serd_topo_chg_cb: not present %s", path);
2741 2734 fmd_serd_reset(entp->hdl, path);
2742 2735 FREE(path);
2743 2736 Serd_need_save = 1;
2744 2737 }
2745 2738 nvlist_free(fmri);
2746 2739 }
2747 2740
2748 2741 void
2749 2742 serd_fini(void)
2750 2743 {
2751 2744 lut_free(SerdEngines, serd_destructor, NULL);
2752 2745 }
2753 2746
2754 2747 static void
2755 2748 publish_suspects(struct fme *fmep, struct rsl *srl)
2756 2749 {
2757 2750 struct rsl *rp;
2758 2751 nvlist_t *fault;
2759 2752 uint8_t cert;
2760 2753 uint_t *frs;
2761 2754 uint_t frsum, fr;
2762 2755 uint_t messval;
2763 2756 uint_t retireval;
2764 2757 uint_t responseval;
2765 2758 struct node *snp;
2766 2759 int frcnt, fridx;
2767 2760 boolean_t allfaulty = B_TRUE;
2768 2761 struct rsl *erl = srl + fmep->nsuspects - 1;
2769 2762
2770 2763 /*
2771 2764 * sort the array
2772 2765 */
2773 2766 qsort(srl, fmep->nsuspects, sizeof (struct rsl), rslcmp);
2774 2767
2775 2768 /* sum the fitrates */
2776 2769 frs = alloca(fmep->nsuspects * sizeof (uint_t));
2777 2770 fridx = frcnt = frsum = 0;
2778 2771
2779 2772 for (rp = srl; rp <= erl; rp++) {
2780 2773 struct node *n;
2781 2774
2782 2775 n = eventprop_lookup(rp->suspect, L_FITrate);
2783 2776 if (node2uint(n, &fr) != 0) {
2784 2777 out(O_DEBUG|O_NONL, "event ");
2785 2778 ipath_print(O_DEBUG|O_NONL,
2786 2779 rp->suspect->enode->u.event.ename->u.name.s,
2787 2780 rp->suspect->ipp);
2788 2781 out(O_VERB, " has no FITrate (using 1)");
2789 2782 fr = 1;
2790 2783 } else if (fr == 0) {
2791 2784 out(O_DEBUG|O_NONL, "event ");
2792 2785 ipath_print(O_DEBUG|O_NONL,
2793 2786 rp->suspect->enode->u.event.ename->u.name.s,
2794 2787 rp->suspect->ipp);
2795 2788 out(O_VERB, " has zero FITrate (using 1)");
2796 2789 fr = 1;
2797 2790 }
2798 2791
2799 2792 frs[fridx++] = fr;
2800 2793 frsum += fr;
2801 2794 frcnt++;
2802 2795 }
2803 2796
2804 2797 /* Add them in reverse order of our sort, as fmd reverses order */
2805 2798 for (rp = erl; rp >= srl; rp--) {
2806 2799 cert = percentof(frs[--fridx], frsum);
2807 2800 fault = fmd_nvl_create_fault(fmep->hdl,
2808 2801 rp->suspect->enode->u.event.ename->u.name.s,
2809 2802 cert,
2810 2803 rp->asru,
2811 2804 rp->fru,
2812 2805 rp->rsrc);
2813 2806 if (fault == NULL)
2814 2807 out(O_DIE, "fault creation failed");
2815 2808 /* if "message" property exists, add it to the fault */
2816 2809 if (node2uint(eventprop_lookup(rp->suspect, L_message),
2817 2810 &messval) == 0) {
2818 2811
2819 2812 out(O_ALTFP,
2820 2813 "[FME%d, %s adds message=%d to suspect list]",
2821 2814 fmep->id,
2822 2815 rp->suspect->enode->u.event.ename->u.name.s,
2823 2816 messval);
2824 2817 if (nvlist_add_boolean_value(fault,
2825 2818 FM_SUSPECT_MESSAGE,
2826 2819 (messval) ? B_TRUE : B_FALSE) != 0) {
2827 2820 out(O_DIE, "cannot add no-message to fault");
2828 2821 }
2829 2822 }
2830 2823
2831 2824 /* if "retire" property exists, add it to the fault */
2832 2825 if (node2uint(eventprop_lookup(rp->suspect, L_retire),
2833 2826 &retireval) == 0) {
2834 2827
2835 2828 out(O_ALTFP,
2836 2829 "[FME%d, %s adds retire=%d to suspect list]",
2837 2830 fmep->id,
2838 2831 rp->suspect->enode->u.event.ename->u.name.s,
2839 2832 retireval);
2840 2833 if (nvlist_add_boolean_value(fault,
2841 2834 FM_SUSPECT_RETIRE,
2842 2835 (retireval) ? B_TRUE : B_FALSE) != 0) {
2843 2836 out(O_DIE, "cannot add no-retire to fault");
2844 2837 }
2845 2838 }
2846 2839
2847 2840 /* if "response" property exists, add it to the fault */
2848 2841 if (node2uint(eventprop_lookup(rp->suspect, L_response),
2849 2842 &responseval) == 0) {
2850 2843
2851 2844 out(O_ALTFP,
2852 2845 "[FME%d, %s adds response=%d to suspect list]",
2853 2846 fmep->id,
2854 2847 rp->suspect->enode->u.event.ename->u.name.s,
2855 2848 responseval);
2856 2849 if (nvlist_add_boolean_value(fault,
2857 2850 FM_SUSPECT_RESPONSE,
2858 2851 (responseval) ? B_TRUE : B_FALSE) != 0) {
2859 2852 out(O_DIE, "cannot add no-response to fault");
2860 2853 }
2861 2854 }
2862 2855
2863 2856 /* add any payload properties */
2864 2857 lut_walk(rp->suspect->payloadprops,
2865 2858 (lut_cb)addpayloadprop, (void *)fault);
2866 2859 rslfree(rp);
2867 2860
2868 2861 /*
2869 2862 * If "action" property exists, evaluate it; this must be done
2870 2863 * before the allfaulty check below since some actions may
2871 2864 * modify the asru to be used in fmd_nvl_fmri_has_fault. This
2872 2865 * needs to be restructured if any new actions are introduced
2873 2866 * that have effects that we do not want to be visible if
2874 2867 * we decide not to publish in the dupclose check below.
2875 2868 */
2876 2869 if ((snp = eventprop_lookup(rp->suspect, L_action)) != NULL) {
2877 2870 struct evalue evalue;
2878 2871
2879 2872 out(O_ALTFP|O_NONL,
2880 2873 "[FME%d, %s action ", fmep->id,
2881 2874 rp->suspect->enode->u.event.ename->u.name.s);
2882 2875 ptree_name_iter(O_ALTFP|O_NONL, snp);
2883 2876 out(O_ALTFP, "]");
2884 2877 Action_nvl = fault;
2885 2878 (void) eval_expr(snp, NULL, NULL, NULL, NULL,
2886 2879 NULL, 0, &evalue);
2887 2880 }
2888 2881
2889 2882 fmd_case_add_suspect(fmep->hdl, fmep->fmcase, fault);
2890 2883
2891 2884 /*
2892 2885 * check if the asru is already marked as "faulty".
2893 2886 */
2894 2887 if (allfaulty) {
2895 2888 nvlist_t *asru;
2896 2889
2897 2890 out(O_ALTFP|O_VERB, "FME%d dup check ", fmep->id);
2898 2891 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, rp->suspect);
2899 2892 out(O_ALTFP|O_VERB|O_NONL, " ");
2900 2893 if (nvlist_lookup_nvlist(fault,
2901 2894 FM_FAULT_ASRU, &asru) != 0) {
2902 2895 out(O_ALTFP|O_VERB, "NULL asru");
2903 2896 allfaulty = B_FALSE;
2904 2897 } else if (fmd_nvl_fmri_has_fault(fmep->hdl, asru,
2905 2898 FMD_HAS_FAULT_ASRU, NULL)) {
2906 2899 out(O_ALTFP|O_VERB, "faulty");
2907 2900 } else {
2908 2901 out(O_ALTFP|O_VERB, "not faulty");
2909 2902 allfaulty = B_FALSE;
2910 2903 }
2911 2904 }
2912 2905
2913 2906 }
2914 2907
2915 2908 if (!allfaulty) {
2916 2909 /*
2917 2910 * don't update the count stat if all asrus are already
2918 2911 * present and unrepaired in the asru cache
2919 2912 */
2920 2913 for (rp = erl; rp >= srl; rp--) {
2921 2914 struct event *suspect = rp->suspect;
2922 2915
2923 2916 if (suspect == NULL)
2924 2917 continue;
2925 2918
2926 2919 /* if "count" exists, increment the appropriate stat */
2927 2920 if ((snp = eventprop_lookup(suspect,
2928 2921 L_count)) != NULL) {
2929 2922 out(O_ALTFP|O_NONL,
2930 2923 "[FME%d, %s count ", fmep->id,
2931 2924 suspect->enode->u.event.ename->u.name.s);
2932 2925 ptree_name_iter(O_ALTFP|O_NONL, snp);
2933 2926 out(O_ALTFP, "]");
2934 2927 istat_bump(snp, 0);
2935 2928
2936 2929 }
2937 2930 }
2938 2931 istat_save(); /* write out any istat changes */
2939 2932 }
2940 2933 }
2941 2934
2942 2935 static const char *
2943 2936 undiag_2defect_str(int ud)
2944 2937 {
2945 2938 switch (ud) {
2946 2939 case UD_VAL_MISSINGINFO:
2947 2940 case UD_VAL_MISSINGOBS:
2948 2941 case UD_VAL_MISSINGPATH:
2949 2942 case UD_VAL_MISSINGZERO:
2950 2943 case UD_VAL_BADOBS:
2951 2944 case UD_VAL_CFGMISMATCH:
2952 2945 return (UNDIAG_DEFECT_CHKPT);
2953 2946
2954 2947 case UD_VAL_BADEVENTI:
2955 2948 case UD_VAL_BADEVENTPATH:
2956 2949 case UD_VAL_BADEVENTCLASS:
2957 2950 case UD_VAL_INSTFAIL:
2958 2951 case UD_VAL_NOPATH:
2959 2952 case UD_VAL_UNSOLVD:
2960 2953 return (UNDIAG_DEFECT_FME);
2961 2954
2962 2955 case UD_VAL_MAXFME:
2963 2956 return (UNDIAG_DEFECT_LIMIT);
2964 2957
2965 2958 case UD_VAL_UNKNOWN:
2966 2959 default:
2967 2960 return (UNDIAG_DEFECT_UNKNOWN);
2968 2961 }
2969 2962 }
2970 2963
2971 2964 static const char *
2972 2965 undiag_2fault_str(int ud)
2973 2966 {
2974 2967 switch (ud) {
2975 2968 case UD_VAL_BADEVENTI:
2976 2969 case UD_VAL_BADEVENTPATH:
2977 2970 case UD_VAL_BADEVENTCLASS:
2978 2971 case UD_VAL_INSTFAIL:
2979 2972 case UD_VAL_NOPATH:
2980 2973 case UD_VAL_UNSOLVD:
2981 2974 return (UNDIAG_FAULT_FME);
2982 2975 default:
2983 2976 return (NULL);
2984 2977 }
2985 2978 }
2986 2979
2987 2980 static char *
2988 2981 undiag_2reason_str(int ud, char *arg)
2989 2982 {
2990 2983 const char *ptr;
2991 2984 char *buf;
2992 2985 int with_arg = 0;
2993 2986
2994 2987 switch (ud) {
2995 2988 case UD_VAL_BADEVENTPATH:
2996 2989 ptr = UD_STR_BADEVENTPATH;
2997 2990 with_arg = 1;
2998 2991 break;
2999 2992 case UD_VAL_BADEVENTCLASS:
3000 2993 ptr = UD_STR_BADEVENTCLASS;
3001 2994 with_arg = 1;
3002 2995 break;
3003 2996 case UD_VAL_BADEVENTI:
3004 2997 ptr = UD_STR_BADEVENTI;
3005 2998 with_arg = 1;
3006 2999 break;
3007 3000 case UD_VAL_BADOBS:
3008 3001 ptr = UD_STR_BADOBS;
3009 3002 break;
3010 3003 case UD_VAL_CFGMISMATCH:
3011 3004 ptr = UD_STR_CFGMISMATCH;
3012 3005 break;
3013 3006 case UD_VAL_INSTFAIL:
3014 3007 ptr = UD_STR_INSTFAIL;
3015 3008 with_arg = 1;
3016 3009 break;
3017 3010 case UD_VAL_MAXFME:
3018 3011 ptr = UD_STR_MAXFME;
3019 3012 break;
3020 3013 case UD_VAL_MISSINGINFO:
3021 3014 ptr = UD_STR_MISSINGINFO;
3022 3015 break;
3023 3016 case UD_VAL_MISSINGOBS:
3024 3017 ptr = UD_STR_MISSINGOBS;
3025 3018 break;
3026 3019 case UD_VAL_MISSINGPATH:
3027 3020 ptr = UD_STR_MISSINGPATH;
3028 3021 break;
3029 3022 case UD_VAL_MISSINGZERO:
3030 3023 ptr = UD_STR_MISSINGZERO;
3031 3024 break;
3032 3025 case UD_VAL_NOPATH:
3033 3026 ptr = UD_STR_NOPATH;
3034 3027 with_arg = 1;
3035 3028 break;
3036 3029 case UD_VAL_UNSOLVD:
3037 3030 ptr = UD_STR_UNSOLVD;
3038 3031 break;
3039 3032 case UD_VAL_UNKNOWN:
3040 3033 default:
3041 3034 ptr = UD_STR_UNKNOWN;
3042 3035 break;
3043 3036 }
3044 3037 if (with_arg) {
3045 3038 buf = MALLOC(strlen(ptr) + strlen(arg) - 1);
3046 3039 (void) sprintf(buf, ptr, arg);
3047 3040 } else {
3048 3041 buf = MALLOC(strlen(ptr) + 1);
3049 3042 (void) sprintf(buf, ptr);
3050 3043 }
3051 3044 return (buf);
3052 3045 }
3053 3046
3054 3047 static void
3055 3048 publish_undiagnosable(fmd_hdl_t *hdl, fmd_event_t *ffep, fmd_case_t *fmcase,
3056 3049 nvlist_t *detector, char *arg)
3057 3050 {
3058 3051 struct case_list *newcase;
3059 3052 nvlist_t *defect, *fault;
3060 3053 const char *faultstr;
3061 3054 char *reason = undiag_2reason_str(Undiag_reason, arg);
3062 3055
3063 3056 out(O_ALTFP,
3064 3057 "[undiagnosable ereport received, "
3065 3058 "creating and closing a new case (%s)]", reason);
3066 3059
3067 3060 newcase = MALLOC(sizeof (struct case_list));
3068 3061 newcase->next = NULL;
3069 3062 newcase->fmcase = fmcase;
3070 3063 if (Undiagablecaselist != NULL)
3071 3064 newcase->next = Undiagablecaselist;
3072 3065 Undiagablecaselist = newcase;
3073 3066
3074 3067 if (ffep != NULL)
3075 3068 fmd_case_add_ereport(hdl, newcase->fmcase, ffep);
3076 3069
3077 3070 /* add defect */
3078 3071 defect = fmd_nvl_create_fault(hdl,
3079 3072 undiag_2defect_str(Undiag_reason), 50, NULL, NULL, detector);
3080 3073 (void) nvlist_add_string(defect, UNDIAG_REASON, reason);
3081 3074 (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RETIRE, B_FALSE);
3082 3075 (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RESPONSE, B_FALSE);
3083 3076 fmd_case_add_suspect(hdl, newcase->fmcase, defect);
3084 3077
3085 3078 /* add fault if appropriate */
3086 3079 faultstr = undiag_2fault_str(Undiag_reason);
3087 3080 if (faultstr != NULL) {
3088 3081 fault = fmd_nvl_create_fault(hdl, faultstr, 50, NULL, NULL,
3089 3082 detector);
3090 3083 (void) nvlist_add_string(fault, UNDIAG_REASON, reason);
3091 3084 (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RETIRE,
3092 3085 B_FALSE);
3093 3086 (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RESPONSE,
3094 3087 B_FALSE);
3095 3088 fmd_case_add_suspect(hdl, newcase->fmcase, fault);
3096 3089 }
3097 3090 FREE(reason);
3098 3091
3099 3092 /* solve and close case */
3100 3093 fmd_case_solve(hdl, newcase->fmcase);
3101 3094 fmd_case_close(hdl, newcase->fmcase);
3102 3095 Undiag_reason = UD_VAL_UNKNOWN;
3103 3096 }
3104 3097
3105 3098 static void
3106 3099 fme_undiagnosable(struct fme *f)
3107 3100 {
3108 3101 nvlist_t *defect, *fault, *detector = NULL;
3109 3102 struct event *ep;
3110 3103 char *pathstr;
3111 3104 const char *faultstr;
3112 3105 char *reason = undiag_2reason_str(Undiag_reason, NULL);
3113 3106
3114 3107 out(O_ALTFP, "[solving/closing FME%d, case %s (%s)]",
3115 3108 f->id, fmd_case_uuid(f->hdl, f->fmcase), reason);
3116 3109
3117 3110 for (ep = f->observations; ep; ep = ep->observations) {
3118 3111
3119 3112 if (ep->ffep != f->e0r)
3120 3113 fmd_case_add_ereport(f->hdl, f->fmcase, ep->ffep);
3121 3114
3122 3115 pathstr = ipath2str(NULL, ipath(platform_getpath(ep->nvp)));
3123 3116 platform_units_translate(0, f->config, NULL, NULL, &detector,
3124 3117 pathstr);
3125 3118 FREE(pathstr);
3126 3119
3127 3120 /* add defect */
3128 3121 defect = fmd_nvl_create_fault(f->hdl,
3129 3122 undiag_2defect_str(Undiag_reason), 50 / f->uniqobs,
3130 3123 NULL, NULL, detector);
3131 3124 (void) nvlist_add_string(defect, UNDIAG_REASON, reason);
3132 3125 (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RETIRE,
3133 3126 B_FALSE);
3134 3127 (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RESPONSE,
3135 3128 B_FALSE);
3136 3129 fmd_case_add_suspect(f->hdl, f->fmcase, defect);
3137 3130
3138 3131 /* add fault if appropriate */
3139 3132 faultstr = undiag_2fault_str(Undiag_reason);
3140 3133 if (faultstr == NULL)
3141 3134 continue;
3142 3135 fault = fmd_nvl_create_fault(f->hdl, faultstr, 50 / f->uniqobs,
3143 3136 NULL, NULL, detector);
3144 3137 (void) nvlist_add_string(fault, UNDIAG_REASON, reason);
3145 3138 (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RETIRE,
3146 3139 B_FALSE);
3147 3140 (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RESPONSE,
3148 3141 B_FALSE);
3149 3142 fmd_case_add_suspect(f->hdl, f->fmcase, fault);
3150 3143 nvlist_free(detector);
3151 3144 }
3152 3145 FREE(reason);
3153 3146 fmd_case_solve(f->hdl, f->fmcase);
3154 3147 fmd_case_close(f->hdl, f->fmcase);
3155 3148 Undiag_reason = UD_VAL_UNKNOWN;
3156 3149 }
3157 3150
3158 3151 /*
3159 3152 * fme_close_case
3160 3153 *
3161 3154 * Find the requested case amongst our fmes and close it. Free up
3162 3155 * the related fme.
3163 3156 */
3164 3157 void
3165 3158 fme_close_case(fmd_hdl_t *hdl, fmd_case_t *fmcase)
3166 3159 {
3167 3160 struct case_list *ucasep, *prevcasep = NULL;
3168 3161 struct fme *prev = NULL;
3169 3162 struct fme *fmep;
3170 3163
3171 3164 for (ucasep = Undiagablecaselist; ucasep; ucasep = ucasep->next) {
3172 3165 if (fmcase != ucasep->fmcase) {
3173 3166 prevcasep = ucasep;
3174 3167 continue;
3175 3168 }
3176 3169
3177 3170 if (prevcasep == NULL)
3178 3171 Undiagablecaselist = Undiagablecaselist->next;
3179 3172 else
3180 3173 prevcasep->next = ucasep->next;
3181 3174
3182 3175 FREE(ucasep);
3183 3176 return;
3184 3177 }
3185 3178
3186 3179 for (fmep = FMElist; fmep; fmep = fmep->next) {
3187 3180 if (fmep->hdl == hdl && fmep->fmcase == fmcase)
3188 3181 break;
3189 3182 prev = fmep;
3190 3183 }
3191 3184
3192 3185 if (fmep == NULL) {
3193 3186 out(O_WARN, "Eft asked to close unrecognized case [%s].",
3194 3187 fmd_case_uuid(hdl, fmcase));
3195 3188 return;
3196 3189 }
3197 3190
3198 3191 if (EFMElist == fmep)
3199 3192 EFMElist = prev;
3200 3193
3201 3194 if (prev == NULL)
3202 3195 FMElist = FMElist->next;
3203 3196 else
3204 3197 prev->next = fmep->next;
3205 3198
3206 3199 fmep->next = NULL;
3207 3200
3208 3201 /* Get rid of any timer this fme has set */
3209 3202 if (fmep->wull != 0)
3210 3203 fmd_timer_remove(fmep->hdl, fmep->timer);
3211 3204
3212 3205 if (ClosedFMEs == NULL) {
3213 3206 ClosedFMEs = fmep;
3214 3207 } else {
3215 3208 fmep->next = ClosedFMEs;
3216 3209 ClosedFMEs = fmep;
3217 3210 }
3218 3211
3219 3212 Open_fme_count--;
3220 3213
3221 3214 /* See if we can close the overflow FME */
3222 3215 if (Open_fme_count <= Max_fme) {
3223 3216 for (fmep = FMElist; fmep; fmep = fmep->next) {
3224 3217 if (fmep->overflow && !(fmd_case_closed(fmep->hdl,
3225 3218 fmep->fmcase)))
3226 3219 break;
3227 3220 }
3228 3221
3229 3222 if (fmep != NULL)
3230 3223 fmd_case_close(fmep->hdl, fmep->fmcase);
3231 3224 }
3232 3225 }
3233 3226
3234 3227 /*
3235 3228 * fme_set_timer()
3236 3229 * If the time we need to wait for the given FME is less than the
3237 3230 * current timer, kick that old timer out and establish a new one.
3238 3231 */
3239 3232 static int
3240 3233 fme_set_timer(struct fme *fmep, unsigned long long wull)
3241 3234 {
3242 3235 out(O_ALTFP|O_VERB|O_NONL, " fme_set_timer: request to wait ");
3243 3236 ptree_timeval(O_ALTFP|O_VERB, &wull);
3244 3237
3245 3238 if (wull <= fmep->pull) {
3246 3239 out(O_ALTFP|O_VERB|O_NONL, "already have waited at least ");
3247 3240 ptree_timeval(O_ALTFP|O_VERB, &fmep->pull);
3248 3241 out(O_ALTFP|O_VERB, NULL);
3249 3242 /* we've waited at least wull already, don't need timer */
3250 3243 return (0);
3251 3244 }
3252 3245
3253 3246 out(O_ALTFP|O_VERB|O_NONL, " currently ");
3254 3247 if (fmep->wull != 0) {
3255 3248 out(O_ALTFP|O_VERB|O_NONL, "waiting ");
3256 3249 ptree_timeval(O_ALTFP|O_VERB, &fmep->wull);
3257 3250 out(O_ALTFP|O_VERB, NULL);
3258 3251 } else {
3259 3252 out(O_ALTFP|O_VERB|O_NONL, "not waiting");
3260 3253 out(O_ALTFP|O_VERB, NULL);
3261 3254 }
3262 3255
3263 3256 if (fmep->wull != 0)
3264 3257 if (wull >= fmep->wull)
3265 3258 /* New timer would fire later than established timer */
3266 3259 return (0);
3267 3260
3268 3261 if (fmep->wull != 0) {
3269 3262 fmd_timer_remove(fmep->hdl, fmep->timer);
3270 3263 }
3271 3264
3272 3265 fmep->timer = fmd_timer_install(fmep->hdl, (void *)fmep,
3273 3266 fmep->e0r, wull);
3274 3267 out(O_ALTFP|O_VERB, "timer set, id is %ld", fmep->timer);
3275 3268 fmep->wull = wull;
3276 3269 return (1);
3277 3270 }
3278 3271
3279 3272 void
3280 3273 fme_timer_fired(struct fme *fmep, id_t tid)
3281 3274 {
3282 3275 struct fme *ffmep = NULL;
3283 3276
3284 3277 for (ffmep = FMElist; ffmep; ffmep = ffmep->next)
3285 3278 if (ffmep == fmep)
3286 3279 break;
3287 3280
3288 3281 if (ffmep == NULL) {
3289 3282 out(O_WARN, "Timer fired for an FME (%p) not in FMEs list.",
3290 3283 (void *)fmep);
3291 3284 return;
3292 3285 }
3293 3286
3294 3287 out(O_ALTFP|O_VERB, "Timer fired %lx", tid);
3295 3288 fmep->pull = fmep->wull;
3296 3289 fmep->wull = 0;
3297 3290 fmd_buf_write(fmep->hdl, fmep->fmcase,
3298 3291 WOBUF_PULL, (void *)&fmep->pull, sizeof (fmep->pull));
3299 3292
3300 3293 fme_eval(fmep, fmep->e0r);
3301 3294 }
3302 3295
3303 3296 /*
3304 3297 * Preserve the fme's suspect list in its psuspects list, NULLing the
3305 3298 * suspects list in the meantime.
3306 3299 */
3307 3300 static void
3308 3301 save_suspects(struct fme *fmep)
3309 3302 {
3310 3303 struct event *ep;
3311 3304 struct event *nextep;
3312 3305
3313 3306 /* zero out the previous suspect list */
3314 3307 for (ep = fmep->psuspects; ep; ep = nextep) {
3315 3308 nextep = ep->psuspects;
3316 3309 ep->psuspects = NULL;
3317 3310 }
3318 3311 fmep->psuspects = NULL;
3319 3312
3320 3313 /* zero out the suspect list, copying it to previous suspect list */
3321 3314 fmep->psuspects = fmep->suspects;
3322 3315 for (ep = fmep->suspects; ep; ep = nextep) {
3323 3316 nextep = ep->suspects;
3324 3317 ep->psuspects = ep->suspects;
3325 3318 ep->suspects = NULL;
3326 3319 ep->is_suspect = 0;
3327 3320 }
3328 3321 fmep->suspects = NULL;
3329 3322 fmep->nsuspects = 0;
3330 3323 }
3331 3324
3332 3325 /*
3333 3326 * Retrieve the fme's suspect list from its psuspects list.
3334 3327 */
3335 3328 static void
3336 3329 restore_suspects(struct fme *fmep)
3337 3330 {
3338 3331 struct event *ep;
3339 3332 struct event *nextep;
3340 3333
3341 3334 fmep->nsuspects = 0;
3342 3335 fmep->suspects = fmep->psuspects;
3343 3336 for (ep = fmep->psuspects; ep; ep = nextep) {
3344 3337 fmep->nsuspects++;
3345 3338 nextep = ep->psuspects;
3346 3339 ep->suspects = ep->psuspects;
3347 3340 }
3348 3341 }
3349 3342
3350 3343 /*
3351 3344 * this is what we use to call the Emrys prototype code instead of main()
3352 3345 */
3353 3346 static void
3354 3347 fme_eval(struct fme *fmep, fmd_event_t *ffep)
3355 3348 {
3356 3349 struct event *ep;
3357 3350 unsigned long long my_delay = TIMEVAL_EVENTUALLY;
3358 3351 struct rsl *srl = NULL;
3359 3352 struct rsl *srl2 = NULL;
3360 3353 int mess_zero_count;
3361 3354 int rpcnt;
3362 3355
3363 3356 save_suspects(fmep);
3364 3357
3365 3358 out(O_ALTFP, "Evaluate FME %d", fmep->id);
3366 3359 indent_set(" ");
3367 3360
3368 3361 lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep);
3369 3362 fmep->state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay);
3370 3363
3371 3364 out(O_ALTFP|O_NONL, "FME%d state: %s, suspect list:", fmep->id,
3372 3365 fme_state2str(fmep->state));
3373 3366 for (ep = fmep->suspects; ep; ep = ep->suspects) {
3374 3367 out(O_ALTFP|O_NONL, " ");
3375 3368 itree_pevent_brief(O_ALTFP|O_NONL, ep);
3376 3369 }
3377 3370 out(O_ALTFP, NULL);
3378 3371
3379 3372 switch (fmep->state) {
3380 3373 case FME_CREDIBLE:
3381 3374 print_suspects(SLNEW, fmep);
3382 3375 (void) upsets_eval(fmep, ffep);
3383 3376
3384 3377 /*
3385 3378 * we may have already posted suspects in upsets_eval() which
3386 3379 * can recurse into fme_eval() again. If so then just return.
3387 3380 */
3388 3381 if (fmep->posted_suspects)
3389 3382 return;
3390 3383
3391 3384 stats_counter_bump(fmep->diags);
3392 3385 rpcnt = fmep->nsuspects;
3393 3386 save_suspects(fmep);
3394 3387
3395 3388 /*
3396 3389 * create two lists, one for "message=1" faults and one for
3397 3390 * "message=0" faults. If we have a mixture we will generate
3398 3391 * two separate suspect lists.
3399 3392 */
3400 3393 srl = MALLOC(rpcnt * sizeof (struct rsl));
3401 3394 bzero(srl, rpcnt * sizeof (struct rsl));
3402 3395 srl2 = MALLOC(rpcnt * sizeof (struct rsl));
3403 3396 bzero(srl2, rpcnt * sizeof (struct rsl));
3404 3397 mess_zero_count = trim_suspects(fmep, srl, srl2, ffep);
3405 3398
3406 3399 /*
3407 3400 * If the resulting suspect list has no members, we're
3408 3401 * done so simply close the case. Otherwise sort and publish.
3409 3402 */
3410 3403 if (fmep->nsuspects == 0 && mess_zero_count == 0) {
3411 3404 out(O_ALTFP,
3412 3405 "[FME%d, case %s (all suspects are upsets)]",
3413 3406 fmep->id, fmd_case_uuid(fmep->hdl, fmep->fmcase));
3414 3407 fmd_case_close(fmep->hdl, fmep->fmcase);
3415 3408 } else if (fmep->nsuspects != 0 && mess_zero_count == 0) {
3416 3409 publish_suspects(fmep, srl);
3417 3410 out(O_ALTFP, "[solving FME%d, case %s]", fmep->id,
3418 3411 fmd_case_uuid(fmep->hdl, fmep->fmcase));
3419 3412 fmd_case_solve(fmep->hdl, fmep->fmcase);
3420 3413 } else if (fmep->nsuspects == 0 && mess_zero_count != 0) {
3421 3414 fmep->nsuspects = mess_zero_count;
3422 3415 publish_suspects(fmep, srl2);
3423 3416 out(O_ALTFP, "[solving FME%d, case %s]", fmep->id,
3424 3417 fmd_case_uuid(fmep->hdl, fmep->fmcase));
3425 3418 fmd_case_solve(fmep->hdl, fmep->fmcase);
3426 3419 } else {
3427 3420 struct event *obsp;
3428 3421 struct fme *nfmep;
3429 3422
3430 3423 publish_suspects(fmep, srl);
3431 3424 out(O_ALTFP, "[solving FME%d, case %s]", fmep->id,
3432 3425 fmd_case_uuid(fmep->hdl, fmep->fmcase));
3433 3426 fmd_case_solve(fmep->hdl, fmep->fmcase);
3434 3427
3435 3428 /*
3436 3429 * Got both message=0 and message=1 so create a
3437 3430 * duplicate case. Also need a temporary duplicate fme
3438 3431 * structure for use by publish_suspects().
3439 3432 */
3440 3433 nfmep = alloc_fme();
3441 3434 nfmep->id = Nextid++;
3442 3435 nfmep->hdl = fmep->hdl;
3443 3436 nfmep->nsuspects = mess_zero_count;
3444 3437 nfmep->fmcase = fmd_case_open(fmep->hdl, NULL);
3445 3438 out(O_ALTFP|O_STAMP,
3446 3439 "[creating parallel FME%d, case %s]", nfmep->id,
3447 3440 fmd_case_uuid(nfmep->hdl, nfmep->fmcase));
3448 3441 Open_fme_count++;
3449 3442 if (ffep) {
3450 3443 fmd_case_setprincipal(nfmep->hdl,
3451 3444 nfmep->fmcase, ffep);
3452 3445 fmd_case_add_ereport(nfmep->hdl,
3453 3446 nfmep->fmcase, ffep);
3454 3447 }
3455 3448 for (obsp = fmep->observations; obsp;
3456 3449 obsp = obsp->observations)
3457 3450 if (obsp->ffep && obsp->ffep != ffep)
3458 3451 fmd_case_add_ereport(nfmep->hdl,
3459 3452 nfmep->fmcase, obsp->ffep);
3460 3453
3461 3454 publish_suspects(nfmep, srl2);
3462 3455 out(O_ALTFP, "[solving FME%d, case %s]", nfmep->id,
3463 3456 fmd_case_uuid(nfmep->hdl, nfmep->fmcase));
3464 3457 fmd_case_solve(nfmep->hdl, nfmep->fmcase);
3465 3458 FREE(nfmep);
3466 3459 }
3467 3460 FREE(srl);
3468 3461 FREE(srl2);
3469 3462 restore_suspects(fmep);
3470 3463
3471 3464 fmep->posted_suspects = 1;
3472 3465 fmd_buf_write(fmep->hdl, fmep->fmcase,
3473 3466 WOBUF_POSTD,
3474 3467 (void *)&fmep->posted_suspects,
3475 3468 sizeof (fmep->posted_suspects));
3476 3469
3477 3470 /*
3478 3471 * Now the suspects have been posted, we can clear up
3479 3472 * the instance tree as we won't be looking at it again.
3480 3473 * Also cancel the timer as the case is now solved.
3481 3474 */
3482 3475 if (fmep->wull != 0) {
3483 3476 fmd_timer_remove(fmep->hdl, fmep->timer);
3484 3477 fmep->wull = 0;
3485 3478 }
3486 3479 break;
3487 3480
3488 3481 case FME_WAIT:
3489 3482 ASSERT(my_delay > fmep->ull);
3490 3483 (void) fme_set_timer(fmep, my_delay);
3491 3484 print_suspects(SLWAIT, fmep);
3492 3485 itree_prune(fmep->eventtree);
3493 3486 return;
3494 3487
3495 3488 case FME_DISPROVED:
3496 3489 print_suspects(SLDISPROVED, fmep);
3497 3490 Undiag_reason = UD_VAL_UNSOLVD;
3498 3491 fme_undiagnosable(fmep);
3499 3492 break;
3500 3493 }
3501 3494
3502 3495 itree_free(fmep->eventtree);
3503 3496 fmep->eventtree = NULL;
3504 3497 structconfig_free(fmep->config);
3505 3498 fmep->config = NULL;
3506 3499 destroy_fme_bufs(fmep);
3507 3500 }
3508 3501
3509 3502 static void indent(void);
3510 3503 static int triggered(struct fme *fmep, struct event *ep, int mark);
3511 3504 static enum fme_state effects_test(struct fme *fmep,
3512 3505 struct event *fault_event, unsigned long long at_latest_by,
3513 3506 unsigned long long *pdelay);
3514 3507 static enum fme_state requirements_test(struct fme *fmep, struct event *ep,
3515 3508 unsigned long long at_latest_by, unsigned long long *pdelay);
3516 3509 static enum fme_state causes_test(struct fme *fmep, struct event *ep,
3517 3510 unsigned long long at_latest_by, unsigned long long *pdelay);
3518 3511
3519 3512 static int
3520 3513 checkconstraints(struct fme *fmep, struct arrow *arrowp)
3521 3514 {
3522 3515 struct constraintlist *ctp;
3523 3516 struct evalue value;
3524 3517 char *sep = "";
3525 3518
3526 3519 if (arrowp->forever_false) {
3527 3520 indent();
3528 3521 out(O_ALTFP|O_VERB|O_NONL, " Forever false constraint: ");
3529 3522 for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) {
3530 3523 out(O_ALTFP|O_VERB|O_NONL, sep);
3531 3524 ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0);
3532 3525 sep = ", ";
3533 3526 }
3534 3527 out(O_ALTFP|O_VERB, NULL);
3535 3528 return (0);
3536 3529 }
3537 3530 if (arrowp->forever_true) {
3538 3531 indent();
3539 3532 out(O_ALTFP|O_VERB|O_NONL, " Forever true constraint: ");
3540 3533 for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) {
3541 3534 out(O_ALTFP|O_VERB|O_NONL, sep);
3542 3535 ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0);
3543 3536 sep = ", ";
3544 3537 }
3545 3538 out(O_ALTFP|O_VERB, NULL);
3546 3539 return (1);
3547 3540 }
3548 3541
3549 3542 for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) {
3550 3543 if (eval_expr(ctp->cnode, NULL, NULL,
3551 3544 &fmep->globals, fmep->config,
3552 3545 arrowp, 0, &value)) {
3553 3546 /* evaluation successful */
3554 3547 if (value.t == UNDEFINED || value.v == 0) {
3555 3548 /* known false */
3556 3549 arrowp->forever_false = 1;
3557 3550 indent();
3558 3551 out(O_ALTFP|O_VERB|O_NONL,
3559 3552 " False constraint: ");
3560 3553 ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0);
3561 3554 out(O_ALTFP|O_VERB, NULL);
3562 3555 return (0);
3563 3556 }
3564 3557 } else {
3565 3558 /* evaluation unsuccessful -- unknown value */
3566 3559 indent();
3567 3560 out(O_ALTFP|O_VERB|O_NONL,
3568 3561 " Deferred constraint: ");
3569 3562 ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0);
3570 3563 out(O_ALTFP|O_VERB, NULL);
3571 3564 return (1);
3572 3565 }
3573 3566 }
3574 3567 /* known true */
3575 3568 arrowp->forever_true = 1;
3576 3569 indent();
3577 3570 out(O_ALTFP|O_VERB|O_NONL, " True constraint: ");
3578 3571 for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) {
3579 3572 out(O_ALTFP|O_VERB|O_NONL, sep);
3580 3573 ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0);
3581 3574 sep = ", ";
3582 3575 }
3583 3576 out(O_ALTFP|O_VERB, NULL);
3584 3577 return (1);
3585 3578 }
3586 3579
3587 3580 static int
3588 3581 triggered(struct fme *fmep, struct event *ep, int mark)
3589 3582 {
3590 3583 struct bubble *bp;
3591 3584 struct arrowlist *ap;
3592 3585 int count = 0;
3593 3586
3594 3587 stats_counter_bump(fmep->Tcallcount);
3595 3588 for (bp = itree_next_bubble(ep, NULL); bp;
3596 3589 bp = itree_next_bubble(ep, bp)) {
3597 3590 if (bp->t != B_TO)
3598 3591 continue;
3599 3592 for (ap = itree_next_arrow(bp, NULL); ap;
3600 3593 ap = itree_next_arrow(bp, ap)) {
3601 3594 /* check count of marks against K in the bubble */
3602 3595 if ((ap->arrowp->mark & mark) &&
3603 3596 ++count >= bp->nork)
3604 3597 return (1);
3605 3598 }
3606 3599 }
3607 3600 return (0);
3608 3601 }
3609 3602
3610 3603 static int
3611 3604 mark_arrows(struct fme *fmep, struct event *ep, int mark,
3612 3605 unsigned long long at_latest_by, unsigned long long *pdelay, int keep)
3613 3606 {
3614 3607 struct bubble *bp;
3615 3608 struct arrowlist *ap;
3616 3609 unsigned long long overall_delay = TIMEVAL_EVENTUALLY;
3617 3610 unsigned long long my_delay;
3618 3611 enum fme_state result;
3619 3612 int retval = 0;
3620 3613
3621 3614 for (bp = itree_next_bubble(ep, NULL); bp;
3622 3615 bp = itree_next_bubble(ep, bp)) {
3623 3616 if (bp->t != B_FROM)
3624 3617 continue;
3625 3618 stats_counter_bump(fmep->Marrowcount);
3626 3619 for (ap = itree_next_arrow(bp, NULL); ap;
3627 3620 ap = itree_next_arrow(bp, ap)) {
3628 3621 struct event *ep2 = ap->arrowp->head->myevent;
3629 3622 /*
3630 3623 * if we're clearing marks, we can avoid doing
3631 3624 * all that work evaluating constraints.
3632 3625 */
3633 3626 if (mark == 0) {
3634 3627 if (ap->arrowp->arrow_marked == 0)
3635 3628 continue;
3636 3629 ap->arrowp->arrow_marked = 0;
3637 3630 ap->arrowp->mark &= ~EFFECTS_COUNTER;
3638 3631 if (keep && (ep2->cached_state &
3639 3632 (WAIT_EFFECT|CREDIBLE_EFFECT|PARENT_WAIT)))
3640 3633 ep2->keep_in_tree = 1;
3641 3634 ep2->cached_state &=
3642 3635 ~(WAIT_EFFECT|CREDIBLE_EFFECT|PARENT_WAIT);
3643 3636 (void) mark_arrows(fmep, ep2, mark, 0, NULL,
3644 3637 keep);
3645 3638 continue;
3646 3639 }
3647 3640 ap->arrowp->arrow_marked = 1;
3648 3641 if (ep2->cached_state & REQMNTS_DISPROVED) {
3649 3642 indent();
3650 3643 out(O_ALTFP|O_VERB|O_NONL,
3651 3644 " ALREADY DISPROVED ");
3652 3645 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3653 3646 out(O_ALTFP|O_VERB, NULL);
3654 3647 continue;
3655 3648 }
3656 3649 if (ep2->cached_state & WAIT_EFFECT) {
3657 3650 indent();
3658 3651 out(O_ALTFP|O_VERB|O_NONL,
3659 3652 " ALREADY EFFECTS WAIT ");
3660 3653 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3661 3654 out(O_ALTFP|O_VERB, NULL);
3662 3655 continue;
3663 3656 }
3664 3657 if (ep2->cached_state & CREDIBLE_EFFECT) {
3665 3658 indent();
3666 3659 out(O_ALTFP|O_VERB|O_NONL,
3667 3660 " ALREADY EFFECTS CREDIBLE ");
3668 3661 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3669 3662 out(O_ALTFP|O_VERB, NULL);
3670 3663 continue;
3671 3664 }
3672 3665 if ((ep2->cached_state & PARENT_WAIT) &&
3673 3666 (mark & PARENT_WAIT)) {
3674 3667 indent();
3675 3668 out(O_ALTFP|O_VERB|O_NONL,
3676 3669 " ALREADY PARENT EFFECTS WAIT ");
3677 3670 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3678 3671 out(O_ALTFP|O_VERB, NULL);
3679 3672 continue;
3680 3673 }
3681 3674 platform_set_payloadnvp(ep2->nvp);
3682 3675 if (checkconstraints(fmep, ap->arrowp) == 0) {
3683 3676 platform_set_payloadnvp(NULL);
3684 3677 indent();
3685 3678 out(O_ALTFP|O_VERB|O_NONL,
3686 3679 " CONSTRAINTS FAIL ");
3687 3680 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3688 3681 out(O_ALTFP|O_VERB, NULL);
3689 3682 continue;
3690 3683 }
3691 3684 platform_set_payloadnvp(NULL);
3692 3685 ap->arrowp->mark |= EFFECTS_COUNTER;
3693 3686 if (!triggered(fmep, ep2, EFFECTS_COUNTER)) {
3694 3687 indent();
3695 3688 out(O_ALTFP|O_VERB|O_NONL,
3696 3689 " K-COUNT NOT YET MET ");
3697 3690 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3698 3691 out(O_ALTFP|O_VERB, NULL);
3699 3692 continue;
3700 3693 }
3701 3694 ep2->cached_state &= ~PARENT_WAIT;
3702 3695 /*
3703 3696 * if we've reached an ereport and no propagation time
3704 3697 * is specified, use the Hesitate value
3705 3698 */
3706 3699 if (ep2->t == N_EREPORT && at_latest_by == 0ULL &&
3707 3700 ap->arrowp->maxdelay == 0ULL) {
3708 3701 out(O_ALTFP|O_VERB|O_NONL, " default wait ");
3709 3702 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3710 3703 out(O_ALTFP|O_VERB, NULL);
3711 3704 result = requirements_test(fmep, ep2, Hesitate,
3712 3705 &my_delay);
3713 3706 } else {
3714 3707 result = requirements_test(fmep, ep2,
3715 3708 at_latest_by + ap->arrowp->maxdelay,
3716 3709 &my_delay);
3717 3710 }
3718 3711 if (result == FME_WAIT) {
3719 3712 retval = WAIT_EFFECT;
3720 3713 if (overall_delay > my_delay)
3721 3714 overall_delay = my_delay;
3722 3715 ep2->cached_state |= WAIT_EFFECT;
3723 3716 indent();
3724 3717 out(O_ALTFP|O_VERB|O_NONL, " EFFECTS WAIT ");
3725 3718 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3726 3719 out(O_ALTFP|O_VERB, NULL);
3727 3720 indent_push(" E");
3728 3721 if (mark_arrows(fmep, ep2, PARENT_WAIT,
3729 3722 at_latest_by, &my_delay, 0) ==
3730 3723 WAIT_EFFECT) {
3731 3724 retval = WAIT_EFFECT;
3732 3725 if (overall_delay > my_delay)
3733 3726 overall_delay = my_delay;
3734 3727 }
3735 3728 indent_pop();
3736 3729 } else if (result == FME_DISPROVED) {
3737 3730 indent();
3738 3731 out(O_ALTFP|O_VERB|O_NONL,
3739 3732 " EFFECTS DISPROVED ");
3740 3733 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3741 3734 out(O_ALTFP|O_VERB, NULL);
3742 3735 } else {
3743 3736 ep2->cached_state |= mark;
3744 3737 indent();
3745 3738 if (mark == CREDIBLE_EFFECT)
3746 3739 out(O_ALTFP|O_VERB|O_NONL,
3747 3740 " EFFECTS CREDIBLE ");
3748 3741 else
3749 3742 out(O_ALTFP|O_VERB|O_NONL,
3750 3743 " PARENT EFFECTS WAIT ");
3751 3744 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2);
3752 3745 out(O_ALTFP|O_VERB, NULL);
3753 3746 indent_push(" E");
3754 3747 if (mark_arrows(fmep, ep2, mark, at_latest_by,
3755 3748 &my_delay, 0) == WAIT_EFFECT) {
3756 3749 retval = WAIT_EFFECT;
3757 3750 if (overall_delay > my_delay)
3758 3751 overall_delay = my_delay;
3759 3752 }
3760 3753 indent_pop();
3761 3754 }
3762 3755 }
3763 3756 }
3764 3757 if (retval == WAIT_EFFECT)
3765 3758 *pdelay = overall_delay;
3766 3759 return (retval);
3767 3760 }
3768 3761
3769 3762 static enum fme_state
3770 3763 effects_test(struct fme *fmep, struct event *fault_event,
3771 3764 unsigned long long at_latest_by, unsigned long long *pdelay)
3772 3765 {
3773 3766 struct event *error_event;
3774 3767 enum fme_state return_value = FME_CREDIBLE;
3775 3768 unsigned long long overall_delay = TIMEVAL_EVENTUALLY;
3776 3769 unsigned long long my_delay;
3777 3770
3778 3771 stats_counter_bump(fmep->Ecallcount);
3779 3772 indent_push(" E");
3780 3773 indent();
3781 3774 out(O_ALTFP|O_VERB|O_NONL, "->");
3782 3775 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, fault_event);
3783 3776 out(O_ALTFP|O_VERB, NULL);
3784 3777
3785 3778 if (mark_arrows(fmep, fault_event, CREDIBLE_EFFECT, at_latest_by,
3786 3779 &my_delay, 0) == WAIT_EFFECT) {
3787 3780 return_value = FME_WAIT;
3788 3781 if (overall_delay > my_delay)
3789 3782 overall_delay = my_delay;
3790 3783 }
3791 3784 for (error_event = fmep->observations;
3792 3785 error_event; error_event = error_event->observations) {
3793 3786 indent();
3794 3787 out(O_ALTFP|O_VERB|O_NONL, " ");
3795 3788 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, error_event);
3796 3789 if (!(error_event->cached_state & CREDIBLE_EFFECT)) {
3797 3790 if (error_event->cached_state &
3798 3791 (PARENT_WAIT|WAIT_EFFECT)) {
3799 3792 out(O_ALTFP|O_VERB, " NOT YET triggered");
3800 3793 continue;
3801 3794 }
3802 3795 return_value = FME_DISPROVED;
3803 3796 out(O_ALTFP|O_VERB, " NOT triggered");
3804 3797 break;
3805 3798 } else {
3806 3799 out(O_ALTFP|O_VERB, " triggered");
3807 3800 }
3808 3801 }
3809 3802 if (return_value == FME_DISPROVED) {
3810 3803 (void) mark_arrows(fmep, fault_event, 0, 0, NULL, 0);
3811 3804 } else {
3812 3805 fault_event->keep_in_tree = 1;
3813 3806 (void) mark_arrows(fmep, fault_event, 0, 0, NULL, 1);
3814 3807 }
3815 3808
3816 3809 indent();
3817 3810 out(O_ALTFP|O_VERB|O_NONL, "<-EFFECTS %s ",
3818 3811 fme_state2str(return_value));
3819 3812 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, fault_event);
3820 3813 out(O_ALTFP|O_VERB, NULL);
3821 3814 indent_pop();
3822 3815 if (return_value == FME_WAIT)
3823 3816 *pdelay = overall_delay;
3824 3817 return (return_value);
3825 3818 }
3826 3819
3827 3820 static enum fme_state
3828 3821 requirements_test(struct fme *fmep, struct event *ep,
3829 3822 unsigned long long at_latest_by, unsigned long long *pdelay)
3830 3823 {
3831 3824 int waiting_events;
3832 3825 int credible_events;
3833 3826 int deferred_events;
3834 3827 enum fme_state return_value = FME_CREDIBLE;
3835 3828 unsigned long long overall_delay = TIMEVAL_EVENTUALLY;
3836 3829 unsigned long long arrow_delay;
3837 3830 unsigned long long my_delay;
3838 3831 struct event *ep2;
3839 3832 struct bubble *bp;
3840 3833 struct arrowlist *ap;
3841 3834
3842 3835 if (ep->cached_state & REQMNTS_CREDIBLE) {
3843 3836 indent();
3844 3837 out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY CREDIBLE ");
3845 3838 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3846 3839 out(O_ALTFP|O_VERB, NULL);
3847 3840 return (FME_CREDIBLE);
3848 3841 }
3849 3842 if (ep->cached_state & REQMNTS_DISPROVED) {
3850 3843 indent();
3851 3844 out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY DISPROVED ");
3852 3845 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3853 3846 out(O_ALTFP|O_VERB, NULL);
3854 3847 return (FME_DISPROVED);
3855 3848 }
3856 3849 if (ep->cached_state & REQMNTS_WAIT) {
3857 3850 indent();
3858 3851 *pdelay = ep->cached_delay;
3859 3852 out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY WAIT ");
3860 3853 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3861 3854 out(O_ALTFP|O_VERB|O_NONL, ", wait for: ");
3862 3855 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by);
3863 3856 out(O_ALTFP|O_VERB, NULL);
3864 3857 return (FME_WAIT);
3865 3858 }
3866 3859 stats_counter_bump(fmep->Rcallcount);
3867 3860 indent_push(" R");
3868 3861 indent();
3869 3862 out(O_ALTFP|O_VERB|O_NONL, "->");
3870 3863 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3871 3864 out(O_ALTFP|O_VERB|O_NONL, ", at latest by: ");
3872 3865 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by);
3873 3866 out(O_ALTFP|O_VERB, NULL);
3874 3867
3875 3868 if (ep->t == N_EREPORT) {
3876 3869 if (ep->count == 0) {
3877 3870 if (fmep->pull >= at_latest_by) {
3878 3871 return_value = FME_DISPROVED;
3879 3872 } else {
3880 3873 ep->cached_delay = *pdelay = at_latest_by;
3881 3874 return_value = FME_WAIT;
3882 3875 }
3883 3876 }
3884 3877
3885 3878 indent();
3886 3879 switch (return_value) {
3887 3880 case FME_CREDIBLE:
3888 3881 ep->cached_state |= REQMNTS_CREDIBLE;
3889 3882 out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS CREDIBLE ");
3890 3883 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3891 3884 break;
3892 3885 case FME_DISPROVED:
3893 3886 ep->cached_state |= REQMNTS_DISPROVED;
3894 3887 out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS DISPROVED ");
3895 3888 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3896 3889 break;
3897 3890 case FME_WAIT:
3898 3891 ep->cached_state |= REQMNTS_WAIT;
3899 3892 out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS WAIT ");
3900 3893 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
3901 3894 out(O_ALTFP|O_VERB|O_NONL, " to ");
3902 3895 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by);
3903 3896 break;
3904 3897 default:
3905 3898 out(O_DIE, "requirements_test: unexpected fme_state");
3906 3899 break;
3907 3900 }
3908 3901 out(O_ALTFP|O_VERB, NULL);
3909 3902 indent_pop();
3910 3903
3911 3904 return (return_value);
3912 3905 }
3913 3906
3914 3907 /* this event is not a report, descend the tree */
3915 3908 for (bp = itree_next_bubble(ep, NULL); bp;
3916 3909 bp = itree_next_bubble(ep, bp)) {
3917 3910 int n;
3918 3911
3919 3912 if (bp->t != B_FROM)
3920 3913 continue;
3921 3914
3922 3915 n = bp->nork;
3923 3916
3924 3917 credible_events = 0;
3925 3918 waiting_events = 0;
3926 3919 deferred_events = 0;
3927 3920 arrow_delay = TIMEVAL_EVENTUALLY;
3928 3921 /*
3929 3922 * n is -1 for 'A' so adjust it.
3930 3923 * XXX just count up the arrows for now.
3931 3924 */
3932 3925 if (n < 0) {
3933 3926 n = 0;
3934 3927 for (ap = itree_next_arrow(bp, NULL); ap;
3935 3928 ap = itree_next_arrow(bp, ap))
3936 3929 n++;
3937 3930 indent();
3938 3931 out(O_ALTFP|O_VERB, " Bubble Counted N=%d", n);
3939 3932 } else {
3940 3933 indent();
3941 3934 out(O_ALTFP|O_VERB, " Bubble N=%d", n);
3942 3935 }
3943 3936
3944 3937 if (n == 0)
3945 3938 continue;
3946 3939 if (!(bp->mark & (BUBBLE_ELIDED|BUBBLE_OK))) {
3947 3940 for (ap = itree_next_arrow(bp, NULL); ap;
3948 3941 ap = itree_next_arrow(bp, ap)) {
3949 3942 ep2 = ap->arrowp->head->myevent;
3950 3943 platform_set_payloadnvp(ep2->nvp);
3951 3944 (void) checkconstraints(fmep, ap->arrowp);
3952 3945 if (!ap->arrowp->forever_false) {
3953 3946 /*
3954 3947 * if all arrows are invalidated by the
3955 3948 * constraints, then we should elide the
3956 3949 * whole bubble to be consistant with
3957 3950 * the tree creation time behaviour
3958 3951 */
3959 3952 bp->mark |= BUBBLE_OK;
3960 3953 platform_set_payloadnvp(NULL);
3961 3954 break;
3962 3955 }
3963 3956 platform_set_payloadnvp(NULL);
3964 3957 }
3965 3958 }
3966 3959 for (ap = itree_next_arrow(bp, NULL); ap;
3967 3960 ap = itree_next_arrow(bp, ap)) {
3968 3961 ep2 = ap->arrowp->head->myevent;
3969 3962 if (n <= credible_events)
3970 3963 break;
3971 3964
3972 3965 ap->arrowp->mark |= REQMNTS_COUNTER;
3973 3966 if (triggered(fmep, ep2, REQMNTS_COUNTER))
3974 3967 /* XXX adding max timevals! */
3975 3968 switch (requirements_test(fmep, ep2,
3976 3969 at_latest_by + ap->arrowp->maxdelay,
3977 3970 &my_delay)) {
3978 3971 case FME_DEFERRED:
3979 3972 deferred_events++;
3980 3973 break;
3981 3974 case FME_CREDIBLE:
3982 3975 credible_events++;
3983 3976 break;
3984 3977 case FME_DISPROVED:
3985 3978 break;
3986 3979 case FME_WAIT:
3987 3980 if (my_delay < arrow_delay)
3988 3981 arrow_delay = my_delay;
3989 3982 waiting_events++;
3990 3983 break;
3991 3984 default:
3992 3985 out(O_DIE,
3993 3986 "Bug in requirements_test.");
3994 3987 }
3995 3988 else
3996 3989 deferred_events++;
3997 3990 }
3998 3991 if (!(bp->mark & BUBBLE_OK) && waiting_events == 0) {
3999 3992 bp->mark |= BUBBLE_ELIDED;
4000 3993 continue;
4001 3994 }
4002 3995 indent();
4003 3996 out(O_ALTFP|O_VERB, " Credible: %d Waiting %d",
4004 3997 credible_events + deferred_events, waiting_events);
4005 3998 if (credible_events + deferred_events + waiting_events < n) {
4006 3999 /* Can never meet requirements */
4007 4000 ep->cached_state |= REQMNTS_DISPROVED;
4008 4001 indent();
4009 4002 out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS DISPROVED ");
4010 4003 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4011 4004 out(O_ALTFP|O_VERB, NULL);
4012 4005 indent_pop();
4013 4006 return (FME_DISPROVED);
4014 4007 }
4015 4008 if (credible_events + deferred_events < n) {
4016 4009 /* will have to wait */
4017 4010 /* wait time is shortest known */
4018 4011 if (arrow_delay < overall_delay)
4019 4012 overall_delay = arrow_delay;
4020 4013 return_value = FME_WAIT;
4021 4014 } else if (credible_events < n) {
4022 4015 if (return_value != FME_WAIT)
4023 4016 return_value = FME_DEFERRED;
4024 4017 }
4025 4018 }
4026 4019
4027 4020 /*
4028 4021 * don't mark as FME_DEFERRED. If this event isn't reached by another
4029 4022 * path, then this will be considered FME_CREDIBLE. But if it is
4030 4023 * reached by a different path so the K-count is met, then might
4031 4024 * get overridden by FME_WAIT or FME_DISPROVED.
4032 4025 */
4033 4026 if (return_value == FME_WAIT) {
4034 4027 ep->cached_state |= REQMNTS_WAIT;
4035 4028 ep->cached_delay = *pdelay = overall_delay;
4036 4029 } else if (return_value == FME_CREDIBLE) {
4037 4030 ep->cached_state |= REQMNTS_CREDIBLE;
4038 4031 }
4039 4032 indent();
4040 4033 out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS %s ",
4041 4034 fme_state2str(return_value));
4042 4035 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4043 4036 out(O_ALTFP|O_VERB, NULL);
4044 4037 indent_pop();
4045 4038 return (return_value);
4046 4039 }
4047 4040
4048 4041 static enum fme_state
4049 4042 causes_test(struct fme *fmep, struct event *ep,
4050 4043 unsigned long long at_latest_by, unsigned long long *pdelay)
4051 4044 {
4052 4045 unsigned long long overall_delay = TIMEVAL_EVENTUALLY;
4053 4046 unsigned long long my_delay;
4054 4047 int credible_results = 0;
4055 4048 int waiting_results = 0;
4056 4049 enum fme_state fstate;
4057 4050 struct event *tail_event;
4058 4051 struct bubble *bp;
4059 4052 struct arrowlist *ap;
4060 4053 int k = 1;
4061 4054
4062 4055 stats_counter_bump(fmep->Ccallcount);
4063 4056 indent_push(" C");
4064 4057 indent();
4065 4058 out(O_ALTFP|O_VERB|O_NONL, "->");
4066 4059 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4067 4060 out(O_ALTFP|O_VERB, NULL);
4068 4061
4069 4062 for (bp = itree_next_bubble(ep, NULL); bp;
4070 4063 bp = itree_next_bubble(ep, bp)) {
4071 4064 if (bp->t != B_TO)
4072 4065 continue;
4073 4066 k = bp->nork; /* remember the K value */
4074 4067 for (ap = itree_next_arrow(bp, NULL); ap;
4075 4068 ap = itree_next_arrow(bp, ap)) {
4076 4069 int do_not_follow = 0;
4077 4070
4078 4071 /*
4079 4072 * if we get to the same event multiple times
4080 4073 * only worry about the first one.
4081 4074 */
4082 4075 if (ap->arrowp->tail->myevent->cached_state &
4083 4076 CAUSES_TESTED) {
4084 4077 indent();
4085 4078 out(O_ALTFP|O_VERB|O_NONL,
4086 4079 " causes test already run for ");
4087 4080 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL,
4088 4081 ap->arrowp->tail->myevent);
4089 4082 out(O_ALTFP|O_VERB, NULL);
4090 4083 continue;
4091 4084 }
4092 4085
4093 4086 /*
4094 4087 * see if false constraint prevents us
4095 4088 * from traversing this arrow
4096 4089 */
4097 4090 platform_set_payloadnvp(ep->nvp);
4098 4091 if (checkconstraints(fmep, ap->arrowp) == 0)
4099 4092 do_not_follow = 1;
4100 4093 platform_set_payloadnvp(NULL);
4101 4094 if (do_not_follow) {
4102 4095 indent();
4103 4096 out(O_ALTFP|O_VERB|O_NONL,
4104 4097 " False arrow from ");
4105 4098 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL,
4106 4099 ap->arrowp->tail->myevent);
4107 4100 out(O_ALTFP|O_VERB, NULL);
4108 4101 continue;
4109 4102 }
4110 4103
4111 4104 ap->arrowp->tail->myevent->cached_state |=
4112 4105 CAUSES_TESTED;
4113 4106 tail_event = ap->arrowp->tail->myevent;
4114 4107 fstate = hypothesise(fmep, tail_event, at_latest_by,
4115 4108 &my_delay);
4116 4109
4117 4110 switch (fstate) {
4118 4111 case FME_WAIT:
4119 4112 if (my_delay < overall_delay)
4120 4113 overall_delay = my_delay;
4121 4114 waiting_results++;
4122 4115 break;
4123 4116 case FME_CREDIBLE:
4124 4117 credible_results++;
4125 4118 break;
4126 4119 case FME_DISPROVED:
4127 4120 break;
4128 4121 default:
4129 4122 out(O_DIE, "Bug in causes_test");
4130 4123 }
4131 4124 }
4132 4125 }
4133 4126 /* compare against K */
4134 4127 if (credible_results + waiting_results < k) {
4135 4128 indent();
4136 4129 out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES DISPROVED ");
4137 4130 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4138 4131 out(O_ALTFP|O_VERB, NULL);
4139 4132 indent_pop();
4140 4133 return (FME_DISPROVED);
4141 4134 }
4142 4135 if (waiting_results != 0) {
4143 4136 *pdelay = overall_delay;
4144 4137 indent();
4145 4138 out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES WAIT ");
4146 4139 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4147 4140 out(O_ALTFP|O_VERB|O_NONL, " to ");
4148 4141 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by);
4149 4142 out(O_ALTFP|O_VERB, NULL);
4150 4143 indent_pop();
4151 4144 return (FME_WAIT);
4152 4145 }
4153 4146 indent();
4154 4147 out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES CREDIBLE ");
4155 4148 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4156 4149 out(O_ALTFP|O_VERB, NULL);
4157 4150 indent_pop();
4158 4151 return (FME_CREDIBLE);
4159 4152 }
4160 4153
4161 4154 static enum fme_state
4162 4155 hypothesise(struct fme *fmep, struct event *ep,
4163 4156 unsigned long long at_latest_by, unsigned long long *pdelay)
4164 4157 {
4165 4158 enum fme_state rtr, otr;
4166 4159 unsigned long long my_delay;
4167 4160 unsigned long long overall_delay = TIMEVAL_EVENTUALLY;
4168 4161
4169 4162 stats_counter_bump(fmep->Hcallcount);
4170 4163 indent_push(" H");
4171 4164 indent();
4172 4165 out(O_ALTFP|O_VERB|O_NONL, "->");
4173 4166 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4174 4167 out(O_ALTFP|O_VERB|O_NONL, ", at latest by: ");
4175 4168 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by);
4176 4169 out(O_ALTFP|O_VERB, NULL);
4177 4170
4178 4171 rtr = requirements_test(fmep, ep, at_latest_by, &my_delay);
4179 4172 if ((rtr == FME_WAIT) && (my_delay < overall_delay))
4180 4173 overall_delay = my_delay;
4181 4174 if (rtr != FME_DISPROVED) {
4182 4175 if (is_problem(ep->t)) {
4183 4176 otr = effects_test(fmep, ep, at_latest_by, &my_delay);
4184 4177 if (otr != FME_DISPROVED) {
4185 4178 if (fmep->peek == 0 && ep->is_suspect == 0) {
4186 4179 ep->suspects = fmep->suspects;
4187 4180 ep->is_suspect = 1;
4188 4181 fmep->suspects = ep;
4189 4182 fmep->nsuspects++;
4190 4183 }
4191 4184 }
4192 4185 } else
4193 4186 otr = causes_test(fmep, ep, at_latest_by, &my_delay);
4194 4187 if ((otr == FME_WAIT) && (my_delay < overall_delay))
4195 4188 overall_delay = my_delay;
4196 4189 if ((otr != FME_DISPROVED) &&
4197 4190 ((rtr == FME_WAIT) || (otr == FME_WAIT)))
4198 4191 *pdelay = overall_delay;
4199 4192 }
4200 4193 if (rtr == FME_DISPROVED) {
4201 4194 indent();
4202 4195 out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED ");
4203 4196 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4204 4197 out(O_ALTFP|O_VERB, " (doesn't meet requirements)");
4205 4198 indent_pop();
4206 4199 return (FME_DISPROVED);
4207 4200 }
4208 4201 if ((otr == FME_DISPROVED) && is_problem(ep->t)) {
4209 4202 indent();
4210 4203 out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED ");
4211 4204 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4212 4205 out(O_ALTFP|O_VERB, " (doesn't explain all reports)");
4213 4206 indent_pop();
4214 4207 return (FME_DISPROVED);
4215 4208 }
4216 4209 if (otr == FME_DISPROVED) {
4217 4210 indent();
4218 4211 out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED ");
4219 4212 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4220 4213 out(O_ALTFP|O_VERB, " (causes are not credible)");
4221 4214 indent_pop();
4222 4215 return (FME_DISPROVED);
4223 4216 }
4224 4217 if ((rtr == FME_WAIT) || (otr == FME_WAIT)) {
4225 4218 indent();
4226 4219 out(O_ALTFP|O_VERB|O_NONL, "<-WAIT ");
4227 4220 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4228 4221 out(O_ALTFP|O_VERB|O_NONL, " to ");
4229 4222 ptree_timeval(O_ALTFP|O_VERB|O_NONL, &overall_delay);
4230 4223 out(O_ALTFP|O_VERB, NULL);
4231 4224 indent_pop();
4232 4225 return (FME_WAIT);
4233 4226 }
4234 4227 indent();
4235 4228 out(O_ALTFP|O_VERB|O_NONL, "<-CREDIBLE ");
4236 4229 itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep);
4237 4230 out(O_ALTFP|O_VERB, NULL);
4238 4231 indent_pop();
4239 4232 return (FME_CREDIBLE);
4240 4233 }
4241 4234
4242 4235 /*
4243 4236 * fme_istat_load -- reconstitute any persistent istats
4244 4237 */
4245 4238 void
4246 4239 fme_istat_load(fmd_hdl_t *hdl)
4247 4240 {
4248 4241 int sz;
4249 4242 char *sbuf;
4250 4243 char *ptr;
4251 4244
4252 4245 if ((sz = fmd_buf_size(hdl, NULL, WOBUF_ISTATS)) == 0) {
4253 4246 out(O_ALTFP, "fme_istat_load: No stats");
4254 4247 return;
4255 4248 }
4256 4249
4257 4250 sbuf = alloca(sz);
4258 4251
4259 4252 fmd_buf_read(hdl, NULL, WOBUF_ISTATS, sbuf, sz);
4260 4253
4261 4254 /*
4262 4255 * pick apart the serialized stats
4263 4256 *
4264 4257 * format is:
4265 4258 * <class-name>, '@', <path>, '\0', <value>, '\0'
4266 4259 * for example:
4267 4260 * "stat.first@stat0/path0\02\0stat.second@stat0/path1\023\0"
4268 4261 *
4269 4262 * since this is parsing our own serialized data, any parsing issues
4270 4263 * are fatal, so we check for them all with ASSERT() below.
4271 4264 */
4272 4265 ptr = sbuf;
4273 4266 while (ptr < &sbuf[sz]) {
4274 4267 char *sepptr;
4275 4268 struct node *np;
4276 4269 int val;
4277 4270
4278 4271 sepptr = strchr(ptr, '@');
4279 4272 ASSERT(sepptr != NULL);
4280 4273 *sepptr = '\0';
4281 4274
4282 4275 /* construct the event */
4283 4276 np = newnode(T_EVENT, NULL, 0);
4284 4277 np->u.event.ename = newnode(T_NAME, NULL, 0);
4285 4278 np->u.event.ename->u.name.t = N_STAT;
4286 4279 np->u.event.ename->u.name.s = stable(ptr);
4287 4280 np->u.event.ename->u.name.it = IT_ENAME;
4288 4281 np->u.event.ename->u.name.last = np->u.event.ename;
4289 4282
4290 4283 ptr = sepptr + 1;
4291 4284 ASSERT(ptr < &sbuf[sz]);
4292 4285 ptr += strlen(ptr);
4293 4286 ptr++; /* move past the '\0' separating path from value */
4294 4287 ASSERT(ptr < &sbuf[sz]);
4295 4288 ASSERT(isdigit(*ptr));
4296 4289 val = atoi(ptr);
4297 4290 ASSERT(val > 0);
4298 4291 ptr += strlen(ptr);
4299 4292 ptr++; /* move past the final '\0' for this entry */
4300 4293
4301 4294 np->u.event.epname = pathstring2epnamenp(sepptr + 1);
4302 4295 ASSERT(np->u.event.epname != NULL);
4303 4296
4304 4297 istat_bump(np, val);
4305 4298 tree_free(np);
4306 4299 }
4307 4300
4308 4301 istat_save();
4309 4302 }
↓ open down ↓ |
2151 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX