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 /* 23*a6f0fae9Sgt29601 * 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 407c478bd9Sstevel@tonic-gate #ifndef _SM_STATD_H 417c478bd9Sstevel@tonic-gate #define _SM_STATD_H 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #ifdef __cplusplus 467c478bd9Sstevel@tonic-gate extern "C" { 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* Limit defines */ 507c478bd9Sstevel@tonic-gate #define SM_DIRECTORY_MODE 00755 517c478bd9Sstevel@tonic-gate #define MAX_HASHSIZE 50 527c478bd9Sstevel@tonic-gate #define SM_RPC_TIMEOUT 15 537c478bd9Sstevel@tonic-gate #define PERCENT_MINJOIN 10 547c478bd9Sstevel@tonic-gate #define MAX_FDS 256 557c478bd9Sstevel@tonic-gate #define MAX_THR 25 567c478bd9Sstevel@tonic-gate #define INC_DELAYTIME 30 577c478bd9Sstevel@tonic-gate #define MAX_DELAYTIME 300 587c478bd9Sstevel@tonic-gate #define SM_CLTS_TIMEOUT 15 597c478bd9Sstevel@tonic-gate /* max strlen of /statmon/state, /statmon/sm.bak, /statmon/sm */ 607c478bd9Sstevel@tonic-gate #define SM_MAXPATHLEN 17 617c478bd9Sstevel@tonic-gate /* Increment size for realloc of array host_name */ 627c478bd9Sstevel@tonic-gate #define HOST_NAME_INCR 5 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* supported address family names in /var/statmon symlinks */ 657c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV4 "ipv4" 667c478bd9Sstevel@tonic-gate #define SM_ADDR_IPV6 "ipv6" 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* Supported for readdir_r() */ 697c478bd9Sstevel@tonic-gate #define MAXDIRENT (sizeof (struct dirent) + _POSIX_PATH_MAX + 1) 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* Structure entry for monitor table (mon_table) */ 727c478bd9Sstevel@tonic-gate struct mon_entry { 737c478bd9Sstevel@tonic-gate mon id; /* mon information: mon_name, my_id */ 747c478bd9Sstevel@tonic-gate struct mon_entry *prev; /* Prev ptr to prev entry in hash */ 757c478bd9Sstevel@tonic-gate struct mon_entry *nxt; /* Next ptr to next entry in hash */ 767c478bd9Sstevel@tonic-gate }; 777c478bd9Sstevel@tonic-gate typedef struct mon_entry mon_entry; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* Structure entry for record (rec_table) and recovery (recov_q) tables */ 807c478bd9Sstevel@tonic-gate struct name_entry { 817c478bd9Sstevel@tonic-gate char *name; /* name of host */ 827c478bd9Sstevel@tonic-gate int count; /* count of entries */ 837c478bd9Sstevel@tonic-gate struct name_entry *prev; /* Prev ptr to prev entry in hash */ 847c478bd9Sstevel@tonic-gate struct name_entry *nxt; /* Next ptr to next entry in hash */ 857c478bd9Sstevel@tonic-gate }; 867c478bd9Sstevel@tonic-gate typedef struct name_entry name_entry; 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate /* Structure for passing arguments into thread send_notice */ 897c478bd9Sstevel@tonic-gate typedef struct moninfo { 907c478bd9Sstevel@tonic-gate mon id; /* Monitor information */ 917c478bd9Sstevel@tonic-gate int state; /* Current state */ 927c478bd9Sstevel@tonic-gate } moninfo_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* Structure entry for hash tables */ 957c478bd9Sstevel@tonic-gate typedef struct sm_hash { 967c478bd9Sstevel@tonic-gate union { 977c478bd9Sstevel@tonic-gate struct mon_entry *mon_hdptr; /* Head ptr for mon_table */ 987c478bd9Sstevel@tonic-gate name_entry *rec_hdptr; /* Head ptr for rec_table */ 997c478bd9Sstevel@tonic-gate name_entry *recov_hdptr; /* Head ptr for recov_q */ 1007c478bd9Sstevel@tonic-gate } smhd_t; 1017c478bd9Sstevel@tonic-gate mutex_t lock; /* Lock to protect each list head */ 1027c478bd9Sstevel@tonic-gate } sm_hash_t; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate #define sm_monhdp smhd_t.mon_hdptr 1057c478bd9Sstevel@tonic-gate #define sm_rechdp smhd_t.rec_hdptr 1067c478bd9Sstevel@tonic-gate #define sm_recovhdp smhd_t.recov_hdptr 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate /* Structure entry for address list in name-to-address entry */ 1097c478bd9Sstevel@tonic-gate typedef struct addr_entry { 1107c478bd9Sstevel@tonic-gate struct addr_entry *next; 1117c478bd9Sstevel@tonic-gate struct netobj ah; 1127c478bd9Sstevel@tonic-gate sa_family_t family; 1137c478bd9Sstevel@tonic-gate } addr_entry_t; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* Structure entry for name-to-address translation table */ 1167c478bd9Sstevel@tonic-gate typedef struct name_addr_entry { 1177c478bd9Sstevel@tonic-gate struct name_addr_entry *next; 1187c478bd9Sstevel@tonic-gate char *name; 1197c478bd9Sstevel@tonic-gate struct addr_entry *addresses; 1207c478bd9Sstevel@tonic-gate } name_addr_entry_t; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* Hash tables for each of the in-cache information */ 1237c478bd9Sstevel@tonic-gate extern sm_hash_t mon_table[MAX_HASHSIZE]; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* Global variables */ 1267c478bd9Sstevel@tonic-gate extern mutex_t crash_lock; /* lock for die and crash variables */ 1277c478bd9Sstevel@tonic-gate extern int die; /* Flag to indicate that an SM_CRASH */ 1287c478bd9Sstevel@tonic-gate /* request came in & to stop threads cleanly */ 1297c478bd9Sstevel@tonic-gate extern int in_crash; /* Flag to single thread sm_crash requests. */ 1307c478bd9Sstevel@tonic-gate extern int regfiles_only; /* Flag to indicate symlink use in statmon */ 1317c478bd9Sstevel@tonic-gate extern cond_t crash_finish; /* Condition to wait until crash is finished */ 1327c478bd9Sstevel@tonic-gate extern mutex_t sm_trylock; /* Lock to single thread sm_try */ 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * The only established lock precedence here is: 1357c478bd9Sstevel@tonic-gate * 1367c478bd9Sstevel@tonic-gate * thr_rwlock > name_addrlock 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate extern mutex_t name_addrlock; /* Locks all entries of name-to-addr table */ 1397c478bd9Sstevel@tonic-gate extern rwlock_t thr_rwlock; /* Reader/writer lock for requests coming in */ 1407c478bd9Sstevel@tonic-gate extern cond_t retrywait; /* Condition to wait before starting retry */ 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate extern char STATE[MAXPATHLEN], CURRENT[MAXPATHLEN]; 1437c478bd9Sstevel@tonic-gate extern char BACKUP[MAXPATHLEN]; 1447c478bd9Sstevel@tonic-gate extern int LOCAL_STATE; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate /* 1477c478bd9Sstevel@tonic-gate * Hash functions for monitor and record hash tables. 1487c478bd9Sstevel@tonic-gate * Functions are hashed based on first 2 letters and last 2 letters of name. 1497c478bd9Sstevel@tonic-gate * If only 1 letter in name, then, hash only on 1 letter. 1507c478bd9Sstevel@tonic-gate */ 1517c478bd9Sstevel@tonic-gate #define SMHASH(name, key) { \ 1527c478bd9Sstevel@tonic-gate int l; \ 1537c478bd9Sstevel@tonic-gate key = *name; \ 1547c478bd9Sstevel@tonic-gate if ((l = strlen(name)) != 1) \ 1557c478bd9Sstevel@tonic-gate key |= ((*(name+(l-1)) << 24) | (*(name+1) << 16) | \ 1567c478bd9Sstevel@tonic-gate (*(name+(l-2)) << 8)); \ 1577c478bd9Sstevel@tonic-gate key = key % MAX_HASHSIZE; \ 1587c478bd9Sstevel@tonic-gate } 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern int debug; /* Prints out debug information if set. */ 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate extern char hostname[MAXHOSTNAMELEN]; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* 1657c478bd9Sstevel@tonic-gate * These variables will be used to store all the 1667c478bd9Sstevel@tonic-gate * alias names for the host, as well as the -a 1677c478bd9Sstevel@tonic-gate * command line hostnames. 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate extern char **host_name; /* store -a opts */ 1707c478bd9Sstevel@tonic-gate extern int host_name_count; 1717c478bd9Sstevel@tonic-gate extern int addrix; /* # of -a entries */ 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * The following 2 variables are meaningful 1757c478bd9Sstevel@tonic-gate * only under a HA configuration. 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate extern char **path_name; /* store -p opts */ 1787c478bd9Sstevel@tonic-gate extern int pathix; /* # of -p entries */ 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* Function prototypes used in program */ 1817c478bd9Sstevel@tonic-gate extern int create_file(char *name); 1827c478bd9Sstevel@tonic-gate extern void delete_file(char *name); 1837c478bd9Sstevel@tonic-gate extern void record_name(char *name, int op); 1847c478bd9Sstevel@tonic-gate extern void sm_crash(void); 1857c478bd9Sstevel@tonic-gate extern void sm_notify(stat_chge *ntfp); 1867c478bd9Sstevel@tonic-gate extern void statd_init(); 1877c478bd9Sstevel@tonic-gate extern void merge_hosts(void); 188*a6f0fae9Sgt29601 extern CLIENT *create_client(char *, int, int, struct timeval *); 1897c478bd9Sstevel@tonic-gate extern char *xmalloc(unsigned); 1907c478bd9Sstevel@tonic-gate extern void sm_status(sm_name *namep, sm_stat_res *resp); 1917c478bd9Sstevel@tonic-gate extern void sm_mon(mon *monp, sm_stat_res *resp); 1927c478bd9Sstevel@tonic-gate extern void sm_unmon(mon_id *monidp, sm_stat *resp); 1937c478bd9Sstevel@tonic-gate extern void sm_unmon_all(my_id *myidp, sm_stat *resp); 1947c478bd9Sstevel@tonic-gate extern void sm_simu_crash(void *myidp); 1957c478bd9Sstevel@tonic-gate extern void sm_inithash(); 1967c478bd9Sstevel@tonic-gate extern void copydir_from_to(char *from_dir, char *to_dir); 1977c478bd9Sstevel@tonic-gate extern int str_cmp_unqual_hostname(char *, char *); 1987c478bd9Sstevel@tonic-gate extern void nsmaddrproc1_reg(reg1args *, reg1res *); 1997c478bd9Sstevel@tonic-gate extern void record_addr(char *name, sa_family_t family, struct netobj *ah); 2007c478bd9Sstevel@tonic-gate extern int is_symlink(char *file); 2017c478bd9Sstevel@tonic-gate extern int create_symlink(char *todir, char *rname, char *lname); 2027c478bd9Sstevel@tonic-gate extern int str_cmp_address_specifier(char *specifier1, char *specifier2); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2057c478bd9Sstevel@tonic-gate } 2067c478bd9Sstevel@tonic-gate #endif 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #endif /* _SM_STATD_H */ 209