d9638e547d8811f2c689977f8dd2a353938b61fdmws/*
d9638e547d8811f2c689977f8dd2a353938b61fdmws * CDDL HEADER START
d9638e547d8811f2c689977f8dd2a353938b61fdmws *
d9638e547d8811f2c689977f8dd2a353938b61fdmws * The contents of this file are subject to the terms of the
25351652d920ae27c5a56c199da581033ce763f6Vuong Nguyen * Common Development and Distribution License (the "License").
25351652d920ae27c5a56c199da581033ce763f6Vuong Nguyen * You may not use this file except in compliance with the License.
d9638e547d8811f2c689977f8dd2a353938b61fdmws *
d9638e547d8811f2c689977f8dd2a353938b61fdmws * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d9638e547d8811f2c689977f8dd2a353938b61fdmws * or http://www.opensolaris.org/os/licensing.
d9638e547d8811f2c689977f8dd2a353938b61fdmws * See the License for the specific language governing permissions
d9638e547d8811f2c689977f8dd2a353938b61fdmws * and limitations under the License.
d9638e547d8811f2c689977f8dd2a353938b61fdmws *
d9638e547d8811f2c689977f8dd2a353938b61fdmws * When distributing Covered Code, include this CDDL HEADER in each
d9638e547d8811f2c689977f8dd2a353938b61fdmws * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d9638e547d8811f2c689977f8dd2a353938b61fdmws * If applicable, add the following below this CDDL HEADER, with the
d9638e547d8811f2c689977f8dd2a353938b61fdmws * fields enclosed by brackets "[]" replaced with your own identifying
d9638e547d8811f2c689977f8dd2a353938b61fdmws * information: Portions Copyright [yyyy] [name of copyright owner]
d9638e547d8811f2c689977f8dd2a353938b61fdmws *
d9638e547d8811f2c689977f8dd2a353938b61fdmws * CDDL HEADER END
d9638e547d8811f2c689977f8dd2a353938b61fdmws */
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws/*
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
d9638e547d8811f2c689977f8dd2a353938b61fdmws * Use is subject to license terms.
d9638e547d8811f2c689977f8dd2a353938b61fdmws */
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#ifndef _FMD_XPRT_H
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define _FMD_XPRT_H
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#include <pthread.h>
d9638e547d8811f2c689977f8dd2a353938b61fdmws#include <libnvpair.h>
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#ifdef __cplusplus
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern "C" {
d9638e547d8811f2c689977f8dd2a353938b61fdmws#endif
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#include <fmd_module.h>
d9638e547d8811f2c689977f8dd2a353938b61fdmws#include <fmd_list.h>
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsstruct fmd_eventq; /* see <fmd_eventq.h> */
d9638e547d8811f2c689977f8dd2a353938b61fdmwsstruct fmd_thread; /* see <fmd_thread.h> */
d9638e547d8811f2c689977f8dd2a353938b61fdmwsstruct fmd_idspace; /* see <fmd_idspace.h> */
d9638e547d8811f2c689977f8dd2a353938b61fdmwsstruct fmd_log; /* see <fmd_log.h> */
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsstruct fmd_xprt_impl; /* see below */
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef void fmd_xprt_rule_f(struct fmd_xprt_impl *, nvlist_t *);
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_syn;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_ack;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_run;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_sub;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_unsub;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_unsuback;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_uuclose;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_error;
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_rule_f fmd_xprt_event_drop;
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hansonextern fmd_xprt_rule_f fmd_xprt_event_uuresolved;
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hansonextern fmd_xprt_rule_f fmd_xprt_event_updated;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef struct fmd_xprt_rule {
d9638e547d8811f2c689977f8dd2a353938b61fdmws const char *xr_class; /* pattern to match */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_rule_f *xr_func; /* action to invoke */
d9638e547d8811f2c689977f8dd2a353938b61fdmws} fmd_xprt_rule_t;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern const fmd_xprt_rule_t _fmd_xprt_state_syn[];
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern const fmd_xprt_rule_t _fmd_xprt_state_ack[];
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern const fmd_xprt_rule_t _fmd_xprt_state_err[];
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern const fmd_xprt_rule_t _fmd_xprt_state_sub[];
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern const fmd_xprt_rule_t _fmd_xprt_state_run[];
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef struct fmd_xprt_stat {
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_eventqstat_t xs_evqstat; /* statistics for xprt event queue */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_module; /* module name associated with xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_authority; /* authority associated with xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_state; /* state name associated with xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_received; /* number of events received by xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_discarded; /* number of events discarded by xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_retried; /* number of events retried by xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_replayed; /* number of events replayed by xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_lost; /* number of events lost by xprt */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_timeouts; /* number of events recv'd with ttl=0 */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_stat_t xs_subscriptions; /* number of active subscriptions */
d9638e547d8811f2c689977f8dd2a353938b61fdmws} fmd_xprt_stat_t;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef struct fmd_xprt_class {
d9638e547d8811f2c689977f8dd2a353938b61fdmws char *xc_class; /* class string for subscription */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xc_refs; /* reference count for subscription */
d9638e547d8811f2c689977f8dd2a353938b61fdmws struct fmd_xprt_class *xc_next; /* next class on xi_subhash chain */
d9638e547d8811f2c689977f8dd2a353938b61fdmws} fmd_xprt_class_t;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef struct fmd_xprt_class_hash {
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_eventq_t *xch_queue; /* associated event queue (or NULL) */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_class_t **xch_hash; /* subscription hash bucket array */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xch_hashlen; /* size of xch_hash bucket array */
d9638e547d8811f2c689977f8dd2a353938b61fdmws} fmd_xprt_class_hash_t;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwstypedef struct fmd_xprt_impl {
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_list_t xi_list; /* linked list next/prev pointers */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xi_version; /* transport protocol version */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xi_id; /* transport identifier */
d9638e547d8811f2c689977f8dd2a353938b61fdmws struct fmd_eventq *xi_queue; /* event queue for outbound events */
d9638e547d8811f2c689977f8dd2a353938b61fdmws struct fmd_thread *xi_thread; /* thread associated with transport */
d9638e547d8811f2c689977f8dd2a353938b61fdmws const fmd_xprt_rule_t *xi_state; /* rules for the current state */
d9638e547d8811f2c689977f8dd2a353938b61fdmws nvlist_t *xi_auth; /* authority for peer endpoint */
d9638e547d8811f2c689977f8dd2a353938b61fdmws void *xi_data; /* data for xprt_get/setspecific */
d9638e547d8811f2c689977f8dd2a353938b61fdmws struct fmd_log *xi_log; /* log for received events (optional) */
d9638e547d8811f2c689977f8dd2a353938b61fdmws pthread_mutex_t xi_stats_lock; /* lock protecting xi_stats data */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_stat_t *xi_stats; /* built-in per-transport statistics */
d9638e547d8811f2c689977f8dd2a353938b61fdmws pthread_mutex_t xi_lock; /* lock for modifying members below */
d9638e547d8811f2c689977f8dd2a353938b61fdmws pthread_cond_t xi_cv; /* condition variable for xi_flags */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xi_flags; /* flags (see below) */
d9638e547d8811f2c689977f8dd2a353938b61fdmws uint_t xi_busy; /* active threads in xprt_recv() */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_class_hash_t xi_lsub; /* subscriptions in local dispq */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_class_hash_t xi_rsub; /* subscriptions in remote peer */
d9638e547d8811f2c689977f8dd2a353938b61fdmws fmd_xprt_class_hash_t xi_usub; /* pending remote unsubscriptions */
d9638e547d8811f2c689977f8dd2a353938b61fdmws} fmd_xprt_impl_t;
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws/*
d9638e547d8811f2c689977f8dd2a353938b61fdmws * Flags for fmd_xprt_create() and xi_flags. NOTE: Any public API flags must
d9638e547d8811f2c689977f8dd2a353938b61fdmws * exactly match the corresponding definitions in <fmd_api.h>.
d9638e547d8811f2c689977f8dd2a353938b61fdmws */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_RDONLY 0x1 /* xprt is read-only */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_RDWR 0x3 /* xprt is read-write */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_ACCEPT 0x4 /* xprt is accepting connection */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_SUSPENDED 0x8 /* xprt is suspended by user */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_SUBSCRIBER 0x10 /* xprt is actively subscribing */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_ISUSPENDED 0x20 /* xprt is waiting for _fmd_init */
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_DSUSPENDED 0x40 /* xprt is suspended by fmd mechanism */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_EXTERNAL 0x80 /* xprt is external to a chassis */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_NO_REMOTE_REPAIR 0x100 /* xprt allows remote repair */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_CACHE_AS_LOCAL 0x200 /* xprt caches fault as if local */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_HCONLY 0x400 /* xprt only proxies hc-scheme faults */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_HC_PRESENT_ONLY 0x800 /* only locally present hc faults */
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson#define FMD_XPRT_CMASK /* xprt create flag mask */ \
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson (FMD_XPRT_RDWR | FMD_XPRT_ACCEPT | FMD_XPRT_SUSPENDED | \
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson FMD_XPRT_EXTERNAL | FMD_XPRT_NO_REMOTE_REPAIR | \
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson FMD_XPRT_CACHE_AS_LOCAL | FMD_XPRT_HCONLY | FMD_XPRT_HC_PRESENT_ONLY)
d9638e547d8811f2c689977f8dd2a353938b61fdmws#define FMD_XPRT_SMASK \
d9638e547d8811f2c689977f8dd2a353938b61fdmws (FMD_XPRT_SUSPENDED | FMD_XPRT_ISUSPENDED | FMD_XPRT_DSUSPENDED)
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern fmd_xprt_t *fmd_xprt_create(fmd_module_t *, uint_t, nvlist_t *, void *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_destroy(fmd_xprt_t *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_xsuspend(fmd_xprt_t *, uint_t);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_xresume(fmd_xprt_t *, uint_t);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_send(fmd_xprt_t *);
25351652d920ae27c5a56c199da581033ce763f6Vuong Nguyenextern void fmd_xprt_recv(fmd_xprt_t *, nvlist_t *, hrtime_t, boolean_t);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_uuclose(fmd_xprt_t *, const char *);
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hansonextern void fmd_xprt_uuresolved(fmd_xprt_t *, const char *);
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hansonextern void fmd_xprt_updated(fmd_xprt_t *, const char *, uint8_t *, uint8_t *,
cbf75e67acb6c32a2f4884f28a839d59f7988d37Stephen Hanson uint_t);
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_subscribe(fmd_xprt_t *, const char *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_unsubscribe(fmd_xprt_t *, const char *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_subscribe_all(const char *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_unsubscribe_all(const char *);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_suspend_all(void);
d9638e547d8811f2c689977f8dd2a353938b61fdmwsextern void fmd_xprt_resume_all(void);
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#ifdef __cplusplus
d9638e547d8811f2c689977f8dd2a353938b61fdmws}
d9638e547d8811f2c689977f8dd2a353938b61fdmws#endif
d9638e547d8811f2c689977f8dd2a353938b61fdmws
d9638e547d8811f2c689977f8dd2a353938b61fdmws#endif /* _FMD_XPRT_H */