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 */ 2298573c19SMarcel Telka 2398573c19SMarcel Telka /* 2498573c19SMarcel Telka * Copyright 2015 Nexenta Systems, Inc. All rights reserved. 2598573c19SMarcel Telka */ 2698573c19SMarcel Telka 277c478bd9Sstevel@tonic-gate /* 28a6f0fae9Sgt * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 297c478bd9Sstevel@tonic-gate * Use is subject to license terms. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 33*064d1627SToomas Soome /* All Rights Reserved */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate /* 367c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 377c478bd9Sstevel@tonic-gate * The Regents of the University of California 387c478bd9Sstevel@tonic-gate * All Rights Reserved 397c478bd9Sstevel@tonic-gate * 407c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 417c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 427c478bd9Sstevel@tonic-gate * contributors. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate 45bbaa8b60SDan Kruchinin /* 46bbaa8b60SDan Kruchinin * Copyright (c) 2012 by Delphix. All rights reserved. 47bbaa8b60SDan Kruchinin */ 48bbaa8b60SDan Kruchinin 497c478bd9Sstevel@tonic-gate #ifndef _SM_STATD_H 507c478bd9Sstevel@tonic-gate #define _SM_STATD_H 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #ifdef __cplusplus 537c478bd9Sstevel@tonic-gate extern "C" { 547c478bd9Sstevel@tonic-gate #endif 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* Limit defines */ 577c478bd9Sstevel@tonic-gate #define SM_DIRECTORY_MODE 00755 587c478bd9Sstevel@tonic-gate #define MAX_HASHSIZE 50 597c478bd9Sstevel@tonic-gate #define SM_RPC_TIMEOUT 15 607c478bd9Sstevel@tonic-gate #define PERCENT_MINJOIN 10 617c478bd9Sstevel@tonic-gate #define MAX_FDS 256 627c478bd9Sstevel@tonic-gate #define MAX_THR 25 637c478bd9Sstevel@tonic-gate #define INC_DELAYTIME 30 647c478bd9Sstevel@tonic-gate #define MAX_DELAYTIME 300 657c478bd9Sstevel@tonic-gate #define SM_CLTS_TIMEOUT 15 667c478bd9Sstevel@tonic-gate /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */ 677c478bd9Sstevel@tonic-gate #define SM_MAXPATHLEN 17 687c478bd9Sstevel@tonic-gate /* Increment size for realloc of array host_name */ 697c478bd9Sstevel@tonic-gate #define HOST_NAME_INCR 5 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* supported address family names in /var/statmon symlinks */ 727c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV4 "ipv4" 737c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV6 "ipv6" 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* Supported for readdir_r() */ 76a6f0fae9Sgt #define MAXDIRENT (sizeof (struct dirent) + _POSIX_PATH_MAX + 1) 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate /* Structure entry for monitor table (mon_table) */ 797c478bd9Sstevel@tonic-gate struct mon_entry { 807c478bd9Sstevel@tonic-gate mon id; /* mon information: mon_name, my_id */ 817c478bd9Sstevel@tonic-gate struct mon_entry *prev; /* Prev ptr to prev entry in hash */ 827c478bd9Sstevel@tonic-gate struct mon_entry *nxt; /* Next ptr to next entry in hash */ 837c478bd9Sstevel@tonic-gate }; 847c478bd9Sstevel@tonic-gate typedef struct mon_entry mon_entry; 857c478bd9Sstevel@tonic-gate 8698573c19SMarcel Telka /* Structure entry for record (record_table) and recovery (recov_q) tables */ 877c478bd9Sstevel@tonic-gate struct name_entry { 887c478bd9Sstevel@tonic-gate char *name; /* name of host */ 897c478bd9Sstevel@tonic-gate int count; /* count of entries */ 907c478bd9Sstevel@tonic-gate struct name_entry *prev; /* Prev ptr to prev entry in hash */ 917c478bd9Sstevel@tonic-gate struct name_entry *nxt; /* Next ptr to next entry in hash */ 927c478bd9Sstevel@tonic-gate }; 937c478bd9Sstevel@tonic-gate typedef struct name_entry name_entry; 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* Structure for passing arguments into thread send_notice */ 967c478bd9Sstevel@tonic-gate typedef struct moninfo { 977c478bd9Sstevel@tonic-gate mon id; /* Monitor information */ 987c478bd9Sstevel@tonic-gate int state; /* Current state */ 997c478bd9Sstevel@tonic-gate } moninfo_t; 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* Structure entry for hash tables */ 1027c478bd9Sstevel@tonic-gate typedef struct sm_hash { 1037c478bd9Sstevel@tonic-gate union { 1047c478bd9Sstevel@tonic-gate struct mon_entry *mon_hdptr; /* Head ptr for mon_table */ 10598573c19SMarcel Telka name_entry *rec_hdptr; /* Head ptr for record_table */ 1067c478bd9Sstevel@tonic-gate name_entry *recov_hdptr; /* Head ptr for recov_q */ 1077c478bd9Sstevel@tonic-gate } smhd_t; 1087c478bd9Sstevel@tonic-gate mutex_t lock; /* Lock to protect each list head */ 1097c478bd9Sstevel@tonic-gate } sm_hash_t; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define sm_monhdp smhd_t.mon_hdptr 1127c478bd9Sstevel@tonic-gate #define sm_rechdp smhd_t.rec_hdptr 1137c478bd9Sstevel@tonic-gate #define sm_recovhdp smhd_t.recov_hdptr 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* Structure entry for address list in name-to-address entry */ 1167c478bd9Sstevel@tonic-gate typedef struct addr_entry { 1177c478bd9Sstevel@tonic-gate struct addr_entry *next; 1187c478bd9Sstevel@tonic-gate struct netobj ah; 1197c478bd9Sstevel@tonic-gate sa_family_t family; 1207c478bd9Sstevel@tonic-gate } addr_entry_t; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* Structure entry for name-to-address translation table */ 1237c478bd9Sstevel@tonic-gate typedef struct name_addr_entry { 1247c478bd9Sstevel@tonic-gate struct name_addr_entry *next; 1257c478bd9Sstevel@tonic-gate char *name; 1267c478bd9Sstevel@tonic-gate struct addr_entry *addresses; 1277c478bd9Sstevel@tonic-gate } name_addr_entry_t; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* Hash tables for each of the in-cache information */ 1307c478bd9Sstevel@tonic-gate extern sm_hash_t mon_table[MAX_HASHSIZE]; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* Global variables */ 1337c478bd9Sstevel@tonic-gate extern mutex_t crash_lock; /* lock for die and crash variables */ 1347c478bd9Sstevel@tonic-gate extern int die; /* Flag to indicate that an SM_CRASH */ 1357c478bd9Sstevel@tonic-gate /* request came in & to stop threads cleanly */ 1367c478bd9Sstevel@tonic-gate extern int in_crash; /* Flag to single thread sm_crash requests. */ 1377c478bd9Sstevel@tonic-gate extern int regfiles_only; /* Flag to indicate symlink use in statmon */ 1387c478bd9Sstevel@tonic-gate extern mutex_t sm_trylock; /* Lock to single thread sm_try */ 1397c478bd9Sstevel@tonic-gate /* 1407c478bd9Sstevel@tonic-gate * The only established lock precedence here is: 1417c478bd9Sstevel@tonic-gate * 1427c478bd9Sstevel@tonic-gate * thr_rwlock > name_addrlock 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate extern mutex_t name_addrlock; /* Locks all entries of name-to-addr table */ 1457c478bd9Sstevel@tonic-gate extern rwlock_t thr_rwlock; /* Reader/writer lock for requests coming in */ 1467c478bd9Sstevel@tonic-gate extern cond_t retrywait; /* Condition to wait before starting retry */ 1477c478bd9Sstevel@tonic-gate 14898573c19SMarcel Telka extern boolean_t in_merges; /* Flag to indicate the host_name is not */ 14998573c19SMarcel Telka /* populated yet */ 15098573c19SMarcel Telka extern mutex_t merges_lock; /* Lock for in_merges variable */ 15198573c19SMarcel Telka extern cond_t merges_cond; /* Condition variable for in_merges */ 15298573c19SMarcel Telka 1537c478bd9Sstevel@tonic-gate extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN]; 1547c478bd9Sstevel@tonic-gate extern char BACKUP[MAXPATHLEN]; 1557c478bd9Sstevel@tonic-gate extern int LOCAL_STATE; 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * Hash functions for monitor and record hash tables. 1597c478bd9Sstevel@tonic-gate * Functions are hashed based on first 2 letters and last 2 letters of name. 1607c478bd9Sstevel@tonic-gate * If only 1 letter in name, then, hash only on 1 letter. 1617c478bd9Sstevel@tonic-gate */ 1627c478bd9Sstevel@tonic-gate #define SMHASH(name, key) { \ 1637c478bd9Sstevel@tonic-gate int l; \ 1647c478bd9Sstevel@tonic-gate key = *name; \ 1657c478bd9Sstevel@tonic-gate if ((l = strlen(name)) != 1) \ 1667c478bd9Sstevel@tonic-gate key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \ 1677c478bd9Sstevel@tonic-gate (*(name+(l-2)) << 8)); \ 1687c478bd9Sstevel@tonic-gate key = key % MAX_HASHSIZE; \ 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate extern int debug; /* Prints out debug information if set. */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate extern char hostname[MAXHOSTNAMELEN]; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate /* 1767c478bd9Sstevel@tonic-gate * These variables will be used to store all the 1777c478bd9Sstevel@tonic-gate * alias names for the host, as well as the -a 1787c478bd9Sstevel@tonic-gate * command line hostnames. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate extern char **host_name; /* store -a opts */ 1817c478bd9Sstevel@tonic-gate extern int host_name_count; 1827c478bd9Sstevel@tonic-gate extern int addrix; /* # of -a entries */ 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * The following 2 variables are meaningful 1867c478bd9Sstevel@tonic-gate * only under a HA configuration. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate extern char **path_name; /* store -p opts */ 1897c478bd9Sstevel@tonic-gate extern int pathix; /* # of -p entries */ 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* Function prototypes used in program */ 1927c478bd9Sstevel@tonic-gate extern int create_file(char *name); 1937c478bd9Sstevel@tonic-gate extern void delete_file(char *name); 1947c478bd9Sstevel@tonic-gate extern void record_name(char *name, int op); 1957c478bd9Sstevel@tonic-gate extern void sm_crash(void); 19698573c19SMarcel Telka extern void statd_init(void); 1977c478bd9Sstevel@tonic-gate extern void merge_hosts(void); 198bbaa8b60SDan Kruchinin extern void merge_ips(void); 199bbaa8b60SDan Kruchinin extern CLIENT *create_client(char *, int, int, char *, struct timeval *); 2007c478bd9Sstevel@tonic-gate extern char *xmalloc(unsigned); 201bbaa8b60SDan Kruchinin 202bbaa8b60SDan Kruchinin /* 203bbaa8b60SDan Kruchinin * RPC service functions, slightly different here than the 204bbaa8b60SDan Kruchinin * generated ones in sm_inter.h 205bbaa8b60SDan Kruchinin */ 206*064d1627SToomas Soome extern void nsmaddrproc1_reg(void *, void *); 207*064d1627SToomas Soome extern void sm_stat_svc(void *, void *); 208*064d1627SToomas Soome extern void sm_mon_svc(void *, void *); 209*064d1627SToomas Soome extern void sm_unmon_svc(void *, void *); 210*064d1627SToomas Soome extern void sm_unmon_all_svc(void *, void *); 211*064d1627SToomas Soome extern void sm_simu_crash_svc(void *, void *); 212*064d1627SToomas Soome extern void sm_notify_svc(void *, void *); 213bbaa8b60SDan Kruchinin 21498573c19SMarcel Telka extern void sm_inithash(void); 2157c478bd9Sstevel@tonic-gate extern void copydir_from_to(char *from_dir, char *to_dir); 2167c478bd9Sstevel@tonic-gate extern int str_cmp_unqual_hostname(char *, char *); 2177c478bd9Sstevel@tonic-gate extern void record_addr(char *name, sa_family_t family, struct netobj *ah); 2187c478bd9Sstevel@tonic-gate extern int is_symlink(char *file); 2197c478bd9Sstevel@tonic-gate extern int create_symlink(char *todir, char *rname, char *lname); 2207c478bd9Sstevel@tonic-gate extern int str_cmp_address_specifier(char *specifier1, char *specifier2); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate #endif 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate #endif /* _SM_STATD_H */ 227