1684 /* don't want this to be verbose (unless Debug is set) */
1685 prev_verbose = Verbose;
1686 if (Debug == 0)
1687 Verbose = 0;
1688
1689 lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep);
1690 state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay);
1691
1692 fmep->peek = 0;
1693
1694 /* put verbose flag back */
1695 Verbose = prev_verbose;
1696
1697 if (state != FME_DISPROVED) {
1698 /* found an FME that explains the ereport */
1699 matched++;
1700 out(O_ALTFP|O_NONL, "[");
1701 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1702 out(O_ALTFP, " explained by FME%d]", fmep->id);
1703
1704 if (pre_peek_nvp)
1705 nvlist_free(pre_peek_nvp);
1706
1707 if (ep->count == 1)
1708 serialize_observation(fmep, eventstring, ipp);
1709
1710 if (ffep) {
1711 fmd_case_add_ereport(hdl, fmep->fmcase, ffep);
1712 ep->ffep = ffep;
1713 }
1714
1715 stats_counter_bump(fmep->Rcount);
1716
1717 /* re-eval FME */
1718 fme_eval(fmep, ffep);
1719 } else {
1720
1721 /* not a match, undo noting of observation */
1722 fmep->ecurrent = NULL;
1723 if (--ep->count == 0) {
1724 /* unlink it from observations */
2011
2012 for (nc = n; nc != NULL; nc = nc->u.name.next) {
2013 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2014 if (err != 0) {
2015 failure = "alloc of an hc-pair failed";
2016 goto boom;
2017 }
2018 err = nvlist_add_string(p, FM_FMRI_HC_NAME, nc->u.name.s);
2019 numstr = ulltostr(nc->u.name.child->u.ull, nullbyte);
2020 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
2021 if (err != 0) {
2022 failure = "construction of an hc-pair failed";
2023 goto boom;
2024 }
2025 pa[i++] = p;
2026 }
2027
2028 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2029 if (err == 0) {
2030 for (i = 0; i < depth; i++)
2031 if (pa[i] != NULL)
2032 nvlist_free(pa[i]);
2033 return (f);
2034 }
2035 failure = "addition of hc-pair array to FMRI failed";
2036
2037 boom:
2038 for (i = 0; i < depth; i++)
2039 if (pa[i] != NULL)
2040 nvlist_free(pa[i]);
2041 nvlist_free(f);
2042 out(O_DIE, "%s", failure);
2043 /*NOTREACHED*/
2044 return (NULL);
2045 }
2046
2047 /* an ipath cache entry is an array of these, with s==NULL at the end */
2048 struct ipath {
2049 const char *s; /* component name (in stable) */
2050 int i; /* instance number */
2051 };
2052
2053 static nvlist_t *
2054 ipath2fmri(struct ipath *ipath)
2055 {
2056 nvlist_t **pa, *f, *p;
2057 uint_t depth = 0;
2058 char *numstr, *nullbyte;
2059 char *failure;
2084
2085 for (ipp = ipath; ipp->s != NULL; ipp++) {
2086 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2087 if (err != 0) {
2088 failure = "alloc of an hc-pair failed";
2089 goto boom;
2090 }
2091 err = nvlist_add_string(p, FM_FMRI_HC_NAME, ipp->s);
2092 numstr = ulltostr(ipp->i, nullbyte);
2093 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
2094 if (err != 0) {
2095 failure = "construction of an hc-pair failed";
2096 goto boom;
2097 }
2098 pa[i++] = p;
2099 }
2100
2101 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2102 if (err == 0) {
2103 for (i = 0; i < depth; i++)
2104 if (pa[i] != NULL)
2105 nvlist_free(pa[i]);
2106 return (f);
2107 }
2108 failure = "addition of hc-pair array to FMRI failed";
2109
2110 boom:
2111 for (i = 0; i < depth; i++)
2112 if (pa[i] != NULL)
2113 nvlist_free(pa[i]);
2114 nvlist_free(f);
2115 out(O_DIE, "%s", failure);
2116 /*NOTREACHED*/
2117 return (NULL);
2118 }
2119
2120 static uint8_t
2121 percentof(uint_t part, uint_t whole)
2122 {
2123 unsigned long long p = part * 1000;
2124
2125 return ((p / whole / 10) + (((p / whole % 10) >= 5) ? 1 : 0));
2126 }
2127
2128 struct rsl {
2129 struct event *suspect;
2130 nvlist_t *asru;
2131 nvlist_t *fru;
2132 nvlist_t *rsrc;
2133 };
2134
2135 static void publish_suspects(struct fme *fmep, struct rsl *srl);
2136
2137 /*
2138 * rslfree -- free internal members of struct rsl not expected to be
2139 * freed elsewhere.
2140 */
2141 static void
2142 rslfree(struct rsl *freeme)
2143 {
2144 if (freeme->asru != NULL)
2145 nvlist_free(freeme->asru);
2146 if (freeme->fru != NULL)
2147 nvlist_free(freeme->fru);
2148 if (freeme->rsrc != NULL && freeme->rsrc != freeme->asru)
2149 nvlist_free(freeme->rsrc);
2150 }
2151
2152 /*
2153 * rslcmp -- compare two rsl structures. Use the following
2154 * comparisons to establish cardinality:
2155 *
2156 * 1. Name of the suspect's class. (simple strcmp)
2157 * 2. Name of the suspect's ASRU. (trickier, since nvlist)
2158 *
2159 */
2160 static int
2161 rslcmp(const void *a, const void *b)
2162 {
2163 struct rsl *r1 = (struct rsl *)a;
2164 struct rsl *r2 = (struct rsl *)b;
2165 int rv;
2166
2167 rv = strcmp(r1->suspect->enode->u.event.ename->u.name.s,
2168 r2->suspect->enode->u.event.ename->u.name.s);
|
1684 /* don't want this to be verbose (unless Debug is set) */
1685 prev_verbose = Verbose;
1686 if (Debug == 0)
1687 Verbose = 0;
1688
1689 lut_walk(fmep->eventtree, (lut_cb)clear_arrows, (void *)fmep);
1690 state = hypothesise(fmep, fmep->e0, fmep->ull, &my_delay);
1691
1692 fmep->peek = 0;
1693
1694 /* put verbose flag back */
1695 Verbose = prev_verbose;
1696
1697 if (state != FME_DISPROVED) {
1698 /* found an FME that explains the ereport */
1699 matched++;
1700 out(O_ALTFP|O_NONL, "[");
1701 ipath_print(O_ALTFP|O_NONL, eventstring, ipp);
1702 out(O_ALTFP, " explained by FME%d]", fmep->id);
1703
1704 nvlist_free(pre_peek_nvp);
1705
1706 if (ep->count == 1)
1707 serialize_observation(fmep, eventstring, ipp);
1708
1709 if (ffep) {
1710 fmd_case_add_ereport(hdl, fmep->fmcase, ffep);
1711 ep->ffep = ffep;
1712 }
1713
1714 stats_counter_bump(fmep->Rcount);
1715
1716 /* re-eval FME */
1717 fme_eval(fmep, ffep);
1718 } else {
1719
1720 /* not a match, undo noting of observation */
1721 fmep->ecurrent = NULL;
1722 if (--ep->count == 0) {
1723 /* unlink it from observations */
2010
2011 for (nc = n; nc != NULL; nc = nc->u.name.next) {
2012 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2013 if (err != 0) {
2014 failure = "alloc of an hc-pair failed";
2015 goto boom;
2016 }
2017 err = nvlist_add_string(p, FM_FMRI_HC_NAME, nc->u.name.s);
2018 numstr = ulltostr(nc->u.name.child->u.ull, nullbyte);
2019 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
2020 if (err != 0) {
2021 failure = "construction of an hc-pair failed";
2022 goto boom;
2023 }
2024 pa[i++] = p;
2025 }
2026
2027 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2028 if (err == 0) {
2029 for (i = 0; i < depth; i++)
2030 nvlist_free(pa[i]);
2031 return (f);
2032 }
2033 failure = "addition of hc-pair array to FMRI failed";
2034
2035 boom:
2036 for (i = 0; i < depth; i++)
2037 nvlist_free(pa[i]);
2038 nvlist_free(f);
2039 out(O_DIE, "%s", failure);
2040 /*NOTREACHED*/
2041 return (NULL);
2042 }
2043
2044 /* an ipath cache entry is an array of these, with s==NULL at the end */
2045 struct ipath {
2046 const char *s; /* component name (in stable) */
2047 int i; /* instance number */
2048 };
2049
2050 static nvlist_t *
2051 ipath2fmri(struct ipath *ipath)
2052 {
2053 nvlist_t **pa, *f, *p;
2054 uint_t depth = 0;
2055 char *numstr, *nullbyte;
2056 char *failure;
2081
2082 for (ipp = ipath; ipp->s != NULL; ipp++) {
2083 err = nvlist_xalloc(&p, NV_UNIQUE_NAME, &Eft_nv_hdl);
2084 if (err != 0) {
2085 failure = "alloc of an hc-pair failed";
2086 goto boom;
2087 }
2088 err = nvlist_add_string(p, FM_FMRI_HC_NAME, ipp->s);
2089 numstr = ulltostr(ipp->i, nullbyte);
2090 err |= nvlist_add_string(p, FM_FMRI_HC_ID, numstr);
2091 if (err != 0) {
2092 failure = "construction of an hc-pair failed";
2093 goto boom;
2094 }
2095 pa[i++] = p;
2096 }
2097
2098 err = nvlist_add_nvlist_array(f, FM_FMRI_HC_LIST, pa, depth);
2099 if (err == 0) {
2100 for (i = 0; i < depth; i++)
2101 nvlist_free(pa[i]);
2102 return (f);
2103 }
2104 failure = "addition of hc-pair array to FMRI failed";
2105
2106 boom:
2107 for (i = 0; i < depth; i++)
2108 nvlist_free(pa[i]);
2109 nvlist_free(f);
2110 out(O_DIE, "%s", failure);
2111 /*NOTREACHED*/
2112 return (NULL);
2113 }
2114
2115 static uint8_t
2116 percentof(uint_t part, uint_t whole)
2117 {
2118 unsigned long long p = part * 1000;
2119
2120 return ((p / whole / 10) + (((p / whole % 10) >= 5) ? 1 : 0));
2121 }
2122
2123 struct rsl {
2124 struct event *suspect;
2125 nvlist_t *asru;
2126 nvlist_t *fru;
2127 nvlist_t *rsrc;
2128 };
2129
2130 static void publish_suspects(struct fme *fmep, struct rsl *srl);
2131
2132 /*
2133 * rslfree -- free internal members of struct rsl not expected to be
2134 * freed elsewhere.
2135 */
2136 static void
2137 rslfree(struct rsl *freeme)
2138 {
2139 nvlist_free(freeme->asru);
2140 nvlist_free(freeme->fru);
2141 if (freeme->rsrc != freeme->asru)
2142 nvlist_free(freeme->rsrc);
2143 }
2144
2145 /*
2146 * rslcmp -- compare two rsl structures. Use the following
2147 * comparisons to establish cardinality:
2148 *
2149 * 1. Name of the suspect's class. (simple strcmp)
2150 * 2. Name of the suspect's ASRU. (trickier, since nvlist)
2151 *
2152 */
2153 static int
2154 rslcmp(const void *a, const void *b)
2155 {
2156 struct rsl *r1 = (struct rsl *)a;
2157 struct rsl *r2 = (struct rsl *)b;
2158 int rv;
2159
2160 rv = strcmp(r1->suspect->enode->u.event.ename->u.name.s,
2161 r2->suspect->enode->u.event.ename->u.name.s);
|