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