svn commit: r215700 - in stable/8: sbin/iscontrol
sys/dev/iscsi/initiator
Dag-Erling Smorgrav
des at FreeBSD.org
Mon Nov 22 19:02:31 UTC 2010
Author: des
Date: Mon Nov 22 19:02:30 2010
New Revision: 215700
URL: http://svn.freebsd.org/changeset/base/215700
Log:
MFC r209052, r210702, r211095, r211182, r212149: Fix a memory leak and
some potential deadlocks, increase the target limit from 4 to 64, and
numerous other scalability and stability improvements, including.
Submitted by: Daniel Braniss <danny at cs.huji.ac.il>
Sponsored by: Dansk Scanning A/S, Data Robotics Inc.
Deleted:
stable/8/sbin/iscontrol/pdu.h
Modified:
stable/8/sbin/iscontrol/Makefile
stable/8/sbin/iscontrol/auth_subr.c
stable/8/sbin/iscontrol/config.c
stable/8/sbin/iscontrol/fsm.c
stable/8/sbin/iscontrol/iscontrol.8
stable/8/sbin/iscontrol/iscontrol.c
stable/8/sbin/iscontrol/iscontrol.h
stable/8/sbin/iscontrol/iscsi.conf.5
stable/8/sbin/iscontrol/login.c
stable/8/sbin/iscontrol/misc.c
stable/8/sbin/iscontrol/pdu.c
stable/8/sys/dev/iscsi/initiator/isc_cam.c
stable/8/sys/dev/iscsi/initiator/isc_sm.c
stable/8/sys/dev/iscsi/initiator/isc_soc.c
stable/8/sys/dev/iscsi/initiator/isc_subr.c
stable/8/sys/dev/iscsi/initiator/iscsi.c
stable/8/sys/dev/iscsi/initiator/iscsi.h
stable/8/sys/dev/iscsi/initiator/iscsi_subr.c
stable/8/sys/dev/iscsi/initiator/iscsivar.h
Directory Properties:
stable/8/sbin/iscontrol/ (props changed)
Modified: stable/8/sbin/iscontrol/Makefile
==============================================================================
--- stable/8/sbin/iscontrol/Makefile Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/Makefile Mon Nov 22 19:02:30 2010 (r215700)
@@ -4,8 +4,10 @@ SRCS= iscontrol.c pdu.c fsm.c config.c l
PROG= iscontrol
DPADD= ${LIBCAM} ${LIBMD}
LDADD= -lcam -lmd
+S= ${.CURDIR}/../../sys
-CFLAGS += -I${.CURDIR}/../../sys/dev/iscsi/initiator
+WARNS?= 3
+CFLAGS += -I$S
#CFLAGS += -g -DDEBUG
MAN= iscsi.conf.5 iscontrol.8
Modified: stable/8/sbin/iscontrol/auth_subr.c
==============================================================================
--- stable/8/sbin/iscontrol/auth_subr.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/auth_subr.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD$");
#include <md5.h>
#include <sha.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static int
@@ -152,7 +152,7 @@ chapDigest(char *ap, char id, char *cp,
}
char *
-genChapChallenge(char *encoding, int len)
+genChapChallenge(char *encoding, uint len)
{
int fd;
unsigned char tmp[1024];
Modified: stable/8/sbin/iscontrol/config.c
==============================================================================
--- stable/8/sbin/iscontrol/config.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/config.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2009 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
/*
@@ -94,6 +94,11 @@ __FBSDID("$FreeBSD$");
#define OPT_iqn 34
#define OPT_sockbufsize 35
+/*
+ | sentinel
+ */
+#define OPT_end 0
+
#define _OFF(v) ((int)&((isc_opt_t *)NULL)->v)
#define _E(u, s, v) {.usage=u, .scope=s, .name=#v, .tokenID=OPT_##v}
@@ -145,7 +150,7 @@ textkey_t keyMap[] = {
_E(U_LO, S_SW, sessionType),
- {0}
+ _E(0, 0, end)
};
#define _OPT_INT(w) strtol((char *)w, NULL, 0)
@@ -154,7 +159,7 @@ textkey_t keyMap[] = {
static __inline int
_OPT_BOOL(char *w)
{
- if(isalpha(*w))
+ if(isalpha((unsigned char)*w))
return strcasecmp(w, "TRUE") == 0;
else
return _OPT_INT(w);
@@ -244,13 +249,12 @@ getConfig(FILE *fd, char *key, char **Ar
len = 0;
state = 0;
while((lp = getline(fd)) != NULL) {
- for(; isspace(*lp); lp++)
+ for(; isspace((unsigned char)*lp); lp++)
;
switch(state) {
case 0:
if((p = strchr(lp, '{')) != NULL) {
- n = 0;
- while((--p > lp) && *p && isspace(*p));
+ while((--p > lp) && *p && isspace((unsigned char)*p));
n = p - lp;
if(len && strncmp(lp, key, MAX(n, len)) == 0)
state = 2;
@@ -273,7 +277,7 @@ getConfig(FILE *fd, char *key, char **Ar
}
- for(p = &lp[strlen(lp)-1]; isspace(*p); p--)
+ for(p = &lp[strlen(lp)-1]; isspace((unsigned char)*p); p--)
*p = 0;
if((*nargs)-- > 0)
*ar++ = strdup(lp);
@@ -352,9 +356,9 @@ parseArgs(int nargs, char **args, isc_op
continue;
*p = 0;
v = p + 1;
- while(isspace(*--p))
+ while(isspace((unsigned char)*--p))
*p = 0;
- while(isspace(*v))
+ while(isspace((unsigned char)*v))
v++;
if((tk = keyLookup(*ar)) == NULL)
continue;
Modified: stable/8/sbin/iscontrol/fsm.c
==============================================================================
--- stable/8/sbin/iscontrol/fsm.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/fsm.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -56,7 +56,7 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
typedef enum {
@@ -99,26 +99,26 @@ tcpConnect(isess_t *sess)
#ifdef notyet
{
time_t sec;
- // make sure we are not in a loop
- // XXX: this code has to be tested
- sec = time(0) - sess->reconnect_time;
- if(sec > (5*60)) {
- // if we've been connected for more that 5 minutes
- // then just reconnect
- sess->reconnect_time = sec;
- sess->reconnect_cnt1 = 0;
- }
- else {
- //
- sess->reconnect_cnt1++;
- if((sec / sess->reconnect_cnt1) < 2) {
- // if less that 2 seconds from the last reconnect
- // we are most probably looping
- syslog(LOG_CRIT, "too many reconnects %d", sess->reconnect_cnt1);
- return 0;
+ // make sure we are not in a loop
+ // XXX: this code has to be tested
+ sec = time(0) - sess->reconnect_time;
+ if(sec > (5*60)) {
+ // if we've been connected for more that 5 minutes
+ // then just reconnect
+ sess->reconnect_time = sec;
+ sess->reconnect_cnt1 = 0;
+ }
+ else {
+ //
+ sess->reconnect_cnt1++;
+ if((sec / sess->reconnect_cnt1) < 2) {
+ // if less that 2 seconds from the last reconnect
+ // we are most probably looping
+ syslog(LOG_CRIT, "too many reconnects %d", sess->reconnect_cnt1);
+ return 0;
+ }
}
}
- }
#endif
sess->reconnect_cnt++;
}
@@ -140,13 +140,13 @@ tcpConnect(isess_t *sess)
if (soc == -1)
continue;
- // from Patrick.Guelat at imp.ch:
- // iscontrol can be called without waiting for the socket entry to time out
- val = 1;
+ // from Patrick.Guelat at imp.ch:
+ // iscontrol can be called without waiting for the socket entry to time out
+ val = 1;
if(setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, &val, (socklen_t)sizeof(val)) < 0) {
- fprintf(stderr, "Cannot set socket SO_REUSEADDR %d: %s\n\n",
- errno, strerror(errno));
- }
+ fprintf(stderr, "Cannot set socket SO_REUSEADDR %d: %s\n\n",
+ errno, strerror(errno));
+ }
if(connect(soc, res->ai_addr, res->ai_addrlen) == 0)
break;
@@ -196,7 +196,7 @@ tcpConnect(isess_t *sess)
}
sess->flags |= SESS_CONNECTED;
return T1;
- }
+ }
fprintf(stderr, "errno=%d\n", sv_errno);
perror("connect");
@@ -289,7 +289,7 @@ startSession(isess_t *sess)
// XXX: this has to go
size_t n;
n = sizeof(sess->isid);
- if(sysctlbyname("net.iscsi.isid", (void *)sess->isid, (size_t *)&n, 0, 0) != 0)
+ if(sysctlbyname("net.iscsi_initiator.isid", (void *)sess->isid, (size_t *)&n, 0, 0) != 0)
perror("sysctlbyname");
}
if(ioctl(fd, ISCSISETSES, &n)) {
@@ -343,29 +343,29 @@ trap(int sig)
}
}
-static void
+static int
doCAM(isess_t *sess)
{
char pathstr[1024];
union ccb *ccb;
- int i;
+ int i, n;
if(ioctl(sess->fd, ISCSIGETCAM, &sess->cam) != 0) {
syslog(LOG_WARNING, "ISCSIGETCAM failed: %d", errno);
- return;
+ return 0;
}
- debug(2, "nluns=%d", sess->cam.target_nluns);
+ debug(1, "nluns=%d", sess->cam.target_nluns);
/*
| for now will do this for each lun ...
*/
- for(i = 0; i < sess->cam.target_nluns; i++) {
+ for(n = i = 0; i < sess->cam.target_nluns; i++) {
debug(2, "CAM path_id=%d target_id=%d target_lun=%d",
sess->cam.path_id, sess->cam.target_id, sess->cam.target_lun[i]);
sess->camdev = cam_open_btl(sess->cam.path_id, sess->cam.target_id,
- sess->cam.target_lun[i], O_RDWR, NULL);
+ i, O_RDWR, NULL);
if(sess->camdev == NULL) {
- syslog(LOG_WARNING, "%s", cam_errbuf);
+ //syslog(LOG_WARNING, "%s", cam_errbuf);
debug(3, "%s", cam_errbuf);
continue;
}
@@ -378,20 +378,21 @@ doCAM(isess_t *sess)
ccb->ccb_h.func_code = XPT_REL_SIMQ;
ccb->crs.release_flags = RELSIM_ADJUST_OPENINGS;
ccb->crs.openings = sess->op->tags;
-
if(cam_send_ccb(sess->camdev, ccb) < 0)
- syslog(LOG_WARNING, "%s", cam_errbuf);
+ debug(2, "%s", cam_errbuf);
else
if((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
syslog(LOG_WARNING, "XPT_REL_SIMQ CCB failed");
// cam_error_print(sess->camdev, ccb, CAM_ESF_ALL, CAM_EPF_ALL, stderr);
}
- else
+ else {
+ n++;
syslog(LOG_INFO, "%s tagged openings now %d\n", pathstr, ccb->crs.openings);
-
+ }
cam_freeccb(ccb);
cam_close_device(sess->camdev);
}
+ return n;
}
static trans_t
@@ -417,7 +418,15 @@ supervise(isess_t *sess)
perror("daemon");
exit(1);
}
+ if(sess->op->pidfile != NULL) {
+ FILE *pidf;
+ pidf = fopen(sess->op->pidfile, "w");
+ if(pidf != NULL) {
+ fprintf(pidf, "%d\n", getpid());
+ fclose(pidf);
+ }
+ }
openlog("iscontrol", LOG_CONS|LOG_PERROR|LOG_PID|LOG_NDELAY, LOG_KERN);
syslog(LOG_INFO, "running");
@@ -426,7 +435,11 @@ supervise(isess_t *sess)
perror("ISCSISTART");
return -1;
}
- doCAM(sess);
+ if(doCAM(sess) == 0) {
+ syslog(LOG_WARNING, "no device found");
+ ioctl(sess->fd, ISCSISTOP);
+ return T15;
+ }
}
else {
@@ -449,7 +462,8 @@ supervise(isess_t *sess)
sess->flags |= SESS_FULLFEATURE;
sess->flags &= ~(SESS_REDIRECT | SESS_RECONNECT);
- printf("iscontrol: supervise starting main loop\n");
+ if(vflag)
+ printf("iscontrol: supervise starting main loop\n");
/*
| the main loop - actually do nothing
| all the work is done inside the kernel
@@ -468,14 +482,14 @@ supervise(isess_t *sess)
}
if(sess->flags & SESS_DISCONNECT) {
- val = 0;
- if(ioctl(sess->fd, ISCSISTOP, &val)) {
- perror("ISCSISTOP");
- }
sess->flags &= ~SESS_FULLFEATURE;
return T9;
}
else {
+ val = 0;
+ if(ioctl(sess->fd, ISCSISTOP, &val)) {
+ perror("ISCSISTOP");
+ }
sess->flags |= SESS_INITIALLOGIN1;
}
return T8;
@@ -490,7 +504,7 @@ handledDiscoveryResp(isess_t *sess, pdu_
debug_called(3);
len = pp->ds_len;
- ptr = pp->ds;
+ ptr = pp->ds_addr;
while(len > 0) {
if(*ptr != 0)
printf("%s\n", ptr);
@@ -579,8 +593,13 @@ doLogin(isess_t *sess)
static int
handleLogoutResp(isess_t *sess, pdu_t *pp)
{
- if(sess->flags & SESS_DISCONNECT)
+ if(sess->flags & SESS_DISCONNECT) {
+ int val = 0;
+ if(ioctl(sess->fd, ISCSISTOP, &val)) {
+ perror("ISCSISTOP");
+ }
return 0;
+ }
return T13;
}
@@ -610,7 +629,7 @@ typedef enum {
S1, S2, /*S3,*/ S4, S5, S6, S7, S8
} state_t;
-#if 0
+/**
S1: FREE
S2: XPT_WAIT
S4: IN_LOGIN
@@ -652,7 +671,7 @@ typedef enum {
| +-----\ /--->\ / T14 |
| ------- --+----+------+T17
+---------------------------+
-#endif
+*/
int
fsm(isc_opt_t *op)
Modified: stable/8/sbin/iscontrol/iscontrol.8
==============================================================================
--- stable/8/sbin/iscontrol/iscontrol.8 Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/iscontrol.8 Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2007-2008 Daniel Braniss <danny at cs.huji.ac.il>
+.\" Copyright (c) 2007-2010 Daniel Braniss <danny at cs.huji.ac.il>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -32,11 +32,12 @@
.Nd login/negotiator/control for an iSCSI initiator session
.Sh SYNOPSIS
.Nm
-.Op Fl vd
+.Op Fl dv
.Oo
-.Op Fl c Ar file
+.Fl c Ar file
.Op Fl n Ar nickname
.Oc
+.Op Fl p Ar pidfile
.Op Fl t Ar target
.Op Ar variable Ns = Ns Ar value
.Sh DESCRIPTION
@@ -57,26 +58,29 @@ It will terminate/logout the session
when a SIGHUP signal is received.
The flags are as follows:
.Bl -tag -width variable=value
-.It Fl v
-verbose mode.
-.It Fl d
-do a
-.Em discovery session
-and exit.
.It Fl c Ar file
a file containing configuration
.Em key-options ,
see
-.Xr iscsi.conf 5
+.Xr iscsi.conf 5 .
+.It Fl d
+do a
+.Em discovery session
+and exit.
.It Fl n Ar nickname
if
.Sy -c file
is specified, then search for the block named
.Em nickname
in that file, see
-.Xr iscsi.conf 5
+.Xr iscsi.conf 5 .
+.It Fl p Ar pidfile
+will write the process ID of the session to the specified
+.Em pidfile
.It Fl t Ar target
-is the target's IP address or name
+the target's IP address or name.
+.It Fl v
+verbose mode.
.It Ar variable Ns = Ns Ar value
see
.Xr iscsi.conf 5
@@ -86,13 +90,13 @@ possible values.
.Sh EXAMPLES
.Dl iscontrol -dt myiscsitarget
.Pp
-will start a
+will start a
.Em discovery session
with the target and
print to stdout the list of available targetnames/targetadresses.
Note: this listing does not necessarily mean availability, since
depending on the target configuration, a discovery session might
-not need login/access permission, but a
+not need login/access permission, but a
.Em full session
certainly does.
.sp
Modified: stable/8/sbin/iscontrol/iscontrol.c
==============================================================================
--- stable/8/sbin/iscontrol/iscontrol.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/iscontrol.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -53,15 +53,11 @@ __FBSDID("$FreeBSD$");
#include <time.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
-#define USAGE "[-v] [-d] [-c config] [-n name] [-t target] "
-#define OPTIONS "vdc:t:n:"
-
-#ifndef DEBUG
-//int vflag;
-#endif
+#define USAGE "[-v] [-d] [-c config] [-n name] [-t target] [-p pidfile]"
+#define OPTIONS "vdc:t:n:p:"
token_t AuthMethods[] = {
{"None", NONE},
@@ -70,14 +66,14 @@ token_t AuthMethods[] = {
{"SPKM2", SPKM2},
{"SRP", SRP},
{"CHAP", CHAP},
- {0}
+ {0, 0}
};
token_t DigestMethods[] = {
{"None", 0},
{"CRC32", 1},
{"CRC32C", 1},
- {0}
+ {0, 0}
};
u_char isid[6 + 6];
@@ -128,7 +124,7 @@ int
main(int cc, char **vv)
{
int ch, disco;
- char *pname, *p, *q, *ta, *kw;
+ char *pname, *pidfile, *p, *q, *ta, *kw;
isc_opt_t *op;
FILE *fd;
@@ -141,6 +137,7 @@ main(int cc, char **vv)
kw = ta = 0;
disco = 0;
+ pidfile = NULL;
while((ch = getopt(cc, vv, OPTIONS)) != -1) {
switch(ch) {
@@ -163,6 +160,9 @@ main(int cc, char **vv)
case 'n':
kw = optarg;
break;
+ case 'p':
+ pidfile = optarg;
+ break;
default:
badu:
fprintf(stderr, "Usage: %s %s\n", pname, USAGE);
@@ -225,7 +225,7 @@ main(int cc, char **vv)
op->sessionType = "Discovery";
op->targetName = 0;
}
-
+ op->pidfile = pidfile;
fsm(op);
exit(0);
Modified: stable/8/sbin/iscontrol/iscontrol.h
==============================================================================
--- stable/8/sbin/iscontrol/iscontrol.h Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/iscontrol.h Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -154,7 +154,7 @@ void parseArgs(int nargs, char **args, i
void parseConfig(FILE *fd, char *key, isc_opt_t *op);
char *chapDigest(char *ap, char id, char *cp, char *chapSecret);
-char *genChapChallenge(char *encoding, int len);
+char *genChapChallenge(char *encoding, uint len);
int str2bin(char *str, char **rsp);
char *bin2str(char *fmt, unsigned char *md, int blen);
Modified: stable/8/sbin/iscontrol/iscsi.conf.5
==============================================================================
--- stable/8/sbin/iscontrol/iscsi.conf.5 Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/iscsi.conf.5 Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,4 +1,4 @@
-.\" Copyright (c) 2007-2008 Daniel Braniss <danny at cs.huji.ac.il>
+.\" Copyright (c) 2007-2010 Daniel Braniss <danny at cs.huji.ac.il>
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -68,6 +68,7 @@ Only CRC32C is implemented.
Default is none.
.It Cm DataDigest
same as for HeaderDigest, but on the data part of the iSCSI PDU.
+(not yet tested)
.It Cm MaxConnections
is the number of simultaneous connections per session,
currently only 1.
@@ -205,6 +206,6 @@ ISCSI RFC 3720
.\"Sh AUTHORS
.Sh BUGS
Some options have not been implemented, either they were found
-to be unecessary, or not understood, this can change in the future.
+to be unnecessary, or not understood, this can change in the future.
.br
The tags opening value is difficult to calculate, use wisely.
Modified: stable/8/sbin/iscontrol/login.c
==============================================================================
--- stable/8/sbin/iscontrol/login.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/login.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static char *status_class1[] = {
@@ -107,7 +107,7 @@ getkeyval(char *key, pdu_t *pp)
debug_called(3);
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
klen = strlen(key);
while(len > klen) {
if(strncmp(key, ptr, klen) == 0)
@@ -163,7 +163,7 @@ processParams(isess_t *sess, pdu_t *pp)
debug_called(3);
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
while(len > 0) {
if(vflag > 1)
printf("got: len=%d %s\n", len, ptr);
@@ -233,7 +233,7 @@ handleLoginResp(isess_t *sess, pdu_t *pp
st_class = status >> 8;
if(status) {
- int st_detail = status & 0xff;
+ uint st_detail = status & 0xff;
switch(st_class) {
case 1: // Redirect
Modified: stable/8/sbin/iscontrol/misc.c
==============================================================================
--- stable/8/sbin/iscontrol/misc.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/misc.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <string.h>
+#include <dev/iscsi/initiator/iscsi.h>
+#include "iscontrol.h"
+
static inline char
c2b(unsigned char c)
{
Modified: stable/8/sbin/iscontrol/pdu.c
==============================================================================
--- stable/8/sbin/iscontrol/pdu.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sbin/iscontrol/pdu.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -43,7 +43,7 @@ __FBSDID("$FreeBSD$");
#include <stdarg.h>
#include <camlib.h>
-#include "iscsi.h"
+#include <dev/iscsi/initiator/iscsi.h>
#include "iscontrol.h"
static void pukeText(char *it, pdu_t *pp);
@@ -85,7 +85,7 @@ sendPDU(isess_t *sess, pdu_t *pp, handle
int res;
pp->ahs_size = 8 * 1024;
- if((pp->ahs = malloc(pp->ahs_size)) == NULL) {
+ if((pp->ahs_addr = malloc(pp->ahs_size)) == NULL) {
fprintf(stderr, "out of mem!");
return -1;
}
@@ -126,16 +126,16 @@ addText(pdu_t *pp, char *fmt, ...)
if((pp->ds_len + len) > pp->ds_size) {
u_char *np;
- np = realloc(pp->ds, pp->ds_size + len + FUDGE);
+ np = realloc(pp->ds_addr, pp->ds_size + len + FUDGE);
if(np == NULL) {
free(str);
//XXX: out of memory!
return -1;
}
- pp->ds = np;
+ pp->ds_addr = np;
pp->ds_size += len + FUDGE;
}
- memcpy(pp->ds + pp->ds_len, str, len);
+ memcpy(pp->ds_addr + pp->ds_len, str, len);
pp->ds_len += len;
free(str);
return len;
@@ -145,12 +145,12 @@ void
freePDU(pdu_t *pp)
{
if(pp->ahs_size)
- free(pp->ahs);
+ free(pp->ahs_addr);
if(pp->ds_size)
- free(pp->ds);
+ free(pp->ds_addr);
bzero(&pp->ipdu, sizeof(union ipdu_u));
- pp->ahs = NULL;
- pp->ds = NULL;
+ pp->ahs_addr = NULL;
+ pp->ds_addr = NULL;
pp->ahs_size = 0;
pp->ds_size = pp->ds_len = 0;
}
@@ -163,7 +163,7 @@ pukeText(char *it, pdu_t *pp)
size_t len, n;
len = pp->ds_len;
- ptr = (char *)pp->ds;
+ ptr = (char *)pp->ds_addr;
cmd = pp->ipdu.bhs.opcode;
printf("%s: cmd=0x%x len=%d\n", it, cmd, (int)len);
Modified: stable/8/sys/dev/iscsi/initiator/isc_cam.c
==============================================================================
--- stable/8/sys/dev/iscsi/initiator/isc_cam.c Mon Nov 22 19:01:47 2010 (r215699)
+++ stable/8/sys/dev/iscsi/initiator/isc_cam.c Mon Nov 22 19:02:30 2010 (r215700)
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Daniel Braniss <danny at cs.huji.ac.il>
+ * Copyright (c) 2005-2010 Daniel Braniss <danny at cs.huji.ac.il>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -24,7 +24,9 @@
* SUCH DAMAGE.
*
*/
-
+/*
+ | $Id: isc_cam.c 998 2009-12-20 10:32:45Z danny $
+ */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@@ -43,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <sys/mbuf.h>
#include <sys/uio.h>
#include <sys/sysctl.h>
+#include <sys/sx.h>
#include <cam/cam.h>
#include <cam/cam_ccb.h>
@@ -53,52 +56,70 @@ __FBSDID("$FreeBSD$");
#include <dev/iscsi/initiator/iscsi.h>
#include <dev/iscsi/initiator/iscsivar.h>
-// XXX: untested/incomplete
-void
-ic_freeze(isc_session_t *sp)
+static void
+_inq(struct cam_sim *sim, union ccb *ccb)
{
+ struct ccb_pathinq *cpi = &ccb->cpi;
+ isc_session_t *sp = cam_sim_softc(sim);
+
debug_called(8);
-#if 0
- sdebug(2, "freezing path=%p", sp->cam_path == NULL? 0: sp->cam_path);
- if((sp->cam_path != NULL) && !(sp->flags & ISC_FROZEN)) {
- xpt_freeze_devq(sp->cam_path, 1);
- }
+ debug(3, "sid=%d target=%d lun=%d", sp->sid, ccb->ccb_h.target_id, ccb->ccb_h.target_lun);
+
+ cpi->version_num = 1; /* XXX??? */
+ cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE | PI_WIDE_32;
+ cpi->target_sprt = 0;
+ cpi->hba_misc = 0;
+ cpi->hba_eng_cnt = 0;
+ cpi->max_target = 0; //ISCSI_MAX_TARGETS - 1;
+ cpi->initiator_id = ISCSI_MAX_TARGETS;
+ cpi->max_lun = sp->opt.maxluns - 1;
+ cpi->bus_id = cam_sim_bus(sim);
+ cpi->base_transfer_speed = 3300; // 40000; // XXX:
+ strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
+ strncpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
+ strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
+ cpi->unit_number = cam_sim_unit(sim);
+ cpi->ccb_h.status = CAM_REQ_CMP;
+#if defined(KNOB_VALID_ADDRESS)
+ cpi->transport = XPORT_ISCSI;
+ cpi->transport_version = 0;
#endif
- sp->flags |= ISC_FROZEN;
}
-// XXX: untested/incomplete
-void
-ic_release(isc_session_t *sp)
+static __inline int
+_scsi_encap(struct cam_sim *sim, union ccb *ccb)
{
- debug_called(8);
-#if 0
- sdebug(2, "release path=%p", sp->cam_path == NULL? 0: sp->cam_path);
- if((sp->cam_path != NULL) && (sp->flags & ISC_FROZEN)) {
- xpt_release_devq(sp->cam_path, 1, TRUE);
- }
+ int ret;
+
+#if __FreeBSD_version < 700000
+ ret = scsi_encap(sim, ccb);
+#else
+ isc_session_t *sp = cam_sim_softc(sim);
+
+ mtx_unlock(&sp->cam_mtx);
+ ret = scsi_encap(sim, ccb);
+ mtx_lock(&sp->cam_mtx);
#endif
- sp->flags &= ~ISC_FROZEN;
+ return ret;
}
void
ic_lost_target(isc_session_t *sp, int target)
{
- struct isc_softc *isp = sp->isc;
-
debug_called(8);
- sdebug(2, "target=%d", target);
+ sdebug(2, "lost target=%d", target);
+
if(sp->cam_path != NULL) {
- mtx_lock(&isp->cam_mtx);
+ mtx_lock(&sp->cam_mtx);
xpt_async(AC_LOST_DEVICE, sp->cam_path, NULL);
xpt_free_path(sp->cam_path);
- mtx_unlock(&isp->cam_mtx);
+ mtx_unlock(&sp->cam_mtx);
sp->cam_path = 0; // XXX
}
}
static void
-_scan_callback(struct cam_periph *periph, union ccb *ccb)
+scan_callback(struct cam_periph *periph, union ccb *ccb)
{
isc_session_t *sp = (isc_session_t *)ccb->ccb_h.spriv_ptr0;
@@ -106,63 +127,52 @@ _scan_callback(struct cam_periph *periph
free(ccb, M_TEMP);
- if(sp->flags & ISC_FFPWAIT) {
- sp->flags &= ~ISC_FFPWAIT;
+ if(sp->flags & ISC_SCANWAIT) {
+ sp->flags &= ~ISC_SCANWAIT;
wakeup(sp);
}
}
-static void
-_scan_target(isc_session_t *sp, int target)
+static int
+ic_scan(isc_session_t *sp)
{
- union ccb *ccb;
+ union ccb *ccb;
debug_called(8);
- sdebug(2, "target=%d", target);
+ sdebug(2, "scanning sid=%d", sp->sid);
if((ccb = malloc(sizeof(union ccb), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
xdebug("scan failed (can't allocate CCB)");
- return;
+ return ENOMEM; // XXX
}
- CAM_LOCK(sp->isc);
- xpt_setup_ccb(&ccb->ccb_h, sp->cam_path, 5/*priority (low)*/);
- ccb->ccb_h.func_code = XPT_SCAN_BUS;
- ccb->ccb_h.cbfcnp = _scan_callback;
- ccb->crcn.flags = CAM_FLAG_NONE;
- ccb->ccb_h.spriv_ptr0 = sp;
- xpt_action(ccb);
- CAM_UNLOCK(sp->isc);
-}
-
-int
-ic_fullfeature(struct cdev *dev)
-{
- struct isc_softc *isp = dev->si_drv1;
- isc_session_t *sp = (isc_session_t *)dev->si_drv2;
+ sp->flags &= ~ISC_CAMDEVS;
+ sp->flags |= ISC_SCANWAIT;
- debug_called(8);
- sdebug(3, "dev=%d sc=%p", dev2unit(dev), isp);
-
- sp->flags &= ~ISC_FFPHASE;
- sp->flags |= ISC_FFPWAIT;
-
- CAM_LOCK(isp);
- if(xpt_create_path(&sp->cam_path, xpt_periph, cam_sim_path(sp->isc->cam_sim),
- sp->sid, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
+ CAM_LOCK(sp);
+ if(xpt_create_path(&sp->cam_path, xpt_periph, cam_sim_path(sp->cam_sim),
+ 0, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
xdebug("can't create cam path");
- CAM_UNLOCK(isp);
+ CAM_UNLOCK(sp);
+ free(ccb, M_TEMP);
return ENODEV; // XXX
}
- CAM_UNLOCK(isp);
+ xpt_setup_ccb(&ccb->ccb_h, sp->cam_path, 5/*priority (low)*/);
+ ccb->ccb_h.func_code = XPT_SCAN_BUS;
+ ccb->ccb_h.cbfcnp = scan_callback;
+ ccb->crcn.flags = CAM_FLAG_NONE;
+ ccb->ccb_h.spriv_ptr0 = sp;
- _scan_target(sp, sp->sid);
+ xpt_action(ccb);
+ CAM_UNLOCK(sp);
- while(sp->flags & ISC_FFPWAIT)
+ while(sp->flags & ISC_SCANWAIT)
tsleep(sp, PRIBIO, "ffp", 5*hz); // the timeout time should
// be configurable
+ sdebug(2, "# of luns=%d", sp->target_nluns);
+
if(sp->target_nluns > 0) {
- sp->flags |= ISC_FFPHASE;
+ sp->flags |= ISC_CAMDEVS;
return 0;
}
@@ -170,110 +180,25 @@ ic_fullfeature(struct cdev *dev)
}
static void
-_inq(struct cam_sim *sim, union ccb *ccb, int maxluns)
-{
- struct ccb_pathinq *cpi = &ccb->cpi;
-
- debug_called(4);
-
- cpi->version_num = 1; /* XXX??? */
- cpi->hba_inquiry = PI_SDTR_ABLE | PI_TAG_ABLE | PI_WIDE_32;
- cpi->target_sprt = 0;
- cpi->hba_misc = 0;
- cpi->hba_eng_cnt = 0;
- cpi->max_target = ISCSI_MAX_TARGETS - 1;
- cpi->initiator_id = ISCSI_MAX_TARGETS;
- cpi->max_lun = maxluns;
- cpi->bus_id = cam_sim_bus(sim);
- cpi->base_transfer_speed = 3300;
- strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
- strncpy(cpi->hba_vid, "iSCSI", HBA_IDLEN);
- strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
- cpi->unit_number = cam_sim_unit(sim);
- cpi->transport = XPORT_ISCSI;
- cpi->transport_version = 0;
- cpi->ccb_h.status = CAM_REQ_CMP;
-}
-
-static __inline int
-_scsi_encap(struct cam_sim *sim, union ccb *ccb)
-{
- int ret;
-
-#if __FreeBSD_version < 700000
- ret = scsi_encap(sim, ccb);
-#else
- struct isc_softc *isp = (struct isc_softc *)cam_sim_softc(sim);
-
- mtx_unlock(&isp->cam_mtx);
- ret = scsi_encap(sim, ccb);
- mtx_lock(&isp->cam_mtx);
-#endif
- return ret;
-}
-
-static void
ic_action(struct cam_sim *sim, union ccb *ccb)
{
+ isc_session_t *sp = cam_sim_softc(sim);
struct ccb_hdr *ccb_h = &ccb->ccb_h;
- struct isc_softc *isp = (struct isc_softc *)cam_sim_softc(sim);
- isc_session_t *sp;
debug_called(8);
- if((ccb_h->target_id != CAM_TARGET_WILDCARD) && (ccb_h->target_id < MAX_SESSIONS))
- sp = isp->sessions[ccb_h->target_id];
- else
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-all
mailing list