Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Jan 2012 09:58:36 +0100
From:      =?windows-1252?Q?Hans_Petter_Selasky?= <hans.petter.selasky@bitfrost.no>
To:        =?windows-1252?Q?svn-src-head=40freebsd.org?= <svn-src-head@freebsd.org>,  =?windows-1252?Q?svn-src-all=40freebsd.org?= <svn-src-all@freebsd.org>,  =?windows-1252?Q?src-committers=40freebsd.org?= <src-committers@freebsd.org>,  =?windows-1252?Q?Kenneth_D._Merry?= <ken@FreeBSD.org>
Subject:   RE: svn commit: r229997 - in head: share/examples/scsi_target sys/amd64/conf sys/cam/ctl sys/cam/scsi sys/conf sys/dev/ata sys/dev/ciss sys/i386/conf sys/ia64/conf sys/sparc64/conf usr.bin usr.bin/ctls...
Message-ID:  <zarafa.4f0ea0bc.7115.4be8e2091dfed731@eric2.bitfrost>
In-Reply-To: <201201120034.q0C0YXrq084182@svn.freebsd.org>
References:  <201201120034.q0C0YXrq084182@svn.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,=0D=0A=0D=0A=A0=0D=0A=0D=0ADoes the cam target layer support attach/de=
tach of logical units=3F=0D=0A=0D=0A=A0=0D=0A=0D=0ACan it be used with US=
B target mode=3F=0D=0A=0D=0A=A0=0D=0A=0D=0A--HPS=0D=0A=A0=0D=0A-----Origi=
nal message-----=0D=0ATo:src-committers@freebsd.org; svn-src-all@freebsd.=
org; svn-src-head@freebsd.org;=20=0D=0AFrom:Kenneth D. Merry <ken@FreeBSD=
=2Eorg>=0D=0ASent:Thu 12-01-2012 01:35=0D=0ASubject:svn commit: r229997 -=
 in head: share/examples/scsi_target sys/amd64/conf sys/cam/ctl sys/cam/s=
