xref: /illumos-gate/usr/src/cmd/fs.d/nfs/statd/sm_statd.h (revision 064d16273d15bf6b8ef164ed9d00a767e2fcd0ed)
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 /*
24  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
25  */
26 
27 /*
28  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
29  * Use is subject to license terms.
30  */
31 
32 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
33 /*	  All Rights Reserved	*/
34 
35 /*
36  * University Copyright- Copyright (c) 1982, 1986, 1988
37  * The Regents of the University of California
38  * All Rights Reserved
39  *
40  * University Acknowledgment- Portions of this document are derived from
41  * software developed by the University of California, Berkeley, and its
42  * contributors.
43  */
44 
45 /*
46  * Copyright (c) 2012 by Delphix. All rights reserved.
47  */
48 
49 #ifndef	_SM_STATD_H
50 #define	_SM_STATD_H
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /* Limit defines */
57 #define	SM_DIRECTORY_MODE 00755
58 #define	MAX_HASHSIZE 50
59 #define	SM_RPC_TIMEOUT	15
60 #define	PERCENT_MINJOIN 10
61 #define	MAX_FDS	256
62 #define	MAX_THR	25
63 #define	INC_DELAYTIME	30
64 #define	MAX_DELAYTIME	300
65 #define	SM_CLTS_TIMEOUT	15
66 /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */
67 #define	SM_MAXPATHLEN	17
68 /* Increment size for realloc of array host_name */
69 #define	HOST_NAME_INCR  5
70 
71 /* supported address family names in /var/statmon symlinks */
72 #define	SM_ADDR_IPV4	"ipv4"
73 #define	SM_ADDR_IPV6	"ipv6"
74 
75 /* Supported for readdir_r() */
76 #define	MAXDIRENT	(sizeof (struct dirent) +  _POSIX_PATH_MAX + 1)
77 
78 /* Structure entry for monitor table (mon_table) */
79 struct mon_entry {
80 	mon id;				/* mon information: mon_name, my_id */
81 	struct mon_entry *prev;		/* Prev ptr to prev entry in hash */
82 	struct mon_entry *nxt;		/* Next ptr to next entry in hash */
83 };
84 typedef struct mon_entry mon_entry;
85 
86 /* Structure entry for record (record_table) and recovery (recov_q) tables */
87 struct name_entry {
88 	char *name;			/* name of host */
89 	int count;			/* count of entries */
90 	struct name_entry *prev;	/* Prev ptr to prev entry in hash */
91 	struct name_entry *nxt;		/* Next ptr to next entry in hash */
92 };
93 typedef struct name_entry name_entry;
94 
95 /* Structure for passing arguments into thread send_notice */
96 typedef struct moninfo {
97 	mon id;				/* Monitor information */
98 	int state;			/* Current state */
99 } moninfo_t;
100 
101 /* Structure entry for hash tables */
102 typedef struct sm_hash {
103 	union {
104 		struct mon_entry *mon_hdptr;	/* Head ptr for mon_table */
105 		name_entry *rec_hdptr;		/* Head ptr for record_table */
106 		name_entry *recov_hdptr;	/* Head ptr for recov_q */
107 	} smhd_t;
108 	mutex_t	lock;			/* Lock to protect each list head */
109 } sm_hash_t;
110 
111 #define	sm_monhdp	smhd_t.mon_hdptr
112 #define	sm_rechdp	smhd_t.rec_hdptr
113 #define	sm_recovhdp	smhd_t.recov_hdptr
114 
115 /* Structure entry for address list in name-to-address entry */
116 typedef struct addr_entry {
117 	struct addr_entry *next;
118 	struct netobj ah;
119 	sa_family_t family;
120 } addr_entry_t;
121 
122 /* Structure entry for name-to-address translation table */
123 typedef struct name_addr_entry {
124 	struct name_addr_entry *next;
125 	char *name;
126 	struct addr_entry *addresses;
127 } name_addr_entry_t;
128 
129 /* Hash tables for each of the in-cache information */
130 extern sm_hash_t	mon_table[MAX_HASHSIZE];
131 
132 /* Global variables */
133 extern mutex_t crash_lock;	/* lock for die and crash variables */
134 extern int die;			/* Flag to indicate that an SM_CRASH */
135 				/* request came in & to stop threads cleanly */
136 extern int in_crash;		/* Flag to single thread sm_crash requests. */
137 extern int regfiles_only;	/* Flag to indicate symlink use in statmon */
138 extern mutex_t sm_trylock;	/* Lock to single thread sm_try */
139 /*
140  * The only established lock precedence here is:
141  *
142  *	thr_rwlock > name_addrlock
143  */
144 extern mutex_t name_addrlock;	/* Locks all entries of name-to-addr table */
145 extern rwlock_t thr_rwlock;	/* Reader/writer lock for requests coming in */
146 extern cond_t retrywait;	/* Condition to wait before starting retry */
147 
148 extern boolean_t in_merges;	/* Flag to indicate the host_name is not */
149 				/* populated yet */
150 extern mutex_t merges_lock;	/* Lock for in_merges variable */
151 extern cond_t merges_cond;	/* Condition variable for in_merges */
152 
153 extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN];
154 extern char BACKUP[MAXPATHLEN];
155 extern int LOCAL_STATE;
156 
157 /*
158  * Hash functions for monitor and record hash tables.
159  * Functions are hashed based on first 2 letters and last 2 letters of name.
160  * If only 1 letter in name, then, hash only on 1 letter.
161  */
162 #define	SMHASH(name, key) { \
163 	int l; \
164 	key = *name; \
165 	if ((l = strlen(name)) != 1) \
166 		key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \
167 			(*(name+(l-2)) << 8)); \
168 	key = key % MAX_HASHSIZE; \
169 }
170 
171 extern int debug;		/* Prints out debug information if set. */
172 
173 extern char hostname[MAXHOSTNAMELEN];
174 
175 /*
176  * These variables will be used to store all the
177  * alias names for the host, as well as the -a
178  * command line hostnames.
179  */
180 extern char **host_name; /* store -a opts */
181 extern int	host_name_count;
182 extern int  addrix; /* # of -a entries */
183 
184 /*
185  * The following 2 variables are meaningful
186  * only under a HA configuration.
187  */
188 extern char **path_name; /* store -p opts */
189 extern int  pathix; /* # of -p entries */
190 
191 /* Function prototypes used in program */
192 extern int	create_file(char *name);
193 extern void	delete_file(char *name);
194 extern void	record_name(char *name, int op);
195 extern void	sm_crash(void);
196 extern void	statd_init(void);
197 extern void	merge_hosts(void);
198 extern void	merge_ips(void);
199 extern CLIENT	*create_client(char *, int, int, char *, struct timeval *);
200 extern char	*xmalloc(unsigned);
201 
202 /*
203  * RPC service functions, slightly different here than the
204  * generated ones in sm_inter.h
205  */
206 extern void	nsmaddrproc1_reg(void *, void *);
207 extern void	sm_stat_svc(void *, void *);
208 extern void	sm_mon_svc(void *, void *);
209 extern void	sm_unmon_svc(void *, void *);
210 extern void	sm_unmon_all_svc(void *, void *);
211 extern void	sm_simu_crash_svc(void *, void *);
212 extern void	sm_notify_svc(void *, void *);
213 
214 extern void	sm_inithash(void);
215 extern void	copydir_from_to(char *from_dir, char *to_dir);
216 extern int	str_cmp_unqual_hostname(char *, char *);
217 extern void	record_addr(char *name, sa_family_t family, struct netobj *ah);
218 extern int	is_symlink(char *file);
219 extern int	create_symlink(char *todir, char *rname, char *lname);
220 extern int	str_cmp_address_specifier(char *specifier1, char *specifier2);
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* _SM_STATD_H */
227