[BACK]Return to crs_lib.h CVS log [TXT][DIR] Up to [Development] / failsafe / FailSafe / cluster_services / include

File: [Development] / failsafe / FailSafe / cluster_services / include / crs_lib.h (download)

Revision 1.1, Thu Aug 31 19:16:32 2000 UTC (17 years, 1 month ago) by vasa
Branch: MAIN
CVS Tags: HEAD

Initial checkin

/*
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it would be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * Further, this software is distributed without any warranty that it is
 * free of the rightful claim of any third person regarding infringement
 * or the like.  Any license provided herein, whether implied or
 * otherwise, applies only to this software file.  Patent licenses, if
 * any, provided herein do not apply to combinations of this program with
 * other software, or any other product whatsoever.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
 * 
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
 * Mountain View, CA 94043, or:
 * 
 * http://www.sgi.com 
 * 
 * For further information regarding this notice, see: 
 * 
 * http://oss.sgi.com/projects/GenInfo/NoticeExplan
 */
/*
 * crs_lib.h
 *
 * This file contains data structs and consts shared by CRSD and CRS lib.
 *
 * $Id: crs_lib.h,v 1.1 2000/08/31 19:16:32 vasa Exp $
 */

#ifndef CRS_LIB_H
#define CRS_LIB_H

#ident "$Id: crs_lib.h,v 1.1 2000/08/31 19:16:32 vasa Exp $"

#define CRS_IPC_FILE_PREFIX	CI_HACOMM_DIR "/" "crsd-ipc"

/* Configuration information */

typedef struct crs_ipaddr_s {
    char		*hostname;
    struct sockaddr_in	sin;
    int			priority;
} crs_ipaddr_t;

struct crs_controlling_port_s;
struct crs_controlled_port_s;
typedef struct crs_controlling_port_s	crs_controlling_port_t;
typedef struct crs_controlled_port_s	crs_controlled_port_t;

typedef struct crs_grp_reset_s {
    char		*group; 	/* Group name. */
    crs_nodeinc_t	reset_inc; 	/* Seqno of last successful reset req. */
} crs_grp_reset_t;

typedef enum crs_reset_type_t {
    CRS_RESET_NOP	= 0,		/* No op. */
    CRS_RESET_PWRCCL	= 1,		/* Power cycle the machine. */
    CRS_RESET_RESET	= 2,		/* Reset the machine */
    CRS_RESET_NMI	= 3,		/* Send an NMI */
    CRS_RESET_COUNT
} crs_reset_type_t;

typedef struct crs_node_s {
    ci_nodeid_t		nodeid;		/* Nodeid of this node. */
    char		*hostname;	/* Hostname of this node. */
    ci_nlist_t		*ipaddrl;	/* List of IP addresses that
    					 * will be used to address 
					 * this node. Elements of type
    					 * crs_ipaddr_t. */
    ci_nlist_t		*ctlringl;	/* List of ports owned by
					 * this node - list of type
    					 * crs_controlling_port_t. */
    ci_nlist_t		*ctlredl;	/* List of controlled ports at 
					 * this node - list of type
					 * crs_controlled_port_t. */
    struct crs_node_s	*sysctlr_nodep;	/* Node that controls the
					 * system controller port of
					 * this node. */
    struct crs_node_s	*console_nodep;	/* Node that controls the 
					 * console port of this node. */
    crs_controlled_port_t *sysctlrp;	/* Ptr to sysctrl controlled port. */
    crs_controlled_port_t *consolep;	/* Ptr to console controlled port. */
    crs_reset_type_t	reset_type;	/* When we get a reset request
					 * without any special instructions 
					 * do we reset/nmi/power cycle
					 * this machine? */
    ci_clock_t		time_last_reset;/* Time this node was last reset. */
    crs_reset_status_t  status_last_reset;/* Status of the reset node, SUCCESS
					     or MAYBEPWRDN. */
    ci_nlist_t		*last_resetl;	/* List of crs_grp_reset_t *. */
} crs_node_t;

typedef enum crs_controlled_port_class_e {
    CRSDP_CONSOLE	= 1,
    CRSDP_SYSCTLR	= 2
} crs_controlled_port_class_t;

