Whamcloud - gitweb
LU-1406 ofd: init lu_target in OFD
[fs/lustre-release.git] / lnet / utils / portals.c
index 1acddcd..bce8033 100644 (file)
@@ -1,7 +1,5 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
- * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
+/*
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  *
  *   This file is part of Portals, http://www.sf.net/projects/lustre/
  *
  *
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#include <sys/socket.h>
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#ifdef HAVE_SYS_IOCTL_H
-#include <sys/ioctl.h>
-#endif
-#ifndef _IOWR
-#include "ioctl.h"
-#endif
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
-#include <stdarg.h>
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#endif
-
-#include <libcfs/portals_utils.h>
+#include <libcfs/libcfsutil.h>
 #include <lnet/api-support.h>
 #include <lnet/lnetctl.h>
 #include <lnet/socklnd.h>
-#include "parser.h"
 
 unsigned int libcfs_debug;
 unsigned int libcfs_printk = D_CANTMASK;
@@ -59,8 +30,8 @@ static int   g_net_set;
 static __u32 g_net;
 
 /* Convert a string boolean to an int; "enable" -> 1 */
-int 
-lnet_parse_bool (int *b, char *str) 
+int
+lnet_parse_bool (int *b, char *str)
 {
         if (!strcasecmp (str, "no") ||
             !strcasecmp (str, "n") ||
@@ -71,7 +42,7 @@ lnet_parse_bool (int *b, char *str)
                 *b = 0;
                 return (0);
         }
-        
+
         if (!strcasecmp (str, "yes") ||
             !strcasecmp (str, "y") ||
             !strcasecmp (str, "on") ||
@@ -81,7 +52,7 @@ lnet_parse_bool (int *b, char *str)
                 *b = 1;
                 return (0);
         }
-        
+
         return (-1);
 }
 
@@ -89,13 +60,13 @@ int
 lnet_parse_port (int *port, char *str)
 {
         char      *end;
-        
+
         *port = strtol (str, &end, 0);
 
         if (*end == 0 &&                        /* parsed whole string */
             *port > 0 && *port < 65536)         /* minimal sanity check */
                 return (0);
-        
+
         return (-1);
 }
 
@@ -194,41 +165,54 @@ ptl_ipaddr_2_str (__u32 ipaddr, char *str, int lookup)
 }
 
 int
-lnet_parse_time (time_t *t, char *str) 
+lnet_parse_time (time_t *t, char *str)
 {
         char          *end;
         int            n;
         struct tm      tm;
-        
+
         *t = strtol (str, &end, 0);
         if (*end == 0) /* parsed whole string */
                 return (0);
-        
+
         memset (&tm, 0, sizeof (tm));
         n = sscanf (str, "%d-%d-%d-%d:%d:%d",
-                    &tm.tm_year, &tm.tm_mon, &tm.tm_mday, 
+                    &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
                     &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
         if (n != 6)
                 return (-1);
-        
+
         tm.tm_mon--;                    /* convert to 0 == Jan */
         tm.tm_year -= 1900;             /* y2k quirk */
         tm.tm_isdst = -1;               /* dunno if it's daylight savings... */
-        
+
         *t = mktime (&tm);
         if (*t == (time_t)-1)
                 return (-1);
-                        
+
         return (0);
 }
 
-int g_net_is_set (char *cmd) 
+int
+lnet_parse_nid(char *nid_str, lnet_process_id_t *id_ptr)
+{
+        id_ptr->pid = LNET_PID_ANY;
+        id_ptr->nid = libcfs_str2nid(nid_str);
+        if (id_ptr->nid == LNET_NID_ANY) {
+                fprintf (stderr, "Can't parse nid \"%s\"\n", nid_str);
+                return -1;
+        }
+
+        return 0;
+}
+
+int g_net_is_set (char *cmd)
 {
         if (g_net_set)
                 return 1;
-        
+
         if (cmd != NULL)
-                fprintf(stderr, 
+                fprintf(stderr,
                         "You must run the 'network' command before '%s'.\n",
                         cmd);
         return 0;
@@ -251,18 +235,18 @@ int g_net_is_compatible (char *cmd, ...)
                         return 1;
                 }
         } while (nal != 0);
-        
+
         va_end (ap);
-        
+
         if (cmd != NULL)
-                fprintf (stderr, 
+                fprintf (stderr,
                          "Command %s not compatible with %s NAL\n",
-                         cmd, 
+                         cmd,
                          libcfs_lnd2str(LNET_NETTYP(g_net)));
         return 0;
 }
 
-int ptl_initialize(int argc, char **argv) 
+int ptl_initialize(int argc, char **argv)
 {
         register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
                          LNET_DEV_MAJOR, LNET_DEV_MINOR);
@@ -320,6 +304,14 @@ int jt_ptl_network(int argc, char **argv)
                 return -1;
         }
 
