Skip to contentSkip to conversation

scst: Add scst_local driver.

PATCH In review Bart Van Assche 3 participants 6 messages Dec 20, 2010 – Dec 30, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 3/7 scst: Add scst_local driver.

scst_local makes virtual SCST devices available as local SCSI devices.

---
 Documentation/scst/README.scst_local |  263 ++++++
 drivers/scst/Kconfig                 |    2 +
 drivers/scst/Makefile                |    2 +-
 drivers/scst/scst_local/Kconfig      |   22 +
 drivers/scst/scst_local/Makefile     |    2 +
 drivers/scst/scst_local/scst_local.c | 1471 ++++++++++++++++++++++++++++++++++
 6 files changed, 1761 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/scst/README.scst_local
 create mode 100644 drivers/scst/scst_local/Kconfig
 create mode 100644 drivers/scst/scst_local/Makefile
 create mode 100644 drivers/scst/scst_local/scst_local.c
Documentation/scst/README.scst_local new file +263 -0
new file mode 100644
index 0000000..da24bab
@@ -0,0 +1,263 @@
+SCST Local ...
+Richard Sharpe, 30-Nov-2008
+
+This is the SCST Local driver. Its function is to allow you to access devices
+that are exported via SCST directly on the same Linux system that they are
+exported from.
+
+No assumptions are made in the code about the device types on the target, so
+any device handlers that you load in SCST should be visible, including tapes
+and so forth.
+
+You can freely use any sg, sd, st, etc. devices imported from target,
+except the following: you can't mount file systems or put swap on them.
+This is a limitation of Linux memory/cache manager. See SCST README file
+for details.
+
+To build, simply issue 'make' in the scst_local directory.
+
+Try 'modinfo scst_local' for a listing of module parameters so far.
+
+Here is how I have used it so far:
+
+1. Load up scst:
+
+  modprobe scst
+  modprobe scst_vdisk
+
+2. Create a virtual disk (or your own device handler):
+
+  dd if=/dev/zero of=/some/path/vdisk1.img bs=16384 count=1000000
+  echo "add_device vm_disk1 filename=/some/path/vdisk1.img" >/sys/kernel/scst_tgt/handlers/vdisk_fileio/mgmt
+
+3. Load the scst_local driver:
+
+  insmod scst_local
+  echo "add vm_disk1 0" >/sys/kernel/scst_tgt/targets/scst_local/scst_local_tgt/luns/mgmt
+
+4. Check what you have
+
+   cat /proc/scsi/scsi
+  Attached devices:
+  Host: scsi0 Channel: 00 Id: 00 Lun: 00
+    Vendor: ATA      Model: ST9320320AS      Rev: 0303
+    Type:   Direct-Access                    ANSI  SCSI revision: 05
+  Host: scsi4 Channel: 00 Id: 00 Lun: 00
+    Vendor: TSSTcorp Model: CD/DVDW TS-L632D Rev: TO04
+    Type:   CD-ROM                           ANSI  SCSI revision: 05
+  Host: scsi7 Channel: 00 Id: 00 Lun: 00
+    Vendor: SCST_FIO Model: vm_disk1         Rev:  200
+    Type:   Direct-Access                    ANSI  SCSI revision: 04
+
+Or instead of manually "add_device" in (2) and step (3) write a
+scstadmin config:
+
+HANDLER vdisk_fileio {
+        DEVICE vm_disk1 {
+        	filename /some/path/vdisk1.img
+        }
+}
+
+TARGET_DRIVER scst_local {
+	TARGET scst_local_tgt {
+		LUN 0 vm_disk1
+	}
+}
+
+then:
+
+  insmod scst_local
+  scstadmin -config conf_file.cfg
+
+More advanced examples:
+
+For (3) you can:
+
+  insmod scst_local add_default_tgt=0
+  echo "add_target scst_local_tgt session_name=scst_local_host" >/sys/kernel/scst_tgt/targets/scst_local//mgmt
+  echo "add vm_disk1 0" >/sys/kernel/scst_tgt/targets/scst_local/scst_local_tgt/luns/mgmt
+
+Scst_local module's parameter add_default_tgt disables creation of
+default target "scst_local_tgt" and session "scst_local_host", so you
+needed to create it manually.
+
+There can be any number of targets and sessions created. Each SCST
+session corresponds to SCSI host. You can change which LUNs assigned to
+each session by using SCST access control. This mode is intended for
+user space target drivers (see below).
+
+Alternatively, you can write an scstadmin's config file conf_file.cfg:
+
+HANDLER vdisk_fileio {
+        DEVICE vm_disk1 {
+        	filename /some/path/vdisk1.img
+        }
+}
+
+TARGET_DRIVER scst_local {
+	TARGET scst_local_tgt {
+		session_name scst_local_host
+
+		LUN 0 vm_disk1
+	}
+}
+
+then:
+
+  insmod scst_local add_default_tgt=0
+  scstadmin -config conf_file.cfg
+
+NOTE! Although scstadmin allows to create scst_local's sessions using
+"session_name" expression, it doesn't save existing sessions during
+writing config file by "write_config" command. If you need this
+functionality, feel free to send a request for it in SCST development
+mailing list.
+
+5. Have fun.
+
+Some of this was coded while in Santa Clara, some in Bangalore, and some in
+Hyderabad. Noe doubt some will be coded on the way back to Santa Clara.
+
+The code still has bugs, so if you encounter any, email me the fixes at:
+
+   [email protected]
+
+I am thinking of renaming this to something more interesting.
+
+
+Sysfs interface
+===============
+
+See SCST's README for a common SCST sysfs description.
+
+Root of this driver is /sys/kernel/scst_tgt/targets/scst_local. It has
+the following additional entry:
+
+ - stats - read-only attribute with some statistical information.
+
+Each target subdirectory contains the following additional entries:
+
+ - phys_transport_version - contains and allows to change physical
+   transport version descriptor. It determines by which phisical
+   interface this target will look like. See SPC for more details. By
+   default, it is not defined (0).
+
+ - scsi_transport_version - contains and allows to change SCSI
+   transport version descriptor. It determines by which SCSI
+   transport this target will look like. See SPC for more details. By
+   default, it is SAS.
+
+Each session subdirectory contains the following additional entries:
+
+ - transport_id - contains this host's TransportID. This TransportID
+   used to identify initiator in Persisten Reservation commands. If you
+   change scsi_transport_version for a target, make sure you set for all
+   its sessions correct TransportID. See SPC for more details.
+
+ - host - links to the corresponding SCSI host. Using it you can find
+   local sg/bsg/sd/etc. devices of this session. For instance, this
+   links points out to host12, so you can find your sg devices by:
+
+$ lsscsi -g|grep "\[12:"
+[12:0:0:0]   disk    SCST_FIO rd1               200  /dev/sdc  /dev/sg2
+[12:0:0:1]   disk    SCST_FIO nullio            200  /dev/sdd  /dev/sg3
+
+They are /dev/sg2 and /dev/sg3.
+
+The following management commands available via /sys/kernel/scst_tgt/targets/scst_local/mgmt:
+
+ - add_target target_name [session_name=sess_name; [session_name=sess_name1;] [...]] -
+   creates a target with optionally one or more sessions.
+
+ - del_target target_name - deletes a target.
+
+ - add_session target_name session_name - adds to target target_name
+   session (SCSI host) with name session_name.
+
+ - del_session target_name session_name - deletes session session_name
+    from target target_name.
+
+
+Note on performance
+===================
+
+Although this driver implemented in the most performance effective way,
+including zero-copy passing data between SCSI/block subsystems and SCST,
+in many cases it is NOT suited to measure performance as a NULL link.
+For example, it is not suited for max IOPS measurements. This is because
+for such cases not performance of the link between the target and
+initiator is the bottleneck, but CPU or memory speed on the target or
+initiator. For scst_local you have both initiator and target on the same
+system, which means each your initiator and target are much less
+CPU/memory powerful.
+
+
+User space target drivers
+=========================
+
+Scst_local can be used to write full featured SCST target drivers in
+user space:
+
+1. For each SCSI target a user space target driver should create an
+   scst_local's target using "add_target" command.
+
+2. Then the user space target driver should, if needed, set its SCSI and
+   physical transport version descriptors using attributes
+   scsi_transport_version and phys_transport_version correspondingly in
+   /sys/kernel/scst_tgt/targets/scst_local/target_name directory.
+
+3. For incoming session (I_T nexus) from an initiator the user space
+   target driver should create scst_local's session using "add_session"
+   command.
+
+4. Then, if needed, the user space target driver should set TransportID
+   for this session (I_T nexus) using attribute
+   /sys/kernel/scst_tgt/targets/scst_local/target_name/sessions/session_name/transport_id
+
+5. Then the user space target driver should find out sg/bsg devices for
+   the LUNs the created session has using link
+   /sys/kernel/scst_tgt/targets/scst_local/target_name/sessions/session_name/host
+   as described above.
+
+6. Then the user space target driver can start serving the initiator using
+   found sg/bsg devices.
+
+For other connected initiators steps 3-6 should be repeated.
+
+
+Change log
+==========
+
+V0.1 24-Sep-2008 (Hyderabad) Initial coding, pretty chatty and messy,
+                             but worked.
+
+V0.2 25-Sep-2008 (Hong Kong) Cleaned up the code a lot, reduced the log
+			     chatter, fixed a bug where multiple LUNs did not
+			     work. Also, added logging control. Tested with
+			     five virtual disks. They all came up as /dev/sdb
+			     through /dev/sdf and I could dd to them. Also
+			     fixed a bug preventing multiple adapters.
+
+V0.3 26-Sep-2008 (Santa Clara) Added back a copyright plus cleaned up some
+			       unused functions and structures.
+
+V0.4 5-Oct-2008 (Santa Clara) Changed name to scst_local as suggested, cleaned
+			      up some unused variables (made them used) and
+			      change allocation to a kmem_cache pool.
+
+V0.5 5-Oct-2008 (Santa Clara) Added mgmt commands to handle dev reset and
+			      aborts. Not sure if aborts works. Also corrected
+			      the version info and renamed readme to README.
+
+V0.6 7-Oct-2008 (Santa Clara) Removed some redundant code and made some
+			      changes suggested by Vladislav.
+
+V0.7 11-Oct-2008 (Santa Clara) Moved into the scst tree. Cleaned up some
+			       unused functions, used TRACE macros etc.
+
+V0.9 30-Nov-2008 (Mtn View) Cleaned up an additional problem with symbols not
+			    being defined in older version of the kernel. Also
+			    fixed some English and cleaned up this doc.
+
+V1.0 10-Sep-2010 (Moscow)   Sysfs management added. Reviewed and cleaned up.
+
drivers/scst/Kconfig +2 -0
index fd24ec3..0263931 100644
@@ -248,4 +248,6 @@ config SCST_MEASURE_LATENCY
 
 	  If unsure, say "N".
 