typedef struct crs_controlled_port_type_s {
    char			*typename;	/* msc, mmsc ... */
    crs_controlled_port_class_t	class;		/* sysctlr/console */
} crs_controlled_port_type_t;

typedef struct crs_controlling_port_type_s {
    char			*typename;
} crs_controlling_port_type_t;

typedef struct crs_controlling_port_type_info_s {
    crs_controlling_port_type_t	type;	
    void			(*free)(crs_controlling_port_t *);
    ci_err_t			(*open)(crs_controlling_port_t *);
    ci_err_t			(*readch)(crs_controlling_port_t *, char *, int);
    ci_err_t			(*writech)(crs_controlling_port_t *,  char);
    void			(*close)(crs_controlling_port_t *);
} crs_controlling_port_type_info_t;

typedef struct crs_controlled_port_type_info_s {
    crs_controlled_port_type_t	type;		
    void			(*free)(crs_controlled_port_t *);
    ci_err_t			(*init)(crs_controlled_port_t *);
    ci_err_t			(*pwrccl)(crs_controlled_port_t *);
    ci_err_t			(*reset)(crs_controlled_port_t *);
    ci_err_t			(*nmi)(crs_controlled_port_t *);
    ci_err_t 			(*ping)(crs_controlled_port_t *);
    ssize_t			(*put)(crs_controlled_port_t *, 
				       const void *, size_t);
    ssize_t			(*get)(crs_controlled_port_t *, 
				       void *, size_t);
} crs_controlled_port_type_info_t;

typedef enum crs_controlling_port_status_e {
    CRSGPS_NEW		= 1,	/* Port data structs have not yet been init */
    CRSGPS_OPEN		= 2,	/* Port has been opened */
    CRSGPS_CLOSED	= 3	/* Port is closed */
} crs_controlling_port_status_t;

typedef enum crs_controlled_port_status_e {
    CRSDPS_NEW		= 0,	/* Port data structs have not yet been init */
    CRSDPS_MONSTARTED	= 1,	/* Port monitoring has been started */
    CRSDPS_NOTMONITORED	= 2,    /* Port is not being monitored */
    CRSDPS_LIVE		= 3,	/* Port is being monitored and is alive */
    CRSDPS_DEAD		= 4,	/* Port is being monitored and is dead */
    CRSDPS_NOTOWNER	= 5,	/* Port can not be monitored by us. */
    CRSDPS_DISABLED	= 6	/* Port is disabled currently. */
} crs_controlled_port_status_t;

typedef struct crs_controlled_port_state_s {
    crs_controlled_port_status_t	status;
    boolean_t				disabled;	/* Whether operations
    							 * on this controlled
    							 * port are currently
    							 * administratively
    							 * disabled. */
    ci_clock_t				cmd_resp_time;  /* last time a cmd to this
							 * port was successful
							 * in getting a response
							 * back. */  
    ci_clock_t				cmd_fail_time;	/* Time a cmd to this
 							 * port failed to evoke
  							 * a response for the
  							 * first time without
  							 * having been followed
  							 * by a good cmd. */
    boolean_t				status_change;	/* Indicates if a change
							 * in the status of the
							 * serial line was observed
							 * during the last opertaion
							 * on this port. Used for
							 * logging purposes. */

} crs_controlled_port_state_t;

struct crs_controlling_port_s {
    char				*name;
    crs_controlling_port_status_t	status;
    crs_controlling_port_type_info_t	*infop;	/* Pointer to type info struct */
    ci_nlist_t				*ctlredl;/* List of controlled ports -
    						  * elements  of type
    						  * crs_controlled_port_t */
    crs_node_t				*nodep;	/* Back pointer to the node 
    						 * on which this port resides.
    						 * We probablyy won't use it. */
    crs_mutex_hdl_t			mutex;	/* Mutex to control access to
						 * this port. */
    void				*data;	/* Port type specific data. */
};

#define CRS_SYSCTLR_PASSWD_NONE		"none"

