/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <strings.h>
#include <meta.h>
#include <syslog.h>
extern md_mn_msg_tbl_entry_t msg_table[];
/*
* When contacting the local rpc.mdcommd we always want to do that using
* the IPv4 version of localhost.
*/
{
}
void (*
{
}
int (*
{
}
{
}
void
{
}
extern uint_t meta_rpc_err_mask(void);
/*
* If a clnt_call gets an RPC error, force the message out here with details.
* This would be nice to send to commd_debug(), but we can't call rpc.mdcommd
* code from libmeta.
*/
static void
{
/*
* This is sized for a max message which would look like this:
* "mdmn_wakeup_initiator: rpc.mdcommd node 4294967295"
*/
struct rpc_err e;
if (nid == 0) {
"%s: %s node (local)", ident, COMMD_PROGNAME);
} else {
}
}
}
/* Default timeout can be changed using clnt_control() */
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
int *
{
if (res == RPC_SUCCESS) {
return (clnt_res);
}
return (NULL);
}
/*
* Let the kernel create a clusterwide unique message ID
*
* returns 0 on success
* 1 on failure
*/
int
{
return (1); /* failure */
}
return (1); /* failure */
}
/*
* mid_smid and mid_oclass are only used for submessages.
* mdmn_create_msgid is never called for submessages, as they inherit
* the message ID from their parent.
* Thus we can safely null out the following fields.
*/
msgid->mid_oclass = 0;
/* if the node_id is not set yet, somethings seems to be wrong */
return (1); /* failure */
}
return (0); /* success */
}
{
/* It's MSGID_COPY(from, to); */
if (res->mmr_out_size > 0) {
}
if (res->mmr_err_size > 0) {
}
}
}
}
return (nres);
}
void
{
if (res->mmr_out_size > 0) {
}
if (res->mmr_err_size > 0) {
}
}
}
}
}
/* allocate a new message and copy a given message into it */
{
}
}
/* It's MSGID_COPY(from, to); */
if (msg->msg_event_size > 0) {
}
return (nmsg);
}
void
{
(direction == MD_MN_COPY_TO_INCORE));
if (direction == MD_MN_COPY_TO_ONDISK) {
/* paranoid checks */
} else {
}
}
/* Free a message */
void
{
if (msg->msg_event_size > 0) {
}
}
/* The following declarations are only for the next two routines */
/*
* mdmn_get_local_clnt(flag)
* If there is a client in the free pool, get one,
* If no client is available, create one.
* Every multithreaded application that uses mdmn_send_message must call it
* single threaded first with special flags so we do the initialization
* stuff in a safe environment.
*
* Input: MNGLC_INIT_ONLY: just initializes the mutex
* MNGLC_FOR_REAL : do real work
* Output:
* An rpc client for sending rpc requests to the local commd
* NULL in case of an error
*
*/
static CLIENT *
{
static int inited = 0;
if (inited == 0) {
inited = 1;
}
if (flag == MNGLC_INIT_ONLY)
(void) mutex_lock(&mcl_mutex);
/* if there is no entry, create a client and return a it */
TWO, "tcp");
} else {
/*
* If there is an entry from a previous put operation,
* remove it from the head of the list and free the list stuff
* around it. Then return the client
*/
tmp = mdmn_clients;
}
(void) mutex_unlock(&mcl_mutex);
clnt_pcreateerror("local_daemon");
}
return (local_daemon);
}
/*
* mdmn_put_local_clnt()
* returns a no longer used client to the pool
*
* Input: an RPC client
* Output: void
*/
static void
{
(void) mutex_lock(&mcl_mutex);
tmp = mdmn_clients;
malloc(sizeof (md_mn_client_list_t));
(void) mutex_unlock(&mcl_mutex);
}
/*
* This is the regular interface for sending a message.
* This function only passes through all arguments to
* mdmn_send_message_with_msgid() and adds a NULL for the message ID.
*
* Normally, you don't have already a message ID for the message you want
* to send. Only in case of replaying a previously logged message,
* a msgid is already attached to it.
* In that case mdmn_send_message_with_msgid() has to be called directly.
*
* The recipient argument is almost always unused, and is therefore typically
* set to zero, as zero is an invalid cluster nodeid. The exceptions are the
* marking and clearing of the DRL from a node that is not currently the
* owner. In these cases, the recipient argument will be the nodeid of the
* mirror owner, and MD_MSGF_DIRECTED will be set in the flags. Non-owner
* nodes will not receive these messages.
*
* Return values / CAVEAT EMPTOR: see mdmn_send_message_with_msgid()
*/
int
char *data,
int size,
md_error_t *ep)
{
}
/*
* mdmn_send_message_with_msgid()
* Create a message from the given pieces of data and hand it over
* to the local commd.
* This may fail for various reasons (rpc error / class busy / class locked ...)
* Some error types are immediately deadly, others will cause retries
* until the request is fulfilled or until the retries are ecxceeded.
*
* In case an error is returned it is up to the user to decide what to do.
*
* Returns:
* 0 on success
* 1 if retries1 exceeded
* 2 if retries2 exceeded
* -1 if connecting to the local daemon failed
* -2 if the RPC call to the local daemon failed
* -3 if this node hasn't yet joined the set
* -4 if any other problem occured
*
* CAVEAT EMPTOR:
* The caller is responsible for calling free_result() when finished with
* the results!
*/
int
char *data,
int size,
md_error_t *ep)
{
int retval;
/*
* Special case for multithreaded applications:
* When starting up, the application should call mdmn_send_message
* single threaded with all parameters set to NULL.
* When we detect this we know, we safely can do initialization
* stuff here.
* We only check for set and type being zero
*/
/* do all needed initializations here */
(void) mdmn_get_local_clnt(MNGLC_INIT_ONLY);
return (0); /* success */
}
/* did the caller specify space to store the result pointer? */
"FATAL, can not allocate result structure\n"));
return (-4);
}
/* Replay messages already have their msgID */
if ((flags & MD_MSGF_REPLAY_MSG) == 0) {
"FATAL, can not create message ID\n"));
return (-4);
}
} else {
/* in this case a message ID must be specified */
}
/*
* When setting the flags, additionally apply the
* default flags for this message type.
*/
/*
* For the timeout pick the specific timeout for the message times the
* the maximum number of nodes.
* This is a better estimate than 1 hour or 3 days or never.
*/
if (flags & MD_MSGF_VERBOSE) {
}
/* get an RPC client to the local commd */
return (-1);
}
/*
* run that loop until:
* - commstate is Ok
* - deadly commstate occured
* - retries1 or retries2 exceeded
*/
for (; ; ) {
/* Bingo! */
retval = 0;
goto out;
}
/* Hmm... what if there's no handler? */
retval = 0;
goto out;
}
/*
* This node didn't yet join the disk set. It is not
* supposed to send any messages then.
* This is deadly (no retries)
*/
retval = -3;
goto out;
}
/* these two are deadly too (no retries) */
retval = -4;
goto out;
}
/* Class busy? Use retry1 */
if (retry1-- == 0) {
goto out;
}
if (flags & MD_MSGF_VERBOSE)
(void) printf("#Resend1 ID=(%d, "
"0x%llx-%d)\n",
continue;
}
/*
* Be patient, wait for 1 secs and try again.
* It's not likely that the ABORT condition ever
* goes away, but it won't hurt to retry
*/
(void) sleep(1);
continue;
}
if (flags & MD_MSGF_FAIL_ON_SUSPEND) {
/* caller wants us to fail here */
retval = -4;
goto out;
} else {
/* wait for 1 secs and try again. */
(void) sleep(1);
continue;
}
}
} else {
/*
* If we get a NULL back from the rpc call, try to
* reinitialize the client.
* Depending on retries2 we try again, or not.
*/
"send_message: ID=(%d, 0x%llx-%d) resp = NULL\n",
return (-1);
}
(char *)&timeout);
}
/*
* If we are here, either resp is zero or resp is non-zero
* but some commstate not mentioned above occured.
* In either case we use retry2
*/
if (retry2-- == 0) {
"send_message: (%d, 0x%llx-%d) retry2 exceeded\n"),
goto out;
}
if (flags & MD_MSGF_VERBOSE) {
"send_message: (%d, 0x%llx-%d) resend on retry2\n"),
}
}
}
out:
return (retval);
}
/*
*
* Parameter:
* set number or 0 (meaning all sets)
* class number or 0 (meaning all classes)
*
* Returns:
* 0 on success (set is suspended and all messages drained)
* MDE_DS_COMMDCTL_SUSPEND_NYD if set is not yet drained
* MDE_DS_COMMDCTL_SUSPEND_FAIL if any failure occurred
*/
int
{
int *resp;
return (MDE_DS_COMMDCTL_SUSPEND_FAIL);
}
"tcp");
clnt_pcreateerror("local_daemon");
return (MDE_DS_COMMDCTL_SUSPEND_FAIL);
}
if (timeout != 0) {
return (1);
}
}
return (MDE_DS_COMMDCTL_SUSPEND_FAIL);
}
/* set successfully drained, no outstanding messages */
return (0);
}
if (*resp != MDMNE_SET_NOT_DRAINED) {
/* some error occurred */
return (MDE_DS_COMMDCTL_SUSPEND_FAIL);
}
/* still outstanding messages, return not yet drained failure */
return (MDE_DS_COMMDCTL_SUSPEND_NYD);
}
/*
*
* Parameter:
* set number or 0 (meaning all sets)
* class number or 0 (meaning all classes)
*
* Returns:
* 0 on success
* MDE_DS_COMMDCTL_RESUME_FAIL on failure
*/
int
{
int *resp;
return (MDE_DS_COMMDCTL_RESUME_FAIL);
}
"tcp");
clnt_pcreateerror("local_daemon");
return (MDE_DS_COMMDCTL_RESUME_FAIL);
}
if (timeout != 0) {
return (1);
}
}
ret = 0;
}
}
return (ret);
}
/*
* abort all communication
*
* returns void, because: if *this* get's an error what do you want to do?
*/
void
mdmn_abort(void)
{
(void) mdmn_send_message(0, /* No set is needed for this message */
}
}
/*
* trigger the reinitialization for a given set.
*
* Parameter: set number
*
* Returns:
* 0 on success
* 1 on failure
*/
int
{
int *resp;
return (1);
}
"tcp");
clnt_pcreateerror("local_daemon");
return (1);
}
if (timeout != 0) {
return (1);
}
}
ret = 0;
}
}
return (ret);
}
/*
* Lock a single message type from being processed on this node
*
* Parameter: md_mn_msgtype_t msgtype, uint_t locktype
*
* Returns:
* 0 on success
* 1 on failure
*/
int
{
int *resp;
return (1);
}
"tcp");
clnt_pcreateerror("local_daemon");
return (1);
}
ret = 0;
}
}
return (ret);
}