Whamcloud - gitweb
LU-13306 mgs: use large NIDS in the nid table on the MGS
[fs/lustre-release.git] / lnet / selftest / console.c
index a595476..03d55c5 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lnet/selftest/conctl.c
  *
@@ -223,8 +222,7 @@ lstcon_group_alloc(char *name, struct lstcon_group **grpp)
        return 0;
 }
 
-static void
-lstcon_group_addref(struct lstcon_group *grp)
+void lstcon_group_addref(struct lstcon_group *grp)
 {
        grp->grp_ref++;
 }
@@ -244,8 +242,7 @@ lstcon_group_drain(struct lstcon_group *grp, int keep)
        }
 }
 
-static void
-lstcon_group_decref(struct lstcon_group *grp)
+void lstcon_group_decref(struct lstcon_group *grp)
 {
        int i;
 
@@ -264,8 +261,7 @@ lstcon_group_decref(struct lstcon_group *grp)
                                  grp_ndl_hash[LST_NODE_HASHSIZE]));
 }
 
-static int
-lstcon_group_find(const char *name, struct lstcon_group **grpp)
+int lstcon_group_find(const char *name, struct lstcon_group **grpp)
 {
        struct lstcon_group *grp;
 
@@ -315,15 +311,11 @@ lstcon_group_ndlink_move(struct lstcon_group *old,
        unsigned int idx = LNET_NIDADDR(ndl->ndl_node->nd_id.nid) %
                                        LST_NODE_HASHSIZE;
 
-       list_del(&ndl->ndl_hlink);
-       list_del(&ndl->ndl_link);
        old->grp_nnode--;
 
-       list_add_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
-       list_add_tail(&ndl->ndl_link, &new->grp_ndl_list);
+       list_move_tail(&ndl->ndl_hlink, &new->grp_ndl_hash[idx]);
+       list_move_tail(&ndl->ndl_link, &new->grp_ndl_list);
        new->grp_nnode++;
-
-       return;
 }
 
 static void
@@ -332,8 +324,8 @@ lstcon_group_move(struct lstcon_group *old, struct lstcon_group *new)
        struct lstcon_ndlink *ndl;
 
        while (!list_empty(&old->grp_ndl_list)) {
-               ndl = list_entry(old->grp_ndl_list.next,
-                                struct lstcon_ndlink, ndl_link);
+               ndl = list_first_entry(&old->grp_ndl_list,
+                                      struct lstcon_ndlink, ndl_link);
                lstcon_group_ndlink_move(old, new, ndl);
        }
 }
@@ -720,24 +712,6 @@ lstcon_group_refresh(char *name, struct list_head __user *result_up)
         return rc;
 }
 
-int
-lstcon_group_list(int index, int len, char __user *name_up)
-{
-       struct lstcon_group *grp;
-
-       LASSERT(index >= 0);
-       LASSERT(name_up != NULL);
-
-       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;
-               }
-       }
-
-       return -ENOENT;
-}
-
 static int
 lstcon_nodes_getent(struct list_head *head, int *index_p,
                    int *count_p, struct lstcon_node_ent __user *dents_up)
@@ -804,7 +778,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
         }
 
         /* non-verbose query */
-       LIBCFS_ALLOC(gentp, sizeof(struct lstcon_ndlist_ent));
+       CFS_ALLOC_PTR(gentp);
         if (gentp == NULL) {
                 CERROR("Can't allocate ndlist_ent\n");
                lstcon_group_decref(grp);
@@ -818,7 +792,7 @@ lstcon_group_info(char *name, struct lstcon_ndlist_ent __user *gents_p,
        rc = copy_to_user(gents_p, gentp,
                          sizeof(struct lstcon_ndlist_ent)) ? -EFAULT : 0;
 
-       LIBCFS_FREE(gentp, sizeof(struct lstcon_ndlist_ent));
+       CFS_FREE_PTR(gentp);
 
        lstcon_group_decref(grp);
 
@@ -859,24 +833,22 @@ lstcon_batch_add(char *name)
                 return -ENOMEM;
         }
 
-       LIBCFS_ALLOC(bat->bat_cli_hash,
-                    sizeof(struct list_head) * LST_NODE_HASHSIZE);
+       CFS_ALLOC_PTR_ARRAY(bat->bat_cli_hash, LST_NODE_HASHSIZE);
        if (bat->bat_cli_hash == NULL) {
                CERROR("Can't allocate hash for batch %s\n", name);
                LIBCFS_FREE(bat, sizeof(*bat));
 
-                return -ENOMEM;
-        }
+               return -ENOMEM;
+       }
 
