Whamcloud - gitweb
LU-9679 lnet: tidy lnet_discover and fix mem accounting bug.
[fs/lustre-release.git] / lnet / lnet / api-ni.c
index f59d581..05c0cb3 100644 (file)
@@ -536,17 +536,17 @@ intf_max_set(const char *val, cfs_kernel_param_arg_t *kp)
        return 0;
 }
 
-static char *
+static const char *
 lnet_get_routes(void)
 {
        return routes;
 }
 
-static char *
+static const char *
 lnet_get_networks(void)
 {
-       char   *nets;
-       int     rc;
+       const char *nets;
+       int rc;
 
        if (*networks != 0 && *ip2nets != 0) {
                LCONSOLE_ERROR_MSG(0x101, "Please specify EITHER 'networks' or "
@@ -1270,6 +1270,7 @@ lnet_unprepare (void)
                the_lnet.ln_mt_zombie_rstqs = NULL;
        }
 
+       lnet_assert_handler_unused(the_lnet.ln_mt_handler);
        the_lnet.ln_mt_handler = NULL;
 
        lnet_portals_destroy();
@@ -1644,7 +1645,7 @@ lnet_ping_info_validate(struct lnet_ping_info *pinfo)
        /* Loopback is guaranteed to be present */
        if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max)
                return -ERANGE;
-       if (LNET_NETTYP(LNET_NIDNET(LNET_PING_INFO_LONI(pinfo))) != LOLND)
+       if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0)
                return -EPROTO;
        return 0;
 }
@@ -1674,7 +1675,7 @@ lnet_ping_target_destroy(void)
 static void
 lnet_ping_target_event_handler(struct lnet_event *event)
 {
-       struct lnet_ping_buffer *pbuf = event->md.user_ptr;
+       struct lnet_ping_buffer *pbuf = event->md_user_ptr;
 
        if (event->unlinked)
                lnet_ping_buffer_decref(pbuf);
@@ -1842,6 +1843,7 @@ lnet_ping_target_fini(void)
        lnet_ping_md_unlink(the_lnet.ln_ping_target,
                            &the_lnet.ln_ping_target_md);
 
+       lnet_assert_handler_unused(the_lnet.ln_ping_target_handler);
        lnet_ping_target_destroy();
 }
 
@@ -1947,7 +1949,7 @@ int lnet_push_target_post(struct lnet_ping_buffer *pbuf,
 
 static void lnet_push_target_event_handler(struct lnet_event *ev)
 {
-       struct lnet_ping_buffer *pbuf = ev->md.user_ptr;
+       struct lnet_ping_buffer *pbuf = ev->md_user_ptr;
 
        CDEBUG(D_NET, "type %d status %d unlinked %d\n", ev->type, ev->status,
               ev->unlinked);
@@ -2015,6 +2017,7 @@ static void lnet_push_target_fini(void)
        the_lnet.ln_push_target_nnis = 0;
 
        LNetClearLazyPortal(LNET_RESERVED_PORTAL);
+       lnet_assert_handler_unused(the_lnet.ln_push_target_handler);
        the_lnet.ln_push_target_handler = NULL;
 }
 
@@ -2804,7 +2807,7 @@ lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni,
        }
 
        cfg_ni->lic_nid = ni->ni_nid;
-       if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND)
+       if (ni->ni_nid == LNET_NID_LO_0)
                cfg_ni->lic_status = LNET_NI_STATUS_UP;
        else
                cfg_ni->lic_status = ni->ni_status->ns_status;
@@ -2896,7 +2899,7 @@ lnet_fill_ni_info_legacy(struct lnet_ni *ni,
        config->cfg_config_u.cfg_net.net_peer_rtr_credits =
                ni->ni_net->net_tunables.lct_peer_rtr_credits;
 
-       if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND)
+       if (ni->ni_nid == LNET_NID_LO_0)
                net_config->ni_status = LNET_NI_STATUS_UP;
        else
                net_config->ni_status = ni->ni_status->ns_status;
@@ -3175,7 +3178,7 @@ static int lnet_handle_legacy_ip2nets(char *ip2nets,
                                      struct lnet_ioctl_config_lnd_tunables *tun)
 {
        struct lnet_net *net;
-       char *nets;
+       const char *nets;
        int rc;
        LIST_HEAD(net_head);
 
@@ -3358,7 +3361,7 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
        LIST_HEAD(net_head);
        int rc;
        struct lnet_ioctl_config_lnd_tunables tun;
-       char *nets = conf->cfg_config_u.cfg_net.net_intf;
+       const char *nets = conf->cfg_config_u.cfg_net.net_intf;
 
        /* Create a net/ni structures for the network string */
        rc = lnet_parse_networks(&net_head, nets, use_tcp_bonding);
@@ -4099,7 +4102,7 @@ struct ping_data {
 static void
 lnet_ping_event_handler(struct lnet_event *event)
 {
-       struct ping_data *pd = event->md.user_ptr;
+       struct ping_data *pd = event->md_user_ptr;
 
        CDEBUG(D_NET, "ping event (%d %d)%s\n",
               event->type, event->status,
@@ -4254,7 +4257,6 @@ lnet_discover(struct lnet_process_id id, __u32 force,
        int cpt;
        int i;
        int rc;
-       int max_intf = lnet_interfaces_max;
 
        if (n_ids <= 0 ||
            id.nid == LNET_NID_ANY)
@@ -4264,11 +4266,11 @@ lnet_discover(struct lnet_process_id id, __u32 force,
                id.pid = LNET_PID_LUSTRE;
 
        /*
-        * if the user buffer has more space than the max_intf
-        * then only fill it up to max_intf
+        * If the user buffer has more space than the lnet_interfaces_max,
+        * then only fill it up to lnet_interfaces_max.
         */
-       if (n_ids > max_intf)
-               n_ids = max_intf;
+       if (n_ids > lnet_interfaces_max)
+               n_ids = lnet_interfaces_max;
 
        CFS_ALLOC_PTR_ARRAY(buf, n_ids);
        if (!buf)
@@ -4296,11 +4298,6 @@ lnet_discover(struct lnet_process_id id, __u32 force,
        if (rc)
                goto out_decref;
 
-       /* Peer may have changed. */
-       lp = lpni->lpni_peer_net->lpn_peer;
-       if (lp->lp_nnis < n_ids)
-               n_ids = lp->lp_nnis;
-
        i = 0;
        p = NULL;
        while ((p = lnet_get_next_peer_ni_locked(lp, NULL, p)) != NULL) {
@@ -4309,20 +4306,16 @@ lnet_discover(struct lnet_process_id id, __u32 force,
                if (++i >= n_ids)
                        break;
        }
+       rc = i;
 
-       lnet_net_unlock(cpt);
-
-       rc = -EFAULT;
-       if (copy_to_user(ids, buf, n_ids * sizeof(*buf)))
-               goto out_relock;
-       rc = n_ids;
-out_relock:
-       lnet_net_lock(cpt);
 out_decref:
        lnet_peer_ni_decref_locked(lpni);
 out:
        lnet_net_unlock(cpt);
 
+       if (rc >= 0)
+               if (copy_to_user(ids, buf, rc * sizeof(*buf)))
+                       rc = -EFAULT;
        CFS_FREE_PTR_ARRAY(buf, n_ids);
 
        return rc;