csi sys/conf sys/dev/ata sys/dev/ciss sys/i386/conf sys/ia64/conf sys/spa=
rc64/conf usr.bin usr.bin/ctls...=0D=0AAuthor: ken=0D=0ADate: Thu Jan 12 =
00:34:33 2012=0D=0ANew Revision: 229997=0D=0AURL: http://svn.freebsd.org/=
changeset/base/229997=0D=0A=0D=0ALog:=0D=0A=A0Add the CAM Target Layer (C=
TL).=0D=0A=A0=0D=0A=A0CTL is a disk and processor device emulation subsys=
tem originally written=0D=0A=A0for Copan Systems under Linux starting in =
2003. =A0It has been shipping in=0D=0A=A0Copan (now SGI) products since 2=
005.=0D=0A=A0=0D=0A=A0It was ported to FreeBSD in 2008, and thanks to an =
agreement between SGI=0D=0A=A0(who acquired Copan's assets in 2010) and S=
pectra Logic in 2010, CTL is=0D=0A=A0available under a BSD-style license.=
 =A0The intent behind the agreement was=0D=0A=A0that Spectra would work t=
o get CTL into the FreeBSD tree.=0D=0A=A0=0D=0A=A0Some CTL features:=0D=0A=
=A0=0D=0A=A0 - Disk and processor device emulation.=0D=0A=A0 - Tagged que=
ueing=0D=0A=A0 - SCSI task attribute support (ordered, head of queue, sim=
ple tags)=0D=0A=A0 - SCSI implicit command ordering support. =A0(e.g. if =
a read follows a mode=0D=0A=A0 =A0 select, the read will be blocked until=
 the mode select completes.)=0D=0A=A0 - Full task management support (abo=
rt, LUN reset, target reset, etc.)=0D=0A=A0 - Support for multiple ports=0D=
=0A=A0 - Support for multiple simultaneous initiators=0D=0A=A0 - Support =
for multiple simultaneous backing stores=0D=0A=A0 - Persistent reservatio=
n support=0D=0A=A0 - Mode sense/select support=0D=0A=A0 - Error injection=
 support=0D=0A=A0 - High Availability support (1)=0D=0A=A0 - All I/O hand=
led in-kernel, no userland context switch overhead.=0D=0A=A0=0D=0A=A0(1) =
HA Support is just an API stub, and needs much more to be fully=0D=0A=A0 =
=A0 =A0functional.=0D=0A=A0=0D=0A=A0ctl.c:The core of CTL. =A0Command han=
dlers and processing,=0D=0A=A0character driver, and HA support are here.=0D=
=0A=A0=0D=0A=A0ctl.h:Basic function declarations and data structures.=0D=0A=
=A0=0D=0A=A0ctl_backend.c,=0D=0A=A0ctl_backend.h:The basic CTL backend AP=
I.=0D=0A=A0=0D=0A=A0ctl_backend_block.c,=0D=0A=A0ctl_backend_block.h:The =
block and file backend. =A0This allows for using=0D=0A=A0a disk or a file=
 as the backing store for a LUN.=0D=0A=A0Multiple threads are started to =
do I/O to the=0D=0A=A0backing device, primarily because the VFS API=0D=0A=
=A0requires that to get any concurrency.=0D=0A=A0=0D=0A=A0ctl_backend_ram=
disk.c:A "fake" ramdisk backend. =A0It only allocates a=0D=0A=A0small amo=
unt of memory to act as a source and sink=0D=0A=A0for reads and writes fr=
om an initiator. =A0Therefore=0D=0A=A0it cannot be used for any real data=
, but it can be=0D=0A=A0used to test for throughput. =A0It can also be us=
ed=0D=0A=A0to test initiators' support for extremely large LUNs.=0D=0A=A0=
=0D=0A=A0ctl_cmd_table.c:This is a table with all 256 possible SCSI opcod=
es,=0D=0A=A0and command handler functions defined for supported=0D=0A=A0o=
pcodes.=0D=0A=A0=0D=0A=A0ctl_debug.h:Debugging support.=0D=0A=A0=0D=0A=A0=
ctl_error.c,=0D=0A=A0ctl_error.h:CTL-specific wrappers around the CAM sen=
se building=0D=0A=A0functions.=0D=0A=A0=0D=0A=A0ctl_frontend.c,=0D=0A=A0c=
tl_frontend.h:These files define the basic CTL frontend port API.=0D=0A=A0=
=0D=0A=A0ctl_frontend_cam_sim.c:This is a CTL frontend port that is also =
a CAM SIM.=0D=0A=A0This frontend allows for using CTL without any=0D=0A=A0=
target-capable hardware. =A0So any LUNs you create in=0D=0A=A0CTL are vis=
ible in CAM via this port.=0D=0A=A0=0D=0A=A0ctl_frontend_internal.c,=0D=0A=
=A0ctl_frontend_internal.h:=0D=0A=A0This is a frontend port written for C=
opan to do=0D=0A=A0some system-specific tasks that required sending=0D=0A=
=A0commands into CTL from inside the kernel. =A0This=0D=0A=A0isn't entire=
ly relevant to FreeBSD in general,=0D=0A=A0but can perhaps be repurposed.=
=0D=0A=A0=0D=0A=A0ctl_ha.h:This is a stubbed-out High Availability API. =A0=
Much=0D=0A=A0more is needed for full HA support. =A0See the=0D=0A=A0comme=
nts in the header and the description of what=0D=0A=A0is needed in the RE=
ADME.ctl.txt file for more=0D=0A=A0details.=0D=0A=A0=0D=0A=A0ctl_io.h:Thi=
s defines most of the core CTL I/O structures.=0D=0A=A0union ctl_io is co=
nceptually very similar to CAM's=0D=0A=A0union ccb.=0D=0A=A0=0D=0A=A0ctl_=
ioctl.h:This defines all ioctls available through the CTL=0D=0A=A0charact=
er device, and the data structures needed=0D=0A=A0for those ioctls.=0D=0A=
=A0=0D=0A=A0ctl_mem_pool.c,=0D=0A=A0ctl_mem_pool.h:Generic memory pool im=
plementation used by the=0D=0A=A0internal frontend.=0D=0A=A0=0D=0A=A0ctl_=
private.h:Private data structres (e.g. CTL softc) and=0D=0A=A0function pr=
ototypes. =A0This also includes the SCSI=0D=0A=A0vendor and product names=
 used by CTL.=0D=0A=A0=0D=0A=A0ctl_scsi_all.c,=0D=0A=A0ctl_scsi_all.h:CTL=
 wrappers around CAM sense printing functions.=0D=0A=A0=0D=0A=A0ctl_ser_t=
able.c:Command serialization table. =A0This defines what=0D=0A=A0happens =
when one type of command is followed by=0D=0A=A0another type of command.=0D=
=0A=A0=0D=0A=A0ctl_util.c,=0D=0A=A0ctl_util.h:CTL utility functions, prim=
arily designed to be=0D=0A=A0used from userland. =A0See ctladm for the pr=
imary=0D=0A=A0consumer of these functions. =A0These include CDB=0D=0A=A0b=
uilding functions.=0D=0A=A0=0D=0A=A0scsi_ctl.c:CAM target peripheral driv=
er and CTL frontend port.=0D=0A=A0This is the path into CTL for commands =
from=0D=0A=A0target-capable hardware/SIMs.=0D=0A=A0=0D=0A=A0README.ctl.tx=
t:CTL code features, roadmap, to-do list.=0D=0A=A0=0D=0A=A0usr.sbin/Makef=
ile:Add ctladm.=0D=0A=A0=0D=0A=A0ctladm/Makefile,=0D=0A=A0ctladm/ctladm.8=
,=0D=0A=A0ctladm/ctladm.c,=0D=0A=A0ctladm/ctladm.h,=0D=0A=A0ctladm/util.c=
:ctladm(8) is the CTL management utility.=0D=0A=A0It fills a role similar=
 to camcontrol(8).=0D=0A=A0It allow configuring LUNs, issuing commands,=0D=
=0A=A0injecting errors and various other control=0D=0A=A0functions.=0D=0A=
=A0=0D=0A=A0usr.bin/Makefile:Add ctlstat.=0D=0A=A0=0D=0A=A0ctlstat/Makefi=
le=0D=0A=A0ctlstat/ctlstat.8,=0D=0A=A0ctlstat/ctlstat.c:ctlstat(8) fills =
a role similar to iostat(8).=0D=0A=A0It reports I/O statistics for CTL.=0D=
=0A=A0=0D=0A=A0sys/conf/files:Add CTL files.=0D=0A=A0=0D=0A=A0sys/conf/NO=
TES:Add device ctl.=0D=0A=A0=0D=0A=A0sys/cam/scsi_all.h:To conform to mor=
e recent specs, the inquiry CDB=0D=0A=A0length field is now 2 bytes long.=
=0D=0A=A0=0D=0A=A0Add several mode page definitions for CTL.=0D=0A=A0=0D=0A=
=A0sys/cam/scsi_all.c:Handle the new 2 byte inquiry length.=0D=0A=A0=0D=0A=
=A0sys/dev/ciss/ciss.c,=0D=0A=A0sys/dev/ata/atapi-cam.c,=0D=0A=A0sys/cam/=
scsi/scsi_targ_bh.c,=0D=0A=A0scsi_target/scsi_cmds.c,=0D=0A=A0mlxcontrol/=
interface.c:Update for 2 byte inquiry length field.=0D=0A=A0=0D=0A=A0scsi=
_da.h:Add versions of the format and rigid disk pages=0D=0A=A0that are in=
 a more reasonable format for CTL.=0D=0A=A0=0D=0A=A0amd64/conf/GENERIC,=0D=
=0A=A0i386/conf/GENERIC,=0D=0A=A0ia64/conf/GENERIC,=0D=0A=A0sparc64/conf/=
GENERIC:Add device ctl.=0D=0A=A0=0D=0A=A0i386/conf/PAE:The CTL frontend S=
IM at least does not compile=0D=0A=A0cleanly on PAE.=0D=0A=A0=0D=0A=A0Spo=
nsored by:Copan Systems, SGI and Spectra Logic=0D=0A=A0MFC after:1 month=0D=
=0A=0D=0AAdded:=0D=0A=A0head/sys/cam/ctl/=0D=0A=A0head/sys/cam/ctl/README=
=2Ectl.txt =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl.c =A0=
 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl.h =A0 (contents, =
props changed)=0D=0A=A0head/sys/cam/ctl/ctl_backend.c =A0 (contents, prop=
s changed)=0D=0A=A0head/sys/cam/ctl/ctl_backend.h =A0 (contents, props ch=
anged)=0D=0A=A0head/sys/cam/ctl/ctl_backend_block.c =A0 (contents, props =
changed)=0D=0A=A0head/sys/cam/ctl/ctl_backend_block.h =A0 (contents, prop=
s changed)=0D=0A=A0head/sys/cam/ctl/ctl_backend_ramdisk.c =A0 (contents, =
props changed)=0D=0A=A0head/sys/cam/ctl/ctl_cmd_table.c =A0 (contents, pr=
ops changed)=0D=0A=A0head/sys/cam/ctl/ctl_debug.h =A0 (contents, props ch=
anged)=0D=0A=A0head/sys/cam/ctl/ctl_error.c =A0 (contents, props changed)=
=0D=0A=A0head/sys/cam/ctl/ctl_error.h =A0 (contents, props changed)=0D=0A=
=A0head/sys/cam/ctl/ctl_frontend.c =A0 (contents, props changed)=0D=0A=A0=
head/sys/cam/ctl/ctl_frontend.h =A0 (contents, props changed)=0D=0A=A0hea=
d/sys/cam/ctl/ctl_frontend_cam_sim.c =A0 (contents, props changed)=0D=0A=A0=
head/sys/cam/ctl/ctl_frontend_internal.c =A0 (contents, props changed)=0D=
=0A=A0head/sys/cam/ctl/ctl_frontend_internal.h =A0 (contents, props chang=
ed)=0D=0A=A0head/sys/cam/ctl/ctl_ha.h =A0 (contents, props changed)=0D=0A=
=A0head/sys/cam/ctl/ctl_io.h =A0 (contents, props changed)=0D=0A=A0head/s=
ys/cam/ctl/ctl_ioctl.h =A0 (contents, props changed)=0D=0A=A0head/sys/cam=
/ctl/ctl_mem_pool.c =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ct=
l/ctl_mem_pool.h =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/c=
tl_private.h =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl_s=
csi_all.c =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl_scsi=
_all.h =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl_ser_tab=
le.c =A0 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl_util.c =A0=
 (contents, props changed)=0D=0A=A0head/sys/cam/ctl/ctl_util.h =A0 (conte=
nts, props changed)=0D=0A=A0head/sys/cam/ctl/scsi_ctl.c =A0 (contents, pr=
ops changed)=0D=0A=A0head/usr.bin/ctlstat/=0D=0A=A0head/usr.bin/ctlstat/M=
akefile =A0 (contents, props changed)=0D=0A=A0head/usr.bin/ctlstat/ctlsta=
t.8 =A0 (contents, props changed)=0D=0A=A0head/usr.bin/ctlstat/ctlstat.c =
=A0 (contents, props changed)=0D=0A=A0head/usr.sbin/ctladm/=0D=0A=A0head/=
usr.sbin/ctladm/Makefile =A0 (contents, props changed)=0D=0A=A0head/usr.s=
bin/ctladm/ctladm.8 =A0 (contents, props changed)=0D=0A=A0head/usr.sbin/c=
tladm/ctladm.c =A0 (contents, props changed)=0D=0A=A0head/usr.sbin/ctladm=
/ctladm.h =A0 (contents, props changed)=0D=0A=A0head/usr.sbin/ctladm/util=
=2Ec =A0 (contents, props changed)=0D=0AModified:=0D=0A=A0head/share/exam=
ples/scsi_target/scsi_cmds.c=0D=0A=A0head/sys/amd64/conf/GENERIC=0D=0A=A0=
head/sys/cam/scsi/scsi_all.c=0D=0A=A0head/sys/cam/scsi/scsi_all.h=0D=0A=A0=
head/sys/cam/scsi/scsi_da.h=0D=0A=A0head/sys/cam/scsi/scsi_targ_bh.c=0D=0A=
=A0head/sys/conf/NOTES=0D=0A=A0head/sys/conf/files=0D=0A=A0head/sys/dev/a=
ta/atapi-cam.c=0D=0A=A0head/sys/dev/ciss/ciss.c=0D=0A=A0head/sys/i386/con=
f/GENERIC=0D=0A=A0head/sys/i386/conf/PAE=0D=0A=A0head/sys/ia64/conf/GENER=
IC=0D=0A=A0head/sys/sparc64/conf/GENERIC=0D=0A=A0head/usr.bin/Makefile=0D=
=0A=A0head/usr.sbin/Makefile=0D=0A=A0head/usr.sbin/mlxcontrol/interface.c=
=0D=0A=0D=0AModified: head/share/examples/scsi_target/scsi_cmds.c=0D=0A=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=0D=0A--- head/share/examples/scsi_target/scsi_cmds.cThu Jan 12 00:=
05:35 2012(r229996)=0D=0A+++ head/share/examples/scsi_target/scsi_cmds.cT=
hu Jan 12 00:34:33 2012(r229997)=0D=0A@@ -328,7 +328,7 @@ tcmd_inquiry(st=
ruct ccb_accept_tio *atio=0D=0Abcopy(&inq_data, ctio->data_ptr, sizeof(in=
q_data));=0D=0Actio->dxfer_len =3D inq_data.additional_length + 4;=0D=0Ac=
tio->dxfer_len =3D min(ctio->dxfer_len,=0D=0A- =A0 =A0 =A0SCSI_CDB6_LEN(i=
nq->length));=0D=0A+ =A0 =A0 =A0scsi_2btoul(inq->length));=0D=0Actio->ccb=
_h.flags |=3D CAM_DIR_IN | CAM_SEND_STATUS;=0D=0Actio->scsi_status =3D SC=
SI_STATUS_OK;=0D=0A}=0D=0A=0D=0AModified: head/sys/amd64/conf/GENERIC=0D=0A=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=0D=0A--- head/sys/amd64/conf/GENERICThu Jan 12 00:05:35 2012(r2=
29996)=0D=0A+++ head/sys/amd64/conf/GENERICThu Jan 12 00:34:33 2012(r2299=
97)=0D=0A@@ -131,7 +131,8 @@ deviceda# Direct Access (disks)=0D=0Adevices=
a# Sequential Access (tape etc)=0D=0Adevicecd# CD=0D=0Adevicepass# Passth=
rough device (direct ATA/SCSI access)=0D=0A-deviceses# SCSI Environmental=
 Services (and SAF-TE)=0D=0A+deviceses# Enclosure Services (SES and SAF-T=
E)=0D=0A+devicectl# CAM Target Layer=0D=0A=0D=0A# RAID controllers interf=
aced to the SCSI subsystem=0D=0Adeviceamr# AMI MegaRAID=0D=0A=0D=0AAdded:=
 head/sys/cam/ctl/README.ctl.txt=0D=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A--- /dev/null00:00:=
