Whamcloud - gitweb
LU-6068 misc: update old URLs to hpdd.intel.com
[fs/lustre-release.git] / lnet / utils / portals.c
index 8f1b2c5..bd670ce 100644 (file)
@@ -1,7 +1,9 @@
 /*
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  *
- *   This file is part of Portals, http://www.sf.net/projects/lustre/
+ * Copyright (c) 2013, 2014, Intel Corporation.
+ *
+ *   This file is part of Lustre, https://wiki.hpdd.intel.com/
  *
  *   Portals is free software; you can redistribute it and/or
  *   modify it under the terms of version 2 of the GNU General Public
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  */
-
-#include <libcfs/libcfsutil.h>
-#include <lnet/nidstr.h>
+#include <errno.h>
+#include <getopt.h>
+#include <limits.h>
+#include <netdb.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <time.h>
+#include <linux/types.h>
+#include <libcfs/libcfs.h>
+#include <libcfs/util/string.h>
+#include <libcfs/util/ioctl.h>
 #include <lnet/lnetctl.h>
 #include <lnet/socklnd.h>
-#include <lnet/lib-dlc.h>
+#include <lnet/lnet.h>
 
 unsigned int libcfs_debug;
 unsigned int libcfs_printk = D_CANTMASK;
@@ -570,8 +584,7 @@ jt_ptl_print_peers (int argc, char **argv)
         int                      index;
         int                      rc;
 
-       if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
-                                 O2IBLND, GNILND, 0))
+       if (!g_net_is_compatible (argv[0], SOCKLND, O2IBLND, GNILND, 0))
                 return -1;
 
         for (index = 0;;index++) {
@@ -587,7 +600,7 @@ jt_ptl_print_peers (int argc, char **argv)
                         id.nid = data.ioc_nid;
                         id.pid = data.ioc_u32[4];
                         printf ("%-20s [%d]%s->%s:%d #%d\n",
-                                libcfs_id2str(id), 
+                               libcfs_id2str(id),
                                 data.ioc_count, /* persistence */
                                /* my ip */
                                ptl_ipaddr_2_str(data.ioc_u32[2], buffer[0],
@@ -597,14 +610,6 @@ jt_ptl_print_peers (int argc, char **argv)
                                                 sizeof(buffer[1]), 1),
                                 data.ioc_u32[1], /* peer port */
                                 data.ioc_u32[3]); /* conn_count */
-                } 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 */
-                               /* peer ip */
-                               ptl_ipaddr_2_str(data.ioc_u32[0], buffer[1],
-                                                sizeof(buffer[1]), 1),
-                                data.ioc_u32[1]); /* peer port */
                } else if (g_net_is_compatible(NULL, GNILND, 0)) {
                        int disconn = data.ioc_flags >> 16;
                        char *state;
@@ -652,8 +657,7 @@ jt_ptl_add_peer (int argc, char **argv)
         int                      port = 0;
         int                      rc;
 
-       if (!g_net_is_compatible (argv[0], SOCKLND, RALND,
-                                 GNILND, 0))
+       if (!g_net_is_compatible(argv[0], SOCKLND, GNILND, 0))
                 return -1;
 
         if (argc != 4) {
@@ -703,8 +707,7 @@ jt_ptl_del_peer (int argc, char **argv)
         __u32                    ip = 0;
         int                      rc;
 
-       if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND,
-                                 O2IBLND, GNILND, 0))
+       if (!g_net_is_compatible(argv[0], SOCKLND, O2IBLND, GNILND, 0))
                 return -1;
 
         if (g_net_is_compatible(NULL, SOCKLND, 0)) {
@@ -758,8 +761,7 @@ jt_ptl_print_connections (int argc, char **argv)
         int                      index;
         int                      rc;
 
-       if (!g_net_is_compatible (argv[0], SOCKLND, RALND, MXLND, O2IBLND,
-                                 GNILND, 0))
+       if (!g_net_is_compatible(argv[0], SOCKLND, O2IBLND, GNILND, 0))
                 return -1;
 
         for (index = 0; ; index++) {
@@ -791,10 +793,6 @@ jt_ptl_print_connections (int argc, char **argv)
                                 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),
@@ -832,8 +830,7 @@ int jt_ptl_disconnect(int argc, char **argv)
                 return 0;
         }
 
