Whamcloud - gitweb
56e597580e0d65353a482cda786af9408e9525de
[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 <limits.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <libcfs/util/ioctl.h>
34 #include "liblnetconfig.h"
35 #include "cyaml.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         return LUSTRE_CFG_RC_NO_ERR;
66 }
67
68 int
69 lustre_net_show_tunables(struct cYAML *tunables,
70                          struct lnet_ioctl_config_lnd_cmn_tunables *cmn)
71 {
72
73
74         if (cYAML_create_number(tunables, "peer_timeout",
75                                 cmn->lct_peer_timeout)
76                                         == NULL)
77                 goto out;
78
79         if (cYAML_create_number(tunables, "peer_credits",
80                                 cmn->lct_peer_tx_credits)
81                                         == NULL)
82                 goto out;
83
84         if (cYAML_create_number(tunables,
85                                 "peer_buffer_credits",
86                                 cmn->lct_peer_rtr_credits)
87                                         == NULL)
88                 goto out;
89
90         if (cYAML_create_number(tunables, "credits",
91                                 cmn->lct_max_tx_credits)
92                                         == NULL)
93                 goto out;
94
95         return LUSTRE_CFG_RC_NO_ERR;
96
97 out:
98         return LUSTRE_CFG_RC_OUT_OF_MEM;
99 }
100
101 int
102 lustre_ni_show_tunables(struct cYAML *lnd_tunables,
103                         __u32 net_type,
104                         struct lnet_lnd_tunables *lnd)
105 {
106         int rc = LUSTRE_CFG_RC_NO_ERR;
107
108         if (net_type == O2IBLND)
109                 rc = lustre_o2iblnd_show_tun(lnd_tunables,
110                                              &lnd->lnd_tun_u.lnd_o2ib);
111
112         return rc;
113 }
114
115 static void
116 yaml_extract_o2ib_tun(struct cYAML *tree,
117                       struct lnet_ioctl_config_o2iblnd_tunables *lnd_cfg)
118 {
119         struct cYAML *map_on_demand = NULL, *concurrent_sends = NULL;
120         struct cYAML *fmr_pool_size = NULL, *fmr_cache = NULL;
121         struct cYAML *fmr_flush_trigger = NULL, *lndparams = NULL;
122
123         lndparams = cYAML_get_object_item(tree, "lnd tunables");
124         if (!lndparams)
125                 return;
126
127         map_on_demand = cYAML_get_object_item(lndparams, "map_on_demand");
128         lnd_cfg->lnd_map_on_demand =
129                 (map_on_demand) ? map_on_demand->cy_valueint : 0;
130
131         concurrent_sends = cYAML_get_object_item(lndparams, "concurrent_sends");
132         lnd_cfg->lnd_concurrent_sends =
133                 (concurrent_sends) ? concurrent_sends->cy_valueint : 0;
134
135         fmr_pool_size = cYAML_get_object_item(lndparams, "fmr_pool_size");
136         lnd_cfg->lnd_fmr_pool_size =
137                 (fmr_pool_size) ? fmr_pool_size->cy_valueint : 0;
138
139         fmr_flush_trigger = cYAML_get_object_item(lndparams,
140                                                   "fmr_flush_trigger");
141         lnd_cfg->lnd_fmr_flush_trigger =
142                 (fmr_flush_trigger) ? fmr_flush_trigger->cy_valueint : 0;
143
144         fmr_cache = cYAML_get_object_item(lndparams, "fmr_cache");
145         lnd_cfg->lnd_fmr_cache =
146                 (fmr_cache) ? fmr_cache->cy_valueint : 0;
147 }
148
149
150 void
151 lustre_yaml_extract_lnd_tunables(struct cYAML *tree,
152                                  __u32 net_type,
153                                  struct lnet_lnd_tunables *tun)
154 {
155         if (net_type == O2IBLND)
156                 yaml_extract_o2ib_tun(tree,
157                                       &tun->lnd_tun_u.lnd_o2ib);
158
159 }
160