00 1970(empty, because file is newly added)=0D=0A+++ head/sys/cam/ctl/REA=
DME.ctl.txtThu Jan 12 00:34:33 2012(r229997)=0D=0A@@ -0,0 +1,449 @@=0D=0A=
+/* $FreeBSD$ */=0D=0A+=0D=0A+CTL - CAM Target Layer Description=0D=0A+=0D=
=0A+Revision 1.4 (December 29th, 2011)=0D=0A+Ken Merry <ken@FreeBSD.org>=0D=
=0A+=0D=0A+Table of Contents:=0D=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=0D=0A+=0D=0A+Introduction=0D=0A+Features=0D=0A+Configuring a=
nd Running CTL=0D=0A+Revision 1.N Changes=0D=0A+To Do List=0D=0A+Code Roa=
dmap=0D=0A+Userland Commands=0D=0A+=0D=0A+Introduction:=0D=0A+=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A+=0D=0A+CTL is a disk and processor device =
emulation subsystem originally written=0D=0A+for Copan Systems under Linu=
x starting in 2003. =A0It has been shipping in=0D=0A+Copan (now SGI) prod=
ucts since 2005.=0D=0A+=0D=0A+It was ported to FreeBSD in 2008, and thank=
s to an agreement between SGI=0D=0A+(who acquired Copan's assets in 2010)=
 and Spectra Logic in 2010, CTL is=0D=0A+available under a BSD-style lice=
nse. =A0The intent behind the agreement was=0D=0A+that Spectra would work=
 to get CTL into the FreeBSD tree.=0D=0A+=0D=0A+Features:=0D=0A+=3D=3D=3D=
=3D=3D=3D=3D=3D=0D=0A+=0D=0A+ - Disk and processor device emulation.=0D=0A=
+ - Tagged queueing=0D=0A+ - SCSI task attribute support (ordered, head o=
f queue, simple tags)=0D=0A+ - SCSI implicit command ordering support. =A0=
(e.g. if a read follows a mode=0D=0A+ =A0 select, the read will be blocke=
d until the mode select completes.)=0D=0A+ - Full task management support=
 (abort, LUN reset, target reset, etc.)=0D=0A+ - Support for multiple por=
ts=0D=0A+ - Support for multiple simultaneous initiators=0D=0A+ - Support=
 for multiple simultaneous backing stores=0D=0A+ - Persistent reservation=
 support=0D=0A+ - Mode sense/select support=0D=0A+ - Error injection supp=
ort=0D=0A+ - High Availability support (1)=0D=0A+ - All I/O handled in-ke=
rnel, no userland context switch overhead.=0D=0A+=0D=0A+(1) HA Support is=
 just an API stub, and needs much more to be fully=0D=0A+ =A0 =A0function=
al. =A0See the to-do list below.=0D=0A+=0D=0A+Configuring and Running CTL=
:=0D=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=0D=0A+=0D=0A+ - After applying the CTL patchset to your t=
ree, build world and install it=0D=0A+ =A0 on your target system.=0D=0A+=0D=
=0A+ - Add 'device ctl' to your kernel configuration file.=0D=0A+=0D=0A+ =
- If you're running with a 8Gb or 4Gb Qlogic FC board, add=0D=0A+ =A0 'op=
tions ISP_TARGET_MODE' to your kernel config file. =A0Keep in mind that=0D=
=0A+ =A0 the isp(4) driver can run in target or initiator mode, but not b=
oth on=0D=0A+ =A0 the same machine. =A0'device ispfw' or loading the ispf=
w module is also=0D=0A+ =A0 recommended.=0D=0A+=0D=0A+ - Rebuild and inst=
all a new kernel.=0D=0A+=0D=0A+ - Reboot with the new kernel.=0D=0A+=0D=0A=
+ - To add a LUN with the RAM disk backend:=0D=0A+=0D=0A+ctladm create -b=
 ramdisk -s 10485760000000000000=0D=0A+ctladm port -o on=0D=0A+=0D=0A+ - =
You should now see the CTL disk LUN through camcontrol devlist:=0D=0A+=0D=
=0A+scbus6 on ctl2cam0 bus 0:=0D=0A+<FREEBSD CTLDISK 0001> =A0 =A0 =A0 =A0=
 =A0 =A0 at scbus6 target 1 lun 0 (da24,pass32)=0D=0A+<> =A0 =A0 =A0 =A0 =
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 at scbus6 target -1 lun -=
1 ()=0D=0A+=0D=0A+ =A0 This is visible through the CTL CAM SIM. =A0This a=
llows using CTL without=0D=0A+ =A0 any physical hardware. =A0You should b=
e able to issue any normal SCSI=0D=0A+ =A0 commands to the device via the=
 pass(4)/da(4) devices.=0D=0A+=0D=0A+ =A0 If any target-capable HBAs are =
in the system (e.g. isp(4)), and have=0D=0A+ =A0 target mode enabled, you=
 should now also be able to see the CTL LUNs via=0D=0A+ =A0 that target i=
nterface.=0D=0A+=0D=0A+ =A0 Note that all CTL LUNs are presented to all f=
rontends. =A0There is no=0D=0A+ =A0 LUN masking, or separate, per-port co=
nfiguration.=0D=0A+=0D=0A+ - Note that the ramdisk backend is a "fake" ra=
mdisk. =A0That is, it is=0D=0A+ =A0 backed by a small amount of RAM that =
is used for all I/O requests. =A0This=0D=0A+ =A0 is useful for performanc=
e testing, but not for any data integrity tests.=0D=0A+=0D=0A+ - To add a=
 LUN with the block/file backend:=0D=0A+=0D=0A+truncate -s +1T myfile=0D=0A=
+ctladm create -b block -o file=3Dmyfile=0D=0A+ctladm port -o on=0D=0A+=0D=
=0A+ - You can also see a list of LUNs and their backends like this:=0D=0A=
+=0D=0A+# ctladm devlist=0D=0A+LUN Backend =A0 =A0 =A0 Size (Blocks) =A0 =
BS Serial Number =A0 =A0Device ID =A0 =A0 =A0=20=0D=0A+ =A00 block =A0 =A0=
 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 0 =A0 =A0 MYDEVID =A0 0 =A0=
 =A0=20=0D=0A+ =A01 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERI=
AL =A0 1 =A0 =A0 MYDEVID =A0 1 =A0 =A0=20=0D=0A+ =A02 block =A0 =A0 =A0 =A0=
 =A0 =A02147483648 =A0512 MYSERIAL =A0 2 =A0 =A0 MYDEVID =A0 2 =A0 =A0=20=
=0D=0A+ =A03 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 =
3 =A0 =A0 MYDEVID =A0 3 =A0 =A0=20=0D=0A+ =A04 block =A0 =A0 =A0 =A0 =A0 =
=A02147483648 =A0512 MYSERIAL =A0 4 =A0 =A0 MYDEVID =A0 4 =A0 =A0=20=0D=0A=
+ =A05 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 5 =A0 =
=A0 MYDEVID =A0 5 =A0 =A0=20=0D=0A+ =A06 block =A0 =A0 =A0 =A0 =A0 =A0214=
7483648 =A0512 MYSERIAL =A0 6 =A0 =A0 MYDEVID =A0 6 =A0 =A0=20=0D=0A+ =A0=
7 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 7 =A0 =A0 M=
YDEVID =A0 7 =A0 =A0=20=0D=0A+ =A08 block =A0 =A0 =A0 =A0 =A0 =A021474836=
48 =A0512 MYSERIAL =A0 8 =A0 =A0 MYDEVID =A0 8 =A0 =A0=20=0D=0A+ =A09 blo=
ck =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 9 =A0 =A0 MYDEVI=
D =A0 9 =A0 =A0=20=0D=0A+ 10 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A05=
12 MYSERIAL =A010 =A0 =A0 MYDEVID =A010 =A0 =A0=20=0D=0A+ 11 block =A0 =A0=
 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A011 =A0 =A0 MYDEVID =A011 =A0=
 =A0=0D=0A+=0D=0A+ - You can see the LUN type and backing store for block=
/file backend LUNs=0D=0A+ =A0 like this:=0D=0A+=0D=0A+# ctladm devlist -v=
=0D=0A+LUN Backend =A0 =A0 =A0 Size (Blocks) =A0 BS Serial Number =A0 =A0=
Device ID =A0 =A0 =A0=20=0D=0A+ =A00 block =A0 =A0 =A0 =A0 =A0 =A02147483=
648 =A0512 MYSERIAL =A0 0 =A0 =A0 MYDEVID =A0 0 =A0 =A0=20=0D=0A+ =A0 =A0=
 =A0lun_type=3D0=0D=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0fil=
e=3Dtestdisk0=0D=0A+ =A01 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 =
MYSERIAL =A0 1 =A0 =A0 MYDEVID =A0 1 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_typ=
e=3D0=0D=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdis=
k1=0D=0A+ =A02 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0=
 2 =A0 =A0 MYDEVID =A0 2 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+=
 =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdisk2=0D=0A+ =A0=
3 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 3 =A0 =A0 M=
YDEVID =A0 3 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+ =A0 =A0 =A0=
num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdisk3=0D=0A+ =A04 block =A0=
 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 4 =A0 =A0 MYDEVID =A0 =
4 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+ =A0 =A0 =A0num_threads=
=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdisk4=0D=0A+ =A05 block =A0 =A0 =A0 =A0=
 =A0 =A02147483648 =A0512 MYSERIAL =A0 5 =A0 =A0 MYDEVID =A0 5 =A0 =A0=20=
=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+=
 =A0 =A0 =A0file=3Dtestdisk5=0D=0A+ =A06 block =A0 =A0 =A0 =A0 =A0 =A0214=
7483648 =A0512 MYSERIAL =A0 6 =A0 =A0 MYDEVID =A0 6 =A0 =A0=20=0D=0A+ =A0=
 =A0 =A0lun_type=3D0=0D=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0=
file=3Dtestdisk6=0D=0A+ =A07 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A05=
12 MYSERIAL =A0 7 =A0 =A0 MYDEVID =A0 7 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_=
type=3D0=0D=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtest=
disk7=0D=0A+ =A08 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL=
 =A0 8 =A0 =A0 MYDEVID =A0 8 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=
=0A+ =A0 =A0 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdisk8=0D=0A=
+ =A09 block =A0 =A0 =A0 =A0 =A0 =A02147483648 =A0512 MYSERIAL =A0 9 =A0 =
=A0 MYDEVID =A0 9 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+ =A0 =A0=
 =A0num_threads=3D14=0D=0A+ =A0 =A0 =A0file=3Dtestdisk9=0D=0A+ 10 ramdisk=
 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 0 =A0 =A00 MYSERIAL =A0 0 =A0 =A0 MY=
DEVID =A0 0 =A0 =A0=20=0D=0A+ =A0 =A0 =A0lun_type=3D3=0D=0A+ 11 ramdisk =A0=
 =A0 204800000000000 =A0512 MYSERIAL =A0 1 =A0 =A0 MYDEVID =A0 1 =A0 =A0=20=
=0D=0A+ =A0 =A0 =A0lun_type=3D0=0D=0A+=0D=0A+=0D=0A+Revision 1.4 Changes=0D=
=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A+ -=
 Added in the second HA mode (where CTL does the data transfers instead=0D=
=0A+ =A0 of having data transfers done below CTL), and abstracted out the=
 Copan=0D=0A+ =A0 HA API.=0D=0A+=0D=0A+ - Fixed the phantom device proble=
m in the CTL CAM SIM and improved the=0D=0A+ =A0 CAM SIM to automatically=
 trigger a rescan when the port is enabled and=0D=0A+ =A0 disabled.=0D=0A=
+=20=0D=0A+ - Made the number of threads in the block backend configurabl=
e via sysctl,=0D=0A+ =A0 loader tunable and the ctladm command line. =A0(=
You can now specify=0D=0A+ =A0 -o num_threads=3D4 when creating a LUN wit=
h ctladm create.)=0D=0A+=0D=0A+ - Fixed some LUN selection issues in ctls=
tat(8) and allowed for selection=0D=0A+ =A0 of LUN numbers up to 1023.=0D=
=0A+=0D=0A+ - General cleanup.=0D=0A+=0D=0A+ - This version intended for =
public release.=0D=0A+=0D=0A+Revision 1.3 Changes=0D=0A+=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A+ - Added descriptor sens=
e support to CTL. =A0It can be enabled through the=0D=0A+ =A0 control mod=
e page (10), but is disabled by default.=0D=0A+=0D=0A+ - Improved error i=
njection support. =A0The number of errors that can be=0D=0A+ =A0 injected=
 with 'ctladm inject' has been increased, and any arbitrary=0D=0A+ =A0 se=
nse data may now be injected as well.=0D=0A+=0D=0A+ - The port infrastruc=
ture has been revamped. =A0Individual ports and types=0D=0A+ =A0 of ports=
 may now be enabled and disabled from the command line. =A0ctladm=0D=0A+ =
=A0 now has the ability to set the WWNN and WWPN for each port.=0D=0A+=0D=
=0A+ - The block backend can now send multiple I/Os to backing files. =A0=
Multiple=0D=0A+ =A0 writes are only allowed for ZFS, but multiple readers=
 are allowed for=0D=0A+ =A0 any filesystem.=0D=0A+=0D=0A+ - The block and=
 ramdisk backends now support setting the LUN blocksize.=0D=0A+ =A0 There=
 are some restrictions when the backing device is a block device,=0D=0A+ =
=A0 but otherwise the blocksize may be set to anything.=0D=0A+=0D=0A+Revi=
sion 1.2 Changes=0D=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=0D=0A+=0D=0A+ - CTL initialization process has been revamped. =A0=
Instead of using an=0D=0A+ =A0 ad-hoc method, it is now sequenced through=
 SYSINIT() calls.=0D=0A+=0D=0A+ - A block/file backend has been added. =A0=
This allows using arbitrary files=0D=0A+ =A0 or block devices as a backin=
g store.=0D=0A+=0D=0A+ - The userland LUN configuration interface has bee=
n completely rewritten.=0D=0A+ =A0 Configuration is now done out of band.=
=0D=0A+=0D=0A+ - The ctladm(8) command line interface has been revamped, =
and is now=0D=0A+ =A0 similar to camcontrol(8).=0D=0A+=0D=0A+To Do List:=0D=
=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A+=0D=0A+ - Make CTL buildable as =
a module. =A0Work needs to be done on initialization,=0D=0A+ =A0 and on f=
reeing resources and LUNs when it is built as a module.=0D=0A+=0D=0A+ - U=
se devstat(9) for CTL's statistics collection. =A0CTL uses a home-grown=0D=
=0A+ =A0 statistics collection system that is similar to devstat(9). =A0c=
tlstat=0D=0A+ =A0 should be retired in favor of iostat, etc., once aggreg=
ation modes are=0D=0A+ =A0 available in iostat to match the behavior of c=
tlstat -t and dump modes=0D=0A+ =A0 are available to match the behavior o=
f ctlstat -d/ctlstat -J.=0D=0A+=0D=0A+ - ZFS ARC backend for CTL. =A0Sinc=
e ZFS copies all I/O into the ARC=0D=0A+ =A0 (Adaptive Replacement Cache)=
, running the block/file backend on top of a=0D=0A+ =A0 ZFS-backed zdev o=
r file will involve an extra set of copies. =A0The=0D=0A+ =A0 optimal sol=
ution for backing targets served by CTL with ZFS would be to=0D=0A+ =A0 a=
llocate buffers out of the ARC directly, and DMA to/from them directly.=0D=
=0A+ =A0 That would eliminate an extra data buffer allocation and copy.=0D=
=0A+=0D=0A+ - Switch CTL over to using CAM CCBs instead of its own union =
ctl_io. =A0This=0D=0A+ =A0 will likely require a significant amount of wo=
rk, but will eliminate=0D=0A+ =A0 another data structure in the stack, mo=
re memory allocations, etc. =A0This=0D=0A+ =A0 will also require changes =
to the CAM CCB structure to support CTL.=0D=0A+=0D=0A+ - Full-featured Hi=
gh Availability support. =A0The HA API that is in ctl_ha.h=0D=0A+ =A0 is =
essentially a renamed version of Copan's HA API. =A0There is no=0D=0A+ =A0=
 substance to it, but it remains in CTL to show what needs to be done to=0D=
=0A+ =A0 implement active/active HA from a CTL standpoint. =A0The things =
that would=0D=0A+ =A0 need to be done include:=0D=0A+- A kernel level sof=
tware API for message passing as well as DMA=0D=0A+ =A0between at least t=
wo nodes.=0D=0A+- Hardware support and drivers for inter-node communicati=
on. =A0This=0D=0A+ =A0could be as simples as ethernet hardware and driver=
s.=0D=0A+- A "supervisor", or startup framework to control and coordinate=
=0D=0A+ =A0HA startup, failover (going from active/active to single mode)=
,=0D=0A+ =A0and failback (going from single mode to active/active).=0D=0A=
+- HA support in other components of the stack. =A0The goal behind HA=0D=0A=
+ =A0is that one node can fail and another node can seamlessly take=0D=0A=
+ =A0over handling I/O requests. =A0This requires support from pretty=0D=0A=
+ =A0much every component in the storage stack, from top to bottom.=0D=0A=
+ =A0CTL is one piece of it, but you also need support in the RAID=0D=0A+=
 =A0stack/filesystem/backing store. =A0You also need full configuration=0D=
=0A+ =A0mirroring, and all peer nodes need to be able to talk to the=0D=0A=
+ =A0underlying storage hardware.=0D=0A+=0D=0A+Code Roadmap:=0D=0A+=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A+=0D=0A+CTL has the concept of plugga=
ble frontend ports and backends. =A0All=0D=0A+frontends and backends can =
be active at the same time. =A0You can have a=0D=0A+ramdisk-backed LUN pr=
esent along side a file backed LUN.=0D=0A+=0D=0A+ctl.c:=0D=0A+-----=0D=0A=
+=0D=0A+This is the core of CTL, where all of the command handlers and a =
lot of=0D=0A+other things live. =A0Yes, it is large. =A0It started off sm=
all and grew to its=0D=0A+current size over time. =A0Perhaps it can be sp=
lit into more files at some=0D=0A+point.=0D=0A+=0D=0A+Here is a roadmap o=
f some of the primary functions in ctl.c. =A0Starting here=0D=0A+and foll=
owing the various leaf functions will show the command flow.=0D=0A+=0D=0A=
+ctl_queue() This is where commands from the frontend ports come=0D=0A+in=
=2E=0D=0A+=0D=0A+ctl_queue_sense()This is only used for non-packetized SC=
SI. =A0i.e.=0D=0A+parallel SCSI prior to U320 and perhaps U160.=0D=0A+=0D=
=0A+ctl_work_thread() This is the primary work thread, and everything get=
s=0D=0A+executed from there.=0D=0A+=0D=0A+ctl_scsiio_precheck() This wher=
e all of the initial checks are done, and I/O=0D=0A+is either queued for =
execution or blocked.=0D=0A+=0D=0A+ctl_scsiio() This is where the command=
 handler is actually=0D=0A+executed. =A0(See ctl_cmd_table.c for the mapp=
ing of=0D=0A+SCSI opcode to command handler function.)=0D=0A+=0D=0A+ctl_d=
one()This is the routine called (or ctl_done_lock()) to=0D=0A+initiate th=
e command completion process.=0D=0A+=0D=0A+ctl_process_done()This is wher=
e command completion actually happens.=0D=0A+=0D=0A+ctl.h:=0D=0A+-----=0D=
=0A+=0D=0A+Basic function declarations and data structures.=0D=0A+=0D=0A+=
ctl_backend.c,=0D=0A+ctl_backend.h:=0D=0A+-------------=0D=0A+=0D=0A+Thes=
e files define the basic CTL backend API. =A0The comments in the header=0D=
=0A+explain the API.=0D=0A+=0D=0A+ctl_backend_block.c=0D=0A+ctl_backend_b=
lock.h:=0D=0A+-------------------=0D=0A+=0D=0A+The block and file backend=
=2E =A0This allows for using a disk or a file as the=0D=0A+backing store =
for a LUN. =A0Multiple threads are started to do I/O to the=0D=0A+backing=
 device, primarily because the VFS API requires that to get any=0D=0A+con=
currency.=0D=0A+=0D=0A+ctl_backend_ramdisk.c:=0D=0A+---------------------=
=0D=0A+=0D=0A+A "fake" ramdisk backend. =A0It only allocates a small amou=
nt of memory to=0D=0A+act as a source and sink for reads and writes from =
an initiator. =A0Therefore=0D=0A+it cannot be used for any real data, but=
 it can be used to test for=0D=0A+throughput. =A0It can also be used to t=
est initiators' support for extremely=0D=0A+large LUNs.=0D=0A+=0D=0A+ctl_=
cmd_table.c:=0D=0A+---------------=0D=0A+=0D=0A+This is a table with all =
256 possible SCSI opcodes, and command handler=0D=0A+functions defined fo=
r supported opcodes. =A0It is included in ctl.c.=0D=0A+=0D=0A+ctl_debug.h=
:=0D=0A+-----------=0D=0A+=0D=0A+Simplistic debugging support.=0D=0A+=0D=0A=
+ctl_error.c,=0D=0A+ctl_error.h:=0D=0A+-----------=0D=0A+=0D=0A+CTL-speci=
fic wrappers around the CAM sense building functions.=0D=0A+=0D=0A+ctl_fr=
ontend.c,=0D=0A+ctl_frontend.h:=0D=0A+--------------=0D=0A+=0D=0A+These f=
iles define the basic CTL frontend port API. =A0The comments in the=0D=0A=
+header explain the API.=0D=0A+=0D=0A+ctl_frontend_cam_sim.c:=0D=0A+-----=
-----------------=0D=0A+=0D=0A+This is a CTL frontend port that is also a=
 CAM SIM. =A0The idea is that this=0D=0A+frontend allows for using CTL wi=
thout any target-capable hardware. =A0So any=0D=0A+LUNs you create in CTL=
 are visible via this port.=0D=0A+=0D=0A+=0D=0A+ctl_frontend_internal.c=0D=
=0A+ctl_frontend_internal.h:=0D=0A+-----------------------=0D=0A+=0D=0A+T=
his is a frontend port written for Copan to do some system-specific tasks=
=0D=0A+that required sending commands into CTL from inside the kernel. =A0=
This isn't=0D=0A+entirely relevant to FreeBSD in general, but can perhaps=
 be repurposed or=0D=0A+removed later.=0D=0A+=0D=0A+ctl_ha.h:=0D=0A+-----=
---=0D=0A+=0D=0A+This is a stubbed-out High Availability API. =A0See the =
comments in the=0D=0A+header and the description of what is needed as far=
 as HA support above.=0D=0A+=0D=0A+ctl_io.h:=0D=0A+--------=0D=0A+=0D=0A+=
This defines most of the core CTL I/O structures. =A0union ctl_io is=0D=0A=
+conceptually very similar to CAM's union ccb. =A0=0D=0A+=0D=0A+ctl_ioctl=
=2Eh:=0D=0A+-----------=0D=0A+=0D=0A+This defines all ioctls available th=
rough the CTL character device, and=0D=0A+the data structures needed for =
those ioctls.=0D=0A+=0D=0A+ctl_mem_pool.c=0D=0A+ctl_mem_pool.h:=0D=0A+---=
-----------=0D=0A+=0D=0A+Generic memory pool implementation. =A0This is c=
urrently only used by the=0D=0A+internal frontend. =A0The internal fronte=
nd can probably be rewritten to use=0D=0A+UMA zones and this can be remov=
ed.=0D=0A+=0D=0A+ctl_private.h:=0D=0A+-------------=0D=0A+=0D=0A+Private =
data structres (e.g. CTL softc) and function prototypes. =A0This also=0D=0A=
+includes the SCSI vendor and product names used by CTL.=0D=0A+=0D=0A+ctl=
_scsi_all.c=0D=0A+ctl_scsi_all.h:=0D=0A+--------------=0D=0A+=0D=0A+CTL w=
rappers around CAM sense printing functions.=0D=0A+=0D=0A+ctl_ser_table.c=
:=0D=0A+---------------=0D=0A+=0D=0A+Command serialization table. =A0This=
 defines what happens when one type of=0D=0A+command is followed by anoth=
er type of command. =A0e.g., what do you do when=0D=0A+you have a mode se=
lect followed by a write=3F =A0You block the write until the=0D=0A+mode s=
elect is complete. =A0That is defined in this table.=0D=0A+=0D=0A+ctl_uti=
l.c=0D=0A+ctl_util.h:=0D=0A+----------=0D=0A+=0D=0A+CTL utility functions=
, primarily designed to be used from userland. =A0See=0D=0A+ctladm for th=
e primary consumer of these functions. =A0These include CDB=0D=0A+buildin=
g functions.=0D=0A+=0D=0A+scsi_ctl.c:=0D=0A+----------=0D=0A+=0D=0A+CAM t=
arget peripheral driver and CTL frontend port. =A0This is the path into=0D=
=0A+CTL for commands from target-capable hardware/SIMs.=0D=0A+=0D=0A+User=
land Commands:=0D=0A+=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=
=0A+=0D=0A+ctladm(8) fills a role similar to camcontrol(8). =A0It allow c=
onfiguring LUNs,=0D=0A+issuing commands, injecting errors and various oth=
er control functions.=0D=0A+=0D=0A+ctlstat(8) fills a role similar to ios=
tat(8). =A0It reports I/O statistics=0D=0A+for CTL.=0D=0A=0D=0AAdded: hea=
d/sys/cam/ctl/ctl.c=0D=0A=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=0D=0A--- /dev/null00:00:00 1970(empt=
y, because file is newly added)=0D=0A+++ head/sys/cam/ctl/ctl.cThu Jan 12=
 00:34:33 2012(r229997)=0D=0A@@ -0,0 +1,13082 @@=0D=0A+/*-=0D=0A+ * Copyr=
ight (c) 2003-2009 Silicon Graphics International Corp.=0D=0A+ * All righ=
ts reserved.=0D=0A+ *=0D=0A+ * Redistribution and use in source and binar=
y forms, with or without=0D=0A+ * modification, are permitted provided th=
at the following conditions=0D=0A+ * are met:=0D=0A+ * 1. Redistributions=
 of source code must retain the above copyright=0D=0A+ * =A0 =A0notice, t=
his list of conditions, and the following disclaimer,=0D=0A+ * =A0 =A0wit=
hout modification.=0D=0A+ * 2. Redistributions in binary form must reprod=
uce at minimum a disclaimer=0D=0A+ * =A0 =A0substantially similar to the =
"NO WARRANTY" disclaimer below=0D=0A+ * =A0 =A0("Disclaimer") and any red=
istribution must be conditioned upon=0D=0A+ * =A0 =A0including a substant=
ially similar Disclaimer requirement for further=0D=0A+ * =A0 =A0binary r=
edistribution.=0D=0A+ *=0D=0A+ * NO WARRANTY=0D=0A+ * THIS SOFTWARE IS PR=
OVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=0D=0A+ * "AS IS" AND ANY=
 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=0D=0A+ * LIMITED TO, T=
HE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR=0D=0A+ * A PARTI=
CULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT=0D=0A+ * HO=
LDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL=0D=
=0A+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE =
GOODS=0D=0A+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS IN=
TERRUPTION)=0D=0A+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETH=
ER IN CONTRACT,=0D=0A+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =
OR OTHERWISE) ARISING=0D=0A+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE=
, EVEN IF ADVISED OF THE=0D=0A+ * POSSIBILITY OF SUCH DAMAGES.=0D=0A+ *=0D=
=0A+ * $Id: //depot/users/kenm/FreeBSD-test2/sys/cam/ctl/ctl.c#8 $=0D=0A+=
 */=0D=0A+/*=0D=0A+ * CAM Target Layer, a SCSI device emulation subsystem=
=2E=0D=0A+ *=0D=0A+ * Author: Ken Merry <ken@FreeBSD.org>=0D=0A+ */=0D=0A=
+=0D=0A+#define _CTL_C=0D=0A+=0D=0A+#include <sys/cdefs.h>=0D=0A+__FBSDID=
("$FreeBSD$");=0D=0A+=0D=0A+#include <sys/param.h>=0D=0A+#include <sys/sy=
stm.h>=0D=0A+#include <sys/kernel.h>=0D=0A+#include <sys/types.h>=0D=0A+#=
include <sys/kthread.h>=0D=0A+#include <sys/bio.h>=0D=0A+#include <sys/fc=
ntl.h>=0D=0A+#include <sys/lock.h>=0D=0A+#include <sys/mutex.h>=0D=0A+#in=
clude <sys/condvar.h>=0D=0A+#include <sys/malloc.h>=0D=0A+#include <sys/c=
onf.h>=0D=0A+#include <sys/ioccom.h>=0D=0A+#include <sys/queue.h>=0D=0A+#=
include <sys/sbuf.h>=0D=0A+#include <sys/endian.h>=0D=0A+#include <sys/sy=
sctl.h>=0D=0A+=0D=0A+#include <cam/cam.h>=0D=0A+#include <cam/scsi/scsi_a=
ll.h>=0D=0A+#include <cam/scsi/scsi_da.h>=0D=0A+#include <cam/ctl/ctl_io.=
h>=0D=0A+#include <cam/ctl/ctl.h>=0D=0A+#include <cam/ctl/ctl_frontend.h>=
=0D=0A+#include <cam/ctl/ctl_frontend_internal.h>=0D=0A+#include <cam/ctl=
/ctl_util.h>=0D=0A+#include <cam/ctl/ctl_backend.h>=0D=0A+#include <cam/c=
tl/ctl_ioctl.h>=0D=0A+#include <cam/ctl/ctl_ha.h>=0D=0A+#include <cam/ctl=
/ctl_private.h>=0D=0A+#include <cam/ctl/ctl_debug.h>=0D=0A+#include <cam/=
ctl/ctl_scsi_all.h>=0D=0A+#include <cam/ctl/ctl_error.h>=0D=0A+=0D=0A+str=
uct ctl_softc *control_softc =3D NULL;=0D=0A+=0D=0A+/*=0D=0A+ * The defau=
lt is to run with CTL_DONE_THREAD turned on. =A0Completed=0D=0A+ * transa=
ctions are queued for processing by the CTL work thread. =A0When=0D=0A+ *=
 CTL_DONE_THREAD is not defined, completed transactions are processed in=0D=
=0A+ * the caller's context.=0D=0A+ */=0D=0A+#define CTL_DONE_THREAD=0D=0A=
+=0D=0A+/*=0D=0A+ * =A0* Use the serial number and device ID provided by =
the backend, rather than=0D=0A+ * =A0 * making up our own.=0D=0A+ * =A0 =A0=
*/=0D=0A+#define CTL_USE_BACKEND_SN=0D=0A+=0D=0A+/*=0D=0A+ * Size and ali=
gnment macros needed for Copan-specific HA hardware. =A0These=0D=0A+ * ca=
n go away when the HA code is re-written, and uses busdma for any=0D=0A+ =
* hardware.=0D=0A+ */=0D=0A+#defineCTL_ALIGN_8B(target, source, type)\=0D=
=0A+if (((uint32_t)source & 0x7) !=3D 0)\=0D=0A+target =3D (type)(source =
+ (0x8 - ((uint32_t)source & 0x7)));\=0D=0A+else\=0D=0A+target =3D (type)=
source;=0D=0A+=0D=0A+#defineCTL_SIZE_8B(target, size)\=0D=0A+if ((size & =
0x7) !=3D 0)\=0D=0A+target =3D size + (0x8 - (size & 0x7));\=0D=0A+else\=0D=
=0A+target =3D size;=0D=0A+=0D=0A+#define CTL_ALIGN_8B_MARGIN16=0D=0A+=0D=
=0A+/*=0D=0A+ * Template mode pages.=0D=0A+ */=0D=0A+=0D=0A+/*=0D=0A+ * N=
ote that these are default values only. =A0The actual values will be=0D=0A=
+ * filled in when the user does a mode sense.=0D=0A+ */=0D=0A+static str=
uct copan_power_subpage power_page_default =3D {=0D=0A+/*page_code*/ PWR_=
PAGE_CODE | SMPH_SPF,=0D=0A+/*subpage*/ PWR_SUBPAGE_CODE,=0D=0A+/*page_le=
ngth*/ {(sizeof(struct copan_power_subpage) - 4) & 0xff00,=0D=0A+ (sizeof=
(struct copan_power_subpage) - 4) & 0x00ff},=0D=0A+/*page_version*/ PWR_V=
ERSION,=0D=0A+/* total_luns */ 26,=0D=0A+/* max_active_luns*/ PWR_DFLT_MA=
X_LUNS,=0D=0A+/*reserved*/ {0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+ =A0 =A0 =A0=
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+ =A0 =A0 =A00, 0, 0, 0, 0, 0}=0D=0A+}=
;=0D=0A+=0D=0A+static struct copan_power_subpage power_page_changeable =3D=
 {=0D=0A+/*page_code*/ PWR_PAGE_CODE | SMPH_SPF,=0D=0A+/*subpage*/ PWR_SU=
BPAGE_CODE,=0D=0A+/*page_length*/ {(sizeof(struct copan_power_subpage) - =
4) & 0xff00,=0D=0A+ (sizeof(struct copan_power_subpage) - 4) & 0x00ff},=0D=
=0A+/*page_version*/ 0,=0D=0A+/* total_luns */ 0,=0D=0A+/* max_active_lun=
s*/ 0,=0D=0A+/*reserved*/ {0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+ =A0 =A0 =A00=
, 0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+ =A0 =A0 =A00, 0, 0, 0, 0, 0}=0D=0A+};=
=0D=0A+=0D=0A+static struct copan_aps_subpage aps_page_default =3D {=0D=0A=
+APS_PAGE_CODE | SMPH_SPF, //page_code=0D=0A+APS_SUBPAGE_CODE, //subpage=0D=
=0A+{(sizeof(struct copan_aps_subpage) - 4) & 0xff00,=0D=0A+ (sizeof(stru=
ct copan_aps_subpage) - 4) & 0x00ff}, //page_length=0D=0A+APS_VERSION, //=
page_version=0D=0A+0, //lock_active=0D=0A+{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, =
0,=0D=0A+0, 0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+0, 0, 0, 0, 0} //reserved=0D=
=0A+};=0D=0A+=0D=0A+static struct copan_aps_subpage aps_page_changeable =3D=
 {=0D=0A+APS_PAGE_CODE | SMPH_SPF, //page_code=0D=0A+APS_SUBPAGE_CODE, //=
subpage=0D=0A+{(sizeof(struct copan_aps_subpage) - 4) & 0xff00,=0D=0A+ (s=
izeof(struct copan_aps_subpage) - 4) & 0x00ff}, //page_length=0D=0A+0, //=
page_version=0D=0A+0, //lock_active=0D=0A+{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, =
0,=0D=0A+0, 0, 0, 0, 0, 0, 0, 0, 0, 0,=0D=0A+0, 0, 0, 0, 0} //reserved=0D=
=0A+};=0D=0A+=0D=0A+static struct copan_debugconf_subpage debugconf_page_=
default =3D {=0D=0A+DBGCNF_PAGE_CODE | SMPH_SPF,/* page_code */=0D=0A+DBG=
CNF_SUBPAGE_CODE,/* subpage */=0D=0A+{(sizeof(struct copan_debugconf_subp=
age) - 4) >> 8,=0D=0A+ (sizeof(struct copan_debugconf_subpage) - 4) >> 0}=
, /* page_length */=0D=0A+DBGCNF_VERSION,/* page_version */=0D=0A+{CTL_TI=
ME_IO_DEFAULT_SECS>>8,=0D=0A+ CTL_TIME_IO_DEFAULT_SECS>>0},/* ctl_time_io=
_secs */=0D=0A+};=0D=0A+=0D=0A+static struct copan_debugconf_subpage debu=
gconf_page_changeable =3D {=0D=0A+DBGCNF_PAGE_CODE | SMPH_SPF,/* page_cod=
e */=0D=0A+DBGCNF_SUBPAGE_CODE,/* subpage */=0D=0A+{(sizeof(struct copan_=
debugconf_subpage) - 4) >> 8,=0D=0A+ (sizeof(struct copan_debugconf_subpa=
ge) - 4) >> 0}, /* page_length */=0D=0A+0,/* page_version */=0D=0A+{0xff,=
0xff},/* ctl_time_io_secs */=0D=0A+};=0D=0A+=0D=0A+static struct scsi_for=
mat_page format_page_default =3D {=0D=0A+/*page_code*/SMS_FORMAT_DEVICE_P=
AGE,=0D=0A+/*page_length*/sizeof(struct scsi_format_page) - 2,=0D=0A+/*tr=
acks_per_zone*/ {0, 0},=0D=0A+/*alt_sectors_per_zone*/ {0, 0},=0D=0A+/*al=
t_tracks_per_zone*/ {0, 0},=0D=0A+/*alt_tracks_per_lun*/ {0, 0},=0D=0A+/*=
sectors_per_track*/ {(CTL_DEFAULT_SECTORS_PER_TRACK >> 8) & 0xff,=0D=0A+ =
=A0 =A0 =A0 =A0CTL_DEFAULT_SECTORS_PER_TRACK & 0xff},=0D=0A+/*bytes_per_s=
ector*/ {0, 0},=0D=0A+/*interleave*/ {0, 0},=0D=0A+/*track_skew*/ {0, 0},=
=0D=0A+/*cylinder_skew*/ {0, 0},=0D=0A+/*flags*/ SFP_HSEC,=0D=0A+/*reserv=
ed*/ {0, 0, 0}=0D=0A+};=0D=0A+=0D=0A+static struct scsi_format_page forma=
t_page_changeable =3D {=0D=0A+/*page_code*/SMS_FORMAT_DEVICE_PAGE,=0D=0A+=
/*page_length*/sizeof(struct scsi_format_page) - 2,=0D=0A+/*tracks_per_zo=
ne*/ {0, 0},=0D=0A+/*alt_sectors_per_zone*/ {0, 0},=0D=0A+/*alt_tracks_pe=
r_zone*/ {0, 0},=0D=0A+/*alt_tracks_per_lun*/ {0, 0},=0D=0A+/*sectors_per=
_track*/ {0, 0},=0D=0A+/*bytes_per_sector*/ {0, 0},=0D=0A+/*interleave*/ =
{0, 0},=0D=0A+/*track_skew*/ {0, 0},=0D=0A+/*cylinder_skew*/ {0, 0},=0D=0A=
+/*flags*/ 0,=0D=0A+/*reserved*/ {0, 0, 0}=0D=0A+};=0D=0A+=0D=0A+static s=
truct scsi_rigid_disk_page rigid_disk_page_default =3D {=0D=0A+/*page_cod=
e*/SMS_RIGID_DISK_PAGE,=0D=0A+/*page_length*/sizeof(struct scsi_rigid_dis=
k_page) - 2,=0D=0A+/*cylinders*/ {0, 0, 0},=0D=0A+/*heads*/ CTL_DEFAULT_H=
EADS,=0D=0A+/*start_write_precomp*/ {0, 0, 0},=0D=0A+/*start_reduced_curr=
ent*/ {0, 0, 0},=0D=0A+/*step_rate*/ {0, 0},=0D=0A+/*landing_zone_cylinde=
r*/ {0, 0, 0},=0D=0A+/*rpl*/ SRDP_RPL_DISABLED,=0D=0A+/*rotational_offset=
*/ 0,=0D=0A+/*reserved1*/ 0,=0D=0A+/*rotation_rate*/ {(CTL_DEFAULT_ROTATI=
ON_RATE >> 8) & 0xff,=0D=0A+ =A0 CTL_DEFAULT_ROTATION_RATE & 0xff},=0D=0A=
+/*reserved2*/ {0, 0}=0D=0A+};=0D=0A+=0D=0A+static struct scsi_rigid_disk=
_page rigid_disk_page_changeable =3D {=0D=0A+/*page_code*/SMS_RIGID_DISK_=
PAGE,=0D=0A+/*page_length*/sizeof(struct scsi_rigid_disk_page) - 2,=0D=0A=
+/*cylinders*/ {0, 0, 0},=0D=0A+/*heads*/ 0,=0D=0A+/*start_write_precomp*=
/ {0, 0, 0},=0D=0A+/*start_reduced_current*/ {0, 0, 0},=0D=0A+/*step_rate=
*/ {0, 0},=0D=0A+/*landing_zone_cylinder*/ {0, 0, 0},=0D=0A+/*rpl*/ 0,=0D=
=0A+/*rotational_offset*/ 0,=0D=0A+/*reserved1*/ 0,=0D=0A+/*rotation_rate=
*/ {0, 0},=0D=0A+/*reserved2*/ {0, 0}=0D=0A+};=0D=0A+=0D=0A+static struct=
 scsi_caching_page caching_page_default =3D {=0D=0A+/*page_code*/SMS_CACH=
ING_PAGE,=0D=0A+/*page_length*/sizeof(struct scsi_caching_page) - 2,=0D=0A=
+/*flags1*/ SCP_DISC | SCP_WCE,=0D=0A+/*ret_priority*/ 0,=0D=0A+/*disable=
_pf_transfer_len*/ {0xff, 0xff},=0D=0A+/*min_prefetch*/ {0, 0},=0D=0A+/*m=
ax_prefetch*/ {0xff, 0xff},=0D=0A+/*max_pf_ceiling*/ {0xff, 0xff},=0D=0A+=
/*flags2*/ 0,=0D=0A+/*cache_segments*/ 0,=0D=0A+/*cache_seg_size*/ {0, 0}=
,=0D=0A+/*reserved*/ 0,=0D=0A+/*non_cache_seg_size*/ {0, 0, 0}=0D=0A+};=0D=
=0A+=0D=0A+static struct scsi_caching_page caching_page_changeable =3D {=0D=
=0A+/*page_code*/SMS_CACHING_PAGE,=0D=0A+/*page_length*/sizeof(struct scs=
i_caching_page) - 2,=0D=0A+/*flags1*/ 0,=0D=0A+/*ret_priority*/ 0,=0D=0A+=
/*disable_pf_transfer_len*/ {0, 0},=0D=0A+/*min_prefetch*/ {0, 0},=0D=0A+=
/*max_prefetch*/ {0, 0},=0D=0A+/*max_pf_ceiling*/ {0, 0},=0D=0A+/*flags2*=
/ 0,=0D=0A+/*cache_segments*/ 0,=0D=0A+/*cache_seg_size*/ {0, 0},=0D=0A+/=
*reserved*/ 0,=0D=0A+/*non_cache_seg_size*/ {0, 0, 0}=0D=0A+};=0D=0A+=0D=0A=
+static struct scsi_control_page control_page_default =3D {=0D=0A+/*page_=
code*/SMS_CONTROL_MODE_PAGE,=0D=0A+/*page_length*/sizeof(struct scsi_cont=
rol_page) - 2,=0D=0A+/*rlec*/0,=0D=0A+/*queue_flags*/0,=0D=0A+/*eca_and_a=
en*/0,=0D=0A+/*reserved*/0,=0D=0A+/*aen_holdoff_period*/{0, 0}=0D=0A+};=0D=
=0A+=0D=0A+static struct scsi_control_page control_page_changeable =3D {=0D=
=0A+/*page_code*/SMS_CONTROL_MODE_PAGE,=0D=0A+/*page_length*/sizeof(struc=
t scsi_control_page) - 2,=0D=0A+/*rlec*/SCP_DSENSE,=0D=0A+/*queue_flags*/=
0,=0D=0A+/*eca_and_aen*/0,=0D=0A+/*reserved*/0,=0D=0A+/*aen_holdoff_perio=
d*/{0, 0}=0D=0A+};=0D=0A+=0D=0A+SYSCTL_NODE(_kern_cam, OID_AUTO, ctl, CTL=
FLAG_RD, 0, "CAM Target Layer");=0D=0A+=0D=0A+/*=0D=0A+ * XXX KDM move th=
ese into the softc.=0D=0A+ */=0D=0A+static int rcv_sync_msg;=0D=0A+static=
 int persis_offset;=0D=0A+static uint8_t ctl_pause_rtr;=0D=0A+static int =
