Whamcloud - gitweb
LU-2456 lnet: Dynamic LNet Configuration (DLC) IOCTL changes
[fs/lustre-release.git] / lnet / selftest / console.c
index 9689506..73031a5 100644 (file)
@@ -73,21 +73,21 @@ lstcon_node_get(lstcon_node_t *nd)
 static int
 lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
 {
-        lstcon_ndlink_t *ndl;
-        unsigned int     idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
+       lstcon_ndlink_t *ndl;
+       unsigned int     idx = LNET_NIDADDR(id.nid) % LST_GLOBAL_HASHSIZE;
 
-        LASSERT (id.nid != LNET_NID_ANY);
+       LASSERT(id.nid != LNET_NID_ANY);
 
-        cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_hash[idx],
-                                      lstcon_ndlink_t, ndl_hlink) {
-                if (ndl->ndl_node->nd_id.nid != id.nid ||
-                    ndl->ndl_node->nd_id.pid != id.pid)
-                        continue;
+       list_for_each_entry(ndl, &console_session.ses_ndl_hash[idx],
+                           ndl_hlink) {
+               if (ndl->ndl_node->nd_id.nid != id.nid ||
+                   ndl->ndl_node->nd_id.pid != id.pid)
+                       continue;
 
-                lstcon_node_get(ndl->ndl_node);
-                *ndpp = ndl->ndl_node;
-                return 0;
-        }
+               lstcon_node_get(ndl->ndl_node);
+               *ndpp = ndl->ndl_node;
+               return 0;
+       }
         
         if (!create)
                 return -ENOENT;
@@ -107,59 +107,58 @@ lstcon_node_find(lnet_process_id_t id, lstcon_node_t **ndpp, int create)
         ndl->ndl_node->nd_timeout = 0;
         memset(&ndl->ndl_node->nd_ping, 0, sizeof(lstcon_rpc_t));
 
-        /* queued in global hash & list, no refcount is taken by
-         * global hash & list, if caller release his refcount,
-         * node will be released */
-        cfs_list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
-        cfs_list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
+       /* queued in global hash & list, no refcount is taken by
+        * global hash & list, if caller release his refcount,
+        * node will be released */
+       list_add_tail(&ndl->ndl_hlink, &console_session.ses_ndl_hash[idx]);
+       list_add_tail(&ndl->ndl_link, &console_session.ses_ndl_list);
 
-        return 0;
+       return 0;
 }
 
 void
 lstcon_node_put(lstcon_node_t *nd)
 {
-        lstcon_ndlink_t  *ndl;
+       lstcon_ndlink_t *ndl;
 
-        LASSERT (nd->nd_ref > 0);
+       LASSERT(nd->nd_ref > 0);
 
-        if (--nd->nd_ref > 0)
-                return;
+       if (--nd->nd_ref > 0)
+               return;
 
-        ndl = (lstcon_ndlink_t *)(nd + 1);
+       ndl = (lstcon_ndlink_t *)(nd + 1);
 
-        LASSERT (!cfs_list_empty(&ndl->ndl_link));
-        LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
+       LASSERT(!list_empty(&ndl->ndl_link));
+       LASSERT(!list_empty(&ndl->ndl_hlink));
 
-        /* remove from session */
-        cfs_list_del(&ndl->ndl_link);
-        cfs_list_del(&ndl->ndl_hlink);
+       /* remove from session */
+       list_del(&ndl->ndl_link);
+       list_del(&ndl->ndl_hlink);
 
-        LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
+       LIBCFS_FREE(nd, sizeof(lstcon_node_t) + sizeof(lstcon_ndlink_t));
 }
 
 static int