struct crs_controlled_port_s {
    crs_controlled_port_type_info_t	*infop;	/* Type info */
    crs_controlled_port_state_t		*snapshot; /* Port State. */
    char				*passwd;/* The system controller passwd
						 * in case it is an msc or an mmsc
						 * port. */
    crs_node_t				*nodep;	/* Back pointer to the node 
						 * on which port resides. */
    crs_controlling_port_t		*ctlringp;/* Back pointer to the
						   * port that controls
						   * this port. */
    crs_mutex_hdl_t			mutex;	/* Mutex to control access to
						 * this port. */
    boolean_t				busy;	/* Whether this port is 
    						 * in use. */
    int					owner_id;/* Id of the thread that is
    						 * currently using this port. */
    void				*data;	/* Type specific data */
};

typedef struct crs_crsd_params_s {		/* See crsd_priv.h for */
    int			mon_interval;		/*  explanations. */
    int			nap_interval;
    int			reset_interval;
    int			send_retry_interval;
    int			resend_timeout;
    int			resend_tries;
    boolean_t		run_pwrfail;
    ci_clock_t		min_net_delay;
    ci_clock_t		max_net_delay;
    ci_clock_t		max_net_fail_int;
    ci_clock_t		max_serial_fail_int;
    boolean_t		mon_on_startup;
} crs_crsd_params_t;

typedef enum crs_crsd_param_type_s {
    CRS_MON_INTERVAL		=  0,
    CRS_NAP_INTERVAL		=  1,
    CRS_RESET_INTERVAL		=  2,
    CRS_SEND_RETRY_INTERVAL	=  3,
    CRS_RESEND_TIMEOUT		=  4,
    CRS_RESEND_TRIES		=  5,
    CRS_RUN_PWRFAIL		=  6,
    CRS_MIN_NET_DELAY		=  7,
    CRS_MAX_NET_DELAY		=  8,
    CRS_MAX_NET_FAIL_INT	=  9,
    CRS_MAX_SERIAL_FAIL_INT	= 10,
    CRS_MON_ON_STARTUP		= 11,
    CRS_NUMPARAMS	
} crs_crsd_param_type_t;

typedef struct crs_params_s {
    int		values[CRS_NUMPARAMS];
} crs_params_t;

#define CRS_MON_INTERVAL_DEFAULT	  	  2000	/* msecs */
#define CRS_NAP_INTERVAL_DEFAULT	  	  1000	/* msecs */
#define	CRS_RESET_INTERVAL_DEFAULT	 	 20000	/* msecs */
#define CRS_SEND_RETRY_INTERVAL_DEFAULT		  1000	/* msecs */
#define CRS_RESEND_TIMEOUT_DEFAULT		 10000	/* msecs */
#define CRS_RESEND_TRIES_DEFAULT		     2  
#define CRS_RUN_PWRFAIL_DEFAULT			B_TRUE
#define CRS_MIN_NET_DELAY_DEFAULT	   	   250	/* msecs */
#define CRS_MAX_NET_DELAY_DEFAULT	   	   500	/* msecs */
#define CRS_MAX_NET_FAIL_INT_DEFAULT	   	300000	/* msecs  = 5 min */
#define CRS_MAX_SERIAL_FAIL_INT_DEFAULT	   	 15000	/* msecs */
#define CRS_MON_ON_STARTUP_DEFAULT		B_TRUE

#define CRS_HELPSTR_RUN_PWRFAIL			"Whether to run the power fail"\
						" algorithm when the system"\
						" controller does not respond."

typedef struct crs_config_s {
    boolean_t		active;		/* active == B_TRUE : crsd should
    					 * accept and execute client
    					 * requests when using this config.
    					 * active == B_FALSE : crsd should 
    					 * not execute client requests when
    					 * using this config. */
    ci_config_cluster_t	my_cluster;	/* My cluster configuration, used for 
					 * sending mail notification. */
    crs_node_t		*my_nodep;
    ci_nlist_t		*nodel;		/* List of nodes that the crs
					 * subsystem is aware of. */
    ci_nlist_t		*ctlringl;	/* List of type information about
					 * controlling ports. */
    ci_nlist_t		*ctlredl;	/* List of type information about
    					 * controlled ports. */
    crs_crsd_params_t	params;
} crs_config_t;

