Whamcloud - gitweb
LU-12452 lnet: allow to set IP ToS value per-NI
[fs/lustre-release.git] / lnet / utils / lnetconfig / liblnetconfig_lnd.c
1 // SPDX-License-Identifier: LGPL-2.0
2
3 /*
4  * Copyright (c) 2015, James Simmons
5  *
6  * Copyright (c) 2016, 2017, Intel Corporation.
7  */
8
9 /*
10  * This file is part of Lustre, http://www.lustre.org/
11  *
12  * Author: James Simmons <jsimmons@infradead.org>
13  */
14
15 #include <limits.h>
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <libcfs/util/ioctl.h>
20 #include "liblnd.h"
21 #include "liblnetconfig.h"
22
23 static int
24 lustre_o2iblnd_show_tun(struct cYAML *lndparams,
25                         struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
26 {
27         if (cYAML_create_number(lndparams, "peercredits_hiw",
28                                 lnd_cfg->lnd_peercredits_hiw) == NULL)
29                 return LUSTRE_CFG_RC_OUT_OF_MEM;
30
31         if (cYAML_create_number(lndparams, "map_on_demand",
32                                 lnd_cfg->lnd_map_on_demand) == NULL)
33                 return LUSTRE_CFG_RC_OUT_OF_MEM;
34
35         if (cYAML_create_number(lndparams, "concurrent_sends",
36                                 lnd_cfg->lnd_concurrent_sends) == NULL)
37                 return LUSTRE_CFG_RC_OUT_OF_MEM;
38
39         if (cYAML_create_number(lndparams, "fmr_pool_size",
40                                 lnd_cfg->lnd_fmr_pool_size) == NULL)
41                 return LUSTRE_CFG_RC_OUT_OF_MEM;
42
43         if (cYAML_create_number(lndparams, "fmr_flush_trigger",
44                                 lnd_cfg->lnd_fmr_flush_trigger) == NULL)
45                 return LUSTRE_CFG_RC_OUT_OF_MEM;
46
47         if (cYAML_create_number(lndparams, "fmr_cache",
48                                 lnd_cfg->lnd_fmr_cache) == NULL)
49                 return LUSTRE_CFG_RC_OUT_OF_MEM;
50
51         if (cYAML_create_number(lndparams, "ntx",
52                                 lnd_cfg->lnd_ntx) == NULL)
53                 return LUSTRE_CFG_RC_OUT_OF_MEM;
54
55         if (cYAML_create_number(lndparams, "conns_per_peer",
56                                 lnd_cfg->lnd_conns_per_peer) == NULL)
57                 return LUSTRE_CFG_RC_OUT_OF_MEM;
58
59         if (cYAML_create_number(lndparams, "timeout",
60                                 lnd_cfg->lnd_timeout) == NULL)
61                 return LUSTRE_CFG_RC_OUT_OF_MEM;
62
63         if (cYAML_create_number(lndparams, "tos",
64                                 lnd_cfg->lnd_tos) == NULL)
65                 return LUSTRE_CFG_RC_OUT_OF_MEM;
66
67         return LUSTRE_CFG_RC_NO_ERR;
68 }
69
70
71 static int
72 lustre_socklnd_show_tun(struct cYAML *lndparams,
73                         struct lnet_ioctl_config_socklnd_tunables *lnd_cfg)
74 {
75         if (cYAML_create_number(lndparams, "conns_per_peer",
76                                 lnd_cfg->lnd_conns_per_peer) == NULL)
77                 return LUSTRE_CFG_RC_OUT_OF_MEM;
78
79         if (cYAML_create_number(lndparams, "timeout",
80                                 lnd_cfg->lnd_timeout) == NULL)
81                 return LUSTRE_CFG_RC_OUT_OF_MEM;
82
83         if (cYAML_create_number(lndparams, "tos",
84                                 lnd_cfg->lnd_tos) == NULL)
85                 return LUSTRE_CFG_RC_OUT_OF_MEM;
86
87         return LUSTRE_CFG_RC_NO_ERR;
88 }
89
90 #ifdef HAVE_KFILND
91 static int
92 lustre_kfilnd_show_tun(struct cYAML *lndparams,
93                        struct lnet_ioctl_config_kfilnd_tunables *lnd_cfg,
94                        bool backup)
95 {
96         if (cYAML_create_number(lndparams, "prov_major_version",
97                                 lnd_cfg->lnd_prov_major_version) == NULL)
98                 return LUSTRE_CFG_RC_OUT_OF_MEM;
99
100         if (cYAML_create_number(lndparams, "prov_minor_version",
101                                 lnd_cfg->lnd_prov_minor_version) == NULL)
102                 return LUSTRE_CFG_RC_OUT_OF_MEM;
103
104         if (cYAML_create_number(lndparams, "auth_key",
105                                 lnd_cfg->lnd_auth_key) == NULL)
106                 return LUSTRE_CFG_RC_OUT_OF_MEM;
107
108         if (cYAML_create_string(lndparams, "traffic_class",
109                                 lnd_cfg->lnd_traffic_class_str) == NULL)
110                 return LUSTRE_CFG_RC_OUT_OF_MEM;
111
112         if (!backup &&
113             cYAML_create_number(lndparams, "traffic_class_num",
114                                 lnd_cfg->lnd_traffic_class) == NULL)
115                 return LUSTRE_CFG_RC_OUT_OF_MEM;
116
117         return LUSTRE_CFG_RC_NO_ERR;
118 }
119 #endif
120
121 static int
122 lustre_gnilnd_show_tun(struct cYAML *lndparams,
123                         struct lnet_ioctl_config_gnilnd_tunables *lnd_cfg)
124 {
125         if (cYAML_create_number(lndparams, "timeout",
126                                 lnd_cfg->lnd_timeout) == NULL)
127                 return LUSTRE_CFG_RC_OUT_OF_MEM;
128
129         return LUSTRE_CFG_RC_NO_ERR;
130 }
131
132 int
133 lustre_net_show_tunables(struct cYAML *tunables,
134                          struct lnet_ioctl_config_lnd_cmn_tunables *cmn)
135 {
136         if (cYAML_create_number(tunables, "peer_timeout",
137                                 cmn->lct_peer_timeout)
138                                         == NULL)
139                 goto out;
140
141         if (cYAML_create_number(tunables, "peer_credits",
142                                 cmn->lct_peer_tx_credits)
143                                         == NULL)
144                 goto out;
145
146         if (cYAML_create_number(tunables,
147                                 "peer_buffer_credits",
148                                 cmn->lct_peer_rtr_credits)
149                                         == NULL)
150                 goto out;
151
152         if (cYAML_create_number(tunables, "credits",
153                                 cmn->lct_max_tx_credits)
154                                         == NULL)
155                 goto out;
156
157         return LUSTRE_CFG_RC_NO_ERR;
158
159 out:
160         return LUSTRE_CFG_RC_OUT_OF_MEM;
161 }
162
163 int
164 lustre_ni_show_tunables(struct cYAML *lnd_tunables,
165                         __u32 net_type,
166                         struct lnet_lnd_tunables *lnd,
167                         bool backup)
168 {
169         int rc = LUSTRE_CFG_RC_NO_MATCH;
170
171         if (net_type == O2IBLND)
172                 rc = lustre_o2iblnd_show_tun(lnd_tunables,
173                                              &lnd->lnd_tun_u.lnd_o2ib);
174         else if (net_type == SOCKLND)
175                 rc = lustre_socklnd_show_tun(lnd_tunables,
176                                              &lnd->lnd_tun_u.lnd_sock);
177 #ifdef HAVE_KFILND
178         else if (net_type == KFILND)
179                 rc = lustre_kfilnd_show_tun(lnd_tunables,
180                                             &lnd->lnd_tun_u.lnd_kfi,
181                                             backup);
182 #endif
183         else if (net_type == GNILND)
184                 rc = lustre_gnilnd_show_tun(lnd_tunables,
185                                             &lnd->lnd_tun_u.lnd_gni);
186         return rc;
187 }
188
189 static void
190 yaml_extract_o2ib_tun(struct cYAML *tree,
191                       struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
192 {
193         struct cYAML *map_on_demand = NULL, *concurrent_sends = NULL;
194         struct cYAML *fmr_pool_size = NULL, *fmr_cache = NULL;
195         struct cYAML *fmr_flush_trigger = NULL, *lndparams = NULL;
196         struct cYAML *conns_per_peer = NULL, *ntx = NULL;
197         struct cYAML *tos = NULL;
198
199         lndparams = cYAML_get_object_item(tree, "lnd tunables");
200         if (!lndparams)
201                 return;
202
203         map_on_demand = cYAML_get_object_item(lndparams, "map_on_demand");
204         lnd_cfg->lnd_map_on_demand =
205                 (map_on_demand) ? map_on_demand->cy_valueint : UINT_MAX;
206
207         concurrent_sends = cYAML_get_object_item(lndparams, "concurrent_sends");
208         lnd_cfg->lnd_concurrent_sends =
209                 (concurrent_sends) ? concurrent_sends->cy_valueint : 0;
210
211         fmr_pool_size = cYAML_get_object_item(lndparams, "fmr_pool_size");
212         lnd_cfg->lnd_fmr_pool_size =
213                 (fmr_pool_size) ? fmr_pool_size->cy_valueint : 0;
214
215         fmr_flush_trigger = cYAML_get_object_item(lndparams,
216                                                   "fmr_flush_trigger");
217         lnd_cfg->lnd_fmr_flush_trigger =
218                 (fmr_flush_trigger) ? fmr_flush_trigger->cy_valueint : 0;
219
220         fmr_cache = cYAML_get_object_item(lndparams, "fmr_cache");
221         lnd_cfg->lnd_fmr_cache =
222                 (fmr_cache) ? fmr_cache->cy_valueint : 0;
223
224         ntx = cYAML_get_object_item(lndparams, "ntx");
225         lnd_cfg->lnd_ntx = (ntx) ? ntx->cy_valueint : 0;
226
227         conns_per_peer = cYAML_get_object_item(lndparams, "conns_per_peer");
228         lnd_cfg->lnd_conns_per_peer =
229                 (conns_per_peer) ? conns_per_peer->cy_valueint : 1;
230
231         tos = cYAML_get_object_item(lndparams, "tos");
232         lnd_cfg->lnd_tos =
233                 (tos) ? tos->cy_valueint : -1;
234 }
235
236 #ifdef HAVE_KFILND
237 static void
238 yaml_extract_kfi_tun(struct cYAML *tree,
239                       struct lnet_ioctl_config_kfilnd_tunables *lnd_cfg)
240 {
241         struct cYAML *prov_major_version = NULL;
242         struct cYAML *prov_minor_version = NULL;
243         struct cYAML *auth_key = NULL;
244         struct cYAML *traffic_class = NULL;
245         struct cYAML *lndparams = NULL;
246
247         lndparams = cYAML_get_object_item(tree, "lnd tunables");
248         if (!lndparams)
249                 return;
250
251         prov_major_version =
252                 cYAML_get_object_item(lndparams, "prov_major_version");
253         lnd_cfg->lnd_prov_major_version =
254                 (prov_major_version) ? prov_major_version->cy_valueint : 0;
255
256         prov_minor_version =
257                 cYAML_get_object_item(lndparams, "prov_minor_version");
258         lnd_cfg->lnd_prov_minor_version =
259                 (prov_minor_version) ? prov_minor_version->cy_valueint : 0;
260
261         auth_key = cYAML_get_object_item(lndparams, "auth_key");
262         lnd_cfg->lnd_auth_key =
263                 (auth_key) ? auth_key->cy_valueint : 0;
264
265         traffic_class = cYAML_get_object_item(lndparams, "traffic_class");
266         if (traffic_class && traffic_class->cy_valuestring &&
267             strlen(traffic_class->cy_valuestring) < LNET_MAX_STR_LEN)
268                 strcpy(&lnd_cfg->lnd_traffic_class_str[0],
269                        traffic_class->cy_valuestring);
270 }
271 #endif
272
273 static void
274 yaml_extract_sock_tun(struct cYAML *tree,
275                          struct lnet_ioctl_config_socklnd_tunables *lnd_cfg)
276 {
277         struct cYAML *conns_per_peer = NULL;
278         struct cYAML *tos = NULL;
279         struct cYAML *lndparams = NULL;
280
281         lndparams = cYAML_get_object_item(tree, "lnd tunables");
282         if (!lndparams)
283                 return;
284
285         conns_per_peer = cYAML_get_object_item(lndparams, "conns_per_peer");
286         lnd_cfg->lnd_conns_per_peer =
287                 (conns_per_peer) ? conns_per_peer->cy_valueint : 1;
288
289         tos = cYAML_get_object_item(lndparams, "tos");
290         lnd_cfg->lnd_tos =
291                 (tos) ? tos->cy_valueint : -1;
292 }
293
294 void
295 lustre_yaml_extract_lnd_tunables(struct cYAML *tree,
296                                  __u32 net_type,
297                                  struct lnet_lnd_tunables *tun)
298 {
299         if (net_type == O2IBLND)
300                 yaml_extract_o2ib_tun(tree,
301                                       &tun->lnd_tun_u.lnd_o2ib);
302         else if (net_type == SOCKLND)
303                 yaml_extract_sock_tun(tree,
304                                       &tun->lnd_tun_u.lnd_sock);
305 #ifdef HAVE_KFILND
306         else if (net_type == KFILND)
307                 yaml_extract_kfi_tun(tree,
308                                      &tun->lnd_tun_u.lnd_kfi);
309 #endif
310 }
311