+source "drivers/scst/scst_local/Kconfig"
+
 endmenu
drivers/scst/Makefile +1 -1
index 2ffddc8..ac87362 100644
@@ -8,4 +8,4 @@ scst-y        += scst_sysfs.o
 scst-y        += scst_mem.o
 scst-y        += scst_debug.o
 
-obj-$(CONFIG_SCST)   += scst.o dev_handlers/
+obj-$(CONFIG_SCST)   += scst.o dev_handlers/ scst_local/
drivers/scst/scst_local/Kconfig new file +22 -0
new file mode 100644
index 0000000..da40460
@@ -0,0 +1,22 @@
+config SCST_LOCAL
+	tristate "SCST Local driver"
+	depends on SCST && !HIGHMEM4G && !HIGHMEM64G
+	---help---
+	  This module provides a LLD SCSI driver that connects to
+	  the SCST target mode subsystem in a loop-back manner.
+	  It allows you to test target-mode device-handlers locally.
+	  You will need the SCST subsystem as well.
+
+	  If unsure whether you really want or need this, say N.
+
+config SCST_LOCAL_FORCE_DIRECT_PROCESSING
+	bool "Force local processing"
+	depends on SCST_LOCAL
+	help
+	  This experimental option forces scst_local to make SCST process
+	  SCSI commands in the same context, in which they was submitted.
+	  Otherwise, they will be processed in SCST threads. Setting this
+	  option to "Y" will give some performance increase, but might be
+	  unsafe.
+
+	  If unsure, say "N".
drivers/scst/scst_local/Makefile new file +2 -0
new file mode 100644
index 0000000..8cbbbff
@@ -0,0 +1,2 @@
+obj-$(CONFIG_SCST_LOCAL) += scst_local.o
+
drivers/scst/scst_local/scst_local.c new file +1471 -0

