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