17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55f25dc2aSgavinm * Common Development and Distribution License (the "License"). 65f25dc2aSgavinm * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 215f25dc2aSgavinm 227c478bd9Sstevel@tonic-gate /* 23f5961f52SAdrian Frost * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 2433f5ff17SMilan Jurik * Copyright 2012 Milan Jurik. All rights reserved. 25*a3f6a2a4SRob Johnston * Copyright (c) 2018, Joyent, Inc. 267c478bd9Sstevel@tonic-gate * 277c478bd9Sstevel@tonic-gate * fme.c -- fault management exercise module 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * this module provides the simulated fault management exercise. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <stdio.h> 337c478bd9Sstevel@tonic-gate #include <stdlib.h> 347c478bd9Sstevel@tonic-gate #include <string.h> 357c478bd9Sstevel@tonic-gate #include <strings.h> 367c478bd9Sstevel@tonic-gate #include <ctype.h> 377c478bd9Sstevel@tonic-gate #include <alloca.h> 387c478bd9Sstevel@tonic-gate #include <libnvpair.h> 397c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h> 407c478bd9Sstevel@tonic-gate #include <fm/fmd_api.h> 417c478bd9Sstevel@tonic-gate #include "alloc.h" 427c478bd9Sstevel@tonic-gate #include "out.h" 437c478bd9Sstevel@tonic-gate #include "stats.h" 447c478bd9Sstevel@tonic-gate #include "stable.h" 457c478bd9Sstevel@tonic-gate #include "literals.h" 467c478bd9Sstevel@tonic-gate #include "lut.h" 477c478bd9Sstevel@tonic-gate #include "tree.h" 487c478bd9Sstevel@tonic-gate #include "ptree.h" 497c478bd9Sstevel@tonic-gate #include "itree.h" 507c478bd9Sstevel@tonic-gate #include "ipath.h" 517c478bd9Sstevel@tonic-gate #include "fme.h" 527c478bd9Sstevel@tonic-gate #include "evnv.h" 537c478bd9Sstevel@tonic-gate #include "eval.h" 547c478bd9Sstevel@tonic-gate #include "config.h" 557c478bd9Sstevel@tonic-gate #include "platform.h" 56e5ba14ffSstephh #include "esclex.h" 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* imported from eft.c... */ 597c478bd9Sstevel@tonic-gate extern hrtime_t Hesitate; 60e5ba14ffSstephh extern char *Serd_Override; 617c478bd9Sstevel@tonic-gate extern nv_alloc_t Eft_nv_hdl; 620cc1f05eSjrutt extern int Max_fme; 637aec1d6eScindi extern fmd_hdl_t *Hdl; 647aec1d6eScindi 657aec1d6eScindi static int Istat_need_save; 66b5016cbbSstephh static int Serd_need_save; 6708f6c065Sgavinm void istat_save(void); 68b5016cbbSstephh void serd_save(void); 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate /* fme under construction is global so we can free it on module abort */ 717c478bd9Sstevel@tonic-gate static struct fme *Nfmep; 727c478bd9Sstevel@tonic-gate 7332d4e834STarik Soydan static int Undiag_reason = UD_VAL_UNKNOWN; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static int Nextid = 0; 767c478bd9Sstevel@tonic-gate 770cc1f05eSjrutt static int Open_fme_count = 0; /* Count of open FMEs */ 780cc1f05eSjrutt 797c478bd9Sstevel@tonic-gate /* list of fault management exercises underway */ 807c478bd9Sstevel@tonic-gate static struct fme { 817c478bd9Sstevel@tonic-gate struct fme *next; /* next exercise */ 827c478bd9Sstevel@tonic-gate unsigned long long ull; /* time when fme was created */ 837c478bd9Sstevel@tonic-gate int id; /* FME id */ 84e5ba14ffSstephh struct config *config; /* cooked configuration data */ 857c478bd9Sstevel@tonic-gate struct lut *eventtree; /* propagation tree for this FME */ 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * The initial error report that created this FME is kept in 887c478bd9Sstevel@tonic-gate * two forms. e0 points to the instance tree node and is used 897c478bd9Sstevel@tonic-gate * by fme_eval() as the starting point for the inference 907c478bd9Sstevel@tonic-gate * algorithm. e0r is the event handle FMD passed to us when 917c478bd9Sstevel@tonic-gate * the ereport first arrived and is used when setting timers, 927c478bd9Sstevel@tonic-gate * which are always relative to the time of this initial 937c478bd9Sstevel@tonic-gate * report. 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate struct event *e0; 967c478bd9Sstevel@tonic-gate fmd_event_t *e0r; 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate id_t timer; /* for setting an fmd time-out */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate struct event *ecurrent; /* ereport under consideration */ 1017c478bd9Sstevel@tonic-gate struct event *suspects; /* current suspect list */ 1027c478bd9Sstevel@tonic-gate struct event *psuspects; /* previous suspect list */ 1037c478bd9Sstevel@tonic-gate int nsuspects; /* count of suspects */ 1047c478bd9Sstevel@tonic-gate int posted_suspects; /* true if we've posted a diagnosis */ 1057c478bd9Sstevel@tonic-gate int uniqobs; /* number of unique events observed */ 1067c478bd9Sstevel@tonic-gate int peek; /* just peeking, don't track suspects */ 1070cc1f05eSjrutt int overflow; /* true if overflow FME */ 1087c478bd9Sstevel@tonic-gate enum fme_state { 1097c478bd9Sstevel@tonic-gate FME_NOTHING = 5000, /* not evaluated yet */ 1107c478bd9Sstevel@tonic-gate FME_WAIT, /* need to wait for more info */ 1117c478bd9Sstevel@tonic-gate FME_CREDIBLE, /* suspect list is credible */ 1127aec1d6eScindi FME_DISPROVED, /* no valid suspects found */ 1137aec1d6eScindi FME_DEFERRED /* don't know yet (k-count not met) */ 1147c478bd9Sstevel@tonic-gate } state; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate unsigned long long pull; /* time passed since created */ 1177c478bd9Sstevel@tonic-gate unsigned long long wull; /* wait until this time for re-eval */ 1187c478bd9Sstevel@tonic-gate struct event *observations; /* observation list */ 1197c478bd9Sstevel@tonic-gate struct lut *globals; /* values of global variables */ 1207c478bd9Sstevel@tonic-gate /* fmd interfacing */ 1217c478bd9Sstevel@tonic-gate fmd_hdl_t *hdl; /* handle for talking with fmd */ 1227c478bd9Sstevel@tonic-gate fmd_case_t *fmcase; /* what fmd 'case' we associate with */ 1237c478bd9Sstevel@tonic-gate /* stats */ 1247c478bd9Sstevel@tonic-gate struct stats *Rcount; 1257c478bd9Sstevel@tonic-gate struct stats *Hcallcount; 1267c478bd9Sstevel@tonic-gate struct stats *Rcallcount; 1277c478bd9Sstevel@tonic-gate struct stats *Ccallcount; 1287c478bd9Sstevel@tonic-gate struct stats *Ecallcount; 1297c478bd9Sstevel@tonic-gate struct stats *Tcallcount; 1307c478bd9Sstevel@tonic-gate struct stats *Marrowcount; 1317c478bd9Sstevel@tonic-gate struct stats *diags; 1327c478bd9Sstevel@tonic-gate } *FMElist, *EFMElist, *ClosedFMEs; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate static struct case_list { 1357c478bd9Sstevel@tonic-gate fmd_case_t *fmcase; 1367c478bd9Sstevel@tonic-gate struct case_list *next; 1377c478bd9Sstevel@tonic-gate } *Undiagablecaselist; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate static void fme_eval(struct fme *fmep, fmd_event_t *ffep); 1407c478bd9Sstevel@tonic-gate static enum fme_state hypothesise(struct fme *fmep, struct event *ep, 1417aec1d6eScindi unsigned long long at_latest_by, unsigned long long *pdelay); 1427c478bd9Sstevel@tonic-gate static struct node *eventprop_lookup(struct event *ep, const char *propname); 1437c478bd9Sstevel@tonic-gate static struct node *pathstring2epnamenp(char *path); 144b5016cbbSstephh static void publish_undiagnosable(fmd_hdl_t *hdl, fmd_event_t *ffep, 145705e9f42SStephen Hanson fmd_case_t *fmcase, nvlist_t *detector, char *arg); 146705e9f42SStephen Hanson static char *undiag_2reason_str(int ud, char *arg); 14732d4e834STarik Soydan static const char *undiag_2defect_str(int ud); 1487c478bd9Sstevel@tonic-gate static void restore_suspects(struct fme *fmep); 1497c478bd9Sstevel@tonic-gate static void save_suspects(struct fme *fmep); 1507c478bd9Sstevel@tonic-gate static void destroy_fme(struct fme *f); 1517c478bd9Sstevel@tonic-gate static void fme_receive_report(fmd_hdl_t *hdl, fmd_event_t *ffep, 1527c478bd9Sstevel@tonic-gate const char *eventstring, const struct ipath *ipp, nvlist_t *nvl); 15308f6c065Sgavinm static void istat_counter_reset_cb(struct istat_entry *entp, 15408f6c065Sgavinm struct stats *statp, const struct ipath *ipp); 155e5ba14ffSstephh static void istat_counter_topo_chg_cb(struct istat_entry *entp, 156e5ba14ffSstephh struct stats *statp, void *unused); 157b5016cbbSstephh static void serd_reset_cb(struct serd_entry *entp, void *unused, 158b5016cbbSstephh const struct ipath *ipp); 159e5ba14ffSstephh static void serd_topo_chg_cb(struct serd_entry *entp, void *unused, 160e5ba14ffSstephh void *unused2); 161b5016cbbSstephh static void destroy_fme_bufs(struct fme *fp); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate static struct fme * 1647c478bd9Sstevel@tonic-gate alloc_fme(void) 1657c478bd9Sstevel@tonic-gate { 1667c478bd9Sstevel@tonic-gate struct fme *fmep; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate fmep = MALLOC(sizeof (*fmep)); 1697c478bd9Sstevel@tonic-gate bzero(fmep, sizeof (*fmep)); 1707c478bd9Sstevel@tonic-gate return (fmep); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * fme_ready -- called when all initialization of the FME (except for 1757c478bd9Sstevel@tonic-gate * stats) has completed successfully. Adds the fme to global lists 1767c478bd9Sstevel@tonic-gate * and establishes its stats. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate static struct fme * 1797c478bd9Sstevel@tonic-gate fme_ready(struct fme *fmep) 1807c478bd9Sstevel@tonic-gate { 1817c478bd9Sstevel@tonic-gate char nbuf[100]; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate Nfmep = NULL; /* don't need to free this on module abort now */ 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate if (EFMElist) { 1867c478bd9Sstevel@tonic-gate EFMElist->next = fmep; 1877c478bd9Sstevel@tonic-gate EFMElist = fmep; 1887c478bd9Sstevel@tonic-gate } else 1897c478bd9Sstevel@tonic-gate FMElist = EFMElist = fmep; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Rcount", fmep->id); 1927c478bd9Sstevel@tonic-gate fmep->Rcount = stats_new_counter(nbuf, "ereports received", 0); 1937c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Hcall", fmep->id); 1947c478bd9Sstevel@tonic-gate fmep->Hcallcount = stats_new_counter(nbuf, "calls to hypothesise()", 1); 1957c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Rcall", fmep->id); 1967c478bd9Sstevel@tonic-gate fmep->Rcallcount = stats_new_counter(nbuf, 1977c478bd9Sstevel@tonic-gate "calls to requirements_test()", 1); 1987c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Ccall", fmep->id); 1997c478bd9Sstevel@tonic-gate fmep->Ccallcount = stats_new_counter(nbuf, "calls to causes_test()", 1); 2007c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Ecall", fmep->id); 2017c478bd9Sstevel@tonic-gate fmep->Ecallcount = 2027c478bd9Sstevel@tonic-gate stats_new_counter(nbuf, "calls to effects_test()", 1); 2037c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Tcall", fmep->id); 2047c478bd9Sstevel@tonic-gate fmep->Tcallcount = stats_new_counter(nbuf, "calls to triggered()", 1); 2057c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.Marrow", fmep->id); 2067c478bd9Sstevel@tonic-gate fmep->Marrowcount = stats_new_counter(nbuf, 2077c478bd9Sstevel@tonic-gate "arrows marked by mark_arrows()", 1); 2087c478bd9Sstevel@tonic-gate (void) sprintf(nbuf, "fme%d.diags", fmep->id); 2097c478bd9Sstevel@tonic-gate fmep->diags = stats_new_counter(nbuf, "suspect lists diagnosed", 0); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB2, "newfme: config snapshot contains..."); 212e5ba14ffSstephh config_print(O_ALTFP|O_VERB2, fmep->config); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate return (fmep); 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 217b5016cbbSstephh extern void ipath_dummy_lut(struct arrow *); 218b5016cbbSstephh extern struct lut *itree_create_dummy(const char *, const struct ipath *); 219b5016cbbSstephh 220b5016cbbSstephh /* ARGSUSED */ 221b5016cbbSstephh static void 222b5016cbbSstephh set_needed_arrows(struct event *ep, struct event *ep2, struct fme *fmep) 223b5016cbbSstephh { 224b5016cbbSstephh struct bubble *bp; 225b5016cbbSstephh struct arrowlist *ap; 226b5016cbbSstephh 227b5016cbbSstephh for (bp = itree_next_bubble(ep, NULL); bp; 228b5016cbbSstephh bp = itree_next_bubble(ep, bp)) { 229b5016cbbSstephh if (bp->t != B_FROM) 230b5016cbbSstephh continue; 231b5016cbbSstephh for (ap = itree_next_arrow(bp, NULL); ap; 232b5016cbbSstephh ap = itree_next_arrow(bp, ap)) { 233b5016cbbSstephh ap->arrowp->pnode->u.arrow.needed = 1; 234b5016cbbSstephh ipath_dummy_lut(ap->arrowp); 235b5016cbbSstephh } 236b5016cbbSstephh } 237b5016cbbSstephh } 238b5016cbbSstephh 239b5016cbbSstephh /* ARGSUSED */ 240b5016cbbSstephh static void 241b5016cbbSstephh unset_needed_arrows(struct event *ep, struct event *ep2, struct fme *fmep) 242b5016cbbSstephh { 243b5016cbbSstephh struct bubble *bp; 244b5016cbbSstephh struct arrowlist *ap; 245b5016cbbSstephh 246b5016cbbSstephh for (bp = itree_next_bubble(ep, NULL); bp; 247b5016cbbSstephh bp = itree_next_bubble(ep, bp)) { 248b5016cbbSstephh if (bp->t != B_FROM) 249b5016cbbSstephh continue; 250b5016cbbSstephh for (ap = itree_next_arrow(bp, NULL); ap; 251b5016cbbSstephh ap = itree_next_arrow(bp, ap)) 252b5016cbbSstephh ap->arrowp->pnode->u.arrow.needed = 0; 253b5016cbbSstephh } 254b5016cbbSstephh } 255b5016cbbSstephh 256b5016cbbSstephh static void globals_destructor(void *left, void *right, void *arg); 257b5016cbbSstephh static void clear_arrows(struct event *ep, struct event *ep2, struct fme *fmep); 258b5016cbbSstephh 259705e9f42SStephen Hanson static boolean_t 260b5016cbbSstephh prune_propagations(const char *e0class, const struct ipath *e0ipp) 261b5016cbbSstephh { 262b5016cbbSstephh char nbuf[100]; 263b5016cbbSstephh unsigned long long my_delay = TIMEVAL_EVENTUALLY; 264b5016cbbSstephh extern struct lut *Usednames; 265b5016cbbSstephh 266b5016cbbSstephh Nfmep = alloc_fme(); 267b5016cbbSstephh Nfmep->id = Nextid; 268b5016cbbSstephh Nfmep->state = FME_NOTHING; 269b5016cbbSstephh Nfmep->eventtree = itree_create_dummy(e0class, e0ipp); 270b5016cbbSstephh if ((Nfmep->e0 = 271b5016cbbSstephh itree_lookup(Nfmep->eventtree, e0class, e0ipp)) == NULL) { 272b5016cbbSstephh itree_free(Nfmep->eventtree); 273b5016cbbSstephh FREE(Nfmep); 274b5016cbbSstephh Nfmep = NULL; 275705e9f42SStephen Hanson return (B_FALSE); 276b5016cbbSstephh } 277b5016cbbSstephh Nfmep->ecurrent = Nfmep->observations = Nfmep->e0; 278b5016cbbSstephh Nfmep->e0->count++; 279b5016cbbSstephh 280b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Rcount", Nfmep->id); 281b5016cbbSstephh Nfmep->Rcount = stats_new_counter(nbuf, "ereports received", 0); 282b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Hcall", Nfmep->id); 283b5016cbbSstephh Nfmep->Hcallcount = 284b5016cbbSstephh stats_new_counter(nbuf, "calls to hypothesise()", 1); 285b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Rcall", Nfmep->id); 286b5016cbbSstephh Nfmep->Rcallcount = stats_new_counter(nbuf, 287b5016cbbSstephh "calls to requirements_test()", 1); 288b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Ccall", Nfmep->id); 289b5016cbbSstephh Nfmep->Ccallcount = 290b5016cbbSstephh stats_new_counter(nbuf, "calls to causes_test()", 1); 291b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Ecall", Nfmep->id); 292b5016cbbSstephh Nfmep->Ecallcount = 293b5016cbbSstephh stats_new_counter(nbuf, "calls to effects_test()", 1); 294b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Tcall", Nfmep->id); 295b5016cbbSstephh Nfmep->Tcallcount = stats_new_counter(nbuf, "calls to triggered()", 1); 296b5016cbbSstephh (void) sprintf(nbuf, "fme%d.Marrow", Nfmep->id); 297b5016cbbSstephh Nfmep->Marrowcount = stats_new_counter(nbuf, 298b5016cbbSstephh "arrows marked by mark_arrows()", 1); 299b5016cbbSstephh (void) sprintf(nbuf, "fme%d.diags", Nfmep->id); 300b5016cbbSstephh Nfmep->diags = stats_new_counter(nbuf, "suspect lists diagnosed", 0); 301b5016cbbSstephh 302b5016cbbSstephh Nfmep->peek = 1; 303b5016cbbSstephh lut_walk(Nfmep->eventtree, (lut_cb)unset_needed_arrows, (void *)Nfmep); 304b5016cbbSstephh lut_free(Usednames, NULL, NULL); 305b5016cbbSstephh Usednames = NULL; 306b5016cbbSstephh lut_walk(Nfmep->eventtree, (lut_cb)clear_arrows, (void *)Nfmep); 307b5016cbbSstephh (void) hypothesise(Nfmep, Nfmep->e0, Nfmep->ull, &my_delay); 308b5016cbbSstephh itree_prune(Nfmep->eventtree); 309b5016cbbSstephh lut_walk(Nfmep->eventtree, (lut_cb)set_needed_arrows, (void *)Nfmep); 310b5016cbbSstephh 311b5016cbbSstephh stats_delete(Nfmep->Rcount); 312b5016cbbSstephh stats_delete(Nfmep->Hcallcount); 313b5016cbbSstephh stats_delete(Nfmep->Rcallcount); 314b5016cbbSstephh stats_delete(Nfmep->Ccallcount); 315b5016cbbSstephh stats_delete(Nfmep->Ecallcount); 316b5016cbbSstephh stats_delete(Nfmep->Tcallcount); 317b5016cbbSstephh stats_delete(Nfmep->Marrowcount); 318b5016cbbSstephh stats_delete(Nfmep->diags); 319b5016cbbSstephh itree_free(Nfmep->eventtree); 320b5016cbbSstephh lut_free(Nfmep->globals, globals_destructor, NULL); 321b5016cbbSstephh FREE(Nfmep); 322705e9f42SStephen Hanson return (B_TRUE); 323b5016cbbSstephh } 324b5016cbbSstephh 3257c478bd9Sstevel@tonic-gate static struct fme * 326b5016cbbSstephh newfme(const char *e0class, const struct ipath *e0ipp, fmd_hdl_t *hdl, 327*a3f6a2a4SRob Johnston fmd_case_t *fmcase, fmd_event_t *ffep, nvlist_t *nvl) 3287c478bd9Sstevel@tonic-gate { 3297c478bd9Sstevel@tonic-gate struct cfgdata *cfgdata; 330b5016cbbSstephh int init_size; 331b5016cbbSstephh extern int alloc_total(); 332705e9f42SStephen Hanson nvlist_t *detector = NULL; 333705e9f42SStephen Hanson char *pathstr; 334705e9f42SStephen Hanson char *arg; 335705e9f42SStephen Hanson 336705e9f42SStephen Hanson /* 337705e9f42SStephen Hanson * First check if e0ipp is actually in the topology so we can give a 338705e9f42SStephen Hanson * more useful error message. 339705e9f42SStephen Hanson */ 340705e9f42SStephen Hanson ipathlastcomp(e0ipp); 341705e9f42SStephen Hanson pathstr = ipath2str(NULL, e0ipp); 342705e9f42SStephen Hanson cfgdata = config_snapshot(); 343705e9f42SStephen Hanson platform_units_translate(0, cfgdata->cooked, NULL, NULL, 344705e9f42SStephen Hanson &detector, pathstr); 345705e9f42SStephen Hanson FREE(pathstr); 346705e9f42SStephen Hanson structconfig_free(cfgdata->cooked); 347705e9f42SStephen Hanson config_free(cfgdata); 348705e9f42SStephen Hanson if (detector == NULL) { 349f5961f52SAdrian Frost /* See if class permits silent discard on unknown component. */ 350f5961f52SAdrian Frost if (lut_lookup(Ereportenames_discard, (void *)e0class, NULL)) { 351f5961f52SAdrian Frost out(O_ALTFP|O_VERB2, "Unable to map \"%s\" ereport " 352f5961f52SAdrian Frost "to component path, but silent discard allowed.", 353f5961f52SAdrian Frost e0class); 354*a3f6a2a4SRob Johnston fmd_case_close(hdl, fmcase); 355f5961f52SAdrian Frost } else { 356f5961f52SAdrian Frost Undiag_reason = UD_VAL_BADEVENTPATH; 357f5961f52SAdrian Frost (void) nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR, 358f5961f52SAdrian Frost &detector); 359f5961f52SAdrian Frost arg = ipath2str(e0class, e0ipp); 360f5961f52SAdrian Frost publish_undiagnosable(hdl, ffep, fmcase, detector, arg); 361f5961f52SAdrian Frost FREE(arg); 362f5961f52SAdrian Frost } 363705e9f42SStephen Hanson return (NULL); 364705e9f42SStephen Hanson } 365705e9f42SStephen Hanson 366705e9f42SStephen Hanson /* 367705e9f42SStephen Hanson * Next run a quick first pass of the rules with a dummy config. This 368705e9f42SStephen Hanson * allows us to prune those rules which can't possibly cause this 369705e9f42SStephen Hanson * ereport. 370705e9f42SStephen Hanson */ 371705e9f42SStephen Hanson if (!prune_propagations(e0class, e0ipp)) { 372705e9f42SStephen Hanson /* 373705e9f42SStephen Hanson * The fault class must have been in the rules or we would 374705e9f42SStephen Hanson * not have registered for it (and got a "nosub"), and the 375705e9f42SStephen Hanson * pathname must be in the topology or we would have failed the 376705e9f42SStephen Hanson * previous test. So to get here means the combination of 377705e9f42SStephen Hanson * class and pathname in the ereport must be invalid. 378705e9f42SStephen Hanson */ 379705e9f42SStephen Hanson Undiag_reason = UD_VAL_BADEVENTCLASS; 380705e9f42SStephen Hanson arg = ipath2str(e0class, e0ipp); 381705e9f42SStephen Hanson publish_undiagnosable(hdl, ffep, fmcase, detector, arg); 382705e9f42SStephen Hanson nvlist_free(detector); 383705e9f42SStephen Hanson FREE(arg); 384705e9f42SStephen Hanson return (NULL); 385705e9f42SStephen Hanson } 3867c478bd9Sstevel@tonic-gate 387705e9f42SStephen Hanson /* 388705e9f42SStephen Hanson * Now go ahead and create the real fme using the pruned rules. 389705e9f42SStephen Hanson */ 390b5016cbbSstephh init_size = alloc_total(); 391b5016cbbSstephh out(O_ALTFP|O_STAMP, "start config_snapshot using %d bytes", init_size); 39235f59e50SStephen Hanson nvlist_free(detector); 39335f59e50SStephen Hanson pathstr = ipath2str(NULL, e0ipp); 39432d4e834STarik Soydan cfgdata = config_snapshot(); 39535f59e50SStephen Hanson platform_units_translate(0, cfgdata->cooked, NULL, NULL, 39635f59e50SStephen Hanson &detector, pathstr); 39735f59e50SStephen Hanson FREE(pathstr); 398b5016cbbSstephh platform_save_config(hdl, fmcase); 399b5016cbbSstephh out(O_ALTFP|O_STAMP, "config_snapshot added %d bytes", 400b5016cbbSstephh alloc_total() - init_size); 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate Nfmep = alloc_fme(); 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate Nfmep->id = Nextid++; 405e5ba14ffSstephh Nfmep->config = cfgdata->cooked; 406e5ba14ffSstephh config_free(cfgdata); 4077c478bd9Sstevel@tonic-gate Nfmep->posted_suspects = 0; 4087c478bd9Sstevel@tonic-gate Nfmep->uniqobs = 0; 4097c478bd9Sstevel@tonic-gate Nfmep->state = FME_NOTHING; 4107c478bd9Sstevel@tonic-gate Nfmep->pull = 0ULL; 4110cc1f05eSjrutt Nfmep->overflow = 0; 4127c478bd9Sstevel@tonic-gate 413b5016cbbSstephh Nfmep->fmcase = fmcase; 414b5016cbbSstephh Nfmep->hdl = hdl; 4157c478bd9Sstevel@tonic-gate 416e5ba14ffSstephh if ((Nfmep->eventtree = itree_create(Nfmep->config)) == NULL) { 41732d4e834STarik Soydan Undiag_reason = UD_VAL_INSTFAIL; 418705e9f42SStephen Hanson arg = ipath2str(e0class, e0ipp); 419705e9f42SStephen Hanson publish_undiagnosable(hdl, ffep, fmcase, detector, arg); 420705e9f42SStephen Hanson nvlist_free(detector); 421705e9f42SStephen Hanson FREE(arg); 422e5ba14ffSstephh structconfig_free(Nfmep->config); 423b5016cbbSstephh destroy_fme_bufs(Nfmep); 4247c478bd9Sstevel@tonic-gate FREE(Nfmep); 4257c478bd9Sstevel@tonic-gate Nfmep = NULL; 4267c478bd9Sstevel@tonic-gate return (NULL); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate itree_ptree(O_ALTFP|O_VERB2, Nfmep->eventtree); 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if ((Nfmep->e0 = 4327c478bd9Sstevel@tonic-gate itree_lookup(Nfmep->eventtree, e0class, e0ipp)) == NULL) { 43332d4e834STarik Soydan Undiag_reason = UD_VAL_BADEVENTI; 434705e9f42SStephen Hanson arg = ipath2str(e0class, e0ipp); 435705e9f42SStephen Hanson publish_undiagnosable(hdl, ffep, fmcase, detector, arg); 436705e9f42SStephen Hanson nvlist_free(detector); 437705e9f42SStephen Hanson FREE(arg); 4387c478bd9Sstevel@tonic-gate itree_free(Nfmep->eventtree); 439e5ba14ffSstephh structconfig_free(Nfmep->config); 440b5016cbbSstephh destroy_fme_bufs(Nfmep); 4417c478bd9Sstevel@tonic-gate FREE(Nfmep); 4427c478bd9Sstevel@tonic-gate Nfmep = NULL; 4437c478bd9Sstevel@tonic-gate return (NULL); 4447c478bd9Sstevel@tonic-gate } 4457c478bd9Sstevel@tonic-gate 446705e9f42SStephen Hanson nvlist_free(detector); 4477c478bd9Sstevel@tonic-gate return (fme_ready(Nfmep)); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate void 4517c478bd9Sstevel@tonic-gate fme_fini(void) 4527c478bd9Sstevel@tonic-gate { 4537c478bd9Sstevel@tonic-gate struct fme *sfp, *fp; 4547c478bd9Sstevel@tonic-gate struct case_list *ucasep, *nextcasep; 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate ucasep = Undiagablecaselist; 4577c478bd9Sstevel@tonic-gate while (ucasep != NULL) { 4587c478bd9Sstevel@tonic-gate nextcasep = ucasep->next; 4597c478bd9Sstevel@tonic-gate FREE(ucasep); 4607c478bd9Sstevel@tonic-gate ucasep = nextcasep; 4617c478bd9Sstevel@tonic-gate } 4627c478bd9Sstevel@tonic-gate Undiagablecaselist = NULL; 4637c478bd9Sstevel@tonic-gate 4647c478bd9Sstevel@tonic-gate /* clean up closed fmes */ 4657c478bd9Sstevel@tonic-gate fp = ClosedFMEs; 4667c478bd9Sstevel@tonic-gate while (fp != NULL) { 4677c478bd9Sstevel@tonic-gate sfp = fp->next; 4687c478bd9Sstevel@tonic-gate destroy_fme(fp); 4697c478bd9Sstevel@tonic-gate fp = sfp; 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate ClosedFMEs = NULL; 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate fp = FMElist; 4747c478bd9Sstevel@tonic-gate while (fp != NULL) { 4757c478bd9Sstevel@tonic-gate sfp = fp->next; 4767c478bd9Sstevel@tonic-gate destroy_fme(fp); 4777c478bd9Sstevel@tonic-gate fp = sfp; 4787c478bd9Sstevel@tonic-gate } 4797c478bd9Sstevel@tonic-gate FMElist = EFMElist = NULL; 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate /* if we were in the middle of creating an fme, free it now */ 4827c478bd9Sstevel@tonic-gate if (Nfmep) { 4837c478bd9Sstevel@tonic-gate destroy_fme(Nfmep); 4847c478bd9Sstevel@tonic-gate Nfmep = NULL; 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate } 4877c478bd9Sstevel@tonic-gate 4887c478bd9Sstevel@tonic-gate /* 4897c478bd9Sstevel@tonic-gate * Allocated space for a buffer name. 20 bytes allows for 4907c478bd9Sstevel@tonic-gate * a ridiculous 9,999,999 unique observations. 4917c478bd9Sstevel@tonic-gate */ 4927c478bd9Sstevel@tonic-gate #define OBBUFNMSZ 20 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * serialize_observation 4967c478bd9Sstevel@tonic-gate * 4977c478bd9Sstevel@tonic-gate * Create a recoverable version of the current observation 4987c478bd9Sstevel@tonic-gate * (f->ecurrent). We keep a serialized version of each unique 4997c478bd9Sstevel@tonic-gate * observation in order that we may resume correctly the fme in the 5007c478bd9Sstevel@tonic-gate * correct state if eft or fmd crashes and we're restarted. 5017c478bd9Sstevel@tonic-gate */ 5027c478bd9Sstevel@tonic-gate static void 5037c478bd9Sstevel@tonic-gate serialize_observation(struct fme *fp, const char *cls, const struct ipath *ipp) 5047c478bd9Sstevel@tonic-gate { 5057c478bd9Sstevel@tonic-gate size_t pkdlen; 5067c478bd9Sstevel@tonic-gate char tmpbuf[OBBUFNMSZ]; 5077c478bd9Sstevel@tonic-gate char *pkd = NULL; 5087c478bd9Sstevel@tonic-gate char *estr; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", fp->uniqobs); 5117c478bd9Sstevel@tonic-gate estr = ipath2str(cls, ipp); 5127c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, tmpbuf, strlen(estr) + 1); 5137c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, tmpbuf, (void *)estr, 5147c478bd9Sstevel@tonic-gate strlen(estr) + 1); 5157c478bd9Sstevel@tonic-gate FREE(estr); 5167c478bd9Sstevel@tonic-gate 5177c478bd9Sstevel@tonic-gate if (fp->ecurrent != NULL && fp->ecurrent->nvp != NULL) { 5187c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, 5197c478bd9Sstevel@tonic-gate OBBUFNMSZ, "observed%d.nvp", fp->uniqobs); 5207c478bd9Sstevel@tonic-gate if (nvlist_xpack(fp->ecurrent->nvp, 5217c478bd9Sstevel@tonic-gate &pkd, &pkdlen, NV_ENCODE_XDR, &Eft_nv_hdl) != 0) 5227c478bd9Sstevel@tonic-gate out(O_DIE|O_SYS, "pack of observed nvl failed"); 5237c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, tmpbuf, pkdlen); 5247c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, tmpbuf, (void *)pkd, pkdlen); 5257c478bd9Sstevel@tonic-gate FREE(pkd); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate fp->uniqobs++; 5297c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_NOBS, (void *)&fp->uniqobs, 5307c478bd9Sstevel@tonic-gate sizeof (fp->uniqobs)); 5317c478bd9Sstevel@tonic-gate } 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate /* 5347c478bd9Sstevel@tonic-gate * init_fme_bufs -- We keep several bits of state about an fme for 5357c478bd9Sstevel@tonic-gate * use if eft or fmd crashes and we're restarted. 5367c478bd9Sstevel@tonic-gate */ 5377c478bd9Sstevel@tonic-gate static void 5387c478bd9Sstevel@tonic-gate init_fme_bufs(struct fme *fp) 5397c478bd9Sstevel@tonic-gate { 5407c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_PULL, sizeof (fp->pull)); 5417c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_PULL, (void *)&fp->pull, 5427c478bd9Sstevel@tonic-gate sizeof (fp->pull)); 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_ID, sizeof (fp->id)); 5457c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_ID, (void *)&fp->id, 5467c478bd9Sstevel@tonic-gate sizeof (fp->id)); 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_NOBS, sizeof (fp->uniqobs)); 5497c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_NOBS, (void *)&fp->uniqobs, 5507c478bd9Sstevel@tonic-gate sizeof (fp->uniqobs)); 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate fmd_buf_create(fp->hdl, fp->fmcase, WOBUF_POSTD, 5537c478bd9Sstevel@tonic-gate sizeof (fp->posted_suspects)); 5547c478bd9Sstevel@tonic-gate fmd_buf_write(fp->hdl, fp->fmcase, WOBUF_POSTD, 5557c478bd9Sstevel@tonic-gate (void *)&fp->posted_suspects, sizeof (fp->posted_suspects)); 5567c478bd9Sstevel@tonic-gate } 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate static void 5597c478bd9Sstevel@tonic-gate destroy_fme_bufs(struct fme *fp) 5607c478bd9Sstevel@tonic-gate { 5617c478bd9Sstevel@tonic-gate char tmpbuf[OBBUFNMSZ]; 5627c478bd9Sstevel@tonic-gate int o; 5637c478bd9Sstevel@tonic-gate 564b5016cbbSstephh platform_restore_config(fp->hdl, fp->fmcase); 5657c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_CFGLEN); 5667c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_CFG); 5677c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_PULL); 5687c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_ID); 5697c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_POSTD); 5707c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, WOBUF_NOBS); 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate for (o = 0; o < fp->uniqobs; o++) { 5737c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", o); 5747c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, tmpbuf); 5757c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d.nvp", o); 5767c478bd9Sstevel@tonic-gate fmd_buf_destroy(fp->hdl, fp->fmcase, tmpbuf); 5777c478bd9Sstevel@tonic-gate } 5787c478bd9Sstevel@tonic-gate } 5797c478bd9Sstevel@tonic-gate 5807c478bd9Sstevel@tonic-gate /* 5817c478bd9Sstevel@tonic-gate * reconstitute_observations -- convert a case's serialized observations 5827c478bd9Sstevel@tonic-gate * back into struct events. Returns zero if all observations are 5837c478bd9Sstevel@tonic-gate * successfully reconstituted. 5847c478bd9Sstevel@tonic-gate */ 5857c478bd9Sstevel@tonic-gate static int 5867c478bd9Sstevel@tonic-gate reconstitute_observations(struct fme *fmep) 5877c478bd9Sstevel@tonic-gate { 5887c478bd9Sstevel@tonic-gate struct event *ep; 5897c478bd9Sstevel@tonic-gate struct node *epnamenp = NULL; 5907c478bd9Sstevel@tonic-gate size_t pkdlen; 5917c478bd9Sstevel@tonic-gate char *pkd = NULL; 5927c478bd9Sstevel@tonic-gate char *tmpbuf = alloca(OBBUFNMSZ); 5937c478bd9Sstevel@tonic-gate char *sepptr; 5947c478bd9Sstevel@tonic-gate char *estr; 5957c478bd9Sstevel@tonic-gate int ocnt; 5967c478bd9Sstevel@tonic-gate int elen; 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate for (ocnt = 0; ocnt < fmep->uniqobs; ocnt++) { 5997c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d", ocnt); 6007c478bd9Sstevel@tonic-gate elen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf); 6017c478bd9Sstevel@tonic-gate if (elen == 0) { 6027c478bd9Sstevel@tonic-gate out(O_ALTFP, 6037c478bd9Sstevel@tonic-gate "reconstitute_observation: no %s buffer found.", 6047c478bd9Sstevel@tonic-gate tmpbuf); 60532d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGOBS; 6067c478bd9Sstevel@tonic-gate break; 6077c478bd9Sstevel@tonic-gate } 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate estr = MALLOC(elen); 6107c478bd9Sstevel@tonic-gate fmd_buf_read(fmep->hdl, fmep->fmcase, tmpbuf, estr, elen); 6117c478bd9Sstevel@tonic-gate sepptr = strchr(estr, '@'); 6127c478bd9Sstevel@tonic-gate if (sepptr == NULL) { 6137c478bd9Sstevel@tonic-gate out(O_ALTFP, 6147c478bd9Sstevel@tonic-gate "reconstitute_observation: %s: " 6157c478bd9Sstevel@tonic-gate "missing @ separator in %s.", 6167c478bd9Sstevel@tonic-gate tmpbuf, estr); 61732d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGPATH; 6187c478bd9Sstevel@tonic-gate FREE(estr); 6197c478bd9Sstevel@tonic-gate break; 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate *sepptr = '\0'; 6237c478bd9Sstevel@tonic-gate if ((epnamenp = pathstring2epnamenp(sepptr + 1)) == NULL) { 6247c478bd9Sstevel@tonic-gate out(O_ALTFP, 6257c478bd9Sstevel@tonic-gate "reconstitute_observation: %s: " 6267c478bd9Sstevel@tonic-gate "trouble converting path string \"%s\" " 6277c478bd9Sstevel@tonic-gate "to internal representation.", 6287c478bd9Sstevel@tonic-gate tmpbuf, sepptr + 1); 62932d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGPATH; 6307c478bd9Sstevel@tonic-gate FREE(estr); 6317c478bd9Sstevel@tonic-gate break; 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate /* construct the event */ 6357c478bd9Sstevel@tonic-gate ep = itree_lookup(fmep->eventtree, 6367c478bd9Sstevel@tonic-gate stable(estr), ipath(epnamenp)); 6377c478bd9Sstevel@tonic-gate if (ep == NULL) { 6387c478bd9Sstevel@tonic-gate out(O_ALTFP, 6397c478bd9Sstevel@tonic-gate "reconstitute_observation: %s: " 6407c478bd9Sstevel@tonic-gate "lookup of \"%s\" in itree failed.", 6417c478bd9Sstevel@tonic-gate tmpbuf, ipath2str(estr, ipath(epnamenp))); 64232d4e834STarik Soydan Undiag_reason = UD_VAL_BADOBS; 6437c478bd9Sstevel@tonic-gate tree_free(epnamenp); 6447c478bd9Sstevel@tonic-gate FREE(estr); 6457c478bd9Sstevel@tonic-gate break; 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate tree_free(epnamenp); 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate /* 6507c478bd9Sstevel@tonic-gate * We may or may not have a saved nvlist for the observation 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate (void) snprintf(tmpbuf, OBBUFNMSZ, "observed%d.nvp", ocnt); 6537c478bd9Sstevel@tonic-gate pkdlen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf); 6547c478bd9Sstevel@tonic-gate if (pkdlen != 0) { 6557c478bd9Sstevel@tonic-gate pkd = MALLOC(pkdlen); 6567c478bd9Sstevel@tonic-gate fmd_buf_read(fmep->hdl, 6577c478bd9Sstevel@tonic-gate fmep->fmcase, tmpbuf, pkd, pkdlen); 6587aec1d6eScindi ASSERT(ep->nvp == NULL); 6597c478bd9Sstevel@tonic-gate if (nvlist_xunpack(pkd, 6607c478bd9Sstevel@tonic-gate pkdlen, &ep->nvp, &Eft_nv_hdl) != 0) 6617c478bd9Sstevel@tonic-gate out(O_DIE|O_SYS, "pack of observed nvl failed"); 6627c478bd9Sstevel@tonic-gate FREE(pkd); 6637c478bd9Sstevel@tonic-gate } 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate if (ocnt == 0) 6667c478bd9Sstevel@tonic-gate fmep->e0 = ep; 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate FREE(estr); 6697c478bd9Sstevel@tonic-gate fmep->ecurrent = ep; 6707c478bd9Sstevel@tonic-gate ep->count++; 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate /* link it into list of observations seen */ 6737c478bd9Sstevel@tonic-gate ep->observations = fmep->observations; 6747c478bd9Sstevel@tonic-gate fmep->observations = ep; 6757c478bd9Sstevel@tonic-gate } 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate if (ocnt == fmep->uniqobs) { 6787c478bd9Sstevel@tonic-gate (void) fme_ready(fmep); 6797c478bd9Sstevel@tonic-gate return (0); 6807c478bd9Sstevel@tonic-gate } 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate return (1); 6837c478bd9Sstevel@tonic-gate } 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate /* 6867c478bd9Sstevel@tonic-gate * restart_fme -- called during eft initialization. Reconstitutes 6877c478bd9Sstevel@tonic-gate * an in-progress fme. 6887c478bd9Sstevel@tonic-gate */ 6897c478bd9Sstevel@tonic-gate void 6907c478bd9Sstevel@tonic-gate fme_restart(fmd_hdl_t *hdl, fmd_case_t *inprogress) 6917c478bd9Sstevel@tonic-gate { 6927c478bd9Sstevel@tonic-gate nvlist_t *defect; 6937c478bd9Sstevel@tonic-gate struct case_list *bad; 6947c478bd9Sstevel@tonic-gate struct fme *fmep; 695e5ba14ffSstephh struct cfgdata *cfgdata; 6967c478bd9Sstevel@tonic-gate size_t rawsz; 697b5016cbbSstephh struct event *ep; 698b5016cbbSstephh char *tmpbuf = alloca(OBBUFNMSZ); 699b5016cbbSstephh char *sepptr; 700b5016cbbSstephh char *estr; 701b5016cbbSstephh int elen; 702b5016cbbSstephh struct node *epnamenp = NULL; 703b5016cbbSstephh int init_size; 704b5016cbbSstephh extern int alloc_total(); 705705e9f42SStephen Hanson char *reason; 706b5016cbbSstephh 707b5016cbbSstephh /* 708b5016cbbSstephh * ignore solved or closed cases 709b5016cbbSstephh */ 710b5016cbbSstephh if (fmd_case_solved(hdl, inprogress) || 711b5016cbbSstephh fmd_case_closed(hdl, inprogress)) 712b5016cbbSstephh return; 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate fmep = alloc_fme(); 7157c478bd9Sstevel@tonic-gate fmep->fmcase = inprogress; 7167c478bd9Sstevel@tonic-gate fmep->hdl = hdl; 7177c478bd9Sstevel@tonic-gate 7189f8ca725Sstephh if (fmd_buf_size(hdl, inprogress, WOBUF_POSTD) == 0) { 7199f8ca725Sstephh out(O_ALTFP, "restart_fme: no saved posted status"); 72032d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGINFO; 7219f8ca725Sstephh goto badcase; 7229f8ca725Sstephh } else { 7239f8ca725Sstephh fmd_buf_read(hdl, inprogress, WOBUF_POSTD, 7249f8ca725Sstephh (void *)&fmep->posted_suspects, 7259f8ca725Sstephh sizeof (fmep->posted_suspects)); 7269f8ca725Sstephh } 7279f8ca725Sstephh 728b5016cbbSstephh if (fmd_buf_size(hdl, inprogress, WOBUF_ID) == 0) { 729b5016cbbSstephh out(O_ALTFP, "restart_fme: no saved id"); 73032d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGINFO; 7319f8ca725Sstephh goto badcase; 732b5016cbbSstephh } else { 733b5016cbbSstephh fmd_buf_read(hdl, inprogress, WOBUF_ID, (void *)&fmep->id, 734b5016cbbSstephh sizeof (fmep->id)); 735b5016cbbSstephh } 736b5016cbbSstephh if (Nextid <= fmep->id) 737b5016cbbSstephh Nextid = fmep->id + 1; 738b5016cbbSstephh 739b5016cbbSstephh out(O_ALTFP, "Replay FME %d", fmep->id); 7409f8ca725Sstephh 7417c478bd9Sstevel@tonic-gate if (fmd_buf_size(hdl, inprogress, WOBUF_CFGLEN) != sizeof (size_t)) { 7427c478bd9Sstevel@tonic-gate out(O_ALTFP, "restart_fme: No config data"); 74332d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGINFO; 7447c478bd9Sstevel@tonic-gate goto badcase; 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate fmd_buf_read(hdl, inprogress, WOBUF_CFGLEN, (void *)&rawsz, 7477c478bd9Sstevel@tonic-gate sizeof (size_t)); 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate if ((fmep->e0r = fmd_case_getprincipal(hdl, inprogress)) == NULL) { 7507c478bd9Sstevel@tonic-gate out(O_ALTFP, "restart_fme: No event zero"); 75132d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGZERO; 7527c478bd9Sstevel@tonic-gate goto badcase; 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate 755b5016cbbSstephh if (fmd_buf_size(hdl, inprogress, WOBUF_PULL) == 0) { 756b5016cbbSstephh out(O_ALTFP, "restart_fme: no saved wait time"); 75732d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGINFO; 758b5016cbbSstephh goto badcase; 759b5016cbbSstephh } else { 760b5016cbbSstephh fmd_buf_read(hdl, inprogress, WOBUF_PULL, (void *)&fmep->pull, 761b5016cbbSstephh sizeof (fmep->pull)); 762b5016cbbSstephh } 763b5016cbbSstephh 764b5016cbbSstephh if (fmd_buf_size(hdl, inprogress, WOBUF_NOBS) == 0) { 765b5016cbbSstephh out(O_ALTFP, "restart_fme: no count of observations"); 76632d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGINFO; 767b5016cbbSstephh goto badcase; 768b5016cbbSstephh } else { 769b5016cbbSstephh fmd_buf_read(hdl, inprogress, WOBUF_NOBS, 770b5016cbbSstephh (void *)&fmep->uniqobs, sizeof (fmep->uniqobs)); 771b5016cbbSstephh } 772b5016cbbSstephh 773b5016cbbSstephh (void) snprintf(tmpbuf, OBBUFNMSZ, "observed0"); 774b5016cbbSstephh elen = fmd_buf_size(fmep->hdl, fmep->fmcase, tmpbuf); 775b5016cbbSstephh if (elen == 0) { 776b5016cbbSstephh out(O_ALTFP, "reconstitute_observation: no %s buffer found.", 777b5016cbbSstephh tmpbuf); 77832d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGOBS; 779b5016cbbSstephh goto badcase; 780b5016cbbSstephh } 781b5016cbbSstephh estr = MALLOC(elen); 782b5016cbbSstephh fmd_buf_read(fmep->hdl, fmep->fmcase, tmpbuf, estr, elen); 783b5016cbbSstephh sepptr = strchr(estr, '@'); 784b5016cbbSstephh if (sepptr == NULL) { 785b5016cbbSstephh out(O_ALTFP, "reconstitute_observation: %s: " 786b5016cbbSstephh "missing @ separator in %s.", 787b5016cbbSstephh tmpbuf, estr); 78832d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGPATH; 789b5016cbbSstephh FREE(estr); 790b5016cbbSstephh goto badcase; 791b5016cbbSstephh } 792b5016cbbSstephh *sepptr = '\0'; 793b5016cbbSstephh if ((epnamenp = pathstring2epnamenp(sepptr + 1)) == NULL) { 794b5016cbbSstephh out(O_ALTFP, "reconstitute_observation: %s: " 795b5016cbbSstephh "trouble converting path string \"%s\" " 796b5016cbbSstephh "to internal representation.", tmpbuf, sepptr + 1); 79732d4e834STarik Soydan Undiag_reason = UD_VAL_MISSINGPATH; 798b5016cbbSstephh FREE(estr); 799b5016cbbSstephh goto badcase; 800b5016cbbSstephh } 801705e9f42SStephen Hanson (void) prune_propagations(stable(estr), ipath(epnamenp)); 802b5016cbbSstephh tree_free(epnamenp); 803b5016cbbSstephh FREE(estr); 804b5016cbbSstephh 805b5016cbbSstephh init_size = alloc_total(); 806b5016cbbSstephh out(O_ALTFP|O_STAMP, "start config_restore using %d bytes", init_size); 8077c478bd9Sstevel@tonic-gate cfgdata = MALLOC(sizeof (struct cfgdata)); 8087c478bd9Sstevel@tonic-gate cfgdata->cooked = NULL; 8097c478bd9Sstevel@tonic-gate cfgdata->devcache = NULL; 810602ca9eaScth cfgdata->devidcache = NULL; 81144ed9dbbSStephen Hanson cfgdata->tpcache = NULL; 8127c478bd9Sstevel@tonic-gate cfgdata->cpucache = NULL; 813b5016cbbSstephh cfgdata->raw_refcnt = 1; 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate if (rawsz > 0) { 8167c478bd9Sstevel@tonic-gate if (fmd_buf_size(hdl, inprogress, WOBUF_CFG) != rawsz) { 8177c478bd9Sstevel@tonic-gate out(O_ALTFP, "restart_fme: Config data size mismatch"); 81832d4e834STarik Soydan Undiag_reason = UD_VAL_CFGMISMATCH; 8197c478bd9Sstevel@tonic-gate goto badcase; 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate cfgdata->begin = MALLOC(rawsz); 8227c478bd9Sstevel@tonic-gate cfgdata->end = cfgdata->nextfree = cfgdata->begin + rawsz; 8237c478bd9Sstevel@tonic-gate fmd_buf_read(hdl, 8247c478bd9Sstevel@tonic-gate inprogress, WOBUF_CFG, cfgdata->begin, rawsz); 8257c478bd9Sstevel@tonic-gate } else { 8267c478bd9Sstevel@tonic-gate cfgdata->begin = cfgdata->end = cfgdata->nextfree = NULL; 8277c478bd9Sstevel@tonic-gate } 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate config_cook(cfgdata); 830e5ba14ffSstephh fmep->config = cfgdata->cooked; 831e5ba14ffSstephh config_free(cfgdata); 832b5016cbbSstephh out(O_ALTFP|O_STAMP, "config_restore added %d bytes", 833b5016cbbSstephh alloc_total() - init_size); 834b5016cbbSstephh 835e5ba14ffSstephh if ((fmep->eventtree = itree_create(fmep->config)) == NULL) { 8367c478bd9Sstevel@tonic-gate /* case not properly saved or irretrievable */ 8377c478bd9Sstevel@tonic-gate out(O_ALTFP, "restart_fme: NULL instance tree"); 83832d4e834STarik Soydan Undiag_reason = UD_VAL_INSTFAIL; 8397c478bd9Sstevel@tonic-gate goto badcase; 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate itree_ptree(O_ALTFP|O_VERB2, fmep->eventtree); 8437c478bd9Sstevel@tonic-gate 844b5016cbbSstephh if (reconstitute_observations(fmep) != 0) 8457c478bd9Sstevel@tonic-gate goto badcase; 8467c478bd9Sstevel@tonic-gate 847b5016cbbSstephh out(O_ALTFP|O_NONL, "FME %d replay observations: ", fmep->id); 848b5016cbbSstephh for (ep = fmep->observations; ep; ep = ep->observations) { 849b5016cbbSstephh out(O_ALTFP|O_NONL, " "); 850b5016cbbSstephh itree_pevent_brief(O_ALTFP|O_NONL, ep); 8517c478bd9Sstevel@tonic-gate } 852b5016cbbSstephh out(O_ALTFP, NULL); 8537c478bd9Sstevel@tonic-gate 8540cc1f05eSjrutt Open_fme_count++; 8550cc1f05eSjrutt 8567c478bd9Sstevel@tonic-gate /* give the diagnosis algorithm a shot at the new FME state */ 8579f8ca725Sstephh fme_eval(fmep, fmep->e0r); 8587c478bd9Sstevel@tonic-gate return; 8597c478bd9Sstevel@tonic-gate 8607c478bd9Sstevel@tonic-gate badcase: 8617c478bd9Sstevel@tonic-gate if (fmep->eventtree != NULL) 8627c478bd9Sstevel@tonic-gate itree_free(fmep->eventtree); 863e5ba14ffSstephh if (fmep->config) 864e5ba14ffSstephh structconfig_free(fmep->config); 8657c478bd9Sstevel@tonic-gate destroy_fme_bufs(fmep); 8667c478bd9Sstevel@tonic-gate FREE(fmep); 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 8697c478bd9Sstevel@tonic-gate * Since we're unable to restart the case, add it to the undiagable 8707c478bd9Sstevel@tonic-gate * list and solve and close it as appropriate. 8717c478bd9Sstevel@tonic-gate */ 8727c478bd9Sstevel@tonic-gate bad = MALLOC(sizeof (struct case_list)); 8737c478bd9Sstevel@tonic-gate bad->next = NULL; 8747c478bd9Sstevel@tonic-gate 8757c478bd9Sstevel@tonic-gate if (Undiagablecaselist != NULL) 8767c478bd9Sstevel@tonic-gate bad->next = Undiagablecaselist; 8777c478bd9Sstevel@tonic-gate Undiagablecaselist = bad; 8787c478bd9Sstevel@tonic-gate bad->fmcase = inprogress; 8797c478bd9Sstevel@tonic-gate 8809f8ca725Sstephh out(O_ALTFP|O_NONL, "[case %s (unable to restart), ", 8817c478bd9Sstevel@tonic-gate fmd_case_uuid(hdl, bad->fmcase)); 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate if (fmd_case_solved(hdl, bad->fmcase)) { 8849f8ca725Sstephh out(O_ALTFP|O_NONL, "already solved, "); 8857c478bd9Sstevel@tonic-gate } else { 8869f8ca725Sstephh out(O_ALTFP|O_NONL, "solving, "); 88732d4e834STarik Soydan defect = fmd_nvl_create_fault(hdl, 88832d4e834STarik Soydan undiag_2defect_str(Undiag_reason), 100, NULL, NULL, NULL); 889705e9f42SStephen Hanson reason = undiag_2reason_str(Undiag_reason, NULL); 890705e9f42SStephen Hanson (void) nvlist_add_string(defect, UNDIAG_REASON, reason); 891705e9f42SStephen Hanson FREE(reason); 8927c478bd9Sstevel@tonic-gate fmd_case_add_suspect(hdl, bad->fmcase, defect); 8937c478bd9Sstevel@tonic-gate fmd_case_solve(hdl, bad->fmcase); 89432d4e834STarik Soydan Undiag_reason = UD_VAL_UNKNOWN; 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate if (fmd_case_closed(hdl, bad->fmcase)) { 8987c478bd9Sstevel@tonic-gate out(O_ALTFP, "already closed ]"); 8997c478bd9Sstevel@tonic-gate } else { 9007c478bd9Sstevel@tonic-gate out(O_ALTFP, "closing ]"); 9017c478bd9Sstevel@tonic-gate fmd_case_close(hdl, bad->fmcase); 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate 9057aec1d6eScindi /*ARGSUSED*/ 9067aec1d6eScindi static void 9077aec1d6eScindi globals_destructor(void *left, void *right, void *arg) 9087aec1d6eScindi { 9097aec1d6eScindi struct evalue *evp = (struct evalue *)right; 9107aec1d6eScindi if (evp->t == NODEPTR) 91180ab886dSwesolows tree_free((struct node *)(uintptr_t)evp->v); 912837416c3Scy evp->v = (uintptr_t)NULL; 9137aec1d6eScindi FREE(evp); 9147aec1d6eScindi } 9157aec1d6eScindi 9167c478bd9Sstevel@tonic-gate void 9177c478bd9Sstevel@tonic-gate destroy_fme(struct fme *f) 9187c478bd9Sstevel@tonic-gate { 9197c478bd9Sstevel@tonic-gate stats_delete(f->Rcount); 9207c478bd9Sstevel@tonic-gate stats_delete(f->Hcallcount); 9217c478bd9Sstevel@tonic-gate stats_delete(f->Rcallcount); 9227c478bd9Sstevel@tonic-gate stats_delete(f->Ccallcount); 9237c478bd9Sstevel@tonic-gate stats_delete(f->Ecallcount); 9247c478bd9Sstevel@tonic-gate stats_delete(f->Tcallcount); 9257c478bd9Sstevel@tonic-gate stats_delete(f->Marrowcount); 9267c478bd9Sstevel@tonic-gate stats_delete(f->diags); 9277c478bd9Sstevel@tonic-gate 9289f8ca725Sstephh if (f->eventtree != NULL) 9299f8ca725Sstephh itree_free(f->eventtree); 930e5ba14ffSstephh if (f->config) 931e5ba14ffSstephh structconfig_free(f->config); 9327aec1d6eScindi lut_free(f->globals, globals_destructor, NULL); 9337c478bd9Sstevel@tonic-gate FREE(f); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate static const char * 9377c478bd9Sstevel@tonic-gate fme_state2str(enum fme_state s) 9387c478bd9Sstevel@tonic-gate { 9397c478bd9Sstevel@tonic-gate switch (s) { 9407c478bd9Sstevel@tonic-gate case FME_NOTHING: return ("NOTHING"); 9417c478bd9Sstevel@tonic-gate case FME_WAIT: return ("WAIT"); 9427c478bd9Sstevel@tonic-gate case FME_CREDIBLE: return ("CREDIBLE"); 9437c478bd9Sstevel@tonic-gate case FME_DISPROVED: return ("DISPROVED"); 9447aec1d6eScindi case FME_DEFERRED: return ("DEFERRED"); 9457c478bd9Sstevel@tonic-gate default: return ("UNKNOWN"); 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate 9497c478bd9Sstevel@tonic-gate static int 9507c478bd9Sstevel@tonic-gate is_problem(enum nametype t) 9517c478bd9Sstevel@tonic-gate { 9527c478bd9Sstevel@tonic-gate return (t == N_FAULT || t == N_DEFECT || t == N_UPSET); 9537c478bd9Sstevel@tonic-gate } 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate static int 9567c478bd9Sstevel@tonic-gate is_defect(enum nametype t) 9577c478bd9Sstevel@tonic-gate { 9587c478bd9Sstevel@tonic-gate return (t == N_DEFECT); 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate static int 9627c478bd9Sstevel@tonic-gate is_upset(enum nametype t) 9637c478bd9Sstevel@tonic-gate { 9647c478bd9Sstevel@tonic-gate return (t == N_UPSET); 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate static void 9687c478bd9Sstevel@tonic-gate fme_print(int flags, struct fme *fmep) 9697c478bd9Sstevel@tonic-gate { 9707c478bd9Sstevel@tonic-gate struct event *ep; 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate out(flags, "Fault Management Exercise %d", fmep->id); 9737c478bd9Sstevel@tonic-gate out(flags, "\t State: %s", fme_state2str(fmep->state)); 9747c478bd9Sstevel@tonic-gate out(flags|O_NONL, "\t Start time: "); 9757c478bd9Sstevel@tonic-gate ptree_timeval(flags|O_NONL, &fmep->ull); 9767c478bd9Sstevel@tonic-gate out(flags, NULL); 9777c478bd9Sstevel@tonic-gate if (fmep->wull) { 9787c478bd9Sstevel@tonic-gate out(flags|O_NONL, "\t Wait time: "); 9797c478bd9Sstevel@tonic-gate ptree_timeval(flags|O_NONL, &fmep->wull); 9807c478bd9Sstevel@tonic-gate out(flags, NULL); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate out(flags|O_NONL, "\t E0: "); 9837c478bd9Sstevel@tonic-gate if (fmep->e0) 9847c478bd9Sstevel@tonic-gate itree_pevent_brief(flags|O_NONL, fmep->e0); 9857c478bd9Sstevel@tonic-gate else 9867c478bd9Sstevel@tonic-gate out(flags|O_NONL, "NULL"); 9877c478bd9Sstevel@tonic-gate out(flags, NULL); 9887c478bd9Sstevel@tonic-gate out(flags|O_NONL, "\tObservations:"); 9897c478bd9Sstevel@tonic-gate for (ep = fmep->observations; ep; ep = ep->observations) { 9907c478bd9Sstevel@tonic-gate out(flags|O_NONL, " "); 9917c478bd9Sstevel@tonic-gate itree_pevent_brief(flags|O_NONL, ep); 9927c478bd9Sstevel@tonic-gate } 9937c478bd9Sstevel@tonic-gate out(flags, NULL); 9947c478bd9Sstevel@tonic-gate out(flags|O_NONL, "\tSuspect list:"); 9957c478bd9Sstevel@tonic-gate for (ep = fmep->suspects; ep; ep = ep->suspects) { 9967c478bd9Sstevel@tonic-gate out(flags|O_NONL, " "); 9977c478bd9Sstevel@tonic-gate itree_pevent_brief(flags|O_NONL, ep); 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate out(flags, NULL); 10009f8ca725Sstephh if (fmep->eventtree != NULL) { 10019f8ca725Sstephh out(flags|O_VERB2, "\t Tree:"); 10029f8ca725Sstephh itree_ptree(flags|O_VERB2, fmep->eventtree); 10039f8ca725Sstephh } 10047c478bd9Sstevel@tonic-gate } 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate static struct node * 10077c478bd9Sstevel@tonic-gate pathstring2epnamenp(char *path) 10087c478bd9Sstevel@tonic-gate { 10097c478bd9Sstevel@tonic-gate char *sep = "/"; 10107c478bd9Sstevel@tonic-gate struct node *ret; 10117c478bd9Sstevel@tonic-gate char *ptr; 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate if ((ptr = strtok(path, sep)) == NULL) 10147c478bd9Sstevel@tonic-gate out(O_DIE, "pathstring2epnamenp: invalid empty class"); 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate ret = tree_iname(stable(ptr), NULL, 0); 10177c478bd9Sstevel@tonic-gate 10187c478bd9Sstevel@tonic-gate while ((ptr = strtok(NULL, sep)) != NULL) 10197c478bd9Sstevel@tonic-gate ret = tree_name_append(ret, 10207c478bd9Sstevel@tonic-gate tree_iname(stable(ptr), NULL, 0)); 10217c478bd9Sstevel@tonic-gate 10227c478bd9Sstevel@tonic-gate return (ret); 10237c478bd9Sstevel@tonic-gate } 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate /* 10267c478bd9Sstevel@tonic-gate * for a given upset sp, increment the corresponding SERD engine. if the 10277c478bd9Sstevel@tonic-gate * SERD engine trips, return the ename and ipp of the resulting ereport. 10287c478bd9Sstevel@tonic-gate * returns true if engine tripped and *enamep and *ippp were filled in. 10297c478bd9Sstevel@tonic-gate */ 10307c478bd9Sstevel@tonic-gate static int 10317aec1d6eScindi serd_eval(struct fme *fmep, fmd_hdl_t *hdl, fmd_event_t *ffep, 10327aec1d6eScindi fmd_case_t *fmcase, struct event *sp, const char **enamep, 10337aec1d6eScindi const struct ipath **ippp) 10347c478bd9Sstevel@tonic-gate { 10357c478bd9Sstevel@tonic-gate struct node *serdinst; 10367c478bd9Sstevel@tonic-gate char *serdname; 1037049e2ea4SScott Davenport char *serdresource; 10388e7248e5SStephen Hanson char *serdclass; 10397aec1d6eScindi struct node *nid; 1040b5016cbbSstephh struct serd_entry *newentp; 1041049e2ea4SScott Davenport int i, serdn = -1, serdincrement = 1, len = 0; 10428e7248e5SStephen Hanson char *serdsuffix = NULL, *serdt = NULL; 1043b7d3956bSstephh struct evalue *ep; 10447c478bd9Sstevel@tonic-gate 10457c478bd9Sstevel@tonic-gate ASSERT(sp->t == N_UPSET); 10467c478bd9Sstevel@tonic-gate ASSERT(ffep != NULL); 10477c478bd9Sstevel@tonic-gate 1048b7d3956bSstephh if ((ep = (struct evalue *)lut_lookup(sp->serdprops, 1049b7d3956bSstephh (void *)"n", (lut_cmp)strcmp)) != NULL) { 1050b7d3956bSstephh ASSERT(ep->t == UINT64); 1051b7d3956bSstephh serdn = (int)ep->v; 1052b7d3956bSstephh } 1053b7d3956bSstephh if ((ep = (struct evalue *)lut_lookup(sp->serdprops, 1054b7d3956bSstephh (void *)"t", (lut_cmp)strcmp)) != NULL) { 1055b7d3956bSstephh ASSERT(ep->t == STRING); 1056b7d3956bSstephh serdt = (char *)(uintptr_t)ep->v; 1057b7d3956bSstephh } 1058b7d3956bSstephh if ((ep = (struct evalue *)lut_lookup(sp->serdprops, 1059b7d3956bSstephh (void *)"suffix", (lut_cmp)strcmp)) != NULL) { 1060b7d3956bSstephh ASSERT(ep->t == STRING); 1061b7d3956bSstephh serdsuffix = (char *)(uintptr_t)ep->v; 1062b7d3956bSstephh } 1063b7d3956bSstephh if ((ep = (struct evalue *)lut_lookup(sp->serdprops, 1064b7d3956bSstephh (void *)"increment", (lut_cmp)strcmp)) != NULL) { 1065b7d3956bSstephh ASSERT(ep->t == UINT64); 1066b7d3956bSstephh serdincrement = (int)ep->v; 1067b7d3956bSstephh } 1068b7d3956bSstephh 10697c478bd9Sstevel@tonic-gate /* 10707c478bd9Sstevel@tonic-gate * obtain instanced SERD engine from the upset sp. from this 10717c478bd9Sstevel@tonic-gate * derive serdname, the string used to identify the SERD engine. 10727c478bd9Sstevel@tonic-gate */ 10737c478bd9Sstevel@tonic-gate serdinst = eventprop_lookup(sp, L_engine); 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate if (serdinst == NULL) 1076b7d3956bSstephh return (-1); 10777c478bd9Sstevel@tonic-gate 10788e7248e5SStephen Hanson len = strlen(serdinst->u.stmt.np->u.event.ename->u.name.s) + 1; 1079049e2ea4SScott Davenport if (serdsuffix != NULL) 1080049e2ea4SScott Davenport len += strlen(serdsuffix); 10818e7248e5SStephen Hanson serdclass = MALLOC(len); 10828e7248e5SStephen Hanson if (serdsuffix != NULL) 10838e7248e5SStephen Hanson (void) snprintf(serdclass, len, "%s%s", 10848e7248e5SStephen Hanson serdinst->u.stmt.np->u.event.ename->u.name.s, serdsuffix); 10858e7248e5SStephen Hanson else 10868e7248e5SStephen Hanson (void) snprintf(serdclass, len, "%s", 10878e7248e5SStephen Hanson serdinst->u.stmt.np->u.event.ename->u.name.s); 10888e7248e5SStephen Hanson serdresource = ipath2str(NULL, 10898e7248e5SStephen Hanson ipath(serdinst->u.stmt.np->u.event.epname)); 10908e7248e5SStephen Hanson len += strlen(serdresource) + 1; 10918e7248e5SStephen Hanson serdname = MALLOC(len); 10928e7248e5SStephen Hanson (void) snprintf(serdname, len, "%s@%s", serdclass, serdresource); 1093049e2ea4SScott Davenport FREE(serdresource); 1094b7d3956bSstephh 10957aec1d6eScindi /* handle serd engine "id" property, if there is one */ 10967aec1d6eScindi if ((nid = 10977aec1d6eScindi lut_lookup(serdinst->u.stmt.lutp, (void *)L_id, NULL)) != NULL) { 10987aec1d6eScindi struct evalue *gval; 10997aec1d6eScindi char suffixbuf[200]; 11007aec1d6eScindi char *suffix; 11017aec1d6eScindi char *nserdname; 11027aec1d6eScindi size_t nname; 11037aec1d6eScindi 11047aec1d6eScindi out(O_ALTFP|O_NONL, "serd \"%s\" id: ", serdname); 11057aec1d6eScindi ptree_name_iter(O_ALTFP|O_NONL, nid); 11067aec1d6eScindi 11077aec1d6eScindi ASSERTinfo(nid->t == T_GLOBID, ptree_nodetype2str(nid->t)); 11087aec1d6eScindi 11097aec1d6eScindi if ((gval = lut_lookup(fmep->globals, 11107aec1d6eScindi (void *)nid->u.globid.s, NULL)) == NULL) { 11117aec1d6eScindi out(O_ALTFP, " undefined"); 11127aec1d6eScindi } else if (gval->t == UINT64) { 11137aec1d6eScindi out(O_ALTFP, " %llu", gval->v); 11147aec1d6eScindi (void) sprintf(suffixbuf, "%llu", gval->v); 11157aec1d6eScindi suffix = suffixbuf; 11167aec1d6eScindi } else { 111780ab886dSwesolows out(O_ALTFP, " \"%s\"", (char *)(uintptr_t)gval->v); 111880ab886dSwesolows suffix = (char *)(uintptr_t)gval->v; 11197aec1d6eScindi } 11207aec1d6eScindi 11217aec1d6eScindi nname = strlen(serdname) + strlen(suffix) + 2; 11227aec1d6eScindi nserdname = MALLOC(nname); 11237aec1d6eScindi (void) snprintf(nserdname, nname, "%s:%s", serdname, suffix); 11247aec1d6eScindi FREE(serdname); 11257aec1d6eScindi serdname = nserdname; 11267aec1d6eScindi } 11277aec1d6eScindi 1128b7d3956bSstephh /* 1129b7d3956bSstephh * if the engine is empty, and we have an override for n/t then 1130b7d3956bSstephh * destroy and recreate it. 1131b7d3956bSstephh */ 1132b7d3956bSstephh if ((serdn != -1 || serdt != NULL) && fmd_serd_exists(hdl, serdname) && 1133b7d3956bSstephh fmd_serd_empty(hdl, serdname)) 1134b7d3956bSstephh fmd_serd_destroy(hdl, serdname); 1135b7d3956bSstephh 11367c478bd9Sstevel@tonic-gate if (!fmd_serd_exists(hdl, serdname)) { 11377c478bd9Sstevel@tonic-gate struct node *nN, *nT; 1138e5ba14ffSstephh const char *s; 1139e5ba14ffSstephh struct node *nodep; 1140e5ba14ffSstephh struct config *cp; 1141e5ba14ffSstephh char *path; 1142e5ba14ffSstephh uint_t nval; 1143e5ba14ffSstephh hrtime_t tval; 1144e5ba14ffSstephh int i; 1145e5ba14ffSstephh char *ptr; 1146e5ba14ffSstephh int got_n_override = 0, got_t_override = 0; 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate /* no SERD engine yet, so create it */ 1149e5ba14ffSstephh nodep = serdinst->u.stmt.np->u.event.epname; 1150e5ba14ffSstephh path = ipath2str(NULL, ipath(nodep)); 1151e5ba14ffSstephh cp = config_lookup(fmep->config, path, 0); 1152e5ba14ffSstephh FREE((void *)path); 1153e5ba14ffSstephh 1154e5ba14ffSstephh /* 1155e5ba14ffSstephh * We allow serd paramaters to be overridden, either from 1156e5ba14ffSstephh * eft.conf file values (if Serd_Override is set) or from 1157e5ba14ffSstephh * driver properties (for "serd.io.device" engines). 1158e5ba14ffSstephh */ 1159e5ba14ffSstephh if (Serd_Override != NULL) { 1160e5ba14ffSstephh char *save_ptr, *ptr1, *ptr2, *ptr3; 1161e5ba14ffSstephh ptr3 = save_ptr = STRDUP(Serd_Override); 1162e5ba14ffSstephh while (*ptr3 != '\0') { 1163e5ba14ffSstephh ptr1 = strchr(ptr3, ','); 1164e5ba14ffSstephh *ptr1 = '\0'; 11658e7248e5SStephen Hanson if (strcmp(ptr3, serdclass) == 0) { 1166e5ba14ffSstephh ptr2 = strchr(ptr1 + 1, ','); 1167e5ba14ffSstephh *ptr2 = '\0'; 1168e5ba14ffSstephh nval = atoi(ptr1 + 1); 1169e5ba14ffSstephh out(O_ALTFP, "serd override %s_n %d", 11708e7248e5SStephen Hanson serdclass, nval); 1171e5ba14ffSstephh ptr3 = strchr(ptr2 + 1, ' '); 1172e5ba14ffSstephh if (ptr3) 1173e5ba14ffSstephh *ptr3 = '\0'; 1174e5ba14ffSstephh ptr = STRDUP(ptr2 + 1); 1175e5ba14ffSstephh out(O_ALTFP, "serd override %s_t %s", 11768e7248e5SStephen Hanson serdclass, ptr); 1177e5ba14ffSstephh got_n_override = 1; 1178e5ba14ffSstephh got_t_override = 1; 1179e5ba14ffSstephh break; 1180e5ba14ffSstephh } else { 1181e5ba14ffSstephh ptr2 = strchr(ptr1 + 1, ','); 1182e5ba14ffSstephh ptr3 = strchr(ptr2 + 1, ' '); 1183e5ba14ffSstephh if (ptr3 == NULL) 1184e5ba14ffSstephh break; 1185e5ba14ffSstephh } 1186e5ba14ffSstephh ptr3++; 1187e5ba14ffSstephh } 1188e5ba14ffSstephh FREE(save_ptr); 1189e5ba14ffSstephh } 11907c478bd9Sstevel@tonic-gate 1191e5ba14ffSstephh if (cp && got_n_override == 0) { 1192e5ba14ffSstephh /* 11938e7248e5SStephen Hanson * convert serd engine class into property name 1194e5ba14ffSstephh */ 11958e7248e5SStephen Hanson char *prop_name = MALLOC(strlen(serdclass) + 3); 11968e7248e5SStephen Hanson for (i = 0; i < strlen(serdclass); i++) { 11978e7248e5SStephen Hanson if (serdclass[i] == '.') 11988e7248e5SStephen Hanson prop_name[i] = '_'; 1199e5ba14ffSstephh else 12008e7248e5SStephen Hanson prop_name[i] = serdclass[i]; 1201e5ba14ffSstephh } 12028e7248e5SStephen Hanson prop_name[i++] = '_'; 12038e7248e5SStephen Hanson prop_name[i++] = 'n'; 12048e7248e5SStephen Hanson prop_name[i] = '\0'; 12058e7248e5SStephen Hanson if (s = config_getprop(cp, prop_name)) { 1206e5ba14ffSstephh nval = atoi(s); 12078e7248e5SStephen Hanson out(O_ALTFP, "serd override %s_n %s", 12088e7248e5SStephen Hanson serdclass, s); 1209e5ba14ffSstephh got_n_override = 1; 1210e5ba14ffSstephh } 12118e7248e5SStephen Hanson prop_name[i - 1] = 't'; 12128e7248e5SStephen Hanson if (s = config_getprop(cp, prop_name)) { 1213e5ba14ffSstephh ptr = STRDUP(s); 12148e7248e5SStephen Hanson out(O_ALTFP, "serd override %s_t %s", 12158e7248e5SStephen Hanson serdclass, s); 1216e5ba14ffSstephh got_t_override = 1; 1217e5ba14ffSstephh } 12188e7248e5SStephen Hanson FREE(prop_name); 1219e5ba14ffSstephh } 12207c478bd9Sstevel@tonic-gate 1221b7d3956bSstephh if (serdn != -1 && got_n_override == 0) { 1222b7d3956bSstephh nval = serdn; 12238e7248e5SStephen Hanson out(O_ALTFP, "serd override %s_n %d", serdclass, serdn); 1224b7d3956bSstephh got_n_override = 1; 1225b7d3956bSstephh } 1226b7d3956bSstephh if (serdt != NULL && got_t_override == 0) { 1227b7d3956bSstephh ptr = STRDUP(serdt); 12288e7248e5SStephen Hanson out(O_ALTFP, "serd override %s_t %s", serdclass, serdt); 1229b7d3956bSstephh got_t_override = 1; 1230b7d3956bSstephh } 1231b7d3956bSstephh 1232e5ba14ffSstephh if (!got_n_override) { 1233e5ba14ffSstephh nN = lut_lookup(serdinst->u.stmt.lutp, (void *)L_N, 1234e5ba14ffSstephh NULL); 1235e5ba14ffSstephh ASSERT(nN->t == T_NUM); 1236e5ba14ffSstephh nval = (uint_t)nN->u.ull; 1237e5ba14ffSstephh } 1238e5ba14ffSstephh if (!got_t_override) { 1239e5ba14ffSstephh nT = lut_lookup(serdinst->u.stmt.lutp, (void *)L_T, 1240e5ba14ffSstephh NULL); 1241e5ba14ffSstephh ASSERT(nT->t == T_TIMEVAL); 1242e5ba14ffSstephh tval = (hrtime_t)nT->u.ull; 1243e5ba14ffSstephh } else { 1244e5ba14ffSstephh const unsigned long long *ullp; 1245e5ba14ffSstephh const char *suffix; 1246e5ba14ffSstephh int len; 1247e5ba14ffSstephh 1248e5ba14ffSstephh len = strspn(ptr, "0123456789"); 1249e5ba14ffSstephh suffix = stable(&ptr[len]); 1250e5ba14ffSstephh ullp = (unsigned long long *)lut_lookup(Timesuffixlut, 1251e5ba14ffSstephh (void *)suffix, NULL); 1252e5ba14ffSstephh ptr[len] = '\0'; 1253b7d3956bSstephh tval = strtoull(ptr, NULL, 0) * (ullp ? *ullp : 1ll); 1254e5ba14ffSstephh FREE(ptr); 1255e5ba14ffSstephh } 1256e5ba14ffSstephh fmd_serd_create(hdl, serdname, nval, tval); 12577c478bd9Sstevel@tonic-gate } 12587c478bd9Sstevel@tonic-gate 1259b5016cbbSstephh newentp = MALLOC(sizeof (*newentp)); 12608e7248e5SStephen Hanson newentp->ename = stable(serdclass); 12618e7248e5SStephen Hanson FREE(serdclass); 1262b5016cbbSstephh newentp->ipath = ipath(serdinst->u.stmt.np->u.event.epname); 1263b5016cbbSstephh newentp->hdl = hdl; 1264b5016cbbSstephh if (lut_lookup(SerdEngines, newentp, (lut_cmp)serd_cmp) == NULL) { 1265b5016cbbSstephh SerdEngines = lut_add(SerdEngines, (void *)newentp, 1266e5ba14ffSstephh (void *)newentp, (lut_cmp)serd_cmp); 1267b5016cbbSstephh Serd_need_save = 1; 1268b5016cbbSstephh serd_save(); 1269b5016cbbSstephh } else { 1270b5016cbbSstephh FREE(newentp); 1271b5016cbbSstephh } 1272b5016cbbSstephh 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate /* 12757c478bd9Sstevel@tonic-gate * increment SERD engine. if engine fires, reset serd 1276b7d3956bSstephh * engine and return trip_strcode if required. 12777c478bd9Sstevel@tonic-gate */ 1278b7d3956bSstephh for (i = 0; i < serdincrement; i++) { 1279b7d3956bSstephh if (fmd_serd_record(hdl, serdname, ffep)) { 1280b7d3956bSstephh fmd_case_add_serd(hdl, fmcase, serdname); 1281b7d3956bSstephh fmd_serd_reset(hdl, serdname); 1282b7d3956bSstephh 1283b7d3956bSstephh if (ippp) { 1284b7d3956bSstephh struct node *tripinst = 1285b7d3956bSstephh lut_lookup(serdinst->u.stmt.lutp, 1286b7d3956bSstephh (void *)L_trip, NULL); 1287b7d3956bSstephh ASSERT(tripinst != NULL); 1288b7d3956bSstephh *enamep = tripinst->u.event.ename->u.name.s; 1289b7d3956bSstephh *ippp = ipath(tripinst->u.event.epname); 1290b7d3956bSstephh out(O_ALTFP|O_NONL, 1291b7d3956bSstephh "[engine fired: %s, sending: ", serdname); 1292b7d3956bSstephh ipath_print(O_ALTFP|O_NONL, *enamep, *ippp); 1293b7d3956bSstephh out(O_ALTFP, "]"); 1294b7d3956bSstephh } else { 1295b7d3956bSstephh out(O_ALTFP, "[engine fired: %s, no trip]", 1296b7d3956bSstephh serdname); 1297b7d3956bSstephh } 1298b7d3956bSstephh FREE(serdname); 1299b7d3956bSstephh return (1); 1300b7d3956bSstephh } 13017c478bd9Sstevel@tonic-gate } 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate FREE(serdname); 13047c478bd9Sstevel@tonic-gate return (0); 13057c478bd9Sstevel@tonic-gate } 13067c478bd9Sstevel@tonic-gate 13077c478bd9Sstevel@tonic-gate /* 13087c478bd9Sstevel@tonic-gate * search a suspect list for upsets. feed each upset to serd_eval() and 13097c478bd9Sstevel@tonic-gate * build up tripped[], an array of ereports produced by the firing of 13107c478bd9Sstevel@tonic-gate * any SERD engines. then feed each ereport back into 13117c478bd9Sstevel@tonic-gate * fme_receive_report(). 13127c478bd9Sstevel@tonic-gate * 13137c478bd9Sstevel@tonic-gate * returns ntrip, the number of these ereports produced. 13147c478bd9Sstevel@tonic-gate */ 13157c478bd9Sstevel@tonic-gate static int 13167c478bd9Sstevel@tonic-gate upsets_eval(struct fme *fmep, fmd_event_t *ffep) 13177c478bd9Sstevel@tonic-gate { 13187c478bd9Sstevel@tonic-gate /* we build an array of tripped ereports that we send ourselves */ 13197c478bd9Sstevel@tonic-gate struct { 13207c478bd9Sstevel@tonic-gate const char *ename; 13217c478bd9Sstevel@tonic-gate const struct ipath *ipp; 13227c478bd9Sstevel@tonic-gate } *tripped; 13237c478bd9Sstevel@tonic-gate struct event *sp; 13247c478bd9Sstevel@tonic-gate int ntrip, nupset, i; 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate /* 13277c478bd9Sstevel@tonic-gate * count the number of upsets to determine the upper limit on 13287c478bd9Sstevel@tonic-gate * expected trip ereport strings. remember that one upset can 13297c478bd9Sstevel@tonic-gate * lead to at most one ereport. 13307c478bd9Sstevel@tonic-gate */ 13317c478bd9Sstevel@tonic-gate nupset = 0; 13327c478bd9Sstevel@tonic-gate for (sp = fmep->suspects; sp; sp = sp->suspects) { 13337c478bd9Sstevel@tonic-gate if (sp->t == N_UPSET) 13347c478bd9Sstevel@tonic-gate nupset++; 13357c478bd9Sstevel@tonic-gate } 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate if (nupset == 0) 13387c478bd9Sstevel@tonic-gate return (0); 13397c478bd9Sstevel@tonic-gate 13407c478bd9Sstevel@tonic-gate /* 13417c478bd9Sstevel@tonic-gate * get to this point if we have upsets and expect some trip 13427c478bd9Sstevel@tonic-gate * ereports 13437c478bd9Sstevel@tonic-gate */ 13447c478bd9Sstevel@tonic-gate tripped = alloca(sizeof (*tripped) * nupset); 13457c478bd9Sstevel@tonic-gate bzero((void *)tripped, sizeof (*tripped) * nupset); 13467c478bd9Sstevel@tonic-gate 13477c478bd9Sstevel@tonic-gate ntrip = 0; 13487c478bd9Sstevel@tonic-gate for (sp = fmep->suspects; sp; sp = sp->suspects) 13493e8d8e18Sdb if (sp->t == N_UPSET && 13507aec1d6eScindi serd_eval(fmep, fmep->hdl, ffep, fmep->fmcase, sp, 1351b7d3956bSstephh &tripped[ntrip].ename, &tripped[ntrip].ipp) == 1) 13527c478bd9Sstevel@tonic-gate ntrip++; 13537c478bd9Sstevel@tonic-gate 135427134bdaSstephh for (i = 0; i < ntrip; i++) { 135527134bdaSstephh struct event *ep, *nep; 135627134bdaSstephh struct fme *nfmep; 135727134bdaSstephh fmd_case_t *fmcase; 135827134bdaSstephh const struct ipath *ipp; 135927134bdaSstephh const char *eventstring; 136027134bdaSstephh int prev_verbose; 136127134bdaSstephh unsigned long long my_delay = TIMEVAL_EVENTUALLY; 136227134bdaSstephh enum fme_state state; 136327134bdaSstephh 136427134bdaSstephh /* 136527134bdaSstephh * First try and evaluate a case with the trip ereport plus 136627134bdaSstephh * all the other ereports that cause the trip. If that fails 136727134bdaSstephh * to evaluate then try again with just this ereport on its own. 136827134bdaSstephh */ 136927134bdaSstephh out(O_ALTFP|O_NONL, "fme_receive_report_serd: "); 137027134bdaSstephh ipath_print(O_ALTFP|O_NONL, tripped[i].ename, tripped[i].ipp); 137127134bdaSstephh out(O_ALTFP|O_STAMP, NULL); 137227134bdaSstephh ep = fmep->e0; 137327134bdaSstephh eventstring = ep->enode->u.event.ename->u.name.s; 137427134bdaSstephh ipp = ep->ipp; 137527134bdaSstephh 137627134bdaSstephh /* 137727134bdaSstephh * create a duplicate fme and case 137827134bdaSstephh */ 137927134bdaSstephh fmcase = fmd_case_open(fmep->hdl, NULL); 138027134bdaSstephh out(O_ALTFP|O_NONL, "duplicate fme for event ["); 138127134bdaSstephh ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 138227134bdaSstephh out(O_ALTFP, " ]"); 1383705e9f42SStephen Hanson 138427134bdaSstephh if ((nfmep = newfme(eventstring, ipp, fmep->hdl, 1385705e9f42SStephen Hanson fmcase, ffep, ep->nvp)) == NULL) { 138627134bdaSstephh out(O_ALTFP|O_NONL, "["); 138727134bdaSstephh ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 138827134bdaSstephh out(O_ALTFP, " CANNOT DIAGNOSE]"); 138927134bdaSstephh continue; 139027134bdaSstephh } 1391705e9f42SStephen Hanson 139227134bdaSstephh Open_fme_count++; 139327134bdaSstephh nfmep->pull = fmep->pull; 139427134bdaSstephh init_fme_bufs(nfmep); 139527134bdaSstephh out(O_ALTFP|O_NONL, "["); 139627134bdaSstephh ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 139727134bdaSstephh out(O_ALTFP, " created FME%d, case %s]", nfmep->id, 139827134bdaSstephh fmd_case_uuid(nfmep->hdl, nfmep->fmcase)); 139927134bdaSstephh if (ffep) { 140027134bdaSstephh fmd_case_setprincipal(nfmep->hdl, nfmep->fmcase, ffep); 1401b7d3956bSstephh fmd_case_add_ereport(nfmep->hdl, nfmep->fmcase, ffep); 140227134bdaSstephh nfmep->e0r = ffep; 140327134bdaSstephh } 140427134bdaSstephh 140527134bdaSstephh /* 140627134bdaSstephh * add the original ereports 140727134bdaSstephh */ 140827134bdaSstephh for (ep = fmep->observations; ep; ep = ep->observations) { 140927134bdaSstephh eventstring = ep->enode->u.event.ename->u.name.s; 141027134bdaSstephh ipp = ep->ipp; 141127134bdaSstephh out(O_ALTFP|O_NONL, "adding event ["); 141227134bdaSstephh ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 141327134bdaSstephh out(O_ALTFP, " ]"); 141427134bdaSstephh nep = itree_lookup(nfmep->eventtree, eventstring, ipp); 141527134bdaSstephh if (nep->count++ == 0) { 141627134bdaSstephh nep->observations = nfmep->observations; 141727134bdaSstephh nfmep->observations = nep; 141827134bdaSstephh serialize_observation(nfmep, eventstring, ipp); 141927134bdaSstephh nep->nvp = evnv_dupnvl(ep->nvp); 142027134bdaSstephh } 1421b7d3956bSstephh if (ep->ffep && ep->ffep != ffep) 142227134bdaSstephh fmd_case_add_ereport(nfmep->hdl, nfmep->fmcase, 1423b7d3956bSstephh ep->ffep); 142427134bdaSstephh stats_counter_bump(nfmep->Rcount); 142527134bdaSstephh } 142627134bdaSstephh 142727134bdaSstephh /* 142827134bdaSstephh * add the serd trigger ereport 142927134bdaSstephh */ 143027134bdaSstephh if ((ep = itree_lookup(nfmep->eventtree, tripped[i].ename, 143127134bdaSstephh tripped[i].ipp)) == NULL) { 143227134bdaSstephh /* 143327134bdaSstephh * The trigger ereport is not in the instance tree. It 143427134bdaSstephh * was presumably removed by prune_propagations() as 143527134bdaSstephh * this combination of events is not present in the 143627134bdaSstephh * rules. 143727134bdaSstephh */ 143827134bdaSstephh out(O_ALTFP, "upsets_eval: e0 not in instance tree"); 143932d4e834STarik Soydan Undiag_reason = UD_VAL_BADEVENTI; 144027134bdaSstephh goto retry_lone_ereport; 144127134bdaSstephh } 144227134bdaSstephh out(O_ALTFP|O_NONL, "adding event ["); 144327134bdaSstephh ipath_print(O_ALTFP|O_NONL, tripped[i].ename, tripped[i].ipp); 144427134bdaSstephh out(O_ALTFP, " ]"); 144527134bdaSstephh nfmep->ecurrent = ep; 144627134bdaSstephh ep->nvp = NULL; 144727134bdaSstephh ep->count = 1; 144827134bdaSstephh ep->observations = nfmep->observations; 144927134bdaSstephh nfmep->observations = ep; 145027134bdaSstephh 145127134bdaSstephh /* 145227134bdaSstephh * just peek first. 145327134bdaSstephh */ 145427134bdaSstephh nfmep->peek = 1; 145527134bdaSstephh prev_verbose = Verbose; 145627134bdaSstephh if (Debug == 0) 145727134bdaSstephh Verbose = 0; 145827134bdaSstephh lut_walk(nfmep->eventtree, (lut_cb)clear_arrows, (void *)nfmep); 145927134bdaSstephh state = hypothesise(nfmep, nfmep->e0, nfmep->ull, &my_delay); 146027134bdaSstephh nfmep->peek = 0; 146127134bdaSstephh Verbose = prev_verbose; 146227134bdaSstephh if (state == FME_DISPROVED) { 146327134bdaSstephh out(O_ALTFP, "upsets_eval: hypothesis disproved"); 146432d4e834STarik Soydan Undiag_reason = UD_VAL_UNSOLVD; 146527134bdaSstephh retry_lone_ereport: 146627134bdaSstephh /* 146727134bdaSstephh * However the trigger ereport on its own might be 146827134bdaSstephh * diagnosable, so check for that. Undo the new fme 146927134bdaSstephh * and case we just created and call fme_receive_report. 147027134bdaSstephh */ 147127134bdaSstephh out(O_ALTFP|O_NONL, "["); 147227134bdaSstephh ipath_print(O_ALTFP|O_NONL, tripped[i].ename, 147327134bdaSstephh tripped[i].ipp); 147427134bdaSstephh out(O_ALTFP, " retrying with just trigger ereport]"); 147527134bdaSstephh itree_free(nfmep->eventtree); 147627134bdaSstephh nfmep->eventtree = NULL; 147727134bdaSstephh structconfig_free(nfmep->config); 147827134bdaSstephh nfmep->config = NULL; 147927134bdaSstephh destroy_fme_bufs(nfmep); 148027134bdaSstephh fmd_case_close(nfmep->hdl, nfmep->fmcase); 148127134bdaSstephh fme_receive_report(fmep->hdl, ffep, 148227134bdaSstephh tripped[i].ename, tripped[i].ipp, NULL); 148327134bdaSstephh continue; 148427134bdaSstephh } 148527134bdaSstephh 148627134bdaSstephh /* 148727134bdaSstephh * and evaluate 148827134bdaSstephh */ 148927134bdaSstephh serialize_observation(nfmep, tripped[i].ename, tripped[i].ipp); 149027134bdaSstephh fme_eval(nfmep, ffep); 149127134bdaSstephh } 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate return (ntrip); 14947c478bd9Sstevel@tonic-gate } 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate /* 14977c478bd9Sstevel@tonic-gate * fme_receive_external_report -- call when an external ereport comes in 14987c478bd9Sstevel@tonic-gate * 14997c478bd9Sstevel@tonic-gate * this routine just converts the relevant information from the ereport 15007c478bd9Sstevel@tonic-gate * into a format used internally and passes it on to fme_receive_report(). 15017c478bd9Sstevel@tonic-gate */ 15027c478bd9Sstevel@tonic-gate void 15037c478bd9Sstevel@tonic-gate fme_receive_external_report(fmd_hdl_t *hdl, fmd_event_t *ffep, nvlist_t *nvl, 1504602ca9eaScth const char *class) 15057c478bd9Sstevel@tonic-gate { 1506602ca9eaScth struct node *epnamenp; 1507602ca9eaScth fmd_case_t *fmcase; 1508602ca9eaScth const struct ipath *ipp; 1509705e9f42SStephen Hanson nvlist_t *detector = NULL; 15107c478bd9Sstevel@tonic-gate 1511602ca9eaScth class = stable(class); 1512b5016cbbSstephh 1513602ca9eaScth /* Get the component path from the ereport */ 1514602ca9eaScth epnamenp = platform_getpath(nvl); 1515602ca9eaScth 1516602ca9eaScth /* See if we ended up without a path. */ 1517602ca9eaScth if (epnamenp == NULL) { 1518602ca9eaScth /* See if class permits silent discard on unknown component. */ 1519602ca9eaScth if (lut_lookup(Ereportenames_discard, (void *)class, NULL)) { 1520602ca9eaScth out(O_ALTFP|O_VERB2, "Unable to map \"%s\" ereport " 1521602ca9eaScth "to component path, but silent discard allowed.", 1522602ca9eaScth class); 1523602ca9eaScth } else { 1524602ca9eaScth /* 1525602ca9eaScth * XFILE: Failure to find a component is bad unless 1526602ca9eaScth * 'discard_if_config_unknown=1' was specified in the 1527602ca9eaScth * ereport definition. Indicate undiagnosable. 1528602ca9eaScth */ 152932d4e834STarik Soydan Undiag_reason = UD_VAL_NOPATH; 1530602ca9eaScth fmcase = fmd_case_open(hdl, NULL); 1531705e9f42SStephen Hanson 1532705e9f42SStephen Hanson /* 1533705e9f42SStephen Hanson * We don't have a component path here (which means that 1534705e9f42SStephen Hanson * the detector was not in hc-scheme and couldn't be 1535705e9f42SStephen Hanson * converted to hc-scheme. Report the raw detector as 1536705e9f42SStephen Hanson * the suspect resource if there is one. 1537705e9f42SStephen Hanson */ 1538705e9f42SStephen Hanson (void) nvlist_lookup_nvlist(nvl, FM_EREPORT_DETECTOR, 1539705e9f42SStephen Hanson &detector); 1540705e9f42SStephen Hanson publish_undiagnosable(hdl, ffep, fmcase, detector, 1541705e9f42SStephen Hanson (char *)class); 1542602ca9eaScth } 15437c478bd9Sstevel@tonic-gate return; 15447c478bd9Sstevel@tonic-gate } 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate ipp = ipath(epnamenp); 15477c478bd9Sstevel@tonic-gate tree_free(epnamenp); 1548602ca9eaScth fme_receive_report(hdl, ffep, class, ipp, nvl); 15497c478bd9Sstevel@tonic-gate } 15507c478bd9Sstevel@tonic-gate 155108f6c065Sgavinm /*ARGSUSED*/ 155208f6c065Sgavinm void 155308f6c065Sgavinm fme_receive_repair_list(fmd_hdl_t *hdl, fmd_event_t *ffep, nvlist_t *nvl, 155408f6c065Sgavinm const char *eventstring) 155508f6c065Sgavinm { 155608f6c065Sgavinm char *uuid; 155708f6c065Sgavinm nvlist_t **nva; 155808f6c065Sgavinm uint_t nvc; 155908f6c065Sgavinm const struct ipath *ipp; 156008f6c065Sgavinm 156108f6c065Sgavinm if (nvlist_lookup_string(nvl, FM_SUSPECT_UUID, &uuid) != 0 || 156208f6c065Sgavinm nvlist_lookup_nvlist_array(nvl, FM_SUSPECT_FAULT_LIST, 156308f6c065Sgavinm &nva, &nvc) != 0) { 156408f6c065Sgavinm out(O_ALTFP, "No uuid or fault list for list.repaired event"); 156508f6c065Sgavinm return; 156608f6c065Sgavinm } 156708f6c065Sgavinm 156808f6c065Sgavinm out(O_ALTFP, "Processing list.repaired from case %s", uuid); 156908f6c065Sgavinm 157008f6c065Sgavinm while (nvc-- != 0) { 157108f6c065Sgavinm /* 1572b5016cbbSstephh * Reset any istat or serd engine associated with this path. 157308f6c065Sgavinm */ 157408f6c065Sgavinm char *path; 157508f6c065Sgavinm 157608f6c065Sgavinm if ((ipp = platform_fault2ipath(*nva++)) == NULL) 157708f6c065Sgavinm continue; 157808f6c065Sgavinm 157908f6c065Sgavinm path = ipath2str(NULL, ipp); 158008f6c065Sgavinm out(O_ALTFP, "fme_receive_repair_list: resetting state for %s", 158108f6c065Sgavinm path); 158208f6c065Sgavinm FREE(path); 158308f6c065Sgavinm 158408f6c065Sgavinm lut_walk(Istats, (lut_cb)istat_counter_reset_cb, (void *)ipp); 158508f6c065Sgavinm istat_save(); 158608f6c065Sgavinm 1587b5016cbbSstephh lut_walk(SerdEngines, (lut_cb)serd_reset_cb, (void *)ipp); 1588b5016cbbSstephh serd_save(); 158908f6c065Sgavinm } 159008f6c065Sgavinm } 159108f6c065Sgavinm 1592e5ba14ffSstephh /*ARGSUSED*/ 1593e5ba14ffSstephh void 1594e5ba14ffSstephh fme_receive_topology_change(void) 1595e5ba14ffSstephh { 1596e5ba14ffSstephh lut_walk(Istats, (lut_cb)istat_counter_topo_chg_cb, NULL); 1597e5ba14ffSstephh istat_save(); 1598e5ba14ffSstephh 1599e5ba14ffSstephh lut_walk(SerdEngines, (lut_cb)serd_topo_chg_cb, NULL); 1600e5ba14ffSstephh serd_save(); 1601e5ba14ffSstephh } 1602e5ba14ffSstephh 16037aec1d6eScindi static int mark_arrows(struct fme *fmep, struct event *ep, int mark, 160400d0963fSdilpreet unsigned long long at_latest_by, unsigned long long *pdelay, int keep); 16057aec1d6eScindi 16067aec1d6eScindi /* ARGSUSED */ 16077aec1d6eScindi static void 16087aec1d6eScindi clear_arrows(struct event *ep, struct event *ep2, struct fme *fmep) 16097aec1d6eScindi { 16107aec1d6eScindi struct bubble *bp; 16117aec1d6eScindi struct arrowlist *ap; 16127aec1d6eScindi 16137aec1d6eScindi ep->cached_state = 0; 161400d0963fSdilpreet ep->keep_in_tree = 0; 16157aec1d6eScindi for (bp = itree_next_bubble(ep, NULL); bp; 16167aec1d6eScindi bp = itree_next_bubble(ep, bp)) { 16177aec1d6eScindi if (bp->t != B_FROM) 16187aec1d6eScindi continue; 16197aec1d6eScindi bp->mark = 0; 16207aec1d6eScindi for (ap = itree_next_arrow(bp, NULL); ap; 16217aec1d6eScindi ap = itree_next_arrow(bp, ap)) 16227aec1d6eScindi ap->arrowp->mark = 0; 16237aec1d6eScindi } 16247aec1d6eScindi } 16257aec1d6eScindi 16267c478bd9Sstevel@tonic-gate static void 16277c478bd9Sstevel@tonic-gate fme_receive_report(fmd_hdl_t *hdl, fmd_event_t *ffep, 16287c478bd9Sstevel@tonic-gate const char *eventstring, const struct ipath *ipp, nvlist_t *nvl) 16297c478bd9Sstevel@tonic-gate { 16307c478bd9Sstevel@tonic-gate struct event *ep; 16317c478bd9Sstevel@tonic-gate struct fme *fmep = NULL; 16320cc1f05eSjrutt struct fme *ofmep = NULL; 16330cc1f05eSjrutt struct fme *cfmep, *svfmep; 16347c478bd9Sstevel@tonic-gate int matched = 0; 16350cc1f05eSjrutt nvlist_t *defect; 1636b5016cbbSstephh fmd_case_t *fmcase; 1637705e9f42SStephen Hanson char *reason; 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "fme_receive_report: "); 16407c478bd9Sstevel@tonic-gate ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 16417c478bd9Sstevel@tonic-gate out(O_ALTFP|O_STAMP, NULL); 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate /* decide which FME it goes to */ 16447c478bd9Sstevel@tonic-gate for (fmep = FMElist; fmep; fmep = fmep->next) { 16457c478bd9Sstevel@tonic-gate int prev_verbose; 16467c478bd9Sstevel@tonic-gate unsigned long long my_delay = TIMEVAL_EVENTUALLY; 16477c478bd9Sstevel@tonic-gate enum fme_state state; 16487aec1d6eScindi nvlist_t *pre_peek_nvp = NULL; 16497c478bd9Sstevel@tonic-gate 16500cc1f05eSjrutt if (fmep->overflow) { 16510cc1f05eSjrutt if (!(fmd_case_closed(fmep->hdl, fmep->fmcase))) 16520cc1f05eSjrutt ofmep = fmep; 16530cc1f05eSjrutt 16540cc1f05eSjrutt continue; 16550cc1f05eSjrutt } 16560cc1f05eSjrutt 1657d96ce684Sstephh /* 1658d96ce684Sstephh * ignore solved or closed cases 1659d96ce684Sstephh */ 1660d96ce684Sstephh if (fmep->posted_suspects || 1661d96ce684Sstephh fmd_case_solved(fmep->hdl, fmep->fmcase) || 1662d96ce684Sstephh fmd_case_closed(fmep->hdl, fmep->fmcase)) 1663d96ce684Sstephh continue; 1664d96ce684Sstephh 16657c478bd9Sstevel@tonic-gate /* look up event in event tree for this FME */ 16667c478bd9Sstevel@tonic-gate if ((ep = itree_lookup(fmep->eventtree, 16677c478bd9Sstevel@tonic-gate eventstring, ipp)) == NULL) 16687c478bd9Sstevel@tonic-gate continue; 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate /* note observation */ 16717c478bd9Sstevel@tonic-gate fmep->ecurrent = ep; 16727c478bd9Sstevel@tonic-gate if (ep->count++ == 0) { 16737c478bd9Sstevel@tonic-gate /* link it into list of observations seen */ 16747c478bd9Sstevel@tonic-gate ep->observations = fmep->observations; 16757c478bd9Sstevel@tonic-gate fmep->observations = ep; 16767c478bd9Sstevel@tonic-gate ep->nvp = evnv_dupnvl(nvl); 16777aec1d6eScindi } else { 16787aec1d6eScindi /* use new payload values for peek */ 16797aec1d6eScindi pre_peek_nvp = ep->nvp; 16807aec1d6eScindi ep->nvp = evnv_dupnvl(nvl); 16817c478bd9Sstevel@tonic-gate } 16827c478bd9Sstevel@tonic-gate 16837c478bd9Sstevel@tonic-gate /* tell hypothesise() not to mess with suspect list */ 16847c478bd9Sstevel@tonic-gate fmep->peek = 1; 16857c478bd9Sstevel@tonic-gate 16867c478bd9Sstevel@tonic-gate /* don't want this to be verbose (unless Debug is set) */ 16877c478bd9Sstevel@tonic-gate prev_verbose = Verbose; 16887c478bd9Sstevel@tonic-gate if (Debug == 0) 16897c478bd9Sstevel@tonic-gate Verbose = 0; 16907c478bd9Sstevel@tonic-gate 16917aec1d6eScindi lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep); 16927aec1d6eScindi state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay); 16937c478bd9Sstevel@tonic-gate 16947c478bd9Sstevel@tonic-gate fmep->peek = 0; 16957c478bd9Sstevel@tonic-gate 16967c478bd9Sstevel@tonic-gate /* put verbose flag back */ 16977c478bd9Sstevel@tonic-gate Verbose = prev_verbose; 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate if (state != FME_DISPROVED) { 17007c478bd9Sstevel@tonic-gate /* found an FME that explains the ereport */ 17017c478bd9Sstevel@tonic-gate matched++; 17027c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "["); 17037c478bd9Sstevel@tonic-gate ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 17047c478bd9Sstevel@tonic-gate out(O_ALTFP, " explained by FME%d]", fmep->id); 17057c478bd9Sstevel@tonic-gate 1706aab83bb8SJosef 'Jeff' Sipek nvlist_free(pre_peek_nvp); 17077aec1d6eScindi 17087c478bd9Sstevel@tonic-gate if (ep->count == 1) 17097c478bd9Sstevel@tonic-gate serialize_observation(fmep, eventstring, ipp); 17107c478bd9Sstevel@tonic-gate 1711b7d3956bSstephh if (ffep) { 17127c478bd9Sstevel@tonic-gate fmd_case_add_ereport(hdl, fmep->fmcase, ffep); 1713b7d3956bSstephh ep->ffep = ffep; 1714b7d3956bSstephh } 17157c478bd9Sstevel@tonic-gate 17167c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Rcount); 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* re-eval FME */ 17197c478bd9Sstevel@tonic-gate fme_eval(fmep, ffep); 17207c478bd9Sstevel@tonic-gate } else { 17217c478bd9Sstevel@tonic-gate 17227c478bd9Sstevel@tonic-gate /* not a match, undo noting of observation */ 17237c478bd9Sstevel@tonic-gate fmep->ecurrent = NULL; 17247c478bd9Sstevel@tonic-gate if (--ep->count == 0) { 17257c478bd9Sstevel@tonic-gate /* unlink it from observations */ 17267c478bd9Sstevel@tonic-gate fmep->observations = ep->observations; 17277c478bd9Sstevel@tonic-gate ep->observations = NULL; 17287c478bd9Sstevel@tonic-gate nvlist_free(ep->nvp); 17297c478bd9Sstevel@tonic-gate ep->nvp = NULL; 17307aec1d6eScindi } else { 17317aec1d6eScindi nvlist_free(ep->nvp); 17327aec1d6eScindi ep->nvp = pre_peek_nvp; 17337c478bd9Sstevel@tonic-gate } 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate } 17367c478bd9Sstevel@tonic-gate 17377c478bd9Sstevel@tonic-gate if (matched) 17387c478bd9Sstevel@tonic-gate return; /* explained by at least one existing FME */ 17397c478bd9Sstevel@tonic-gate 17407c478bd9Sstevel@tonic-gate /* clean up closed fmes */ 17410cc1f05eSjrutt cfmep = ClosedFMEs; 17420cc1f05eSjrutt while (cfmep != NULL) { 17430cc1f05eSjrutt svfmep = cfmep->next; 17440cc1f05eSjrutt destroy_fme(cfmep); 17450cc1f05eSjrutt cfmep = svfmep; 17467c478bd9Sstevel@tonic-gate } 17477c478bd9Sstevel@tonic-gate ClosedFMEs = NULL; 17487c478bd9Sstevel@tonic-gate 17490cc1f05eSjrutt if (ofmep) { 17500cc1f05eSjrutt out(O_ALTFP|O_NONL, "["); 17510cc1f05eSjrutt ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 17520cc1f05eSjrutt out(O_ALTFP, " ADDING TO OVERFLOW FME]"); 17530cc1f05eSjrutt if (ffep) 17540cc1f05eSjrutt fmd_case_add_ereport(hdl, ofmep->fmcase, ffep); 17550cc1f05eSjrutt 17560cc1f05eSjrutt return; 17570cc1f05eSjrutt 17580cc1f05eSjrutt } else if (Max_fme && (Open_fme_count >= Max_fme)) { 17590cc1f05eSjrutt out(O_ALTFP|O_NONL, "["); 17600cc1f05eSjrutt ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 17610cc1f05eSjrutt out(O_ALTFP, " MAX OPEN FME REACHED]"); 1762b5016cbbSstephh 1763b5016cbbSstephh fmcase = fmd_case_open(hdl, NULL); 1764b5016cbbSstephh 17650cc1f05eSjrutt /* Create overflow fme */ 1766705e9f42SStephen Hanson if ((fmep = newfme(eventstring, ipp, hdl, fmcase, ffep, 1767705e9f42SStephen Hanson nvl)) == NULL) { 17680cc1f05eSjrutt out(O_ALTFP|O_NONL, "["); 17690cc1f05eSjrutt ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 17700cc1f05eSjrutt out(O_ALTFP, " CANNOT OPEN OVERFLOW FME]"); 17710cc1f05eSjrutt return; 17720cc1f05eSjrutt } 17730cc1f05eSjrutt 17740cc1f05eSjrutt Open_fme_count++; 17750cc1f05eSjrutt 17760cc1f05eSjrutt init_fme_bufs(fmep); 17770cc1f05eSjrutt fmep->overflow = B_TRUE; 17780cc1f05eSjrutt 17790cc1f05eSjrutt if (ffep) 17800cc1f05eSjrutt fmd_case_add_ereport(hdl, fmep->fmcase, ffep); 17810cc1f05eSjrutt 178232d4e834STarik Soydan Undiag_reason = UD_VAL_MAXFME; 178332d4e834STarik Soydan defect = fmd_nvl_create_fault(hdl, 178432d4e834STarik Soydan undiag_2defect_str(Undiag_reason), 100, NULL, NULL, NULL); 1785705e9f42SStephen Hanson reason = undiag_2reason_str(Undiag_reason, NULL); 1786705e9f42SStephen Hanson (void) nvlist_add_string(defect, UNDIAG_REASON, reason); 1787705e9f42SStephen Hanson FREE(reason); 17880cc1f05eSjrutt fmd_case_add_suspect(hdl, fmep->fmcase, defect); 17890cc1f05eSjrutt fmd_case_solve(hdl, fmep->fmcase); 179032d4e834STarik Soydan Undiag_reason = UD_VAL_UNKNOWN; 17910cc1f05eSjrutt return; 17920cc1f05eSjrutt } 17930cc1f05eSjrutt 1794b5016cbbSstephh /* open a case */ 1795b5016cbbSstephh fmcase = fmd_case_open(hdl, NULL); 1796b5016cbbSstephh 17977c478bd9Sstevel@tonic-gate /* start a new FME */ 1798705e9f42SStephen Hanson if ((fmep = newfme(eventstring, ipp, hdl, fmcase, ffep, nvl)) == NULL) { 17997c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "["); 18007c478bd9Sstevel@tonic-gate ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 18017c478bd9Sstevel@tonic-gate out(O_ALTFP, " CANNOT DIAGNOSE]"); 18027c478bd9Sstevel@tonic-gate return; 18037c478bd9Sstevel@tonic-gate } 18047c478bd9Sstevel@tonic-gate 18050cc1f05eSjrutt Open_fme_count++; 18060cc1f05eSjrutt 18077c478bd9Sstevel@tonic-gate init_fme_bufs(fmep); 18087c478bd9Sstevel@tonic-gate 18097c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "["); 18107c478bd9Sstevel@tonic-gate ipath_print(O_ALTFP|O_NONL, eventstring, ipp); 18117c478bd9Sstevel@tonic-gate out(O_ALTFP, " created FME%d, case %s]", fmep->id, 18127c478bd9Sstevel@tonic-gate fmd_case_uuid(hdl, fmep->fmcase)); 18137c478bd9Sstevel@tonic-gate 18147c478bd9Sstevel@tonic-gate ep = fmep->e0; 18157c478bd9Sstevel@tonic-gate ASSERT(ep != NULL); 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate /* note observation */ 18187c478bd9Sstevel@tonic-gate fmep->ecurrent = ep; 18197c478bd9Sstevel@tonic-gate if (ep->count++ == 0) { 18207c478bd9Sstevel@tonic-gate /* link it into list of observations seen */ 18217c478bd9Sstevel@tonic-gate ep->observations = fmep->observations; 18227c478bd9Sstevel@tonic-gate fmep->observations = ep; 18237c478bd9Sstevel@tonic-gate ep->nvp = evnv_dupnvl(nvl); 18247c478bd9Sstevel@tonic-gate serialize_observation(fmep, eventstring, ipp); 18257aec1d6eScindi } else { 18267aec1d6eScindi /* new payload overrides any previous */ 18277aec1d6eScindi nvlist_free(ep->nvp); 18287aec1d6eScindi ep->nvp = evnv_dupnvl(nvl); 18297c478bd9Sstevel@tonic-gate } 18307c478bd9Sstevel@tonic-gate 18317c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Rcount); 18327c478bd9Sstevel@tonic-gate 18337c478bd9Sstevel@tonic-gate if (ffep) { 18347c478bd9Sstevel@tonic-gate fmd_case_add_ereport(hdl, fmep->fmcase, ffep); 18357c478bd9Sstevel@tonic-gate fmd_case_setprincipal(hdl, fmep->fmcase, ffep); 18367c478bd9Sstevel@tonic-gate fmep->e0r = ffep; 1837b7d3956bSstephh ep->ffep = ffep; 18387c478bd9Sstevel@tonic-gate } 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate /* give the diagnosis algorithm a shot at the new FME state */ 18417c478bd9Sstevel@tonic-gate fme_eval(fmep, ffep); 18427c478bd9Sstevel@tonic-gate } 18437c478bd9Sstevel@tonic-gate 18447c478bd9Sstevel@tonic-gate void 18457c478bd9Sstevel@tonic-gate fme_status(int flags) 18467c478bd9Sstevel@tonic-gate { 18477c478bd9Sstevel@tonic-gate struct fme *fmep; 18487c478bd9Sstevel@tonic-gate 18497c478bd9Sstevel@tonic-gate if (FMElist == NULL) { 18507c478bd9Sstevel@tonic-gate out(flags, "No fault management exercises underway."); 18517c478bd9Sstevel@tonic-gate return; 18527c478bd9Sstevel@tonic-gate } 18537c478bd9Sstevel@tonic-gate 18547c478bd9Sstevel@tonic-gate for (fmep = FMElist; fmep; fmep = fmep->next) 18557c478bd9Sstevel@tonic-gate fme_print(flags, fmep); 18567c478bd9Sstevel@tonic-gate } 18577c478bd9Sstevel@tonic-gate 18587c478bd9Sstevel@tonic-gate /* 18597c478bd9Sstevel@tonic-gate * "indent" routines used mostly for nicely formatted debug output, but also 18607c478bd9Sstevel@tonic-gate * for sanity checking for infinite recursion bugs. 18617c478bd9Sstevel@tonic-gate */ 18627c478bd9Sstevel@tonic-gate 18637c478bd9Sstevel@tonic-gate #define MAX_INDENT 1024 18647c478bd9Sstevel@tonic-gate static const char *indent_s[MAX_INDENT]; 18657c478bd9Sstevel@tonic-gate static int current_indent; 18667c478bd9Sstevel@tonic-gate 18677c478bd9Sstevel@tonic-gate static void 18687c478bd9Sstevel@tonic-gate indent_push(const char *s) 18697c478bd9Sstevel@tonic-gate { 18707c478bd9Sstevel@tonic-gate if (current_indent < MAX_INDENT) 18717c478bd9Sstevel@tonic-gate indent_s[current_indent++] = s; 18727c478bd9Sstevel@tonic-gate else 18737c478bd9Sstevel@tonic-gate out(O_DIE, "unexpected recursion depth (%d)", current_indent); 18747c478bd9Sstevel@tonic-gate } 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate static void 18777c478bd9Sstevel@tonic-gate indent_set(const char *s) 18787c478bd9Sstevel@tonic-gate { 18797c478bd9Sstevel@tonic-gate current_indent = 0; 18807c478bd9Sstevel@tonic-gate indent_push(s); 18817c478bd9Sstevel@tonic-gate } 18827c478bd9Sstevel@tonic-gate 18837c478bd9Sstevel@tonic-gate static void 18847c478bd9Sstevel@tonic-gate indent_pop(void) 18857c478bd9Sstevel@tonic-gate { 18867c478bd9Sstevel@tonic-gate if (current_indent > 0) 18877c478bd9Sstevel@tonic-gate current_indent--; 18887c478bd9Sstevel@tonic-gate else 18897c478bd9Sstevel@tonic-gate out(O_DIE, "recursion underflow"); 18907c478bd9Sstevel@tonic-gate } 18917c478bd9Sstevel@tonic-gate 18927c478bd9Sstevel@tonic-gate static void 18937c478bd9Sstevel@tonic-gate indent(void) 18947c478bd9Sstevel@tonic-gate { 18957c478bd9Sstevel@tonic-gate int i; 18967c478bd9Sstevel@tonic-gate if (!Verbose) 18977c478bd9Sstevel@tonic-gate return; 18987c478bd9Sstevel@tonic-gate for (i = 0; i < current_indent; i++) 18997c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, indent_s[i]); 19007c478bd9Sstevel@tonic-gate } 19017c478bd9Sstevel@tonic-gate 19027c478bd9Sstevel@tonic-gate #define SLNEW 1 19037c478bd9Sstevel@tonic-gate #define SLCHANGED 2 19047c478bd9Sstevel@tonic-gate #define SLWAIT 3 19057c478bd9Sstevel@tonic-gate #define SLDISPROVED 4 19067c478bd9Sstevel@tonic-gate 19077c478bd9Sstevel@tonic-gate static void 19087c478bd9Sstevel@tonic-gate print_suspects(int circumstance, struct fme *fmep) 19097c478bd9Sstevel@tonic-gate { 19107c478bd9Sstevel@tonic-gate struct event *ep; 19117c478bd9Sstevel@tonic-gate 19127c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "["); 19137c478bd9Sstevel@tonic-gate if (circumstance == SLCHANGED) { 19147c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "FME%d diagnosis changed. state: %s, " 19157c478bd9Sstevel@tonic-gate "suspect list:", fmep->id, fme_state2str(fmep->state)); 19167c478bd9Sstevel@tonic-gate } else if (circumstance == SLWAIT) { 1917b5016cbbSstephh out(O_ALTFP|O_NONL, "FME%d set wait timer %ld ", fmep->id, 1918b5016cbbSstephh fmep->timer); 19197c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_NONL, &fmep->wull); 19207c478bd9Sstevel@tonic-gate } else if (circumstance == SLDISPROVED) { 19217c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "FME%d DIAGNOSIS UNKNOWN", fmep->id); 19227c478bd9Sstevel@tonic-gate } else { 19237c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, "FME%d DIAGNOSIS PRODUCED:", fmep->id); 19247c478bd9Sstevel@tonic-gate } 19257c478bd9Sstevel@tonic-gate 19267c478bd9Sstevel@tonic-gate if (circumstance == SLWAIT || circumstance == SLDISPROVED) { 19277c478bd9Sstevel@tonic-gate out(O_ALTFP, "]"); 19287c478bd9Sstevel@tonic-gate return; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate for (ep = fmep->suspects; ep; ep = ep->suspects) { 19327c478bd9Sstevel@tonic-gate out(O_ALTFP|O_NONL, " "); 19337c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_NONL, ep); 19347c478bd9Sstevel@tonic-gate } 19357c478bd9Sstevel@tonic-gate out(O_ALTFP, "]"); 19367c478bd9Sstevel@tonic-gate } 19377c478bd9Sstevel@tonic-gate 19387c478bd9Sstevel@tonic-gate static struct node * 19397c478bd9Sstevel@tonic-gate eventprop_lookup(struct event *ep, const char *propname) 19407c478bd9Sstevel@tonic-gate { 19417c478bd9Sstevel@tonic-gate return (lut_lookup(ep->props, (void *)propname, NULL)); 19427c478bd9Sstevel@tonic-gate } 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate #define MAXDIGITIDX 23 19457c478bd9Sstevel@tonic-gate static char numbuf[MAXDIGITIDX + 1]; 19467c478bd9Sstevel@tonic-gate 19477c478bd9Sstevel@tonic-gate static int 19487c478bd9Sstevel@tonic-gate node2uint(struct node *n, uint_t *valp) 19497c478bd9Sstevel@tonic-gate { 19507c478bd9Sstevel@tonic-gate struct evalue value; 19517c478bd9Sstevel@tonic-gate struct lut *globals = NULL; 19527c478bd9Sstevel@tonic-gate 19537c478bd9Sstevel@tonic-gate if (n == NULL) 19547c478bd9Sstevel@tonic-gate return (1); 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate /* 19577c478bd9Sstevel@tonic-gate * check value.v since we are being asked to convert an unsigned 19587c478bd9Sstevel@tonic-gate * long long int to an unsigned int 19597c478bd9Sstevel@tonic-gate */ 19607c478bd9Sstevel@tonic-gate if (! eval_expr(n, NULL, NULL, &globals, NULL, NULL, 0, &value) || 19617c478bd9Sstevel@tonic-gate value.t != UINT64 || value.v > (1ULL << 32)) 19627c478bd9Sstevel@tonic-gate return (1); 19637c478bd9Sstevel@tonic-gate 19647c478bd9Sstevel@tonic-gate *valp = (uint_t)value.v; 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate return (0); 19677c478bd9Sstevel@tonic-gate } 19687c478bd9Sstevel@tonic-gate 19697c478bd9Sstevel@tonic-gate static nvlist_t * 19707c478bd9Sstevel@tonic-gate node2fmri(struct node *n) 19717c478bd9Sstevel@tonic-gate { 19727c478bd9Sstevel@tonic-gate nvlist_t **pa, *f, *p; 19737c478bd9Sstevel@tonic-gate struct node *nc; 19747c478bd9Sstevel@tonic-gate uint_t depth = 0; 19757c478bd9Sstevel@tonic-gate char *numstr, *nullbyte; 19767c478bd9Sstevel@tonic-gate char *failure; 19777c478bd9Sstevel@tonic-gate int err, i; 19787c478bd9Sstevel@tonic-gate 19797c478bd9Sstevel@tonic-gate /* XXX do we need to be able to handle a non-T_NAME node? */ 19807c478bd9Sstevel@tonic-gate if (n == NULL || n->t != T_NAME) 19817c478bd9Sstevel@tonic-gate return (NULL); 19827c478bd9Sstevel@tonic-gate 19837c478bd9Sstevel@tonic-gate for (nc = n; nc != NULL; nc = nc->u.name.next) { 19847c478bd9Sstevel@tonic-gate if (nc->u.name.child == NULL || nc->u.name.child->t != T_NUM) 19857c478bd9Sstevel@tonic-gate break; 19867c478bd9Sstevel@tonic-gate depth++; 19877c478bd9Sstevel@tonic-gate } 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate if (nc != NULL) { 19907c478bd9Sstevel@tonic-gate /* We bailed early, something went wrong */ 19917c478bd9Sstevel@tonic-gate return (NULL); 19927c478bd9Sstevel@tonic-gate } 19937c478bd9Sstevel@tonic-gate 19947c478bd9Sstevel@tonic-gate if ((err = nvlist_xalloc(&f, NV_UNIQUE_NAME, &Eft_nv_hdl)) != 0) 19957c478bd9Sstevel@tonic-gate out(O_DIE|O_SYS, "alloc of fmri nvl failed"); 19967c478bd9Sstevel@tonic-gate pa = alloca(depth * sizeof (nvlist_t *)); 19977c478bd9Sstevel@tonic-gate for (i = 0; i < depth; i++) 19987c478bd9Sstevel@tonic-gate pa[i] = NULL; 19997c478bd9Sstevel@tonic-gate 20007c478bd9Sstevel@tonic-gate err = nvlist_add_string(f, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC); 20017c478bd9Sstevel@tonic-gate err |= nvlist_add_uint8(f, FM_VERSION, FM_HC_SCHEME_VERSION); 20027c478bd9Sstevel@tonic-gate err |= nvlist_add_string(f, FM_FMRI_HC_ROOT, ""); 20037c478bd9Sstevel@tonic-gate err |= nvlist_add_uint32(f, FM_FMRI_HC_LIST_SZ, depth); 20047c478bd9Sstevel@tonic-gate if (err != 0) { 20057c478bd9Sstevel@tonic-gate failure = "basic construction of FMRI failed"; 20067c478bd9Sstevel@tonic-gate goto boom; 20077c478bd9Sstevel@tonic-gate } 20087c478bd9Sstevel@tonic-gate 20097c478bd9Sstevel@tonic-gate numbuf[MAXDIGITIDX] = '\0'; 20107c478bd9Sstevel@tonic-gate nullbyte = &numbuf[MAXDIGITIDX]; 20117c478bd9Sstevel@tonic-gate i = 0; 20127c478bd9Sstevel@tonic-gate 20137c478bd9Sstevel@tonic-gate for (nc = n; nc != NULL; nc = nc->u.name.next) { 20147c478bd9Sstevel@tonic-gate err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl); 20157c478bd9Sstevel@tonic-gate if (err != 0) { 20167c478bd9Sstevel@tonic-gate failure = "alloc of an hc-pair failed"; 20177c478bd9Sstevel@tonic-gate goto boom; 20187c478bd9Sstevel@tonic-gate } 20197c478bd9Sstevel@tonic-gate err = nvlist_add_string(p, FM_FMRI_HC_NAME, nc->u.name.s); 20207c478bd9Sstevel@tonic-gate numstr = ulltostr(nc->u.name.child->u.ull, nullbyte); 20217c478bd9Sstevel@tonic-gate err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr); 20227c478bd9Sstevel@tonic-gate if (err != 0) { 20237c478bd9Sstevel@tonic-gate failure = "construction of an hc-pair failed"; 20247c478bd9Sstevel@tonic-gate goto boom; 20257c478bd9Sstevel@tonic-gate } 20267c478bd9Sstevel@tonic-gate pa[i++] = p; 20277c478bd9Sstevel@tonic-gate } 20287c478bd9Sstevel@tonic-gate 20297c478bd9Sstevel@tonic-gate err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth); 20307c478bd9Sstevel@tonic-gate if (err == 0) { 20317c478bd9Sstevel@tonic-gate for (i = 0; i < depth; i++) 2032aab83bb8SJosef 'Jeff' Sipek nvlist_free(pa[i]); 20337c478bd9Sstevel@tonic-gate return (f); 20347c478bd9Sstevel@tonic-gate } 20357c478bd9Sstevel@tonic-gate failure = "addition of hc-pair array to FMRI failed"; 20367c478bd9Sstevel@tonic-gate 20377c478bd9Sstevel@tonic-gate boom: 20387c478bd9Sstevel@tonic-gate for (i = 0; i < depth; i++) 2039aab83bb8SJosef 'Jeff' Sipek nvlist_free(pa[i]); 20407c478bd9Sstevel@tonic-gate nvlist_free(f); 20417c478bd9Sstevel@tonic-gate out(O_DIE, "%s", failure); 20427c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 204380ab886dSwesolows return (NULL); 20447c478bd9Sstevel@tonic-gate } 20457c478bd9Sstevel@tonic-gate 2046e5ba14ffSstephh /* an ipath cache entry is an array of these, with s==NULL at the end */ 2047e5ba14ffSstephh struct ipath { 2048e5ba14ffSstephh const char *s; /* component name (in stable) */ 2049e5ba14ffSstephh int i; /* instance number */ 2050e5ba14ffSstephh }; 2051e5ba14ffSstephh 2052e5ba14ffSstephh static nvlist_t * 2053e5ba14ffSstephh ipath2fmri(struct ipath *ipath) 2054e5ba14ffSstephh { 2055e5ba14ffSstephh nvlist_t **pa, *f, *p; 2056e5ba14ffSstephh uint_t depth = 0; 2057e5ba14ffSstephh char *numstr, *nullbyte; 2058e5ba14ffSstephh char *failure; 2059e5ba14ffSstephh int err, i; 2060e5ba14ffSstephh struct ipath *ipp; 2061e5ba14ffSstephh 2062e5ba14ffSstephh for (ipp = ipath; ipp->s != NULL; ipp++) 2063e5ba14ffSstephh depth++; 2064e5ba14ffSstephh 2065e5ba14ffSstephh if ((err = nvlist_xalloc(&f, NV_UNIQUE_NAME, &Eft_nv_hdl)) != 0) 2066e5ba14ffSstephh out(O_DIE|O_SYS, "alloc of fmri nvl failed"); 2067e5ba14ffSstephh pa = alloca(depth * sizeof (nvlist_t *)); 2068e5ba14ffSstephh for (i = 0; i < depth; i++) 2069e5ba14ffSstephh pa[i] = NULL; 2070e5ba14ffSstephh 2071e5ba14ffSstephh err = nvlist_add_string(f, FM_FMRI_SCHEME, FM_FMRI_SCHEME_HC); 2072e5ba14ffSstephh err |= nvlist_add_uint8(f, FM_VERSION, FM_HC_SCHEME_VERSION); 2073e5ba14ffSstephh err |= nvlist_add_string(f, FM_FMRI_HC_ROOT, ""); 2074e5ba14ffSstephh err |= nvlist_add_uint32(f, FM_FMRI_HC_LIST_SZ, depth); 2075e5ba14ffSstephh if (err != 0) { 2076e5ba14ffSstephh failure = "basic construction of FMRI failed"; 2077e5ba14ffSstephh goto boom; 2078e5ba14ffSstephh } 2079e5ba14ffSstephh 2080e5ba14ffSstephh numbuf[MAXDIGITIDX] = '\0'; 2081e5ba14ffSstephh nullbyte = &numbuf[MAXDIGITIDX]; 2082e5ba14ffSstephh i = 0; 2083e5ba14ffSstephh 2084e5ba14ffSstephh for (ipp = ipath; ipp->s != NULL; ipp++) { 2085e5ba14ffSstephh err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl); 2086e5ba14ffSstephh if (err != 0) { 2087e5ba14ffSstephh failure = "alloc of an hc-pair failed"; 2088e5ba14ffSstephh goto boom; 2089e5ba14ffSstephh } 2090e5ba14ffSstephh err = nvlist_add_string(p, FM_FMRI_HC_NAME, ipp->s); 2091e5ba14ffSstephh numstr = ulltostr(ipp->i, nullbyte); 2092e5ba14ffSstephh err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr); 2093e5ba14ffSstephh if (err != 0) { 2094e5ba14ffSstephh failure = "construction of an hc-pair failed"; 2095e5ba14ffSstephh goto boom; 2096e5ba14ffSstephh } 2097e5ba14ffSstephh pa[i++] = p; 2098e5ba14ffSstephh } 2099e5ba14ffSstephh 2100e5ba14ffSstephh err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth); 2101e5ba14ffSstephh if (err == 0) { 2102e5ba14ffSstephh for (i = 0; i < depth; i++) 2103aab83bb8SJosef 'Jeff' Sipek nvlist_free(pa[i]); 2104e5ba14ffSstephh return (f); 2105e5ba14ffSstephh } 2106e5ba14ffSstephh failure = "addition of hc-pair array to FMRI failed"; 2107e5ba14ffSstephh 2108e5ba14ffSstephh boom: 2109e5ba14ffSstephh for (i = 0; i < depth; i++) 2110aab83bb8SJosef 'Jeff' Sipek nvlist_free(pa[i]); 2111e5ba14ffSstephh nvlist_free(f); 2112e5ba14ffSstephh out(O_DIE, "%s", failure); 2113e5ba14ffSstephh /*NOTREACHED*/ 2114e5ba14ffSstephh return (NULL); 2115e5ba14ffSstephh } 2116e5ba14ffSstephh 21177c478bd9Sstevel@tonic-gate static uint8_t 21187c478bd9Sstevel@tonic-gate percentof(uint_t part, uint_t whole) 21197c478bd9Sstevel@tonic-gate { 21207c478bd9Sstevel@tonic-gate unsigned long long p = part * 1000; 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate return ((p / whole / 10) + (((p / whole % 10) >= 5) ? 1 : 0)); 21237c478bd9Sstevel@tonic-gate } 21247c478bd9Sstevel@tonic-gate 212580ab886dSwesolows struct rsl { 21267c478bd9Sstevel@tonic-gate struct event *suspect; 21277c478bd9Sstevel@tonic-gate nvlist_t *asru; 21287c478bd9Sstevel@tonic-gate nvlist_t *fru; 21297c478bd9Sstevel@tonic-gate nvlist_t *rsrc; 21307c478bd9Sstevel@tonic-gate }; 21317c478bd9Sstevel@tonic-gate 2132b7d3956bSstephh static void publish_suspects(struct fme *fmep, struct rsl *srl); 2133b7d3956bSstephh 21347c478bd9Sstevel@tonic-gate /* 21357c478bd9Sstevel@tonic-gate * rslfree -- free internal members of struct rsl not expected to be 21367c478bd9Sstevel@tonic-gate * freed elsewhere. 21377c478bd9Sstevel@tonic-gate */ 21387c478bd9Sstevel@tonic-gate static void 21397c478bd9Sstevel@tonic-gate rslfree(struct rsl *freeme) 21407c478bd9Sstevel@tonic-gate { 2141aab83bb8SJosef 'Jeff' Sipek nvlist_free(freeme->asru); 2142aab83bb8SJosef 'Jeff' Sipek nvlist_free(freeme->fru); 2143aab83bb8SJosef 'Jeff' Sipek if (freeme->rsrc != freeme->asru) 21447c478bd9Sstevel@tonic-gate nvlist_free(freeme->rsrc); 21457c478bd9Sstevel@tonic-gate } 21467c478bd9Sstevel@tonic-gate 21477c478bd9Sstevel@tonic-gate /* 21487c478bd9Sstevel@tonic-gate * rslcmp -- compare two rsl structures. Use the following 21497c478bd9Sstevel@tonic-gate * comparisons to establish cardinality: 21507c478bd9Sstevel@tonic-gate * 21517c478bd9Sstevel@tonic-gate * 1. Name of the suspect's class. (simple strcmp) 21527c478bd9Sstevel@tonic-gate * 2. Name of the suspect's ASRU. (trickier, since nvlist) 21537c478bd9Sstevel@tonic-gate * 21547c478bd9Sstevel@tonic-gate */ 21557c478bd9Sstevel@tonic-gate static int 21567c478bd9Sstevel@tonic-gate rslcmp(const void *a, const void *b) 21577c478bd9Sstevel@tonic-gate { 21587c478bd9Sstevel@tonic-gate struct rsl *r1 = (struct rsl *)a; 21597c478bd9Sstevel@tonic-gate struct rsl *r2 = (struct rsl *)b; 21607c478bd9Sstevel@tonic-gate int rv; 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate rv = strcmp(r1->suspect->enode->u.event.ename->u.name.s, 21637c478bd9Sstevel@tonic-gate r2->suspect->enode->u.event.ename->u.name.s); 21647c478bd9Sstevel@tonic-gate if (rv != 0) 21657c478bd9Sstevel@tonic-gate return (rv); 21667c478bd9Sstevel@tonic-gate 2167b7d3956bSstephh if (r1->rsrc == NULL && r2->rsrc == NULL) 21687c478bd9Sstevel@tonic-gate return (0); 2169b7d3956bSstephh if (r1->rsrc == NULL) 21707c478bd9Sstevel@tonic-gate return (-1); 2171b7d3956bSstephh if (r2->rsrc == NULL) 21727c478bd9Sstevel@tonic-gate return (1); 2173b7d3956bSstephh return (evnv_cmpnvl(r1->rsrc, r2->rsrc, 0)); 21747c478bd9Sstevel@tonic-gate } 21757c478bd9Sstevel@tonic-gate 21767c478bd9Sstevel@tonic-gate /* 21777c478bd9Sstevel@tonic-gate * get_resources -- for a given suspect, determine what ASRU, FRU and 21787c478bd9Sstevel@tonic-gate * RSRC nvlists should be advertised in the final suspect list. 21797c478bd9Sstevel@tonic-gate */ 21807c478bd9Sstevel@tonic-gate void 21817c478bd9Sstevel@tonic-gate get_resources(struct event *sp, struct rsl *rsrcs, struct config *croot) 21827c478bd9Sstevel@tonic-gate { 21837c478bd9Sstevel@tonic-gate struct node *asrudef, *frudef; 21847c478bd9Sstevel@tonic-gate nvlist_t *asru, *fru; 21857c478bd9Sstevel@tonic-gate nvlist_t *rsrc = NULL; 21867c478bd9Sstevel@tonic-gate char *pathstr; 21877c478bd9Sstevel@tonic-gate 21887c478bd9Sstevel@tonic-gate /* 21897c478bd9Sstevel@tonic-gate * First find any ASRU and/or FRU defined in the 21907c478bd9Sstevel@tonic-gate * initial fault tree. 21917c478bd9Sstevel@tonic-gate */ 21927c478bd9Sstevel@tonic-gate asrudef = eventprop_lookup(sp, L_ASRU); 21937c478bd9Sstevel@tonic-gate frudef = eventprop_lookup(sp, L_FRU); 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate /* 21967c478bd9Sstevel@tonic-gate * Create FMRIs based on those definitions 21977c478bd9Sstevel@tonic-gate */ 21987c478bd9Sstevel@tonic-gate asru = node2fmri(asrudef); 21997c478bd9Sstevel@tonic-gate fru = node2fmri(frudef); 22007c478bd9Sstevel@tonic-gate pathstr = ipath2str(NULL, sp->ipp); 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate /* 2203b7d3956bSstephh * Allow for platform translations of the FMRIs 22047c478bd9Sstevel@tonic-gate */ 22057c478bd9Sstevel@tonic-gate platform_units_translate(is_defect(sp->t), croot, &asru, &fru, &rsrc, 22067c478bd9Sstevel@tonic-gate pathstr); 22077c478bd9Sstevel@tonic-gate 22087c478bd9Sstevel@tonic-gate FREE(pathstr); 22097c478bd9Sstevel@tonic-gate rsrcs->suspect = sp; 22107c478bd9Sstevel@tonic-gate rsrcs->asru = asru; 22117c478bd9Sstevel@tonic-gate rsrcs->fru = fru; 22127c478bd9Sstevel@tonic-gate rsrcs->rsrc = rsrc; 22137c478bd9Sstevel@tonic-gate } 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate /* 22167c478bd9Sstevel@tonic-gate * trim_suspects -- prior to publishing, we may need to remove some 22177c478bd9Sstevel@tonic-gate * suspects from the list. If we're auto-closing upsets, we don't 22187c478bd9Sstevel@tonic-gate * want any of those in the published list. If the ASRUs for multiple 22197c478bd9Sstevel@tonic-gate * defects resolve to the same ASRU (driver) we only want to publish 22207c478bd9Sstevel@tonic-gate * that as a single suspect. 22217c478bd9Sstevel@tonic-gate */ 2222b7d3956bSstephh static int 2223b7d3956bSstephh trim_suspects(struct fme *fmep, struct rsl *begin, struct rsl *begin2, 22248e7248e5SStephen Hanson fmd_event_t *ffep) 22257c478bd9Sstevel@tonic-gate { 22267c478bd9Sstevel@tonic-gate struct event *ep; 2227b7d3956bSstephh struct rsl *rp = begin; 2228b7d3956bSstephh struct rsl *rp2 = begin2; 2229b7d3956bSstephh int mess_zero_count = 0; 2230b7d3956bSstephh int serd_rval; 2231b7d3956bSstephh uint_t messval; 22327c478bd9Sstevel@tonic-gate 2233b7d3956bSstephh /* remove any unwanted upsets and populate our array */ 22347c478bd9Sstevel@tonic-gate for (ep = fmep->psuspects; ep; ep = ep->psuspects) { 2235b7d3956bSstephh if (is_upset(ep->t)) 22367c478bd9Sstevel@tonic-gate continue; 2237b7d3956bSstephh serd_rval = serd_eval(fmep, fmep->hdl, ffep, fmep->fmcase, ep, 2238b7d3956bSstephh NULL, NULL); 2239b7d3956bSstephh if (serd_rval == 0) 2240b7d3956bSstephh continue; 2241b7d3956bSstephh if (node2uint(eventprop_lookup(ep, L_message), 2242b7d3956bSstephh &messval) == 0 && messval == 0) { 2243b7d3956bSstephh get_resources(ep, rp2, fmep->config); 2244b7d3956bSstephh rp2++; 2245b7d3956bSstephh mess_zero_count++; 2246b7d3956bSstephh } else { 2247b7d3956bSstephh get_resources(ep, rp, fmep->config); 2248b7d3956bSstephh rp++; 2249b7d3956bSstephh fmep->nsuspects++; 2250b7d3956bSstephh } 22517c478bd9Sstevel@tonic-gate } 2252b7d3956bSstephh return (mess_zero_count); 22537c478bd9Sstevel@tonic-gate } 22547c478bd9Sstevel@tonic-gate 22557aec1d6eScindi /* 22567aec1d6eScindi * addpayloadprop -- add a payload prop to a problem 22577aec1d6eScindi */ 22587aec1d6eScindi static void 22597aec1d6eScindi addpayloadprop(const char *lhs, struct evalue *rhs, nvlist_t *fault) 22607aec1d6eScindi { 2261b7d3956bSstephh nvlist_t *rsrc, *hcs; 2262b7d3956bSstephh 22637aec1d6eScindi ASSERT(fault != NULL); 22647aec1d6eScindi ASSERT(lhs != NULL); 22657aec1d6eScindi ASSERT(rhs != NULL); 22667aec1d6eScindi 2267b7d3956bSstephh if (nvlist_lookup_nvlist(fault, FM_FAULT_RESOURCE, &rsrc) != 0) 2268b7d3956bSstephh out(O_DIE, "cannot add payloadprop \"%s\" to fault", lhs); 2269b7d3956bSstephh 2270b7d3956bSstephh if (nvlist_lookup_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, &hcs) != 0) { 2271b7d3956bSstephh out(O_ALTFP|O_VERB2, "addpayloadprop: create hc_specific"); 2272b7d3956bSstephh if (nvlist_xalloc(&hcs, NV_UNIQUE_NAME, &Eft_nv_hdl) != 0) 2273b7d3956bSstephh out(O_DIE, 2274b7d3956bSstephh "cannot add payloadprop \"%s\" to fault", lhs); 2275b7d3956bSstephh if (nvlist_add_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, hcs) != 0) 2276b7d3956bSstephh out(O_DIE, 2277b7d3956bSstephh "cannot add payloadprop \"%s\" to fault", lhs); 2278b7d3956bSstephh nvlist_free(hcs); 2279b7d3956bSstephh if (nvlist_lookup_nvlist(rsrc, FM_FMRI_HC_SPECIFIC, &hcs) != 0) 2280b7d3956bSstephh out(O_DIE, 2281b7d3956bSstephh "cannot add payloadprop \"%s\" to fault", lhs); 2282b7d3956bSstephh } else 2283b7d3956bSstephh out(O_ALTFP|O_VERB2, "addpayloadprop: reuse hc_specific"); 2284b7d3956bSstephh 22857aec1d6eScindi if (rhs->t == UINT64) { 22867aec1d6eScindi out(O_ALTFP|O_VERB2, "addpayloadprop: %s=%llu", lhs, rhs->v); 22877aec1d6eScindi 2288b7d3956bSstephh if (nvlist_add_uint64(hcs, lhs, rhs->v) != 0) 22897aec1d6eScindi out(O_DIE, 22907aec1d6eScindi "cannot add payloadprop \"%s\" to fault", lhs); 22917aec1d6eScindi } else { 22927aec1d6eScindi out(O_ALTFP|O_VERB2, "addpayloadprop: %s=\"%s\"", 229380ab886dSwesolows lhs, (char *)(uintptr_t)rhs->v); 22947aec1d6eScindi 2295b7d3956bSstephh if (nvlist_add_string(hcs, lhs, (char *)(uintptr_t)rhs->v) != 0) 22967aec1d6eScindi out(O_DIE, 22977aec1d6eScindi "cannot add payloadprop \"%s\" to fault", lhs); 22987aec1d6eScindi } 22997aec1d6eScindi } 23007aec1d6eScindi 23017aec1d6eScindi static char *Istatbuf; 23027aec1d6eScindi static char *Istatbufptr; 23037aec1d6eScindi static int Istatsz; 23047aec1d6eScindi 23057aec1d6eScindi /* 23067aec1d6eScindi * istataddsize -- calculate size of istat and add it to Istatsz 23077aec1d6eScindi */ 23087aec1d6eScindi /*ARGSUSED2*/ 23097aec1d6eScindi static void 23107aec1d6eScindi istataddsize(const struct istat_entry *lhs, struct stats *rhs, void *arg) 23117aec1d6eScindi { 23127aec1d6eScindi int val; 23137aec1d6eScindi 23147aec1d6eScindi ASSERT(lhs != NULL); 23157aec1d6eScindi ASSERT(rhs != NULL); 23167aec1d6eScindi 23177aec1d6eScindi if ((val = stats_counter_value(rhs)) == 0) 23187aec1d6eScindi return; /* skip zero-valued stats */ 23197aec1d6eScindi 23207aec1d6eScindi /* count up the size of the stat name */ 23217aec1d6eScindi Istatsz += ipath2strlen(lhs->ename, lhs->ipath); 23227aec1d6eScindi Istatsz++; /* for the trailing NULL byte */ 23237aec1d6eScindi 23247aec1d6eScindi /* count up the size of the stat value */ 23257aec1d6eScindi Istatsz += snprintf(NULL, 0, "%d", val); 23267aec1d6eScindi Istatsz++; /* for the trailing NULL byte */ 23277aec1d6eScindi } 23287aec1d6eScindi 23297aec1d6eScindi /* 23307aec1d6eScindi * istat2str -- serialize an istat, writing result to *Istatbufptr 23317aec1d6eScindi */ 23327aec1d6eScindi /*ARGSUSED2*/ 23337aec1d6eScindi static void 23347aec1d6eScindi istat2str(const struct istat_entry *lhs, struct stats *rhs, void *arg) 23357aec1d6eScindi { 23367aec1d6eScindi char *str; 23377aec1d6eScindi int len; 23387aec1d6eScindi int val; 23397aec1d6eScindi 23407aec1d6eScindi ASSERT(lhs != NULL); 23417aec1d6eScindi ASSERT(rhs != NULL); 23427aec1d6eScindi 23437aec1d6eScindi if ((val = stats_counter_value(rhs)) == 0) 23447aec1d6eScindi return; /* skip zero-valued stats */ 23457aec1d6eScindi 23467aec1d6eScindi /* serialize the stat name */ 23477aec1d6eScindi str = ipath2str(lhs->ename, lhs->ipath); 23487aec1d6eScindi len = strlen(str); 23497aec1d6eScindi 23507aec1d6eScindi ASSERT(Istatbufptr + len + 1 < &Istatbuf[Istatsz]); 23517aec1d6eScindi (void) strlcpy(Istatbufptr, str, &Istatbuf[Istatsz] - Istatbufptr); 23527aec1d6eScindi Istatbufptr += len; 23537aec1d6eScindi FREE(str); 23547aec1d6eScindi *Istatbufptr++ = '\0'; 23557aec1d6eScindi 23567aec1d6eScindi /* serialize the stat value */ 23577aec1d6eScindi Istatbufptr += snprintf(Istatbufptr, &Istatbuf[Istatsz] - Istatbufptr, 23587aec1d6eScindi "%d", val); 23597aec1d6eScindi *Istatbufptr++ = '\0'; 23607aec1d6eScindi 23617aec1d6eScindi ASSERT(Istatbufptr <= &Istatbuf[Istatsz]); 23627aec1d6eScindi } 23637aec1d6eScindi 23647aec1d6eScindi void 23657aec1d6eScindi istat_save() 23667aec1d6eScindi { 23677aec1d6eScindi if (Istat_need_save == 0) 23687aec1d6eScindi return; 23697aec1d6eScindi 23707aec1d6eScindi /* figure out how big the serialzed info is */ 23717aec1d6eScindi Istatsz = 0; 23727aec1d6eScindi lut_walk(Istats, (lut_cb)istataddsize, NULL); 23737aec1d6eScindi 23747aec1d6eScindi if (Istatsz == 0) { 23757aec1d6eScindi /* no stats to save */ 23767aec1d6eScindi fmd_buf_destroy(Hdl, NULL, WOBUF_ISTATS); 23777aec1d6eScindi return; 23787aec1d6eScindi } 23797aec1d6eScindi 23807aec1d6eScindi /* create the serialized buffer */ 23817aec1d6eScindi Istatbufptr = Istatbuf = MALLOC(Istatsz); 23827aec1d6eScindi lut_walk(Istats, (lut_cb)istat2str, NULL); 23837aec1d6eScindi 23847aec1d6eScindi /* clear out current saved stats */ 23857aec1d6eScindi fmd_buf_destroy(Hdl, NULL, WOBUF_ISTATS); 23867aec1d6eScindi 23877aec1d6eScindi /* write out the new version */ 23887aec1d6eScindi fmd_buf_write(Hdl, NULL, WOBUF_ISTATS, Istatbuf, Istatsz); 23897aec1d6eScindi FREE(Istatbuf); 23907aec1d6eScindi 23917aec1d6eScindi Istat_need_save = 0; 23927aec1d6eScindi } 23937aec1d6eScindi 23947aec1d6eScindi int 23957aec1d6eScindi istat_cmp(struct istat_entry *ent1, struct istat_entry *ent2) 23967aec1d6eScindi { 23977aec1d6eScindi if (ent1->ename != ent2->ename) 23987aec1d6eScindi return (ent2->ename - ent1->ename); 23997aec1d6eScindi if (ent1->ipath != ent2->ipath) 24007aec1d6eScindi return ((char *)ent2->ipath - (char *)ent1->ipath); 24017aec1d6eScindi 24027aec1d6eScindi return (0); 24037aec1d6eScindi } 24047aec1d6eScindi 24057aec1d6eScindi /* 24067aec1d6eScindi * istat-verify -- verify the component associated with a stat still exists 24077aec1d6eScindi * 24087aec1d6eScindi * if the component no longer exists, this routine resets the stat and 24097aec1d6eScindi * returns 0. if the component still exists, it returns 1. 24107aec1d6eScindi */ 24117aec1d6eScindi static int 24127aec1d6eScindi istat_verify(struct node *snp, struct istat_entry *entp) 24137aec1d6eScindi { 24147aec1d6eScindi struct stats *statp; 24157aec1d6eScindi nvlist_t *fmri; 24167aec1d6eScindi 24177aec1d6eScindi fmri = node2fmri(snp->u.event.epname); 24187aec1d6eScindi if (platform_path_exists(fmri)) { 24197aec1d6eScindi nvlist_free(fmri); 24207aec1d6eScindi return (1); 24217aec1d6eScindi } 24227aec1d6eScindi nvlist_free(fmri); 24237aec1d6eScindi 24247aec1d6eScindi /* component no longer in system. zero out the associated stats */ 24257aec1d6eScindi if ((statp = (struct stats *) 24267aec1d6eScindi lut_lookup(Istats, entp, (lut_cmp)istat_cmp)) == NULL || 24277aec1d6eScindi stats_counter_value(statp) == 0) 24287aec1d6eScindi return (0); /* stat is already reset */ 24297aec1d6eScindi 24307aec1d6eScindi Istat_need_save = 1; 24317aec1d6eScindi stats_counter_reset(statp); 24327aec1d6eScindi return (0); 24337aec1d6eScindi } 24347aec1d6eScindi 24357aec1d6eScindi static void 24367aec1d6eScindi istat_bump(struct node *snp, int n) 24377aec1d6eScindi { 24387aec1d6eScindi struct stats *statp; 24397aec1d6eScindi struct istat_entry ent; 24407aec1d6eScindi 24417aec1d6eScindi ASSERT(snp != NULL); 24427aec1d6eScindi ASSERTinfo(snp->t == T_EVENT, ptree_nodetype2str(snp->t)); 24437aec1d6eScindi ASSERT(snp->u.event.epname != NULL); 24447aec1d6eScindi 24457aec1d6eScindi /* class name should be hoisted into a single stable entry */ 24467aec1d6eScindi ASSERT(snp->u.event.ename->u.name.next == NULL); 24477aec1d6eScindi ent.ename = snp->u.event.ename->u.name.s; 24487aec1d6eScindi ent.ipath = ipath(snp->u.event.epname); 24497aec1d6eScindi 24507aec1d6eScindi if (!istat_verify(snp, &ent)) { 24517aec1d6eScindi /* component no longer exists in system, nothing to do */ 24527aec1d6eScindi return; 24537aec1d6eScindi } 24547aec1d6eScindi 24557aec1d6eScindi if ((statp = (struct stats *) 24567aec1d6eScindi lut_lookup(Istats, &ent, (lut_cmp)istat_cmp)) == NULL) { 24577aec1d6eScindi /* need to create the counter */ 24587aec1d6eScindi int cnt = 0; 24597aec1d6eScindi struct node *np; 24607aec1d6eScindi char *sname; 24617aec1d6eScindi char *snamep; 24627aec1d6eScindi struct istat_entry *newentp; 24637aec1d6eScindi 24647aec1d6eScindi /* count up the size of the stat name */ 24657aec1d6eScindi np = snp->u.event.ename; 24667aec1d6eScindi while (np != NULL) { 24677aec1d6eScindi cnt += strlen(np->u.name.s); 24687aec1d6eScindi cnt++; /* for the '.' or '@' */ 24697aec1d6eScindi np = np->u.name.next; 24707aec1d6eScindi } 24717aec1d6eScindi np = snp->u.event.epname; 24727aec1d6eScindi while (np != NULL) { 24737aec1d6eScindi cnt += snprintf(NULL, 0, "%s%llu", 24747aec1d6eScindi np->u.name.s, np->u.name.child->u.ull); 24757aec1d6eScindi cnt++; /* for the '/' or trailing NULL byte */ 24767aec1d6eScindi np = np->u.name.next; 24777aec1d6eScindi } 24787aec1d6eScindi 24797aec1d6eScindi /* build the stat name */ 24807aec1d6eScindi snamep = sname = alloca(cnt); 24817aec1d6eScindi np = snp->u.event.ename; 24827aec1d6eScindi while (np != NULL) { 24837aec1d6eScindi snamep += snprintf(snamep, &sname[cnt] - snamep, 24847aec1d6eScindi "%s", np->u.name.s); 24857aec1d6eScindi np = np->u.name.next; 24867aec1d6eScindi if (np) 24877aec1d6eScindi *snamep++ = '.'; 24887aec1d6eScindi } 24897aec1d6eScindi *snamep++ = '@'; 24907aec1d6eScindi np = snp->u.event.epname; 24917aec1d6eScindi while (np != NULL) { 24927aec1d6eScindi snamep += snprintf(snamep, &sname[cnt] - snamep, 24937aec1d6eScindi "%s%llu", np->u.name.s, np->u.name.child->u.ull); 24947aec1d6eScindi np = np->u.name.next; 24957aec1d6eScindi if (np) 24967aec1d6eScindi *snamep++ = '/'; 24977aec1d6eScindi } 24987aec1d6eScindi *snamep++ = '\0'; 24997aec1d6eScindi 25007aec1d6eScindi /* create the new stat & add it to our list */ 25017aec1d6eScindi newentp = MALLOC(sizeof (*newentp)); 25027aec1d6eScindi *newentp = ent; 25037aec1d6eScindi statp = stats_new_counter(NULL, sname, 0); 25047aec1d6eScindi Istats = lut_add(Istats, (void *)newentp, (void *)statp, 25057aec1d6eScindi (lut_cmp)istat_cmp); 25067aec1d6eScindi } 25077aec1d6eScindi 25087aec1d6eScindi /* if n is non-zero, set that value instead of bumping */ 25097aec1d6eScindi if (n) { 25107aec1d6eScindi stats_counter_reset(statp); 25117aec1d6eScindi stats_counter_add(statp, n); 25127aec1d6eScindi } else 25137aec1d6eScindi stats_counter_bump(statp); 25147aec1d6eScindi Istat_need_save = 1; 25158a40a695Sgavinm 25168a40a695Sgavinm ipath_print(O_ALTFP|O_VERB2, ent.ename, ent.ipath); 25178a40a695Sgavinm out(O_ALTFP|O_VERB2, " %s to value %d", n ? "set" : "incremented", 25188a40a695Sgavinm stats_counter_value(statp)); 25197aec1d6eScindi } 25207aec1d6eScindi 25217aec1d6eScindi /*ARGSUSED*/ 25227aec1d6eScindi static void 25237aec1d6eScindi istat_destructor(void *left, void *right, void *arg) 25247aec1d6eScindi { 25257aec1d6eScindi struct istat_entry *entp = (struct istat_entry *)left; 25267aec1d6eScindi struct stats *statp = (struct stats *)right; 25277aec1d6eScindi FREE(entp); 25287aec1d6eScindi stats_delete(statp); 25297aec1d6eScindi } 25307aec1d6eScindi 253108f6c065Sgavinm /* 253208f6c065Sgavinm * Callback used in a walk of the Istats to reset matching stat counters. 253308f6c065Sgavinm */ 253408f6c065Sgavinm static void 253508f6c065Sgavinm istat_counter_reset_cb(struct istat_entry *entp, struct stats *statp, 253608f6c065Sgavinm const struct ipath *ipp) 253708f6c065Sgavinm { 253808f6c065Sgavinm char *path; 253908f6c065Sgavinm 254008f6c065Sgavinm if (entp->ipath == ipp) { 254108f6c065Sgavinm path = ipath2str(entp->ename, ipp); 254208f6c065Sgavinm out(O_ALTFP, "istat_counter_reset_cb: resetting %s", path); 254308f6c065Sgavinm FREE(path); 254408f6c065Sgavinm stats_counter_reset(statp); 254508f6c065Sgavinm Istat_need_save = 1; 254608f6c065Sgavinm } 254708f6c065Sgavinm } 254808f6c065Sgavinm 2549e5ba14ffSstephh /*ARGSUSED*/ 2550e5ba14ffSstephh static void 2551e5ba14ffSstephh istat_counter_topo_chg_cb(struct istat_entry *entp, struct stats *statp, 2552e5ba14ffSstephh void *unused) 2553e5ba14ffSstephh { 2554e5ba14ffSstephh char *path; 2555e5ba14ffSstephh nvlist_t *fmri; 2556e5ba14ffSstephh 2557e5ba14ffSstephh fmri = ipath2fmri((struct ipath *)(entp->ipath)); 2558e5ba14ffSstephh if (!platform_path_exists(fmri)) { 2559e5ba14ffSstephh path = ipath2str(entp->ename, entp->ipath); 2560e5ba14ffSstephh out(O_ALTFP, "istat_counter_topo_chg_cb: not present %s", path); 2561e5ba14ffSstephh FREE(path); 2562e5ba14ffSstephh stats_counter_reset(statp); 2563e5ba14ffSstephh Istat_need_save = 1; 2564e5ba14ffSstephh } 2565e5ba14ffSstephh nvlist_free(fmri); 2566e5ba14ffSstephh } 2567e5ba14ffSstephh 25687aec1d6eScindi void 25697aec1d6eScindi istat_fini(void) 25707aec1d6eScindi { 25717aec1d6eScindi lut_free(Istats, istat_destructor, NULL); 25727aec1d6eScindi } 25737aec1d6eScindi 2574b5016cbbSstephh static char *Serdbuf; 2575b5016cbbSstephh static char *Serdbufptr; 2576b5016cbbSstephh static int Serdsz; 2577b5016cbbSstephh 2578b5016cbbSstephh /* 2579b5016cbbSstephh * serdaddsize -- calculate size of serd and add it to Serdsz 2580b5016cbbSstephh */ 2581b5016cbbSstephh /*ARGSUSED*/ 2582b5016cbbSstephh static void 2583b5016cbbSstephh serdaddsize(const struct serd_entry *lhs, struct stats *rhs, void *arg) 2584b5016cbbSstephh { 2585b5016cbbSstephh ASSERT(lhs != NULL); 2586b5016cbbSstephh 2587b5016cbbSstephh /* count up the size of the stat name */ 2588b5016cbbSstephh Serdsz += ipath2strlen(lhs->ename, lhs->ipath); 2589b5016cbbSstephh Serdsz++; /* for the trailing NULL byte */ 2590b5016cbbSstephh } 2591b5016cbbSstephh 2592b5016cbbSstephh /* 2593b5016cbbSstephh * serd2str -- serialize a serd engine, writing result to *Serdbufptr 2594b5016cbbSstephh */ 2595b5016cbbSstephh /*ARGSUSED*/ 2596b5016cbbSstephh static void 2597b5016cbbSstephh serd2str(const struct serd_entry *lhs, struct stats *rhs, void *arg) 2598b5016cbbSstephh { 2599b5016cbbSstephh char *str; 2600b5016cbbSstephh int len; 2601b5016cbbSstephh 2602b5016cbbSstephh ASSERT(lhs != NULL); 2603b5016cbbSstephh 2604b5016cbbSstephh /* serialize the serd engine name */ 2605b5016cbbSstephh str = ipath2str(lhs->ename, lhs->ipath); 2606b5016cbbSstephh len = strlen(str); 2607b5016cbbSstephh 2608b5016cbbSstephh ASSERT(Serdbufptr + len + 1 <= &Serdbuf[Serdsz]); 2609b5016cbbSstephh (void) strlcpy(Serdbufptr, str, &Serdbuf[Serdsz] - Serdbufptr); 2610b5016cbbSstephh Serdbufptr += len; 2611b5016cbbSstephh FREE(str); 2612b5016cbbSstephh *Serdbufptr++ = '\0'; 2613b5016cbbSstephh ASSERT(Serdbufptr <= &Serdbuf[Serdsz]); 2614b5016cbbSstephh } 2615b5016cbbSstephh 2616b5016cbbSstephh void 2617b5016cbbSstephh serd_save() 2618b5016cbbSstephh { 2619b5016cbbSstephh if (Serd_need_save == 0) 2620b5016cbbSstephh return; 2621b5016cbbSstephh 2622b5016cbbSstephh /* figure out how big the serialzed info is */ 2623b5016cbbSstephh Serdsz = 0; 2624b5016cbbSstephh lut_walk(SerdEngines, (lut_cb)serdaddsize, NULL); 2625b5016cbbSstephh 2626b5016cbbSstephh if (Serdsz == 0) { 2627b5016cbbSstephh /* no serd engines to save */ 2628b5016cbbSstephh fmd_buf_destroy(Hdl, NULL, WOBUF_SERDS); 2629b5016cbbSstephh return; 2630b5016cbbSstephh } 2631b5016cbbSstephh 2632b5016cbbSstephh /* create the serialized buffer */ 2633b5016cbbSstephh Serdbufptr = Serdbuf = MALLOC(Serdsz); 2634b5016cbbSstephh lut_walk(SerdEngines, (lut_cb)serd2str, NULL); 2635b5016cbbSstephh 2636b5016cbbSstephh /* clear out current saved stats */ 2637b5016cbbSstephh fmd_buf_destroy(Hdl, NULL, WOBUF_SERDS); 2638b5016cbbSstephh 2639b5016cbbSstephh /* write out the new version */ 2640b5016cbbSstephh fmd_buf_write(Hdl, NULL, WOBUF_SERDS, Serdbuf, Serdsz); 2641b5016cbbSstephh FREE(Serdbuf); 2642b5016cbbSstephh Serd_need_save = 0; 2643b5016cbbSstephh } 2644b5016cbbSstephh 2645b5016cbbSstephh int 2646b5016cbbSstephh serd_cmp(struct serd_entry *ent1, struct serd_entry *ent2) 2647b5016cbbSstephh { 2648b5016cbbSstephh if (ent1->ename != ent2->ename) 2649b5016cbbSstephh return (ent2->ename - ent1->ename); 2650b5016cbbSstephh if (ent1->ipath != ent2->ipath) 2651b5016cbbSstephh return ((char *)ent2->ipath - (char *)ent1->ipath); 2652b5016cbbSstephh 2653b5016cbbSstephh return (0); 2654b5016cbbSstephh } 2655b5016cbbSstephh 2656b5016cbbSstephh void 2657b5016cbbSstephh fme_serd_load(fmd_hdl_t *hdl) 2658b5016cbbSstephh { 2659b5016cbbSstephh int sz; 2660b5016cbbSstephh char *sbuf; 2661b5016cbbSstephh char *sepptr; 2662b5016cbbSstephh char *ptr; 2663b5016cbbSstephh struct serd_entry *newentp; 2664b5016cbbSstephh struct node *epname; 2665b5016cbbSstephh nvlist_t *fmri; 2666b5016cbbSstephh char *namestring; 2667b5016cbbSstephh 2668b5016cbbSstephh if ((sz = fmd_buf_size(hdl, NULL, WOBUF_SERDS)) == 0) 2669b5016cbbSstephh return; 2670b5016cbbSstephh sbuf = alloca(sz); 2671b5016cbbSstephh fmd_buf_read(hdl, NULL, WOBUF_SERDS, sbuf, sz); 2672b5016cbbSstephh ptr = sbuf; 2673b5016cbbSstephh while (ptr < &sbuf[sz]) { 2674b5016cbbSstephh sepptr = strchr(ptr, '@'); 2675b5016cbbSstephh *sepptr = '\0'; 2676b5016cbbSstephh namestring = ptr; 2677b5016cbbSstephh sepptr++; 2678b5016cbbSstephh ptr = sepptr; 2679b5016cbbSstephh ptr += strlen(ptr); 2680b5016cbbSstephh ptr++; /* move past the '\0' separating paths */ 2681b5016cbbSstephh epname = pathstring2epnamenp(sepptr); 2682b5016cbbSstephh fmri = node2fmri(epname); 2683b5016cbbSstephh if (platform_path_exists(fmri)) { 2684b5016cbbSstephh newentp = MALLOC(sizeof (*newentp)); 2685b5016cbbSstephh newentp->hdl = hdl; 2686b5016cbbSstephh newentp->ipath = ipath(epname); 2687b5016cbbSstephh newentp->ename = stable(namestring); 2688b5016cbbSstephh SerdEngines = lut_add(SerdEngines, (void *)newentp, 2689e5ba14ffSstephh (void *)newentp, (lut_cmp)serd_cmp); 2690b5016cbbSstephh } else 2691b5016cbbSstephh Serd_need_save = 1; 2692e5ba14ffSstephh tree_free(epname); 2693b5016cbbSstephh nvlist_free(fmri); 2694b5016cbbSstephh } 2695b5016cbbSstephh /* save it back again in case some of the paths no longer exist */ 2696b5016cbbSstephh serd_save(); 2697b5016cbbSstephh } 2698b5016cbbSstephh 2699b5016cbbSstephh /*ARGSUSED*/ 2700b5016cbbSstephh static void 2701b5016cbbSstephh serd_destructor(void *left, void *right, void *arg) 2702b5016cbbSstephh { 2703b5016cbbSstephh struct serd_entry *entp = (struct serd_entry *)left; 2704b5016cbbSstephh FREE(entp); 2705b5016cbbSstephh } 2706b5016cbbSstephh 2707b5016cbbSstephh /* 2708b5016cbbSstephh * Callback used in a walk of the SerdEngines to reset matching serd engines. 2709b5016cbbSstephh */ 2710b5016cbbSstephh /*ARGSUSED*/ 2711b5016cbbSstephh static void 2712b5016cbbSstephh serd_reset_cb(struct serd_entry *entp, void *unused, const struct ipath *ipp) 2713b5016cbbSstephh { 2714b5016cbbSstephh char *path; 2715b5016cbbSstephh 2716b5016cbbSstephh if (entp->ipath == ipp) { 2717b5016cbbSstephh path = ipath2str(entp->ename, ipp); 2718b5016cbbSstephh out(O_ALTFP, "serd_reset_cb: resetting %s", path); 2719b5016cbbSstephh fmd_serd_reset(entp->hdl, path); 2720b5016cbbSstephh FREE(path); 2721b5016cbbSstephh Serd_need_save = 1; 2722b5016cbbSstephh } 2723b5016cbbSstephh } 2724b5016cbbSstephh 2725e5ba14ffSstephh /*ARGSUSED*/ 2726e5ba14ffSstephh static void 2727e5ba14ffSstephh serd_topo_chg_cb(struct serd_entry *entp, void *unused, void *unused2) 2728e5ba14ffSstephh { 2729e5ba14ffSstephh char *path; 2730e5ba14ffSstephh nvlist_t *fmri; 2731e5ba14ffSstephh 2732e5ba14ffSstephh fmri = ipath2fmri((struct ipath *)(entp->ipath)); 2733e5ba14ffSstephh if (!platform_path_exists(fmri)) { 2734e5ba14ffSstephh path = ipath2str(entp->ename, entp->ipath); 2735e5ba14ffSstephh out(O_ALTFP, "serd_topo_chg_cb: not present %s", path); 2736e5ba14ffSstephh fmd_serd_reset(entp->hdl, path); 2737e5ba14ffSstephh FREE(path); 2738e5ba14ffSstephh Serd_need_save = 1; 2739e5ba14ffSstephh } 2740e5ba14ffSstephh nvlist_free(fmri); 2741e5ba14ffSstephh } 2742e5ba14ffSstephh 2743b5016cbbSstephh void 2744b5016cbbSstephh serd_fini(void) 2745b5016cbbSstephh { 2746b5016cbbSstephh lut_free(SerdEngines, serd_destructor, NULL); 2747b5016cbbSstephh } 2748b5016cbbSstephh 27497c478bd9Sstevel@tonic-gate static void 2750b7d3956bSstephh publish_suspects(struct fme *fmep, struct rsl *srl) 27517c478bd9Sstevel@tonic-gate { 27527c478bd9Sstevel@tonic-gate struct rsl *rp; 27537c478bd9Sstevel@tonic-gate nvlist_t *fault; 27547c478bd9Sstevel@tonic-gate uint8_t cert; 27557c478bd9Sstevel@tonic-gate uint_t *frs; 27568e7248e5SStephen Hanson uint_t frsum, fr; 27577aec1d6eScindi uint_t messval; 2758b7d3956bSstephh uint_t retireval; 2759b7d3956bSstephh uint_t responseval; 27607aec1d6eScindi struct node *snp; 27617c478bd9Sstevel@tonic-gate int frcnt, fridx; 27627aec1d6eScindi boolean_t allfaulty = B_TRUE; 2763b7d3956bSstephh struct rsl *erl = srl + fmep->nsuspects - 1; 27647c478bd9Sstevel@tonic-gate 27657c478bd9Sstevel@tonic-gate /* 2766b7d3956bSstephh * sort the array 27677c478bd9Sstevel@tonic-gate */ 2768b7d3956bSstephh qsort(srl, fmep->nsuspects, sizeof (struct rsl), rslcmp); 27697c478bd9Sstevel@tonic-gate 27708e7248e5SStephen Hanson /* sum the fitrates */ 27718e7248e5SStephen Hanson frs = alloca(fmep->nsuspects * sizeof (uint_t)); 27728e7248e5SStephen Hanson fridx = frcnt = frsum = 0; 27737c478bd9Sstevel@tonic-gate 27748e7248e5SStephen Hanson for (rp = srl; rp <= erl; rp++) { 27758e7248e5SStephen Hanson struct node *n; 27767c478bd9Sstevel@tonic-gate 27778e7248e5SStephen Hanson n = eventprop_lookup(rp->suspect, L_FITrate); 27788e7248e5SStephen Hanson if (node2uint(n, &fr) != 0) { 27798e7248e5SStephen Hanson out(O_DEBUG|O_NONL, "event "); 27808e7248e5SStephen Hanson ipath_print(O_DEBUG|O_NONL, 27818e7248e5SStephen Hanson rp->suspect->enode->u.event.ename->u.name.s, 27828e7248e5SStephen Hanson rp->suspect->ipp); 2783f6e214c7SGavin Maltby out(O_VERB, " has no FITrate (using 1)"); 27848e7248e5SStephen Hanson fr = 1; 27858e7248e5SStephen Hanson } else if (fr == 0) { 27868e7248e5SStephen Hanson out(O_DEBUG|O_NONL, "event "); 27878e7248e5SStephen Hanson ipath_print(O_DEBUG|O_NONL, 27888e7248e5SStephen Hanson rp->suspect->enode->u.event.ename->u.name.s, 27898e7248e5SStephen Hanson rp->suspect->ipp); 2790f6e214c7SGavin Maltby out(O_VERB, " has zero FITrate (using 1)"); 27918e7248e5SStephen Hanson fr = 1; 27927c478bd9Sstevel@tonic-gate } 27938e7248e5SStephen Hanson 27948e7248e5SStephen Hanson frs[fridx++] = fr; 27958e7248e5SStephen Hanson frsum += fr; 27968e7248e5SStephen Hanson frcnt++; 27977c478bd9Sstevel@tonic-gate } 27987c478bd9Sstevel@tonic-gate 27997c478bd9Sstevel@tonic-gate /* Add them in reverse order of our sort, as fmd reverses order */ 28007c478bd9Sstevel@tonic-gate for (rp = erl; rp >= srl; rp--) { 28018e7248e5SStephen Hanson cert = percentof(frs[--fridx], frsum); 28027c478bd9Sstevel@tonic-gate fault = fmd_nvl_create_fault(fmep->hdl, 28037c478bd9Sstevel@tonic-gate rp->suspect->enode->u.event.ename->u.name.s, 28047c478bd9Sstevel@tonic-gate cert, 28057c478bd9Sstevel@tonic-gate rp->asru, 28067c478bd9Sstevel@tonic-gate rp->fru, 28077c478bd9Sstevel@tonic-gate rp->rsrc); 28087c478bd9Sstevel@tonic-gate if (fault == NULL) 28097c478bd9Sstevel@tonic-gate out(O_DIE, "fault creation failed"); 28107aec1d6eScindi /* if "message" property exists, add it to the fault */ 28117aec1d6eScindi if (node2uint(eventprop_lookup(rp->suspect, L_message), 28127aec1d6eScindi &messval) == 0) { 28137aec1d6eScindi 28147aec1d6eScindi out(O_ALTFP, 28157aec1d6eScindi "[FME%d, %s adds message=%d to suspect list]", 28167aec1d6eScindi fmep->id, 28177aec1d6eScindi rp->suspect->enode->u.event.ename->u.name.s, 28187aec1d6eScindi messval); 28197aec1d6eScindi if (nvlist_add_boolean_value(fault, 28207aec1d6eScindi FM_SUSPECT_MESSAGE, 28217aec1d6eScindi (messval) ? B_TRUE : B_FALSE) != 0) { 28227aec1d6eScindi out(O_DIE, "cannot add no-message to fault"); 28237aec1d6eScindi } 28247aec1d6eScindi } 2825b7d3956bSstephh 2826b7d3956bSstephh /* if "retire" property exists, add it to the fault */ 2827b7d3956bSstephh if (node2uint(eventprop_lookup(rp->suspect, L_retire), 2828b7d3956bSstephh &retireval) == 0) { 2829b7d3956bSstephh 2830b7d3956bSstephh out(O_ALTFP, 2831b7d3956bSstephh "[FME%d, %s adds retire=%d to suspect list]", 2832b7d3956bSstephh fmep->id, 2833b7d3956bSstephh rp->suspect->enode->u.event.ename->u.name.s, 2834b7d3956bSstephh retireval); 2835b7d3956bSstephh if (nvlist_add_boolean_value(fault, 2836b7d3956bSstephh FM_SUSPECT_RETIRE, 2837b7d3956bSstephh (retireval) ? B_TRUE : B_FALSE) != 0) { 2838b7d3956bSstephh out(O_DIE, "cannot add no-retire to fault"); 2839b7d3956bSstephh } 2840b7d3956bSstephh } 2841b7d3956bSstephh 2842b7d3956bSstephh /* if "response" property exists, add it to the fault */ 2843b7d3956bSstephh if (node2uint(eventprop_lookup(rp->suspect, L_response), 2844b7d3956bSstephh &responseval) == 0) { 2845b7d3956bSstephh 2846b7d3956bSstephh out(O_ALTFP, 2847b7d3956bSstephh "[FME%d, %s adds response=%d to suspect list]", 2848b7d3956bSstephh fmep->id, 2849b7d3956bSstephh rp->suspect->enode->u.event.ename->u.name.s, 2850b7d3956bSstephh responseval); 2851b7d3956bSstephh if (nvlist_add_boolean_value(fault, 2852b7d3956bSstephh FM_SUSPECT_RESPONSE, 2853b7d3956bSstephh (responseval) ? B_TRUE : B_FALSE) != 0) { 2854b7d3956bSstephh out(O_DIE, "cannot add no-response to fault"); 2855b7d3956bSstephh } 2856b7d3956bSstephh } 2857b7d3956bSstephh 28587aec1d6eScindi /* add any payload properties */ 28597aec1d6eScindi lut_walk(rp->suspect->payloadprops, 28607aec1d6eScindi (lut_cb)addpayloadprop, (void *)fault); 28617c478bd9Sstevel@tonic-gate rslfree(rp); 28625f25dc2aSgavinm 28635f25dc2aSgavinm /* 28645f25dc2aSgavinm * If "action" property exists, evaluate it; this must be done 2865b7d3956bSstephh * before the allfaulty check below since some actions may 286625c6ff4bSstephh * modify the asru to be used in fmd_nvl_fmri_has_fault. This 28675f25dc2aSgavinm * needs to be restructured if any new actions are introduced 28685f25dc2aSgavinm * that have effects that we do not want to be visible if 28695f25dc2aSgavinm * we decide not to publish in the dupclose check below. 28705f25dc2aSgavinm */ 28717aec1d6eScindi if ((snp = eventprop_lookup(rp->suspect, L_action)) != NULL) { 28727aec1d6eScindi struct evalue evalue; 28737aec1d6eScindi 28747aec1d6eScindi out(O_ALTFP|O_NONL, 28757aec1d6eScindi "[FME%d, %s action ", fmep->id, 28767aec1d6eScindi rp->suspect->enode->u.event.ename->u.name.s); 28777aec1d6eScindi ptree_name_iter(O_ALTFP|O_NONL, snp); 28787aec1d6eScindi out(O_ALTFP, "]"); 28797aec1d6eScindi Action_nvl = fault; 28807aec1d6eScindi (void) eval_expr(snp, NULL, NULL, NULL, NULL, 28817aec1d6eScindi NULL, 0, &evalue); 28827aec1d6eScindi } 28835f25dc2aSgavinm 2884b7d3956bSstephh fmd_case_add_suspect(fmep->hdl, fmep->fmcase, fault); 2885b7d3956bSstephh 28867aec1d6eScindi /* 2887567cc2e6Sstephh * check if the asru is already marked as "faulty". 28887aec1d6eScindi */ 2889567cc2e6Sstephh if (allfaulty) { 28907aec1d6eScindi nvlist_t *asru; 28917aec1d6eScindi 2892b7d3956bSstephh out(O_ALTFP|O_VERB, "FME%d dup check ", fmep->id); 28937aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, rp->suspect); 28947aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " "); 28957aec1d6eScindi if (nvlist_lookup_nvlist(fault, 28967aec1d6eScindi FM_FAULT_ASRU, &asru) != 0) { 28977aec1d6eScindi out(O_ALTFP|O_VERB, "NULL asru"); 28987aec1d6eScindi allfaulty = B_FALSE; 289925c6ff4bSstephh } else if (fmd_nvl_fmri_has_fault(fmep->hdl, asru, 290025c6ff4bSstephh FMD_HAS_FAULT_ASRU, NULL)) { 29017aec1d6eScindi out(O_ALTFP|O_VERB, "faulty"); 29027aec1d6eScindi } else { 29037aec1d6eScindi out(O_ALTFP|O_VERB, "not faulty"); 29047aec1d6eScindi allfaulty = B_FALSE; 29057aec1d6eScindi } 29067aec1d6eScindi } 29077aec1d6eScindi 29087aec1d6eScindi } 29095f25dc2aSgavinm 2910567cc2e6Sstephh if (!allfaulty) { 2911567cc2e6Sstephh /* 2912567cc2e6Sstephh * don't update the count stat if all asrus are already 2913567cc2e6Sstephh * present and unrepaired in the asru cache 2914567cc2e6Sstephh */ 29155f25dc2aSgavinm for (rp = erl; rp >= srl; rp--) { 29165f25dc2aSgavinm struct event *suspect = rp->suspect; 29175f25dc2aSgavinm 29185f25dc2aSgavinm if (suspect == NULL) 29195f25dc2aSgavinm continue; 29205f25dc2aSgavinm 29215f25dc2aSgavinm /* if "count" exists, increment the appropriate stat */ 29225f25dc2aSgavinm if ((snp = eventprop_lookup(suspect, 29235f25dc2aSgavinm L_count)) != NULL) { 29245f25dc2aSgavinm out(O_ALTFP|O_NONL, 29255f25dc2aSgavinm "[FME%d, %s count ", fmep->id, 29265f25dc2aSgavinm suspect->enode->u.event.ename->u.name.s); 29275f25dc2aSgavinm ptree_name_iter(O_ALTFP|O_NONL, snp); 29285f25dc2aSgavinm out(O_ALTFP, "]"); 29295f25dc2aSgavinm istat_bump(snp, 0); 29305f25dc2aSgavinm 29315f25dc2aSgavinm } 29325f25dc2aSgavinm } 29335f25dc2aSgavinm istat_save(); /* write out any istat changes */ 29347c478bd9Sstevel@tonic-gate } 29357c478bd9Sstevel@tonic-gate } 29367c478bd9Sstevel@tonic-gate 293732d4e834STarik Soydan static const char * 293832d4e834STarik Soydan undiag_2defect_str(int ud) 293932d4e834STarik Soydan { 294032d4e834STarik Soydan switch (ud) { 294132d4e834STarik Soydan case UD_VAL_MISSINGINFO: 294232d4e834STarik Soydan case UD_VAL_MISSINGOBS: 294332d4e834STarik Soydan case UD_VAL_MISSINGPATH: 294432d4e834STarik Soydan case UD_VAL_MISSINGZERO: 294532d4e834STarik Soydan case UD_VAL_BADOBS: 294632d4e834STarik Soydan case UD_VAL_CFGMISMATCH: 294732d4e834STarik Soydan return (UNDIAG_DEFECT_CHKPT); 294832d4e834STarik Soydan 294932d4e834STarik Soydan case UD_VAL_BADEVENTI: 2950705e9f42SStephen Hanson case UD_VAL_BADEVENTPATH: 2951705e9f42SStephen Hanson case UD_VAL_BADEVENTCLASS: 295232d4e834STarik Soydan case UD_VAL_INSTFAIL: 295332d4e834STarik Soydan case UD_VAL_NOPATH: 295432d4e834STarik Soydan case UD_VAL_UNSOLVD: 295532d4e834STarik Soydan return (UNDIAG_DEFECT_FME); 295632d4e834STarik Soydan 295732d4e834STarik Soydan case UD_VAL_MAXFME: 295832d4e834STarik Soydan return (UNDIAG_DEFECT_LIMIT); 295932d4e834STarik Soydan 296032d4e834STarik Soydan case UD_VAL_UNKNOWN: 296132d4e834STarik Soydan default: 296232d4e834STarik Soydan return (UNDIAG_DEFECT_UNKNOWN); 296332d4e834STarik Soydan } 296432d4e834STarik Soydan } 296532d4e834STarik Soydan 2966705e9f42SStephen Hanson static const char * 2967705e9f42SStephen Hanson undiag_2fault_str(int ud) 296832d4e834STarik Soydan { 296932d4e834STarik Soydan switch (ud) { 297032d4e834STarik Soydan case UD_VAL_BADEVENTI: 2971705e9f42SStephen Hanson case UD_VAL_BADEVENTPATH: 2972705e9f42SStephen Hanson case UD_VAL_BADEVENTCLASS: 2973705e9f42SStephen Hanson case UD_VAL_INSTFAIL: 2974705e9f42SStephen Hanson case UD_VAL_NOPATH: 2975705e9f42SStephen Hanson case UD_VAL_UNSOLVD: 2976705e9f42SStephen Hanson return (UNDIAG_FAULT_FME); 2977705e9f42SStephen Hanson default: 2978705e9f42SStephen Hanson return (NULL); 2979705e9f42SStephen Hanson } 2980705e9f42SStephen Hanson } 2981705e9f42SStephen Hanson 2982705e9f42SStephen Hanson static char * 2983705e9f42SStephen Hanson undiag_2reason_str(int ud, char *arg) 2984705e9f42SStephen Hanson { 2985705e9f42SStephen Hanson const char *ptr; 2986705e9f42SStephen Hanson char *buf; 2987705e9f42SStephen Hanson int with_arg = 0; 2988705e9f42SStephen Hanson 2989705e9f42SStephen Hanson switch (ud) { 2990705e9f42SStephen Hanson case UD_VAL_BADEVENTPATH: 2991705e9f42SStephen Hanson ptr = UD_STR_BADEVENTPATH; 2992705e9f42SStephen Hanson with_arg = 1; 2993705e9f42SStephen Hanson break; 2994705e9f42SStephen Hanson case UD_VAL_BADEVENTCLASS: 2995705e9f42SStephen Hanson ptr = UD_STR_BADEVENTCLASS; 2996705e9f42SStephen Hanson with_arg = 1; 2997705e9f42SStephen Hanson break; 2998705e9f42SStephen Hanson case UD_VAL_BADEVENTI: 2999705e9f42SStephen Hanson ptr = UD_STR_BADEVENTI; 3000705e9f42SStephen Hanson with_arg = 1; 3001705e9f42SStephen Hanson break; 300232d4e834STarik Soydan case UD_VAL_BADOBS: 3003705e9f42SStephen Hanson ptr = UD_STR_BADOBS; 3004705e9f42SStephen Hanson break; 300532d4e834STarik Soydan case UD_VAL_CFGMISMATCH: 3006705e9f42SStephen Hanson ptr = UD_STR_CFGMISMATCH; 3007705e9f42SStephen Hanson break; 300832d4e834STarik Soydan case UD_VAL_INSTFAIL: 3009705e9f42SStephen Hanson ptr = UD_STR_INSTFAIL; 3010705e9f42SStephen Hanson with_arg = 1; 3011705e9f42SStephen Hanson break; 301232d4e834STarik Soydan case UD_VAL_MAXFME: 3013705e9f42SStephen Hanson ptr = UD_STR_MAXFME; 3014705e9f42SStephen Hanson break; 301532d4e834STarik Soydan case UD_VAL_MISSINGINFO: 3016705e9f42SStephen Hanson ptr = UD_STR_MISSINGINFO; 3017705e9f42SStephen Hanson break; 301832d4e834STarik Soydan case UD_VAL_MISSINGOBS: 3019705e9f42SStephen Hanson ptr = UD_STR_MISSINGOBS; 3020705e9f42SStephen Hanson break; 302132d4e834STarik Soydan case UD_VAL_MISSINGPATH: 3022705e9f42SStephen Hanson ptr = UD_STR_MISSINGPATH; 3023705e9f42SStephen Hanson break; 302432d4e834STarik Soydan case UD_VAL_MISSINGZERO: 3025705e9f42SStephen Hanson ptr = UD_STR_MISSINGZERO; 3026705e9f42SStephen Hanson break; 302732d4e834STarik Soydan case UD_VAL_NOPATH: 3028705e9f42SStephen Hanson ptr = UD_STR_NOPATH; 3029705e9f42SStephen Hanson with_arg = 1; 3030705e9f42SStephen Hanson break; 303132d4e834STarik Soydan case UD_VAL_UNSOLVD: 3032705e9f42SStephen Hanson ptr = UD_STR_UNSOLVD; 3033705e9f42SStephen Hanson break; 303432d4e834STarik Soydan case UD_VAL_UNKNOWN: 303532d4e834STarik Soydan default: 3036705e9f42SStephen Hanson ptr = UD_STR_UNKNOWN; 3037705e9f42SStephen Hanson break; 303832d4e834STarik Soydan } 3039705e9f42SStephen Hanson if (with_arg) { 3040705e9f42SStephen Hanson buf = MALLOC(strlen(ptr) + strlen(arg) - 1); 3041705e9f42SStephen Hanson (void) sprintf(buf, ptr, arg); 3042705e9f42SStephen Hanson } else { 3043705e9f42SStephen Hanson buf = MALLOC(strlen(ptr) + 1); 3044705e9f42SStephen Hanson (void) sprintf(buf, ptr); 3045705e9f42SStephen Hanson } 3046705e9f42SStephen Hanson return (buf); 304732d4e834STarik Soydan } 304832d4e834STarik Soydan 30497c478bd9Sstevel@tonic-gate static void 3050705e9f42SStephen Hanson publish_undiagnosable(fmd_hdl_t *hdl, fmd_event_t *ffep, fmd_case_t *fmcase, 3051705e9f42SStephen Hanson nvlist_t *detector, char *arg) 30527c478bd9Sstevel@tonic-gate { 30537c478bd9Sstevel@tonic-gate struct case_list *newcase; 3054705e9f42SStephen Hanson nvlist_t *defect, *fault; 3055705e9f42SStephen Hanson const char *faultstr; 3056705e9f42SStephen Hanson char *reason = undiag_2reason_str(Undiag_reason, arg); 30577c478bd9Sstevel@tonic-gate 30587c478bd9Sstevel@tonic-gate out(O_ALTFP, 30597c478bd9Sstevel@tonic-gate "[undiagnosable ereport received, " 3060705e9f42SStephen Hanson "creating and closing a new case (%s)]", reason); 30617c478bd9Sstevel@tonic-gate 30627c478bd9Sstevel@tonic-gate newcase = MALLOC(sizeof (struct case_list)); 30637c478bd9Sstevel@tonic-gate newcase->next = NULL; 3064b5016cbbSstephh newcase->fmcase = fmcase; 30657c478bd9Sstevel@tonic-gate if (Undiagablecaselist != NULL) 30667c478bd9Sstevel@tonic-gate newcase->next = Undiagablecaselist; 30677c478bd9Sstevel@tonic-gate Undiagablecaselist = newcase; 30687c478bd9Sstevel@tonic-gate 30697c478bd9Sstevel@tonic-gate if (ffep != NULL) 30707c478bd9Sstevel@tonic-gate fmd_case_add_ereport(hdl, newcase->fmcase, ffep); 30717c478bd9Sstevel@tonic-gate 3072705e9f42SStephen Hanson /* add defect */ 307332d4e834STarik Soydan defect = fmd_nvl_create_fault(hdl, 3074705e9f42SStephen Hanson undiag_2defect_str(Undiag_reason), 50, NULL, NULL, detector); 3075705e9f42SStephen Hanson (void) nvlist_add_string(defect, UNDIAG_REASON, reason); 3076705e9f42SStephen Hanson (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RETIRE, B_FALSE); 3077705e9f42SStephen Hanson (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RESPONSE, B_FALSE); 30787c478bd9Sstevel@tonic-gate fmd_case_add_suspect(hdl, newcase->fmcase, defect); 30797c478bd9Sstevel@tonic-gate 3080705e9f42SStephen Hanson /* add fault if appropriate */ 3081705e9f42SStephen Hanson faultstr = undiag_2fault_str(Undiag_reason); 3082705e9f42SStephen Hanson if (faultstr != NULL) { 3083705e9f42SStephen Hanson fault = fmd_nvl_create_fault(hdl, faultstr, 50, NULL, NULL, 3084705e9f42SStephen Hanson detector); 3085705e9f42SStephen Hanson (void) nvlist_add_string(fault, UNDIAG_REASON, reason); 3086705e9f42SStephen Hanson (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RETIRE, 3087705e9f42SStephen Hanson B_FALSE); 3088705e9f42SStephen Hanson (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RESPONSE, 3089705e9f42SStephen Hanson B_FALSE); 3090705e9f42SStephen Hanson fmd_case_add_suspect(hdl, newcase->fmcase, fault); 3091705e9f42SStephen Hanson } 3092705e9f42SStephen Hanson FREE(reason); 3093705e9f42SStephen Hanson 3094705e9f42SStephen Hanson /* solve and close case */ 30957c478bd9Sstevel@tonic-gate fmd_case_solve(hdl, newcase->fmcase); 30967c478bd9Sstevel@tonic-gate fmd_case_close(hdl, newcase->fmcase); 309732d4e834STarik Soydan Undiag_reason = UD_VAL_UNKNOWN; 30987c478bd9Sstevel@tonic-gate } 30997c478bd9Sstevel@tonic-gate 31007c478bd9Sstevel@tonic-gate static void 31017c478bd9Sstevel@tonic-gate fme_undiagnosable(struct fme *f) 31027c478bd9Sstevel@tonic-gate { 3103705e9f42SStephen Hanson nvlist_t *defect, *fault, *detector = NULL; 3104705e9f42SStephen Hanson struct event *ep; 3105705e9f42SStephen Hanson char *pathstr; 3106705e9f42SStephen Hanson const char *faultstr; 3107705e9f42SStephen Hanson char *reason = undiag_2reason_str(Undiag_reason, NULL); 31087c478bd9Sstevel@tonic-gate 31097c478bd9Sstevel@tonic-gate out(O_ALTFP, "[solving/closing FME%d, case %s (%s)]", 3110705e9f42SStephen Hanson f->id, fmd_case_uuid(f->hdl, f->fmcase), reason); 3111705e9f42SStephen Hanson 3112705e9f42SStephen Hanson for (ep = f->observations; ep; ep = ep->observations) { 3113705e9f42SStephen Hanson 3114705e9f42SStephen Hanson if (ep->ffep != f->e0r) 3115705e9f42SStephen Hanson fmd_case_add_ereport(f->hdl, f->fmcase, ep->ffep); 3116705e9f42SStephen Hanson 3117705e9f42SStephen Hanson pathstr = ipath2str(NULL, ipath(platform_getpath(ep->nvp))); 3118705e9f42SStephen Hanson platform_units_translate(0, f->config, NULL, NULL, &detector, 3119705e9f42SStephen Hanson pathstr); 3120705e9f42SStephen Hanson FREE(pathstr); 3121705e9f42SStephen Hanson 3122705e9f42SStephen Hanson /* add defect */ 3123705e9f42SStephen Hanson defect = fmd_nvl_create_fault(f->hdl, 3124705e9f42SStephen Hanson undiag_2defect_str(Undiag_reason), 50 / f->uniqobs, 3125705e9f42SStephen Hanson NULL, NULL, detector); 3126705e9f42SStephen Hanson (void) nvlist_add_string(defect, UNDIAG_REASON, reason); 3127705e9f42SStephen Hanson (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RETIRE, 3128705e9f42SStephen Hanson B_FALSE); 3129705e9f42SStephen Hanson (void) nvlist_add_boolean_value(defect, FM_SUSPECT_RESPONSE, 3130705e9f42SStephen Hanson B_FALSE); 3131705e9f42SStephen Hanson fmd_case_add_suspect(f->hdl, f->fmcase, defect); 3132705e9f42SStephen Hanson 3133705e9f42SStephen Hanson /* add fault if appropriate */ 3134705e9f42SStephen Hanson faultstr = undiag_2fault_str(Undiag_reason); 3135705e9f42SStephen Hanson if (faultstr == NULL) 3136705e9f42SStephen Hanson continue; 3137705e9f42SStephen Hanson fault = fmd_nvl_create_fault(f->hdl, faultstr, 50 / f->uniqobs, 3138705e9f42SStephen Hanson NULL, NULL, detector); 3139705e9f42SStephen Hanson (void) nvlist_add_string(fault, UNDIAG_REASON, reason); 3140705e9f42SStephen Hanson (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RETIRE, 3141705e9f42SStephen Hanson B_FALSE); 3142705e9f42SStephen Hanson (void) nvlist_add_boolean_value(fault, FM_SUSPECT_RESPONSE, 3143705e9f42SStephen Hanson B_FALSE); 3144705e9f42SStephen Hanson fmd_case_add_suspect(f->hdl, f->fmcase, fault); 3145705e9f42SStephen Hanson nvlist_free(detector); 3146705e9f42SStephen Hanson } 3147705e9f42SStephen Hanson FREE(reason); 31487c478bd9Sstevel@tonic-gate fmd_case_solve(f->hdl, f->fmcase); 31497c478bd9Sstevel@tonic-gate fmd_case_close(f->hdl, f->fmcase); 315032d4e834STarik Soydan Undiag_reason = UD_VAL_UNKNOWN; 31517c478bd9Sstevel@tonic-gate } 31527c478bd9Sstevel@tonic-gate 31537c478bd9Sstevel@tonic-gate /* 31547c478bd9Sstevel@tonic-gate * fme_close_case 31557c478bd9Sstevel@tonic-gate * 31567c478bd9Sstevel@tonic-gate * Find the requested case amongst our fmes and close it. Free up 31577c478bd9Sstevel@tonic-gate * the related fme. 31587c478bd9Sstevel@tonic-gate */ 31597c478bd9Sstevel@tonic-gate void 31607c478bd9Sstevel@tonic-gate fme_close_case(fmd_hdl_t *hdl, fmd_case_t *fmcase) 31617c478bd9Sstevel@tonic-gate { 31627c478bd9Sstevel@tonic-gate struct case_list *ucasep, *prevcasep = NULL; 31637c478bd9Sstevel@tonic-gate struct fme *prev = NULL; 31647c478bd9Sstevel@tonic-gate struct fme *fmep; 31657c478bd9Sstevel@tonic-gate 31667c478bd9Sstevel@tonic-gate for (ucasep = Undiagablecaselist; ucasep; ucasep = ucasep->next) { 31677c478bd9Sstevel@tonic-gate if (fmcase != ucasep->fmcase) { 31687c478bd9Sstevel@tonic-gate prevcasep = ucasep; 31697c478bd9Sstevel@tonic-gate continue; 31707c478bd9Sstevel@tonic-gate } 31717c478bd9Sstevel@tonic-gate 31727c478bd9Sstevel@tonic-gate if (prevcasep == NULL) 31737c478bd9Sstevel@tonic-gate Undiagablecaselist = Undiagablecaselist->next; 31747c478bd9Sstevel@tonic-gate else 31757c478bd9Sstevel@tonic-gate prevcasep->next = ucasep->next; 31767c478bd9Sstevel@tonic-gate 31777c478bd9Sstevel@tonic-gate FREE(ucasep); 31787c478bd9Sstevel@tonic-gate return; 31797c478bd9Sstevel@tonic-gate } 31807c478bd9Sstevel@tonic-gate 31817c478bd9Sstevel@tonic-gate for (fmep = FMElist; fmep; fmep = fmep->next) { 31827c478bd9Sstevel@tonic-gate if (fmep->hdl == hdl && fmep->fmcase == fmcase) 31837c478bd9Sstevel@tonic-gate break; 31847c478bd9Sstevel@tonic-gate prev = fmep; 31857c478bd9Sstevel@tonic-gate } 31867c478bd9Sstevel@tonic-gate 31877c478bd9Sstevel@tonic-gate if (fmep == NULL) { 31887c478bd9Sstevel@tonic-gate out(O_WARN, "Eft asked to close unrecognized case [%s].", 31897c478bd9Sstevel@tonic-gate fmd_case_uuid(hdl, fmcase)); 31907c478bd9Sstevel@tonic-gate return; 31917c478bd9Sstevel@tonic-gate } 31927c478bd9Sstevel@tonic-gate 31937c478bd9Sstevel@tonic-gate if (EFMElist == fmep) 31947c478bd9Sstevel@tonic-gate EFMElist = prev; 31957c478bd9Sstevel@tonic-gate 31967c478bd9Sstevel@tonic-gate if (prev == NULL) 31977c478bd9Sstevel@tonic-gate FMElist = FMElist->next; 31987c478bd9Sstevel@tonic-gate else 31997c478bd9Sstevel@tonic-gate prev->next = fmep->next; 32007c478bd9Sstevel@tonic-gate 32017c478bd9Sstevel@tonic-gate fmep->next = NULL; 32027c478bd9Sstevel@tonic-gate 32037c478bd9Sstevel@tonic-gate /* Get rid of any timer this fme has set */ 32047c478bd9Sstevel@tonic-gate if (fmep->wull != 0) 32057c478bd9Sstevel@tonic-gate fmd_timer_remove(fmep->hdl, fmep->timer); 32067c478bd9Sstevel@tonic-gate 32077c478bd9Sstevel@tonic-gate if (ClosedFMEs == NULL) { 32087c478bd9Sstevel@tonic-gate ClosedFMEs = fmep; 32097c478bd9Sstevel@tonic-gate } else { 32107c478bd9Sstevel@tonic-gate fmep->next = ClosedFMEs; 32117c478bd9Sstevel@tonic-gate ClosedFMEs = fmep; 32127c478bd9Sstevel@tonic-gate } 32130cc1f05eSjrutt 32140cc1f05eSjrutt Open_fme_count--; 32150cc1f05eSjrutt 32160cc1f05eSjrutt /* See if we can close the overflow FME */ 32170cc1f05eSjrutt if (Open_fme_count <= Max_fme) { 32180cc1f05eSjrutt for (fmep = FMElist; fmep; fmep = fmep->next) { 32190cc1f05eSjrutt if (fmep->overflow && !(fmd_case_closed(fmep->hdl, 32200cc1f05eSjrutt fmep->fmcase))) 32210cc1f05eSjrutt break; 32220cc1f05eSjrutt } 32230cc1f05eSjrutt 32240cc1f05eSjrutt if (fmep != NULL) 32250cc1f05eSjrutt fmd_case_close(fmep->hdl, fmep->fmcase); 32260cc1f05eSjrutt } 32277c478bd9Sstevel@tonic-gate } 32287c478bd9Sstevel@tonic-gate 32297c478bd9Sstevel@tonic-gate /* 32307c478bd9Sstevel@tonic-gate * fme_set_timer() 32317c478bd9Sstevel@tonic-gate * If the time we need to wait for the given FME is less than the 32327c478bd9Sstevel@tonic-gate * current timer, kick that old timer out and establish a new one. 32337c478bd9Sstevel@tonic-gate */ 32347aec1d6eScindi static int 32357c478bd9Sstevel@tonic-gate fme_set_timer(struct fme *fmep, unsigned long long wull) 32367c478bd9Sstevel@tonic-gate { 32377c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " fme_set_timer: request to wait "); 32387c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB, &wull); 32397c478bd9Sstevel@tonic-gate 32407c478bd9Sstevel@tonic-gate if (wull <= fmep->pull) { 32417c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "already have waited at least "); 32427c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB, &fmep->pull); 32437c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 32447c478bd9Sstevel@tonic-gate /* we've waited at least wull already, don't need timer */ 32457aec1d6eScindi return (0); 32467c478bd9Sstevel@tonic-gate } 32477c478bd9Sstevel@tonic-gate 32487c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " currently "); 32497c478bd9Sstevel@tonic-gate if (fmep->wull != 0) { 32507c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "waiting "); 32517c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB, &fmep->wull); 32527c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 32537c478bd9Sstevel@tonic-gate } else { 32547c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "not waiting"); 32557c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 32567c478bd9Sstevel@tonic-gate } 32577c478bd9Sstevel@tonic-gate 32587c478bd9Sstevel@tonic-gate if (fmep->wull != 0) 32597c478bd9Sstevel@tonic-gate if (wull >= fmep->wull) 32607c478bd9Sstevel@tonic-gate /* New timer would fire later than established timer */ 32617aec1d6eScindi return (0); 32627c478bd9Sstevel@tonic-gate 32637aec1d6eScindi if (fmep->wull != 0) { 32647c478bd9Sstevel@tonic-gate fmd_timer_remove(fmep->hdl, fmep->timer); 32657aec1d6eScindi } 32667c478bd9Sstevel@tonic-gate 32677c478bd9Sstevel@tonic-gate fmep->timer = fmd_timer_install(fmep->hdl, (void *)fmep, 32687c478bd9Sstevel@tonic-gate fmep->e0r, wull); 32697c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, "timer set, id is %ld", fmep->timer); 32707c478bd9Sstevel@tonic-gate fmep->wull = wull; 32717aec1d6eScindi return (1); 32727c478bd9Sstevel@tonic-gate } 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate void 32757c478bd9Sstevel@tonic-gate fme_timer_fired(struct fme *fmep, id_t tid) 32767c478bd9Sstevel@tonic-gate { 32777c478bd9Sstevel@tonic-gate struct fme *ffmep = NULL; 32787c478bd9Sstevel@tonic-gate 32797c478bd9Sstevel@tonic-gate for (ffmep = FMElist; ffmep; ffmep = ffmep->next) 32807c478bd9Sstevel@tonic-gate if (ffmep == fmep) 32817c478bd9Sstevel@tonic-gate break; 32827c478bd9Sstevel@tonic-gate 32837c478bd9Sstevel@tonic-gate if (ffmep == NULL) { 32847c478bd9Sstevel@tonic-gate out(O_WARN, "Timer fired for an FME (%p) not in FMEs list.", 32857c478bd9Sstevel@tonic-gate (void *)fmep); 32867c478bd9Sstevel@tonic-gate return; 32877c478bd9Sstevel@tonic-gate } 32887c478bd9Sstevel@tonic-gate 3289b5016cbbSstephh out(O_ALTFP|O_VERB, "Timer fired %lx", tid); 3290d96ce684Sstephh fmep->pull = fmep->wull; 3291d96ce684Sstephh fmep->wull = 0; 3292d96ce684Sstephh fmd_buf_write(fmep->hdl, fmep->fmcase, 3293d96ce684Sstephh WOBUF_PULL, (void *)&fmep->pull, sizeof (fmep->pull)); 3294b5016cbbSstephh 329500d0963fSdilpreet fme_eval(fmep, fmep->e0r); 32967c478bd9Sstevel@tonic-gate } 32977c478bd9Sstevel@tonic-gate 32987c478bd9Sstevel@tonic-gate /* 32997c478bd9Sstevel@tonic-gate * Preserve the fme's suspect list in its psuspects list, NULLing the 33007c478bd9Sstevel@tonic-gate * suspects list in the meantime. 33017c478bd9Sstevel@tonic-gate */ 33027c478bd9Sstevel@tonic-gate static void 33037c478bd9Sstevel@tonic-gate save_suspects(struct fme *fmep) 33047c478bd9Sstevel@tonic-gate { 33057c478bd9Sstevel@tonic-gate struct event *ep; 33067c478bd9Sstevel@tonic-gate struct event *nextep; 33077c478bd9Sstevel@tonic-gate 33087c478bd9Sstevel@tonic-gate /* zero out the previous suspect list */ 33097c478bd9Sstevel@tonic-gate for (ep = fmep->psuspects; ep; ep = nextep) { 33107c478bd9Sstevel@tonic-gate nextep = ep->psuspects; 33117c478bd9Sstevel@tonic-gate ep->psuspects = NULL; 33127c478bd9Sstevel@tonic-gate } 33137c478bd9Sstevel@tonic-gate fmep->psuspects = NULL; 33147c478bd9Sstevel@tonic-gate 33157c478bd9Sstevel@tonic-gate /* zero out the suspect list, copying it to previous suspect list */ 33167c478bd9Sstevel@tonic-gate fmep->psuspects = fmep->suspects; 33177c478bd9Sstevel@tonic-gate for (ep = fmep->suspects; ep; ep = nextep) { 33187c478bd9Sstevel@tonic-gate nextep = ep->suspects; 33197c478bd9Sstevel@tonic-gate ep->psuspects = ep->suspects; 33207c478bd9Sstevel@tonic-gate ep->suspects = NULL; 33217c478bd9Sstevel@tonic-gate ep->is_suspect = 0; 33227c478bd9Sstevel@tonic-gate } 33237c478bd9Sstevel@tonic-gate fmep->suspects = NULL; 33247c478bd9Sstevel@tonic-gate fmep->nsuspects = 0; 33257c478bd9Sstevel@tonic-gate } 33267c478bd9Sstevel@tonic-gate 33277c478bd9Sstevel@tonic-gate /* 33287c478bd9Sstevel@tonic-gate * Retrieve the fme's suspect list from its psuspects list. 33297c478bd9Sstevel@tonic-gate */ 33307c478bd9Sstevel@tonic-gate static void 33317c478bd9Sstevel@tonic-gate restore_suspects(struct fme *fmep) 33327c478bd9Sstevel@tonic-gate { 33337c478bd9Sstevel@tonic-gate struct event *ep; 33347c478bd9Sstevel@tonic-gate struct event *nextep; 33357c478bd9Sstevel@tonic-gate 33368e7248e5SStephen Hanson fmep->nsuspects = 0; 33377c478bd9Sstevel@tonic-gate fmep->suspects = fmep->psuspects; 33387c478bd9Sstevel@tonic-gate for (ep = fmep->psuspects; ep; ep = nextep) { 33397c478bd9Sstevel@tonic-gate fmep->nsuspects++; 33407c478bd9Sstevel@tonic-gate nextep = ep->psuspects; 33417c478bd9Sstevel@tonic-gate ep->suspects = ep->psuspects; 33427c478bd9Sstevel@tonic-gate } 33437c478bd9Sstevel@tonic-gate } 33447c478bd9Sstevel@tonic-gate 33457c478bd9Sstevel@tonic-gate /* 33467c478bd9Sstevel@tonic-gate * this is what we use to call the Emrys prototype code instead of main() 33477c478bd9Sstevel@tonic-gate */ 33487c478bd9Sstevel@tonic-gate static void 33497c478bd9Sstevel@tonic-gate fme_eval(struct fme *fmep, fmd_event_t *ffep) 33507c478bd9Sstevel@tonic-gate { 33517c478bd9Sstevel@tonic-gate struct event *ep; 33527c478bd9Sstevel@tonic-gate unsigned long long my_delay = TIMEVAL_EVENTUALLY; 3353b7d3956bSstephh struct rsl *srl = NULL; 3354b7d3956bSstephh struct rsl *srl2 = NULL; 3355b7d3956bSstephh int mess_zero_count; 3356b7d3956bSstephh int rpcnt; 33577c478bd9Sstevel@tonic-gate 33587c478bd9Sstevel@tonic-gate save_suspects(fmep); 33597c478bd9Sstevel@tonic-gate 3360b5016cbbSstephh out(O_ALTFP, "Evaluate FME %d", fmep->id); 33617c478bd9Sstevel@tonic-gate indent_set(" "); 33627c478bd9Sstevel@tonic-gate 33637aec1d6eScindi lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep); 33647aec1d6eScindi fmep->state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay); 33657c478bd9Sstevel@tonic-gate 3366b5016cbbSstephh out(O_ALTFP|O_NONL, "FME%d state: %s, suspect list:", fmep->id, 33677c478bd9Sstevel@tonic-gate fme_state2str(fmep->state)); 33687c478bd9Sstevel@tonic-gate for (ep = fmep->suspects; ep; ep = ep->suspects) { 3369b5016cbbSstephh out(O_ALTFP|O_NONL, " "); 3370b5016cbbSstephh itree_pevent_brief(O_ALTFP|O_NONL, ep); 33717c478bd9Sstevel@tonic-gate } 3372b5016cbbSstephh out(O_ALTFP, NULL); 33737c478bd9Sstevel@tonic-gate 3374d96ce684Sstephh switch (fmep->state) { 3375d96ce684Sstephh case FME_CREDIBLE: 3376d96ce684Sstephh print_suspects(SLNEW, fmep); 3377d96ce684Sstephh (void) upsets_eval(fmep, ffep); 3378d96ce684Sstephh 33797c478bd9Sstevel@tonic-gate /* 3380d96ce684Sstephh * we may have already posted suspects in upsets_eval() which 3381d96ce684Sstephh * can recurse into fme_eval() again. If so then just return. 33827c478bd9Sstevel@tonic-gate */ 3383d96ce684Sstephh if (fmep->posted_suspects) 3384d96ce684Sstephh return; 33857c478bd9Sstevel@tonic-gate 3386b7d3956bSstephh stats_counter_bump(fmep->diags); 3387b7d3956bSstephh rpcnt = fmep->nsuspects; 3388b7d3956bSstephh save_suspects(fmep); 3389b7d3956bSstephh 3390b7d3956bSstephh /* 3391b7d3956bSstephh * create two lists, one for "message=1" faults and one for 3392b7d3956bSstephh * "message=0" faults. If we have a mixture we will generate 3393b7d3956bSstephh * two separate suspect lists. 3394b7d3956bSstephh */ 3395b7d3956bSstephh srl = MALLOC(rpcnt * sizeof (struct rsl)); 3396b7d3956bSstephh bzero(srl, rpcnt * sizeof (struct rsl)); 3397b7d3956bSstephh srl2 = MALLOC(rpcnt * sizeof (struct rsl)); 3398b7d3956bSstephh bzero(srl2, rpcnt * sizeof (struct rsl)); 33998e7248e5SStephen Hanson mess_zero_count = trim_suspects(fmep, srl, srl2, ffep); 3400b7d3956bSstephh 3401b7d3956bSstephh /* 3402b7d3956bSstephh * If the resulting suspect list has no members, we're 3403b7d3956bSstephh * done so simply close the case. Otherwise sort and publish. 3404b7d3956bSstephh */ 3405b7d3956bSstephh if (fmep->nsuspects == 0 && mess_zero_count == 0) { 3406b7d3956bSstephh out(O_ALTFP, 3407b7d3956bSstephh "[FME%d, case %s (all suspects are upsets)]", 3408b7d3956bSstephh fmep->id, fmd_case_uuid(fmep->hdl, fmep->fmcase)); 3409b7d3956bSstephh fmd_case_close(fmep->hdl, fmep->fmcase); 3410b7d3956bSstephh } else if (fmep->nsuspects != 0 && mess_zero_count == 0) { 3411b7d3956bSstephh publish_suspects(fmep, srl); 3412b7d3956bSstephh out(O_ALTFP, "[solving FME%d, case %s]", fmep->id, 3413b7d3956bSstephh fmd_case_uuid(fmep->hdl, fmep->fmcase)); 3414b7d3956bSstephh fmd_case_solve(fmep->hdl, fmep->fmcase); 3415b7d3956bSstephh } else if (fmep->nsuspects == 0 && mess_zero_count != 0) { 3416b7d3956bSstephh fmep->nsuspects = mess_zero_count; 3417b7d3956bSstephh publish_suspects(fmep, srl2); 3418b7d3956bSstephh out(O_ALTFP, "[solving FME%d, case %s]", fmep->id, 3419b7d3956bSstephh fmd_case_uuid(fmep->hdl, fmep->fmcase)); 3420b7d3956bSstephh fmd_case_solve(fmep->hdl, fmep->fmcase); 3421b7d3956bSstephh } else { 3422b7d3956bSstephh struct event *obsp; 3423b7d3956bSstephh struct fme *nfmep; 3424b7d3956bSstephh 3425b7d3956bSstephh publish_suspects(fmep, srl); 3426b7d3956bSstephh out(O_ALTFP, "[solving FME%d, case %s]", fmep->id, 3427b7d3956bSstephh fmd_case_uuid(fmep->hdl, fmep->fmcase)); 3428b7d3956bSstephh fmd_case_solve(fmep->hdl, fmep->fmcase); 3429b7d3956bSstephh 3430b7d3956bSstephh /* 3431b7d3956bSstephh * Got both message=0 and message=1 so create a 3432b7d3956bSstephh * duplicate case. Also need a temporary duplicate fme 3433b7d3956bSstephh * structure for use by publish_suspects(). 3434b7d3956bSstephh */ 3435b7d3956bSstephh nfmep = alloc_fme(); 3436b7d3956bSstephh nfmep->id = Nextid++; 3437b7d3956bSstephh nfmep->hdl = fmep->hdl; 3438b7d3956bSstephh nfmep->nsuspects = mess_zero_count; 3439b7d3956bSstephh nfmep->fmcase = fmd_case_open(fmep->hdl, NULL); 3440b7d3956bSstephh out(O_ALTFP|O_STAMP, 3441b7d3956bSstephh "[creating parallel FME%d, case %s]", nfmep->id, 3442b7d3956bSstephh fmd_case_uuid(nfmep->hdl, nfmep->fmcase)); 3443b7d3956bSstephh Open_fme_count++; 3444b7d3956bSstephh if (ffep) { 3445b7d3956bSstephh fmd_case_setprincipal(nfmep->hdl, 3446b7d3956bSstephh nfmep->fmcase, ffep); 3447b7d3956bSstephh fmd_case_add_ereport(nfmep->hdl, 3448b7d3956bSstephh nfmep->fmcase, ffep); 3449b7d3956bSstephh } 3450b7d3956bSstephh for (obsp = fmep->observations; obsp; 3451b7d3956bSstephh obsp = obsp->observations) 3452b7d3956bSstephh if (obsp->ffep && obsp->ffep != ffep) 3453b7d3956bSstephh fmd_case_add_ereport(nfmep->hdl, 3454b7d3956bSstephh nfmep->fmcase, obsp->ffep); 3455b7d3956bSstephh 3456b7d3956bSstephh publish_suspects(nfmep, srl2); 3457b7d3956bSstephh out(O_ALTFP, "[solving FME%d, case %s]", nfmep->id, 3458b7d3956bSstephh fmd_case_uuid(nfmep->hdl, nfmep->fmcase)); 3459b7d3956bSstephh fmd_case_solve(nfmep->hdl, nfmep->fmcase); 3460b7d3956bSstephh FREE(nfmep); 3461b7d3956bSstephh } 3462b7d3956bSstephh FREE(srl); 3463b7d3956bSstephh FREE(srl2); 3464b7d3956bSstephh restore_suspects(fmep); 3465b7d3956bSstephh 3466d96ce684Sstephh fmep->posted_suspects = 1; 3467d96ce684Sstephh fmd_buf_write(fmep->hdl, fmep->fmcase, 3468d96ce684Sstephh WOBUF_POSTD, 3469d96ce684Sstephh (void *)&fmep->posted_suspects, 3470d96ce684Sstephh sizeof (fmep->posted_suspects)); 34717c478bd9Sstevel@tonic-gate 3472d96ce684Sstephh /* 3473d96ce684Sstephh * Now the suspects have been posted, we can clear up 3474d96ce684Sstephh * the instance tree as we won't be looking at it again. 3475d96ce684Sstephh * Also cancel the timer as the case is now solved. 3476d96ce684Sstephh */ 3477d96ce684Sstephh if (fmep->wull != 0) { 3478d96ce684Sstephh fmd_timer_remove(fmep->hdl, fmep->timer); 3479d96ce684Sstephh fmep->wull = 0; 34807c478bd9Sstevel@tonic-gate } 3481d96ce684Sstephh break; 3482d96ce684Sstephh 3483d96ce684Sstephh case FME_WAIT: 3484d96ce684Sstephh ASSERT(my_delay > fmep->ull); 3485d96ce684Sstephh (void) fme_set_timer(fmep, my_delay); 3486d96ce684Sstephh print_suspects(SLWAIT, fmep); 3487b5016cbbSstephh itree_prune(fmep->eventtree); 3488b5016cbbSstephh return; 3489d96ce684Sstephh 3490d96ce684Sstephh case FME_DISPROVED: 3491d96ce684Sstephh print_suspects(SLDISPROVED, fmep); 349232d4e834STarik Soydan Undiag_reason = UD_VAL_UNSOLVD; 3493d96ce684Sstephh fme_undiagnosable(fmep); 3494d96ce684Sstephh break; 34957c478bd9Sstevel@tonic-gate } 34967c478bd9Sstevel@tonic-gate 3497b5016cbbSstephh itree_free(fmep->eventtree); 3498b5016cbbSstephh fmep->eventtree = NULL; 3499e5ba14ffSstephh structconfig_free(fmep->config); 3500e5ba14ffSstephh fmep->config = NULL; 3501b5016cbbSstephh destroy_fme_bufs(fmep); 35027c478bd9Sstevel@tonic-gate } 35037c478bd9Sstevel@tonic-gate 35047c478bd9Sstevel@tonic-gate static void indent(void); 35057c478bd9Sstevel@tonic-gate static int triggered(struct fme *fmep, struct event *ep, int mark); 35067c478bd9Sstevel@tonic-gate static enum fme_state effects_test(struct fme *fmep, 35077aec1d6eScindi struct event *fault_event, unsigned long long at_latest_by, 35087aec1d6eScindi unsigned long long *pdelay); 35097c478bd9Sstevel@tonic-gate static enum fme_state requirements_test(struct fme *fmep, struct event *ep, 35107aec1d6eScindi unsigned long long at_latest_by, unsigned long long *pdelay); 35117c478bd9Sstevel@tonic-gate static enum fme_state causes_test(struct fme *fmep, struct event *ep, 35127c478bd9Sstevel@tonic-gate unsigned long long at_latest_by, unsigned long long *pdelay); 35137c478bd9Sstevel@tonic-gate 35147aec1d6eScindi static int 35157aec1d6eScindi checkconstraints(struct fme *fmep, struct arrow *arrowp) 35167aec1d6eScindi { 35177aec1d6eScindi struct constraintlist *ctp; 35187aec1d6eScindi struct evalue value; 3519b5016cbbSstephh char *sep = ""; 35207aec1d6eScindi 35217aec1d6eScindi if (arrowp->forever_false) { 35227aec1d6eScindi indent(); 35237aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " Forever false constraint: "); 35247aec1d6eScindi for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) { 35257aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, sep); 35267aec1d6eScindi ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0); 35277aec1d6eScindi sep = ", "; 35287aec1d6eScindi } 35297aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 35307aec1d6eScindi return (0); 35317aec1d6eScindi } 3532b5016cbbSstephh if (arrowp->forever_true) { 3533b5016cbbSstephh indent(); 3534b5016cbbSstephh out(O_ALTFP|O_VERB|O_NONL, " Forever true constraint: "); 3535b5016cbbSstephh for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) { 3536b5016cbbSstephh out(O_ALTFP|O_VERB|O_NONL, sep); 3537b5016cbbSstephh ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0); 3538b5016cbbSstephh sep = ", "; 3539b5016cbbSstephh } 3540b5016cbbSstephh out(O_ALTFP|O_VERB, NULL); 3541b5016cbbSstephh return (1); 3542b5016cbbSstephh } 35437aec1d6eScindi 35447aec1d6eScindi for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) { 35457aec1d6eScindi if (eval_expr(ctp->cnode, NULL, NULL, 3546e5ba14ffSstephh &fmep->globals, fmep->config, 35477aec1d6eScindi arrowp, 0, &value)) { 35487aec1d6eScindi /* evaluation successful */ 35497aec1d6eScindi if (value.t == UNDEFINED || value.v == 0) { 35507aec1d6eScindi /* known false */ 35517aec1d6eScindi arrowp->forever_false = 1; 35527aec1d6eScindi indent(); 35537aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 35547aec1d6eScindi " False constraint: "); 35557aec1d6eScindi ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0); 35567aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 35577aec1d6eScindi return (0); 35587aec1d6eScindi } 35597aec1d6eScindi } else { 35607aec1d6eScindi /* evaluation unsuccessful -- unknown value */ 35617aec1d6eScindi indent(); 35627aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 35637aec1d6eScindi " Deferred constraint: "); 35647aec1d6eScindi ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0); 35657aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 3566b5016cbbSstephh return (1); 35677aec1d6eScindi } 35687aec1d6eScindi } 35697aec1d6eScindi /* known true */ 3570b5016cbbSstephh arrowp->forever_true = 1; 3571b5016cbbSstephh indent(); 3572b5016cbbSstephh out(O_ALTFP|O_VERB|O_NONL, " True constraint: "); 3573b5016cbbSstephh for (ctp = arrowp->constraints; ctp != NULL; ctp = ctp->next) { 3574b5016cbbSstephh out(O_ALTFP|O_VERB|O_NONL, sep); 3575b5016cbbSstephh ptree(O_ALTFP|O_VERB|O_NONL, ctp->cnode, 1, 0); 3576b5016cbbSstephh sep = ", "; 3577b5016cbbSstephh } 3578b5016cbbSstephh out(O_ALTFP|O_VERB, NULL); 35797aec1d6eScindi return (1); 35807aec1d6eScindi } 35817aec1d6eScindi 35827c478bd9Sstevel@tonic-gate static int 35837c478bd9Sstevel@tonic-gate triggered(struct fme *fmep, struct event *ep, int mark) 35847c478bd9Sstevel@tonic-gate { 35857c478bd9Sstevel@tonic-gate struct bubble *bp; 35867c478bd9Sstevel@tonic-gate struct arrowlist *ap; 35877c478bd9Sstevel@tonic-gate int count = 0; 35887c478bd9Sstevel@tonic-gate 35897c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Tcallcount); 35907c478bd9Sstevel@tonic-gate for (bp = itree_next_bubble(ep, NULL); bp; 35917c478bd9Sstevel@tonic-gate bp = itree_next_bubble(ep, bp)) { 35927c478bd9Sstevel@tonic-gate if (bp->t != B_TO) 35937c478bd9Sstevel@tonic-gate continue; 35947c478bd9Sstevel@tonic-gate for (ap = itree_next_arrow(bp, NULL); ap; 35957c478bd9Sstevel@tonic-gate ap = itree_next_arrow(bp, ap)) { 35967c478bd9Sstevel@tonic-gate /* check count of marks against K in the bubble */ 35977aec1d6eScindi if ((ap->arrowp->mark & mark) && 35987c478bd9Sstevel@tonic-gate ++count >= bp->nork) 35997c478bd9Sstevel@tonic-gate return (1); 36007c478bd9Sstevel@tonic-gate } 36017c478bd9Sstevel@tonic-gate } 36027c478bd9Sstevel@tonic-gate return (0); 36037c478bd9Sstevel@tonic-gate } 36047c478bd9Sstevel@tonic-gate 36057aec1d6eScindi static int 36067aec1d6eScindi mark_arrows(struct fme *fmep, struct event *ep, int mark, 360700d0963fSdilpreet unsigned long long at_latest_by, unsigned long long *pdelay, int keep) 36087c478bd9Sstevel@tonic-gate { 36097c478bd9Sstevel@tonic-gate struct bubble *bp; 36107c478bd9Sstevel@tonic-gate struct arrowlist *ap; 36117aec1d6eScindi unsigned long long overall_delay = TIMEVAL_EVENTUALLY; 36127aec1d6eScindi unsigned long long my_delay; 36137aec1d6eScindi enum fme_state result; 36147aec1d6eScindi int retval = 0; 36157c478bd9Sstevel@tonic-gate 36167c478bd9Sstevel@tonic-gate for (bp = itree_next_bubble(ep, NULL); bp; 36177c478bd9Sstevel@tonic-gate bp = itree_next_bubble(ep, bp)) { 36187c478bd9Sstevel@tonic-gate if (bp->t != B_FROM) 36197c478bd9Sstevel@tonic-gate continue; 36207aec1d6eScindi stats_counter_bump(fmep->Marrowcount); 36217aec1d6eScindi for (ap = itree_next_arrow(bp, NULL); ap; 36227aec1d6eScindi ap = itree_next_arrow(bp, ap)) { 36237aec1d6eScindi struct event *ep2 = ap->arrowp->head->myevent; 36247aec1d6eScindi /* 36257aec1d6eScindi * if we're clearing marks, we can avoid doing 36267aec1d6eScindi * all that work evaluating constraints. 36277aec1d6eScindi */ 36287aec1d6eScindi if (mark == 0) { 3629b5016cbbSstephh if (ap->arrowp->arrow_marked == 0) 3630b5016cbbSstephh continue; 3631b5016cbbSstephh ap->arrowp->arrow_marked = 0; 36327aec1d6eScindi ap->arrowp->mark &= ~EFFECTS_COUNTER; 363300d0963fSdilpreet if (keep && (ep2->cached_state & 363400d0963fSdilpreet (WAIT_EFFECT|CREDIBLE_EFFECT|PARENT_WAIT))) 363500d0963fSdilpreet ep2->keep_in_tree = 1; 36367aec1d6eScindi ep2->cached_state &= 36377aec1d6eScindi ~(WAIT_EFFECT|CREDIBLE_EFFECT|PARENT_WAIT); 363800d0963fSdilpreet (void) mark_arrows(fmep, ep2, mark, 0, NULL, 363900d0963fSdilpreet keep); 36407aec1d6eScindi continue; 36417aec1d6eScindi } 3642b5016cbbSstephh ap->arrowp->arrow_marked = 1; 36437aec1d6eScindi if (ep2->cached_state & REQMNTS_DISPROVED) { 36447aec1d6eScindi indent(); 36457aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36467aec1d6eScindi " ALREADY DISPROVED "); 36477aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36487aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36497aec1d6eScindi continue; 36507aec1d6eScindi } 36517aec1d6eScindi if (ep2->cached_state & WAIT_EFFECT) { 36527aec1d6eScindi indent(); 36537aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36547aec1d6eScindi " ALREADY EFFECTS WAIT "); 36557aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36567aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36577aec1d6eScindi continue; 36587aec1d6eScindi } 36597aec1d6eScindi if (ep2->cached_state & CREDIBLE_EFFECT) { 36607aec1d6eScindi indent(); 36617aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36627aec1d6eScindi " ALREADY EFFECTS CREDIBLE "); 36637aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36647aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36657aec1d6eScindi continue; 36667aec1d6eScindi } 36677aec1d6eScindi if ((ep2->cached_state & PARENT_WAIT) && 36687aec1d6eScindi (mark & PARENT_WAIT)) { 36697aec1d6eScindi indent(); 36707aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36717aec1d6eScindi " ALREADY PARENT EFFECTS WAIT "); 36727aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36737aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36747aec1d6eScindi continue; 36757aec1d6eScindi } 36767aec1d6eScindi platform_set_payloadnvp(ep2->nvp); 367700d0963fSdilpreet if (checkconstraints(fmep, ap->arrowp) == 0) { 36787aec1d6eScindi platform_set_payloadnvp(NULL); 36797aec1d6eScindi indent(); 36807aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36817aec1d6eScindi " CONSTRAINTS FAIL "); 36827aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36837aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36847aec1d6eScindi continue; 36857aec1d6eScindi } 36867aec1d6eScindi platform_set_payloadnvp(NULL); 36877aec1d6eScindi ap->arrowp->mark |= EFFECTS_COUNTER; 36887aec1d6eScindi if (!triggered(fmep, ep2, EFFECTS_COUNTER)) { 36897aec1d6eScindi indent(); 36907aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 36917aec1d6eScindi " K-COUNT NOT YET MET "); 36927aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 36937aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 36947aec1d6eScindi continue; 36957aec1d6eScindi } 36967aec1d6eScindi ep2->cached_state &= ~PARENT_WAIT; 3697d96ce684Sstephh /* 3698d96ce684Sstephh * if we've reached an ereport and no propagation time 3699d96ce684Sstephh * is specified, use the Hesitate value 3700d96ce684Sstephh */ 3701d96ce684Sstephh if (ep2->t == N_EREPORT && at_latest_by == 0ULL && 3702d96ce684Sstephh ap->arrowp->maxdelay == 0ULL) { 3703d96ce684Sstephh out(O_ALTFP|O_VERB|O_NONL, " default wait "); 3704d96ce684Sstephh itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 3705d96ce684Sstephh out(O_ALTFP|O_VERB, NULL); 3706b5016cbbSstephh result = requirements_test(fmep, ep2, Hesitate, 3707b5016cbbSstephh &my_delay); 3708d96ce684Sstephh } else { 3709d96ce684Sstephh result = requirements_test(fmep, ep2, 3710d96ce684Sstephh at_latest_by + ap->arrowp->maxdelay, 3711d96ce684Sstephh &my_delay); 3712d96ce684Sstephh } 37137aec1d6eScindi if (result == FME_WAIT) { 37147aec1d6eScindi retval = WAIT_EFFECT; 37157aec1d6eScindi if (overall_delay > my_delay) 37167aec1d6eScindi overall_delay = my_delay; 37177aec1d6eScindi ep2->cached_state |= WAIT_EFFECT; 37187aec1d6eScindi indent(); 37197aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " EFFECTS WAIT "); 37207aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 37217aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 37227aec1d6eScindi indent_push(" E"); 37237aec1d6eScindi if (mark_arrows(fmep, ep2, PARENT_WAIT, 372400d0963fSdilpreet at_latest_by, &my_delay, 0) == 372500d0963fSdilpreet WAIT_EFFECT) { 37267aec1d6eScindi retval = WAIT_EFFECT; 37277aec1d6eScindi if (overall_delay > my_delay) 37287aec1d6eScindi overall_delay = my_delay; 37297c478bd9Sstevel@tonic-gate } 37307aec1d6eScindi indent_pop(); 37317aec1d6eScindi } else if (result == FME_DISPROVED) { 37327aec1d6eScindi indent(); 37337aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 37347aec1d6eScindi " EFFECTS DISPROVED "); 37357aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 37367aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 37377aec1d6eScindi } else { 37387aec1d6eScindi ep2->cached_state |= mark; 37397aec1d6eScindi indent(); 37407aec1d6eScindi if (mark == CREDIBLE_EFFECT) 37417c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, 37427aec1d6eScindi " EFFECTS CREDIBLE "); 37437aec1d6eScindi else 37447aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 37457aec1d6eScindi " PARENT EFFECTS WAIT "); 37467aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep2); 37477aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 37487aec1d6eScindi indent_push(" E"); 37497aec1d6eScindi if (mark_arrows(fmep, ep2, mark, at_latest_by, 375000d0963fSdilpreet &my_delay, 0) == WAIT_EFFECT) { 37517aec1d6eScindi retval = WAIT_EFFECT; 37527aec1d6eScindi if (overall_delay > my_delay) 37537aec1d6eScindi overall_delay = my_delay; 37547c478bd9Sstevel@tonic-gate } 37557aec1d6eScindi indent_pop(); 37567c478bd9Sstevel@tonic-gate } 37577c478bd9Sstevel@tonic-gate } 37587c478bd9Sstevel@tonic-gate } 37597aec1d6eScindi if (retval == WAIT_EFFECT) 37607aec1d6eScindi *pdelay = overall_delay; 37617aec1d6eScindi return (retval); 37627c478bd9Sstevel@tonic-gate } 37637c478bd9Sstevel@tonic-gate 37647c478bd9Sstevel@tonic-gate static enum fme_state 37657aec1d6eScindi effects_test(struct fme *fmep, struct event *fault_event, 37667aec1d6eScindi unsigned long long at_latest_by, unsigned long long *pdelay) 37677c478bd9Sstevel@tonic-gate { 37687c478bd9Sstevel@tonic-gate struct event *error_event; 37697c478bd9Sstevel@tonic-gate enum fme_state return_value = FME_CREDIBLE; 37707aec1d6eScindi unsigned long long overall_delay = TIMEVAL_EVENTUALLY; 37717aec1d6eScindi unsigned long long my_delay; 37727c478bd9Sstevel@tonic-gate 37737c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Ecallcount); 37747c478bd9Sstevel@tonic-gate indent_push(" E"); 37757c478bd9Sstevel@tonic-gate indent(); 37767c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "->"); 37777c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, fault_event); 37787c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 37797c478bd9Sstevel@tonic-gate 3780d96ce684Sstephh if (mark_arrows(fmep, fault_event, CREDIBLE_EFFECT, at_latest_by, 3781d96ce684Sstephh &my_delay, 0) == WAIT_EFFECT) { 3782d96ce684Sstephh return_value = FME_WAIT; 3783d96ce684Sstephh if (overall_delay > my_delay) 3784d96ce684Sstephh overall_delay = my_delay; 3785d96ce684Sstephh } 37867c478bd9Sstevel@tonic-gate for (error_event = fmep->observations; 37877c478bd9Sstevel@tonic-gate error_event; error_event = error_event->observations) { 37887c478bd9Sstevel@tonic-gate indent(); 37897c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " "); 37907c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, error_event); 37917aec1d6eScindi if (!(error_event->cached_state & CREDIBLE_EFFECT)) { 37927aec1d6eScindi if (error_event->cached_state & 37937aec1d6eScindi (PARENT_WAIT|WAIT_EFFECT)) { 37947aec1d6eScindi out(O_ALTFP|O_VERB, " NOT YET triggered"); 37957aec1d6eScindi continue; 37967aec1d6eScindi } 37977c478bd9Sstevel@tonic-gate return_value = FME_DISPROVED; 37987c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, " NOT triggered"); 37997c478bd9Sstevel@tonic-gate break; 38007c478bd9Sstevel@tonic-gate } else { 38017c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, " triggered"); 38027c478bd9Sstevel@tonic-gate } 38037c478bd9Sstevel@tonic-gate } 380400d0963fSdilpreet if (return_value == FME_DISPROVED) { 380500d0963fSdilpreet (void) mark_arrows(fmep, fault_event, 0, 0, NULL, 0); 380600d0963fSdilpreet } else { 380700d0963fSdilpreet fault_event->keep_in_tree = 1; 380800d0963fSdilpreet (void) mark_arrows(fmep, fault_event, 0, 0, NULL, 1); 380900d0963fSdilpreet } 38107c478bd9Sstevel@tonic-gate 38117c478bd9Sstevel@tonic-gate indent(); 38127aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-EFFECTS %s ", 38137aec1d6eScindi fme_state2str(return_value)); 38147c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, fault_event); 38157c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 38167c478bd9Sstevel@tonic-gate indent_pop(); 38177aec1d6eScindi if (return_value == FME_WAIT) 38187aec1d6eScindi *pdelay = overall_delay; 38197c478bd9Sstevel@tonic-gate return (return_value); 38207c478bd9Sstevel@tonic-gate } 38217c478bd9Sstevel@tonic-gate 38227c478bd9Sstevel@tonic-gate static enum fme_state 38237c478bd9Sstevel@tonic-gate requirements_test(struct fme *fmep, struct event *ep, 38247aec1d6eScindi unsigned long long at_latest_by, unsigned long long *pdelay) 38257c478bd9Sstevel@tonic-gate { 38267c478bd9Sstevel@tonic-gate int waiting_events; 38277c478bd9Sstevel@tonic-gate int credible_events; 38287aec1d6eScindi int deferred_events; 38297c478bd9Sstevel@tonic-gate enum fme_state return_value = FME_CREDIBLE; 38307c478bd9Sstevel@tonic-gate unsigned long long overall_delay = TIMEVAL_EVENTUALLY; 38317c478bd9Sstevel@tonic-gate unsigned long long arrow_delay; 38327c478bd9Sstevel@tonic-gate unsigned long long my_delay; 38337c478bd9Sstevel@tonic-gate struct event *ep2; 38347c478bd9Sstevel@tonic-gate struct bubble *bp; 38357c478bd9Sstevel@tonic-gate struct arrowlist *ap; 38367c478bd9Sstevel@tonic-gate 38377aec1d6eScindi if (ep->cached_state & REQMNTS_CREDIBLE) { 38387aec1d6eScindi indent(); 38397aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY CREDIBLE "); 38407aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38417aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 38427aec1d6eScindi return (FME_CREDIBLE); 38437aec1d6eScindi } 38447aec1d6eScindi if (ep->cached_state & REQMNTS_DISPROVED) { 38457aec1d6eScindi indent(); 38467aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY DISPROVED "); 38477aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38487aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 38497aec1d6eScindi return (FME_DISPROVED); 38507aec1d6eScindi } 38517aec1d6eScindi if (ep->cached_state & REQMNTS_WAIT) { 38527aec1d6eScindi indent(); 38537aec1d6eScindi *pdelay = ep->cached_delay; 38547aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, " REQMNTS ALREADY WAIT "); 38557aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38567aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, ", wait for: "); 38577aec1d6eScindi ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by); 38587aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 38597aec1d6eScindi return (FME_WAIT); 38607aec1d6eScindi } 38617c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Rcallcount); 38627c478bd9Sstevel@tonic-gate indent_push(" R"); 38637c478bd9Sstevel@tonic-gate indent(); 38647c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "->"); 38657c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38667c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, ", at latest by: "); 38677c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by); 38687c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 38697c478bd9Sstevel@tonic-gate 38707c478bd9Sstevel@tonic-gate if (ep->t == N_EREPORT) { 38717c478bd9Sstevel@tonic-gate if (ep->count == 0) { 38727c478bd9Sstevel@tonic-gate if (fmep->pull >= at_latest_by) { 38737c478bd9Sstevel@tonic-gate return_value = FME_DISPROVED; 38747c478bd9Sstevel@tonic-gate } else { 38757aec1d6eScindi ep->cached_delay = *pdelay = at_latest_by; 38767c478bd9Sstevel@tonic-gate return_value = FME_WAIT; 38777c478bd9Sstevel@tonic-gate } 38787c478bd9Sstevel@tonic-gate } 38797c478bd9Sstevel@tonic-gate 38807c478bd9Sstevel@tonic-gate indent(); 38817c478bd9Sstevel@tonic-gate switch (return_value) { 38827c478bd9Sstevel@tonic-gate case FME_CREDIBLE: 38837aec1d6eScindi ep->cached_state |= REQMNTS_CREDIBLE; 38847aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS CREDIBLE "); 38857c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38867c478bd9Sstevel@tonic-gate break; 38877c478bd9Sstevel@tonic-gate case FME_DISPROVED: 38887aec1d6eScindi ep->cached_state |= REQMNTS_DISPROVED; 38897aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS DISPROVED "); 38907c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38917c478bd9Sstevel@tonic-gate break; 38927c478bd9Sstevel@tonic-gate case FME_WAIT: 38937aec1d6eScindi ep->cached_state |= REQMNTS_WAIT; 38947aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS WAIT "); 38957c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 38967c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " to "); 38977c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by); 38987c478bd9Sstevel@tonic-gate break; 38997c478bd9Sstevel@tonic-gate default: 39007c478bd9Sstevel@tonic-gate out(O_DIE, "requirements_test: unexpected fme_state"); 39017c478bd9Sstevel@tonic-gate break; 39027c478bd9Sstevel@tonic-gate } 39037c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 39047c478bd9Sstevel@tonic-gate indent_pop(); 39057c478bd9Sstevel@tonic-gate 39067c478bd9Sstevel@tonic-gate return (return_value); 39077c478bd9Sstevel@tonic-gate } 39087c478bd9Sstevel@tonic-gate 39097c478bd9Sstevel@tonic-gate /* this event is not a report, descend the tree */ 39107c478bd9Sstevel@tonic-gate for (bp = itree_next_bubble(ep, NULL); bp; 39117c478bd9Sstevel@tonic-gate bp = itree_next_bubble(ep, bp)) { 39127aec1d6eScindi int n; 39137aec1d6eScindi 39147c478bd9Sstevel@tonic-gate if (bp->t != B_FROM) 39157c478bd9Sstevel@tonic-gate continue; 39167c478bd9Sstevel@tonic-gate 39177aec1d6eScindi n = bp->nork; 39187aec1d6eScindi 39197aec1d6eScindi credible_events = 0; 39207aec1d6eScindi waiting_events = 0; 39217aec1d6eScindi deferred_events = 0; 39227aec1d6eScindi arrow_delay = TIMEVAL_EVENTUALLY; 39237aec1d6eScindi /* 39247aec1d6eScindi * n is -1 for 'A' so adjust it. 39257aec1d6eScindi * XXX just count up the arrows for now. 39267aec1d6eScindi */ 39277aec1d6eScindi if (n < 0) { 39287aec1d6eScindi n = 0; 39297aec1d6eScindi for (ap = itree_next_arrow(bp, NULL); ap; 39307aec1d6eScindi ap = itree_next_arrow(bp, ap)) 39317aec1d6eScindi n++; 39327aec1d6eScindi indent(); 39337aec1d6eScindi out(O_ALTFP|O_VERB, " Bubble Counted N=%d", n); 39347aec1d6eScindi } else { 39357aec1d6eScindi indent(); 39367aec1d6eScindi out(O_ALTFP|O_VERB, " Bubble N=%d", n); 39377aec1d6eScindi } 39387c478bd9Sstevel@tonic-gate 39397aec1d6eScindi if (n == 0) 39407aec1d6eScindi continue; 39417aec1d6eScindi if (!(bp->mark & (BUBBLE_ELIDED|BUBBLE_OK))) { 39427c478bd9Sstevel@tonic-gate for (ap = itree_next_arrow(bp, NULL); ap; 39437c478bd9Sstevel@tonic-gate ap = itree_next_arrow(bp, ap)) { 39447c478bd9Sstevel@tonic-gate ep2 = ap->arrowp->head->myevent; 39457aec1d6eScindi platform_set_payloadnvp(ep2->nvp); 3946b7d3956bSstephh (void) checkconstraints(fmep, ap->arrowp); 39478cffa125SStephen Hanson if (!ap->arrowp->forever_false) { 39487aec1d6eScindi /* 3949b7d3956bSstephh * if all arrows are invalidated by the 39507aec1d6eScindi * constraints, then we should elide the 39517aec1d6eScindi * whole bubble to be consistant with 39527aec1d6eScindi * the tree creation time behaviour 39537aec1d6eScindi */ 3954b7d3956bSstephh bp->mark |= BUBBLE_OK; 39557aec1d6eScindi platform_set_payloadnvp(NULL); 39567c478bd9Sstevel@tonic-gate break; 39577aec1d6eScindi } 39587aec1d6eScindi platform_set_payloadnvp(NULL); 39597aec1d6eScindi } 39607aec1d6eScindi } 39617aec1d6eScindi for (ap = itree_next_arrow(bp, NULL); ap; 39627aec1d6eScindi ap = itree_next_arrow(bp, ap)) { 39637aec1d6eScindi ep2 = ap->arrowp->head->myevent; 39647aec1d6eScindi if (n <= credible_events) 39657aec1d6eScindi break; 39667c478bd9Sstevel@tonic-gate 39677aec1d6eScindi ap->arrowp->mark |= REQMNTS_COUNTER; 39687aec1d6eScindi if (triggered(fmep, ep2, REQMNTS_COUNTER)) 39697aec1d6eScindi /* XXX adding max timevals! */ 39707aec1d6eScindi switch (requirements_test(fmep, ep2, 39717aec1d6eScindi at_latest_by + ap->arrowp->maxdelay, 39727aec1d6eScindi &my_delay)) { 39737aec1d6eScindi case FME_DEFERRED: 39747aec1d6eScindi deferred_events++; 39757aec1d6eScindi break; 39767aec1d6eScindi case FME_CREDIBLE: 39777c478bd9Sstevel@tonic-gate credible_events++; 39787aec1d6eScindi break; 39797aec1d6eScindi case FME_DISPROVED: 39807aec1d6eScindi break; 39817aec1d6eScindi case FME_WAIT: 39827aec1d6eScindi if (my_delay < arrow_delay) 39837aec1d6eScindi arrow_delay = my_delay; 39847aec1d6eScindi waiting_events++; 39857aec1d6eScindi break; 39867aec1d6eScindi default: 39877aec1d6eScindi out(O_DIE, 39887aec1d6eScindi "Bug in requirements_test."); 39897aec1d6eScindi } 39907aec1d6eScindi else 39917aec1d6eScindi deferred_events++; 39927aec1d6eScindi } 3993b7d3956bSstephh if (!(bp->mark & BUBBLE_OK) && waiting_events == 0) { 3994b7d3956bSstephh bp->mark |= BUBBLE_ELIDED; 3995b7d3956bSstephh continue; 3996b7d3956bSstephh } 39977aec1d6eScindi indent(); 39987aec1d6eScindi out(O_ALTFP|O_VERB, " Credible: %d Waiting %d", 39997aec1d6eScindi credible_events + deferred_events, waiting_events); 40007aec1d6eScindi if (credible_events + deferred_events + waiting_events < n) { 40017aec1d6eScindi /* Can never meet requirements */ 40027aec1d6eScindi ep->cached_state |= REQMNTS_DISPROVED; 40037c478bd9Sstevel@tonic-gate indent(); 40047aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS DISPROVED "); 40057c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 40067c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 40077aec1d6eScindi indent_pop(); 40087aec1d6eScindi return (FME_DISPROVED); 40097aec1d6eScindi } 40107aec1d6eScindi if (credible_events + deferred_events < n) { 40117aec1d6eScindi /* will have to wait */ 40127aec1d6eScindi /* wait time is shortest known */ 40137aec1d6eScindi if (arrow_delay < overall_delay) 40147aec1d6eScindi overall_delay = arrow_delay; 40157aec1d6eScindi return_value = FME_WAIT; 40167aec1d6eScindi } else if (credible_events < n) { 40177aec1d6eScindi if (return_value != FME_WAIT) 40187aec1d6eScindi return_value = FME_DEFERRED; 40197c478bd9Sstevel@tonic-gate } 40207c478bd9Sstevel@tonic-gate } 40217c478bd9Sstevel@tonic-gate 40227c478bd9Sstevel@tonic-gate /* 40237aec1d6eScindi * don't mark as FME_DEFERRED. If this event isn't reached by another 40247aec1d6eScindi * path, then this will be considered FME_CREDIBLE. But if it is 40257aec1d6eScindi * reached by a different path so the K-count is met, then might 40267aec1d6eScindi * get overridden by FME_WAIT or FME_DISPROVED. 40277c478bd9Sstevel@tonic-gate */ 40287aec1d6eScindi if (return_value == FME_WAIT) { 40297aec1d6eScindi ep->cached_state |= REQMNTS_WAIT; 40307aec1d6eScindi ep->cached_delay = *pdelay = overall_delay; 40317aec1d6eScindi } else if (return_value == FME_CREDIBLE) { 40327aec1d6eScindi ep->cached_state |= REQMNTS_CREDIBLE; 40337c478bd9Sstevel@tonic-gate } 40347c478bd9Sstevel@tonic-gate indent(); 40357aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-REQMNTS %s ", 40367aec1d6eScindi fme_state2str(return_value)); 40377c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 40387c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 40397c478bd9Sstevel@tonic-gate indent_pop(); 40407c478bd9Sstevel@tonic-gate return (return_value); 40417c478bd9Sstevel@tonic-gate } 40427c478bd9Sstevel@tonic-gate 40437c478bd9Sstevel@tonic-gate static enum fme_state 40447c478bd9Sstevel@tonic-gate causes_test(struct fme *fmep, struct event *ep, 40457c478bd9Sstevel@tonic-gate unsigned long long at_latest_by, unsigned long long *pdelay) 40467c478bd9Sstevel@tonic-gate { 40477c478bd9Sstevel@tonic-gate unsigned long long overall_delay = TIMEVAL_EVENTUALLY; 40487c478bd9Sstevel@tonic-gate unsigned long long my_delay; 40497c478bd9Sstevel@tonic-gate int credible_results = 0; 40507c478bd9Sstevel@tonic-gate int waiting_results = 0; 40517c478bd9Sstevel@tonic-gate enum fme_state fstate; 40527c478bd9Sstevel@tonic-gate struct event *tail_event; 40537c478bd9Sstevel@tonic-gate struct bubble *bp; 40547c478bd9Sstevel@tonic-gate struct arrowlist *ap; 40557c478bd9Sstevel@tonic-gate int k = 1; 40567c478bd9Sstevel@tonic-gate 40577c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Ccallcount); 40587c478bd9Sstevel@tonic-gate indent_push(" C"); 40597c478bd9Sstevel@tonic-gate indent(); 40607c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "->"); 40617c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 40627c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 40637c478bd9Sstevel@tonic-gate 40647c478bd9Sstevel@tonic-gate for (bp = itree_next_bubble(ep, NULL); bp; 40657c478bd9Sstevel@tonic-gate bp = itree_next_bubble(ep, bp)) { 40667c478bd9Sstevel@tonic-gate if (bp->t != B_TO) 40677c478bd9Sstevel@tonic-gate continue; 40687c478bd9Sstevel@tonic-gate k = bp->nork; /* remember the K value */ 40697c478bd9Sstevel@tonic-gate for (ap = itree_next_arrow(bp, NULL); ap; 40707c478bd9Sstevel@tonic-gate ap = itree_next_arrow(bp, ap)) { 40717c478bd9Sstevel@tonic-gate int do_not_follow = 0; 40727aec1d6eScindi 40737aec1d6eScindi /* 40747aec1d6eScindi * if we get to the same event multiple times 40757aec1d6eScindi * only worry about the first one. 40767aec1d6eScindi */ 40777aec1d6eScindi if (ap->arrowp->tail->myevent->cached_state & 40787aec1d6eScindi CAUSES_TESTED) { 40797aec1d6eScindi indent(); 40807aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, 40817aec1d6eScindi " causes test already run for "); 40827aec1d6eScindi itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, 40837aec1d6eScindi ap->arrowp->tail->myevent); 40847aec1d6eScindi out(O_ALTFP|O_VERB, NULL); 40857aec1d6eScindi continue; 40867aec1d6eScindi } 40877aec1d6eScindi 40887c478bd9Sstevel@tonic-gate /* 40897c478bd9Sstevel@tonic-gate * see if false constraint prevents us 40907c478bd9Sstevel@tonic-gate * from traversing this arrow 40917c478bd9Sstevel@tonic-gate */ 40927c478bd9Sstevel@tonic-gate platform_set_payloadnvp(ep->nvp); 409300d0963fSdilpreet if (checkconstraints(fmep, ap->arrowp) == 0) 40947aec1d6eScindi do_not_follow = 1; 40957c478bd9Sstevel@tonic-gate platform_set_payloadnvp(NULL); 40967c478bd9Sstevel@tonic-gate if (do_not_follow) { 40977c478bd9Sstevel@tonic-gate indent(); 40987c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, 40997c478bd9Sstevel@tonic-gate " False arrow from "); 41007c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, 41017c478bd9Sstevel@tonic-gate ap->arrowp->tail->myevent); 41027c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 41037c478bd9Sstevel@tonic-gate continue; 41047c478bd9Sstevel@tonic-gate } 41057c478bd9Sstevel@tonic-gate 41067aec1d6eScindi ap->arrowp->tail->myevent->cached_state |= 41077aec1d6eScindi CAUSES_TESTED; 41087aec1d6eScindi tail_event = ap->arrowp->tail->myevent; 41097aec1d6eScindi fstate = hypothesise(fmep, tail_event, at_latest_by, 41107aec1d6eScindi &my_delay); 41117c478bd9Sstevel@tonic-gate 41127c478bd9Sstevel@tonic-gate switch (fstate) { 41137c478bd9Sstevel@tonic-gate case FME_WAIT: 41147c478bd9Sstevel@tonic-gate if (my_delay < overall_delay) 41157c478bd9Sstevel@tonic-gate overall_delay = my_delay; 41167c478bd9Sstevel@tonic-gate waiting_results++; 41177c478bd9Sstevel@tonic-gate break; 41187c478bd9Sstevel@tonic-gate case FME_CREDIBLE: 41197c478bd9Sstevel@tonic-gate credible_results++; 41207c478bd9Sstevel@tonic-gate break; 41217c478bd9Sstevel@tonic-gate case FME_DISPROVED: 41227c478bd9Sstevel@tonic-gate break; 41237c478bd9Sstevel@tonic-gate default: 41247c478bd9Sstevel@tonic-gate out(O_DIE, "Bug in causes_test"); 41257c478bd9Sstevel@tonic-gate } 41267c478bd9Sstevel@tonic-gate } 41277c478bd9Sstevel@tonic-gate } 41287c478bd9Sstevel@tonic-gate /* compare against K */ 41297c478bd9Sstevel@tonic-gate if (credible_results + waiting_results < k) { 41307c478bd9Sstevel@tonic-gate indent(); 41317aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES DISPROVED "); 41327c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 41337c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 41347c478bd9Sstevel@tonic-gate indent_pop(); 41357c478bd9Sstevel@tonic-gate return (FME_DISPROVED); 41367c478bd9Sstevel@tonic-gate } 41377c478bd9Sstevel@tonic-gate if (waiting_results != 0) { 41387c478bd9Sstevel@tonic-gate *pdelay = overall_delay; 41397c478bd9Sstevel@tonic-gate indent(); 41407aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES WAIT "); 41417c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 41427c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " to "); 41437c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by); 41447c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 41457c478bd9Sstevel@tonic-gate indent_pop(); 41467c478bd9Sstevel@tonic-gate return (FME_WAIT); 41477c478bd9Sstevel@tonic-gate } 41487c478bd9Sstevel@tonic-gate indent(); 41497aec1d6eScindi out(O_ALTFP|O_VERB|O_NONL, "<-CAUSES CREDIBLE "); 41507c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 41517c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 41527c478bd9Sstevel@tonic-gate indent_pop(); 41537c478bd9Sstevel@tonic-gate return (FME_CREDIBLE); 41547c478bd9Sstevel@tonic-gate } 41557c478bd9Sstevel@tonic-gate 41567c478bd9Sstevel@tonic-gate static enum fme_state 41577c478bd9Sstevel@tonic-gate hypothesise(struct fme *fmep, struct event *ep, 4158*a3f6a2a4SRob Johnston unsigned long long at_latest_by, unsigned long long *pdelay) 41597c478bd9Sstevel@tonic-gate { 41607c478bd9Sstevel@tonic-gate enum fme_state rtr, otr; 41617c478bd9Sstevel@tonic-gate unsigned long long my_delay; 41627c478bd9Sstevel@tonic-gate unsigned long long overall_delay = TIMEVAL_EVENTUALLY; 41637c478bd9Sstevel@tonic-gate 41647c478bd9Sstevel@tonic-gate stats_counter_bump(fmep->Hcallcount); 41657c478bd9Sstevel@tonic-gate indent_push(" H"); 41667c478bd9Sstevel@tonic-gate indent(); 41677c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "->"); 41687c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 41697c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, ", at latest by: "); 41707c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB|O_NONL, &at_latest_by); 41717c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 41727c478bd9Sstevel@tonic-gate 41737aec1d6eScindi rtr = requirements_test(fmep, ep, at_latest_by, &my_delay); 41747c478bd9Sstevel@tonic-gate if ((rtr == FME_WAIT) && (my_delay < overall_delay)) 41757c478bd9Sstevel@tonic-gate overall_delay = my_delay; 41767c478bd9Sstevel@tonic-gate if (rtr != FME_DISPROVED) { 41777c478bd9Sstevel@tonic-gate if (is_problem(ep->t)) { 41787aec1d6eScindi otr = effects_test(fmep, ep, at_latest_by, &my_delay); 41797c478bd9Sstevel@tonic-gate if (otr != FME_DISPROVED) { 4180b5016cbbSstephh if (fmep->peek == 0 && ep->is_suspect == 0) { 41817c478bd9Sstevel@tonic-gate ep->suspects = fmep->suspects; 4182b5016cbbSstephh ep->is_suspect = 1; 41837c478bd9Sstevel@tonic-gate fmep->suspects = ep; 41847c478bd9Sstevel@tonic-gate fmep->nsuspects++; 41857c478bd9Sstevel@tonic-gate } 41867c478bd9Sstevel@tonic-gate } 41877c478bd9Sstevel@tonic-gate } else 41887c478bd9Sstevel@tonic-gate otr = causes_test(fmep, ep, at_latest_by, &my_delay); 41897c478bd9Sstevel@tonic-gate if ((otr == FME_WAIT) && (my_delay < overall_delay)) 41907c478bd9Sstevel@tonic-gate overall_delay = my_delay; 41917c478bd9Sstevel@tonic-gate if ((otr != FME_DISPROVED) && 41927c478bd9Sstevel@tonic-gate ((rtr == FME_WAIT) || (otr == FME_WAIT))) 41937c478bd9Sstevel@tonic-gate *pdelay = overall_delay; 41947c478bd9Sstevel@tonic-gate } 41957c478bd9Sstevel@tonic-gate if (rtr == FME_DISPROVED) { 41967c478bd9Sstevel@tonic-gate indent(); 41977c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED "); 41987c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 41997c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, " (doesn't meet requirements)"); 42007c478bd9Sstevel@tonic-gate indent_pop(); 42017c478bd9Sstevel@tonic-gate return (FME_DISPROVED); 42027c478bd9Sstevel@tonic-gate } 42037c478bd9Sstevel@tonic-gate if ((otr == FME_DISPROVED) && is_problem(ep->t)) { 42047c478bd9Sstevel@tonic-gate indent(); 42057c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED "); 42067c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 42077c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, " (doesn't explain all reports)"); 42087c478bd9Sstevel@tonic-gate indent_pop(); 42097c478bd9Sstevel@tonic-gate return (FME_DISPROVED); 42107c478bd9Sstevel@tonic-gate } 42117c478bd9Sstevel@tonic-gate if (otr == FME_DISPROVED) { 42127c478bd9Sstevel@tonic-gate indent(); 42137c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "<-DISPROVED "); 42147c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 42157c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, " (causes are not credible)"); 42167c478bd9Sstevel@tonic-gate indent_pop(); 42177c478bd9Sstevel@tonic-gate return (FME_DISPROVED); 42187c478bd9Sstevel@tonic-gate } 42197c478bd9Sstevel@tonic-gate if ((rtr == FME_WAIT) || (otr == FME_WAIT)) { 42207c478bd9Sstevel@tonic-gate indent(); 42217c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "<-WAIT "); 42227c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 42237c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, " to "); 42247c478bd9Sstevel@tonic-gate ptree_timeval(O_ALTFP|O_VERB|O_NONL, &overall_delay); 42257c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 42267c478bd9Sstevel@tonic-gate indent_pop(); 42277c478bd9Sstevel@tonic-gate return (FME_WAIT); 42287c478bd9Sstevel@tonic-gate } 42297c478bd9Sstevel@tonic-gate indent(); 42307c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB|O_NONL, "<-CREDIBLE "); 42317c478bd9Sstevel@tonic-gate itree_pevent_brief(O_ALTFP|O_VERB|O_NONL, ep); 42327c478bd9Sstevel@tonic-gate out(O_ALTFP|O_VERB, NULL); 42337c478bd9Sstevel@tonic-gate indent_pop(); 42347c478bd9Sstevel@tonic-gate return (FME_CREDIBLE); 42357c478bd9Sstevel@tonic-gate } 42367aec1d6eScindi 42377aec1d6eScindi /* 42387aec1d6eScindi * fme_istat_load -- reconstitute any persistent istats 42397aec1d6eScindi */ 42407aec1d6eScindi void 42417aec1d6eScindi fme_istat_load(fmd_hdl_t *hdl) 42427aec1d6eScindi { 42437aec1d6eScindi int sz; 42447aec1d6eScindi char *sbuf; 42457aec1d6eScindi char *ptr; 42467aec1d6eScindi 42477aec1d6eScindi if ((sz = fmd_buf_size(hdl, NULL, WOBUF_ISTATS)) == 0) { 42487aec1d6eScindi out(O_ALTFP, "fme_istat_load: No stats"); 42497aec1d6eScindi return; 42507aec1d6eScindi } 42517aec1d6eScindi 42527aec1d6eScindi sbuf = alloca(sz); 42537aec1d6eScindi 42547aec1d6eScindi fmd_buf_read(hdl, NULL, WOBUF_ISTATS, sbuf, sz); 42557aec1d6eScindi 42567aec1d6eScindi /* 42577aec1d6eScindi * pick apart the serialized stats 42587aec1d6eScindi * 42597aec1d6eScindi * format is: 42607aec1d6eScindi * <class-name>, '@', <path>, '\0', <value>, '\0' 42617aec1d6eScindi * for example: 42627aec1d6eScindi * "stat.first@stat0/path0\02\0stat.second@stat0/path1\023\0" 42637aec1d6eScindi * 42647aec1d6eScindi * since this is parsing our own serialized data, any parsing issues 42657aec1d6eScindi * are fatal, so we check for them all with ASSERT() below. 42667aec1d6eScindi */ 42677aec1d6eScindi ptr = sbuf; 42687aec1d6eScindi while (ptr < &sbuf[sz]) { 42697aec1d6eScindi char *sepptr; 42707aec1d6eScindi struct node *np; 42717aec1d6eScindi int val; 42727aec1d6eScindi 42737aec1d6eScindi sepptr = strchr(ptr, '@'); 42747aec1d6eScindi ASSERT(sepptr != NULL); 42757aec1d6eScindi *sepptr = '\0'; 42767aec1d6eScindi 42777aec1d6eScindi /* construct the event */ 42787aec1d6eScindi np = newnode(T_EVENT, NULL, 0); 42797aec1d6eScindi np->u.event.ename = newnode(T_NAME, NULL, 0); 42807aec1d6eScindi np->u.event.ename->u.name.t = N_STAT; 42817aec1d6eScindi np->u.event.ename->u.name.s = stable(ptr); 42827aec1d6eScindi np->u.event.ename->u.name.it = IT_ENAME; 42837aec1d6eScindi np->u.event.ename->u.name.last = np->u.event.ename; 42847aec1d6eScindi 42857aec1d6eScindi ptr = sepptr + 1; 42867aec1d6eScindi ASSERT(ptr < &sbuf[sz]); 42877aec1d6eScindi ptr += strlen(ptr); 42887aec1d6eScindi ptr++; /* move past the '\0' separating path from value */ 42897aec1d6eScindi ASSERT(ptr < &sbuf[sz]); 42907aec1d6eScindi ASSERT(isdigit(*ptr)); 42917aec1d6eScindi val = atoi(ptr); 42927aec1d6eScindi ASSERT(val > 0); 42937aec1d6eScindi ptr += strlen(ptr); 42947aec1d6eScindi ptr++; /* move past the final '\0' for this entry */ 42957aec1d6eScindi 42967aec1d6eScindi np->u.event.epname = pathstring2epnamenp(sepptr + 1); 42977aec1d6eScindi ASSERT(np->u.event.epname != NULL); 42987aec1d6eScindi 42997aec1d6eScindi istat_bump(np, val); 43007aec1d6eScindi tree_free(np); 43017aec1d6eScindi } 43027aec1d6eScindi 43037aec1d6eScindi istat_save(); 43047aec1d6eScindi } 4305