Commit d28b11692e6ec577cec70606d793e14843124a03

Authored by Andy Grover
Committed by Nicholas Bellinger
1 parent b16a35b050

target/iscsi: Inline iscsit_allocate_se_cmd and *_for_tmr

Trying to move a bunch of stuff around so iscsi can use target_submit_cmd
someday, and so stuff needs to be in that function directly instead of
hidden, so it can be reordered etc.

Signed-off-by: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

Showing 3 changed files with 101 additions and 130 deletions Side-by-side Diff

drivers/target/iscsi/iscsi_target.c
... ... @@ -27,8 +27,10 @@
27 27 #include <asm/unaligned.h>
28 28 #include <scsi/scsi_device.h>
29 29 #include <scsi/iscsi_proto.h>
  30 +#include <scsi/scsi_tcq.h>
30 31 #include <target/target_core_base.h>
31 32 #include <target/target_core_fabric.h>
  33 +#include <target/target_core_configfs.h>
32 34  
33 35 #include "iscsi_target_core.h"
34 36 #include "iscsi_target_parameters.h"
... ... @@ -842,6 +844,8 @@
842 844 int dump_immediate_data = 0, send_check_condition = 0, payload_length;
843 845 struct iscsi_cmd *cmd = NULL;
844 846 struct iscsi_scsi_req *hdr;
  847 + int iscsi_task_attr;
  848 + int sam_task_attr;
845 849  
846 850 spin_lock_bh(&conn->sess->session_stats_lock);
847 851 conn->sess->cmd_pdus++;
848 852  
849 853  
... ... @@ -958,12 +962,39 @@
958 962 (hdr->flags & ISCSI_FLAG_CMD_READ) ? DMA_FROM_DEVICE :
959 963 DMA_NONE;
960 964  
961   - cmd = iscsit_allocate_se_cmd(conn, hdr->data_length, data_direction,
962   - (hdr->flags & ISCSI_FLAG_CMD_ATTR_MASK));
  965 + cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
963 966 if (!cmd)
964 967 return iscsit_add_reject(ISCSI_REASON_BOOKMARK_NO_RESOURCES, 1,
965   - buf, conn);
  968 + buf, conn);
966 969  
  970 + cmd->data_direction = data_direction;
  971 + cmd->data_length = hdr->data_length;
  972 + iscsi_task_attr = hdr->flags & ISCSI_FLAG_CMD_ATTR_MASK;
  973 + /*
  974 + * Figure out the SAM Task Attribute for the incoming SCSI CDB
  975 + */
  976 + if ((iscsi_task_attr == ISCSI_ATTR_UNTAGGED) ||
  977 + (iscsi_task_attr == ISCSI_ATTR_SIMPLE))
  978 + sam_task_attr = MSG_SIMPLE_TAG;
  979 + else if (iscsi_task_attr == ISCSI_ATTR_ORDERED)
  980 + sam_task_attr = MSG_ORDERED_TAG;
  981 + else if (iscsi_task_attr == ISCSI_ATTR_HEAD_OF_QUEUE)
  982 + sam_task_attr = MSG_HEAD_TAG;
  983 + else if (iscsi_task_attr == ISCSI_ATTR_ACA)
  984 + sam_task_attr = MSG_ACA_TAG;
  985 + else {
  986 + pr_debug("Unknown iSCSI Task Attribute: 0x%02x, using"
  987 + " MSG_SIMPLE_TAG\n", iscsi_task_attr);
  988 + sam_task_attr = MSG_SIMPLE_TAG;
  989 + }
  990 +
  991 + /*
  992 + * Initialize struct se_cmd descriptor from target_core_mod infrastructure
  993 + */
  994 + transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops,
  995 + conn->sess->se_sess, cmd->data_length, cmd->data_direction,
  996 + sam_task_attr, &cmd->sense_buffer[0]);
  997 +
967 998 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
968 999 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
969 1000 hdr->cmdsn, hdr->data_length, payload_length, conn->cid);
970 1001  
... ... @@ -1718,10 +1749,75 @@
1718 1749 (hdr->refcmdsn != ISCSI_RESERVED_TAG))
1719 1750 hdr->refcmdsn = ISCSI_RESERVED_TAG;
1720 1751  
1721   - cmd = iscsit_allocate_se_cmd_for_tmr(conn, function);
  1752 + cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
