25cf1a301a396c38e8adf52c15f537b80d2483f7jl * CDDL HEADER START
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The contents of this file are subject to the terms of the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Common Development and Distribution License (the "License").
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * You may not use this file except in compliance with the License.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * See the License for the specific language governing permissions
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * and limitations under the License.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * When distributing Covered Code, include this CDDL HEADER in each
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * If applicable, add the following below this CDDL HEADER, with the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * fields enclosed by brackets "[]" replaced with your own identifying
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * information: Portions Copyright [yyyy] [name of copyright owner]
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * CDDL HEADER END
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Use is subject to license terms.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#pragma ident "%Z%%M% %I% %E% SMI"
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMA Event Transport Module
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Plugin for sending/receiving FMA events to/from a remote endoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETM declarations
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/* Per endpoint data */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl etm_xport_hdl_t epm_tlhdl; /* Transport Layer instance handle */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl pthread_mutex_t epm_lock; /* Protects remainder of struct */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl pthread_cond_t epm_tx_cv; /* Cond var for send/transmit */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl etm_xport_conn_t epm_oconn; /* Connection for outgoing events */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define ETM_EP_INST_MAX 4 /* Max chars in endpt instance */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define ETM_SERVER_XPRT_FLAGS (FMD_XPRT_RDWR | FMD_XPRT_ACCEPT)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define FREE_BUF(hdl, buf, size) fmd_hdl_free((hdl), (buf), (size));
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define IS_CLIENT(mp) (((mp)->epm_xprtflags & FMD_XPRT_ACCEPT) ? 0 : 1)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define INCRSTAT(x) { (void) pthread_mutex_lock(&Etm_mod_lock); \
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define DECRSTAT(x) { (void) pthread_mutex_lock(&Etm_mod_lock); \
25cf1a301a396c38e8adf52c15f537b80d2483f7jl#define ADDSTAT(x, y) { (void) pthread_mutex_lock(&Etm_mod_lock); \
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (x) += (y); \
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Global variables
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic pthread_mutex_t Etm_mod_lock = PTHREAD_MUTEX_INITIALIZER;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Protects globals */
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic hrtime_t Reconn_interval; /* Time between reconnection attempts */
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic hrtime_t Reconn_timeout; /* Time allowed for reconnection */
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic hrtime_t Rw_timeout; /* Time allowed for I/O operation */
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic etm_epmap_t *Epmap_head = NULL; /* Head of list of epmap structs */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/* Module statistics */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* read counters */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* write counters */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* error counters */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* misc */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* read counters */
77a7fd96f77f04bbd7634db14755686062589ecajrutt { "post_filter", FMD_TYPE_UINT64, "Drops by post_filter" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* write counters */
77a7fd96f77f04bbd7634db14755686062589ecajrutt { "send_filter", FMD_TYPE_UINT64, "Drops by send_filter" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* ETM error counters */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl { "error_protocol", FMD_TYPE_UINT64, "ETM protocol errors" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl { "error_drop_read", FMD_TYPE_UINT64, "Dropped read messages" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl { "error_read_badhdr", FMD_TYPE_UINT64, "Bad headers read" },
77a7fd96f77f04bbd7634db14755686062589ecajrutt { "error_send_filter", FMD_TYPE_UINT64, "Send filter errors" },
77a7fd96f77f04bbd7634db14755686062589ecajrutt { "error_post_filter", FMD_TYPE_UINT64, "Post filter errors" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* ETM Misc */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl { "peer_count", FMD_TYPE_UINT64, "Number of peers initialized" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETM Private functions
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Hex dump for debug.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_hex_dump(fmd_hdl_t *hdl, void *buf, size_t buflen, int direction)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl int i, j, k;
25cf1a301a396c38e8adf52c15f537b80d2483f7jl k = buflen % 16; /* Is there a last (non-8-column) row? */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Dump the complete 8-column rows */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl for (i = 0; i < j; i++) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "%3d: %4x %4x %4x %4x %4x %4x %4x %4x", i,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Dump the last (incomplete) row */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl switch (k) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "%3d: %4x %4x %4x %4x", i, *(c+0), *(c+1),
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "%3d: %4x %4x %4x %4x %4x %4x", i, *(c+0),
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Provide the length of a message based on the data in the given ETM header.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Check the contents of the ETM header for errors.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return the header type (hdr_type).
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt fmd_hdl_debug(hdl, "Bad delimiter in ETM header from %s "
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Until version is negotiated, other fields may be wrong */
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt fmd_hdl_debug(hdl, "Bad version in ETM header from %s : 0x%x\n",
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt fmd_hdl_debug(hdl, "Bad type in ETM header from %s : 0x%x\n",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Create an ETM header of a given type in the given buffer.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return length of header.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_create_hdr(void *buf, uint8_t ver, uint8_t type, uint32_t msglen)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Convert message bytes to nvlist and post to fmd.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return zero for success, non-zero for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Note : nvl is free'd by fmd.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_post_msg(fmd_hdl_t *hdl, etm_epmap_t *mp, void *buf, size_t buflen)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (1);
77a7fd96f77f04bbd7634db14755686062589ecajrutt return (0);
77a7fd96f77f04bbd7634db14755686062589ecajrutt fmd_hdl_debug(hdl, "post_filter error : %s", strerror(errno));
77a7fd96f77f04bbd7634db14755686062589ecajrutt INCRSTAT(Etm_stats.error_post_filter.fmds_value.ui64);
77a7fd96f77f04bbd7634db14755686062589ecajrutt /* Still post event */
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt /* Remote peer will attempt to resend event */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "unable to post message, module exiting");
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt /* Remote peer will attempt to resend event */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (rv);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Handle the startup handshake to the server. The client always initiates
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * the startup handshake. In the following sequence, we are the client and
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * the remote endpoint is the server.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Client sends C_HELLO and transitions to Q_INIT_PENDING state.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Server sends S_HELLO and transitions to Q_INIT_PENDING state.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Client sends ACK and transitions to Q_OPEN state.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Server receives ACK and transitions to Q_OPEN state.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return 0 for success, nonzero for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((mp->epm_oconn = etm_xport_open(hdl, mp->epm_tlhdl)) == NULL)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_C_HELLO, 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (2);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((etm_xport_read(hdl, mp->epm_oconn, Rw_timeout, hbuf,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (3);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_error(hdl, "Protocol error, did not receive S_HELLO "
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (4);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Get version from the server.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Currently, only one version is supported.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_error(hdl, "Unable to use same version as %s : %d",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (5);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_ACK, 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_error(hdl, "Failed to write ACK for S_HELLO to %s",
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (6);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Call fmd_xprt_open and fmd_xprt_setspecific with
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Etm_mod_lock held to avoid race with etm_send thread.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((mp->epm_xprthdl = fmd_xprt_open(hdl, mp->epm_xprtflags,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * Open a connection to the peer, send a SHUTDOWN message,
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * and close the connection.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt if ((mp->epm_oconn = etm_xport_open(hdl, mp->epm_tlhdl)) == NULL)
ac92251dc182f030faf6a5f76981d551b0b16072jrutt hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_SHUTDOWN, 0);
ac92251dc182f030faf6a5f76981d551b0b16072jrutt (void) etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf, hdrlen);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Alloc a nvlist and add a string for the endpoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return zero for success, non-zero for failure.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Cannot use nvlist_xalloc(3NVPAIR) due to a recursive mutex situation
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * in fmd when this nvlist_t is free'd.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (nvlist_add_string(mp->epm_ep_nvl, "domain-id", mp->epm_ep_str)) {
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt fmd_hdl_error(hdl, "failed to add domain-id string to nvlist "
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Free the nvlist for the endpoint_id string.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*ARGSUSED*/
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Check for a duplicate endpoint/peer string.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*ARGSUSED*/
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (1);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Attempt to re-open a connection with the remote endpoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((mp->epm_reconn_end > 0) && (mp->epm_cstat == C_UNINITIALIZED)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "queue resumed for %s", mp->epm_ep_str);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Suspend a given connection and setup for reconnection retries.
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * Assume caller holds lock on epm_lock.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "queue suspended for %s", mp->epm_ep_str);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Reinitialize the connection. The old fmd_xprt_t handle must be
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Assume caller holds lock on epm_lock.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * To avoid a deadlock, wait for etm_send to finish before
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * calling fmd_xprt_close()
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt fmd_hdl_debug(hdl, "queue closed for %s", mp->epm_ep_str);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Receive data from ETM transport layer.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Note : This is not the fmdo_recv entry point.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_recv(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_epmap_t *mp)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((etm_xport_read(hdl, conn, Rw_timeout, hbuf, hdrlen)) != hdrlen) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_NAK, 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Client is initiating a startup handshake */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_S_HELLO, 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* This is client's ACK from startup handshake */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Call fmd_xprt_open and fmd_xprt_setspecific with
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Etm_mod_lock held to avoid race with etm_send thread.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * A server shutdown is considered to be temporary.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Prepare for reconnection.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Peer (client) is unaware that we've restarted */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl hdrlen = etm_create_hdr(hbuf, mp->epm_ver, ETM_HDR_ACK, 0);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * If we got this far and the current state of the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * outbound/sending connection is TIMED_OUT or
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * LIMBO, then we should reinitialize it.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (rv);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * ETM transport layer callback function.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The transport layer calls this function to :
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * (a) pass an incoming message (flag == ETM_CBFLAG_RECV)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * (b) tell us to reinitialize the connection (flag == ETM_CBFLAG_REINIT)
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_cb_func(fmd_hdl_t *hdl, etm_xport_conn_t conn, etm_cb_flag_t flag,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl switch (flag) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Return ECANCELED so the transport layer will close the
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * server connection. The transport layer is responsible for
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * reestablishing this connection (should a connection request
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * arrive from the peer).
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "Unknown callback flag : 0x%x", flag);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (rv);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Allocate and initialize an etm_epmap_t struct for the given endpoint
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * name string.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "skipping duplicate peer : %s", epname);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl newmap = fmd_hdl_zalloc(hdl, sizeof (etm_epmap_t), FMD_SLEEP);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl newmap->epm_ep_str = fmd_hdl_strdup(hdl, epname, FMD_SLEEP);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl newmap->epm_ver = ETM_PROTO_V1; /* Currently support one proto ver */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if ((newmap->epm_tlhdl = etm_xport_init(hdl, newmap->epm_ep_str,
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * For whatever reason, we could not complete the
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * startup handshake with the server. Set the timer
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * and try again.
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * We may be restarting after a crash. If so, the client
ac92251dc182f030faf6a5f76981d551b0b16072jrutt * may be unaware of this.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Add this transport instance handle to the list */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Parse the given property list string and call etm_init_epmap
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * for each endpoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_create_epmaps(fmd_hdl_t *hdl, char *eplist, int flags)
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Create a copy of eplist for parsing.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * strtok/strtok_r(3C) will insert null chars to the string.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Therefore, fmd_hdl_strdup/fmd_hdl_strfree cannot be used.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The following are supported for the "client_list" and
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * "server_list" properties :
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * A space-separated list of endpoints.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * "dev:///dom0 dev:///dom1 dev:///dom2"
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * An array syntax for a range of instances.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * "dev:///dom[0:2]"
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * A combination of both.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * "dev:///dom0 dev:///dom[1:2]"
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * This string is using array syntax.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Check the string for correct syntax.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* expand the array syntax */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl "exceeds MAXPATHLEN\n");
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Free the transport infrastructure for an endpoint.
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * If an etm_send thread is in progress, wait for it to finish.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * The etm_recv thread is managed by the transport layer and will
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * be destroyed with etm_xport_fini().
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (void) etm_xport_write(hdl, mp->epm_oconn, Rw_timeout, hbuf,
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMD entry points
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMD fmdo_send entry point.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Send an event to the remote endpoint and receive an ACK.
25cf1a301a396c38e8adf52c15f537b80d2483f7jletm_send(fmd_hdl_t *hdl, fmd_xprt_t *xprthdl, fmd_event_t *ep, nvlist_t *nvl)
77a7fd96f77f04bbd7634db14755686062589ecajrutt * Another thread may be (1) trying to close this
77a7fd96f77f04bbd7634db14755686062589ecajrutt * fmd_xprt_t, or (2) posting an event to it.
77a7fd96f77f04bbd7634db14755686062589ecajrutt * If (1), don't want to spend too much time here.
77a7fd96f77f04bbd7634db14755686062589ecajrutt * If (2), allow it to finish and release epm_lock.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_debug(hdl, "queue suspended for %s", mp->epm_ep_str);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (void *) ep);
77a7fd96f77f04bbd7634db14755686062589ecajrutt rv = etm_xport_send_filter(hdl, msgnvl, mp->epm_ep_str);
77a7fd96f77f04bbd7634db14755686062589ecajrutt fmd_hdl_debug(hdl, "send_filter error : %s", strerror(errno));
77a7fd96f77f04bbd7634db14755686062589ecajrutt INCRSTAT(Etm_stats.error_send_filter.fmds_value.ui64);
77a7fd96f77f04bbd7634db14755686062589ecajrutt /* Still send event */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl (void) etm_create_hdr(buf, mp->epm_ver, ETM_HDR_MSG, nvsize);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (rv = nvlist_pack(msgnvl, &nvbuf, &nvsize, NV_ENCODE_XDR, 0)) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl fmd_hdl_error(hdl, "Failed to pack event : %s\n", strerror(rv));
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Peer received a bad value in the header */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Server has restarted */
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * Cannot call fmd_xprt_close here, so we'll do it
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt * on the timeout thread.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * fault.* or list.* events will be replayed if a
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * transport is opened with the same auth.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Other events will be discarded.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return (rv);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMD fmdo_timeout entry point..
25cf1a301a396c38e8adf52c15f537b80d2483f7jl/*ARGSUSED*/
25cf1a301a396c38e8adf52c15f537b80d2483f7jlstatic void
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Server has shutdown and we (client) need to reconnect */
154b1f02449b21af9273efd1a7776a3fe65a0744jrutt /* mp->epm_ep_nvl is free'd in fmd_xprt_close */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * FMD Module declarations
25cf1a301a396c38e8adf52c15f537b80d2483f7jl { "reconnect_interval", FMD_TYPE_UINT64, "10000000000" },
77a7fd96f77f04bbd7634db14755686062589ecajrutt { "reconnect_timeout", FMD_TYPE_UINT64, "300000000000" },
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Initialize the transport for use by ETM.
25cf1a301a396c38e8adf52c15f537b80d2483f7jl if (fmd_hdl_register(hdl, FMD_API_VERSION, &etm_info) != 0) {
25cf1a301a396c38e8adf52c15f537b80d2483f7jl return; /* invalid data in configuration file */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Create global stats */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl sizeof (Etm_stats) / sizeof (fmd_stat_t), (fmd_stat_t *)&Etm_stats);
25cf1a301a396c38e8adf52c15f537b80d2483f7jl /* Get module properties */
25cf1a301a396c38e8adf52c15f537b80d2483f7jl Reconn_timeout = fmd_prop_get_int64(hdl, "reconnect_timeout");
25cf1a301a396c38e8adf52c15f537b80d2483f7jl Reconn_interval = fmd_prop_get_int64(hdl, "reconnect_interval");
25cf1a301a396c38e8adf52c15f537b80d2483f7jl * Teardown the transport
25cf1a301a396c38e8adf52c15f537b80d2483f7jl while (mp) {