+        if (LNET_NETTYP(net) == CIBLND    ||
+            LNET_NETTYP(net) == OPENIBLND ||
+            LNET_NETTYP(net) == IIBLND    ||
+            LNET_NETTYP(net) == VIBLND) {
+                fprintf(stderr, "Net %s obsoleted\n", libcfs_lnd2str(net));
+                return -1;
+        }
+
         g_net_set = 1;
         g_net = net;
         return 0;
@@ -346,7 +338,7 @@ jt_ptl_list_nids(int argc, char **argv)
                 LIBCFS_IOC_INIT (data);
                 data.ioc_count = count;
                 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data);
-                
+
                 if (rc < 0) {
                         if ((count > 0) && (errno == ENOENT))
                                 /* We found them all */
@@ -358,7 +350,7 @@ jt_ptl_list_nids(int argc, char **argv)
 
                 if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) {
                         printf("%s\n", libcfs_nid2str(data.ioc_nid));
-                        if (return_nid) { 
+                        if (return_nid) {
                                 *(__u64 *)(argv[1]) = data.ioc_nid;
                                 return_nid--;
                         }
@@ -386,7 +378,7 @@ jt_ptl_which_nid (int argc, char **argv)
                 fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
                 return 0;
         }
-        
+
         for (i = 1; i < argc; i++) {
                 nidstr = argv[i];
                 nid = libcfs_str2nid(nidstr);
@@ -394,10 +386,10 @@ jt_ptl_which_nid (int argc, char **argv)
                         fprintf(stderr, "Can't parse NID %s\n", nidstr);
                         return -1;
                 }
-                
+
                 LIBCFS_IOC_INIT(data);
                 data.ioc_nid = nid;
-                
+
                 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LNET_DIST, &data);
                 if (rc != 0) {
                         fprintf(stderr, "Can't get distance to %s: %s\n",
@@ -411,12 +403,12 @@ jt_ptl_which_nid (int argc, char **argv)
                 if (dist < 0) {
                         if (dist == -EHOSTUNREACH)
                                 continue;
-                
+
                         fprintf(stderr, "Unexpected distance to %s: %d\n",
                                 nidstr, dist);
                         return -1;
                 }
-                
+
                 if (best_nid == LNET_NID_ANY ||
                     dist < best_dist ||
                     (dist == best_dist && order < best_order)) {
@@ -430,7 +422,7 @@ jt_ptl_which_nid (int argc, char **argv)
                 fprintf(stderr, "No reachable NID\n");
                 return -1;
         }
-        
+
         printf("%s\n", libcfs_nid2str(best_nid));
         return 0;
 }
@@ -450,7 +442,7 @@ jt_ptl_print_interfaces (int argc, char **argv)
                 LIBCFS_IOC_INIT(data);
                 data.ioc_net   = g_net;
                 data.ioc_count = index;
-                
+
                 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data);
                 if (rc != 0)
                         break;
