View | Details | Raw Unified | Return to bug 198396 | Differences between
and this patch

Collapse All | Expand All

(-)./Makefile (+1 lines)
Lines 7-12 Link Here
7
MAN=		iscsi.conf.5 iscsictl.8
7
MAN=		iscsi.conf.5 iscsictl.8
8
8
9
LIBADD=		cam util
9
LIBADD=		cam util
10
LDADD=		-lxo
10
11
11
YFLAGS+=	-v
12
YFLAGS+=	-v
12
LFLAGS+=	-i
13
LFLAGS+=	-i
(-)./iscsictl.c (-138 / +209 lines)
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
}
(-)./parse.y (-28 / +29 lines)
Lines 34-45 Link Here
34
#include <sys/types.h>
34
#include <sys/types.h>
35
#include <sys/stat.h>
35
#include <sys/stat.h>
36
#include <assert.h>
36
#include <assert.h>
37
#include <err.h>
38
#include <stdio.h>
37
#include <stdio.h>
39
#include <stdint.h>
38
#include <stdint.h>
40
#include <stdlib.h>
39
#include <stdlib.h>
41
#include <string.h>
40
#include <string.h>
42
41
42
#include <libxo/xo.h>
43
43
#include "iscsictl.h"
44
#include "iscsictl.h"
44
45
45
extern FILE *yyin;
46
extern FILE *yyin;
Lines 77-83 Link Here
77
target:		STR OPENING_BRACKET target_entries CLOSING_BRACKET
78
target:		STR OPENING_BRACKET target_entries CLOSING_BRACKET
78
	{
79
	{
79
		if (target_find(conf, $1) != NULL)
80
		if (target_find(conf, $1) != NULL)
80
			errx(1, "duplicated target %s", $1);
81
			xo_errx(1, "duplicated target %s", $1);
81
		target->t_nickname = $1;
82
		target->t_nickname = $1;
82
		target = target_new(conf);
83
		target = target_new(conf);
83
	}
84
	}
Lines 127-133 Link Here
127
target_name:	TARGET_NAME EQUALS STR
128
target_name:	TARGET_NAME EQUALS STR
128
	{
129
	{
129
		if (target->t_name != NULL)
130
		if (target->t_name != NULL)
130
			errx(1, "duplicated TargetName at line %d", lineno);
131
			xo_errx(1, "duplicated TargetName at line %d", lineno);
131
		target->t_name = $3;
132
		target->t_name = $3;
132
	}
133
	}
133
	;
134
	;
Lines 135-141 Link Here
135
target_address:	TARGET_ADDRESS EQUALS STR
136
target_address:	TARGET_ADDRESS EQUALS STR
136
	{
137
	{
137
		if (target->t_address != NULL)
138
		if (target->t_address != NULL)
138
			errx(1, "duplicated TargetAddress at line %d", lineno);
139
			xo_errx(1, "duplicated TargetAddress at line %d", lineno);
139
		target->t_address = $3;
140
		target->t_address = $3;
140
	}
141
	}
141
	;
142
	;
Lines 143-149 Link Here
143
initiator_name:	INITIATOR_NAME EQUALS STR
144
initiator_name:	INITIATOR_NAME EQUALS STR
144
	{
145
	{
145
		if (target->t_initiator_name != NULL)
146
		if (target->t_initiator_name != NULL)
146
			errx(1, "duplicated InitiatorName at line %d", lineno);
147
			xo_errx(1, "duplicated InitiatorName at line %d", lineno);
147
		target->t_initiator_name = $3;
148
		target->t_initiator_name = $3;
148
	}
149
	}
149
	;
150
	;
Lines 151-157 Link Here
151
initiator_address:	INITIATOR_ADDRESS EQUALS STR
152
initiator_address:	INITIATOR_ADDRESS EQUALS STR
152
	{
153
	{
153
		if (target->t_initiator_address != NULL)
154
		if (target->t_initiator_address != NULL)
154
			errx(1, "duplicated InitiatorAddress at line %d", lineno);
155
			xo_errx(1, "duplicated InitiatorAddress at line %d", lineno);
155
		target->t_initiator_address = $3;
156
		target->t_initiator_address = $3;
156
	}
157
	}
