[Midnightbsd-cvs] src [10819] trunk/usr.sbin/ctladm: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Jun 10 16:16:39 EDT 2018


Revision: 10819
          http://svnweb.midnightbsd.org/src/?rev=10819
Author:   laffer1
Date:     2018-06-10 16:16:39 -0400 (Sun, 10 Jun 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/usr.sbin/ctladm/Makefile
    trunk/usr.sbin/ctladm/ctladm.8
    trunk/usr.sbin/ctladm/ctladm.c
    trunk/usr.sbin/ctladm/util.c

Property Changed:
----------------
    trunk/usr.sbin/ctladm/ctladm.8

Modified: trunk/usr.sbin/ctladm/Makefile
===================================================================
--- trunk/usr.sbin/ctladm/Makefile	2018-06-10 20:15:35 UTC (rev 10818)
+++ trunk/usr.sbin/ctladm/Makefile	2018-06-10 20:16:39 UTC (rev 10819)
@@ -1,13 +1,14 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/ctladm/Makefile 274870 2014-11-22 17:50:14Z trasz $
 
 PROG=		ctladm
 SRCS=		ctladm.c util.c ctl_util.c ctl_scsi_all.c
-.PATH:		${.CURDIR}/../../sys/cam/ctl 
+.PATH:		${.CURDIR}/../../sys/cam/ctl
 SDIR=		${.CURDIR}/../../sys
 CFLAGS+=	-I${SDIR}
 # This is necessary because of these warnings:
 # warning: cast increases required alignment of target type
-# The solution is to either upgrade the compiler (preferred), or do void 
+# The solution is to either upgrade the compiler (preferred), or do void
 # pointer gymnastics to get around the warning.  For now, disable the
 # warning instead of doing the void pointer workaround.
 .if ${MACHINE_CPUARCH} == "arm"

Modified: trunk/usr.sbin/ctladm/ctladm.8
===================================================================
--- trunk/usr.sbin/ctladm/ctladm.8	2018-06-10 20:15:35 UTC (rev 10818)
+++ trunk/usr.sbin/ctladm/ctladm.8	2018-06-10 20:16:39 UTC (rev 10819)
@@ -1,5 +1,7 @@
+.\" $MidnightBSD$
 .\"
 .\" Copyright (c) 2003 Silicon Graphics International Corp.
+.\" Copyright (c) 2015 Alexander Motin <mav at FreeBSD.org>
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -31,10 +33,10 @@
 .\"
 .\" Author: Ken Merry <ken at FreeBSD.org>
 .\"
-.\" $Id: ctladm.8,v 1.1 2013-01-30 12:43:58 laffer1 Exp $
-.\" $MidnightBSD$
+.\" $Id: //depot/users/kenm/FreeBSD-test2/usr.sbin/ctladm/ctladm.8#3 $
+.\" $FreeBSD: stable/10/usr.sbin/ctladm/ctladm.8 313371 2017-02-07 01:58:02Z mav $
 .\"
-.Dd March 6, 2013
+.Dd January 23, 2017
 .Dt CTLADM 8
 .Os
 .Sh NAME
@@ -43,28 +45,28 @@
 .Sh SYNOPSIS
 .Nm
 .Aq Ar command
-.Op target:lun
+.Op lun
 .Op generic args
 .Op command args
 .Nm
 .Ic tur
-.Aq target:lun
+.Aq lun
 .Op general options
 .Nm
 .Ic inquiry
-.Aq target:lun
+.Aq lun
 .Op general options
 .Nm
 .Ic reqsense
-.Aq target:lun
+.Aq lun
 .Op general options
 .Nm
 .Ic reportluns
-.Aq target:lun
+.Aq lun
 .Op general options
 .Nm
 .Ic read
-.Aq target:lun
+.Aq lun
 .Op general options
 .Aq Fl l Ar lba
 .Aq Fl d Ar datalen
@@ -74,7 +76,7 @@
 .Op Fl N
 .Nm
 .Ic write
-.Aq target:lun
+.Aq lun
 .Op general options
 .Aq Fl l Ar lba
 .Aq Fl d Ar datalen
@@ -83,19 +85,13 @@
 .Op Fl c Ar cdbsize
 .Op Fl N
 .Nm
-.Ic bbrread
-.Aq target:lun
-.Op general options
-.Aq Fl -l Ar lba
-.Aq Fl -d Ar datalen
-.Nm
 .Ic readcap
-.Aq target:lun
+.Aq lun
 .Op general options
 .Op Fl c Ar cdbsize
 .Nm
 .Ic modesense
-.Aq target:lun
+.Aq lun
 .Aq Fl m Ar page | Fl l
 .Op Fl P Ar pc
 .Op Fl d
@@ -103,19 +99,19 @@
 .Op Fl c Ar size
 .Nm
 .Ic start
-.Aq target:lun
+.Aq lun
 .Op general options
 .Op Fl i
 .Op Fl o
 .Nm
 .Ic stop
-.Aq target:lun
+.Aq lun
 .Op general options
 .Op Fl i
 .Op Fl o
 .Nm
 .Ic synccache
-.Aq target:lun
+.Aq lun
 .Op general options
 .Op Fl l Ar lba
 .Op Fl b Ar blockcount
@@ -123,33 +119,14 @@
 .Op Fl i
 .Op Fl c Ar cdbsize
 .Nm
-.Ic shutdown
-.Op general options
-.Nm
-.Ic startup
-.Op general options
-.Nm
-.Ic hardstop
-.Nm
-.Ic hardstart
-.Nm
 .Ic lunlist
 .Nm
 .Ic delay
-.Aq target:lun
+.Aq lun
 .Aq Fl l Ar datamove|done
 .Aq Fl t Ar secs
 .Op Fl T Ar oneshot|cont
 .Nm
-.Ic realsync Aq on|off|query
-.Nm
-.Ic setsync interval
-.Aq target:lun
-.Aq Fl i Ar interval
-.Nm
-.Ic getsync
-.Aq target:lun
-.Nm
 .Ic inject
 .Aq Fl i Ar action
 .Aq Fl p Ar pattern
@@ -176,6 +153,7 @@
 .Ic modify
 .Aq Fl b Ar backend
 .Aq Fl l Ar lun_id
+.Op Fl o Ar name=value
 .Aq Fl s Ar size_bytes
 .Nm
 .Ic devlist
@@ -184,19 +162,40 @@
 .Op Fl x
 .Nm
 .Ic port
-.Op Fl l
 .Op Fl o Ar on|off
 .Op Fl w Ar wwpn
 .Op Fl W Ar wwnn
 .Op Fl p Ar targ_port
 .Op Fl t Ar fe_type
+.Nm
+.Ic portlist
+.Op Fl f Ar frontend
+.Op Fl i
+.Op Fl l
+.Op Fl p Ar targ_port
 .Op Fl q
+.Op Fl v
 .Op Fl x
 .Nm
+.Ic lunmap
+.Aq Fl p Ar targ_port
+.Op Fl l Ar pLUN
+.Op Fl L Ar cLUN
+.Nm
 .Ic dumpooa
 .Nm
 .Ic dumpstructs
 .Nm
+.Ic islist
+.Op Fl v
+.Op Fl x
+.Nm
+.Ic islogout
+.Aq Fl a | Fl c Ar connection-id | Fl i Ar name | Fl p Ar portal
+.Nm
+.Ic isterminate
+.Aq Fl a | Fl c Ar connection-id | Fl i Ar name | Fl p Ar portal
+.Nm
 .Ic help
 .Sh DESCRIPTION
 The
@@ -221,13 +220,12 @@
 identifier.
 The device identifier takes the following form:
 .Bl -tag -width 14n
-.It target:lun
-Specify the target (almost always 0) and LUN number to operate on.
+.It lun
+Specify the LUN number to operate on.
 .El
 Many of the primary functions of the
 .Nm
 utility take the following optional arguments:
-.Pp
 .Bl -tag -width 10n
 .It Fl C Ar retries
 Specify the number of times to retry a command in the event of failure.
@@ -341,34 +339,6 @@
 data.
 This is to be used for performance testing.
 .El
-.It Ic bbrread
-Issue a SCSI READ command to the logical device to potentially force a bad
-block on a disk in the RAID set to be reconstructed from the other disks in
-the array.  This command should only be used on an array that is in the
-normal state.  If used on a critical array, it could cause the array to go
-offline if the bad block to be remapped is on one of the disks that is
-still active in the array.
-.Pp
-The data for this particular command will be discarded, and not returned to
-the user.
-.Pp
-In order to determine which LUN to read from, the user should first
-determine which LUN the disk with a bad block belongs to.  Then he should
-map the bad disk block back to the logical block address for the array in
-order to determine which LBA to pass in to the
-.Ic bbrread
-command.
-.Pp
-This command is primarily intended for testing.  In practice, bad block
-remapping will generally be triggered by the in-kernel Disk Aerobics and
-Disk Scrubbing code.
-.Bl -tag -width 10n
-.It Fl l Ar lba
-Specify the starting Logical Block Address.
-.It Fl d Ar datalen
-Specify the amount of data in bytes to read from the LUN.  This must be a
-multiple of the LUN blocksize.
-.El
 .It Ic readcap
 Send the
 .Tn SCSI
@@ -402,7 +372,7 @@
 .Fl m
 option are mutually exclusive.  One of the two must be specified, though.
 .It Fl P Ar pc
-Specify the mode page page control value.  Possible values are:
+Specify the mode page control value.  Possible values are:
 .Bl -tag -width 2n -compact
 .It 0
 Current values.
@@ -431,17 +401,6 @@
 Set the immediate bit in the CDB.  Note that CTL does not support the
 immediate bit, so this is primarily useful for making sure that CTL returns
 the proper error.
-.It Fl o
-Set the Copan proprietary on/offline bit in the CDB.  When this flag is
-used, the LUN will be marked online again (see the description of the
-.Ic shutdown
-and
-.Ic startup
-commands).  When this flag is used with a
-start command, the LUN will NOT be spun up.  You need to use a start
-command without the
-.Fl o
-flag to spin up the disks in the LUN.
 .El
 .It Ic stop
 Send the
@@ -457,14 +416,6 @@
 Set the immediate bit in the CDB.  Note that CTL does not support the
 immediate bit, so this is primarily useful for making sure that CTL returns
 the proper error.
-.It Fl o
-Set the Copan proprietary on/offline bit in the CDB.  When this flag is
-used, the LUN will be spun down and taken offline ("Logical unit not ready,
-manual intervention required").  See the description of the
-.Ic shutdown
-and
-.Ic startup
-options.
 .El
 .It Ic synccache
 Send the
@@ -488,56 +439,14 @@
 .It Fl r
 Specify relative addressing for the starting LBA.  CTL does not support
 relative addressing, since it only works for linked commands, and CTL
-doesn't support linked commands.
+does not support linked commands.
 .It Fl i
-Tell the target to return status immediately after issuing the SYHCHRONIZE CACHE
+Tell the target to return status immediately after issuing the SYNCHRONIZE CACHE
 command rather than waiting for the cache to finish syncing.  CTL does not
 support this bit.
 .It Fl c Ar cdbsize
 Specify the minimum CDB size.  Valid values are 10 and 16 bytes.
 .El
-.It Ic shutdown
-Issue a
-.Tn SCSI
-START STOP UNIT command with the start bit cleared and the on/offline bit
-set to all direct access LUNs.  This will spin down all direct access LUNs,
-and mark them offline ("Logical unit not ready, manual intervention
-required").  Once marked offline, the state can only be cleared by sending
-a START STOP UNIT command with the start bit set and the on/offline bit
-set.  The
-.Nm
-commands
-.Ic startup
-and
-.Ic start
-will accomplish this.  Note that the
-on/offline bit is a non-standard Copan extension to the
-.Tn SCSI
-START STOP UNIT command, so merely sending a normal start command from an
-initiator will not clear the condition.  (This is by design.)
-.It Ic startup
-Issue a
-.Tn SCSI
-START STOP UNIT command with the start bit set and the on/offline bit set
-to all direct access LUNs.  This will mark all direct access LUNs "online"
-again.  It will not cause any LUNs to start up.  A separate start command
-without the on/offline bit set is necessary for that.
-.It Ic hardstop
-Use the kernel facility for stopping all direct access LUNs and setting the
-offline bit.  Unlike the
-.Ic shutdown
-command above, this command allows shutting down LUNs with I/O active.  It
-will also issue a LUN reset to any reserved LUNs to break the reservation
-so that the LUN can be stopped.
-.Ic shutdown
-command instead.
-.It Ic hardstart
-This command is functionally identical to the
-.Ic startup
-command described above.  The primary difference is that the LUNs are
-enumerated and commands sent by the in-kernel Front End Target Driver
-instead of by
-.Nm .
 .It Ic lunlist
 List all LUNs registered with CTL.
 Because this command uses the ioctl port, it will only work when the FETDs
@@ -578,39 +487,6 @@
 commands will be completed normally.
 This is the default.
 .El
-.It Ic realsync
-Query and control CTL's SYNCHRONIZE CACHE behavior.  The
-.Sq query
-argument
-will show whether SYNCHRONIZE CACHE commands are being sent to the backend
-or not.
-The default is to send SYNCHRONIZE CACHE commands to the backend.
-The
-.Sq on
-argument will cause all SYNCHRONIZE CACHE commands sent to all LUNs to be
-sent to the backend.
-The
-.Sq off
-argument will cause all SYNCHRONIZE CACHE commands sent to all LUNs to be
-immediately returned to the initiator with successful status.
-.It Ic setsync
-For a given lun, only actually service every Nth SYNCHRONIZE CACHE command
-that is sent.  This can be used for debugging the optimal time period for
-sending SYNCHRONIZE cache commands.  An interval of 0 means that the cache
-will be flushed for this LUN every time a SYNCHRONIZE CACHE command is
-received.
-.Pp
-You must specify the target and LUN you want to modify.
-.It Ic getsync
-Get the interval at which we actually service the SYNCHRONIZE CACHE
-command, as set by the
-.Ic setsync
-command above.
-The reported number means that we will actually flush the cache on every
-Nth SYNCHRONIZE CACHE command.  A value of 0 means that we will flush the
-cache every time.
-.Pp
-You must specify the target and LUN you want to query.
 .It Ic inject
 Inject the specified type of error for the LUN specified, when a command
 that matches the given pattern is seen.
@@ -718,8 +594,6 @@
 The WWNN and WWPN may both be specified at the same time, but cannot be
 combined with enabling/disabling or listing ports.
 .Bl -tag -width 12n
-.It Fl l
-List all CTL frontend ports or a specific port type or number.
 .It Fl o Ar on|off
 Turn the specified CTL frontend ports off or on.
 If no port number or port type is specified, all ports are turned on or
@@ -727,8 +601,6 @@
 .It Fl p Ar targ_port
 Specify the frontend port number.
 The port numbers can be found in the frontend port list.
-.It Fl q
-Omit the header in the port list output.
 .It Fl t Ar fe_type
 Specify the frontend type.
 Currently defined port types are
@@ -756,9 +628,50 @@
 argument must be specified, since this is only possible to implement on a
 single port.
 As a general rule, the WWPN must be different for every port in the system.
+.El
+.It Ic portlist
+List CTL frontend ports.
+.Bl -tag -width 12n
+.It Fl f Ar frontend
+Specify the frontend type.
+.It Fl i
+Report target and connected initiators addresses.
+.It Fl l
+Report LUN mapping.
+.It Fl p Ar targ_port
+Specify the frontend port number.
+.It Fl q
+Omit the header in the port list output.
+.It Fl v
+Enable verbose output (report all port options).
 .It Fl x
 Output the port list in XML format.
 .El
+.It Ic lunmap
+Change LUN mapping for specified port.
+If both
+.Ar pLUN
+and
+.Ar cLUN
+are specified -- LUN will be mapped.
+If
+.Ar pLUN
+is specified, but
+.Ar cLUN
+is not -- LUN will be unmapped.
+If neither
+.Ar pLUN
+nor
+.Ar cLUN
+are specified -- LUN mapping will be disabled, exposing all CTL LUNs.
+.Bl -tag -width 12n
+.It Fl p Ar targ_port
+Specify the frontend port number.
+.It Fl l Ar pLUN
+LUN number visible by specified port.
+.It Fl L Ar cLUN
+CTL LUN number.
+.El
 .It Ic dumpooa
 Dump the OOA (Order Of Arrival) queue for each LUN registered with CTL.
 .It Ic dumpstructs
@@ -805,11 +718,10 @@
 INQUIRY VPD page 0x80 data.
 .It Fl t Ar device_type
 Specify the numeric SCSI device type to use when creating the LUN.
-For example, the Direct Access type is 0.
 If this flag is not used, the type of LUN created is backend-specific.
 Not all LUN types are supported.
-Currently CTL only supports Direct Access (type 0) and Processor (type 3)
-LUNs.
+Currently CTL supports Direct Access (type 0), Processor (type 3)
+and CD/DVD (type 5) LUNs.
 The backend requested may or may not support all of the LUN types that CTL
 supports.
 .El
@@ -847,6 +759,12 @@
 .Dq block .
 .It Fl l Ar lun_id
 Specify the LUN number to remove.
+.It Fl o Ar name=value
+Specify a backend-specific name/value pair.
+Multiple
+.Fl o
+arguments may be specified.
+Refer to the backend documentation for arguments that may be used.
 .It Fl s Ar size_bytes
 Specify the size of the LUN in bytes.
 For the
@@ -884,41 +802,183 @@
 .Fl x ,
 the entire LUN database is displayed in XML format.
 .El
+.It Ic islist
+Get a list of currently running iSCSI connections.
+This includes initiator and target names and the unique connection IDs.
+.Bl -tag -width 11n
+.It Fl v
+Verbose mode.
+.It Fl x
+Dump the raw XML.
+The connections list information from the kernel comes in XML format, and this
+option allows the display of the raw XML data.
+.El
+.It Ic islogout
+Ask the initiator to log out iSCSI connections matching criteria.
+.Bl -tag -width 11n
+.It Fl a
+Log out all connections.
+.It Fl c
+Specify connection ID.
+.It Fl i
+Specify initiator name.
+.It Fl p
+Specify initiator portal (hostname or IP address).
+.El
+.It Ic isterminate
+Forcibly terminate iSCSI connections matching criteria.
+.Bl -tag -width 11n
+.It Fl a
+Terminate all connections.
+.It Fl c
+Specify connection ID.
+.It Fl i
+Specify initiator name.
+.It Fl p
+Specify initiator portal (hostname or IP address).
+.El
 .It Ic help
 Display
 .Nm
 usage information.
 .El
+.Sh OPTIONS
+Number of additional configuration options may be specified for LUNs.
+Some options are global, others are backend-specific.
+.Pp
+Global options:
+.Bl -tag -width 12n
+.It Va vendor
+Specifies LUN vendor string up to 8 chars.
+.It Va product
+Specifies LUN product string up to 16 chars.
+.It Va revision
+Specifies LUN revision string up to 4 chars.
+.It Va scsiname
+Specifies LUN SCSI name string.
+.It Va eui
+Specifies LUN EUI-64 identifier.
+.It Va naa
+Specifies LUN NAA identifier.
+.It Va uuid
+Specifies LUN locally assigned RFC 4122 UUID identifier.
+EUI, NAA or UUID identifier should be set to UNIQUE value to allow
+EXTENDED COPY command access the LUN.
+Non-unique LUN identifiers may lead to data corruption.
+Some initiators may not support later introduced UUID identifiers.
+.It Va ha_role
+Setting to "primary" or "secondary" overrides default role of the node
+in HA cluster, set by kern.cam.ctl.ha_role sysctl.
+.It Va insecure_tpc
+Setting to "on" allows EXTENDED COPY command sent to this LUN access
+other LUNs on this host, not accessible otherwise.
+This allows to offload copying between different iSCSI targets residing
+on the same host in trusted environments.
+.It Va readcache
+Set to "off", disables read caching for the LUN, if supported by the backend.
+.It Va readonly
+Set to "on", blocks all media write operations to the LUN, reporting it
+as write protected.
+.It Va removable
+Set to "on", makes LUN removable.
+.It Va reordering
+Set to "unrestricted", allows target to process commands with SIMPLE task
+attribute in arbitrary order.  Any data integrity exposures related to
+command sequence order shall be explicitly handled by the application
+client through the selection of appropriate commands and task attributes.
+The default value is "restricted".  It improves data integrity, but may
+introduce some additional delays.
+.It Va serseq
+Set to "on" to serialize conseсutive reads/writes.
+Set to "read" to serialize conseсutive reads.
+Set to "off" to allow them be issued in parallel.
+Parallel issue of consecutive operations may confuse logic of the
+backing file system, hurting performance; but it may improve performance
+of backing stores without prefetch/write-back.
+.It Va pblocksize
+.It Va pblockoffset
+Specify physical block size and offset of the device.
+.It Va ublocksize
+.It Va ublockoffset
+Specify UNMAP block size and offset of the device.
+.It Va rpm
+Specifies medium rotation rate of the device: 0 -- not reported,
+1 -- non-rotating (SSD), >1024 -- value in revolutions per minute.
+.It Va formfactor
+Specifies nominal form factor of the device: 0 -- not reported, 1 -- 5.25",
+2 -- 3.5", 3 -- 2.5", 4 -- 1.8", 5 -- less then 1.8".
+.It Va provisioning_type
+When UNMAP support is enabled, this option specifies provisioning type:
+"resource", "thin" or "unknown".
+Default value is "thin".
+Logical units without UNMAP support are reported as fully provisioned.
+.It Va unmap
+Setting to "on" or "off" controls UNMAP support for the logical unit.
+Default value is "on" if supported by the backend.
+.It Va unmap_max_lba
+.It Va unmap_max_descr
+Specify maximum allowed number of LBAs and block descriptors per UNMAP
+command to report in Block Limits VPD page.
+.It Va write_same_max_lba
+Specify maximum allowed number of LBAs per WRITE SAME command to report
+in Block Limits VPD page.
+.It Va avail-threshold
+.It Va used-threshold
+.It Va pool-avail-threshold
+.It Va pool-used-threshold
+Set per-LUN/-pool thin provisioning soft thresholds.
+LUN will establish UNIT ATTENTION condition if its or pool available space
+get below configured avail values, or its or pool used space get above
+configured used values.
+Pool thresholds are working only for ZVOL-backed LUNs.
+.It Va writecache
+Set to "off", disables write caching for the LUN, if supported by the backend.
+.El
+.Pp
+Options specific for block backend:
+.Bl -tag -width 12n
+.It Va file
+Specifies file or device name to use for backing store.
+.It Va num_threads
+Specifies number of backend threads to use for this LUN.
+.El
+.Pp
+Options specific for ramdisk backend:
+.Bl -tag -width 12n
+.It Va capacity
+Specifies capacity of backing store (maximum RAM for data).
+The default value is zero, that disables backing store completely,
+making all writes go to nowhere, while all reads return zeroes.
+.El
 .Sh EXAMPLES
-.Dl ctladm tur 0:1
+.Dl ctladm tur 1
 .Pp
 Send a
 .Tn SCSI
 TEST UNIT READY command to LUN 1.
 .Pp
-.Dl ctladm modesense 0:1 -l
+.Dl ctladm modesense 1 -l
 .Pp
 Display the list of mode pages supported by LUN 1.
 .Pp
-.Dl ctladm modesense 0:0 -m 10 -P 3 -d -c 10
+.Dl ctladm modesense 0 -m 10 -P 3 -d -c 10
 .Pp
 Display the saved version of the Control mode page (page 10) on LUN 0.
 Disable fetching block descriptors, and use a 10 byte MODE SENSE command
 instead of the default 6 byte command.
-.Pp
 .Bd -literal
-ctladm read 0:2 -l 0 -d 1 -b 512 -f - > foo
+ctladm read 2 -l 0 -d 1 -b 512 -f - > foo
 .Ed
 .Pp
 Read the first 512 byte block from LUN 2 and dump it to the file
 .Pa foo .
 .Bd -literal
-ctladm write 0:3 -l 0xff432140 -d 20 -b 512 -f /tmp/bar
+ctladm write 3 -l 0xff432140 -d 20 -b 512 -f /tmp/bar
 .Ed
 .Pp
 Read 10240 bytes from the file
 .Pa /tmp/bar
-and write it to target 0, LUN 3.
+and write it to LUN 3.
 starting at LBA 0xff432140.
 .Pp
 .Dl ctladm create -b ramdisk -s 10485760000000000
@@ -926,8 +986,15 @@
 Create a LUN with the
 .Dq fake
 ramdisk as a backing store.
-The LUN will claim to have a size of approximately 10 terabytes.
+The LUN will claim to have a size of approximately 10 terabytes,
+while having no real data store (all written data are lost).
 .Pp
+.Dl ctladm create -b ramdisk -s 10T -o capacity=10G
+.Pp
+Create a thin provisioned LUN with a ramdisk as a backing store.
+The LUN will have maximal backing store capacity of 10 gigabytes,
+while reporting size of 10 terabytes,
+.Pp
 .Dl ctladm create -b block -o file=src/usr.sbin/ctladm/ctladm.8
 .Pp
 Create a LUN using the block backend, and specify the file
@@ -962,13 +1029,12 @@
 This only works when the FETDs are enabled, since the commands go through the
 ioctl port.
 .Pp
-.Dl ctladm inject 0:6 -i mediumerr -p read -r 0,512 -c
+.Dl ctladm inject 6 -i mediumerr -p read -r 0,512 -c
 .Pp
 Inject a medium error on LUN 6 for every read that covers the first 512
 blocks of the LUN.
-.Pp
 .Bd -literal -offset indent
-ctladm inject 0:6 -i custom -p tur -s 18 "f0 0 02 s12 04 02"
+ctladm inject 6 -i custom -p tur -s 18 "f0 0 02 s12 04 02"
 .Ed
 .Pp
 Inject a custom error on LUN 6 for the next TEST UNIT READY command only.
@@ -980,7 +1046,9 @@
 .Xr cam 4 ,
 .Xr ctl 4 ,
 .Xr xpt 4 ,
-.Xr camcontrol 8
+.Xr camcontrol 8 ,
+.Xr ctld 8 ,
+.Xr ctlstat 8
 .Sh HISTORY
 The
 .Nm


Property changes on: trunk/usr.sbin/ctladm/ctladm.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/ctladm/ctladm.c
===================================================================
--- trunk/usr.sbin/ctladm/ctladm.c	2018-06-10 20:15:35 UTC (rev 10818)
+++ trunk/usr.sbin/ctladm/ctladm.c	2018-06-10 20:16:39 UTC (rev 10819)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2003, 2004 Silicon Graphics International Corp.
  * Copyright (c) 1997-2007 Kenneth D. Merry
@@ -32,7 +33,7 @@
  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGES.
  *
- * $Id: ctladm.c,v 1.1 2013-01-30 12:43:58 laffer1 Exp $
+ * $Id: //depot/users/kenm/FreeBSD-test2/usr.sbin/ctladm/ctladm.c#4 $
  */
 /*
  * CAM Target Layer exercise program.
@@ -41,34 +42,32 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.sbin/ctladm/ctladm.c 316253 2017-03-30 06:13:54Z ngie $");
 
+#include <sys/param.h>
+#include <sys/callout.h>
 #include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/param.h>
+#include <sys/linker.h>
 #include <sys/queue.h>
-#include <sys/callout.h>
 #include <sys/sbuf.h>
+#include <sys/stat.h>
+#include <bsdxml.h>
+#include <ctype.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <stdlib.h>
 #include <stdint.h>
 #include <stdio.h>
-#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <string.h>
-#include <errno.h>
-#include <err.h>
-#include <ctype.h>
-#include <bsdxml.h>
 #include <cam/scsi/scsi_all.h>
 #include <cam/scsi/scsi_message.h>
 #include <cam/ctl/ctl.h>
 #include <cam/ctl/ctl_io.h>
-#include <cam/ctl/ctl_frontend_internal.h>
 #include <cam/ctl/ctl_backend.h>
 #include <cam/ctl/ctl_ioctl.h>
-#include <cam/ctl/ctl_backend_block.h>
 #include <cam/ctl/ctl_util.h>
 #include <cam/ctl/ctl_scsi_all.h>
 #include <camlib.h>
@@ -94,6 +93,7 @@
 	CTLADM_CMD_READ,
 	CTLADM_CMD_WRITE,
 	CTLADM_CMD_PORT,
+	CTLADM_CMD_PORTLIST,
 	CTLADM_CMD_READCAPACITY,
 	CTLADM_CMD_MODESENSE,
 	CTLADM_CMD_DUMPOOA,
@@ -101,22 +101,18 @@
 	CTLADM_CMD_START,
 	CTLADM_CMD_STOP,
 	CTLADM_CMD_SYNC_CACHE,
-	CTLADM_CMD_SHUTDOWN,
-	CTLADM_CMD_STARTUP,
 	CTLADM_CMD_LUNLIST,
-	CTLADM_CMD_HARDSTOP,
-	CTLADM_CMD_HARDSTART,
 	CTLADM_CMD_DELAY,
-	CTLADM_CMD_REALSYNC,
-	CTLADM_CMD_SETSYNC,
-	CTLADM_CMD_GETSYNC,
 	CTLADM_CMD_ERR_INJECT,
-	CTLADM_CMD_BBRREAD,
 	CTLADM_CMD_PRES_IN,
 	CTLADM_CMD_PRES_OUT,
 	CTLADM_CMD_INQ_VPD_DEVID,
 	CTLADM_CMD_RTPG,
-	CTLADM_CMD_MODIFY
+	CTLADM_CMD_MODIFY,
+	CTLADM_CMD_ISLIST,
+	CTLADM_CMD_ISLOGOUT,
+	CTLADM_CMD_ISTERMINATE,
+	CTLADM_CMD_LUNMAP
 } ctladm_cmdfunction;
 
 typedef enum {
@@ -143,7 +139,7 @@
 	CTLADM_ARG_ONOFFLINE	= 0x0080000,
 	CTLADM_ARG_ONESHOT	= 0x0100000,
 	CTLADM_ARG_TIMEOUT	= 0x0200000,
-	CTLADM_ARG_INITIATOR 	= 0x0400000,
+	CTLADM_ARG_INITIATOR	= 0x0400000,
 	CTLADM_ARG_NOCOPY	= 0x0800000,
 	CTLADM_ARG_NEED_TL	= 0x1000000
 } ctladm_cmdargs;
@@ -162,11 +158,10 @@
 } ctladm_optret;
 
 static const char rw_opts[] = "Nb:c:d:f:l:";
-static const char startstop_opts[] = "io";
+static const char startstop_opts[] = "i";
 
-struct ctladm_opts option_table[] = {
+static struct ctladm_opts option_table[] = {
 	{"adddev", CTLADM_CMD_ADDDEV, CTLADM_ARG_NONE, NULL},
-	{"bbrread", CTLADM_CMD_BBRREAD, CTLADM_ARG_NEED_TL, "d:l:"},
 	{"create", CTLADM_CMD_CREATE, CTLADM_ARG_NONE, "b:B:d:l:o:s:S:t:"},
 	{"delay", CTLADM_CMD_DELAY, CTLADM_ARG_NEED_TL, "T:l:t:"},
 	{"devid", CTLADM_CMD_INQ_VPD_DEVID, CTLADM_ARG_NEED_TL, NULL},
@@ -173,29 +168,27 @@
 	{"devlist", CTLADM_CMD_DEVLIST, CTLADM_ARG_NONE, "b:vx"},
 	{"dumpooa", CTLADM_CMD_DUMPOOA, CTLADM_ARG_NONE, NULL},
 	{"dumpstructs", CTLADM_CMD_DUMPSTRUCTS, CTLADM_ARG_NONE, NULL},
-	{"getsync", CTLADM_CMD_GETSYNC, CTLADM_ARG_NEED_TL, NULL},
-	{"hardstart", CTLADM_CMD_HARDSTART, CTLADM_ARG_NONE, NULL},
-	{"hardstop", CTLADM_CMD_HARDSTOP, CTLADM_ARG_NONE, NULL},
 	{"help", CTLADM_CMD_HELP, CTLADM_ARG_NONE, NULL},
 	{"inject", CTLADM_CMD_ERR_INJECT, CTLADM_ARG_NEED_TL, "cd:i:p:r:s:"},
 	{"inquiry", CTLADM_CMD_INQUIRY, CTLADM_ARG_NEED_TL, NULL},
+	{"islist", CTLADM_CMD_ISLIST, CTLADM_ARG_NONE, "vx"},
+	{"islogout", CTLADM_CMD_ISLOGOUT, CTLADM_ARG_NONE, "ac:i:p:"},
+	{"isterminate", CTLADM_CMD_ISTERMINATE, CTLADM_ARG_NONE, "ac:i:p:"},
 	{"lunlist", CTLADM_CMD_LUNLIST, CTLADM_ARG_NONE, NULL},
+	{"lunmap", CTLADM_CMD_LUNMAP, CTLADM_ARG_NONE, "p:l:L:"},
 	{"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"},
-	{"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:s:"},
+	{"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:o:s:"},
 	{"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:p:qt:w:W:x"},
+	{"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ilp:qvx"},
 	{"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"},
 	{"prout", CTLADM_CMD_PRES_OUT, CTLADM_ARG_NEED_TL, "a:k:r:s:"},
 	{"read", CTLADM_CMD_READ, CTLADM_ARG_NEED_TL, rw_opts},
 	{"readcapacity", CTLADM_CMD_READCAPACITY, CTLADM_ARG_NEED_TL, "c:"},
-	{"realsync", CTLADM_CMD_REALSYNC, CTLADM_ARG_NONE, NULL},
 	{"remove", CTLADM_CMD_RM, CTLADM_ARG_NONE, "b:l:o:"},
 	{"reportluns", CTLADM_CMD_REPORT_LUNS, CTLADM_ARG_NEED_TL, NULL},
 	{"reqsense", CTLADM_CMD_REQ_SENSE, CTLADM_ARG_NEED_TL, NULL},
 	{"rtpg", CTLADM_CMD_RTPG, CTLADM_ARG_NEED_TL, NULL},
-	{"setsync", CTLADM_CMD_SETSYNC, CTLADM_ARG_NEED_TL, "i:"},
-	{"shutdown", CTLADM_CMD_SHUTDOWN, CTLADM_ARG_NONE, NULL},
 	{"start", CTLADM_CMD_START, CTLADM_ARG_NEED_TL, startstop_opts},
-	{"startup", CTLADM_CMD_STARTUP, CTLADM_ARG_NONE, NULL},
 	{"stop", CTLADM_CMD_STOP, CTLADM_ARG_NEED_TL, startstop_opts},
 	{"synccache", CTLADM_CMD_SYNC_CACHE, CTLADM_ARG_NEED_TL, "b:c:il:r"},
 	{"tur", CTLADM_CMD_TUR, CTLADM_ARG_NEED_TL, NULL},
@@ -208,55 +201,45 @@
 
 ctladm_optret getoption(struct ctladm_opts *table, char *arg, uint32_t *cmdnum,
 			ctladm_cmdargs *argnum, const char **subopt);
-static int cctl_parse_tl(char *str, int *target, int *lun);
 static int cctl_dump_ooa(int fd, int argc, char **argv);
-static int cctl_port_dump(int fd, int quiet, int xml, int32_t fe_num,
-			  ctl_port_type port_type);
 static int cctl_port(int fd, int argc, char **argv, char *combinedopt);
 static int cctl_do_io(int fd, int retries, union ctl_io *io, const char *func);
-static int cctl_delay(int fd, int target, int lun, int argc, char **argv,
+static int cctl_delay(int fd, int lun, int argc, char **argv,
 		      char *combinedopt);
 static int cctl_lunlist(int fd);
-static void cctl_cfi_mt_statusstr(cfi_mt_status status, char *str, int str_len);
-static void cctl_cfi_bbr_statusstr(cfi_bbrread_status, char *str, int str_len);
-static int cctl_hardstopstart(int fd, ctladm_cmdfunction command);
-static int cctl_bbrread(int fd, int target, int lun, int iid, int argc,
-			char **argv, char *combinedopt);
-static int cctl_startup_shutdown(int fd, int target, int lun, int iid,
-				 ctladm_cmdfunction command);
-static int cctl_sync_cache(int fd, int target, int lun, int iid, int retries,
+static int cctl_sync_cache(int fd, int lun, int iid, int retries,
 			   int argc, char **argv, char *combinedopt);
-static int cctl_start_stop(int fd, int target, int lun, int iid, int retries,
+static int cctl_start_stop(int fd, int lun, int iid, int retries,
 			   int start, int argc, char **argv, char *combinedopt);
-static int cctl_mode_sense(int fd, int target, int lun, int iid, int retries, 
+static int cctl_mode_sense(int fd, int lun, int iid, int retries,
 			   int argc, char **argv, char *combinedopt);
-static int cctl_read_capacity(int fd, int target, int lun, int iid,
+static int cctl_read_capacity(int fd, int lun, int iid,
 			      int retries, int argc, char **argv,
 			      char *combinedopt);
-static int cctl_read_write(int fd, int target, int lun, int iid, int retries,
+static int cctl_read_write(int fd, int lun, int iid, int retries,
 			   int argc, char **argv, char *combinedopt,
 			   ctladm_cmdfunction command);
-static int cctl_get_luns(int fd, int target, int lun, int iid, int retries,
+static int cctl_get_luns(int fd, int lun, int iid, int retries,
 			 struct scsi_report_luns_data **lun_data,
 			 uint32_t *num_luns);
-static int cctl_report_luns(int fd, int target, int lun, int iid, int retries);
-static int cctl_tur(int fd, int target, int lun, int iid, int retries);
-static int cctl_get_inquiry(int fd, int target, int lun, int iid, int retries,
+static int cctl_report_luns(int fd, int lun, int iid, int retries);
+static int cctl_tur(int fd, int lun, int iid, int retries);
+static int cctl_get_inquiry(int fd, int lun, int iid, int retries,
 			    char *path_str, int path_len,
 			    struct scsi_inquiry_data *inq_data);
-static int cctl_inquiry(int fd, int target, int lun, int iid, int retries);
-static int cctl_req_sense(int fd, int target, int lun, int iid, int retries);
-static int cctl_persistent_reserve_in(int fd, int target, int lun,
+static int cctl_inquiry(int fd, int lun, int iid, int retries);
+static int cctl_req_sense(int fd, int lun, int iid, int retries);
+static int cctl_persistent_reserve_in(int fd, int lun,
 				      int initiator, int argc, char **argv,
 				      char *combinedopt, int retry_count);
-static int cctl_persistent_reserve_out(int fd, int target, int lun, 
+static int cctl_persistent_reserve_out(int fd, int lun,
 				       int initiator, int argc, char **argv,
 				       char *combinedopt, int retry_count);
 static int cctl_create_lun(int fd, int argc, char **argv, char *combinedopt);
-static int cctl_inquiry_vpd_devid(int fd, int target, int lun, int initiator);
-static int cctl_report_target_port_group(int fd, int target, int lun,
-					 int initiator);
+static int cctl_inquiry_vpd_devid(int fd, int lun, int initiator);
+static int cctl_report_target_port_group(int fd, int lun, int initiator);
 static int cctl_modify_lun(int fd, int argc, char **argv, char *combinedopt);
+static int cctl_portlist(int fd, int argc, char **argv, char *combinedopt);
 
 ctladm_optret
 getoption(struct ctladm_opts *table, char *arg, uint32_t *cmdnum,
@@ -286,68 +269,31 @@
 		return(CC_OR_NOT_FOUND);
 }
 
-
 static int
-cctl_parse_tl(char *str, int *target, int *lun)
-{
-	char *tmpstr;
-	int retval;
-
-	retval = 0;
-
-	while (isspace(*str) && (*str != '\0'))
-		str++;
-
-	tmpstr = (char *)strtok(str, ":");
-	if ((tmpstr != NULL) && (*tmpstr != '\0')) {
-		*target = strtol(tmpstr, NULL, 0);
-		tmpstr = (char *)strtok(NULL, ":");
-		if ((tmpstr != NULL) && (*tmpstr != '\0')) {
-			*lun = strtol(tmpstr, NULL, 0);
-		} else
-			retval = -1;
-	} else
-		retval = -1;
-
-	return (retval);
-}
-
-static int
 cctl_dump_ooa(int fd, int argc, char **argv)
 {
 	struct ctl_ooa ooa;
 	long double cmd_latency;
-	int num_entries, len;
-	int target = -1, lun = -1;
-	int retval;
+	int num_entries, len, lun = -1, retval = 0;
 	unsigned int i;
 
 	num_entries = 104;
 
-	if ((argc > 2)
-	 && (isdigit(argv[2][0]))) {
-		retval = cctl_parse_tl(argv[2], &target, &lun);
-		if (retval != 0)
-			warnx("invalid target:lun argument %s", argv[2]);
-	}
+	if ((argc > 2) && (isdigit(argv[2][0])))
+		lun = strtol(argv[2], NULL, 0);
 retry:
 
 	len = num_entries * sizeof(struct ctl_ooa_entry);
-
 	bzero(&ooa, sizeof(ooa));
-
 	ooa.entries = malloc(len);
-
 	if (ooa.entries == NULL) {
 		warn("%s: error mallocing %d bytes", __func__, len);
 		return (1);
 	}
-
-	if (argc > 2) {
+	if (lun >= 0) {
 		ooa.lun_num = lun;
 	} else
 		ooa.flags |= CTL_OOA_FLAG_ALL_LUNS;
-
 	ooa.alloc_len = len;
 	ooa.alloc_num = num_entries;
 	if (ioctl(fd, CTL_GET_OOA, &ooa) == -1) {
@@ -385,7 +331,7 @@
 		cmd_latency = ts.tv_sec * 1000;
 		if (ts.tv_nsec > 0)
 			cmd_latency += ts.tv_nsec / 1000000;
-		
+
 		fprintf(stdout, "LUN %jd tag 0x%04x%s%s%s%s%s: %s. CDB: %s "
 			"(%0.0Lf ms)\n",
 			(intmax_t)entry->lun_num, entry->tag_num,
@@ -402,17 +348,10 @@
 			cmd_latency);
 	}
 	fprintf(stdout, "OOA queues dump done\n");
-#if 0
-	if (ioctl(fd, CTL_DUMP_OOA) == -1) {
-		warn("%s: CTL_DUMP_OOA ioctl failed", __func__);
-		return (1);
-	}
-#endif
 
 bailout:
 	free(ooa.entries);
-
-	return (0);
+	return (retval);
 }
 
 static int
@@ -425,146 +364,6 @@
 	return (0);
 }
 
-static int
-cctl_port_dump(int fd, int quiet, int xml, int32_t targ_port,
-	       ctl_port_type port_type)
-{
-	struct ctl_port_list port_list;
-	struct ctl_port_entry *entries;
-	struct sbuf *sb = NULL;
-	int num_entries;
-	int did_print = 0;
-	unsigned int i;
-
-	num_entries = 16;
-
-retry:
-
-	entries = malloc(sizeof(*entries) * num_entries);
-	bzero(&port_list, sizeof(port_list));
-	port_list.entries = entries;
-	port_list.alloc_num = num_entries;
-	port_list.alloc_len = num_entries * sizeof(*entries);
-	if (ioctl(fd, CTL_GET_PORT_LIST, &port_list) != 0) {
-		warn("%s: CTL_GET_PORT_LIST ioctl failed", __func__);
-		return (1);
-	}
-	if (port_list.status == CTL_PORT_LIST_NEED_MORE_SPACE) {
-		printf("%s: allocated %d, need %d, retrying\n", __func__,
-		       num_entries, port_list.fill_num + port_list.dropped_num);
-		free(entries);
-		num_entries = port_list.fill_num + port_list.dropped_num;
-		goto retry;
-	}
-
-	if ((quiet == 0)
-	 && (xml == 0))
-		printf("Port Online Type     Name         pp vp %-18s %-18s\n",
-		       "WWNN", "WWPN");
-
-	if (xml != 0) {
-		sb = sbuf_new_auto();
-		sbuf_printf(sb, "<ctlfelist>\n");
-	}
-	for (i = 0; i < port_list.fill_num; i++) {
-		struct ctl_port_entry *entry;
-		const char *type;
-
-		entry = &entries[i];
-
-		switch (entry->port_type) {
-		case CTL_PORT_FC:
-			type = "FC";
-			break;
-		case CTL_PORT_SCSI:
-			type = "SCSI";
-			break;
-		case CTL_PORT_IOCTL:
-			type = "IOCTL";
-			break;
-		case CTL_PORT_INTERNAL:
-			type = "INTERNAL";
-			break;
-		case CTL_PORT_ISC:
-			type = "ISC";
-			break;
-		default:
-			type = "UNKNOWN";
-			break;
-		}
-
-		/*
-		 * If the user specified a frontend number or a particular
-		 * frontend type, only print out that particular frontend
-		 * or frontend type.
-		 */
-		if ((targ_port != -1)
-		 && (targ_port != entry->targ_port))
-			continue;
-		else if ((port_type != CTL_PORT_NONE)
-		      && ((port_type & entry->port_type) == 0))
-			continue;
-
-		did_print = 1;
-
-#if 0
-		printf("Num: %ju Type: %s (%#x) Name: %s Physical Port: %d "
-		       "Virtual Port: %d\n", (uintmax_t)entry->fe_num, type,
-		       entry->port_type, entry->fe_name, entry->physical_port,
-		       entry->virtual_port);
-		printf("WWNN %#jx WWPN %#jx Online: %s\n",
-		       (uintmax_t)entry->wwnn, (uintmax_t)entry->wwpn,
-		       (entry->online) ? "YES" : "NO" );
-#endif
-		if (xml == 0) {
-			printf("%-4d %-6s %-8s %-12s %-2d %-2d %#-18jx "
-			       "%#-18jx\n",
-			       entry->targ_port, (entry->online) ? "YES" : "NO",
-			       type, entry->port_name, entry->physical_port,
-			       entry->virtual_port, (uintmax_t)entry->wwnn,
-			       (uintmax_t)entry->wwpn);
-		} else {
-			sbuf_printf(sb, "<targ_port id=\"%d\">\n",
-				    entry->targ_port);
-			sbuf_printf(sb, "<online>%s</online>\n",
-				    (entry->online) ? "YES" : "NO");
-			sbuf_printf(sb, "<port_type>%s</port_type>\n", type);
-			sbuf_printf(sb, "<port_name>%s</port_name>\n",
-				    entry->port_name);
-			sbuf_printf(sb, "<physical_port>%d</physical_port>\n",
-				    entry->physical_port);
-			sbuf_printf(sb, "<virtual_port>%d</virtual_port>\n",
-				    entry->virtual_port);
-			sbuf_printf(sb, "<wwnn>%#jx</wwnn>\n",
-				    (uintmax_t)entry->wwnn);
-			sbuf_printf(sb, "<wwpn>%#jx</wwpn>\n",
-				    (uintmax_t)entry->wwpn);
-			sbuf_printf(sb, "</targ_port>\n");
-		}
-
-	}
-	if (xml != 0) {
-		sbuf_printf(sb, "</ctlfelist>\n");
-		if (sbuf_finish(sb) != 0)
-			err(1, "%s: sbuf_finish", __func__);
-		printf("%s", sbuf_data(sb));
-		sbuf_delete(sb);
-	}
-
-	/*
-	 * Give some indication that we didn't find the frontend or
-	 * frontend type requested by the user.  We could print something
-	 * out, but it would probably be better to hide that behind a
-	 * verbose flag.
-	 */
-	if ((did_print == 0)
-	 && ((targ_port != -1)
-	  || (port_type != CTL_PORT_NONE)))
-		return (1);
-	else
-		return (0);
-}
-
 typedef enum {
 	CCTL_PORT_MODE_NONE,
 	CCTL_PORT_MODE_LIST,
@@ -573,10 +372,12 @@
 	CCTL_PORT_MODE_OFF
 } cctl_port_mode;
 
-struct ctladm_opts cctl_fe_table[] = {
+static struct ctladm_opts cctl_fe_table[] = {
 	{"fc", CTL_PORT_FC, CTLADM_ARG_NONE, NULL},
 	{"scsi", CTL_PORT_SCSI, CTLADM_ARG_NONE, NULL},
 	{"internal", CTL_PORT_INTERNAL, CTLADM_ARG_NONE, NULL},
+	{"iscsi", CTL_PORT_ISCSI, CTLADM_ARG_NONE, NULL},
+	{"sas", CTL_PORT_SAS, CTLADM_ARG_NONE, NULL},
 	{"all", CTL_PORT_ALL, CTLADM_ARG_NONE, NULL},
 	{NULL, 0, 0, NULL}
 };
@@ -605,7 +406,7 @@
 		case 'o':
 			if (port_mode != CCTL_PORT_MODE_NONE)
 				goto bailout_badarg;
-			
+
 			if (strcasecmp(optarg, "on") == 0)
 				port_mode = CCTL_PORT_MODE_ON;
 			else if (strcasecmp(optarg, "off") == 0)
@@ -689,7 +490,7 @@
 	} else if ((targ_port == -1) && (port_type == CTL_PORT_NONE))
 		port_type = CTL_PORT_ALL;
 
-	bzero(&entry, sizeof(&entry));
+	bzero(&entry, sizeof(entry));
 
 	/*
 	 * These are needed for all but list/dump mode.
@@ -698,9 +499,22 @@
 	entry.targ_port = targ_port;
 
 	switch (port_mode) {
-	case CCTL_PORT_MODE_LIST:
-		cctl_port_dump(fd, quiet, xml, targ_port, port_type);
+	case CCTL_PORT_MODE_LIST: {
+		char opts[] = "xq";
+		char argx[] = "-x";
+		char argq[] = "-q";
+		char *argvx[2];
+		int argcx = 0;
+
+		optind = 0;
+		optreset = 1;
+		if (xml)
+			argvx[argcx++] = argx;
+		if (quiet)
+			argvx[argcx++] = argq;
+		cctl_portlist(fd, argcx, argvx, opts);
 		break;
+	}
 	case CCTL_PORT_MODE_SET:
 		if (targ_port == -1) {
 			warnx("%s: -w and -W require -n", __func__);
@@ -770,7 +584,7 @@
 }
 
 static int
-cctl_delay(int fd, int target, int lun, int argc, char **argv,
+cctl_delay(int fd, int lun, int argc, char **argv,
 	   char *combinedopt)
 {
 	struct ctl_io_delay_info delay_info;
@@ -825,7 +639,6 @@
 		goto bailout;
 	}
 
-	delay_info.target_id = target;
 	delay_info.lun_id = lun;
 	delay_info.delay_secs = delaytime;
 
@@ -866,141 +679,14 @@
 		retval = 1;
 		break;
 	}
-bailout:
 
-	/* delayloc should never be NULL, but just in case...*/
-	if (delayloc != NULL)
-		free(delayloc);
-
-	return (retval);
-}
-
-static int
-cctl_realsync(int fd, int argc, char **argv)
-{
-	int syncstate;
-	int retval;
-	char *syncarg;
-
-	retval = 0;
-
-	if (argc != 3) {
-		warnx("%s %s takes exactly one argument", argv[0], argv[1]);
-		retval = 1;
-		goto bailout;
-	}
-
-	syncarg = argv[2];
-
-	if (strncasecmp(syncarg, "query", min(strlen(syncarg),
-			strlen("query"))) == 0) {
-		if (ioctl(fd, CTL_REALSYNC_GET, &syncstate) == -1) {
-			warn("%s: CTL_REALSYNC_GET ioctl failed", __func__);
-			retval = 1;
-			goto bailout;
-		}
-		fprintf(stdout, "SYNCHRONIZE CACHE support is: ");
-		switch (syncstate) {
-		case 0:
-			fprintf(stdout, "OFF\n");
-			break;
-		case 1:
-			fprintf(stdout, "ON\n");
-			break;
-		default:
-			fprintf(stdout, "unknown (%d)\n", syncstate);
-			break;
-		}
-		goto bailout;
-	} else if (strcasecmp(syncarg, "on") == 0) {
-		syncstate = 1;
-	} else if (strcasecmp(syncarg, "off") == 0) {
-		syncstate = 0;
-	} else {
-		warnx("%s: invalid realsync argument %s", __func__, syncarg);
-		retval = 1;
-		goto bailout;
-	}
-
-	if (ioctl(fd, CTL_REALSYNC_SET, &syncstate) == -1) {
-		warn("%s: CTL_REALSYNC_SET ioctl failed", __func__);
-		retval = 1;
-		goto bailout;
-	}
 bailout:
+	free(delayloc);
+	free(delaytype);
 	return (retval);
 }
 
