/* -*- 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 2008 Sun Microsystems, Inc. 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>
-#include "ioctl.h"
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <time.h>
-#include <stdarg.h>
-#include <endian.h>
-#if CRAY_PORTALS
-#ifdef REDSTORM
-#define __QK__
-#endif
-#include <portals/ipmap.h>
-#endif
+#include <libcfs/libcfsutil.h>
+#include <lnet/api-support.h>
+#include <lnet/lnetctl.h>
+#include <lnet/socklnd.h>
-#ifdef __CYGWIN__
+unsigned int libcfs_debug;
+unsigned int libcfs_printk = D_CANTMASK;
-#include <netinet/in.h>
-
-#endif /* __CYGWIN__ */
-
-#include <portals/api-support.h>
-#include <portals/ptlctl.h>
-#include <portals/list.h>
-#include <portals/lib-types.h>
-#include <portals/socknal.h>
-#include "parser.h"
-
-unsigned int portal_debug;
-unsigned int portal_printk;
-
-static unsigned int g_nal = 0;
-
-typedef struct
-{
- char *name;
- int num;
-} name2num_t;
-
-static name2num_t nalnames[] = {
- {"any", 0},
-#if !CRAY_PORTALS
- {"tcp", SOCKNAL},
- {"elan", QSWNAL},
- {"gm", GMNAL},
- {"openib", OPENIBNAL},
- {"iib", IIBNAL},
- {"lo", LONAL},
-#else
- {"cray_kern_nal", CRAY_KERN_NAL},
- {"cray_user_nal", CRAY_USER_NAL},
- {"cray_qk_nal", CRAY_QK_NAL},
-#endif
- {NULL, -1}
-};
-
-static cfg_record_cb_t g_record_cb;
+static int g_net_set;
+static __u32 g_net;
/* Convert a string boolean to an int; "enable" -> 1 */
-int ptl_parse_bool (int *b, char *str) {
+int
+lnet_parse_bool (int *b, char *str)
+{
if (!strcasecmp (str, "no") ||
!strcasecmp (str, "n") ||
!strcasecmp (str, "off") ||
*b = 0;
return (0);
}
-
+
if (!strcasecmp (str, "yes") ||
!strcasecmp (str, "y") ||
!strcasecmp (str, "on") ||
*b = 1;
return (0);
}
-
- return (-1);
-}
-
-/* Convert human readable size string to and int; "1k" -> 1000 */
-int ptl_parse_size (int *sizep, char *str) {
- int size;
- char mod[32];
-
- switch (sscanf (str, "%d%1[gGmMkK]", &size, mod)) {
- default:
- return (-1);
-
- case 1:
- *sizep = size;
- return (0);
-
- case 2:
- switch (*mod) {
- case 'g':
- case 'G':
- *sizep = size << 30;
- return (0);
-
- case 'm':
- case 'M':
- *sizep = size << 20;
- return (0);
-
- case 'k':
- case 'K':
- *sizep = size << 10;
- return (0);
-
- default:
- *sizep = size;
- return (0);
- }
- }
-}
-int
-ptl_set_cfg_record_cb(cfg_record_cb_t cb)
-{
- g_record_cb = cb;
- return 0;
-}
-
-int
-pcfg_ioctl(struct portals_cfg *pcfg)
-{
- int rc;
-
- if (pcfg->pcfg_nal ==0)
- pcfg->pcfg_nal = g_nal;
-
- if (g_record_cb) {
- rc = g_record_cb(PORTALS_CFG_TYPE, sizeof(*pcfg), pcfg);
- } else {
- struct portal_ioctl_data data;
- PORTAL_IOC_INIT (data);
- data.ioc_pbuf1 = (char*)pcfg;
- data.ioc_plen1 = sizeof(*pcfg);
- /* XXX liblustre hack XXX */
- data.ioc_nal_cmd = pcfg->pcfg_command;
- data.ioc_nid = pcfg->pcfg_nid;
-
- rc = l_ioctl (PORTALS_DEV_ID, IOC_PORTAL_NAL_CMD, &data);
- }
-
- return (rc);
-}
-
-
-
-static name2num_t *
-name2num_lookup_name (name2num_t *table, char *str)
-{
- while (table->name != NULL)
- if (!strcmp (str, table->name))
- return (table);
- else
- table++;
- return (NULL);
-}
-
-static name2num_t *
-name2num_lookup_num (name2num_t *table, int num)
-{
- while (table->name != NULL)
- if (num == table->num)
- return (table);
- else
- table++;
- return (NULL);
+ return (-1);
}
int
-ptl_name2nal (char *str)
+lnet_parse_port (int *port, char *str)
{
- name2num_t *e = name2num_lookup_name (nalnames, str);
+ char *end;
- return ((e == NULL) ? -1 : e->num);
-}
+ *port = strtol (str, &end, 0);
-static char *
-nal2name (int nal)
-{
- name2num_t *e = name2num_lookup_num (nalnames, nal);
+ if (*end == 0 && /* parsed whole string */
+ *port > 0 && *port < 65536) /* minimal sanity check */
+ return (0);
- return ((e == NULL) ? "???" : e->name);
+ return (-1);
}
#ifdef HAVE_GETHOSTBYNAME
hname);
break;
default:
- fprintf(stderr, "gethostbyname error: %s\n",
- strerror(errno));
+ fprintf(stderr, "gethostbyname error for %s: %s\n",
+ hname, strerror(h_errno));
break;
}
return NULL;
#endif
int
-ptl_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);
-}
-
-int
-ptl_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_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
-ptl_parse_ipquad (__u32 *ipaddrp, char *str)
+lnet_parse_ipquad (__u32 *ipaddrp, char *str)
{
int a;
int b;
}
int
-ptl_parse_ipaddr (__u32 *ipaddrp, char *str)
+lnet_parse_ipaddr (__u32 *ipaddrp, char *str)
{
#ifdef HAVE_GETHOSTBYNAME
struct hostent *he;
#endif
- if (!strcmp (str, "_all_"))
- {
+ if (!strcmp (str, "_all_")) {
*ipaddrp = 0;
return (0);
}
- if (ptl_parse_ipquad(ipaddrp, str) == 0)
+ if (lnet_parse_ipquad(ipaddrp, str) == 0)
return (0);
-#if HAVE_GETHOSTBYNAME
+#ifdef HAVE_GETHOSTBYNAME
if ((('a' <= str[0] && str[0] <= 'z') ||
('A' <= str[0] && str[0] <= 'Z')) &&
- (he = ptl_gethostbyname (str)) != NULL)
- {
+ (he = ptl_gethostbyname (str)) != NULL) {
__u32 addr = *(__u32 *)he->h_addr;
*ipaddrp = ntohl(addr); /* HOST byte order */
}
int
-ptl_parse_nid (ptl_nid_t *nidp, char *str)
+lnet_parse_time (time_t *t, char *str)
{
- __u32 ipaddr;
- char *end;
- unsigned long long ullval;
-
- if (!strcmp (str, "_all_")) {
- *nidp = PTL_NID_ANY;
- return (0);
- }
-
- if (ptl_parse_ipaddr (&ipaddr, str) == 0) {
-#if !CRAY_PORTALS
- *nidp = (ptl_nid_t)ipaddr;
-#else
- *nidp = (((ptl_nid_t)ipaddr & PNAL_HOSTID_MASK) << PNAL_VNODE_SHIFT);
-#endif
- return (0);
- }
+ char *end;
+ int n;
+ struct tm tm;
- ullval = strtoull(str, &end, 0);
- if (*end == 0) {
- /* parsed whole string */
- *nidp = (ptl_nid_t)ullval;
+ *t = strtol (str, &end, 0);
+ if (*end == 0) /* parsed whole string */
return (0);
- }
-
- return (-1);
-}
-__u64 ptl_nid2u64(ptl_nid_t nid)
-{
- switch (sizeof (nid)) {
- case 8:
- return (nid);
- case 4:
- return ((__u32)nid);
- default:
- fprintf(stderr, "Unexpected sizeof(ptl_nid_t) == %u\n", sizeof(nid));
- abort();
- /* notreached */
+ 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_hour, &tm.tm_min, &tm.tm_sec);
+ if (n != 6)
return (-1);
- }
-}
-char *
-ptl_nid2str (char *buffer, ptl_nid_t nid)
-{
- __u64 nid64 = ptl_nid2u64(nid);
-#ifdef HAVE_GETHOSTBYNAME
- struct hostent *he = 0;
-
- /* Don't try to resolve NIDs that are e.g. Elan host IDs. Assume
- * TCP addresses in the 0.x.x.x subnet are not in use. This can
- * happen on routers and slows things down a _lot_. Bug 3442. */
- if (nid & 0xff000000) {
- __u32 addr = htonl((__u32)nid); /* back to NETWORK byte order */
-
- he = gethostbyaddr ((const char *)&addr, sizeof (addr), AF_INET);
- }
+ tm.tm_mon--; /* convert to 0 == Jan */
+ tm.tm_year -= 1900; /* y2k quirk */
+ tm.tm_isdst = -1; /* dunno if it's daylight savings... */
- if (he != NULL)
- sprintf(buffer, "%#x:%s", (int)(nid64 >> 32), he->h_name);
- else
-#endif /* HAVE_GETHOSTBYNAME */
- sprintf(buffer, LPX64, nid64);
+ *t = mktime (&tm);
+ if (*t == (time_t)-1)
+ return (-1);
- return (buffer);
+ return (0);
}
-int g_nal_is_set ()
+int g_net_is_set (char *cmd)
{
- if (g_nal == 0) {
- fprintf (stderr, "Error: you must run the 'network' command first.\n");
- return (0);
- }
+ if (g_net_set)
+ return 1;
- return (1);
+ if (cmd != NULL)
+ fprintf(stderr,
+ "You must run the 'network' command before '%s'.\n",
+ cmd);
+ return 0;
}
-int g_nal_is_compatible (char *cmd, ...)
+int g_net_is_compatible (char *cmd, ...)
{
va_list ap;
int nal;
- if (!g_nal_is_set ())
- return (0);
+ if (!g_net_is_set(cmd))
+ return 0;
- va_start (ap, cmd);
+ va_start(ap, cmd);
do {
nal = va_arg (ap, int);
- } while (nal != 0 && nal != g_nal);
-
+ if (nal == LNET_NETTYP(g_net)) {
+ va_end (ap);
+ return 1;
+ }
+ } while (nal != 0);
+
va_end (ap);
-
- if (g_nal == nal)
- return (1);
- if (cmd != NULL) {
- /* Don't complain verbosely if we've not been passed a command
- * name to complain about! */
- fprintf (stderr, "Command %s not compatible with nal %s\n",
- cmd, nal2name (g_nal));
- }
- return (0);
+ if (cmd != NULL)
+ fprintf (stderr,
+ "Command %s not compatible with %s NAL\n",
+ cmd,
+ libcfs_lnd2str(LNET_NETTYP(g_net)));
+ return 0;
}
-int
-sock_write (int cfd, void *buffer, int nob)
+int ptl_initialize(int argc, char **argv)
{
- while (nob > 0)
- {
- int rc = write (cfd, buffer, nob);
+ register_ioc_dev(LNET_DEV_ID, LNET_DEV_PATH,
+ LNET_DEV_MAJOR, LNET_DEV_MINOR);
+ return 0;
+}
- if (rc < 0)
- {
- if (errno == EINTR)
- continue;
-
- return (rc);
+
+int jt_ptl_network(int argc, char **argv)
+{
+ struct libcfs_ioctl_data data;
+ __u32 net = LNET_NIDNET(LNET_NID_ANY);
+ int rc;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <net>|up|down\n", argv[0]);
+ return 0;
+ }
+
+ if (!strcmp(argv[1], "unconfigure") ||
+ !strcmp(argv[1], "down")) {
+ LIBCFS_IOC_INIT(data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_UNCONFIGURE, &data);
+
+ if (rc == 0) {
+ printf ("LNET ready to unload\n");
+ return 0;
}
- if (rc == 0)
- {
- fprintf (stderr, "Unexpected zero sock_write\n");
- abort();
+ if (errno == EBUSY)
+ fprintf(stderr, "LNET busy\n");
+ else
+ fprintf(stderr, "LNET unconfigure error %d: %s\n",
+ errno, strerror(errno));
+ return -1;
+ }
+
+ if (!strcmp(argv[1], "configure") ||
+ !strcmp(argv[1], "up")) {
+ LIBCFS_IOC_INIT(data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_CONFIGURE, &data);
+
+ if (rc == 0) {
+ printf ("LNET configured\n");
+ return 0;
}
- nob -= rc;
- buffer = (char *)buffer + nob;
+ fprintf(stderr, "LNET configure error %d: %s\n",
+ errno, strerror(errno));
+ return -1;
}
-
- return (0);
+
+ net = libcfs_str2net(argv[1]);
+ if (net == LNET_NIDNET(LNET_NID_ANY)) {
+ fprintf(stderr, "Can't parse net %s\n", argv[1]);
+ return -1;
+ }
+
+ g_net_set = 1;
+ g_net = net;
+ return 0;
}
int
-sock_read (int cfd, void *buffer, int nob)
+jt_ptl_list_nids(int argc, char **argv)
{
- while (nob > 0)
- {
- int rc = read (cfd, buffer, nob);
-
- if (rc < 0)
- {
- if (errno == EINTR)
- continue;
-
- return (rc);
+ struct libcfs_ioctl_data data;
+ int all = 0, return_nid = 0;
+ int count;
+ int rc;
+
+ all = (argc == 2) && (strcmp(argv[1], "all") == 0);
+ /* Hack to pass back value */
+ return_nid = (argc == 2) && (argv[1][0] == 1);
+
+ if ((argc > 2) && !(all || return_nid)) {
+ fprintf(stderr, "usage: %s [all]\n", argv[0]);
+ return 0;
+ }
+
+ for (count = 0;; count++) {
+ 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 */
+ break;
+ fprintf(stderr,"IOC_LIBCFS_GET_NI error %d: %s\n",
+ errno, strerror(errno));
+ return -1;
}
-
- if (rc == 0) /* EOF */
- {
- errno = ECONNABORTED;
- return (-1);
+
+ if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) {
+ printf("%s\n", libcfs_nid2str(data.ioc_nid));
+ if (return_nid) {
+ *(__u64 *)(argv[1]) = data.ioc_nid;
+ return_nid--;
+ }
}
-
- nob -= rc;
- buffer = (char *)buffer + nob;
}
-
- return (0);
-}
-int ptl_initialize(int argc, char **argv)
-{
- register_ioc_dev(PORTALS_DEV_ID, PORTALS_DEV_PATH);
return 0;
}
-
-int jt_ptl_network(int argc, char **argv)
+int
+jt_ptl_which_nid (int argc, char **argv)
{
- name2num_t *entry;
- int nal;
-
- if (argc == 2 &&
- (nal = ptl_name2nal (argv[1])) >= 0) {
- g_nal = nal;
- return (0);
+ struct libcfs_ioctl_data data;
+ int best_dist = 0;
+ int best_order = 0;
+ lnet_nid_t best_nid = LNET_NID_ANY;
+ int dist;
+ int order;
+ lnet_nid_t nid;
+ char *nidstr;
+ int rc;
+ int i;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
+ return 0;
}
-
- fprintf(stderr, "usage: %s \n", argv[0]);
- for (entry = nalnames; entry->name != NULL; entry++)
- fprintf (stderr, "%s%s", entry == nalnames ? "<" : "|", entry->name);
- fprintf(stderr, ">\n");
- return (-1);
+
+ for (i = 1; i < argc; i++) {
+ nidstr = argv[i];
+ nid = libcfs_str2nid(nidstr);
+ if (nid == LNET_NID_ANY) {
+ 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",
+ nidstr, strerror(errno));
+ return -1;
+ }
+
+ dist = data.ioc_u32[0];
+ order = data.ioc_u32[1];
+
+ 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)) {
+ best_dist = dist;
+ best_order = order;
+ best_nid = nid;
+ }
+ }
+
+ if (best_nid == LNET_NID_ANY) {
+ fprintf(stderr, "No reachable NID\n");
+ return -1;
+ }
+
+ printf("%s\n", libcfs_nid2str(best_nid));
+ return 0;
}
int
jt_ptl_print_interfaces (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
char buffer[3][64];
int index;
int rc;
- if (!g_nal_is_compatible (argv[0], SOCKNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, 0))
return -1;
for (index = 0;;index++) {
- PCFG_INIT (pcfg, NAL_CMD_GET_INTERFACE);
- pcfg.pcfg_count = index;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_count = index;
- rc = pcfg_ioctl (&pcfg);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_INTERFACE, &data);
if (rc != 0)
break;
printf ("%s: (%s/%s) npeer %d nroute %d\n",
- ptl_ipaddr_2_str(pcfg.pcfg_id, buffer[2], 1),
- ptl_ipaddr_2_str(pcfg.pcfg_id, buffer[0], 0),
- ptl_ipaddr_2_str(pcfg.pcfg_misc, buffer[1], 0),
- pcfg.pcfg_fd, pcfg.pcfg_count);
+ ptl_ipaddr_2_str(data.ioc_u32[0], buffer[2], 1),
+ ptl_ipaddr_2_str(data.ioc_u32[0], buffer[0], 0),
+ ptl_ipaddr_2_str(data.ioc_u32[1], buffer[1], 0),
+ data.ioc_u32[2], data.ioc_u32[3]);
+ }
+
+ if (index == 0) {
+ if (errno == ENOENT) {
+ printf ("<no interfaces>\n");
+ } else {
+ fprintf(stderr, "Error getting interfaces: %s: "
+ "check dmesg.\n",
+ strerror(errno));
+ }
}
- if (index == 0)
- printf ("<no interfaces>\n");
return 0;
}
int
jt_ptl_add_interface (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
__u32 ipaddr;
int rc;
__u32 netmask = 0xffffff00;
return 0;
}
- if (!g_nal_is_compatible(argv[0], SOCKNAL, 0))
+ if (!g_net_is_compatible(argv[0], SOCKLND, 0))
return -1;
- if (ptl_parse_ipaddr(&ipaddr, argv[1]) != 0) {
+ if (lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
return -1;
}
netmask = 0;
for (i = count; i > 0; i--)
netmask = netmask|(1<<(32-i));
- } else if (ptl_parse_ipquad(&netmask, argv[2]) != 0) {
+ } else if (lnet_parse_ipquad(&netmask, argv[2]) != 0) {
fprintf (stderr, "Can't parse netmask: %s\n", argv[2]);
return -1;
}
}
- PCFG_INIT(pcfg, NAL_CMD_ADD_INTERFACE);
- pcfg.pcfg_id = ipaddr;
- pcfg.pcfg_misc = netmask;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_u32[0] = ipaddr;
+ data.ioc_u32[1] = netmask;
- rc = pcfg_ioctl (&pcfg);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_INTERFACE, &data);
if (rc != 0) {
fprintf (stderr, "failed to add interface: %s\n",
strerror (errno));
int
jt_ptl_del_interface (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
int rc;
__u32 ipaddr = 0;
return 0;
}
- if (!g_nal_is_compatible(argv[0], SOCKNAL, 0))
+ if (!g_net_is_compatible(argv[0], SOCKLND, 0))
return -1;
if (argc == 2 &&
- ptl_parse_ipaddr(&ipaddr, argv[1]) != 0) {
+ lnet_parse_ipaddr(&ipaddr, argv[1]) != 0) {
fprintf (stderr, "Can't parse ip: %s\n", argv[1]);
return -1;
}
-
- PCFG_INIT(pcfg, NAL_CMD_DEL_INTERFACE);
- pcfg.pcfg_id = ipaddr;
- rc = pcfg_ioctl (&pcfg);
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_u32[0] = ipaddr;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_INTERFACE, &data);
if (rc != 0) {
fprintf (stderr, "failed to delete interface: %s\n",
strerror (errno));
int
jt_ptl_print_peers (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
+ lnet_process_id_t id;
char buffer[2][64];
int index;
int rc;
- if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND, PTLLND, MXLND,
+ OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return -1;
for (index = 0;;index++) {
- PCFG_INIT (pcfg, NAL_CMD_GET_PEER);
- pcfg.pcfg_count = index;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_count = index;
- rc = pcfg_ioctl (&pcfg);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_PEER, &data);
if (rc != 0)
break;
- if (g_nal_is_compatible(NULL, SOCKNAL, 0))
- printf (LPX64"[%d]%s@%s:%d #%d\n",
- pcfg.pcfg_nid, pcfg.pcfg_wait,
- ptl_ipaddr_2_str (pcfg.pcfg_size, buffer[0], 1),
- ptl_ipaddr_2_str (pcfg.pcfg_id, buffer[1], 1),
- pcfg.pcfg_misc, pcfg.pcfg_count);
- else
- printf (LPX64"[%d]\n",
- pcfg.pcfg_nid, pcfg.pcfg_wait);
+ if (g_net_is_compatible(NULL, SOCKLND, 0)) {
+ id.nid = data.ioc_nid;
+ id.pid = data.ioc_u32[4];
+ printf ("%-20s [%d]%s->%s:%d #%d\n",
+ libcfs_id2str(id),
+ data.ioc_count, /* persistence */
+ ptl_ipaddr_2_str (data.ioc_u32[2], buffer[0], 1), /* my ip */
+ ptl_ipaddr_2_str (data.ioc_u32[0], buffer[1], 1), /* peer ip */
+ data.ioc_u32[1], /* peer port */
+ data.ioc_u32[3]); /* conn_count */
+ } else if (g_net_is_compatible(NULL, PTLLND, 0)) {
+ id.nid = data.ioc_nid;
+ id.pid = data.ioc_u32[4];
+ printf ("%-20s s %d%s [%d] "LPD64".%06d"
+ " m "LPD64"/"LPD64" q %d/%d c %d/%d\n",
+ libcfs_id2str(id),
+ data.ioc_net, /* state */
+ data.ioc_flags ? "" : " ~!h", /* sent_hello */
+ data.ioc_count, /* refcount */
+ data.ioc_u64[0]/1000000, /* incarnation secs */
+ (int)(data.ioc_u64[0]%1000000), /* incarnation usecs */
+ (((__u64)data.ioc_u32[1])<<32) |
+ ((__u64)data.ioc_u32[0]), /* next_matchbits */
+ (((__u64)data.ioc_u32[3])<<32) |
+ ((__u64)data.ioc_u32[2]), /* last_matchbits_seen */
+ data.ioc_u32[5] >> 16, /* nsendq */
+ 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)) {
+ printf ("%-20s [%d]@%s:%d\n",
+ libcfs_nid2str(data.ioc_nid), /* peer nid */
+ data.ioc_count, /* peer persistence */
+ ptl_ipaddr_2_str (data.ioc_u32[0], buffer[1], 1), /* peer ip */
+ data.ioc_u32[1]); /* peer port */
+ } else {
+ printf ("%-20s [%d]\n",
+ libcfs_nid2str(data.ioc_nid), data.ioc_count);
+ }
}
- if (index == 0)
- printf ("<no peers>\n");
+ if (index == 0) {
+ if (errno == ENOENT) {
+ printf ("<no peers>\n");
+ } else {
+ fprintf(stderr, "Error getting peer list: %s: "
+ "check dmesg.\n",
+ strerror(errno));
+ }
+ }
return 0;
}
-int
+int
jt_ptl_add_peer (int argc, char **argv)
{
- struct portals_cfg pcfg;
- ptl_nid_t nid;
+ struct libcfs_ioctl_data data;
+ lnet_nid_t nid;
__u32 ip = 0;
int port = 0;
int rc;
- if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
+ OPENIBLND, CIBLND, IIBLND, VIBLND, 0))
return -1;
- if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
+ if (g_net_is_compatible(NULL, SOCKLND, OPENIBLND, CIBLND, RALND, 0)) {
if (argc != 4) {
- fprintf (stderr, "usage(tcp): %s nid ipaddr port\n",
+ 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(openib,iib): %s nid\n", argv[0]);
+ fprintf (stderr, "usage(iib): %s nid\n", argv[0]);
return 0;
}
- if (ptl_parse_nid (&nid, argv[1]) != 0 ||
- nid == PTL_NID_ANY) {
+ nid = libcfs_str2nid(argv[1]);
+ if (nid == LNET_NID_ANY) {
fprintf (stderr, "Can't parse NID: %s\n", argv[1]);
return -1;
}
- if (g_nal_is_compatible (NULL, SOCKNAL, 0)) {
- if (ptl_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, VIBLND, RALND, 0) &&
+ lnet_parse_ipaddr (&ip, argv[2]) != 0) {
+ fprintf (stderr, "Can't parse ip addr: %s\n", argv[2]);
+ return -1;
+ }
- if (ptl_parse_port (&port, argv[3]) != 0) {
- fprintf (stderr, "Can't parse port: %s\n", argv[3]);
- return -1;
- }
+ if (g_net_is_compatible (NULL, SOCKLND, OPENIBLND, CIBLND, RALND, 0) &&
+ lnet_parse_port (&port, argv[3]) != 0) {
+ fprintf (stderr, "Can't parse port: %s\n", argv[3]);
+ return -1;
}
- PCFG_INIT(pcfg, NAL_CMD_ADD_PEER);
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_id = ip;
- pcfg.pcfg_misc = port;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_nid = nid;
+ data.ioc_u32[0] = ip;
+ data.ioc_u32[1] = port;
- rc = pcfg_ioctl (&pcfg);
+ rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_ADD_PEER, &data);
if (rc != 0) {
fprintf (stderr, "failed to add peer: %s\n",
strerror (errno));
return -1;
}
-
+
return 0;
}
-int
+int
jt_ptl_del_peer (int argc, char **argv)
{
- struct portals_cfg pcfg;
- ptl_nid_t nid = PTL_NID_ANY;
+ struct libcfs_ioctl_data data;
+ lnet_nid_t nid = LNET_NID_ANY;
+ lnet_pid_t pid = LNET_PID_ANY;
__u32 ip = 0;
- int single_share = 0;
- int argidx;
+ char *end;
int rc;
- if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, PTLLND,
+ OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return -1;
- if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
- if (argc > 4) {
- fprintf (stderr, "usage: %s [nid] [ipaddr] [single_share]\n",
+ if (g_net_is_compatible(NULL, SOCKLND, 0)) {
+ if (argc > 3) {
+ fprintf (stderr, "usage: %s [nid] [ipaddr]\n",
argv[0]);
return 0;
}
- } else if (argc > 3) {
- fprintf (stderr, "usage: %s [nid] [single_share]\n", argv[0]);
+ } else if (g_net_is_compatible(NULL, PTLLND, 0)) {
+ if (argc > 3) {
+ fprintf (stderr, "usage: %s [nid] [pid]\n",
+ argv[0]);
+ return 0;
+ }
+ } else if (argc > 2) {
+ fprintf (stderr, "usage: %s [nid]\n", argv[0]);
return 0;
}
-
+
if (argc > 1 &&
- ptl_parse_nid (&nid, argv[1]) != 0) {
+ !libcfs_str2anynid(&nid, argv[1])) {
fprintf (stderr, "Can't parse nid: %s\n", argv[1]);
return -1;
}
- argidx = 2;
- if (g_nal_is_compatible(NULL, SOCKNAL, 0)) {
- if (argc > argidx &&
- ptl_parse_ipaddr (&ip, argv[argidx]) != 0) {
+ if (g_net_is_compatible(NULL, SOCKLND, 0)) {
+ if (argc > 2 &&
+ lnet_parse_ipaddr (&ip, argv[2]) != 0) {
fprintf (stderr, "Can't parse ip addr: %s\n",
- argv[argidx]);
+ argv[2]);
return -1;
}
- argidx++;
- }
-
- if (argc > argidx) {
- if (!strcmp (argv[argidx], "single_share")) {
- single_share = 1;
- } else {
- fprintf (stderr, "Unrecognised arg %s'\n", argv[3]);
- return -1;
+ } else if (g_net_is_compatible(NULL, PTLLND, 0)) {
+ if (argc > 2) {
+ pid = strtol(argv[2], &end, 0);
+ if (end == argv[2] || *end == 0) {
+ fprintf(stderr, "Can't parse pid %s\n",
+ argv[2]);
+ return -1;
+ }
}
}
- PCFG_INIT(pcfg, NAL_CMD_DEL_PEER);
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_id = ip;
- pcfg.pcfg_flags = single_share;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_nid = nid;
+ data.ioc_u32[0] = ip;
+ data.ioc_u32[1] = pid;
- rc = pcfg_ioctl (&pcfg);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_PEER, &data);
if (rc != 0) {
fprintf (stderr, "failed to remove peer: %s\n",
strerror (errno));
return -1;
}
-
+
return 0;
}
-int
+int
jt_ptl_print_connections (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
+ lnet_process_id_t id;
char buffer[2][64];
int index;
int rc;
- if (!g_nal_is_compatible (argv[0], SOCKNAL, OPENIBNAL, IIBNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
+ OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return -1;
- for (index = 0;;index++) {
- PCFG_INIT (pcfg, NAL_CMD_GET_CONN);
- pcfg.pcfg_count = index;
-
- rc = pcfg_ioctl (&pcfg);
+ 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_CONN, &data);
if (rc != 0)
break;
- if (g_nal_is_compatible (NULL, SOCKNAL, 0))
- printf ("[%d]%s:"LPX64"@%s:%d:%s %d/%d %s\n",
- pcfg.pcfg_gw_nal, /* scheduler */
- ptl_ipaddr_2_str (pcfg.pcfg_fd, buffer[0], 1), /* local IP addr */
- pcfg.pcfg_nid,
- ptl_ipaddr_2_str (pcfg.pcfg_id, buffer[1], 1), /* remote IP addr */
- pcfg.pcfg_misc, /* remote port */
- (pcfg.pcfg_flags == SOCKNAL_CONN_ANY) ? "A" :
- (pcfg.pcfg_flags == SOCKNAL_CONN_CONTROL) ? "C" :
- (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_IN) ? "I" :
- (pcfg.pcfg_flags == SOCKNAL_CONN_BULK_OUT) ? "O" : "?",
- pcfg.pcfg_count, /* tx buffer size */
- pcfg.pcfg_size, /* rx buffer size */
- pcfg.pcfg_wait ? "nagle" : "nonagle");
- else
- printf (LPX64"\n",
- pcfg.pcfg_nid);
- }
-
- if (index == 0)
- printf ("<no connections>\n");
- return 0;
-}
-
-int jt_ptl_connect(int argc, char **argv)
-{
-#ifndef HAVE_CONNECT
- /* no connect() support */
- return -1;
-#else /* HAVE_CONNECT */
- struct portals_cfg pcfg;
- struct sockaddr_in srvaddr;
- struct sockaddr_in locaddr;
- __u32 ipaddr;
- char *flag;
- int fd, rc;
- int type = SOCKNAL_CONN_ANY;
- int port, rport;
- int o;
-
- if (argc < 3) {
- fprintf(stderr, "usage: %s ip port [type]\n", argv[0]);
- return 0;
- }
-
- if (!g_nal_is_compatible (argv[0], SOCKNAL, 0))
- return -1;
-
- rc = ptl_parse_ipaddr (&ipaddr, argv[1]);
- if (rc != 0) {
- fprintf(stderr, "Can't parse hostname: %s\n", argv[1]);
- return -1;
- }
-
- if (ptl_parse_port (&port, argv[2]) != 0) {
- fprintf (stderr, "Can't parse port: %s\n", argv[2]);
- return -1;
- }
-
- if (argc > 3)
- for (flag = argv[3]; *flag != 0; flag++)
- switch (*flag)
- {
- case 'I':
- if (type != SOCKNAL_CONN_ANY) {
- fprintf(stderr, "Can't flag type twice\n");
- return -1;
- }
- type = SOCKNAL_CONN_BULK_IN;
- break;
-
- case 'O':
- if (type != SOCKNAL_CONN_ANY) {
- fprintf(stderr, "Can't flag type twice\n");
- return -1;
- }
- type = SOCKNAL_CONN_BULK_OUT;
- break;
-
- case 'C':
- if (type != SOCKNAL_CONN_ANY) {
- fprintf(stderr, "Can't flag type twice\n");
- return -1;
- }
- type = SOCKNAL_CONN_CONTROL;
- break;
-
- default:
- fprintf (stderr, "unrecognised flag '%c'\n",
- *flag);
- return (-1);
- }
-
- memset(&locaddr, 0, sizeof(locaddr));
- locaddr.sin_family = AF_INET;
- locaddr.sin_addr.s_addr = INADDR_ANY;
-
- memset(&srvaddr, 0, sizeof(srvaddr));
- srvaddr.sin_family = AF_INET;
- srvaddr.sin_port = htons(port);
- srvaddr.sin_addr.s_addr = htonl(ipaddr);
-
-
- for (rport = IPPORT_RESERVED - 1; rport > IPPORT_RESERVED / 2; --rport) {
- fd = socket(PF_INET, SOCK_STREAM, 0);
- if ( fd < 0 ) {
- fprintf(stderr, "socket() failed: %s\n", strerror(errno));
- return -1;
- }
-
- o = 1;
- rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,
- &o, sizeof(o));
-
- locaddr.sin_port = htons(rport);
- rc = bind(fd, (struct sockaddr *)&locaddr, sizeof(locaddr));
- if (rc == 0 || errno == EACCES) {
- rc = connect(fd, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
- if (rc == 0) {
- break;
- } else if (errno != EADDRINUSE) {
- fprintf(stderr, "Error connecting to host: %s\n", strerror(errno));
- close(fd);
- return -1;
- }
- } else if (errno != EADDRINUSE) {
- fprintf(stderr, "Error binding to port %d: %d: %s\n", port, errno, strerror(errno));
- close(fd);
- return -1;
+ if (g_net_is_compatible (NULL, SOCKLND, 0)) {
+ id.nid = data.ioc_nid;
+ id.pid = data.ioc_u32[6];
+ printf ("%-20s %s[%d]%s->%s:%d %d/%d %s\n",
+ libcfs_id2str(id),
+ (data.ioc_u32[3] == SOCKLND_CONN_ANY) ? "A" :
+ (data.ioc_u32[3] == SOCKLND_CONN_CONTROL) ? "C" :
+ (data.ioc_u32[3] == SOCKLND_CONN_BULK_IN) ? "I" :
+ (data.ioc_u32[3] == SOCKLND_CONN_BULK_OUT) ? "O" : "?",
+ data.ioc_u32[4], /* scheduler */
+ ptl_ipaddr_2_str (data.ioc_u32[2], buffer[0], 1), /* local IP addr */
+ ptl_ipaddr_2_str (data.ioc_u32[0], buffer[1], 1), /* remote IP addr */
+ data.ioc_u32[1], /* remote port */
+ data.ioc_count, /* tx buffer size */
+ data.ioc_u32[5], /* rx buffer size */
+ data.ioc_flags ? "nagle" : "nonagle");
+ } else if (g_net_is_compatible (NULL, RALND, 0)) {
+ 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));
}
}
- if (rport == IPPORT_RESERVED / 2) {
- fprintf(stderr,
- "Warning: all privileged ports are in use.\n");
- return -1;
- }
-
- printf("Connected host: %s type: %s\n",
- argv[1],
- (type == SOCKNAL_CONN_ANY) ? "A" :
- (type == SOCKNAL_CONN_CONTROL) ? "C" :
- (type == SOCKNAL_CONN_BULK_IN) ? "I" :
- (type == SOCKNAL_CONN_BULK_OUT) ? "O" : "?");
-
- PCFG_INIT(pcfg, NAL_CMD_REGISTER_PEER_FD);
- pcfg.pcfg_nal = g_nal;
- pcfg.pcfg_fd = fd;
- pcfg.pcfg_misc = type;
-
- rc = pcfg_ioctl(&pcfg);
- if (rc) {
- fprintf(stderr, "failed to register fd with portals: %s\n",
- strerror(errno));
- close (fd);
- return -1;
+ if (index == 0) {
+ if (errno == ENOENT) {
+ printf ("<no connections>\n");
+ } else {
+ fprintf(stderr, "Error getting connection list: %s: "
+ "check dmesg.\n",
+ strerror(errno));
+ }
}
-
- printf("Connection to %s registered with socknal\n", argv[1]);
-
- rc = close(fd);
- if (rc)
- fprintf(stderr, "close failed: %d\n", rc);
-
return 0;
-#endif /* HAVE_CONNECT */
}
int jt_ptl_disconnect(int argc, char **argv)
{
- struct portals_cfg pcfg;
- ptl_nid_t nid = PTL_NID_ANY;
+ struct libcfs_ioctl_data data;
+ lnet_nid_t nid = LNET_NID_ANY;
__u32 ipaddr = 0;
int rc;
return 0;
}
- if (!g_nal_is_compatible (NULL, SOCKNAL, OPENIBNAL, IIBNAL, 0))
+ if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND,
+ OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return 0;
if (argc >= 2 &&
- ptl_parse_nid (&nid, argv[1]) != 0) {
+ !libcfs_str2anynid(&nid, argv[1])) {
fprintf (stderr, "Can't parse nid %s\n", argv[1]);
return -1;
}
- if (g_nal_is_compatible (NULL, SOCKNAL, 0) &&
+ if (g_net_is_compatible (NULL, SOCKLND, 0) &&
argc >= 3 &&
- ptl_parse_ipaddr (&ipaddr, argv[2]) != 0) {
+ lnet_parse_ipaddr (&ipaddr, argv[2]) != 0) {
fprintf (stderr, "Can't parse ip addr %s\n", argv[2]);
return -1;
}
- PCFG_INIT(pcfg, NAL_CMD_CLOSE_CONNECTION);
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_id = ipaddr;
-
- rc = pcfg_ioctl(&pcfg);
- if (rc) {
+ LIBCFS_IOC_INIT(data);
+ 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",
strerror(errno));
return -1;
int jt_ptl_push_connection (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
int rc;
- ptl_nid_t nid = PTL_NID_ANY;
- __u32 ipaddr = 0;
+ lnet_nid_t nid = LNET_NID_ANY;
- if (argc > 3) {
- fprintf(stderr, "usage: %s [nid] [ip]\n", argv[0]);
+ if (argc > 2) {
+ fprintf(stderr, "usage: %s [nid]\n", argv[0]);
return 0;
}
- if (!g_nal_is_compatible (argv[0], SOCKNAL, 0))
+ if (!g_net_is_compatible (argv[0], SOCKLND, 0))
return -1;
-
+
if (argc > 1 &&
- ptl_parse_nid (&nid, argv[1]) != 0) {
+ !libcfs_str2anynid(&nid, argv[1])) {
fprintf(stderr, "Can't parse nid: %s\n", argv[1]);
return -1;
}
-
- if (argc > 2 &&
- ptl_parse_ipaddr (&ipaddr, argv[2]) != 0) {
- fprintf(stderr, "Can't parse ipaddr: %s\n", argv[2]);
- }
- PCFG_INIT(pcfg, NAL_CMD_PUSH_CONNECTION);
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_id = ipaddr;
-
- rc = pcfg_ioctl(&pcfg);
- if (rc) {
+ 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",
strerror(errno));
return -1;
return 0;
}
-int
+int
jt_ptl_print_active_txs (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
int index;
int rc;
- if (!g_nal_is_compatible (argv[0], QSWNAL, 0))
+ if (!g_net_is_compatible (argv[0], QSWLND, 0))
return -1;
for (index = 0;;index++) {
- PCFG_INIT(pcfg, NAL_CMD_GET_TXDESC);
- pcfg.pcfg_count = index;
-
- rc = pcfg_ioctl(&pcfg);
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_count = index;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_TXDESC, &data);
if (rc != 0)
break;
- printf ("%p: %5s payload %6d bytes to "LPX64" via "LPX64" by pid %6d: %s, %s, state %d\n",
- pcfg.pcfg_pbuf1,
- pcfg.pcfg_count == PTL_MSG_ACK ? "ACK" :
- pcfg.pcfg_count == PTL_MSG_PUT ? "PUT" :
- pcfg.pcfg_count == PTL_MSG_GET ? "GET" :
- pcfg.pcfg_count == PTL_MSG_REPLY ? "REPLY" : "<wierd message>",
- pcfg.pcfg_size,
- pcfg.pcfg_nid,
- pcfg.pcfg_nid2,
- pcfg.pcfg_misc,
- (pcfg.pcfg_flags & 1) ? "delayed" : "immediate",
- (pcfg.pcfg_flags & 2) ? "nblk" : "normal",
- pcfg.pcfg_flags >> 2);
- }
-
- if (index == 0)
- printf ("<no active descs>\n");
+ printf ("type %u payload %6d to %s via %s by pid %6d: "
+ "%s, %s, state %d\n",
+ data.ioc_u32[0],
+ data.ioc_count,
+ libcfs_nid2str(data.ioc_nid),
+ libcfs_nid2str(data.ioc_u64[0]),
+ data.ioc_u32[1],
+ (data.ioc_flags & 1) ? "delayed" : "immediate",
+ (data.ioc_flags & 2) ? "nblk" : "normal",
+ data.ioc_flags >> 2);
+ }
+
+ if (index == 0) {
+ if (errno == ENOENT) {
+ printf ("<no active descs>\n");
+ } else {
+ fprintf(stderr, "Error getting active transmits list: "
+ "%s: check dmesg.\n",
+ strerror(errno));
+ }
+ }
return 0;
}
int jt_ptl_ping(int argc, char **argv)
{
- int rc;
- ptl_nid_t nid;
- long count = 1;
- long size = 4;
- long timeout = 1;
- struct portal_ioctl_data data;
+ int rc;
+ int timeout;
+ lnet_process_id_t id;
+ lnet_process_id_t ids[16];
+ int maxids = sizeof(ids)/sizeof(ids[0]);
+ struct libcfs_ioctl_data data;
+ char *sep;
+ int i;
if (argc < 2) {
- fprintf(stderr, "usage: %s nid [count] [size] [timeout (secs)]\n", argv[0]);
+ fprintf(stderr, "usage: %s id [timeout (secs)]\n", argv[0]);
return 0;
}
- if (!g_nal_is_set())
- return -1;
+ 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]);
+ return -1;
+ }
+ } else {
+ char *end;
- if (ptl_parse_nid (&nid, argv[1]) != 0)
- {
- fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
- return (-1);
- }
-
- if (argc > 2)
- {
- count = atol(argv[2]);
+ 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 (count < 0 || count > 20000)
- {
- fprintf(stderr, "are you insane? %ld is a crazy count.\n", count);
+ if (end != sep ||
+ id.nid == LNET_NID_ANY) {
+ fprintf(stderr, "Can't parse process id \"%s\"\n", argv[1]);
return -1;
}
}
-
- if (argc > 3)
- size= atol(argv[3]);
- if (argc > 4)
- timeout = atol (argv[4]);
-
- PORTAL_IOC_INIT (data);
- data.ioc_count = count;
- data.ioc_size = size;
- data.ioc_nid = nid;
- data.ioc_nal = g_nal;
- data.ioc_timeout = timeout;
-
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_PING, &data);
- if (rc) {
- fprintf(stderr, "failed to start pinger: %s\n",
+ if (argc > 2)
+ timeout = 1000 * atol(argv[2]);
+ else
+ timeout = 1000; /* default 1 second timeout */
+
+ LIBCFS_IOC_INIT (data);
+ data.ioc_nid = id.nid;
+ data.ioc_u32[0] = id.pid;
+ data.ioc_u32[1] = timeout;
+ data.ioc_plen1 = sizeof(ids);
+ data.ioc_pbuf1 = (char *)ids;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PING, &data);
+ if (rc != 0) {
+ fprintf(stderr, "failed to ping %s: %s\n",
+ id.pid == LNET_PID_ANY ?
+ libcfs_nid2str(id.nid) : libcfs_id2str(id),
strerror(errno));
return -1;
}
- return 0;
-}
-int jt_ptl_shownid(int argc, char **argv)
-{
- struct portal_ioctl_data data;
- int rc;
-
- if (argc > 1) {
- fprintf(stderr, "usage: %s\n", argv[0]);
- return 0;
- }
-
- if (!g_nal_is_set())
- return -1;
+ for (i = 0; i < data.ioc_count && i < maxids; i++)
+ printf("%s\n", libcfs_id2str(ids[i]));
+
+ if (data.ioc_count > maxids)
+ printf("%d out of %d ids listed\n", maxids, data.ioc_count);
- PORTAL_IOC_INIT (data);
- data.ioc_nal = g_nal;
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_GET_NID, &data);
- if (rc < 0)
- fprintf(stderr, "getting my NID failed: %s\n",
- strerror (errno));
- else
- printf(LPX64"\n", data.ioc_nid);
return 0;
}
int jt_ptl_mynid(int argc, char **argv)
{
+ struct libcfs_ioctl_data data;
+ lnet_nid_t nid;
int rc;
- char hostname[1024];
- char *nidstr;
- struct portals_cfg pcfg;
- ptl_nid_t mynid;
- if (argc > 2) {
- fprintf(stderr, "usage: %s [NID]\n", argv[0]);
- fprintf(stderr, "NID defaults to the primary IP address of the machine.\n");
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s NID\n", argv[0]);
return 0;
}
- if (!g_nal_is_set())
- return -1;
-
- if (argc >= 2)
- nidstr = argv[1];
- else if (gethostname(hostname, sizeof(hostname)) != 0) {
- fprintf(stderr, "gethostname failed: %s\n",
- strerror(errno));
+ nid = libcfs_str2nid(argv[1]);
+ if (nid == LNET_NID_ANY) {
+ fprintf(stderr, "Can't parse NID '%s'\n", argv[1]);
return -1;
}
- else
- nidstr = hostname;
- rc = ptl_parse_nid (&mynid, nidstr);
- if (rc != 0) {
- fprintf (stderr, "Can't convert '%s' into a NID\n", nidstr);
- return -1;
- }
-
- PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
- pcfg.pcfg_nid = mynid;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = LNET_NIDNET(nid);
+ data.ioc_nid = nid;
- rc = pcfg_ioctl(&pcfg);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_REGISTER_MYNID, &data);
if (rc < 0)
fprintf(stderr, "setting my NID failed: %s\n",
strerror(errno));
else
- printf("registered my nid "LPX64" (%s)\n",
- ptl_nid2u64(mynid), hostname);
+ printf("registered my nid %s\n", libcfs_nid2str(nid));
+
return 0;
}
jt_ptl_fail_nid (int argc, char **argv)
{
int rc;
- ptl_nid_t nid;
+ lnet_nid_t nid;
unsigned int threshold;
- struct portal_ioctl_data data;
+ struct libcfs_ioctl_data data;
if (argc < 2 || argc > 3)
{
- fprintf (stderr, "usage: %s nid|\"_all_\" [count (0 == mend)]\n", argv[0]);
+ fprintf (stderr, "usage: %s nid|\"*\" [count (0 == mend)]\n", argv[0]);
return (0);
}
-
- if (!g_nal_is_set())
- return (-1);
- if (!strcmp (argv[1], "_all_"))
- nid = PTL_NID_ANY;
- else if (ptl_parse_nid (&nid, argv[1]) != 0)
+ if (!libcfs_str2anynid(&nid, argv[1]))
{
fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
return (-1);
}
- if (argc < 3)
- threshold = PTL_MD_THRESH_INF;
- else if (sscanf (argv[2], "%i", &threshold) != 1) {
+ if (argc < 3) {
+ threshold = LNET_MD_THRESH_INF;
+ } else if (sscanf (argv[2], "%i", &threshold) != 1) {
fprintf (stderr, "Can't parse count \"%s\"\n", argv[2]);
return (-1);
}
-
- PORTAL_IOC_INIT (data);
- data.ioc_nal = g_nal;
+
+ LIBCFS_IOC_INIT (data);
data.ioc_nid = nid;
data.ioc_count = threshold;
-
- rc = l_ioctl (PORTALS_DEV_ID, IOC_PORTAL_FAIL_NID, &data);
+
+ rc = l_ioctl (LNET_DEV_ID, IOC_LIBCFS_FAIL_NID, &data);
if (rc < 0)
- fprintf (stderr, "IOC_PORTAL_FAIL_NID failed: %s\n",
+ fprintf (stderr, "IOC_LIBCFS_FAIL_NID failed: %s\n",
strerror (errno));
else
printf ("%s %s\n", threshold == 0 ? "Unfailing" : "Failing", argv[1]);
-
+
return (0);
}
int
jt_ptl_add_route (int argc, char **argv)
{
- struct portals_cfg pcfg;
- ptl_nid_t nid1;
- ptl_nid_t nid2;
- ptl_nid_t gateway_nid;
+ struct libcfs_ioctl_data data;
+ lnet_nid_t gateway_nid;
+ unsigned int hops = 1;
+ char *end;
int rc;
-
- if (argc < 3)
+
+ if (argc < 2 || argc > 3)
{
- fprintf (stderr, "usage: %s gateway target [target]\n", argv[0]);
+ fprintf (stderr, "usage: %s gateway [hopcount]\n", argv[0]);
return (0);
}
- if (!g_nal_is_set())
+ if (!g_net_is_set(argv[0]))
return (-1);
- if (ptl_parse_nid (&gateway_nid, argv[1]) != 0)
- {
+ gateway_nid = libcfs_str2nid(argv[1]);
+ if (gateway_nid == LNET_NID_ANY) {
fprintf (stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
return (-1);
}
- if (ptl_parse_nid (&nid1, argv[2]) != 0)
- {
- fprintf (stderr, "Can't parse first target NID \"%s\"\n", argv[2]);
- return (-1);
- }
-
- if (argc < 4)
- nid2 = nid1;
- else if (ptl_parse_nid (&nid2, argv[3]) != 0)
- {
- fprintf (stderr, "Can't parse second target NID \"%s\"\n", argv[4]);
- return (-1);
+ if (argc == 3) {
+ hops = strtoul(argv[2], &end, 0);
+ if (hops >= 256 || *end != 0) {
+ fprintf (stderr, "Can't parse hopcount \"%s\"\n", argv[2]);
+ return -1;
+ }
}
- PCFG_INIT(pcfg, NAL_CMD_ADD_ROUTE);
- pcfg.pcfg_nid = gateway_nid;
- pcfg.pcfg_nal = ROUTER;
- pcfg.pcfg_gw_nal = g_nal;
- pcfg.pcfg_nid2 = MIN (nid1, nid2);
- pcfg.pcfg_nid3 = MAX (nid1, nid2);
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net;
+ data.ioc_count = hops;
+ data.ioc_nid = gateway_nid;
- rc = pcfg_ioctl(&pcfg);
- if (rc != 0)
- {
- fprintf (stderr, "NAL_CMD_ADD_ROUTE failed: %s\n", strerror (errno));
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_ADD_ROUTE, &data);
+ if (rc != 0) {
+ fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno));
return (-1);
}
-
+
return (0);
}
int
jt_ptl_del_route (int argc, char **argv)
{
- struct portals_cfg pcfg;
- ptl_nid_t nid;
- ptl_nid_t nid1 = PTL_NID_ANY;
- ptl_nid_t nid2 = PTL_NID_ANY;
+ struct libcfs_ioctl_data data;
+ lnet_nid_t nid;
int rc;
-
- if (argc < 2)
- {
- fprintf (stderr, "usage: %s targetNID\n", argv[0]);
- return (0);
- }
-
- if (!g_nal_is_set())
- return (-1);
- if (ptl_parse_nid (&nid, argv[1]) != 0)
- {
- fprintf (stderr, "Can't parse gateway NID \"%s\"\n", argv[1]);
- return (-1);
+ if (argc != 2) {
+ fprintf (stderr, "usage: %s gatewayNID\n", argv[0]);
+ return (0);
}
- if (argc >= 3 &&
- ptl_parse_nid (&nid1, argv[2]) != 0)
- {
- fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[2]);
- return (-1);
+ if (!libcfs_str2anynid(&nid, argv[1])) {
+ fprintf (stderr, "Can't parse gateway NID "
+ "\"%s\"\n", argv[1]);
+ return -1;
}
- if (argc < 4) {
- nid2 = nid1;
- } else {
- if (ptl_parse_nid (&nid2, argv[3]) != 0) {
- fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[3]);
- return (-1);
- }
-
- if (nid1 > nid2) {
- ptl_nid_t tmp = nid1;
-
- nid1 = nid2;
- nid2 = tmp;
- }
- }
-
- PCFG_INIT(pcfg, NAL_CMD_DEL_ROUTE);
- pcfg.pcfg_nal = ROUTER;
- pcfg.pcfg_gw_nal = g_nal;
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_nid2 = nid1;
- pcfg.pcfg_nid3 = nid2;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_net = g_net_set ? g_net : LNET_NIDNET(LNET_NID_ANY);
+ data.ioc_nid = nid;
- rc = pcfg_ioctl(&pcfg);
- if (rc != 0)
- {
- fprintf (stderr, "NAL_CMD_DEL_ROUTE ("LPX64") failed: %s\n",
- ptl_nid2u64(nid), strerror (errno));
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_DEL_ROUTE, &data);
+ if (rc != 0) {
+ fprintf (stderr, "IOC_LIBCFS_DEL_ROUTE (%s) failed: %s\n",
+ libcfs_nid2str(nid), strerror (errno));
return (-1);
}
-
+
return (0);
}
int
jt_ptl_notify_router (int argc, char **argv)
{
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
int enable;
- ptl_nid_t nid;
+ lnet_nid_t nid;
int rc;
struct timeval now;
time_t when;
return (0);
}
- if (ptl_parse_nid (&nid, argv[1]) != 0)
- {
+ nid = libcfs_str2nid(argv[1]);
+ if (nid == LNET_NID_ANY) {
fprintf (stderr, "Can't parse target NID \"%s\"\n", argv[1]);
return (-1);
}
- if (ptl_parse_bool (&enable, argv[2]) != 0) {
+ if (lnet_parse_bool (&enable, argv[2]) != 0) {
fprintf (stderr, "Can't parse boolean %s\n", argv[2]);
return (-1);
}
gettimeofday(&now, NULL);
-
+
if (argc < 4) {
when = now.tv_sec;
- } else if (ptl_parse_time (&when, argv[3]) != 0) {
+ } else if (lnet_parse_time (&when, argv[3]) != 0) {
fprintf(stderr, "Can't parse time %s\n"
"Please specify either 'YYYY-MM-DD-HH:MM:SS'\n"
"or an absolute unix time in seconds\n", argv[3]);
return (-1);
}
- PCFG_INIT(pcfg, NAL_CMD_NOTIFY_ROUTER);
- pcfg.pcfg_nal = ROUTER;
- pcfg.pcfg_gw_nal = g_nal;
- pcfg.pcfg_nid = nid;
- pcfg.pcfg_flags = enable;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_nid = nid;
+ data.ioc_flags = enable;
/* Yeuch; 'cept I need a __u64 on 64 bit machines... */
- pcfg.pcfg_nid3 = (__u64)when;
-
- rc = pcfg_ioctl(&pcfg);
- if (rc != 0)
- {
- fprintf (stderr, "NAL_CMD_NOTIFY_ROUTER ("LPX64") failed: %s\n",
- ptl_nid2u64(nid), strerror (errno));
+ 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);
}
int
jt_ptl_print_routes (int argc, char **argv)
{
- char buffer[3][128];
- struct portals_cfg pcfg;
+ struct libcfs_ioctl_data data;
int rc;
int index;
- int gateway_nal;
- ptl_nid_t gateway_nid;
- ptl_nid_t nid1;
- ptl_nid_t nid2;
+ __u32 net;
+ lnet_nid_t nid;
+ unsigned int hops;
int alive;
for (index = 0;;index++)
{
- PCFG_INIT(pcfg, NAL_CMD_GET_ROUTE);
- pcfg.pcfg_nal = ROUTER;
- pcfg.pcfg_count = index;
-
- rc = pcfg_ioctl(&pcfg);
+ LIBCFS_IOC_INIT(data);
+ data.ioc_count = index;
+
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
if (rc != 0)
break;
- gateway_nal = pcfg.pcfg_gw_nal;
- gateway_nid = pcfg.pcfg_nid;
- nid1 = pcfg.pcfg_nid2;
- nid2 = pcfg.pcfg_nid3;
- alive = pcfg.pcfg_flags;
+ net = data.ioc_net;
+ hops = data.ioc_count;
+ nid = data.ioc_nid;
+ alive = data.ioc_flags;
- printf ("%8s %18s : %s - %s, %s\n",
- nal2name (gateway_nal),
- ptl_nid2str (buffer[0], gateway_nid),
- ptl_nid2str (buffer[1], nid1),
- ptl_nid2str (buffer[2], nid2),
- alive ? "up" : "down");
+ printf ("net %18s hops %u gw %32s %s\n",
+ libcfs_net2str(net), hops,
+ libcfs_nid2str(nid), alive ? "up" : "down");
}
+
+ if (errno != ENOENT)
+ fprintf(stderr, "Error getting routes: %s: check dmesg.\n",
+ strerror(errno));
+
return (0);
}
static int
lwt_control(int enable, int clear)
{
- struct portal_ioctl_data data;
+ struct libcfs_ioctl_data data;
int rc;
- PORTAL_IOC_INIT(data);
- data.ioc_flags = enable;
- data.ioc_misc = clear;
+ LIBCFS_IOC_INIT(data);
+ data.ioc_flags = (enable ? 1 : 0) | (clear ? 2 : 0);
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_LWT_CONTROL, &data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LWT_CONTROL, &data);
if (rc == 0)
return (0);
- fprintf(stderr, "IOC_PORTAL_LWT_CONTROL failed: %s\n",
+ fprintf(stderr, "IOC_LIBCFS_LWT_CONTROL failed: %s\n",
strerror(errno));
return (-1);
}
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 portal_ioctl_data data;
+ struct libcfs_ioctl_data data;
int rc;
- PORTAL_IOC_INIT(data);
+ LIBCFS_IOC_INIT(data);
data.ioc_pbuf1 = (char *)events;
data.ioc_plen1 = size;
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_LWT_SNAPSHOT, &data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LWT_SNAPSHOT, &data);
if (rc != 0) {
- fprintf(stderr, "IOC_PORTAL_LWT_SNAPSHOT failed: %s\n",
+ fprintf(stderr, "IOC_LIBCFS_LWT_SNAPSHOT failed: %s\n",
strerror(errno));
return (-1);
}
/* crappy overloads */
- if (data.ioc_nid2 != sizeof(lwt_event_t) ||
- data.ioc_nid3 != offsetof(lwt_event_t, lwte_where)) {
+ if (data.ioc_u32[2] != sizeof(lwt_event_t) ||
+ data.ioc_u32[3] != offsetof(lwt_event_t, lwte_where)) {
fprintf(stderr,"kernel/user LWT event mismatch %d(%d),%d(%d)\n",
- (int)data.ioc_nid2, sizeof(lwt_event_t),
- (int)data.ioc_nid3,
+ (int)data.ioc_u32[2], (int)sizeof(lwt_event_t),
+ (int)data.ioc_u32[3],
(int)offsetof(lwt_event_t, lwte_where));
return (-1);
}
- LASSERT (data.ioc_count != 0);
- LASSERT (data.ioc_misc != 0);
-
if (now != NULL)
- *now = data.ioc_nid;
+ *now = data.ioc_u64[0];
+ LASSERT (data.ioc_u32[0] != 0);
if (ncpu != NULL)
- *ncpu = data.ioc_count;
+ *ncpu = data.ioc_u32[0];
+ LASSERT (data.ioc_u32[1] != 0);
if (totalsize != NULL)
- *totalsize = data.ioc_misc;
+ *totalsize = data.ioc_u32[1];
return (0);
}
lwt_get_string(char *kstr)
{
char *ustr;
- struct portal_ioctl_data data;
+ struct libcfs_ioctl_data data;
int size;
int rc;
/* FIXME: this could maintain a symbol table since we expect to be
* looking up the same strings all the time... */
- PORTAL_IOC_INIT(data);
+ LIBCFS_IOC_INIT(data);
data.ioc_pbuf1 = kstr;
data.ioc_plen1 = 1; /* non-zero just to fool portal_ioctl_is_invalid() */
data.ioc_pbuf2 = NULL;
data.ioc_plen2 = 0;
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_LWT_LOOKUP_STRING, &data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LWT_LOOKUP_STRING, &data);
if (rc != 0) {
- fprintf(stderr, "IOC_PORTAL_LWT_LOOKUP_STRING failed: %s\n",
+ fprintf(stderr, "IOC_LIBCFS_LWT_LOOKUP_STRING failed: %s\n",
strerror(errno));
return (NULL);
}
return (NULL);
}
- PORTAL_IOC_INIT(data);
+ LIBCFS_IOC_INIT(data);
data.ioc_pbuf1 = kstr;
data.ioc_plen1 = 1; /* non-zero just to fool portal_ioctl_is_invalid() */
data.ioc_pbuf2 = ustr;
data.ioc_plen2 = size;
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_LWT_LOOKUP_STRING, &data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_LWT_LOOKUP_STRING, &data);
if (rc != 0) {
- fprintf(stderr, "IOC_PORTAL_LWT_LOOKUP_STRING failed: %s\n",
+ fprintf(stderr, "IOC_LIBCFS_LWT_LOOKUP_STRING failed: %s\n",
strerror(errno));
return (NULL);
}
}
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"
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) {
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;
" %s stop [fname]\n", argv[0], argv[0]);
return (-1);
}
-
+
if (!strcmp(argv[1], "start")) {
/* disable */
if (lwt_control(0, 0) != 0)
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);
}
}
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++)
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
/* 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;
}
tlast = next_event[cpu]->lwte_when;
-
+
next_event[cpu]++;
if (next_event[cpu] == cpu_event[cpu + 1])
next_event[cpu] = cpu_event[cpu];
{
static int gfp = 0; /* sticky! */
- struct portal_ioctl_data data;
+ struct libcfs_ioctl_data data;
int rc;
int count;
char *end;
-
+
if (argc < 2) {
fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
return 0;
}
gfp = rc;
}
-
- PORTAL_IOC_INIT(data);
+
+ LIBCFS_IOC_INIT(data);
data.ioc_count = count;
data.ioc_flags = gfp;
- rc = l_ioctl(PORTALS_DEV_ID, IOC_PORTAL_MEMHOG, &data);
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_MEMHOG, &data);
if (rc != 0) {
fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
return -1;
}
-
+
printf("memhog %d OK\n", count);
return 0;
}
+int jt_ptl_testprotocompat(int argc, char **argv)
+{
+ struct libcfs_ioctl_data data;
+ int rc;
+ int flags;
+ char *end;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s <number>\n", argv[0]);
+ return 0;
+ }
+
+ flags = strtol(argv[1], &end, 0);
+ if (flags < 0 || *end != 0) {
+ fprintf(stderr, "Can't parse flags '%s'\n", argv[1]);
+ return -1;
+ }
+
+ LIBCFS_IOC_INIT(data);
+ data.ioc_flags = flags;
+ rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_TESTPROTOCOMPAT, &data);
+
+ if (rc != 0) {
+ fprintf(stderr, "test proto compat %x failed: %s\n",
+ flags, strerror(errno));
+ return -1;
+ }
+
+ printf("test proto compat %x OK\n", flags);
+ return 0;
+}
+
+