157
	;
158
	;
Lines 159-165 Link Here
159
initiator_alias:	INITIATOR_ALIAS EQUALS STR
160
initiator_alias:	INITIATOR_ALIAS EQUALS STR
160
	{
161
	{
161
		if (target->t_initiator_alias != NULL)
162
		if (target->t_initiator_alias != NULL)
162
			errx(1, "duplicated InitiatorAlias at line %d", lineno);
163
			xo_errx(1, "duplicated InitiatorAlias at line %d", lineno);
163
		target->t_initiator_alias = $3;
164
		target->t_initiator_alias = $3;
164
	}
165
	}
165
	;
166
	;
Lines 167-173 Link Here
167
user:		USER EQUALS STR
168
user:		USER EQUALS STR
168
	{
169
	{
169
		if (target->t_user != NULL)
170
		if (target->t_user != NULL)
170
			errx(1, "duplicated chapIName at line %d", lineno);
171
			xo_errx(1, "duplicated chapIName at line %d", lineno);
171
		target->t_user = $3;
172
		target->t_user = $3;
172
	}
173
	}
173
	;
174
	;
Lines 175-181 Link Here
175
secret:		SECRET EQUALS STR
176
secret:		SECRET EQUALS STR
176
	{
177
	{
177
		if (target->t_secret != NULL)
178
		if (target->t_secret != NULL)
178
			errx(1, "duplicated chapSecret at line %d", lineno);
179
			xo_errx(1, "duplicated chapSecret at line %d", lineno);
179
		target->t_secret = $3;
180
		target->t_secret = $3;
180
	}
181
	}
181
	;
182
	;
Lines 183-189 Link Here
183
mutual_user:	MUTUAL_USER EQUALS STR
184
mutual_user:	MUTUAL_USER EQUALS STR
184
	{
185
	{
185
		if (target->t_mutual_user != NULL)
186
		if (target->t_mutual_user != NULL)
186
			errx(1, "duplicated tgtChapName at line %d", lineno);
187
			xo_errx(1, "duplicated tgtChapName at line %d", lineno);
187
		target->t_mutual_user = $3;
188
		target->t_mutual_user = $3;
188
	}
189
	}
189
	;
190
	;
Lines 191-197 Link Here
191
mutual_secret:	MUTUAL_SECRET EQUALS STR
192
mutual_secret:	MUTUAL_SECRET EQUALS STR
192
	{
193
	{
193
		if (target->t_mutual_secret != NULL)
194
		if (target->t_mutual_secret != NULL)
194
			errx(1, "duplicated tgtChapSecret at line %d", lineno);
195
			xo_errx(1, "duplicated tgtChapSecret at line %d", lineno);
195
		target->t_mutual_secret = $3;
196
		target->t_mutual_secret = $3;
196
	}
197
	}
197
	;
198
	;
Lines 199-211 Link Here
199
auth_method:	AUTH_METHOD EQUALS STR
200
auth_method:	AUTH_METHOD EQUALS STR
200
	{
201
	{
201
		if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
202
		if (target->t_auth_method != AUTH_METHOD_UNSPECIFIED)
202
			errx(1, "duplicated AuthMethod at line %d", lineno);
203
			xo_errx(1, "duplicated AuthMethod at line %d", lineno);
203
		if (strcasecmp($3, "none") == 0)
204
		if (strcasecmp($3, "none") == 0)
204
			target->t_auth_method = AUTH_METHOD_NONE;
205
			target->t_auth_method = AUTH_METHOD_NONE;
205
		else if (strcasecmp($3, "chap") == 0)
206
		else if (strcasecmp($3, "chap") == 0)
206
			target->t_auth_method = AUTH_METHOD_CHAP;
207
			target->t_auth_method = AUTH_METHOD_CHAP;
207
		else
208
		else
208
			errx(1, "invalid AuthMethod at line %d; "
209
			xo_errx(1, "invalid AuthMethod at line %d; "
209
			    "must be either \"none\" or \"CHAP\"", lineno);
210
			    "must be either \"none\" or \"CHAP\"", lineno);
210
	}
211
	}
211
	;
212
	;
