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