scsi: target: Have drivers report if they support direct submissions
authorMike Christie <michael.christie@oracle.com>
Thu, 28 Sep 2023 02:09:01 +0000 (21:09 -0500)
committerMartin K. Petersen <martin.petersen@oracle.com>
Fri, 13 Oct 2023 19:53:57 +0000 (15:53 -0400)
In some cases, like with multiple LUN targets or where the target has to
respond to transport level requests from the receiving context it can be
better to defer cmd submission to a helper thread. If the backend driver
blocks on something like request/tag allocation it can block the entire
target submission path and other LUs and transport IO on that session.

In other cases like single LUN targets with storage that can support all
the commands that the target can queue, then it's best to submit the cmd
to the backend from the target's cmd receiving context.

Subsequent commits will allow the user to config what they prefer, but
drivers like loop can't directly submit because they can be called from a
context that can't sleep. And, drivers like vhost-scsi can support direct
submission, but need to keep their default behavior of deferring execution
to avoid possible regressions where the backend can block.

Make the drivers tell LIO core if they support direct submissions and their
current default, so we can prevent users from misconfiguring the system and
initialize devices correctly.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20230928020907.5730-2-michael.christie@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
13 files changed:
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/scsi/elx/efct/efct_lio.c
drivers/scsi/ibmvscsi_tgt/ibmvscsi_tgt.c
drivers/scsi/qla2xxx/tcm_qla2xxx.c
drivers/target/iscsi/iscsi_target_configfs.c
drivers/target/loopback/tcm_loop.c
drivers/target/sbp/sbp_target.c
drivers/target/tcm_fc/tfc_conf.c
drivers/usb/gadget/function/f_tcm.c
drivers/vhost/scsi.c
drivers/xen/xen-scsiback.c
include/target/target_core_base.h
include/target/target_core_fabric.h