Lines 213-225 Link Here
213
header_digest:	HEADER_DIGEST EQUALS STR
214
header_digest:	HEADER_DIGEST EQUALS STR
214
	{
215
	{
215
		if (target->t_header_digest != DIGEST_UNSPECIFIED)
216
		if (target->t_header_digest != DIGEST_UNSPECIFIED)
216
			errx(1, "duplicated HeaderDigest at line %d", lineno);
217
			xo_errx(1, "duplicated HeaderDigest at line %d", lineno);
217
		if (strcasecmp($3, "none") == 0)
218
		if (strcasecmp($3, "none") == 0)
218
			target->t_header_digest = DIGEST_NONE;
219
			target->t_header_digest = DIGEST_NONE;
219
		else if (strcasecmp($3, "CRC32C") == 0)
220
		else if (strcasecmp($3, "CRC32C") == 0)
220
			target->t_header_digest = DIGEST_CRC32C;
221
			target->t_header_digest = DIGEST_CRC32C;
221
		else
222
		else
222
			errx(1, "invalid HeaderDigest at line %d; "
223
			xo_errx(1, "invalid HeaderDigest at line %d; "
223
			    "must be either \"none\" or \"CRC32C\"", lineno);
224
			    "must be either \"none\" or \"CRC32C\"", lineno);
224
	}
225
	}
225
	;
226
	;
Lines 227-239 Link Here
227
data_digest:	DATA_DIGEST EQUALS STR
228
data_digest:	DATA_DIGEST EQUALS STR
228
	{
229
	{
229
		if (target->t_data_digest != DIGEST_UNSPECIFIED)
230
		if (target->t_data_digest != DIGEST_UNSPECIFIED)
230
			errx(1, "duplicated DataDigest at line %d", lineno);
231
			xo_errx(1, "duplicated DataDigest at line %d", lineno);
231
		if (strcasecmp($3, "none") == 0)
232
		if (strcasecmp($3, "none") == 0)
232
			target->t_data_digest = DIGEST_NONE;
233
			target->t_data_digest = DIGEST_NONE;
233
		else if (strcasecmp($3, "CRC32C") == 0)
234
		else if (strcasecmp($3, "CRC32C") == 0)
234
			target->t_data_digest = DIGEST_CRC32C;
235
			target->t_data_digest = DIGEST_CRC32C;
235
		else
236
		else
236
			errx(1, "invalid DataDigest at line %d; "
237
			xo_errx(1, "invalid DataDigest at line %d; "
237
			    "must be either \"none\" or \"CRC32C\"", lineno);
238
			    "must be either \"none\" or \"CRC32C\"", lineno);
238
	}
239
	}
239
	;
240
	;
Lines 241-253 Link Here
241
session_type:	SESSION_TYPE EQUALS STR
242
session_type:	SESSION_TYPE EQUALS STR
242
	{
243
	{
243
		if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
244
		if (target->t_session_type != SESSION_TYPE_UNSPECIFIED)
244
			errx(1, "duplicated SessionType at line %d", lineno);
245
			xo_errx(1, "duplicated SessionType at line %d", lineno);
245
		if (strcasecmp($3, "normal") == 0)
246
		if (strcasecmp($3, "normal") == 0)
246
			target->t_session_type = SESSION_TYPE_NORMAL;
247
			target->t_session_type = SESSION_TYPE_NORMAL;
247
		else if (strcasecmp($3, "discovery") == 0)
248
		else if (strcasecmp($3, "discovery") == 0)
248
			target->t_session_type = SESSION_TYPE_DISCOVERY;
249
			target->t_session_type = SESSION_TYPE_DISCOVERY;
249
		else
250
		else
250
			errx(1, "invalid SessionType at line %d; "
251
			xo_errx(1, "invalid SessionType at line %d; "
251
			    "must be either \"normal\" or \"discovery\"", lineno);
252
			    "must be either \"normal\" or \"discovery\"", lineno);
252
	}
253
	}
253
	;
254
	;
Lines 255-261 Link Here
255
offload:	OFFLOAD EQUALS STR
256
offload:	OFFLOAD EQUALS STR
256
	{
257
	{
257
		if (target->t_offload != NULL)
258
		if (target->t_offload != NULL)
258
			errx(1, "duplicated offload at line %d", lineno);
259
			xo_errx(1, "duplicated offload at line %d", lineno);
259
		target->t_offload = $3;
260
		target->t_offload = $3;
260
	}
261
	}
