Skip to content

Commit 9b760fd

Browse files
doug-gilbertmartinkpetersen
authored andcommitted
scsi: scsi_debug: add cdb_len parameter
While testing "sd: Micro-optimize READ / WRITE CDB encoding" patches it was helpful to check various code paths associated with READ/WRITE 6, 10 and 16 byte cdb variants. There seems to be no user space "knobs" to twiddle use_10_for_rw and friends in the scsi_device structure. So add a parameter to scsi_debug called "cdb_len" for this purpose. [mkp: fixed typo] Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 4b1d8e7 commit 9b760fd

File tree

1 file changed

+87
-5
lines changed

1 file changed

+87
-5
lines changed

drivers/scsi/scsi_debug.c

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* anything out of the ordinary is seen.
77
* ^^^^^^^^^^^^^^^^^^^^^^^ Original ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88
*
9-
* Copyright (C) 2001 - 2016 Douglas Gilbert
9+
* Copyright (C) 2001 - 2017 Douglas Gilbert
1010
*
1111
* This program is free software; you can redistribute it and/or modify
1212
* it under the terms of the GNU General Public License as published by
@@ -61,8 +61,8 @@
6161
#include "scsi_logging.h"
6262

6363
/* make sure inq_product_rev string corresponds to this version */
64-
#define SDEBUG_VERSION "1.86"
65-
static const char *sdebug_version_date = "20160430";
64+
#define SDEBUG_VERSION "0187" /* format to fit INQUIRY revision field */
65+
static const char *sdebug_version_date = "20171202";
6666

6767
#define MY_NAME "scsi_debug"
6868

@@ -105,6 +105,7 @@ static const char *sdebug_version_date = "20160430";
105105
* (id 0) containing 1 logical unit (lun 0). That is 1 device.
106106
*/
107107
#define DEF_ATO 1
108+
#define DEF_CDB_LEN 10
108109
#define DEF_JDELAY 1 /* if > 0 unit is a jiffy */
109110
#define DEF_DEV_SIZE_MB 8
110111
#define DEF_DIF 0
@@ -571,6 +572,7 @@ static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEMENT + 1] = {
571572

572573
static int sdebug_add_host = DEF_NUM_HOST;
573574
static int sdebug_ato = DEF_ATO;
575+
static int sdebug_cdb_len = DEF_CDB_LEN;
574576
static int sdebug_jdelay = DEF_JDELAY; /* if > 0 then unit is jiffies */
575577
static int sdebug_dev_size_mb = DEF_DEV_SIZE_MB;
576578
static int sdebug_dif = DEF_DIF;
@@ -797,6 +799,61 @@ static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
797799
/* return -ENOTTY; // correct return but upsets fdisk */
798800
}
799801