index c12005eab14c1981866864e02513cec8117ab390..58f70cfec45a72abd8df2ba88098a92f7fcacb4a 100644 (file)
@@ -3867,6 +3867,9 @@ static const struct target_core_fabric_ops srpt_template = {
        .tfc_discovery_attrs            = srpt_da_attrs,
        .tfc_wwn_attrs                  = srpt_wwn_attrs,
        .tfc_tpg_attrib_attrs           = srpt_tpg_attrib_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 /**
index a982b9cf9870174f63e7963f54e4eb560ad6843e..6a6ec32c46bdf3a1d532e988a6c98e7fc13f6a6e 100644 (file)
@@ -1611,6 +1611,8 @@ static const struct target_core_fabric_ops efct_lio_ops = {
        .sess_get_initiator_sid         = NULL,
        .tfc_tpg_base_attrs             = efct_lio_tpg_attrs,
        .tfc_tpg_attrib_attrs           = efct_lio_tpg_attrib_attrs,
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static const struct target_core_fabric_ops efct_lio_npiv_ops = {
@@ -1646,6 +1648,9 @@ static const struct target_core_fabric_ops efct_lio_npiv_ops = {
        .sess_get_initiator_sid         = NULL,
        .tfc_tpg_base_attrs             = efct_lio_npiv_tpg_attrs,
        .tfc_tpg_attrib_attrs           = efct_lio_npiv_tpg_attrib_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 int efct_scsi_tgt_driver_init(void)
index 385f812b8793c26ef3321df602b28f6123f401e9..4dc411a58107010dca5ddb73e54ebc231c679631 100644 (file)
@@ -3975,6 +3975,9 @@ static const struct target_core_fabric_ops ibmvscsis_ops = {
        .fabric_drop_tpg                = ibmvscsis_drop_tpg,
 
        .tfc_wwn_attrs                  = ibmvscsis_wwn_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static void ibmvscsis_dev_release(struct device *dev) {};
index 3b5ba4b47b3b2717708b64f6e85fec986513070a..796cea463cfdff7023f16037146ca0b6aa4d60da 100644 (file)
@@ -1822,6 +1822,9 @@ static const struct target_core_fabric_ops tcm_qla2xxx_ops = {
        .tfc_wwn_attrs                  = tcm_qla2xxx_wwn_attrs,
        .tfc_tpg_base_attrs             = tcm_qla2xxx_tpg_attrs,
        .tfc_tpg_attrib_attrs           = tcm_qla2xxx_tpg_attrib_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
@@ -1859,6 +1862,9 @@ static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
        .fabric_init_nodeacl            = tcm_qla2xxx_init_nodeacl,
 
        .tfc_wwn_attrs                  = tcm_qla2xxx_wwn_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static int tcm_qla2xxx_register_configfs(void)
index bf190dcb9eee2077dbafcd6260016271d3cc90bf..88db94f382bb926d6edbba4f7ca5abbdadb6d70c 100644 (file)
@@ -1590,4 +1590,7 @@ const struct target_core_fabric_ops iscsi_ops = {
        .tfc_tpg_nacl_param_attrs       = lio_target_nacl_param_attrs,
 
        .write_pending_must_be_called   = 1,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
index 4ec99a55ac305a4829e894030226dacb404b0d2d..fbacccdd2ff68500578d758581bd2f01ba52e7ab 100644 (file)
@@ -1102,6 +1102,8 @@ static const struct target_core_fabric_ops loop_ops = {
        .tfc_wwn_attrs                  = tcm_loop_wwn_attrs,
        .tfc_tpg_base_attrs             = tcm_loop_tpg_attrs,
        .tfc_tpg_attrib_attrs           = tcm_loop_tpg_attrib_attrs,
+       .default_submit_type            = TARGET_QUEUE_SUBMIT,
+       .direct_submit_supp             = 0,
 };
 
 static int __init tcm_loop_fabric_init(void)
index 2a761bc09193894e9f4a0eaf5c363e251212d58d..b604fcae21e1125bc6d1a7767f1072ef9ce9dc3c 100644 (file)
@@ -2278,6 +2278,9 @@ static const struct target_core_fabric_ops sbp_ops = {
        .tfc_wwn_attrs                  = sbp_wwn_attrs,
        .tfc_tpg_base_attrs             = sbp_tpg_base_attrs,
        .tfc_tpg_attrib_attrs           = sbp_tpg_attrib_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static int __init sbp_init(void)
index 6ac3fc1a7d39bba8478bbdb1e00a27dafb44c46f..5ee03d1cba2bee5fbe04b0ba8122cf5ac4513dff 100644 (file)
@@ -432,6 +432,9 @@ static const struct target_core_fabric_ops ft_fabric_ops = {
 
        .tfc_wwn_attrs                  = ft_wwn_attrs,
        .tfc_tpg_nacl_base_attrs        = ft_nacl_base_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static struct notifier_block ft_notifier = {
index 79ed2e6e576aab74b4eadb18201fe483f3e5478d..ff33f31bcdf64591211f79028d6828e50097e8fa 100644 (file)
@@ -1687,6 +1687,9 @@ static const struct target_core_fabric_ops usbg_ops = {
 
        .tfc_wwn_attrs                  = usbg_wwn_attrs,
        .tfc_tpg_base_attrs             = usbg_base_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 /* Start gadget.c code */
index abef0619c7901af0f36232a558e46a1b1dbf16ae..dc274463bdf0273b8cb239004033a1aefd46e28e 100644 (file)
@@ -2598,6 +2598,9 @@ static const struct target_core_fabric_ops vhost_scsi_ops = {
        .tfc_wwn_attrs                  = vhost_scsi_wwn_attrs,
        .tfc_tpg_base_attrs             = vhost_scsi_tpg_attrs,
        .tfc_tpg_attrib_attrs           = vhost_scsi_tpg_attrib_attrs,
+
+       .default_submit_type            = TARGET_QUEUE_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static int __init vhost_scsi_init(void)
index 8b77e4c06e43f8c28b1605f752c7bf208a31950b..0c51edfd13dcdfbb12c988c63c78cd85ea0b086d 100644 (file)
@@ -1832,6 +1832,9 @@ static const struct target_core_fabric_ops scsiback_ops = {
        .tfc_wwn_attrs                  = scsiback_wwn_attrs,
        .tfc_tpg_base_attrs             = scsiback_tpg_attrs,
        .tfc_tpg_param_attrs            = scsiback_param_attrs,
+
+       .default_submit_type            = TARGET_DIRECT_SUBMIT,
+       .direct_submit_supp             = 1,
 };
 
 static const struct xenbus_device_id scsiback_ids[] = {
index 159567359bbb0fea21d1ee0576fbeaca13331647..401abdf8a9ef5b1828d1433ccc8f6e55085ecf4d 100644 (file)
 #define SE_MODE_PAGE_BUF                       512
 #define SE_SENSE_BUF                           96
 
+enum target_submit_type {
+       /* Use the fabric driver's default submission type */
+       TARGET_FABRIC_DEFAULT_SUBMIT,
+       /* Submit from the calling context */
+       TARGET_DIRECT_SUBMIT,
+       /* Defer submission to the LIO workqueue */
+       TARGET_QUEUE_SUBMIT,
+};
+
 /* struct se_hba->hba_flags */
 enum hba_flags_table {
        HBA_FLAGS_INTERNAL_USE  = 0x01,
index 2a6c4c935666aaf212df3a61757e274c4c4b4fef..dcd7d76d2f3010c7a0dba16a4fad5c871ae7f4d4 100644 (file)
@@ -118,6 +118,15 @@ struct target_core_fabric_ops {
         * its entirety before a command is aborted.
         */
        unsigned int write_pending_must_be_called:1;
+       /*
+        * Set this if the driver supports submitting commands to the backend
+        * from target_submit/target_submit_cmd.
+        */
+       unsigned int direct_submit_supp:1;
+       /*
+        * Set this to a target_submit_type value.
+        */
+       u8 default_submit_type;
 };
 
 int target_register_template(const struct target_core_fabric_ops *fo);