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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 23 /* 24 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25 * Use is subject to license terms. 26 */ 27 28 #ifndef _FMD_XPRT_H 29 #define _FMD_XPRT_H 30 31 #pragma ident "%Z%%M% %I% %E% SMI" 32 33 #include <pthread.h> 34 #include <libnvpair.h> 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #include <fmd_module.h> 41 #include <fmd_list.h> 42 43 struct fmd_eventq; /* see <fmd_eventq.h> */ 44 struct fmd_thread; /* see <fmd_thread.h> */ 45 struct fmd_idspace; /* see <fmd_idspace.h> */ 46 struct fmd_log; /* see <fmd_log.h> */ 47 48 struct fmd_xprt_impl; /* see below */ 49 50 typedef void fmd_xprt_rule_f(struct fmd_xprt_impl *, nvlist_t *); 51 52 extern fmd_xprt_rule_f fmd_xprt_event_syn; 53 extern fmd_xprt_rule_f fmd_xprt_event_ack; 54 extern fmd_xprt_rule_f fmd_xprt_event_run; 55 extern fmd_xprt_rule_f fmd_xprt_event_sub; 56 extern fmd_xprt_rule_f fmd_xprt_event_unsub; 57 extern fmd_xprt_rule_f fmd_xprt_event_unsuback; 58 extern fmd_xprt_rule_f fmd_xprt_event_uuclose; 59 extern fmd_xprt_rule_f fmd_xprt_event_error; 60 extern fmd_xprt_rule_f fmd_xprt_event_drop; 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_CMASK 0xF /* xprt create flag mask */ 129 #define FMD_XPRT_SUBSCRIBER 0x10 /* xprt is actively subscribing */ 130 #define FMD_XPRT_ISUSPENDED 0x20 /* xprt is waiting for _fmd_init */ 131 #define FMD_XPRT_DSUSPENDED 0x40 /* xprt is suspended by fmd mechanism */ 132 133 #define FMD_XPRT_SMASK \ 134 (FMD_XPRT_SUSPENDED | FMD_XPRT_ISUSPENDED | FMD_XPRT_DSUSPENDED) 135 136 extern fmd_xprt_t *fmd_xprt_create(fmd_module_t *, uint_t, nvlist_t *, void *); 137 extern void fmd_xprt_destroy(fmd_xprt_t *); 138 extern void fmd_xprt_xsuspend(fmd_xprt_t *, uint_t); 139 extern void fmd_xprt_xresume(fmd_xprt_t *, uint_t); 140 extern void fmd_xprt_send(fmd_xprt_t *); 141 extern void fmd_xprt_recv(fmd_xprt_t *, nvlist_t *, hrtime_t); 142 extern void fmd_xprt_uuclose(fmd_xprt_t *, const char *); 143 144 extern void fmd_xprt_subscribe(fmd_xprt_t *, const char *); 145 extern void fmd_xprt_unsubscribe(fmd_xprt_t *, const char *); 146 extern void fmd_xprt_subscribe_all(const char *); 147 extern void fmd_xprt_unsubscribe_all(const char *); 148 extern void fmd_xprt_suspend_all(void); 149 extern void fmd_xprt_resume_all(void); 150 151 #ifdef __cplusplus 152 } 153 #endif 154 155 #endif /* _FMD_XPRT_H */ 156