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