DEVEL15-windows-64bit-printf-sanity-20090218
[openafs.git] / src / venus / kdump.c
index 71bde8a..4297782 100644 (file)
@@ -27,6 +27,16 @@ RCSID
 #undef USE_UCONTEXT
 #endif
 
+#ifdef AFS_LINUX26_ENV
+/* For some reason, this doesn't get defined in linux/types.h
+   if __KERNEL_STRICT_NAMES is defined. But the definition of
+   struct inode uses it.
+*/
+#ifndef pgoff_t
+#define pgoff_t unsigned long
+#endif
+#endif
+
 #include <string.h>
 
 #ifdef __linux__
@@ -176,8 +186,6 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #endif
 #endif
 
-#include <sys/file.h>
-
 #ifdef AFS_SGI62_ENV
 #include <sys/fcntl.h>
 #ifndef L_SET
@@ -195,6 +203,10 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #include <sys/socket.h>
 #endif
 
+#ifndef AFS_LINUX26_ENV
+#include <sys/file.h>
+#endif
+
 /*
  * On SGIs, when _KERNEL is defined, <netinet/in.h> declares inet_addr()
  * in a way that conflicts with the declaration in <arpa/inet.h>.
@@ -220,11 +232,6 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #include <sys/vnode.h>
 #endif /* AFS_SGI_ENV */
 #else
-#ifdef       AFS_MACH_ENV
-#include <vfs/vfs.h>
-#include <vfs/vnode.h>
-#include <sys/inode.h>
-#else /* AFS_MACH_ENV */
 #if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
 #include <sys/vnode.h>
 #include <sys/mount.h>
@@ -234,7 +241,9 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #else
 #include "sys/vfs.h"
 #ifdef AFS_LINUX20_ENV
+#ifndef UIO_MAXIOV
 #define UIO_MAXIOV 1           /* don't care */
+#endif
 #if __GLIBC_MINOR__ == 0
 #include <iovec.h>
 #endif
@@ -246,7 +255,12 @@ typedef struct adaptive_mutex2 adaptive_mutex2_t;
 #undef LONG_MAX
 #undef ULONG_MAX
 #define _LINUX_TIME_H
+#ifndef AFS_LINUX26_ENV
 #define _LINUX_FCNTL_H
+#endif
+#ifdef AFS_IA64_LINUX24_ENV
+#define flock64  flock
+#endif /* AFS_IA64_LINUX24_ENV */
 #ifdef AFS_S390_LINUX20_ENV
 #define _S390_STATFS_H
 #else
@@ -274,7 +288,7 @@ typedef struct timeval {
     int tv_usec;
 } timeval_t;                   /* Needed here since KERNEL defined. */
 #endif /*AFS_ALPHA_LINUX20_ENV */
-#if defined(AFSBIG_ENDIAN)
+#if defined(WORDS_BIGENDIAN)
 #define _LINUX_BYTEORDER_BIG_ENDIAN_H
 #else
 #define _LINUX_BYTEORDER_LITTLE_ENDIAN_H
@@ -284,6 +298,16 @@ typedef struct timeval {
 #define timer_t ktimer_t
 #define timer_t_redefined
 #endif
+#ifdef AFS_LINUX26_ENV
+/* For some reason, this doesn't get defined in linux/types.h
+   if __KERNEL_STRICT_NAMES is defined. But the definition of
+   struct inode uses it.
+*/
+#ifndef HAVE_SECTOR_T
+/* got it from linux/types.h */
+typedef unsigned long sector_t;
+#endif /* HAVE_SECTOR_T */
+#endif /* AFS_LINUX26_ENV */
 #include <linux/version.h>
 #include <linux/fs.h>
 #include <osi_vfs.h>
@@ -327,7 +351,6 @@ typedef enum _spustate {    /* FROM /etc/conf/h/_types.h */
 #endif
 #endif
 #endif
-#endif /* AFS_MACH_ENV */
 #include <signal.h>
 #endif
 
@@ -533,9 +556,6 @@ void print_cmstats();
 
 
 
-#ifndef AFS_KDUMP_LIB
-extern struct cmd_syndesc *cmd_CreateSyntax();
-#endif
 int opencore();
 
 #if    defined(AFS_HPUX_ENV) && defined(__LP64__)
@@ -625,7 +645,11 @@ PrintIPAddr(int addr)
 #include <stdlib.h>
 #include <string.h>
 
+#ifdef AFS_LINUX26_ENV
+#define KSYMS "/proc/kallsyms"
+#else
 #define KSYMS "/proc/ksyms"
+#endif
 
 /* symlist_t contains all the kernel symbols. Forcing a 64 byte array is
  * a bit wasteful, but simple.
@@ -633,7 +657,11 @@ PrintIPAddr(int addr)
 #define MAXNAMELEN 64
 typedef struct symlist {
     char s_name[MAXNAMELEN];
+#ifdef AFS_LINUX_64BIT_KERNEL
+    unsigned long s_value;
+#else
     int s_value;
+#endif /* AFS_LINUX_64BIT_KERNEL */
 } symlist_t;
 
 #define KSYM_ALLOC_STEP 128
@@ -687,8 +715,19 @@ read_ksyms(void)
                exit(1);
            }
        }
