Whamcloud - gitweb
f2a193d95f5e549b2fd9a734bacd452b818aa9fa
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig.h
1 /*
2  * LGPL 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 Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of the
9  * License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * LGPL HEADER END
20  *
21  * Copyright (c) 2014, 2017, Intel Corporation.
22  *
23  * Author:
24  *   Amir Shehata <amir.shehata@intel.com>
25  */
26
27 #ifndef LIB_LNET_CONFIG_API_H
28 #define LIB_LNET_CONFIG_API_H
29
30 #include <libcfs/util/string.h>
31 #include <linux/lnet/lnet-dlc.h>
32 #include <linux/lnet/nidstr.h>
33
34 #define LUSTRE_CFG_RC_NO_ERR                     0
35 #define LUSTRE_CFG_RC_BAD_PARAM                 -1
36 #define LUSTRE_CFG_RC_MISSING_PARAM             -2
37 #define LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM        -3
38 #define LUSTRE_CFG_RC_OUT_OF_MEM                -4
39 #define LUSTRE_CFG_RC_GENERIC_ERR               -5
40 #define LUSTRE_CFG_RC_NO_MATCH                  -6
41 #define LUSTRE_CFG_RC_MATCH                     -7
42
43 struct lnet_dlc_network_descr {
44         struct list_head network_on_rule;
45         __u32 nw_id;
46         struct list_head nw_intflist;
47 };
48
49 struct lnet_dlc_intf_descr {
50         struct list_head intf_on_network;
51         char intf_name[LNET_MAX_STR_LEN];
52         struct cfs_expr_list *cpt_expr;
53 };
54
55 /* forward declaration of the cYAML structure. */
56 struct cYAML;
57
58 /*
59  * lustre_lnet_config_lib_init()
60  *   Initialize the Library to enable communication with the LNET kernel
61  *   module.  Returns the device ID or -EINVAL if there is an error
62  */
63 int lustre_lnet_config_lib_init();
64
65 /*
66  * lustre_lnet_config_lib_uninit
67  *      Uninitialize the DLC Library
68  */
69 void lustre_lnet_config_lib_uninit();
70
71 /*
72  * lustre_lnet_config_ni_system
73  *   Initialize/Uninitialize the lnet NI system.
74  *
75  *   up - whehter to init or uninit the system
76  *   load_ni_from_mod - load NI from mod params.
77  *   seq_no - sequence number of the request
78  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
79  *            caller
80  */
81 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
82                                  int seq_no, struct cYAML **err_rc);
83
84 /*
85  * lustre_lnet_config_route
86  *   Send down an IOCTL to the kernel to configure the route
87  *
88  *   nw - network
89  *   gw - gateway
90  *   hops - number of hops passed down by the user
91  *   prio - priority of the route
92  *   seq_no - sequence number of the request
93  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
94  */
95 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
96                              int seq_no, struct cYAML **err_rc);
97
98 /*
99  * lustre_lnet_del_route
100  *   Send down an IOCTL to the kernel to delete a route
101  *
102  *   nw - network
103  *   gw - gateway
104  *   seq_no - sequence number of the request
105  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
106  */
107 int lustre_lnet_del_route(char *nw, char *gw, int seq_no,
108                           struct cYAML **err_rc);
109
110 /*
111  * lustre_lnet_show_route
112  *   Send down an IOCTL to the kernel to show routes
113  *   This function will get one route at a time and filter according to
114  *   provided parameters. If no routes are available then it will dump all
115  *   routes that are in the system.
116  *
117  *   nw - network.  Optional.  Used to filter output
118  *   gw - gateway. Optional. Used to filter ouptut
119  *   hops - number of hops passed down by the user
120  *          Optional.  Used to filter output.
121  *   prio - priority of the route.  Optional.  Used to filter output.
122  *   detail - flag to indicate whether detail output is required
123  *   seq_no - sequence number of the request
124  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
125  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
126  */
127 int lustre_lnet_show_route(char *nw, char *gw,
128                            int hops, int prio, int detail,
129                            int seq_no, struct cYAML **show_rc,
130                            struct cYAML **err_rc);
131
132 /*
133  * lustre_lnet_config_ni
134  *   Send down an IOCTL to configure a network interface. It implicitly
135  *   creates a network if one doesn't exist..
136  *
137  *   nw_descr - network and interface descriptor
138  *   global_cpts - globally defined CPTs
139  *   ip2net - this parameter allows configuring multiple networks.
140  *      it takes precedence over the net and intf parameters
141  *   tunables - LND tunables
142  *   seq_no - sequence number of the request
143  *   lnd_tunables - lnet specific tunable parameters
144  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
145  */
146 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
147                           struct cfs_expr_list *global_cpts,
148                           char *ip2net,
149                           struct lnet_ioctl_config_lnd_tunables *tunables,
150                           int seq_no, struct cYAML **err_rc);
151
152 /*
153  * lustre_lnet_del_ni
154  *   Send down an IOCTL to delete a network interface. It implicitly
155  *   deletes a network if it becomes empty of nis
156  *
157  *   nw  - network and interface list
158  *   seq_no - sequence number of the request
159  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
160  */
161 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw,
162                        int seq_no, struct cYAML **err_rc);
163
164 /*
165  * lustre_lnet_show_net
166  *   Send down an IOCTL to show networks.
167  *   This function will use the nw paramter to filter the output.  If it's
168  *   not provided then all networks are listed.
169  *
170  *   nw - network to show.  Optional.  Used to filter output.
171  *   detail - flag to indicate if we require detail output.
172  *   seq_no - sequence number of the request
173  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
174  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
175  */
176 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
177                          struct cYAML **show_rc, struct cYAML **err_rc);
178
179 /*
180  * lustre_lnet_enable_routing
181  *   Send down an IOCTL to enable or diable routing
182  *
183  *   enable - 1 to enable routing, 0 to disable routing
184  *   seq_no - sequence number of the request
185  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
186  */
187 int lustre_lnet_enable_routing(int enable, int seq_no,
188                                struct cYAML **err_rc);
189
190 /*
191  * lustre_lnet_config_numa_range
192  *   Set the NUMA range which impacts the NIs to be selected
193  *   during sending. If the NUMA range is large the NUMA
194  *   distance between the message memory and the NI becomes
195  *   less significant. The NUMA range is a relative number
196  *   with no other meaning besides allowing a wider breadth
197  *   for picking an NI to send from.
198  *
199  *   range - numa range value.
200  *   seq_no - sequence number of the request
201  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
202  *   caller
203  */
204 int lustre_lnet_config_numa_range(int range, int seq_no,
205                                   struct cYAML **err_rc);
206
207 /*
208  * lustre_lnet_show_num_range
209  *   Get the currently set NUMA range
210  *
211  *   seq_no - sequence number of the request
212  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
213  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
214  *   caller
215  */
216 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
217                                 struct cYAML **err_rc);
218
219 /*
220  * lustre_lnet_config_max_intf
221  *   Sets the maximum number of interfaces per node. this tunable is
222  *   primarily useful for sanity checks prior to allocating memory.
223  *
224  *   max - maximum value to configure
225  *   seq_no - sequence number of the request
226  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
227  *   caller
228  */
229 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc);
230
231 /*
232  * lustre_lnet_show_max_intf
233  *    show current maximum interface setting
234  *
235  *   seq_no - sequence number of the request
236  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
237  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
238  *   caller
239  */
240 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
241                               struct cYAML **err_rc);
242
243 /*
244  * lustre_lnet_config_discovery
245  *   Enable or disable peer discovery. Peer discovery is enabled by default.
246  *
247  *   enable - non-0 enables, 0 disables
248  *   seq_no - sequence number of the request
249  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
250  *   caller
251  */
252 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc);
253
254 /*
255  * lustre_lnet_show_discovery
256  *    show current peer discovery setting
257  *
258  *   seq_no - sequence number of the request
259  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
260  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
261  *   caller
262  */
263 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
264                                struct cYAML **err_rc);
265
266 /*
267  * lustre_lnet_config_buffers
268  *   Send down an IOCTL to configure routing buffer sizes.  A value of 0 means
269  *   default that particular buffer to default size. A value of -1 means
270  *   leave the value of the buffer un changed.
271  *
272  *   tiny - tiny buffers
273  *   small - small buffers
274  *   large - large buffers.
275  *   seq_no - sequence number of the request
276  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
277  */
278 int lustre_lnet_config_buffers(int tiny, int small, int large,
279                                int seq_no, struct cYAML **err_rc);
280
281 /*
282  * lustre_lnet_show_routing
283  *   Send down an IOCTL to dump buffers and routing status
284  *   This function is used to dump buffers for all CPU partitions.
285  *
286  *   seq_no - sequence number of the request
287  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
288  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
289  */
290 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
291                              struct cYAML **err_rc);
292
293 /*
294  * lustre_lnet_show_stats
295  *   Shows internal LNET statistics.  This is useful to display the
296  *   current LNET activity, such as number of messages route, etc
297  *
298  *     seq_no - sequence number of the command
299  *     show_rc - YAML structure of the resultant show
300  *     err_rc - YAML strucutre of the resultant return code.
301  */
302 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
303                            struct cYAML **err_rc);
304
305 /*
306  * lustre_lnet_config_peer_nid
307  *   Add a peer nid to a peer with primary nid pnid. If no pnid is given
308  *   then the first nid in the nid list becomes the primary nid for
309  *   a newly created peer.
310  *   Otherwise if pnid is provided and it's unique then a new peer is
311  *   created with pnid as the primary NID and the nids in the nid list as
312  *   secondary nids.
313  *   If any of the peers nids provided in with exception to the pnid is
314  *   not unique the operation fails. Some peer nids might have already
315  *   been added. It's the role of the caller of this API to remove the
316  *   added NIDs if they wish.
317  *
318  *     pnid - Primary NID of the peer
319  *     nid - list of nids to add
320  *     num_nids - number of nids in the nid array
321  *     mr - true if this peer is MR capable.
322  *     seq_no - sequence number of the command
323  *     err_rc - YAML strucutre of the resultant return code.
324  */
325 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
326                                 bool mr, int seq_no, struct cYAML **err_rc);
327
328 /*
329  * lustre_lnet_del_peer_nid
330  *  Delete the nids given in the nid list from the peer with primary NID
331  *  pnid. If pnid is NULL or it doesn't identify a peer the operation
332  *  fails and no change happens to the system.
333  *  The operation is aborted on the first NID that fails to be deleted.
334  *
335  *     pnid - Primary NID of the peer
336  *     nid - list of nids to add
337  *     num_nids - number of nids in the nid array
338  *     seq_no - sequence number of the command
339  *     err_rc - YAML strucutre of the resultant return code.
340  */
341 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
342                              int seq_no, struct cYAML **err_rc);
343
344 /*
345  * lustre_lnet_show_peer
346  *   Show the peer identified by nid, knid. If knid is NULL all
347  *   peers in the system are shown.
348  *
349  *     knid - A NID of the peer
350  *     detail - display detailed information
351  *     seq_no - sequence number of the command
352  *     show_rc - YAML structure of the resultant show
353  *     err_rc - YAML strucutre of the resultant return code.
354  *
355  */
356 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
357                           struct cYAML **show_rc, struct cYAML **err_rc);
358
359 /*
360  * lustre_lnet_list_peer
361  *   List the known peers.
362  *
363  *     seq_no - sequence number of the command
364  *     show_rc - YAML structure of the resultant show
365  *     err_rc - YAML strucutre of the resultant return code.
366  *
367  */
368 int lustre_lnet_list_peer(int seq_no,
369                           struct cYAML **show_rc, struct cYAML **err_rc);
370
371 /* lustre_lnet_ping_nid
372  *   Ping the nid list, pnids.
373  *
374  *    pnids - NID list to ping.
375  *    timeout - timeout(seconds) for ping.
376  *    seq_no - sequence number of the command.
377  *    show_rc - YAML structure of the resultant show.
378  *    err_rc - YAML strucutre of the resultant return code.
379  *
380  */
381 int lustre_lnet_ping_nid(char *pnid, int timeout, int seq_no,
382                         struct cYAML **show_rc, struct cYAML **err_rc);
383
384 /* lustre_lnet_discover_nid
385  *   Discover the nid list, pnids.
386  *
387  *    pnids - NID list to discover.
388  *    force - force discovery.
389  *    seq_no - sequence number of the command.
390  *    show_rc - YAML structure of the resultant show.
391  *    err_rc - YAML strucutre of the resultant return code.
392  *
393  */
394 int lustre_lnet_discover_nid(char *pnid, int force, int seq_no,
395                              struct cYAML **show_rc, struct cYAML **err_rc);
396
397 /*
398  * lustre_yaml_config
399  *   Parses the provided YAML file and then calls the specific APIs
400  *   to configure the entities identified in the file
401  *
402  *   f - YAML file
403  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
404  */
405 int lustre_yaml_config(char *f, struct cYAML **err_rc);
406
407 /*
408  * lustre_yaml_del
409  *   Parses the provided YAML file and then calls the specific APIs
410  *   to delete the entities identified in the file
411  *
412  *   f - YAML file
413  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
414  */
415 int lustre_yaml_del(char *f, struct cYAML **err_rc);
416
417 /*
418  * lustre_yaml_show
419  *   Parses the provided YAML file and then calls the specific APIs
420  *   to show the entities identified in the file
421  *
422  *   f - YAML file
423  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
424  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
425  */
426 int lustre_yaml_show(char *f, struct cYAML **show_rc,
427                      struct cYAML **err_rc);
428
429 /*
430  * lustre_yaml_exec
431  *   Parses the provided YAML file and then calls the specific APIs
432  *   to execute the entities identified in the file
433  *
434  *   f - YAML file
435  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
436  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
437  */
438 int lustre_yaml_exec(char *f, struct cYAML **show_rc,
439                      struct cYAML **err_rc);
440
441 /*
442  * lustre_lnet_init_nw_descr
443  *      initialize the network descriptor structure for use
444  */
445 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr);
446
447 /*
448  * lustre_lnet_parse_interfaces
449  *      prase an interface string and populate descriptor structures
450  *              intf_str - interface string of the format
451  *                      <intf>[<expr>], <intf>[<expr>],..
452  *              nw_descr - network descriptor to populate
453  *              init - True to initialize nw_descr
454  */
455 int lustre_lnet_parse_interfaces(char *intf_str,
456                                  struct lnet_dlc_network_descr *nw_descr);
457
458 /*
459  * lustre_lnet_parse_nids
460  *      Parse a set of nids into a locally allocated array and return the
461  *      pointer of the array to the caller. The caller is responsible for
462  *      freeing the array. If an initial array is provided then copy over
463  *      the contents of that array into the new array and append to it the
464  *      new content.
465  *      The nids can be of the form "nid [,nid, nid, nid]"
466  *              nids: nids string to be parsed
467  *              array: initial array of content
468  *              size: num of elements in the array
469  *              out_array: [OUT] new allocated array.
470  *      Returns size of array
471  *              sets the out_array to NULL on failure.
472  */
473 int lustre_lnet_parse_nids(char *nids, char **array, int size,
474                            char ***out_array);
475
476 #endif /* LIB_LNET_CONFIG_API_H */