@@ -546,7 +538,7 @@ jt_ptl_del_interface (int argc, char **argv)
                 fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
                 return -1;
         }
-        
+
         LIBCFS_IOC_INIT(data);
         data.ioc_net    = g_net;
         data.ioc_u32[0] = ipaddr;
@@ -571,14 +563,14 @@ jt_ptl_print_peers (int argc, char **argv)
         int                      rc;
 
         if (!g_net_is_compatible (argv[0], SOCKLND, RALND, PTLLND, MXLND,
-                                  OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
+                                  O2IBLND, 0))
                 return -1;
 
         for (index = 0;;index++) {
                 LIBCFS_IOC_INIT(data);
                 data.ioc_net     = g_net;
                 data.ioc_count   = index;
-                
+
                 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
                 if (rc != 0)
                         break;
@@ -612,7 +604,7 @@ jt_ptl_print_peers (int argc, char **argv)
                                 data.ioc_u32[5] & 0xffff, /* nactiveq */
                                 data.ioc_u32[6] >> 16, /* credits */
                                 data.ioc_u32[6] & 0xffff); /* outstanding_credits */
-                } else if (g_net_is_compatible(NULL, RALND, OPENIBLND, CIBLND, VIBLND, 0)) {
+                } else if (g_net_is_compatible(NULL, RALND, 0)) {
                         printf ("%-20s [%d]@%s:%d\n",
                                 libcfs_nid2str(data.ioc_nid), /* peer nid */
                                 data.ioc_count,   /* peer persistence */
@@ -636,7 +628,7 @@ jt_ptl_print_peers (int argc, char **argv)
         return 0;
 }
 
-int 
+int
 jt_ptl_add_peer (int argc, char **argv)
 {
         struct libcfs_ioctl_data data;
@@ -645,24 +637,12 @@ jt_ptl_add_peer (int argc, char **argv)
         int                      port = 0;
         int                      rc;
 
-        if (!g_net_is_compatible (argv[0], SOCKLND, RALND, 
-                                  OPENIBLND, CIBLND, IIBLND, VIBLND, 0))
+        if (!g_net_is_compatible (argv[0], SOCKLND, RALND, 0))
                 return -1;
 
-        if (g_net_is_compatible(NULL, SOCKLND, OPENIBLND, CIBLND, RALND, 0)) {
-                if (argc != 4) {
-                        fprintf (stderr, "usage(tcp,openib,cib,ra): %s nid ipaddr port\n", 
-                                 argv[0]);
-                        return 0;
-                }
-        } else if (g_net_is_compatible(NULL, VIBLND, 0)) {
-                if (argc != 3) {
-                        fprintf (stderr, "usage(vib): %s nid ipaddr\n", 
-                                 argv[0]);
-                        return 0;
-                }
-        } else if (argc != 2) {
-                fprintf (stderr, "usage(iib): %s nid\n", argv[0]);
+        if (argc != 4) {
+                fprintf (stderr, "usage(tcp,ra): %s nid ipaddr port\n",
+                         argv[0]);
                 return 0;
         }
 
@@ -672,14 +652,12 @@ jt_ptl_add_peer (int argc, char **argv)
                 return -1;
         }
 
-        if (g_net_is_compatible (NULL, SOCKLND, OPENIBLND, CIBLND, VIBLND, RALND, 0) &&
-            lnet_parse_ipaddr (&ip, argv[2]) != 0) {
+        if (lnet_parse_ipaddr (&ip, argv[2]) != 0) {
                 fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
                 return -1;
         }
 
-        if (g_net_is_compatible (NULL, SOCKLND, OPENIBLND, CIBLND, RALND, 0) &&
-            lnet_parse_port (&port, argv[3]) != 0) {
+        if (lnet_parse_port (&port, argv[3]) != 0) {
                 fprintf (stderr, "Can't parse port: %s\n", argv[3]);
                 return -1;
         }
@@ -696,11 +674,11 @@ jt_ptl_add_peer (int argc, char **argv)
                          strerror (errno));
                 return -1;
         }
-        
+
         return 0;
 }
 
-int 
+int
 jt_ptl_del_peer (int argc, char **argv)
 {
         struct libcfs_ioctl_data data;
@@ -711,7 +689,7 @@ jt_ptl_del_peer (int argc, char **argv)
         int                      rc;
 
         if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, PTLLND,
-                                  OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
+                                  O2IBLND, 0))
                 return -1;
 
         if (g_net_is_compatible(NULL, SOCKLND, 0)) {
@@ -730,7 +708,7 @@ jt_ptl_del_peer (int argc, char **argv)
                 fprintf (stderr, "usage: %s [nid]\n", argv[0]);
                 return 0;
         }
