Whamcloud - gitweb
5f68b47c82d7ce2071910eda3cacfe341fd934ba
[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 #include <stdio.h>
29 #include <string.h>
30 #include <libcfs/util/ioctl.h>
31 #include "liblnetconfig.h"
32 #include "cyaml.h"
33
34 static int
35 lustre_ko2iblnd_show_net(struct cYAML *lndparams,
36                          struct lnet_ioctl_config_lnd_tunables *tunables)
37 {
38         struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg;
39
40         lnd_cfg = &tunables->lt_tun_u.lt_o2ib;
41
42         if (cYAML_create_number(lndparams, "peercredits_hiw",
43                                 lnd_cfg->lnd_peercredits_hiw) == NULL)
44                 return -1;
45
46         if (cYAML_create_number(lndparams, "map_on_demand",
47                                 lnd_cfg->lnd_map_on_demand) == NULL)
48                 return -1;
49
50         if (cYAML_create_number(lndparams, "concurrent_sends",
51                                 lnd_cfg->lnd_concurrent_sends) == NULL)
52                 return -1;
53
54         if (cYAML_create_number(lndparams, "fmr_pool_size",
55                                 lnd_cfg->lnd_fmr_pool_size) == NULL)
56                 return -1;
57
58         if (cYAML_create_number(lndparams, "fmr_flush_trigger",
59                                 lnd_cfg->lnd_fmr_flush_trigger) == NULL)
60                 return -1;
61
62         if (cYAML_create_number(lndparams, "fmr_cache",
63                                 lnd_cfg->lnd_fmr_cache) == NULL)
64                 return -1;
65         return 0;
66 }
67
68 int
69 lustre_interface_show_net(struct cYAML *interfaces, unsigned int index,
70                           bool detail, struct lnet_ioctl_config_data *data,
71                           struct lnet_ioctl_net_config *net_config)
72 {
73         char ni_index[2]; /* LNET_MAX_INTERFACES is only 16 */
74
75         if (strlen(net_config->ni_interfaces[index]) == 0)
76                 return 0;
77
78         snprintf(ni_index, sizeof(ni_index), "%d", index);
79         if (cYAML_create_string(interfaces, ni_index,
80                                 net_config->ni_interfaces[index]) == NULL)
81                 return -1;
82
83         if (detail) {
84                 __u32 net = LNET_NETTYP(LNET_NIDNET(data->cfg_nid));
85                 struct lnet_ioctl_config_lnd_tunables *lnd_cfg;
86                 struct cYAML *lndparams;
87
88                 if (data->cfg_config_u.cfg_net.net_interface_count == 0 ||
89                     net != O2IBLND)
90                         return 0;
91
92                 lndparams = cYAML_create_object(interfaces, "lnd tunables");
93                 if (lndparams == NULL)
94                         return -1;
95
96                 lnd_cfg = (struct lnet_ioctl_config_lnd_tunables *)net_config->cfg_bulk;
97                 if (lustre_ko2iblnd_show_net(lndparams, lnd_cfg) < 0)
98                         return -1;
99         }
100         return 0;
101 }
102
103 static void
104 lustre_ko2iblnd_parse_net(struct cYAML *lndparams,
105                           struct lnet_ioctl_config_lnd_tunables *lnd_cfg)
106 {
107         struct cYAML *map_on_demand = NULL, *concurrent_sends = NULL;
108         struct cYAML *fmr_pool_size = NULL, *fmr_cache = NULL;
109         struct cYAML *fmr_flush_trigger = NULL;
110
111         map_on_demand = cYAML_get_object_item(lndparams, "map_on_demand");
112         lnd_cfg->lt_tun_u.lt_o2ib.lnd_map_on_demand =
113                 (map_on_demand) ? map_on_demand->cy_valueint : 0;
114
115         concurrent_sends = cYAML_get_object_item(lndparams, "concurrent_sends");
116         lnd_cfg->lt_tun_u.lt_o2ib.lnd_concurrent_sends =
117                 (concurrent_sends) ? concurrent_sends->cy_valueint : 0;
118
119         fmr_pool_size = cYAML_get_object_item(lndparams, "fmr_pool_size");
120         lnd_cfg->lt_tun_u.lt_o2ib.lnd_fmr_pool_size =
121                 (fmr_pool_size) ? fmr_pool_size->cy_valueint : 0;
122
123         fmr_flush_trigger = cYAML_get_object_item(lndparams,
124                                                   "fmr_flush_trigger");
125         lnd_cfg->lt_tun_u.lt_o2ib.lnd_fmr_flush_trigger =
126                 (fmr_flush_trigger) ? fmr_flush_trigger->cy_valueint : 0;
127
128         fmr_cache = cYAML_get_object_item(lndparams, "fmr_cache");
129         lnd_cfg->lt_tun_u.lt_o2ib.lnd_fmr_cache =
130                 (fmr_cache) ? fmr_cache->cy_valueint : 0;
131 }
132
133 void
134 lustre_interface_parse(struct cYAML *lndparams, const char *dev_name,
135                        struct lnet_ioctl_config_lnd_tunables *lnd_cfg)
136 {
137         if (dev_name != NULL && strstr(dev_name, "ib"))
138                 lustre_ko2iblnd_parse_net(lndparams, lnd_cfg);
139 }