xref: /illumos-gate/usr/src/cmd/fm/fmd/common/fmd_xprt.h (revision 10702807a53210bf9bd5290bc7b46516744be71a)
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 2008 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 
60 typedef struct fmd_xprt_rule {
61 	const char *xr_class;		/* pattern to match */
62 	fmd_xprt_rule_f *xr_func;	/* action to invoke */
63 } fmd_xprt_rule_t;
64 
65 extern const fmd_xprt_rule_t _fmd_xprt_state_syn[];
66 extern const fmd_xprt_rule_t _fmd_xprt_state_ack[];
67 extern const fmd_xprt_rule_t _fmd_xprt_state_err[];
68 extern const fmd_xprt_rule_t _fmd_xprt_state_sub[];
69 extern const fmd_xprt_rule_t _fmd_xprt_state_run[];
70 
71 typedef struct fmd_xprt_stat {
72 	fmd_eventqstat_t xs_evqstat;	/* statistics for xprt event queue */
73 	fmd_stat_t xs_module;		/* module name associated with xprt */
74 	fmd_stat_t xs_authority;	/* authority associated with xprt */
75 	fmd_stat_t xs_state;		/* state name associated with xprt */
76 	fmd_stat_t xs_received;		/* number of events received by xprt */
77 	fmd_stat_t xs_discarded;	/* number of events discarded by xprt */
78 	fmd_stat_t xs_retried;		/* number of events retried by xprt */
79 	fmd_stat_t xs_replayed;		/* number of events replayed by xprt */
80 	fmd_stat_t xs_lost;		/* number of events lost by xprt */
81 	fmd_stat_t xs_timeouts;		/* number of events recv'd with ttl=0 */
82 	fmd_stat_t xs_subscriptions;	/* number of active subscriptions */
83 } fmd_xprt_stat_t;
84 
85 typedef struct fmd_xprt_class {
86 	char *xc_class;			/* class string for subscription */
87 	uint_t xc_refs;			/* reference count for subscription */
88 	struct fmd_xprt_class *xc_next;	/* next class on xi_subhash chain */
89 } fmd_xprt_class_t;
90 
91 typedef struct fmd_xprt_class_hash {
92 	fmd_eventq_t *xch_queue;	/* associated event queue (or NULL) */
93 	fmd_xprt_class_t **xch_hash;	/* subscription hash bucket array */
94 	uint_t xch_hashlen;		/* size of xch_hash bucket array */
95 } fmd_xprt_class_hash_t;
96 
97 typedef struct fmd_xprt_impl {
98 	fmd_list_t xi_list;		/* linked list next/prev pointers */
99 	uint_t xi_version;		/* transport protocol version */
100 	uint_t xi_id;			/* transport identifier */
101 	struct fmd_eventq *xi_queue;	/* event queue for outbound events */
102 	struct fmd_thread *xi_thread;	/* thread associated with transport */
103 	const fmd_xprt_rule_t *xi_state; /* rules for the current state */
104 	nvlist_t *xi_auth;		/* authority for peer endpoint */
105 	void *xi_data;			/* data for xprt_get/setspecific */
106 	struct fmd_log *xi_log;		/* log for received events (optional) */
107 	pthread_mutex_t xi_stats_lock;	/* lock protecting xi_stats data */
108 	fmd_xprt_stat_t *xi_stats;	/* built-in per-transport statistics */
109 	pthread_mutex_t xi_lock;	/* lock for modifying members below */
110 	pthread_cond_t xi_cv;		/* condition variable for xi_flags */
111 	uint_t xi_flags;		/* flags (see below) */
112 	uint_t xi_busy;			/* active threads in xprt_recv() */
113 	fmd_xprt_class_hash_t xi_lsub;	/* subscriptions in local dispq */
114 	fmd_xprt_class_hash_t xi_rsub;	/* subscriptions in remote peer */
115 	fmd_xprt_class_hash_t xi_usub;	/* pending remote unsubscriptions */
116 } fmd_xprt_impl_t;
117 
118 /*
119  * Flags for fmd_xprt_create() and xi_flags.  NOTE: Any public API flags must
120  * exactly match the corresponding definitions in <fmd_api.h>.
121  */
122 #define	FMD_XPRT_RDONLY		0x1	/* xprt is read-only */
123 #define	FMD_XPRT_RDWR		0x3	/* xprt is read-write */
124 #define	FMD_XPRT_ACCEPT		0x4	/* xprt is accepting connection */
125 #define	FMD_XPRT_SUSPENDED	0x8	/* xprt is suspended by user */
126 #define	FMD_XPRT_CMASK		0xF	/* xprt create flag mask */
127 #define	FMD_XPRT_SUBSCRIBER	0x10	/* xprt is actively subscribing */
128 #define	FMD_XPRT_ISUSPENDED	0x20	/* xprt is waiting for _fmd_init */
129 #define	FMD_XPRT_DSUSPENDED	0x40	/* xprt is suspended by fmd mechanism */
130 
131 #define	FMD_XPRT_SMASK	\
132 	(FMD_XPRT_SUSPENDED | FMD_XPRT_ISUSPENDED | FMD_XPRT_DSUSPENDED)
133 
134 extern fmd_xprt_t *fmd_xprt_create(fmd_module_t *, uint_t, nvlist_t *, void *);
135 extern void fmd_xprt_destroy(fmd_xprt_t *);
136 extern void fmd_xprt_xsuspend(fmd_xprt_t *, uint_t);
137 extern void fmd_xprt_xresume(fmd_xprt_t *, uint_t);
138 extern void fmd_xprt_send(fmd_xprt_t *);
139 extern void fmd_xprt_recv(fmd_xprt_t *, nvlist_t *, hrtime_t, boolean_t);
140 extern void fmd_xprt_uuclose(fmd_xprt_t *, const char *);
141 
142 extern void fmd_xprt_subscribe(fmd_xprt_t *, const char *);
143 extern void fmd_xprt_unsubscribe(fmd_xprt_t *, const char *);
144 extern void fmd_xprt_subscribe_all(const char *);
145 extern void fmd_xprt_unsubscribe_all(const char *);
146 extern void fmd_xprt_suspend_all(void);
147 extern void fmd_xprt_resume_all(void);
148 
149 #ifdef	__cplusplus
150 }
151 #endif
152 
153 #endif	/* _FMD_XPRT_H */
154