-                
+
         if (argc > 1 &&
             !libcfs_str2anynid(&nid, argv[1])) {
                 fprintf (stderr, "Can't parse nid: %s\n", argv[1]);
@@ -754,7 +732,7 @@ jt_ptl_del_peer (int argc, char **argv)
                         }
                 }
         }
-                   
+
         LIBCFS_IOC_INIT(data);
         data.ioc_net    = g_net;
         data.ioc_nid    = nid;
@@ -767,11 +745,11 @@ jt_ptl_del_peer (int argc, char **argv)
                          strerror (errno));
                 return -1;
         }
-        
+
         return 0;
 }
 
-int 
+int
 jt_ptl_print_connections (int argc, char **argv)
 {
         struct libcfs_ioctl_data data;
@@ -780,8 +758,7 @@ jt_ptl_print_connections (int argc, char **argv)
         int                      index;
         int                      rc;
 
-        if (!g_net_is_compatible (argv[0], SOCKLND, RALND, 
-                                  OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
+        if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, O2IBLND, 0))
                 return -1;
 
         for (index = 0; ; index++) {
@@ -813,6 +790,10 @@ jt_ptl_print_connections (int argc, char **argv)
                         printf ("%-20s [%d]\n",
                                 libcfs_nid2str(data.ioc_nid),
                                 data.ioc_u32[0] /* device id */);
+                } else if (g_net_is_compatible (NULL, O2IBLND, 0)) {
+                        printf ("%s mtu %d\n",
+                                libcfs_nid2str(data.ioc_nid),
+                                data.ioc_u32[0]); /* path MTU */
                 } else {
                         printf ("%s\n", libcfs_nid2str(data.ioc_nid));
                 }
@@ -842,8 +823,7 @@ int jt_ptl_disconnect(int argc, char **argv)
                 return 0;
         }
 
