Whamcloud - gitweb
LU-554 LNet: add gnilnd awareness to LNet
[fs/lustre-release.git] / lnet / libcfs / nidstrings.c
index 75ae7b0..4e514c0 100644 (file)
@@ -1,23 +1,41 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002 Cluster File Systems, Inc.
- *   Author: Phil Schwan <phil@clusterfs.com>
+ * GPL HEADER START
  *
- *   This file is part of Lustre, http://www.lustre.org.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   Lustre is free software; you can redistribute it and/or
- *   modify it under the terms of version 2 of the GNU General Public
- *   License as published by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   Lustre is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   You should have received a copy of the GNU General Public License
- *   along with Lustre; if not, write to the Free Software
- *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lnet/libcfs/nidstrings.c
+ *
+ * Author: Phil Schwan <phil@clusterfs.com>
  */
 
 #ifndef EXPORT_SYMTAB
@@ -46,9 +64,6 @@
  * between getting its string and using it.
  */
 
-#define LNET_NIDSTR_COUNT  128     /* # of nidstrings */
-#define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */
-
 static char      libcfs_nidstrings[LNET_NIDSTR_COUNT][LNET_NIDSTR_SIZE];
 static int       libcfs_nidstring_idx = 0;
 
@@ -84,19 +99,19 @@ libcfs_next_nidstring (void)
         return str;
 }
 
-static int  libcfs_lo_str2addr(char *str, int nob, __u32 *addr);
+static int  libcfs_lo_str2addr(const char *str, int nob, __u32 *addr);
 static void libcfs_ip_addr2str(__u32 addr, char *str);
-static int  libcfs_ip_str2addr(char *str, int nob, __u32 *addr);
+static int  libcfs_ip_str2addr(const char *str, int nob, __u32 *addr);
 static void libcfs_decnum_addr2str(__u32 addr, char *str);
 static void libcfs_hexnum_addr2str(__u32 addr, char *str);
-static int  libcfs_num_str2addr(char *str, int nob, __u32 *addr);
+static int  libcfs_num_str2addr(const char *str, int nob, __u32 *addr);
 
 struct netstrfns {
         int          nf_type;
         char        *nf_name;
         char        *nf_modname;
         void       (*nf_addr2str)(__u32 addr, char *str);
-        int        (*nf_str2addr)(char *str, int nob, __u32 *addr);
+        int        (*nf_str2addr)(const char *str, int nob, __u32 *addr);
 };
 
 static struct netstrfns  libcfs_netstrfns[] = {
@@ -160,6 +175,11 @@ static struct netstrfns  libcfs_netstrfns[] = {
          /* .nf_modname   */  "kptllnd",
          /* .nf_addr2str  */  libcfs_decnum_addr2str,
          /* .nf_str2addr  */  libcfs_num_str2addr},
+        {/* .nf_type      */  GNILND,
+         /* .nf_name      */  "gni",
+         /* .nf_modname   */  "kgnilnd",
+         /* .nf_addr2str  */  libcfs_decnum_addr2str,
+         /* .nf_str2addr  */  libcfs_num_str2addr},
         /* placeholder for net0 alias.  It MUST BE THE LAST ENTRY */
         {/* .nf_type      */  -1},
 };
@@ -167,7 +187,7 @@ static struct netstrfns  libcfs_netstrfns[] = {
 const int libcfs_nnetstrfns = sizeof(libcfs_netstrfns)/sizeof(libcfs_netstrfns[0]);
 
 int
-libcfs_lo_str2addr(char *str, int nob, __u32 *addr)
+libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
 {
         *addr = 0;
         return 1;
@@ -200,7 +220,7 @@ libcfs_ip_addr2str(__u32 addr, char *str)
  * fine too :) */
 
 int
-libcfs_ip_str2addr(char *str, int nob, __u32 *addr)
+libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
 {
         int   a;
         int   b;
@@ -259,7 +279,7 @@ libcfs_hexnum_addr2str(__u32 addr, char *str)
 }
 
 int
-libcfs_num_str2addr(char *str, int nob, __u32 *addr)
+libcfs_num_str2addr(const char *str, int nob, __u32 *addr)
 {
         int     n;
 
@@ -292,7 +312,7 @@ libcfs_lnd2netstrfns(int lnd)
 }
 
 struct netstrfns *
-libcfs_name2netstrfns(char *name)
+libcfs_name2netstrfns(const char *name)
 {
         int    i;
 
@@ -333,7 +353,7 @@ libcfs_lnd2str(int lnd)
 }
 
 int
-libcfs_str2lnd(char *str)
+libcfs_str2lnd(const char *str)
 {
         struct netstrfns *nf = libcfs_name2netstrfns(str);
 
@@ -395,9 +415,9 @@ libcfs_nid2str(lnet_nid_t nid)
 }
 
 static struct netstrfns *
-libcfs_str2net_internal(char *str, __u32 *net)
+libcfs_str2net_internal(const char *str, __u32 *net)
 {
-        struct netstrfns *nf;
+        struct netstrfns *nf = NULL;
         int               nob;
         int               netnum;
         int               i;
@@ -432,7 +452,7 @@ libcfs_str2net_internal(char *str, __u32 *net)
 }
 
 __u32
-libcfs_str2net(char *str)
+libcfs_str2net(const char *str)
 {
         __u32  net;
 
@@ -443,9 +463,9 @@ libcfs_str2net(char *str)
 }
 
 lnet_nid_t
-libcfs_str2nid(char *str)
+libcfs_str2nid(const char *str)
 {
-        char             *sep = strchr(str, '@');
+        const char       *sep = strchr(str, '@');
         struct netstrfns *nf;
         __u32             net;
         __u32             addr;
@@ -485,7 +505,7 @@ libcfs_id2str(lnet_process_id_t id)
 }
 
 int
-libcfs_str2anynid(lnet_nid_t *nidp, char *str)
+libcfs_str2anynid(lnet_nid_t *nidp, const char *str)
 {
         if (!strcmp(str, "*")) {
                 *nidp = LNET_NID_ANY;