Whamcloud - gitweb
2690bac5c91e07eeeec9241a60f3731805d7e486
[fs/lustre-release.git] / lnet / include / lnet / nidstr.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2014, 2015, Intel Corporation.
27  */
28 #ifndef _LNET_NIDSTRINGS_H
29 #define _LNET_NIDSTRINGS_H
30 #include <lnet/types.h>
31
32 /**
33  *  Lustre Network Driver types.
34  */
35 enum {
36         /* Only add to these values (i.e. don't ever change or redefine them):
37          * network addresses depend on them... */
38         QSWLND          = 1,
39         SOCKLND         = 2,
40         GMLND           = 3,
41         PTLLND          = 4,
42         O2IBLND         = 5,
43         CIBLND          = 6,
44         OPENIBLND       = 7,
45         IIBLND          = 8,
46         LOLND           = 9,
47         RALND           = 10,
48         VIBLND          = 11,
49         MXLND           = 12,
50         GNILND          = 13,
51         GNIIPLND        = 14,
52         PTL4LND         = 15,
53 };
54
55 struct list_head;
56
57 #define LNET_NIDSTR_COUNT 1024  /* # of nidstrings */
58 #define LNET_NIDSTR_SIZE  32    /* size of each one (see below for usage) */
59
60 /* support decl needed by both kernel and user space */
61 char *libcfs_next_nidstring(void);
62 int libcfs_isknown_lnd(__u32 lnd);
63 char *libcfs_lnd2modname(__u32 lnd);
64 char *libcfs_lnd2str_r(__u32 lnd, char *buf, size_t buf_size);
65 static inline char *libcfs_lnd2str(__u32 lnd)
66 {
67         return libcfs_lnd2str_r(lnd, libcfs_next_nidstring(),
68                                 LNET_NIDSTR_SIZE);
69 }
70 int libcfs_str2lnd(const char *str);
71 char *libcfs_net2str_r(__u32 net, char *buf, size_t buf_size);
72 static inline char *libcfs_net2str(__u32 net)
73 {
74         return libcfs_net2str_r(net, libcfs_next_nidstring(),
75                                 LNET_NIDSTR_SIZE);
76 }
77 char *libcfs_nid2str_r(lnet_nid_t nid, char *buf, size_t buf_size);
78 static inline char *libcfs_nid2str(lnet_nid_t nid)
79 {
80         return libcfs_nid2str_r(nid, libcfs_next_nidstring(),
81                                 LNET_NIDSTR_SIZE);
82 }
83 __u32 libcfs_str2net(const char *str);
84 lnet_nid_t libcfs_str2nid(const char *str);
85 int libcfs_str2anynid(lnet_nid_t *nid, const char *str);
86 char *libcfs_id2str(lnet_process_id_t id);
87 void cfs_free_nidlist(struct list_head *list);
88 int cfs_parse_nidlist(char *str, int len, struct list_head *list);
89 int cfs_print_nidlist(char *buffer, int count, struct list_head *list);
90 int cfs_match_nid(lnet_nid_t nid, struct list_head *list);
91
92 int cfs_ip_addr_parse(char *str, int len, struct list_head *list);
93 int cfs_ip_addr_match(__u32 addr, struct list_head *list);
94 bool cfs_nidrange_is_contiguous(struct list_head *nidlist);
95 void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
96                                char *max_nid, size_t nidstr_length);
97
98 struct netstrfns {
99         __u32   nf_type;
100         char    *nf_name;
101         char    *nf_modname;
102         void    (*nf_addr2str)(__u32 addr, char *str, size_t size);
103         int     (*nf_str2addr)(const char *str, int nob, __u32 *addr);
104         int     (*nf_parse_addrlist)(char *str, int len,
105                                      struct list_head *list);
106         int     (*nf_print_addrlist)(char *buffer, int count,
107                                      struct list_head *list);
108         int     (*nf_match_addr)(__u32 addr, struct list_head *list);
109         bool    (*nf_is_contiguous)(struct list_head *nidlist);
110         void    (*nf_min_max)(struct list_head *nidlist, __u32 *min_nid,
111                               __u32 *max_nid);
112 };
113
114 #endif /* _LNET_NIDSTRINGS_H */