261
	;
262
	;
Lines 263-282 Link Here
263
protocol:	PROTOCOL EQUALS STR
264
protocol:	PROTOCOL EQUALS STR
264
	{
265
	{
265
		if (target->t_protocol != PROTOCOL_UNSPECIFIED)
266
		if (target->t_protocol != PROTOCOL_UNSPECIFIED)
266
			errx(1, "duplicated protocol at line %d", lineno);
267
			xo_errx(1, "duplicated protocol at line %d", lineno);
267
		if (strcasecmp($3, "iscsi") == 0)
268
		if (strcasecmp($3, "iscsi") == 0)
268
			target->t_protocol = PROTOCOL_ISCSI;
269
			target->t_protocol = PROTOCOL_ISCSI;
269
		else if (strcasecmp($3, "iser") == 0)
270
		else if (strcasecmp($3, "iser") == 0)
270
			target->t_protocol = PROTOCOL_ISER;
271
			target->t_protocol = PROTOCOL_ISER;
271
		else
272
		else
272
			errx(1, "invalid protocol at line %d; "
273
			xo_errx(1, "invalid protocol at line %d; "
273
			    "must be either \"iscsi\" or \"iser\"", lineno);
274
			    "must be either \"iscsi\" or \"iser\"", lineno);
274
	}
275
	}
275
	;
276
	;
276
277
277
ignored:	IGNORED EQUALS STR
278
ignored:	IGNORED EQUALS STR
278
	{
279
	{
279
		warnx("obsolete statement ignored at line %d", lineno);
280
		xo_warnx("obsolete statement ignored at line %d", lineno);
280
	}
281
	}
281
	;
282
	;
282
283
Lines 286-292 Link Here
286
yyerror(const char *str)
287
yyerror(const char *str)
287
{
288
{
288
289
289
	errx(1, "error in configuration file at line %d near '%s': %s",
290
	xo_errx(1, "error in configuration file at line %d near '%s': %s",
290
	    lineno, yytext, str);
291
	    lineno, yytext, str);
291
}
292
}
292
293
Lines 298-316 Link Here
298
299
299
	error = stat(path, &sb);
300
	error = stat(path, &sb);
300
	if (error != 0) {
301
	if (error != 0) {
301
		warn("stat");
302
		xo_warn("stat");
302
		return;
303
		return;
303
	}
304
	}
304
	if (sb.st_mode & S_IWOTH) {
305
	if (sb.st_mode & S_IWOTH) {
305
		warnx("%s is world-writable", path);
306
		xo_warnx("%s is world-writable", path);
306
	} else if (sb.st_mode & S_IROTH) {
307
	} else if (sb.st_mode & S_IROTH) {
307
		warnx("%s is world-readable", path);
308
		xo_warnx("%s is world-readable", path);
308
	} else if (sb.st_mode & S_IXOTH) {
309
	} else if (sb.st_mode & S_IXOTH) {
309
		/*
310
		/*
310
		 * Ok, this one doesn't matter, but still do it,
311
		 * Ok, this one doesn't matter, but still do it,
311
		 * just for consistency.
312
		 * just for consistency.
312
		 */
313
		 */
313
		warnx("%s is world-executable", path);
314
		xo_warnx("%s is world-executable", path);
314
	}
315
	}
