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 580ab886dSwesolows * Common Development and Distribution License (the "License"). 680ab886dSwesolows * 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 */ 21d9638e54Smws 227c478bd9Sstevel@tonic-gate /* 23*24db4641Seschrock * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _FMD_API_H 287c478bd9Sstevel@tonic-gate #define _FMD_API_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <libnvpair.h> 347c478bd9Sstevel@tonic-gate #include <stdarg.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Fault Management Daemon Client Interfaces 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * Note: The contents of this file are private to the implementation of the 447c478bd9Sstevel@tonic-gate * Solaris system and FMD subsystem and are subject to change at any time 457c478bd9Sstevel@tonic-gate * without notice. Applications and drivers using these interfaces will fail 467c478bd9Sstevel@tonic-gate * to run on future releases. These interfaces should not be used for any 477c478bd9Sstevel@tonic-gate * purpose until they are publicly documented for use outside of Sun. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #define FMD_API_VERSION_1 1 517c478bd9Sstevel@tonic-gate #define FMD_API_VERSION_2 2 52d9638e54Smws #define FMD_API_VERSION_3 3 53*24db4641Seschrock #define FMD_API_VERSION_4 4 547c478bd9Sstevel@tonic-gate 55*24db4641Seschrock #define FMD_API_VERSION FMD_API_VERSION_4 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate typedef struct fmd_hdl fmd_hdl_t; 587c478bd9Sstevel@tonic-gate typedef struct fmd_event fmd_event_t; 597c478bd9Sstevel@tonic-gate typedef struct fmd_case fmd_case_t; 60d9638e54Smws typedef struct fmd_xprt fmd_xprt_t; 617c478bd9Sstevel@tonic-gate 627aec1d6eScindi struct topo_hdl; 637aec1d6eScindi 647c478bd9Sstevel@tonic-gate #define FMD_B_FALSE 0 /* false value for booleans as int */ 657c478bd9Sstevel@tonic-gate #define FMD_B_TRUE 1 /* true value for booleans as int */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #ifndef MIN 687c478bd9Sstevel@tonic-gate #define MIN(x, y) ((x) < (y) ? (x) : (y)) 697c478bd9Sstevel@tonic-gate #endif 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate #ifndef MAX 727c478bd9Sstevel@tonic-gate #define MAX(x, y) ((x) > (y) ? (x) : (y)) 737c478bd9Sstevel@tonic-gate #endif 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #define FMD_TYPE_BOOL 0 /* int */ 767c478bd9Sstevel@tonic-gate #define FMD_TYPE_INT32 1 /* int32_t */ 777c478bd9Sstevel@tonic-gate #define FMD_TYPE_UINT32 2 /* uint32_t */ 787c478bd9Sstevel@tonic-gate #define FMD_TYPE_INT64 3 /* int64_t */ 797c478bd9Sstevel@tonic-gate #define FMD_TYPE_UINT64 4 /* uint64_t */ 807c478bd9Sstevel@tonic-gate #define FMD_TYPE_STRING 5 /* const char* */ 817c478bd9Sstevel@tonic-gate #define FMD_TYPE_TIME 6 /* uint64_t */ 827c478bd9Sstevel@tonic-gate #define FMD_TYPE_SIZE 7 /* uint64_t */ 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate typedef struct fmd_prop { 857c478bd9Sstevel@tonic-gate const char *fmdp_name; /* property name */ 867c478bd9Sstevel@tonic-gate uint_t fmdp_type; /* property type (see above) */ 877c478bd9Sstevel@tonic-gate const char *fmdp_defv; /* default value */ 887c478bd9Sstevel@tonic-gate } fmd_prop_t; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate typedef struct fmd_stat { 917c478bd9Sstevel@tonic-gate char fmds_name[32]; /* statistic name */ 927c478bd9Sstevel@tonic-gate uint_t fmds_type; /* statistic type (see above) */ 937c478bd9Sstevel@tonic-gate char fmds_desc[64]; /* statistic description */ 947c478bd9Sstevel@tonic-gate union { 957c478bd9Sstevel@tonic-gate int bool; /* FMD_TYPE_BOOL */ 967c478bd9Sstevel@tonic-gate int32_t i32; /* FMD_TYPE_INT32 */ 977c478bd9Sstevel@tonic-gate uint32_t ui32; /* FMD_TYPE_UINT32 */ 987c478bd9Sstevel@tonic-gate int64_t i64; /* FMD_TYPE_INT64 */ 997c478bd9Sstevel@tonic-gate uint64_t ui64; /* FMD_TYPE_UINT64, TIME, SIZE */ 1007c478bd9Sstevel@tonic-gate char *str; /* FMD_TYPE_STRING */ 1017c478bd9Sstevel@tonic-gate } fmds_value; 1027c478bd9Sstevel@tonic-gate } fmd_stat_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate typedef struct fmd_hdl_ops { 1057c478bd9Sstevel@tonic-gate void (*fmdo_recv)(fmd_hdl_t *, fmd_event_t *, nvlist_t *, const char *); 1067c478bd9Sstevel@tonic-gate void (*fmdo_timeout)(fmd_hdl_t *, id_t, void *); 1077c478bd9Sstevel@tonic-gate void (*fmdo_close)(fmd_hdl_t *, fmd_case_t *); 1087c478bd9Sstevel@tonic-gate void (*fmdo_stats)(fmd_hdl_t *); 1097c478bd9Sstevel@tonic-gate void (*fmdo_gc)(fmd_hdl_t *); 110d9638e54Smws int (*fmdo_send)(fmd_hdl_t *, fmd_xprt_t *, fmd_event_t *, nvlist_t *); 111*24db4641Seschrock void (*fmdo_topo)(fmd_hdl_t *, struct topo_hdl *); 1127c478bd9Sstevel@tonic-gate } fmd_hdl_ops_t; 1137c478bd9Sstevel@tonic-gate 114d9638e54Smws #define FMD_SEND_SUCCESS 0 /* fmdo_send queued event */ 115d9638e54Smws #define FMD_SEND_FAILED 1 /* fmdo_send unrecoverable error */ 116d9638e54Smws #define FMD_SEND_RETRY 2 /* fmdo_send requests retry */ 117d9638e54Smws 1187c478bd9Sstevel@tonic-gate typedef struct fmd_hdl_info { 1197c478bd9Sstevel@tonic-gate const char *fmdi_desc; /* fmd client description string */ 1207c478bd9Sstevel@tonic-gate const char *fmdi_vers; /* fmd client version string */ 1217c478bd9Sstevel@tonic-gate const fmd_hdl_ops_t *fmdi_ops; /* ops vector for client */ 1227c478bd9Sstevel@tonic-gate const fmd_prop_t *fmdi_props; /* array of configuration props */ 1237c478bd9Sstevel@tonic-gate } fmd_hdl_info_t; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate extern void _fmd_init(fmd_hdl_t *); 1267c478bd9Sstevel@tonic-gate extern void _fmd_fini(fmd_hdl_t *); 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate extern int fmd_hdl_register(fmd_hdl_t *, int, const fmd_hdl_info_t *); 1297c478bd9Sstevel@tonic-gate extern void fmd_hdl_unregister(fmd_hdl_t *); 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate extern void fmd_hdl_subscribe(fmd_hdl_t *, const char *); 1327c478bd9Sstevel@tonic-gate extern void fmd_hdl_unsubscribe(fmd_hdl_t *, const char *); 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate extern void fmd_hdl_setspecific(fmd_hdl_t *, void *); 1357c478bd9Sstevel@tonic-gate extern void *fmd_hdl_getspecific(fmd_hdl_t *); 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate extern void fmd_hdl_opendict(fmd_hdl_t *, const char *); 138*24db4641Seschrock extern struct topo_hdl *fmd_hdl_topo_hold(fmd_hdl_t *, int); 139*24db4641Seschrock extern void fmd_hdl_topo_rele(fmd_hdl_t *, struct topo_hdl *); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #define FMD_NOSLEEP 0x0 /* do not sleep or retry on failure */ 1427c478bd9Sstevel@tonic-gate #define FMD_SLEEP 0x1 /* sleep or retry if alloc fails */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate extern void *fmd_hdl_alloc(fmd_hdl_t *, size_t, int); 1457c478bd9Sstevel@tonic-gate extern void *fmd_hdl_zalloc(fmd_hdl_t *, size_t, int); 1467c478bd9Sstevel@tonic-gate extern void fmd_hdl_free(fmd_hdl_t *, void *, size_t); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate extern char *fmd_hdl_strdup(fmd_hdl_t *, const char *, int); 1497c478bd9Sstevel@tonic-gate extern void fmd_hdl_strfree(fmd_hdl_t *, char *); 1507c478bd9Sstevel@tonic-gate 15180ab886dSwesolows extern void fmd_hdl_vabort(fmd_hdl_t *, const char *, va_list) __NORETURN; 15280ab886dSwesolows extern void fmd_hdl_abort(fmd_hdl_t *, const char *, ...) __NORETURN; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate extern void fmd_hdl_verror(fmd_hdl_t *, const char *, va_list); 1557c478bd9Sstevel@tonic-gate extern void fmd_hdl_error(fmd_hdl_t *, const char *, ...); 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate extern void fmd_hdl_vdebug(fmd_hdl_t *, const char *, va_list); 1587c478bd9Sstevel@tonic-gate extern void fmd_hdl_debug(fmd_hdl_t *, const char *, ...); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern int32_t fmd_prop_get_int32(fmd_hdl_t *, const char *); 1617c478bd9Sstevel@tonic-gate extern int64_t fmd_prop_get_int64(fmd_hdl_t *, const char *); 1627c478bd9Sstevel@tonic-gate extern char *fmd_prop_get_string(fmd_hdl_t *, const char *); 1637c478bd9Sstevel@tonic-gate extern void fmd_prop_free_string(fmd_hdl_t *, char *); 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate #define FMD_STAT_NOALLOC 0x0 /* fmd should use caller's memory */ 1667c478bd9Sstevel@tonic-gate #define FMD_STAT_ALLOC 0x1 /* fmd should allocate stats memory */ 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate extern fmd_stat_t *fmd_stat_create(fmd_hdl_t *, uint_t, uint_t, fmd_stat_t *); 1697c478bd9Sstevel@tonic-gate extern void fmd_stat_destroy(fmd_hdl_t *, uint_t, fmd_stat_t *); 1707c478bd9Sstevel@tonic-gate extern void fmd_stat_setstr(fmd_hdl_t *, fmd_stat_t *, const char *); 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate extern fmd_case_t *fmd_case_open(fmd_hdl_t *, void *); 1737c478bd9Sstevel@tonic-gate extern void fmd_case_reset(fmd_hdl_t *, fmd_case_t *); 1747c478bd9Sstevel@tonic-gate extern void fmd_case_solve(fmd_hdl_t *, fmd_case_t *); 1757c478bd9Sstevel@tonic-gate extern void fmd_case_close(fmd_hdl_t *, fmd_case_t *); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate extern const char *fmd_case_uuid(fmd_hdl_t *, fmd_case_t *); 1787c478bd9Sstevel@tonic-gate extern fmd_case_t *fmd_case_uulookup(fmd_hdl_t *, const char *); 1797c478bd9Sstevel@tonic-gate extern void fmd_case_uuclose(fmd_hdl_t *, const char *); 1807c478bd9Sstevel@tonic-gate extern int fmd_case_uuclosed(fmd_hdl_t *, const char *); 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate extern int fmd_case_solved(fmd_hdl_t *, fmd_case_t *); 1837c478bd9Sstevel@tonic-gate extern int fmd_case_closed(fmd_hdl_t *, fmd_case_t *); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate extern void fmd_case_add_ereport(fmd_hdl_t *, fmd_case_t *, fmd_event_t *); 1867c478bd9Sstevel@tonic-gate extern void fmd_case_add_serd(fmd_hdl_t *, fmd_case_t *, const char *); 1877c478bd9Sstevel@tonic-gate extern void fmd_case_add_suspect(fmd_hdl_t *, fmd_case_t *, nvlist_t *); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate extern void fmd_case_setspecific(fmd_hdl_t *, fmd_case_t *, void *); 1907c478bd9Sstevel@tonic-gate extern void *fmd_case_getspecific(fmd_hdl_t *, fmd_case_t *); 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate extern void fmd_case_setprincipal(fmd_hdl_t *, fmd_case_t *, fmd_event_t *); 1937c478bd9Sstevel@tonic-gate extern fmd_event_t *fmd_case_getprincipal(fmd_hdl_t *, fmd_case_t *); 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate extern fmd_case_t *fmd_case_next(fmd_hdl_t *, fmd_case_t *); 1967c478bd9Sstevel@tonic-gate extern fmd_case_t *fmd_case_prev(fmd_hdl_t *, fmd_case_t *); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate extern void fmd_buf_create(fmd_hdl_t *, fmd_case_t *, const char *, size_t); 1997c478bd9Sstevel@tonic-gate extern void fmd_buf_destroy(fmd_hdl_t *, fmd_case_t *, const char *); 2007c478bd9Sstevel@tonic-gate extern void fmd_buf_read(fmd_hdl_t *, fmd_case_t *, 2017c478bd9Sstevel@tonic-gate const char *, void *, size_t); 2027c478bd9Sstevel@tonic-gate extern void fmd_buf_write(fmd_hdl_t *, fmd_case_t *, 2037c478bd9Sstevel@tonic-gate const char *, const void *, size_t); 2047c478bd9Sstevel@tonic-gate extern size_t fmd_buf_size(fmd_hdl_t *, fmd_case_t *, const char *); 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate extern void fmd_serd_create(fmd_hdl_t *, const char *, uint_t, hrtime_t); 2077c478bd9Sstevel@tonic-gate extern void fmd_serd_destroy(fmd_hdl_t *, const char *); 2087c478bd9Sstevel@tonic-gate extern int fmd_serd_exists(fmd_hdl_t *, const char *); 2097c478bd9Sstevel@tonic-gate extern void fmd_serd_reset(fmd_hdl_t *, const char *); 2107c478bd9Sstevel@tonic-gate extern int fmd_serd_record(fmd_hdl_t *, const char *, fmd_event_t *); 2117c478bd9Sstevel@tonic-gate extern int fmd_serd_fired(fmd_hdl_t *, const char *); 2127c478bd9Sstevel@tonic-gate extern int fmd_serd_empty(fmd_hdl_t *, const char *); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate extern pthread_t fmd_thr_create(fmd_hdl_t *, void (*)(void *), void *); 2157c478bd9Sstevel@tonic-gate extern void fmd_thr_destroy(fmd_hdl_t *, pthread_t); 2167c478bd9Sstevel@tonic-gate extern void fmd_thr_signal(fmd_hdl_t *, pthread_t); 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate extern id_t fmd_timer_install(fmd_hdl_t *, void *, fmd_event_t *, hrtime_t); 2197c478bd9Sstevel@tonic-gate extern void fmd_timer_remove(fmd_hdl_t *, id_t); 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate extern nvlist_t *fmd_nvl_create_fault(fmd_hdl_t *, 2227c478bd9Sstevel@tonic-gate const char *, uint8_t, nvlist_t *, nvlist_t *, nvlist_t *); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate extern int fmd_nvl_class_match(fmd_hdl_t *, nvlist_t *, const char *); 2257c478bd9Sstevel@tonic-gate extern int fmd_nvl_fmri_expand(fmd_hdl_t *, nvlist_t *); 2267c478bd9Sstevel@tonic-gate extern int fmd_nvl_fmri_present(fmd_hdl_t *, nvlist_t *); 2277c478bd9Sstevel@tonic-gate extern int fmd_nvl_fmri_unusable(fmd_hdl_t *, nvlist_t *); 2287aec1d6eScindi extern int fmd_nvl_fmri_faulty(fmd_hdl_t *, nvlist_t *); 2297c478bd9Sstevel@tonic-gate extern int fmd_nvl_fmri_contains(fmd_hdl_t *, nvlist_t *, nvlist_t *); 230d9638e54Smws extern nvlist_t *fmd_nvl_fmri_translate(fmd_hdl_t *, nvlist_t *, nvlist_t *); 231d9638e54Smws 232d9638e54Smws extern int fmd_event_local(fmd_hdl_t *, fmd_event_t *); 233*24db4641Seschrock extern uint64_t fmd_event_ena_create(fmd_hdl_t *); 234*24db4641Seschrock 235d9638e54Smws 236d9638e54Smws #define FMD_XPRT_RDONLY 0x1 /* transport is read-only */ 237d9638e54Smws #define FMD_XPRT_RDWR 0x3 /* transport is read-write */ 238d9638e54Smws #define FMD_XPRT_ACCEPT 0x4 /* transport is accepting connection */ 239d9638e54Smws #define FMD_XPRT_SUSPENDED 0x8 /* transport starts suspended */ 240d9638e54Smws 241d9638e54Smws extern fmd_xprt_t *fmd_xprt_open(fmd_hdl_t *, uint_t, nvlist_t *, void *); 242d9638e54Smws extern void fmd_xprt_close(fmd_hdl_t *, fmd_xprt_t *); 243d9638e54Smws extern void fmd_xprt_post(fmd_hdl_t *, fmd_xprt_t *, nvlist_t *, hrtime_t); 244d9638e54Smws extern void fmd_xprt_suspend(fmd_hdl_t *, fmd_xprt_t *); 245d9638e54Smws extern void fmd_xprt_resume(fmd_hdl_t *, fmd_xprt_t *); 246d9638e54Smws extern int fmd_xprt_error(fmd_hdl_t *, fmd_xprt_t *); 247d9638e54Smws extern nvlist_t *fmd_xprt_translate(fmd_hdl_t *, fmd_xprt_t *, fmd_event_t *); 248d9638e54Smws extern void fmd_xprt_setspecific(fmd_hdl_t *, fmd_xprt_t *, void *); 249d9638e54Smws extern void *fmd_xprt_getspecific(fmd_hdl_t *, fmd_xprt_t *); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2527c478bd9Sstevel@tonic-gate } 2537c478bd9Sstevel@tonic-gate #endif 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate #endif /* _FMD_API_H */ 256