-        if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND,
-                                  OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
+        if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND, O2IBLND, 0))
                 return 0;
 
         if (argc >= 2 &&
@@ -863,7 +843,7 @@ int jt_ptl_disconnect(int argc, char **argv)
         data.ioc_net     = g_net;
         data.ioc_nid     = nid;
         data.ioc_u32[0]  = ipaddr;
-        
+
         rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CLOSE_CONNECTION, &data);
         if (rc != 0) {
                 fprintf(stderr, "failed to remove connection: %s\n",
@@ -887,17 +867,17 @@ int jt_ptl_push_connection (int argc, char **argv)
 
         if (!g_net_is_compatible (argv[0], SOCKLND, 0))
                 return -1;
-        
+
         if (argc > 1 &&
             !libcfs_str2anynid(&nid, argv[1])) {
                 fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
                 return -1;
         }
-                        
+
         LIBCFS_IOC_INIT(data);
         data.ioc_net     = g_net;
         data.ioc_nid     = nid;
-        
+
         rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PUSH_CONNECTION, &data);
         if (rc != 0) {
                 fprintf(stderr, "failed to push connection: %s\n",
@@ -908,7 +888,7 @@ int jt_ptl_push_connection (int argc, char **argv)
         return 0;
 }
 
-int 
+int
 jt_ptl_print_active_txs (int argc, char **argv)
 {
         struct libcfs_ioctl_data data;
@@ -969,27 +949,31 @@ int jt_ptl_ping(int argc, char **argv)
 
         sep = strchr(argv[1], '-');
         if (sep == NULL) {
-                id.pid = LNET_PID_ANY;
-                id.nid = libcfs_str2nid(argv[1]);
-                if (id.nid == LNET_NID_ANY) {
-                        fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
+                rc = lnet_parse_nid(argv[1], &id);
+                if (rc != 0)
                         return -1;
-                }
         } else {
                 char   *end;
-                
+
                 if (argv[1][0] == 'u' ||
                     argv[1][0] == 'U')
                         id.pid = strtoul(&argv[1][1], &end, 0) | LNET_PID_USERFLAG;
                 else
                         id.pid = strtoul(argv[1], &end, 0);
 
-                id.nid = libcfs_str2nid(sep + 1);
-                
-                if (end != sep ||
-                    id.nid == LNET_NID_ANY) {
-                        fprintf(stderr, "Can't parse process id \"%s\"\n", argv[1]);
-                        return -1;
+                if (end != sep) { /* assuming '-' is part of hostname */
+                        rc = lnet_parse_nid(argv[1], &id);
+                        if (rc != 0)
+                                return -1;
+                } else {
+                        id.nid = libcfs_str2nid(sep + 1);
+
+                        if (id.nid == LNET_NID_ANY) {
+                                fprintf(stderr,
+                                        "Can't parse process id \"%s\"\n",
+                                        argv[1]);
+                                return -1;
+                        }
                 }
         }
 
@@ -1067,7 +1051,7 @@ jt_ptl_fail_nid (int argc, char **argv)
                 fprintf (stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n", argv[0]);
                 return (0);
         }
-        
+
         if (!libcfs_str2anynid(&nid, argv[1]))
         {
                 fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
@@ -1080,18 +1064,18 @@ jt_ptl_fail_nid (int argc, char **argv)
                 fprintf (stderr, "Can't parse count \"%s\"\n", argv[2]);
                 return (-1);
         }
-        
+
         LIBCFS_IOC_INIT (data);
         data.ioc_nid = nid;
         data.ioc_count = threshold;
-        
+
         rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data);
         if (rc < 0)
                 fprintf (stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n",
                          strerror (errno));
         else
                 printf ("%s %s\n", threshold == 0 ? "Unfailing" : "Failing", argv[1]);
-        
+
         return (0);
 }
 
@@ -1103,7 +1087,7 @@ jt_ptl_add_route (int argc, char **argv)
         unsigned int             hops = 1;
         char                    *end;
         int                      rc;
-        
+
         if (argc < 2 || argc > 3)
         {
                 fprintf (stderr, "usage: %s gateway [hopcount]\n", argv[0]);
@@ -1126,7 +1110,7 @@ jt_ptl_add_route (int argc, char **argv)
                         return -1;
                 }
         }
-        
+
         LIBCFS_IOC_INIT(data);
         data.ioc_net = g_net;
         data.ioc_count = hops;
@@ -1137,7 +1121,7 @@ jt_ptl_add_route (int argc, char **argv)
                 fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno));
                 return (-1);
         }
-        
+
         return (0);
 }
 
@@ -1147,7 +1131,7 @@ jt_ptl_del_route (int argc, char **argv)
         struct libcfs_ioctl_data data;
         lnet_nid_t               nid;
         int                      rc;
-        
+
         if (argc != 2) {
                 fprintf (stderr, "usage: %s gatewayNID\n", argv[0]);
                 return (0);
@@ -1165,11 +1149,11 @@ jt_ptl_del_route (int argc, char **argv)
 
         rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
         if (rc != 0) {
-                fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n", 
+                fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n",
                          libcfs_nid2str(nid), strerror (errno));
                 return (-1);
         }
