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