-static int
-cctl_getsetsync(int fd, int target, int lun, ctladm_cmdfunction command,
-		int argc, char **argv, char *combinedopt)
-{
-	struct ctl_sync_info sync_info;
-	uint32_t ioctl_cmd;
-	int sync_interval = -1;
-	int retval;
-	int c;
-
-	retval = 0;
-
-	memset(&sync_info, 0, sizeof(sync_info));
-	sync_info.target_id = target;
-	sync_info.lun_id = lun;
-
-	while ((c = getopt(argc, argv, combinedopt)) != -1) {
-		switch (c) {
-		case 'i':
-			sync_interval = strtoul(optarg, NULL, 0);
-			break;
-		default:
-			break;
-		}
-	}
-
-	if (command == CTLADM_CMD_SETSYNC) {
-		if (sync_interval == -1) {
-			warnx("%s: you must specify the sync interval with -i",
-			      __func__);
-			retval = 1;
-			goto bailout;
-		}
-		sync_info.sync_interval = sync_interval;
-		ioctl_cmd = CTL_SETSYNC;
-	} else {
-		ioctl_cmd = CTL_GETSYNC;
-	}
-
-	if (ioctl(fd, ioctl_cmd, &sync_info) == -1) {
-		warn("%s: CTL_%sSYNC ioctl failed", __func__,
-		     (command == CTLADM_CMD_SETSYNC) ? "SET" : "GET");
-		retval = 1;
-		goto bailout;
-	}
-
-	switch (sync_info.status) {
-	case CTL_GS_SYNC_OK:
-		if (command == CTLADM_CMD_GETSYNC) {
-			fprintf(stdout, "%d:%d: sync interval: %d\n",
-				target, lun, sync_info.sync_interval);
-		}
-		break;
-	case CTL_GS_SYNC_NO_LUN:
-		warnx("%s: unknown target:LUN %d:%d", __func__, target, lun);
-		retval = 1;
-		break;
-	case CTL_GS_SYNC_NONE:
-	default:
-		warnx("%s: unknown CTL_%sSYNC status %d", __func__,
-		      (command == CTLADM_CMD_SETSYNC) ? "SET" : "GET",
-		      sync_info.status);
-		retval = 1;
-		break;
-	}
-bailout:
-	return (retval);
-}
-
-struct ctladm_opts cctl_err_types[] = {
+static struct ctladm_opts cctl_err_types[] = {
 	{"aborted", CTL_LUN_INJ_ABORTED, CTLADM_ARG_NONE, NULL},
 	{"mediumerr", CTL_LUN_INJ_MEDIUM_ERR, CTLADM_ARG_NONE, NULL},
 	{"ua", CTL_LUN_INJ_UA, CTLADM_ARG_NONE, NULL},
@@ -1009,7 +695,7 @@
 
 };
 
-struct ctladm_opts cctl_err_patterns[] = {
+static struct ctladm_opts cctl_err_patterns[] = {
 	{"read", CTL_LUN_PAT_READ, CTLADM_ARG_NONE, NULL},
 	{"write", CTL_LUN_PAT_WRITE, CTLADM_ARG_NONE, NULL},
 	{"rw", CTL_LUN_PAT_READWRITE, CTLADM_ARG_NONE, NULL},
@@ -1024,7 +710,7 @@
 };
 
 static int
-cctl_error_inject(int fd, uint32_t target, uint32_t lun, int argc, char **argv, 
+cctl_error_inject(int fd, uint32_t lun, int argc, char **argv,
 		  char *combinedopt)
 {
 	int retval = 0;
@@ -1039,7 +725,6 @@
 	int c;
 
 	bzero(&err_desc, sizeof(err_desc));
-	err_desc.target_id = target;
 	err_desc.lun_id = lun;
 
 	while ((c = getopt(argc, argv, combinedopt)) != -1) {
@@ -1189,12 +874,12 @@
         if (fd_sense == 1) {
 		ssize_t amt_read;
 		int amt_to_read = sense_len;
- 		u_int8_t *buf_ptr = (uint8_t *)&err_desc.custom_sense;
+		u_int8_t *buf_ptr = (uint8_t *)&err_desc.custom_sense;
 
 		for (amt_read = 0; amt_to_read > 0;
 		     amt_read = read(STDIN_FILENO, buf_ptr, amt_to_read)) {
 			if (amt_read == -1) {
-         			warn("error reading sense data from stdin");
+				warn("error reading sense data from stdin");
 				retval = 1;
 				goto bailout;
 			}
@@ -1250,15 +935,11 @@
 	struct scsi_report_luns_data *lun_data;
 	struct scsi_inquiry_data *inq_data;
 	uint32_t num_luns;
-	int target;
 	int initid;
 	unsigned int i;
 	int retval;
 
-	retval = 0;
 	inq_data = NULL;
-
-	target = 6;
 	initid = 7;
 
 	/*
@@ -1265,7 +946,7 @@
 	 * XXX KDM assuming LUN 0 is fine, but we may need to change this
 	 * if we ever acquire the ability to have multiple targets.
 	 */
-	if ((retval = cctl_get_luns(fd, target, /*lun*/ 0, initid,
+	if ((retval = cctl_get_luns(fd, /*lun*/ 0, initid,
 				    /*retries*/ 2, &lun_data, &num_luns)) != 0)
 		goto bailout;
 
@@ -1302,7 +983,7 @@
 		if (lun_val == -1)
 			continue;
 
-		if ((retval = cctl_get_inquiry(fd, target, lun_val, initid,
+		if ((retval = cctl_get_inquiry(fd, lun_val, initid,
 					       /*retries*/ 2, scsi_path,
 					       sizeof(scsi_path),
 					       inq_data)) != 0) {
@@ -1322,356 +1003,21 @@
 	return (retval);
 }
 
-static void
-cctl_cfi_mt_statusstr(cfi_mt_status status, char *str, int str_len)
-{
-	switch (status) {
-	case CFI_MT_PORT_OFFLINE:
-		snprintf(str, str_len, "Port Offline");
-		break;
-	case CFI_MT_ERROR:
-		snprintf(str, str_len, "Error");
-		break;
-	case CFI_MT_SUCCESS:
-		snprintf(str, str_len, "Success");
-		break;
-	case CFI_MT_NONE:
-		snprintf(str, str_len, "None??");
-		break;
-	default:
-		snprintf(str, str_len, "Unknown status: %d", status);
-		break;
-	}
-}
-
-static void
-cctl_cfi_bbr_statusstr(cfi_bbrread_status status, char *str, int str_len)
-{
-	switch (status) {
-	case CFI_BBR_SUCCESS:
-		snprintf(str, str_len, "Success");
-		break;
-	case CFI_BBR_LUN_UNCONFIG:
-		snprintf(str, str_len, "LUN not configured");
-		break;
-	case CFI_BBR_NO_LUN:
-		snprintf(str, str_len, "LUN does not exist");
-		break;
-	case CFI_BBR_NO_MEM:
-		snprintf(str, str_len, "Memory allocation error");
-		break;
-	case CFI_BBR_BAD_LEN:
-		snprintf(str, str_len, "Length is not a multiple of blocksize");
-		break;
-	case CFI_BBR_RESERV_CONFLICT:
-		snprintf(str, str_len, "Reservation conflict");
-		break;
-	case CFI_BBR_LUN_STOPPED:
-		snprintf(str, str_len, "LUN is powered off");
-		break;
-	case CFI_BBR_LUN_OFFLINE_CTL:
-		snprintf(str, str_len, "LUN is offline");
-		break;
-	case CFI_BBR_LUN_OFFLINE_RC:
-		snprintf(str, str_len, "RAIDCore array is offline (double "
-			 "failure?)");
-		break;
-	case CFI_BBR_SCSI_ERROR:
-		snprintf(str, str_len, "SCSI Error");
-		break;
-	case CFI_BBR_ERROR:
-		snprintf(str, str_len, "Error");
-		break;
-	default:
-		snprintf(str, str_len, "Unknown status: %d", status);
-		break;
-	}
-}
-
 static int
-cctl_hardstopstart(int fd, ctladm_cmdfunction command)
-{
-	struct ctl_hard_startstop_info hs_info;
-	char error_str[256];
-	int do_start;
-	int retval;
-
-	retval = 0;
-
-	if (command == CTLADM_CMD_HARDSTART)
-		do_start = 1;
-	else
-		do_start = 0;
-
-	if (ioctl(fd, (do_start == 1) ? CTL_HARD_START : CTL_HARD_STOP,
-		  &hs_info) == -1) {
-		warn("%s: CTL_HARD_%s ioctl failed", __func__,
-		     (do_start == 1) ? "START" : "STOP");
-		retval = 1;
-		goto bailout;
-	}
-
-	fprintf(stdout, "Hard %s Status: ", (command == CTLADM_CMD_HARDSTOP) ?
-		"Stop" : "Start");
-	cctl_cfi_mt_statusstr(hs_info.status, error_str, sizeof(error_str));
-	fprintf(stdout, "%s\n", error_str);
-	fprintf(stdout, "Total LUNs: %d\n", hs_info.total_luns);
-	fprintf(stdout, "LUNs complete: %d\n", hs_info.luns_complete);
-	fprintf(stdout, "LUNs failed: %d\n", hs_info.luns_failed);
-
-bailout:
-	return (retval);
-}
-
-static int
-cctl_bbrread(int fd, int target __unused, int lun, int iid __unused,
-	     int argc, char **argv, char *combinedopt)
-{
-	struct ctl_bbrread_info bbr_info;
-	char error_str[256];
-	int datalen = -1;
-	uint64_t lba = 0;
-	int lba_set = 0;
-	int retval;
-	int c;
-
-	retval = 0;
-
-	while ((c = getopt(argc, argv, combinedopt)) != -1) {
-		switch (c) {
-		case 'd':
-			datalen = strtoul(optarg, NULL, 0);
-			break;
-		case 'l':
-			lba = strtoull(optarg, NULL, 0);
-			lba_set = 1;
-			break;
-		default:
-			break;
-		}
-	}
-
-	if (lba_set == 0) {
-		warnx("%s: you must specify an LBA with -l", __func__);
-		retval = 1;
-		goto bailout;
-	}
-
-	if (datalen == -1) {
-		warnx("%s: you must specify a length with -d", __func__);
-		retval = 1;
-		goto bailout;
-	}
-
-	bbr_info.lun_num = lun;
-	bbr_info.lba = lba;
-	/*
-	 * XXX KDM get the blocksize first??
-	 */
-	if ((datalen % 512) != 0) {
-		warnx("%s: data length %d is not a multiple of 512 bytes",
-		     __func__, datalen);
-		retval = 1;
-		goto bailout;
-	}
-	bbr_info.len = datalen;
-
-	if (ioctl(fd, CTL_BBRREAD, &bbr_info) == -1) {
-		warn("%s: CTL_BBRREAD ioctl failed", __func__);
-		retval = 1;
-		goto bailout;
-	}
-	cctl_cfi_mt_statusstr(bbr_info.status, error_str, sizeof(error_str));
-	fprintf(stdout, "BBR Read Overall Status: %s\n", error_str);
-	cctl_cfi_bbr_statusstr(bbr_info.bbr_status, error_str,
-			       sizeof(error_str));
-	fprintf(stdout, "BBR Read Status: %s\n", error_str);
-	/*
-	 * XXX KDM should we bother printing out SCSI status if we get
-	 * CFI_BBR_SCSI_ERROR back?
-	 *
-	 * Return non-zero if this fails?
-	 */
-bailout:
-	return (retval);
-}
-
-static int
-cctl_startup_shutdown(int fd, int target, int lun, int iid,
-		      ctladm_cmdfunction command)
-{
-	union ctl_io *io;
-	struct ctl_id id;
-	struct scsi_report_luns_data *lun_data;
-	struct scsi_inquiry_data *inq_data;
-	uint32_t num_luns;
-	unsigned int i;
-	int retval;
-
-	retval = 0;
-	inq_data = NULL;
-
-	/*
-	 * - report luns
-	 * - step through each lun, do an inquiry
-	 * - check OOA queue on direct access luns
-	 * - send stop with offline bit to each direct access device with a
-	 *   clear OOA queue
-	 *   - if we get a reservation conflict, reset the LUN to clear it
-	 *     and reissue the stop with the offline bit set
-	 */
-
-	id.id = iid;
-
-	io = ctl_scsi_alloc_io(id);
-	if (io == NULL) {
-		warnx("%s: can't allocate memory", __func__);
-		return (1);
-	}
-
-	if ((retval = cctl_get_luns(fd, target, lun, iid, /*retries*/ 2,
-				    &lun_data, &num_luns)) != 0)
-		goto bailout;
-
-	inq_data = malloc(sizeof(*inq_data));
-	if (inq_data == NULL) {
-		warn("%s: couldn't allocate memory for inquiry data\n",
-		     __func__);
-		retval = 1;
-		goto bailout;
-	}
-	for (i = 0; i < num_luns; i++) {
-		char scsi_path[40];
-		int lun_val;
-
-		/*
-		 * XXX KDM figure out a way to share this code with
-		 * cctl_lunlist()?
-		 */
-		switch (lun_data->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) {
-		case RPL_LUNDATA_ATYP_PERIPH:
-			lun_val = lun_data->luns[i].lundata[1];
-			break;
-		case RPL_LUNDATA_ATYP_FLAT:
-			lun_val = (lun_data->luns[i].lundata[0] &
-				RPL_LUNDATA_FLAT_LUN_MASK) |
-				(lun_data->luns[i].lundata[1] <<
-				RPL_LUNDATA_FLAT_LUN_BITS);
-			break;
-		case RPL_LUNDATA_ATYP_LUN:
-		case RPL_LUNDATA_ATYP_EXTLUN:
-		default:
-			fprintf(stdout, "Unsupported LUN format %d\n",
-				lun_data->luns[i].lundata[0] &
-				RPL_LUNDATA_ATYP_MASK);
-			lun_val = -1;
-			break;
-		}
-		if (lun_val == -1)
-			continue;
-
-		if ((retval = cctl_get_inquiry(fd, target, lun_val, iid,
-					       /*retries*/ 2, scsi_path,
-					       sizeof(scsi_path),
-					       inq_data)) != 0) {
-			goto bailout;
-		}
-		printf("%s", scsi_path);
-		scsi_print_inquiry(inq_data);
-		/*
-		 * We only want to shutdown direct access devices.
-		 */
-		if (SID_TYPE(inq_data) != T_DIRECT) {
-			printf("%s LUN is not direct access, skipped\n",
-			       scsi_path);
-			continue;
-		}
-
-		if (command == CTLADM_CMD_SHUTDOWN) {
-			struct ctl_ooa_info ooa_info;
-
-			ooa_info.target_id = target;
-			ooa_info.lun_id = lun_val;
-
-			if (ioctl(fd, CTL_CHECK_OOA, &ooa_info) == -1) {
-				printf("%s CTL_CHECK_OOA ioctl failed\n",
-				       scsi_path);
-				continue;
-			}
-
-			if (ooa_info.status != CTL_OOA_SUCCESS) {
-				printf("%s CTL_CHECK_OOA returned status %d\n", 
-				       scsi_path, ooa_info.status);
-				continue;
-			}
-			if (ooa_info.num_entries != 0) {
-				printf("%s %d entr%s in the OOA queue, "
-				       "skipping shutdown\n", scsi_path,
-				       ooa_info.num_entries,
-				       (ooa_info.num_entries > 1)?"ies" : "y" );
-				continue;
-			}
-		}
-		
-		ctl_scsi_start_stop(/*io*/ io,
-				    /*start*/(command == CTLADM_CMD_STARTUP) ?
-					      1 : 0,
-				    /*load_eject*/ 0,
-				    /*immediate*/ 0,
-				    /*power_conditions*/ SSS_PC_START_VALID,
-				    /*onoffline*/ 1,
-				    /*ctl_tag_type*/
-				    (command == CTLADM_CMD_STARTUP) ?
-				    CTL_TAG_SIMPLE :CTL_TAG_ORDERED,
-				    /*control*/ 0);
-
-		io->io_hdr.nexus.targ_target.id = target;
-		io->io_hdr.nexus.targ_lun = lun_val;
-		io->io_hdr.nexus.initid = id;
-
-		if (cctl_do_io(fd, /*retries*/ 3, io, __func__) != 0) {
-			retval = 1;
-			goto bailout;
-		}
-
-		if ((io->io_hdr.status & CTL_STATUS_MASK) != CTL_SUCCESS)
-			ctl_io_error_print(io, inq_data, stderr);
-		else {
-			printf("%s LUN is now %s\n", scsi_path,
-			       (command == CTLADM_CMD_STARTUP) ? "online" :
-			       "offline");
-		}
-	}
-bailout:
-	if (lun_data != NULL)
-		free(lun_data);
-
-	if (inq_data != NULL)
-		free(inq_data);
-
-	if (io != NULL)
-		ctl_scsi_free_io(io);
-
-	return (retval);
-}
-
-static int
-cctl_sync_cache(int fd, int target, int lun, int iid, int retries,
+cctl_sync_cache(int fd, int lun, int iid, int retries,
 		int argc, char **argv, char *combinedopt)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	int cdb_size = -1;
 	int retval;
 	uint64_t our_lba = 0;
 	uint32_t our_block_count = 0;
-	int reladr = 0, immed = 0; 
+	int reladr = 0, immed = 0;
 	int c;
 
-	id.id = iid;
 	retval = 0;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warnx("%s: can't allocate memory", __func__);
 		return (1);
@@ -1723,9 +1069,8 @@
 			    /*tag_type*/ CTL_TAG_SIMPLE,
 			    /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -1743,19 +1088,17 @@
 }
 
 static int
-cctl_start_stop(int fd, int target, int lun, int iid, int retries, int start,
+cctl_start_stop(int fd, int lun, int iid, int retries, int start,
 		int argc, char **argv, char *combinedopt)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	char scsi_path[40];
-	int immed = 0, onoffline = 0;
+	int immed = 0;
 	int retval, c;
 
-	id.id = iid;
 	retval = 0;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warnx("%s: can't allocate memory", __func__);
 		return (1);
@@ -1766,9 +1109,6 @@
 		case 'i':
 			immed = 1;
 			break;
-		case 'o':
-			onoffline = 1;
-			break;
 		default:
 			break;
 		}
@@ -1785,14 +1125,12 @@
 			    /*load_eject*/ 0,
 			    /*immediate*/ immed,
 			    /*power_conditions*/ SSS_PC_START_VALID,
-			    /*onoffline*/ onoffline,
 			    /*ctl_tag_type*/ start ? CTL_TAG_SIMPLE :
 						     CTL_TAG_ORDERED,
 			    /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -1813,11 +1151,10 @@
 }
 
 static int
-cctl_mode_sense(int fd, int target, int lun, int iid, int retries, 
+cctl_mode_sense(int fd, int lun, int iid, int retries,
 		int argc, char **argv, char *combinedopt)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t datalen;
 	uint8_t *dataptr;
 	int pc = -1, cdbsize, retval, dbd = 0, subpage = -1;
@@ -1825,12 +1162,11 @@
 	int page_code = -1;
 	int c;
 
-	id.id = iid;
 	cdbsize = 0;
 	retval = 0;
 	dataptr = NULL;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory", __func__);
 		return (1);
@@ -1958,9 +1294,8 @@
 			    /*tag_type*/ CTL_TAG_SIMPLE,
 			    /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -2031,11 +1366,10 @@
 }
 
 static int
-cctl_read_capacity(int fd, int target, int lun, int iid, int retries, 
-           	   int argc, char **argv, char *combinedopt)
+cctl_read_capacity(int fd, int lun, int iid, int retries,
+		   int argc, char **argv, char *combinedopt)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	struct scsi_read_capacity_data *data;
 	struct scsi_read_capacity_data_long *longdata;
 	int cdbsize = -1, retval;
@@ -2045,9 +1379,8 @@
 	cdbsize = 10;
 	dataptr = NULL;
 	retval = 0;
-	id.id = iid;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory\n", __func__);
 		return (1);
@@ -2111,8 +1444,7 @@
 		break;
 	}
 
-	io->io_hdr.nexus.initid = id;
-	io->io_hdr.nexus.targ_target.id = target;
+	io->io_hdr.nexus.initid = iid;
 	io->io_hdr.nexus.targ_lun = lun;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
@@ -2157,12 +1489,11 @@
 }
 
 static int
-cctl_read_write(int fd, int target, int lun, int iid, int retries,
+cctl_read_write(int fd, int lun, int iid, int retries,
 		int argc, char **argv, char *combinedopt,
 		ctladm_cmdfunction command)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	int file_fd, do_stdio;
 	int cdbsize = -1, databytes;
 	uint8_t *dataptr;
@@ -2177,9 +1508,8 @@
 	do_stdio = 0;
 	dataptr = NULL;
 	file_fd = -1;
-	id.id = iid;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory\n", __func__);
 		return (1);
@@ -2303,9 +1633,8 @@
 			    /*tag_type*/ CTL_TAG_SIMPLE,
 			    /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -2340,19 +1669,17 @@
 }
 
 static int
-cctl_get_luns(int fd, int target, int lun, int iid, int retries, struct
+cctl_get_luns(int fd, int lun, int iid, int retries, struct
 	      scsi_report_luns_data **lun_data, uint32_t *num_luns)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t nluns;
 	int lun_datalen;
 	int retval;
 
 	retval = 0;
-	id.id = iid;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warnx("%s: can't allocate memory", __func__);
 		return (1);
@@ -2381,8 +1708,7 @@
 			     /*tag_type*/ CTL_TAG_SIMPLE,
 			     /*control*/ 0);
 
-	io->io_hdr.nexus.initid = id;
-	io->io_hdr.nexus.targ_target.id = target;
+	io->io_hdr.nexus.initid = iid;
 	io->io_hdr.nexus.targ_lun = lun;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
@@ -2413,7 +1739,7 @@
 }
 
 static int
-cctl_report_luns(int fd, int target, int lun, int iid, int retries)
+cctl_report_luns(int fd, int lun, int iid, int retries)
 {
 	struct scsi_report_luns_data *lun_data;
 	uint32_t num_luns, i;
@@ -2421,7 +1747,7 @@
 
 	lun_data = NULL;
 
-	if ((retval = cctl_get_luns(fd, target, lun, iid, retries, &lun_data,
+	if ((retval = cctl_get_luns(fd, lun, iid, retries, &lun_data,
 				   &num_luns)) != 0)
 		goto bailout;
 
@@ -2466,14 +1792,11 @@
 }
 
 static int
-cctl_tur(int fd, int target, int lun, int iid, int retries)
+cctl_tur(int fd, int lun, int iid, int retries)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 
-	id.id = iid;
-
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		fprintf(stderr, "can't allocate memory\n");
 		return (1);
@@ -2483,9 +1806,8 @@
 		     /* tag_type */ CTL_TAG_SIMPLE,
 		     /* control */ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		ctl_scsi_free_io(io);
@@ -2501,19 +1823,16 @@
 }
 
 static int
-cctl_get_inquiry(int fd, int target, int lun, int iid, int retries, 
+cctl_get_inquiry(int fd, int lun, int iid, int retries,
 		 char *path_str, int path_len,
 		 struct scsi_inquiry_data *inq_data)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	int retval;
 
 	retval = 0;
 
-	id.id = iid;
-
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warnx("cctl_inquiry: can't allocate memory\n");
 		return (1);
@@ -2527,9 +1846,8 @@
 			 /*tag_type*/ CTL_TAG_SIMPLE,
 			 /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -2549,14 +1867,12 @@
 }
 
 static int
-cctl_inquiry(int fd, int target, int lun, int iid, int retries)
+cctl_inquiry(int fd, int lun, int iid, int retries)
 {
 	struct scsi_inquiry_data *inq_data;
 	char scsi_path[40];
 	int retval;
 
-	retval = 0;
-
 	inq_data = malloc(sizeof(*inq_data));
 	if (inq_data == NULL) {
 		warnx("%s: can't allocate inquiry data", __func__);
@@ -2564,7 +1880,7 @@
 		goto bailout;
 	}
 
-	if ((retval = cctl_get_inquiry(fd, target, lun, iid, retries, scsi_path,
+	if ((retval = cctl_get_inquiry(fd, lun, iid, retries, scsi_path,
 				       sizeof(scsi_path), inq_data)) != 0)
 		goto bailout;
 
@@ -2579,18 +1895,15 @@
 }
 
 static int
-cctl_req_sense(int fd, int target, int lun, int iid, int retries)
+cctl_req_sense(int fd, int lun, int iid, int retries)
 {
 	union ctl_io *io;
 	struct scsi_sense_data *sense_data;
-	struct ctl_id id;
 	int retval;
 
 	retval = 0;
 
-	id.id = iid;
-
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warnx("cctl_req_sense: can't allocate memory\n");
 		return (1);
@@ -2605,9 +1918,8 @@
 			       /*tag_type*/ CTL_TAG_SIMPLE,
 			       /*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retries, io, __func__) != 0) {
 		retval = 1;
@@ -2630,19 +1942,17 @@
 }
 
 static int
-cctl_report_target_port_group(int fd, int target, int lun, int initiator)
+cctl_report_target_port_group(int fd, int lun, int iid)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t datalen;
 	uint8_t *dataptr;
 	int retval;
 
-	id.id = initiator;
 	dataptr = NULL;
 	retval = 0;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory", __func__);
 		return (1);
@@ -2652,7 +1962,7 @@
 	dataptr = (uint8_t *)malloc(datalen);
 	if (dataptr == NULL) {
 		warn("%s: can't allocate %d bytes", __func__, datalen);
-	    	retval = 1;
+		retval = 1;
 		goto bailout;
 	}
 
@@ -2665,9 +1975,8 @@
 				/*tag_type*/ CTL_TAG_SIMPLE,
 				/*control*/ 0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, 0, io, __func__) != 0) {
 		retval = 1;
@@ -2698,19 +2007,17 @@
 }
 
 static int
-cctl_inquiry_vpd_devid(int fd, int target, int lun, int initiator)
+cctl_inquiry_vpd_devid(int fd, int lun, int iid)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t datalen;
 	uint8_t *dataptr;
 	int retval;
 
-	id.id = initiator;
 	retval = 0;
 	dataptr = NULL;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory", __func__);
 		return (1);
@@ -2720,7 +2027,7 @@
 	dataptr = (uint8_t *)malloc(datalen);
 	if (dataptr == NULL) {
 		warn("%s: can't allocate %d bytes", __func__, datalen);
-	    	retval = 1;
+		retval = 1;
 		goto bailout;
 	}
 
@@ -2734,9 +2041,8 @@
 			 /*tag_type*/  CTL_TAG_SIMPLE,
 			 /*control*/   0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, 0, io, __func__) != 0) {
 		retval = 1;
@@ -2767,12 +2073,11 @@
 }
 
 static int
-cctl_persistent_reserve_in(int fd, int target, int lun, int initiator, 
+cctl_persistent_reserve_in(int fd, int lun, int iid,
                            int argc, char **argv, char *combinedopt,
 			   int retry_count)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t datalen;
 	uint8_t *dataptr;
 	int action = -1;
@@ -2779,11 +2084,10 @@
 	int retval;
 	int c;
 
-	id.id = initiator;
 	retval = 0;
 	dataptr = NULL;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory", __func__);
 		return (1);
@@ -2810,7 +2114,7 @@
 	dataptr = (uint8_t *)malloc(datalen);
 	if (dataptr == NULL) {
 		warn("%s: can't allocate %d bytes", __func__, datalen);
-	    	retval = 1;
+		retval = 1;
 		goto bailout;
 	}
 
@@ -2823,9 +2127,8 @@
 				   /*tag_type*/ CTL_TAG_SIMPLE,
 				   /*control*/  0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retry_count, io, __func__) != 0) {
 		retval = 1;
@@ -2835,8 +2138,6 @@
 	if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS) {
 		int returned_len, used_len;
 
-		returned_len = 0;
-
 		switch (action) {
 		case 0:
 			returned_len = scsi_4btoul(&dataptr[4]) + 8;
@@ -2873,12 +2174,11 @@
 }
 
 static int
-cctl_persistent_reserve_out(int fd, int target, int lun, int initiator, 
-			    int argc, char **argv, char *combinedopt, 
+cctl_persistent_reserve_out(int fd, int lun, int iid,
+			    int argc, char **argv, char *combinedopt,
 			    int retry_count)
 {
 	union ctl_io *io;
-	struct ctl_id id;
 	uint32_t datalen;
 	uint64_t key = 0, sa_key = 0;
 	int action = -1, restype = -1;
@@ -2886,11 +2186,10 @@
 	int retval;
 	int c;
 
-	id.id = initiator;
 	retval = 0;
 	dataptr = NULL;
 
-	io = ctl_scsi_alloc_io(id);
+	io = ctl_scsi_alloc_io(iid);
 	if (io == NULL) {
 		warn("%s: can't allocate memory", __func__);
 		return (1);
@@ -2948,9 +2247,8 @@
 				    /*tag_type*/ CTL_TAG_SIMPLE,
 				    /*control*/  0);
 
-	io->io_hdr.nexus.targ_target.id = target;
 	io->io_hdr.nexus.targ_lun = lun;
-	io->io_hdr.nexus.initid = id;
+	io->io_hdr.nexus.initid = iid;
 
 	if (cctl_do_io(fd, retry_count, io, __func__) != 0) {
 		retval = 1;
@@ -3157,14 +2455,18 @@
 		goto bailout;
 	}
 
-	if (req.status == CTL_LUN_ERROR) {
-		warnx("%s: error returned from LUN creation request:\n%s",
-		      __func__, req.error_str);
+	switch (req.status) {
+	case CTL_LUN_ERROR:
+		warnx("LUN creation error: %s", req.error_str);
 		retval = 1;
 		goto bailout;
-	} else if (req.status != CTL_LUN_OK) {
-		warnx("%s: unknown LUN creation request status %d",
-		      __func__, req.status);
+	case CTL_LUN_WARNING:
+		warnx("LUN creation warning: %s", req.error_str);
+		break;
+	case CTL_LUN_OK:
+		break;
+	default:
+		warnx("unknown LUN creation status: %d", req.status);
 		retval = 1;
 		goto bailout;
 	}
@@ -3303,19 +2605,23 @@
 		goto bailout;
 	}
 
-	if (req.status == CTL_LUN_ERROR) {
-		warnx("%s: error returned from LUN removal request:\n%s",
-		      __func__, req.error_str);
+	switch (req.status) {
+	case CTL_LUN_ERROR:
+		warnx("LUN removal error: %s", req.error_str);
 		retval = 1;
 		goto bailout;
-	} else if (req.status != CTL_LUN_OK) {
-		warnx("%s: unknown LUN removal request status %d",
-		      __func__, req.status);
+	case CTL_LUN_WARNING:
+		warnx("LUN removal warning: %s", req.error_str);
+		break;
+	case CTL_LUN_OK:
+		break;
+	default:
+		warnx("unknown LUN removal status: %d", req.status);
 		retval = 1;
 		goto bailout;
 	}
 
-	printf("LUN %d deleted successfully\n", lun_id);
+	printf("LUN %d removed successfully\n", lun_id);
 
 bailout:
 	return (retval);
@@ -3329,8 +2635,11 @@
 	uint32_t lun_id = 0;
 	int lun_id_set = 0, lun_size_set = 0;
 	char *backend_name = NULL;
+	STAILQ_HEAD(, cctl_req_option) option_list;
+	int num_options = 0;
 	int retval = 0, c;
 
+	STAILQ_INIT(&option_list);
 	while ((c = getopt(argc, argv, combinedopt)) != -1) {
 		switch (c) {
 		case 'b':
@@ -3340,6 +2649,43 @@
 			lun_id = strtoul(optarg, NULL, 0);
 			lun_id_set = 1;
 			break;
+		case 'o': {
+			struct cctl_req_option *option;
+			char *tmpstr;
+			char *name, *value;
+
+			tmpstr = strdup(optarg);
+			name = strsep(&tmpstr, "=");
+			if (name == NULL) {
+				warnx("%s: option -o takes \"name=value\""
+				      "argument", __func__);
+				retval = 1;
+				goto bailout;
+			}
+			value = strsep(&tmpstr, "=");
+			if (value == NULL) {
+				warnx("%s: option -o takes \"name=value\""
+				      "argument", __func__);
+				retval = 1;
+				goto bailout;
+			}
+			option = malloc(sizeof(*option));
+			if (option == NULL) {
+				warn("%s: error allocating %zd bytes",
+				     __func__, sizeof(*option));
+				retval = 1;
+				goto bailout;
+			}
+			option->name = strdup(name);
+			option->namelen = strlen(name) + 1;
+			option->value = strdup(value);
+			option->vallen = strlen(value) + 1;
+			free(tmpstr);
+
+			STAILQ_INSERT_TAIL(&option_list, option, links);
+			num_options++;
+			break;
+		}
 		case 's':
 			if (strcasecmp(optarg, "auto") != 0) {
 				retval = expand_number(optarg, &lun_size);
@@ -3363,8 +2709,9 @@
 	if (lun_id_set == 0)
 		errx(1, "%s: LUN id (-l) must be specified", __func__);
 
-	if (lun_size_set == 0)
-		errx(1, "%s: size (-s) must be specified", __func__);
+	if (lun_size_set == 0 && num_options == 0)
+		errx(1, "%s: size (-s) or options (-o) must be specified",
+		    __func__);
 
 	bzero(&req, sizeof(req));
 
@@ -3374,6 +2721,42 @@
 	req.reqdata.modify.lun_id = lun_id;
 	req.reqdata.modify.lun_size_bytes = lun_size;
 
+	req.num_be_args = num_options;
+	if (num_options > 0) {
+		struct cctl_req_option *option, *next_option;
+		int i;
+
+		req.be_args = malloc(num_options * sizeof(*req.be_args));
+		if (req.be_args == NULL) {
+			warn("%s: error allocating %zd bytes", __func__,
+			     num_options * sizeof(*req.be_args));
+			retval = 1;
+			goto bailout;
+		}
+
+		for (i = 0, option = STAILQ_FIRST(&option_list);
+		     i < num_options; i++, option = next_option) {
+			next_option = STAILQ_NEXT(option, links);
+
+			req.be_args[i].namelen = option->namelen;
+			req.be_args[i].name = strdup(option->name);
+			req.be_args[i].vallen = option->vallen;
+			req.be_args[i].value = strdup(option->value);
+			/*
+			 * XXX KDM do we want a way to specify a writeable
+			 * flag of some sort?  Do we want a way to specify
+			 * binary data?
+			 */
+			req.be_args[i].flags = CTL_BEARG_ASCII | CTL_BEARG_RD;
+
+			STAILQ_REMOVE(&option_list, option, cctl_req_option,
+				      links);
+			free(option->name);
+			free(option->value);
+			free(option);
+		}
+	}
+
 	if (ioctl(fd, CTL_LUN_REQ, &req) == -1) {
 		warn("%s: error issuing CTL_LUN_REQ ioctl", __func__);
 		retval = 1;
@@ -3380,14 +2763,18 @@
 		goto bailout;
 	}
 
-	if (req.status == CTL_LUN_ERROR) {
-		warnx("%s: error returned from LUN modification request:\n%s",
-		      __func__, req.error_str);
+	switch (req.status) {
+	case CTL_LUN_ERROR:
+		warnx("LUN modification error: %s", req.error_str);
 		retval = 1;
 		goto bailout;
-	} else if (req.status != CTL_LUN_OK) {
-		warnx("%s: unknown LUN modification request status %d",
-		      __func__, req.status);
+	case CTL_LUN_WARNING:
+		warnx("LUN modification warning: %s", req.error_str);
+		break;
+	case CTL_LUN_OK:
+		break;
+	default:
+		warnx("unknown LUN modification status: %d", req.status);
 		retval = 1;
 		goto bailout;
 	}
@@ -3398,7 +2785,413 @@
 	return (retval);
 }
 
+struct cctl_islist_conn {
+	int connection_id;
+	char *initiator;
+	char *initiator_addr;
+	char *initiator_alias;
+	char *target;
+	char *target_alias;
+	char *header_digest;
+	char *data_digest;
+	char *max_data_segment_length;;
+	int immediate_data;
+	int iser;
+	STAILQ_ENTRY(cctl_islist_conn) links;
+};
 
+struct cctl_islist_data {
+	int num_conns;
+	STAILQ_HEAD(,cctl_islist_conn) conn_list;
+	struct cctl_islist_conn *cur_conn;
+	int level;
+	struct sbuf *cur_sb[32];
+};
+
+static void
+cctl_islist_start_element(void *user_data, const char *name, const char **attr)
+{
+	int i;
+	struct cctl_islist_data *islist;
+	struct cctl_islist_conn *cur_conn;
+
+	islist = (struct cctl_islist_data *)user_data;
+	cur_conn = islist->cur_conn;
+	islist->level++;
+	if ((u_int)islist->level >= (sizeof(islist->cur_sb) /
+	    sizeof(islist->cur_sb[0])))
+		errx(1, "%s: too many nesting levels, %zd max", __func__,
+		     sizeof(islist->cur_sb) / sizeof(islist->cur_sb[0]));
+
+	islist->cur_sb[islist->level] = sbuf_new_auto();
+	if (islist->cur_sb[islist->level] == NULL)
+		err(1, "%s: Unable to allocate sbuf", __func__);
+
+	if (strcmp(name, "connection") == 0) {
+		if (cur_conn != NULL)
+			errx(1, "%s: improper connection element nesting",
+			    __func__);
+
+		cur_conn = calloc(1, sizeof(*cur_conn));
+		if (cur_conn == NULL)
+			err(1, "%s: cannot allocate %zd bytes", __func__,
+			    sizeof(*cur_conn));
+
+		islist->num_conns++;
+		islist->cur_conn = cur_conn;
+
+		STAILQ_INSERT_TAIL(&islist->conn_list, cur_conn, links);
+
+		for (i = 0; attr[i] != NULL; i += 2) {
+			if (strcmp(attr[i], "id") == 0) {
+				cur_conn->connection_id =
+				    strtoull(attr[i+1], NULL, 0);
+			} else {
+				errx(1,
+				    "%s: invalid connection attribute %s = %s",
+				     __func__, attr[i], attr[i+1]);
+			}
+		}
+	}
+}
+
+static void
+cctl_islist_end_element(void *user_data, const char *name)
+{
+	struct cctl_islist_data *islist;
+	struct cctl_islist_conn *cur_conn;
+	char *str;
+
+	islist = (struct cctl_islist_data *)user_data;
+	cur_conn = islist->cur_conn;
+
+	if ((cur_conn == NULL)
+	 && (strcmp(name, "ctlislist") != 0))
+		errx(1, "%s: cur_conn == NULL! (name = %s)", __func__, name);
+
+	if (islist->cur_sb[islist->level] == NULL)
+		errx(1, "%s: no valid sbuf at level %d (name %s)", __func__,
+		     islist->level, name);
+
+	sbuf_finish(islist->cur_sb[islist->level]);
+	str = strdup(sbuf_data(islist->cur_sb[islist->level]));
+	if (str == NULL)
+		err(1, "%s can't allocate %zd bytes for string", __func__,
+		    sbuf_len(islist->cur_sb[islist->level]));
+
+	sbuf_delete(islist->cur_sb[islist->level]);
+	islist->cur_sb[islist->level] = NULL;
+	islist->level--;
+
+	if (strcmp(name, "initiator") == 0) {
+		cur_conn->initiator = str;
+		str = NULL;
+	} else if (strcmp(name, "initiator_addr") == 0) {
+		cur_conn->initiator_addr = str;
+		str = NULL;
+	} else if (strcmp(name, "initiator_alias") == 0) {
+		cur_conn->initiator_alias = str;
+		str = NULL;
+	} else if (strcmp(name, "target") == 0) {
+		cur_conn->target = str;
+		str = NULL;
+	} else if (strcmp(name, "target_alias") == 0) {
+		cur_conn->target_alias = str;
+		str = NULL;
+	} else if (strcmp(name, "target_portal_group_tag") == 0) {
+	} else if (strcmp(name, "header_digest") == 0) {
+		cur_conn->header_digest = str;
+		str = NULL;
+	} else if (strcmp(name, "data_digest") == 0) {
+		cur_conn->data_digest = str;
+		str = NULL;
+	} else if (strcmp(name, "max_data_segment_length") == 0) {
+		cur_conn->max_data_segment_length = str;
+		str = NULL;
+	} else if (strcmp(name, "immediate_data") == 0) {
+		cur_conn->immediate_data = atoi(str);
+	} else if (strcmp(name, "iser") == 0) {
+		cur_conn->iser = atoi(str);
+	} else if (strcmp(name, "connection") == 0) {
+		islist->cur_conn = NULL;
+	} else if (strcmp(name, "ctlislist") == 0) {
+		/* Nothing. */
+	} else {
+		/*
+		 * Unknown element; ignore it for forward compatiblity.
+		 */
+	}
+
+	free(str);
+}
+
+static void
+cctl_islist_char_handler(void *user_data, const XML_Char *str, int len)
+{
+	struct cctl_islist_data *islist;
+
+	islist = (struct cctl_islist_data *)user_data;
+
+	sbuf_bcat(islist->cur_sb[islist->level], str, len);
+}
+
+static int
+cctl_islist(int fd, int argc, char **argv, char *combinedopt)
+{
+	struct ctl_iscsi req;
+	struct cctl_islist_data islist;
+	struct cctl_islist_conn *conn;
+	XML_Parser parser;
+	char *conn_str;
+	int conn_len;
+	int dump_xml = 0;
+	int c, retval, verbose = 0;
+
+	retval = 0;
+	conn_len = 4096;
+
+	bzero(&islist, sizeof(islist));
+	STAILQ_INIT(&islist.conn_list);
+
+	while ((c = getopt(argc, argv, combinedopt)) != -1) {
+		switch (c) {
+		case 'v':
+			verbose = 1;
+			break;
+		case 'x':
+			dump_xml = 1;
+			break;
+		default:
+			break;
+		}
+	}
+
+retry:
+	conn_str = malloc(conn_len);
+
+	bzero(&req, sizeof(req));
+	req.type = CTL_ISCSI_LIST;
+	req.data.list.alloc_len = conn_len;
+	req.data.list.conn_xml = conn_str;
+
+	if (ioctl(fd, CTL_ISCSI, &req) == -1) {
+		warn("%s: error issuing CTL_ISCSI ioctl", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	if (req.status == CTL_ISCSI_ERROR) {
+		warnx("%s: error returned from CTL_ISCSI ioctl:\n%s",
+		      __func__, req.error_str);
+	} else if (req.status == CTL_ISCSI_LIST_NEED_MORE_SPACE) {
+		conn_len = conn_len << 1;
+		goto retry;
+	}
+
+	if (dump_xml != 0) {
+		printf("%s", conn_str);
+		goto bailout;
+	}
+
+	parser = XML_ParserCreate(NULL);
+	if (parser == NULL) {
+		warn("%s: Unable to create XML parser", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	XML_SetUserData(parser, &islist);
+	XML_SetElementHandler(parser, cctl_islist_start_element,
+	    cctl_islist_end_element);
+	XML_SetCharacterDataHandler(parser, cctl_islist_char_handler);
+
+	retval = XML_Parse(parser, conn_str, strlen(conn_str), 1);
+	if (retval != 1) {
+		warnx("%s: Unable to parse XML: Error %d", __func__,
+		    XML_GetErrorCode(parser));
+		XML_ParserFree(parser);
+		retval = 1;
+		goto bailout;
+	}
+	retval = 0;
+	XML_ParserFree(parser);
+
+	if (verbose != 0) {
+		STAILQ_FOREACH(conn, &islist.conn_list, links) {
+			printf("Session ID:       %d\n", conn->connection_id);
+			printf("Initiator name:   %s\n", conn->initiator);
+			printf("Initiator portal: %s\n", conn->initiator_addr);
+			printf("Initiator alias:  %s\n", conn->initiator_alias);
+			printf("Target name:      %s\n", conn->target);
+			printf("Target alias:     %s\n", conn->target_alias);
+			printf("Header digest:    %s\n", conn->header_digest);
+			printf("Data digest:      %s\n", conn->data_digest);
+			printf("DataSegmentLen:   %s\n", conn->max_data_segment_length);
+			printf("ImmediateData:    %s\n", conn->immediate_data ? "Yes" : "No");
+			printf("iSER (RDMA):      %s\n", conn->iser ? "Yes" : "No");
+			printf("\n");
+		}
+	} else {
+		printf("%4s %-16s %-36s %-36s\n", "ID", "Portal", "Initiator name",
+		    "Target name");
+		STAILQ_FOREACH(conn, &islist.conn_list, links) {
+			printf("%4u %-16s %-36s %-36s\n",
+			    conn->connection_id, conn->initiator_addr, conn->initiator,
+			    conn->target);
+		}
+	}
+bailout:
+	free(conn_str);
+
+	return (retval);
+}
+
+static int
+cctl_islogout(int fd, int argc, char **argv, char *combinedopt)
+{
+	struct ctl_iscsi req;
+	int retval = 0, c;
+	int all = 0, connection_id = -1, nargs = 0;
+	char *initiator_name = NULL, *initiator_addr = NULL;
+
+	while ((c = getopt(argc, argv, combinedopt)) != -1) {
+		switch (c) {
+		case 'a':
+			all = 1;
+			nargs++;
+			break;
+		case 'c':
+			connection_id = strtoul(optarg, NULL, 0);
+			nargs++;
+			break;
+		case 'i':
+			initiator_name = strdup(optarg);
+			if (initiator_name == NULL)
+				err(1, "%s: strdup", __func__);
+			nargs++;
+			break;
+		case 'p':
+			initiator_addr = strdup(optarg);
+			if (initiator_addr == NULL)
+				err(1, "%s: strdup", __func__);
+			nargs++;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (nargs == 0)
+		errx(1, "%s: either -a, -c, -i, or -p must be specified",
+		    __func__);
+	if (nargs > 1)
+		errx(1, "%s: only one of -a, -c, -i, or -p may be specified",
+		    __func__);
+
+	bzero(&req, sizeof(req));
+	req.type = CTL_ISCSI_LOGOUT;
+	req.data.logout.connection_id = connection_id;
+	if (initiator_addr != NULL)
+		strlcpy(req.data.logout.initiator_addr,
+		    initiator_addr, sizeof(req.data.logout.initiator_addr));
+	if (initiator_name != NULL)
+		strlcpy(req.data.logout.initiator_name,
+		    initiator_name, sizeof(req.data.logout.initiator_name));
+	if (all != 0)
+		req.data.logout.all = 1;
+
+	if (ioctl(fd, CTL_ISCSI, &req) == -1) {
+		warn("%s: error issuing CTL_ISCSI ioctl", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	if (req.status != CTL_ISCSI_OK) {
+		warnx("%s: error returned from CTL iSCSI logout request:\n%s",
+		      __func__, req.error_str);
+		retval = 1;
+		goto bailout;
+	}
+
+	printf("iSCSI logout requests submitted\n");
+
+bailout:
+	return (retval);
+}
+
+static int
+cctl_isterminate(int fd, int argc, char **argv, char *combinedopt)
+{
+	struct ctl_iscsi req;
+	int retval = 0, c;
+	int all = 0, connection_id = -1, nargs = 0;
+	char *initiator_name = NULL, *initiator_addr = NULL;
+
+	while ((c = getopt(argc, argv, combinedopt)) != -1) {
+		switch (c) {
+		case 'a':
+			all = 1;
+			nargs++;
+			break;
+		case 'c':
+			connection_id = strtoul(optarg, NULL, 0);
+			nargs++;
+			break;
+		case 'i':
+			initiator_name = strdup(optarg);
+			if (initiator_name == NULL)
+				err(1, "%s: strdup", __func__);
+			nargs++;
+			break;
+		case 'p':
+			initiator_addr = strdup(optarg);
+			if (initiator_addr == NULL)
+				err(1, "%s: strdup", __func__);
+			nargs++;
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (nargs == 0)
+		errx(1, "%s: either -a, -c, -i, or -p must be specified",
+		    __func__);
+	if (nargs > 1)
+		errx(1, "%s: only one of -a, -c, -i, or -p may be specified",
+		    __func__);
+
+	bzero(&req, sizeof(req));
+	req.type = CTL_ISCSI_TERMINATE;
+	req.data.terminate.connection_id = connection_id;
+	if (initiator_addr != NULL)
+		strlcpy(req.data.terminate.initiator_addr,
+		    initiator_addr, sizeof(req.data.terminate.initiator_addr));
+	if (initiator_name != NULL)
+		strlcpy(req.data.terminate.initiator_name,
+		    initiator_name, sizeof(req.data.terminate.initiator_name));
+	if (all != 0)
+		req.data.terminate.all = 1;
+
+	if (ioctl(fd, CTL_ISCSI, &req) == -1) {
+		warn("%s: error issuing CTL_ISCSI ioctl", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	if (req.status != CTL_ISCSI_OK) {
+		warnx("%s: error returned from CTL iSCSI connection "
+		    "termination request:\n%s", __func__, req.error_str);
+		retval = 1;
+		goto bailout;
+	}
+
+	printf("iSCSI connections terminated\n");
+
+bailout:
+	return (retval);
+}
+
 /*
  * Name/value pair used for per-LUN attributes.
  */
@@ -3409,7 +3202,7 @@
 };
 
 /*
- * Backend LUN information.  
+ * Backend LUN information.
  */
 struct cctl_lun {
 	uint64_t lun_id;
@@ -3440,7 +3233,7 @@
 	devlist = (struct cctl_devlist_data *)user_data;
 	cur_lun = devlist->cur_lun;
 	devlist->level++;
-	if ((u_int)devlist->level > (sizeof(devlist->cur_sb) /
+	if ((u_int)devlist->level >= (sizeof(devlist->cur_sb) /
 	    sizeof(devlist->cur_sb[0])))
 		errx(1, "%s: too many nesting levels, %zd max", __func__,
 		     sizeof(devlist->cur_sb) / sizeof(devlist->cur_sb[0]));
@@ -3525,7 +3318,7 @@
 	} else if (strcmp(name, "lun") == 0) {
 		devlist->cur_lun = NULL;
 	} else if (strcmp(name, "ctllunlist") == 0) {
-		
+		/* Nothing. */
 	} else {
 		struct cctl_lun_nv *nv;
 
@@ -3632,11 +3425,15 @@
 	XML_SetCharacterDataHandler(parser, cctl_char_handler);
 
 	retval = XML_Parse(parser, lun_str, strlen(lun_str), 1);
-	XML_ParserFree(parser);
 	if (retval != 1) {
+		warnx("%s: Unable to parse XML: Error %d", __func__,
+		    XML_GetErrorCode(parser));
+		XML_ParserFree(parser);
 		retval = 1;
 		goto bailout;
 	}
+	retval = 0;
+	XML_ParserFree(parser);
 
 	printf("LUN Backend  %18s %4s %-16s %-16s\n", "Size (Blocks)", "BS",
 	       "Serial Number", "Device ID");
@@ -3665,6 +3462,360 @@
 	return (retval);
 }
 
+/*
+ * Port information.
+ */
+struct cctl_port {
+	uint64_t port_id;
+	char *online;
+	char *frontend_type;
+	char *name;
+	int pp, vp;
+	char *target, *port, *lun_map;
+	STAILQ_HEAD(,cctl_lun_nv) init_list;
+	STAILQ_HEAD(,cctl_lun_nv) lun_list;
+	STAILQ_HEAD(,cctl_lun_nv) attr_list;
+	STAILQ_ENTRY(cctl_port) links;
+};
+
+struct cctl_portlist_data {
+	int num_ports;
+	STAILQ_HEAD(,cctl_port) port_list;
+	struct cctl_port *cur_port;
+	int level;
+	uint64_t cur_id;
+	struct sbuf *cur_sb[32];
+};
+
+static void
+cctl_start_pelement(void *user_data, const char *name, const char **attr)
+{
+	int i;
+	struct cctl_portlist_data *portlist;
+	struct cctl_port *cur_port;
+
+	portlist = (struct cctl_portlist_data *)user_data;
+	cur_port = portlist->cur_port;
+	portlist->level++;
+	if ((u_int)portlist->level >= (sizeof(portlist->cur_sb) /
+	    sizeof(portlist->cur_sb[0])))
+		errx(1, "%s: too many nesting levels, %zd max", __func__,
+		     sizeof(portlist->cur_sb) / sizeof(portlist->cur_sb[0]));
+
+	portlist->cur_sb[portlist->level] = sbuf_new_auto();
+	if (portlist->cur_sb[portlist->level] == NULL)
+		err(1, "%s: Unable to allocate sbuf", __func__);
+
+	portlist->cur_id = 0;
+	for (i = 0; attr[i] != NULL; i += 2) {
+		if (strcmp(attr[i], "id") == 0) {
+			portlist->cur_id = strtoull(attr[i+1], NULL, 0);
+			break;
+		}
+	}
+
+	if (strcmp(name, "targ_port") == 0) {
+		if (cur_port != NULL)
+			errx(1, "%s: improper port element nesting", __func__);
+
+		cur_port = calloc(1, sizeof(*cur_port));
+		if (cur_port == NULL)
+			err(1, "%s: cannot allocate %zd bytes", __func__,
+			    sizeof(*cur_port));
+
+		portlist->num_ports++;
+		portlist->cur_port = cur_port;
+
+		STAILQ_INIT(&cur_port->init_list);
+		STAILQ_INIT(&cur_port->lun_list);
+		STAILQ_INIT(&cur_port->attr_list);
+		cur_port->port_id = portlist->cur_id;
+		STAILQ_INSERT_TAIL(&portlist->port_list, cur_port, links);
+	}
+}
+
+static void
+cctl_end_pelement(void *user_data, const char *name)
+{
+	struct cctl_portlist_data *portlist;
+	struct cctl_port *cur_port;
+	char *str;
+
+	portlist = (struct cctl_portlist_data *)user_data;
+	cur_port = portlist->cur_port;
+
+	if ((cur_port == NULL)
+	 && (strcmp(name, "ctlportlist") != 0))
+		errx(1, "%s: cur_port == NULL! (name = %s)", __func__, name);
+
+	if (portlist->cur_sb[portlist->level] == NULL)
+		errx(1, "%s: no valid sbuf at level %d (name %s)", __func__,
+		     portlist->level, name);
+
+	if (sbuf_finish(portlist->cur_sb[portlist->level]) != 0)
+		err(1, "%s: sbuf_finish", __func__);
+	str = strdup(sbuf_data(portlist->cur_sb[portlist->level]));
+	if (str == NULL)
+		err(1, "%s can't allocate %zd bytes for string", __func__,
+		    sbuf_len(portlist->cur_sb[portlist->level]));
+
+	if (strlen(str) == 0) {
+		free(str);
+		str = NULL;
+	}
+
+	sbuf_delete(portlist->cur_sb[portlist->level]);
+	portlist->cur_sb[portlist->level] = NULL;
+	portlist->level--;
+
+	if (strcmp(name, "frontend_type") == 0) {
+		cur_port->frontend_type = str;
+		str = NULL;
+	} else if (strcmp(name, "port_name") == 0) {
+		cur_port->name = str;
+		str = NULL;
+	} else if (strcmp(name, "online") == 0) {
+		cur_port->online = str;
+		str = NULL;
+	} else if (strcmp(name, "physical_port") == 0) {
+		cur_port->pp = strtoull(str, NULL, 0);
+	} else if (strcmp(name, "virtual_port") == 0) {
+		cur_port->vp = strtoull(str, NULL, 0);
+	} else if (strcmp(name, "target") == 0) {
+		cur_port->target = str;
+		str = NULL;
+	} else if (strcmp(name, "port") == 0) {
+		cur_port->port = str;
+		str = NULL;
+	} else if (strcmp(name, "lun_map") == 0) {
+		cur_port->lun_map = str;
+		str = NULL;
+	} else if (strcmp(name, "targ_port") == 0) {
+		portlist->cur_port = NULL;
+	} else if (strcmp(name, "ctlportlist") == 0) {
+		/* Nothing. */
+	} else {
+		struct cctl_lun_nv *nv;
+
+		nv = calloc(1, sizeof(*nv));
+		if (nv == NULL)
+			err(1, "%s: can't allocate %zd bytes for nv pair",
+			    __func__, sizeof(*nv));
+
+		if (strcmp(name, "initiator") == 0 ||
+		    strcmp(name, "lun") == 0)
+			asprintf(&nv->name, "%ju", portlist->cur_id);
+		else
+			nv->name = strdup(name);
+		if (nv->name == NULL)
+			err(1, "%s: can't allocated %zd bytes for string",
+			    __func__, strlen(name));
+
+		nv->value = str;
+		str = NULL;
+		if (strcmp(name, "initiator") == 0)
+			STAILQ_INSERT_TAIL(&cur_port->init_list, nv, links);
+		else if (strcmp(name, "lun") == 0)
+			STAILQ_INSERT_TAIL(&cur_port->lun_list, nv, links);
+		else
+			STAILQ_INSERT_TAIL(&cur_port->attr_list, nv, links);
+	}
+
+	free(str);
+}
+
+static void
+cctl_char_phandler(void *user_data, const XML_Char *str, int len)
+{
+	struct cctl_portlist_data *portlist;
+
+	portlist = (struct cctl_portlist_data *)user_data;
+
+	sbuf_bcat(portlist->cur_sb[portlist->level], str, len);
+}
+
+static int
+cctl_portlist(int fd, int argc, char **argv, char *combinedopt)
+{
+	struct ctl_lun_list list;
+	struct cctl_portlist_data portlist;
+	struct cctl_port *port;
+	XML_Parser parser;
+	char *port_str;
+	int port_len;
+	int dump_xml = 0;
+	int retval, c;
+	char *frontend = NULL;
+	uint64_t portarg = UINT64_MAX;
+	int verbose = 0, init = 0, lun = 0, quiet = 0;
+
+	retval = 0;
+	port_len = 4096;
+
+	bzero(&portlist, sizeof(portlist));
+	STAILQ_INIT(&portlist.port_list);
+
+	while ((c = getopt(argc, argv, combinedopt)) != -1) {
+		switch (c) {
+		case 'f':
+			frontend = strdup(optarg);
+			break;
+		case 'i':
+			init++;
+			break;
+		case 'l':
+			lun++;
+			break;
+		case 'p':
+			portarg = strtoll(optarg, NULL, 0);
+			break;
+		case 'q':
+			quiet++;
+			break;
+		case 'v':
+			verbose++;
+			break;
+		case 'x':
+			dump_xml = 1;
+			break;
+		default:
+			break;
+		}
+	}
+
+retry:
+	port_str = malloc(port_len);
+
+	bzero(&list, sizeof(list));
+	list.alloc_len = port_len;
+	list.status = CTL_LUN_LIST_NONE;
+	list.lun_xml = port_str;
+
+	if (ioctl(fd, CTL_PORT_LIST, &list) == -1) {
+		warn("%s: error issuing CTL_PORT_LIST ioctl", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	if (list.status == CTL_LUN_LIST_ERROR) {
+		warnx("%s: error returned from CTL_PORT_LIST ioctl:\n%s",
+		      __func__, list.error_str);
+	} else if (list.status == CTL_LUN_LIST_NEED_MORE_SPACE) {
+		port_len = port_len << 1;
+		goto retry;
+	}
+
+	if (dump_xml != 0) {
+		printf("%s", port_str);
+		goto bailout;
+	}
+
+	parser = XML_ParserCreate(NULL);
+	if (parser == NULL) {
+		warn("%s: Unable to create XML parser", __func__);
+		retval = 1;
+		goto bailout;
+	}
+
+	XML_SetUserData(parser, &portlist);
+	XML_SetElementHandler(parser, cctl_start_pelement, cctl_end_pelement);
+	XML_SetCharacterDataHandler(parser, cctl_char_phandler);
+
+	retval = XML_Parse(parser, port_str, strlen(port_str), 1);
+	if (retval != 1) {
+		warnx("%s: Unable to parse XML: Error %d", __func__,
+		    XML_GetErrorCode(parser));
+		XML_ParserFree(parser);
+		retval = 1;
+		goto bailout;
+	}
+	retval = 0;
+	XML_ParserFree(parser);
+
+	if (quiet == 0)
+		printf("Port Online Frontend Name     pp vp\n");
+	STAILQ_FOREACH(port, &portlist.port_list, links) {
+		struct cctl_lun_nv *nv;
+
+		if ((frontend != NULL)
+		 && (strcmp(port->frontend_type, frontend) != 0))
+			continue;
+
+		if ((portarg != UINT64_MAX) && (portarg != port->port_id))
+			continue;
+
+		printf("%-4ju %-6s %-8s %-8s %-2d %-2d %s\n",
+		    (uintmax_t)port->port_id, port->online,
+		    port->frontend_type, port->name, port->pp, port->vp,
+		    port->port ? port->port : "");
+
+		if (init || verbose) {
+			if (port->target)
+				printf("  Target: %s\n", port->target);
+			STAILQ_FOREACH(nv, &port->init_list, links) {
+				printf("  Initiator %s: %s\n",
+				    nv->name, nv->value);
+			}
+		}
+
+		if (lun || verbose) {
+			if (port->lun_map) {
+				STAILQ_FOREACH(nv, &port->lun_list, links)
+					printf("  LUN %s: %s\n",
+					    nv->name, nv->value);
+				if (STAILQ_EMPTY(&port->lun_list))
+					printf("  No LUNs mapped\n");
+			} else
+				printf("  All LUNs mapped\n");
+		}
+
+		if (verbose) {
+			STAILQ_FOREACH(nv, &port->attr_list, links) {
+				printf("      %s=%s\n", nv->name, nv->value);
+			}
+		}
+	}
+bailout:
+	free(port_str);
+
+	return (retval);
+}
+
+static int
+cctl_lunmap(int fd, int argc, char **argv, char *combinedopt)
+{
+	struct ctl_lun_map lm;
+	int retval = 0, c;
+
+	retval = 0;
+	lm.port = UINT32_MAX;
+	lm.plun = UINT32_MAX;
+	lm.lun = UINT32_MAX;
+
+	while ((c = getopt(argc, argv, combinedopt)) != -1) {
+		switch (c) {
+		case 'p':
+			lm.port = strtoll(optarg, NULL, 0);
+			break;
+		case 'l':
+			lm.plun = strtoll(optarg, NULL, 0);
+			break;
+		case 'L':
+			lm.lun = strtoll(optarg, NULL, 0);
+			break;
+		default:
+			break;
+		}
+	}
+
+	if (ioctl(fd, CTL_LUN_MAP, &lm) == -1) {
+		warn("%s: error issuing CTL_LUN_MAP ioctl", __func__);
+		retval = 1;
+	}
+
+	return (retval);
+}
+
 void
 usage(int error)
 {
@@ -3696,22 +3847,19 @@
 "                            [-S serial_num] [-t dev_type]\n"
 "         ctladm remove      <-b backend> <-l lun_id> [-o name=value]\n"
 "         ctladm modify      <-b backend> <-l lun_id> <-s size_bytes>\n"
-"         ctladm devlist     [-b][-v][-x]\n"
-"         ctladm shutdown\n"
-"         ctladm startup\n"
-"         ctladm hardstop\n"
-"         ctladm hardstart\n"
+"         ctladm devlist     [-b backend] [-v] [-x]\n"
 "         ctladm lunlist\n"
-"         ctladm bbrread     [dev_id] <-l lba> <-d datalen>\n"
+"         ctladm lunmap      -p targ_port [-l pLUN] [-L cLUN]\n"
 "         ctladm delay       [dev_id] <-l datamove|done> [-T oneshot|cont]\n"
 "                            [-t secs]\n"
-"         ctladm realsync    <on|off|query>\n"
-"         ctladm setsync     [dev_id] <-i interval>\n"
-"         ctladm getsync     [dev_id]\n"
 "         ctladm inject      [dev_id] <-i action> <-p pattern> [-r lba,len]\n"
 "                            [-s len fmt [args]] [-c] [-d delete_id]\n"
-"         ctladm port        <-l | -o <on|off> | [-w wwnn][-W wwpn]>\n"
-"                            [-p targ_port] [-t port_type] [-q] [-x]\n"
+"         ctladm port        <-o <on|off> | [-w wwnn][-W wwpn]>\n"
+"                            [-p targ_port] [-t port_type]\n"
+"         ctladm portlist    [-f frontend] [-i] [-p targ_port] [-q] [-v] [-x]\n"
+"         ctladm islist      [-v | -x]\n"
+"         ctladm islogout    <-a | -c connection-id | -i name | -p portal>\n"
+"         ctladm isterminate <-a | -c connection-id | -i name | -p portal>\n"
 "         ctladm dumpooa\n"
 "         ctladm dumpstructs\n"
 "         ctladm help\n"
@@ -3794,9 +3942,18 @@
 "-p targ_port             : specify target port number\n"
 "-q                       : omit header in list output\n"
 "-x                       : output port list in XML format\n"
-"bbrread options:\n"
-"-l lba                   : starting LBA\n"
-"-d datalen               : length, in bytes, to read\n",
+"portlist options:\n"
+"-f fronetnd              : specify frontend type\n"
+"-i                       : report target and initiators addresses\n"
+"-l                       : report LUN mapping\n"
+"-p targ_port             : specify target port number\n"
+"-q                       : omit header in list output\n"
+"-v                       : verbose output (report all port options)\n"
+"-x                       : output port list in XML format\n"
+"lunmap options:\n"
+"-p targ_port             : specify target port number\n"
+"-L pLUN                  : specify port-visible LUN\n"
+"-L cLUN                  : specify CTL LUN\n",
 CTL_DEFAULT_DEV);
 }
 
@@ -3811,11 +3968,12 @@
 	const char *mainopt = "C:D:I:";
 	const char *subopt = NULL;
 	char combinedopt[256];
-	int target, lun;
+	int lun;
 	int optstart = 2;
 	int retval, fd;
 	int retries;
 	int initid;
+	int saved_errno;
 
 	retval = 0;
 	cmdargs = CTLADM_ARG_NONE;
@@ -3823,7 +3981,6 @@
 	device = NULL;
 	fd = -1;
 	retries = 0;
-	target = 0;
 	lun = 0;
 	initid = 7;
 
@@ -3849,16 +4006,13 @@
 	}
 
 	if (cmdargs & CTLADM_ARG_NEED_TL) {
-	 	if ((argc < 3)
-		 || (!isdigit(argv[2][0]))) {
-			warnx("option %s requires a target:lun argument",
+		if ((argc < 3) || (!isdigit(argv[2][0]))) {
+			warnx("option %s requires a lun argument",
 			      argv[1]);
 			usage(0);
 			exit(1);
 		}
-		retval = cctl_parse_tl(argv[2], &target, &lun);
-		if (retval != 0)
-			errx(1, "invalid target:lun argument %s", argv[2]);
+		lun = strtol(argv[2], NULL, 0);
 
 		cmdargs |= CTLADM_ARG_TARG_LUN;
 		optstart++;
@@ -3965,6 +4119,14 @@
 	if ((cmdargs & CTLADM_ARG_DEVICE)
 	 && (command != CTLADM_CMD_HELP)) {
 		fd = open(device, O_RDWR);
+		if (fd == -1 && errno == ENOENT) {
+			saved_errno = errno;
+			retval = kldload("ctl");
+			if (retval != -1)
+				fd = open(device, O_RDWR);
+			else
+				errno = saved_errno;
+		}
 		if (fd == -1) {
 			fprintf(stderr, "%s: error opening %s: %s\n",
 				argv[0], device, strerror(errno));
@@ -3981,16 +4143,16 @@
 
 	switch (command) {
 	case CTLADM_CMD_TUR:
-		retval = cctl_tur(fd, target, lun, initid, retries);
+		retval = cctl_tur(fd, lun, initid, retries);
 		break;
 	case CTLADM_CMD_INQUIRY:
-		retval = cctl_inquiry(fd, target, lun, initid, retries);
+		retval = cctl_inquiry(fd, lun, initid, retries);
 		break;
 	case CTLADM_CMD_REQ_SENSE:
-		retval = cctl_req_sense(fd, target, lun, initid, retries);
+		retval = cctl_req_sense(fd, lun, initid, retries);
 		break;
 	case CTLADM_CMD_REPORT_LUNS:
-		retval = cctl_report_luns(fd, target, lun, initid, retries);
+		retval = cctl_report_luns(fd, lun, initid, retries);
 		break;
 	case CTLADM_CMD_CREATE:
 		retval = cctl_create_lun(fd, argc, argv, combinedopt);
@@ -4003,59 +4165,44 @@
 		break;
 	case CTLADM_CMD_READ:
 	case CTLADM_CMD_WRITE:
-		retval = cctl_read_write(fd, target, lun, initid, retries,
+		retval = cctl_read_write(fd, lun, initid, retries,
 					 argc, argv, combinedopt, command);
 		break;
 	case CTLADM_CMD_PORT:
 		retval = cctl_port(fd, argc, argv, combinedopt);
 		break;
+	case CTLADM_CMD_PORTLIST:
+		retval = cctl_portlist(fd, argc, argv, combinedopt);
+		break;
+	case CTLADM_CMD_LUNMAP:
+		retval = cctl_lunmap(fd, argc, argv, combinedopt);
+		break;
 	case CTLADM_CMD_READCAPACITY:
-		retval = cctl_read_capacity(fd, target, lun, initid, retries,
+		retval = cctl_read_capacity(fd, lun, initid, retries,
 					    argc, argv, combinedopt);
 		break;
 	case CTLADM_CMD_MODESENSE:
-		retval = cctl_mode_sense(fd, target, lun, initid, retries,
+		retval = cctl_mode_sense(fd, lun, initid, retries,
 					 argc, argv, combinedopt);
 		break;
 	case CTLADM_CMD_START:
 	case CTLADM_CMD_STOP:
-		retval = cctl_start_stop(fd, target, lun, initid, retries,
+		retval = cctl_start_stop(fd, lun, initid, retries,
 					 (command == CTLADM_CMD_START) ? 1 : 0,
 					 argc, argv, combinedopt);
 		break;
 	case CTLADM_CMD_SYNC_CACHE:
-		retval = cctl_sync_cache(fd, target, lun, initid, retries,
+		retval = cctl_sync_cache(fd, lun, initid, retries,
 					 argc, argv, combinedopt);
 		break;
-	case CTLADM_CMD_SHUTDOWN:
-	case CTLADM_CMD_STARTUP:
-		retval = cctl_startup_shutdown(fd, target, lun, initid,
-					       command);
-		break;
-	case CTLADM_CMD_HARDSTOP:
-	case CTLADM_CMD_HARDSTART:
-		retval = cctl_hardstopstart(fd, command);
-		break;
-	case CTLADM_CMD_BBRREAD:
-		retval = cctl_bbrread(fd, target, lun, initid, argc, argv,
-				      combinedopt);
-		break;
 	case CTLADM_CMD_LUNLIST:
 		retval = cctl_lunlist(fd);
 		break;
 	case CTLADM_CMD_DELAY:
-		retval = cctl_delay(fd, target, lun, argc, argv, combinedopt);
+		retval = cctl_delay(fd, lun, argc, argv, combinedopt);
 		break;
-	case CTLADM_CMD_REALSYNC:
-		retval = cctl_realsync(fd, argc, argv);
-		break;
-	case CTLADM_CMD_SETSYNC:
-	case CTLADM_CMD_GETSYNC:
-		retval = cctl_getsetsync(fd, target, lun, command,
-					 argc, argv, combinedopt);
-		break;
 	case CTLADM_CMD_ERR_INJECT:
-		retval = cctl_error_inject(fd, target, lun, argc, argv,
+		retval = cctl_error_inject(fd, lun, argc, argv,
 					   combinedopt);
 		break;
 	case CTLADM_CMD_DUMPOOA:
@@ -4065,24 +4212,33 @@
 		retval = cctl_dump_structs(fd, cmdargs);
 		break;
 	case CTLADM_CMD_PRES_IN:
-		retval = cctl_persistent_reserve_in(fd, target, lun, initid, 
+		retval = cctl_persistent_reserve_in(fd, lun, initid,
 		                                    argc, argv, combinedopt,
 						    retries);
 		break;
 	case CTLADM_CMD_PRES_OUT:
-		retval = cctl_persistent_reserve_out(fd, target, lun, initid, 
+		retval = cctl_persistent_reserve_out(fd, lun, initid,
 						     argc, argv, combinedopt,
 						     retries);
 		break;
 	case CTLADM_CMD_INQ_VPD_DEVID:
-	        retval = cctl_inquiry_vpd_devid(fd, target, lun, initid);
+	        retval = cctl_inquiry_vpd_devid(fd, lun, initid);
 		break;
 	case CTLADM_CMD_RTPG:
-	        retval = cctl_report_target_port_group(fd, target, lun, initid);
+	        retval = cctl_report_target_port_group(fd, lun, initid);
 		break;
 	case CTLADM_CMD_MODIFY:
 	        retval = cctl_modify_lun(fd, argc, argv, combinedopt);
 		break;
+	case CTLADM_CMD_ISLIST:
+	        retval = cctl_islist(fd, argc, argv, combinedopt);
+		break;
+	case CTLADM_CMD_ISLOGOUT:
+	        retval = cctl_islogout(fd, argc, argv, combinedopt);
+		break;
+	case CTLADM_CMD_ISTERMINATE:
+	        retval = cctl_isterminate(fd, argc, argv, combinedopt);
+		break;
 	case CTLADM_CMD_HELP:
 	default:
 		usage(retval);

Modified: trunk/usr.sbin/ctladm/util.c
===================================================================
--- trunk/usr.sbin/ctladm/util.c	2018-06-10 20:15:35 UTC (rev 10818)
+++ trunk/usr.sbin/ctladm/util.c	2018-06-10 20:16:39 UTC (rev 10819)
@@ -56,7 +56,7 @@
 #include <camlib.h>
 #include "ctladm.h"
 
-int verbose;
+static int verbose;
 
 /* iget: Integer argument callback
  */



More information about the Midnightbsd-cvs mailing list