diff options
Diffstat (limited to 'drivers/target')
26 files changed, 239 insertions, 1086 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index aebde3289c50..50bad55a0c42 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <target/target_core_fabric.h> | 30 | #include <target/target_core_fabric.h> |
31 | #include <target/target_core_configfs.h> | 31 | #include <target/target_core_configfs.h> |
32 | 32 | ||
33 | #include "iscsi_target_core.h" | 33 | #include <target/iscsi/iscsi_target_core.h> |
34 | #include "iscsi_target_parameters.h" | 34 | #include "iscsi_target_parameters.h" |
35 | #include "iscsi_target_seq_pdu_list.h" | 35 | #include "iscsi_target_seq_pdu_list.h" |
36 | #include "iscsi_target_tq.h" | 36 | #include "iscsi_target_tq.h" |
@@ -45,7 +45,7 @@ | |||
45 | #include "iscsi_target_util.h" | 45 | #include "iscsi_target_util.h" |
46 | #include "iscsi_target.h" | 46 | #include "iscsi_target.h" |
47 | #include "iscsi_target_device.h" | 47 | #include "iscsi_target_device.h" |
48 | #include "iscsi_target_stat.h" | 48 | #include <target/iscsi/iscsi_target_stat.h> |
49 | 49 | ||
50 | #include <target/iscsi/iscsi_transport.h> | 50 | #include <target/iscsi/iscsi_transport.h> |
51 | 51 | ||
@@ -968,11 +968,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
968 | 968 | ||
969 | conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; | 969 | conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; |
970 | if (hdr->flags & ISCSI_FLAG_CMD_READ) { | 970 | if (hdr->flags & ISCSI_FLAG_CMD_READ) { |
971 | spin_lock_bh(&conn->sess->ttt_lock); | 971 | cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); |
972 | cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; | ||
973 | if (cmd->targ_xfer_tag == 0xFFFFFFFF) | ||
974 | cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; | ||
975 | spin_unlock_bh(&conn->sess->ttt_lock); | ||
976 | } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE) | 972 | } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE) |
977 | cmd->targ_xfer_tag = 0xFFFFFFFF; | 973 | cmd->targ_xfer_tag = 0xFFFFFFFF; |
978 | cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); | 974 | cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); |
@@ -1998,6 +1994,7 @@ iscsit_setup_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
1998 | cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); | 1994 | cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); |
1999 | cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); | 1995 | cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); |
2000 | cmd->data_direction = DMA_NONE; | 1996 | cmd->data_direction = DMA_NONE; |
1997 | cmd->text_in_ptr = NULL; | ||
2001 | 1998 | ||
2002 | return 0; | 1999 | return 0; |
2003 | } | 2000 | } |
@@ -2011,9 +2008,13 @@ iscsit_process_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
2011 | int cmdsn_ret; | 2008 | int cmdsn_ret; |
2012 | 2009 | ||
2013 | if (!text_in) { | 2010 | if (!text_in) { |
2014 | pr_err("Unable to locate text_in buffer for sendtargets" | 2011 | cmd->targ_xfer_tag = be32_to_cpu(hdr->ttt); |
2015 | " discovery\n"); | 2012 | if (cmd->targ_xfer_tag == 0xFFFFFFFF) { |
2016 | goto reject; | 2013 | pr_err("Unable to locate text_in buffer for sendtargets" |
2014 | " discovery\n"); | ||
2015 | goto reject; | ||
2016 | } | ||
2017 | goto empty_sendtargets; | ||
2017 | } | 2018 | } |
2018 | if (strncmp("SendTargets", text_in, 11) != 0) { | 2019 | if (strncmp("SendTargets", text_in, 11) != 0) { |
2019 | pr_err("Received Text Data that is not" | 2020 | pr_err("Received Text Data that is not" |
@@ -2040,6 +2041,7 @@ iscsit_process_text_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | |||
2040 | list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); | 2041 | list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); |
2041 | spin_unlock_bh(&conn->cmd_lock); | 2042 | spin_unlock_bh(&conn->cmd_lock); |
2042 | 2043 | ||
2044 | empty_sendtargets: | ||
2043 | iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); | 2045 | iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); |
2044 | 2046 | ||
2045 | if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { | 2047 | if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { |
@@ -3047,11 +3049,7 @@ static int iscsit_send_r2t( | |||
3047 | int_to_scsilun(cmd->se_cmd.orig_fe_lun, | 3049 | int_to_scsilun(cmd->se_cmd.orig_fe_lun, |
3048 | (struct scsi_lun *)&hdr->lun); | 3050 | (struct scsi_lun *)&hdr->lun); |
3049 | hdr->itt = cmd->init_task_tag; | 3051 | hdr->itt = cmd->init_task_tag; |
3050 | spin_lock_bh(&conn->sess->ttt_lock); | 3052 | r2t->targ_xfer_tag = session_get_next_ttt(conn->sess); |
3051 | r2t->targ_xfer_tag = conn->sess->targ_xfer_tag++; | ||
3052 | if (r2t->targ_xfer_tag == 0xFFFFFFFF) | ||
3053 | r2t->targ_xfer_tag = conn->sess->targ_xfer_tag++; | ||
3054 | spin_unlock_bh(&conn->sess->ttt_lock); | ||
3055 | hdr->ttt = cpu_to_be32(r2t->targ_xfer_tag); | 3053 | hdr->ttt = cpu_to_be32(r2t->targ_xfer_tag); |
3056 | hdr->statsn = cpu_to_be32(conn->stat_sn); | 3054 | hdr->statsn = cpu_to_be32(conn->stat_sn); |
3057 | hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); | 3055 | hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); |
@@ -3393,7 +3391,8 @@ static bool iscsit_check_inaddr_any(struct iscsi_np *np) | |||
3393 | 3391 | ||
3394 | static int | 3392 | static int |
3395 | iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, | 3393 | iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, |
3396 | enum iscsit_transport_type network_transport) | 3394 | enum iscsit_transport_type network_transport, |
3395 | int skip_bytes, bool *completed) | ||
3397 | { | 3396 | { |
3398 | char *payload = NULL; | 3397 | char *payload = NULL; |
3399 | struct iscsi_conn *conn = cmd->conn; | 3398 | struct iscsi_conn *conn = cmd->conn; |
@@ -3405,7 +3404,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, | |||
3405 | unsigned char buf[ISCSI_IQN_LEN+12]; /* iqn + "TargetName=" + \0 */ | 3404 | unsigned char buf[ISCSI_IQN_LEN+12]; /* iqn + "TargetName=" + \0 */ |
3406 | unsigned char *text_in = cmd->text_in_ptr, *text_ptr = NULL; | 3405 | unsigned char *text_in = cmd->text_in_ptr, *text_ptr = NULL; |
3407 | 3406 | ||
3408 | buffer_len = max(conn->conn_ops->MaxRecvDataSegmentLength, | 3407 | buffer_len = min(conn->conn_ops->MaxRecvDataSegmentLength, |
3409 | SENDTARGETS_BUF_LIMIT); | 3408 | SENDTARGETS_BUF_LIMIT); |
3410 | 3409 | ||
3411 | payload = kzalloc(buffer_len, GFP_KERNEL); | 3410 | payload = kzalloc(buffer_len, GFP_KERNEL); |
@@ -3484,9 +3483,16 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, | |||
3484 | end_of_buf = 1; | 3483 | end_of_buf = 1; |
3485 | goto eob; | 3484 | goto eob; |
3486 | } | 3485 | } |
3487 | memcpy(payload + payload_len, buf, len); | 3486 | |
3488 | payload_len += len; | 3487 | if (skip_bytes && len <= skip_bytes) { |
3489 | target_name_printed = 1; | 3488 | skip_bytes -= len; |
3489 | } else { | ||
3490 | memcpy(payload + payload_len, buf, len); | ||
3491 | payload_len += len; | ||
3492 | target_name_printed = 1; | ||
3493 | if (len > skip_bytes) | ||
3494 | skip_bytes = 0; | ||
3495 | } | ||
3490 | } | 3496 | } |
3491 | 3497 | ||
3492 | len = sprintf(buf, "TargetAddress=" | 3498 | len = sprintf(buf, "TargetAddress=" |
@@ -3502,15 +3508,24 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, | |||
3502 | end_of_buf = 1; | 3508 | end_of_buf = 1; |
3503 | goto eob; | 3509 | goto eob; |
3504 | } | 3510 | } |
3505 | memcpy(payload + payload_len, buf, len); | 3511 | |
3506 | payload_len += len; | 3512 | if (skip_bytes && len <= skip_bytes) { |
3513 | skip_bytes -= len; | ||
3514 | } else { | ||
3515 | memcpy(payload + payload_len, buf, len); | ||
3516 | payload_len += len; | ||
3517 | if (len > skip_bytes) | ||
3518 | skip_bytes = 0; | ||
3519 | } | ||
3507 | } | 3520 | } |
3508 | spin_unlock(&tpg->tpg_np_lock); | 3521 | spin_unlock(&tpg->tpg_np_lock); |
3509 | } | 3522 | } |
3510 | spin_unlock(&tiqn->tiqn_tpg_lock); | 3523 | spin_unlock(&tiqn->tiqn_tpg_lock); |
3511 | eob: | 3524 | eob: |
3512 | if (end_of_buf) | 3525 | if (end_of_buf) { |
3526 | *completed = false; | ||
3513 | break; | 3527 | break; |
3528 | } | ||
3514 | 3529 | ||
3515 | if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) | 3530 | if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) |
3516 | break; | 3531 | break; |
@@ -3528,13 +3543,23 @@ iscsit_build_text_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, | |||
3528 | enum iscsit_transport_type network_transport) | 3543 | enum iscsit_transport_type network_transport) |
3529 | { | 3544 | { |
3530 | int text_length, padding; | 3545 | int text_length, padding; |
3546 | bool completed = true; | ||
3531 | 3547 | ||
3532 | text_length = iscsit_build_sendtargets_response(cmd, network_transport); | 3548 | text_length = iscsit_build_sendtargets_response(cmd, network_transport, |
3549 | cmd->read_data_done, | ||
3550 | &completed); | ||
3533 | if (text_length < 0) | 3551 | if (text_length < 0) |
3534 | return text_length; | 3552 | return text_length; |
3535 | 3553 | ||
3554 | if (completed) { | ||
3555 | hdr->flags |= ISCSI_FLAG_CMD_FINAL; | ||
3556 | } else { | ||
3557 | hdr->flags |= ISCSI_FLAG_TEXT_CONTINUE; | ||
3558 | cmd->read_data_done += text_length; | ||
3559 | if (cmd->targ_xfer_tag == 0xFFFFFFFF) | ||
3560 | cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); | ||
3561 | } | ||
3536 | hdr->opcode = ISCSI_OP_TEXT_RSP; | 3562 | hdr->opcode = ISCSI_OP_TEXT_RSP; |
3537 | hdr->flags |= ISCSI_FLAG_CMD_FINAL; | ||
3538 | padding = ((-text_length) & 3); | 3563 | padding = ((-text_length) & 3); |
3539 | hton24(hdr->dlength, text_length); | 3564 | hton24(hdr->dlength, text_length); |
3540 | hdr->itt = cmd->init_task_tag; | 3565 | hdr->itt = cmd->init_task_tag; |
@@ -3543,21 +3568,25 @@ iscsit_build_text_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, | |||
3543 | hdr->statsn = cpu_to_be32(cmd->stat_sn); | 3568 | hdr->statsn = cpu_to_be32(cmd->stat_sn); |
3544 | 3569 | ||
3545 | iscsit_increment_maxcmdsn(cmd, conn->sess); | 3570 | iscsit_increment_maxcmdsn(cmd, conn->sess); |
3571 | /* | ||
3572 | * Reset maxcmdsn_inc in multi-part text payload exchanges to | ||
3573 | * correctly increment MaxCmdSN for each response answering a | ||
3574 | * non immediate text request with a valid CmdSN. | ||
3575 | */ | ||
3576 | cmd->maxcmdsn_inc = 0; | ||
3546 | hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); | 3577 | hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); |
3547 | hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); | 3578 | hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); |
3548 | 3579 | ||
3549 | pr_debug("Built Text Response: ITT: 0x%08x, StatSN: 0x%08x," | 3580 | pr_debug("Built Text Response: ITT: 0x%08x, TTT: 0x%08x, StatSN: 0x%08x," |
3550 | " Length: %u, CID: %hu\n", cmd->init_task_tag, cmd->stat_sn, | 3581 | " Length: %u, CID: %hu F: %d C: %d\n", cmd->init_task_tag, |
3551 | text_length, conn->cid); | 3582 | cmd->targ_xfer_tag, cmd->stat_sn, text_length, conn->cid, |
3583 | !!(hdr->flags & ISCSI_FLAG_CMD_FINAL), | ||
3584 | !!(hdr->flags & ISCSI_FLAG_TEXT_CONTINUE)); | ||
3552 | 3585 | ||
3553 | return text_length + padding; | 3586 | return text_length + padding; |
3554 | } | 3587 | } |
3555 | EXPORT_SYMBOL(iscsit_build_text_rsp); | 3588 | EXPORT_SYMBOL(iscsit_build_text_rsp); |
3556 | 3589 | ||
3557 | /* | ||
3558 | * FIXME: Add support for F_BIT and C_BIT when the length is longer than | ||
3559 | * MaxRecvDataSegmentLength. | ||
3560 | */ | ||
3561 | static int iscsit_send_text_rsp( | 3590 | static int iscsit_send_text_rsp( |
3562 | struct iscsi_cmd *cmd, | 3591 | struct iscsi_cmd *cmd, |
3563 | struct iscsi_conn *conn) | 3592 | struct iscsi_conn *conn) |
@@ -4021,9 +4050,15 @@ static int iscsi_target_rx_opcode(struct iscsi_conn *conn, unsigned char *buf) | |||
4021 | ret = iscsit_handle_task_mgt_cmd(conn, cmd, buf); | 4050 | ret = iscsit_handle_task_mgt_cmd(conn, cmd, buf); |
4022 | break; | 4051 | break; |
4023 | case ISCSI_OP_TEXT: | 4052 | case ISCSI_OP_TEXT: |
4024 | cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); | 4053 | if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) { |
4025 | if (!cmd) | 4054 | cmd = iscsit_find_cmd_from_itt(conn, hdr->itt); |
4026 | goto reject; | 4055 | if (!cmd) |
4056 | goto reject; | ||
4057 | } else { | ||
4058 | cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); | ||
4059 | if (!cmd) | ||
4060 | goto reject; | ||
4061 | } | ||
4027 | 4062 | ||
4028 | ret = iscsit_handle_text_cmd(conn, cmd, buf); | 4063 | ret = iscsit_handle_text_cmd(conn, cmd, buf); |
4029 | break; | 4064 | break; |
diff --git a/drivers/target/iscsi/iscsi_target_auth.c b/drivers/target/iscsi/iscsi_target_auth.c index ab4915c0d933..47e249dccb5f 100644 --- a/drivers/target/iscsi/iscsi_target_auth.c +++ b/drivers/target/iscsi/iscsi_target_auth.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <linux/err.h> | 22 | #include <linux/err.h> |
23 | #include <linux/scatterlist.h> | 23 | #include <linux/scatterlist.h> |
24 | 24 | ||
25 | #include "iscsi_target_core.h" | 25 | #include <target/iscsi/iscsi_target_core.h> |
26 | #include "iscsi_target_nego.h" | 26 | #include "iscsi_target_nego.h" |
27 | #include "iscsi_target_auth.h" | 27 | #include "iscsi_target_auth.h" |
28 | 28 | ||
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c index 9059c1e0b26e..48384b675e62 100644 --- a/drivers/target/iscsi/iscsi_target_configfs.c +++ b/drivers/target/iscsi/iscsi_target_configfs.c | |||
@@ -28,7 +28,7 @@ | |||
28 | #include <target/configfs_macros.h> | 28 | #include <target/configfs_macros.h> |
29 | #include <target/iscsi/iscsi_transport.h> | 29 | #include <target/iscsi/iscsi_transport.h> |
30 | 30 | ||
31 | #include "iscsi_target_core.h" | 31 | #include <target/iscsi/iscsi_target_core.h> |
32 | #include "iscsi_target_parameters.h" | 32 | #include "iscsi_target_parameters.h" |
33 | #include "iscsi_target_device.h" | 33 | #include "iscsi_target_device.h" |
34 | #include "iscsi_target_erl0.h" | 34 | #include "iscsi_target_erl0.h" |
@@ -36,7 +36,7 @@ | |||
36 | #include "iscsi_target_tpg.h" | 36 | #include "iscsi_target_tpg.h" |
37 | #include "iscsi_target_util.h" | 37 | #include "iscsi_target_util.h" |
38 | #include "iscsi_target.h" | 38 | #include "iscsi_target.h" |
39 | #include "iscsi_target_stat.h" | 39 | #include <target/iscsi/iscsi_target_stat.h> |
40 | #include "iscsi_target_configfs.h" | 40 | #include "iscsi_target_configfs.h" |
41 | 41 | ||
42 | struct target_fabric_configfs *lio_target_fabric_configfs; | 42 | struct target_fabric_configfs *lio_target_fabric_configfs; |
@@ -674,12 +674,9 @@ static ssize_t lio_target_nacl_show_info( | |||
674 | rb += sprintf(page+rb, "InitiatorAlias: %s\n", | 674 | rb += sprintf(page+rb, "InitiatorAlias: %s\n", |
675 | sess->sess_ops->InitiatorAlias); | 675 | sess->sess_ops->InitiatorAlias); |
676 | 676 | ||
677 | rb += sprintf(page+rb, "LIO Session ID: %u " | 677 | rb += sprintf(page+rb, |
678 | "ISID: 0x%02x %02x %02x %02x %02x %02x " | 678 | "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", |
679 | "TSIH: %hu ", sess->sid, | 679 | sess->sid, sess->isid, sess->tsih); |
680 | sess->isid[0], sess->isid[1], sess->isid[2], | ||
681 | sess->isid[3], sess->isid[4], sess->isid[5], | ||
682 | sess->tsih); | ||
683 | rb += sprintf(page+rb, "SessionType: %s\n", | 680 | rb += sprintf(page+rb, "SessionType: %s\n", |
684 | (sess->sess_ops->SessionType) ? | 681 | (sess->sess_ops->SessionType) ? |
685 | "Discovery" : "Normal"); | 682 | "Discovery" : "Normal"); |
@@ -1758,9 +1755,7 @@ static u32 lio_sess_get_initiator_sid( | |||
1758 | /* | 1755 | /* |
1759 | * iSCSI Initiator Session Identifier from RFC-3720. | 1756 | * iSCSI Initiator Session Identifier from RFC-3720. |
1760 | */ | 1757 | */ |
1761 | return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x", | 1758 | return snprintf(buf, size, "%6phN", sess->isid); |
1762 | sess->isid[0], sess->isid[1], sess->isid[2], | ||
1763 | sess->isid[3], sess->isid[4], sess->isid[5]); | ||
1764 | } | 1759 | } |
1765 | 1760 | ||
1766 | static int lio_queue_data_in(struct se_cmd *se_cmd) | 1761 | static int lio_queue_data_in(struct se_cmd *se_cmd) |
diff --git a/drivers/target/iscsi/iscsi_target_core.h b/drivers/target/iscsi/iscsi_target_core.h deleted file mode 100644 index cbcff38ac9b7..000000000000 --- a/drivers/target/iscsi/iscsi_target_core.h +++ /dev/null | |||
@@ -1,883 +0,0 @@ | |||
1 | #ifndef ISCSI_TARGET_CORE_H | ||
2 | #define ISCSI_TARGET_CORE_H | ||
3 | |||
4 | #include <linux/in.h> | ||
5 | #include <linux/configfs.h> | ||
6 | #include <net/sock.h> | ||
7 | #include <net/tcp.h> | ||
8 | #include <scsi/scsi_cmnd.h> | ||
9 | #include <scsi/iscsi_proto.h> | ||
10 | #include <target/target_core_base.h> | ||
11 | |||
12 | #define ISCSIT_VERSION "v4.1.0" | ||
13 | #define ISCSI_MAX_DATASN_MISSING_COUNT 16 | ||
14 | #define ISCSI_TX_THREAD_TCP_TIMEOUT 2 | ||
15 | #define ISCSI_RX_THREAD_TCP_TIMEOUT 2 | ||
16 | #define SECONDS_FOR_ASYNC_LOGOUT 10 | ||
17 | #define SECONDS_FOR_ASYNC_TEXT 10 | ||
18 | #define SECONDS_FOR_LOGOUT_COMP 15 | ||
19 | #define WHITE_SPACE " \t\v\f\n\r" | ||
20 | #define ISCSIT_MIN_TAGS 16 | ||
21 | #define ISCSIT_EXTRA_TAGS 8 | ||
22 | #define ISCSIT_TCP_BACKLOG 256 | ||
23 | |||
24 | /* struct iscsi_node_attrib sanity values */ | ||
25 | #define NA_DATAOUT_TIMEOUT 3 | ||
26 | #define NA_DATAOUT_TIMEOUT_MAX 60 | ||
27 | #define NA_DATAOUT_TIMEOUT_MIX 2 | ||
28 | #define NA_DATAOUT_TIMEOUT_RETRIES 5 | ||
29 | #define NA_DATAOUT_TIMEOUT_RETRIES_MAX 15 | ||
30 | #define NA_DATAOUT_TIMEOUT_RETRIES_MIN 1 | ||
31 | #define NA_NOPIN_TIMEOUT 15 | ||
32 | #define NA_NOPIN_TIMEOUT_MAX 60 | ||
33 | #define NA_NOPIN_TIMEOUT_MIN 3 | ||
34 | #define NA_NOPIN_RESPONSE_TIMEOUT 30 | ||
35 | #define NA_NOPIN_RESPONSE_TIMEOUT_MAX 60 | ||
36 | #define NA_NOPIN_RESPONSE_TIMEOUT_MIN 3 | ||
37 | #define NA_RANDOM_DATAIN_PDU_OFFSETS 0 | ||
38 | #define NA_RANDOM_DATAIN_SEQ_OFFSETS 0 | ||
39 | #define NA_RANDOM_R2T_OFFSETS 0 | ||
40 | |||
41 | /* struct iscsi_tpg_attrib sanity values */ | ||
42 | #define TA_AUTHENTICATION 1 | ||
43 | #define TA_LOGIN_TIMEOUT 15 | ||
44 | #define TA_LOGIN_TIMEOUT_MAX 30 | ||
45 | #define TA_LOGIN_TIMEOUT_MIN 5 | ||
46 | #define TA_NETIF_TIMEOUT 2 | ||
47 | #define TA_NETIF_TIMEOUT_MAX 15 | ||
48 | #define TA_NETIF_TIMEOUT_MIN 2 | ||
49 | #define TA_GENERATE_NODE_ACLS 0 | ||
50 | #define TA_DEFAULT_CMDSN_DEPTH 64 | ||
51 | #define TA_DEFAULT_CMDSN_DEPTH_MAX 512 | ||
52 | #define TA_DEFAULT_CMDSN_DEPTH_MIN 1 | ||
53 | #define TA_CACHE_DYNAMIC_ACLS 0 | ||
54 | /* Enabled by default in demo mode (generic_node_acls=1) */ | ||
55 | #define TA_DEMO_MODE_WRITE_PROTECT 1 | ||
56 | /* Disabled by default in production mode w/ explict ACLs */ | ||
57 | #define TA_PROD_MODE_WRITE_PROTECT 0 | ||
58 | #define TA_DEMO_MODE_DISCOVERY 1 | ||
59 | #define TA_DEFAULT_ERL 0 | ||
60 | #define TA_CACHE_CORE_NPS 0 | ||
61 | /* T10 protection information disabled by default */ | ||
62 | #define TA_DEFAULT_T10_PI 0 | ||
63 | |||
64 | #define ISCSI_IOV_DATA_BUFFER 5 | ||
65 | |||
66 | enum iscsit_transport_type { | ||
67 | ISCSI_TCP = 0, | ||
68 | ISCSI_SCTP_TCP = 1, | ||
69 | ISCSI_SCTP_UDP = 2, | ||
70 | ISCSI_IWARP_TCP = 3, | ||
71 | ISCSI_IWARP_SCTP = 4, | ||
72 | ISCSI_INFINIBAND = 5, | ||
73 | }; | ||
74 | |||
75 | /* RFC-3720 7.1.4 Standard Connection State Diagram for a Target */ | ||
76 | enum target_conn_state_table { | ||
77 | TARG_CONN_STATE_FREE = 0x1, | ||
78 | TARG_CONN_STATE_XPT_UP = 0x3, | ||
79 | TARG_CONN_STATE_IN_LOGIN = 0x4, | ||
80 | TARG_CONN_STATE_LOGGED_IN = 0x5, | ||
81 | TARG_CONN_STATE_IN_LOGOUT = 0x6, | ||
82 | TARG_CONN_STATE_LOGOUT_REQUESTED = 0x7, | ||
83 | TARG_CONN_STATE_CLEANUP_WAIT = 0x8, | ||
84 | }; | ||
85 | |||
86 | /* RFC-3720 7.3.2 Session State Diagram for a Target */ | ||
87 | enum target_sess_state_table { | ||
88 | TARG_SESS_STATE_FREE = 0x1, | ||
89 | TARG_SESS_STATE_ACTIVE = 0x2, | ||
90 | TARG_SESS_STATE_LOGGED_IN = 0x3, | ||
91 | TARG_SESS_STATE_FAILED = 0x4, | ||
92 | TARG_SESS_STATE_IN_CONTINUE = 0x5, | ||
93 | }; | ||
94 | |||
95 | /* struct iscsi_data_count->type */ | ||
96 | enum data_count_type { | ||
97 | ISCSI_RX_DATA = 1, | ||
98 | ISCSI_TX_DATA = 2, | ||
99 | }; | ||
100 | |||
101 | /* struct iscsi_datain_req->dr_complete */ | ||
102 | enum datain_req_comp_table { | ||
103 | DATAIN_COMPLETE_NORMAL = 1, | ||
104 | DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY = 2, | ||
105 | DATAIN_COMPLETE_CONNECTION_RECOVERY = 3, | ||
106 | }; | ||
107 | |||
108 | /* struct iscsi_datain_req->recovery */ | ||
109 | enum datain_req_rec_table { | ||
110 | DATAIN_WITHIN_COMMAND_RECOVERY = 1, | ||
111 | DATAIN_CONNECTION_RECOVERY = 2, | ||
112 | }; | ||
113 | |||
114 | /* struct iscsi_portal_group->state */ | ||
115 | enum tpg_state_table { | ||
116 | TPG_STATE_FREE = 0, | ||
117 | TPG_STATE_ACTIVE = 1, | ||
118 | TPG_STATE_INACTIVE = 2, | ||
119 | TPG_STATE_COLD_RESET = 3, | ||
120 | }; | ||
121 | |||
122 | /* struct iscsi_tiqn->tiqn_state */ | ||
123 | enum tiqn_state_table { | ||
124 | TIQN_STATE_ACTIVE = 1, | ||
125 | TIQN_STATE_SHUTDOWN = 2, | ||
126 | }; | ||
127 | |||
128 | /* struct iscsi_cmd->cmd_flags */ | ||
129 | enum cmd_flags_table { | ||
130 | ICF_GOT_LAST_DATAOUT = 0x00000001, | ||
131 | ICF_GOT_DATACK_SNACK = 0x00000002, | ||
132 | ICF_NON_IMMEDIATE_UNSOLICITED_DATA = 0x00000004, | ||
133 | ICF_SENT_LAST_R2T = 0x00000008, | ||
134 | ICF_WITHIN_COMMAND_RECOVERY = 0x00000010, | ||
135 | ICF_CONTIG_MEMORY = 0x00000020, | ||
136 | ICF_ATTACHED_TO_RQUEUE = 0x00000040, | ||
137 | ICF_OOO_CMDSN = 0x00000080, | ||
138 | ICF_SENDTARGETS_ALL = 0x00000100, | ||
139 | ICF_SENDTARGETS_SINGLE = 0x00000200, | ||
140 | }; | ||
141 | |||
142 | /* struct iscsi_cmd->i_state */ | ||
143 | enum cmd_i_state_table { | ||
144 | ISTATE_NO_STATE = 0, | ||
145 | ISTATE_NEW_CMD = 1, | ||
146 | ISTATE_DEFERRED_CMD = 2, | ||
147 | ISTATE_UNSOLICITED_DATA = 3, | ||
148 | ISTATE_RECEIVE_DATAOUT = 4, | ||
149 | ISTATE_RECEIVE_DATAOUT_RECOVERY = 5, | ||
150 | ISTATE_RECEIVED_LAST_DATAOUT = 6, | ||
151 | ISTATE_WITHIN_DATAOUT_RECOVERY = 7, | ||
152 | ISTATE_IN_CONNECTION_RECOVERY = 8, | ||
153 | ISTATE_RECEIVED_TASKMGT = 9, | ||
154 | ISTATE_SEND_ASYNCMSG = 10, | ||
155 | ISTATE_SENT_ASYNCMSG = 11, | ||
156 | ISTATE_SEND_DATAIN = 12, | ||
157 | ISTATE_SEND_LAST_DATAIN = 13, | ||
158 | ISTATE_SENT_LAST_DATAIN = 14, | ||
159 | ISTATE_SEND_LOGOUTRSP = 15, | ||
160 | ISTATE_SENT_LOGOUTRSP = 16, | ||
161 | ISTATE_SEND_NOPIN = 17, | ||
162 | ISTATE_SENT_NOPIN = 18, | ||
163 | ISTATE_SEND_REJECT = 19, | ||
164 | ISTATE_SENT_REJECT = 20, | ||
165 | ISTATE_SEND_R2T = 21, | ||
166 | ISTATE_SENT_R2T = 22, | ||
167 | ISTATE_SEND_R2T_RECOVERY = 23, | ||
168 | ISTATE_SENT_R2T_RECOVERY = 24, | ||
169 | ISTATE_SEND_LAST_R2T = 25, | ||
170 | ISTATE_SENT_LAST_R2T = 26, | ||
171 | ISTATE_SEND_LAST_R2T_RECOVERY = 27, | ||
172 | ISTATE_SENT_LAST_R2T_RECOVERY = 28, | ||
173 | ISTATE_SEND_STATUS = 29, | ||
174 | ISTATE_SEND_STATUS_BROKEN_PC = 30, | ||
175 | ISTATE_SENT_STATUS = 31, | ||
176 | ISTATE_SEND_STATUS_RECOVERY = 32, | ||
177 | ISTATE_SENT_STATUS_RECOVERY = 33, | ||
178 | ISTATE_SEND_TASKMGTRSP = 34, | ||
179 | ISTATE_SENT_TASKMGTRSP = 35, | ||
180 | ISTATE_SEND_TEXTRSP = 36, | ||
181 | ISTATE_SENT_TEXTRSP = 37, | ||
182 | ISTATE_SEND_NOPIN_WANT_RESPONSE = 38, | ||
183 | ISTATE_SENT_NOPIN_WANT_RESPONSE = 39, | ||
184 | ISTATE_SEND_NOPIN_NO_RESPONSE = 40, | ||
185 | ISTATE_REMOVE = 41, | ||
186 | ISTATE_FREE = 42, | ||
187 | }; | ||
188 | |||
189 | /* Used for iscsi_recover_cmdsn() return values */ | ||
190 | enum recover_cmdsn_ret_table { | ||
191 | CMDSN_ERROR_CANNOT_RECOVER = -1, | ||
192 | CMDSN_NORMAL_OPERATION = 0, | ||
193 | CMDSN_LOWER_THAN_EXP = 1, | ||
194 | CMDSN_HIGHER_THAN_EXP = 2, | ||
195 | CMDSN_MAXCMDSN_OVERRUN = 3, | ||
196 | }; | ||
197 | |||
198 | /* Used for iscsi_handle_immediate_data() return values */ | ||
199 | enum immedate_data_ret_table { | ||
200 | IMMEDIATE_DATA_CANNOT_RECOVER = -1, | ||
201 | IMMEDIATE_DATA_NORMAL_OPERATION = 0, | ||
202 | IMMEDIATE_DATA_ERL1_CRC_FAILURE = 1, | ||
203 | }; | ||
204 | |||
205 | /* Used for iscsi_decide_dataout_action() return values */ | ||
206 | enum dataout_action_ret_table { | ||
207 | DATAOUT_CANNOT_RECOVER = -1, | ||
208 | DATAOUT_NORMAL = 0, | ||
209 | DATAOUT_SEND_R2T = 1, | ||
210 | DATAOUT_SEND_TO_TRANSPORT = 2, | ||
211 | DATAOUT_WITHIN_COMMAND_RECOVERY = 3, | ||
212 | }; | ||
213 | |||
214 | /* Used for struct iscsi_node_auth->naf_flags */ | ||
215 | enum naf_flags_table { | ||
216 | NAF_USERID_SET = 0x01, | ||
217 | NAF_PASSWORD_SET = 0x02, | ||
218 | NAF_USERID_IN_SET = 0x04, | ||
219 | NAF_PASSWORD_IN_SET = 0x08, | ||
220 | }; | ||
221 | |||
222 | /* Used by various struct timer_list to manage iSCSI specific state */ | ||
223 | enum iscsi_timer_flags_table { | ||
224 | ISCSI_TF_RUNNING = 0x01, | ||
225 | ISCSI_TF_STOP = 0x02, | ||
226 | ISCSI_TF_EXPIRED = 0x04, | ||
227 | }; | ||
228 | |||
229 | /* Used for struct iscsi_np->np_flags */ | ||
230 | enum np_flags_table { | ||
231 | NPF_IP_NETWORK = 0x00, | ||
232 | }; | ||
233 | |||
234 | /* Used for struct iscsi_np->np_thread_state */ | ||
235 | enum np_thread_state_table { | ||
236 | ISCSI_NP_THREAD_ACTIVE = 1, | ||
237 | ISCSI_NP_THREAD_INACTIVE = 2, | ||
238 | ISCSI_NP_THREAD_RESET = 3, | ||
239 | ISCSI_NP_THREAD_SHUTDOWN = 4, | ||
240 | ISCSI_NP_THREAD_EXIT = 5, | ||
241 | }; | ||
242 | |||
243 | struct iscsi_conn_ops { | ||
244 | u8 HeaderDigest; /* [0,1] == [None,CRC32C] */ | ||
245 | u8 DataDigest; /* [0,1] == [None,CRC32C] */ | ||
246 | u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */ | ||
247 | u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */ | ||
248 | u8 OFMarker; /* [0,1] == [No,Yes] */ | ||
249 | u8 IFMarker; /* [0,1] == [No,Yes] */ | ||
250 | u32 OFMarkInt; /* [1..65535] */ | ||
251 | u32 IFMarkInt; /* [1..65535] */ | ||
252 | /* | ||
253 | * iSER specific connection parameters | ||
254 | */ | ||
255 | u32 InitiatorRecvDataSegmentLength; /* [512..2**24-1] */ | ||
256 | u32 TargetRecvDataSegmentLength; /* [512..2**24-1] */ | ||
257 | }; | ||
258 | |||
259 | struct iscsi_sess_ops { | ||
260 | char InitiatorName[224]; | ||
261 | char InitiatorAlias[256]; | ||
262 | char TargetName[224]; | ||
263 | char TargetAlias[256]; | ||
264 | char TargetAddress[256]; | ||
265 | u16 TargetPortalGroupTag; /* [0..65535] */ | ||
266 | u16 MaxConnections; /* [1..65535] */ | ||
267 | u8 InitialR2T; /* [0,1] == [No,Yes] */ | ||
268 | u8 ImmediateData; /* [0,1] == [No,Yes] */ | ||
269 | u32 MaxBurstLength; /* [512..2**24-1] */ | ||
270 | u32 FirstBurstLength; /* [512..2**24-1] */ | ||
271 | u16 DefaultTime2Wait; /* [0..3600] */ | ||
272 | u16 DefaultTime2Retain; /* [0..3600] */ | ||
273 | u16 MaxOutstandingR2T; /* [1..65535] */ | ||
274 | u8 DataPDUInOrder; /* [0,1] == [No,Yes] */ | ||
275 | u8 DataSequenceInOrder; /* [0,1] == [No,Yes] */ | ||
276 | u8 ErrorRecoveryLevel; /* [0..2] */ | ||
277 | u8 SessionType; /* [0,1] == [Normal,Discovery]*/ | ||
278 | /* | ||
279 | * iSER specific session parameters | ||
280 | */ | ||
281 | u8 RDMAExtensions; /* [0,1] == [No,Yes] */ | ||
282 | }; | ||
283 | |||
284 | struct iscsi_queue_req { | ||
285 | int state; | ||
286 | struct iscsi_cmd *cmd; | ||
287 | struct list_head qr_list; | ||
288 | }; | ||
289 | |||
290 | struct iscsi_data_count { | ||
291 | int data_length; | ||
292 | int sync_and_steering; | ||
293 | enum data_count_type type; | ||
294 | u32 iov_count; | ||
295 | u32 ss_iov_count; | ||
296 | u32 ss_marker_count; | ||
297 | struct kvec *iov; | ||
298 | }; | ||
299 | |||
300 | struct iscsi_param_list { | ||
301 | bool iser; | ||
302 | struct list_head param_list; | ||
303 | struct list_head extra_response_list; | ||
304 | }; | ||
305 | |||
306 | struct iscsi_datain_req { | ||
307 | enum datain_req_comp_table dr_complete; | ||
308 | int generate_recovery_values; | ||
309 | enum datain_req_rec_table recovery; | ||
310 | u32 begrun; | ||
311 | u32 runlength; | ||
312 | u32 data_length; | ||
313 | u32 data_offset; | ||
314 | u32 data_sn; | ||
315 | u32 next_burst_len; | ||
316 | u32 read_data_done; | ||
317 | u32 seq_send_order; | ||
318 | struct list_head cmd_datain_node; | ||
319 | } ____cacheline_aligned; | ||
320 | |||
321 | struct iscsi_ooo_cmdsn { | ||
322 | u16 cid; | ||
323 | u32 batch_count; | ||
324 | u32 cmdsn; | ||
325 | u32 exp_cmdsn; | ||
326 | struct iscsi_cmd *cmd; | ||
327 | struct list_head ooo_list; | ||
328 | } ____cacheline_aligned; | ||
329 | |||
330 | struct iscsi_datain { | ||
331 | u8 flags; | ||
332 | u32 data_sn; | ||
333 | u32 length; | ||
334 | u32 offset; | ||
335 | } ____cacheline_aligned; | ||
336 | |||
337 | struct iscsi_r2t { | ||
338 | int seq_complete; | ||
339 | int recovery_r2t; | ||
340 | int sent_r2t; | ||
341 | u32 r2t_sn; | ||
342 | u32 offset; | ||
343 | u32 targ_xfer_tag; | ||
344 | u32 xfer_len; | ||
345 | struct list_head r2t_list; | ||
346 | } ____cacheline_aligned; | ||
347 | |||
348 | struct iscsi_cmd { | ||
349 | enum iscsi_timer_flags_table dataout_timer_flags; | ||
350 | /* DataOUT timeout retries */ | ||
351 | u8 dataout_timeout_retries; | ||
352 | /* Within command recovery count */ | ||
353 | u8 error_recovery_count; | ||
354 | /* iSCSI dependent state for out or order CmdSNs */ | ||
355 | enum cmd_i_state_table deferred_i_state; | ||
356 | /* iSCSI dependent state */ | ||
357 | enum cmd_i_state_table i_state; | ||
358 | /* Command is an immediate command (ISCSI_OP_IMMEDIATE set) */ | ||
359 | u8 immediate_cmd; | ||
360 | /* Immediate data present */ | ||
361 | u8 immediate_data; | ||
362 | /* iSCSI Opcode */ | ||
363 | u8 iscsi_opcode; | ||
364 | /* iSCSI Response Code */ | ||
365 | u8 iscsi_response; | ||
366 | /* Logout reason when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */ | ||
367 | u8 logout_reason; | ||
368 | /* Logout response code when iscsi_opcode == ISCSI_INIT_LOGOUT_CMND */ | ||
369 | u8 logout_response; | ||
370 | /* MaxCmdSN has been incremented */ | ||
371 | u8 maxcmdsn_inc; | ||
372 | /* Immediate Unsolicited Dataout */ | ||
373 | u8 unsolicited_data; | ||
374 | /* Reject reason code */ | ||
375 | u8 reject_reason; | ||
376 | /* CID contained in logout PDU when opcode == ISCSI_INIT_LOGOUT_CMND */ | ||
377 | u16 logout_cid; | ||
378 | /* Command flags */ | ||
379 | enum cmd_flags_table cmd_flags; | ||
380 | /* Initiator Task Tag assigned from Initiator */ | ||
381 | itt_t init_task_tag; | ||
382 | /* Target Transfer Tag assigned from Target */ | ||
383 | u32 targ_xfer_tag; | ||
384 | /* CmdSN assigned from Initiator */ | ||
385 | u32 cmd_sn; | ||
386 | /* ExpStatSN assigned from Initiator */ | ||
387 | u32 exp_stat_sn; | ||
388 | /* StatSN assigned to this ITT */ | ||
389 | u32 stat_sn; | ||
390 | /* DataSN Counter */ | ||
391 | u32 data_sn; | ||
392 | /* R2TSN Counter */ | ||
393 | u32 r2t_sn; | ||
394 | /* Last DataSN acknowledged via DataAck SNACK */ | ||
395 | u32 acked_data_sn; | ||
396 | /* Used for echoing NOPOUT ping data */ | ||
397 | u32 buf_ptr_size; | ||
398 | /* Used to store DataDigest */ | ||
399 | u32 data_crc; | ||
400 | /* Counter for MaxOutstandingR2T */ | ||
401 | u32 outstanding_r2ts; | ||
402 | /* Next R2T Offset when DataSequenceInOrder=Yes */ | ||
403 | u32 r2t_offset; | ||
404 | /* Iovec current and orig count for iscsi_cmd->iov_data */ | ||
405 | u32 iov_data_count; | ||
406 | u32 orig_iov_data_count; | ||
407 | /* Number of miscellaneous iovecs used for IP stack calls */ | ||
408 | u32 iov_misc_count; | ||
409 | /* Number of struct iscsi_pdu in struct iscsi_cmd->pdu_list */ | ||
410 | u32 pdu_count; | ||
411 | /* Next struct iscsi_pdu to send in struct iscsi_cmd->pdu_list */ | ||
412 | u32 pdu_send_order; | ||
413 | /* Current struct iscsi_pdu in struct iscsi_cmd->pdu_list */ | ||
414 | u32 pdu_start; | ||
415 | /* Next struct iscsi_seq to send in struct iscsi_cmd->seq_list */ | ||
416 | u32 seq_send_order; | ||
417 | /* Number of struct iscsi_seq in struct iscsi_cmd->seq_list */ | ||
418 | u32 seq_count; | ||
419 | /* Current struct iscsi_seq in struct iscsi_cmd->seq_list */ | ||
420 | u32 seq_no; | ||
421 | /* Lowest offset in current DataOUT sequence */ | ||
422 | u32 seq_start_offset; | ||
423 | /* Highest offset in current DataOUT sequence */ | ||
424 | u32 seq_end_offset; | ||
425 | /* Total size in bytes received so far of READ data */ | ||
426 | u32 read_data_done; | ||
427 | /* Total size in bytes received so far of WRITE data */ | ||
428 | u32 write_data_done; | ||
429 | /* Counter for FirstBurstLength key */ | ||
430 | u32 first_burst_len; | ||
431 | /* Counter for MaxBurstLength key */ | ||
432 | u32 next_burst_len; | ||
433 | /* Transfer size used for IP stack calls */ | ||
434 | u32 tx_size; | ||
435 | /* Buffer used for various purposes */ | ||
436 | void *buf_ptr; | ||
437 | /* Used by SendTargets=[iqn.,eui.] discovery */ | ||
438 | void *text_in_ptr; | ||
439 | /* See include/linux/dma-mapping.h */ | ||
440 | enum dma_data_direction data_direction; | ||
441 | /* iSCSI PDU Header + CRC */ | ||
442 | unsigned char pdu[ISCSI_HDR_LEN + ISCSI_CRC_LEN]; | ||
443 | /* Number of times struct iscsi_cmd is present in immediate queue */ | ||
444 | atomic_t immed_queue_count; | ||
445 | atomic_t response_queue_count; | ||
446 | spinlock_t datain_lock; | ||
447 | spinlock_t dataout_timeout_lock; | ||
448 | /* spinlock for protecting struct iscsi_cmd->i_state */ | ||
449 | spinlock_t istate_lock; | ||
450 | /* spinlock for adding within command recovery entries */ | ||
451 | spinlock_t error_lock; | ||
452 | /* spinlock for adding R2Ts */ | ||
453 | spinlock_t r2t_lock; | ||
454 | /* DataIN List */ | ||
455 | struct list_head datain_list; | ||
456 | /* R2T List */ | ||
457 | struct list_head cmd_r2t_list; | ||
458 | /* Timer for DataOUT */ | ||
459 | struct timer_list dataout_timer; | ||
460 | /* Iovecs for SCSI data payload RX/TX w/ kernel level sockets */ | ||
461 | struct kvec *iov_data; | ||
462 | /* Iovecs for miscellaneous purposes */ | ||
463 | #define ISCSI_MISC_IOVECS 5 | ||
464 | struct kvec iov_misc[ISCSI_MISC_IOVECS]; | ||
465 | /* Array of struct iscsi_pdu used for DataPDUInOrder=No */ | ||
466 | struct iscsi_pdu *pdu_list; | ||
467 | /* Current struct iscsi_pdu used for DataPDUInOrder=No */ | ||
468 | struct iscsi_pdu *pdu_ptr; | ||
469 | /* Array of struct iscsi_seq used for DataSequenceInOrder=No */ | ||
470 | struct iscsi_seq *seq_list; | ||
471 | /* Current struct iscsi_seq used for DataSequenceInOrder=No */ | ||
472 | struct iscsi_seq *seq_ptr; | ||
473 | /* TMR Request when iscsi_opcode == ISCSI_OP_SCSI_TMFUNC */ | ||
474 | struct iscsi_tmr_req *tmr_req; | ||
475 | /* Connection this command is alligient to */ | ||
476 | struct iscsi_conn *conn; | ||
477 | /* Pointer to connection recovery entry */ | ||
478 | struct iscsi_conn_recovery *cr; | ||
479 | /* Session the command is part of, used for connection recovery */ | ||
480 | struct iscsi_session *sess; | ||
481 | /* list_head for connection list */ | ||
482 | struct list_head i_conn_node; | ||
483 | /* The TCM I/O descriptor that is accessed via container_of() */ | ||
484 | struct se_cmd se_cmd; | ||
485 | /* Sense buffer that will be mapped into outgoing status */ | ||
486 | #define ISCSI_SENSE_BUFFER_LEN (TRANSPORT_SENSE_BUFFER + 2) | ||
487 | unsigned char sense_buffer[ISCSI_SENSE_BUFFER_LEN]; | ||
488 | |||
489 | u32 padding; | ||
490 | u8 pad_bytes[4]; | ||
491 | |||
492 | struct scatterlist *first_data_sg; | ||
493 | u32 first_data_sg_off; | ||
494 | u32 kmapped_nents; | ||
495 | sense_reason_t sense_reason; | ||
496 | } ____cacheline_aligned; | ||
497 | |||
498 | struct iscsi_tmr_req { | ||
499 | bool task_reassign:1; | ||
500 | u32 exp_data_sn; | ||
501 | struct iscsi_cmd *ref_cmd; | ||
502 | struct iscsi_conn_recovery *conn_recovery; | ||
503 | struct se_tmr_req *se_tmr_req; | ||
504 | }; | ||
505 | |||
506 | struct iscsi_conn { | ||
507 | wait_queue_head_t queues_wq; | ||
508 | /* Authentication Successful for this connection */ | ||
509 | u8 auth_complete; | ||
510 | /* State connection is currently in */ | ||
511 | u8 conn_state; | ||
512 | u8 conn_logout_reason; | ||
513 | u8 network_transport; | ||
514 | enum iscsi_timer_flags_table nopin_timer_flags; | ||
515 | enum iscsi_timer_flags_table nopin_response_timer_flags; | ||
516 | /* Used to know what thread encountered a transport failure */ | ||
517 | u8 which_thread; | ||
518 | /* connection id assigned by the Initiator */ | ||
519 | u16 cid; | ||
520 | /* Remote TCP Port */ | ||
521 | u16 login_port; | ||
522 | u16 local_port; | ||
523 | int net_size; | ||
524 | int login_family; | ||
525 | u32 auth_id; | ||
526 | u32 conn_flags; | ||
527 | /* Used for iscsi_tx_login_rsp() */ | ||
528 | itt_t login_itt; | ||
529 | u32 exp_statsn; | ||
530 | /* Per connection status sequence number */ | ||
531 | u32 stat_sn; | ||
532 | /* IFMarkInt's Current Value */ | ||
533 | u32 if_marker; | ||
534 | /* OFMarkInt's Current Value */ | ||
535 | u32 of_marker; | ||
536 | /* Used for calculating OFMarker offset to next PDU */ | ||
537 | u32 of_marker_offset; | ||
538 | #define IPV6_ADDRESS_SPACE 48 | ||
539 | unsigned char login_ip[IPV6_ADDRESS_SPACE]; | ||
540 | unsigned char local_ip[IPV6_ADDRESS_SPACE]; | ||
541 | int conn_usage_count; | ||
542 | int conn_waiting_on_uc; | ||
543 | atomic_t check_immediate_queue; | ||
544 | atomic_t conn_logout_remove; | ||
545 | atomic_t connection_exit; | ||
546 | atomic_t connection_recovery; | ||
547 | atomic_t connection_reinstatement; | ||
548 | atomic_t connection_wait_rcfr; | ||
549 | atomic_t sleep_on_conn_wait_comp; | ||
550 | atomic_t transport_failed; | ||
551 | struct completion conn_post_wait_comp; | ||
552 | struct completion conn_wait_comp; | ||
553 | struct completion conn_wait_rcfr_comp; | ||
554 | struct completion conn_waiting_on_uc_comp; | ||
555 | struct completion conn_logout_comp; | ||
556 | struct completion tx_half_close_comp; | ||
557 | struct completion rx_half_close_comp; | ||
558 | /* socket used by this connection */ | ||
559 | struct socket *sock; | ||
560 | void (*orig_data_ready)(struct sock *); | ||
561 | void (*orig_state_change)(struct sock *); | ||
562 | #define LOGIN_FLAGS_READ_ACTIVE 1 | ||
563 | #define LOGIN_FLAGS_CLOSED 2 | ||
564 | #define LOGIN_FLAGS_READY 4 | ||
565 | unsigned long login_flags; | ||
566 | struct delayed_work login_work; | ||
567 | struct delayed_work login_cleanup_work; | ||
568 | struct iscsi_login *login; | ||
569 | struct timer_list nopin_timer; | ||
570 | struct timer_list nopin_response_timer; | ||
571 | struct timer_list transport_timer; | ||
572 | struct task_struct *login_kworker; | ||
573 | /* Spinlock used for add/deleting cmd's from conn_cmd_list */ | ||
574 | spinlock_t cmd_lock; | ||
575 | spinlock_t conn_usage_lock; | ||
576 | spinlock_t immed_queue_lock; | ||
577 | spinlock_t nopin_timer_lock; | ||
578 | spinlock_t response_queue_lock; | ||
579 | spinlock_t state_lock; | ||
580 | /* libcrypto RX and TX contexts for crc32c */ | ||
581 | struct hash_desc conn_rx_hash; | ||
582 | struct hash_desc conn_tx_hash; | ||
583 | /* Used for scheduling TX and RX connection kthreads */ | ||
584 | cpumask_var_t conn_cpumask; | ||
585 | unsigned int conn_rx_reset_cpumask:1; | ||
586 | unsigned int conn_tx_reset_cpumask:1; | ||
587 | /* list_head of struct iscsi_cmd for this connection */ | ||
588 | struct list_head conn_cmd_list; | ||
589 | struct list_head immed_queue_list; | ||
590 | struct list_head response_queue_list; | ||
591 | struct iscsi_conn_ops *conn_ops; | ||
592 | struct iscsi_login *conn_login; | ||
593 | struct iscsit_transport *conn_transport; | ||
594 | struct iscsi_param_list *param_list; | ||
595 | /* Used for per connection auth state machine */ | ||
596 | void *auth_protocol; | ||
597 | void *context; | ||
598 | struct iscsi_login_thread_s *login_thread; | ||
599 | struct iscsi_portal_group *tpg; | ||
600 | struct iscsi_tpg_np *tpg_np; | ||
601 | /* Pointer to parent session */ | ||
602 | struct iscsi_session *sess; | ||
603 | /* Pointer to thread_set in use for this conn's threads */ | ||
604 | struct iscsi_thread_set *thread_set; | ||
605 | /* list_head for session connection list */ | ||
606 | struct list_head conn_list; | ||
607 | } ____cacheline_aligned; | ||
608 | |||
609 | struct iscsi_conn_recovery { | ||
610 | u16 cid; | ||
611 | u32 cmd_count; | ||
612 | u32 maxrecvdatasegmentlength; | ||
613 | u32 maxxmitdatasegmentlength; | ||
614 | int ready_for_reallegiance; | ||
615 | struct list_head conn_recovery_cmd_list; | ||
616 | spinlock_t conn_recovery_cmd_lock; | ||
617 | struct timer_list time2retain_timer; | ||
618 | struct iscsi_session *sess; | ||
619 | struct list_head cr_list; | ||
620 | } ____cacheline_aligned; | ||
621 | |||
622 | struct iscsi_session { | ||
623 | u8 initiator_vendor; | ||
624 | u8 isid[6]; | ||
625 | enum iscsi_timer_flags_table time2retain_timer_flags; | ||
626 | u8 version_active; | ||
627 | u16 cid_called; | ||
628 | u16 conn_recovery_count; | ||
629 | u16 tsih; | ||
630 | /* state session is currently in */ | ||
631 | u32 session_state; | ||
632 | /* session wide counter: initiator assigned task tag */ | ||
633 | itt_t init_task_tag; | ||
634 | /* session wide counter: target assigned task tag */ | ||
635 | u32 targ_xfer_tag; | ||
636 | u32 cmdsn_window; | ||
637 | |||
638 | /* protects cmdsn values */ | ||
639 | struct mutex cmdsn_mutex; | ||
640 | /* session wide counter: expected command sequence number */ | ||
641 | u32 exp_cmd_sn; | ||
642 | /* session wide counter: maximum allowed command sequence number */ | ||
643 | u32 max_cmd_sn; | ||
644 | struct list_head sess_ooo_cmdsn_list; | ||
645 | |||
646 | /* LIO specific session ID */ | ||
647 | u32 sid; | ||
648 | char auth_type[8]; | ||
649 | /* unique within the target */ | ||
650 | int session_index; | ||
651 | /* Used for session reference counting */ | ||
652 | int session_usage_count; | ||
653 | int session_waiting_on_uc; | ||
654 | atomic_long_t cmd_pdus; | ||
655 | atomic_long_t rsp_pdus; | ||
656 | atomic_long_t tx_data_octets; | ||
657 | atomic_long_t rx_data_octets; | ||
658 | atomic_long_t conn_digest_errors; | ||
659 | atomic_long_t conn_timeout_errors; | ||
660 | u64 creation_time; | ||
661 | /* Number of active connections */ | ||
662 | atomic_t nconn; | ||
663 | atomic_t session_continuation; | ||
664 | atomic_t session_fall_back_to_erl0; | ||
665 | atomic_t session_logout; | ||
666 | atomic_t session_reinstatement; | ||
667 | atomic_t session_stop_active; | ||
668 | atomic_t sleep_on_sess_wait_comp; | ||
669 | /* connection list */ | ||
670 | struct list_head sess_conn_list; | ||
671 | struct list_head cr_active_list; | ||
672 | struct list_head cr_inactive_list; | ||
673 | spinlock_t conn_lock; | ||
674 | spinlock_t cr_a_lock; | ||
675 | spinlock_t cr_i_lock; | ||
676 | spinlock_t session_usage_lock; | ||
677 | spinlock_t ttt_lock; | ||
678 | struct completion async_msg_comp; | ||
679 | struct completion reinstatement_comp; | ||
680 | struct completion session_wait_comp; | ||
681 | struct completion session_waiting_on_uc_comp; | ||
682 | struct timer_list time2retain_timer; | ||
683 | struct iscsi_sess_ops *sess_ops; | ||
684 | struct se_session *se_sess; | ||
685 | struct iscsi_portal_group *tpg; | ||
686 | } ____cacheline_aligned; | ||
687 | |||
688 | struct iscsi_login { | ||
689 | u8 auth_complete; | ||
690 | u8 checked_for_existing; | ||
691 | u8 current_stage; | ||
692 | u8 leading_connection; | ||
693 | u8 first_request; | ||
694 | u8 version_min; | ||
695 | u8 version_max; | ||
696 | u8 login_complete; | ||
697 | u8 login_failed; | ||
698 | bool zero_tsih; | ||
699 | char isid[6]; | ||
700 | u32 cmd_sn; | ||
701 | itt_t init_task_tag; | ||
702 | u32 initial_exp_statsn; | ||
703 | u32 rsp_length; | ||
704 | u16 cid; | ||
705 | u16 tsih; | ||
706 | char req[ISCSI_HDR_LEN]; | ||
707 | char rsp[ISCSI_HDR_LEN]; | ||
708 | char *req_buf; | ||
709 | char *rsp_buf; | ||
710 | struct iscsi_conn *conn; | ||
711 | struct iscsi_np *np; | ||
712 | } ____cacheline_aligned; | ||
713 | |||
714 | struct iscsi_node_attrib { | ||
715 | u32 dataout_timeout; | ||
716 | u32 dataout_timeout_retries; | ||
717 | u32 default_erl; | ||
718 | u32 nopin_timeout; | ||
719 | u32 nopin_response_timeout; | ||
720 | u32 random_datain_pdu_offsets; | ||
721 | u32 random_datain_seq_offsets; | ||
722 | u32 random_r2t_offsets; | ||
723 | u32 tmr_cold_reset; | ||
724 | u32 tmr_warm_reset; | ||
725 | struct iscsi_node_acl *nacl; | ||
726 | }; | ||
727 | |||
728 | struct se_dev_entry_s; | ||
729 | |||
730 | struct iscsi_node_auth { | ||
731 | enum naf_flags_table naf_flags; | ||
732 | int authenticate_target; | ||
733 | /* Used for iscsit_global->discovery_auth, | ||
734 | * set to zero (auth disabled) by default */ | ||
735 | int enforce_discovery_auth; | ||
736 | #define MAX_USER_LEN 256 | ||
737 | #define MAX_PASS_LEN 256 | ||
738 | char userid[MAX_USER_LEN]; | ||
739 | char password[MAX_PASS_LEN]; | ||
740 | char userid_mutual[MAX_USER_LEN]; | ||
741 | char password_mutual[MAX_PASS_LEN]; | ||
742 | }; | ||
743 | |||
744 | #include "iscsi_target_stat.h" | ||
745 | |||
746 | struct iscsi_node_stat_grps { | ||
747 | struct config_group iscsi_sess_stats_group; | ||
748 | struct config_group iscsi_conn_stats_group; | ||
749 | }; | ||
750 | |||
751 | struct iscsi_node_acl { | ||
752 | struct iscsi_node_attrib node_attrib; | ||
753 | struct iscsi_node_auth node_auth; | ||
754 | struct iscsi_node_stat_grps node_stat_grps; | ||
755 | struct se_node_acl se_node_acl; | ||
756 | }; | ||
757 | |||
758 | struct iscsi_tpg_attrib { | ||
759 | u32 authentication; | ||
760 | u32 login_timeout; | ||
761 | u32 netif_timeout; | ||
762 | u32 generate_node_acls; | ||
763 | u32 cache_dynamic_acls; | ||
764 | u32 default_cmdsn_depth; | ||
765 | u32 demo_mode_write_protect; | ||
766 | u32 prod_mode_write_protect; | ||
767 | u32 demo_mode_discovery; | ||
768 | u32 default_erl; | ||
769 | u8 t10_pi; | ||
770 | struct iscsi_portal_group *tpg; | ||
771 | }; | ||
772 | |||
773 | struct iscsi_np { | ||
774 | int np_network_transport; | ||
775 | int np_ip_proto; | ||
776 | int np_sock_type; | ||
777 | enum np_thread_state_table np_thread_state; | ||
778 | bool enabled; | ||
779 | enum iscsi_timer_flags_table np_login_timer_flags; | ||
780 | u32 np_exports; | ||
781 | enum np_flags_table np_flags; | ||
782 | unsigned char np_ip[IPV6_ADDRESS_SPACE]; | ||
783 | u16 np_port; | ||
784 | spinlock_t np_thread_lock; | ||
785 | struct completion np_restart_comp; | ||
786 | struct socket *np_socket; | ||
787 | struct __kernel_sockaddr_storage np_sockaddr; | ||
788 | struct task_struct *np_thread; | ||
789 | struct timer_list np_login_timer; | ||
790 | void *np_context; | ||
791 | struct iscsit_transport *np_transport; | ||
792 | struct list_head np_list; | ||
793 | } ____cacheline_aligned; | ||
794 | |||
795 | struct iscsi_tpg_np { | ||
796 | struct iscsi_np *tpg_np; | ||
797 | struct iscsi_portal_group *tpg; | ||
798 | struct iscsi_tpg_np *tpg_np_parent; | ||
799 | struct list_head tpg_np_list; | ||
800 | struct list_head tpg_np_child_list; | ||
801 | struct list_head tpg_np_parent_list; | ||
802 | struct se_tpg_np se_tpg_np; | ||
803 | spinlock_t tpg_np_parent_lock; | ||
804 | struct completion tpg_np_comp; | ||
805 | struct kref tpg_np_kref; | ||
806 | }; | ||
807 | |||
808 | struct iscsi_portal_group { | ||
809 | unsigned char tpg_chap_id; | ||
810 | /* TPG State */ | ||
811 | enum tpg_state_table tpg_state; | ||
812 | /* Target Portal Group Tag */ | ||
813 | u16 tpgt; | ||
814 | /* Id assigned to target sessions */ | ||
815 | u16 ntsih; | ||
816 | /* Number of active sessions */ | ||
817 | u32 nsessions; | ||
818 | /* Number of Network Portals available for this TPG */ | ||
819 | u32 num_tpg_nps; | ||
820 | /* Per TPG LIO specific session ID. */ | ||
821 | u32 sid; | ||
822 | /* Spinlock for adding/removing Network Portals */ | ||
823 | spinlock_t tpg_np_lock; | ||
824 | spinlock_t tpg_state_lock; | ||
825 | struct se_portal_group tpg_se_tpg; | ||
826 | struct mutex tpg_access_lock; | ||
827 | struct semaphore np_login_sem; | ||
828 | struct iscsi_tpg_attrib tpg_attrib; | ||
829 | struct iscsi_node_auth tpg_demo_auth; | ||
830 | /* Pointer to default list of iSCSI parameters for TPG */ | ||
831 | struct iscsi_param_list *param_list; | ||
832 | struct iscsi_tiqn *tpg_tiqn; | ||
833 | struct list_head tpg_gnp_list; | ||
834 | struct list_head tpg_list; | ||
835 | } ____cacheline_aligned; | ||
836 | |||
837 | struct iscsi_wwn_stat_grps { | ||
838 | struct config_group iscsi_stat_group; | ||
839 | struct config_group iscsi_instance_group; | ||
840 | struct config_group iscsi_sess_err_group; | ||
841 | struct config_group iscsi_tgt_attr_group; | ||
842 | struct config_group iscsi_login_stats_group; | ||
843 | struct config_group iscsi_logout_stats_group; | ||
844 | }; | ||
845 | |||
846 | struct iscsi_tiqn { | ||
847 | #define ISCSI_IQN_LEN 224 | ||
848 | unsigned char tiqn[ISCSI_IQN_LEN]; | ||
849 | enum tiqn_state_table tiqn_state; | ||
850 | int tiqn_access_count; | ||
851 | u32 tiqn_active_tpgs; | ||
852 | u32 tiqn_ntpgs; | ||
853 | u32 tiqn_num_tpg_nps; | ||
854 | u32 tiqn_nsessions; | ||
855 | struct list_head tiqn_list; | ||
856 | struct list_head tiqn_tpg_list; | ||
857 | spinlock_t tiqn_state_lock; | ||
858 | spinlock_t tiqn_tpg_lock; | ||
859 | struct se_wwn tiqn_wwn; | ||
860 | struct iscsi_wwn_stat_grps tiqn_stat_grps; | ||
861 | int tiqn_index; | ||
862 | struct iscsi_sess_err_stats sess_err_stats; | ||
863 | struct iscsi_login_stats login_stats; | ||
864 | struct iscsi_logout_stats logout_stats; | ||
865 | } ____cacheline_aligned; | ||
866 | |||
867 | struct iscsit_global { | ||
868 | /* In core shutdown */ | ||
869 | u32 in_shutdown; | ||
870 | u32 active_ts; | ||
871 | /* Unique identifier used for the authentication daemon */ | ||
872 | u32 auth_id; | ||
873 | u32 inactive_ts; | ||
874 | /* Thread Set bitmap count */ | ||
875 | int ts_bitmap_count; | ||
876 | /* Thread Set bitmap pointer */ | ||
877 | unsigned long *ts_bitmap; | ||
878 | /* Used for iSCSI discovery session authentication */ | ||
879 | struct iscsi_node_acl discovery_acl; | ||
880 | struct iscsi_portal_group *discovery_tpg; | ||
881 | }; | ||
882 | |||
883 | #endif /* ISCSI_TARGET_CORE_H */ | ||
diff --git a/drivers/target/iscsi/iscsi_target_datain_values.c b/drivers/target/iscsi/iscsi_target_datain_values.c index e93d5a7a3f81..fb3b52b124ac 100644 --- a/drivers/target/iscsi/iscsi_target_datain_values.c +++ b/drivers/target/iscsi/iscsi_target_datain_values.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <scsi/iscsi_proto.h> | 19 | #include <scsi/iscsi_proto.h> |
20 | 20 | ||
21 | #include "iscsi_target_core.h" | 21 | #include <target/iscsi/iscsi_target_core.h> |
22 | #include "iscsi_target_seq_pdu_list.h" | 22 | #include "iscsi_target_seq_pdu_list.h" |
23 | #include "iscsi_target_erl1.h" | 23 | #include "iscsi_target_erl1.h" |
24 | #include "iscsi_target_util.h" | 24 | #include "iscsi_target_util.h" |
diff --git a/drivers/target/iscsi/iscsi_target_device.c b/drivers/target/iscsi/iscsi_target_device.c index 7087c736daa5..34c3cd1b05ce 100644 --- a/drivers/target/iscsi/iscsi_target_device.c +++ b/drivers/target/iscsi/iscsi_target_device.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include <target/target_core_base.h> | 21 | #include <target/target_core_base.h> |
22 | #include <target/target_core_fabric.h> | 22 | #include <target/target_core_fabric.h> |
23 | 23 | ||
24 | #include "iscsi_target_core.h" | 24 | #include <target/iscsi/iscsi_target_core.h> |
25 | #include "iscsi_target_device.h" | 25 | #include "iscsi_target_device.h" |
26 | #include "iscsi_target_tpg.h" | 26 | #include "iscsi_target_tpg.h" |
27 | #include "iscsi_target_util.h" | 27 | #include "iscsi_target_util.h" |
diff --git a/drivers/target/iscsi/iscsi_target_erl0.c b/drivers/target/iscsi/iscsi_target_erl0.c index a0ae5fc0ad75..1c197bad6132 100644 --- a/drivers/target/iscsi/iscsi_target_erl0.c +++ b/drivers/target/iscsi/iscsi_target_erl0.c | |||
@@ -21,7 +21,8 @@ | |||
21 | #include <target/target_core_base.h> | 21 | #include <target/target_core_base.h> |
22 | #include <target/target_core_fabric.h> | 22 | #include <target/target_core_fabric.h> |
23 | 23 | ||
24 | #include "iscsi_target_core.h" | 24 | #include <target/iscsi/iscsi_target_core.h> |
25 | #include <target/iscsi/iscsi_transport.h> | ||
25 | #include "iscsi_target_seq_pdu_list.h" | 26 | #include "iscsi_target_seq_pdu_list.h" |
26 | #include "iscsi_target_tq.h" | 27 | #include "iscsi_target_tq.h" |
27 | #include "iscsi_target_erl0.h" | 28 | #include "iscsi_target_erl0.h" |
@@ -939,7 +940,8 @@ void iscsit_take_action_for_connection_exit(struct iscsi_conn *conn) | |||
939 | 940 | ||
940 | if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) { | 941 | if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) { |
941 | spin_unlock_bh(&conn->state_lock); | 942 | spin_unlock_bh(&conn->state_lock); |
942 | iscsit_close_connection(conn); | 943 | if (conn->conn_transport->transport_type == ISCSI_TCP) |
944 | iscsit_close_connection(conn); | ||
943 | return; | 945 | return; |
944 | } | 946 | } |
945 | 947 | ||
diff --git a/drivers/target/iscsi/iscsi_target_erl1.c b/drivers/target/iscsi/iscsi_target_erl1.c index cda4d80cfaef..2e561deb30a2 100644 --- a/drivers/target/iscsi/iscsi_target_erl1.c +++ b/drivers/target/iscsi/iscsi_target_erl1.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <target/target_core_fabric.h> | 22 | #include <target/target_core_fabric.h> |
23 | #include <target/iscsi/iscsi_transport.h> | 23 | #include <target/iscsi/iscsi_transport.h> |
24 | 24 | ||
25 | #include "iscsi_target_core.h" | 25 | #include <target/iscsi/iscsi_target_core.h> |
26 | #include "iscsi_target_seq_pdu_list.h" | 26 | #include "iscsi_target_seq_pdu_list.h" |
27 | #include "iscsi_target_datain_values.h" | 27 | #include "iscsi_target_datain_values.h" |
28 | #include "iscsi_target_device.h" | 28 | #include "iscsi_target_device.h" |
diff --git a/drivers/target/iscsi/iscsi_target_erl2.c b/drivers/target/iscsi/iscsi_target_erl2.c index 4ca8fd2a70db..e24f1c7c5862 100644 --- a/drivers/target/iscsi/iscsi_target_erl2.c +++ b/drivers/target/iscsi/iscsi_target_erl2.c | |||
@@ -21,7 +21,7 @@ | |||
21 | #include <target/target_core_base.h> | 21 | #include <target/target_core_base.h> |
22 | #include <target/target_core_fabric.h> | 22 | #include <target/target_core_fabric.h> |
23 | 23 | ||
24 | #include "iscsi_target_core.h" | 24 | #include <target/iscsi/iscsi_target_core.h> |
25 | #include "iscsi_target_datain_values.h" | 25 | #include "iscsi_target_datain_values.h" |
26 | #include "iscsi_target_util.h" | 26 | #include "iscsi_target_util.h" |
27 | #include "iscsi_target_erl0.h" | 27 | #include "iscsi_target_erl0.h" |
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 713c0c1877ab..153fb66ac1b8 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c | |||
@@ -24,14 +24,14 @@ | |||
24 | #include <target/target_core_base.h> | 24 | #include <target/target_core_base.h> |
25 | #include <target/target_core_fabric.h> | 25 | #include <target/target_core_fabric.h> |
26 | 26 | ||
27 | #include "iscsi_target_core.h" | 27 | #include <target/iscsi/iscsi_target_core.h> |
28 | #include <target/iscsi/iscsi_target_stat.h> | ||
28 | #include "iscsi_target_tq.h" | 29 | #include "iscsi_target_tq.h" |
29 | #include "iscsi_target_device.h" | 30 | #include "iscsi_target_device.h" |
30 | #include "iscsi_target_nego.h" | 31 | #include "iscsi_target_nego.h" |
31 | #include "iscsi_target_erl0.h" | 32 | #include "iscsi_target_erl0.h" |
32 | #include "iscsi_target_erl2.h" | 33 | #include "iscsi_target_erl2.h" |
33 | #include "iscsi_target_login.h" | 34 | #include "iscsi_target_login.h" |
34 | #include "iscsi_target_stat.h" | ||
35 | #include "iscsi_target_tpg.h" | 35 | #include "iscsi_target_tpg.h" |
36 | #include "iscsi_target_util.h" | 36 | #include "iscsi_target_util.h" |
37 | #include "iscsi_target.h" | 37 | #include "iscsi_target.h" |
diff --git a/drivers/target/iscsi/iscsi_target_nego.c b/drivers/target/iscsi/iscsi_target_nego.c index 62a095f36bf2..8c02fa34716f 100644 --- a/drivers/target/iscsi/iscsi_target_nego.c +++ b/drivers/target/iscsi/iscsi_target_nego.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <target/target_core_fabric.h> | 22 | #include <target/target_core_fabric.h> |
23 | #include <target/iscsi/iscsi_transport.h> | 23 | #include <target/iscsi/iscsi_transport.h> |
24 | 24 | ||
25 | #include "iscsi_target_core.h" | 25 | #include <target/iscsi/iscsi_target_core.h> |
26 | #include "iscsi_target_parameters.h" | 26 | #include "iscsi_target_parameters.h" |
27 | #include "iscsi_target_login.h" | 27 | #include "iscsi_target_login.h" |
28 | #include "iscsi_target_nego.h" | 28 | #include "iscsi_target_nego.h" |
diff --git a/drivers/target/iscsi/iscsi_target_nodeattrib.c b/drivers/target/iscsi/iscsi_target_nodeattrib.c index 16454a922e2b..208cca8a363c 100644 --- a/drivers/target/iscsi/iscsi_target_nodeattrib.c +++ b/drivers/target/iscsi/iscsi_target_nodeattrib.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <target/target_core_base.h> | 19 | #include <target/target_core_base.h> |
20 | 20 | ||
21 | #include "iscsi_target_core.h" | 21 | #include <target/iscsi/iscsi_target_core.h> |
22 | #include "iscsi_target_device.h" | 22 | #include "iscsi_target_device.h" |
23 | #include "iscsi_target_tpg.h" | 23 | #include "iscsi_target_tpg.h" |
24 | #include "iscsi_target_util.h" | 24 | #include "iscsi_target_util.h" |
diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c index 18c29260b4a2..d4f9e9645697 100644 --- a/drivers/target/iscsi/iscsi_target_parameters.c +++ b/drivers/target/iscsi/iscsi_target_parameters.c | |||
@@ -18,7 +18,7 @@ | |||
18 | 18 | ||
19 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
20 | 20 | ||
21 | #include "iscsi_target_core.h" | 21 | #include <target/iscsi/iscsi_target_core.h> |
22 | #include "iscsi_target_util.h" | 22 | #include "iscsi_target_util.h" |
23 | #include "iscsi_target_parameters.h" | 23 | #include "iscsi_target_parameters.h" |
24 | 24 | ||
diff --git a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c index ca41b583f2f6..e446a09c886b 100644 --- a/drivers/target/iscsi/iscsi_target_seq_pdu_list.c +++ b/drivers/target/iscsi/iscsi_target_seq_pdu_list.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/random.h> | 21 | #include <linux/random.h> |
22 | 22 | ||
23 | #include "iscsi_target_core.h" | 23 | #include <target/iscsi/iscsi_target_core.h> |
24 | #include "iscsi_target_util.h" | 24 | #include "iscsi_target_util.h" |
25 | #include "iscsi_target_tpg.h" | 25 | #include "iscsi_target_tpg.h" |
26 | #include "iscsi_target_seq_pdu_list.h" | 26 | #include "iscsi_target_seq_pdu_list.h" |
diff --git a/drivers/target/iscsi/iscsi_target_stat.c b/drivers/target/iscsi/iscsi_target_stat.c index 103395510307..5e1349a3b143 100644 --- a/drivers/target/iscsi/iscsi_target_stat.c +++ b/drivers/target/iscsi/iscsi_target_stat.c | |||
@@ -23,12 +23,12 @@ | |||
23 | #include <target/target_core_base.h> | 23 | #include <target/target_core_base.h> |
24 | #include <target/configfs_macros.h> | 24 | #include <target/configfs_macros.h> |
25 | 25 | ||
26 | #include "iscsi_target_core.h" | 26 | #include <target/iscsi/iscsi_target_core.h> |
27 | #include "iscsi_target_parameters.h" | 27 | #include "iscsi_target_parameters.h" |
28 | #include "iscsi_target_device.h" | 28 | #include "iscsi_target_device.h" |
29 | #include "iscsi_target_tpg.h" | 29 | #include "iscsi_target_tpg.h" |
30 | #include "iscsi_target_util.h" | 30 | #include "iscsi_target_util.h" |
31 | #include "iscsi_target_stat.h" | 31 | #include <target/iscsi/iscsi_target_stat.h> |
32 | 32 | ||
33 | #ifndef INITIAL_JIFFIES | 33 | #ifndef INITIAL_JIFFIES |
34 | #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ)) | 34 | #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ)) |
diff --git a/drivers/target/iscsi/iscsi_target_stat.h b/drivers/target/iscsi/iscsi_target_stat.h deleted file mode 100644 index 3ff76b4faad3..000000000000 --- a/drivers/target/iscsi/iscsi_target_stat.h +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | #ifndef ISCSI_TARGET_STAT_H | ||
2 | #define ISCSI_TARGET_STAT_H | ||
3 | |||
4 | /* | ||
5 | * For struct iscsi_tiqn->tiqn_wwn default groups | ||
6 | */ | ||
7 | extern struct config_item_type iscsi_stat_instance_cit; | ||
8 | extern struct config_item_type iscsi_stat_sess_err_cit; | ||
9 | extern struct config_item_type iscsi_stat_tgt_attr_cit; | ||
10 | extern struct config_item_type iscsi_stat_login_cit; | ||
11 | extern struct config_item_type iscsi_stat_logout_cit; | ||
12 | |||
13 | /* | ||
14 | * For struct iscsi_session->se_sess default groups | ||
15 | */ | ||
16 | extern struct config_item_type iscsi_stat_sess_cit; | ||
17 | |||
18 | /* iSCSI session error types */ | ||
19 | #define ISCSI_SESS_ERR_UNKNOWN 0 | ||
20 | #define ISCSI_SESS_ERR_DIGEST 1 | ||
21 | #define ISCSI_SESS_ERR_CXN_TIMEOUT 2 | ||
22 | #define ISCSI_SESS_ERR_PDU_FORMAT 3 | ||
23 | |||
24 | /* iSCSI session error stats */ | ||
25 | struct iscsi_sess_err_stats { | ||
26 | spinlock_t lock; | ||
27 | u32 digest_errors; | ||
28 | u32 cxn_timeout_errors; | ||
29 | u32 pdu_format_errors; | ||
30 | u32 last_sess_failure_type; | ||
31 | char last_sess_fail_rem_name[224]; | ||
32 | } ____cacheline_aligned; | ||
33 | |||
34 | /* iSCSI login failure types (sub oids) */ | ||
35 | #define ISCSI_LOGIN_FAIL_OTHER 2 | ||
36 | #define ISCSI_LOGIN_FAIL_REDIRECT 3 | ||
37 | #define ISCSI_LOGIN_FAIL_AUTHORIZE 4 | ||
38 | #define ISCSI_LOGIN_FAIL_AUTHENTICATE 5 | ||
39 | #define ISCSI_LOGIN_FAIL_NEGOTIATE 6 | ||
40 | |||
41 | /* iSCSI login stats */ | ||
42 | struct iscsi_login_stats { | ||
43 | spinlock_t lock; | ||
44 | u32 accepts; | ||
45 | u32 other_fails; | ||
46 | u32 redirects; | ||
47 | u32 authorize_fails; | ||
48 | u32 authenticate_fails; | ||
49 | u32 negotiate_fails; /* used for notifications */ | ||
50 | u64 last_fail_time; /* time stamp (jiffies) */ | ||
51 | u32 last_fail_type; | ||
52 | int last_intr_fail_ip_family; | ||
53 | unsigned char last_intr_fail_ip_addr[IPV6_ADDRESS_SPACE]; | ||
54 | char last_intr_fail_name[224]; | ||
55 | } ____cacheline_aligned; | ||
56 | |||
57 | /* iSCSI logout stats */ | ||
58 | struct iscsi_logout_stats { | ||
59 | spinlock_t lock; | ||
60 | u32 normal_logouts; | ||
61 | u32 abnormal_logouts; | ||
62 | } ____cacheline_aligned; | ||
63 | |||
64 | #endif /*** ISCSI_TARGET_STAT_H ***/ | ||
diff --git a/drivers/target/iscsi/iscsi_target_tmr.c b/drivers/target/iscsi/iscsi_target_tmr.c index 78404b1cc0bf..b0224a77e26d 100644 --- a/drivers/target/iscsi/iscsi_target_tmr.c +++ b/drivers/target/iscsi/iscsi_target_tmr.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include <target/target_core_fabric.h> | 23 | #include <target/target_core_fabric.h> |
24 | #include <target/iscsi/iscsi_transport.h> | 24 | #include <target/iscsi/iscsi_transport.h> |
25 | 25 | ||
26 | #include "iscsi_target_core.h" | 26 | #include <target/iscsi/iscsi_target_core.h> |
27 | #include "iscsi_target_seq_pdu_list.h" | 27 | #include "iscsi_target_seq_pdu_list.h" |
28 | #include "iscsi_target_datain_values.h" | 28 | #include "iscsi_target_datain_values.h" |
29 | #include "iscsi_target_device.h" | 29 | #include "iscsi_target_device.h" |
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c index 9053a3c0c6e5..bdd127c0e3ae 100644 --- a/drivers/target/iscsi/iscsi_target_tpg.c +++ b/drivers/target/iscsi/iscsi_target_tpg.c | |||
@@ -20,7 +20,7 @@ | |||
20 | #include <target/target_core_fabric.h> | 20 | #include <target/target_core_fabric.h> |
21 | #include <target/target_core_configfs.h> | 21 | #include <target/target_core_configfs.h> |
22 | 22 | ||
23 | #include "iscsi_target_core.h" | 23 | #include <target/iscsi/iscsi_target_core.h> |
24 | #include "iscsi_target_erl0.h" | 24 | #include "iscsi_target_erl0.h" |
25 | #include "iscsi_target_login.h" | 25 | #include "iscsi_target_login.h" |
26 | #include "iscsi_target_nodeattrib.h" | 26 | #include "iscsi_target_nodeattrib.h" |
diff --git a/drivers/target/iscsi/iscsi_target_tq.c b/drivers/target/iscsi/iscsi_target_tq.c index 601e9cc61e98..26aa50996473 100644 --- a/drivers/target/iscsi/iscsi_target_tq.c +++ b/drivers/target/iscsi/iscsi_target_tq.c | |||
@@ -20,40 +20,26 @@ | |||
20 | #include <linux/list.h> | 20 | #include <linux/list.h> |
21 | #include <linux/bitmap.h> | 21 | #include <linux/bitmap.h> |
22 | 22 | ||
23 | #include "iscsi_target_core.h" | 23 | #include <target/iscsi/iscsi_target_core.h> |
24 | #include "iscsi_target_tq.h" | 24 | #include "iscsi_target_tq.h" |
25 | #include "iscsi_target.h" | 25 | #include "iscsi_target.h" |
26 | 26 | ||
27 | static LIST_HEAD(active_ts_list); | ||
28 | static LIST_HEAD(inactive_ts_list); | 27 | static LIST_HEAD(inactive_ts_list); |
29 | static DEFINE_SPINLOCK(active_ts_lock); | ||
30 | static DEFINE_SPINLOCK(inactive_ts_lock); | 28 | static DEFINE_SPINLOCK(inactive_ts_lock); |
31 | static DEFINE_SPINLOCK(ts_bitmap_lock); | 29 | static DEFINE_SPINLOCK(ts_bitmap_lock); |
32 | 30 | ||
33 | static void iscsi_add_ts_to_active_list(struct iscsi_thread_set *ts) | ||
34 | { | ||
35 | spin_lock(&active_ts_lock); | ||
36 | list_add_tail(&ts->ts_list, &active_ts_list); | ||
37 | iscsit_global->active_ts++; | ||
38 | spin_unlock(&active_ts_lock); | ||
39 | } | ||
40 | |||
41 | static void iscsi_add_ts_to_inactive_list(struct iscsi_thread_set *ts) | 31 | static void iscsi_add_ts_to_inactive_list(struct iscsi_thread_set *ts) |
42 | { | 32 | { |
33 | if (!list_empty(&ts->ts_list)) { | ||
34 | WARN_ON(1); | ||
35 | return; | ||
36 | } | ||
43 | spin_lock(&inactive_ts_lock); | 37 | spin_lock(&inactive_ts_lock); |
44 | list_add_tail(&ts->ts_list, &inactive_ts_list); | 38 | list_add_tail(&ts->ts_list, &inactive_ts_list); |
45 | iscsit_global->inactive_ts++; | 39 | iscsit_global->inactive_ts++; |
46 | spin_unlock(&inactive_ts_lock); | 40 | spin_unlock(&inactive_ts_lock); |
47 | } | 41 | } |
48 | 42 | ||
49 | static void iscsi_del_ts_from_active_list(struct iscsi_thread_set *ts) | ||
50 | { | ||
51 | spin_lock(&active_ts_lock); | ||
52 | list_del(&ts->ts_list); | ||
53 | iscsit_global->active_ts--; | ||
54 | spin_unlock(&active_ts_lock); | ||
55 | } | ||
56 | |||
57 | static struct iscsi_thread_set *iscsi_get_ts_from_inactive_list(void) | 43 | static struct iscsi_thread_set *iscsi_get_ts_from_inactive_list(void) |
58 | { | 44 | { |
59 | struct iscsi_thread_set *ts; | 45 | struct iscsi_thread_set *ts; |
@@ -66,7 +52,7 @@ static struct iscsi_thread_set *iscsi_get_ts_from_inactive_list(void) | |||
66 | 52 | ||
67 | ts = list_first_entry(&inactive_ts_list, struct iscsi_thread_set, ts_list); | 53 | ts = list_first_entry(&inactive_ts_list, struct iscsi_thread_set, ts_list); |
68 | 54 | ||
69 | list_del(&ts->ts_list); | 55 | list_del_init(&ts->ts_list); |
70 | iscsit_global->inactive_ts--; | 56 | iscsit_global->inactive_ts--; |
71 | spin_unlock(&inactive_ts_lock); | 57 | spin_unlock(&inactive_ts_lock); |
72 | 58 | ||
@@ -204,8 +190,6 @@ static void iscsi_deallocate_extra_thread_sets(void) | |||
204 | 190 | ||
205 | void iscsi_activate_thread_set(struct iscsi_conn *conn, struct iscsi_thread_set *ts) | 191 | void iscsi_activate_thread_set(struct iscsi_conn *conn, struct iscsi_thread_set *ts) |
206 | { | 192 | { |
207 | iscsi_add_ts_to_active_list(ts); | ||
208 | |||
209 | spin_lock_bh(&ts->ts_state_lock); | 193 | spin_lock_bh(&ts->ts_state_lock); |
210 | conn->thread_set = ts; | 194 | conn->thread_set = ts; |
211 | ts->conn = conn; | 195 | ts->conn = conn; |
@@ -397,7 +381,6 @@ struct iscsi_conn *iscsi_rx_thread_pre_handler(struct iscsi_thread_set *ts) | |||
397 | 381 | ||
398 | if (ts->delay_inactive && (--ts->thread_count == 0)) { | 382 | if (ts->delay_inactive && (--ts->thread_count == 0)) { |
399 | spin_unlock_bh(&ts->ts_state_lock); | 383 | spin_unlock_bh(&ts->ts_state_lock); |
400 | iscsi_del_ts_from_active_list(ts); | ||
401 | 384 | ||
402 | if (!iscsit_global->in_shutdown) | 385 | if (!iscsit_global->in_shutdown) |
403 | iscsi_deallocate_extra_thread_sets(); | 386 | iscsi_deallocate_extra_thread_sets(); |
@@ -452,7 +435,6 @@ struct iscsi_conn *iscsi_tx_thread_pre_handler(struct iscsi_thread_set *ts) | |||
452 | 435 | ||
453 | if (ts->delay_inactive && (--ts->thread_count == 0)) { | 436 | if (ts->delay_inactive && (--ts->thread_count == 0)) { |
454 | spin_unlock_bh(&ts->ts_state_lock); | 437 | spin_unlock_bh(&ts->ts_state_lock); |
455 | iscsi_del_ts_from_active_list(ts); | ||
456 | 438 | ||
457 | if (!iscsit_global->in_shutdown) | 439 | if (!iscsit_global->in_shutdown) |
458 | iscsi_deallocate_extra_thread_sets(); | 440 | iscsi_deallocate_extra_thread_sets(); |
diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index bcd88ec99793..390df8ed72b2 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <target/target_core_configfs.h> | 25 | #include <target/target_core_configfs.h> |
26 | #include <target/iscsi/iscsi_transport.h> | 26 | #include <target/iscsi/iscsi_transport.h> |
27 | 27 | ||
28 | #include "iscsi_target_core.h" | 28 | #include <target/iscsi/iscsi_target_core.h> |
29 | #include "iscsi_target_parameters.h" | 29 | #include "iscsi_target_parameters.h" |
30 | #include "iscsi_target_seq_pdu_list.h" | 30 | #include "iscsi_target_seq_pdu_list.h" |
31 | #include "iscsi_target_datain_values.h" | 31 | #include "iscsi_target_datain_values.h" |
@@ -390,6 +390,7 @@ struct iscsi_cmd *iscsit_find_cmd_from_itt( | |||
390 | init_task_tag, conn->cid); | 390 | init_task_tag, conn->cid); |
391 | return NULL; | 391 | return NULL; |
392 | } | 392 | } |
393 | EXPORT_SYMBOL(iscsit_find_cmd_from_itt); | ||
393 | 394 | ||
394 | struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump( | 395 | struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump( |
395 | struct iscsi_conn *conn, | 396 | struct iscsi_conn *conn, |
@@ -939,13 +940,8 @@ static int iscsit_add_nopin(struct iscsi_conn *conn, int want_response) | |||
939 | state = (want_response) ? ISTATE_SEND_NOPIN_WANT_RESPONSE : | 940 | state = (want_response) ? ISTATE_SEND_NOPIN_WANT_RESPONSE : |
940 | ISTATE_SEND_NOPIN_NO_RESPONSE; | 941 | ISTATE_SEND_NOPIN_NO_RESPONSE; |
941 | cmd->init_task_tag = RESERVED_ITT; | 942 | cmd->init_task_tag = RESERVED_ITT; |
942 | spin_lock_bh(&conn->sess->ttt_lock); | 943 | cmd->targ_xfer_tag = (want_response) ? |
943 | cmd->targ_xfer_tag = (want_response) ? conn->sess->targ_xfer_tag++ : | 944 | session_get_next_ttt(conn->sess) : 0xFFFFFFFF; |
944 | 0xFFFFFFFF; | ||
945 | if (want_response && (cmd->targ_xfer_tag == 0xFFFFFFFF)) | ||
946 | cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; | ||
947 | spin_unlock_bh(&conn->sess->ttt_lock); | ||
948 | |||
949 | spin_lock_bh(&conn->cmd_lock); | 945 | spin_lock_bh(&conn->cmd_lock); |
950 | list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); | 946 | list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); |
951 | spin_unlock_bh(&conn->cmd_lock); | 947 | spin_unlock_bh(&conn->cmd_lock); |
diff --git a/drivers/target/iscsi/iscsi_target_util.h b/drivers/target/iscsi/iscsi_target_util.h index a68508c4fec8..1ab754a671ff 100644 --- a/drivers/target/iscsi/iscsi_target_util.h +++ b/drivers/target/iscsi/iscsi_target_util.h | |||
@@ -16,7 +16,6 @@ extern struct iscsi_r2t *iscsit_get_holder_for_r2tsn(struct iscsi_cmd *, u32); | |||
16 | extern int iscsit_sequence_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, | 16 | extern int iscsit_sequence_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, |
17 | unsigned char * ,__be32 cmdsn); | 17 | unsigned char * ,__be32 cmdsn); |
18 | extern int iscsit_check_unsolicited_dataout(struct iscsi_cmd *, unsigned char *); | 18 | extern int iscsit_check_unsolicited_dataout(struct iscsi_cmd *, unsigned char *); |
19 | extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t); | ||
20 | extern struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump(struct iscsi_conn *, | 19 | extern struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump(struct iscsi_conn *, |
21 | itt_t, u32); | 20 | itt_t, u32); |
22 | extern struct iscsi_cmd *iscsit_find_cmd_from_ttt(struct iscsi_conn *, u32); | 21 | extern struct iscsi_cmd *iscsit_find_cmd_from_ttt(struct iscsi_conn *, u32); |
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c index d836de200a03..44620fb6bd45 100644 --- a/drivers/target/target_core_file.c +++ b/drivers/target/target_core_file.c | |||
@@ -494,6 +494,11 @@ fd_execute_write_same(struct se_cmd *cmd) | |||
494 | target_complete_cmd(cmd, SAM_STAT_GOOD); | 494 | target_complete_cmd(cmd, SAM_STAT_GOOD); |
495 | return 0; | 495 | return 0; |
496 | } | 496 | } |
497 | if (cmd->prot_op) { | ||
498 | pr_err("WRITE_SAME: Protection information with FILEIO" | ||
499 | " backends not supported\n"); | ||
500 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | ||
501 | } | ||
497 | sg = &cmd->t_data_sg[0]; | 502 | sg = &cmd->t_data_sg[0]; |
498 | 503 | ||
499 | if (cmd->t_data_nents > 1 || | 504 | if (cmd->t_data_nents > 1 || |
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c index 78346b850968..d4a4b0fb444a 100644 --- a/drivers/target/target_core_iblock.c +++ b/drivers/target/target_core_iblock.c | |||
@@ -464,6 +464,11 @@ iblock_execute_write_same(struct se_cmd *cmd) | |||
464 | sector_t block_lba = cmd->t_task_lba; | 464 | sector_t block_lba = cmd->t_task_lba; |
465 | sector_t sectors = sbc_get_write_same_sectors(cmd); | 465 | sector_t sectors = sbc_get_write_same_sectors(cmd); |
466 | 466 | ||
467 | if (cmd->prot_op) { | ||
468 | pr_err("WRITE_SAME: Protection information with IBLOCK" | ||
469 | " backends not supported\n"); | ||
470 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | ||
471 | } | ||
467 | sg = &cmd->t_data_sg[0]; | 472 | sg = &cmd->t_data_sg[0]; |
468 | 473 | ||
469 | if (cmd->t_data_nents > 1 || | 474 | if (cmd->t_data_nents > 1 || |
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c index 283cf786ef98..2de6fb8cee8d 100644 --- a/drivers/target/target_core_pr.c +++ b/drivers/target/target_core_pr.c | |||
@@ -1874,8 +1874,8 @@ static int core_scsi3_update_aptpl_buf( | |||
1874 | } | 1874 | } |
1875 | 1875 | ||
1876 | if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { | 1876 | if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { |
1877 | pr_err("Unable to update renaming" | 1877 | pr_err("Unable to update renaming APTPL metadata," |
1878 | " APTPL metadata\n"); | 1878 | " reallocating larger buffer\n"); |
1879 | ret = -EMSGSIZE; | 1879 | ret = -EMSGSIZE; |
1880 | goto out; | 1880 | goto out; |
1881 | } | 1881 | } |
@@ -1892,8 +1892,8 @@ static int core_scsi3_update_aptpl_buf( | |||
1892 | lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); | 1892 | lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); |
1893 | 1893 | ||
1894 | if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { | 1894 | if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { |
1895 | pr_err("Unable to update renaming" | 1895 | pr_err("Unable to update renaming APTPL metadata," |
1896 | " APTPL metadata\n"); | 1896 | " reallocating larger buffer\n"); |
1897 | ret = -EMSGSIZE; | 1897 | ret = -EMSGSIZE; |
1898 | goto out; | 1898 | goto out; |
1899 | } | 1899 | } |
@@ -1956,7 +1956,7 @@ static int __core_scsi3_write_aptpl_to_file( | |||
1956 | static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl) | 1956 | static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl) |
1957 | { | 1957 | { |
1958 | unsigned char *buf; | 1958 | unsigned char *buf; |
1959 | int rc; | 1959 | int rc, len = PR_APTPL_BUF_LEN; |
1960 | 1960 | ||
1961 | if (!aptpl) { | 1961 | if (!aptpl) { |
1962 | char *null_buf = "No Registrations or Reservations\n"; | 1962 | char *null_buf = "No Registrations or Reservations\n"; |
@@ -1970,25 +1970,26 @@ static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, b | |||
1970 | 1970 | ||
1971 | return 0; | 1971 | return 0; |
1972 | } | 1972 | } |
1973 | 1973 | retry: | |
1974 | buf = kzalloc(PR_APTPL_BUF_LEN, GFP_KERNEL); | 1974 | buf = vzalloc(len); |
1975 | if (!buf) | 1975 | if (!buf) |
1976 | return TCM_OUT_OF_RESOURCES; | 1976 | return TCM_OUT_OF_RESOURCES; |
1977 | 1977 | ||
1978 | rc = core_scsi3_update_aptpl_buf(dev, buf, PR_APTPL_BUF_LEN); | 1978 | rc = core_scsi3_update_aptpl_buf(dev, buf, len); |
1979 | if (rc < 0) { | 1979 | if (rc < 0) { |
1980 | kfree(buf); | 1980 | vfree(buf); |
1981 | return TCM_OUT_OF_RESOURCES; | 1981 | len *= 2; |
1982 | goto retry; | ||
1982 | } | 1983 | } |
1983 | 1984 | ||
1984 | rc = __core_scsi3_write_aptpl_to_file(dev, buf); | 1985 | rc = __core_scsi3_write_aptpl_to_file(dev, buf); |
1985 | if (rc != 0) { | 1986 | if (rc != 0) { |
1986 | pr_err("SPC-3 PR: Could not update APTPL\n"); | 1987 | pr_err("SPC-3 PR: Could not update APTPL\n"); |
1987 | kfree(buf); | 1988 | vfree(buf); |
1988 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | 1989 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
1989 | } | 1990 | } |
1990 | dev->t10_pr.pr_aptpl_active = 1; | 1991 | dev->t10_pr.pr_aptpl_active = 1; |
1991 | kfree(buf); | 1992 | vfree(buf); |
1992 | pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); | 1993 | pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); |
1993 | return 0; | 1994 | return 0; |
1994 | } | 1995 | } |
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index cd4bed7b2757..9a2f9d3a6e70 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c | |||
@@ -37,6 +37,9 @@ | |||
37 | #include "target_core_alua.h" | 37 | #include "target_core_alua.h" |
38 | 38 | ||
39 | static sense_reason_t | 39 | static sense_reason_t |
40 | sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool); | ||
41 | |||
42 | static sense_reason_t | ||
40 | sbc_emulate_readcapacity(struct se_cmd *cmd) | 43 | sbc_emulate_readcapacity(struct se_cmd *cmd) |
41 | { | 44 | { |
42 | struct se_device *dev = cmd->se_dev; | 45 | struct se_device *dev = cmd->se_dev; |
@@ -251,7 +254,10 @@ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb) | |||
251 | static sense_reason_t | 254 | static sense_reason_t |
252 | sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops) | 255 | sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops) |
253 | { | 256 | { |
257 | struct se_device *dev = cmd->se_dev; | ||
258 | sector_t end_lba = dev->transport->get_blocks(dev) + 1; | ||
254 | unsigned int sectors = sbc_get_write_same_sectors(cmd); | 259 | unsigned int sectors = sbc_get_write_same_sectors(cmd); |
260 | sense_reason_t ret; | ||
255 | 261 | ||
256 | if ((flags[0] & 0x04) || (flags[0] & 0x02)) { | 262 | if ((flags[0] & 0x04) || (flags[0] & 0x02)) { |
257 | pr_err("WRITE_SAME PBDATA and LBDATA" | 263 | pr_err("WRITE_SAME PBDATA and LBDATA" |
@@ -264,6 +270,16 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o | |||
264 | sectors, cmd->se_dev->dev_attrib.max_write_same_len); | 270 | sectors, cmd->se_dev->dev_attrib.max_write_same_len); |
265 | return TCM_INVALID_CDB_FIELD; | 271 | return TCM_INVALID_CDB_FIELD; |
266 | } | 272 | } |
273 | /* | ||
274 | * Sanity check for LBA wrap and request past end of device. | ||
275 | */ | ||
276 | if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || | ||
277 | ((cmd->t_task_lba + sectors) > end_lba)) { | ||
278 | pr_err("WRITE_SAME exceeds last lba %llu (lba %llu, sectors %u)\n", | ||
279 | (unsigned long long)end_lba, cmd->t_task_lba, sectors); | ||
280 | return TCM_ADDRESS_OUT_OF_RANGE; | ||
281 | } | ||
282 | |||
267 | /* We always have ANC_SUP == 0 so setting ANCHOR is always an error */ | 283 | /* We always have ANC_SUP == 0 so setting ANCHOR is always an error */ |
268 | if (flags[0] & 0x10) { | 284 | if (flags[0] & 0x10) { |
269 | pr_warn("WRITE SAME with ANCHOR not supported\n"); | 285 | pr_warn("WRITE SAME with ANCHOR not supported\n"); |
@@ -277,12 +293,21 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o | |||
277 | if (!ops->execute_write_same_unmap) | 293 | if (!ops->execute_write_same_unmap) |
278 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 294 | return TCM_UNSUPPORTED_SCSI_OPCODE; |
279 | 295 | ||
296 | if (!dev->dev_attrib.emulate_tpws) { | ||
297 | pr_err("Got WRITE_SAME w/ UNMAP=1, but backend device" | ||
298 | " has emulate_tpws disabled\n"); | ||
299 | return TCM_UNSUPPORTED_SCSI_OPCODE; | ||
300 | } | ||
280 | cmd->execute_cmd = ops->execute_write_same_unmap; | 301 | cmd->execute_cmd = ops->execute_write_same_unmap; |
281 | return 0; | 302 | return 0; |
282 | } | 303 | } |
283 | if (!ops->execute_write_same) | 304 | if (!ops->execute_write_same) |
284 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 305 | return TCM_UNSUPPORTED_SCSI_OPCODE; |
285 | 306 | ||
307 | ret = sbc_check_prot(dev, cmd, &cmd->t_task_cdb[0], sectors, true); | ||
308 | if (ret) | ||
309 | return ret; | ||
310 | |||
286 | cmd->execute_cmd = ops->execute_write_same; | 311 | cmd->execute_cmd = ops->execute_write_same; |
287 | return 0; | 312 | return 0; |
288 | } | 313 | } |
@@ -614,14 +639,21 @@ sbc_set_prot_op_checks(u8 protect, enum target_prot_type prot_type, | |||
614 | return 0; | 639 | return 0; |
615 | } | 640 | } |
616 | 641 | ||
617 | static bool | 642 | static sense_reason_t |
618 | sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, | 643 | sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, |
619 | u32 sectors, bool is_write) | 644 | u32 sectors, bool is_write) |
620 | { | 645 | { |
621 | u8 protect = cdb[1] >> 5; | 646 | u8 protect = cdb[1] >> 5; |
622 | 647 | ||
623 | if ((!cmd->t_prot_sg || !cmd->t_prot_nents) && cmd->prot_pto) | 648 | if (!cmd->t_prot_sg || !cmd->t_prot_nents) { |
624 | return true; | 649 | if (protect && !dev->dev_attrib.pi_prot_type) { |
650 | pr_err("CDB contains protect bit, but device does not" | ||
651 | " advertise PROTECT=1 feature bit\n"); | ||
652 | return TCM_INVALID_CDB_FIELD; | ||
653 | } | ||
654 | if (cmd->prot_pto) | ||
655 | return TCM_NO_SENSE; | ||
656 | } | ||
625 | 657 | ||
626 | switch (dev->dev_attrib.pi_prot_type) { | 658 | switch (dev->dev_attrib.pi_prot_type) { |
627 | case TARGET_DIF_TYPE3_PROT: | 659 | case TARGET_DIF_TYPE3_PROT: |
@@ -629,7 +661,7 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, | |||
629 | break; | 661 | break; |
630 | case TARGET_DIF_TYPE2_PROT: | 662 | case TARGET_DIF_TYPE2_PROT: |
631 | if (protect) | 663 | if (protect) |
632 | return false; | 664 | return TCM_INVALID_CDB_FIELD; |
633 | 665 | ||
634 | cmd->reftag_seed = cmd->t_task_lba; | 666 | cmd->reftag_seed = cmd->t_task_lba; |
635 | break; | 667 | break; |
@@ -638,12 +670,12 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, | |||
638 | break; | 670 | break; |
639 | case TARGET_DIF_TYPE0_PROT: | 671 | case TARGET_DIF_TYPE0_PROT: |
640 | default: | 672 | default: |
641 | return true; | 673 | return TCM_NO_SENSE; |
642 | } | 674 | } |
643 | 675 | ||
644 | if (sbc_set_prot_op_checks(protect, dev->dev_attrib.pi_prot_type, | 676 | if (sbc_set_prot_op_checks(protect, dev->dev_attrib.pi_prot_type, |
645 | is_write, cmd)) | 677 | is_write, cmd)) |
646 | return false; | 678 | return TCM_INVALID_CDB_FIELD; |
647 | 679 | ||
648 | cmd->prot_type = dev->dev_attrib.pi_prot_type; | 680 | cmd->prot_type = dev->dev_attrib.pi_prot_type; |
649 | cmd->prot_length = dev->prot_length * sectors; | 681 | cmd->prot_length = dev->prot_length * sectors; |
@@ -662,7 +694,30 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, | |||
662 | __func__, cmd->prot_type, cmd->data_length, cmd->prot_length, | 694 | __func__, cmd->prot_type, cmd->data_length, cmd->prot_length, |
663 | cmd->prot_op, cmd->prot_checks); | 695 | cmd->prot_op, cmd->prot_checks); |
664 | 696 | ||
665 | return true; | 697 | return TCM_NO_SENSE; |
698 | } | ||
699 | |||
700 | static int | ||
701 | sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb) | ||
702 | { | ||
703 | if (cdb[1] & 0x10) { | ||
704 | if (!dev->dev_attrib.emulate_dpo) { | ||
705 | pr_err("Got CDB: 0x%02x with DPO bit set, but device" | ||
706 | " does not advertise support for DPO\n", cdb[0]); | ||
707 | return -EINVAL; | ||
708 | } | ||
709 | } | ||
710 | if (cdb[1] & 0x8) { | ||
711 | if (!dev->dev_attrib.emulate_fua_write || | ||
712 | !dev->dev_attrib.emulate_write_cache) { | ||
713 | pr_err("Got CDB: 0x%02x with FUA bit set, but device" | ||
714 | " does not advertise support for FUA write\n", | ||
715 | cdb[0]); | ||
716 | return -EINVAL; | ||
717 | } | ||
718 | cmd->se_cmd_flags |= SCF_FUA; | ||
719 | } | ||
720 | return 0; | ||
666 | } | 721 | } |
667 | 722 | ||
668 | sense_reason_t | 723 | sense_reason_t |
@@ -686,8 +741,12 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
686 | sectors = transport_get_sectors_10(cdb); | 741 | sectors = transport_get_sectors_10(cdb); |
687 | cmd->t_task_lba = transport_lba_32(cdb); | 742 | cmd->t_task_lba = transport_lba_32(cdb); |
688 | 743 | ||
689 | if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) | 744 | if (sbc_check_dpofua(dev, cmd, cdb)) |
690 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 745 | return TCM_INVALID_CDB_FIELD; |
746 | |||
747 | ret = sbc_check_prot(dev, cmd, cdb, sectors, false); | ||
748 | if (ret) | ||
749 | return ret; | ||
691 | 750 | ||
692 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 751 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
693 | cmd->execute_rw = ops->execute_rw; | 752 | cmd->execute_rw = ops->execute_rw; |
@@ -697,8 +756,12 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
697 | sectors = transport_get_sectors_12(cdb); | 756 | sectors = transport_get_sectors_12(cdb); |
698 | cmd->t_task_lba = transport_lba_32(cdb); | 757 | cmd->t_task_lba = transport_lba_32(cdb); |
699 | 758 | ||
700 | if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) | 759 | if (sbc_check_dpofua(dev, cmd, cdb)) |
701 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 760 | return TCM_INVALID_CDB_FIELD; |
761 | |||
762 | ret = sbc_check_prot(dev, cmd, cdb, sectors, false); | ||
763 | if (ret) | ||
764 | return ret; | ||
702 | 765 | ||
703 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 766 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
704 | cmd->execute_rw = ops->execute_rw; | 767 | cmd->execute_rw = ops->execute_rw; |
@@ -708,8 +771,12 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
708 | sectors = transport_get_sectors_16(cdb); | 771 | sectors = transport_get_sectors_16(cdb); |
709 | cmd->t_task_lba = transport_lba_64(cdb); | 772 | cmd->t_task_lba = transport_lba_64(cdb); |
710 | 773 | ||
711 | if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) | 774 | if (sbc_check_dpofua(dev, cmd, cdb)) |
712 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 775 | return TCM_INVALID_CDB_FIELD; |
776 | |||
777 | ret = sbc_check_prot(dev, cmd, cdb, sectors, false); | ||
778 | if (ret) | ||
779 | return ret; | ||
713 | 780 | ||
714 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 781 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
715 | cmd->execute_rw = ops->execute_rw; | 782 | cmd->execute_rw = ops->execute_rw; |
@@ -727,11 +794,13 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
727 | sectors = transport_get_sectors_10(cdb); | 794 | sectors = transport_get_sectors_10(cdb); |
728 | cmd->t_task_lba = transport_lba_32(cdb); | 795 | cmd->t_task_lba = transport_lba_32(cdb); |
729 | 796 | ||
730 | if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) | 797 | if (sbc_check_dpofua(dev, cmd, cdb)) |
731 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 798 | return TCM_INVALID_CDB_FIELD; |
799 | |||
800 | ret = sbc_check_prot(dev, cmd, cdb, sectors, true); | ||
801 | if (ret) | ||
802 | return ret; | ||
732 | 803 | ||
733 | if (cdb[1] & 0x8) | ||
734 | cmd->se_cmd_flags |= SCF_FUA; | ||
735 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 804 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
736 | cmd->execute_rw = ops->execute_rw; | 805 | cmd->execute_rw = ops->execute_rw; |
737 | cmd->execute_cmd = sbc_execute_rw; | 806 | cmd->execute_cmd = sbc_execute_rw; |
@@ -740,11 +809,13 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
740 | sectors = transport_get_sectors_12(cdb); | 809 | sectors = transport_get_sectors_12(cdb); |
741 | cmd->t_task_lba = transport_lba_32(cdb); | 810 | cmd->t_task_lba = transport_lba_32(cdb); |
742 | 811 | ||
743 | if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) | 812 | if (sbc_check_dpofua(dev, cmd, cdb)) |
744 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 813 | return TCM_INVALID_CDB_FIELD; |
814 | |||
815 | ret = sbc_check_prot(dev, cmd, cdb, sectors, true); | ||
816 | if (ret) | ||
817 | return ret; | ||
745 | 818 | ||
746 | if (cdb[1] & 0x8) | ||
747 | cmd->se_cmd_flags |= SCF_FUA; | ||
748 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 819 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
749 | cmd->execute_rw = ops->execute_rw; | 820 | cmd->execute_rw = ops->execute_rw; |
750 | cmd->execute_cmd = sbc_execute_rw; | 821 | cmd->execute_cmd = sbc_execute_rw; |
@@ -753,11 +824,13 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
753 | sectors = transport_get_sectors_16(cdb); | 824 | sectors = transport_get_sectors_16(cdb); |
754 | cmd->t_task_lba = transport_lba_64(cdb); | 825 | cmd->t_task_lba = transport_lba_64(cdb); |
755 | 826 | ||
756 | if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) | 827 | if (sbc_check_dpofua(dev, cmd, cdb)) |
757 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 828 | return TCM_INVALID_CDB_FIELD; |
829 | |||
830 | ret = sbc_check_prot(dev, cmd, cdb, sectors, true); | ||
831 | if (ret) | ||
832 | return ret; | ||
758 | 833 | ||
759 | if (cdb[1] & 0x8) | ||
760 | cmd->se_cmd_flags |= SCF_FUA; | ||
761 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 834 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
762 | cmd->execute_rw = ops->execute_rw; | 835 | cmd->execute_rw = ops->execute_rw; |
763 | cmd->execute_cmd = sbc_execute_rw; | 836 | cmd->execute_cmd = sbc_execute_rw; |
@@ -768,6 +841,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
768 | return TCM_INVALID_CDB_FIELD; | 841 | return TCM_INVALID_CDB_FIELD; |
769 | sectors = transport_get_sectors_10(cdb); | 842 | sectors = transport_get_sectors_10(cdb); |
770 | 843 | ||
844 | if (sbc_check_dpofua(dev, cmd, cdb)) | ||
845 | return TCM_INVALID_CDB_FIELD; | ||
846 | |||
771 | cmd->t_task_lba = transport_lba_32(cdb); | 847 | cmd->t_task_lba = transport_lba_32(cdb); |
772 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; | 848 | cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; |
773 | 849 | ||
@@ -777,8 +853,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
777 | cmd->execute_rw = ops->execute_rw; | 853 | cmd->execute_rw = ops->execute_rw; |
778 | cmd->execute_cmd = sbc_execute_rw; | 854 | cmd->execute_cmd = sbc_execute_rw; |
779 | cmd->transport_complete_callback = &xdreadwrite_callback; | 855 | cmd->transport_complete_callback = &xdreadwrite_callback; |
780 | if (cdb[1] & 0x8) | ||
781 | cmd->se_cmd_flags |= SCF_FUA; | ||
782 | break; | 856 | break; |
783 | case VARIABLE_LENGTH_CMD: | 857 | case VARIABLE_LENGTH_CMD: |
784 | { | 858 | { |
@@ -787,6 +861,8 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
787 | case XDWRITEREAD_32: | 861 | case XDWRITEREAD_32: |
788 | sectors = transport_get_sectors_32(cdb); | 862 | sectors = transport_get_sectors_32(cdb); |
789 | 863 | ||
864 | if (sbc_check_dpofua(dev, cmd, cdb)) | ||
865 | return TCM_INVALID_CDB_FIELD; | ||
790 | /* | 866 | /* |
791 | * Use WRITE_32 and READ_32 opcodes for the emulated | 867 | * Use WRITE_32 and READ_32 opcodes for the emulated |
792 | * XDWRITE_READ_32 logic. | 868 | * XDWRITE_READ_32 logic. |
@@ -801,8 +877,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
801 | cmd->execute_rw = ops->execute_rw; | 877 | cmd->execute_rw = ops->execute_rw; |
802 | cmd->execute_cmd = sbc_execute_rw; | 878 | cmd->execute_cmd = sbc_execute_rw; |
803 | cmd->transport_complete_callback = &xdreadwrite_callback; | 879 | cmd->transport_complete_callback = &xdreadwrite_callback; |
804 | if (cdb[1] & 0x8) | ||
805 | cmd->se_cmd_flags |= SCF_FUA; | ||
806 | break; | 880 | break; |
807 | case WRITE_SAME_32: | 881 | case WRITE_SAME_32: |
808 | sectors = transport_get_sectors_32(cdb); | 882 | sectors = transport_get_sectors_32(cdb); |
@@ -888,6 +962,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
888 | if (!ops->execute_unmap) | 962 | if (!ops->execute_unmap) |
889 | return TCM_UNSUPPORTED_SCSI_OPCODE; | 963 | return TCM_UNSUPPORTED_SCSI_OPCODE; |
890 | 964 | ||
965 | if (!dev->dev_attrib.emulate_tpu) { | ||
966 | pr_err("Got UNMAP, but backend device has" | ||
967 | " emulate_tpu disabled\n"); | ||
968 | return TCM_UNSUPPORTED_SCSI_OPCODE; | ||
969 | } | ||
891 | size = get_unaligned_be16(&cdb[7]); | 970 | size = get_unaligned_be16(&cdb[7]); |
892 | cmd->execute_cmd = ops->execute_unmap; | 971 | cmd->execute_cmd = ops->execute_unmap; |
893 | break; | 972 | break; |
@@ -955,7 +1034,8 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) | |||
955 | unsigned long long end_lba; | 1034 | unsigned long long end_lba; |
956 | check_lba: | 1035 | check_lba: |
957 | end_lba = dev->transport->get_blocks(dev) + 1; | 1036 | end_lba = dev->transport->get_blocks(dev) + 1; |
958 | if (cmd->t_task_lba + sectors > end_lba) { | 1037 | if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || |
1038 | ((cmd->t_task_lba + sectors) > end_lba)) { | ||
959 | pr_err("cmd exceeds last lba %llu " | 1039 | pr_err("cmd exceeds last lba %llu " |
960 | "(lba %llu, sectors %u)\n", | 1040 | "(lba %llu, sectors %u)\n", |
961 | end_lba, cmd->t_task_lba, sectors); | 1041 | end_lba, cmd->t_task_lba, sectors); |
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index 4c71657da56a..460e93109473 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c | |||
@@ -647,7 +647,7 @@ spc_emulate_evpd_b2(struct se_cmd *cmd, unsigned char *buf) | |||
647 | * support the use of the WRITE SAME (16) command to unmap LBAs. | 647 | * support the use of the WRITE SAME (16) command to unmap LBAs. |
648 | */ | 648 | */ |
649 | if (dev->dev_attrib.emulate_tpws != 0) | 649 | if (dev->dev_attrib.emulate_tpws != 0) |
650 | buf[5] |= 0x40; | 650 | buf[5] |= 0x40 | 0x20; |
651 | 651 | ||
652 | return 0; | 652 | return 0; |
653 | } | 653 | } |