1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 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 #ifndef _FMD_XPRT_H 28 #define _FMD_XPRT_H 29 30 31 #include <pthread.h> 32 #include <libnvpair.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 #include <fmd_module.h> 39 #include <fmd_list.h> 40 41 struct fmd_eventq; /* see <fmd_eventq.h> */ 42 struct fmd_thread; /* see <fmd_thread.h> */ 43 struct fmd_idspace; /* see <fmd_idspace.h> */ 44 struct fmd_log; /* see <fmd_log.h> */ 45 46 struct fmd_xprt_impl; /* see below */ 47 48 typedef void fmd_xprt_rule_f(struct fmd_xprt_impl *, nvlist_t *); 49 50 extern fmd_xprt_rule_f fmd_xprt_event_syn; 51 extern fmd_xprt_rule_f fmd_xprt_event_ack; 52 extern fmd_xprt_rule_f fmd_xprt_event_run; 53 extern fmd_xprt_rule_f fmd_xprt_event_sub; 54 extern fmd_xprt_rule_f fmd_xprt_event_unsub; 55 extern fmd_xprt_rule_f fmd_xprt_event_unsuback; 56 extern fmd_xprt_rule_f fmd_xprt_event_uuclose; 57 extern fmd_xprt_rule_f fmd_xprt_event_error; 58 extern fmd_xprt_rule_f fmd_xprt_event_drop; 59 extern fmd_xprt_rule_f fmd_xprt_event_uuresolved; 60 extern fmd_xprt_rule_f fmd_xprt_event_updated; 61 62 typedef struct fmd_xprt_rule { 63 const char *xr_class; /* pattern to match */ 64 fmd_xprt_rule_f *xr_func; /* action to invoke */ 65 } fmd_xprt_rule_t; 66 67 extern const fmd_xprt_rule_t _fmd_xprt_state_syn[]; 68 extern const fmd_xprt_rule_t _fmd_xprt_state_ack[]; 69 extern const fmd_xprt_rule_t _fmd_xprt_state_err[]; 70 extern const fmd_xprt_rule_t _fmd_xprt_state_sub[]; 71 extern const fmd_xprt_rule_t _fmd_xprt_state_run[]; 72 73 typedef struct fmd_xprt_stat { 74 fmd_eventqstat_t xs_evqstat; /* statistics for xprt event queue */ 75 fmd_stat_t xs_module; /* module name associated with xprt */ 76 fmd_stat_t xs_authority; /* authority associated with xprt */ 77 fmd_stat_t xs_state; /* state name associated with xprt */ 78 fmd_stat_t xs_received; /* number of events received by xprt */ 79 fmd_stat_t xs_discarded; /* number of events discarded by xprt */ 80 fmd_stat_t xs_retried; /* number of events retried by xprt */ 81 fmd_stat_t xs_replayed; /* number of events replayed by xprt */ 82 fmd_stat_t xs_lost; /* number of events lost by xprt */ 83 fmd_stat_t xs_timeouts; /* number of events recv'd with ttl=0 */ 84 fmd_stat_t xs_subscriptions; /* number of active subscriptions */ 85 } fmd_xprt_stat_t; 86 87 typedef struct fmd_xprt_class { 88 char *xc_class; /* class string for subscription */ 89 uint_t xc_refs; /* reference count for subscription */ 90 struct fmd_xprt_class *xc_next; /* next class on xi_subhash chain */ 91 } fmd_xprt_class_t; 92 93 typedef struct fmd_xprt_class_hash { 94 fmd_eventq_t *xch_queue; /* associated event queue (or NULL) */ 95 fmd_xprt_class_t **xch_hash; /* subscription hash bucket array */ 96 uint_t xch_hashlen; /* size of xch_hash bucket array */ 97 } fmd_xprt_class_hash_t; 98 99 typedef struct fmd_xprt_impl { 100 fmd_list_t xi_list; /* linked list next/prev pointers */ 101 uint_t xi_version; /* transport protocol version */ 102 uint_t xi_id; /* transport identifier */ 103 struct fmd_eventq *xi_queue; /* event queue for outbound events */ 104 struct fmd_thread *xi_thread; /* thread associated with transport */ 105 const fmd_xprt_rule_t *xi_state; /* rules for the current state */ 106 nvlist_t *xi_auth; /* authority for peer endpoint */ 107 void *xi_data; /* data for xprt_get/setspecific */ 108 struct fmd_log *xi_log; /* log for received events (optional) */ 109 pthread_mutex_t xi_stats_lock; /* lock protecting xi_stats data */ 110 fmd_xprt_stat_t *xi_stats; /* built-in per-transport statistics */ 111 pthread_mutex_t xi_lock; /* lock for modifying members below */ 112 pthread_cond_t xi_cv; /* condition variable for xi_flags */ 113 uint_t xi_flags; /* flags (see below) */ 114 uint_t xi_busy; /* active threads in xprt_recv() */ 115 fmd_xprt_class_hash_t xi_lsub; /* subscriptions in local dispq */ 116 fmd_xprt_class_hash_t xi_rsub; /* subscriptions in remote peer */ 117 fmd_xprt_class_hash_t xi_usub; /* pending remote unsubscriptions */ 118 } fmd_xprt_impl_t; 119 120 /* 121 * Flags for fmd_xprt_create() and xi_flags. NOTE: Any public API flags must 122 * exactly match the corresponding definitions in <fmd_api.h>. 123 */ 124 #define FMD_XPRT_RDONLY 0x1 /* xprt is read-only */ 125 #define FMD_XPRT_RDWR 0x3 /* xprt is read-write */ 126 #define FMD_XPRT_ACCEPT 0x4 /* xprt is accepting connection */ 127 #define FMD_XPRT_SUSPENDED 0x8 /* xprt is suspended by user */ 128 #define FMD_XPRT_SUBSCRIBER 0x10 /* xprt is actively subscribing */ 129 #define FMD_XPRT_ISUSPENDED 0x20 /* xprt is waiting for _fmd_init */ 130 #define FMD_XPRT_DSUSPENDED 0x40 /* xprt is suspended by fmd mechanism */ 131 #define FMD_XPRT_EXTERNAL 0x80 /* xprt is external to a chassis */ 132 #define FMD_XPRT_NO_REMOTE_REPAIR 0x100 /* xprt allows remote repair */ 133 #define FMD_XPRT_CACHE_AS_LOCAL 0x200 /* xprt caches fault as if local */ 134 #define FMD_XPRT_HCONLY 0x400 /* xprt only proxies hc-scheme faults */ 135 #define FMD_XPRT_HC_PRESENT_ONLY 0x800 /* only locally present hc faults */ 136 137 #define FMD_XPRT_CMASK /* xprt create flag mask */ \ 138 (FMD_XPRT_RDWR | FMD_XPRT_ACCEPT | FMD_XPRT_SUSPENDED | \ 139 FMD_XPRT_EXTERNAL | FMD_XPRT_NO_REMOTE_REPAIR | \ 140 FMD_XPRT_CACHE_AS_LOCAL | FMD_XPRT_HCONLY | FMD_XPRT_HC_PRESENT_ONLY) 141 #define FMD_XPRT_SMASK \ 142 (FMD_XPRT_SUSPENDED | FMD_XPRT_ISUSPENDED | FMD_XPRT_DSUSPENDED) 143 144 extern fmd_xprt_t *fmd_xprt_create(fmd_module_t *, uint_t, nvlist_t *, void *); 145 extern void fmd_xprt_destroy(fmd_xprt_t *); 146 extern void fmd_xprt_xsuspend(fmd_xprt_t *, uint_t); 147 extern void fmd_xprt_xresume(fmd_xprt_t *, uint_t); 148 extern void fmd_xprt_send(fmd_xprt_t *); 149 extern void fmd_xprt_recv(fmd_xprt_t *, nvlist_t *, hrtime_t, boolean_t); 150 extern void fmd_xprt_uuclose(fmd_xprt_t *, const char *); 151 extern void fmd_xprt_uuresolved(fmd_xprt_t *, const char *); 152 extern void fmd_xprt_updated(fmd_xprt_t *, const char *, uint8_t *, uint8_t *, 153 uint_t); 154 155 extern void fmd_xprt_subscribe(fmd_xprt_t *, const char *); 156 extern void fmd_xprt_unsubscribe(fmd_xprt_t *, const char *); 157 extern void fmd_xprt_subscribe_all(const char *); 158 extern void fmd_xprt_unsubscribe_all(const char *); 159 extern void fmd_xprt_suspend_all(void); 160 extern void fmd_xprt_resume_all(void); 161 162 #ifdef __cplusplus 163 } 164 #endif 165 166 #endif /* _FMD_XPRT_H */ 167