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