Lines 36-42
Link Here
|
36 |
#include <sys/linker.h> |
36 |
#include <sys/linker.h> |
37 |
#include <assert.h> |
37 |
#include <assert.h> |
38 |
#include <ctype.h> |
38 |
#include <ctype.h> |
39 |
#include <err.h> |
|
|
40 |
#include <errno.h> |
39 |
#include <errno.h> |
41 |
#include <fcntl.h> |
40 |
#include <fcntl.h> |
42 |
#include <limits.h> |
41 |
#include <limits.h> |
Lines 44-49
Link Here
|
44 |
#include <stdlib.h> |
43 |
#include <stdlib.h> |
45 |
#include <string.h> |
44 |
#include <string.h> |
46 |
#include <unistd.h> |
45 |
#include <unistd.h> |
|
|
46 |
#include <libxo/xo.h> |
47 |
|
47 |
|
48 |
#include <iscsi_ioctl.h> |
48 |
#include <iscsi_ioctl.h> |
49 |
#include "iscsictl.h" |
49 |
#include "iscsictl.h" |
Lines 55-61
Link Here
|
55 |
|
55 |
|
56 |
conf = calloc(1, sizeof(*conf)); |
56 |
conf = calloc(1, sizeof(*conf)); |
57 |
if (conf == NULL) |
57 |
if (conf == NULL) |
58 |
err(1, "calloc"); |
58 |
xo_err(1, "calloc"); |
59 |
|
59 |
|
60 |
TAILQ_INIT(&conf->conf_targets); |
60 |
TAILQ_INIT(&conf->conf_targets); |
61 |
|
61 |
|
Lines 83-89
Link Here
|
83 |
|
83 |
|
84 |
targ = calloc(1, sizeof(*targ)); |
84 |
targ = calloc(1, sizeof(*targ)); |
85 |
if (targ == NULL) |
85 |
if (targ == NULL) |
86 |
err(1, "calloc"); |
86 |
xo_err(1, "calloc"); |
87 |
targ->t_conf = conf; |
87 |
targ->t_conf = conf; |
88 |
TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next); |
88 |
TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next); |
89 |
|
89 |
|
Lines 110-121
Link Here
|
110 |
|
110 |
|
111 |
name = calloc(1, namelen + 1); |
111 |
name = calloc(1, namelen + 1); |
112 |
if (name == NULL) |
112 |
if (name == NULL) |
113 |
err(1, "calloc"); |
113 |
xo_err(1, "calloc"); |
114 |
strcpy(name, DEFAULT_IQN); |
114 |
strcpy(name, DEFAULT_IQN); |
115 |
error = gethostname(name + strlen(DEFAULT_IQN), |
115 |
error = gethostname(name + strlen(DEFAULT_IQN), |
116 |
namelen - strlen(DEFAULT_IQN)); |
116 |
namelen - strlen(DEFAULT_IQN)); |
117 |
if (error != 0) |
117 |
if (error != 0) |
118 |
err(1, "gethostname"); |
118 |
xo_err(1, "gethostname"); |
119 |
|
119 |
|
120 |
return (name); |
120 |
return (name); |
121 |
} |
121 |
} |
Lines 158-164
Link Here
|
158 |
int i; |
158 |
int i; |
159 |
|
159 |
|
160 |
if (strlen(name) >= MAX_NAME_LEN) { |
160 |
if (strlen(name) >= MAX_NAME_LEN) { |
161 |
warnx("overlong name for \"%s\"; max length allowed " |
161 |
xo_warnx("overlong name for \"%s\"; max length allowed " |
162 |
"by iSCSI specification is %d characters", |
162 |
"by iSCSI specification is %d characters", |
163 |
name, MAX_NAME_LEN); |
163 |
name, MAX_NAME_LEN); |
164 |
return (false); |
164 |
return (false); |
Lines 178-184
Link Here
|
178 |
continue; |
178 |
continue; |
179 |
if (name[i] == '-' || name[i] == '.' || name[i] == ':') |
179 |
if (name[i] == '-' || name[i] == '.' || name[i] == ':') |
180 |
continue; |
180 |
continue; |
181 |
warnx("invalid character \"%c\" in iSCSI name " |
181 |
xo_warnx("invalid character \"%c\" in iSCSI name " |
182 |
"\"%s\"; allowed characters are letters, digits, " |
182 |
"\"%s\"; allowed characters are letters, digits, " |
183 |
"'-', '.', and ':'", name[i], name); |
183 |
"'-', '.', and ':'", name[i], name); |
184 |
break; |
184 |
break; |
Lines 188-199
Link Here
|
188 |
*/ |
188 |
*/ |
189 |
} else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) { |
189 |
} else if (strncasecmp(name, "eui.", strlen("eui.")) == 0) { |
190 |
if (strlen(name) != strlen("eui.") + 16) |
190 |
if (strlen(name) != strlen("eui.") + 16) |
191 |
warnx("invalid iSCSI name \"%s\"; the \"eui.\" " |
191 |
xo_warnx("invalid iSCSI name \"%s\"; the \"eui.\" " |
192 |
"should be followed by exactly 16 hexadecimal " |
192 |
"should be followed by exactly 16 hexadecimal " |
193 |
"digits", name); |
193 |
"digits", name); |
194 |
for (i = strlen("eui."); name[i] != '\0'; i++) { |
194 |
for (i = strlen("eui."); name[i] != '\0'; i++) { |
195 |
if (!valid_hex(name[i])) { |
195 |
if (!valid_hex(name[i])) { |
196 |
warnx("invalid character \"%c\" in iSCSI " |
196 |
xo_warnx("invalid character \"%c\" in iSCSI " |
197 |
"name \"%s\"; allowed characters are 1-9 " |
197 |
"name \"%s\"; allowed characters are 1-9 " |
198 |
"and A-F", name[i], name); |
198 |
"and A-F", name[i], name); |
199 |
break; |
199 |
break; |
Lines 201-219
Link Here
|
201 |
} |
201 |
} |
202 |
} else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) { |
202 |
} else if (strncasecmp(name, "naa.", strlen("naa.")) == 0) { |
203 |
if (strlen(name) > strlen("naa.") + 32) |
203 |
if (strlen(name) > strlen("naa.") + 32) |
204 |
warnx("invalid iSCSI name \"%s\"; the \"naa.\" " |
204 |
xo_warnx("invalid iSCSI name \"%s\"; the \"naa.\" " |
205 |
"should be followed by at most 32 hexadecimal " |
205 |
"should be followed by at most 32 hexadecimal " |
206 |
"digits", name); |
206 |
"digits", name); |
207 |
for (i = strlen("naa."); name[i] != '\0'; i++) { |
207 |
for (i = strlen("naa."); name[i] != '\0'; i++) { |
208 |
if (!valid_hex(name[i])) { |
208 |
if (!valid_hex(name[i])) { |
209 |
warnx("invalid character \"%c\" in ISCSI " |
209 |
xo_warnx("invalid character \"%c\" in ISCSI " |
210 |
"name \"%s\"; allowed characters are 1-9 " |
210 |
"name \"%s\"; allowed characters are 1-9 " |
211 |
"and A-F", name[i], name); |
211 |
"and A-F", name[i], name); |
212 |
break; |
212 |
break; |
213 |
} |
213 |
} |
214 |
} |
214 |
} |
215 |
} else { |
215 |
} else { |
216 |
warnx("invalid iSCSI name \"%s\"; should start with " |
216 |
xo_warnx("invalid iSCSI name \"%s\"; should start with " |
217 |
"either \".iqn\", \"eui.\", or \"naa.\"", |
217 |
"either \".iqn\", \"eui.\", or \"naa.\"", |
218 |
name); |
218 |
name); |
219 |
} |
219 |
} |
Lines 231-256
Link Here
|
231 |
targ->t_session_type = SESSION_TYPE_NORMAL; |
231 |
targ->t_session_type = SESSION_TYPE_NORMAL; |
232 |
if (targ->t_session_type == SESSION_TYPE_NORMAL && |
232 |
if (targ->t_session_type == SESSION_TYPE_NORMAL && |
233 |
targ->t_name == NULL) |
233 |
targ->t_name == NULL) |
234 |
errx(1, "missing TargetName for target \"%s\"", |
234 |
xo_errx(1, "missing TargetName for target \"%s\"", |
235 |
targ->t_nickname); |
235 |
targ->t_nickname); |
236 |
if (targ->t_session_type == SESSION_TYPE_DISCOVERY && |
236 |
if (targ->t_session_type == SESSION_TYPE_DISCOVERY && |
237 |
targ->t_name != NULL) |
237 |
targ->t_name != NULL) |
238 |
errx(1, "cannot specify TargetName for discovery " |
238 |
xo_errx(1, "cannot specify TargetName for discovery " |
239 |
"sessions for target \"%s\"", targ->t_nickname); |
239 |
"sessions for target \"%s\"", targ->t_nickname); |
240 |
if (targ->t_name != NULL) { |
240 |
if (targ->t_name != NULL) { |
241 |
if (valid_iscsi_name(targ->t_name) == false) |
241 |
if (valid_iscsi_name(targ->t_name) == false) |
242 |
errx(1, "invalid target name \"%s\"", |
242 |
xo_errx(1, "invalid target name \"%s\"", |
243 |
targ->t_name); |
243 |
targ->t_name); |
244 |
} |
244 |
} |
245 |
if (targ->t_protocol == PROTOCOL_UNSPECIFIED) |
245 |
if (targ->t_protocol == PROTOCOL_UNSPECIFIED) |
246 |
targ->t_protocol = PROTOCOL_ISCSI; |
246 |
targ->t_protocol = PROTOCOL_ISCSI; |
247 |
if (targ->t_address == NULL) |
247 |
if (targ->t_address == NULL) |
248 |
errx(1, "missing TargetAddress for target \"%s\"", |
248 |
xo_errx(1, "missing TargetAddress for target \"%s\"", |
249 |
targ->t_nickname); |
249 |
targ->t_nickname); |
250 |
if (targ->t_initiator_name == NULL) |
250 |
if (targ->t_initiator_name == NULL) |
251 |
targ->t_initiator_name = default_initiator_name(); |
251 |
targ->t_initiator_name = default_initiator_name(); |
252 |
if (valid_iscsi_name(targ->t_initiator_name) == false) |
252 |
if (valid_iscsi_name(targ->t_initiator_name) == false) |
253 |
errx(1, "invalid initiator name \"%s\"", |
253 |
xo_errx(1, "invalid initiator name \"%s\"", |
254 |
targ->t_initiator_name); |
254 |
targ->t_initiator_name); |
255 |
if (targ->t_header_digest == DIGEST_UNSPECIFIED) |
255 |
if (targ->t_header_digest == DIGEST_UNSPECIFIED) |
256 |
targ->t_header_digest = DIGEST_NONE; |
256 |
targ->t_header_digest = DIGEST_NONE; |
Lines 268-286
Link Here
|
268 |
} |
268 |
} |
269 |
if (targ->t_auth_method == AUTH_METHOD_CHAP) { |
269 |
if (targ->t_auth_method == AUTH_METHOD_CHAP) { |
270 |
if (targ->t_user == NULL) { |
270 |
if (targ->t_user == NULL) { |
271 |
errx(1, "missing chapIName for target \"%s\"", |
271 |
xo_errx(1, "missing chapIName for target \"%s\"", |
272 |
targ->t_nickname); |
272 |
targ->t_nickname); |
273 |
} |
273 |
} |
274 |
if (targ->t_secret == NULL) |
274 |
if (targ->t_secret == NULL) |
275 |
errx(1, "missing chapSecret for target \"%s\"", |
275 |
xo_errx(1, "missing chapSecret for target \"%s\"", |
276 |
targ->t_nickname); |
276 |
targ->t_nickname); |
277 |
if (targ->t_mutual_user != NULL || |
277 |
if (targ->t_mutual_user != NULL || |
278 |
targ->t_mutual_secret != NULL) { |
278 |
targ->t_mutual_secret != NULL) { |
279 |
if (targ->t_mutual_user == NULL) |
279 |
if (targ->t_mutual_user == NULL) |
280 |
errx(1, "missing tgtChapName for " |
280 |
xo_errx(1, "missing tgtChapName for " |
281 |
"target \"%s\"", targ->t_nickname); |
281 |
"target \"%s\"", targ->t_nickname); |
282 |
if (targ->t_mutual_secret == NULL) |
282 |
if (targ->t_mutual_secret == NULL) |
283 |
errx(1, "missing tgtChapSecret for " |
283 |
xo_errx(1, "missing tgtChapSecret for " |
284 |
"target \"%s\"", targ->t_nickname); |
284 |
"target \"%s\"", targ->t_nickname); |
285 |
} |
285 |
} |
286 |
} |
286 |
} |
Lines 350-356
Link Here
|
350 |
conf_from_target(&isa.isa_conf, targ); |
350 |
conf_from_target(&isa.isa_conf, targ); |
351 |
error = ioctl(iscsi_fd, ISCSISADD, &isa); |
351 |
error = ioctl(iscsi_fd, ISCSISADD, &isa); |
352 |
if (error != 0) |
352 |
if (error != 0) |
353 |
warn("ISCSISADD"); |
353 |
xo_warn("ISCSISADD"); |
354 |
return (error); |
354 |
return (error); |
355 |
} |
355 |
} |
356 |
|
356 |
|
Lines 365-371
Link Here
|
365 |
conf_from_target(&ism.ism_conf, targ); |
365 |
conf_from_target(&ism.ism_conf, targ); |
366 |
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism); |
366 |
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism); |
367 |
if (error != 0) |
367 |
if (error != 0) |
368 |
warn("ISCSISMODIFY"); |
368 |
xo_warn("ISCSISMODIFY"); |
369 |
return (error); |
369 |
return (error); |
370 |
} |
370 |
} |
371 |
|
371 |
|
Lines 385-391
Link Here
|
385 |
states = realloc(states, |
385 |
states = realloc(states, |
386 |
nentries * sizeof(struct iscsi_session_state)); |
386 |
nentries * sizeof(struct iscsi_session_state)); |
387 |
if (states == NULL) |
387 |
if (states == NULL) |
388 |
err(1, "realloc"); |
388 |
xo_err(1, "realloc"); |
389 |
|
389 |
|
390 |
memset(&isl, 0, sizeof(isl)); |
390 |
memset(&isl, 0, sizeof(isl)); |
391 |
isl.isl_nentries = nentries; |
391 |
isl.isl_nentries = nentries; |
Lines 399-405
Link Here
|
399 |
break; |
399 |
break; |
400 |
} |
400 |
} |
401 |
if (error != 0) |
401 |
if (error != 0) |
402 |
errx(1, "ISCSISLIST"); |
402 |
xo_errx(1, "ISCSISLIST"); |
403 |
|
403 |
|
404 |
for (i = 0; i < isl.isl_nentries; i++) { |
404 |
for (i = 0; i < isl.isl_nentries; i++) { |
405 |
state = &states[i]; |
405 |
state = &states[i]; |
Lines 408-414
Link Here
|
408 |
break; |
408 |
break; |
409 |
} |
409 |
} |
410 |
if (i == isl.isl_nentries) |
410 |
if (i == isl.isl_nentries) |
411 |
errx(1, "session-id %u not found", session_id); |
411 |
xo_errx(1, "session-id %u not found", session_id); |
412 |
|
412 |
|
413 |
conf = &state->iss_conf; |
413 |
conf = &state->iss_conf; |
414 |
|
414 |
|
Lines 427-433
Link Here
|
427 |
memcpy(&ism.ism_conf, conf, sizeof(ism.ism_conf)); |
427 |
memcpy(&ism.ism_conf, conf, sizeof(ism.ism_conf)); |
428 |
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism); |
428 |
error = ioctl(iscsi_fd, ISCSISMODIFY, &ism); |
429 |
if (error != 0) |
429 |
if (error != 0) |
430 |
warn("ISCSISMODIFY"); |
430 |
xo_warn("ISCSISMODIFY"); |
431 |
} |
431 |
} |
432 |
|
432 |
|
433 |
static int |
433 |
static int |
Lines 440-446
Link Here
|
440 |
conf_from_target(&isr.isr_conf, targ); |
440 |
conf_from_target(&isr.isr_conf, targ); |
441 |
error = ioctl(iscsi_fd, ISCSISREMOVE, &isr); |
441 |
error = ioctl(iscsi_fd, ISCSISREMOVE, &isr); |
442 |
if (error != 0) |
442 |
if (error != 0) |
443 |
warn("ISCSISREMOVE"); |
443 |
xo_warn("ISCSISREMOVE"); |
444 |
return (error); |
444 |
return (error); |
445 |
} |
445 |
} |
446 |
|
446 |
|
Lines 462-468
Link Here
|
462 |
states = realloc(states, |
462 |
states = realloc(states, |
463 |
nentries * sizeof(struct iscsi_session_state)); |
463 |
nentries * sizeof(struct iscsi_session_state)); |
464 |
if (states == NULL) |
464 |
if (states == NULL) |
465 |
err(1, "realloc"); |
465 |
xo_err(1, "realloc"); |
466 |
|
466 |
|
467 |
memset(&isl, 0, sizeof(isl)); |
467 |
memset(&isl, 0, sizeof(isl)); |
468 |
isl.isl_nentries = nentries; |
468 |
isl.isl_nentries = nentries; |
Lines 476-553
Link Here
|
476 |
break; |
476 |
break; |
477 |
} |
477 |
} |
478 |
if (error != 0) { |
478 |
if (error != 0) { |
479 |
warn("ISCSISLIST"); |
479 |
xo_warn("ISCSISLIST"); |
480 |
return (error); |
480 |
return (error); |
481 |
} |
481 |
} |
482 |
|
482 |
|
483 |
if (verbose != 0) { |
483 |
if (verbose != 0) { |
|
|
484 |
xo_open_list("target"); |
484 |
for (i = 0; i < isl.isl_nentries; i++) { |
485 |
for (i = 0; i < isl.isl_nentries; i++) { |
485 |
state = &states[i]; |
486 |
state = &states[i]; |
486 |
conf = &state->iss_conf; |
487 |
conf = &state->iss_conf; |
487 |
|
488 |
|
488 |
printf("Session ID: %u\n", state->iss_id); |
489 |
xo_open_instance("target"); |
489 |
printf("Initiator name: %s\n", conf->isc_initiator); |
490 |
|
490 |
printf("Initiator portal: %s\n", |
491 |
/* |
491 |
conf->isc_initiator_addr); |
492 |
* Display-only modifier as this information |
492 |
printf("Initiator alias: %s\n", |
493 |
* is also present within the 'session' container |
493 |
conf->isc_initiator_alias); |
494 |
*/ |
494 |
printf("Target name: %s\n", conf->isc_target); |
495 |
xo_emit("{Ld:/%-18s}{Vd:sessionId/%u}\n", |
495 |
printf("Target portal: %s\n", |
496 |
"Session ID:", state->iss_id); |
496 |
conf->isc_target_addr); |
497 |
|
497 |
printf("Target alias: %s\n", |
498 |
/* Start Container: initiator */ |
498 |
state->iss_target_alias); |
499 |
xo_open_container("initiator"); |
499 |
printf("User: %s\n", conf->isc_user); |
500 |
xo_emit("{L:/%-18s}{V:name/%s}\n", |
500 |
printf("Secret: %s\n", conf->isc_secret); |
501 |
"Initiator name:", conf->isc_initiator); |
501 |
printf("Mutual user: %s\n", |
502 |
xo_emit("{L:/%-18s}{V:portal/%s}\n", |
502 |
conf->isc_mutual_user); |
503 |
"Initiator portal:", conf->isc_initiator_addr); |
503 |
printf("Mutual secret: %s\n", |
504 |
xo_emit("{L:/%-18s}{V:alias/%s}\n", |
504 |
conf->isc_mutual_secret); |
505 |
"Initiator alias:", conf->isc_initiator_alias); |
505 |
printf("Session type: %s\n", |
506 |
xo_close_container("initiator"); |
506 |
conf->isc_discovery ? "Discovery" : "Normal"); |
507 |
/* End Container: initiator */ |
507 |
printf("Session state: %s\n", |
508 |
|
508 |
state->iss_connected ? |
509 |
/* Start Container: target */ |
509 |
"Connected" : "Disconnected"); |
510 |
xo_open_container("target"); |
510 |
printf("Failure reason: %s\n", state->iss_reason); |
511 |
xo_emit("{L:/%-18s}{V:name/%s}\n", |
511 |
printf("Header digest: %s\n", |
512 |
"Target name:", conf->isc_target); |
512 |
state->iss_header_digest == ISCSI_DIGEST_CRC32C ? |
513 |
xo_emit("{L:/%-18s}{V:portal/%s}\n", |
513 |
"CRC32C" : "None"); |
514 |
"Target portal:", conf->isc_target_addr); |
514 |
printf("Data digest: %s\n", |
515 |
xo_emit("{L:/%-18s}{V:alias/%s}\n", |
515 |
state->iss_data_digest == ISCSI_DIGEST_CRC32C ? |
516 |
"Target alias:", state->iss_target_alias); |
516 |
"CRC32C" : "None"); |
517 |
xo_close_container("target"); |
517 |
printf("DataSegmentLen: %d\n", |
518 |
/* End Container: target */ |
518 |
state->iss_max_data_segment_length); |
519 |
|
519 |
printf("ImmediateData: %s\n", |
520 |
/* Start Container: auth */ |
520 |
state->iss_immediate_data ? "Yes" : "No"); |
521 |
xo_open_container("auth"); |
521 |
printf("iSER (RDMA): %s\n", |
522 |
xo_emit("{L:/%-18s}{V:user/%s}\n", |
522 |
conf->isc_iser ? "Yes" : "No"); |
523 |
"User:", conf->isc_user); |
523 |
printf("Offload driver: %s\n", state->iss_offload); |
524 |
xo_emit("{L:/%-18s}{V:secret/%s}\n", |
524 |
printf("Device nodes: "); |
525 |
"Secret:", conf->isc_secret); |
|
|
526 |
xo_emit("{L:/%-18s}{V:mutualUser/%s}\n", |
527 |
"Mutual user:", conf->isc_mutual_user); |
528 |
xo_emit("{L:/%-18s}{V:mutualSecret/%s}\n", |
529 |
"Mutual secret:", conf->isc_mutual_secret); |
530 |
xo_close_container("auth"); |
531 |
/* End Container: auth */ |
532 |
|
533 |
/* Start Container: session */ |
534 |
xo_open_container("session"); |
535 |
/* |
536 |
* Session ID is already printed for |
537 |
* display outputs. Only include it for |
538 |
* non-display output. |
539 |
*/ |
540 |
xo_emit("{Ve:id/%u}", |
541 |
state->iss_id); |
542 |
xo_emit("{L:/%-18s}{V:type/%s}\n", |
543 |
"Session type:", (conf->isc_discovery ? "Discovery" : "Normal")); |
544 |
xo_emit("{L:/%-18s}{V:state/%s}\n", |
545 |
"Session state:", |
546 |
(state->iss_connected ? |
547 |
"Connected" : "Disconnected")); |
548 |
xo_close_container("session"); |
549 |
/* End Container: session */ |
550 |
|
551 |
xo_emit("{L:/%-18s}{V:failureReason/%s}\n", |
552 |
"Failure reason:", state->iss_reason); |
553 |
|
554 |
/* Start Container: digest */ |
555 |
xo_open_container("digest"); |
556 |
xo_emit("{L:/%-18s}{V:header/%s}\n", |
557 |
"Header digest:", |
558 |
(state->iss_header_digest == ISCSI_DIGEST_CRC32C ? |
559 |
"CRC32C" : "None")); |
560 |
xo_emit("{L:/%-18s}{V:data/%s}\n", |
561 |
"Data digest:", |
562 |
(state->iss_data_digest == ISCSI_DIGEST_CRC32C ? |
563 |
"CRC32C" : "None")); |
564 |
xo_close_container("digest"); |
565 |
/* End Container: digest */ |
566 |
|
567 |
xo_emit("{L:/%-18s}{V:dataSegmentLen/%d}\n", |
568 |
"DataSegmentLen:", state->iss_max_data_segment_length); |
569 |
xo_emit("{L:/%-18s}{V:immediateData/%s}\n", |
570 |
"ImmediateData:", state->iss_immediate_data ? "Yes" : "No"); |
571 |
xo_emit("{L:/%-18s}{V:iSER/%s}\n", |
572 |
"iSER (RDMA):", conf->isc_iser ? "Yes" : "No"); |
573 |
|
574 |
xo_emit("{L:/%-18s}{V:offloadDriver/%s}\n", |
575 |
"Offload driver:", state->iss_offload); |
576 |
xo_emit("{L:/%-18s}", |
577 |
"Device nodes:"); |
525 |
print_periphs(state->iss_id); |
578 |
print_periphs(state->iss_id); |
526 |
printf("\n\n"); |
579 |
xo_emit("\n\n"); |
|
|
580 |
xo_close_instance("target"); |
527 |
} |
581 |
} |
|
|
582 |
xo_close_list("target"); |
528 |
} else { |
583 |
} else { |
529 |
printf("%-36s %-16s %s\n", |
584 |
xo_emit("{T:/%-36s} {T:/%-16s} {T:/%s}\n", |
530 |
"Target name", "Target portal", "State"); |
585 |
"Target name", "Target portal", "State"); |
|
|
586 |
|
531 |
for (i = 0; i < isl.isl_nentries; i++) { |
587 |
for (i = 0; i < isl.isl_nentries; i++) { |
|
|
588 |
if (i == 0) { |
589 |
xo_open_list("target"); |
590 |
} |
591 |
|
532 |
state = &states[i]; |
592 |
state = &states[i]; |
533 |
conf = &state->iss_conf; |
593 |
conf = &state->iss_conf; |
534 |
|
594 |
|
535 |
printf("%-36s %-16s ", |
595 |
xo_open_instance("target"); |
536 |
conf->isc_target, conf->isc_target_addr); |
596 |
xo_emit("{V:name/%-36s/%s} {V:portal/%-16s/%s} ", |
537 |
|
597 |
conf->isc_target, conf->isc_target_addr); |
|
|
598 |
|
538 |
if (state->iss_reason[0] != '\0') { |
599 |
if (state->iss_reason[0] != '\0') { |
539 |
printf("%s\n", state->iss_reason); |
600 |
xo_emit("{V:state/%s", state->iss_reason); |
540 |
} else { |
601 |
} else { |
541 |
if (conf->isc_discovery) { |
602 |
if (conf->isc_discovery) { |
542 |
printf("Discovery\n"); |
603 |
xo_emit("{V:state}\n", "Discovery"); |
543 |
} else if (state->iss_connected) { |
604 |
} else if (state->iss_connected) { |
544 |
printf("Connected: "); |
605 |
xo_emit("{V:state}: ", "Connected"); |
545 |
print_periphs(state->iss_id); |
606 |
print_periphs(state->iss_id); |
546 |
printf("\n"); |
607 |
xo_emit("\n"); |
547 |
} else { |
608 |
} else { |
548 |
printf("Disconnected\n"); |
609 |
xo_emit("{V:state}\n", "Disconnected"); |
549 |
} |
610 |
} |
550 |
} |
611 |
} |
|
|
612 |
xo_close_instance("target"); |
613 |
} |
614 |
if (isl.isl_nentries != 0) { |
615 |
xo_close_list("target"); |
551 |
} |
616 |
} |
552 |
} |
617 |
} |
553 |
|
618 |
|
Lines 582-588
Link Here
|
582 |
|
647 |
|
583 |
c = strdup(s); |
648 |
c = strdup(s); |
584 |
if (c == NULL) |
649 |
if (c == NULL) |
585 |
err(1, "strdup"); |
650 |
xo_err(1, "strdup"); |
586 |
return (c); |
651 |
return (c); |
587 |
} |
652 |
} |
588 |
|
653 |
|
Lines 599-605
Link Here
|
599 |
int failed = 0; |
664 |
int failed = 0; |
600 |
struct conf *conf; |
665 |
struct conf *conf; |
601 |
struct target *targ; |
666 |
struct target *targ; |
602 |
|
667 |
|
|
|
668 |
argc = xo_parse_args(argc, argv); |
669 |
xo_open_container("iscsictl"); |
670 |
|
603 |
while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:t:u:s:v")) != -1) { |
671 |
while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:t:u:s:v")) != -1) { |
604 |
switch (ch) { |
672 |
switch (ch) { |
605 |
case 'A': |
673 |
case 'A': |
Lines 626-636
Link Here
|
626 |
case 'i': |
694 |
case 'i': |
627 |
session_id = strtol(optarg, &end, 10); |
695 |
session_id = strtol(optarg, &end, 10); |
628 |
if ((size_t)(end - optarg) != strlen(optarg)) |
696 |
if ((size_t)(end - optarg) != strlen(optarg)) |
629 |
errx(1, "trailing characters after session-id"); |
697 |
xo_errx(1, "trailing characters after session-id"); |
630 |
if (session_id < 0) |
698 |
if (session_id < 0) |
631 |
errx(1, "session-id cannot be negative"); |
699 |
xo_errx(1, "session-id cannot be negative"); |
632 |
if (session_id > UINT_MAX) |
700 |
if (session_id > UINT_MAX) |
633 |
errx(1, "session-id cannot be greater than %u", |
701 |
xo_errx(1, "session-id cannot be greater than %u", |
634 |
UINT_MAX); |
702 |
UINT_MAX); |
635 |
break; |
703 |
break; |
636 |
case 'n': |
704 |
case 'n': |
Lines 663-669
Link Here
|
663 |
if (Aflag + Mflag + Rflag + Lflag == 0) |
731 |
if (Aflag + Mflag + Rflag + Lflag == 0) |
664 |
Lflag = 1; |
732 |
Lflag = 1; |
665 |
if (Aflag + Mflag + Rflag + Lflag > 1) |
733 |
if (Aflag + Mflag + Rflag + Lflag > 1) |
666 |
errx(1, "at most one of -A, -M, -R, or -L may be specified"); |
734 |
xo_errx(1, "at most one of -A, -M, -R, or -L may be specified"); |
667 |
|
735 |
|
668 |
/* |
736 |
/* |
669 |
* Note that we ignore unneccessary/inapplicable "-c" flag; so that |
737 |
* Note that we ignore unneccessary/inapplicable "-c" flag; so that |
Lines 673-794
Link Here
|
673 |
if (Aflag != 0) { |
741 |
if (Aflag != 0) { |
674 |
if (aflag != 0) { |
742 |
if (aflag != 0) { |
675 |
if (portal != NULL) |
743 |
if (portal != NULL) |
676 |
errx(1, "-a and -p and mutually exclusive"); |
744 |
xo_errx(1, "-a and -p and mutually exclusive"); |
677 |
if (target != NULL) |
745 |
if (target != NULL) |
678 |
errx(1, "-a and -t and mutually exclusive"); |
746 |
xo_errx(1, "-a and -t and mutually exclusive"); |
679 |
if (user != NULL) |
747 |
if (user != NULL) |
680 |
errx(1, "-a and -u and mutually exclusive"); |
748 |
xo_errx(1, "-a and -u and mutually exclusive"); |
681 |
if (secret != NULL) |
749 |
if (secret != NULL) |
682 |
errx(1, "-a and -s and mutually exclusive"); |
750 |
xo_errx(1, "-a and -s and mutually exclusive"); |
683 |
if (nickname != NULL) |
751 |
if (nickname != NULL) |
684 |
errx(1, "-a and -n and mutually exclusive"); |
752 |
xo_errx(1, "-a and -n and mutually exclusive"); |
685 |
if (discovery_host != NULL) |
753 |
if (discovery_host != NULL) |
686 |
errx(1, "-a and -d and mutually exclusive"); |
754 |
xo_errx(1, "-a and -d and mutually exclusive"); |
687 |
} else if (nickname != NULL) { |
755 |
} else if (nickname != NULL) { |
688 |
if (portal != NULL) |
756 |
if (portal != NULL) |
689 |
errx(1, "-n and -p and mutually exclusive"); |
757 |
xo_errx(1, "-n and -p and mutually exclusive"); |
690 |
if (target != NULL) |
758 |
if (target != NULL) |
691 |
errx(1, "-n and -t and mutually exclusive"); |
759 |
xo_errx(1, "-n and -t and mutually exclusive"); |
692 |
if (user != NULL) |
760 |
if (user != NULL) |
693 |
errx(1, "-n and -u and mutually exclusive"); |
761 |
xo_errx(1, "-n and -u and mutually exclusive"); |
694 |
if (secret != NULL) |
762 |
if (secret != NULL) |
695 |
errx(1, "-n and -s and mutually exclusive"); |
763 |
xo_errx(1, "-n and -s and mutually exclusive"); |
696 |
if (discovery_host != NULL) |
764 |
if (discovery_host != NULL) |
697 |
errx(1, "-n and -d and mutually exclusive"); |
765 |
xo_errx(1, "-n and -d and mutually exclusive"); |
698 |
} else if (discovery_host != NULL) { |
766 |
} else if (discovery_host != NULL) { |
699 |
if (portal != NULL) |
767 |
if (portal != NULL) |
700 |
errx(1, "-d and -p and mutually exclusive"); |
768 |
xo_errx(1, "-d and -p and mutually exclusive"); |
701 |
if (target != NULL) |
769 |
if (target != NULL) |
702 |
errx(1, "-d and -t and mutually exclusive"); |
770 |
xo_errx(1, "-d and -t and mutually exclusive"); |
703 |
} else { |
771 |
} else { |
704 |
if (target == NULL && portal == NULL) |
772 |
if (target == NULL && portal == NULL) |
705 |
errx(1, "must specify -a, -n or -t/-p"); |
773 |
xo_errx(1, "must specify -a, -n or -t/-p"); |
706 |
|
774 |
|
707 |
if (target != NULL && portal == NULL) |
775 |
if (target != NULL && portal == NULL) |
708 |
errx(1, "-t must always be used with -p"); |
776 |
xo_errx(1, "-t must always be used with -p"); |
709 |
if (portal != NULL && target == NULL) |
777 |
if (portal != NULL && target == NULL) |
710 |
errx(1, "-p must always be used with -t"); |
778 |
xo_errx(1, "-p must always be used with -t"); |
711 |
} |
779 |
} |
712 |
|
780 |
|
713 |
if (user != NULL && secret == NULL) |
781 |
if (user != NULL && secret == NULL) |
714 |
errx(1, "-u must always be used with -s"); |
782 |
xo_errx(1, "-u must always be used with -s"); |
715 |
if (secret != NULL && user == NULL) |
783 |
if (secret != NULL && user == NULL) |
716 |
errx(1, "-s must always be used with -u"); |
784 |
xo_errx(1, "-s must always be used with -u"); |
717 |
|
785 |
|
718 |
if (session_id != -1) |
786 |
if (session_id != -1) |
719 |
errx(1, "-i cannot be used with -A"); |
787 |
xo_errx(1, "-i cannot be used with -A"); |
720 |
if (vflag != 0) |
788 |
if (vflag != 0) |
721 |
errx(1, "-v cannot be used with -A"); |
789 |
xo_errx(1, "-v cannot be used with -A"); |
722 |
|
790 |
|
723 |
} else if (Mflag != 0) { |
791 |
} else if (Mflag != 0) { |
724 |
if (session_id == -1) |
792 |
if (session_id == -1) |
725 |
errx(1, "-M requires -i"); |
793 |
xo_errx(1, "-M requires -i"); |
726 |
|
794 |
|
727 |
if (discovery_host != NULL) |
795 |
if (discovery_host != NULL) |
728 |
errx(1, "-M and -d are mutually exclusive"); |
796 |
xo_errx(1, "-M and -d are mutually exclusive"); |
729 |
if (aflag != 0) |
797 |
if (aflag != 0) |
730 |
errx(1, "-M and -a are mutually exclusive"); |
798 |
xo_errx(1, "-M and -a are mutually exclusive"); |
731 |
if (nickname != NULL) { |
799 |
if (nickname != NULL) { |
732 |
if (portal != NULL) |
800 |
if (portal != NULL) |
733 |
errx(1, "-n and -p and mutually exclusive"); |
801 |
xo_errx(1, "-n and -p and mutually exclusive"); |
734 |
if (target != NULL) |
802 |
if (target != NULL) |
735 |
errx(1, "-n and -t and mutually exclusive"); |
803 |
xo_errx(1, "-n and -t and mutually exclusive"); |
736 |
if (user != NULL) |
804 |
if (user != NULL) |
737 |
errx(1, "-n and -u and mutually exclusive"); |
805 |
xo_errx(1, "-n and -u and mutually exclusive"); |
738 |
if (secret != NULL) |
806 |
if (secret != NULL) |
739 |
errx(1, "-n and -s and mutually exclusive"); |
807 |
xo_errx(1, "-n and -s and mutually exclusive"); |
740 |
} |
808 |
} |
741 |
|
809 |
|
742 |
if (vflag != 0) |
810 |
if (vflag != 0) |
743 |
errx(1, "-v cannot be used with -M"); |
811 |
xo_errx(1, "-v cannot be used with -M"); |
744 |
|
812 |
|
745 |
} else if (Rflag != 0) { |
813 |
} else if (Rflag != 0) { |
746 |
if (user != NULL) |
814 |
if (user != NULL) |
747 |
errx(1, "-R and -u are mutually exclusive"); |
815 |
xo_errx(1, "-R and -u are mutually exclusive"); |
748 |
if (secret != NULL) |
816 |
if (secret != NULL) |
749 |
errx(1, "-R and -s are mutually exclusive"); |
817 |
xo_errx(1, "-R and -s are mutually exclusive"); |
750 |
if (discovery_host != NULL) |
818 |
if (discovery_host != NULL) |
751 |
errx(1, "-R and -d are mutually exclusive"); |
819 |
xo_errx(1, "-R and -d are mutually exclusive"); |
752 |
|
820 |
|
753 |
if (aflag != 0) { |
821 |
if (aflag != 0) { |
754 |
if (portal != NULL) |
822 |
if (portal != NULL) |
755 |
errx(1, "-a and -p and mutually exclusive"); |
823 |
xo_errx(1, "-a and -p and mutually exclusive"); |
756 |
if (target != NULL) |
824 |
if (target != NULL) |
757 |
errx(1, "-a and -t and mutually exclusive"); |
825 |
xo_errx(1, "-a and -t and mutually exclusive"); |
758 |
if (nickname != NULL) |
826 |
if (nickname != NULL) |
759 |
errx(1, "-a and -n and mutually exclusive"); |
827 |
xo_errx(1, "-a and -n and mutually exclusive"); |
760 |
} else if (nickname != NULL) { |
828 |
} else if (nickname != NULL) { |
761 |
if (portal != NULL) |
829 |
if (portal != NULL) |
762 |
errx(1, "-n and -p and mutually exclusive"); |
830 |
xo_errx(1, "-n and -p and mutually exclusive"); |
763 |
if (target != NULL) |
831 |
if (target != NULL) |
764 |
errx(1, "-n and -t and mutually exclusive"); |
832 |
xo_errx(1, "-n and -t and mutually exclusive"); |
765 |
} else if (target == NULL && portal == NULL) { |
833 |
} else if (target == NULL && portal == NULL) { |
766 |
errx(1, "must specify either -a, -n, -t, or -p"); |
834 |
xo_errx(1, "must specify either -a, -n, -t, or -p"); |
767 |
} |
835 |
} |
768 |
|
836 |
|
769 |
if (session_id != -1) |
837 |
if (session_id != -1) |
770 |
errx(1, "-i cannot be used with -R"); |
838 |
xo_errx(1, "-i cannot be used with -R"); |
771 |
if (vflag != 0) |
839 |
if (vflag != 0) |
772 |
errx(1, "-v cannot be used with -R"); |
840 |
xo_errx(1, "-v cannot be used with -R"); |
773 |
|
841 |
|
774 |
} else { |
842 |
} else { |
775 |
assert(Lflag != 0); |
843 |
assert(Lflag != 0); |
776 |
|
844 |
|
777 |
if (portal != NULL) |
845 |
if (portal != NULL) |
778 |
errx(1, "-L and -p and mutually exclusive"); |
846 |
xo_errx(1, "-L and -p and mutually exclusive"); |
779 |
if (target != NULL) |
847 |
if (target != NULL) |
780 |
errx(1, "-L and -t and mutually exclusive"); |
848 |
xo_errx(1, "-L and -t and mutually exclusive"); |
781 |
if (user != NULL) |
849 |
if (user != NULL) |
782 |
errx(1, "-L and -u and mutually exclusive"); |
850 |
xo_errx(1, "-L and -u and mutually exclusive"); |
783 |
if (secret != NULL) |
851 |
if (secret != NULL) |
784 |
errx(1, "-L and -s and mutually exclusive"); |
852 |
xo_errx(1, "-L and -s and mutually exclusive"); |
785 |
if (nickname != NULL) |
853 |
if (nickname != NULL) |
786 |
errx(1, "-L and -n and mutually exclusive"); |
854 |
xo_errx(1, "-L and -n and mutually exclusive"); |
787 |
if (discovery_host != NULL) |
855 |
if (discovery_host != NULL) |
788 |
errx(1, "-L and -d and mutually exclusive"); |
856 |
xo_errx(1, "-L and -d and mutually exclusive"); |
789 |
|
857 |
|
790 |
if (session_id != -1) |
858 |
if (session_id != -1) |
791 |
errx(1, "-i cannot be used with -L"); |
859 |
xo_errx(1, "-i cannot be used with -L"); |
792 |
} |
860 |
} |
793 |
|
861 |
|
794 |
iscsi_fd = open(ISCSI_PATH, O_RDWR); |
862 |
iscsi_fd = open(ISCSI_PATH, O_RDWR); |
Lines 801-807
Link Here
|
801 |
errno = saved_errno; |
869 |
errno = saved_errno; |
802 |
} |
870 |
} |
803 |
if (iscsi_fd < 0) |
871 |
if (iscsi_fd < 0) |
804 |
err(1, "failed to open %s", ISCSI_PATH); |
872 |
xo_err(1, "failed to open %s", ISCSI_PATH); |
805 |
|
873 |
|
806 |
if (Aflag != 0 && aflag != 0) { |
874 |
if (Aflag != 0 && aflag != 0) { |
807 |
conf = conf_new_from_file(conf_path); |
875 |
conf = conf_new_from_file(conf_path); |
Lines 812-818
Link Here
|
812 |
conf = conf_new_from_file(conf_path); |
880 |
conf = conf_new_from_file(conf_path); |
813 |
targ = target_find(conf, nickname); |
881 |
targ = target_find(conf, nickname); |
814 |
if (targ == NULL) |
882 |
if (targ == NULL) |
815 |
errx(1, "target %s not found in %s", |
883 |
xo_errx(1, "target %s not found in %s", |
816 |
nickname, conf_path); |
884 |
nickname, conf_path); |
817 |
|
885 |
|
818 |
if (Aflag != 0) |
886 |
if (Aflag != 0) |
Lines 829-835
Link Here
|
829 |
} else { |
897 |
} else { |
830 |
if (Aflag != 0 && target != NULL) { |
898 |
if (Aflag != 0 && target != NULL) { |
831 |
if (valid_iscsi_name(target) == false) |
899 |
if (valid_iscsi_name(target) == false) |
832 |
errx(1, "invalid target name \"%s\"", target); |
900 |
xo_errx(1, "invalid target name \"%s\"", target); |
833 |
} |
901 |
} |
834 |
conf = conf_new(); |
902 |
conf = conf_new(); |
835 |
targ = target_new(conf); |
903 |
targ = target_new(conf); |
Lines 854-865
Link Here
|
854 |
else |
922 |
else |
855 |
failed += kernel_list(iscsi_fd, targ, vflag); |
923 |
failed += kernel_list(iscsi_fd, targ, vflag); |
856 |
} |
924 |
} |
857 |
|
925 |
|
858 |
error = close(iscsi_fd); |
926 |
error = close(iscsi_fd); |
859 |
if (error != 0) |
927 |
if (error != 0) |
860 |
err(1, "close"); |
928 |
xo_err(1, "close"); |
861 |
|
929 |
|
862 |
if (failed > 0) |
930 |
if (failed > 0) |
863 |
return (1); |
931 |
return (1); |
|
|
932 |
|
933 |
xo_close_container("iscsictl"); |
934 |
xo_finish(); |
864 |
return (0); |
935 |
return (0); |
865 |
} |
936 |
} |