2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * afs_util.c - miscellaneous AFS client utility functions
15 #include "../afs/param.h" /* Should be always first */
16 #include "../afs/stds.h"
17 #include "../afs/sysincludes.h" /* Standard vendor system headers */
21 #include <netinet/in.h>
24 #include "../h/hashing.h"
26 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV)
27 #include <netinet/in_var.h>
28 #endif /* ! AFS_HPUX110_ENV */
29 #endif /* !defined(UKERNEL) */
31 #include "../afs/afsincludes.h" /* Afs-based standard headers */
32 #include "../afs/afs_stats.h" /* afs statistics */
34 #if defined(AFS_SUN56_ENV)
36 #include <inet/common.h>
37 #if defined(AFS_SUN58_ENV)
38 #include <netinet/ip6.h>
43 #if defined(AFS_AIX_ENV)
44 #include <sys/fp_io.h>
47 extern struct volume *afs_volumes[NVOLS];
49 char *afs_cv2string(char *ttp, afs_uint32 aval)
51 register char *tp = ttp;
55 AFS_STATCNT(afs_cv2string);
70 void print_internet_address(char *preamble, struct srvAddr *sa,
71 char *postamble, int flag)
73 register struct server *aserver = sa->server;
77 AFS_STATCNT(print_internet_address);
78 address = ntohl(sa->sa_ip);
79 if (aserver->flags & SRVR_MULTIHOMED) {
80 if (flag == 1) { /* server down mesg */
81 if (!(aserver->flags & SRVR_ISDOWN))
82 ptr = " (multi-homed address; other same-host interfaces maybe up)\n";
84 ptr = " (all multi-homed ip addresses down for the server)\n";
85 } else if (flag == 2) { /* server up mesg */
86 ptr = " (multi-homed address; other same-host interfaces may still be down)\n";
89 afs_warn("%s%d.%d.%d.%d in cell %s%s%s",
90 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
91 aserver->cell->cellName, postamble, ptr);
92 afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s",
93 preamble, (address >> 24), (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
94 aserver->cell->cellName, postamble, ptr);
96 } /*print_internet_address*/
101 * this code badly needs to be cleaned up... too many ugly ifdefs.
104 extern afs_int32 afs_showflags;
106 afs_warn(a,b,c,d,e,f,g,h,i,j)
108 long b,c,d,e,f,g,h,i,j;
110 AFS_STATCNT(afs_warn);
112 if (afs_showflags & GAGCONSOLE)
114 #if defined(AFS_AIX_ENV)
117 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
118 if (fp_open("/dev/console",O_WRONLY|O_NOCTTY|O_NDELAY,
119 0666,0,FP_SYS,&fd) == 0) {
124 sprintf(buf, a,b,c,d,e,f,g,h,i,j);
126 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
130 printf(a,b,c,d,e,f,g,h,i,j);
135 afs_warnuser(a,b,c,d,e,f,g,h,i,j)
137 long b,c,d,e,f,g,h,i,j;
139 AFS_STATCNT(afs_warnuser);
140 if (afs_showflags & GAGUSER)
142 #ifdef AFS_GLOBAL_SUNLOCK
143 int haveGlock = ISAFS_GLOCK();
146 #endif /* AFS_GLOBAL_SUNLOCK */
148 uprintf(a,b,c,d,e,f,g,h,i,j);
150 #ifdef AFS_GLOBAL_SUNLOCK
153 #endif /* AFS_GLOBAL_SUNLOCK */
158 /* run everywhere, checking locks */
159 void afs_CheckLocks()
162 extern afs_rwlock_t afs_xconn, afs_xvolume, afs_xuser, afs_xcell;
163 extern afs_rwlock_t afs_xserver;
164 extern struct server *afs_servers[NSERVERS];
165 extern struct unixuser *afs_users[NUSERS];
166 extern unsigned char *afs_indexFlags;
169 afs_warn("Looking for locked data structures.\n");
170 afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n",
171 afs_xconn, afs_xvolume, afs_xuser, afs_xcell, afs_xserver);
173 register struct vcache *tvc;
174 AFS_STATCNT(afs_CheckLocks);
176 for(i=0;i<VCSIZE;i++) {
177 for(tvc = afs_vhashT[i]; tvc; tvc=tvc->hnext) {
179 if (tvc->vrefCount > 1)
180 #else /* AFS_OSF_ENV */
183 afs_warn("Stat cache entry at %x is held\n", tvc);
184 if (CheckLock(&tvc->lock))
185 afs_warn("Stat entry at %x is locked\n", tvc);
190 register struct dcache *tdc;
191 for (i=0;i<afs_cacheFiles;i++) {
192 tdc = afs_indexTable[i];
195 afs_warn("Disk entry %d at %x is held\n", i, tdc);
197 if (afs_indexFlags[i] & IFDataMod)
198 afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i, tdc);
205 for (i=0;i<NSERVERS;i++) {
206 for (ts = afs_servers[i]; ts; ts=ts->next) {
207 if (ts->flags & SRVR_ISDOWN)
208 printf("Server entry %x is marked down\n", ts);
209 for (sa = ts->addr; sa; sa = sa->next_sa) {
210 for (tc = sa->conns; tc; tc=tc->next) {
212 afs_warn("conn at %x (server %x) is held\n", tc, sa->sa_ip);
220 for (i=0;i<NVOLS;i++) {
221 for (tv = afs_volumes[i]; tv; tv=tv->next) {
222 if (CheckLock(&tv->lock))
223 afs_warn("volume at %x is locked\n", tv);
225 afs_warn("volume at %x is held\n", tv);
232 for (i=0;i<NUSERS;i++) {
233 for (tu = afs_users[i]; tu; tu=tu->next) {
234 if (tu->refCount) printf("user at %x is held\n", tu);
243 AFS_STATCNT(afs_noop);
252 AFS_STATCNT(afs_badop);
253 osi_Panic("afs bad vnode op");
254 return 0; /* make SGI C compiler happy */
258 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
259 * given data pointer, without triggering "cast truncates pointer"
260 * warnings. We use this where we explicitly don't care whether a
261 * pointer is truncated -- it loses information where a pointer is
262 * larger than an afs_int32.
266 afs_data_pointer_to_int32(const void *p)
269 afs_int32 i32[sizeof(void *)/sizeof(afs_int32)];
273 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
278 /* used to determine the byte order of the system */
281 char c[sizeof(int)/sizeof(char)];
287 /* little-endian system */
290 /* big-endian system */
291 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
296 return ip.i32[i32_sub];