extern crs_config_t	*crscp;		/* Pointer to the crs configuration
					 * information data structure. */


/* Communication between the daemon and the library */

#define StrlenPlus1(s)	(strlen(s) + 1)

typedef enum crs_req_type_e {
    CRSREQ_DUMMY	= 0,
    CRSREQ_REGISTER	= 1,
    CRSREQ_UNREGISTER	= 2,
    CRSREQ_STARTMON	= 3,
    CRSREQ_STOPMON	= 4,
    CRSREQ_GETSTATUS	= 5,
    CRSREQ_RESET	= 6,
    CRSREQ_DUMP		= 7
} crs_req_type_t;

typedef enum crs_req_status_e {
    CRSREQS_SUCCESS	= 0,
    CRSREQS_NEW		= 1,
    CRSREQS_FAILED	= 2,
    CRSREQS_NOTREADY	= 3,
    CRSREQS_INVALID	= 4
} crs_req_status_t;
    
typedef	uint32_t	crs_version_t;

typedef struct crs_msg_s {
    crs_version_t	version;/* CRS library version number. The daemon
				 * might reject a request if the request
				 * from a client linked with an unsupported
				 * library version. */
    crs_req_type_t	type;
    crs_req_hdl_t	hdl;	/* Request handle generated by the crs 
				 * library to identify the request. */
    int			flags; 
    ci_err_t		status;
    size_t		len;	/* Size of the msg inclusive of this hdr. */
    char		data[1];
} crs_msg_t;

typedef crs_msg_t	crs_req_msg_t;
typedef crs_msg_t	crs_rsp_msg_t;

/* Prototype from crs_params.c */
const char              *crs_cdbkey_to_clikey(char *);
const char              *crs_clikey_to_cdbkey(char *);
const ci_param_name_t   *crs_params_names_get(int *);
int                     crs_params_count_get(void);
crs_params_t            *crs_params_create(void);
void                    crs_params_clear(crs_params_t *);
void                    crs_params_destroy(crs_params_t *);
ci_param_t              *crs_param_extract(crs_params_t *, char *);
void                    crs_param_free(ci_param_t *);
ci_err_t                crs_param_compile(crs_params_t *, char *, 
                                          ci_param_t *);
boolean_t               crs_params_verify(crs_params_t *, char *);
ci_err_t                crs_params_set(cdb_handle_t, boolean_t,
				       crs_params_t *, char *);
ci_err_t		crs_params_get(cdb_handle_t, boolean_t,
				       crs_params_t *, char *);

/* Prototypes from crs_portreg.c */
ci_err_t	crs_porttypes_register(void);

/* Prototypes from crs_port.c */

crs_controlling_port_type_info_t *
crs_controlling_port_type_create(char *,
				 void (*)(crs_controlling_port_t *),
				 ci_err_t (*)(crs_controlling_port_t *),
				 ci_err_t (*)(crs_controlling_port_t *, char *, int),
				 ci_err_t (*)(crs_controlling_port_t *, char),
				 void (*)(crs_controlling_port_t *));
ci_nlist_t *
crs_controlling_port_type_list_create(void);
crs_controlling_port_type_info_t *
crs_controlling_port_type_search(crs_controlling_port_type_t *);
ci_err_t
crs_controlling_port_type_register(crs_controlling_port_type_info_t *);
crs_controlled_port_type_info_t *
crs_controlled_port_type_create(char *,
				crs_controlled_port_class_t,
				ci_err_t (*)(crs_controlled_port_t *),
				void (*)(crs_controlled_port_t *),
				ci_err_t (*)(crs_controlled_port_t *),
				ci_err_t (*)(crs_controlled_port_t *),
				ci_err_t (*)(crs_controlled_port_t *),
				ci_err_t (*)(crs_controlled_port_t *),
				ssize_t	 (*)(crs_controlled_port_t *, const void *, size_t),
				ssize_t	 (*)(crs_controlled_port_t *, void *, size_t));