315
316
316
	/*
317
	/*
(-)./periphs.c (-9 / +18 lines)
Lines 46-52 Link Here
46
#include <inttypes.h>
46
#include <inttypes.h>
47
#include <limits.h>
47
#include <limits.h>
48
#include <fcntl.h>
48
#include <fcntl.h>
49
#include <err.h>
50
49
51
#include <cam/cam.h>
50
#include <cam/cam.h>
52
#include <cam/cam_debug.h>
51
#include <cam/cam_debug.h>
Lines 58-63 Link Here
58
#include <cam/scsi/smp_all.h>
57
#include <cam/scsi/smp_all.h>
59
#include <cam/ata/ata_all.h>
58
#include <cam/ata/ata_all.h>
60
#include <camlib.h>
59
#include <camlib.h>
60
#include <libxo/xo.h>
61
61
62
#include "iscsictl.h"
62
#include "iscsictl.h"
63
63
Lines 70-79 Link Here
70
	int skip_bus, skip_device;
70
	int skip_bus, skip_device;
71
71
72
	if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
72
	if ((fd = open(XPT_DEVICE, O_RDWR)) == -1) {
73
		warn("couldn't open %s", XPT_DEVICE);
73
		xo_warn("couldn't open %s", XPT_DEVICE);
74
		return;
74
		return;
75
	}
75
	}
76
76
		
77
	/*
77
	/*
78
	 * First, iterate over the whole list to find the bus.
78
	 * First, iterate over the whole list to find the bus.
79
	 */
79
	 */
Lines 89-95 Link Here
89
	ccb.cdm.match_buf_len = bufsize;
89
	ccb.cdm.match_buf_len = bufsize;
90
	ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
90
	ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
91
	if (ccb.cdm.matches == NULL) {
91
	if (ccb.cdm.matches == NULL) {
92
		warnx("can't malloc memory for matches");
92
		xo_warnx("can't malloc memory for matches");
93
		close(fd);
93
		close(fd);
94
		return;
94
		return;
95
	}
95
	}
Lines 104-127 Link Here
104
104
105
	skip_bus = 1;
105
	skip_bus = 1;
106
	skip_device = 1;
106
	skip_device = 1;
107
107
	
108
	int lun_no=0;
109
	xo_open_list("lun");
108
	/*
110
	/*
109
	 * We do the ioctl multiple times if necessary, in case there are
111
	 * We do the ioctl multiple times if necessary, in case there are
110
	 * more than 100 nodes in the EDT.
112
	 * more than 100 nodes in the EDT.
111
	 */
113
	 */
112
	do {
114
	do {
113
		if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
115
		if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
114
			warn("error sending CAMIOCOMMAND ioctl");
116
			xo_warn("error sending CAMIOCOMMAND ioctl");
115
			break;
117
			break;
116
		}
118
		}
117
119
118
		if ((ccb.ccb_h.status != CAM_REQ_CMP)
120
		if ((ccb.ccb_h.status != CAM_REQ_CMP)
119
		 || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
121
		 || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
120
		    && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
122
		    && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
121
			warnx("got CAM error %#x, CDM error %d\n",
123
			xo_warnx("got CAM error %#x, CDM error %d\n",
122
			      ccb.ccb_h.status, ccb.cdm.status);
124
			      ccb.ccb_h.status, ccb.cdm.status);
123
			break;
125
			break;
124
		}
126
		}
127
		
128
		
125
129
126
		for (i = 0; i < ccb.cdm.num_matches; i++) {
130
		for (i = 0; i < ccb.cdm.num_matches; i++) {
127
			switch (ccb.cdm.matches[i].type) {
131
			switch (ccb.cdm.matches[i].type) {
Lines 166-174 Link Here
166
				if (strcmp(periph_result->periph_name, "pass") == 0)
170
				if (strcmp(periph_result->periph_name, "pass") == 0)
167
					continue;
171
					continue;
168
172
169
				fprintf(stdout, "%s%d ",
173
				xo_open_instance("lun");	
174
				xo_emit("{e:id/%d}", lun_no);
175
				xo_emit("{Vq:device/%s%d} ",
170
					periph_result->periph_name,
176
					periph_result->periph_name,
171
					periph_result->unit_number);
177
					periph_result->unit_number);
178
				xo_close_instance("lun");
179
				lun_no++;
172
180
173
				break;
181
				break;
174
			}
182
			}
Lines 180-186 Link Here
180
188
181
	} while ((ccb.ccb_h.status == CAM_REQ_CMP)
189
	} while ((ccb.ccb_h.status == CAM_REQ_CMP)
182
		&& (ccb.cdm.status == CAM_DEV_MATCH_MORE));
190
		&& (ccb.cdm.status == CAM_DEV_MATCH_MORE));
183
191
	
192
	xo_close_list("lun");
184
	close(fd);
193
	close(fd);
185
}
194
}
186
195

Return to bug 198396