-        
+
         return (0);
 }
 
@@ -1202,7 +1186,7 @@ jt_ptl_notify_router (int argc, char **argv)
         }
 
         gettimeofday(&now, NULL);
-        
+
         if (argc < 4) {
                 when = now.tv_sec;
         } else if (lnet_parse_time (&when, argv[3]) != 0) {
@@ -1221,14 +1205,14 @@ jt_ptl_notify_router (int argc, char **argv)
         data.ioc_flags = enable;
         /* Yeuch; 'cept I need a __u64 on 64 bit machines... */
         data.ioc_u64[0] = (__u64)when;
-        
+
         rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_NOTIFY_ROUTER, &data);
         if (rc != 0) {
                 fprintf (stderr, "IOC_LIBCFS_NOTIFY_ROUTER (%s) failed: %s\n",
                          libcfs_nid2str(nid), strerror (errno));
                 return (-1);
         }
-        
+
         return (0);
 }
 
@@ -1247,7 +1231,7 @@ jt_ptl_print_routes (int argc, char **argv)
         {
                 LIBCFS_IOC_INIT(data);
                 data.ioc_count = index;
-                
+
                 rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
                 if (rc != 0)
                         break;
@@ -1288,7 +1272,7 @@ lwt_control(int enable, int clear)
 }
 
 static int
