Whamcloud - gitweb
afe11b69b89c4f51289915b525858eb1d68525ca
[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                           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_peer_ni_healthv
337  *   set the health value of the peer NI. -1 resets the value to maximum.
338  *
339  *   value: health value to set.
340  *   all: true to set all local NIs to that value.
341  *   pni_nid: Peer NI NID to set its health value. all parameter always takes
342  *   precedence
343  *   seq_no - sequence number of the request
344  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
345  *   caller
346  */
347 int lustre_lnet_config_peer_ni_healthv(int value, bool all, char *pni_nid,
348                                        int seq_no, struct cYAML **err_rc);
349
350 /*
351  * lustre_lnet_config_recov_intrv
352  *   set the recovery interval in seconds. That's the interval to ping an
353  *   unhealthy interface.
354  *
355  *   intrv - recovery interval value to configure
356  *   seq_no - sequence number of the request
357  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
358  *   caller
359  */
360 int lustre_lnet_config_recov_intrv(int intrv, int seq_no, struct cYAML **err_rc);
361
362 /*
363  * lustre_lnet_show_recov_intrv
364  *    show the recovery interval set in the system
365  *
366  *   seq_no - sequence number of the request
367  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
368  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
369  *   caller
370  */
371 int lustre_lnet_show_recov_intrv(int seq_no, struct cYAML **show_rc,
372                                  struct cYAML **err_rc);
373
374 /*
375  * lustre_lnet_config_rtr_sensitivity
376  *   sets the router sensitivity percentage. If the percentage health
377  *   of a router interface drops below that it's considered failed
378  *
379  *   sen - sensitivity value to configure
380  *   seq_no - sequence number of the request
381  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
382  *   caller
383  */
384 int lustre_lnet_config_rtr_sensitivity(int sen, int seq_no, struct cYAML **err_rc);
385
386 /*
387  * lustre_lnet_config_hsensitivity
388  *   sets the health sensitivity; the value by which to decrement the
389  *   health value of a local or peer NI. If 0 then health is turned off
390  *
391  *   sen - sensitivity value to configure
392  *   seq_no - sequence number of the request
393  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
394  *   caller
395  */
396 int lustre_lnet_config_hsensitivity(int sen, int seq_no, struct cYAML **err_rc);
397
398 /*
399  * lustre_lnet_show_hsensitivity
400  *    show the health sensitivity in the system
401  *
402  *   seq_no - sequence number of the request
403  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
404  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
405  *   caller
406  */
407 int lustre_lnet_show_hsensitivity(int seq_no, struct cYAML **show_rc,
408                                   struct cYAML **err_rc);
409
410 /*
411  * lustre_lnet_show_rtr_sensitivity
412  *    show the router sensitivity percentage in the system
413  *
414  *   seq_no - sequence number of the request
415  *   show_rc - [OUT] struct cYAML tree containing health sensitivity info
416  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
417  *   caller
418  */
419 int lustre_lnet_show_rtr_sensitivity(int seq_no, struct cYAML **show_rc,
420                                      struct cYAML **err_rc);
421
422 /*
423  * lustre_lnet_config_transaction_to
424  *   sets the timeout after which a message expires or a timeout event is
425  *   propagated for an expired response.
426  *
427  *   timeout - timeout value to configure
428  *   seq_no - sequence number of the request
429  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
430  *   caller
431  */
432 int lustre_lnet_config_transaction_to(int timeout, int seq_no, struct cYAML **err_rc);
433
434 /*
435  * lustre_lnet_show_transaction_to
436  *    show the transaction timeout in the system
437  *
438  *   seq_no - sequence number of the request
439  *   show_rc - [OUT] struct cYAML tree containing transaction timeout info
440  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
441  *   caller
442  */
443 int lustre_lnet_show_transaction_to(int seq_no, struct cYAML **show_rc,
444                                     struct cYAML **err_rc);
445
446 /*
447  * lustre_lnet_config_retry_count
448  *   sets the maximum number of retries to resend a message
449  *
450  *   count - maximum value to configure
451  *   seq_no - sequence number of the request
452  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
453  *   caller
454  */
455 int lustre_lnet_config_retry_count(int count, int seq_no, struct cYAML **err_rc);
456
457 /*
458  * lustre_lnet_show_retry_count
459  *    show current maximum number of retries in the system
460  *
461  *   seq_no - sequence number of the request
462  *   show_rc - [OUT] struct cYAML tree containing retry count info
463  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
464  *   caller
465  */
466 int lustre_lnet_show_retry_count(int seq_no, struct cYAML **show_rc,
467                                  struct cYAML **err_rc);
468
469 int lustre_lnet_show_lnd_timeout(int seq_no, struct cYAML **show_rc,
470                                  struct cYAML **err_rc);
471
472 int lustre_lnet_show_local_ni_recovq(int seq_no, struct cYAML **show_rc,
473                                      struct cYAML **err_rc);
474
475 int lustre_lnet_show_peer_ni_recovq(int seq_no, struct cYAML **show_rc,
476                                     struct cYAML **err_rc);
477 int lustre_lnet_config_response_tracking(int count, int seq_no,
478                                          struct cYAML **err_rc);
479 int lustre_lnet_show_response_tracking(int seq_no, struct cYAML **show_rc,
480                                        struct cYAML **err_rc);
481 int lustre_lnet_config_recovery_limit(int val, int seq_no,
482                                       struct cYAML **err_rc);
483 int lustre_lnet_show_recovery_limit(int seq_no, struct cYAML **show_rc,
484                                     struct cYAML **err_rc);
485
486 /*
487  * lustre_lnet_config_max_intf
488  *   Sets the maximum number of interfaces per node. this tunable is
489  *   primarily useful for sanity checks prior to allocating memory.
490  *
491  *   max - maximum value to configure
492  *   seq_no - sequence number of the request
493  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
494  *   caller
495  */
496 int lustre_lnet_config_max_intf(int max, int seq_no, struct cYAML **err_rc);
497
498 /*
499  * lustre_lnet_show_max_intf
500  *    show current maximum interface setting
501  *
502  *   seq_no - sequence number of the request
503  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
504  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
505  *   caller
506  */
507 int lustre_lnet_show_max_intf(int seq_no, struct cYAML **show_rc,
508                               struct cYAML **err_rc);
509
510 /*
511  * lustre_lnet_calc_service_id
512  *    Calculate the lustre service id to be used for qos
513  */
514 int lustre_lnet_calc_service_id(__u64 *service_id);
515
516 /*
517  * lustre_lnet_config_discovery
518  *   Enable or disable peer discovery. Peer discovery is enabled by default.
519  *
520  *   enable - non-0 enables, 0 disables
521  *   seq_no - sequence number of the request
522  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
523  *   caller
524  */
525 int lustre_lnet_config_discovery(int enable, int seq_no, struct cYAML **err_rc);
526
527 /*
528  * lustre_lnet_show_discovery
529  *    show current peer discovery setting
530  *
531  *   seq_no - sequence number of the request
532  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
533  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
534  *   caller
535  */
536 int lustre_lnet_show_discovery(int seq_no, struct cYAML **show_rc,
537                                struct cYAML **err_rc);
538
539 /*
540  * lustre_lnet_config_drop_asym_route
541  *   Drop or accept asymmetrical route messages. Accept by default.
542  *
543  *   drop - non-0 drops, 0 accepts
544  *   seq_no - sequence number of the request
545  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
546  *   caller
547  */
548 int lustre_lnet_config_drop_asym_route(int drop, int seq_no,
549                                        struct cYAML **err_rc);
550
551 /*
552  * lustre_lnet_show_drop_asym_route
553  *    show current drop asym route setting
554  *
555  *   seq_no - sequence number of the request
556  *   show_rc - [OUT] struct cYAML tree containing NUMA range info
557  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by
558  *   caller
559  */
560 int lustre_lnet_show_drop_asym_route(int seq_no, struct cYAML **show_rc,
561                                      struct cYAML **err_rc);
562
563 /*
564  * lustre_lnet_config_buffers
565  *   Send down an IOCTL to configure routing buffer sizes.  A value of 0 means
566  *   default that particular buffer to default size. A value of -1 means
567  *   leave the value of the buffer un changed.
568  *
569  *   tiny - tiny buffers
570  *   small - small buffers
571  *   large - large buffers.
572  *   seq_no - sequence number of the request
573  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
574  */
575 int lustre_lnet_config_buffers(int tiny, int small, int large,
576                                int seq_no, struct cYAML **err_rc);
577
578 /*
579  * lustre_lnet_show_routing
580  *   Send down an IOCTL to dump buffers and routing status
581  *   This function is used to dump buffers for all CPU partitions.
582  *
583  *   seq_no - sequence number of the request
584  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
585  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
586  *   backup - true to output only what's necessary for reconfiguring
587  *            a node.
588  */
589 int lustre_lnet_show_routing(int seq_no, struct cYAML **show_rc,
590                              struct cYAML **err_rc, bool backup);
591
592 /*
593  * lustre_lnet_show_stats
594  *   Shows internal LNET statistics.  This is useful to display the
595  *   current LNET activity, such as number of messages route, etc
596  *
597  *     seq_no - sequence number of the command
598  *     show_rc - YAML structure of the resultant show
599  *     err_rc - YAML strucutre of the resultant return code.
600  */
601 int lustre_lnet_show_stats(int seq_no, struct cYAML **show_rc,
602                            struct cYAML **err_rc);
603
604 /*
605  * lustre_lnet_modify_peer
606  *  Handle a peer config or delete operation.
607  *
608  *  Config Operation:
609  *  Add a peer NID to a peer with primary NID pnid. 
610  *  If the provided primary NID is unique, then a new peer is
611  *  created with this primary NID, and the NIDs in the NID list are added as
612  *  secondary NIDs to this new peer.
613  *  If any of the NIDs in the NID list are not unique then the operation
614  *  fails. Some peer NIDs might have already been added. It's the responsibility
615  *  of the caller of this API to remove the added NIDs if so desired.
616  *
617  *  Delete Operation:
618  *  Delete the NIDs given in the NID list from the peer with the primary NID
619  *  pnid. If pnid is NULL, or it doesn't identify a peer, the operation fails,
620  *  and no change happens to the system.
621  *  The operation is aborted on the first NID that fails to be deleted.
622  *
623  *      prim_nid - The desired primary NID of a new peer, or the primary NID of
624  *                 an existing peer.
625  *      nids - a comma separated string of nids
626  *      is_mr - Specifies whether this peer is MR capable.
627  *      cmd - CONFIG or DELETE
628  *      seq_no - sequence number of the command
629  *      err_rc - YAML structure of the resultant return code
630  */
631 int lustre_lnet_modify_peer(char *prim_nid, char *nids, bool is_mr,
632                             int cmd, int seq_no, struct cYAML **err_rc);
633
634 /*
635  * lustre_lnet_show_peer
636  *   Show the peer identified by nid, knid. If knid is NULL all
637  *   peers in the system are shown.
638  *
639  *     knid - A NID of the peer
640  *     detail - display detailed information
641  *     seq_no - sequence number of the command
642  *     show_rc - YAML structure of the resultant show
643  *     err_rc - YAML strucutre of the resultant return code.
644  *     backup - true to output only what's necessary for reconfiguring
645  *              a node.
646  *
647  */
648 int lustre_lnet_show_peer(char *knid, int detail, int seq_no,
649                           struct cYAML **show_rc, struct cYAML **err_rc,
650                           bool backup);
651
652 /*
653  * lustre_lnet_list_peer
654  *   List the known peers.
655  *
656  *     seq_no - sequence number of the command
657  *     show_rc - YAML structure of the resultant show
658  *     err_rc - YAML strucutre of the resultant return code.
659  *
660  */
661 int lustre_lnet_list_peer(int seq_no,
662                           struct cYAML **show_rc, struct cYAML **err_rc);
663
664 /* lustre_lnet_ping_nid
665  *   Ping the nid list, pnids.
666  *
667  *    pnids - NID list to ping.
668  *    timeout - timeout(seconds) for ping.
669  *    seq_no - sequence number of the command.
670  *    show_rc - YAML structure of the resultant show.
671  *    err_rc - YAML strucutre of the resultant return code.
672  *
673  */
674 int lustre_lnet_ping_nid(char *pnid, int timeout, int seq_no,
675                         struct cYAML **show_rc, struct cYAML **err_rc);
676
677 /* lustre_lnet_discover_nid
678  *   Discover the nid list, pnids.
679  *
680  *    pnids - NID list to discover.
681  *    force - force discovery.
682  *    seq_no - sequence number of the command.
683  *    show_rc - YAML structure of the resultant show.
684  *    err_rc - YAML strucutre of the resultant return code.
685  *
686  */
687 int lustre_lnet_discover_nid(char *pnid, int force, int seq_no,
688                              struct cYAML **show_rc, struct cYAML **err_rc);
689
690 /*
691  * lustre_yaml_config
692  *   Parses the provided YAML file and then calls the specific APIs
693  *   to configure the entities identified in the file
694  *
695  *   f - YAML file
696  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
697  */
698 int lustre_yaml_config(char *f, struct cYAML **err_rc);
699
700 /*
701  * lustre_yaml_del
702  *   Parses the provided YAML file and then calls the specific APIs
703  *   to delete the entities identified in the file
704  *
705  *   f - YAML file
706  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
707  */
708 int lustre_yaml_del(char *f, struct cYAML **err_rc);
709
710 /*
711  * lustre_yaml_show
712  *   Parses the provided YAML file and then calls the specific APIs
713  *   to show the entities identified in the file
714  *
715  *   f - YAML file
716  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
717  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
718  */
719 int lustre_yaml_show(char *f, struct cYAML **show_rc,
720                      struct cYAML **err_rc);
721
722 /*
723  * lustre_yaml_exec
724  *   Parses the provided YAML file and then calls the specific APIs
725  *   to execute the entities identified in the file
726  *
727  *   f - YAML file
728  *   show_rc - [OUT] The show output in YAML.  Must be freed by caller.
729  *   err_rc - [OUT] struct cYAML tree describing the error. Freed by caller
730  */
731 int lustre_yaml_exec(char *f, struct cYAML **show_rc,
732                      struct cYAML **err_rc);
733
734 /**
735  * yaml_emitter_set_output_netlink
736  *
737  *   Special handling to integrate LNet handling into libyaml.
738  *   This function sets up the ability to take the data stored in @emitter
739  *   and formats into a netlink packet to send to the kernel.
740  *
741  *   emitter    - YAML emitter containing what the user specified
742  *   nl         - Netlink socket to be used by libyaml
743  *   family     - Netlink family
744  *   version    - notify kernel what version user land supports
745  *   cmd        - Netlink command to execute
746  *   flags      - Netlink flags
747  */
748 int yaml_emitter_set_output_netlink(yaml_emitter_t *emitter, struct nl_sock *nl,
749                                     char *family, int version, int cmd,
750                                     int flags);
751
752 /**
753  * yaml_parser_set_input_netlink
754  *
755  *   Special handling to LNet handling into libyaml.
756  *   This function sets up the ability to receive the Netlink data
757  *   from the Linux kernel. That data is formated into a YAML document.
758  *
759  *   parser     - YAML parser that is used to present the data received
760  *                from the kernel in Netlink format.
761  *   nl         - should be the Netlink socket receiving data from
762  *                the kernel.
763  *   stream     - Handle the case of continuous data coming in.
764  */
765 int yaml_parser_set_input_netlink(yaml_parser_t *parser, struct nl_sock *nl,
766                                   bool stream);
767
768 /**
769  * yaml_parser_get_reader_error
770  *
771  *   By default libyaml reports a generic write error. We need a way
772  *   to report better parser errors so we can track down problems.
773  *
774  *   parser     - YAML parser that has reported an error.
775  */
776 const char *yaml_parser_get_reader_error(yaml_parser_t *parser);
777
778 /**
779  * yaml_parser_log_error
780  *
781  *   Helper function to report the parser error to @log.
782  *
783  *   parser     - YAML parser that has reported an error.
784  *   log        - file descriptor to write the error message out to.
785  *   errmsg     - Special extra string to append to error message.
786  */
787 void yaml_parser_log_error(yaml_parser_t *parser, FILE *log,
788                            const char *errmsg);
789
790 /**
791  * yaml_emitter_log_error
792  *
793  *   Helper function to report the emitter error to @log.
794  *
795  *   emitter    - YAML emitter that has reported an error.
796  *   log        - file descriptor to write the error message out to.
797  */
798 void yaml_emitter_log_error(yaml_emitter_t *emitter, FILE *log);
799
800
801 /*
802  * lustre_lnet_init_nw_descr
803  *      initialize the network descriptor structure for use
804  */
805 void lustre_lnet_init_nw_descr(struct lnet_dlc_network_descr *nw_descr);
806
807 /*
808  * lustre_lnet_parse_interfaces
809  *      prase an interface string and populate descriptor structures
810  *              intf_str - interface string of the format
811  *                      <intf>[<expr>], <intf>[<expr>],..
812  *              nw_descr - network descriptor to populate
813  *              init - True to initialize nw_descr
814  */
815 int lustre_lnet_parse_interfaces(char *intf_str,
816                                  struct lnet_dlc_network_descr *nw_descr);
817
818 /*
819  * lustre_lnet_parse_nidstr
820  *     This is a small wrapper around cfs_parse_nidlist.
821  *         nidstr - A string parseable by cfs_parse_nidlist
822  *         lnet_nidlist - An array of lnet_nid_t to hold the nids specified
823  *                        by the nidstring.
824  *         max_nids - Size of the lnet_nidlist array, and the maximum number of
825  *                    nids that can be expressed by the nidstring. If the
826  *                    nidstring expands to a larger number of nids than max_nids
827  *                    then an error is returned.
828  *         err_str - char pointer where we store an informative error
829  *                   message when an error is encountered
830  *     Returns:
831  *         The number (> 0) of lnet_nid_t stored in the supplied array, or
832  *         LUSTRE_CFG_RC_BAD_PARAM if:
833  *           - nidstr is NULL
834  *           - nidstr contains an asterisk. This character is not allowed
835  *             because it would cause the size of the expanded nidlist to exceed
836  *             the maximum number of nids that is supported by expected callers
837  *             of this function.
838  *           - cfs_parse_nidlist fails to parse the nidstring
839  *           - The nidlist populated by cfs_parse_nidlist is empty
840  *           - The nidstring expands to a larger number of nids than max_nids
841  *           - The nidstring expands to zero nids
842  *         LUSTRE_CFG_RC_OUT_OF_MEM if:
843  *           - cfs_expand_nidlist can return ENOMEM. We return out of mem in
844  *             this case.
845  */
846 int lustre_lnet_parse_nidstr(char *nidstr, lnet_nid_t *lnet_nidlist,
847                              int max_nids, char *err_str);
848
849 /* lustre_lnet_add_udsp
850  *      Add a selection policy.
851  *      src - source NID descriptor
852  *      dst - destination NID descriptor
853  *      rte - router NID descriptor
854  *      type - action type
855  *      action - union of the action
856  *      idx - the index to delete
857  *      seq_no - sequence number of the request
858  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
859  *               caller
860  */
861 int lustre_lnet_add_udsp(char *src, char *dst, char *rte, char *type,
862                          union lnet_udsp_action *action, int idx,
863                          int seq_no, struct cYAML **err_rc);
864
865 /* lustre_lnet_del_udsp
866  *      Delete a net selection policy.
867  *      idx - the index to delete
868  *      seq_no - sequence number of the request
869  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
870  *      caller
871  */
872 int lustre_lnet_del_udsp(unsigned int idx, int seq_no, struct cYAML **err_rc);
873
874 /* lustre_lnet_show_udsp
875  *      show selection policy.
876  *      idx - the index to show. -1 to show all policies
877  *      seq_no - sequence number of the request
878  *      err_rc - [IN/OUT] struct cYAML tree containing udsp info
879  *      err_rc - [OUT] struct cYAML tree describing the error. Freed by
880  *      caller
881  */
882 int lustre_lnet_show_udsp(int idx, int seq_no, struct cYAML **show_rc,
883                           struct cYAML **err_rc);
884
885 #endif /* LIB_LNET_CONFIG_API_H */