Whamcloud - gitweb
LU-2311 osd-ldiskfs: fix link refcounting
[fs/lustre-release.git] / lnet / lnet / config.c
index 99c9ff3..b18c103 100644 (file)
@@ -26,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -100,10 +102,8 @@ lnet_ni_free(struct lnet_ni *ni)
        if (ni->ni_tx_queues != NULL)
                cfs_percpt_free(ni->ni_tx_queues);
 
-       if (ni->ni_cpts != NULL) {
-               LIBCFS_FREE(ni->ni_cpts,
-                           sizeof(ni->ni_cpts[0] * ni->ni_ncpts));
-       }
+       if (ni->ni_cpts != NULL)
+               cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
 #ifndef __KERNEL__
 # ifdef HAVE_LIBPTHREAD
@@ -114,7 +114,7 @@ lnet_ni_free(struct lnet_ni *ni)
 }
 
 lnet_ni_t *
-lnet_ni_alloc(__u32 net, struct cfs_expr_list **el, cfs_list_t *nilist)
+lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, cfs_list_t *nilist)
 {
        struct lnet_tx_queue    *tq;
        struct lnet_ni          *ni;
@@ -135,7 +135,7 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list **el, cfs_list_t *nilist)
         }
 
 #ifdef __KERNEL__
-       cfs_spin_lock_init(&ni->ni_lock);
+       spin_lock_init(&ni->ni_lock);
 #else
 # ifdef HAVE_LIBPTHREAD
        pthread_mutex_init(&ni->ni_lock, NULL);
@@ -155,11 +155,11 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list **el, cfs_list_t *nilist)
        cfs_percpt_for_each(tq, i, ni->ni_tx_queues)
                CFS_INIT_LIST_HEAD(&tq->tq_delayed);
 
-       if (el == NULL || *el == NULL) {
+       if (el == NULL) {
                ni->ni_cpts  = NULL;
                ni->ni_ncpts = LNET_CPT_NUMBER;
        } else {
-               rc = cfs_expr_list_values(*el, LNET_CPT_NUMBER, &ni->ni_cpts);
+               rc = cfs_expr_list_values(el, LNET_CPT_NUMBER, &ni->ni_cpts);
                if (rc <= 0) {
                        CERROR("Failed to set CPTs for NI %s: %d\n",
                               libcfs_net2str(net), rc);
@@ -173,15 +173,13 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list **el, cfs_list_t *nilist)
                }
 
                ni->ni_ncpts = rc;
-               cfs_expr_list_free(*el); /* consume it */
-               *el = NULL;
        }
 
-        /* LND will fill in the address part of the NID */
-        ni->ni_nid = LNET_MKNID(net, 0);
-        ni->ni_last_alive = cfs_time_current();
-        cfs_list_add_tail(&ni->ni_list, nilist);
-        return ni;
+       /* LND will fill in the address part of the NID */
+       ni->ni_nid = LNET_MKNID(net, 0);
+       ni->ni_last_alive = cfs_time_current_sec();
+       cfs_list_add_tail(&ni->ni_list, nilist);
+       return ni;
  failed:
        lnet_ni_free(ni);
        return NULL;
@@ -275,8 +273,13 @@ lnet_parse_networks(cfs_list_t *nilist, char *networks)
                         }
 
                        if (LNET_NETTYP(net) != LOLND && /* LO is implicit */
-                           lnet_ni_alloc(net, &el, nilist) == NULL)
-                                goto failed;
+                           lnet_ni_alloc(net, el, nilist) == NULL)
+                               goto failed;
+
+                       if (el != NULL) {
+                               cfs_expr_list_free(el);
+                               el = NULL;
+                       }
 
                        str = comma;
                        continue;
@@ -290,11 +293,16 @@ lnet_parse_networks(cfs_list_t *nilist, char *networks)
                }
 
                nnets++;
-               ni = lnet_ni_alloc(net, &el, nilist);
-                if (ni == NULL)
-                        goto failed;
+               ni = lnet_ni_alloc(net, el, nilist);
+               if (ni == NULL)
+                       goto failed;
+
+               if (el != NULL) {
+                       cfs_expr_list_free(el);
+                       el = NULL;
+               }
 
-                niface = 0;
+               niface = 0;
                iface = bracket + 1;
 
                bracket = strchr(iface, ')');