-       if (!g_net_is_compatible (NULL, SOCKLND, RALND, MXLND, O2IBLND,
-                                 GNILND, 0))
+       if (!g_net_is_compatible(NULL, SOCKLND, O2IBLND, GNILND, 0))
                 return 0;
 
         if (argc >= 2 &&
@@ -898,49 +895,6 @@ int jt_ptl_push_connection (int argc, char **argv)
         return 0;
 }
 
-int
-jt_ptl_print_active_txs (int argc, char **argv)
-{
-        struct libcfs_ioctl_data data;
-        int                      index;
-        int                      rc;
-
-        if (!g_net_is_compatible (argv[0], QSWLND, 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_TXDESC, &data);
-                if (rc != 0)
-                        break;
-
-                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;
@@ -1355,6 +1309,7 @@ fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
                {"dest",        required_argument,      0,      'd'},
                {"rate",        required_argument,      0,      'r'},
                {"interval",    required_argument,      0,      'i'},
+               {"latency",     required_argument,      0,      'l'},
                {"portal",      required_argument,      0,      'p'},
                {"message",     required_argument,      0,      'm'},
                {0, 0, 0, 0}
@@ -1366,7 +1321,7 @@ fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
                return -1;
        }
 
-       optstr = "s:d:r:i:p:m:";
+       optstr = opc == LNET_CTL_DROP_ADD ? "s:d:r:i:p:m:" : "s:d:r:l:p:m:";
        memset(&attr, 0, sizeof(attr));
        while (1) {
                char c = getopt_long(argc, argv, optstr, opts, NULL);
@@ -1388,11 +1343,23 @@ fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
                        break;
 
                case 'r': /* drop rate */
-                       attr.u.drop.da_rate = strtoul(optarg, NULL, 0);
+                       if (opc == LNET_CTL_DROP_ADD)
+                               attr.u.drop.da_rate = strtoul(optarg, NULL, 0);
+                       else
+                               attr.u.delay.la_rate = strtoul(optarg, NULL, 0);
                        break;
 
                case 'i': /* time interval (# seconds) for message drop */
-                       attr.u.drop.da_interval = strtoul(optarg, NULL, 0);
+                       if (opc == LNET_CTL_DROP_ADD)
+                               attr.u.drop.da_interval = strtoul(optarg,
+                                                                 NULL, 0);
+                       else
+                               attr.u.delay.la_interval = strtoul(optarg,
+                                                                  NULL, 0);
+                       break;
+
+               case 'l': /* seconds to wait before activating rule */
+                       attr.u.delay.la_latency = strtoul(optarg, NULL, 0);
                        break;
 
                case 'p': /* portal to filter */
@@ -1415,9 +1382,28 @@ fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
        }
        optind = 1;
 
-       if ((attr.u.drop.da_rate == 0) == (attr.u.drop.da_interval == 0)) {
-               fprintf(stderr, "please provide drop rate or interval\n");
-               return -1;
+       if (opc == LNET_CTL_DROP_ADD) {
+               /* NB: drop rate and interval are exclusive to each other */
+               if (!((attr.u.drop.da_rate == 0) ^
+                     (attr.u.drop.da_interval == 0))) {
+                       fprintf(stderr,
+                               "please provide either drop rate or interval "
+                               "but not both at the same time.\n");
+                       return -1;
+               }
+       } else if (opc == LNET_CTL_DELAY_ADD) {
+               if (!((attr.u.delay.la_rate == 0) ^
+                     (attr.u.delay.la_interval == 0))) {
+                       fprintf(stderr,
+                               "please provide either delay rate or interval "
+                               "but not both at the same time.\n");
+                       return -1;
+               }
+
+               if (attr.u.delay.la_latency == 0) {
+                       fprintf(stderr, "latency cannot be zero\n");
+                       return -1;
+               }
        }
 
        if (attr.fa_src == 0 || attr.fa_dst == 0) {
@@ -1443,8 +1429,9 @@ fault_simul_rule_add(__u32 opc, char *name, int argc, char **argv)
        }
 
        printf("Added %s rule %s->%s (1/%d)\n",
-              name, libcfs_nid2str(attr.fa_src),
-              libcfs_nid2str(attr.fa_dst), attr.u.drop.da_rate);
+              name, libcfs_nid2str(attr.fa_src), libcfs_nid2str(attr.fa_dst),
+              opc == LNET_CTL_DROP_ADD ?
+              attr.u.drop.da_rate : attr.u.delay.la_rate);
        return 0;
 
 getopt_failed:
@@ -1458,6 +1445,12 @@ jt_ptl_drop_add(int argc, char **argv)
        return fault_simul_rule_add(LNET_CTL_DROP_ADD, "drop", argc, argv);
 }
 
