Whamcloud - gitweb
LU-14665 lnet: simplify lnet_ni_add_interface
[fs/lustre-release.git] / lnet / lnet / config.c
index 746253b..f6ade39 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #define DEBUG_SUBSYSTEM S_LNET
@@ -113,29 +112,13 @@ lnet_ni_unique_net(struct list_head *nilist, char *iface)
        list_for_each(tmp, nilist) {
                ni = list_entry(tmp, struct lnet_ni, ni_netlist);
 
-               if (ni->ni_interfaces[0] != NULL &&
-                   strncmp(ni->ni_interfaces[0], iface, strlen(iface)) == 0)
+               if (ni->ni_interface != NULL &&
+                   strncmp(ni->ni_interface, iface, strlen(iface)) == 0)
                        return false;
        }
 
        return true;
 }
-
-/* check that the NI is unique to the interfaces with in the same NI.
- * This is only a consideration if use_tcp_bonding is set */
-static bool
-lnet_ni_unique_ni(char *iface_list[LNET_INTERFACES_NUM], char *iface)
-{
-       int i;
-       for (i = 0; i < LNET_INTERFACES_NUM; i++) {
-               if (iface_list[i] != NULL &&
-                   strncmp(iface_list[i], iface, strlen(iface)) == 0)
-                       return false;
-       }
-
-       return true;
-}
-
 static bool
 in_array(__u32 *array, __u32 size, __u32 value)
 {
@@ -294,8 +277,6 @@ lnet_net_remove_cpts(__u32 *cpts, __u32 ncpts, struct lnet_net *net)
 void
 lnet_ni_free(struct lnet_ni *ni)
 {
-       int i;
-
        lnet_net_remove_cpts(ni->ni_cpts, ni->ni_ncpts, ni->ni_net);
 
        if (ni->ni_refs != NULL)
@@ -307,10 +288,9 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_cpts != NULL)
                cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
-       for (i = 0; i < LNET_INTERFACES_NUM &&
-                   ni->ni_interfaces[i] != NULL; i++) {
-               LIBCFS_FREE(ni->ni_interfaces[i],
-                           strlen(ni->ni_interfaces[i]) + 1);
+       if (ni->ni_interface != NULL) {
+               LIBCFS_FREE(ni->ni_interface,
+                           strlen(ni->ni_interface) + 1);
        }
 
        /* release reference to net namespace */
@@ -373,11 +353,14 @@ lnet_net_alloc(__u32 net_id, struct list_head *net_list)
        INIT_LIST_HEAD(&net->net_ni_list);
        INIT_LIST_HEAD(&net->net_ni_added);
        INIT_LIST_HEAD(&net->net_ni_zombie);
+       INIT_LIST_HEAD(&net->net_rtr_pref_nids);
        spin_lock_init(&net->net_lock);
 
        net->net_id = net_id;
        net->net_last_alive = ktime_get_real_seconds();
 
+       net->net_sel_priority = LNET_MAX_SELECTION_PRIORITY;
+
        /* initialize global paramters to undefiend */
        net->net_tunables.lct_peer_timeout = -1;
        net->net_tunables.lct_max_tx_credits = -1;
@@ -393,41 +376,32 @@ lnet_net_alloc(__u32 net_id, struct list_head *net_list)
 static int
 lnet_ni_add_interface(struct lnet_ni *ni, char *iface)
 {
-       int niface = 0;
+       size_t iface_len = strlen(iface) + 1;
 
        if (ni == NULL)
                return -ENOMEM;
 
-       if (!lnet_ni_unique_ni(ni->ni_interfaces, iface))
-               return -EINVAL;
-
-       /* Allocate a separate piece of memory and copy
-        * into it the string, so we don't have
-        * a depencency on the tokens string.  This way we
-        * can free the tokens at the end of the function.
-        * The newly allocated ni_interfaces[] can be
-        * freed when freeing the NI */
-       while (niface < LNET_INTERFACES_NUM &&
-              ni->ni_interfaces[niface] != NULL)
-               niface++;
-
-       if (niface >= LNET_INTERFACES_NUM) {
-               LCONSOLE_ERROR_MSG(0x115, "Too many interfaces "
-                                  "for net %s\n",
-                                  libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+       if (ni->ni_interface != NULL) {
+               LCONSOLE_ERROR_MSG(0x115, "%s: interface %s already set for net %s: rc = %d\n",
+                                  iface, ni->ni_interface,
+                                  libcfs_net2str(LNET_NIDNET(ni->ni_nid)),
+                                  -EINVAL);
                return -EINVAL;
        }
 
-       LIBCFS_ALLOC(ni->ni_interfaces[niface],
-                    strlen(iface) + 1);
+       /* Allocate memory for the interface, so the code parsing input into
+        * tokens and adding interfaces can free the input safely.
+        * ni->ni_interface is freed in lnet_ni_free().
+        */
+       LIBCFS_ALLOC(ni->ni_interface, iface_len);
 
-       if (ni->ni_interfaces[niface] == NULL) {
-               CERROR("Can't allocate net interface name\n");
+       if (ni->ni_interface == NULL) {
+               CERROR("%s: cannot allocate net interface name: rc = %d\n",
+                       iface, -ENOMEM);
                return -ENOMEM;
        }
 
-       strncpy(ni->ni_interfaces[niface], iface,
-               strlen(iface) + 1);
+       strscpy(ni->ni_interface, iface, iface_len);
 
        return 0;
 }
@@ -481,6 +455,7 @@ lnet_ni_alloc_common(struct lnet_net *net, char *iface)
                ni->ni_net_ns = get_net(&init_net);
 
        ni->ni_state = LNET_NI_STATE_INIT;
+       ni->ni_sel_priority = LNET_MAX_SELECTION_PRIORITY;
        list_add_tail(&ni->ni_netlist, &net->net_ni_added);
 
        /*
@@ -578,8 +553,7 @@ failed:
  * nilist.
  */
 int
-lnet_parse_networks(struct list_head *netlist, const char *networks,
-                   bool use_tcp_bonding)
+lnet_parse_networks(struct list_head *netlist, const char *networks)
 {
        struct cfs_expr_list *net_el = NULL;
        struct cfs_expr_list *ni_el = NULL;
@@ -721,8 +695,7 @@ lnet_parse_networks(struct list_head *netlist, const char *networks,
                if (IS_ERR_OR_NULL(net))
                        goto failed;
 
-               if (!nistr ||
-                   (use_tcp_bonding && LNET_NETTYP(net_id) == SOCKLND)) {
+               if (!nistr) {
                        /*
                         * No interface list was specified, allocate a
                         * ni using the defaults.
@@ -801,16 +774,9 @@ lnet_parse_networks(struct list_head *netlist, const char *networks,
                                goto failed_syntax;
                        }
 
-                       if (use_tcp_bonding &&
-                           LNET_NETTYP(net->net_id) == SOCKLND) {
-                               rc = lnet_ni_add_interface(ni, name);
-                               if (rc != 0)
-                                       goto failed;
-                       } else {
-                               ni = lnet_ni_alloc(net, ni_el, name);
-                               if (IS_ERR_OR_NULL(ni))
-                                       goto failed;
-                       }
+                       ni = lnet_ni_alloc(net, ni_el, name);
+                       if (IS_ERR_OR_NULL(ni))
+                               goto failed;
 
                        if (ni_el) {
                                if (ni_el != net_el) {