Whamcloud - gitweb
LU-16035 kfilnd: Initial kfilnd implementation
[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 static int
89 lustre_kfilnd_show_tun(struct cYAML *lndparams,
90                         struct lnet_ioctl_config_kfilnd_tunables *lnd_cfg)
91 {
92         if (cYAML_create_number(lndparams, "prov_major_version",
93                                 lnd_cfg->lnd_prov_major_version) == NULL)
94                 return LUSTRE_CFG_RC_OUT_OF_MEM;
95
96         if (cYAML_create_number(lndparams, "prov_minor_version",
97                                 lnd_cfg->lnd_prov_minor_version) == NULL)
98                 return LUSTRE_CFG_RC_OUT_OF_MEM;
99
100         if (cYAML_create_number(lndparams, "auth_key",
101                                 lnd_cfg->lnd_auth_key) == NULL)
102                 return LUSTRE_CFG_RC_OUT_OF_MEM;
103
104         return LUSTRE_CFG_RC_NO_ERR;
105 }
106
107 int
108 lustre_net_show_tunables(struct cYAML *tunables,
109                          struct lnet_ioctl_config_lnd_cmn_tunables *cmn)
110 {
111         if (cYAML_create_number(tunables, "peer_timeout",
112                                 cmn->lct_peer_timeout)
113                                         == NULL)
114                 goto out;
115
116         if (cYAML_create_number(tunables, "peer_credits",
117                                 cmn->lct_peer_tx_credits)
118                                         == NULL)
119                 goto out;
120
121         if (cYAML_create_number(tunables,
122                                 "peer_buffer_credits",
123                                 cmn->lct_peer_rtr_credits)
124                                         == NULL)
125                 goto out;
126
127         if (cYAML_create_number(tunables, "credits",
128                                 cmn->lct_max_tx_credits)
129                                         == NULL)
130                 goto out;
131
132         return LUSTRE_CFG_RC_NO_ERR;
133
134 out:
135         return LUSTRE_CFG_RC_OUT_OF_MEM;
136 }
137
138 int
139 lustre_ni_show_tunables(struct cYAML *lnd_tunables,
140                         __u32 net_type,
141                         struct lnet_lnd_tunables *lnd)
142 {
143         int rc = LUSTRE_CFG_RC_NO_MATCH;
144
145         if (net_type == O2IBLND)
146                 rc = lustre_o2iblnd_show_tun(lnd_tunables,
147                                              &lnd->lnd_tun_u.lnd_o2ib);
148         else if (net_type == SOCKLND)
149                 rc = lustre_socklnd_show_tun(lnd_tunables,
150                                              &lnd->lnd_tun_u.lnd_sock);
151         else if (net_type == KFILND)
152                 rc = lustre_kfilnd_show_tun(lnd_tunables,
153                                             &lnd->lnd_tun_u.lnd_kfi);
154
155         return rc;
156 }
157
158 static void
159 yaml_extract_o2ib_tun(struct cYAML *tree,
160                       struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
161 {
162         struct cYAML *map_on_demand = NULL, *concurrent_sends = NULL;
163         struct cYAML *fmr_pool_size = NULL, *fmr_cache = NULL;
164         struct cYAML *fmr_flush_trigger = NULL, *lndparams = NULL;
165         struct cYAML *conns_per_peer = NULL, *ntx = NULL;
166
167         lndparams = cYAML_get_object_item(tree, "lnd tunables");
168         if (!lndparams)
169                 return;
170
171         map_on_demand = cYAML_get_object_item(lndparams, "map_on_demand");
172         lnd_cfg->lnd_map_on_demand =
173                 (map_on_demand) ? map_on_demand->cy_valueint : UINT_MAX;
174
175         concurrent_sends = cYAML_get_object_item(lndparams, "concurrent_sends");
176         lnd_cfg->lnd_concurrent_sends =
177                 (concurrent_sends) ? concurrent_sends->cy_valueint : 0;
178
179         fmr_pool_size = cYAML_get_object_item(lndparams, "fmr_pool_size");
180         lnd_cfg->lnd_fmr_pool_size =
181                 (fmr_pool_size) ? fmr_pool_size->cy_valueint : 0;
182
183         fmr_flush_trigger = cYAML_get_object_item(lndparams,
184                                                   "fmr_flush_trigger");
185         lnd_cfg->lnd_fmr_flush_trigger =
186                 (fmr_flush_trigger) ? fmr_flush_trigger->cy_valueint : 0;
187
188         fmr_cache = cYAML_get_object_item(lndparams, "fmr_cache");
189         lnd_cfg->lnd_fmr_cache =
190                 (fmr_cache) ? fmr_cache->cy_valueint : 0;
191
192         ntx = cYAML_get_object_item(lndparams, "ntx");
193         lnd_cfg->lnd_ntx = (ntx) ? ntx->cy_valueint : 0;
194
195         conns_per_peer = cYAML_get_object_item(lndparams, "conns_per_peer");
196         lnd_cfg->lnd_conns_per_peer =
197                 (conns_per_peer) ? conns_per_peer->cy_valueint : 1;
198
199 }
200
201 static void
202 yaml_extract_kfi_tun(struct cYAML *tree,
203                       struct lnet_ioctl_config_kfilnd_tunables *lnd_cfg)
204 {
205         struct cYAML *prov_major_version = NULL;
206         struct cYAML *prov_minor_version = NULL;
207         struct cYAML *auth_key = NULL;
208         struct cYAML *lndparams = NULL;
209
210         lndparams = cYAML_get_object_item(tree, "lnd tunables");
211         if (!lndparams)
212                 return;
213
214         prov_major_version =
215                 cYAML_get_object_item(lndparams, "prov_major_version");
216         lnd_cfg->lnd_prov_major_version =
217                 (prov_major_version) ? prov_major_version->cy_valueint : 0;
218
219         prov_minor_version =
220                 cYAML_get_object_item(lndparams, "prov_minor_version");
221         lnd_cfg->lnd_prov_minor_version =
222                 (prov_minor_version) ? prov_minor_version->cy_valueint : 0;
223
224         auth_key = cYAML_get_object_item(lndparams, "auth_key");
225         lnd_cfg->lnd_auth_key =
226                 (auth_key) ? auth_key->cy_valueint : 0;
227 }
228
229 static void
230 yaml_extract_sock_tun(struct cYAML *tree,
231                          struct lnet_ioctl_config_socklnd_tunables *lnd_cfg)
232 {
233         struct cYAML *conns_per_peer = NULL, *lndparams = NULL;
234
235         lndparams = cYAML_get_object_item(tree, "lnd tunables");
236         if (!lndparams)
237                 return;
238
239         conns_per_peer = cYAML_get_object_item(lndparams, "conns_per_peer");
240         lnd_cfg->lnd_conns_per_peer =
241                 (conns_per_peer) ? conns_per_peer->cy_valueint : 1;
242 }
243
244 void
245 lustre_yaml_extract_lnd_tunables(struct cYAML *tree,
246                                  __u32 net_type,
247                                  struct lnet_lnd_tunables *tun)
248 {
249         if (net_type == O2IBLND)
250                 yaml_extract_o2ib_tun(tree,
251                                       &tun->lnd_tun_u.lnd_o2ib);
252         else if (net_type == SOCKLND)
253                 yaml_extract_sock_tun(tree,
254                                       &tun->lnd_tun_u.lnd_sock);
255         else if (net_type == KFILND)
256                 yaml_extract_kfi_tun(tree,
257                                      &tun->lnd_tun_u.lnd_kfi);
258 }
259