Whamcloud - gitweb
LU-1154 clio: rename coo_attr_set to coo_attr_update
[fs/lustre-release.git] / lnet / utils / lst.c
index 30428db..7917e3e 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -28,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
  * Author: Liang Zhen <liangzhen@clusterfs.com>
  */
 
-#define _GNU_SOURCE
-
+#include <getopt.h>
+#include <pwd.h>
 #include <libcfs/libcfsutil.h>
 #include <lnet/lnetctl.h>
 #include <lnet/lnetst.h>
-
+#include <lnet/nidstr.h>
+/* NB: these includes are layering violation */
+#include <lustre_ver.h>
+#include <lustre/lustre_idl.h>
 
 lst_sid_t LST_INVALID_SID = {LNET_NID_ANY, -1};
 static lst_sid_t           session_id;
 static int                 session_key;
-static lstcon_trans_stat_t trans_stat;
+
+/* All nodes running 2.6.50 or later understand feature LST_FEAT_BULK_LEN */
+static unsigned                session_features = LST_FEATS_MASK;
+static lstcon_trans_stat_t     trans_stat;
 
 typedef struct list_string {
-        struct list_string *lstr_next;
-        int                 lstr_sz;
-        char                lstr_str[0];
+       struct list_string *lstr_next;
+       int                 lstr_sz;
+       char                lstr_str[0];
 } lstr_t;
 
 #ifndef offsetof
@@ -279,7 +285,7 @@ out:
                                 rc = -1;
                         }
 
-                        (*idspp)[i].pid = LUSTRE_LNET_PID;
+                       (*idspp)[i].pid = LNET_PID_LUSTRE;
                         i++;
                 }
 
@@ -391,33 +397,33 @@ lst_print_error(char *sub, const char *def_format, ...)
 }
 
 void
-lst_free_rpcent(cfs_list_t *head)
+lst_free_rpcent(struct list_head *head)
 {
-        lstcon_rpc_ent_t *ent;
+       lstcon_rpc_ent_t *ent;
 
-        while (!cfs_list_empty(head)) {
-                ent = cfs_list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
+       while (!list_empty(head)) {
+               ent = list_entry(head->next, lstcon_rpc_ent_t, rpe_link);
 
-                cfs_list_del(&ent->rpe_link);
-                free(ent);
-        }
+               list_del(&ent->rpe_link);
+               free(ent);
+       }
 }
 
 void
-lst_reset_rpcent(cfs_list_t *head)
+lst_reset_rpcent(struct list_head *head)
 {
-        lstcon_rpc_ent_t *ent;
+       lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
-                ent->rpe_sid      = LST_INVALID_SID;
-                ent->rpe_peer.nid = LNET_NID_ANY;
-                ent->rpe_peer.pid = LNET_PID_ANY;
-                ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
-        }
+       list_for_each_entry(ent, head, rpe_link) {
+               ent->rpe_sid       = LST_INVALID_SID;
+               ent->rpe_peer.nid  = LNET_NID_ANY;
+               ent->rpe_peer.pid  = LNET_PID_ANY;
+               ent->rpe_rpc_errno = ent->rpe_fwk_errno = 0;
+       }
 }
 
 int
-lst_alloc_rpcent(cfs_list_t *head, int count, int offset)
+lst_alloc_rpcent(struct list_head *head, int count, int offset)
 {
         lstcon_rpc_ent_t *ent;
         int               i;
@@ -431,23 +437,23 @@ lst_alloc_rpcent(cfs_list_t *head, int count, int offset)
 
                 memset(ent, 0, offsetof(lstcon_rpc_ent_t, rpe_payload[offset]));
 
-                ent->rpe_sid      = LST_INVALID_SID;
-                ent->rpe_peer.nid = LNET_NID_ANY;
-                ent->rpe_peer.pid = LNET_PID_ANY;
-                cfs_list_add(&ent->rpe_link, head);
-        }
+               ent->rpe_sid      = LST_INVALID_SID;
+               ent->rpe_peer.nid = LNET_NID_ANY;
+               ent->rpe_peer.pid = LNET_PID_ANY;
+               list_add(&ent->rpe_link, head);
+       }
 
-        return 0;
+       return 0;
 }
 
 void
