Whamcloud - gitweb
LU-9480 lnet: configure lnet_interfaces_max tunable from dlc
[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, 2016, 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_buffers
245  *   Send down an IOCTL to configure routing buffer sizes.  A value of 0 means
246  *   default that particular buffer to default size. A value of -1 means
247  *   leave the value of the buffer un changed.
248  *
249  *   tiny - tiny buffers
250  *   small - small buffers
251  *   large - large buffers.
252  *   seq_no - sequence number of the request
253  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
254  */
255 int lustre_lnet_config_buffers(int tiny, int small, int large,
256                                int seq_no, struct cYAML **err_rc);
257
258 /*
259  * lustre_lnet_show_routing
260  *   Send down an IOCTL to dump buffers and routing status
261  *   This function is used to dump buffers for all CPU partitions.
262  *
263  *   seq_no - sequence number of the request
264  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
265  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
266  */
267 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
268                              struct cYAML **err_rc);
269
270 /*
271  * lustre_lnet_show_stats
272  *   Shows internal LNET statistics.  This is useful to display the
273  *   current LNET activity, such as number of messages route, etc
274  *
275  *     seq_no - sequence number of the command
276  *     show_rc - YAML structure of the resultant show
277  *     err_rc - YAML strucutre of the resultant return code.
278  */
279 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
280                            struct cYAML **err_rc);
281
282 /*
283  * lustre_lnet_config_peer_nid
284  *   Add a peer nid to a peer with primary nid pnid. If no pnid is given
285  *   then the first nid in the nid list becomes the primary nid for
286  *   a newly created peer.
287  *   Otherwise if pnid is provided and it's unique then a new peer is
288  *   created with pnid as the primary NID and the nids in the nid list as
289  *   secondary nids.
290  *   If any of the peers nids provided in with exception to the pnid is
291  *   not unique the operation fails. Some peer nids might have already
292  *   been added. It's the role of the caller of this API to remove the
293  *   added NIDs if they wish.
294  *
295  *     pnid - Primary NID of the peer
296  *     nid - list of nids to add
297  *     num_nids - number of nids in the nid array
298  *     mr - true if this peer is MR capable.
299  *     seq_no - sequence number of the command
300  *     err_rc - YAML strucutre of the resultant return code.
301  */
302 int lustre_lnet_config_peer_nid(char *pnid, char **nid, int num_nids,
303                                 bool mr, int seq_no, struct cYAML **err_rc);
304
305 /*
306  * lustre_lnet_del_peer_nid
307  *  Delete the nids given in the nid list from the peer with primary NID
308  *  pnid. If pnid is NULL or it doesn't identify a peer the operation
309  *  fails and no change happens to the system.
310  *  The operation is aborted on the first NID that fails to be deleted.
311  *
312  *     pnid - Primary NID of the peer
313  *     nid - list of nids to add
314  *     num_nids - number of nids in the nid array
315  *     seq_no - sequence number of the command
316  *     err_rc - YAML strucutre of the resultant return code.
317  */
318 int lustre_lnet_del_peer_nid(char *pnid, char **nid, int num_nids,
319                              int seq_no, struct cYAML **err_rc);
320
321 /*
322  * lustre_lnet_show_peer
323  *   Show the peer identified by nid, knid. If knid is NULL all
324  *   peers in the system are shown.
325  *
326  *     knid - A NID of the peer
327  *     detail - display detailed information
328  *     seq_no - sequence number of the command
329  *     show_rc - YAML structure of the resultant show
330  *     err_rc - YAML strucutre of the resultant return code.
331  *
332  */
333 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
334                           struct cYAML **show_rc, struct cYAML **err_rc);
335
336 /*
337  * lustre_yaml_config
338  *   Parses the provided YAML file and then calls the specific APIs
339  *   to configure the entities identified in the file
340  *
341  *   f - YAML file
342  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
343  */
344 int lustre_yaml_config(char *f, struct cYAML **err_rc);
345
346 /*
347  * lustre_yaml_del
348  *   Parses the provided YAML file and then calls the specific APIs
349  *   to delete the entities identified in the file
350  *
351  *   f - YAML file
352  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
353  */
354 int lustre_yaml_del(char *f, struct cYAML **err_rc);
355
356 /*
357  * lustre_yaml_show
358  *   Parses the provided YAML file and then calls the specific APIs
359  *   to show the entities identified in the file
360  *
361  *   f - YAML file
362  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
363  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
364  */
365 int lustre_yaml_show(char *f, struct cYAML **show_rc,
366                      struct cYAML **err_rc);
367
368 /*
369  * lustre_lnet_init_nw_descr
370  *      initialize the network descriptor structure for use
371  */
372 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr);
373
374 /*
375  * lustre_lnet_parse_interfaces
376  *      prase an interface string and populate descriptor structures
377  *              intf_str - interface string of the format
378  *                      <intf>[<expr>], <intf>[<expr>],..
379  *              nw_descr - network descriptor to populate
380  *              init - True to initialize nw_descr
381  */
382 int lustre_lnet_parse_interfaces(char *intf_str,
383                                  struct lnet_dlc_network_descr *nw_descr);
384
385 /*
386  * lustre_lnet_parse_nids
387  *      Parse a set of nids into a locally allocated array and return the
388  *      pointer of the array to the caller. The caller is responsible for
389  *      freeing the array. If an initial array is provided then copy over
390  *      the contents of that array into the new array and append to it the
391  *      new content.
392  *      The nids can be of the form "nid [,nid, nid, nid]"
393  *              nids: nids string to be parsed
394  *              array: initial array of content
395  *              size: num of elements in the array
396  *              out_array: [OUT] new allocated array.
397  *      Returns size of array
398  *              sets the out_array to NULL on failure.
399  */
400 int lustre_lnet_parse_nids(char *nids, char **array, int size,
401                            char ***out_array);
402
403 #endif /* LIB_LNET_CONFIG_API_H */