1722 1753 if (!cmd)
1723 1754 return iscsit_add_reject(ISCSI_REASON_BOOKMARK_NO_RESOURCES,
1724   - 1, buf, conn);
  1755 + 1, buf, conn);
  1756 +
  1757 + cmd->data_direction = DMA_NONE;
  1758 +
  1759 + cmd->tmr_req = kzalloc(sizeof(struct iscsi_tmr_req), GFP_KERNEL);
  1760 + if (!cmd->tmr_req) {
  1761 + pr_err("Unable to allocate memory for"
  1762 + " Task Management command!\n");
  1763 + return iscsit_add_reject_from_cmd(
  1764 + ISCSI_REASON_BOOKMARK_NO_RESOURCES,
  1765 + 1, 1, buf, cmd);
  1766 + }
  1767 +
  1768 + /*
  1769 + * TASK_REASSIGN for ERL=2 / connection stays inside of
  1770 + * LIO-Target $FABRIC_MOD
  1771 + */
  1772 + if (function != ISCSI_TM_FUNC_TASK_REASSIGN) {
  1773 +
  1774 + u8 tcm_function;
  1775 + int ret;
  1776 +
  1777 + transport_init_se_cmd(&cmd->se_cmd,
  1778 + &lio_target_fabric_configfs->tf_ops,
  1779 + conn->sess->se_sess, 0, DMA_NONE,
  1780 + MSG_SIMPLE_TAG, &cmd->sense_buffer[0]);
  1781 +
  1782 + switch (function) {
  1783 + case ISCSI_TM_FUNC_ABORT_TASK:
  1784 + tcm_function = TMR_ABORT_TASK;
  1785 + break;
  1786 + case ISCSI_TM_FUNC_ABORT_TASK_SET:
  1787 + tcm_function = TMR_ABORT_TASK_SET;
  1788 + break;
  1789 + case ISCSI_TM_FUNC_CLEAR_ACA:
  1790 + tcm_function = TMR_CLEAR_ACA;
  1791 + break;
  1792 + case ISCSI_TM_FUNC_CLEAR_TASK_SET:
  1793 + tcm_function = TMR_CLEAR_TASK_SET;
  1794 + break;
  1795 + case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET:
  1796 + tcm_function = TMR_LUN_RESET;
  1797 + break;
  1798 + case ISCSI_TM_FUNC_TARGET_WARM_RESET:
  1799 + tcm_function = TMR_TARGET_WARM_RESET;
  1800 + break;
  1801 + case ISCSI_TM_FUNC_TARGET_COLD_RESET:
  1802 + tcm_function = TMR_TARGET_COLD_RESET;
  1803 + break;
  1804 + default:
  1805 + pr_err("Unknown iSCSI TMR Function:"
  1806 + " 0x%02x\n", function);
  1807 + return iscsit_add_reject_from_cmd(
  1808 + ISCSI_REASON_BOOKMARK_NO_RESOURCES,
  1809 + 1, 1, buf, cmd);
  1810 + }
  1811 +
  1812 + ret = core_tmr_alloc_req(&cmd->se_cmd, cmd->tmr_req,
  1813 + tcm_function, GFP_KERNEL);
  1814 + if (ret < 0)
  1815 + return iscsit_add_reject_from_cmd(
  1816 + ISCSI_REASON_BOOKMARK_NO_RESOURCES,
  1817 + 1, 1, buf, cmd);
  1818 +
  1819 + cmd->tmr_req->se_tmr_req = cmd->se_cmd.se_tmr_req;
  1820 + }
