]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
target: Add TARGET_SCF_LOOKUP_LUN_FROM_TAG support for ABORT_TASK
authorNicholas Bellinger <nab@linux-iscsi.org>
Sat, 3 Jun 2017 13:55:50 +0000 (06:55 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Fri, 7 Jul 2017 05:57:56 +0000 (22:57 -0700)
This patch introduces support in target_submit_tmr() for locating a
unpacked_lun from an existing se_cmd->tag during ABORT_TASK.

When TARGET_SCF_LOOKUP_LUN_FROM_TAG is set, target_submit_tmr()
will do the extra lookup via target_lookup_lun_from_tag() and
subsequently invoke transport_lookup_tmr_lun() so a proper
percpu se_lun->lun_ref is taken before workqueue dispatch into
se_device->tmr_wq happens.

Aside from the extra target_lookup_lun_from_tag(), the existing
code-path remains unchanged.

Reviewed-by: Himanshu Madhani <himanshu.madhani@cavium.com>
Reviewed-by: Quinn Tran <quinn.tran@cavium.com>
Cc: Mike Christie <mchristi@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_transport.c
include/target/target_core_base.h

index 97a01f48068bcd550e5b446c4b26217a760fa5c4..e045803921f875a716d45d84dc2eedd85bb8596c 100644 (file)
@@ -1594,6 +1594,29 @@ static void target_complete_tmr_failure(struct work_struct *work)
        transport_cmd_check_stop_to_fabric(se_cmd);
 }
 
+static bool target_lookup_lun_from_tag(struct se_session *se_sess, u64 tag,
+                                      u64 *unpacked_lun)
+{
+       struct se_cmd *se_cmd;
+       unsigned long flags;
+       bool ret = false;
+
+       spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
+       list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) {
+               if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
+                       continue;
+
+               if (se_cmd->tag == tag) {
+                       *unpacked_lun = se_cmd->orig_fe_lun;
+                       ret = true;
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
+
+       return ret;
+}
+
 /**
  * target_submit_tmr - lookup unpacked lun and submit uninitialized se_cmd
  *                     for TMR CDBs
@@ -1641,19 +1664,31 @@ int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess,
                core_tmr_release_req(se_cmd->se_tmr_req);
                return ret;
        }
+       /*
+        * If this is ABORT_TASK with no explicit fabric provided LUN,
+        * go ahead and search active session tags for a match to figure
+        * out unpacked_lun for the original se_cmd.
+        */
+       if (tm_type == TMR_ABORT_TASK && (flags & TARGET_SCF_LOOKUP_LUN_FROM_TAG)) {
+               if (!target_lookup_lun_from_tag(se_sess, tag, &unpacked_lun))
+                       goto failure;
+       }
 
        ret = transport_lookup_tmr_lun(se_cmd, unpacked_lun);
-       if (ret) {
-               /*
-                * For callback during failure handling, push this work off
-                * to process context with TMR_LUN_DOES_NOT_EXIST status.
-                */
-               INIT_WORK(&se_cmd->work, target_complete_tmr_failure);
-               schedule_work(&se_cmd->work);
-               return 0;
-       }
+       if (ret)
+               goto failure;
+
        transport_generic_handle_tmr(se_cmd);
        return 0;
+
+       /*
+        * For callback during failure handling, push this work off
+        * to process context with TMR_LUN_DOES_NOT_EXIST status.
+        */
+failure:
+       INIT_WORK(&se_cmd->work, target_complete_tmr_failure);
+       schedule_work(&se_cmd->work);
+       return 0;
 }
 EXPORT_SYMBOL(target_submit_tmr);
 
index 47d9f381209fccb703361c0edcaec59183cdf625..f835528e424e79cb63bb0f0afe45f8624079bbab 100644 (file)
@@ -188,7 +188,8 @@ enum target_sc_flags_table {
        TARGET_SCF_BIDI_OP              = 0x01,
        TARGET_SCF_ACK_KREF             = 0x02,
        TARGET_SCF_UNKNOWN_SIZE         = 0x04,
-       TARGET_SCF_USE_CPUID    = 0x08,
+       TARGET_SCF_USE_CPUID            = 0x08,
+       TARGET_SCF_LOOKUP_LUN_FROM_TAG  = 0x10,
 };
 
 /* fabric independent task management function values */