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