diff mbox series

[v3,09/15] scsi_debug: zbc module parameter

Message ID 20200220200838.15809-10-dgilbert@interlog.com (mailing list archive)
State Superseded
Headers show
Series host managed ZBC + doublestore | expand

Commit Message

Douglas Gilbert Feb. 20, 2020, 8:08 p.m. UTC
Add zbc module parameter (a boolean) as a synonym for the more
obscure ptype=0x14 . The zbc attribute is also available in
/sys/bus/pseudo/drivers/scsi_debug/zbc and is modifiable.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
 drivers/scsi/scsi_debug.c | 42 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

Comments

Johannes Thumshirn Feb. 21, 2020, 9:49 a.m. UTC | #1
On 20/02/2020 21:09, Douglas Gilbert wrote:
> +MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
>   MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
>   MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
> -MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");

Unrelated change, isn't it?
Douglas Gilbert Feb. 21, 2020, 3:37 p.m. UTC | #2
On 2020-02-21 4:49 a.m., Johannes Thumshirn wrote:
> On 20/02/2020 21:09, Douglas Gilbert wrote:
>> +MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
>>    MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
>>    MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
>> -MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
> 
> Unrelated change, isn't it?

Yes, it should be in the re-arrange in alphabetical order patch. Do you
know a one-liner (or two or ...) for pulling a line out of one patch
and placing it in another with git :-)

Doug Gilbert
Johannes Thumshirn Feb. 22, 2020, 8:27 a.m. UTC | #3
On 21/02/2020 16:37, Douglas Gilbert wrote:
> On 2020-02-21 4:49 a.m., Johannes Thumshirn wrote:
>> On 20/02/2020 21:09, Douglas Gilbert wrote:
>>> +MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
>>>     MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
>>>     MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
>>> -MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
>>
>> Unrelated change, isn't it?
> 
> Yes, it should be in the re-arrange in alphabetical order patch. Do you
> know a one-liner (or two or ...) for pulling a line out of one patch
> and placing it in another with git :-)

 From the top of my head (haven't tested it right now) I'd do

git rebase -i $BASE_BRANCH
<mark this patch as 'edit'>
git reset --soft HEAD^
git add -p
<add hunk #1>
git commit
git add -p
<add other hunks>
git commit
git rebase --continue

This /should/ do the trick, but someone please speak up if there's an 
error in there.

Byte,
	Johannes
diff mbox series

Patch

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 10f8698031aa..be3597805b08 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -763,6 +763,7 @@  static bool have_dif_prot;
 static bool write_since_sync;
 static bool sdebug_statistics = DEF_STATISTICS;
 static bool sdebug_wp;
+static bool sdebug_zbc;
 
 static unsigned int sdebug_store_sectors;
 static sector_t sdebug_capacity;	/* in sectors */
@@ -5443,6 +5444,7 @@  module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int,
 module_param_named(wp, sdebug_wp, bool, S_IRUGO | S_IWUSR);
 module_param_named(write_same_length, sdebug_write_same_length, int,
 		   S_IRUGO | S_IWUSR);
+module_param_named(zbc, sdebug_zbc, bool, S_IRUGO | S_IWUSR);
 
 MODULE_AUTHOR("Eric Youngdale + Douglas Gilbert");
 MODULE_DESCRIPTION("SCSI debug adapter driver");
@@ -5483,9 +5485,9 @@  MODULE_PARM_DESC(no_uld, "stop ULD (e.g. sd driver) attaching (def=0))");
 MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
 MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
 MODULE_PARM_DESC(opt_blks, "optimal transfer length in blocks (def=1024)");
+MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
 MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
 MODULE_PARM_DESC(physblk_exp, "physical block exponent (def=0)");
-MODULE_PARM_DESC(opt_xferlen_exp, "optimal transfer length granularity exponent (def=physblk_exp)");
 MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
 MODULE_PARM_DESC(random, "If set, uniformly randomize command duration between 0 and delay_in_ns");
 MODULE_PARM_DESC(removable, "claim to have removable media (def=0)");
@@ -5504,6 +5506,7 @@  MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size
 MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
 MODULE_PARM_DESC(wp, "Write Protect (def=0)");
 MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)");
+MODULE_PARM_DESC(zbc, "Emulate ZBC device(s) (def=false) [same action as ptype=0x14]");
 
 #define SDEBUG_INFO_LEN 256
 static char sdebug_info[SDEBUG_INFO_LEN];
@@ -6225,6 +6228,42 @@  static ssize_t cdb_len_store(struct device_driver *ddp, const char *buf,
 }
 static DRIVER_ATTR_RW(cdb_len);
 
+static ssize_t zbc_show(struct device_driver *ddp, char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "%d\n", sdebug_ptype == TYPE_ZBC);
+}
+static ssize_t zbc_store(struct device_driver *ddp, const char *buf,
+			 size_t count)
+{
+	bool want_zbc;
+	int ret, n;
+	int prev_pdt = sdebug_ptype;
+
+	ret = kstrtoint(buf, 0, &n);
+	if (ret)
+		return ret;
+	want_zbc = !!n;
+	if (prev_pdt == TYPE_ZBC || want_zbc) {
+		if (prev_pdt == TYPE_ZBC && want_zbc)
+			return count;
+		sdeb_zbc_in_use = want_zbc;
+		if (sdeb_zbc_in_use) {
+			struct sdeb_zone_state *zsp = sdeb_zstate_a;
+
+			sdebug_ptype = TYPE_ZBC;
+			zbc_swrz_start = sdebug_capacity >> 1;
+			zsp->write_pointer = zbc_swrz_start;
+			zsp->z_cond = zc1_empty;
+			++zsp;
+			zsp->write_pointer = zbc_swrz_start;
+			zsp->z_cond = zc1_empty;
+		} else {
+			sdebug_ptype = DEF_PTYPE;	/* a disk ? ? */
+		}
+	}
+	return count;
+}
+static DRIVER_ATTR_RW(zbc);
 
 /* Note: The following array creates attribute files in the
    /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these
@@ -6267,6 +6306,7 @@  static struct attribute *sdebug_drv_attrs[] = {
 	&driver_attr_strict.attr,
 	&driver_attr_uuid_ctl.attr,
 	&driver_attr_cdb_len.attr,
+	&driver_attr_zbc.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(sdebug_drv);