[Stgt-devel] [Patch 1/2] Add dynamic lu configuration.

Mark Harvey markh794
Wed Jun 13 10:01:20 CEST 2007


Ability to configure lu at setup time.
Document extra options passed via tgtadm in doc/README.lu_configuration
Include sample script in scripts/tgt-core-test.

Signed-off-by: Mark Harvey <markh794 at gmail.com>


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/spc.c b/usr/spc.c
index 99a7df3..b9f4e16 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -64,7 +64,7 @@ int spc_inquiry(int host_no, struct scsi_cmd *cmd)
 		uint16_t *desc;
 
 		data[0] = device_type;
-		data[1] = (cmd->dev->attrs->is_removable) ? 0x80 : 0;
+		data[1] = (cmd->dev->attrs->removable) ? 0x80 : 0;
 		data[2] = 5;	/* SPC-3 */
 		data[3] = 0x42;
 		data[7] = 0x02;
@@ -286,18 +286,29 @@ int spc_illegal_op(int host_no, struct scsi_cmd *cmd)
 }
 
 enum {
-	Opt_scsiid, Opt_scsisn, Opt_err,
+	Opt_scsiid, Opt_scsisn,
+	Opt_vendorid, Opt_productid,
+	Opt_productrev, Opt_sense_format,
+	Opt_removable, Opt_online,
+	Opt_err,
 };
 
 static match_table_t tokens = {
 	{Opt_scsiid, "scsi_id=%s"},
 	{Opt_scsisn, "scsi_sn=%s"},
+	{Opt_vendorid, "vendor_id=%s"},
+	{Opt_productid, "product_id=%s"},
+	{Opt_productrev, "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;
@@ -318,6 +329,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_vendorid:
+			match_strncpy(lu->attrs->vendor_id, &args[0],
+					sizeof(lu->attrs->vendor_id));
+			break;
+		case Opt_productid:
+			match_strncpy(lu->attrs->product_id, &args[0],
+					sizeof(lu->attrs->product_id));
+			break;
+		case Opt_productrev:
+			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;
 		}
@@ -333,7 +368,7 @@ int spc_lu_init(struct scsi_lu *lu)
 
 	memcpy(lu->attrs->vendor_id, VENDOR_ID, 8);
 	memcpy(lu->attrs->product_rev, "0001", 4);
-	lu->attrs->is_removable = 0;
+	lu->attrs->removable = 0;
 	lu->attrs->sense_format = 0;
 	lu->attrs->online = 0;
 	lu->attrs->reset = 1;
diff --git a/usr/tgtd.h b/usr/tgtd.h
index 7b64655..35645b1 100644
--- a/usr/tgtd.h
+++ b/usr/tgtd.h
@@ -40,7 +40,7 @@ struct lu_phy_attr {
 	char product_rev[5];
 	uint16_t version_desc[VERSION_DESCRIPTOR_LEN];
 
-	char is_removable;	/* Removable media */
+	char removable;		/* Removable media */
 	char online;		/* Logical Unit online ? */
 	char reset;		/* Power-on or reset has occured */
 	char sense_format;	/* Descrptor format sense data supported */






More information about the stgt mailing list