Whamcloud - gitweb
LU-3889 osc: Allow lock to be canceled at ENQ time
[fs/lustre-release.git] / lnet / lnet / config.c
index c3dd0a7..deca792 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/
@@ -133,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);
@@ -173,11 +175,11 @@ lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, cfs_list_t *nilist)
                ni->ni_ncpts = rc;
        }
 
-        /* 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;
@@ -612,6 +614,37 @@ lnet_parse_hops (char *str, unsigned int *hops)
                 *hops > 0 && *hops < 256);
 }
 
+#define LNET_PRIORITY_SEPARATOR (':')
+
+int
+lnet_parse_priority(char *str, unsigned int *priority, char **token)
+{
+       int   nob;
+       char *sep;
+       int   len;
+
+       sep = strchr(str, LNET_PRIORITY_SEPARATOR);
+       if (sep == NULL) {
+               *priority = 0;
+               return 0;
+       }
+       len = strlen(sep + 1);
+
+       if ((sscanf((sep+1), "%u%n", priority, &nob) < 1) || (len != nob)) {
+               /* Update the caller's token pointer so it treats the found
+                  priority as the token to report in the error message. */
+               *token += sep - str + 1;
+               return -1;
+       }
+
+       CDEBUG(D_NET, "gateway %s, priority %d, nob %d\n", str, *priority, nob);
+
+       /*
+        * Change priority separator to \0 to be able to parse NID
+        */
+       *sep = '\0';
+       return 0;
+}
 
 int
 lnet_parse_route (char *str, int *im_a_router)
@@ -633,6 +666,7 @@ lnet_parse_route (char *str, int *im_a_router)
         int               myrc = -1;
         unsigned int      hops;
         int               got_hops = 0;
+       unsigned int      priority = 0;
 
        CFS_INIT_LIST_HEAD(&gateways);
        CFS_INIT_LIST_HEAD(&nets);
@@ -700,6 +734,11 @@ lnet_parse_route (char *str, int *im_a_router)
                                     LNET_NETTYP(net) == LOLND)
                                        goto token_error;
                        } else {
+                               rc = lnet_parse_priority(ltb->ltb_text,
+                                                        &priority, &token);
+                               if (rc < 0)
+                                       goto token_error;
+
                                nid = libcfs_str2nid(ltb->ltb_text);
                                if (nid == LNET_NID_ANY ||
                                     LNET_NETTYP(LNET_NIDNET(nid)) == LOLND)
@@ -722,14 +761,14 @@ lnet_parse_route (char *str, int *im_a_router)
                cfs_list_for_each (tmp2, &gateways) {
                        ltb = cfs_list_entry(tmp2, lnet_text_buf_t, ltb_list);
                        nid = libcfs_str2nid(ltb->ltb_text);
-                       LASSERT (nid != LNET_NID_ANY);
+                       LASSERT(nid != LNET_NID_ANY);
 
                         if (lnet_islocalnid(nid)) {
                                 *im_a_router = 1;
                                 continue;
                         }
                         
-                        rc = lnet_add_route (net, hops, nid);
+                       rc = lnet_add_route(net, hops, nid, priority);
                         if (rc != 0) {
                                 CERROR("Can't create route "
                                        "to %s via %s\n",