[Stgt-devel] [Patch 2/2] Dynamic logical unit configuration
Mark Harvey
markh794
Fri Jun 15 09:59:16 CEST 2007
>From e7fe3668dae6d3654b59b1f3b889431ea2d284b8 Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Fri, 15 Jun 2007 17:49:25 +1000
Subject: Dynamic logical unit configuration.
Add support to set/configure:
Vendor Identification
Product Identification
Product Revision
Returned format of sense data
Define if lu is capable of supporting removable media
Define if lu is online/offline
Initial documentation of supported options (doc/README.lu_configuration)
Sample script to set up lu (scripts/tgt-core-test)
Signed-off-by: Mark Harvey <markh794 at gmail.com>
---
doc/README.lu_configuration | 69 +++++++++++++++++++++++++++++++++++++++
scripts/tgt-core-test | 76 +++++++++++++++++++++++++++++++++++++++++++
usr/mmc.c | 2 +-
usr/osd.c | 2 +-
usr/sbc.c | 2 +-
usr/spc.c | 38 ++++++++++++++++++++-
6 files changed, 184 insertions(+), 5 deletions(-)
create mode 100644 doc/README.lu_configuration
create mode 100755 scripts/tgt-core-test
diff --git a/doc/README.lu_configuration b/doc/README.lu_configuration
new file mode 100644
index 0000000..1244bc0
--- /dev/null
+++ b/doc/README.lu_configuration
@@ -0,0 +1,69 @@
+Preface
+--------------
+This show a simple example to set up some logical units (lu).
+Please refer to README.iscsi on instructions to create logical unit(s).
+
+tgtadm options
+--------------
+You are able to modify some logical unit parameters as well as
+modify behaviour of SCSI Sense op code.
+
+NOTE: It is not recommended to change these parameters after the
+target/logical unit has been enabled to accept initiators.
+
+It is currently possible to change/modify the following:
+
+ Vendor Identification
+ Product Identification
+ Product Revision
+ Format of returned 'sense data'
+ Define if the lu is capable of supporting removable media
+ Define/set if the lu is online / offline.
+ Params are passed using the 'tgtadm' utility:
+
+Format of options are:
+ vendor_id="string"
+ product_id="string"
+ product_rev="string"
+ removable=<0|1> - 0 = non-removable, 1 = removable media
+ sense_format=<0|1> - 0 = Clasic sense format, 1 = Support descriptor format
+ online=<0|1> - 0 == Unit offline, 1 == Unit Online
+
+The options are passed to the logical unit via the "--params" switch to tgtadm
+
+e.g.
+tgtadm --lld iscsi --mode logicalunit --op update --tid <TID> --lun <LUN> \
+ --params vendor_id=QUANTUM,product_id=HD100,product_rev=0010
+tgtadm --lld iscsi --mode logicalunit --op update --tid <TID> --lun <LUN> \
+ --params removable=1,sense_format=1,online=1
+
+Or it can be performed in one go:
+tgtadm --lld iscsi --mode logicalunit --op update --tid <TID> --lun <LUN> \
+ --params vendor_id=QUANTUM,product_id=HD100,product_rev=0010,scsi_sn=FRED00,removable=1,sense_format=0,online=1
+
+
+# sg_inq -v /dev/sg5
+ inquiry cdb: 12 00 00 00 24 00
+standard INQUIRY:
+ inquiry cdb: 12 00 00 00 42 00
+ PQual=0 Device_type=0 RMB=1 version=0x05 [SPC-3]
+ [AERC=0] [TrmTsk=1] NormACA=0 HiSUP=0 Resp_data_format=2
+ SCCS=0 ACC=0 TGPS=0 3PC=0 Protect=0 BQue=0
+ EncServ=0 MultiP=0 [MChngr=0] [ACKREQQ=0] Addr16=0
+ [RelAdr=0] WBus16=0 Sync=0 Linked=0 [TranDis=0] CmdQue=1
+ Clocking=0x0 QAS=0 IUS=0
+ length=66 (0x42) Peripheral device type: disk
+ Vendor identification: QUANTUM
+ Product identification: HD100
+ Product revision level: 0010
+ inquiry cdb: 12 01 00 00 fc 00
+ inquiry: requested 252 bytes but got 7 bytes
+ inquiry cdb: 12 01 80 00 fc 00
+ inquiry: requested 252 bytes but got 12 bytes
+ Unit serial number: FRED00
+
+As can be seen from above 'sg_inq' output, the RMB (removable) bit is set to 1.
+The Unit serial number page updated with 'FRED00'
+
+Please refer to scripts/tgt-core-test for a working example.
+
diff --git a/scripts/tgt-core-test b/scripts/tgt-core-test
new file mode 100755
index 0000000..1bbb404
--- /dev/null
+++ b/scripts/tgt-core-test
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+# Parent directory for data files..
+HOME=/d/01
+
+P=`ps -ef|grep -v grep|grep tgtd|wc -l`
+if [ "X"$P == "X0" ]; then
+ tgtd -d 1
+ sleep 1
+fi
+
+if [ ! -d $HOME ]; then
+ mkdir -p $HOME
+fi
+
+if [ ! -f $HOME/hd_block ]; then
+ dd if=/dev/zero of=$HOME/hd_block bs=1M count=8
+fi
+if [ ! -f $HOME/cd_block0 ]; then
+ dd if=/dev/zero of=$HOME/cd_block0 bs=1M count=8
+fi
+if [ ! -f $HOME/cd_block1 ]; then
+ dd if=/dev/zero of=$HOME/cd_block1 bs=1M count=8
+fi
+if [ ! -f $HOME/cd_block2 ]; then
+ dd if=/dev/zero of=$HOME/cd_block2 bs=1M count=8
+fi
+
+set -x
+
+###################################################################################
+# Set up SBC HDD device
+###################################################################################
+TID=1
+
+tgtadm --lld iscsi --mode target --op new --tid $TID \
+ -T iqn.2007-03:marks-vtl_sbc:`hostname` --target-type disk
+
+sleep 1
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 0 -b $HOME/hd_block
+
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 0 --params scsi_sn=FRED00,scsi_id=Fred
+
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 0 \
+ --params vendor_id=QUANTUM,product_id=HD100,product_rev=0010,removable=1,sense_format=0
+
+
+tgtadm --lld iscsi --mode target --op bind --tid $TID -I ALL
+
+
+###################################################################################
+# Set up MMC CD/DVD device
+###################################################################################
+TID=2
+
+tgtadm --lld iscsi --mode target --op new --tid $TID \
+ -T iqn.2007-03:marks-vtl_mmc:`hostname` --target-type cd
+
+sleep 1
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 0 -b $HOME/cd_block0
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 0 \
+ --params vendor_id=VirtualCD,product_id=CD101,product_rev=0010,scsi_sn=XYZZY10,removable=1
+
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 1 -b $HOME/cd_block1
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 1 \
+ --params vendor_id=VirtualCD,product_id=CD101,product_rev=0010,scsi_sn=XYZZY11,removable=1
+
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 2 -b $HOME/cd_block2
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 2 \
+ --params vendor_id=VirtualCD,product_id=CD101,product_rev=0010,scsi_sn=XYZZY12,removable=1
+
+tgtadm --lld iscsi --mode target --op bind --tid $TID -I ALL
+
+tgtadm --lld iscsi --mode target --op show
+
+
diff --git a/usr/mmc.c b/usr/mmc.c
index 0ac5f72..adecd4c 100644
--- a/usr/mmc.c
+++ b/usr/mmc.c
@@ -126,7 +126,7 @@ static int mmc_lu_init(struct scsi_lu *lu)
if (spc_lu_init(lu))
return -ENOMEM;
- memcpy(lu->attrs.product_id, "VIRTUAL-CDROM", 16);
+ strncpy(lu->attrs.product_id, "VIRTUAL-CDROM", sizeof(lu->attrs.product_id));
lu->attrs.sense_format = 0;
lu->attrs.version_desc[0] = 0x02A0; /* MMC3, no version claimed */
lu->attrs.version_desc[1] = 0x0960; /* iSCSI */
diff --git a/usr/osd.c b/usr/osd.c
index 33d6455..a7316fa 100644
--- a/usr/osd.c
+++ b/usr/osd.c
@@ -56,7 +56,7 @@ static int osd_lu_init(struct scsi_lu *lu)
if (spc_lu_init(lu))
return -ENOMEM;
- memcpy(lu->attrs.product_id, "OSD", 16);
+ strncpy(lu->attrs.product_id, "OSD", sizeof(lu->attrs.product_id));
lu->attrs.sense_format = 1;
lu->attrs.version_desc[0] = 0x0340; /* OSD */
lu->attrs.version_desc[1] = 0x0960; /* iSCSI */
diff --git a/usr/sbc.c b/usr/sbc.c
index 8fe39e7..3d59f60 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -342,7 +342,7 @@ static int sbc_lu_init(struct scsi_lu *lu)
if (spc_lu_init(lu))
return -ENOMEM;
- memcpy(lu->attrs.product_id, "VIRTUAL-DISK", 16);
+ strncpy(lu->attrs.product_id, "VIRTUAL-DISK", sizeof(lu->attrs.product_id));
lu->attrs.version_desc[0] = 0x04C0; /* SBC-3 no version claimed */
lu->attrs.version_desc[1] = 0x0960; /* iSCSI */
lu->attrs.version_desc[2] = 0x0300; /* SPC-3 */
diff --git a/usr/spc.c b/usr/spc.c
index 602af5d..a6234ca 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -286,18 +286,29 @@ int spc_illegal_op(int host_no, struct scsi_cmd *cmd)
}
enum {
- Opt_scsi_id, Opt_scsi_sn, Opt_err,
+ Opt_scsi_id, Opt_scsi_sn,
+ Opt_vendor_id, Opt_product_id,
+ Opt_product_rev, Opt_sense_format,
+ Opt_removable, Opt_online,
+ Opt_err,
};
static match_table_t tokens = {
{Opt_scsi_id, "scsi_id=%s"},
{Opt_scsi_sn, "scsi_sn=%s"},
+ {Opt_vendor_id, "vendor_id=%s"},
+ {Opt_product_id, "product_id=%s"},
+ {Opt_product_rev, "product_rev=%s"},
+ {Opt_sense_format, "sense_format=%s"},
+ {Opt_removable, "removable=%s"},
+ {Opt_online, "online=%s"},
{Opt_err, NULL},
};
int spc_lu_config(struct scsi_lu *lu, char *params) {
int err = 0;
char *p;
+ char buf[20];
if (!strncmp("targetOps", params, 9))
params = params + 10;
@@ -307,7 +318,6 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
int token;
if (!*p)
continue;
- dprintf("*p : %s\n", p);
token = match_token(p, tokens, args);
switch (token) {
case Opt_scsi_id:
@@ -318,6 +328,30 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
match_strncpy(lu->attrs.scsi_sn, &args[0],
sizeof(lu->attrs.scsi_sn) - 1);
break;
+ case Opt_vendor_id:
+ match_strncpy(lu->attrs.vendor_id, &args[0],
+ sizeof(lu->attrs.vendor_id));
+ break;
+ case Opt_product_id:
+ match_strncpy(lu->attrs.product_id, &args[0],
+ sizeof(lu->attrs.product_id));
+ break;
+ case Opt_product_rev:
+ match_strncpy(lu->attrs.product_rev, &args[0],
+ sizeof(lu->attrs.product_rev));
+ break;
+ case Opt_sense_format:
+ match_strncpy(buf, &args[0], sizeof(buf));
+ lu->attrs.sense_format = atoi(buf);
+ break;
+ case Opt_removable:
+ match_strncpy(buf, &args[0], sizeof(buf));
+ lu->attrs.removable = atoi(buf);
+ break;
+ case Opt_online:
+ match_strncpy(buf, &args[0], sizeof(buf));
+ lu->attrs.online = atoi(buf);
+ break;
default:
err = TGTADM_INVALID_REQUEST;
}
--
1.5.2.1
More information about the stgt
mailing list