1,471 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

On Monday 20

drivers/scst/scst_local/scst_local.c line 54

Quoted 2 lines
drivers/scst/scst_local/scst_local.c new file +2 -0
+#define TRUE 1
+#define FALSE 0

can't you use 'true' or 'false'?
.. snip..

drivers/scst/scst_local/scst_local.c line 144

Quoted 13 lines
drivers/scst/scst_local/scst_local.c new file +13 -0
+static int scst_local_get_sas_transport_id(struct scst_local_sess *sess,
+	uint8_t **transport_id, int *len)
+{
+	int res = 0;
+	int tr_id_size = 0;
+	uint8_t *tr_id = NULL;
+
+	tr_id_size = 24;  /* A SAS TransportID */
+
+	tr_id = kzalloc(tr_id_size, GFP_KERNEL);
+	if (tr_id == NULL) {
+		PRINT_ERROR("Allocation of TransportID (size %d) failed",
+			tr_id_size);

pr_err? Or is this based on a module parameter?

drivers/scst/scst_local/scst_local.c line 149

Quoted 5 lines
drivers/scst/scst_local/scst_local.c new file +5 -0
+		res = -ENOMEM;
+		goto out;
+	}
+
+	tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;

Hmm, why the 0x00? Can't you just do an assigment?

#2 lore raw
Quoted 5 lines · Konrad Rzeszutek Wilk

On Monday 20

drivers/scst/scst_local/scst_local.c line 54

Quoted 2 lines
drivers/scst/scst_local/scst_local.c new file +2 -0
+#define TRUE 1
+#define FALSE 0

can't you use 'true' or 'false'?

When I first wrote that I did not know if those symbols were available. Probably better to change them now that I know it is.

Quoted 16 lines

.. snip..

drivers/scst/scst_local/scst_local.c line 144

Quoted 13 lines
drivers/scst/scst_local/scst_local.c new file +13 -0
+static int scst_local_get_sas_transport_id(struct scst_local_sess *sess,
+     uint8_t **transport_id, int *len)
+{
+     int res = 0;
+     int tr_id_size = 0;
+     uint8_t *tr_id = NULL;
+
+     tr_id_size = 24;  /* A SAS TransportID */
+
+     tr_id = kzalloc(tr_id_size, GFP_KERNEL);
+     if (tr_id == NULL) {
+             PRINT_ERROR("Allocation of TransportID (size %d) failed",
+                     tr_id_size);

pr_err? Or is this based on a module parameter?

PRINT_ERROR is an SCST macro ... will have to let Bart or Vlad answer that one.

Quoted 7 lines
Quoted 5 lines

+             res = -ENOMEM;
+             goto out;
+     }
+
+     tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;

Hmm, why the 0x00? Can't you just do an assigment?

Yes, that would be better.

Thanks for your feedback.

Signature · 6 lines
Regards,
Richard Sharpe
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author Acked-by
#3 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 6 lines · Konrad Rzeszutek Wilk

On Monday 20

Review

Quoted 2 lines
(quoted diff) +2 -0
+#define TRUE 1
+#define FALSE 0

can't you use 'true' or 'false'?
.. snip..

Quoted 15 lines

Review

Quoted 13 lines
(quoted diff) +13 -0
+static int scst_local_get_sas_transport_id(struct scst_local_sess *sess,
+     uint8_t **transport_id, int *len)
+{
+     int res = 0;
+     int tr_id_size = 0;
+     uint8_t *tr_id = NULL;
+
+     tr_id_size = 24;  /* A SAS TransportID */
+
+     tr_id = kzalloc(tr_id_size, GFP_KERNEL);
+     if (tr_id == NULL) {
+             PRINT_ERROR("Allocation of TransportID (size %d) failed",
+                     tr_id_size);

pr_err? Or is this based on a module parameter?

The macro PRINT_ERROR() has been defined in the header file include/scst/scst_debug.h. For this macro and also for related macros (e.g. TRACE_DBG()) the user can configure via debugfs whether or not PID, function name and/or line number should be included in the generated messages.

Quoted 7 lines
Quoted 5 lines

+             res = -ENOMEM;
+             goto out;
+     }
+
+     tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;

Hmm, why the 0x00? Can't you just do an assigment?

If I do not receive further feedback, I will queue the patch below:

[SCSI] scst_local: Clean up source code

Use true and false instead of TRUE and FALSE and remove one occurrence of "0x00 |".

(quoted diff) +0 -0

b/drivers/scst/scst_local/scst_local.c
index a3804cb..4a20e40 100644

drivers/scst/scst_local/scst_local.c +0 -3
@@ -50,9 +50,6 @@
 static unsigned long scst_local_trace_flag = SCST_LOCAL_DEFAULT_LOG_FLAGS;
 #endif
 
-#define TRUE 1
-#define FALSE 0
-
 #define SCST_LOCAL_VERSION "1.0.0"
 #define SCST_LOCAL_VERSION_DATE "20100910"
 
@@ -147,7 +144,7 @@ static int scst_local_get_sas_transport_id(struct

scst_local_sess *sess,
goto out;
}

- tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;
+ tr_id[0] = SCSI_TRANSPORTID_PROTOCOLID_SAS;

/*
* Assemble a valid SAS address = 0x5OOUUIIR12345678 ... Does SCST
@@ -664,7 +661,7 @@ static int scst_local_abort(struct scsi_cmnd *SCpnt)
sess = to_scst_lcl_sess(scsi_get_device(SCpnt->device->host));

ret = scst_rx_mgmt_fn_tag(sess->scst_sess, SCST_ABORT_TASK, SCpnt->tag,
- FALSE, &dev_reset_completion);
+ false, &dev_reset_completion);

/* Now wait for the completion ... */ wait_for_completion_interruptible(&dev_reset_completion);
@@ -688,7 +685,7 @@ static int scst_local_device_reset(struct scsi_cmnd *SCpnt)
lun = cpu_to_be16(SCpnt->device->lun);

ret = scst_rx_mgmt_fn_lun(sess->scst_sess, SCST_LUN_RESET,
- (const uint8_t *)&lun, sizeof(lun), FALSE,
+ (const uint8_t *)&lun, sizeof(lun), false,
&dev_reset_completion);

/* Now wait for the completion ... */
@@ -713,7 +710,7 @@ static int scst_local_target_reset(struct scsi_cmnd *SCpnt)
lun = cpu_to_be16(SCpnt->device->lun);

ret = scst_rx_mgmt_fn_lun(sess->scst_sess, SCST_TARGET_RESET,
- (const uint8_t *)&lun, sizeof(lun), FALSE,
+ (const uint8_t *)&lun, sizeof(lun), false,
&dev_reset_completion);

/* Now wait for the completion ... */
@@ -795,7 +792,7 @@ static int scst_local_queuecommand(struct Scsi_Host *SChost,
*/
lun = cpu_to_be16(SCpnt->device->lun);
scst_cmd = scst_rx_cmd(sess->scst_sess, (const uint8_t *)&lun,
- sizeof(lun), SCpnt->cmnd, SCpnt->cmd_len, TRUE);
+ sizeof(lun), SCpnt->cmnd, SCpnt->cmd_len, true);
if (!scst_cmd) {
PRINT_ERROR("%s", "scst_rx_cmd() failed");
return -ENOMEM;
@@ -1214,7 +1211,7 @@ static void scst_local_release_adapter(struct device *dev)

cancel_work_sync(&sess->aen_work);

- scst_unregister_session(sess->scst_sess, TRUE, NULL);
+ scst_unregister_session(sess->scst_sess, true, NULL);

kfree(sess);

@@ -1292,7 +1289,7 @@ unregister_dev:
device_unregister(&sess->dev);

unregister_session:
- scst_unregister_session(sess->scst_sess, TRUE, NULL);
+ scst_unregister_session(sess->scst_sess, true, NULL);

out_free:
kfree(sess);
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 7 lines
Quoted 1 line

pr_err? Or is this based on a module parameter?

The macro PRINT_ERROR() has been defined in the header file include/scst/scst_debug.h. For this macro and also for related macros (e.g. TRACE_DBG()) the user can configure via debugfs whether or not PID, function name and/or line number should be included in the generated messages.

Hmm, at one hand that is neat, but at other I am wondering if it would be better to use CONFIG_DYNAMIC_PRINTK functionality (which is what pr_debug could be used for) - which is a more generic framework for this.

Some of these errors look relevant to the user so perhaps going through the debugfs is not proper? Or is it that there are just soo many of them that it is unclear whcih ones would be releveant?

Quoted 10 lines
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+             res = -ENOMEM;
+             goto out;
+     }
+
+     tr_id[0] = 0x00 | SCSI_TRANSPORTID_PROTOCOLID_SAS;

Hmm, why the 0x00? Can't you just do an assigment?

If I do not receive further feedback, I will queue the patch below:

ok.

#5 lore raw
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 7 lines
Quoted 1 line

pr_err? Or is this based on a module parameter?

The macro PRINT_ERROR() has been defined in the header file include/scst/scst_debug.h. For this macro and also for related macros (e.g. TRACE_DBG()) the user can configure via debugfs whether or not PID, function name and/or line number should be included in the generated messages.

Hmm, at one hand that is neat, but at other I am wondering if it would be better to use CONFIG_DYNAMIC_PRINTK functionality (which is what pr_debug could be used for) - which is a more generic framework for this.

(resending as plain text)

Hello Konrad,

As far as I can see CONFIG_DYNAMIC_PRINTK was introduced in kernel 2.6.28 but has been renamed to CONFIG_DYNAMIC_DEBUG in 2.6.30 ? The dynamic debug framework comes close but does not provide all the functionality we need. While the macros in <scst/scst_debug.h> assign a class to each generated line of debug output, the macros in <linux/dynamic_debug.h> treat all generated debug lines equal. Yet while debugging it is very convenient to be able to enable only one class of debug statements and let all others disabled. The SCST macros and debugfs files allow to enable only a specific class of debug statements. A quote from dynamic-debug-howto.txt:

<quote>
Dynamic debug is designed to allow you to dynamically enable/disable kernel code to obtain additional kernel information. Currently, if CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_debug() calls can be dynamically enabled per-callsite.

Dynamic debug has even more useful features:

 * Simple query language allows turning on and off debugging statements by matching any combination of:

   - source filename
   - function name
   - line number (including ranges of line numbers)
   - module name
   - format string

 * Provides a debugfs control file: <debugfs>/dynamic_debug/ control which can be
   read to display the complete list of known debug statements, to help guide you
</quote>

Quoted 3 lines

Some of these errors look relevant to the user so perhaps going through the debugfs is not proper? Or is it that there are just so many of them that it is unclear which ones would be relevant?

Messages generated by one of the PRINT_*() macros also go to the kernel log when the kernel has been built with CONFIG_SCST_DEBUG=n while messages generated via one of the TRACE_*() macros only go to the kernel log if the kernel has been built with CONFIG_SCST_DEBUG=y and the corresponding class has been enabled via debugfs.

Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html