802+
static void config_cdb_len(struct scsi_device *sdev)
803+
{
804+
switch (sdebug_cdb_len) {
805+
case 6: /* suggest 6 byte READ, WRITE and MODE SENSE/SELECT */
806+
sdev->use_10_for_rw = false;
807+
sdev->use_16_for_rw = false;
808+
sdev->use_10_for_ms = false;
809+
break;
810+
case 10: /* suggest 10 byte RWs and 6 byte MODE SENSE/SELECT */
811+
sdev->use_10_for_rw = true;
812+
sdev->use_16_for_rw = false;
813+
sdev->use_10_for_ms = false;
814+
break;
815+
case 12: /* suggest 10 byte RWs and 10 byte MODE SENSE/SELECT */
816+
sdev->use_10_for_rw = true;
817+
sdev->use_16_for_rw = false;
818+
sdev->use_10_for_ms = true;
819+
break;
820+
case 16:
821+
sdev->use_10_for_rw = false;
822+
sdev->use_16_for_rw = true;
823+
sdev->use_10_for_ms = true;
824+
break;
825+
case 32: /* No knobs to suggest this so same as 16 for now */
826+
sdev->use_10_for_rw = false;
827+
sdev->use_16_for_rw = true;
828+
sdev->use_10_for_ms = true;
829+
break;
830+
default:
831+
pr_warn("unexpected cdb_len=%d, force to 10\n",
832+
sdebug_cdb_len);
833+
sdev->use_10_for_rw = true;
834+
sdev->use_16_for_rw = false;
835+
sdev->use_10_for_ms = false;
836+
sdebug_cdb_len = 10;
837+
break;
838+
}
839+
}
840+
841+
static void all_config_cdb_len(void)
842+
{
843+
struct sdebug_host_info *sdbg_host;
844+
struct Scsi_Host *shost;
845+
struct scsi_device *sdev;
846+
847+
spin_lock(&sdebug_host_list_lock);
848+
list_for_each_entry(sdbg_host, &sdebug_host_list, host_list) {
849+
shost = sdbg_host->shost;
850+
shost_for_each_device(sdev, shost) {
851+
config_cdb_len(sdev);
852+
}
853+
}
854+
spin_unlock(&sdebug_host_list_lock);
855+
}
856+
800857
static void clear_luns_changed_on_target(struct sdebug_dev_info *devip)
801858
{
802859
struct sdebug_host_info *sdhp;
@@ -955,7 +1012,7 @@ static int fetch_to_dev_buffer(struct scsi_cmnd *scp, unsigned char *arr,
9551012

9561013
static char sdebug_inq_vendor_id[9] = "Linux ";
9571014
static char sdebug_inq_product_id[17] = "scsi_debug ";
958-
static char sdebug_inq_product_rev[5] = "0186"; /* version less '.' */
1015+
static char sdebug_inq_product_rev[5] = SDEBUG_VERSION;
9591016
/* Use some locally assigned NAAs for SAS addresses. */
9601017
static const u64 naa3_comp_a = 0x3222222000000000ULL;
9611018
static const u64 naa3_comp_b = 0x3333333000000000ULL;
@@ -1411,6 +1468,8 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
14111468
memcpy(&arr[8], sdebug_inq_vendor_id, 8);
14121469
memcpy(&arr[16], sdebug_inq_product_id, 16);
14131470
memcpy(&arr[32], sdebug_inq_product_rev, 4);
1471+
/* Use Vendor Specific area to place driver date in ASCII hex */
1472+
memcpy(&arr[36], sdebug_version_date, 8);
14141473
/* version descriptors (2 bytes each) follow */
14151474
put_unaligned_be16(0xc0, arr + 58); /* SAM-6 no version claimed */
14161475
put_unaligned_be16(0x5c0, arr + 60); /* SPC-5 no version claimed */
@@ -3660,6 +3719,7 @@ static int scsi_debug_slave_configure(struct scsi_device *sdp)
36603719
blk_queue_max_segment_size(sdp->request_queue, -1U);
36613720
if (sdebug_no_uld)
36623721
sdp->no_uld_attach = 1;
3722+
config_cdb_len(sdp);
36633723
return 0;
36643724
}
36653725

@@ -4138,6 +4198,7 @@ static int schedule_resp(struct scsi_cmnd *cmnd, struct sdebug_dev_info *devip,
41384198
*/
41394199
module_param_named(add_host, sdebug_add_host, int, S_IRUGO | S_IWUSR);
41404200
module_param_named(ato, sdebug_ato, int, S_IRUGO);
4201+
module_param_named(cdb_len, sdebug_cdb_len, int, 0644);
41414202
module_param_named(clustering, sdebug_clustering, bool, S_IRUGO | S_IWUSR);
41424203
module_param_named(delay, sdebug_jdelay, int, S_IRUGO | S_IWUSR);
41434204
module_param_named(dev_size_mb, sdebug_dev_size_mb, int, S_IRUGO);
@@ -4195,6 +4256,7 @@ MODULE_VERSION(SDEBUG_VERSION);
41954256

41964257
MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
41974258
MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)");
4259+
MODULE_PARM_DESC(cdb_len, "suggest CDB lengths to drivers (def=10)");
41984260
MODULE_PARM_DESC(clustering, "when set enables larger transfers (def=0)");
41994261
MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
42004262
MODULE_PARM_DESC(dev_size_mb, "size in MiB of ram shared by devs(def=8)");
@@ -4207,7 +4269,8 @@ MODULE_PARM_DESC(guard, "protection checksum: 0=crc, 1=ip (def=0)");
42074269
MODULE_PARM_DESC(host_lock, "host_lock is ignored (def=0)");
42084270
MODULE_PARM_DESC(inq_vendor, "SCSI INQUIRY vendor string (def=\"Linux\")");
42094271
MODULE_PARM_DESC(inq_product, "SCSI INQUIRY product string (def=\"scsi_debug\")");
4210-
MODULE_PARM_DESC(inq_rev, "SCSI INQUIRY revision string (def=\"0186\")");
4272+
MODULE_PARM_DESC(inq_rev, "SCSI INQUIRY revision string (def=\""
4273+
SDEBUG_VERSION "\")");
42114274
MODULE_PARM_DESC(lbpu, "enable LBP, support UNMAP command (def=0)");
42124275
MODULE_PARM_DESC(lbpws, "enable LBP, support WRITE SAME(16) with UNMAP bit (def=0)");
42134276
MODULE_PARM_DESC(lbpws10, "enable LBP, support WRITE SAME(10) with UNMAP bit (def=0)");
@@ -4881,6 +4944,24 @@ static ssize_t uuid_ctl_show(struct device_driver *ddp, char *buf)
48814944
}
48824945
static DRIVER_ATTR_RO(uuid_ctl);
48834946

4947+
static ssize_t cdb_len_show(struct device_driver *ddp, char *buf)
4948+
{
4949+
return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_cdb_len);
4950+
}
4951+
static ssize_t cdb_len_store(struct device_driver *ddp, const char *buf,
4952+
size_t count)
4953+
{
4954+
int ret, n;
4955+
4956+
ret = kstrtoint(buf, 0, &n);
4957+
if (ret)
4958+
return ret;
4959+
sdebug_cdb_len = n;
4960+
all_config_cdb_len();
4961+
return count;
4962+
}
4963+
static DRIVER_ATTR_RW(cdb_len);
4964+
48844965

48854966
/* Note: The following array creates attribute files in the
48864967
/sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these
@@ -4920,6 +5001,7 @@ static struct attribute *sdebug_drv_attrs[] = {
49205001
&driver_attr_ndelay.attr,
49215002
&driver_attr_strict.attr,
49225003
&driver_attr_uuid_ctl.attr,
5004+
&driver_attr_cdb_len.attr,
49235005
NULL,
49245006
};
49255007
ATTRIBUTE_GROUPS(sdebug_drv);

0 commit comments

Comments
 (0)