-lstcon_ndlink_find(cfs_list_t *hash,
+lstcon_ndlink_find(struct list_head *hash,
                    lnet_process_id_t id, lstcon_ndlink_t **ndlpp, int create)
 {
-        unsigned int     idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
-        lstcon_ndlink_t *ndl;
-        lstcon_node_t   *nd;
-        int              rc;
+       unsigned int     idx = LNET_NIDADDR(id.nid) % LST_NODE_HASHSIZE;
+       lstcon_ndlink_t *ndl;
+       lstcon_node_t   *nd;
+       int              rc;
 
-        if (id.nid == LNET_NID_ANY)
-                return -EINVAL;
+       if (id.nid == LNET_NID_ANY)
+               return -EINVAL;
 
-        /* search in hash */
-        cfs_list_for_each_entry_typed(ndl, &hash[idx],
-                                      lstcon_ndlink_t, ndl_hlink) {
-                if (ndl->ndl_node->nd_id.nid != id.nid ||
-                    ndl->ndl_node->nd_id.pid != id.pid)
-                        continue;
+       /* search in hash */
+       list_for_each_entry(ndl, &hash[idx], ndl_hlink) {
+               if (ndl->ndl_node->nd_id.nid != id.nid ||
+                   ndl->ndl_node->nd_id.pid != id.pid)
+                       continue;
 
-                *ndlpp = ndl;
-                return 0;
-        }
+               *ndlpp = ndl;
+               return 0;
+       }
 
         if (create == 0)
                 return -ENOENT;
@@ -177,20 +176,20 @@ lstcon_ndlink_find(cfs_list_t *hash,
         
         *ndlpp = ndl;
 
-        ndl->ndl_node = nd;
-        CFS_INIT_LIST_HEAD(&ndl->ndl_link);
-        cfs_list_add_tail(&ndl->ndl_hlink, &hash[idx]);
+       ndl->ndl_node = nd;
+       INIT_LIST_HEAD(&ndl->ndl_link);
+       list_add_tail(&ndl->ndl_hlink, &hash[idx]);
 
-        return  0;
+       return 0;
 }
 
 static void
 lstcon_ndlink_release(lstcon_ndlink_t *ndl)
 {
-        LASSERT (cfs_list_empty(&ndl->ndl_link));
-        LASSERT (!cfs_list_empty(&ndl->ndl_hlink));
+       LASSERT(list_empty(&ndl->ndl_link));
+       LASSERT(!list_empty(&ndl->ndl_hlink));
 
-        cfs_list_del(&ndl->ndl_hlink); /* delete from hash */
+       list_del(&ndl->ndl_hlink); /* delete from hash */
         lstcon_node_put(ndl->ndl_node);
 
         LIBCFS_FREE(ndl, sizeof(*ndl));
@@ -199,8 +198,8 @@ lstcon_ndlink_release(lstcon_ndlink_t *ndl)
 static int
 lstcon_group_alloc(char *name, lstcon_group_t **grpp)
 {
-        lstcon_group_t *grp;
-        int             i;
+       lstcon_group_t *grp;
+       int             i;
 
         LIBCFS_ALLOC(grp, offsetof(lstcon_group_t,
                                    grp_ndl_hash[LST_NODE_HASHSIZE]));
@@ -211,25 +210,31 @@ lstcon_group_alloc(char *name, lstcon_group_t **grpp)
                                 grp_ndl_hash[LST_NODE_HASHSIZE]));
 
         grp->grp_ref = 1;
-        if (name != NULL)
-                strcpy(grp->grp_name, name);
+       if (name != NULL) {
+               if (strlen(name) > sizeof(grp->grp_name)-1) {
+                       LIBCFS_FREE(grp, offsetof(lstcon_group_t,
+                                         grp_ndl_hash[LST_NODE_HASHSIZE]));
+                       return -E2BIG;
+               }
+               strncpy(grp->grp_name, name, sizeof(grp->grp_name));
+       }
 
-        CFS_INIT_LIST_HEAD(&grp->grp_link);
-        CFS_INIT_LIST_HEAD(&grp->grp_ndl_list);
-        CFS_INIT_LIST_HEAD(&grp->grp_trans_list);
+       INIT_LIST_HEAD(&grp->grp_link);
+       INIT_LIST_HEAD(&grp->grp_ndl_list);
+       INIT_LIST_HEAD(&grp->grp_trans_list);
 
-        for (i = 0; i < LST_NODE_HASHSIZE; i++)
-                CFS_INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
+       for (i = 0; i < LST_NODE_HASHSIZE; i++)
+               INIT_LIST_HEAD(&grp->grp_ndl_hash[i]);
 
-        *grpp = grp;
+       *grpp = grp;
 
-        return 0;
+       return 0;
 }
 
 static void
 lstcon_group_addref(lstcon_group_t *grp)
 {
-        grp->grp_ref ++;
+       grp->grp_ref++;
 }
 
 static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
@@ -237,53 +242,50 @@ static void lstcon_group_ndlink_release(lstcon_group_t *, lstcon_ndlink_t *);
 static void
 lstcon_group_drain(lstcon_group_t *grp, int keep)
 {
-        lstcon_ndlink_t *ndl;
-        lstcon_ndlink_t *tmp;
+       lstcon_ndlink_t *ndl;
+       lstcon_ndlink_t *tmp;
 
-        cfs_list_for_each_entry_safe_typed(ndl, tmp, &grp->grp_ndl_list,
-                                           lstcon_ndlink_t, ndl_link) {
-                if ((ndl->ndl_node->nd_state & keep) == 0)
-                        lstcon_group_ndlink_release(grp, ndl);
-        }
+       list_for_each_entry_safe(ndl, tmp, &grp->grp_ndl_list, ndl_link) {
+               if ((ndl->ndl_node->nd_state & keep) == 0)
+                       lstcon_group_ndlink_release(grp, ndl);
+       }
 }
 
 static void
 lstcon_group_decref(lstcon_group_t *grp)
 {
-        int     i;
+       int i;
 
-        if (--grp->grp_ref > 0)
-                return;
+       if (--grp->grp_ref > 0)
+               return;
 
-        if (!cfs_list_empty(&grp->grp_link))
-                cfs_list_del(&grp->grp_link);
+       if (!list_empty(&grp->grp_link))
+               list_del(&grp->grp_link);
 
-        lstcon_group_drain(grp, 0);
+       lstcon_group_drain(grp, 0);
 
-        for (i = 0; i < LST_NODE_HASHSIZE; i++) {
-                LASSERT (cfs_list_empty(&grp->grp_ndl_hash[i]));
-        }
+       for (i = 0; i < LST_NODE_HASHSIZE; i++)
+               LASSERT(list_empty(&grp->grp_ndl_hash[i]));
 
-        LIBCFS_FREE(grp, offsetof(lstcon_group_t,
-                                  grp_ndl_hash[LST_NODE_HASHSIZE]));
+       LIBCFS_FREE(grp, offsetof(lstcon_group_t,
+                                 grp_ndl_hash[LST_NODE_HASHSIZE]));
 }
 
 static int
-lstcon_group_find(char *name, lstcon_group_t **grpp)
+lstcon_group_find(const char *name, lstcon_group_t **grpp)
 {
-        lstcon_group_t   *grp;
+       lstcon_group_t *grp;
 
-        cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
-                                      lstcon_group_t, grp_link) {
-                if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
-                        continue;
+       list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
+               if (strncmp(grp->grp_name, name, LST_NAME_SIZE) != 0)
+                       continue;
 
-                lstcon_group_addref(grp);  /* +1 ref for caller */
-                *grpp = grp;
-                return 0;
-        }
+               lstcon_group_addref(grp);  /* +1 ref for caller */
+               *grpp = grp;
+               return 0;
+       }
 
-        return -ENOENT;
+       return -ENOENT;
 }
 
 static void
@@ -296,57 +298,57 @@ static int
 lstcon_group_ndlink_find(lstcon_group_t *grp, lnet_process_id_t id,
                          lstcon_ndlink_t **ndlpp, int create)
 {
-        int     rc;
-        
-        rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
-        if (rc != 0)
-                return rc;
+       int rc;
 
-        if (!cfs_list_empty(&(*ndlpp)->ndl_link))
-                return 0;
+       rc = lstcon_ndlink_find(&grp->grp_ndl_hash[0], id, ndlpp, create);
+       if (rc != 0)
+               return rc;
 
-        cfs_list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
-        grp->grp_nnode ++;
+       if (!list_empty(&(*ndlpp)->ndl_link))
+               return 0;
 
-        return 0;
+       list_add_tail(&(*ndlpp)->ndl_link, &grp->grp_ndl_list);
+       grp->grp_nnode++;
+
+       return 0;
 }
 
 static void
 lstcon_group_ndlink_release(lstcon_group_t *grp, lstcon_ndlink_t *ndl)
 {
-        cfs_list_del_init(&ndl->ndl_link);
-        lstcon_ndlink_release(ndl);
-        grp->grp_nnode --;
+       list_del_init(&ndl->ndl_link);
+       lstcon_ndlink_release(ndl);
+       grp->grp_nnode--;
 }
 
 static void
 lstcon_group_ndlink_move(lstcon_group_t *old,
                          lstcon_group_t *new, lstcon_ndlink_t *ndl)
 {
-        unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
-                           LST_NODE_HASHSIZE;
+       unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
+                                       LST_NODE_HASHSIZE;
 
-        cfs_list_del(&ndl->ndl_hlink);
-        cfs_list_del(&ndl->ndl_link);
-        old->grp_nnode --;
+       list_del(&ndl->ndl_hlink);
+       list_del(&ndl->ndl_link);
+       old->grp_nnode--;
 
-        cfs_list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
-        cfs_list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
-        new->grp_nnode ++;
+       list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
+       list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
+       new->grp_nnode++;
 
-        return;
+       return;
 }
 
 static void
 lstcon_group_move(lstcon_group_t *old, lstcon_group_t *new)
 {
-        lstcon_ndlink_t *ndl;
+       lstcon_ndlink_t *ndl;
 
-        while (!cfs_list_empty(&old->grp_ndl_list)) {
-                ndl = cfs_list_entry(old->grp_ndl_list.next,
-                                     lstcon_ndlink_t, ndl_link);
-                lstcon_group_ndlink_move(old, new, ndl);
-        }
+       while (!list_empty(&old->grp_ndl_list)) {
+               ndl = list_entry(old->grp_ndl_list.next,
+                                lstcon_ndlink_t, ndl_link);
+               lstcon_group_ndlink_move(old, new, ndl);
+       }
 }
 
 int
