17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23a6f0fae9Sgt29601 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate /* 317c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 327c478bd9Sstevel@tonic-gate * The Regents of the University of California 337c478bd9Sstevel@tonic-gate * All Rights Reserved 347c478bd9Sstevel@tonic-gate * 357c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 367c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 377c478bd9Sstevel@tonic-gate * contributors. 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 40*bbaa8b60SDan Kruchinin /* 41*bbaa8b60SDan Kruchinin * Copyright 2011 Nexenta Systems, Inc. All rights reserved. 42*bbaa8b60SDan Kruchinin * Copyright (c) 2012 by Delphix. All rights reserved. 43*bbaa8b60SDan Kruchinin */ 44*bbaa8b60SDan Kruchinin 457c478bd9Sstevel@tonic-gate #ifndef _SM_STATD_H 467c478bd9Sstevel@tonic-gate #define _SM_STATD_H 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef __cplusplus 497c478bd9Sstevel@tonic-gate extern "C" { 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* Limit defines */ 537c478bd9Sstevel@tonic-gate #define SM_DIRECTORY_MODE 00755 547c478bd9Sstevel@tonic-gate #define MAX_HASHSIZE 50 557c478bd9Sstevel@tonic-gate #define SM_RPC_TIMEOUT 15 567c478bd9Sstevel@tonic-gate #define PERCENT_MINJOIN 10 577c478bd9Sstevel@tonic-gate #define MAX_FDS 256 587c478bd9Sstevel@tonic-gate #define MAX_THR 25 597c478bd9Sstevel@tonic-gate #define INC_DELAYTIME 30 607c478bd9Sstevel@tonic-gate #define MAX_DELAYTIME 300 617c478bd9Sstevel@tonic-gate #define SM_CLTS_TIMEOUT 15 627c478bd9Sstevel@tonic-gate /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */ 637c478bd9Sstevel@tonic-gate #define SM_MAXPATHLEN 17 647c478bd9Sstevel@tonic-gate /* Increment size for realloc of array host_name */ 657c478bd9Sstevel@tonic-gate #define HOST_NAME_INCR 5 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* supported address family names in /var/statmon symlinks */ 687c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV4 "ipv4" 697c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV6 "ipv6" 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* Supported for readdir_r() */ 727c478bd9Sstevel@tonic-gate #define MAXDIRENT (sizeof (struct dirent) + _POSIX_PATH_MAX + 1) 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* Structure entry for monitor table (mon_table) */ 757c478bd9Sstevel@tonic-gate struct mon_entry { 767c478bd9Sstevel@tonic-gate mon id; /* mon information: mon_name, my_id */ 777c478bd9Sstevel@tonic-gate struct mon_entry *prev; /* Prev ptr to prev entry in hash */ 787c478bd9Sstevel@tonic-gate struct mon_entry *nxt; /* Next ptr to next entry in hash */ 797c478bd9Sstevel@tonic-gate }; 807c478bd9Sstevel@tonic-gate typedef struct mon_entry mon_entry; 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* Structure entry for record (rec_table) and recovery (recov_q) tables */ 837c478bd9Sstevel@tonic-gate struct name_entry { 847c478bd9Sstevel@tonic-gate char *name; /* name of host */ 857c478bd9Sstevel@tonic-gate int count; /* count of entries */ 867c478bd9Sstevel@tonic-gate struct name_entry *prev; /* Prev ptr to prev entry in hash */ 877c478bd9Sstevel@tonic-gate struct name_entry *nxt; /* Next ptr to next entry in hash */ 887c478bd9Sstevel@tonic-gate }; 897c478bd9Sstevel@tonic-gate typedef struct name_entry name_entry; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* Structure for passing arguments into thread send_notice */ 927c478bd9Sstevel@tonic-gate typedef struct moninfo { 937c478bd9Sstevel@tonic-gate mon id; /* Monitor information */ 947c478bd9Sstevel@tonic-gate int state; /* Current state */ 957c478bd9Sstevel@tonic-gate } moninfo_t; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* Structure entry for hash tables */ 987c478bd9Sstevel@tonic-gate typedef struct sm_hash { 997c478bd9Sstevel@tonic-gate union { 1007c478bd9Sstevel@tonic-gate struct mon_entry *mon_hdptr; /* Head ptr for mon_table */ 1017c478bd9Sstevel@tonic-gate name_entry *rec_hdptr; /* Head ptr for rec_table */ 1027c478bd9Sstevel@tonic-gate name_entry *recov_hdptr; /* Head ptr for recov_q */ 1037c478bd9Sstevel@tonic-gate } smhd_t; 1047c478bd9Sstevel@tonic-gate mutex_t lock; /* Lock to protect each list head */ 1057c478bd9Sstevel@tonic-gate } sm_hash_t; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate #define sm_monhdp smhd_t.mon_hdptr 1087c478bd9Sstevel@tonic-gate #define sm_rechdp smhd_t.rec_hdptr 1097c478bd9Sstevel@tonic-gate #define sm_recovhdp smhd_t.recov_hdptr 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* Structure entry for address list in name-to-address entry */ 1127c478bd9Sstevel@tonic-gate typedef struct addr_entry { 1137c478bd9Sstevel@tonic-gate struct addr_entry *next; 1147c478bd9Sstevel@tonic-gate struct netobj ah; 1157c478bd9Sstevel@tonic-gate sa_family_t family; 1167c478bd9Sstevel@tonic-gate } addr_entry_t; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* Structure entry for name-to-address translation table */ 1197c478bd9Sstevel@tonic-gate typedef struct name_addr_entry { 1207c478bd9Sstevel@tonic-gate struct name_addr_entry *next; 1217c478bd9Sstevel@tonic-gate char *name; 1227c478bd9Sstevel@tonic-gate struct addr_entry *addresses; 1237c478bd9Sstevel@tonic-gate } name_addr_entry_t; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* Hash tables for each of the in-cache information */ 1267c478bd9Sstevel@tonic-gate extern sm_hash_t mon_table[MAX_HASHSIZE]; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* Global variables */ 1297c478bd9Sstevel@tonic-gate extern mutex_t crash_lock; /* lock for die and crash variables */ 1307c478bd9Sstevel@tonic-gate extern int die; /* Flag to indicate that an SM_CRASH */ 1317c478bd9Sstevel@tonic-gate /* request came in & to stop threads cleanly */ 1327c478bd9Sstevel@tonic-gate extern int in_crash; /* Flag to single thread sm_crash requests. */ 1337c478bd9Sstevel@tonic-gate extern int regfiles_only; /* Flag to indicate symlink use in statmon */ 1347c478bd9Sstevel@tonic-gate extern cond_t crash_finish; /* Condition to wait until crash is finished */ 1357c478bd9Sstevel@tonic-gate extern mutex_t sm_trylock; /* Lock to single thread sm_try */ 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * The only established lock precedence here is: 1387c478bd9Sstevel@tonic-gate * 1397c478bd9Sstevel@tonic-gate * thr_rwlock > name_addrlock 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate extern mutex_t name_addrlock; /* Locks all entries of name-to-addr table */ 1427c478bd9Sstevel@tonic-gate extern rwlock_t thr_rwlock; /* Reader/writer lock for requests coming in */ 1437c478bd9Sstevel@tonic-gate extern cond_t retrywait; /* Condition to wait before starting retry */ 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN]; 1467c478bd9Sstevel@tonic-gate extern char BACKUP[MAXPATHLEN]; 1477c478bd9Sstevel@tonic-gate extern int LOCAL_STATE; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Hash functions for monitor and record hash tables. 1517c478bd9Sstevel@tonic-gate * Functions are hashed based on first 2 letters and last 2 letters of name. 1527c478bd9Sstevel@tonic-gate * If only 1 letter in name, then, hash only on 1 letter. 1537c478bd9Sstevel@tonic-gate */ 1547c478bd9Sstevel@tonic-gate #define SMHASH(name, key) { \ 1557c478bd9Sstevel@tonic-gate int l; \ 1567c478bd9Sstevel@tonic-gate key = *name; \ 1577c478bd9Sstevel@tonic-gate if ((l = strlen(name)) != 1) \ 1587c478bd9Sstevel@tonic-gate key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \ 1597c478bd9Sstevel@tonic-gate (*(name+(l-2)) << 8)); \ 1607c478bd9Sstevel@tonic-gate key = key % MAX_HASHSIZE; \ 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate extern int debug; /* Prints out debug information if set. */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate extern char hostname[MAXHOSTNAMELEN]; 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * These variables will be used to store all the 1697c478bd9Sstevel@tonic-gate * alias names for the host, as well as the -a 1707c478bd9Sstevel@tonic-gate * command line hostnames. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate extern char **host_name; /* store -a opts */ 1737c478bd9Sstevel@tonic-gate extern int host_name_count; 1747c478bd9Sstevel@tonic-gate extern int addrix; /* # of -a entries */ 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate /* 1777c478bd9Sstevel@tonic-gate * The following 2 variables are meaningful 1787c478bd9Sstevel@tonic-gate * only under a HA configuration. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate extern char **path_name; /* store -p opts */ 1817c478bd9Sstevel@tonic-gate extern int pathix; /* # of -p entries */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate /* Function prototypes used in program */ 1847c478bd9Sstevel@tonic-gate extern int create_file(char *name); 1857c478bd9Sstevel@tonic-gate extern void delete_file(char *name); 1867c478bd9Sstevel@tonic-gate extern void record_name(char *name, int op); 1877c478bd9Sstevel@tonic-gate extern void sm_crash(void); 1887c478bd9Sstevel@tonic-gate extern void statd_init(); 1897c478bd9Sstevel@tonic-gate extern void merge_hosts(void); 190*bbaa8b60SDan Kruchinin extern void merge_ips(void); 191*bbaa8b60SDan Kruchinin extern CLIENT *create_client(char *, int, int, char *, struct timeval *); 1927c478bd9Sstevel@tonic-gate extern char *xmalloc(unsigned); 193*bbaa8b60SDan Kruchinin 194*bbaa8b60SDan Kruchinin /* 195*bbaa8b60SDan Kruchinin * RPC service functions, slightly different here than the 196*bbaa8b60SDan Kruchinin * generated ones in sm_inter.h 197*bbaa8b60SDan Kruchinin */ 198*bbaa8b60SDan Kruchinin extern void nsmaddrproc1_reg(reg1args *, reg1res *); 199*bbaa8b60SDan Kruchinin extern void sm_stat_svc(sm_name *namep, sm_stat_res *resp); 200*bbaa8b60SDan Kruchinin extern void sm_mon_svc(mon *monp, sm_stat_res *resp); 201*bbaa8b60SDan Kruchinin extern void sm_unmon_svc(mon_id *monidp, sm_stat *resp); 202*bbaa8b60SDan Kruchinin extern void sm_unmon_all_svc(my_id *myidp, sm_stat *resp); 203*bbaa8b60SDan Kruchinin extern void sm_simu_crash_svc(void *myidp); 204*bbaa8b60SDan Kruchinin extern void sm_notify_svc(stat_chge *ntfp); 205*bbaa8b60SDan Kruchinin 2067c478bd9Sstevel@tonic-gate extern void sm_inithash(); 2077c478bd9Sstevel@tonic-gate extern void copydir_from_to(char *from_dir, char *to_dir); 2087c478bd9Sstevel@tonic-gate extern int str_cmp_unqual_hostname(char *, char *); 2097c478bd9Sstevel@tonic-gate extern void record_addr(char *name, sa_family_t family, struct netobj *ah); 2107c478bd9Sstevel@tonic-gate extern int is_symlink(char *file); 2117c478bd9Sstevel@tonic-gate extern int create_symlink(char *todir, char *rname, char *lname); 2127c478bd9Sstevel@tonic-gate extern int str_cmp_address_specifier(char *specifier1, char *specifier2); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate #endif 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate #endif /* _SM_STATD_H */ 219