[PATCH] Add ability to dynamically set SCSI Inquiry params

Mark Harvey markh794
Sat Jun 2 09:57:34 CEST 2007


Added support to configure:
  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.

All params are passed using the 'tgtadm' utility:

  VendorIdent="string"
  ProductIdent="string"
  ProductRev="string"
  Removable=<0|1> - 0 == non-removable, 1 == removable media
  SenseFormat=<0|1> - 0 == Clasic sense format, 1 == Support descriptor format
  Online=<0|1> - 0 == Unit offline, 1 == Unit Online

e.g.
tgtadm --lld iscsi --mode logicalunit --op update --tid <TID> --lun <LUN> \
        --params VendorIdent=QUANTUM,ProductIdent=HD100,ProductRev=0010
tgtadm --lld iscsi --mode logicalunit --op update --tid <TID> --lun <LUN> \
        --params Removable=1,SenseFormat=1,Online=1

Example script (scripts/tgt-core-test) to set up HDD & CD device.

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

diff --git a/scripts/tgt-core-test b/scripts/tgt-core-test
new file mode 100755
index 0000000..d529849
--- /dev/null
+++ b/scripts/tgt-core-test
@@ -0,0 +1,73 @@
+#!/bin/bash
+
+P=`ps -ef|grep -v grep|grep tgtd|wc -l`
+if [ "X"$P == "X0" ]; then
+	tgtd -d 1
+	sleep 1
+fi
+
+if [ ! -d /d/01 ]; then
+	mkdir -p /d/01
+fi
+
+if [ ! -f /d/01/hd_block ]; then
+	dd if=/dev/zero of=/d/01/hd_block bs=1M count=8
+fi
+if [ ! -f /d/01/cd_block0 ]; then
+	dd if=/dev/zero of=/d/01/cd_block0 bs=1M count=8
+fi
+if [ ! -f /d/01/cd_block1 ]; then
+	dd if=/dev/zero of=/d/01/cd_block1 bs=1M count=8
+fi
+if [ ! -f /d/01/cd_block2 ]; then
+	dd if=/dev/zero of=/d/01/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 /d/01/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 VendorIdent=QUANTUM,ProductIdent=HD100,ProductRev=0010,Removable=1,SenseFormat=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 /d/01/cd_block0
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 0 \
+	--params VendorIdent=VirtualCD,ProductIdent=CD101,ProductRev=0010,scsi_sn=XYZZY10,Removable=1
+
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 1 -b /d/01/cd_block1
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 1 \
+	--params VendorIdent=VirtualCD,ProductIdent=CD101,ProductRev=0010,scsi_sn=XYZZY11,Removable=1
+
+tgtadm --lld iscsi --mode logicalunit --op new --tid $TID --lun 2 -b /d/01/cd_block2
+tgtadm --lld iscsi --mode logicalunit --op update --tid $TID --lun 2 \
+	--params VendorIdent=VirtualCD,ProductIdent=CD101,ProductRev=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 32a9ff7..a29811e 100644
--- a/usr/spc.c
+++ b/usr/spc.c
@@ -283,18 +283,29 @@ int spc_illegal_op(int host_no, struct scsi_cmd *cmd)
 }
 
 enum {
-	Opt_scsiid, Opt_scsisn, Opt_err,
+	Opt_scsiid, Opt_scsisn,
+	Opt_VendorIdent, Opt_ProductIdent,
+	Opt_ProductRev, Opt_SenseFormat,
+	Opt_Removable, Opt_Online,
+	Opt_err,
 };
 
 static match_table_t tokens = {
 	{Opt_scsiid, "scsi_id=%s"},
 	{Opt_scsisn, "scsi_sn=%s"},
+	{Opt_VendorIdent, "VendorIdent=%s"},
+	{Opt_ProductIdent, "ProductIdent=%s"},
+	{Opt_ProductRev, "ProductRev=%s"},
+	{Opt_SenseFormat, "SenseFormat=%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;
@@ -315,6 +326,30 @@ int spc_lu_config(struct scsi_lu *lu, char *params) {
 			match_strncpy(lu->attributes->scsi_sn, &args[0],
 				      sizeof(lu->attributes->scsi_sn) - 1);
 			break;
+		case Opt_VendorIdent:
+			match_strncpy(lu->attributes->vendor_ident, &args[0],
+					sizeof(lu->attributes->vendor_ident));
+			break;
+		case Opt_ProductIdent:
+			match_strncpy(lu->attributes->product_ident, &args[0],
+					sizeof(lu->attributes->product_ident));
+			break;
+		case Opt_ProductRev:
+			match_strncpy(lu->attributes->product_rev, &args[0],
+					sizeof(lu->attributes->product_rev));
+			break;
+		case Opt_SenseFormat:
+			match_strncpy(buf, &args[0],  sizeof(buf));
+			lu->attributes->sense_format = atoi(buf);
+			break;
+		case Opt_Removable:
+			match_strncpy(buf, &args[0],  sizeof(buf));
+			lu->attributes->is_removable = atoi(buf);
+			break;
+		case Opt_Online:
+			match_strncpy(buf, &args[0],  sizeof(buf));
+			lu->attributes->online = atoi(buf);
+			break;
 		default:
 			err = TGTADM_INVALID_REQUEST;
 		}
-- 
1.5.1.3


--------------050907090501010500080605--



More information about the stgt mailing list