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