Whamcloud - gitweb
LU-9680 utils: fix Netlink / YAML library handling
[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 <errno.h>
31 #include <net/if.h>
32 #include <stdbool.h>
33 #include <sys/socket.h>
34 #include <yaml.h>
35 #include <netlink/netlink.h>
36 #include <netlink/genl/genl.h>
37 #include <netlink/genl/ctrl.h>
38
39 #include <libcfs/util/ioctl.h>
40 #include <libcfs/util/string.h>
41 #include <linux/lnet/lnet-dlc.h>
42 #include <linux/lnet/nidstr.h>
43
44 #define LUSTRE_CFG_RC_NO_ERR                     0
45 #define LUSTRE_CFG_RC_BAD_PARAM                 -1
46 #define LUSTRE_CFG_RC_MISSING_PARAM             -2
47 #define LUSTRE_CFG_RC_OUT_OF_RANGE_PARAM        -3
48 #define LUSTRE_CFG_RC_OUT_OF_MEM                -4
49 #define LUSTRE_CFG_RC_GENERIC_ERR               -5
50 #define LUSTRE_CFG_RC_NO_MATCH                  -6
51 #define LUSTRE_CFG_RC_MATCH                     -7
52 #define LUSTRE_CFG_RC_SKIP                      -8
53 #define LUSTRE_CFG_RC_LAST_ELEM                 -9
54 #define LUSTRE_CFG_RC_MARSHAL_FAIL              -10
55
56 #define CONFIG_CMD              "configure"
57 #define UNCONFIG_CMD            "unconfigure"
58 #define ADD_CMD                 "add"
59 #define DEL_CMD                 "del"
60 #define SHOW_CMD                "show"
61 #define DBG_CMD                 "dbg"
62 #define MANAGE_CMD              "manage"
63
64 #define MAX_NUM_IPS             128
65
66 #define modparam_path "/sys/module/lnet/parameters/"
67 #define o2ib_modparam_path "/sys/module/ko2iblnd/parameters/"
68 #define gni_nid_path "/proc/cray_xt/"
69
70 enum lnetctl_cmd {
71         LNETCTL_CONFIG_CMD      = 1,
72         LNETCTL_UNCONFIG_CMD    = 2,
73         LNETCTL_ADD_CMD         = 3,
74         LNETCTL_DEL_CMD         = 4,
75         LNETCTL_SHOW_CMD        = 5,
76         LNETCTL_DBG_CMD         = 6,
77         LNETCTL_MANAGE_CMD      = 7,
78         LNETCTL_LAST_CMD
79 };
80
81 /*
82  * Max number of nids we'll configure for a single peer via a single DLC
83  * operation
84  */
85 #define LNET_MAX_NIDS_PER_PEER 128
86
87 struct lnet_dlc_network_descr {
88         struct list_head network_on_rule;
89         __u32 nw_id;
90         struct list_head nw_intflist;
91 };
92
93 struct lnet_dlc_intf_descr {
94         struct list_head intf_on_network;
95         char intf_name[IFNAMSIZ];
96         struct cfs_expr_list *cpt_expr;
97 };
98
99 /* This UDSP structures need to match the kernel space structures
100  * in order for the marshall and unmarshall functions to be the same.
101  */
102
103 /* Net is described as a
104  *  1. net type
105  *  2. num range
106  */
107 struct lnet_ud_net_descr {
108         __u32 udn_net_type;
109         struct list_head udn_net_num_range;
110 };
111
112 /* each NID range is defined as
113  *  1. net descriptor
114  *  2. address range descriptor
115  */
116 struct lnet_ud_nid_descr {
117         struct lnet_ud_net_descr ud_net_id;
118         struct list_head ud_addr_range;
119 };
120
121 /* a UDSP rule can have up to three user defined NID descriptors
122  *      - src: defines the local NID range for the rule
123  *      - dst: defines the peer NID range for the rule
124  *      - rte: defines the router NID range for the rule
125  *
126  * An action union defines the action to take when the rule
127  * is matched
128  */
129 struct lnet_udsp {
130         struct list_head udsp_on_list;
131         __u32 udsp_idx;
132         struct lnet_ud_nid_descr udsp_src;
133         struct lnet_ud_nid_descr udsp_dst;
134         struct lnet_ud_nid_descr udsp_rte;
135         enum lnet_udsp_action_type udsp_action_type;
136         union {
137                 __u32 udsp_priority;
138         } udsp_action;
139 };
140
141 /* This union is passed from lnetctl to fill the action union in udsp
142  * structure
143  * TODO: The idea here is if we add extra actions, ex: drop, it can be
144  * added to the union
145  */
146 union lnet_udsp_action {
147         int udsp_priority;
148 };
149
150 /* forward declaration of the cYAML structure. */
151 struct cYAML;
152
153 /*
154  * lustre_lnet_config_lib_init()
155  *   Initialize the Library to enable communication with the LNET kernel
156  *   module.  Returns the device ID or -EINVAL if there is an error
157  */
158 int lustre_lnet_config_lib_init();
159
160 /*
161  * lustre_lnet_config_lib_uninit
162  *      Uninitialize the DLC Library
163  */
164 void lustre_lnet_config_lib_uninit();
165
166 /*
167  * lustre_lnet_config_ni_system
168  *   Initialize/Uninitialize the lnet NI system.
169  *
170  *   up - whehter to init or uninit the system
171  *   load_ni_from_mod - load NI from mod params.
172  *   seq_no - sequence number of the request
173  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
174  *            caller
175  */
176 int lustre_lnet_config_ni_system(bool up, bool load_ni_from_mod,
177                                  int seq_no, struct cYAML **err_rc);
178
179 /*
180  * lustre_lnet_config_route
181  *   Send down an IOCTL to the kernel to configure the route
182  *
183  *   nw - network
184  *   gw - gateway
185  *   hops - number of hops passed down by the user
186  *   prio - priority of the route
187  *   sen - health sensitivity value for the gateway
188  *   seq_no - sequence number of the request
189  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
190  */
191 int lustre_lnet_config_route(char *nw, char *gw, int hops, int prio,
192                              int sen, int seq_no, struct cYAML **err_rc);
193
194 /*
195  * lustre_lnet_del_route
196  *   Send down an IOCTL to the kernel to delete a route
197  *
198  *   nw - network
199  *   gw - gateway
200  *   seq_no - sequence number of the request
201  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
202  */
203 int lustre_lnet_del_route(char *nw, char *gw, int seq_no,
204                           struct cYAML **err_rc);
205
206 /*
207  * lustre_lnet_show_route
208  *   Send down an IOCTL to the kernel to show routes
209  *   This function will get one route at a time and filter according to
210  *   provided parameters. If no routes are available then it will dump all
211  *   routes that are in the system.
212  *
213  *   nw - network.  Optional.  Used to filter output
214  *   gw - gateway. Optional. Used to filter ouptut
215  *   hops - number of hops passed down by the user
216  *          Optional.  Used to filter output.
217  *   prio - priority of the route.  Optional.  Used to filter output.
218  *   detail - flag to indicate whether detail output is required
219  *   seq_no - sequence number of the request
220  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
221  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
222  *   backup - true to output only what's necessary for reconfiguring
223  *            a node.
224  */
225 int lustre_lnet_show_route(char *nw, char *gw,
226                            int hops, int prio, int detail,
227                            int seq_no, struct cYAML **show_rc,
228                            struct cYAML **err_rc, bool backup);
229
230 /*
231  * lustre_lnet_config_ni
232  *   Send down an IOCTL to configure a network interface. It implicitly
233  *   creates a network if one doesn't exist..
234  *
235  *   nw_descr - network and interface descriptor
236  *   global_cpts - globally defined CPTs
237  *   ip2net - this parameter allows configuring multiple networks.
238  *      it takes precedence over the net and intf parameters
239  *   tunables - LND tunables
240  *   seq_no - sequence number of the request
241  *   lnd_tunables - lnet specific tunable parameters
242  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
243  */
244 int lustre_lnet_config_ni(struct lnet_dlc_network_descr *nw_descr,
245                           struct cfs_expr_list *global_cpts,
246                           char *ip2net,
247                           struct lnet_ioctl_config_lnd_tunables *tunables,
248                           long int cpp, int seq_no, struct cYAML **err_rc);
249
250 /*
251  * lustre_lnet_del_ni
252  *   Send down an IOCTL to delete a network interface. It implicitly
253  *   deletes a network if it becomes empty of nis
254  *
255  *   nw  - network and interface list
256  *   seq_no - sequence number of the request
257  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
258  */
259 int lustre_lnet_del_ni(struct lnet_dlc_network_descr *nw,
260                        int seq_no, struct cYAML **err_rc);
261
262 /*
263  * lustre_lnet_show_net
264  *   Send down an IOCTL to show networks.
265  *   This function will use the nw paramter to filter the output.  If it's
266  *   not provided then all networks are listed.
267  *
268  *   nw - network to show.  Optional.  Used to filter output.
269  *   detail - flag to indicate if we require detail output.
270  *   seq_no - sequence number of the request
271  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
272  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
273  *   backup - true to output only what's necessary for reconfiguring
274  *            a node.
275  */
276 int lustre_lnet_show_net(char *nw, int detail, int seq_no,
277                          struct cYAML **show_rc, struct cYAML **err_rc,
278                          bool backup);
279
280 /*
281  * lustre_lnet_enable_routing
282  *   Send down an IOCTL to enable or diable routing
283  *
284  *   enable - 1 to enable routing, 0 to disable routing
285  *   seq_no - sequence number of the request
286  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
287  */
288 int lustre_lnet_enable_routing(int enable, int seq_no,
289                                struct cYAML **err_rc);
290
291 /*
292  * lustre_lnet_config_numa_range
293  *   Set the NUMA range which impacts the NIs to be selected
294  *   during sending. If the NUMA range is large the NUMA
295  *   distance between the message memory and the NI becomes
296  *   less significant. The NUMA range is a relative number
297  *   with no other meaning besides allowing a wider breadth
298  *   for picking an NI to send from.
299  *
300  *   range - numa range value.
301  *   seq_no - sequence number of the request
302  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
303  *   caller
304  */
305 int lustre_lnet_config_numa_range(int range, int seq_no,
306                                   struct cYAML **err_rc);
307
308 /*
309  * lustre_lnet_show_num_range
310  *   Get the currently set NUMA range
311  *
312  *   seq_no - sequence number of the request
313  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
314  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
315  *   caller
316  */
317 int lustre_lnet_show_numa_range(int seq_no, struct cYAML **show_rc,
318                                 struct cYAML **err_rc);
319
320 /*
321  * lustre_lnet_config_ni_healthv
322  *   set the health value of the NI. -1 resets the value to maximum.
323  *
324  *   value: health value to set.
325  *   all: true to set all local NIs to that value.
326  *   ni_nid: NI NID to set its health value. all parameter always takes
327  *   precedence
328  *   seq_no - sequence number of the request
329  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
330  *   caller
331  */
332 int lustre_lnet_config_ni_healthv(int value, bool all, char *ni_nid,
333                                   int seq_no, struct cYAML **err_rc);
334
335
336 /* lustre_lnet_config_ni_conns_per_peer
337  *   set the conns_per_peer value of the NI. Valid range is specific to
338  *   network type.
339  *
340  *   value: conns_per_peer value to set.
341  *   all: true to set all local NIs to that value.
342  *   ni_nid: NI NID to set its conns_per_peer value. 'all' parameter always
343  *   takes precedence
344  *   seq_no - sequence number of the request
345  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
346  *   caller
347  */
348 int lustre_lnet_config_ni_conns_per_peer(int value, bool all, char *ni_nid,
349                                          int seq_no, struct cYAML **err_rc);
350
351 /*
352  * lustre_lnet_config_peer_ni_healthv
353  *   set the health value of the peer NI. -1 resets the value to maximum.
354  *
355  *   value: health value to set.
356  *   all: true to set all local NIs to that value.
357  *   pni_nid: Peer NI NID to set its health value. all parameter always takes
358  *   precedence
359  *   seq_no - sequence number of the request
360  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
361  *   caller
362  */
363 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *pni_nid,
364                                        int seq_no, struct cYAML **err_rc);
365
366 /*
367  * lustre_lnet_config_recov_intrv
368  *   set the recovery interval in seconds. That's the interval to ping an
369  *   unhealthy interface.
370  *
371  *   intrv - recovery interval value to configure
372  *   seq_no - sequence number of the request
373  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
374  *   caller
375  */
376 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc);
377
378 /*
379  * lustre_lnet_show_recov_intrv
380  *    show the recovery interval set in the system
381  *
382  *   seq_no - sequence number of the request
383  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
384  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
385  *   caller
386  */
387 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
388                                  struct cYAML **err_rc);
389
390 /*
391  * lustre_lnet_config_rtr_sensitivity
392  *   sets the router sensitivity percentage. If the percentage health
393  *   of a router interface drops below that it's considered failed
394  *
395  *   sen - sensitivity value to configure
396  *   seq_no - sequence number of the request
397  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
398  *   caller
399  */
400 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc);
401
402 /*
403  * lustre_lnet_config_hsensitivity
404  *   sets the health sensitivity; the value by which to decrement the
405  *   health value of a local or peer NI. If 0 then health is turned off
406  *
407  *   sen - sensitivity value to configure
408  *   seq_no - sequence number of the request
409  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
410  *   caller
411  */
412 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc);
413
414 /*
415  * lustre_lnet_show_hsensitivity
416  *    show the health sensitivity in the system
417  *
418  *   seq_no - sequence number of the request
419  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
420  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
421  *   caller
422  */
423 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
424                                   struct cYAML **err_rc);
425
426 /*
427  * lustre_lnet_show_rtr_sensitivity
428  *    show the router sensitivity percentage in the system
429  *
430  *   seq_no - sequence number of the request
431  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
432  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
433  *   caller
434  */
435 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
436                                      struct cYAML **err_rc);
437
438 /*
439  * lustre_lnet_config_transaction_to
440  *   sets the timeout after which a message expires or a timeout event is
441  *   propagated for an expired response.
442  *
443  *   timeout - timeout value to configure
444  *   seq_no - sequence number of the request
445  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
446  *   caller
447  */
448 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc);
449
450 /*
451  * lustre_lnet_show_transaction_to
452  *    show the transaction timeout in the system
453  *
454  *   seq_no - sequence number of the request
455  *   show_rc - [OUT] struct cYAML tree containing transaction timeout info
456  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
457  *   caller
458  */
459 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
460                                     struct cYAML **err_rc);
461
462 /*
463  * lustre_lnet_config_retry_count
464  *   sets the maximum number of retries to resend a message
465  *
466  *   count - maximum value to configure
467  *   seq_no - sequence number of the request
468  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
469  *   caller
470  */
471 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc);
472
473 /*
474  * lustre_lnet_show_retry_count
475  *    show current maximum number of retries in the system
476  *
477  *   seq_no - sequence number of the request
478  *   show_rc - [OUT] struct cYAML tree containing retry count info
479  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
480  *   caller
481  */
482 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
483                                  struct cYAML **err_rc);
484
485 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
486                                  struct cYAML **err_rc);
487
488 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
489                                      struct cYAML **err_rc);
490
491 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
492                                     struct cYAML **err_rc);
493 int lustre_lnet_config_response_tracking(int count, int seq_no,
494                                          struct cYAML **err_rc);
495 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
496                                        struct cYAML **err_rc);
497 int lustre_lnet_config_recovery_limit(int val, int seq_no,
498                                       struct cYAML **err_rc);
499 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
500                                     struct cYAML **err_rc);
501 int lustre_lnet_show_max_recovery_ping_interval(int seq_no,
502                                                 struct cYAML **show_rc,
503                                                 struct cYAML **err_rc);
504
505 /*
506  * lustre_lnet_config_max_intf
507  *   Sets the maximum number of interfaces per node. this tunable is
508  *   primarily useful for sanity checks prior to allocating memory.
509  *
510  *   max - maximum value to configure
511  *   seq_no - sequence number of the request
512  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
513  *   caller
514  */
515 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc);
516
517 /*
518  * lustre_lnet_show_max_intf
519  *    show current maximum interface setting
520  *
521  *   seq_no - sequence number of the request
522  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
523  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
524  *   caller
525  */
526 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
527                               struct cYAML **err_rc);
528
529 /*
530  * lustre_lnet_calc_service_id
531  *    Calculate the lustre service id to be used for qos
532  */
533 int lustre_lnet_calc_service_id(__u64 *service_id);
534
535 /*
536  * lustre_lnet_setup_mrrouting
537  *    configure linux routing tables for tcp interfaces
538  *
539  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
540  *   caller
541  */
542 int lustre_lnet_setup_mrrouting(struct cYAML **err_rc);
543
544 /*
545  * lustre_lnet_calc_cpt_of_nid
546  *      Return the cpt number of the NID provided
547  */
548 int lustre_lnet_calc_cpt_of_nid(char *nidc, long int ncpts);
549
550 /*
551  * lustre_lnet_config_discovery
552  *   Enable or disable peer discovery. Peer discovery is enabled by default.
553  *
554  *   enable - non-0 enables, 0 disables
555  *   seq_no - sequence number of the request
556  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
557  *   caller
558  */
559 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc);
560
561 /*
562  * lustre_lnet_show_discovery
563  *    show current peer discovery setting
564  *
565  *   seq_no - sequence number of the request
566  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
567  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
568  *   caller
569  */
570 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
571                                struct cYAML **err_rc);
572
573 /*
574  * lustre_lnet_config_drop_asym_route
575  *   Drop or accept asymmetrical route messages. Accept by default.
576  *
577  *   drop - non-0 drops, 0 accepts
578  *   seq_no - sequence number of the request
579  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
580  *   caller
581  */
582 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
583                                        struct cYAML **err_rc);
584
585 /*
586  * lustre_lnet_show_drop_asym_route
587  *    show current drop asym route setting
588  *
589  *   seq_no - sequence number of the request
590  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
591  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
592  *   caller
593  */
594 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
595                                      struct cYAML **err_rc);
596
597 /*
598  * lustre_lnet_config_buffers
599  *   Send down an IOCTL to configure routing buffer sizes.  A value of 0 means
600  *   default that particular buffer to default size. A value of -1 means
601  *   leave the value of the buffer un changed.
602  *
603  *   tiny - tiny buffers
604  *   small - small buffers
605  *   large - large buffers.
606  *   seq_no - sequence number of the request
607  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
608  */
609 int lustre_lnet_config_buffers(int tiny, int small, int large,
610                                int seq_no, struct cYAML **err_rc);
611
612 /*
613  * lustre_lnet_config_max_recovery_ping_interval
614  *   Set the maximum recovery ping interval.
615  *
616  *   interval - interval value in seconds
617  *   seq_no - sequence number of the request
618  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
619  */
620 int lustre_lnet_config_max_recovery_ping_interval(int interval, int seq_no,
621                                                   struct cYAML **err_rc);
622
623 /*
624  * lustre_lnet_show_routing
625  *   Send down an IOCTL to dump buffers and routing status
626  *   This function is used to dump buffers for all CPU partitions.
627  *
628  *   seq_no - sequence number of the request
629  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
630  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
631  *   backup - true to output only what's necessary for reconfiguring
632  *            a node.
633  */
634 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
635                              struct cYAML **err_rc, bool backup);
636
637 /*
638  * lustre_lnet_show_stats
639  *   Shows internal LNET statistics.  This is useful to display the
640  *   current LNET activity, such as number of messages route, etc
641  *
642  *     seq_no - sequence number of the command
643  *     show_rc - YAML structure of the resultant show
644  *     err_rc - YAML strucutre of the resultant return code.
645  */
646 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
647                            struct cYAML **err_rc);
648
649 /*
650  * lustre_lnet_reset_stats
651  *   Resets internal LNET statistics.
652  *
653  *     err_rc - YAML strucutre of the resultant return code.
654  */
655 int lustre_lnet_reset_stats(int seq_no, struct cYAML **err_rc);
656
657 /*
658  * lustre_lnet_modify_peer
659  *  Handle a peer config or delete operation.
660  *
661  *  Config Operation:
662  *  Add a peer NID to a peer with primary NID pnid. 
663  *  If the provided primary NID is unique, then a new peer is
664  *  created with this primary NID, and the NIDs in the NID list are added as
665  *  secondary NIDs to this new peer.
666  *  If any of the NIDs in the NID list are not unique then the operation
667  *  fails. Some peer NIDs might have already been added. It's the responsibility
668  *  of the caller of this API to remove the added NIDs if so desired.
669  *
670  *  Delete Operation:
671  *  Delete the NIDs given in the NID list from the peer with the primary NID
672  *  pnid. If pnid is NULL, or it doesn't identify a peer, the operation fails,
673  *  and no change happens to the system.
674  *  The operation is aborted on the first NID that fails to be deleted.
675  *
676  *      prim_nid - The desired primary NID of a new peer, or the primary NID of
677  *                 an existing peer.
678  *      nids - a comma separated string of nids
679  *      is_mr - Specifies whether this peer is MR capable.
680  *      cmd - CONFIG or DELETE
681  *      seq_no - sequence number of the command
682  *      err_rc - YAML structure of the resultant return code
683  */
684 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
685                             int cmd, int seq_no, struct cYAML **err_rc);
686
687 /*
688  * lustre_lnet_show_peer
689  *   Show the peer identified by nid, knid. If knid is NULL all
690  *   peers in the system are shown.
691  *
692  *     knid - A NID of the peer
693  *     detail - display detailed information
694  *     seq_no - sequence number of the command
695  *     show_rc - YAML structure of the resultant show
696  *     err_rc - YAML strucutre of the resultant return code.
697  *     backup - true to output only what's necessary for reconfiguring
698  *              a node.
699  *
700  */
701 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
702                           struct cYAML **show_rc, struct cYAML **err_rc,
703                           bool backup);
704
705 /*
706  * lustre_lnet_list_peer
707  *   List the known peers.
708  *
709  *     seq_no - sequence number of the command
710  *     show_rc - YAML structure of the resultant show
711  *     err_rc - YAML strucutre of the resultant return code.
712  *
713  */
714 int lustre_lnet_list_peer(int seq_no,
715                           struct cYAML **show_rc, struct cYAML **err_rc);
716
717 /* lustre_lnet_ping_nid
718  *   Ping the nid list, pnids.
719  *
720  *    pnids - NID list to ping.
721  *    src_nidstr - source NID
722  *    timeout - timeout(seconds) for ping.
723  *    seq_no - sequence number of the command.
724  *    show_rc - YAML structure of the resultant show.
725  *    err_rc - YAML strucutre of the resultant return code.
726  *
727  */
728 int lustre_lnet_ping_nid(char *pnid, char *src_nidstr, int timeout, int seq_no,
729                         struct cYAML **show_rc, struct cYAML **err_rc);
730
731 /* lustre_lnet_discover_nid
732  *   Discover the nid list, pnids.
733  *
734  *    pnids - NID list to discover.
735  *    force - force discovery.
736  *    seq_no - sequence number of the command.
737  *    show_rc - YAML structure of the resultant show.
738  *    err_rc - YAML strucutre of the resultant return code.
739  *
740  */
741 int lustre_lnet_discover_nid(char *pnid, int force, int seq_no,
742                              struct cYAML **show_rc, struct cYAML **err_rc);
743
744 /*
745  * lustre_yaml_config
746  *   Parses the provided YAML file and then calls the specific APIs
747  *   to configure the entities identified in the file
748  *
749  *   f - YAML file
750  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
751  */
752 int lustre_yaml_config(char *f, struct cYAML **err_rc);
753
754 /*
755  * lustre_yaml_del
756  *   Parses the provided YAML file and then calls the specific APIs
757  *   to delete the entities identified in the file
758  *
759  *   f - YAML file
760  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
761  */
762 int lustre_yaml_del(char *f, struct cYAML **err_rc);
763
764 /*
765  * lustre_yaml_show
766  *   Parses the provided YAML file and then calls the specific APIs
767  *   to show the entities identified in the file
768  *
769  *   f - YAML file
770  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
771  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
772  */
773 int lustre_yaml_show(char *f, struct cYAML **show_rc,
774                      struct cYAML **err_rc);
775
776 /*
777  * lustre_yaml_exec
778  *   Parses the provided YAML file and then calls the specific APIs
779  *   to execute the entities identified in the file
780  *
781  *   f - YAML file
782  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
783  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
784  */
785 int lustre_yaml_exec(char *f, struct cYAML **show_rc,
786                      struct cYAML **err_rc);
787
788 /**
789  * yaml_emitter_set_output_netlink
790  *
791  *   Special handling to integrate LNet handling into libyaml.
792  *   This function sets up the ability to take the data stored in @emitter
793  *   and formats into a netlink packet to send to the kernel.
794  *
795  *   emitter    - YAML emitter containing what the user specified
796  *   nl         - Netlink socket to be used by libyaml
797  *   family     - Netlink family
798  *   version    - notify kernel what version user land supports
799  *   cmd        - Netlink command to execute
800  *   flags      - Netlink flags
801  */
802 int yaml_emitter_set_output_netlink(yaml_emitter_t *emitter, struct nl_sock *nl,
803                                     char *family, int version, int cmd,
804                                     int flags);
805
806 /**
807  * yaml_parser_set_input_netlink
808  *
809  *   Special handling to LNet handling into libyaml.
810  *   This function sets up the ability to receive the Netlink data
811  *   from the Linux kernel. That data is formated into a YAML document.
812  *
813  *   parser     - YAML parser that is used to present the data received
814  *                from the kernel in Netlink format.
815  *   nl         - should be the Netlink socket receiving data from
816  *                the kernel.
817  *   stream     - Handle the case of continuous data coming in.
818  */
819 int yaml_parser_set_input_netlink(yaml_parser_t *parser, struct nl_sock *nl,
820                                   bool stream);
821
822 /**
823  * yaml_parser_get_reader_proto_version
824  *
825  *   This function retrieves the Neltink version the kernel module
826  *   is set to.
827  *
828  *   parser     - YAML parser being used for Netlink communication.
829  */
830 int yaml_parser_get_reader_proto_version(yaml_parser_t *parser);
831
832 /**
833  * yaml_parser_get_reader_error
834  *
835  *   By default libyaml reports a generic write error. We need a way
836  *   to report better parser errors so we can track down problems.
837  *
838  *   parser     - YAML parser that has reported an error.
839  */
840 const char *yaml_parser_get_reader_error(yaml_parser_t *parser);
841
842 /**
843  * yaml_parser_log_error
844  *
845  *   Helper function to report the parser error to @log.
846  *
847  *   parser     - YAML parser that has reported an error.
848  *   log        - file descriptor to write the error message out to.
849  *   errmsg     - Special extra string to append to error message.
850  */
851 void yaml_parser_log_error(yaml_parser_t *parser, FILE *log,
852                            const char *errmsg);
853
854 /**
855  * yaml_emitter_log_error
856  *
857  *   Helper function to report the emitter error to @log.
858  *
859  *   emitter    - YAML emitter that has reported an error.
860  *   log        - file descriptor to write the error message out to.
861  */
862 void yaml_emitter_log_error(yaml_emitter_t *emitter, FILE *log);
863
864
865 /*
866  * lustre_lnet_init_nw_descr
867  *      initialize the network descriptor structure for use
868  */
869 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr);
870
871 /*
872  * lustre_lnet_parse_interfaces
873  *      prase an interface string and populate descriptor structures
874  *              intf_str - interface string of the format
875  *                      <intf>[<expr>], <intf>[<expr>],..
876  *              nw_descr - network descriptor to populate
877  *              init - True to initialize nw_descr
878  */
879 int lustre_lnet_parse_interfaces(char *intf_str,
880                                  struct lnet_dlc_network_descr *nw_descr);
881
882 /*
883  * lustre_lnet_parse_nidstr
884  *     This is a small wrapper around cfs_parse_nidlist.
885  *         nidstr - A string parseable by cfs_parse_nidlist
886  *         lnet_nidlist - An array of lnet_nid_t to hold the nids specified
887  *                        by the nidstring.
888  *         max_nids - Size of the lnet_nidlist array, and the maximum number of
889  *                    nids that can be expressed by the nidstring. If the
890  *                    nidstring expands to a larger number of nids than max_nids
891  *                    then an error is returned.
892  *         err_str - char pointer where we store an informative error
893  *                   message when an error is encountered
894  *     Returns:
895  *         The number (> 0) of lnet_nid_t stored in the supplied array, or
896  *         LUSTRE_CFG_RC_BAD_PARAM if:
897  *           - nidstr is NULL
898  *           - nidstr contains an asterisk. This character is not allowed
899  *             because it would cause the size of the expanded nidlist to exceed
900  *             the maximum number of nids that is supported by expected callers
901  *             of this function.
902  *           - cfs_parse_nidlist fails to parse the nidstring
903  *           - The nidlist populated by cfs_parse_nidlist is empty
904  *           - The nidstring expands to a larger number of nids than max_nids
905  *           - The nidstring expands to zero nids
906  *         LUSTRE_CFG_RC_OUT_OF_MEM if:
907  *           - cfs_expand_nidlist can return ENOMEM. We return out of mem in
908  *             this case.
909  */
910 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
911                              int max_nids, char *err_str);
912
913 /* lustre_lnet_add_udsp
914  *      Add a selection policy.
915  *      src - source NID descriptor
916  *      dst - destination NID descriptor
917  *      rte - router NID descriptor
918  *      type - action type
919  *      action - union of the action
920  *      idx - the index to delete
921  *      seq_no - sequence number of the request
922  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
923  *               caller
924  */
925 int lustre_lnet_add_udsp(char *src, char *dst, char *rte, char *type,
926                          union lnet_udsp_action *action, int idx,
927                          int seq_no, struct cYAML **err_rc);
928
929 /* lustre_lnet_del_udsp
930  *      Delete a net selection policy.
931  *      idx - the index to delete
932  *      seq_no - sequence number of the request
933  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
934  *      caller
935  */
936 int lustre_lnet_del_udsp(unsigned int idx, int seq_no, struct cYAML **err_rc);
937
938 /* lustre_lnet_show_udsp
939  *      show selection policy.
940  *      idx - the index to show. -1 to show all policies
941  *      seq_no - sequence number of the request
942  *      err_rc - [IN/OUT] struct cYAML tree containing udsp info
943  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
944  *      caller
945  */
946 int lustre_lnet_show_udsp(int idx, int seq_no, struct cYAML **show_rc,
947                           struct cYAML **err_rc);
948
949 #endif /* LIB_LNET_CONFIG_API_H */