7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #include <sys/fm/protocol.h>
  28 #include <fm/fmd_msg.h>
  29 #include <strings.h>
  30 #include <alloca.h>
  31 #include <stdio.h>
  32 
  33 #include <fmd_protocol.h>
  34 #include <fmd_module.h>
  35 #include <fmd_conf.h>
  36 #include <fmd_subr.h>
  37 #include <fmd_error.h>
  38 #include <fmd_time.h>
  39 #include <fmd.h>
  40 
  41 /*
  42  * Create an FMRI authority element for the environment in which this instance
  43  * of fmd is deployed.  This function is called once and the result is cached.
  44  */
  45 nvlist_t *
  46 fmd_protocol_authority(void)
  47 {
  48         const char *str;
  49         nvlist_t *nvl;
  50         int err = 0;
  51 
 
 131         if (resource != NULL)
 132                 err |= nvlist_add_nvlist(nvl, FM_FAULT_RESOURCE, resource);
 133         if (location != NULL)
 134                 err |= nvlist_add_string(nvl, FM_FAULT_LOCATION, location);
 135 
 136         if (err != 0)
 137                 fmd_panic("failed to populate nvlist: %s\n", fmd_strerror(err));
 138 
 139         return (nvl);
 140 }
 141 
 142 nvlist_t *
 143 fmd_protocol_list(const char *class, nvlist_t *de_fmri, const char *uuid,
 144     const char *code, uint_t argc, nvlist_t **argv, uint8_t *flagv, int domsg,
 145     struct timeval *tvp, int injected)
 146 {
 147         int64_t tod[2];
 148         nvlist_t *nvl;
 149         int err = 0;
 150         fmd_msg_hdl_t *msghdl;
 151         char *severity;
 152 
 153         tod[0] = tvp->tv_sec;
 154         tod[1] = tvp->tv_usec;
 155 
 156         if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, &fmd.d_nva) != 0)
 157                 fmd_panic("failed to xalloc suspect list nvlist");
 158 
 159         err |= nvlist_add_uint8(nvl, FM_VERSION, FM_SUSPECT_VERSION);
 160         err |= nvlist_add_string(nvl, FM_CLASS, class);
 161         err |= nvlist_add_string(nvl, FM_SUSPECT_UUID, uuid);
 162         err |= nvlist_add_string(nvl, FM_SUSPECT_DIAG_CODE, code);
 163         err |= nvlist_add_int64_array(nvl, FM_SUSPECT_DIAG_TIME, tod, 2);
 164         err |= nvlist_add_nvlist(nvl, FM_SUSPECT_DE, de_fmri);
 165         err |= nvlist_add_uint32(nvl, FM_SUSPECT_FAULT_SZ, argc);
 166 
 167         if (injected)
 168                 err |= nvlist_add_boolean_value(nvl, FM_SUSPECT_INJECTED,
 169                     B_TRUE);
 170 
 171         if (!domsg) {
 172                 err |= nvlist_add_boolean_value(nvl,
 173                     FM_SUSPECT_MESSAGE, B_FALSE);
 174         }
 175 
 176         if (argc != 0) {
 177                 err |= nvlist_add_nvlist_array(nvl,
 178                     FM_SUSPECT_FAULT_LIST, argv, argc);
 179                 err |= nvlist_add_uint8_array(nvl,
 180                     FM_SUSPECT_FAULT_STATUS, flagv, argc);
 181         }
 182 
 183         /*
 184          * Attempt to lookup the severity associated with this diagnosis from
 185          * the portable object file using the diag code.  Failure to init
 186          * libfmd_msg or add to the nvlist will be treated as fatal.  However,
 187          * we won't treat a fmd_msg_getitem_id failure as fatal since during
 188          * development it's not uncommon to be working with po/dict files that
 189          * haven't yet been updated with newly added diagnoses.
 190          */
 191         msghdl = fmd_msg_init(fmd.d_rootdir, FMD_MSG_VERSION);
 192         if (msghdl == NULL)
 193                 fmd_panic("failed to initialize libfmd_msg\n");
 194 
 195         if ((severity = fmd_msg_getitem_id(msghdl, NULL, code,
 196             FMD_MSG_ITEM_SEVERITY)) != NULL) {
 197                 err |= nvlist_add_string(nvl, FM_SUSPECT_SEVERITY, severity);
 198                 free(severity);
 199         }
 200         fmd_msg_fini(msghdl);
 201 
 202         if (err != 0)
 203                 fmd_panic("failed to populate nvlist: %s\n", fmd_strerror(err));
 204 
 205         return (nvl);
 206 }
 207 
 208 nvlist_t *
 209 fmd_protocol_rsrc_asru(const char *class,
 210     nvlist_t *fmri, const char *uuid, const char *code,
 211     boolean_t faulty, boolean_t unusable, boolean_t message, nvlist_t *event,
 212     struct timeval *tvp, boolean_t repaired, boolean_t replaced,
 213     boolean_t acquitted, boolean_t resolved, nvlist_t *diag_de,
 214     boolean_t injected)
 215 {
 216         nvlist_t *nvl;
 217         int64_t tod[2];
 218         int err = 0;
 219 
 
 | 
 
 
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  * Copyright 2018 Nexenta Systems, Inc.
  29  */
  30 
  31 #include <sys/fm/protocol.h>
  32 
  33 #include <fm/fmd_msg.h>
  34 
  35 #include <alloca.h>
  36 #include <stdio.h>
  37 #include <strings.h>
  38 
  39 #include <fmd_protocol.h>
  40 #include <fmd_module.h>
  41 #include <fmd_conf.h>
  42 #include <fmd_subr.h>
  43 #include <fmd_error.h>
  44 #include <fmd_time.h>
  45 #include <fmd.h>
  46 
  47 /*
  48  * Create an FMRI authority element for the environment in which this instance
  49  * of fmd is deployed.  This function is called once and the result is cached.
  50  */
  51 nvlist_t *
  52 fmd_protocol_authority(void)
  53 {
  54         const char *str;
  55         nvlist_t *nvl;
  56         int err = 0;
  57 
 
 137         if (resource != NULL)
 138                 err |= nvlist_add_nvlist(nvl, FM_FAULT_RESOURCE, resource);
 139         if (location != NULL)
 140                 err |= nvlist_add_string(nvl, FM_FAULT_LOCATION, location);
 141 
 142         if (err != 0)
 143                 fmd_panic("failed to populate nvlist: %s\n", fmd_strerror(err));
 144 
 145         return (nvl);
 146 }
 147 
 148 nvlist_t *
 149 fmd_protocol_list(const char *class, nvlist_t *de_fmri, const char *uuid,
 150     const char *code, uint_t argc, nvlist_t **argv, uint8_t *flagv, int domsg,
 151     struct timeval *tvp, int injected)
 152 {
 153         int64_t tod[2];
 154         nvlist_t *nvl;
 155         int err = 0;
 156         fmd_msg_hdl_t *msghdl;
 157         char *item;
 158 
 159         tod[0] = tvp->tv_sec;
 160         tod[1] = tvp->tv_usec;
 161 
 162         if (nvlist_xalloc(&nvl, NV_UNIQUE_NAME, &fmd.d_nva) != 0)
 163                 fmd_panic("failed to xalloc suspect list nvlist");
 164 
 165         err |= nvlist_add_uint8(nvl, FM_VERSION, FM_SUSPECT_VERSION);
 166         err |= nvlist_add_string(nvl, FM_CLASS, class);
 167         err |= nvlist_add_string(nvl, FM_SUSPECT_UUID, uuid);
 168         err |= nvlist_add_string(nvl, FM_SUSPECT_DIAG_CODE, code);
 169         err |= nvlist_add_int64_array(nvl, FM_SUSPECT_DIAG_TIME, tod, 2);
 170         err |= nvlist_add_nvlist(nvl, FM_SUSPECT_DE, de_fmri);
 171         err |= nvlist_add_uint32(nvl, FM_SUSPECT_FAULT_SZ, argc);
 172 
 173         if (injected)
 174                 err |= nvlist_add_boolean_value(nvl, FM_SUSPECT_INJECTED,
 175                     B_TRUE);
 176 
 177         if (!domsg) {
 178                 err |= nvlist_add_boolean_value(nvl,
 179                     FM_SUSPECT_MESSAGE, B_FALSE);
 180         }
 181 
 182         if (argc != 0) {
 183                 err |= nvlist_add_nvlist_array(nvl,
 184                     FM_SUSPECT_FAULT_LIST, argv, argc);
 185                 err |= nvlist_add_uint8_array(nvl,
 186                     FM_SUSPECT_FAULT_STATUS, flagv, argc);
 187         }
 188 
 189         /*
 190          * Attempt to lookup the type, severity, and description associated with
 191          * this diagnosis from the portable object file using the diag code.
 192          * Failure to init libfmd_msg or add to the nvlist will be treated as
 193          * fatal.  However, we won't treat a fmd_msg_getitem_id failure as fatal
 194          * since during development it's not uncommon to be working with po/dict
 195          * files that haven't yet been updated with newly added diagnoses.
 196          */
 197         msghdl = fmd_msg_init(fmd.d_rootdir, FMD_MSG_VERSION);
 198         if (msghdl == NULL)
 199                 fmd_panic("failed to initialize libfmd_msg\n");
 200 
 201         if ((item = fmd_msg_getitem_id(msghdl, NULL, code,
 202             FMD_MSG_ITEM_TYPE)) != NULL) {
 203                 err |= nvlist_add_string(nvl, FM_SUSPECT_TYPE, item);
 204                 free(item);
 205         }
 206         if ((item = fmd_msg_getitem_id(msghdl, NULL, code,
 207             FMD_MSG_ITEM_SEVERITY)) != NULL) {
 208                 err |= nvlist_add_string(nvl, FM_SUSPECT_SEVERITY, item);
 209                 free(item);
 210         }
 211         if ((item = fmd_msg_getitem_id(msghdl, NULL, code,
 212             FMD_MSG_ITEM_DESC)) != NULL) {
 213                 err |= nvlist_add_string(nvl, FM_SUSPECT_DESC, item);
 214                 free(item);
 215         }
 216         fmd_msg_fini(msghdl);
 217 
 218         if (err != 0)
 219                 fmd_panic("failed to populate nvlist: %s\n", fmd_strerror(err));
 220 
 221         return (nvl);
 222 }
 223 
 224 nvlist_t *
 225 fmd_protocol_rsrc_asru(const char *class,
 226     nvlist_t *fmri, const char *uuid, const char *code,
 227     boolean_t faulty, boolean_t unusable, boolean_t message, nvlist_t *event,
 228     struct timeval *tvp, boolean_t repaired, boolean_t replaced,
 229     boolean_t acquitted, boolean_t resolved, nvlist_t *diag_de,
 230     boolean_t injected)
 231 {
 232         nvlist_t *nvl;
 233         int64_t tod[2];
 234         int err = 0;
 235 
 
 |