aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target/iscsi
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2012-04-03 18:51:22 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-04-14 20:40:37 -0400
commitd28b11692e6ec577cec70606d793e14843124a03 (patch)
treedd16687e7bec2f24a026231ac3f7b73352e06e60 /drivers/target/iscsi
parentb16a35b050e70c8376250b563785e3038c4b6393 (diff)
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>
Diffstat (limited to 'drivers/target/iscsi')
-rw-r--r--drivers/target/iscsi/iscsi_target.c106
-rw-r--r--drivers/target/iscsi/iscsi_target_util.c123
-rw-r--r--drivers/target/iscsi/iscsi_target_util.h2
3 files changed, 101 insertions, 130 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index d68363a79db7..57cef3b44c36 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -27,8 +27,10 @@
27#include <asm/unaligned.h> 27#include <asm/unaligned.h>
28#include <scsi/scsi_device.h> 28#include <scsi/scsi_device.h>
29#include <scsi/iscsi_proto.h> 29#include <scsi/iscsi_proto.h>
30#include <scsi/scsi_tcq.h>
30#include <target/target_core_base.h> 31#include <target/target_core_base.h>
31#include <target/target_core_fabric.h> 32#include <target/target_core_fabric.h>
33#include <target/target_core_configfs.h>
32 34
33#include "iscsi_target_core.h" 35#include "iscsi_target_core.h"
34#include "iscsi_target_parameters.h" 36#include "iscsi_target_parameters.h"
@@ -842,6 +844,8 @@ static int iscsit_handle_scsi_cmd(
842 int dump_immediate_data = 0, send_check_condition = 0, payload_length; 844 int dump_immediate_data = 0, send_check_condition = 0, payload_length;
843 struct iscsi_cmd *cmd = NULL; 845 struct iscsi_cmd *cmd = NULL;
844 struct iscsi_scsi_req *hdr; 846 struct iscsi_scsi_req *hdr;
847 int iscsi_task_attr;
848 int sam_task_attr;
845 849
846 spin_lock_bh(&conn->sess->session_stats_lock); 850 spin_lock_bh(&conn->sess->session_stats_lock);
847 conn->sess->cmd_pdus++; 851 conn->sess->cmd_pdus++;
@@ -958,11 +962,38 @@ done:
958 (hdr->flags & ISCSI_FLAG_CMD_READ) ? DMA_FROM_DEVICE : 962 (hdr->flags & ISCSI_FLAG_CMD_READ) ? DMA_FROM_DEVICE :
959 DMA_NONE; 963 DMA_NONE;
960 964
961 cmd = iscsit_allocate_se_cmd(conn, hdr->data_length, data_direction, 965 cmd = iscsit_allocate_cmd(conn, GFP_KERNEL);
962 (hdr->flags & ISCSI_FLAG_CMD_ATTR_MASK));
963 if (!cmd) 966 if (!cmd)
964 return iscsit_add_reject(ISCSI_REASON_BOOKMARK_NO_RESOURCES, 1, 967 return iscsit_add_reject(ISCSI_REASON_BOOKMARK_NO_RESOURCES, 1,
965 buf, conn); 968 buf, conn);
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]);
966 997
967 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," 998 pr_debug("Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x,"
968 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt, 999 " ExpXferLen: %u, Length: %u, CID: %hu\n", hdr->itt,
@@ -1718,10 +1749,75 @@ static int iscsit_handle_task_mgt_cmd(
1718 (hdr->refcmdsn != ISCSI_RESERVED_TAG)) 1749 (hdr->refcmdsn != ISCSI_RESERVED_TAG))
1719 hdr->refcmdsn = ISCSI_RESERVED_TAG; 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 if (!cmd) 1753 if (!cmd)
1723 return iscsit_add_reject(ISCSI_REASON_BOOKMARK_NO_RESOURCES, 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 cmd->iscsi_opcode = ISCSI_OP_SCSI_TMFUNC; 1822 cmd->iscsi_opcode = ISCSI_OP_SCSI_TMFUNC;
1727 cmd->i_state = ISTATE_SEND_TASKMGTRSP; 1823 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c
index 89cb91e2ffe8..66a6e9ba86fe 100644
--- a/drivers/target/iscsi/iscsi_target_util.c
+++ b/drivers/target/iscsi/iscsi_target_util.c
@@ -176,129 +176,6 @@ struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *conn, gfp_t gfp_mask)
176 return cmd; 176 return cmd;
177} 177}
178 178
179/*
180 * Called from iscsi_handle_scsi_cmd()
181 */
182struct 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
226struct 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;
297out:
298 iscsit_release_cmd(cmd);
299 return NULL;
300}
301
302int iscsit_decide_list_to_build( 179int iscsit_decide_list_to_build(
303 struct iscsi_cmd *cmd, 180 struct iscsi_cmd *cmd,
304 u32 immediate_data_length) 181 u32 immediate_data_length)
diff --git a/drivers/target/iscsi/iscsi_target_util.h b/drivers/target/iscsi/iscsi_target_util.h
index 835bf7de0281..df8dbddc6e78 100644
--- a/drivers/target/iscsi/iscsi_target_util.h
+++ b/drivers/target/iscsi/iscsi_target_util.h
@@ -9,8 +9,6 @@ extern struct iscsi_r2t *iscsit_get_r2t_from_list(struct iscsi_cmd *);
9extern void iscsit_free_r2t(struct iscsi_r2t *, struct iscsi_cmd *); 9extern void iscsit_free_r2t(struct iscsi_r2t *, struct iscsi_cmd *);
10extern void iscsit_free_r2ts_from_list(struct iscsi_cmd *); 10extern void iscsit_free_r2ts_from_list(struct iscsi_cmd *);
11extern struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *, gfp_t); 11extern struct iscsi_cmd *iscsit_allocate_cmd(struct iscsi_conn *, gfp_t);
12extern struct iscsi_cmd *iscsit_allocate_se_cmd(struct iscsi_conn *, u32, int, int);
13extern struct iscsi_cmd *iscsit_allocate_se_cmd_for_tmr(struct iscsi_conn *, u8);
14extern int iscsit_decide_list_to_build(struct iscsi_cmd *, u32); 12extern int iscsit_decide_list_to_build(struct iscsi_cmd *, u32);
15extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsi_cmd *, u32); 13extern struct iscsi_seq *iscsit_get_seq_holder_for_datain(struct iscsi_cmd *, u32);
16extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsi_cmd *); 14extern struct iscsi_seq *iscsit_get_seq_holder_for_r2t(struct iscsi_cmd *);