@@ -410,7 +412,7 @@ lstcon_sesrpc_readent(int transop, srpc_msg_t *msg,
 static int
 lstcon_group_nodes_add(lstcon_group_t *grp,
                       int count, lnet_process_id_t *ids_up,
-                      unsigned *featp, cfs_list_t *result_up)
+                      unsigned *featp, struct list_head *result_up)
 {
         lstcon_rpc_trans_t      *trans;
         lstcon_ndlink_t         *ndl;
@@ -477,7 +479,7 @@ lstcon_group_nodes_add(lstcon_group_t *grp,
 static int
 lstcon_group_nodes_remove(lstcon_group_t *grp,
                           int count, lnet_process_id_t *ids_up,
-                          cfs_list_t *result_up)
+                         struct list_head *result_up)
 {
         lstcon_rpc_trans_t     *trans;
         lstcon_ndlink_t        *ndl;
@@ -548,14 +550,14 @@ lstcon_group_add(char *name)
                 return -ENOMEM;
         }
 
-        cfs_list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
+       list_add_tail(&grp->grp_link, &console_session.ses_grp_list);
 
-        return rc;
+       return rc;
 }
 
 int
 lstcon_nodes_add(char *name, int count, lnet_process_id_t *ids_up,
-                unsigned *featp, cfs_list_t *result_up)
+                unsigned *featp, struct list_head *result_up)
 {
         lstcon_group_t         *grp;
         int                     rc;
@@ -649,17 +651,17 @@ lstcon_group_clean(char *name, int args)
 
         lstcon_group_drain(grp, args);
 
-        lstcon_group_put(grp);
-        /* release empty group */
-        if (cfs_list_empty(&grp->grp_ndl_list))
-                lstcon_group_put(grp);
+       lstcon_group_put(grp);
+       /* release empty group */
+       if (list_empty(&grp->grp_ndl_list))
+               lstcon_group_put(grp);
 
-        return 0;
+       return 0;
 }
 
 int
 lstcon_nodes_remove(char *name, int count,
-                    lnet_process_id_t *ids_up, cfs_list_t *result_up)
+                   lnet_process_id_t *ids_up, struct list_head *result_up)
 {
         lstcon_group_t *grp = NULL;
         int             rc;
@@ -679,16 +681,16 @@ lstcon_nodes_remove(char *name, int count,
 
         rc = lstcon_group_nodes_remove(grp, count, ids_up, result_up);
 
-        lstcon_group_put(grp);
-        /* release empty group */
-        if (cfs_list_empty(&grp->grp_ndl_list))
-                lstcon_group_put(grp);
+       lstcon_group_put(grp);
+       /* release empty group */
+       if (list_empty(&grp->grp_ndl_list))
+               lstcon_group_put(grp);
 
-        return rc;
+       return rc;
 }
 
 int
-lstcon_group_refresh(char *name, cfs_list_t *result_up)
+lstcon_group_refresh(char *name, struct list_head *result_up)
 {
         lstcon_rpc_trans_t      *trans;
         lstcon_group_t          *grp;
@@ -730,26 +732,25 @@ lstcon_group_refresh(char *name, cfs_list_t *result_up)
 }
 
 int
-lstcon_group_list(int index, int len, char *name_up)
+lstcon_group_list(int index, int len, char __user *name_up)
 {
-        lstcon_group_t *grp;
+       lstcon_group_t *grp;
 
-        LASSERT (index >= 0);
-        LASSERT (name_up != NULL);
+       LASSERT(index >= 0);
+       LASSERT(name_up != NULL);
 
-        cfs_list_for_each_entry_typed(grp, &console_session.ses_grp_list,
-                                      lstcon_group_t, grp_link) {
-                if (index-- == 0) {
+       list_for_each_entry(grp, &console_session.ses_grp_list, grp_link) {
+               if (index-- == 0) {
                        return copy_to_user(name_up, grp->grp_name, len) ?
-                               -EFAULT : 0;
-                }
-        }
+                                           -EFAULT : 0;
+               }
+       }
 
-        return -ENOENT;
+       return -ENOENT;
 }
 
 static int
-lstcon_nodes_getent(cfs_list_t *head, int *index_p,
+lstcon_nodes_getent(struct list_head *head, int *index_p,
                     int *count_p, lstcon_node_ent_t *dents_up)
 {
         lstcon_ndlink_t  *ndl;
@@ -757,14 +758,14 @@ lstcon_nodes_getent(cfs_list_t *head, int *index_p,
         int               count = 0;
         int               index = 0;
 
-        LASSERT (index_p != NULL && count_p != NULL);
-        LASSERT (dents_up != NULL);
-        LASSERT (*index_p >= 0);
-        LASSERT (*count_p > 0);
+       LASSERT(index_p != NULL && count_p != NULL);
+       LASSERT(dents_up != NULL);
+       LASSERT(*index_p >= 0);
+       LASSERT(*count_p > 0);
 
-        cfs_list_for_each_entry_typed(ndl, head, lstcon_ndlink_t, ndl_link) {
-                if (index++ < *index_p)
-                        continue;
+       list_for_each_entry(ndl, head, ndl_link) {
+               if (index++ < *index_p)
+                       continue;
 
                 if (count >= *count_p)
                         break;
@@ -821,36 +822,34 @@ lstcon_group_info(char *name, lstcon_ndlist_ent_t *gents_p,
                 return -ENOMEM;
         }
 
-        memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
+       memset(gentp, 0, sizeof(lstcon_ndlist_ent_t));
 
-        cfs_list_for_each_entry_typed(ndl, &grp->grp_ndl_list,
-                                      lstcon_ndlink_t, ndl_link)
+       list_for_each_entry(ndl, &grp->grp_ndl_list, ndl_link)
                 LST_NODE_STATE_COUNTER(ndl->ndl_node, gentp);
 
        rc = copy_to_user(gents_p, gentp,
-                              sizeof(lstcon_ndlist_ent_t)) ? -EFAULT: 0;
+                         sizeof(lstcon_ndlist_ent_t)) ? -EFAULT : 0;
 
-        LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
+       LIBCFS_FREE(gentp, sizeof(lstcon_ndlist_ent_t));
 
-        lstcon_group_put(grp);
+       lstcon_group_put(grp);
 
-        return 0;
+       return 0;
 }
 
-int
-lstcon_batch_find(char *name, lstcon_batch_t **batpp)
+static int
+lstcon_batch_find(const char *name, lstcon_batch_t **batpp)
 {
-        lstcon_batch_t   *bat;
+       lstcon_batch_t *bat;
 
-        cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
-                                      lstcon_batch_t, bat_link) {
-                if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
-                        *batpp = bat;
-                        return 0;
-                }
-        }
+       list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
+               if (strncmp(bat->bat_name, name, LST_NAME_SIZE) == 0) {
+                       *batpp = bat;
+                       return 0;
+               }
+       }
 
-        return -ENOENT;
+       return -ENOENT;
 }
 
 int
@@ -873,7 +872,7 @@ lstcon_batch_add(char *name)
         }
 
         LIBCFS_ALLOC(bat->bat_cli_hash,
-                     sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
+                    sizeof(struct list_head) * LST_NODE_HASHSIZE);
         if (bat->bat_cli_hash == NULL) {
                 CERROR("Can't allocate hash for batch %s\n", name);
                 LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
@@ -882,7 +881,7 @@ lstcon_batch_add(char *name)
         }
 
         LIBCFS_ALLOC(bat->bat_srv_hash,
-                     sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
+                    sizeof(struct list_head) * LST_NODE_HASHSIZE);
         if (bat->bat_srv_hash == NULL) {
                 CERROR("Can't allocate hash for batch %s\n", name);
                 LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
@@ -891,45 +890,50 @@ lstcon_batch_add(char *name)
                 return -ENOMEM;
         }
 
