]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - iscsi-initiator-utils/patches/0033-iscsiadm-param-parsing-for-advanced-node-creation.patch
iscsi-initiator-utils: Various improvements.
[people/ms/ipfire-3.x.git] / iscsi-initiator-utils / patches / 0033-iscsiadm-param-parsing-for-advanced-node-creation.patch
1 From a41a27cd9b910191a616706c4f473259909bc45d Mon Sep 17 00:00:00 2001
2 From: Chris Leech <cleech@redhat.com>
3 Date: Tue, 18 Dec 2012 11:27:00 -0800
4 Subject: iscsiadm: --param parsing for advanced node creation
5
6 Share parse_param and apply_param code from iscsistart, allow using multiple
7 --param options to set arbitrary fields in node mode.
8
9 Signed-off-by: Chris Leech <cleech@redhat.com>
10 ---
11 usr/Makefile | 2 +-
12 usr/iscsi_param.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 usr/iscsi_param.h | 7 ++++
14 usr/iscsiadm.c | 16 ++++++++--
15 usr/iscsistart.c | 91 ++--------------------------------------------------
16 5 files changed, 120 insertions(+), 91 deletions(-)
17 create mode 100644 usr/iscsi_param.c
18 create mode 100644 usr/iscsi_param.h
19
20 diff --git a/usr/Makefile b/usr/Makefile
21 index 673b7f1..1506111 100644
22 --- a/usr/Makefile
23 +++ b/usr/Makefile
24 @@ -40,7 +40,7 @@ SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
25 ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
26 sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
27 iscsi_net_util.o iscsid_req.o transport.o iser.o cxgbi.o be2iscsi.o \
28 - initiator_common.o iscsi_err.o $(IPC_OBJ) $(SYSDEPS_SRCS)
29 + initiator_common.o iscsi_err.o iscsi_param.o $(IPC_OBJ) $(SYSDEPS_SRCS)
30 # core initiator files
31 INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o kern_err_table.o
32
33 diff --git a/usr/iscsi_param.c b/usr/iscsi_param.c
34 new file mode 100644
35 index 0000000..c075e8f
36 --- /dev/null
37 +++ b/usr/iscsi_param.c
38 @@ -0,0 +1,95 @@
39 +#include <string.h>
40 +#include "log.h"
41 +#include "config.h"
42 +#include "idbm.h"
43 +#include "list.h"
44 +#include "iface.h"
45 +#include "idbm_fields.h"
46 +#include "iscsi_err.h"
47 +
48 +int apply_params(struct list_head *user_params, struct node_rec *rec)
49 +{
50 + struct user_param *param;
51 + int rc;
52 +
53 + /* Must init this so we can check if user overrode them */
54 + rec->session.initial_login_retry_max = -1;
55 + rec->conn[0].timeo.noop_out_interval = -1;
56 + rec->conn[0].timeo.noop_out_timeout = -1;
57 +
58 + list_for_each_entry(param, user_params, list) {
59 + /*
60 + * user may not have passed in all params that were set by
61 + * ibft/iscsi_boot, so clear out values that might conflict
62 + * with user overrides
63 + */
64 + if (!strcmp(param->name, IFACE_NETNAME)) {
65 + /* overriding netname so MAC will be for old netdev */
66 + memset(rec->iface.hwaddress, 0,
67 + sizeof(rec->iface.hwaddress));
68 + } else if (!strcmp(param->name, IFACE_HWADDR)) {
69 + /* overriding MAC so netdev will be for old MAC */
70 + memset(rec->iface.netdev, 0, sizeof(rec->iface.netdev));
71 + } else if (!strcmp(param->name, IFACE_TRANSPORTNAME)) {
72 + /*
73 + * switching drivers so all old binding info is no
74 + * longer valid. Old values were either for offload
75 + * and we are switching to software or the reverse,
76 + * or switching types of cards (bnx2i to cxgb3i).
77 + */
78 + memset(&rec->iface, 0, sizeof(rec->iface));
79 + iface_setup_defaults(&rec->iface);
80 + }
81 + }
82 +
83 + rc = idbm_node_set_rec_from_param(user_params, rec, 0);
84 + if (rc)
85 + return rc;
86 +
87 + /*
88 + * For root boot we could not change this in older versions so
89 + * if user did not override then use the defaults.
90 + *
91 + * Increase to account for boot using static setup.
92 + */
93 + if (rec->session.initial_login_retry_max == -1)
94 + rec->session.initial_login_retry_max = 30;
95 + /* we used to not be able to answer so turn off */
96 + if (rec->conn[0].timeo.noop_out_interval == -1)
97 + rec->conn[0].timeo.noop_out_interval = 0;
98 + if (rec->conn[0].timeo.noop_out_timeout == -1)
99 + rec->conn[0].timeo.noop_out_timeout = 0;
100 +
101 + return 0;
102 +}
103 +
104 +int parse_param(struct list_head *user_params, char *param_str)
105 +{
106 + struct user_param *param;
107 + char *name, *value;
108 +
109 + name = param_str;
110 +
111 + value = strchr(param_str, '=');
112 + if (!value) {
113 + log_error("Invalid --param %s. Missing value.", param_str);
114 + return ISCSI_ERR_INVAL;
115 + }
116 + *value = '\0';
117 +
118 + value++;
119 + if (!strlen(value)) {
120 + log_error("Invalid --param %s. Missing value.", param_str);
121 + return ISCSI_ERR_INVAL;
122 + }
123 +
124 + param = idbm_alloc_user_param(name, value);
125 + if (!param) {
126 + log_error("Could not allocate memory for param.");
127 + return ISCSI_ERR_NOMEM;
128 + }
129 +
130 + list_add(&param->list, user_params);
131 + return 0;
132 +}
133 +
134 diff --git a/usr/iscsi_param.h b/usr/iscsi_param.h
135 new file mode 100644
136 index 0000000..8b7956c
137 --- /dev/null
138 +++ b/usr/iscsi_param.h
139 @@ -0,0 +1,7 @@
140 +#ifndef ISCSI_PARAM_H
141 +#define ISCSI_PARAM_H
142 +
143 +extern int parse_param(struct list_head *user_params, char *param_str);
144 +extern int apply_params(struct list_head *user_params, struct node_rec *rec);
145 +
146 +#endif
147 diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
148 index 323d0a8..ef866ae 100644
149 --- a/usr/iscsiadm.c
150 +++ b/usr/iscsiadm.c
151 @@ -53,6 +53,7 @@
152 #include "iscsi_err.h"
153 #include "iscsi_ipc.h"
154 #include "iscsi_timer.h"
155 +#include "iscsi_param.h"
156
157 static char program_name[] = "iscsiadm";
158 static char config_file[TARGET_NAME_MAXLEN];
159 @@ -112,6 +113,7 @@ static struct option const long_options[] =
160 {"count", required_argument, NULL, 'c'},
161 {"interval", required_argument, NULL, 'i'},
162 {"newroot", required_argument, NULL, 0},
163 + {"param", required_argument, NULL, 0},
164 {NULL, 0, NULL, 0},
165 };
166 static char *short_options = "RlDVhm:a:b:c:C:p:P:T:H:i:I:U:k:L:d:r:n:v:o:sSt:u";
167 @@ -127,7 +129,7 @@ iscsiadm -m discoverydb [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p
168 [ -o operation ] [ -n name ] [ -v value ] [ -lD ] ] \n\
169 iscsiadm -m discovery [ -hV ] [ -d debug_level ] [-P printlevel] [ -t type -p ip:port -I ifaceN ... [ -l ] ] | [ [ -p ip:port ] [ -l | -D ] ] \n\
170 iscsiadm -m node [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -L all,manual,automatic ] [ -U all,manual,automatic ] [ -S ] [ [ -T targetname -p ip:port -I ifaceN ] [ -l | -u | -R | -s] ] \
171 -[ [ -o operation ] [ -n name ] [ -v value ] ]\n\
172 +[ [ -o operation ] [ -n name ] [ -v value ] ] [ --param=NAME=VALUE ]\n\
173 iscsiadm -m session [ -hV ] [ -d debug_level ] [ -P printlevel] [ -r sessionid | sysfsdir [ -R | -u | -s ] [ -o operation ] [ -n name ] [ -v value ] ]\n\
174 iscsiadm -m iface [ -hV ] [ -d debug_level ] [ -P printlevel ] [ -I ifacename | -H hostno|MAC ] [ [ -o operation ] [ -n name ] [ -v value ] ] [ -C ping [ -a ip ] [ -b packetsize ] [ -c count ] [ -i interval ] ]\n\
175 iscsiadm -m fw [ -l ]\n\
176 @@ -2430,9 +2432,11 @@ main(int argc, char **argv)
177 uint32_t host_no = -1;
178 struct user_param *param;
179 struct list_head params;
180 + struct list_head user_params;
181
182 INIT_LIST_HEAD(&params);
183 INIT_LIST_HEAD(&ifaces);
184 + INIT_LIST_HEAD(&user_params);
185 /* do not allow ctrl-c for now... */
186 memset(&sa_old, 0, sizeof(struct sigaction));
187 memset(&sa_new, 0, sizeof(struct sigaction));
188 @@ -2455,8 +2459,14 @@ main(int argc, char **argv)
189 case 0:
190 if (long_options[longindex].flag != 0)
191 break;
192 - if (!strcmp(long_options[longindex].name, "newroot"))
193 + if (!strcmp(long_options[longindex].name, "newroot")) {
194 newroot = optarg;
195 + break;
196 + }
197 + if (!strcmp(long_options[longindex].name, "param")) {
198 + parse_param(&user_params, optarg);
199 + break;
200 + }
201 break;
202 case 'k':
203 killiscsid = atoi(optarg);
204 @@ -2748,6 +2758,8 @@ main(int argc, char **argv)
205 goto out;
206 }
207
208 + apply_params(&user_params, rec);
209 +
210 rc = exec_node_op(op, do_login, do_logout, do_show,
211 do_rescan, do_stats, info_level, rec,
212 &params);
213 diff --git a/usr/iscsistart.c b/usr/iscsistart.c
214 index 6924d49..85be35b 100644
215 --- a/usr/iscsistart.c
216 +++ b/usr/iscsistart.c
217 @@ -50,6 +50,7 @@
218 #include "iscsid_req.h"
219 #include "iscsi_err.h"
220 #include "iface.h"
221 +#include "iscsi_param.h"
222
223 /* global config info */
224 /* initiator needs initiator name/alias */
225 @@ -131,99 +132,13 @@ static int stop_event_loop(void)
226 return rc;
227 }
228
229 -static int apply_params(struct node_rec *rec)
230 -{
231 - struct user_param *param;
232 - int rc;
233 -
234 - /* Must init this so we can check if user overrode them */
235 - rec->session.initial_login_retry_max = -1;
236 - rec->conn[0].timeo.noop_out_interval = -1;
237 - rec->conn[0].timeo.noop_out_timeout = -1;
238 -
239 - list_for_each_entry(param, &user_params, list) {
240 - /*
241 - * user may not have passed in all params that were set by
242 - * ibft/iscsi_boot, so clear out values that might conflict
243 - * with user overrides
244 - */
245 - if (!strcmp(param->name, IFACE_NETNAME)) {
246 - /* overriding netname so MAC will be for old netdev */
247 - memset(rec->iface.hwaddress, 0,
248 - sizeof(rec->iface.hwaddress));
249 - } else if (!strcmp(param->name, IFACE_HWADDR)) {
250 - /* overriding MAC so netdev will be for old MAC */
251 - memset(rec->iface.netdev, 0, sizeof(rec->iface.netdev));
252 - } else if (!strcmp(param->name, IFACE_TRANSPORTNAME)) {
253 - /*
254 - * switching drivers so all old binding info is no
255 - * longer valid. Old values were either for offload
256 - * and we are switching to software or the reverse,
257 - * or switching types of cards (bnx2i to cxgb3i).
258 - */
259 - memset(&rec->iface, 0, sizeof(rec->iface));
260 - iface_setup_defaults(&rec->iface);
261 - }
262 - }
263 -
264 - rc = idbm_node_set_rec_from_param(&user_params, rec, 0);
265 - if (rc)
266 - return rc;
267 -
268 - /*
269 - * For root boot we could not change this in older versions so
270 - * if user did not override then use the defaults.
271 - *
272 - * Increase to account for boot using static setup.
273 - */
274 - if (rec->session.initial_login_retry_max == -1)
275 - rec->session.initial_login_retry_max = 30;
276 - /* we used to not be able to answer so turn off */
277 - if (rec->conn[0].timeo.noop_out_interval == -1)
278 - rec->conn[0].timeo.noop_out_interval = 0;
279 - if (rec->conn[0].timeo.noop_out_timeout == -1)
280 - rec->conn[0].timeo.noop_out_timeout = 0;
281 -
282 - return 0;
283 -}
284 -
285 -static int parse_param(char *param_str)
286 -{
287 - struct user_param *param;
288 - char *name, *value;
289 -
290 - name = param_str;
291 -
292 - value = strchr(param_str, '=');
293 - if (!value) {
294 - log_error("Invalid --param %s. Missing value.", param_str);
295 - return ISCSI_ERR_INVAL;
296 - }
297 - *value = '\0';
298 -
299 - value++;
300 - if (!strlen(value)) {
301 - log_error("Invalid --param %s. Missing value.", param_str);
302 - return ISCSI_ERR_INVAL;
303 - }
304 -
305 - param = idbm_alloc_user_param(name, value);
306 - if (!param) {
307 - log_error("Could not allocate memory for param.");
308 - return ISCSI_ERR_NOMEM;
309 - }
310 -
311 - list_add(&param->list, &user_params);
312 - return 0;
313 -}
314 -
315 static int login_session(struct node_rec *rec)
316 {
317 iscsiadm_req_t req;
318 iscsiadm_rsp_t rsp;
319 int rc, retries = 0;
320
321 - rc = apply_params(rec);
322 + rc = apply_params(&user_params, rec);
323 if (rc)
324 return rc;
325
326 @@ -426,7 +341,7 @@ int main(int argc, char *argv[])
327 fw_free_targets(&targets);
328 exit(0);
329 case 'P':
330 - err = parse_param(optarg);
331 + err = parse_param(&user_params, optarg);
332 if (err)
333 exit(err);
334 break;
335 --
336 1.7.11.7
337