Lines Matching defs:task

136  * @task: scsi command task
146 void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t,
149 struct iscsi_conn *conn = task->conn;
152 task->hdr_len = sizeof(struct iscsi_data);
159 hdr->lun = task->lun;
160 hdr->itt = task->hdr_itt;
176 static int iscsi_add_hdr(struct iscsi_task *task, unsigned len)
178 unsigned exp_len = task->hdr_len + len;
180 if (exp_len > task->hdr_max) {
186 task->hdr_len = exp_len;
193 static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
195 struct scsi_cmnd *cmd = task->sc;
201 ecdb_ahdr = iscsi_next_hdr(task);
209 rc = iscsi_add_hdr(task, sizeof(ecdb_ahdr->ahslength) +
222 ISCSI_DBG_SESSION(task->conn->session,
226 task->hdr_len);
231 * iscsi_check_tmf_restrictions - check if a task is affected by TMF
232 * @task: iscsi task
235 * During TMF a task has to be checked if it's affected.
243 static int iscsi_check_tmf_restrictions(struct iscsi_task *task, int opcode)
245 struct iscsi_session *session = task->conn->session;
261 if (hdr_lun != task->sc->device->lun)
270 "task [op %x itt 0x%x/0x%x] rejected.\n",
271 opcode, task->itt, task->hdr_itt);
280 "task [op %x itt 0x%x/0x%x] fast abort.\n",
281 opcode, task->itt, task->hdr_itt);
287 * the caller has already checked if the task
293 task->hdr_itt == tmf->rtt) {
295 "Preventing task %x/%x from sending "
296 "data-out due to abort task in "
297 "progress\n", task->itt,
298 task->hdr_itt);
309 * @task: iscsi task
314 static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)
316 struct iscsi_conn *conn = task->conn;
318 struct scsi_cmnd *sc = task->sc;
324 rc = iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_CMD);
329 rc = conn->session->tt->alloc_pdu(task, ISCSI_OP_SCSI_CMD);
333 hdr = (struct iscsi_scsi_req *)task->hdr;
338 hdr->itt = task->hdr_itt = itt;
340 hdr->itt = task->hdr_itt = build_itt(task->itt,
341 task->conn->session->age);
342 task->hdr_len = 0;
343 rc = iscsi_add_hdr(task, sizeof(*hdr));
349 task->lun = hdr->lun;
355 rc = iscsi_prep_ecdb_ahs(task);
362 task->imm_count = 0;
364 task->protected = true;
369 struct iscsi_r2t_info *r2t = &task->unsol_r2t;
390 task->imm_count = min(session->first_burst,
393 task->imm_count = min(transfer_length,
395 hton24(hdr->dlength, task->imm_count);
402 task->imm_count;
403 r2t->data_offset = task->imm_count;
408 if (!task->unsol_r2t.data_length)
420 hdrlength = task->hdr_len - sizeof(*hdr);
427 hdr->cmdsn = task->cmdsn = cpu_to_be32(session->cmdsn);
429 if (session->tt->init_task && session->tt->init_task(task))
432 task->state = ISCSI_TASK_RUNNING;
440 task->itt, transfer_length,
447 * iscsi_free_task - free a task
448 * @task: iscsi cmd task
452 * up mgmt tasks then returns the task to the pool.
454 static void iscsi_free_task(struct iscsi_task *task)
456 struct iscsi_conn *conn = task->conn;
458 struct scsi_cmnd *sc = task->sc;
459 int oldstate = task->state;
461 ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n",
462 task->itt, task->state, task->sc);
464 session->tt->cleanup_task(task);
465 task->state = ISCSI_TASK_FREE;
466 task->sc = NULL;
468 * login task is preallocated so do not free
470 if (conn->login_task == task)
473 kfifo_in(&session->cmdpool.queue, (void*)&task, sizeof(void*));
477 iscsi_cmd(sc)->task = NULL;
479 * queue command may call this to free the task, so
487 bool iscsi_get_task(struct iscsi_task *task)
489 return refcount_inc_not_zero(&task->refcount);
494 * __iscsi_put_task - drop the refcount on a task
495 * @task: iscsi_task to drop the refcount on
497 * The back_lock must be held when calling in case it frees the task.
499 void __iscsi_put_task(struct iscsi_task *task)
501 if (refcount_dec_and_test(&task->refcount))
502 iscsi_free_task(task);
506 void iscsi_put_task(struct iscsi_task *task)
508 struct iscsi_session *session = task->conn->session;
510 if (refcount_dec_and_test(&task->refcount)) {
512 iscsi_free_task(task);
519 * iscsi_complete_task - finish a task
520 * @task: iscsi cmd task
521 * @state: state to complete task with
525 static void iscsi_complete_task(struct iscsi_task *task, int state)
527 struct iscsi_conn *conn = task->conn;
530 "complete task itt 0x%x state %d sc %p\n",
531 task->itt, task->state, task->sc);
532 if (task->state == ISCSI_TASK_COMPLETED ||
533 task->state == ISCSI_TASK_ABRT_TMF ||
534 task->state == ISCSI_TASK_ABRT_SESS_RECOV ||
535 task->state == ISCSI_TASK_REQUEUE_SCSIQ)
537 WARN_ON_ONCE(task->state == ISCSI_TASK_FREE);
538 task->state = state;
540 if (READ_ONCE(conn->ping_task) == task)
544 __iscsi_put_task(task);
548 * iscsi_complete_scsi_task - finish scsi task normally
549 * @task: iscsi task for scsi cmd
558 void iscsi_complete_scsi_task(struct iscsi_task *task,
561 struct iscsi_conn *conn = task->conn;
563 ISCSI_DBG_SESSION(conn->session, "[itt 0x%x]\n", task->itt);
567 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
574 static bool cleanup_queued_task(struct iscsi_task *task)
576 struct iscsi_conn *conn = task->conn;
581 * but have not yet taken the task off the requeue list, then a TMF or
584 if (task->state == ISCSI_TASK_COMPLETED)
587 if (!list_empty(&task->running)) {
588 list_del_init(&task->running);
593 if (task->state == ISCSI_TASK_RUNNING ||
594 task->state == ISCSI_TASK_COMPLETED)
595 __iscsi_put_task(task);
598 if (conn->session->running_aborted_task == task) {
600 __iscsi_put_task(task);
603 if (conn->task == task) {
604 conn->task = NULL;
605 __iscsi_put_task(task);
612 * session back and frwd lock must be held and if not called for a task that
615 static void __fail_scsi_task(struct iscsi_task *task, int err)
617 struct iscsi_conn *conn = task->conn;
621 if (cleanup_queued_task(task))
624 if (task->state == ISCSI_TASK_PENDING) {
637 sc = task->sc;
640 iscsi_complete_task(task, state);
643 static void fail_scsi_task(struct iscsi_task *task, int err)
645 struct iscsi_session *session = task->conn->session;
648 __fail_scsi_task(task, err);
653 struct iscsi_task *task)
656 struct iscsi_hdr *hdr = task->hdr;
685 if (session->tt->init_task && session->tt->init_task(task))
691 task->state = ISCSI_TASK_RUNNING;
694 hdr->itt, task->data_count);
699 * iscsi_alloc_mgmt_task - allocate and setup a mgmt task.
700 * @conn: iscsi conn that the task will be sent on.
711 struct iscsi_task *task;
722 * Same task can be used. Same ITT must be used.
727 "progress. Cannot start new task.\n");
732 iscsi_conn_printk(KERN_ERR, conn, "Invalid buffer len of %u for login task. Max len is %u\n", data_size, ISCSI_DEF_MAX_RECV_SEG_LEN);
736 task = conn->login_task;
750 (void*)&task, sizeof(void*)))
754 * released in complete pdu for task we expect a response for, and
755 * released by the lld when it has transmitted the task for
758 refcount_set(&task->refcount, 1);
759 task->conn = conn;
760 task->sc = NULL;
761 INIT_LIST_HEAD(&task->running);
762 task->state = ISCSI_TASK_PENDING;
765 memcpy(task->data, data, data_size);
766 task->data_count = data_size;
768 task->data_count = 0;
771 if (conn->session->tt->alloc_pdu(task, hdr->opcode)) {
773 "pdu for mgmt task.\n");
778 itt = task->hdr->itt;
779 task->hdr_len = sizeof(struct iscsi_hdr);
780 memcpy(task->hdr, hdr, sizeof(struct iscsi_hdr));
784 task->hdr->itt = itt;
786 task->hdr->itt = build_itt(task->itt,
787 task->conn->session->age);
790 return task;
793 iscsi_put_task(task);
798 * iscsi_send_mgmt_task - Send task created with iscsi_alloc_mgmt_task.
799 * @task: iscsi task to send.
802 * the task with iscsi_put_task;
804 static int iscsi_send_mgmt_task(struct iscsi_task *task)
806 struct iscsi_conn *conn = task->conn;
812 rc = iscsi_prep_mgmt_task(conn, task);
816 rc = session->tt->xmit_task(task);
820 list_add_tail(&task->running, &conn->mgmtqueue);
830 struct iscsi_task *task;
833 task = iscsi_alloc_mgmt_task(conn, hdr, data, data_size);
834 if (!task)
837 rc = iscsi_send_mgmt_task(task);
839 iscsi_put_task(task);
862 * @task: scsi command task
867 * then completes the command and task. called under back_lock
870 struct iscsi_task *task, char *data,
875 struct scsi_cmnd *sc = task->sc;
882 if (task->protected) {
893 ascq = session->tt->check_protection(task, &sector);
950 sc, sc->result, task->itt);
952 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
959 * @task: scsi command task
962 * then completes the command and task. called under back_lock
966 struct iscsi_task *task)
969 struct scsi_cmnd *sc = task->sc;
991 sc, sc->result, task->itt);
993 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1019 struct iscsi_task *task;
1037 task = iscsi_alloc_mgmt_task(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
1038 if (!task)
1042 WRITE_ONCE(conn->ping_task, task);
1044 if (iscsi_send_mgmt_task(task)) {
1047 iscsi_put_task(task);
1061 * @task: scsi command task
1069 static int iscsi_nop_out_rsp(struct iscsi_task *task,
1072 struct iscsi_conn *conn = task->conn;
1075 if (READ_ONCE(conn->ping_task) != task) {
1085 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1145 struct iscsi_task *task;
1150 task = iscsi_itt_to_task(conn, rejected_pdu.itt);
1151 if (!task) {
1154 "not lookup rejected task.\n");
1157 rc = iscsi_nop_out_rsp(task,
1173 * iscsi_itt_to_task - look up task by itt
1217 struct iscsi_task *task;
1271 task = iscsi_itt_to_ctask(conn, hdr->itt);
1272 if (!task)
1274 task->last_xfer = jiffies;
1286 task = iscsi_itt_to_task(conn, hdr->itt);
1287 if (!task)
1296 iscsi_scsi_cmd_rsp(conn, hdr, task, data, datalen);
1299 iscsi_data_in_rsp(conn, hdr, task);
1325 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1335 rc = iscsi_nop_out_rsp(task, (struct iscsi_nopin*)hdr,
1348 iscsi_complete_task(task, ISCSI_TASK_COMPLETED);
1408 struct iscsi_task *task;
1413 task = iscsi_itt_to_task(conn, itt);
1414 if (!task || !task->sc)
1417 if (iscsi_cmd(task->sc)->age != conn->session->age) {
1419 "task's session age %d, expected %d\n",
1420 iscsi_cmd(task->sc)->age, conn->session->age);
1424 return task;
1501 static int iscsi_xmit_task(struct iscsi_conn *conn, struct iscsi_task *task,
1506 if (!conn->task) {
1513 if (!iscsi_get_task(task)) {
1519 conn->task = NULL;
1523 * If this was a requeue for a R2T we have an extra ref on the task in
1524 * case a bad target sends a cmd rsp before we have handled the task.
1527 iscsi_put_task(task);
1535 * Save the task and ref in case we weren't cleaning up this
1536 * task and get woken up again.
1538 conn->task = task;
1543 rc = conn->session->tt->xmit_task(task);
1546 /* done with this task */
1547 task->last_xfer = jiffies;
1551 * as conn->task above.
1553 iscsi_get_task(task);
1554 conn->task = task;
1557 iscsi_put_task(task);
1562 * iscsi_requeue_task - requeue task to run from session workqueue
1563 * @task: task to requeue
1565 * Callers must have taken a ref to the task that is going to be requeued.
1567 void iscsi_requeue_task(struct iscsi_task *task)
1569 struct iscsi_conn *conn = task->conn;
1576 if (list_empty(&task->running)) {
1577 list_add_tail(&task->running, &conn->requeue);
1583 iscsi_put_task(task);
1601 struct iscsi_task *task;
1611 if (conn->task) {
1612 rc = iscsi_xmit_task(conn, conn->task, false);
1624 task = list_entry(conn->mgmtqueue.next, struct iscsi_task,
1626 list_del_init(&task->running);
1627 if (iscsi_prep_mgmt_task(conn, task)) {
1630 __iscsi_put_task(task);
1634 rc = iscsi_xmit_task(conn, task, false);
1647 task = list_entry(conn->requeue.next, struct iscsi_task,
1650 if (iscsi_check_tmf_restrictions(task, ISCSI_OP_SCSI_DATA_OUT))
1653 list_del_init(&task->running);
1654 rc = iscsi_xmit_task(conn, task, true);
1663 task = list_entry(conn->cmdqueue.next, struct iscsi_task,
1665 list_del_init(&task->running);
1667 fail_scsi_task(task, DID_IMM_RETRY);
1670 rc = iscsi_prep_scsi_cmd_pdu(task);
1673 fail_scsi_task(task, DID_IMM_RETRY);
1675 fail_scsi_task(task, DID_ABORT);
1678 rc = iscsi_xmit_task(conn, task, false);
1682 * we could continuously get new task requests so
1716 struct iscsi_task *task;
1719 (void *) &task, sizeof(void *)))
1723 iscsi_cmd(sc)->task = task;
1725 refcount_set(&task->refcount, 1);
1726 task->state = ISCSI_TASK_PENDING;
1727 task->conn = conn;
1728 task->sc = sc;
1729 task->have_checked_conn = false;
1730 task->last_timeout = jiffies;
1731 task->last_xfer = jiffies;
1732 task->protected = false;
1733 INIT_LIST_HEAD(&task->running);
1734 return task;
1757 struct iscsi_task *task = NULL;
1760 iscsi_cmd(sc)->task = NULL;
1834 task = iscsi_alloc_task(conn, sc);
1835 if (!task) {
1841 reason = iscsi_prep_scsi_cmd_pdu(task);
1851 if (session->tt->xmit_task(task)) {
1857 list_add_tail(&task->running, &conn->cmdqueue);
1867 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1877 iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ);
1952 /* if the session drops it will clean up the task */
1965 struct iscsi_task *task;
1971 task = session->cmds[i];
1972 if (!task->sc || task->state == ISCSI_TASK_FREE)
1975 if (lun != -1 && lun != task->sc->device->lun)
1982 if (!iscsi_get_task(task)) {
1992 task->sc, task->itt, task->state);
1993 __fail_scsi_task(task, error);
1994 __iscsi_put_task(task);
2077 struct iscsi_task *task = NULL, *running_task;
2090 task = iscsi_cmd(sc)->task;
2091 if (!task) {
2100 if (!iscsi_get_task(task)) {
2106 task = NULL;
2143 * recvd one for the task since the last timeout ask for
2145 * we can check if it is the task or connection when we send the
2148 if (time_after(task->last_xfer, task->last_timeout)) {
2152 "%lu\n.", task->last_xfer, task->last_timeout);
2153 task->have_checked_conn = false;
2172 if (!running_task->sc || running_task == task ||
2181 task->sc->jiffies_at_alloc))
2184 if (time_after(running_task->last_xfer, task->last_timeout)) {
2186 * This task has not made progress, but a task
2198 "complete. Our last xfer vs running task "
2200 task->last_xfer, running_task->last_xfer,
2201 task->last_timeout);
2210 if (task->have_checked_conn)
2218 task->have_checked_conn = true;
2225 task->have_checked_conn = true;
2231 if (task) {
2232 task->last_timeout = jiffies;
2233 iscsi_put_task(task);
2332 static void iscsi_prep_abort_task_pdu(struct iscsi_task *task,
2339 hdr->lun = task->lun;
2340 hdr->rtt = task->hdr_itt;
2341 hdr->refcmdsn = task->cmdsn;
2349 struct iscsi_task *task;
2365 if (!iscsi_cmd(sc)->task) {
2387 task = iscsi_cmd(sc)->task;
2388 if (!task || !task->sc) {
2389 /* task completed before time out */
2398 if (!iscsi_get_task(task)) {
2407 ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n", sc, task->itt);
2414 if (task->state == ISCSI_TASK_PENDING) {
2415 fail_scsi_task(task, DID_ABORT);
2425 iscsi_prep_abort_task_pdu(task, hdr);
2444 fail_scsi_task(task, DID_ABORT);
2451 session->running_aborted_task = task;
2456 if (iscsi_task_is_completed(task)) {
2459 /* task completed before tmf abort response */
2474 sc, task->itt);
2475 iscsi_put_task(task);
2484 task ? task->itt : 0);
2486 * The driver might be accessing the task so hold the ref. The conn
2488 * driver's no longer touching the task.
2491 iscsi_put_task(task);
3006 * @cmd_task_size: LLD task private data size
3078 struct iscsi_task *task = session->cmds[cmd_i];
3081 task->dd_data = &task[1];
3082 task->itt = cmd_i;
3083 task->state = ISCSI_TASK_FREE;
3084 INIT_LIST_HEAD(&task->running);
3357 struct iscsi_task *task;
3361 task = conn->session->cmds[i];
3362 if (task->sc)
3365 if (task->state == ISCSI_TASK_FREE)
3370 task->itt, task->state);
3373 if (cleanup_queued_task(task)) {
3379 if (task->state == ISCSI_TASK_PENDING)
3381 iscsi_complete_task(task, state);
3402 * up the login task and connection. We do not need to block and set