-        strcpy(bat->bat_name, name);
+       if (strlen(name) > sizeof(bat->bat_name)-1) {
+               LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
+               LIBCFS_FREE(bat->bat_cli_hash, LST_NODE_HASHSIZE);
+               LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
+               return -E2BIG;
+       }
+       strncpy(bat->bat_name, name, sizeof(bat->bat_name));
         bat->bat_hdr.tsb_index = 0;
         bat->bat_hdr.tsb_id.bat_id = ++console_session.ses_id_cookie;
 
         bat->bat_ntest = 0;
         bat->bat_state = LST_BATCH_IDLE;
 
-        CFS_INIT_LIST_HEAD(&bat->bat_cli_list);
-        CFS_INIT_LIST_HEAD(&bat->bat_srv_list);
-        CFS_INIT_LIST_HEAD(&bat->bat_test_list);
-        CFS_INIT_LIST_HEAD(&bat->bat_trans_list);
+       INIT_LIST_HEAD(&bat->bat_cli_list);
+       INIT_LIST_HEAD(&bat->bat_srv_list);
+       INIT_LIST_HEAD(&bat->bat_test_list);
+       INIT_LIST_HEAD(&bat->bat_trans_list);
 
         for (i = 0; i < LST_NODE_HASHSIZE; i++) {
-                CFS_INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
-                CFS_INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
+               INIT_LIST_HEAD(&bat->bat_cli_hash[i]);
+               INIT_LIST_HEAD(&bat->bat_srv_hash[i]);
         }
 
-        cfs_list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
+       list_add_tail(&bat->bat_link, &console_session.ses_bat_list);
 
         return rc;
 }
 
 int
-lstcon_batch_list(int index, int len, char *name_up)
+lstcon_batch_list(int index, int len, char __user *name_up)
 {
-        lstcon_batch_t    *bat;
+       lstcon_batch_t *bat;
 
-        LASSERT (name_up != NULL);
-        LASSERT (index >= 0);
+       LASSERT(name_up != NULL);
+       LASSERT(index >= 0);
 
-        cfs_list_for_each_entry_typed(bat, &console_session.ses_bat_list,
-                                      lstcon_batch_t, bat_link) {
-                if (index-- == 0) {
+       list_for_each_entry(bat, &console_session.ses_bat_list, bat_link) {
+               if (index-- == 0) {
                        return copy_to_user(name_up, bat->bat_name, len) ?
-                               -EFAULT: 0;
-                }
-        }
+                                           -EFAULT : 0;
+               }
+       }
 
-        return -ENOENT;
+       return -ENOENT;
 }
 
 int
@@ -938,8 +942,8 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
                   lstcon_node_ent_t *dents_up)
 {
         lstcon_test_batch_ent_t *entp;
-        cfs_list_t              *clilst;
-        cfs_list_t              *srvlst;
+       struct list_head        *clilst;
+       struct list_head        *srvlst;
         lstcon_test_t           *test = NULL;
         lstcon_batch_t          *bat;
         lstcon_ndlink_t         *ndl;
@@ -951,13 +955,12 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
                 return -ENOENT;
         }
 