ci_nlist_t *
crs_controlled_port_type_list_create(void);
crs_controlled_port_type_info_t *
crs_controlled_port_type_search(crs_controlled_port_type_t *);
ci_err_t
crs_controlled_port_type_register(crs_controlled_port_type_info_t *);
crs_controlling_port_t *
crs_controlling_port_create(crs_controlling_port_type_info_t *, 
			    char *, crs_node_t *);
ci_nlist_t *
crs_controlling_port_list_create(void);
ci_err_t
crs_controlling_port_add(crs_node_t *, crs_controlling_port_t *);
crs_controlling_port_t *
crs_controlling_port_search(crs_node_t *, char *);
crs_controlling_port_t *
crs_controlling_port_first(ci_nlist_t *, void **);
crs_controlling_port_t *
crs_controlling_port_next(ci_nlist_t *, void **);
crs_controlled_port_t *
crs_controlled_port_create(crs_controlled_port_type_info_t *, boolean_t,
			   char *, crs_node_t *, crs_controlling_port_t *);
ci_nlist_t *
crs_controlled_port_list_create(void);
ci_err_t
crs_controlled_port_add(crs_node_t *, crs_controlled_port_t *);
crs_controlled_port_t *
crs_controlled_port_search(crs_node_t *, crs_controlled_port_class_t);
crs_controlled_port_t *
crs_controlled_port_first(ci_nlist_t *, void **);
crs_controlled_port_t *
crs_controlled_port_next(ci_nlist_t *list, void **);

/* Prototypes from crs_node.c */

crs_ipaddr_t *	crs_ipaddr_create(char *, int, ci_err_t *);
ci_nlist_t *	crs_ipaddr_list_create(void);
ci_err_t	crs_ipaddr_add(crs_node_t *, crs_ipaddr_t *);
ci_nlist_t *	crs_node_list_create(void);
crs_node_t *	crs_node_create(ci_nodeid_t, char *);
crs_node_t *	crs_node_search_on_nodeid(ci_nodeid_t);
crs_node_t *	crs_node_search_on_name(char *);
crs_node_t *	crs_node_search(ci_nodeid_t);
ci_err_t	crs_node_add(crs_node_t	*);
crs_node_t *	crs_node_first(void **);
crs_node_t *	crs_node_next(void **);

/* Prototypes from crsl_ops.c */
ci_err_t	crs_port_startmon(crs_controlled_port_t	*);
ci_err_t	crs_port_stopmon(crs_controlled_port_t *);
ci_err_t	crs_port_pwrccl(crs_controlled_port_t *);
ci_err_t	crs_port_reset(crs_controlled_port_t *);
ci_err_t	crs_port_nmi(crs_controlled_port_t *);
ci_err_t	crs_port_ping(crs_controlled_port_t *);
ssize_t		crs_port_put(crs_controlled_port_t *, const void *, size_t);
ssize_t		crs_port_get(crs_controlled_port_t *, void *, size_t);

/* Prototypes from crs_config.c */
void		crs_config_switch(void);
void		crs_config_create(void);
void		crs_config_destroy(void);
void		crs_config_init(void);
ci_err_t	crs_config_read(cdb_handle_t);
void		crs_config_print(int);

/* Prototypes from crs_grp_reset.c */
ci_nlist_t *		crs_grp_reset_list_create(void);
void			crs_grp_reset_destroy(crs_grp_reset_t *);
crs_grp_reset_t *	crs_grp_reset_create(char *, 
					      crs_nodeinc_t);
ci_err_t		crs_grp_reset_add(ci_nlist_t *, crs_grp_reset_t *);
ci_err_t		crs_grp_reset_delete(ci_nlist_t *, crs_grp_reset_t *);
crs_grp_reset_t *	crs_grp_reset_first(ci_nlist_t *,  void **);
crs_grp_reset_t *	crs_grp_reset_next(ci_nlist_t *,  void **);
crs_grp_reset_t	*	crs_grp_reset_search(crs_node_t *, char *);

/* Prototypes from crs_strings.h */
char *		crs_rtype_name(crs_reset_type_t);

#endif /* CRS_LIB_H */