[PATCH] Add ability to dynamically set SCSI Inquiry params

Mark Harvey markh794
Thu May 31 22:07:33 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.
  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 == New sense 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..37a007c
--- /dev/null
+++ b/scripts/tgt-core-test
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+P=`ps -ef|grep -v grep|grep tgtd|wc -l`
+if [ "X"$P == "X0" ]; then
+       tgtd -d 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
+
+sleep 1
+
+###################################################################################
+# 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=1
+
+
+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 e9a74d9..d864443 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->VendorIdent, &args[0],
+                                       sizeof(lu->attributes->VendorIdent));
+                       break;
+               case Opt_ProductIdent:
+                       match_strncpy(lu->attributes->ProductIdent, &args[0],
+                                       sizeof(lu->attributes->ProductIdent));
+                       break;
+               case Opt_ProductRev:
+                       match_strncpy(lu->attributes->ProductRev, &args[0],
+                                       sizeof(lu->attributes->ProductRev));
+                       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->isRemovable = 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



More information about the stgt mailing list