-        if (testidx > 0) {
-                /* query test, test index start from 1 */
-                cfs_list_for_each_entry_typed(test, &bat->bat_test_list,
-                                              lstcon_test_t, tes_link) {
-                        if (testidx-- == 1)
-                                break;
-                }
+       if (testidx > 0) {
+               /* query test, test index start from 1 */
+               list_for_each_entry(test, &bat->bat_test_list, tes_link) {
+                       if (testidx-- == 1)
+                               break;
+               }
 
                 if (testidx > 0) {
                         CDEBUG(D_NET, "Can't find specified test in batch\n");
@@ -994,18 +997,18 @@ lstcon_batch_info(char *name, lstcon_test_batch_ent_t *ent_up, int server,
                 entp->u.tbe_test.tse_concur = test->tes_concur;
         }
 
-        cfs_list_for_each_entry_typed(ndl, clilst, lstcon_ndlink_t, ndl_link)
-                LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
+       list_for_each_entry(ndl, clilst, ndl_link)
+               LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_cli_nle);
 
-        cfs_list_for_each_entry_typed(ndl, srvlst, lstcon_ndlink_t, ndl_link)
-                LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
+       list_for_each_entry(ndl, srvlst, ndl_link)
+               LST_NODE_STATE_COUNTER(ndl->ndl_node, &entp->tbe_srv_nle);
 
        rc = copy_to_user(ent_up, entp,
-                              sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
+                         sizeof(lstcon_test_batch_ent_t)) ? -EFAULT : 0;
 
-        LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
+       LIBCFS_FREE(entp, sizeof(lstcon_test_batch_ent_t));
 
-        return rc;
+       return rc;
 }
 
 int
@@ -1032,7 +1035,7 @@ lstcon_batrpc_condition(int transop, lstcon_node_t *nd, void *arg)
 
 static int
 lstcon_batch_op(lstcon_batch_t *bat, int transop,
-                cfs_list_t *result_up)
+               struct list_head *result_up)
 {
         lstcon_rpc_trans_t *trans;
         int                 rc;
@@ -1055,7 +1058,7 @@ lstcon_batch_op(lstcon_batch_t *bat, int transop,
 }
 
 int
-lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
+lstcon_batch_run(char *name, int timeout, struct list_head *result_up)
 {
         lstcon_batch_t *bat;
         int             rc;
@@ -1077,7 +1080,7 @@ lstcon_batch_run(char *name, int timeout, cfs_list_t *result_up)
 }
 
 int
-lstcon_batch_stop(char *name, int force, cfs_list_t *result_up)
+lstcon_batch_stop(char *name, int force, struct list_head *result_up)
 {
         lstcon_batch_t *bat;
         int             rc;
@@ -1105,66 +1108,66 @@ lstcon_batch_destroy(lstcon_batch_t *bat)
         lstcon_test_t      *test;
         int                 i;
 
-        cfs_list_del(&bat->bat_link);
+       list_del(&bat->bat_link);
 
-        while (!cfs_list_empty(&bat->bat_test_list)) {
-                test = cfs_list_entry(bat->bat_test_list.next,
-                                      lstcon_test_t, tes_link);
-                LASSERT (cfs_list_empty(&test->tes_trans_list));
+       while (!list_empty(&bat->bat_test_list)) {
+               test = list_entry(bat->bat_test_list.next,
+                                 lstcon_test_t, tes_link);
+               LASSERT(list_empty(&test->tes_trans_list));
 
-                cfs_list_del(&test->tes_link);
+               list_del(&test->tes_link);
 
-                lstcon_group_put(test->tes_src_grp);
-                lstcon_group_put(test->tes_dst_grp);
+               lstcon_group_put(test->tes_src_grp);
+               lstcon_group_put(test->tes_dst_grp);
 
-                LIBCFS_FREE(test, offsetof(lstcon_test_t,
-                                           tes_param[test->tes_paramlen]));
-        }
+               LIBCFS_FREE(test, offsetof(lstcon_test_t,
+                                          tes_param[test->tes_paramlen]));
+       }
 
-        LASSERT (cfs_list_empty(&bat->bat_trans_list));
+       LASSERT(list_empty(&bat->bat_trans_list));
 
-        while (!cfs_list_empty(&bat->bat_cli_list)) {
-                ndl = cfs_list_entry(bat->bat_cli_list.next,
-                                     lstcon_ndlink_t, ndl_link);
-                cfs_list_del_init(&ndl->ndl_link);
+       while (!list_empty(&bat->bat_cli_list)) {
+               ndl = list_entry(bat->bat_cli_list.next,
+                                lstcon_ndlink_t, ndl_link);
+               list_del_init(&ndl->ndl_link);
 
-                lstcon_ndlink_release(ndl);
-        }
+               lstcon_ndlink_release(ndl);
+       }
 
-        while (!cfs_list_empty(&bat->bat_srv_list)) {
-                ndl = cfs_list_entry(bat->bat_srv_list.next,
-                                     lstcon_ndlink_t, ndl_link);
-                cfs_list_del_init(&ndl->ndl_link);
+       while (!list_empty(&bat->bat_srv_list)) {
+               ndl = list_entry(bat->bat_srv_list.next,
+                                lstcon_ndlink_t, ndl_link);
+               list_del_init(&ndl->ndl_link);
 
-                lstcon_ndlink_release(ndl);
-        }
+               lstcon_ndlink_release(ndl);
+       }
 
-        for (i = 0; i < LST_NODE_HASHSIZE; i++) {
-                LASSERT (cfs_list_empty(&bat->bat_cli_hash[i]));
-                LASSERT (cfs_list_empty(&bat->bat_srv_hash[i]));
-        }
+       for (i = 0; i < LST_NODE_HASHSIZE; i++) {
+               LASSERT(list_empty(&bat->bat_cli_hash[i]));
+               LASSERT(list_empty(&bat->bat_srv_hash[i]));
+       }
 
-        LIBCFS_FREE(bat->bat_cli_hash,
-                    sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
-        LIBCFS_FREE(bat->bat_srv_hash,
-                    sizeof(cfs_list_t) * LST_NODE_HASHSIZE);
-        LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
+       LIBCFS_FREE(bat->bat_cli_hash,
+                   sizeof(struct list_head) * LST_NODE_HASHSIZE);
+       LIBCFS_FREE(bat->bat_srv_hash,
+                   sizeof(struct list_head) * LST_NODE_HASHSIZE);
+       LIBCFS_FREE(bat, sizeof(lstcon_batch_t));
 }
 
 int
 lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
 {
-        lstcon_test_t    *test;
-        lstcon_batch_t   *batch;
-        lstcon_ndlink_t  *ndl;
-        cfs_list_t       *hash;
-        cfs_list_t       *head;
+       lstcon_test_t    *test;
+       lstcon_batch_t   *batch;
+       lstcon_ndlink_t  *ndl;
+       struct list_head *hash;
+       struct list_head *head;
 
-        test = (lstcon_test_t *)arg;
-        LASSERT (test != NULL);
+       test = (lstcon_test_t *)arg;
+       LASSERT(test != NULL);
 
-        batch = test->tes_batch;
-        LASSERT (batch != NULL);
+       batch = test->tes_batch;
+       LASSERT(batch != NULL);
 
         if (test->tes_oneside &&
             transop == LST_TRANS_TSBSRVADD)
@@ -1189,14 +1192,14 @@ lstcon_testrpc_condition(int transop, lstcon_node_t *nd, void *arg)
         if (lstcon_ndlink_find(hash, nd->nd_id, &ndl, 1) != 0)
                 return -ENOMEM;
 
-        if (cfs_list_empty(&ndl->ndl_link))
-                cfs_list_add_tail(&ndl->ndl_link, head);
+       if (list_empty(&ndl->ndl_link))
+               list_add_tail(&ndl->ndl_link, head);
 
-        return 1;
+       return 1;
 }
 
 static int
-lstcon_test_nodes_add(lstcon_test_t *test, cfs_list_t *result_up)
+lstcon_test_nodes_add(lstcon_test_t *test, struct list_head *result_up)
 {
         lstcon_rpc_trans_t     *trans;
         lstcon_group_t         *grp;
@@ -1247,116 +1250,153 @@ again:
         goto again;
 }
 
-int
-lstcon_test_add(char *name, int type, int loop, int concur,
-                int dist, int span, char *src_name, char * dst_name,
-                void *param, int paramlen, int *retp,
-                cfs_list_t *result_up)
+static int
+lstcon_verify_batch(const char *name, lstcon_batch_t **batch)
 {
-        lstcon_group_t  *src_grp = NULL;
-        lstcon_group_t  *dst_grp = NULL;
-        lstcon_test_t   *test    = NULL;
-        lstcon_batch_t  *batch;
-        int              rc;
+       int rc;
 
-        rc = lstcon_batch_find(name, &batch);
-        if (rc != 0) {
-                CDEBUG(D_NET, "Can't find batch %s\n", name);
-                return rc;
-        }
+       rc = lstcon_batch_find(name, batch);
+       if (rc != 0) {
+               CDEBUG(D_NET, "Can't find batch %s\n", name);
+               return rc;
+       }
 
-        if (batch->bat_state != LST_BATCH_IDLE) {
-                CDEBUG(D_NET, "Can't change running batch %s\n", name);
-                return rc;
-        }
+       if ((*batch)->bat_state != LST_BATCH_IDLE) {
+               CDEBUG(D_NET, "Can't change running batch %s\n", name);
+               return -EINVAL;
+       }
 
-        rc = lstcon_group_find(src_name, &src_grp);
-        if (rc != 0) {
-                CDEBUG(D_NET, "Can't find group %s\n", src_name);
-                goto out;
-        }
+       return 0;
+}
 
-        rc = lstcon_group_find(dst_name, &dst_grp);
-        if (rc != 0) {
-                CDEBUG(D_NET, "Can't find group %s\n", dst_name);
-                goto out;
-        }
+static int
+lstcon_verify_group(const char *name, lstcon_group_t **grp)
+{
+       int                     rc;
+       lstcon_ndlink_t         *ndl;
 
-        if (dst_grp->grp_userland)
-                *retp = 1;
+       rc = lstcon_group_find(name, grp);
+       if (rc != 0) {
+               CDEBUG(D_NET, "can't find group %s\n", name);
+               return rc;
+       }
 
-        LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
-        if (!test) {
-                CERROR("Can't allocate test descriptor\n");
-                rc = -ENOMEM;
+       list_for_each_entry(ndl, &(*grp)->grp_ndl_list, ndl_link) {
+               if (ndl->ndl_node->nd_state == LST_NODE_ACTIVE) {
+                       return 0;
+               }
+       }
 
-                goto out;
-        }
+       CDEBUG(D_NET, "Group %s has no ACTIVE nodes\n", name);
 
-        memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
-        test->tes_hdr.tsb_id    = batch->bat_hdr.tsb_id;
-        test->tes_batch         = batch;
-        test->tes_type          = type;
-        test->tes_oneside       = 0; /* TODO */
-        test->tes_loop          = loop;
-        test->tes_concur        = concur;
-        test->tes_stop_onerr    = 1; /* TODO */
-        test->tes_span          = span;
-        test->tes_dist          = dist;
-        test->tes_cliidx        = 0; /* just used for creating RPC */
-        test->tes_src_grp       = src_grp;
-        test->tes_dst_grp       = dst_grp;
-        CFS_INIT_LIST_HEAD(&test->tes_trans_list);
+       return -EINVAL;
+}
 
-        if (param != NULL) {
-                test->tes_paramlen = paramlen;
-                memcpy(&test->tes_param[0], param, paramlen);
-        }
+int
+lstcon_test_add(char *batch_name, int type, int loop,
+               int concur, int dist, int span,
+               char *src_name, char *dst_name,
+               void *param, int paramlen, int *retp,
+               struct list_head *result_up)
+{
+       lstcon_test_t    *test   = NULL;
+       int              rc;
+       lstcon_group_t   *src_grp = NULL;
+       lstcon_group_t   *dst_grp = NULL;
+       lstcon_batch_t   *batch = NULL;
+
+       /*
+        * verify that a batch of the given name exists, and the groups
+        * that will be part of the batch exist and have at least one
+        * active node
+        */
+       rc = lstcon_verify_batch(batch_name, &batch);
+       if (rc != 0)
+               goto out;
 
-        rc = lstcon_test_nodes_add(test, result_up);
+       rc = lstcon_verify_group(src_name, &src_grp);
+       if (rc != 0)
+               goto out;
 
-        if (rc != 0)
-                goto out;
+       rc = lstcon_verify_group(dst_name, &dst_grp);
+       if (rc != 0)
+               goto out;
 
-        if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
-            lstcon_trans_stat()->trs_fwk_errno != 0)
-                CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type, name);
+       if (dst_grp->grp_userland)
+               *retp = 1;
 
-        /* add to test list anyway, so user can check what's going on */
-        cfs_list_add_tail(&test->tes_link, &batch->bat_test_list);
+       LIBCFS_ALLOC(test, offsetof(lstcon_test_t, tes_param[paramlen]));
+       if (!test) {
+               CERROR("Can't allocate test descriptor\n");
+               rc = -ENOMEM;
 
-        batch->bat_ntest ++;
-        test->tes_hdr.tsb_index = batch->bat_ntest;
+               goto out;
+       }
 
-        /*  hold groups so nobody can change them */
-        return rc;
+       memset(test, 0, offsetof(lstcon_test_t, tes_param[paramlen]));
+       test->tes_hdr.tsb_id    = batch->bat_hdr.tsb_id;
+       test->tes_batch         = batch;
+       test->tes_type          = type;
+       test->tes_oneside       = 0; /* TODO */
+       test->tes_loop          = loop;
+       test->tes_concur        = concur;
+       test->tes_stop_onerr    = 1; /* TODO */
+       test->tes_span          = span;
+       test->tes_dist          = dist;
+       test->tes_cliidx        = 0; /* just used for creating RPC */
+       test->tes_src_grp       = src_grp;
+       test->tes_dst_grp       = dst_grp;
+       INIT_LIST_HEAD(&test->tes_trans_list);
+
+       if (param != NULL) {
+               test->tes_paramlen = paramlen;
+               memcpy(&test->tes_param[0], param, paramlen);
+       }
+
+       rc = lstcon_test_nodes_add(test, result_up);
+
+       if (rc != 0)
+               goto out;
+
+       if (lstcon_trans_stat()->trs_rpc_errno != 0 ||
+           lstcon_trans_stat()->trs_fwk_errno != 0)
+               CDEBUG(D_NET, "Failed to add test %d to batch %s\n", type,
+                      batch_name);
+
+       /* add to test list anyway, so user can check what's going on */
+       list_add_tail(&test->tes_link, &batch->bat_test_list);
+
+       batch->bat_ntest++;
+       test->tes_hdr.tsb_index = batch->bat_ntest;
+
+       /*  hold groups so nobody can change them */
+       return rc;
 out:
-        if (test != NULL)
-                LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
+       if (test != NULL)
+               LIBCFS_FREE(test, offsetof(lstcon_test_t, tes_param[paramlen]));
 
-        if (dst_grp != NULL)
-                lstcon_group_put(dst_grp);
+       if (dst_grp != NULL)
+               lstcon_group_put(dst_grp);
 
-        if (src_grp != NULL)
-                lstcon_group_put(src_grp);
+       if (src_grp != NULL)
+               lstcon_group_put(src_grp);
 
-        return rc;
+       return rc;
 }
 
 int
 lstcon_test_find(lstcon_batch_t *batch, int idx, lstcon_test_t **testpp)
 {
-        lstcon_test_t *test;
+       lstcon_test_t *test;
 
-        cfs_list_for_each_entry_typed(test, &batch->bat_test_list,
-                                      lstcon_test_t, tes_link) {
-                if (idx == test->tes_hdr.tsb_index) {
-                        *testpp = test;
-                        return 0;
-                }
-        }
+       list_for_each_entry(test, &batch->bat_test_list, tes_link) {
+               if (idx == test->tes_hdr.tsb_index) {
+                       *testpp = test;
+                       return 0;
+               }
+       }
 
-        return -ENOENT;
+       return -ENOENT;
 }
 
 int