+#ifdef AFS_LINUX_64BIT_KERNEL
+       ksyms[nksyms].s_value = (unsigned long)strtoul(line, &p, 16);
+#else
        ksyms[nksyms].s_value = (int)strtoul(line, &p, 16);
+#endif /* AFS_LINUX_64BIT_KERNEL */
        p++;
+#ifdef AFS_LINUX26_ENV
+       /* Linux 2.6 /proc/kallsyms has a one-char symbol type
+          between address and name, so step over it and the following
+          blank.
+       */
+       p += 2;
+#endif
        q = strchr(p, '\t');
        if (q)
            *q = '\0';
@@ -707,7 +746,11 @@ read_ksyms(void)
 
 
 /* find_symbol returns 0 if not found, otherwise value for symbol */
+#ifdef AFS_LINUX_64BIT_KERNEL
+unsigned long
+#else
 int
+#endif /* AFS_LINUX_64BIT_KERNEL */
 find_symbol(char *name)
 {
     symlist_t *tmp;
@@ -782,10 +825,8 @@ symsrch(s)
 
 
 #ifndef AFS_KDUMP_LIB
-static
-cmdproc(as, arock)
-     register struct cmd_syndesc *as;
-     afs_int32 arock;
+static int
+cmdproc(register struct cmd_syndesc *as, void *arock)
 {
     register afs_int32 code = 0;
 
@@ -911,7 +952,7 @@ main(argc, argv)
     sigaction(SIGSEGV, &nsa, NULL);
 #endif
 
-    ts = cmd_CreateSyntax(NULL, cmdproc, 0,
+    ts = cmd_CreateSyntax(NULL, cmdproc, NULL,
                          "Read internal cache manager structs");
     cmd_AddParm(ts, "-kobj", CMD_SINGLE, CMD_OPTIONAL,
                "kernel object (default /vmunix)");
@@ -1793,7 +1834,7 @@ print_buffers(pnt)
        if (pnt)
            printf
                ("Buffer #%d:\tfid=%lu page=%d, accTime=%d,\n\tHash=%x, data=%x, lockers=%x, dirty=%d, hashI=%d\n",
-                i, bp->fid[0], bp->page, bp->accesstime, bp->hashNext,
+                i, bp->fid, bp->page, bp->accesstime, bp->hashNext,
                 bp->data, bp->lockers, bp->dirty, bp->hashIndex);
 #endif
        j++;
@@ -1885,7 +1926,11 @@ print_alloced_memlist(void)
     findsym("afs_linux_memlist", &symoff);
     kread(kmem, symoff, (char *)&memp, sizeof memp);
     if (memp) {
+#ifdef AFS_LINUX_64BIT_KERNEL
+       kread(kmem, (unsigned long)memp, (char *)&next, sizeof next);
+#else
        kread(kmem, (int)memp, (char *)&next, sizeof next);
+#endif /* AFS_LINUX_64BIT_KERNEL */
     } else {
        memset(&next, 0, sizeof next);
     }
@@ -1960,10 +2005,10 @@ print_allocs(pnt)
     T += j;
     printf("%20s:\t%8d bytes\t[%d servers/%d bytes each]\n", "Server package",
           j, i, sizeof(struct server));
-    j = (Nconns * sizeof(struct conn));
+    j = (Nconns * sizeof(struct afs_conn));
     T += j;
     printf("%20s:\t%8d bytes\t[%d conns/%d bytes each]\n",
-          "Connection package", j, Nconns, sizeof(struct conn));
+          "Connection package", j, Nconns, sizeof(struct afs_conn));
 
     i = (AFS_NCBRS * sizeof(struct afs_cbr)) * (j =
                                                afs_cmperfstats.
@@ -2465,15 +2510,19 @@ print_nfsclient(kmem, ep, ptr, pnt)
      struct nfsclientpag *ep, *ptr;
 {
     char sysname[100];
+       int count;
 
-    if (ep->sysname) {
-       kread(kmem, (off_t) ep->sysname, sysname, (KDUMP_SIZE_T) 30);
-       Sum_nfssysnames += MAXSYSNAME;
-    }
     if (pnt)
-       printf("%lx: uid=%d, host=%x, pag=%x, @sys=%s, lastt=%d, ref=%d\n",
+       printf("%lx: uid=%d, host=%x, pag=%x, lastt=%d, ref=%d count=%d\n",
               ptr, ep->uid, ep->host, ep->pag,
-              (ep->sysname ? sysname : "nil"), ep->lastcall, ep->refCount);
+              ep->lastcall, ep->refCount, ep->sysnamecount);
+
+       for(count = 0; count < ep->sysnamecount; count++){
+               kread(kmem, (off_t) ep->sysname[count], sysname, (KDUMP_SIZE_T) 30);
+               printf("   %lx: @sys[%d]=%s\n",
+                       ep->sysname[count], count, sysname);
+               Sum_nfssysnames += MAXSYSNAME;
+       }
 }
 
 
@@ -2620,12 +2669,12 @@ void
 print_conns(kmem, srv, conns, Con, pnt)
      int kmem, Con, pnt;
      struct srvAddr *srv;
-     struct conn *conns;
+     struct afs_conn *conns;
 {
-    struct conn *cep, ce, *centry = &ce;
+    struct afs_conn *cep, ce, *centry = &ce;
     int i = 1;
 
-    cep = (struct conn *)conns;
+    cep = (struct afs_conn *)conns;
     if (pnt && Con != 2) {
        if (cep)
            printf("\tRPC connections for server %lx:\n", srv);
@@ -2644,7 +2693,7 @@ print_conns(kmem, srv, conns, Con, pnt)
 void
 print_conn(kmem, conns, ptr, pnt)
      int kmem, pnt;
-     struct conn *conns, *ptr;
+     struct afs_conn *conns, *ptr;
 {
     if (!pnt)
        return;
@@ -2779,8 +2828,13 @@ print_vnode(kmem, vep, ptr, pnt)
         vep->i_atime, vep->i_mtime, vep->i_ctime, vep->i_version,
         vep->i_nrpages);
 #endif
+#ifdef AFS_LINUX26_ENV
+    printf("\ti_op=0x%x, i_rdev=0x%x, i_sb=0x%x\n", vep->i_op,
+          vep->i_rdev, vep->i_sb);
+#else /* AFS_LINUX26_ENV */
     printf("\ti_op=0x%x, i_dev=0x%x, i_rdev=0x%x, i_sb=0x%x\n", vep->i_op,
           vep->i_dev, vep->i_rdev, vep->i_sb);
+#endif /* AFS_LINUX26_ENV */
 #ifdef AFS_LINUX24_ENV
 #ifdef AFS_PARISC_LINUX24_ENV
     printf("\ti_sem: count=%d, wait=0x%x\n", vep->i_sem.count,
@@ -2793,9 +2847,15 @@ print_vnode(kmem, vep, ptr, pnt)
     printf("\ti_sem: count=%d, waking=%d, wait=0x%x\n", vep->i_sem.count,
           vep->i_sem.waking, vep->i_sem.wait);
 #endif
+#ifdef AFS_LINUX26_ENV
+    printf("\ti_hash=0x%x:0x%x, i_list=0x%x:0x%x, i_dentry=0x%x:0x%x\n",
+          vep->i_hash.pprev, vep->i_hash.next, vep->i_list.prev,
+          vep->i_list.next, vep->i_dentry.prev, vep->i_dentry.next);
+#else /* AFS_LINUX26_ENV */
     printf("\ti_hash=0x%x:0x%x, i_list=0x%x:0x%x, i_dentry=0x%x:0x%x\n",
           vep->i_hash.prev, vep->i_hash.next, vep->i_list.prev,
           vep->i_list.next, vep->i_dentry.prev, vep->i_dentry.next);
+#endif /* AFS_LINUX26_ENV */
 #endif /* AFS_LINUX22_ENV */
 }
 
@@ -2824,13 +2884,13 @@ print_vcache(kmem, vep, ptr, pnt)
            printf("\n");
 #ifdef AFS33
        printf("%lx: refC=%d, pv=%d, pu=%d, flushDv=%d.%d, mapDV=%d.%d, ",
-              ptr, vep->vrefCount, vep->parentVnode, vep->parentUnique,
+              ptr, VREFCOUNT(vep), vep->parentVnode, vep->parentUnique,
               vep->flushDV.high, vep->flushDV.low, vep->mapDV.high,
               vep->mapDV.low);
 #ifdef AFS_64BIT_CLIENT
        printf
            ("truncPos=(0x%x, 0x%x),\n\tcallb=x%lx, cbE=%d, opens=%d, XoW=%d, ",
-            (int)vep->truncPos >> 32, (int)vep->truncPos & 0xffffffff,
+            (int)(vep->truncPos >> 32), (int)(vep->truncPos & 0xffffffff),
             vep->callback, vep->cbExpires, vep->opens, vep->execsOrWriters);
 #else /* AFS_64BIT_CLIENT */
        printf("truncPos=%d,\n\tcallb=x%lx, cbE=%d, opens=%d, XoW=%d, ",
@@ -2842,15 +2902,11 @@ print_vcache(kmem, vep, ptr, pnt)
 #ifdef AFS_SUN5_ENV
        printf("vstates=x%x, ", vep->vstates);
 #endif /* AFS_SUN5_ENV */
-       printf("dchint=%x, anyA=0x%x\n", vep->h1.dchint, vep->anyAccess);
+       printf("dchint=%x, anyA=0x%x\n", vep->dchint, vep->anyAccess);
 #ifdef AFS_64BIT_CLIENT
-       printf("\tquick[dc=%x, stamp=%x, f=%x, min=%d, len=(0x%x, 0x%x)]\n",
-              vep->quick.dc, vep->quick.stamp, vep->quick.f,
-              vep->quick.minLoc, (int)vep->quick.len >> 32,
-              (int)vep->quick.len & 0xffffffff);
        printf
            ("\tmstat[len=(0x%x, 0x%x), DV=%d.%d, Date=%d, Owner=%d, Group=%d, Mode=0%o, linkc=%d]\n",
-            (int)vep->m.Length >> 32, (int)vep->m.Length & 0xffffffff,
+            (int)(vep->m.Length >> 32), (int)(vep->m.Length & 0xffffffff),
             vep->m.DataVersion.high, vep->m.DataVersion.low, vep->m.Date,
             vep->m.Owner, vep->m.Group, vep->m.Mode, vep->m.LinkCount);
 #else /* AFS_64BIT_CLIENT */
@@ -2937,7 +2993,7 @@ print_vcache(kmem, vep, ptr, pnt)
        }
     }
 #ifdef AFS_LINUX22_ENV
-    printf("\tflushcnt=%d, mapcnt=%d\n", vep->flushcnt, vep->mapcnt);
+    printf("\tmapcnt=%d\n", vep->mapcnt);
 #endif
 }
 
@@ -2963,17 +3019,15 @@ print_dcache(kmem, dcp, dp, pnt)
 #endif
 #ifdef AFS_SGI62_ENV
     printf
-       ("\tf.chunk=%d, f.inode=%lld, f.chunkBytes=%d, f.states=%x, stamp=%x\n",
-        dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states,
-        dcp->stamp);
+       ("\tf.chunk=%d, f.inode=%" AFS_INT64_FMT ", f.chunkBytes=%d, f.states=%x",
+        dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states);
 #else
     printf
-       ("\tf.chunk=%d, f.inode=%d, f.chunkBytes=%d, f.states=%x, stamp=%x\n",
-        dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states,
-        dcp->stamp);
+       ("\tf.chunk=%d, f.inode=%d, f.chunkBytes=%d, f.states=%x\n",
+        dcp->f.chunk, dcp->f.inode, dcp->f.chunkBytes, dcp->f.states);
 #endif
-    printf("\tlruq.prev=%lx, lruq.next=%lx, index=%d, ihint=%x\n",
-          dcp->lruq.prev, dcp->lruq.next, dcp->index, dcp->ihint);
+    printf("\tlruq.prev=%lx, lruq.next=%lx, index=%d\n",
+          dcp->lruq.prev, dcp->lruq.next, dcp->index);
 }
 
 void
@@ -3291,10 +3345,10 @@ print_global_afs_cache(kmem)
 #ifdef AFS_SGI62_ENV
     findsym("cacheInode", &symoff);
     kread(kmem, symoff, (char *)&inode, sizeof inode);
-    printf("\tcacheInode = 0x%llx (%lld)\n", inode, inode);
+    printf("\tcacheInode = 0x%llx (%" AFS_INT64_FMT ")\n", inode, inode);
     findsym("volumeInode", &symoff);
     kread(kmem, symoff, (char *)&inode, sizeof inode);
-    printf("\tvolumeInode = 0x%llx (%lld)\n", inode, inode);
+    printf("\tvolumeInode = 0x%llx (%" AFS_INT64_FMT ")\n", inode, inode);
 #else
     findsym("cacheInode", &symoff);
     kread(kmem, symoff, (char *)&count, sizeof count);
@@ -3354,7 +3408,7 @@ print_rxstats(kmem)
     off_t symoff;
     char sysname[100];
     afs_int32 count, i;
-    struct rx_stats rx_stats;
+    struct rx_statistics rx_stats;
 
     printf("\n\nPrinting some general RX stats...\n\n");
     findsym("rx_stats", &symoff);
@@ -3419,7 +3473,7 @@ print_rx(kmem)
     char sysname[100], c;
     afs_int32 count, i, ar[100];
     short sm;
-    struct rx_stats rx_stats;
+    struct rx_statistics rx_stats;
 
     printf("\n\nPrinting some RX globals...\n\n");
     findsym("rx_extraQuota", &symoff);