Whamcloud - gitweb
LU-7734 lnet: configure local NI from DLC
[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, Intel Corporation.
24  *
25  * Author:
26  *   James Simmons <jsimmons@infradead.org>
27  */
28
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <libcfs/util/ioctl.h>
33 #include "liblnetconfig.h"
34 #include "cyaml.h"
35
36 static int
37 lustre_o2iblnd_show_tun(struct cYAML *lndparams,
38                         struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
39 {
40         if (cYAML_create_number(lndparams, "peercredits_hiw",
41                                 lnd_cfg->lnd_peercredits_hiw) == NULL)
42                 return LUSTRE_CFG_RC_OUT_OF_MEM;
43
44         if (cYAML_create_number(lndparams, "map_on_demand",
45                                 lnd_cfg->lnd_map_on_demand) == NULL)
46                 return LUSTRE_CFG_RC_OUT_OF_MEM;
47
48         if (cYAML_create_number(lndparams, "concurrent_sends",
49                                 lnd_cfg->lnd_concurrent_sends) == NULL)
50                 return LUSTRE_CFG_RC_OUT_OF_MEM;
51
52         if (cYAML_create_number(lndparams, "fmr_pool_size",
53                                 lnd_cfg->lnd_fmr_pool_size) == NULL)
54                 return LUSTRE_CFG_RC_OUT_OF_MEM;
55
56         if (cYAML_create_number(lndparams, "fmr_flush_trigger",
57                                 lnd_cfg->lnd_fmr_flush_trigger) == NULL)
58                 return LUSTRE_CFG_RC_OUT_OF_MEM;
59
60         if (cYAML_create_number(lndparams, "fmr_cache",
61                                 lnd_cfg->lnd_fmr_cache) == NULL)
62                 return LUSTRE_CFG_RC_OUT_OF_MEM;
63
64         return LUSTRE_CFG_RC_NO_ERR;
65 }
66
67 int
68 lustre_net_show_tunables(struct cYAML *tunables,
69                          struct lnet_ioctl_config_lnd_cmn_tunables *cmn)
70 {
71
72
73         if (cYAML_create_number(tunables, "peer_timeout",
74                                 cmn->lct_peer_timeout)
75                                         == NULL)
76                 goto out;
77
78         if (cYAML_create_number(tunables, "peer_credits",
79                                 cmn->lct_peer_tx_credits)
80                                         == NULL)
81                 goto out;
82
83         if (cYAML_create_number(tunables,
84                                 "peer_buffer_credits",
85                                 cmn->lct_peer_rtr_credits)
86                                         == NULL)
87                 goto out;
88
89         if (cYAML_create_number(tunables, "credits",
90                                 cmn->lct_max_tx_credits)
91                                         == NULL)
92                 goto out;
93
94         return LUSTRE_CFG_RC_NO_ERR;
95
96 out:
97         return LUSTRE_CFG_RC_OUT_OF_MEM;
98 }
99
100 int
101 lustre_ni_show_tunables(struct cYAML *lnd_tunables,
102                         __u32 net_type,
103                         struct lnet_lnd_tunables *lnd)
104 {
105         int rc = LUSTRE_CFG_RC_NO_ERR;
106
107         if (net_type == O2IBLND)
108                 rc = lustre_o2iblnd_show_tun(lnd_tunables,
109                                              &lnd->lnd_tun_u.lnd_o2ib);
110
111         return rc;
112 }
113
114 static void
115 yaml_extract_o2ib_tun(struct cYAML *tree,
116                       struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
117 {
118         struct cYAML *map_on_demand = NULL, *concurrent_sends = NULL;
119         struct cYAML *fmr_pool_size = NULL, *fmr_cache = NULL;
120         struct cYAML *fmr_flush_trigger = NULL, *lndparams = NULL;
121
122         lndparams = cYAML_get_object_item(tree, "lnd tunables");
123         if (!lndparams)
124                 return;
125
126         map_on_demand = cYAML_get_object_item(lndparams, "map_on_demand");
127         lnd_cfg->lnd_map_on_demand =
128                 (map_on_demand) ? map_on_demand->cy_valueint : 0;
129
130         concurrent_sends = cYAML_get_object_item(lndparams, "concurrent_sends");
131         lnd_cfg->lnd_concurrent_sends =
132                 (concurrent_sends) ? concurrent_sends->cy_valueint : 0;
133
134         fmr_pool_size = cYAML_get_object_item(lndparams, "fmr_pool_size");
135         lnd_cfg->lnd_fmr_pool_size =
136                 (fmr_pool_size) ? fmr_pool_size->cy_valueint : 0;
137
138         fmr_flush_trigger = cYAML_get_object_item(lndparams,
139                                                   "fmr_flush_trigger");
140         lnd_cfg->lnd_fmr_flush_trigger =
141                 (fmr_flush_trigger) ? fmr_flush_trigger->cy_valueint : 0;
142
143         fmr_cache = cYAML_get_object_item(lndparams, "fmr_cache");
144         lnd_cfg->lnd_fmr_cache =
145                 (fmr_cache) ? fmr_cache->cy_valueint : 0;
146 }
147
148
149 void
150 lustre_yaml_extract_lnd_tunables(struct cYAML *tree,
151                                  __u32 net_type,
152                                  struct lnet_lnd_tunables *tun)
153 {
154         if (net_type == O2IBLND)
155                 yaml_extract_o2ib_tun(tree,
156                                       &tun->lnd_tun_u.lnd_o2ib);
157
158 }
159