-        LIBCFS_ALLOC(bat->bat_srv_hash,
-                    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);
+       CFS_ALLOC_PTR_ARRAY(bat->bat_srv_hash, 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);
                LIBCFS_FREE(bat, sizeof(*bat));
 
-                return -ENOMEM;
-        }
+               return -ENOMEM;
+       }
 
        if (strlen(name) > sizeof(bat->bat_name)-1) {
                LIBCFS_FREE(bat->bat_srv_hash, LST_NODE_HASHSIZE);
@@ -968,7 +940,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
         }
 
         /* non-verbose query */
-       LIBCFS_ALLOC(entp, sizeof(struct lstcon_test_batch_ent));
+       CFS_ALLOC_PTR(entp);
         if (entp == NULL)
                 return -ENOMEM;
 
@@ -992,7 +964,7 @@ lstcon_batch_info(char *name, struct lstcon_test_batch_ent __user *ent_up,
        rc = copy_to_user(ent_up, entp,
                          sizeof(struct lstcon_test_batch_ent)) ? -EFAULT : 0;
 
-       LIBCFS_FREE(entp, sizeof(struct lstcon_test_batch_ent));
+       CFS_FREE_PTR(entp)
 
        return rc;
 }
@@ -1097,8 +1069,8 @@ lstcon_batch_destroy(struct lstcon_batch *bat)
        list_del(&bat->bat_link);
 
        while (!list_empty(&bat->bat_test_list)) {
-               test = list_entry(bat->bat_test_list.next,
-                                 struct lstcon_test, tes_link);
+               test = list_first_entry(&bat->bat_test_list,
+                                       struct lstcon_test, tes_link);
                LASSERT(list_empty(&test->tes_trans_list));
 
                list_del(&test->tes_link);
@@ -1113,16 +1085,16 @@ lstcon_batch_destroy(struct lstcon_batch *bat)
        LASSERT(list_empty(&bat->bat_trans_list));
 
        while (!list_empty(&bat->bat_cli_list)) {
-               ndl = list_entry(bat->bat_cli_list.next,
-                                struct lstcon_ndlink, ndl_link);
+               ndl = list_first_entry(&bat->bat_cli_list,
+                                      struct lstcon_ndlink, ndl_link);
                list_del_init(&ndl->ndl_link);
 
                lstcon_ndlink_release(ndl);
        }
 
        while (!list_empty(&bat->bat_srv_list)) {
-               ndl = list_entry(bat->bat_srv_list.next,
-                                struct lstcon_ndlink, ndl_link);
+               ndl = list_first_entry(&bat->bat_srv_list,
+                                      struct lstcon_ndlink, ndl_link);
                list_del_init(&ndl->ndl_link);
 
                lstcon_ndlink_release(ndl);
@@ -1472,7 +1444,7 @@ lstcon_statrpc_readent(int transop, struct srpc_msg *msg,
        struct srpc_stat_reply *rep = &msg->msg_body.stat_reply;
        struct sfw_counters __user *sfwk_stat;
        struct srpc_counters __user *srpc_stat;
-       struct lnet_counters __user *lnet_stat;
+       struct lnet_counters_common __user *lnet_stat;
 
         if (rep->str_status != 0)
                 return 0;
@@ -1480,7 +1452,7 @@ lstcon_statrpc_readent(int transop, struct srpc_msg *msg,
        sfwk_stat = (struct sfw_counters __user *)&ent_up->rpe_payload[0];
        srpc_stat = (struct srpc_counters __user *)
                ((char __user *)sfwk_stat + sizeof(*sfwk_stat));
-       lnet_stat = (struct lnet_counters __user *)
+       lnet_stat = (struct lnet_counters_common __user *)
                ((char __user *)srpc_stat + sizeof(*srpc_stat));
 
        if (copy_to_user(sfwk_stat, &rep->str_fw, sizeof(*sfwk_stat)) ||
@@ -1495,11 +1467,9 @@ static int
 lstcon_ndlist_stat(struct list_head *ndlist,
                   int timeout, struct list_head __user *result_up)
 {
-       struct list_head    head;
+       LIST_HEAD(head);
        struct lstcon_rpc_trans *trans;
-       int                 rc;
-
-       INIT_LIST_HEAD(&head);
+       int rc;
 
         rc = lstcon_rpc_trans_ndlist(ndlist, &head,
                                      LST_TRANS_STATQRY, NULL, NULL, &trans);
@@ -1693,27 +1663,32 @@ lstcon_nodes_debug(int timeout, int count,
 }
 
 int
-lstcon_session_match(struct lst_sid sid)
+lstcon_session_match(struct lst_sid id)
 {
-        return (console_session.ses_id.ses_nid   == sid.ses_nid &&
-                console_session.ses_id.ses_stamp == sid.ses_stamp) ?  1: 0;
+       struct lst_session_id sid;
+
+       sid.ses_stamp = id.ses_stamp;
+       lnet_nid4_to_nid(id.ses_nid, &sid.ses_nid);
+
+       return (nid_same(&console_session.ses_id.ses_nid, &sid.ses_nid) &&
+               console_session.ses_id.ses_stamp == sid.ses_stamp) ?  1 : 0;
 }
 
 static void
-lstcon_new_session_id(struct lst_sid *sid)
+lstcon_new_session_id(struct lst_session_id *sid)
 {
-       struct lnet_process_id id;
+       struct lnet_processid id;
 
        LASSERT(console_session.ses_state == LST_SESSION_NONE);
 
-       LNetGetId(1, &id);
+       LNetGetId(1, &id, true);
        sid->ses_nid = id.nid;
        sid->ses_stamp = div_u64(ktime_get_ns(), NSEC_PER_MSEC);
 }
 
 int
 lstcon_session_new(char *name, int key, unsigned feats,
-                  int timeout, int force, struct lst_sid __user *sid_up)
+                  int timeout, int force)
 {
         int     rc = 0;
         int     i;
@@ -1745,7 +1720,6 @@ lstcon_session_new(char *name, int key, unsigned feats,
        lstcon_new_session_id(&console_session.ses_id);
 
        console_session.ses_key     = key;
-       console_session.ses_state   = LST_SESSION_ACTIVE;
        console_session.ses_force   = !!force;
        console_session.ses_features = feats;
        console_session.ses_feats_updated = 0;
@@ -1771,52 +1745,12 @@ lstcon_session_new(char *name, int key, unsigned feats,
                 return rc;
         }
 
-       if (copy_to_user(sid_up, &console_session.ses_id,
-                            sizeof(struct lst_sid)) == 0)
-                return rc;
-
-        lstcon_session_end();
-
-        return -EFAULT;
-}
-
-int
-lstcon_session_info(struct lst_sid __user *sid_up, int __user *key_up,
-                   unsigned __user *featp,
-                   struct lstcon_ndlist_ent __user *ndinfo_up,
-                   char __user *name_up, int len)
-{
-       struct lstcon_ndlist_ent *entp;
-       struct lstcon_ndlink *ndl;
-       int rc = 0;
-
-        if (console_session.ses_state != LST_SESSION_ACTIVE)
-                return -ESRCH;
+       console_session.ses_state = LST_SESSION_ACTIVE;
 
-        LIBCFS_ALLOC(entp, sizeof(*entp));
-        if (entp == NULL)
-                return -ENOMEM;
-
-       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(struct lst_sid)) ||
-           copy_to_user(key_up, &console_session.ses_key,
-                            sizeof(*key_up)) ||
-           copy_to_user(featp, &console_session.ses_features,
-                            sizeof(*featp)) ||
-           copy_to_user(ndinfo_up, entp, sizeof(*entp)) ||
-           copy_to_user(name_up, console_session.ses_name, len))
-                rc = -EFAULT;
-
-        LIBCFS_FREE(entp, sizeof(*entp));
-
-        return rc;
+       return rc;
 }
 
-int
-lstcon_session_end()
+int lstcon_session_end(void)
 {
        struct lstcon_rpc_trans *trans;
        struct lstcon_group *grp;
@@ -1853,16 +1787,16 @@ lstcon_session_end()
 
        /* destroy all batches */
        while (!list_empty(&console_session.ses_bat_list)) {
-               bat = list_entry(console_session.ses_bat_list.next,
-                                struct lstcon_batch, bat_link);
+               bat = list_first_entry(&console_session.ses_bat_list,
+                                      struct lstcon_batch, bat_link);
 
                lstcon_batch_destroy(bat);
        }
 
        /* destroy all groups */
        while (!list_empty(&console_session.ses_grp_list)) {
-               grp = list_entry(console_session.ses_grp_list.next,
-                                struct lstcon_group, grp_link);
+               grp = list_first_entry(&console_session.ses_grp_list,
+                                      struct lstcon_group, grp_link);
                LASSERT(grp->grp_ref == 1);
 
                lstcon_group_decref(grp);
@@ -1924,9 +1858,10 @@ lstcon_acceptor_handle(struct srpc_server_rpc *rpc)
 
        mutex_lock(&console_session.ses_mutex);
 
-        jrep->join_sid = console_session.ses_id;
+       jrep->join_sid.ses_stamp = console_session.ses_id.ses_stamp;
+       jrep->join_sid.ses_nid = lnet_nid_to_nid4(&console_session.ses_id.ses_nid);
 
-        if (console_session.ses_id.ses_nid == LNET_NID_ANY) {
+       if (LNET_NID_IS_ANY(&console_session.ses_id.ses_nid)) {
                 jrep->join_status = ESRCH;
                 goto out;
         }
@@ -2031,8 +1966,8 @@ lstcon_console_init(void)
        INIT_LIST_HEAD(&console_session.ses_bat_list);
        INIT_LIST_HEAD(&console_session.ses_trans_list);
 
-       LIBCFS_ALLOC(console_session.ses_ndl_hash,
-                    sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
+       CFS_ALLOC_PTR_ARRAY(console_session.ses_ndl_hash,
+                              LST_GLOBAL_HASHSIZE);
        if (console_session.ses_ndl_hash == NULL)
                return -ENOMEM;
 
@@ -2046,8 +1981,8 @@ lstcon_console_init(void)
        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);
+               CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
+                                  LST_GLOBAL_HASHSIZE);
                return rc;
        }
 
@@ -2058,19 +1993,25 @@ lstcon_console_init(void)
                 goto out;
         }
 
-       rc = blocking_notifier_chain_register(&libcfs_ioctl_list,
+       rc = lstcon_init_netlink();
+       if (rc < 0)
+               goto out;
+
+       rc = blocking_notifier_chain_register(&lnet_ioctl_list,
                                              &lstcon_ioctl_handler);
-       if (rc == 0) {
-               lstcon_rpc_module_init();
-               return 0;
+       if (rc < 0) {
+               lstcon_fini_netlink();
+               goto out;
        }
 
+       lstcon_rpc_module_init();
+       return 0;
+
 out:
        srpc_shutdown_service(&lstcon_acceptor_service);
        srpc_remove_service(&lstcon_acceptor_service);
 
-       LIBCFS_FREE(console_session.ses_ndl_hash,
-                   sizeof(struct list_head) * LST_GLOBAL_HASHSIZE);
+       CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash, LST_GLOBAL_HASHSIZE);
 
        srpc_wait_service_shutdown(&lstcon_acceptor_service);
 
@@ -2082,8 +2023,9 @@ lstcon_console_fini(void)
 {
        int i;
 
-       blocking_notifier_chain_unregister(&libcfs_ioctl_list,
+       blocking_notifier_chain_unregister(&lnet_ioctl_list,
                                           &lstcon_ioctl_handler);
+       lstcon_fini_netlink();
 
        mutex_lock(&console_session.ses_mutex);
 
@@ -2105,8 +2047,8 @@ lstcon_console_fini(void)
        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(struct list_head) * LST_GLOBAL_HASHSIZE);
+       CFS_FREE_PTR_ARRAY(console_session.ses_ndl_hash,
+                          LST_GLOBAL_HASHSIZE);
 
        srpc_wait_service_shutdown(&lstcon_acceptor_service);