xref: /onnv-gate/usr/src/cmd/fs.d/nfs/statd/sm_statd.h (revision 1:475eb30342f9)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
70Sstevel@tonic-gate  * with the License.
80Sstevel@tonic-gate  *
90Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate  * See the License for the specific language governing permissions
120Sstevel@tonic-gate  * and limitations under the License.
130Sstevel@tonic-gate  *
140Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate  *
200Sstevel@tonic-gate  * CDDL HEADER END
210Sstevel@tonic-gate  */
220Sstevel@tonic-gate /*
23*1Sgt29601  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
280Sstevel@tonic-gate /*	  All Rights Reserved  	*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate /*
310Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
320Sstevel@tonic-gate  * The Regents of the University of California
330Sstevel@tonic-gate  * All Rights Reserved
340Sstevel@tonic-gate  *
350Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
360Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
370Sstevel@tonic-gate  * contributors.
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #ifndef	_SM_STATD_H
410Sstevel@tonic-gate #define	_SM_STATD_H
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #ifdef __cplusplus
460Sstevel@tonic-gate extern "C" {
470Sstevel@tonic-gate #endif
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /* Limit defines */
500Sstevel@tonic-gate #define	SM_DIRECTORY_MODE 00755
510Sstevel@tonic-gate #define	MAX_HASHSIZE 50
520Sstevel@tonic-gate #define	SM_RPC_TIMEOUT	15
530Sstevel@tonic-gate #define	PERCENT_MINJOIN 10
540Sstevel@tonic-gate #define	MAX_FDS	256
550Sstevel@tonic-gate #define	MAX_THR	25
560Sstevel@tonic-gate #define	INC_DELAYTIME	30
570Sstevel@tonic-gate #define	MAX_DELAYTIME	300
580Sstevel@tonic-gate #define	SM_CLTS_TIMEOUT	15
590Sstevel@tonic-gate /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */
600Sstevel@tonic-gate #define	SM_MAXPATHLEN	17
610Sstevel@tonic-gate /* Increment size for realloc of array host_name */
620Sstevel@tonic-gate #define	HOST_NAME_INCR  5
630Sstevel@tonic-gate 
640Sstevel@tonic-gate /* supported address family names in /var/statmon symlinks */
650Sstevel@tonic-gate #define	SM_ADDR_IPV4	"ipv4"
660Sstevel@tonic-gate #define	SM_ADDR_IPV6	"ipv6"
670Sstevel@tonic-gate 
680Sstevel@tonic-gate /* Supported for readdir_r() */
69*1Sgt29601 #define	MAXDIRENT	(sizeof (struct dirent) +  _POSIX_PATH_MAX + 1)
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /* Structure entry for monitor table (mon_table) */
720Sstevel@tonic-gate struct mon_entry {
730Sstevel@tonic-gate 	mon id;				/* mon information: mon_name, my_id */
740Sstevel@tonic-gate 	struct mon_entry *prev;		/* Prev ptr to prev entry in hash */
750Sstevel@tonic-gate 	struct mon_entry *nxt;		/* Next ptr to next entry in hash */
760Sstevel@tonic-gate };
770Sstevel@tonic-gate typedef struct mon_entry mon_entry;
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /* Structure entry for record (rec_table) and recovery (recov_q) tables */
800Sstevel@tonic-gate struct name_entry {
810Sstevel@tonic-gate 	char *name;			/* name of host */
820Sstevel@tonic-gate 	int count;			/* count of entries */
830Sstevel@tonic-gate 	struct name_entry *prev;	/* Prev ptr to prev entry in hash */
840Sstevel@tonic-gate 	struct name_entry *nxt;		/* Next ptr to next entry in hash */
850Sstevel@tonic-gate };
860Sstevel@tonic-gate typedef struct name_entry name_entry;
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /* Structure for passing arguments into thread send_notice */
890Sstevel@tonic-gate typedef struct moninfo {
900Sstevel@tonic-gate 	mon id;				/* Monitor information */
910Sstevel@tonic-gate 	int state;			/* Current state */
920Sstevel@tonic-gate } moninfo_t;
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /* Structure entry for hash tables */
950Sstevel@tonic-gate typedef struct sm_hash {
960Sstevel@tonic-gate 	union {
970Sstevel@tonic-gate 		struct mon_entry *mon_hdptr;	/* Head ptr for mon_table */
980Sstevel@tonic-gate 		name_entry *rec_hdptr;		/* Head ptr for rec_table */
990Sstevel@tonic-gate 		name_entry *recov_hdptr;	/* Head ptr for recov_q */
1000Sstevel@tonic-gate 	} smhd_t;
1010Sstevel@tonic-gate 	mutex_t	lock;			/* Lock to protect each list head */
1020Sstevel@tonic-gate } sm_hash_t;
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate #define	sm_monhdp	smhd_t.mon_hdptr
1050Sstevel@tonic-gate #define	sm_rechdp	smhd_t.rec_hdptr
1060Sstevel@tonic-gate #define	sm_recovhdp	smhd_t.recov_hdptr
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /* Structure entry for address list in name-to-address entry */
1090Sstevel@tonic-gate typedef struct addr_entry {
1100Sstevel@tonic-gate 	struct addr_entry *next;
1110Sstevel@tonic-gate 	struct netobj ah;
1120Sstevel@tonic-gate 	sa_family_t family;
1130Sstevel@tonic-gate } addr_entry_t;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /* Structure entry for name-to-address translation table */
1160Sstevel@tonic-gate typedef struct name_addr_entry {
1170Sstevel@tonic-gate 	struct name_addr_entry *next;
1180Sstevel@tonic-gate 	char *name;
1190Sstevel@tonic-gate 	struct addr_entry *addresses;
1200Sstevel@tonic-gate } name_addr_entry_t;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate /* Hash tables for each of the in-cache information */
1230Sstevel@tonic-gate extern sm_hash_t	mon_table[MAX_HASHSIZE];
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate /* Global variables */
1260Sstevel@tonic-gate extern mutex_t crash_lock;	/* lock for die and crash variables */
1270Sstevel@tonic-gate extern int die;			/* Flag to indicate that an SM_CRASH */
1280Sstevel@tonic-gate 				/* request came in & to stop threads cleanly */
1290Sstevel@tonic-gate extern int in_crash;		/* Flag to single thread sm_crash requests. */
1300Sstevel@tonic-gate extern int regfiles_only;	/* Flag to indicate symlink use in statmon */
1310Sstevel@tonic-gate extern cond_t crash_finish;	/* Condition to wait until crash is finished */
1320Sstevel@tonic-gate extern mutex_t sm_trylock;	/* Lock to single thread sm_try */
1330Sstevel@tonic-gate /*
1340Sstevel@tonic-gate  * The only established lock precedence here is:
1350Sstevel@tonic-gate  *
1360Sstevel@tonic-gate  *	thr_rwlock > name_addrlock
1370Sstevel@tonic-gate  */
1380Sstevel@tonic-gate extern mutex_t name_addrlock;	/* Locks all entries of name-to-addr table */
1390Sstevel@tonic-gate extern rwlock_t thr_rwlock;	/* Reader/writer lock for requests coming in */
1400Sstevel@tonic-gate extern cond_t retrywait;	/* Condition to wait before starting retry */
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN];
1430Sstevel@tonic-gate extern char BACKUP[MAXPATHLEN];
1440Sstevel@tonic-gate extern int LOCAL_STATE;
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * Hash functions for monitor and record hash tables.
1480Sstevel@tonic-gate  * Functions are hashed based on first 2 letters and last 2 letters of name.
1490Sstevel@tonic-gate  * If only 1 letter in name, then, hash only on 1 letter.
1500Sstevel@tonic-gate  */
1510Sstevel@tonic-gate #define	SMHASH(name, key) { \
1520Sstevel@tonic-gate 	int l; \
1530Sstevel@tonic-gate 	key = *name; \
1540Sstevel@tonic-gate 	if ((l = strlen(name)) != 1) \
1550Sstevel@tonic-gate 		key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \
1560Sstevel@tonic-gate 			(*(name+(l-2)) << 8)); \
1570Sstevel@tonic-gate 	key = key % MAX_HASHSIZE; \
1580Sstevel@tonic-gate }
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate extern int debug;		/* Prints out debug information if set. */
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate extern char hostname[MAXHOSTNAMELEN];
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate  * These variables will be used to store all the
1660Sstevel@tonic-gate  * alias names for the host, as well as the -a
1670Sstevel@tonic-gate  * command line hostnames.
1680Sstevel@tonic-gate  */
1690Sstevel@tonic-gate extern char **host_name; /* store -a opts */
1700Sstevel@tonic-gate extern int	host_name_count;
1710Sstevel@tonic-gate extern int  addrix; /* # of -a entries */
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate  * The following 2 variables are meaningful
1750Sstevel@tonic-gate  * only under a HA configuration.
1760Sstevel@tonic-gate  */
1770Sstevel@tonic-gate extern char **path_name; /* store -p opts */
1780Sstevel@tonic-gate extern int  pathix; /* # of -p entries */
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate /* Function prototypes used in program */
1810Sstevel@tonic-gate extern int	create_file(char *name);
1820Sstevel@tonic-gate extern void	delete_file(char *name);
1830Sstevel@tonic-gate extern void	record_name(char *name, int op);
1840Sstevel@tonic-gate extern void	sm_crash(void);
1850Sstevel@tonic-gate extern void	sm_notify(stat_chge *ntfp);
1860Sstevel@tonic-gate extern void	statd_init();
1870Sstevel@tonic-gate extern void	merge_hosts(void);
188*1Sgt29601 extern CLIENT	*create_client(char *, int, int, struct timeval *);
1890Sstevel@tonic-gate extern char	*xmalloc(unsigned);
1900Sstevel@tonic-gate extern void	sm_status(sm_name *namep, sm_stat_res *resp);
1910Sstevel@tonic-gate extern void	sm_mon(mon *monp, sm_stat_res *resp);
1920Sstevel@tonic-gate extern void	sm_unmon(mon_id *monidp, sm_stat *resp);
1930Sstevel@tonic-gate extern void	sm_unmon_all(my_id *myidp, sm_stat *resp);
1940Sstevel@tonic-gate extern void	sm_simu_crash(void *myidp);
1950Sstevel@tonic-gate extern void	sm_inithash();
1960Sstevel@tonic-gate extern void	copydir_from_to(char *from_dir, char *to_dir);
1970Sstevel@tonic-gate extern int	str_cmp_unqual_hostname(char *, char *);
1980Sstevel@tonic-gate extern void	nsmaddrproc1_reg(reg1args *, reg1res *);
1990Sstevel@tonic-gate extern void	record_addr(char *name, sa_family_t family, struct netobj *ah);
2000Sstevel@tonic-gate extern int	is_symlink(char *file);
2010Sstevel@tonic-gate extern int	create_symlink(char *todir, char *rname, char *lname);
2020Sstevel@tonic-gate extern int	str_cmp_address_specifier(char *specifier1, char *specifier2);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate #ifdef __cplusplus
2050Sstevel@tonic-gate }
2060Sstevel@tonic-gate #endif
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate #endif /* _SM_STATD_H */
209