xref: /onnv-gate/usr/src/cmd/fs.d/nfs/statd/sm_statd.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate /*
31*0Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*0Sstevel@tonic-gate  * The Regents of the University of California
33*0Sstevel@tonic-gate  * All Rights Reserved
34*0Sstevel@tonic-gate  *
35*0Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*0Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*0Sstevel@tonic-gate  * contributors.
38*0Sstevel@tonic-gate  */
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate #ifndef	_SM_STATD_H
41*0Sstevel@tonic-gate #define	_SM_STATD_H
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate #ifdef __cplusplus
46*0Sstevel@tonic-gate extern "C" {
47*0Sstevel@tonic-gate #endif
48*0Sstevel@tonic-gate 
49*0Sstevel@tonic-gate /* Limit defines */
50*0Sstevel@tonic-gate #define	SM_DIRECTORY_MODE 00755
51*0Sstevel@tonic-gate #define	MAX_HASHSIZE 50
52*0Sstevel@tonic-gate #define	SM_RPC_TIMEOUT	15
53*0Sstevel@tonic-gate #define	PERCENT_MINJOIN 10
54*0Sstevel@tonic-gate #define	MAX_FDS	256
55*0Sstevel@tonic-gate #define	MAX_THR	25
56*0Sstevel@tonic-gate #define	INC_DELAYTIME	30
57*0Sstevel@tonic-gate #define	MAX_DELAYTIME	300
58*0Sstevel@tonic-gate #define	SM_CLTS_TIMEOUT	15
59*0Sstevel@tonic-gate /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */
60*0Sstevel@tonic-gate #define	SM_MAXPATHLEN	17
61*0Sstevel@tonic-gate /* Increment size for realloc of array host_name */
62*0Sstevel@tonic-gate #define	HOST_NAME_INCR  5
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate /* supported address family names in /var/statmon symlinks */
65*0Sstevel@tonic-gate #define	SM_ADDR_IPV4	"ipv4"
66*0Sstevel@tonic-gate #define	SM_ADDR_IPV6	"ipv6"
67*0Sstevel@tonic-gate 
68*0Sstevel@tonic-gate /* Supported for readdir_r() */
69*0Sstevel@tonic-gate #define MAXDIRENT	(sizeof (struct dirent) +  _POSIX_PATH_MAX + 1)
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate /* Structure entry for monitor table (mon_table) */
72*0Sstevel@tonic-gate struct mon_entry {
73*0Sstevel@tonic-gate 	mon id;				/* mon information: mon_name, my_id */
74*0Sstevel@tonic-gate 	struct mon_entry *prev;		/* Prev ptr to prev entry in hash */
75*0Sstevel@tonic-gate 	struct mon_entry *nxt;		/* Next ptr to next entry in hash */
76*0Sstevel@tonic-gate };
77*0Sstevel@tonic-gate typedef struct mon_entry mon_entry;
78*0Sstevel@tonic-gate 
79*0Sstevel@tonic-gate /* Structure entry for record (rec_table) and recovery (recov_q) tables */
80*0Sstevel@tonic-gate struct name_entry {
81*0Sstevel@tonic-gate 	char *name;			/* name of host */
82*0Sstevel@tonic-gate 	int count;			/* count of entries */
83*0Sstevel@tonic-gate 	struct name_entry *prev;	/* Prev ptr to prev entry in hash */
84*0Sstevel@tonic-gate 	struct name_entry *nxt;		/* Next ptr to next entry in hash */
85*0Sstevel@tonic-gate };
86*0Sstevel@tonic-gate typedef struct name_entry name_entry;
87*0Sstevel@tonic-gate 
88*0Sstevel@tonic-gate /* Structure for passing arguments into thread send_notice */
89*0Sstevel@tonic-gate typedef struct moninfo {
90*0Sstevel@tonic-gate 	mon id;				/* Monitor information */
91*0Sstevel@tonic-gate 	int state;			/* Current state */
92*0Sstevel@tonic-gate } moninfo_t;
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate /* Structure entry for hash tables */
95*0Sstevel@tonic-gate typedef struct sm_hash {
96*0Sstevel@tonic-gate 	union {
97*0Sstevel@tonic-gate 		struct mon_entry *mon_hdptr;	/* Head ptr for mon_table */
98*0Sstevel@tonic-gate 		name_entry *rec_hdptr;		/* Head ptr for rec_table */
99*0Sstevel@tonic-gate 		name_entry *recov_hdptr;	/* Head ptr for recov_q */
100*0Sstevel@tonic-gate 	} smhd_t;
101*0Sstevel@tonic-gate 	mutex_t	lock;			/* Lock to protect each list head */
102*0Sstevel@tonic-gate } sm_hash_t;
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate #define	sm_monhdp	smhd_t.mon_hdptr
105*0Sstevel@tonic-gate #define	sm_rechdp	smhd_t.rec_hdptr
106*0Sstevel@tonic-gate #define	sm_recovhdp	smhd_t.recov_hdptr
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate /* Structure entry for address list in name-to-address entry */
109*0Sstevel@tonic-gate typedef struct addr_entry {
110*0Sstevel@tonic-gate 	struct addr_entry *next;
111*0Sstevel@tonic-gate 	struct netobj ah;
112*0Sstevel@tonic-gate 	sa_family_t family;
113*0Sstevel@tonic-gate } addr_entry_t;
114*0Sstevel@tonic-gate 
115*0Sstevel@tonic-gate /* Structure entry for name-to-address translation table */
116*0Sstevel@tonic-gate typedef struct name_addr_entry {
117*0Sstevel@tonic-gate 	struct name_addr_entry *next;
118*0Sstevel@tonic-gate 	char *name;
119*0Sstevel@tonic-gate 	struct addr_entry *addresses;
120*0Sstevel@tonic-gate } name_addr_entry_t;
121*0Sstevel@tonic-gate 
122*0Sstevel@tonic-gate /* Hash tables for each of the in-cache information */
123*0Sstevel@tonic-gate extern sm_hash_t	mon_table[MAX_HASHSIZE];
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /* Global variables */
126*0Sstevel@tonic-gate extern mutex_t crash_lock;	/* lock for die and crash variables */
127*0Sstevel@tonic-gate extern int die;			/* Flag to indicate that an SM_CRASH */
128*0Sstevel@tonic-gate 				/* request came in & to stop threads cleanly */
129*0Sstevel@tonic-gate extern int in_crash;		/* Flag to single thread sm_crash requests. */
130*0Sstevel@tonic-gate extern int regfiles_only;	/* Flag to indicate symlink use in statmon */
131*0Sstevel@tonic-gate extern cond_t crash_finish;	/* Condition to wait until crash is finished */
132*0Sstevel@tonic-gate extern mutex_t sm_trylock;	/* Lock to single thread sm_try */
133*0Sstevel@tonic-gate /*
134*0Sstevel@tonic-gate  * The only established lock precedence here is:
135*0Sstevel@tonic-gate  *
136*0Sstevel@tonic-gate  *	thr_rwlock > name_addrlock
137*0Sstevel@tonic-gate  */
138*0Sstevel@tonic-gate extern mutex_t name_addrlock;	/* Locks all entries of name-to-addr table */
139*0Sstevel@tonic-gate extern rwlock_t thr_rwlock;	/* Reader/writer lock for requests coming in */
140*0Sstevel@tonic-gate extern cond_t retrywait;	/* Condition to wait before starting retry */
141*0Sstevel@tonic-gate 
142*0Sstevel@tonic-gate extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN];
143*0Sstevel@tonic-gate extern char BACKUP[MAXPATHLEN];
144*0Sstevel@tonic-gate extern int LOCAL_STATE;
145*0Sstevel@tonic-gate 
146*0Sstevel@tonic-gate /*
147*0Sstevel@tonic-gate  * Hash functions for monitor and record hash tables.
148*0Sstevel@tonic-gate  * Functions are hashed based on first 2 letters and last 2 letters of name.
149*0Sstevel@tonic-gate  * If only 1 letter in name, then, hash only on 1 letter.
150*0Sstevel@tonic-gate  */
151*0Sstevel@tonic-gate #define	SMHASH(name, key) { \
152*0Sstevel@tonic-gate 	int l; \
153*0Sstevel@tonic-gate 	key = *name; \
154*0Sstevel@tonic-gate 	if ((l = strlen(name)) != 1) \
155*0Sstevel@tonic-gate 		key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \
156*0Sstevel@tonic-gate 			(*(name+(l-2)) << 8)); \
157*0Sstevel@tonic-gate 	key = key % MAX_HASHSIZE; \
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate extern int debug;		/* Prints out debug information if set. */
161*0Sstevel@tonic-gate 
162*0Sstevel@tonic-gate extern char hostname[MAXHOSTNAMELEN];
163*0Sstevel@tonic-gate 
164*0Sstevel@tonic-gate /*
165*0Sstevel@tonic-gate  * These variables will be used to store all the
166*0Sstevel@tonic-gate  * alias names for the host, as well as the -a
167*0Sstevel@tonic-gate  * command line hostnames.
168*0Sstevel@tonic-gate  */
169*0Sstevel@tonic-gate extern char **host_name; /* store -a opts */
170*0Sstevel@tonic-gate extern int	host_name_count;
171*0Sstevel@tonic-gate extern int  addrix; /* # of -a entries */
172*0Sstevel@tonic-gate 
173*0Sstevel@tonic-gate /*
174*0Sstevel@tonic-gate  * The following 2 variables are meaningful
175*0Sstevel@tonic-gate  * only under a HA configuration.
176*0Sstevel@tonic-gate  */
177*0Sstevel@tonic-gate extern char **path_name; /* store -p opts */
178*0Sstevel@tonic-gate extern int  pathix; /* # of -p entries */
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate /* Function prototypes used in program */
181*0Sstevel@tonic-gate extern int	create_file(char *name);
182*0Sstevel@tonic-gate extern void	delete_file(char *name);
183*0Sstevel@tonic-gate extern void	record_name(char *name, int op);
184*0Sstevel@tonic-gate extern void	sm_crash(void);
185*0Sstevel@tonic-gate extern void	sm_notify(stat_chge *ntfp);
186*0Sstevel@tonic-gate extern void	statd_init();
187*0Sstevel@tonic-gate extern void	merge_hosts(void);
188*0Sstevel@tonic-gate extern CLIENT	*create_client(char *host, int prognum, int versnum);
189*0Sstevel@tonic-gate extern char	*xmalloc(unsigned);
190*0Sstevel@tonic-gate extern void	sm_status(sm_name *namep, sm_stat_res *resp);
191*0Sstevel@tonic-gate extern void	sm_mon(mon *monp, sm_stat_res *resp);
192*0Sstevel@tonic-gate extern void	sm_unmon(mon_id *monidp, sm_stat *resp);
193*0Sstevel@tonic-gate extern void	sm_unmon_all(my_id *myidp, sm_stat *resp);
194*0Sstevel@tonic-gate extern void	sm_simu_crash(void *myidp);
195*0Sstevel@tonic-gate extern void	sm_inithash();
196*0Sstevel@tonic-gate extern void	copydir_from_to(char *from_dir, char *to_dir);
197*0Sstevel@tonic-gate extern int	str_cmp_unqual_hostname(char *, char *);
198*0Sstevel@tonic-gate extern void	nsmaddrproc1_reg(reg1args *, reg1res *);
199*0Sstevel@tonic-gate extern void	record_addr(char *name, sa_family_t family, struct netobj *ah);
200*0Sstevel@tonic-gate extern int	is_symlink(char *file);
201*0Sstevel@tonic-gate extern int	create_symlink(char *todir, char *rname, char *lname);
202*0Sstevel@tonic-gate extern int	str_cmp_address_specifier(char *specifier1, char *specifier2);
203*0Sstevel@tonic-gate 
204*0Sstevel@tonic-gate #ifdef __cplusplus
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate #endif
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate #endif /* _SM_STATD_H */
209