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 <afsconfig.h>
16 #include "afs/param.h"
22 #include "afs/sysincludes.h" /* Standard vendor system headers */
25 #if !defined(AFS_LINUX20_ENV)
28 #include <netinet/in.h>
31 #include "h/hashing.h"
33 #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN60_ENV)
34 #include <netinet/in_var.h>
35 #endif /* ! AFS_HPUX110_ENV */
36 #endif /* !defined(UKERNEL) */
38 #include "afsincludes.h" /* Afs-based standard headers */
39 #include "afs/afs_stats.h" /* afs statistics */
41 #if defined(AFS_SUN56_ENV)
43 #include <inet/common.h>
44 #if defined(AFS_SUN58_ENV)
45 #include <netinet/ip6.h>
50 #if defined(AFS_AIX_ENV)
51 #include <sys/fp_io.h>
56 afs_cv2string(char *ttp, afs_uint32 aval)
58 register char *tp = ttp;
62 AFS_STATCNT(afs_cv2string);
78 #ifndef afs_strcasecmp
80 afs_strcasecmp(char *s1, char *s2)
87 if (c1 >= 'A' && c1 <= 'Z')
89 if (c2 >= 'A' && c2 <= 'Z')
101 afs_strcat(char *s1, char *s2)
108 while ((*s1++ = *s2++));
113 #ifdef AFS_OBSD34_ENV
115 afs_strcpy(char *s1, char *s2)
120 while ((*s1++ = *s2++) != '\0');
127 afs_strchr(char *s, int c)
145 n = (char *)afs_osi_Alloc(cc);
153 print_internet_address(char *preamble, struct srvAddr *sa, char *postamble,
156 register struct server *aserver = sa->server;
160 AFS_STATCNT(print_internet_address);
161 address = ntohl(sa->sa_ip);
162 if (aserver->flags & SRVR_MULTIHOMED) {
163 if (flag == 1) { /* server down mesg */
164 if (!(aserver->flags & SRVR_ISDOWN))
166 " (multi-homed address; other same-host interfaces maybe up)\n";
168 ptr = " (all multi-homed ip addresses down for the server)\n";
169 } else if (flag == 2) { /* server up mesg */
171 " (multi-homed address; other same-host interfaces may still be down)\n";
174 afs_warn("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24),
175 (address >> 16) & 0xff, (address >> 8) & 0xff, (address) & 0xff,
176 aserver->cell->cellName, postamble, ptr);
177 afs_warnuser("%s%d.%d.%d.%d in cell %s%s%s", preamble, (address >> 24),
178 (address >> 16) & 0xff, (address >> 8) & 0xff,
179 (address) & 0xff, aserver->cell->cellName, postamble, ptr);
181 } /*print_internet_address */
186 * this code badly needs to be cleaned up... too many ugly ifdefs.
191 afs_warn(char *a, long b, long c, long d, long e, long f, long g, long h,
195 afs_warn(a, b, c, d, e, f, g, h, i, j)
197 #if defined( AFS_USE_VOID_PTR)
198 void *b, *c, *d, *e, *f, *g, *h, *i, *j;
200 long b, c, d, e, f, g, h, i, j;
204 AFS_STATCNT(afs_warn);
206 if (afs_showflags & GAGCONSOLE) {
207 #if defined(AFS_AIX_ENV)
210 /* cf. console_printf() in oncplus/kernext/nfs/serv/shared.c */
212 ("/dev/console", O_WRONLY | O_NOCTTY | O_NDELAY, 0666, 0, FP_SYS,
218 sprintf(buf, a, b, c, d, e, f, g, h, i, j);
220 fp_write(fd, buf, len, 0, UIO_SYSSPACE, &count);
224 printf(a, b, c, d, e, f, g, h, i, j);
231 afs_warnuser(char *a, long b, long c, long d, long e, long f, long g, long h,
235 afs_warnuser(a, b, c, d, e, f, g, h, i, j)
237 long b, c, d, e, f, g, h, i, j;
240 AFS_STATCNT(afs_warnuser);
241 if (afs_showflags & GAGUSER) {
242 #ifdef AFS_GLOBAL_SUNLOCK
243 int haveGlock = ISAFS_GLOCK();
246 #endif /* AFS_GLOBAL_SUNLOCK */
248 uprintf(a, b, c, d, e, f, g, h, i, j);
250 #ifdef AFS_GLOBAL_SUNLOCK
253 #endif /* AFS_GLOBAL_SUNLOCK */
258 /* run everywhere, checking locks */
264 afs_warn("Looking for locked data structures.\n");
265 afs_warn("conn %x, volume %x, user %x, cell %x, server %x\n", afs_xconn,
266 afs_xvolume, afs_xuser, afs_xcell, afs_xserver);
268 register struct vcache *tvc;
269 AFS_STATCNT(afs_CheckLocks);
271 for (i = 0; i < VCSIZE; i++) {
272 for (tvc = afs_vhashT[i]; tvc; tvc = tvc->hnext) {
274 if (VREFCOUNT(tvc) > 1)
275 #else /* AFS_OSF_ENV */
276 #ifdef AFS_DARWIN80_ENV
277 if (vnode_isinuse(AFSTOV(tvc), 0))
282 afs_warn("Stat cache entry at %x is held\n", tvc);
283 if (CheckLock(&tvc->lock))
284 afs_warn("Stat entry at %x is locked\n", tvc);
289 register struct dcache *tdc;
290 for (i = 0; i < afs_cacheFiles; i++) {
291 tdc = afs_indexTable[i];
294 afs_warn("Disk entry %d at %x is held\n", i, tdc);
296 if (afs_indexFlags[i] & IFDataMod)
297 afs_warn("Disk entry %d at %x has IFDataMod flag set.\n", i,
305 for (i = 0; i < NSERVERS; i++) {
306 for (ts = afs_servers[i]; ts; ts = ts->next) {
307 if (ts->flags & SRVR_ISDOWN)
308 printf("Server entry %lx is marked down\n", (unsigned long)ts);
309 for (sa = ts->addr; sa; sa = sa->next_sa) {
310 for (tc = sa->conns; tc; tc = tc->next) {
312 afs_warn("conn at %x (server %x) is held\n", tc,
321 for (i = 0; i < NVOLS; i++) {
322 for (tv = afs_volumes[i]; tv; tv = tv->next) {
323 if (CheckLock(&tv->lock))
324 afs_warn("volume at %x is locked\n", tv);
326 afs_warn("volume at %x is held\n", tv);
333 for (i = 0; i < NUSERS; i++) {
334 for (tu = afs_users[i]; tu; tu = tu->next) {
336 printf("user at %lx is held\n", (unsigned long)tu);
347 AFS_STATCNT(afs_noop);
358 AFS_STATCNT(afs_badop);
359 osi_Panic("afs bad vnode op");
364 * afs_data_pointer_to_int32() - returns least significant afs_int32 of the
365 * given data pointer, without triggering "cast truncates pointer"
366 * warnings. We use this where we explicitly don't care whether a
367 * pointer is truncated -- it loses information where a pointer is
368 * larger than an afs_int32.
372 afs_data_pointer_to_int32(const void *p)
375 afs_int32 i32[sizeof(void *) / sizeof(afs_int32)];
379 int i32_sub; /* subscript of least significant afs_int32 in ip.i32[] */
384 /* used to determine the byte order of the system */
387 char c[sizeof(int) / sizeof(char)];
393 /* little-endian system */
396 /* big-endian system */
397 i32_sub = (sizeof ip.i32 / sizeof ip.i32[0]) - 1;
402 return ip.i32[i32_sub];