@@ -1378,11 +1418,11 @@ lstcon_tsbrpc_readent(int transop, srpc_msg_t *msg,
 
 int
 lstcon_test_batch_query(char *name, int testidx, int client,
-                        int timeout, cfs_list_t *result_up)
+                       int timeout, struct list_head *result_up)
 {
         lstcon_rpc_trans_t *trans;
-        cfs_list_t         *translist;
-        cfs_list_t         *ndlist;
+       struct list_head   *translist;
+       struct list_head   *ndlist;
         lstcon_tsb_hdr_t   *hdr;
         lstcon_batch_t     *batch;
         lstcon_test_t      *test = NULL;
@@ -1463,14 +1503,14 @@ lstcon_statrpc_readent(int transop, srpc_msg_t *msg,
 }
 
 int
-lstcon_ndlist_stat(cfs_list_t *ndlist,
-                   int timeout, cfs_list_t *result_up)
+lstcon_ndlist_stat(struct list_head *ndlist,
+                  int timeout, struct list_head *result_up)
 {
-        cfs_list_t          head;
-        lstcon_rpc_trans_t *trans;
-        int                 rc;
+       struct list_head    head;
+       lstcon_rpc_trans_t *trans;
+       int                 rc;
 
-        CFS_INIT_LIST_HEAD(&head);
+       INIT_LIST_HEAD(&head);
 
         rc = lstcon_rpc_trans_ndlist(ndlist, &head,
                                      LST_TRANS_STATQRY, NULL, NULL, &trans);
@@ -1489,7 +1529,7 @@ lstcon_ndlist_stat(cfs_list_t *ndlist,
 }
 
 int
-lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
+lstcon_group_stat(char *grp_name, int timeout, struct list_head *result_up)
 {
         lstcon_group_t     *grp;
         int                 rc;
@@ -1509,7 +1549,7 @@ lstcon_group_stat(char *grp_name, int timeout, cfs_list_t *result_up)
 
 int
 lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
-                  int timeout, cfs_list_t *result_up)
+                 int timeout, struct list_head *result_up)
 {
         lstcon_ndlink_t         *ndl;
         lstcon_group_t          *tmp;
@@ -1552,9 +1592,9 @@ lstcon_nodes_stat(int count, lnet_process_id_t *ids_up,
 }
 
 int
-lstcon_debug_ndlist(cfs_list_t *ndlist,
-                    cfs_list_t *translist,
-                    int timeout, cfs_list_t *result_up)
+lstcon_debug_ndlist(struct list_head *ndlist,
+                   struct list_head *translist,
+                   int timeout, struct list_head *result_up)
 {
         lstcon_rpc_trans_t *trans;
         int                 rc;
@@ -1576,7 +1616,7 @@ lstcon_debug_ndlist(cfs_list_t *ndlist,
 }
 
 int
-lstcon_session_debug(int timeout, cfs_list_t *result_up)
+lstcon_session_debug(int timeout, struct list_head *result_up)
 {
         return lstcon_debug_ndlist(&console_session.ses_ndl_list,
                                    NULL, timeout, result_up);
@@ -1584,7 +1624,7 @@ lstcon_session_debug(int timeout, cfs_list_t *result_up)
 
 int
 lstcon_batch_debug(int timeout, char *name,
-                   int client, cfs_list_t *result_up)
+                  int client, struct list_head *result_up)
 {
         lstcon_batch_t *bat;
         int             rc;
@@ -1602,7 +1642,7 @@ lstcon_batch_debug(int timeout, char *name,
 
 int
 lstcon_group_debug(int timeout, char *name,
-                   cfs_list_t *result_up)
+                  struct list_head *result_up)
 {
         lstcon_group_t *grp;
         int             rc;
@@ -1621,7 +1661,7 @@ lstcon_group_debug(int timeout, char *name,
 int
 lstcon_nodes_debug(int timeout,
                    int count, lnet_process_id_t *ids_up, 
-                   cfs_list_t *result_up)
+                  struct list_head *result_up)
 {
         lnet_process_id_t  id;
         lstcon_ndlink_t   *ndl;
@@ -1712,7 +1752,7 @@ lstcon_session_new(char *name, int key, unsigned feats,
        }
 
        for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
-               LASSERT(cfs_list_empty(&console_session.ses_ndl_hash[i]));
+               LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
 
        lstcon_new_session_id(&console_session.ses_id);
 
@@ -1723,7 +1763,11 @@ lstcon_session_new(char *name, int key, unsigned feats,
        console_session.ses_feats_updated = 0;
        console_session.ses_timeout = (timeout <= 0) ?
                                      LST_CONSOLE_TIMEOUT : timeout;
-       strcpy(console_session.ses_name, name);
+
+       if (strlen(name) > sizeof(console_session.ses_name)-1)
+               return -E2BIG;
+       strlcpy(console_session.ses_name, name,
+               sizeof(console_session.ses_name));
 
         rc = lstcon_batch_add(LST_DEFAULT_BATCH);
         if (rc != 0)
@@ -1765,9 +1809,8 @@ lstcon_session_info(lst_sid_t *sid_up, int *key_up, unsigned *featp,
 
         memset(entp, 0, sizeof(*entp));
 
-        cfs_list_for_each_entry_typed(ndl, &console_session.ses_ndl_list,
-                                      lstcon_ndlink_t, ndl_link)
-                LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
+       list_for_each_entry(ndl, &console_session.ses_ndl_list, ndl_link)
+               LST_NODE_STATE_COUNTER(ndl->ndl_node, entp);
 
        if (copy_to_user(sid_up, &console_session.ses_id,
                              sizeof(lst_sid_t)) ||
@@ -1820,30 +1863,30 @@ lstcon_session_end()
         console_session.ses_force = 0;
        console_session.ses_feats_updated = 0;
 
-        /* destroy all batches */
-        while (!cfs_list_empty(&console_session.ses_bat_list)) {
-                bat = cfs_list_entry(console_session.ses_bat_list.next,
-                                     lstcon_batch_t, bat_link);
+       /* destroy all batches */
+       while (!list_empty(&console_session.ses_bat_list)) {
+               bat = list_entry(console_session.ses_bat_list.next,
+                                lstcon_batch_t, bat_link);
 
-                lstcon_batch_destroy(bat);
-        }
+               lstcon_batch_destroy(bat);
+       }
 
-        /* destroy all groups */
-        while (!cfs_list_empty(&console_session.ses_grp_list)) {
-                grp = cfs_list_entry(console_session.ses_grp_list.next,
-                                     lstcon_group_t, grp_link);
-                LASSERT (grp->grp_ref == 1);
+       /* destroy all groups */
+       while (!list_empty(&console_session.ses_grp_list)) {
+               grp = list_entry(console_session.ses_grp_list.next,
+                                lstcon_group_t, grp_link);
+               LASSERT(grp->grp_ref == 1);
 
-                lstcon_group_put(grp);
-        }
+               lstcon_group_put(grp);
+       }
 
-        /* all nodes should be released */
-        LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
+       /* all nodes should be released */
+       LASSERT(list_empty(&console_session.ses_ndl_list));
 
-        console_session.ses_shutdown = 0;
-        console_session.ses_expired  = 0;
+       console_session.ses_shutdown = 0;
+       console_session.ses_expired  = 0;
 
-        return rc;
+       return rc;
 }
 
 int
@@ -1918,10 +1961,10 @@ lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
                         goto out;
                 }
 
-                cfs_list_add_tail(&grp->grp_link,
-                                  &console_session.ses_grp_list);
-                lstcon_group_addref(grp);
-        }
+               list_add_tail(&grp->grp_link,
+                             &console_session.ses_grp_list);
+               lstcon_group_addref(grp);
+       }
 
         if (grp->grp_ref > 2) {
                 /* Group in using */
@@ -1947,7 +1990,8 @@ lstcon_acceptor_handle (srpc_server_rpc_t *rpc)
         if (grp->grp_userland == 0)
                 grp->grp_userland = 1;
 
-        strcpy(jrep->join_session, console_session.ses_name);
+       strlcpy(jrep->join_session, console_session.ses_name,
+               sizeof(jrep->join_session));
         jrep->join_timeout = console_session.ses_timeout;
         jrep->join_status  = 0;
 
@@ -1971,7 +2015,7 @@ void lstcon_init_acceptor_service(void)
        lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
 }
 
-extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
+int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
 
 DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
 
@@ -1995,30 +2039,30 @@ lstcon_console_init(void)
 
        mutex_init(&console_session.ses_mutex);
 
-        CFS_INIT_LIST_HEAD(&console_session.ses_ndl_list);
-        CFS_INIT_LIST_HEAD(&console_session.ses_grp_list);
-        CFS_INIT_LIST_HEAD(&console_session.ses_bat_list);
-        CFS_INIT_LIST_HEAD(&console_session.ses_trans_list);
+       INIT_LIST_HEAD(&console_session.ses_ndl_list);
+       INIT_LIST_HEAD(&console_session.ses_grp_list);
+       INIT_LIST_HEAD(&console_session.ses_bat_list);
+       INIT_LIST_HEAD(&console_session.ses_trans_list);
 
-        LIBCFS_ALLOC(console_session.ses_ndl_hash,
-                     sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
-        if (console_session.ses_ndl_hash == NULL)
-                return -ENOMEM;
+       LIBCFS_ALLOC(console_session.ses_ndl_hash,
+                    sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
+       if (console_session.ses_ndl_hash == NULL)
+               return -ENOMEM;
 
-        for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
-                CFS_INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
+       for (i = 0; i < LST_GLOBAL_HASHSIZE; i++)
+               INIT_LIST_HEAD(&console_session.ses_ndl_hash[i]);
 
 
         /* initialize acceptor service table */
         lstcon_init_acceptor_service();
 
-        rc = srpc_add_service(&lstcon_acceptor_service);
-        LASSERT (rc != -EBUSY);
-        if (rc != 0) {
-                LIBCFS_FREE(console_session.ses_ndl_hash,
-                            sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
-                return rc;
-        }
+       rc = srpc_add_service(&lstcon_acceptor_service);
+       LASSERT(rc != -EBUSY);
+       if (rc != 0) {
+               LIBCFS_FREE(console_session.ses_ndl_hash,
+                           sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
+               return rc;
+       }
 
        rc = srpc_service_add_buffers(&lstcon_acceptor_service,
                                      lstcon_acceptor_service.sv_wi_total);
@@ -2035,15 +2079,15 @@ lstcon_console_init(void)
         }
 
 out:
-        srpc_shutdown_service(&lstcon_acceptor_service);
-        srpc_remove_service(&lstcon_acceptor_service);
+       srpc_shutdown_service(&lstcon_acceptor_service);
+       srpc_remove_service(&lstcon_acceptor_service);
 
-        LIBCFS_FREE(console_session.ses_ndl_hash,
-                    sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
+       LIBCFS_FREE(console_session.ses_ndl_hash,
+                   sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
 
-        srpc_wait_service_shutdown(&lstcon_acceptor_service);
+       srpc_wait_service_shutdown(&lstcon_acceptor_service);
 
-        return rc;
+       return rc;
 }
 
 int
@@ -2065,21 +2109,20 @@ lstcon_console_fini(void)
 
        mutex_unlock(&console_session.ses_mutex);
 
-        LASSERT (cfs_list_empty(&console_session.ses_ndl_list));
-        LASSERT (cfs_list_empty(&console_session.ses_grp_list));
-        LASSERT (cfs_list_empty(&console_session.ses_bat_list));
-        LASSERT (cfs_list_empty(&console_session.ses_trans_list));
+       LASSERT(list_empty(&console_session.ses_ndl_list));
+       LASSERT(list_empty(&console_session.ses_grp_list));
+       LASSERT(list_empty(&console_session.ses_bat_list));
+       LASSERT(list_empty(&console_session.ses_trans_list));
 
-        for (i = 0; i < LST_NODE_HASHSIZE; i++) {
-                LASSERT (cfs_list_empty(&console_session.ses_ndl_hash[i]));
-        }
+       for (i = 0; i < LST_NODE_HASHSIZE; i++)
+               LASSERT(list_empty(&console_session.ses_ndl_hash[i]));
 
-        LIBCFS_FREE(console_session.ses_ndl_hash,
-                    sizeof(cfs_list_t) * LST_GLOBAL_HASHSIZE);
+       LIBCFS_FREE(console_session.ses_ndl_hash,
+                   sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
 
-        srpc_wait_service_shutdown(&lstcon_acceptor_service);
+       srpc_wait_service_shutdown(&lstcon_acceptor_service);
 
-        return 0;
+       return 0;
 }
 
 #endif