/* -*- 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;
+unsigned int libcfs_printk = D_CANTMASK;
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") ||
*b = 0;
return (0);
}
-
+
if (!strcasecmp (str, "yes") ||
!strcasecmp (str, "y") ||
!strcasecmp (str, "on") ||
*b = 1;
return (0);
}
-
+
return (-1);
}
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);
}
}
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 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;
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);
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 */
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--;
}
fprintf(stderr, "usage: %s NID [NID...]\n", argv[0]);
return 0;
}
-
+
for (i = 1; i < argc; i++) {
nidstr = argv[i];
nid = libcfs_str2nid(nidstr);
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",
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)) {
fprintf(stderr, "No reachable NID\n");
return -1;
}
-
+
printf("%s\n", libcfs_nid2str(best_nid));
return 0;
}
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;
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;
int index;
int rc;
- if (!g_net_is_compatible (argv[0], SOCKLND, RALND, PTLLND,
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND, PTLLND, MXLND,
OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return -1;
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;
return 0;
}
-int
+int
jt_ptl_add_peer (int argc, char **argv)
{
struct libcfs_ioctl_data data;
int port = 0;
int rc;
- if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
OPENIBLND, CIBLND, IIBLND, VIBLND, 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",
+ 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",
+ fprintf (stderr, "usage(vib): %s nid ipaddr\n",
argv[0]);
return 0;
}
strerror (errno));
return -1;
}
-
+
return 0;
}
-int
+int
jt_ptl_del_peer (int argc, char **argv)
{
struct libcfs_ioctl_data data;
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]);
}
}
}
-
+
LIBCFS_IOC_INIT(data);
data.ioc_net = g_net;
data.ioc_nid = nid;
strerror (errno));
return -1;
}
-
+
return 0;
}
-int
+int
jt_ptl_print_connections (int argc, char **argv)
{
struct libcfs_ioctl_data data;
int index;
int rc;
- if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
+ if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
OPENIBLND, CIBLND, IIBLND, VIBLND, O2IBLND, 0))
return -1;
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));
}
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",
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",
return 0;
}
-int
+int
jt_ptl_print_active_txs (int argc, char **argv)
{
struct libcfs_ioctl_data data;
return 0;
}
-int jt_ptl_ping_test(int argc, char **argv)
-{
- int rc;
- lnet_nid_t nid;
- long count = 1;
- long size = 4;
- long timeout = 1;
- struct libcfs_ioctl_data data;
-
- if (argc < 2) {
- fprintf(stderr, "usage: %s nid [count] [size] [timeout (secs)]\n", argv[0]);
- return 0;
- }
-
- nid = libcfs_str2nid(argv[1]);
- if (nid == LNET_NID_ANY) {
- fprintf (stderr, "Can't parse nid \"%s\"\n", argv[1]);
- return (-1);
- }
-
- if (argc > 2)
- {
- count = atol(argv[2]);
-
- if (count < 0 || count > 20000)
- {
- fprintf(stderr, "are you insane? %ld is a crazy count.\n", count);
- return -1;
- }
- }
-
- if (argc > 3)
- size= atol(argv[3]);
-
- if (argc > 4)
- timeout = atol (argv[4]);
-
- LIBCFS_IOC_INIT (data);
- data.ioc_count = count;
- data.ioc_nid = nid;
- data.ioc_u32[0] = size;
- data.ioc_u32[1] = timeout;
-
- rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_PING_TEST, &data);
- if (rc) {
- fprintf(stderr, "failed to start pinger: %s\n",
- strerror(errno));
- return -1;
- }
- return 0;
-}
-
int jt_ptl_ping(int argc, char **argv)
{
int rc;
}
} else {
char *end;
-
+
if (argv[1][0] == 'u' ||
argv[1][0] == 'U')
id.pid = strtoul(&argv[1][1], &end, 0) | LNET_PID_USERFLAG;
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]);
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]);
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);
}
unsigned int hops = 1;
char *end;
int rc;
-
+
if (argc < 2 || argc > 3)
{
fprintf (stderr, "usage: %s gateway [hopcount]\n", argv[0]);
return -1;
}
}
-
+
LIBCFS_IOC_INIT(data);
data.ioc_net = g_net;
data.ioc_count = hops;
fprintf (stderr, "IOC_LIBCFS_ADD_ROUTE failed: %s\n", strerror (errno));
return (-1);
}
-
+
return (0);
}
struct libcfs_ioctl_data data;
lnet_nid_t nid;
int rc;
-
+
if (argc != 2) {
fprintf (stderr, "usage: %s gatewayNID\n", argv[0]);
return (0);
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);
}
}
gettimeofday(&now, NULL);
-
+
if (argc < 4) {
when = now.tv_sec;
} else if (lnet_parse_time (&when, argv[3]) != 0) {
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);
}
{
LIBCFS_IOC_INIT(data);
data.ioc_count = index;
-
+
rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_ROUTE, &data);
if (rc != 0)
break;
}
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;
}
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];
int rc;
int count;
char *end;
-
+
if (argc < 2) {
fprintf(stderr, "usage: %s <npages> [<GFP flags>]\n", argv[0]);
return 0;
}
gfp = rc;
}
-
+
LIBCFS_IOC_INIT(data);
data.ioc_count = count;
data.ioc_flags = gfp;
fprintf(stderr, "memhog %d failed: %s\n", count, strerror(errno));
return -1;
}
-
+
printf("memhog %d OK\n", count);
return 0;
}