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