1725 1821  
1726 1822 cmd->iscsi_opcode = ISCSI_OP_SCSI_TMFUNC;
1727 1823 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
drivers/target/iscsi/iscsi_target_util.c
... ... @@ -176,129 +176,6 @@
176 176 return cmd;
177 177 }
178 178  
179   -/*
180   - * Called from iscsi_handle_scsi_cmd()
181   - */
182   -struct iscsi_cmd *iscsit_allocate_se_cmd(
183   - struct iscsi_conn *conn,
184   - u32 data_length,
185   - int data_direction,
186   - int iscsi_task_attr)
187   -{
188   - struct iscsi_cmd *cmd;
189   - struct se_cmd *se_cmd;
190   - int sam_task_attr;
191   -
192   - cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
193   - if (!cmd)
194   - return NULL;
195   -
196   - cmd->data_direction = data_direction;
197   - cmd->data_length = data_length;
198   - /*
199   - * Figure out the SAM Task Attribute for the incoming SCSI CDB
200   - */
201   - if ((iscsi_task_attr == ISCSI_ATTR_UNTAGGED) ||
202   - (iscsi_task_attr == ISCSI_ATTR_SIMPLE))
203   - sam_task_attr = MSG_SIMPLE_TAG;
204   - else if (iscsi_task_attr == ISCSI_ATTR_ORDERED)
205   - sam_task_attr = MSG_ORDERED_TAG;
206   - else if (iscsi_task_attr == ISCSI_ATTR_HEAD_OF_QUEUE)
207   - sam_task_attr = MSG_HEAD_TAG;
208   - else if (iscsi_task_attr == ISCSI_ATTR_ACA)
209   - sam_task_attr = MSG_ACA_TAG;
210   - else {
211   - pr_debug("Unknown iSCSI Task Attribute: 0x%02x, using"
212   - " MSG_SIMPLE_TAG\n", iscsi_task_attr);
213   - sam_task_attr = MSG_SIMPLE_TAG;
214   - }
215   -
216   - se_cmd = &cmd->se_cmd;
217   - /*
218   - * Initialize struct se_cmd descriptor from target_core_mod infrastructure
219   - */
220   - transport_init_se_cmd(se_cmd, &lio_target_fabric_configfs->tf_ops,
221   - conn->sess->se_sess, data_length, data_direction,
222   - sam_task_attr, &cmd->sense_buffer[0]);
223   - return cmd;
224   -}
225   -
226   -struct iscsi_cmd *iscsit_allocate_se_cmd_for_tmr(
227   - struct iscsi_conn *conn,
228   - u8 function)
229   -{
230   - struct iscsi_cmd *cmd;
231   - struct se_cmd *se_cmd;
232   - int rc;
233   - u8 tcm_function;
234   -
235   - cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
236   - if (!cmd)
237   - return NULL;
238   -
239   - cmd->data_direction = DMA_NONE;
240   -
241   - cmd->tmr_req = kzalloc(sizeof(struct iscsi_tmr_req), GFP_KERNEL);
242   - if (!cmd->tmr_req) {
243   - pr_err("Unable to allocate memory for"
244   - " Task Management command!\n");
245   - goto out;
246   - }
247   - /*
248   - * TASK_REASSIGN for ERL=2 / connection stays inside of
249   - * LIO-Target $FABRIC_MOD
250   - */
251   - if (function == ISCSI_TM_FUNC_TASK_REASSIGN)
252   - return cmd;
253   -
254   - se_cmd = &cmd->se_cmd;
255   - /*
256   - * Initialize struct se_cmd descriptor from target_core_mod infrastructure
257   - */
258   - transport_init_se_cmd(se_cmd, &lio_target_fabric_configfs->tf_ops,
259   - conn->sess->se_sess, 0, DMA_NONE,
260   - MSG_SIMPLE_TAG, &cmd->sense_buffer[0]);
261   -
262   - switch (function) {
263   - case ISCSI_TM_FUNC_ABORT_TASK:
264   - tcm_function = TMR_ABORT_TASK;
265   - break;
266   - case ISCSI_TM_FUNC_ABORT_TASK_SET:
267   - tcm_function = TMR_ABORT_TASK_SET;
268   - break;
269   - case ISCSI_TM_FUNC_CLEAR_ACA:
270   - tcm_function = TMR_CLEAR_ACA;
271   - break;
272   - case ISCSI_TM_FUNC_CLEAR_TASK_SET:
273   - tcm_function = TMR_CLEAR_TASK_SET;
274   - break;
275   - case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET:
276   - tcm_function = TMR_LUN_RESET;
277   - break;
278   - case ISCSI_TM_FUNC_TARGET_WARM_RESET:
279   - tcm_function = TMR_TARGET_WARM_RESET;
280   - break;
281   - case ISCSI_TM_FUNC_TARGET_COLD_RESET:
282   - tcm_function = TMR_TARGET_COLD_RESET;
283   - break;
284   - default:
285   - pr_err("Unknown iSCSI TMR Function:"
286   - " 0x%02x\n", function);
287   - goto out;
288   - }
289   -
290   - rc = core_tmr_alloc_req(se_cmd, cmd->tmr_req, tcm_function, GFP_KERNEL);
291   - if (rc < 0)
292   - goto out;
293   -
294   - cmd->tmr_req->se_tmr_req = se_cmd->se_tmr_req;
295   -
296   - return cmd;
297   -out:
298   - iscsit_release_cmd(cmd);
299   - return NULL;
300   -}
301   -
302 179 int iscsit_decide_list_to_build(
303 180 struct iscsi_cmd *cmd,
304 181 u32 immediate_data_length)
drivers/target/iscsi/iscsi_target_util.h
... ... @@ -9,8 +9,6 @@
9 9 extern void iscsit_free_r2t(struct iscsi_r2t *, struct iscsi_cmd *);
10 10 extern void iscsit_free_r2ts_from_list(struct iscsi_cmd *);
11 11 extern struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *, gfp_t);
12   -extern struct iscsi_cmd *iscsit_allocate_se_cmd(struct iscsi_conn *, u32, int, int);
13   -extern struct iscsi_cmd *iscsit_allocate_se_cmd_for_tmr(struct iscsi_conn *, u8);
14 12 extern int iscsit_decide_list_to_build(struct iscsi_cmd *, u32);
15 13 extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsi_cmd *, u32);
16 14 extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsi_cmd *);