-lwt_snapshot(cycles_t *now, int *ncpu, int *totalsize, 
+lwt_snapshot(cfs_cycles_t *now, int *ncpu, int *totalsize,
              lwt_event_t *events, int size)
 {
         struct libcfs_ioctl_data data;
@@ -1385,7 +1369,8 @@ lwt_put_string(char *ustr)
 }
 
 static int
-lwt_print(FILE *f, cycles_t t0, cycles_t tlast, double mhz, int cpu, lwt_event_t *e)
+lwt_print(FILE *f, cfs_cycles_t t0, cfs_cycles_t tlast, double mhz, int cpu,
+          lwt_event_t *e)
 {
 #ifndef __WORDSIZE
 # error "__WORDSIZE not defined"
@@ -1419,7 +1404,7 @@ get_cycles_per_usec ()
         FILE      *f = fopen ("/proc/cpuinfo", "r");
         double     mhz;
         char      line[64];
-        
+
         if (f != NULL) {
                 while (fgets (line, sizeof (line), f) != NULL)
                         if (sscanf (line, "cpu MHz : %lf", &mhz) == 1) {
@@ -1433,25 +1418,26 @@ get_cycles_per_usec ()
         return (1000.0);
 }
 
+#define LWT_MAX_CPUS (32)
+
 int
 jt_ptl_lwt(int argc, char **argv)
 {
-        const int       lwt_max_cpus = 32;
         int             ncpus;
         int             totalspace;
         int             nevents_per_cpu;
         lwt_event_t    *events;
-        lwt_event_t    *cpu_event[lwt_max_cpus + 1];
-        lwt_event_t    *next_event[lwt_max_cpus];
-        lwt_event_t    *first_event[lwt_max_cpus];
+        lwt_event_t    *cpu_event[LWT_MAX_CPUS + 1];
+        lwt_event_t    *next_event[LWT_MAX_CPUS];
+        lwt_event_t    *first_event[LWT_MAX_CPUS];
         int             cpu;
         lwt_event_t    *e;
         int             rc;
         int             i;
         double          mhz;
-        cycles_t        t0;
-        cycles_t        tlast;
-        cycles_t        tnow;
+        cfs_cycles_t    t0;
+        cfs_cycles_t    tlast;
+        cfs_cycles_t    tnow;
         struct timeval  tvnow;
         int             printed_date = 0;
         int             nlines = 0;
@@ -1465,7 +1451,7 @@ jt_ptl_lwt(int argc, char **argv)
                         "        %s stop [fname]\n", argv[0], argv[0]);
                 return (-1);
         }
-        
+
         if (!strcmp(argv[1], "start")) {
                 /* disable */
                 if (lwt_control(0, 0) != 0)
@@ -1481,13 +1467,13 @@ jt_ptl_lwt(int argc, char **argv)
 
                 return (0);
         }
-                
+
         if (lwt_snapshot(NULL, &ncpus, &totalspace, NULL, 0) != 0)
                 return (-1);
 
-        if (ncpus > lwt_max_cpus) {
-                fprintf(stderr, "Too many cpus: %d (%d)\n", 
-                        ncpus, lwt_max_cpus);
+        if (ncpus > LWT_MAX_CPUS) {
+                fprintf(stderr, "Too many cpus: %d (%d)\n",
+                        ncpus, LWT_MAX_CPUS);
                 return (-1);
         }
 
@@ -1520,7 +1506,7 @@ jt_ptl_lwt(int argc, char **argv)
         }
 
         mhz = get_cycles_per_usec();
-        
+
         /* carve events into per-cpu slices */
         nevents_per_cpu = totalspace / (ncpus * sizeof(lwt_event_t));
         for (cpu = 0; cpu <= ncpus; cpu++)
@@ -1548,17 +1534,17 @@ jt_ptl_lwt(int argc, char **argv)
                 e = first_event[cpu];
                 if (e == NULL)                  /* no events this cpu */
                         continue;
-                
+
                 if (e == cpu_event[cpu])
                         e = cpu_event[cpu + 1] - 1;
-                else 
+                else
                         e = e - 1;
-                
+
                 /* If there's an event immediately before the first one, this
                  * cpu wrapped its event buffer */
                 if (e->lwte_where == NULL)
                         continue;
-         
+
                 /* We should only start outputting events from the most recent
                  * first event in any wrapped cpu.  Events before this time on
                  * other cpus won't have any events from this CPU to interleave
@@ -1587,20 +1573,20 @@ jt_ptl_lwt(int argc, char **argv)
                         /* no wrapped cpus and this is he first ever event */
                         t0 = next_event[cpu]->lwte_when;
                 }
-                
+
                 if (t0 <= next_event[cpu]->lwte_when) {
                         /* on or after the first event */
                         if (!printed_date) {
-                                cycles_t du = (tnow - t0) / mhz;
+                                cfs_cycles_t du = (tnow - t0) / mhz;
                                 time_t   then = tvnow.tv_sec - du/1000000;
-                                
+
                                 if (du % 1000000 > tvnow.tv_usec)
                                         then--;
 
                                 fprintf(f, "%s", ctime(&then));
                                 printed_date = 1;
                         }
-                        
+
                         rc = lwt_print(f, t0, tlast, mhz, cpu, next_event[cpu]);
                         if (rc != 0)
                                 break;
@@ -1613,7 +1599,7 @@ jt_ptl_lwt(int argc, char **argv)
                 }
 
                 tlast = next_event[cpu]->lwte_when;
-                
+
                 next_event[cpu]++;
                 if (next_event[cpu] == cpu_event[cpu + 1])
                         next_event[cpu] = cpu_event[cpu];
@@ -1640,7 +1626,7 @@ int jt_ptl_memhog(int argc, char **argv)
         int                       rc;
         int                       count;
         char                     *end;
-        
+
         if (argc < 2)  {
                 fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
                 return 0;
@@ -1660,7 +1646,7 @@ int jt_ptl_memhog(int argc, char **argv)
                 }
                 gfp = rc;
         }
-        
+
         LIBCFS_IOC_INIT(data);
         data.ioc_count = count;
         data.ioc_flags = gfp;
@@ -1670,7 +1656,7 @@ int jt_ptl_memhog(int argc, char **argv)
                 fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
                 return -1;
         }
-        
+
         printf("memhog %d OK\n", count);
         return 0;
 }