450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER START
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * The contents of this file are subject to the terms of the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Common Development and Distribution License (the "License").
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You may not use this file except in compliance with the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * or http://www.opensolaris.org/os/licensing.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * See the License for the specific language governing permissions
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * and limitations under the License.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * If applicable, add the following below this CDDL HEADER, with the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * CDDL HEADER END
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <stdio.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <stdlib.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <string.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <strings.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/types.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <errno.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <syslog.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <unistd.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/types.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/socket.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/time.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <netinet/in.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <arpa/inet.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <netdb.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/stat.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/sdt.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <signal.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <fcntl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libnvpair.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libstmf.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <door.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <pthread.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libscf.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <locale.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/stmf_ioctl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <sys/pppt_ioctl.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#include <libstmfproxy.h>
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define PPPT_NODE "/devices/pseudo/pppt@0:pppt"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte#define USAGE "Usage: %s [-d][-f][-n nodeid] nodename\n" \
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Note: nodename must be the same on both nodes\n"
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * static functions
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void daemonInit(void);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void killHandler();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int postMsg(uint_t nelem, uchar_t *aluaMsg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * globals
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid *t_handle; /* transport handle */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortechar aluaNode[256]; /* one of the two alua peers */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortechar myNode[256]; /* this hostname */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint log_debug = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint fore_ground = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint proxy_hdl;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortept_ops_t *pt_ops;
91159e90831fc9243576f2ec1a483b3bb462bcf4John Fortepthread_mutex_t send_mutex = PTHREAD_MUTEX_INITIALIZER;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * killHandler
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Terminates this process on SIGQUIT, SIGINT, SIGTERM
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* ARGSUSED */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortekillHandler(int sig)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * doorHandler
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Recieve data from the local proxy port provider and relay
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * it to the peer node.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/* ARGSUSED */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortedoorHandler(
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte void *cookie,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte char *args,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte size_t alen,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte door_desc_t *ddp,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint_t ndid)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t result = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ddp != NULL || ndid != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "descriptor passed to door %p %d", ddp, ndid);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = EINVAL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (args == NULL || alen == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "empty message passed to door %p %d", args, alen);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = EFAULT;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (result == 0)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte result = postMsg((uint_t)alen, (uchar_t *)args);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) door_return((char *)&result, sizeof (result), NULL, 0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING, "door_return FAILED %d", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortepostMsg(uint_t nelem, uchar_t *aluaMsg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t buflen;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uchar_t *buf;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ret = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int ns;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (t_handle == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "postMsg() no transport handle");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buf = malloc(nelem + sizeof (buflen));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte buflen = htonl(nelem); /* length in network byte order */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(&buflen, buf, sizeof (buflen));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte bcopy(aluaMsg, buf + sizeof (buflen), nelem);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte (void) pthread_mutex_lock(&send_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ns = pt_ops->stmf_proxy_send(t_handle, buf, nelem + sizeof (buflen));
91159e90831fc9243576f2ec1a483b3bb462bcf4John Forte (void) pthread_mutex_unlock(&send_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ns != nelem + sizeof (buflen)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = errno;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (ret == 0)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte ret = ENOTTY; /* something bogus */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_CRIT, "send() call failed: %d", ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(buf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Multi-thread the data path from the peer node to the local
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * proxy port provider. During discover, there can be a large
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * burst of messages from the peer node proportional to the number
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * of LUs. Multiple threads allow these messages to be processed
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * simultaneously.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortetypedef struct pppt_drv_queue {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte struct pppt_drv_queue *next;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t buflen;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uchar_t *buf;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte} pppt_drv_queue_t;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepppt_drv_queue_t *pq_head = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepthread_mutex_t pq_mutex = PTHREAD_MUTEX_INITIALIZER;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepthread_cond_t pq_cond = PTHREAD_COND_INITIALIZER;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint pq_num_threads = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint pq_avail_threads = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*ARGSUSED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortepush_to_drv(void *arg)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_drv_queue_t *pq;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int rc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_lock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq_num_threads++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_unlock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (;;) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_lock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte while (pq_head == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq_avail_threads++;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_cond_wait(&pq_cond, &pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq_avail_threads--;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq = pq_head;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq_head = pq->next;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq->next = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_unlock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Relay the message to the local kernel */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte rc = stmfPostProxyMsg(proxy_hdl, (void *)pq->buf, pq->buflen);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (rc != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* XXX die ? */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_CRIT, "ioctl failed - %d", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(pq->buf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(pq);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*NOTREACHED*/
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Receive data from peer and queue it up for the proxy driver.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint message_count = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forterelay_peer_msg()
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte uint32_t buflen;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pppt_drv_queue_t *pq, *tmpq;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pthread_t tid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int rc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* first receive the length of the message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((pt_ops->stmf_proxy_recv(t_handle, (uchar_t *)&buflen,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sizeof (buflen))) != sizeof (buflen)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING, "recv() call failed: %d",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq = malloc(sizeof (*pq));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq->next = NULL;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq->buflen = ntohl(buflen);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq->buf = malloc(pq->buflen+4);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (log_debug) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "recvMsg: size of buffer - %d", (int)pq->buflen);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((pt_ops->stmf_proxy_recv(t_handle, pq->buf, pq->buflen)) !=
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq->buflen) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING, "recv() call failed: %d",
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Eat the first message from peer */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (message_count++ == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *(pq->buf+pq->buflen) = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(pq->buf);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte free(pq);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Queue the message to the driver */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_lock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pq_head == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pq_head = pq;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* add to the tail */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tmpq = pq_head;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte while (tmpq->next != NULL)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tmpq = tmpq->next;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte tmpq->next = pq;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Make sure there is a thread to service this message */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pq_avail_threads) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* wake an available thread */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_cond_signal(&pq_cond);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_unlock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* no threads available, create a new thread */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) pthread_mutex_unlock(&pq_mutex);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte rc = pthread_create(&tid, NULL, push_to_drv, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (rc != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "pthread_create() call failed: %d", rc);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (pq_num_threads == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* never created a thread */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(rc);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Initialization for a daemon process
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic void
450396635f70344c58b6b1e4db38cf17ff34445cJohn FortedaemonInit(void)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte pid_t pid;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int devnull;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (fore_ground)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((pid = fork()) < 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_CRIT, "Could not fork(). Exiting");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else if (pid != 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * XXX
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Simple approach for now - let the service go online.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Later, set-up a pipe to the child and wait until the
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * child indicates service is setup.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(SMF_EXIT_OK);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) setsid();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) chdir("/");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) umask(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte devnull = open("/dev/null", O_RDWR);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (devnull < 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_CRIT,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "Failed to open /dev/null. Exiting");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) dup2(devnull, STDIN_FILENO);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) dup2(devnull, STDOUT_FILENO);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) dup2(devnull, STDERR_FILENO);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) close(devnull);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortevoid
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortedaemon_fini(int rc)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * XXX inform the parent about the service state
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * For now, just exit on error.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (rc != 0)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(rc);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortestatic int
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteopen_proxy_driver()
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int drv_door_fd;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int stmf_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Create communication channel for the driver.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((drv_door_fd = door_create(doorHandler, NULL, 0)) < 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte perror("door_create");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "could not create door: errno %d", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (SMF_EXIT_ERR_FATAL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ret = stmfInitProxyDoor(&proxy_hdl, drv_door_fd);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_ret != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte perror("pppt ioctl: door install");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_DEBUG,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "could not install door: errno %d", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (SMF_EXIT_ERR_FATAL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte return (SMF_EXIT_OK);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte/*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * daemon entry
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * parse arguments
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * create resources to talk to child
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if !foreground
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * daemonize, run as child
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * open proxy driver
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * install door in proxy driver
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * create socket
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if server-side
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * bind socket
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if !foreground
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * inform parent things aok
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if parent
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * exit(SMF_EXIT_OK)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if server-side
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * accept
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * if client-side
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * connect
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * send hello
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * recv hello
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * loop on recieve
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * XXX anyway to check in envp that we are started by SMF?
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forteint
450396635f70344c58b6b1e4db38cf17ff34445cJohn Fortemain(int argc, char *argv[])
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte{
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte struct sockaddr_in sin;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int rc;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte struct sigaction act;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte sigset_t sigmask;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int c;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int node = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int node_override = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int server_node = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int server_match = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte extern char *optarg;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte int stmf_ret;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) setlocale(LC_ALL, "");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte openlog("stmfproxy", LOG_PID, LOG_DAEMON);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) setlogmask(LOG_UPTO(LOG_INFO));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte while ((c = getopt(argc, argv, "dfn:")) != -1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte switch (c) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case 'd':
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) setlogmask(LOG_UPTO(LOG_DEBUG));
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte log_debug = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case 'f':
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte fore_ground = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte case 'n':
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte node_override = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte node = atoi(optarg);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte default:
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Should never happen from smf
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, USAGE, argv[0]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(SMF_EXIT_ERR_CONFIG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte break;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * After the options, only the server argument should remain.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (optind != argc-1) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, USAGE, argv[0]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(SMF_EXIT_ERR_CONFIG);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) strcpy(aluaNode, argv[optind]);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_DEBUG, "aluaNode %s", aluaNode);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (gethostname(myNode, 255)) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte perror("gethostname");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((inet_aton(aluaNode, &sin.sin_addr)) == 0) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Not ipaddr, try hostname match.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte server_match = (strcmp(aluaNode, myNode)) ? 0 : 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte } else {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * see if this is our ip address
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) fprintf(stderr, "Sorry, cannot use ip adress format\n");
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (server_match) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte server_node = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (!node_override)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte node = 1;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Allow SIGQUIT, SIGINT and SIGTERM signals to terminate us
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte act.sa_handler = killHandler;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigemptyset(&act.sa_mask);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte act.sa_flags = 0;
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Install the signal handler */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigaction(SIGQUIT, &act, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigaction(SIGINT, &act, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigaction(SIGTERM, &act, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigaction(SIGHUP, &act, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* block all signals */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigfillset(&sigmask);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* unblock SIGQUIT, SIGINT, SIGTERM */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigdelset(&sigmask, SIGQUIT);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigdelset(&sigmask, SIGINT);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigdelset(&sigmask, SIGTERM);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigdelset(&sigmask, SIGHUP);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) sigprocmask(SIG_SETMASK, &sigmask, NULL);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* time to go backstage */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte daemonInit();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((rc = open_proxy_driver()) != 0)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte daemon_fini(rc);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if ((rc = stmf_proxy_transport_init("sockets", &pt_ops)) != 0)
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte daemon_fini(rc);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Establish connection
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte *
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * At this point, the parent has exited and the service
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * is online. But there are no real proxy services until
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * this connect call succeeds. That could take a long time if
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * the peer node is down.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte t_handle = pt_ops->stmf_proxy_connect(server_node, aluaNode);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (t_handle == NULL) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_WARNING,
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte "socket() call failed: %d", errno);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* The first message is a greeting */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte (void) postMsg((uint_t)strlen(myNode)+1, (uchar_t *)myNode);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* Read the greeting from peer node */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte relay_peer_msg();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Set the alua state in stmf. No need to keep
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * the device open since the proxy driver has a reference.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte stmf_ret = stmfSetAluaState(B_TRUE, node);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte if (stmf_ret != STMF_STATUS_SUCCESS) {
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte syslog(LOG_DAEMON|LOG_CRIT, "stmf ioctl failed - %x", stmf_ret);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte exit(1);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /* service is online */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte daemon_fini(0);
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte /*
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Loop relaying data from the peer daemon to the local kernel.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * Data coming from the local kernel is handled asynchronously
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte * by the door server.
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte for (;;) { /* loop forever */
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte relay_peer_msg();
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte }
450396635f70344c58b6b1e4db38cf17ff34445cJohn Forte}