=A0 =A0 ctl_is_single;=0D=0A+static int =A0 =A0 index_to_aps_page;=0D=0A+=
=0D=0A+=0D=0A+/*=0D=0A+ * Serial number (0x80), device id (0x83), and sup=
ported pages (0x00)=0D=0A+ */=0D=0A+#define SCSI_EVPD_NUM_SUPPORTED_PAGES=
3=0D=0A+=0D=0A+static void ctl_isc_event_handler(ctl_ha_channel chanel, c=
tl_ha_event event,=0D=0A+ =A0int param);=0D=0A+static void ctl_copy_sense=
_data(union ctl_ha_msg *src, union ctl_io *dest);=0D=0A+static void ctl_i=
nit(void);=0D=0A+void ctl_shutdown(void);=0D=0A+static int ctl_open(struc=
t cdev *dev, int flags, int fmt, struct thread *td);=0D=0A+static int ctl=
_close(struct cdev *dev, int flags, int fmt, struct thread *td);=0D=0A+st=
atic void ctl_ioctl_online(void *arg);=0D=0A+static void ctl_ioctl_offlin=
e(void *arg);=0D=0A+static int ctl_ioctl_targ_enable(void *arg, struct ct=
l_id targ_id);=0D=0A+static int ctl_ioctl_targ_disable(void *arg, struct =
ctl_id targ_id);=0D=0A+static int ctl_ioctl_lun_enable(void *arg, struct =
ctl_id targ_id, int lun_id);=0D=0A+static int ctl_ioctl_lun_disable(void =
*arg, struct ctl_id targ_id, int lun_id);=0D=0A+static int ctl_ioctl_do_d=
atamove(struct ctl_scsiio *ctsio);=0D=0A+static int ctl_serialize_other_s=
c_cmd(struct ctl_scsiio *ctsio, int have_lock);=0D=0A+static int ctl_ioct=
l_submit_wait(union ctl_io *io);=0D=0A+static void ctl_ioctl_datamove(uni=
on ctl_io *io);=0D=0A+static void ctl_ioctl_done(union ctl_io *io);=0D=0A=
+static void ctl_ioctl_hard_startstop_callback(void *arg,=0D=0A+ =A0 =A0 =
=A0struct cfi_metatask *metatask);=0D=0A+static void ctl_ioctl_bbrread_ca=
llback(void *arg,struct cfi_metatask *metatask);=0D=0A+static int ctl_ioc=
tl_fill_ooa(struct ctl_lun *lun, uint32_t *cur_fill_num,=0D=0A+ =A0 =A0 =A0=
struct ctl_ooa *ooa_hdr);=0D=0A+static int ctl_ioctl(struct cdev *dev, u_=
long cmd, caddr_t addr, int flag,=0D=0A+ =A0 =A0 struct thread *td);=0D=0A=
+uint32_t ctl_get_resindex(struct ctl_nexus *nexus);=0D=0A+uint32_t ctl_p=
ort_idx(int port_num);=0D=0A+#ifdef unused=0D=0A+static union ctl_io *ctl=
_malloc_io(ctl_io_type io_type, uint32_t targ_port,=0D=0A+ =A0 uint32_t t=
arg_target, uint32_t targ_lun,=0D=0A+ =A0 int can_wait);=0D=0A+static voi=
d ctl_kfree_io(union ctl_io *io);=0D=0A+#endif /* unused */=0D=0A+static =
void ctl_free_io_internal(union ctl_io *io, int have_lock);=0D=0A+static =
int ctl_alloc_lun(struct ctl_softc *ctl_softc, struct ctl_lun *lun,=0D=0A=
+ struct ctl_be_lun *be_lun, struct ctl_id target_id);=0D=0A+static int c=
tl_free_lun(struct ctl_lun *lun);=0D=0A+static void ctl_create_lun(struct=
 ctl_be_lun *be_lun);=0D=0A+/**=0D=0A+static void ctl_failover_change_pag=
es(struct ctl_softc *softc,=0D=0A+ =A0 =A0 =A0struct ctl_scsiio *ctsio, i=
nt master);=0D=0A+**/=0D=0A+=0D=0A+static int ctl_do_mode_select(union ct=
l_io *io);=0D=0A+static int ctl_pro_preempt(struct ctl_softc *softc, stru=
ct ctl_lun *lun,=0D=0A+ =A0 uint64_t res_key, uint64_t sa_res_key,=0D=0A+=
 =A0 uint8_t type, uint32_t residx,=0D=0A+ =A0 struct ctl_scsiio *ctsio,=0D=
=0A+ =A0 struct scsi_per_res_out *cdb,=0D=0A+ =A0 struct scsi_per_res_out=
_parms* param);=0D=0A+static void ctl_pro_preempt_other(struct ctl_lun *l=
un,=0D=0A+ =A0union ctl_ha_msg *msg);=0D=0A+static void ctl_hndl_per_res_=
out_on_other_sc(union ctl_ha_msg *msg);=0D=0A+static int ctl_inquiry_evpd=
_supported(struct ctl_scsiio *ctsio, int alloc_len);=0D=0A+static int ctl=
_inquiry_evpd_serial(struct ctl_scsiio *ctsio, int alloc_len);=0D=0A+stat=
ic int ctl_inquiry_evpd_devid(struct ctl_scsiio *ctsio, int alloc_len);=0D=
=0A+static int ctl_inquiry_evpd(struct ctl_scsiio *ctsio);=0D=0A+static i=
nt ctl_inquiry_std(struct ctl_scsiio *ctsio);=0D=0A+static int ctl_get_lb=
a_len(union ctl_io *io, uint64_t *lba, uint32_t *len);=0D=0A+static ctl_a=
ction ctl_extent_check(union ctl_io *io1, union ctl_io *io2);=0D=0A+stati=
c ctl_action ctl_check_for_blockage(union ctl_io *pending_io,=0D=0A+ unio=
n ctl_io *ooa_io);=0D=0A+static ctl_action ctl_check_ooa(struct ctl_lun *=
lun, union ctl_io *pending_io,=0D=0A+union ctl_io *starting_io);=0D=0A+st=
atic int ctl_check_blocked(struct ctl_lun *lun);=0D=0A+static int ctl_scs=
iio_lun_check(struct ctl_softc *ctl_softc,=0D=0A+struct ctl_lun *lun,=0D=0A=
+struct ctl_cmd_entry *entry,=0D=0A+struct ctl_scsiio *ctsio);=0D=0A+//st=
atic int ctl_check_rtr(union ctl_io *pending_io, struct ctl_softc *softc)=
;=0D=0A+static void ctl_failover(void);=0D=0A+static int ctl_scsiio_prech=
eck(struct ctl_softc *ctl_softc,=0D=0A+ =A0 =A0 =A0 struct ctl_scsiio *ct=
sio);=0D=0A+static int ctl_scsiio(struct ctl_scsiio *ctsio);=0D=0A+=0D=0A=
+static int ctl_bus_reset(struct ctl_softc *ctl_softc, union ctl_io *io);=
=0D=0A+static int ctl_target_reset(struct ctl_softc *ctl_softc, union ctl=
_io *io,=0D=0A+ =A0 =A0ctl_ua_type ua_type);=0D=0A+static int ctl_lun_res=
et(struct ctl_lun *lun, union ctl_io *io,=0D=0A+ ctl_ua_type ua_type);=0D=
=0A+static int ctl_abort_task(union ctl_io *io);=0D=0A+static void ctl_ru=
n_task_queue(struct ctl_softc *ctl_softc);=0D=0A+#ifdef CTL_IO_DELAY=0D=0A=
+static void ctl_datamove_timer_wakeup(void *arg);=0D=0A+static void ctl_=
done_timer_wakeup(void *arg);=0D=0A+#endif /* CTL_IO_DELAY */=0D=0A+=0D=0A=
+static void ctl_send_datamove_done(union ctl_io *io, int have_lock);=0D=0A=
+static void ctl_datamove_remote_write_cb(struct ctl_ha_dt_req *rq);=0D=0A=
+static int ctl_datamove_remote_dm_write_cb(union ctl_io *io);=0D=0A+stat=
ic void ctl_datamove_remote_write(union ctl_io *io);=0D=0A+static int ctl=
_datamove_remote_dm_read_cb(union ctl_io *io);=0D=0A+static void ctl_data=
move_remote_read_cb(struct ctl_ha_dt_req *rq);=0D=0A+static int ctl_datam=
ove_remote_sgl_setup(union ctl_io *io);=0D=0A+static int ctl_datamove_rem=
ote_xfer(union ctl_io *io, unsigned command,=0D=0A+ =A0 =A0ctl_ha_dt_cb c=
allback);=0D=0A+static void ctl_datamove_remote_read(union ctl_io *io);=0D=
=0A+static void ctl_datamove_remote(union ctl_io *io);=0D=0A+static int c=
tl_process_done(union ctl_io *io, int have_lock);=0D=0A+static void ctl_w=
ork_thread(void *arg);=0D=0A+=0D=0A+/*=0D=0A+ * Load the serialization ta=
ble. =A0This isn't very pretty, but is probably=0D=0A+ * the easiest way =
to do it.=0D=0A+ */=0D=0A+#include "ctl_ser_table.c"=0D=0A+=0D=0A+/*=0D=0A=
+ * We only need to define open, close and ioctl routines for this driver=
=2E=0D=0A+ */=0D=0A+static struct cdevsw ctl_cdevsw =3D {=0D=0A+.d_versio=
n =3DD_VERSION,=0D=0A+.d_flags =3D0,=0D=0A+.d_open =3Dctl_open,=0D=0A+.d_=
close =3Dctl_close,=0D=0A+.d_ioctl =3Dctl_ioctl,=0D=0A+.d_name =3D"ctl",=0D=
=0A+};=0D=0A+=0D=0A+=0D=0A+MALLOC_DEFINE(M_CTL, "ctlmem", "Memory used fo=
r CTL");=0D=0A+=0D=0A+/*=0D=0A+ * If we have the CAM SIM, we may or may n=
ot have another SIM that will=0D=0A+ * cause CTL to get initialized. =A0I=
f not, we need to initialize it.=0D=0A+ */=0D=0A+SYSINIT(ctl_init, SI_SUB=
_CONFIGURE, SI_ORDER_THIRD, ctl_init, NULL);=0D=0A+=0D=0A+static void=0D=0A=
+ctl_isc_handler_finish_xfer(struct ctl_softc *ctl_softc,=0D=0A+ =A0 =A0u=
nion ctl_ha_msg *msg_info)=0D=0A+{=0D=0A+struct ctl_scsiio *ctsio;=0D=0A+=
=0D=0A+if (msg_info->hdr.original_sc =3D=3D NULL) {=0D=0A+printf("%s: ori=
ginal_sc =3D=3D NULL!\n", __func__);=0D=0A+/* XXX KDM now what=3F */=0D=0A=
+return;=0D=0A+}=0D=0A+=0D=0A+ctsio =3D &msg_info->hdr.original_sc->scsii=
o;=0D=0A+ctsio->io_hdr.flags |=3D CTL_FLAG_IO_ACTIVE;=0D=0A+ctsio->io_hdr=
=2Emsg_type =3D CTL_MSG_FINISH_IO;=0D=0A+ctsio->io_hdr.status =3D msg_inf=
o->hdr.status;=0D=0A+ctsio->scsi_status =3D msg_info->scsi.scsi_status;=0D=
=0A+ctsio->sense_len =3D msg_info->scsi.sense_len;=0D=0A+ctsio->sense_res=
idual =3D msg_info->scsi.sense_residual;=0D=0A+ctsio->residual =3D msg_in=
fo->scsi.residual;=0D=0A+memcpy(&ctsio->sense_data, &msg_info->scsi.sense=
_data,=0D=0A+ =A0 =A0 =A0 sizeof(ctsio->sense_data));=0D=0A+memcpy(&ctsio=
->io_hdr.ctl_private[CTL_PRIV_LBA_LEN].bytes,=0D=0A+ =A0 =A0 =A0 &msg_inf=
o->scsi.lbalen, sizeof(msg_info->scsi.lbalen));;=0D=0A+STAILQ_INSERT_TAIL=
(&ctl_softc->isc_queue, &ctsio->io_hdr, links);=0D=0A+ctl_wakeup_thread()=
;=0D=0A+}=0D=0A+=0D=0A+static void=0D=0A+ctl_isc_handler_finish_ser_only(=
struct ctl_softc *ctl_softc,=0D=0A+union ctl_ha_msg *msg_info)=0D=0A+{=0D=
=0A+struct ctl_scsiio *ctsio;=0D=0A+=0D=0A+if (msg_info->hdr.serializing_=
sc =3D=3D NULL) {=0D=0A+printf("%s: serializing_sc =3D=3D NULL!\n", __fun=
c__);=0D=0A+/* XXX KDM now what=3F */=0D=0A+return;=0D=0A+}=0D=0A+=0D=0A+=
ctsio =3D &msg_info->hdr.serializing_sc->scsiio;=0D=0A+#if 0=0D=0A+/*=0D=0A=
+ * Attempt to catch the situation where an I/O has=0D=0A+ * been freed, =
and we're using it again.=0D=0A+ */=0D=0A+if (ctsio->io_hdr.io_type =3D=3D=
 0xff) {=0D=0A+union ctl_io *tmp_io;=0D=0A+tmp_io =3D (union ctl_io *)cts=
io;=0D=0A+printf("%s: %p use after free!\n", __func__,=0D=0A+ =A0 =A0 =A0=
 ctsio);=0D=0A+printf("%s: type %d msg %d cdb %x iptl: "=0D=0A+ =A0 =A0 =A0=
 "%d:%d:%d:%d tag 0x%04x "=0D=0A+ =A0 =A0 =A0 "flag %#x status %x\n",=0D=0A=
+__func__,=0D=0A+tmp_io->io_hdr.io_type,=0D=0A+tmp_io->io_hdr.msg_type,=0D=
=0A+tmp_io->scsiio.cdb[0],=0D=0A+tmp_io->io_hdr.nexus.initid.id,=0D=0A+tm=
p_io->io_hdr.nexus.targ_port,=0D=0A+tmp_io->io_hdr.nexus.targ_target.id,=0D=
=0A+tmp_io->io_hdr.nexus.targ_lun,=0D=0A+(tmp_io->io_hdr.io_type =3D=3D=0D=
=0A+CTL_IO_TASK) =3F=0D=0A+tmp_io->taskio.tag_num :=0D=0A+tmp_io->scsiio.=
tag_num,=0D=0A+ =A0 =A0 =A0 =A0tmp_io->io_hdr.flags,=0D=0A+tmp_io->io_hdr=
=2Estatus);=0D=0A+}=0D=0A+#endif=0D=0A+ctsio->io_hdr.msg_type =3D CTL_MSG=
_FINISH_IO;=0D=0A=0D=0A*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***=0D=0A



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?zarafa.4f0ea0bc.7115.4be8e2091dfed731>