1 /* Copyright (C) 1995, 1989, 1998 Transarc Corporation - All rights reserved */
3 * (C) COPYRIGHT IBM CORPORATION 1987, 1988
4 * LICENSED MATERIALS - PROPERTY OF IBM
7 * afs_util.c - miscellaneous AFS client utility functions
11 #include "../afs/param.h" /* Should be always first */
12 #include "../afs/stds.h"
13 #include "../afs/sysincludes.h" /* Standard vendor system headers */
17 #include <netinet/in.h>
20 #include "../h/hashing.h"
22 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV)
23 #include <netinet/in_var.h>
24 #endif /* ! AFS_HPUX110_ENV */
25 #endif /* !defined(UKERNEL) */
27 #include "../afs/afsincludes.h" /* Afs-based standard headers */
28 #include "../afs/afs_stats.h" /* afs statistics */
30 #if defined(AFS_SUN56_ENV)
32 #include <inet/common.h>
36 #if defined(AFS_AIX_ENV)
37 #include <sys/fp_io.h>
40 extern struct volume *afs_volumes[NVOLS];
42 char *afs_cv2string(char *ttp, afs_uint32 aval)
44 register char *tp = ttp;
48 AFS_STATCNT(afs_cv2string);
63 void print_internet_address(char *preamble, struct srvAddr *sa,
64 char *postamble, int flag)
66 register struct server *aserver = sa->server;
70 AFS_STATCNT(print_internet_address);
71 address = ntohl(sa->sa_ip);
72 if (aserver->flags & SRVR_MULTIHOMED) {
73 if (flag == 1) { /* server down mesg */
74 if (!(aserver->flags & SRVR_ISDOWN))
75 ptr = " (multi-homed address; other same-host interfaces maybe up)\n";
77 ptr = " (all multi-homed ip addresses down for the server)\n";
78 } else if (flag == 2) { /* server up mesg */
79 ptr = " (multi-homed address; other same-host interfaces may still be down)\n";
82 afs_warn("%s%d.%d.%d.%d in cell %s%s%s",
83 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
84 aserver->cell->cellName, postamble, ptr);
85 afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s",
86 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
87 aserver->cell->cellName, postamble, ptr);
89 } /*print_internet_address*/
94 * this code badly needs to be cleaned up... too many ugly ifdefs.
97 extern afs_int32 afs_showflags;
99 afs_warn(a,b,c,d,e,f,g,h,i,j)
101 long b,c,d,e,f,g,h,i,j;
103 AFS_STATCNT(afs_warn);
105 if (afs_showflags & GAGCONSOLE)
107 #if defined(AFS_AIX_ENV)
110 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
111 if (fp_open("/dev/console",O_WRONLY|O_NOCTTY|O_NDELAY,
112 0666,0,FP_SYS,&fd) == 0) {
117 sprintf(buf, a,b,c,d,e,f,g,h,i,j);
119 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
123 printf(a,b,c,d,e,f,g,h,i,j);
128 afs_warnuser(a,b,c,d,e,f,g,h,i,j)
130 long b,c,d,e,f,g,h,i,j;
132 AFS_STATCNT(afs_warnuser);
133 if (afs_showflags & GAGUSER)
135 #ifdef AFS_GLOBAL_SUNLOCK
136 int haveGlock = ISAFS_GLOCK();
139 #endif /* AFS_GLOBAL_SUNLOCK */
141 uprintf(a,b,c,d,e,f,g,h,i,j);
143 #ifdef AFS_GLOBAL_SUNLOCK
146 #endif /* AFS_GLOBAL_SUNLOCK */
151 /* run everywhere, checking locks */
152 void afs_CheckLocks()
155 extern afs_rwlock_t afs_xconn, afs_xvolume, afs_xuser, afs_xcell;
156 extern afs_rwlock_t afs_xserver;
157 extern struct server *afs_servers[NSERVERS];
158 extern struct unixuser *afs_users[NUSERS];
159 extern unsigned char *afs_indexFlags;
162 afs_warn("Looking for locked data structures.\n");
163 afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n",
164 afs_xconn, afs_xvolume, afs_xuser, afs_xcell, afs_xserver);
166 register struct vcache *tvc;
167 AFS_STATCNT(afs_CheckLocks);
169 for(i=0;i<VCSIZE;i++) {
170 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
172 if (tvc->vrefCount > 1)
173 #else /* AFS_OSF_ENV */
176 afs_warn("Stat cache entry at %x is held\n", tvc);
177 if (CheckLock(&tvc->lock))
178 afs_warn("Stat entry at %x is locked\n", tvc);
183 register struct dcache *tdc;
184 for (i=0;i<afs_cacheFiles;i++) {
185 tdc = afs_indexTable[i];
188 afs_warn("Disk entry %d at %x is held\n", i, tdc);
190 if (afs_indexFlags[i] & IFDataMod)
191 afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, tdc);
198 for (i=0;i<NSERVERS;i++) {
199 for (ts = afs_servers[i]; ts; ts=ts->next) {
200 if (ts->flags & SRVR_ISDOWN)
201 printf("Server entry %x is marked down\n", ts);
202 for (sa = ts->addr; sa; sa = sa->next_sa) {
203 for (tc = sa->conns; tc; tc=tc->next) {
205 afs_warn("conn at %x (server %x) is held\n", tc, sa->sa_ip);
213 for (i=0;i<NVOLS;i++) {
214 for (tv = afs_volumes[i]; tv; tv=tv->next) {
215 if (CheckLock(&tv->lock))
216 afs_warn("volume at %x is locked\n", tv);
218 afs_warn("volume at %x is held\n", tv);
225 for (i=0;i<NUSERS;i++) {
226 for (tu = afs_users[i]; tu; tu=tu->next) {
227 if (tu->refCount) printf("user at %x is held\n", tu);
236 AFS_STATCNT(afs_noop);
245 AFS_STATCNT(afs_badop);
246 osi_Panic("afs bad vnode op");
247 return 0; /* make SGI C compiler happy */
251 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
252 * given data pointer, without triggering "cast truncates pointer"
253 * warnings. We use this where we explicitly don't care whether a
254 * pointer is truncated -- it loses information where a pointer is
255 * larger than an afs_int32.
259 afs_data_pointer_to_int32(const void *p)
262 afs_int32 i32[sizeof(void *)/sizeof(afs_int32)];
266 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
271 /* used to determine the byte order of the system */
274 char c[sizeof(int)/sizeof(char)];
280 /* little-endian system */
283 /* big-endian system */
284 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
289 return ip.i32[i32_sub];