-lst_print_transerr(cfs_list_t *head, char *optstr)
+lst_print_transerr(struct list_head *head, char *optstr)
 {
-        lstcon_rpc_ent_t  *ent;
+       lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
-                if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
-                        continue;
+       list_for_each_entry(ent, head, rpe_link) {
+               if (ent->rpe_rpc_errno == 0 && ent->rpe_fwk_errno == 0)
+                       continue;
 
                 if (ent->rpe_rpc_errno != 0) {
                         fprintf(stderr, "%s RPC failed on %s: %s\n",
@@ -456,7 +462,7 @@ lst_print_transerr(cfs_list_t *head, char *optstr)
                         continue;
                 }
 
-                fprintf(stderr, "%s failed on %s: %s\n",
+               fprintf(stderr, "operation %s failed on %s: %s\n",
                         optstr, libcfs_id2str(ent->rpe_peer),
                         strerror(ent->rpe_fwk_errno));
         }
@@ -470,7 +476,7 @@ int lst_info_group_ioctl(char *name, lstcon_ndlist_ent_t *gent,
                          int *idx, int *count, lstcon_node_ent_t *dents);
 
 int lst_query_batch_ioctl(char *batch, int test, int server,
-                          int timeout, cfs_list_t *head);
+                         int timeout, struct list_head *head);
 
 int
 lst_ioctl(unsigned int opc, void *buf, int len)
@@ -505,7 +511,7 @@ lst_ioctl(unsigned int opc, void *buf, int len)
 }
 
 int
-lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
+lst_new_session_ioctl(char *name, int timeout, int force, lst_sid_t *sid)
 {
         lstio_session_new_args_t args = {0};
 
@@ -513,6 +519,7 @@ lst_new_session_ioctl (char *name, int timeout, int force, lst_sid_t *sid)
         args.lstio_ses_timeout = timeout;
         args.lstio_ses_force   = force;
         args.lstio_ses_idp     = sid;
+       args.lstio_ses_feats   = session_features;
         args.lstio_ses_nmlen   = strlen(name);
         args.lstio_ses_namep   = name;
 
@@ -591,7 +598,7 @@ jt_lst_new_session(int argc,  char **argv)
                 if (rc != 0)
                         snprintf(host, sizeof(host), "unknown_host");
 
-                snprintf(buf, LST_NAME_SIZE, "%s@%s", user, host);
+               snprintf(buf, sizeof(buf), "%s@%s", user, host);
                 name = buf;
 
         } else {
@@ -600,32 +607,31 @@ jt_lst_new_session(int argc,  char **argv)
         }
 
         rc = lst_new_session_ioctl(name, timeout, force, &session_id);
-
         if (rc != 0) {
                 lst_print_error("session", "Failed to create session: %s\n",
                                 strerror(errno));
                 return rc;
         }
 
-        fprintf(stdout, "SESSION: %s TIMEOUT: %d FORCE: %s\n",
-                name, timeout, force ? "Yes": "No");
-
-        return rc;
+       fprintf(stdout, "SESSION: %s FEATURES: %x TIMEOUT: %d FORCE: %s\n",
+               name, session_features, timeout, force ? "Yes" : "No");
+       return 0;
 }
 
 int
-lst_session_info_ioctl(char *name, int len, int *key,
-                       lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
+lst_session_info_ioctl(char *name, int len, int *key, unsigned *featp,
+                      lst_sid_t *sid, lstcon_ndlist_ent_t *ndinfo)
 {
-        lstio_session_info_args_t args = {0};
+       lstio_session_info_args_t args = {0};
 
-        args.lstio_ses_idp    = sid;
-        args.lstio_ses_keyp   = key;
-        args.lstio_ses_ndinfo = ndinfo;
-        args.lstio_ses_nmlen  = len;
-        args.lstio_ses_namep  = name;
+       args.lstio_ses_idp     = sid;
+       args.lstio_ses_keyp    = key;
+       args.lstio_ses_featp   = featp;
+       args.lstio_ses_ndinfo  = ndinfo;
+       args.lstio_ses_nmlen   = len;
+       args.lstio_ses_namep   = name;
 
-        return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
+       return lst_ioctl(LSTIO_SESSION_INFO, &args, sizeof(args));
 }
 
 int
@@ -634,10 +640,12 @@ jt_lst_show_session(int argc, char **argv)
         lstcon_ndlist_ent_t ndinfo;
         lst_sid_t           sid;
         char                name[LST_NAME_SIZE];
-        int                 key;
-        int                 rc;
+       unsigned            feats;
+       int                 key;
+       int                 rc;
 
-        rc = lst_session_info_ioctl(name, LST_NAME_SIZE, &key, &sid, &ndinfo);
+       rc = lst_session_info_ioctl(name, sizeof(name), &key,
+                                   &feats, &sid, &ndinfo);
 
         if (rc != 0) {
                 lst_print_error("session", "Failed to show session: %s\n",
@@ -645,9 +653,9 @@ jt_lst_show_session(int argc, char **argv)
                 return -1;
         }
 
-        fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d NODES: %d\n",
-                name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
-                key, ndinfo.nle_nnode);
+       fprintf(stdout, "%s ID: "LPU64"@%s, KEY: %d FEATURES: %x NODES: %d\n",
+               name, sid.ses_stamp, libcfs_nid2str(sid.ses_nid),
+               key, feats, ndinfo.nle_nnode);
 
         return 0;
 }