+int
+jt_ptl_delay_add(int argc, char **argv)
+{
+       return fault_simul_rule_add(LNET_CTL_DELAY_ADD, "delay", argc, argv);
+}
+
 static int
 fault_simul_rule_del(__u32 opc, char *name, int argc, char **argv)
 {
@@ -1541,6 +1534,12 @@ jt_ptl_drop_del(int argc, char **argv)
        return fault_simul_rule_del(LNET_CTL_DROP_DEL, "drop", argc, argv);
 }
 
+int
+jt_ptl_delay_del(int argc, char **argv)
+{
+       return fault_simul_rule_del(LNET_CTL_DELAY_DEL, "delay", argc, argv);
+}
+
 static int
 fault_simul_rule_reset(__u32 opc, char *name, int argc, char **argv)
 {
@@ -1565,6 +1564,13 @@ jt_ptl_drop_reset(int argc, char **argv)
        return fault_simul_rule_reset(LNET_CTL_DROP_RESET, "drop", argc, argv);
 }
 
+int
+jt_ptl_delay_reset(int argc, char **argv)
+{
+       return fault_simul_rule_reset(LNET_CTL_DELAY_RESET, "delay",
+                                     argc, argv);
+}
+
 static int
 fault_simul_rule_list(__u32 opc, char *name, int argc, char **argv)
 {
@@ -1608,6 +1614,19 @@ fault_simul_rule_list(__u32 opc, char *name, int argc, char **argv)
                               stat.u.drop.ds_dropped, stat.fs_count,
                               stat.fs_put, stat.fs_ack,
                               stat.fs_get, stat.fs_reply);
+
+               } else if (opc == LNET_CTL_DELAY_LIST) {
+                       printf("%s->%s (1/%d | %d, latency %d) ptl "LPX64
+                              ", msg %x, "LPU64"/"LPU64", PUT "LPU64
+                              ", ACK "LPU64", GET "LPU64", REP "LPU64"\n",
+                              libcfs_nid2str(attr.fa_src),
+                              libcfs_nid2str(attr.fa_dst),
+                              attr.u.delay.la_rate, attr.u.delay.la_interval,
+                              attr.u.delay.la_latency,
+                              attr.fa_ptl_mask, attr.fa_msg_mask,
+                              stat.u.delay.ls_delayed, stat.fs_count,
+                              stat.fs_put, stat.fs_ack, stat.fs_get,
+                              stat.fs_reply);
                }
        }
        printf("found total %d\n", pos);
@@ -1621,6 +1640,12 @@ jt_ptl_drop_list(int argc, char **argv)
        return fault_simul_rule_list(LNET_CTL_DROP_LIST, "drop", argc, argv);
 }
 
+int
+jt_ptl_delay_list(int argc, char **argv)
+{
+       return fault_simul_rule_list(LNET_CTL_DELAY_LIST, "delay", argc, argv);
+}
+
 double
 get_cycles_per_usec ()
 {