@@ -704,7 +712,7 @@ jt_lst_end_session(int argc, char **argv)
 
 int
 lst_ping_ioctl(char *str, int type, int timeout,
-               int count, lnet_process_id_t *ids, cfs_list_t *head)
+              int count, lnet_process_id_t *ids, struct list_head *head)
 {
         lstio_debug_args_t args = {0};
 
@@ -728,14 +736,15 @@ lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
         lstcon_test_batch_ent_t ent;
         lstcon_ndlist_ent_t    *entp = &ent.tbe_cli_nle;
         lst_sid_t               sid;
-        int                     key;
-        int                     rc;
+       unsigned                feats;
+       int                     key;
+       int                     rc;
 
-        switch (type) {
-        case LST_OPC_SESSION:
-                rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
-                                            &key, &sid, entp);
-                break;
+       switch (type) {
+       case LST_OPC_SESSION:
+               rc = lst_session_info_ioctl(buf, LST_NAME_SIZE,
+                                           &key, &feats, &sid, entp);
+               break;
 
         case LST_OPC_BATCHSRV:
                 entp = &ent.tbe_srv_nle;
@@ -765,9 +774,9 @@ lst_get_node_count(int type, char *str, int *countp, lnet_process_id_t **idspp)
 int
 jt_lst_ping(int argc,  char **argv)
 {
-        cfs_list_t         head;
-        lnet_process_id_t *ids = NULL;
-        lstcon_rpc_ent_t  *ent = NULL;
+       struct list_head   head;
+       lnet_process_id_t *ids = NULL;
+       lstcon_rpc_ent_t  *ent = NULL;
         char              *str = NULL;
         int                optidx  = 0;
         int                server  = 0;
@@ -851,7 +860,7 @@ jt_lst_ping(int argc,  char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, LST_NAME_SIZE);
         if (rc != 0) {
@@ -874,17 +883,17 @@ jt_lst_ping(int argc,  char **argv)
                 goto out;
         }
 
-        /* ignore RPC errors and framwork errors */
-        cfs_list_for_each_entry_typed(ent, &head, lstcon_rpc_ent_t, rpe_link) {
-                fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
-                        libcfs_id2str(ent->rpe_peer),
-                        lst_node_state2str(ent->rpe_state),
-                        (ent->rpe_state == LST_NODE_ACTIVE ||
-                         ent->rpe_state == LST_NODE_BUSY)?
-                                 (ent->rpe_rpc_errno == 0 ?
-                                         &ent->rpe_payload[0] : "Unknown") :
-                                 "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
-        }
+       /* ignore RPC errors and framwork errors */
+       list_for_each_entry(ent, &head, rpe_link) {
+               fprintf(stdout, "\t%s: %s [session: %s id: %s]\n",
+                       libcfs_id2str(ent->rpe_peer),
+                       lst_node_state2str(ent->rpe_state),
+                       (ent->rpe_state == LST_NODE_ACTIVE ||
+                        ent->rpe_state == LST_NODE_BUSY) ?
+                               (ent->rpe_rpc_errno == 0 ?
+                                       &ent->rpe_payload[0] : "Unknown") :
+                               "<NULL>", libcfs_nid2str(ent->rpe_sid.ses_nid));
+       }
 
 out:
         lst_free_rpcent(&head);
@@ -898,7 +907,7 @@ out:
 
 int
 lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
-                     cfs_list_t *resultp)
+                    unsigned *featp, struct list_head *resultp)
 {
         lstio_group_nodes_args_t args = {0};
 
@@ -906,6 +915,7 @@ lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
         args.lstio_grp_nmlen   = strlen(name);
         args.lstio_grp_namep   = name;
         args.lstio_grp_count   = count;
+       args.lstio_grp_featp   = featp;
         args.lstio_grp_idsp    = ids;
         args.lstio_grp_resultp = resultp;
 
@@ -913,106 +923,195 @@ lst_add_nodes_ioctl (char *name, int count, lnet_process_id_t *ids,
 }
 
 int
-lst_add_group_ioctl (char *name)
+lst_del_group_ioctl(char *name)
 {
-        lstio_group_add_args_t args = {0};
+       lstio_group_del_args_t args = {0};
 
-        args.lstio_grp_key     =  session_key;
-        args.lstio_grp_nmlen   =  strlen(name);
-        args.lstio_grp_namep   =  name;
+       args.lstio_grp_key   = session_key;
+       args.lstio_grp_nmlen = strlen(name);
+       args.lstio_grp_namep = name;
 
-        return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
+       return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
 }
 
 int
-jt_lst_add_group(int argc, char **argv)
+lst_del_group(char *grp_name)
 {
-        cfs_list_t         head;
-        lnet_process_id_t *ids;
-        char              *name;
-        int                count;
-        int                rc;
-        int                i;
+       int     rc;
 
-        if (session_key == 0) {
-                fprintf(stderr,
-                        "Can't find env LST_SESSION or value is not valid\n");
-                return -1;
-        }
+       rc = lst_del_group_ioctl(grp_name);
+       if (rc == 0) {
+               fprintf(stdout, "Group is deleted\n");
+               return 0;
+       }
 
-        if (argc < 3) {
-                lst_print_usage(argv[0]);
-                return -1;
-        }
+       if (rc == -1) {
+               lst_print_error("group", "Failed to delete group: %s\n",
+                               strerror(errno));
+               return rc;
+       }
 
-        name = argv[1];
-        if (strlen(name) >= LST_NAME_SIZE) {
-                fprintf(stderr, "Name length is limited to %d\n",
-                        LST_NAME_SIZE - 1);
-                return -1;
-        }
-
-        rc = lst_add_group_ioctl(name);
-        if (rc != 0) {
-                lst_print_error("group", "Failed to add group %s: %s\n",
-                                name, strerror(errno));
-                return -1;
-        }
-
-        CFS_INIT_LIST_HEAD(&head);
-
-        for (i = 2; i < argc; i++) {
-                /* parse address list */
-                rc = lst_parse_nids(argv[i], &count, &ids);
-                if (rc < 0) {
-                        fprintf(stderr, "Ignore invalid id list %s\n",
-                                argv[i]);
-                        continue;
-                }
-
-                if (count == 0)
-                        continue;
-
-                rc = lst_alloc_rpcent(&head, count, 0);
-                if (rc != 0) {
-                        fprintf(stderr, "Out of memory\n");
-                        break;
-                }
+       fprintf(stderr, "Group is deleted with some errors\n");
 
-                rc = lst_add_nodes_ioctl(name, count, ids, &head);
+       if (trans_stat.trs_rpc_errno != 0) {
+               fprintf(stderr,
+                       "[RPC] Failed to send %d end session RPCs: %s\n",
+                       lstcon_rpc_stat_failure(&trans_stat, 0),
+                       strerror(trans_stat.trs_rpc_errno));
+       }
 
-                free(ids);
+       if (trans_stat.trs_fwk_errno != 0) {
+               fprintf(stderr,
+                       "[FWK] Failed to end session on %d nodes: %s\n",
+               lstcon_sesop_stat_failure(&trans_stat, 0),
+               strerror(trans_stat.trs_fwk_errno));
+       }
 
-                if (rc == 0) {
-                        lst_free_rpcent(&head);
-                        fprintf(stderr, "%s are added to session\n", argv[i]);
-                        continue;
-                }
+       return -1;
+}
 
-                if (rc == -1) {
-                        lst_free_rpcent(&head);
-                        lst_print_error("group", "Failed to add nodes %s: %s\n",
-                                        argv[i], strerror(errno));
-                        break;
-                }
+int
+lst_add_group_ioctl (char *name)
+{
+        lstio_group_add_args_t args = {0};
 
-                lst_print_transerr(&head, "create session");
-                lst_free_rpcent(&head);
-        }
+        args.lstio_grp_key     =  session_key;
+        args.lstio_grp_nmlen   =  strlen(name);
+        args.lstio_grp_namep   =  name;
 
-        return rc;
+        return lst_ioctl(LSTIO_GROUP_ADD, &args, sizeof(args));
 }
 
 int
-lst_del_group_ioctl (char *name)
+jt_lst_add_group(int argc, char **argv)
 {
-        lstio_group_del_args_t args = {0};
-
-        args.lstio_grp_key   = session_key;
-        args.lstio_grp_nmlen = strlen(name);
-        args.lstio_grp_namep = name;
-
-        return lst_ioctl(LSTIO_GROUP_DEL, &args, sizeof(args));
+       struct list_head   head;
+       lnet_process_id_t *ids;
+       char              *name;
+       unsigned           feats = session_features;
+       int                count;
+       int                rc;
+       int                i;
+       bool               nodes_added = false;
+
+       if (session_key == 0) {
+               fprintf(stderr,
+                       "Can't find env LST_SESSION or value is not valid\n");
+               return -1;
+       }
+
+       if (argc < 3) {
+               lst_print_usage(argv[0]);
+               return -1;
+       }
+
+       name = argv[1];
+       if (strlen(name) >= LST_NAME_SIZE) {
+               fprintf(stderr, "Name length is limited to %d\n",
+                       LST_NAME_SIZE - 1);
+               return -1;
+       }
+
+       rc = lst_add_group_ioctl(name);
+       if (rc != 0) {
+               lst_print_error("group", "Failed to add group %s: %s\n",
+                               name, strerror(errno));
+               return -1;
+       }
+
+       INIT_LIST_HEAD(&head);
+
+       for (i = 2; i < argc; i++) {
+               /* parse address list */
+               rc = lst_parse_nids(argv[i], &count, &ids);
+               if (rc < 0) {
+                       fprintf(stderr, "Ignore invalid id list %s\n",
+                               argv[i]);
+                       continue;
+               }
+
+               if (count == 0)
+                       continue;
+
+               rc = lst_alloc_rpcent(&head, count, 0);
+               if (rc != 0) {
+                       fprintf(stderr, "Out of memory\n");
+                       free(ids);
+                       rc = -1;
+                       goto failed;
+               }
+
+               rc = lst_add_nodes_ioctl(name, count, ids, &feats, &head);
+
+               free(ids);
+
+               if (rc != 0)
+                       goto failed;
+
+               fprintf(stdout, "%s are added to session\n", argv[i]);
+
+               nodes_added = true;
+
+               if ((feats & session_features) != session_features) {
+                       fprintf(stdout,
+                               "Warning, this session will run with "
+                               "compatible mode because some test nodes "
+                               "might not understand these features: %x\n",
+                               (~feats & session_features));
+               }
+
+               lst_free_rpcent(&head);
+       }
+
+       if (!nodes_added) {
+               /*
+                * The selftest kernel module expects that a group should
+                * have at least one node, since it doesn't make sense for
+                * an empty group to be added to a test.
+                */
+               fprintf(stderr,
+                       "No nodes added successfully, deleting group %s\n",
+                       name);
+               rc = lst_del_group(name);
+               if (rc != 0) {
+                       fprintf(stderr,
+                               "Failed to delete group %s."
+                               "  Group is empty.\n", name);
+               }
+       }
+
+       return rc;
+
+failed:
+       if (rc == -1) {
+               lst_print_error("group", "Failed to add nodes %s: %s\n",
+                               argv[i], strerror(errno));
+
+       } else {
+               if (trans_stat.trs_fwk_errno == EPROTO) {
+                       fprintf(stderr,
+                               "test nodes might have different LST "
+                               "features, please disable some features by "
+                               "setting LST_FEATURES\n");
+               }
+
+               lst_print_transerr(&head, "create session");
+       }
+
+       lst_free_rpcent(&head);
+
+       if (!nodes_added) {
+               fprintf(stderr,
+                       "No nodes added successfully, deleting group %s\n",
+                       name);
+               if (lst_del_group(name) != 0) {
+                       fprintf(stderr,
+                               "Failed to delete group %s."
+                               "  Group is empty.\n", name);
+               }
+       }
+
+       return rc;
 }
 
 int
@@ -1031,39 +1130,14 @@ jt_lst_del_group(int argc, char **argv)
                 return -1;
         }
 
-        rc = lst_del_group_ioctl(argv[1]);
-        if (rc == 0) {
-                fprintf(stdout, "Group is deleted\n");
-                return 0;
-        }
+       rc = lst_del_group(argv[1]);
 
-        if (rc == -1) {
-                lst_print_error("group", "Failed to delete group: %s\n",
-                                strerror(errno));
-                return rc;
-        }
-
-        fprintf(stderr, "Group is deleted with some errors\n");
-
-        if (trans_stat.trs_rpc_errno != 0) {
-                fprintf(stderr, "[RPC] Failed to send %d end session RPCs: %s\n",
-                        lstcon_rpc_stat_failure(&trans_stat, 0),
-                        strerror(trans_stat.trs_rpc_errno));
-        }
-
-        if (trans_stat.trs_fwk_errno != 0) {
-                fprintf(stderr,
-                        "[FWK] Failed to end session on %d nodes: %s\n",
-                        lstcon_sesop_stat_failure(&trans_stat, 0),
-                        strerror(trans_stat.trs_fwk_errno));
-        }
-
-        return -1;
+       return rc;
 }
 
 int
 lst_update_group_ioctl(int opc, char *name, int clean, int count,
-                       lnet_process_id_t *ids, cfs_list_t *resultp)
+                      lnet_process_id_t *ids, struct list_head *resultp)
 {
         lstio_group_update_args_t args = {0};
 
@@ -1082,7 +1156,7 @@ lst_update_group_ioctl(int opc, char *name, int clean, int count,
 int
 jt_lst_update_group(int argc, char **argv)
 {
-        cfs_list_t         head;
+       struct list_head         head;
         lnet_process_id_t *ids = NULL;
         char              *str = NULL;
         char              *grp = NULL;
@@ -1156,7 +1230,7 @@ jt_lst_update_group(int argc, char **argv)
 
         grp = argv[optind];
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         if (opc == LST_GROUP_RMND || opc == LST_GROUP_REFRESH) {
                 rc = lst_get_node_count(opc == LST_GROUP_RMND ? LST_OPC_NODES :
@@ -1413,7 +1487,7 @@ jt_lst_list_group(int argc, char **argv)
 
 int
 lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
-                int timeout, cfs_list_t *resultp)
+               int timeout, struct list_head *resultp)
 {
         lstio_stat_args_t args = {0};
 
@@ -1429,11 +1503,11 @@ lst_stat_ioctl (char *name, int count, lnet_process_id_t *idsp,
 }
 
 typedef struct {
-        cfs_list_t              srp_link;
+       struct list_head              srp_link;
         int                     srp_count;
         char                   *srp_name;
         lnet_process_id_t      *srp_ids;
-        cfs_list_t              srp_result[2];
+       struct list_head              srp_result[2];
 } lst_stat_req_param_t;
 
 static void
@@ -1463,8 +1537,8 @@ lst_stat_req_param_alloc(char *name, lst_stat_req_param_t **srpp, int save_old)
                 return -ENOMEM;
 
         memset(srp, 0, sizeof(*srp));
-        CFS_INIT_LIST_HEAD(&srp->srp_result[0]);
-        CFS_INIT_LIST_HEAD(&srp->srp_result[1]);
+       INIT_LIST_HEAD(&srp->srp_result[0]);
+       INIT_LIST_HEAD(&srp->srp_result[1]);
 
         rc = lst_get_node_count(LST_OPC_GROUP, name,
                                 &srp->srp_count, NULL);
@@ -1558,18 +1632,18 @@ lst_lnet_stat_value(int bw, int send, int off)
 
 static void
 lst_timeval_diff(struct timeval *tv1,
-                 struct timeval *tv2, struct timeval *df)
+                struct timeval *tv2, struct timeval *df)
 {
-        if (tv1->tv_usec >= tv2->tv_usec) {
-                df->tv_sec  = tv1->tv_sec - tv2->tv_sec;
-                df->tv_usec = tv1->tv_usec - tv2->tv_usec;
-                return;
-        }
+       if (tv1->tv_usec >= tv2->tv_usec) {
+               df->tv_sec  = tv1->tv_sec - tv2->tv_sec;
+               df->tv_usec = tv1->tv_usec - tv2->tv_usec;
+               return;
+       }
 
-        df->tv_sec  = tv1->tv_sec - 1 - tv2->tv_sec;
-        df->tv_usec = tv1->tv_sec + 1000000 - tv2->tv_usec;
+       df->tv_sec  = tv1->tv_sec - 1 - tv2->tv_sec;
+       df->tv_usec = tv1->tv_usec + 1000000 - tv2->tv_usec;
 
-        return;
+       return;
 }
 
 void
@@ -1691,10 +1765,10 @@ lst_print_lnet_stat(char *name, int bwrt, int rdwr, int type)
 }
 
 void
-lst_print_stat(char *name, cfs_list_t *resultp,
-               int idx, int lnet, int bwrt, int rdwr, int type)
+lst_print_stat(char *name, struct list_head *resultp,
+              int idx, int lnet, int bwrt, int rdwr, int type)
 {
-        cfs_list_t        tmp[2];
+       struct list_head        tmp[2];
         lstcon_rpc_ent_t *new;
         lstcon_rpc_ent_t *old;
         sfw_counters_t   *sfwk_new;
@@ -1703,24 +1777,23 @@ lst_print_stat(char *name, cfs_list_t *resultp,
         srpc_counters_t  *srpc_old;
         lnet_counters_t  *lnet_new;
         lnet_counters_t  *lnet_old;
-        struct timeval    tv;
         float             delta;
         int               errcount = 0;
 
-        CFS_INIT_LIST_HEAD(&tmp[0]);
-        CFS_INIT_LIST_HEAD(&tmp[1]);
+       INIT_LIST_HEAD(&tmp[0]);
+       INIT_LIST_HEAD(&tmp[1]);
 
         memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
 
-        while (!cfs_list_empty(&resultp[idx])) {
-                if (cfs_list_empty(&resultp[1 - idx])) {
+       while (!list_empty(&resultp[idx])) {
+               if (list_empty(&resultp[1 - idx])) {
                         fprintf(stderr, "Group is changed, re-run stat\n");
                         break;
                 }
 
-                new = cfs_list_entry(resultp[idx].next, lstcon_rpc_ent_t,
+               new = list_entry(resultp[idx].next, lstcon_rpc_ent_t,
                                      rpe_link);
-                old = cfs_list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
+               old = list_entry(resultp[1 - idx].next, lstcon_rpc_ent_t,
                                      rpe_link);
 
                 /* first time get stats result, can't calculate diff */
@@ -1733,11 +1806,11 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                         break;
                 }
 
-                cfs_list_del(&new->rpe_link);
-                cfs_list_add_tail(&new->rpe_link, &tmp[idx]);
+               list_del(&new->rpe_link);
+               list_add_tail(&new->rpe_link, &tmp[idx]);
 
-                cfs_list_del(&old->rpe_link);
-                cfs_list_add_tail(&old->rpe_link, &tmp[1 - idx]);
+               list_del(&old->rpe_link);
+               list_add_tail(&old->rpe_link, &tmp[1 - idx]);
 
                 if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
                     old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
@@ -1754,9 +1827,26 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                 lnet_new = (lnet_counters_t *)((char *)srpc_new + sizeof(*srpc_new));
                 lnet_old = (lnet_counters_t *)((char *)srpc_old + sizeof(*srpc_old));
 
-                lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
+               /* Prior to version 2.3, the running_ms field was a counter for
+                * the number of running tests.  We are looking at this value
+                * to determine if it is a millisecond timestamep (>= 2.3) or a
+                * test counter (< 2.3).  The number 500 is being used for this
+                * barrier as the test counter should never get this high, and
+                * the timestamp should never get this low. */
+
+               if (sfwk_new->running_ms > 500) {
+                       /* use the timestamp from the remote node, not our
+                        * rpe_stamp from when we copied up the data out of
+                        * the kernel */
+
+                       delta = (float) (sfwk_new->running_ms -
+                                       sfwk_old->running_ms) / 1000;
+               } else {
+                       struct timeval    tv;
 
-                delta = tv.tv_sec + (float)tv.tv_usec/1000000;
+                       lst_timeval_diff(&new->rpe_stamp, &old->rpe_stamp, &tv);
+                       delta = tv.tv_sec + (float)tv.tv_usec / 1000000;
+               }
 
                 if (!lnet) /* TODO */
                         continue;
@@ -1764,8 +1854,8 @@ lst_print_stat(char *name, cfs_list_t *resultp,
                 lst_cal_lnet_stat(delta, lnet_new, lnet_old);
         }
 
-        cfs_list_splice(&tmp[idx], &resultp[idx]);
-        cfs_list_splice(&tmp[1 - idx], &resultp[1 - idx]);
+       list_splice(&tmp[idx], &resultp[idx]);
+       list_splice(&tmp[1 - idx], &resultp[1 - idx]);
 
         if (errcount > 0)
                 fprintf(stdout, "Failed to stat on %d nodes\n", errcount);
@@ -1779,7 +1869,7 @@ lst_print_stat(char *name, cfs_list_t *resultp,
 int
 jt_lst_stat(int argc, char **argv)
 {
-        cfs_list_t            head;
+       struct list_head        head;
         lst_stat_req_param_t *srp;
         time_t                last    = 0;
         int                   optidx  = 0;
@@ -1796,19 +1886,19 @@ jt_lst_stat(int argc, char **argv)
 
         static struct option stat_opts[] =
         {
-                {"timeout", required_argument, 0, 't' },
-                {"delay"  , required_argument, 0, 'd' },
-                {"count"  , required_argument, 0, 'o' },
-                {"lnet"   , no_argument,       0, 'l' },
-                {"rpc"    , no_argument,       0, 'c' },
-                {"bw"     , no_argument,       0, 'b' },
-                {"rate"   , no_argument,       0, 'a' },
-                {"read"   , no_argument,       0, 'r' },
-                {"write"  , no_argument,       0, 'w' },
-                {"avg"    , no_argument,       0, 'g' },
-                {"min"    , no_argument,       0, 'n' },
-                {"max"    , no_argument,       0, 'x' },
-                {0,         0,                 0,  0  }
+               {"timeout"   , required_argument, 0, 't' },
+               {"delay"     , required_argument, 0, 'd' },
+               {"count"     , required_argument, 0, 'o' },
+               {"lnet"      , no_argument,      0, 'l' },
+               {"rpc"       , no_argument,      0, 'c' },
+               {"bw"        , no_argument,      0, 'b' },
+               {"rate"      , no_argument,      0, 'a' },
+               {"read"      , no_argument,      0, 'r' },
+               {"write"     , no_argument,      0, 'w' },
+               {"avg"       , no_argument,      0, 'g' },
+               {"min"       , no_argument,      0, 'n' },
+               {"max"       , no_argument,      0, 'x' },
+               {0,            0,                0,  0  }
         };
 
         if (session_key == 0) {
@@ -1818,7 +1908,7 @@ jt_lst_stat(int argc, char **argv)
         }
 
         while (1) {
-                c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
+               c = getopt_long(argc, argv, "t:d:lcbarwgnx", stat_opts, &optidx);
 
                 if (c == -1)
                         break;
@@ -1872,6 +1962,7 @@ jt_lst_stat(int argc, char **argv)
                         }
                         type |= 4;
                         break;
+
                 default:
                         lst_print_usage(argv[0]);
                         return -1;
@@ -1897,14 +1988,14 @@ jt_lst_stat(int argc, char **argv)
         if (count != -1)
             count++;
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         while (optind < argc) {
                 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 1);
                 if (rc != 0)
                         goto out;
 
-                cfs_list_add_tail(&srp->srp_link, &head);
+               list_add_tail(&srp->srp_link, &head);
         }
 
         do {
@@ -1914,11 +2005,9 @@ jt_lst_stat(int argc, char **argv)
                         sleep(delay - now + last);
                         time(&now);
                 }
+               last = now;
 
-                last = now;
-
-                cfs_list_for_each_entry_typed(srp, &head, lst_stat_req_param_t,
-                                              srp_link) {
+               list_for_each_entry(srp, &head, srp_link) {
                         rc = lst_stat_ioctl(srp->srp_name,
                                             srp->srp_count, srp->srp_ids,
                                             timeout, &srp->srp_result[idx]);
@@ -1928,8 +2017,8 @@ jt_lst_stat(int argc, char **argv)
                                 goto out;
                         }
 
-                        lst_print_stat(srp->srp_name, srp->srp_result,
-                                       idx, lnet, bwrt, rdwr, type);
+                       lst_print_stat(srp->srp_name, srp->srp_result,
+                                      idx, lnet, bwrt, rdwr, type);
 
                         lst_reset_rpcent(&srp->srp_result[1 - idx]);
                 }
@@ -1941,10 +2030,10 @@ jt_lst_stat(int argc, char **argv)
         } while (count == -1 || count > 0);
 
 out:
-        while (!cfs_list_empty(&head)) {
-                srp = cfs_list_entry(head.next, lst_stat_req_param_t, srp_link);
+       while (!list_empty(&head)) {
+               srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
 
-                cfs_list_del(&srp->srp_link);
+               list_del(&srp->srp_link);
                 lst_stat_req_param_free(srp);
         }
 
@@ -1954,12 +2043,11 @@ out:
 int
 jt_lst_show_error(int argc, char **argv)
 {
-        cfs_list_t            head;
+       struct list_head            head;
         lst_stat_req_param_t *srp;
         lstcon_rpc_ent_t     *ent;
         sfw_counters_t       *sfwk;
         srpc_counters_t      *srpc;
-        lnet_counters_t      *lnet;
         int                   show_rpc = 1;
         int                   optidx   = 0;
         int                   rc       = 0;
@@ -2000,18 +2088,17 @@ jt_lst_show_error(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         while (optind < argc) {
                 rc = lst_stat_req_param_alloc(argv[optind++], &srp, 0);
                 if (rc != 0)
                         goto out;
 
-                cfs_list_add_tail(&srp->srp_link, &head);
+               list_add_tail(&srp->srp_link, &head);
         }
 
-        cfs_list_for_each_entry_typed(srp, &head, lst_stat_req_param_t,
-                                      srp_link) {
+       list_for_each_entry(srp, &head, srp_link) {
                 rc = lst_stat_ioctl(srp->srp_name, srp->srp_count,
                                     srp->srp_ids, 10, &srp->srp_result[0]);
 
@@ -2025,8 +2112,7 @@ jt_lst_show_error(int argc, char **argv)
 
                 ecount = 0;
 
-                cfs_list_for_each_entry_typed(ent, &srp->srp_result[0],
-                                              lstcon_rpc_ent_t, rpe_link) {
+               list_for_each_entry(ent, &srp->srp_result[0], rpe_link) {
                         if (ent->rpe_rpc_errno != 0) {
                                 ecount ++;
                                 fprintf(stderr, "RPC failure, can't show error on %s\n",
@@ -2043,7 +2129,6 @@ jt_lst_show_error(int argc, char **argv)
 
                         sfwk = (sfw_counters_t *)&ent->rpe_payload[0];
                         srpc = (srpc_counters_t *)((char *)sfwk + sizeof(*sfwk));
-                        lnet = (lnet_counters_t *)((char *)srpc + sizeof(*srpc));
 
                         if (srpc->errors == 0 &&
                             sfwk->brw_errors == 0 && sfwk->ping_errors == 0)
@@ -2070,10 +2155,10 @@ jt_lst_show_error(int argc, char **argv)
                 fprintf(stdout, "Total %d error nodes in %s\n", ecount, srp->srp_name);
         }
 out:
-        while (!cfs_list_empty(&head)) {
-                srp = cfs_list_entry(head.next, lst_stat_req_param_t, srp_link);
+       while (!list_empty(&head)) {
+               srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
 
-                cfs_list_del(&srp->srp_link);
+               list_del(&srp->srp_link);
                 lst_stat_req_param_free(srp);
         }
 
@@ -2127,7 +2212,7 @@ jt_lst_add_batch(int argc, char **argv)
 }
 
 int
-lst_start_batch_ioctl (char *name, int timeout, cfs_list_t *resultp)
+lst_start_batch_ioctl(char *name, int timeout, struct list_head *resultp)
 {
         lstio_batch_run_args_t args = {0};
 
@@ -2143,7 +2228,7 @@ lst_start_batch_ioctl (char *name, int timeout, cfs_list_t *resultp)
 int
 jt_lst_start_batch(int argc, char **argv)
 {
-        cfs_list_t        head;
+       struct list_head        head;
         char             *batch;
         int               optidx  = 0;
         int               timeout = 0;
@@ -2199,7 +2284,7 @@ jt_lst_start_batch(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, 0);
         if (rc != 0) {
@@ -2230,7 +2315,7 @@ jt_lst_start_batch(int argc, char **argv)
 }
 
 int
-lst_stop_batch_ioctl(char *name, int force, cfs_list_t *resultp)
+lst_stop_batch_ioctl(char *name, int force, struct list_head *resultp)
 {
         lstio_batch_stop_args_t args = {0};
 
@@ -2246,7 +2331,7 @@ lst_stop_batch_ioctl(char *name, int force, cfs_list_t *resultp)
 int
 jt_lst_stop_batch(int argc, char **argv)
 {
-        cfs_list_t        head;
+       struct list_head        head;
         char             *batch;
         int               force = 0;
         int               optidx;
@@ -2302,7 +2387,7 @@ jt_lst_stop_batch(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_alloc_rpcent(&head, count, 0);
         if (rc != 0) {
@@ -2599,7 +2684,7 @@ loop:
 
 int
 lst_query_batch_ioctl(char *batch, int test, int server,
-                      int timeout, cfs_list_t *head)
+                     int timeout, struct list_head *head)
 {
         lstio_batch_query_args_t args = {0};
 
@@ -2615,12 +2700,12 @@ lst_query_batch_ioctl(char *batch, int test, int server,
 }
 
 void
-lst_print_tsb_verbose(cfs_list_t *head,
+lst_print_tsb_verbose(struct list_head *head,
                       int active, int idle, int error)
 {
         lstcon_rpc_ent_t *ent;
 
-        cfs_list_for_each_entry_typed(ent, head, lstcon_rpc_ent_t, rpe_link) {
+       list_for_each_entry(ent, head, rpe_link) {
                 if (ent->rpe_priv[0] == 0 && active)
                         continue;
 
@@ -2643,7 +2728,7 @@ int
 jt_lst_query_batch(int argc, char **argv)
 {
         lstcon_test_batch_ent_t ent;
-        cfs_list_t              head;
+       struct list_head              head;
         char                   *batch   = NULL;
         time_t                  last    = 0;
         int                     optidx  = 0;
@@ -2740,7 +2825,7 @@ jt_lst_query_batch(int argc, char **argv)
         }
 
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         if (verbose) {
                 rc = lst_info_batch_ioctl(batch, test, server,
@@ -2884,7 +2969,7 @@ lst_get_bulk_param(int argc, char **argv, lst_test_bulk_param_t *bulk)
                         else if (*end == 'm' || *end == 'M')
                                 bulk->blk_size *= 1024 * 1024;
 
-                        if (bulk->blk_size > CFS_PAGE_SIZE * LNET_MAX_IOV) {
+                       if (bulk->blk_size > PAGE_CACHE_SIZE * LNET_MAX_IOV) {
                                 fprintf(stderr, "Size exceed limitation: %d bytes\n",
                                         bulk->blk_size);
                                 return -1;
@@ -2955,7 +3040,7 @@ lst_get_test_param(char *test, int argc, char **argv, void **param, int *plen)
 int
 lst_add_test_ioctl(char *batch, int type, int loop, int concur,
                    int dist, int span, char *sgrp, char *dgrp,
-                   void *param, int plen, int *retp, cfs_list_t *resultp)
+                  void *param, int plen, int *retp, struct list_head *resultp)
 {
         lstio_test_args_t args = {0};
 
@@ -2983,7 +3068,7 @@ lst_add_test_ioctl(char *batch, int type, int loop, int concur,
 int
 jt_lst_add_test(int argc, char **argv)
 {
-        cfs_list_t    head;
+       struct list_head    head;
         char         *batch  = NULL;
         char         *test   = NULL;
         char         *dstr   = NULL;
@@ -3085,7 +3170,7 @@ jt_lst_add_test(int argc, char **argv)
                 return -1;
         }
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lst_get_node_count(LST_OPC_GROUP, from, &fcount, NULL);
         if (rc != 0) {
@@ -3154,9 +3239,9 @@ static command_t lst_cmdlist[] = {
          "Usage: lst update_group NAME [--clean] [--refresh] [--remove IDs]"            },
         {"list_group",          jt_lst_list_group,      NULL,
           "Usage: lst list_group [--active] [--busy] [--down] [--unknown] GROUP ..."    },
-        {"stat",                jt_lst_stat,            NULL,
-         "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
-         " [--timeout #] [--delay #] [--count #] GROUP [GROUP]"                         },
+       {"stat",                jt_lst_stat,            NULL,
+        "Usage: lst stat [--bw] [--rate] [--read] [--write] [--max] [--min] [--avg] "
+        " [--timeout #] [--delay #] [--count #] GROUP [GROUP]"                         },
         {"show_error",          jt_lst_show_error,      NULL,
          "Usage: lst show_error NAME | IDS ..."                                         },
         {"add_batch",           jt_lst_add_batch,       NULL,
@@ -3179,7 +3264,20 @@ static command_t lst_cmdlist[] = {
 int
 lst_initialize(void)
 {
-        char   *key;
+       char   *key;
+       char   *feats;
+
+       feats = getenv("LST_FEATURES");
+       if (feats != NULL)
+               session_features = strtol(feats, NULL, 16);
+
+       if ((session_features & ~LST_FEATS_MASK) != 0) {
+               fprintf(stderr,
+                       "Unsupported session features %x, "
+                       "only support these features so far: %x\n",
+                       (session_features & ~LST_FEATS_MASK), LST_FEATS_MASK);
+               return -1;
+       }
 
         key = getenv("LST_SESSION");