Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending

Pull SCSI target updates from Nicholas Bellinger:
"The highlights this round include:

- Update vhost-scsi to support F_ANY_LAYOUT using mm/iov_iter.c
logic, and signal VERSION_1 support (MST + Viro + nab)

- Fix iscsi/iser-target to remove problematic active_ts_set usage
(Gavin Guo)

- Update iscsi/iser-target to support multi-sequence sendtargets
(Sagi)

- Fix original PR_APTPL_BUF_LEN 8k size limitation (Martin Svec)

- Add missing WRITE_SAME end-of-device sanity check (Bart)

- Check for LBA + sectors wrap-around in sbc_parse_cdb() (nab)

- Other various minor SPC/SBC compliance fixes based upon Ronnie
Sahlberg test suite (nab)"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (32 commits)
target: Set LBPWS10 bit in Logical Block Provisioning EVPD
target: Fail UNMAP when emulate_tpu=0
target: Fail WRITE_SAME w/ UNMAP=1 when emulate_tpws=0
target: Add sanity checks for DPO/FUA bit usage
target: Perform PROTECT sanity checks for WRITE_SAME
target: Fail I/O with PROTECT bit when protection is unsupported
target: Check for LBA + sectors wrap-around in sbc_parse_cdb
target: Add missing WRITE_SAME end-of-device sanity check
iscsi-target: Avoid IN_LOGOUT failure case for iser-target
target: Fix PR_APTPL_BUF_LEN buffer size limitation
iscsi-target: Drop problematic active_ts_list usage
iscsi/iser-target: Support multi-sequence sendtargets text response
iser-target: Remove duplicate function names
vhost/scsi: potential memory corruption
vhost/scsi: Global tcm_vhost -> vhost_scsi rename
vhost/scsi: Drop left-over scsi_tcq.h include
vhost/scsi: Set VIRTIO_F_ANY_LAYOUT + VIRTIO_F_VERSION_1 feature bits
vhost/scsi: Add ANY_LAYOUT support in vhost_scsi_handle_vq
vhost/scsi: Add ANY_LAYOUT iov -> sgl mapping prerequisites
vhost/scsi: Change vhost_scsi_map_to_sgl to accept iov ptr + len
...

+826 -686
+30 -16
drivers/infiniband/ulp/isert/ib_isert.c
··· 38 38 #define ISER_MAX_CQ_LEN (ISER_MAX_RX_CQ_LEN + ISER_MAX_TX_CQ_LEN + \ 39 39 ISERT_MAX_CONN) 40 40 41 - int isert_debug_level = 0; 41 + static int isert_debug_level; 42 42 module_param_named(debug_level, isert_debug_level, int, 0644); 43 43 MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0 (default:0)"); 44 44 ··· 949 949 isert_err("ib_post_recv() failed with ret: %d\n", ret); 950 950 isert_conn->post_recv_buf_count -= count; 951 951 } else { 952 - isert_dbg("isert_post_recv(): Posted %d RX buffers\n", count); 952 + isert_dbg("Posted %d RX buffers\n", count); 953 953 isert_conn->conn_rx_desc_head = rx_head; 954 954 } 955 955 return ret; ··· 1351 1351 struct iscsi_conn *conn = isert_conn->conn; 1352 1352 u32 payload_length = ntoh24(hdr->dlength); 1353 1353 int rc; 1354 - unsigned char *text_in; 1354 + unsigned char *text_in = NULL; 1355 1355 1356 1356 rc = iscsit_setup_text_cmd(conn, cmd, hdr); 1357 1357 if (rc < 0) 1358 1358 return rc; 1359 1359 1360 - text_in = kzalloc(payload_length, GFP_KERNEL); 1361 - if (!text_in) { 1362 - isert_err("Unable to allocate text_in of payload_length: %u\n", 1363 - payload_length); 1364 - return -ENOMEM; 1360 + if (payload_length) { 1361 + text_in = kzalloc(payload_length, GFP_KERNEL); 1362 + if (!text_in) { 1363 + isert_err("Unable to allocate text_in of payload_length: %u\n", 1364 + payload_length); 1365 + return -ENOMEM; 1366 + } 1365 1367 } 1366 1368 cmd->text_in_ptr = text_in; 1367 1369 ··· 1436 1434 ret = iscsit_handle_logout_cmd(conn, cmd, (unsigned char *)hdr); 1437 1435 break; 1438 1436 case ISCSI_OP_TEXT: 1439 - cmd = isert_allocate_cmd(conn); 1440 - if (!cmd) 1441 - break; 1437 + if (be32_to_cpu(hdr->ttt) != 0xFFFFFFFF) { 1438 + cmd = iscsit_find_cmd_from_itt(conn, hdr->itt); 1439 + if (!cmd) 1440 + break; 1441 + } else { 1442 + cmd = isert_allocate_cmd(conn); 1443 + if (!cmd) 1444 + break; 1445 + } 1442 1446 1443 1447 isert_cmd = iscsit_priv_cmd(cmd); 1444 1448 ret = isert_handle_text_cmd(isert_conn, isert_cmd, cmd, ··· 1666 1658 struct isert_conn *isert_conn = isert_cmd->conn; 1667 1659 struct iscsi_conn *conn = isert_conn->conn; 1668 1660 struct isert_device *device = isert_conn->conn_device; 1661 + struct iscsi_text_rsp *hdr; 1669 1662 1670 1663 isert_dbg("Cmd %p\n", isert_cmd); 1671 1664 ··· 1707 1698 case ISCSI_OP_REJECT: 1708 1699 case ISCSI_OP_NOOP_OUT: 1709 1700 case ISCSI_OP_TEXT: 1701 + hdr = (struct iscsi_text_rsp *)&isert_cmd->tx_desc.iscsi_header; 1702 + /* If the continue bit is on, keep the command alive */ 1703 + if (hdr->flags & ISCSI_FLAG_TEXT_CONTINUE) 1704 + break; 1705 + 1710 1706 spin_lock_bh(&conn->cmd_lock); 1711 1707 if (!list_empty(&cmd->i_conn_node)) 1712 1708 list_del_init(&cmd->i_conn_node); ··· 1723 1709 * associated cmd->se_cmd needs to be released. 1724 1710 */ 1725 1711 if (cmd->se_cmd.se_tfo != NULL) { 1726 - isert_dbg("Calling transport_generic_free_cmd from" 1727 - " isert_put_cmd for 0x%02x\n", 1712 + isert_dbg("Calling transport_generic_free_cmd for 0x%02x\n", 1728 1713 cmd->iscsi_opcode); 1729 1714 transport_generic_free_cmd(&cmd->se_cmd, 0); 1730 1715 break; ··· 2288 2275 } 2289 2276 isert_init_send_wr(isert_conn, isert_cmd, send_wr); 2290 2277 2291 - isert_dbg("conn %p Text Reject\n", isert_conn); 2278 + isert_dbg("conn %p Text Response\n", isert_conn); 2292 2279 2293 2280 return isert_post_response(isert_conn, isert_cmd); 2294 2281 } ··· 3149 3136 spin_lock_bh(&np->np_thread_lock); 3150 3137 if (np->np_thread_state >= ISCSI_NP_THREAD_RESET) { 3151 3138 spin_unlock_bh(&np->np_thread_lock); 3152 - isert_dbg("np_thread_state %d for isert_accept_np\n", 3139 + isert_dbg("np_thread_state %d\n", 3153 3140 np->np_thread_state); 3154 3141 /** 3155 3142 * No point in stalling here when np_thread ··· 3333 3320 { 3334 3321 int ret; 3335 3322 3336 - isert_comp_wq = alloc_workqueue("isert_comp_wq", 0, 0); 3323 + isert_comp_wq = alloc_workqueue("isert_comp_wq", 3324 + WQ_UNBOUND | WQ_HIGHPRI, 0); 3337 3325 if (!isert_comp_wq) { 3338 3326 isert_err("Unable to allocate isert_comp_wq\n"); 3339 3327 ret = -ENOMEM;
+2 -2
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 3518 3518 DECLARE_COMPLETION_ONSTACK(release_done); 3519 3519 struct srpt_rdma_ch *ch; 3520 3520 struct srpt_device *sdev; 3521 - int res; 3521 + unsigned long res; 3522 3522 3523 3523 ch = se_sess->fabric_sess_ptr; 3524 3524 WARN_ON(ch->sess != se_sess); ··· 3533 3533 spin_unlock_irq(&sdev->spinlock); 3534 3534 3535 3535 res = wait_for_completion_timeout(&release_done, 60 * HZ); 3536 - WARN_ON(res <= 0); 3536 + WARN_ON(res == 0); 3537 3537 } 3538 3538 3539 3539 /**
+1 -3
drivers/scsi/qla2xxx/tcm_qla2xxx.c
··· 1570 1570 * match the format by tcm_qla2xxx explict ConfigFS NodeACLs. 1571 1571 */ 1572 1572 memset(&port_name, 0, 36); 1573 - snprintf(port_name, 36, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", 1574 - fc_wwpn[0], fc_wwpn[1], fc_wwpn[2], fc_wwpn[3], fc_wwpn[4], 1575 - fc_wwpn[5], fc_wwpn[6], fc_wwpn[7]); 1573 + snprintf(port_name, sizeof(port_name), "%8phC", fc_wwpn); 1576 1574 /* 1577 1575 * Locate our struct se_node_acl either from an explict NodeACL created 1578 1576 * via ConfigFS, or via running in TPG demo mode.
+70 -35
drivers/target/iscsi/iscsi_target.c
··· 30 30 #include <target/target_core_fabric.h> 31 31 #include <target/target_core_configfs.h> 32 32 33 - #include "iscsi_target_core.h" 33 + #include <target/iscsi/iscsi_target_core.h> 34 34 #include "iscsi_target_parameters.h" 35 35 #include "iscsi_target_seq_pdu_list.h" 36 36 #include "iscsi_target_tq.h" ··· 45 45 #include "iscsi_target_util.h" 46 46 #include "iscsi_target.h" 47 47 #include "iscsi_target_device.h" 48 - #include "iscsi_target_stat.h" 48 + #include <target/iscsi/iscsi_target_stat.h> 49 49 50 50 #include <target/iscsi/iscsi_transport.h> 51 51 ··· 968 968 969 969 conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; 970 970 if (hdr->flags & ISCSI_FLAG_CMD_READ) { 971 - spin_lock_bh(&conn->sess->ttt_lock); 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); 971 + cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); 976 972 } else if (hdr->flags & ISCSI_FLAG_CMD_WRITE) 977 973 cmd->targ_xfer_tag = 0xFFFFFFFF; 978 974 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); ··· 1994 1998 cmd->cmd_sn = be32_to_cpu(hdr->cmdsn); 1995 1999 cmd->exp_stat_sn = be32_to_cpu(hdr->exp_statsn); 1996 2000 cmd->data_direction = DMA_NONE; 2001 + cmd->text_in_ptr = NULL; 1997 2002 1998 2003 return 0; 1999 2004 } ··· 2008 2011 int cmdsn_ret; 2009 2012 2010 2013 if (!text_in) { 2011 - pr_err("Unable to locate text_in buffer for sendtargets" 2012 - " discovery\n"); 2013 - goto reject; 2014 + cmd->targ_xfer_tag = be32_to_cpu(hdr->ttt); 2015 + if (cmd->targ_xfer_tag == 0xFFFFFFFF) { 2016 + pr_err("Unable to locate text_in buffer for sendtargets" 2017 + " discovery\n"); 2018 + goto reject; 2019 + } 2020 + goto empty_sendtargets; 2014 2021 } 2015 2022 if (strncmp("SendTargets", text_in, 11) != 0) { 2016 2023 pr_err("Received Text Data that is not" ··· 2041 2040 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); 2042 2041 spin_unlock_bh(&conn->cmd_lock); 2043 2042 2043 + empty_sendtargets: 2044 2044 iscsit_ack_from_expstatsn(conn, be32_to_cpu(hdr->exp_statsn)); 2045 2045 2046 2046 if (!(hdr->opcode & ISCSI_OP_IMMEDIATE)) { ··· 3049 3047 int_to_scsilun(cmd->se_cmd.orig_fe_lun, 3050 3048 (struct scsi_lun *)&hdr->lun); 3051 3049 hdr->itt = cmd->init_task_tag; 3052 - spin_lock_bh(&conn->sess->ttt_lock); 3053 - r2t->targ_xfer_tag = conn->sess->targ_xfer_tag++; 3054 - if (r2t->targ_xfer_tag == 0xFFFFFFFF) 3055 - r2t->targ_xfer_tag = conn->sess->targ_xfer_tag++; 3056 - spin_unlock_bh(&conn->sess->ttt_lock); 3050 + r2t->targ_xfer_tag = session_get_next_ttt(conn->sess); 3057 3051 hdr->ttt = cpu_to_be32(r2t->targ_xfer_tag); 3058 3052 hdr->statsn = cpu_to_be32(conn->stat_sn); 3059 3053 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); ··· 3391 3393 3392 3394 static int 3393 3395 iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, 3394 - enum iscsit_transport_type network_transport) 3396 + enum iscsit_transport_type network_transport, 3397 + int skip_bytes, bool *completed) 3395 3398 { 3396 3399 char *payload = NULL; 3397 3400 struct iscsi_conn *conn = cmd->conn; ··· 3404 3405 unsigned char buf[ISCSI_IQN_LEN+12]; /* iqn + "TargetName=" + \0 */ 3405 3406 unsigned char *text_in = cmd->text_in_ptr, *text_ptr = NULL; 3406 3407 3407 - buffer_len = max(conn->conn_ops->MaxRecvDataSegmentLength, 3408 + buffer_len = min(conn->conn_ops->MaxRecvDataSegmentLength, 3408 3409 SENDTARGETS_BUF_LIMIT); 3409 3410 3410 3411 payload = kzalloc(buffer_len, GFP_KERNEL); ··· 3483 3484 end_of_buf = 1; 3484 3485 goto eob; 3485 3486 } 3486 - memcpy(payload + payload_len, buf, len); 3487 - payload_len += len; 3488 - target_name_printed = 1; 3487 + 3488 + if (skip_bytes && len <= skip_bytes) { 3489 + skip_bytes -= len; 3490 + } else { 3491 + memcpy(payload + payload_len, buf, len); 3492 + payload_len += len; 3493 + target_name_printed = 1; 3494 + if (len > skip_bytes) 3495 + skip_bytes = 0; 3496 + } 3489 3497 } 3490 3498 3491 3499 len = sprintf(buf, "TargetAddress=" ··· 3508 3502 end_of_buf = 1; 3509 3503 goto eob; 3510 3504 } 3511 - memcpy(payload + payload_len, buf, len); 3512 - payload_len += len; 3505 + 3506 + if (skip_bytes && len <= skip_bytes) { 3507 + skip_bytes -= len; 3508 + } else { 3509 + memcpy(payload + payload_len, buf, len); 3510 + payload_len += len; 3511 + if (len > skip_bytes) 3512 + skip_bytes = 0; 3513 + } 3513 3514 } 3514 3515 spin_unlock(&tpg->tpg_np_lock); 3515 3516 } 3516 3517 spin_unlock(&tiqn->tiqn_tpg_lock); 3517 3518 eob: 3518 - if (end_of_buf) 3519 + if (end_of_buf) { 3520 + *completed = false; 3519 3521 break; 3522 + } 3520 3523 3521 3524 if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) 3522 3525 break; ··· 3543 3528 enum iscsit_transport_type network_transport) 3544 3529 { 3545 3530 int text_length, padding; 3531 + bool completed = true; 3546 3532 3547 - text_length = iscsit_build_sendtargets_response(cmd, network_transport); 3533 + text_length = iscsit_build_sendtargets_response(cmd, network_transport, 3534 + cmd->read_data_done, 3535 + &completed); 3548 3536 if (text_length < 0) 3549 3537 return text_length; 3550 3538 3539 + if (completed) { 3540 + hdr->flags |= ISCSI_FLAG_CMD_FINAL; 3541 + } else { 3542 + hdr->flags |= ISCSI_FLAG_TEXT_CONTINUE; 3543 + cmd->read_data_done += text_length; 3544 + if (cmd->targ_xfer_tag == 0xFFFFFFFF) 3545 + cmd->targ_xfer_tag = session_get_next_ttt(conn->sess); 3546 + } 3551 3547 hdr->opcode = ISCSI_OP_TEXT_RSP; 3552 - hdr->flags |= ISCSI_FLAG_CMD_FINAL; 3553 3548 padding = ((-text_length) & 3); 3554 3549 hton24(hdr->dlength, text_length); 3555 3550 hdr->itt = cmd->init_task_tag; ··· 3568 3543 hdr->statsn = cpu_to_be32(cmd->stat_sn); 3569 3544 3570 3545 iscsit_increment_maxcmdsn(cmd, conn->sess); 3546 + /* 3547 + * Reset maxcmdsn_inc in multi-part text payload exchanges to 3548 + * correctly increment MaxCmdSN for each response answering a 3549 + * non immediate text request with a valid CmdSN. 3550 + */ 3551 + cmd->maxcmdsn_inc = 0; 3571 3552 hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); 3572 3553 hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); 3573 3554 3574 - pr_debug("Built Text Response: ITT: 0x%08x, StatSN: 0x%08x," 3575 - " Length: %u, CID: %hu\n", cmd->init_task_tag, cmd->stat_sn, 3576 - text_length, conn->cid); 3555 + pr_debug("Built Text Response: ITT: 0x%08x, TTT: 0x%08x, StatSN: 0x%08x," 3556 + " Length: %u, CID: %hu F: %d C: %d\n", cmd->init_task_tag, 3557 + cmd->targ_xfer_tag, cmd->stat_sn, text_length, conn->cid, 3558 + !!(hdr->flags & ISCSI_FLAG_CMD_FINAL), 3559 + !!(hdr->flags & ISCSI_FLAG_TEXT_CONTINUE)); 3577 3560 3578 3561 return text_length + padding; 3579 3562 } 3580 3563 EXPORT_SYMBOL(iscsit_build_text_rsp); 3581 3564 3582 - /* 3583 - * FIXME: Add support for F_BIT and C_BIT when the length is longer than 3584 - * MaxRecvDataSegmentLength. 3585 - */ 3586 3565 static int iscsit_send_text_rsp( 3587 3566 struct iscsi_cmd *cmd, 3588 3567 struct iscsi_conn *conn) ··· 4050 4021 ret = iscsit_handle_task_mgt_cmd(conn, cmd, buf); 4051 4022 break; 4052 4023 case ISCSI_OP_TEXT: 4053 - cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); 4054 - if (!cmd) 4055 - goto reject; 4024 + if (hdr->ttt != cpu_to_be32(0xFFFFFFFF)) { 4025 + cmd = iscsit_find_cmd_from_itt(conn, hdr->itt); 4026 + if (!cmd) 4027 + goto reject; 4028 + } else { 4029 + cmd = iscsit_allocate_cmd(conn, TASK_INTERRUPTIBLE); 4030 + if (!cmd) 4031 + goto reject; 4032 + } 4056 4033 4057 4034 ret = iscsit_handle_text_cmd(conn, cmd, buf); 4058 4035 break;
+1 -1
drivers/target/iscsi/iscsi_target_auth.c
··· 22 22 #include <linux/err.h> 23 23 #include <linux/scatterlist.h> 24 24 25 - #include "iscsi_target_core.h" 25 + #include <target/iscsi/iscsi_target_core.h> 26 26 #include "iscsi_target_nego.h" 27 27 #include "iscsi_target_auth.h" 28 28
+6 -11
drivers/target/iscsi/iscsi_target_configfs.c
··· 28 28 #include <target/configfs_macros.h> 29 29 #include <target/iscsi/iscsi_transport.h> 30 30 31 - #include "iscsi_target_core.h" 31 + #include <target/iscsi/iscsi_target_core.h> 32 32 #include "iscsi_target_parameters.h" 33 33 #include "iscsi_target_device.h" 34 34 #include "iscsi_target_erl0.h" ··· 36 36 #include "iscsi_target_tpg.h" 37 37 #include "iscsi_target_util.h" 38 38 #include "iscsi_target.h" 39 - #include "iscsi_target_stat.h" 39 + #include <target/iscsi/iscsi_target_stat.h> 40 40 #include "iscsi_target_configfs.h" 41 41 42 42 struct target_fabric_configfs *lio_target_fabric_configfs; ··· 674 674 rb += sprintf(page+rb, "InitiatorAlias: %s\n", 675 675 sess->sess_ops->InitiatorAlias); 676 676 677 - rb += sprintf(page+rb, "LIO Session ID: %u " 678 - "ISID: 0x%02x %02x %02x %02x %02x %02x " 679 - "TSIH: %hu ", sess->sid, 680 - sess->isid[0], sess->isid[1], sess->isid[2], 681 - sess->isid[3], sess->isid[4], sess->isid[5], 682 - sess->tsih); 677 + rb += sprintf(page+rb, 678 + "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", 679 + sess->sid, sess->isid, sess->tsih); 683 680 rb += sprintf(page+rb, "SessionType: %s\n", 684 681 (sess->sess_ops->SessionType) ? 685 682 "Discovery" : "Normal"); ··· 1755 1758 /* 1756 1759 * iSCSI Initiator Session Identifier from RFC-3720. 1757 1760 */ 1758 - return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x", 1759 - sess->isid[0], sess->isid[1], sess->isid[2], 1760 - sess->isid[3], sess->isid[4], sess->isid[5]); 1761 + return snprintf(buf, size, "%6phN", sess->isid); 1761 1762 } 1762 1763 1763 1764 static int lio_queue_data_in(struct se_cmd *se_cmd)
+14
drivers/target/iscsi/iscsi_target_core.h include/target/iscsi/iscsi_target_core.h
··· 880 880 struct iscsi_portal_group *discovery_tpg; 881 881 }; 882 882 883 + static inline u32 session_get_next_ttt(struct iscsi_session *session) 884 + { 885 + u32 ttt; 886 + 887 + spin_lock_bh(&session->ttt_lock); 888 + ttt = session->targ_xfer_tag++; 889 + if (ttt == 0xFFFFFFFF) 890 + ttt = session->targ_xfer_tag++; 891 + spin_unlock_bh(&session->ttt_lock); 892 + 893 + return ttt; 894 + } 895 + 896 + extern struct iscsi_cmd *iscsit_find_cmd_from_itt(struct iscsi_conn *, itt_t); 883 897 #endif /* ISCSI_TARGET_CORE_H */
+1 -1
drivers/target/iscsi/iscsi_target_datain_values.c
··· 18 18 19 19 #include <scsi/iscsi_proto.h> 20 20 21 - #include "iscsi_target_core.h" 21 + #include <target/iscsi/iscsi_target_core.h> 22 22 #include "iscsi_target_seq_pdu_list.h" 23 23 #include "iscsi_target_erl1.h" 24 24 #include "iscsi_target_util.h"
+1 -1
drivers/target/iscsi/iscsi_target_device.c
··· 21 21 #include <target/target_core_base.h> 22 22 #include <target/target_core_fabric.h> 23 23 24 - #include "iscsi_target_core.h" 24 + #include <target/iscsi/iscsi_target_core.h> 25 25 #include "iscsi_target_device.h" 26 26 #include "iscsi_target_tpg.h" 27 27 #include "iscsi_target_util.h"
+4 -2
drivers/target/iscsi/iscsi_target_erl0.c
··· 21 21 #include <target/target_core_base.h> 22 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 26 #include "iscsi_target_seq_pdu_list.h" 26 27 #include "iscsi_target_tq.h" 27 28 #include "iscsi_target_erl0.h" ··· 940 939 941 940 if (conn->conn_state == TARG_CONN_STATE_IN_LOGOUT) { 942 941 spin_unlock_bh(&conn->state_lock); 943 - iscsit_close_connection(conn); 942 + if (conn->conn_transport->transport_type == ISCSI_TCP) 943 + iscsit_close_connection(conn); 944 944 return; 945 945 } 946 946
+1 -1
drivers/target/iscsi/iscsi_target_erl1.c
··· 22 22 #include <target/target_core_fabric.h> 23 23 #include <target/iscsi/iscsi_transport.h> 24 24 25 - #include "iscsi_target_core.h" 25 + #include <target/iscsi/iscsi_target_core.h> 26 26 #include "iscsi_target_seq_pdu_list.h" 27 27 #include "iscsi_target_datain_values.h" 28 28 #include "iscsi_target_device.h"
+1 -1
drivers/target/iscsi/iscsi_target_erl2.c
··· 21 21 #include <target/target_core_base.h> 22 22 #include <target/target_core_fabric.h> 23 23 24 - #include "iscsi_target_core.h" 24 + #include <target/iscsi/iscsi_target_core.h> 25 25 #include "iscsi_target_datain_values.h" 26 26 #include "iscsi_target_util.h" 27 27 #include "iscsi_target_erl0.h"
+2 -2
drivers/target/iscsi/iscsi_target_login.c
··· 24 24 #include <target/target_core_base.h> 25 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 29 #include "iscsi_target_tq.h" 29 30 #include "iscsi_target_device.h" 30 31 #include "iscsi_target_nego.h" 31 32 #include "iscsi_target_erl0.h" 32 33 #include "iscsi_target_erl2.h" 33 34 #include "iscsi_target_login.h" 34 - #include "iscsi_target_stat.h" 35 35 #include "iscsi_target_tpg.h" 36 36 #include "iscsi_target_util.h" 37 37 #include "iscsi_target.h"
+1 -1
drivers/target/iscsi/iscsi_target_nego.c
··· 22 22 #include <target/target_core_fabric.h> 23 23 #include <target/iscsi/iscsi_transport.h> 24 24 25 - #include "iscsi_target_core.h" 25 + #include <target/iscsi/iscsi_target_core.h> 26 26 #include "iscsi_target_parameters.h" 27 27 #include "iscsi_target_login.h" 28 28 #include "iscsi_target_nego.h"
+1 -1
drivers/target/iscsi/iscsi_target_nodeattrib.c
··· 18 18 19 19 #include <target/target_core_base.h> 20 20 21 - #include "iscsi_target_core.h" 21 + #include <target/iscsi/iscsi_target_core.h> 22 22 #include "iscsi_target_device.h" 23 23 #include "iscsi_target_tpg.h" 24 24 #include "iscsi_target_util.h"
+1 -1
drivers/target/iscsi/iscsi_target_parameters.c
··· 18 18 19 19 #include <linux/slab.h> 20 20 21 - #include "iscsi_target_core.h" 21 + #include <target/iscsi/iscsi_target_core.h> 22 22 #include "iscsi_target_util.h" 23 23 #include "iscsi_target_parameters.h" 24 24
+1 -1
drivers/target/iscsi/iscsi_target_seq_pdu_list.c
··· 20 20 #include <linux/slab.h> 21 21 #include <linux/random.h> 22 22 23 - #include "iscsi_target_core.h" 23 + #include <target/iscsi/iscsi_target_core.h> 24 24 #include "iscsi_target_util.h" 25 25 #include "iscsi_target_tpg.h" 26 26 #include "iscsi_target_seq_pdu_list.h"
+2 -2
drivers/target/iscsi/iscsi_target_stat.c
··· 23 23 #include <target/target_core_base.h> 24 24 #include <target/configfs_macros.h> 25 25 26 - #include "iscsi_target_core.h" 26 + #include <target/iscsi/iscsi_target_core.h> 27 27 #include "iscsi_target_parameters.h" 28 28 #include "iscsi_target_device.h" 29 29 #include "iscsi_target_tpg.h" 30 30 #include "iscsi_target_util.h" 31 - #include "iscsi_target_stat.h" 31 + #include <target/iscsi/iscsi_target_stat.h> 32 32 33 33 #ifndef INITIAL_JIFFIES 34 34 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
drivers/target/iscsi/iscsi_target_stat.h include/target/iscsi/iscsi_target_stat.h
+1 -1
drivers/target/iscsi/iscsi_target_tmr.c
··· 23 23 #include <target/target_core_fabric.h> 24 24 #include <target/iscsi/iscsi_transport.h> 25 25 26 - #include "iscsi_target_core.h" 26 + #include <target/iscsi/iscsi_target_core.h> 27 27 #include "iscsi_target_seq_pdu_list.h" 28 28 #include "iscsi_target_datain_values.h" 29 29 #include "iscsi_target_device.h"
+1 -1
drivers/target/iscsi/iscsi_target_tpg.c
··· 20 20 #include <target/target_core_fabric.h> 21 21 #include <target/target_core_configfs.h> 22 22 23 - #include "iscsi_target_core.h" 23 + #include <target/iscsi/iscsi_target_core.h> 24 24 #include "iscsi_target_erl0.h" 25 25 #include "iscsi_target_login.h" 26 26 #include "iscsi_target_nodeattrib.h"
+6 -24
drivers/target/iscsi/iscsi_target_tq.c
··· 20 20 #include <linux/list.h> 21 21 #include <linux/bitmap.h> 22 22 23 - #include "iscsi_target_core.h" 23 + #include <target/iscsi/iscsi_target_core.h> 24 24 #include "iscsi_target_tq.h" 25 25 #include "iscsi_target.h" 26 26 27 - static LIST_HEAD(active_ts_list); 28 27 static LIST_HEAD(inactive_ts_list); 29 - static DEFINE_SPINLOCK(active_ts_lock); 30 28 static DEFINE_SPINLOCK(inactive_ts_lock); 31 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 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 37 spin_lock(&inactive_ts_lock); 44 38 list_add_tail(&ts->ts_list, &inactive_ts_list); 45 39 iscsit_global->inactive_ts++; 46 40 spin_unlock(&inactive_ts_lock); 47 - } 48 - 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 41 } 56 42 57 43 static struct iscsi_thread_set *iscsi_get_ts_from_inactive_list(void) ··· 52 66 53 67 ts = list_first_entry(&inactive_ts_list, struct iscsi_thread_set, ts_list); 54 68 55 - list_del(&ts->ts_list); 69 + list_del_init(&ts->ts_list); 56 70 iscsit_global->inactive_ts--; 57 71 spin_unlock(&inactive_ts_lock); 58 72 ··· 190 204 191 205 void iscsi_activate_thread_set(struct iscsi_conn *conn, struct iscsi_thread_set *ts) 192 206 { 193 - iscsi_add_ts_to_active_list(ts); 194 - 195 207 spin_lock_bh(&ts->ts_state_lock); 196 208 conn->thread_set = ts; 197 209 ts->conn = conn; ··· 381 397 382 398 if (ts->delay_inactive && (--ts->thread_count == 0)) { 383 399 spin_unlock_bh(&ts->ts_state_lock); 384 - iscsi_del_ts_from_active_list(ts); 385 400 386 401 if (!iscsit_global->in_shutdown) 387 402 iscsi_deallocate_extra_thread_sets(); ··· 435 452 436 453 if (ts->delay_inactive && (--ts->thread_count == 0)) { 437 454 spin_unlock_bh(&ts->ts_state_lock); 438 - iscsi_del_ts_from_active_list(ts); 439 455 440 456 if (!iscsit_global->in_shutdown) 441 457 iscsi_deallocate_extra_thread_sets();
+4 -8
drivers/target/iscsi/iscsi_target_util.c
··· 25 25 #include <target/target_core_configfs.h> 26 26 #include <target/iscsi/iscsi_transport.h> 27 27 28 - #include "iscsi_target_core.h" 28 + #include <target/iscsi/iscsi_target_core.h> 29 29 #include "iscsi_target_parameters.h" 30 30 #include "iscsi_target_seq_pdu_list.h" 31 31 #include "iscsi_target_datain_values.h" ··· 390 390 init_task_tag, conn->cid); 391 391 return NULL; 392 392 } 393 + EXPORT_SYMBOL(iscsit_find_cmd_from_itt); 393 394 394 395 struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump( 395 396 struct iscsi_conn *conn, ··· 940 939 state = (want_response) ? ISTATE_SEND_NOPIN_WANT_RESPONSE : 941 940 ISTATE_SEND_NOPIN_NO_RESPONSE; 942 941 cmd->init_task_tag = RESERVED_ITT; 943 - spin_lock_bh(&conn->sess->ttt_lock); 944 - cmd->targ_xfer_tag = (want_response) ? conn->sess->targ_xfer_tag++ : 945 - 0xFFFFFFFF; 946 - if (want_response && (cmd->targ_xfer_tag == 0xFFFFFFFF)) 947 - cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; 948 - spin_unlock_bh(&conn->sess->ttt_lock); 949 - 942 + cmd->targ_xfer_tag = (want_response) ? 943 + session_get_next_ttt(conn->sess) : 0xFFFFFFFF; 950 944 spin_lock_bh(&conn->cmd_lock); 951 945 list_add_tail(&cmd->i_conn_node, &conn->conn_cmd_list); 952 946 spin_unlock_bh(&conn->cmd_lock);
-1
drivers/target/iscsi/iscsi_target_util.h
··· 16 16 extern int iscsit_sequence_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, 17 17 unsigned char * ,__be32 cmdsn); 18 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 19 extern struct iscsi_cmd *iscsit_find_cmd_from_itt_or_dump(struct iscsi_conn *, 21 20 itt_t, u32); 22 21 extern struct iscsi_cmd *iscsit_find_cmd_from_ttt(struct iscsi_conn *, u32);
+5
drivers/target/target_core_file.c
··· 494 494 target_complete_cmd(cmd, SAM_STAT_GOOD); 495 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 502 sg = &cmd->t_data_sg[0]; 498 503 499 504 if (cmd->t_data_nents > 1 ||
+5
drivers/target/target_core_iblock.c
··· 464 464 sector_t block_lba = cmd->t_task_lba; 465 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 472 sg = &cmd->t_data_sg[0]; 468 473 469 474 if (cmd->t_data_nents > 1 ||
+13 -12
drivers/target/target_core_pr.c
··· 1874 1874 } 1875 1875 1876 1876 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { 1877 - pr_err("Unable to update renaming" 1878 - " APTPL metadata\n"); 1877 + pr_err("Unable to update renaming APTPL metadata," 1878 + " reallocating larger buffer\n"); 1879 1879 ret = -EMSGSIZE; 1880 1880 goto out; 1881 1881 } ··· 1892 1892 lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); 1893 1893 1894 1894 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { 1895 - pr_err("Unable to update renaming" 1896 - " APTPL metadata\n"); 1895 + pr_err("Unable to update renaming APTPL metadata," 1896 + " reallocating larger buffer\n"); 1897 1897 ret = -EMSGSIZE; 1898 1898 goto out; 1899 1899 } ··· 1956 1956 static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl) 1957 1957 { 1958 1958 unsigned char *buf; 1959 - int rc; 1959 + int rc, len = PR_APTPL_BUF_LEN; 1960 1960 1961 1961 if (!aptpl) { 1962 1962 char *null_buf = "No Registrations or Reservations\n"; ··· 1970 1970 1971 1971 return 0; 1972 1972 } 1973 - 1974 - buf = kzalloc(PR_APTPL_BUF_LEN, GFP_KERNEL); 1973 + retry: 1974 + buf = vzalloc(len); 1975 1975 if (!buf) 1976 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 1979 if (rc < 0) { 1980 - kfree(buf); 1981 - return TCM_OUT_OF_RESOURCES; 1980 + vfree(buf); 1981 + len *= 2; 1982 + goto retry; 1982 1983 } 1983 1984 1984 1985 rc = __core_scsi3_write_aptpl_to_file(dev, buf); 1985 1986 if (rc != 0) { 1986 1987 pr_err("SPC-3 PR: Could not update APTPL\n"); 1987 - kfree(buf); 1988 + vfree(buf); 1988 1989 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1989 1990 } 1990 1991 dev->t10_pr.pr_aptpl_active = 1; 1991 - kfree(buf); 1992 + vfree(buf); 1992 1993 pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); 1993 1994 return 0; 1994 1995 }
+110 -30
drivers/target/target_core_sbc.c
··· 37 37 #include "target_core_alua.h" 38 38 39 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 43 sbc_emulate_readcapacity(struct se_cmd *cmd) 41 44 { 42 45 struct se_device *dev = cmd->se_dev; ··· 254 251 static sense_reason_t 255 252 sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops) 256 253 { 254 + struct se_device *dev = cmd->se_dev; 255 + sector_t end_lba = dev->transport->get_blocks(dev) + 1; 257 256 unsigned int sectors = sbc_get_write_same_sectors(cmd); 257 + sense_reason_t ret; 258 258 259 259 if ((flags[0] & 0x04) || (flags[0] & 0x02)) { 260 260 pr_err("WRITE_SAME PBDATA and LBDATA" ··· 270 264 sectors, cmd->se_dev->dev_attrib.max_write_same_len); 271 265 return TCM_INVALID_CDB_FIELD; 272 266 } 267 + /* 268 + * Sanity check for LBA wrap and request past end of device. 269 + */ 270 + if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || 271 + ((cmd->t_task_lba + sectors) > end_lba)) { 272 + pr_err("WRITE_SAME exceeds last lba %llu (lba %llu, sectors %u)\n", 273 + (unsigned long long)end_lba, cmd->t_task_lba, sectors); 274 + return TCM_ADDRESS_OUT_OF_RANGE; 275 + } 276 + 273 277 /* We always have ANC_SUP == 0 so setting ANCHOR is always an error */ 274 278 if (flags[0] & 0x10) { 275 279 pr_warn("WRITE SAME with ANCHOR not supported\n"); ··· 293 277 if (!ops->execute_write_same_unmap) 294 278 return TCM_UNSUPPORTED_SCSI_OPCODE; 295 279 280 + if (!dev->dev_attrib.emulate_tpws) { 281 + pr_err("Got WRITE_SAME w/ UNMAP=1, but backend device" 282 + " has emulate_tpws disabled\n"); 283 + return TCM_UNSUPPORTED_SCSI_OPCODE; 284 + } 296 285 cmd->execute_cmd = ops->execute_write_same_unmap; 297 286 return 0; 298 287 } 299 288 if (!ops->execute_write_same) 300 289 return TCM_UNSUPPORTED_SCSI_OPCODE; 290 + 291 + ret = sbc_check_prot(dev, cmd, &cmd->t_task_cdb[0], sectors, true); 292 + if (ret) 293 + return ret; 301 294 302 295 cmd->execute_cmd = ops->execute_write_same; 303 296 return 0; ··· 639 614 return 0; 640 615 } 641 616 642 - static bool 617 + static sense_reason_t 643 618 sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb, 644 619 u32 sectors, bool is_write) 645 620 { 646 621 u8 protect = cdb[1] >> 5; 647 622 648 - if ((!cmd->t_prot_sg || !cmd->t_prot_nents) && cmd->prot_pto) 649 - return true; 623 + if (!cmd->t_prot_sg || !cmd->t_prot_nents) { 624 + if (protect && !dev->dev_attrib.pi_prot_type) { 625 + pr_err("CDB contains protect bit, but device does not" 626 + " advertise PROTECT=1 feature bit\n"); 627 + return TCM_INVALID_CDB_FIELD; 628 + } 629 + if (cmd->prot_pto) 630 + return TCM_NO_SENSE; 631 + } 650 632 651 633 switch (dev->dev_attrib.pi_prot_type) { 652 634 case TARGET_DIF_TYPE3_PROT: ··· 661 629 break; 662 630 case TARGET_DIF_TYPE2_PROT: 663 631 if (protect) 664 - return false; 632 + return TCM_INVALID_CDB_FIELD; 665 633 666 634 cmd->reftag_seed = cmd->t_task_lba; 667 635 break; ··· 670 638 break; 671 639 case TARGET_DIF_TYPE0_PROT: 672 640 default: 673 - return true; 641 + return TCM_NO_SENSE; 674 642 } 675 643 676 644 if (sbc_set_prot_op_checks(protect, dev->dev_attrib.pi_prot_type, 677 645 is_write, cmd)) 678 - return false; 646 + return TCM_INVALID_CDB_FIELD; 679 647 680 648 cmd->prot_type = dev->dev_attrib.pi_prot_type; 681 649 cmd->prot_length = dev->prot_length * sectors; ··· 694 662 __func__, cmd->prot_type, cmd->data_length, cmd->prot_length, 695 663 cmd->prot_op, cmd->prot_checks); 696 664 697 - return true; 665 + return TCM_NO_SENSE; 666 + } 667 + 668 + static int 669 + sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb) 670 + { 671 + if (cdb[1] & 0x10) { 672 + if (!dev->dev_attrib.emulate_dpo) { 673 + pr_err("Got CDB: 0x%02x with DPO bit set, but device" 674 + " does not advertise support for DPO\n", cdb[0]); 675 + return -EINVAL; 676 + } 677 + } 678 + if (cdb[1] & 0x8) { 679 + if (!dev->dev_attrib.emulate_fua_write || 680 + !dev->dev_attrib.emulate_write_cache) { 681 + pr_err("Got CDB: 0x%02x with FUA bit set, but device" 682 + " does not advertise support for FUA write\n", 683 + cdb[0]); 684 + return -EINVAL; 685 + } 686 + cmd->se_cmd_flags |= SCF_FUA; 687 + } 688 + return 0; 698 689 } 699 690 700 691 sense_reason_t ··· 741 686 sectors = transport_get_sectors_10(cdb); 742 687 cmd->t_task_lba = transport_lba_32(cdb); 743 688 744 - if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) 745 - return TCM_UNSUPPORTED_SCSI_OPCODE; 689 + if (sbc_check_dpofua(dev, cmd, cdb)) 690 + return TCM_INVALID_CDB_FIELD; 691 + 692 + ret = sbc_check_prot(dev, cmd, cdb, sectors, false); 693 + if (ret) 694 + return ret; 746 695 747 696 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 748 697 cmd->execute_rw = ops->execute_rw; ··· 756 697 sectors = transport_get_sectors_12(cdb); 757 698 cmd->t_task_lba = transport_lba_32(cdb); 758 699 759 - if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) 760 - return TCM_UNSUPPORTED_SCSI_OPCODE; 700 + if (sbc_check_dpofua(dev, cmd, cdb)) 701 + return TCM_INVALID_CDB_FIELD; 702 + 703 + ret = sbc_check_prot(dev, cmd, cdb, sectors, false); 704 + if (ret) 705 + return ret; 761 706 762 707 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 763 708 cmd->execute_rw = ops->execute_rw; ··· 771 708 sectors = transport_get_sectors_16(cdb); 772 709 cmd->t_task_lba = transport_lba_64(cdb); 773 710 774 - if (!sbc_check_prot(dev, cmd, cdb, sectors, false)) 775 - return TCM_UNSUPPORTED_SCSI_OPCODE; 711 + if (sbc_check_dpofua(dev, cmd, cdb)) 712 + return TCM_INVALID_CDB_FIELD; 713 + 714 + ret = sbc_check_prot(dev, cmd, cdb, sectors, false); 715 + if (ret) 716 + return ret; 776 717 777 718 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 778 719 cmd->execute_rw = ops->execute_rw; ··· 794 727 sectors = transport_get_sectors_10(cdb); 795 728 cmd->t_task_lba = transport_lba_32(cdb); 796 729 797 - if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) 798 - return TCM_UNSUPPORTED_SCSI_OPCODE; 730 + if (sbc_check_dpofua(dev, cmd, cdb)) 731 + return TCM_INVALID_CDB_FIELD; 799 732 800 - if (cdb[1] & 0x8) 801 - cmd->se_cmd_flags |= SCF_FUA; 733 + ret = sbc_check_prot(dev, cmd, cdb, sectors, true); 734 + if (ret) 735 + return ret; 736 + 802 737 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 803 738 cmd->execute_rw = ops->execute_rw; 804 739 cmd->execute_cmd = sbc_execute_rw; ··· 809 740 sectors = transport_get_sectors_12(cdb); 810 741 cmd->t_task_lba = transport_lba_32(cdb); 811 742 812 - if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) 813 - return TCM_UNSUPPORTED_SCSI_OPCODE; 743 + if (sbc_check_dpofua(dev, cmd, cdb)) 744 + return TCM_INVALID_CDB_FIELD; 814 745 815 - if (cdb[1] & 0x8) 816 - cmd->se_cmd_flags |= SCF_FUA; 746 + ret = sbc_check_prot(dev, cmd, cdb, sectors, true); 747 + if (ret) 748 + return ret; 749 + 817 750 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 818 751 cmd->execute_rw = ops->execute_rw; 819 752 cmd->execute_cmd = sbc_execute_rw; ··· 824 753 sectors = transport_get_sectors_16(cdb); 825 754 cmd->t_task_lba = transport_lba_64(cdb); 826 755 827 - if (!sbc_check_prot(dev, cmd, cdb, sectors, true)) 828 - return TCM_UNSUPPORTED_SCSI_OPCODE; 756 + if (sbc_check_dpofua(dev, cmd, cdb)) 757 + return TCM_INVALID_CDB_FIELD; 829 758 830 - if (cdb[1] & 0x8) 831 - cmd->se_cmd_flags |= SCF_FUA; 759 + ret = sbc_check_prot(dev, cmd, cdb, sectors, true); 760 + if (ret) 761 + return ret; 762 + 832 763 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 833 764 cmd->execute_rw = ops->execute_rw; 834 765 cmd->execute_cmd = sbc_execute_rw; ··· 841 768 return TCM_INVALID_CDB_FIELD; 842 769 sectors = transport_get_sectors_10(cdb); 843 770 771 + if (sbc_check_dpofua(dev, cmd, cdb)) 772 + return TCM_INVALID_CDB_FIELD; 773 + 844 774 cmd->t_task_lba = transport_lba_32(cdb); 845 775 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 846 776 ··· 853 777 cmd->execute_rw = ops->execute_rw; 854 778 cmd->execute_cmd = sbc_execute_rw; 855 779 cmd->transport_complete_callback = &xdreadwrite_callback; 856 - if (cdb[1] & 0x8) 857 - cmd->se_cmd_flags |= SCF_FUA; 858 780 break; 859 781 case VARIABLE_LENGTH_CMD: 860 782 { ··· 861 787 case XDWRITEREAD_32: 862 788 sectors = transport_get_sectors_32(cdb); 863 789 790 + if (sbc_check_dpofua(dev, cmd, cdb)) 791 + return TCM_INVALID_CDB_FIELD; 864 792 /* 865 793 * Use WRITE_32 and READ_32 opcodes for the emulated 866 794 * XDWRITE_READ_32 logic. ··· 877 801 cmd->execute_rw = ops->execute_rw; 878 802 cmd->execute_cmd = sbc_execute_rw; 879 803 cmd->transport_complete_callback = &xdreadwrite_callback; 880 - if (cdb[1] & 0x8) 881 - cmd->se_cmd_flags |= SCF_FUA; 882 804 break; 883 805 case WRITE_SAME_32: 884 806 sectors = transport_get_sectors_32(cdb); ··· 962 888 if (!ops->execute_unmap) 963 889 return TCM_UNSUPPORTED_SCSI_OPCODE; 964 890 891 + if (!dev->dev_attrib.emulate_tpu) { 892 + pr_err("Got UNMAP, but backend device has" 893 + " emulate_tpu disabled\n"); 894 + return TCM_UNSUPPORTED_SCSI_OPCODE; 895 + } 965 896 size = get_unaligned_be16(&cdb[7]); 966 897 cmd->execute_cmd = ops->execute_unmap; 967 898 break; ··· 1034 955 unsigned long long end_lba; 1035 956 check_lba: 1036 957 end_lba = dev->transport->get_blocks(dev) + 1; 1037 - if (cmd->t_task_lba + sectors > end_lba) { 958 + if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || 959 + ((cmd->t_task_lba + sectors) > end_lba)) { 1038 960 pr_err("cmd exceeds last lba %llu " 1039 961 "(lba %llu, sectors %u)\n", 1040 962 end_lba, cmd->t_task_lba, sectors);
+1 -1
drivers/target/target_core_spc.c
··· 647 647 * support the use of the WRITE SAME (16) command to unmap LBAs. 648 648 */ 649 649 if (dev->dev_attrib.emulate_tpws != 0) 650 - buf[5] |= 0x40; 650 + buf[5] |= 0x40 | 0x20; 651 651 652 652 return 0; 653 653 }
+538 -524
drivers/vhost/scsi.c
··· 38 38 #include <linux/miscdevice.h> 39 39 #include <asm/unaligned.h> 40 40 #include <scsi/scsi.h> 41 - #include <scsi/scsi_tcq.h> 42 41 #include <target/target_core_base.h> 43 42 #include <target/target_core_fabric.h> 44 43 #include <target/target_core_fabric_configfs.h> ··· 51 52 52 53 #include "vhost.h" 53 54 54 - #define TCM_VHOST_VERSION "v0.1" 55 - #define TCM_VHOST_NAMELEN 256 56 - #define TCM_VHOST_MAX_CDB_SIZE 32 57 - #define TCM_VHOST_DEFAULT_TAGS 256 58 - #define TCM_VHOST_PREALLOC_SGLS 2048 59 - #define TCM_VHOST_PREALLOC_UPAGES 2048 60 - #define TCM_VHOST_PREALLOC_PROT_SGLS 512 55 + #define VHOST_SCSI_VERSION "v0.1" 56 + #define VHOST_SCSI_NAMELEN 256 57 + #define VHOST_SCSI_MAX_CDB_SIZE 32 58 + #define VHOST_SCSI_DEFAULT_TAGS 256 59 + #define VHOST_SCSI_PREALLOC_SGLS 2048 60 + #define VHOST_SCSI_PREALLOC_UPAGES 2048 61 + #define VHOST_SCSI_PREALLOC_PROT_SGLS 512 61 62 62 63 struct vhost_scsi_inflight { 63 64 /* Wait for the flush operation to finish */ ··· 66 67 struct kref kref; 67 68 }; 68 69 69 - struct tcm_vhost_cmd { 70 + struct vhost_scsi_cmd { 70 71 /* Descriptor from vhost_get_vq_desc() for virt_queue segment */ 71 72 int tvc_vq_desc; 72 73 /* virtio-scsi initiator task attribute */ 73 74 int tvc_task_attr; 75 + /* virtio-scsi response incoming iovecs */ 76 + int tvc_in_iovs; 74 77 /* virtio-scsi initiator data direction */ 75 78 enum dma_data_direction tvc_data_direction; 76 79 /* Expected data transfer length from virtio-scsi header */ ··· 82 81 /* The number of scatterlists associated with this cmd */ 83 82 u32 tvc_sgl_count; 84 83 u32 tvc_prot_sgl_count; 85 - /* Saved unpacked SCSI LUN for tcm_vhost_submission_work() */ 84 + /* Saved unpacked SCSI LUN for vhost_scsi_submission_work() */ 86 85 u32 tvc_lun; 87 86 /* Pointer to the SGL formatted memory from virtio-scsi */ 88 87 struct scatterlist *tvc_sgl; 89 88 struct scatterlist *tvc_prot_sgl; 90 89 struct page **tvc_upages; 91 - /* Pointer to response */ 92 - struct virtio_scsi_cmd_resp __user *tvc_resp; 90 + /* Pointer to response header iovec */ 91 + struct iovec *tvc_resp_iov; 93 92 /* Pointer to vhost_scsi for our device */ 94 93 struct vhost_scsi *tvc_vhost; 95 94 /* Pointer to vhost_virtqueue for the cmd */ 96 95 struct vhost_virtqueue *tvc_vq; 97 96 /* Pointer to vhost nexus memory */ 98 - struct tcm_vhost_nexus *tvc_nexus; 97 + struct vhost_scsi_nexus *tvc_nexus; 99 98 /* The TCM I/O descriptor that is accessed via container_of() */ 100 99 struct se_cmd tvc_se_cmd; 101 - /* work item used for cmwq dispatch to tcm_vhost_submission_work() */ 100 + /* work item used for cmwq dispatch to vhost_scsi_submission_work() */ 102 101 struct work_struct work; 103 102 /* Copy of the incoming SCSI command descriptor block (CDB) */ 104 - unsigned char tvc_cdb[TCM_VHOST_MAX_CDB_SIZE]; 103 + unsigned char tvc_cdb[VHOST_SCSI_MAX_CDB_SIZE]; 105 104 /* Sense buffer that will be mapped into outgoing status */ 106 105 unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER]; 107 106 /* Completed commands list, serviced from vhost worker thread */ ··· 110 109 struct vhost_scsi_inflight *inflight; 111 110 }; 112 111 113 - struct tcm_vhost_nexus { 112 + struct vhost_scsi_nexus { 114 113 /* Pointer to TCM session for I_T Nexus */ 115 114 struct se_session *tvn_se_sess; 116 115 }; 117 116 118 - struct tcm_vhost_nacl { 117 + struct vhost_scsi_nacl { 119 118 /* Binary World Wide unique Port Name for Vhost Initiator port */ 120 119 u64 iport_wwpn; 121 120 /* ASCII formatted WWPN for Sas Initiator port */ 122 - char iport_name[TCM_VHOST_NAMELEN]; 123 - /* Returned by tcm_vhost_make_nodeacl() */ 121 + char iport_name[VHOST_SCSI_NAMELEN]; 122 + /* Returned by vhost_scsi_make_nodeacl() */ 124 123 struct se_node_acl se_node_acl; 125 124 }; 126 125 127 - struct tcm_vhost_tpg { 126 + struct vhost_scsi_tpg { 128 127 /* Vhost port target portal group tag for TCM */ 129 128 u16 tport_tpgt; 130 129 /* Used to track number of TPG Port/Lun Links wrt to explict I_T Nexus shutdown */ 131 130 int tv_tpg_port_count; 132 131 /* Used for vhost_scsi device reference to tpg_nexus, protected by tv_tpg_mutex */ 133 132 int tv_tpg_vhost_count; 134 - /* list for tcm_vhost_list */ 133 + /* list for vhost_scsi_list */ 135 134 struct list_head tv_tpg_list; 136 135 /* Used to protect access for tpg_nexus */ 137 136 struct mutex tv_tpg_mutex; 138 137 /* Pointer to the TCM VHost I_T Nexus for this TPG endpoint */ 139 - struct tcm_vhost_nexus *tpg_nexus; 140 - /* Pointer back to tcm_vhost_tport */ 141 - struct tcm_vhost_tport *tport; 142 - /* Returned by tcm_vhost_make_tpg() */ 138 + struct vhost_scsi_nexus *tpg_nexus; 139 + /* Pointer back to vhost_scsi_tport */ 140 + struct vhost_scsi_tport *tport; 141 + /* Returned by vhost_scsi_make_tpg() */ 143 142 struct se_portal_group se_tpg; 144 143 /* Pointer back to vhost_scsi, protected by tv_tpg_mutex */ 145 144 struct vhost_scsi *vhost_scsi; 146 145 }; 147 146 148 - struct tcm_vhost_tport { 147 + struct vhost_scsi_tport { 149 148 /* SCSI protocol the tport is providing */ 150 149 u8 tport_proto_id; 151 150 /* Binary World Wide unique Port Name for Vhost Target port */ 152 151 u64 tport_wwpn; 153 152 /* ASCII formatted WWPN for Vhost Target port */ 154 - char tport_name[TCM_VHOST_NAMELEN]; 155 - /* Returned by tcm_vhost_make_tport() */ 153 + char tport_name[VHOST_SCSI_NAMELEN]; 154 + /* Returned by vhost_scsi_make_tport() */ 156 155 struct se_wwn tport_wwn; 157 156 }; 158 157 159 - struct tcm_vhost_evt { 158 + struct vhost_scsi_evt { 160 159 /* event to be sent to guest */ 161 160 struct virtio_scsi_event event; 162 161 /* event list, serviced from vhost worker thread */ ··· 172 171 /* Note: can't set VIRTIO_F_VERSION_1 yet, since that implies ANY_LAYOUT. */ 173 172 enum { 174 173 VHOST_SCSI_FEATURES = VHOST_FEATURES | (1ULL << VIRTIO_SCSI_F_HOTPLUG) | 175 - (1ULL << VIRTIO_SCSI_F_T10_PI) 174 + (1ULL << VIRTIO_SCSI_F_T10_PI) | 175 + (1ULL << VIRTIO_F_ANY_LAYOUT) | 176 + (1ULL << VIRTIO_F_VERSION_1) 176 177 }; 177 178 178 179 #define VHOST_SCSI_MAX_TARGET 256 ··· 198 195 199 196 struct vhost_scsi { 200 197 /* Protected by vhost_scsi->dev.mutex */ 201 - struct tcm_vhost_tpg **vs_tpg; 198 + struct vhost_scsi_tpg **vs_tpg; 202 199 char vs_vhost_wwpn[TRANSPORT_IQN_LEN]; 203 200 204 201 struct vhost_dev dev; ··· 215 212 }; 216 213 217 214 /* Local pointer to allocated TCM configfs fabric module */ 218 - static struct target_fabric_configfs *tcm_vhost_fabric_configfs; 215 + static struct target_fabric_configfs *vhost_scsi_fabric_configfs; 219 216 220 - static struct workqueue_struct *tcm_vhost_workqueue; 217 + static struct workqueue_struct *vhost_scsi_workqueue; 221 218 222 - /* Global spinlock to protect tcm_vhost TPG list for vhost IOCTL access */ 223 - static DEFINE_MUTEX(tcm_vhost_mutex); 224 - static LIST_HEAD(tcm_vhost_list); 219 + /* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */ 220 + static DEFINE_MUTEX(vhost_scsi_mutex); 221 + static LIST_HEAD(vhost_scsi_list); 225 222 226 - static int iov_num_pages(struct iovec *iov) 223 + static int iov_num_pages(void __user *iov_base, size_t iov_len) 227 224 { 228 - return (PAGE_ALIGN((unsigned long)iov->iov_base + iov->iov_len) - 229 - ((unsigned long)iov->iov_base & PAGE_MASK)) >> PAGE_SHIFT; 225 + return (PAGE_ALIGN((unsigned long)iov_base + iov_len) - 226 + ((unsigned long)iov_base & PAGE_MASK)) >> PAGE_SHIFT; 230 227 } 231 228 232 - static void tcm_vhost_done_inflight(struct kref *kref) 229 + static void vhost_scsi_done_inflight(struct kref *kref) 233 230 { 234 231 struct vhost_scsi_inflight *inflight; 235 232 ··· 237 234 complete(&inflight->comp); 238 235 } 239 236 240 - static void tcm_vhost_init_inflight(struct vhost_scsi *vs, 237 + static void vhost_scsi_init_inflight(struct vhost_scsi *vs, 241 238 struct vhost_scsi_inflight *old_inflight[]) 242 239 { 243 240 struct vhost_scsi_inflight *new_inflight; ··· 265 262 } 266 263 267 264 static struct vhost_scsi_inflight * 268 - tcm_vhost_get_inflight(struct vhost_virtqueue *vq) 265 + vhost_scsi_get_inflight(struct vhost_virtqueue *vq) 269 266 { 270 267 struct vhost_scsi_inflight *inflight; 271 268 struct vhost_scsi_virtqueue *svq; ··· 277 274 return inflight; 278 275 } 279 276 280 - static void tcm_vhost_put_inflight(struct vhost_scsi_inflight *inflight) 277 + static void vhost_scsi_put_inflight(struct vhost_scsi_inflight *inflight) 281 278 { 282 - kref_put(&inflight->kref, tcm_vhost_done_inflight); 279 + kref_put(&inflight->kref, vhost_scsi_done_inflight); 283 280 } 284 281 285 - static int tcm_vhost_check_true(struct se_portal_group *se_tpg) 282 + static int vhost_scsi_check_true(struct se_portal_group *se_tpg) 286 283 { 287 284 return 1; 288 285 } 289 286 290 - static int tcm_vhost_check_false(struct se_portal_group *se_tpg) 287 + static int vhost_scsi_check_false(struct se_portal_group *se_tpg) 291 288 { 292 289 return 0; 293 290 } 294 291 295 - static char *tcm_vhost_get_fabric_name(void) 292 + static char *vhost_scsi_get_fabric_name(void) 296 293 { 297 294 return "vhost"; 298 295 } 299 296 300 - static u8 tcm_vhost_get_fabric_proto_ident(struct se_portal_group *se_tpg) 297 + static u8 vhost_scsi_get_fabric_proto_ident(struct se_portal_group *se_tpg) 301 298 { 302 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 303 - struct tcm_vhost_tpg, se_tpg); 304 - struct tcm_vhost_tport *tport = tpg->tport; 299 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 300 + struct vhost_scsi_tpg, se_tpg); 301 + struct vhost_scsi_tport *tport = tpg->tport; 305 302 306 303 switch (tport->tport_proto_id) { 307 304 case SCSI_PROTOCOL_SAS: ··· 319 316 return sas_get_fabric_proto_ident(se_tpg); 320 317 } 321 318 322 - static char *tcm_vhost_get_fabric_wwn(struct se_portal_group *se_tpg) 319 + static char *vhost_scsi_get_fabric_wwn(struct se_portal_group *se_tpg) 323 320 { 324 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 325 - struct tcm_vhost_tpg, se_tpg); 326 - struct tcm_vhost_tport *tport = tpg->tport; 321 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 322 + struct vhost_scsi_tpg, se_tpg); 323 + struct vhost_scsi_tport *tport = tpg->tport; 327 324 328 325 return &tport->tport_name[0]; 329 326 } 330 327 331 - static u16 tcm_vhost_get_tag(struct se_portal_group *se_tpg) 328 + static u16 vhost_scsi_get_tpgt(struct se_portal_group *se_tpg) 332 329 { 333 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 334 - struct tcm_vhost_tpg, se_tpg); 330 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 331 + struct vhost_scsi_tpg, se_tpg); 335 332 return tpg->tport_tpgt; 336 333 } 337 334 338 - static u32 tcm_vhost_get_default_depth(struct se_portal_group *se_tpg) 335 + static u32 vhost_scsi_get_default_depth(struct se_portal_group *se_tpg) 339 336 { 340 337 return 1; 341 338 } 342 339 343 340 static u32 344 - tcm_vhost_get_pr_transport_id(struct se_portal_group *se_tpg, 341 + vhost_scsi_get_pr_transport_id(struct se_portal_group *se_tpg, 345 342 struct se_node_acl *se_nacl, 346 343 struct t10_pr_registration *pr_reg, 347 344 int *format_code, 348 345 unsigned char *buf) 349 346 { 350 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 351 - struct tcm_vhost_tpg, se_tpg); 352 - struct tcm_vhost_tport *tport = tpg->tport; 347 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 348 + struct vhost_scsi_tpg, se_tpg); 349 + struct vhost_scsi_tport *tport = tpg->tport; 353 350 354 351 switch (tport->tport_proto_id) { 355 352 case SCSI_PROTOCOL_SAS: ··· 372 369 } 373 370 374 371 static u32 375 - tcm_vhost_get_pr_transport_id_len(struct se_portal_group *se_tpg, 372 + vhost_scsi_get_pr_transport_id_len(struct se_portal_group *se_tpg, 376 373 struct se_node_acl *se_nacl, 377 374 struct t10_pr_registration *pr_reg, 378 375 int *format_code) 379 376 { 380 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 381 - struct tcm_vhost_tpg, se_tpg); 382 - struct tcm_vhost_tport *tport = tpg->tport; 377 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 378 + struct vhost_scsi_tpg, se_tpg); 379 + struct vhost_scsi_tport *tport = tpg->tport; 383 380 384 381 switch (tport->tport_proto_id) { 385 382 case SCSI_PROTOCOL_SAS: ··· 402 399 } 403 400 404 401 static char * 405 - tcm_vhost_parse_pr_out_transport_id(struct se_portal_group *se_tpg, 402 + vhost_scsi_parse_pr_out_transport_id(struct se_portal_group *se_tpg, 406 403 const char *buf, 407 404 u32 *out_tid_len, 408 405 char **port_nexus_ptr) 409 406 { 410 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 411 - struct tcm_vhost_tpg, se_tpg); 412 - struct tcm_vhost_tport *tport = tpg->tport; 407 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 408 + struct vhost_scsi_tpg, se_tpg); 409 + struct vhost_scsi_tport *tport = tpg->tport; 413 410 414 411 switch (tport->tport_proto_id) { 415 412 case SCSI_PROTOCOL_SAS: ··· 432 429 } 433 430 434 431 static struct se_node_acl * 435 - tcm_vhost_alloc_fabric_acl(struct se_portal_group *se_tpg) 432 + vhost_scsi_alloc_fabric_acl(struct se_portal_group *se_tpg) 436 433 { 437 - struct tcm_vhost_nacl *nacl; 434 + struct vhost_scsi_nacl *nacl; 438 435 439 - nacl = kzalloc(sizeof(struct tcm_vhost_nacl), GFP_KERNEL); 436 + nacl = kzalloc(sizeof(struct vhost_scsi_nacl), GFP_KERNEL); 440 437 if (!nacl) { 441 - pr_err("Unable to allocate struct tcm_vhost_nacl\n"); 438 + pr_err("Unable to allocate struct vhost_scsi_nacl\n"); 442 439 return NULL; 443 440 } 444 441 ··· 446 443 } 447 444 448 445 static void 449 - tcm_vhost_release_fabric_acl(struct se_portal_group *se_tpg, 446 + vhost_scsi_release_fabric_acl(struct se_portal_group *se_tpg, 450 447 struct se_node_acl *se_nacl) 451 448 { 452 - struct tcm_vhost_nacl *nacl = container_of(se_nacl, 453 - struct tcm_vhost_nacl, se_node_acl); 449 + struct vhost_scsi_nacl *nacl = container_of(se_nacl, 450 + struct vhost_scsi_nacl, se_node_acl); 454 451 kfree(nacl); 455 452 } 456 453 457 - static u32 tcm_vhost_tpg_get_inst_index(struct se_portal_group *se_tpg) 454 + static u32 vhost_scsi_tpg_get_inst_index(struct se_portal_group *se_tpg) 458 455 { 459 456 return 1; 460 457 } 461 458 462 - static void tcm_vhost_release_cmd(struct se_cmd *se_cmd) 459 + static void vhost_scsi_release_cmd(struct se_cmd *se_cmd) 463 460 { 464 - struct tcm_vhost_cmd *tv_cmd = container_of(se_cmd, 465 - struct tcm_vhost_cmd, tvc_se_cmd); 466 - struct se_session *se_sess = se_cmd->se_sess; 461 + struct vhost_scsi_cmd *tv_cmd = container_of(se_cmd, 462 + struct vhost_scsi_cmd, tvc_se_cmd); 463 + struct se_session *se_sess = tv_cmd->tvc_nexus->tvn_se_sess; 467 464 int i; 468 465 469 466 if (tv_cmd->tvc_sgl_count) { ··· 475 472 put_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); 476 473 } 477 474 478 - tcm_vhost_put_inflight(tv_cmd->inflight); 475 + vhost_scsi_put_inflight(tv_cmd->inflight); 479 476 percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); 480 477 } 481 478 482 - static int tcm_vhost_shutdown_session(struct se_session *se_sess) 479 + static int vhost_scsi_shutdown_session(struct se_session *se_sess) 483 480 { 484 481 return 0; 485 482 } 486 483 487 - static void tcm_vhost_close_session(struct se_session *se_sess) 484 + static void vhost_scsi_close_session(struct se_session *se_sess) 488 485 { 489 486 return; 490 487 } 491 488 492 - static u32 tcm_vhost_sess_get_index(struct se_session *se_sess) 489 + static u32 vhost_scsi_sess_get_index(struct se_session *se_sess) 493 490 { 494 491 return 0; 495 492 } 496 493 497 - static int tcm_vhost_write_pending(struct se_cmd *se_cmd) 494 + static int vhost_scsi_write_pending(struct se_cmd *se_cmd) 498 495 { 499 496 /* Go ahead and process the write immediately */ 500 497 target_execute_cmd(se_cmd); 501 498 return 0; 502 499 } 503 500 504 - static int tcm_vhost_write_pending_status(struct se_cmd *se_cmd) 501 + static int vhost_scsi_write_pending_status(struct se_cmd *se_cmd) 505 502 { 506 503 return 0; 507 504 } 508 505 509 - static void tcm_vhost_set_default_node_attrs(struct se_node_acl *nacl) 506 + static void vhost_scsi_set_default_node_attrs(struct se_node_acl *nacl) 510 507 { 511 508 return; 512 509 } 513 510 514 - static u32 tcm_vhost_get_task_tag(struct se_cmd *se_cmd) 511 + static u32 vhost_scsi_get_task_tag(struct se_cmd *se_cmd) 515 512 { 516 513 return 0; 517 514 } 518 515 519 - static int tcm_vhost_get_cmd_state(struct se_cmd *se_cmd) 516 + static int vhost_scsi_get_cmd_state(struct se_cmd *se_cmd) 520 517 { 521 518 return 0; 522 519 } 523 520 524 - static void vhost_scsi_complete_cmd(struct tcm_vhost_cmd *cmd) 521 + static void vhost_scsi_complete_cmd(struct vhost_scsi_cmd *cmd) 525 522 { 526 523 struct vhost_scsi *vs = cmd->tvc_vhost; 527 524 ··· 530 527 vhost_work_queue(&vs->dev, &vs->vs_completion_work); 531 528 } 532 529 533 - static int tcm_vhost_queue_data_in(struct se_cmd *se_cmd) 530 + static int vhost_scsi_queue_data_in(struct se_cmd *se_cmd) 534 531 { 535 - struct tcm_vhost_cmd *cmd = container_of(se_cmd, 536 - struct tcm_vhost_cmd, tvc_se_cmd); 532 + struct vhost_scsi_cmd *cmd = container_of(se_cmd, 533 + struct vhost_scsi_cmd, tvc_se_cmd); 537 534 vhost_scsi_complete_cmd(cmd); 538 535 return 0; 539 536 } 540 537 541 - static int tcm_vhost_queue_status(struct se_cmd *se_cmd) 538 + static int vhost_scsi_queue_status(struct se_cmd *se_cmd) 542 539 { 543 - struct tcm_vhost_cmd *cmd = container_of(se_cmd, 544 - struct tcm_vhost_cmd, tvc_se_cmd); 540 + struct vhost_scsi_cmd *cmd = container_of(se_cmd, 541 + struct vhost_scsi_cmd, tvc_se_cmd); 545 542 vhost_scsi_complete_cmd(cmd); 546 543 return 0; 547 544 } 548 545 549 - static void tcm_vhost_queue_tm_rsp(struct se_cmd *se_cmd) 546 + static void vhost_scsi_queue_tm_rsp(struct se_cmd *se_cmd) 550 547 { 551 548 return; 552 549 } 553 550 554 - static void tcm_vhost_aborted_task(struct se_cmd *se_cmd) 551 + static void vhost_scsi_aborted_task(struct se_cmd *se_cmd) 555 552 { 556 553 return; 557 554 } 558 555 559 - static void tcm_vhost_free_evt(struct vhost_scsi *vs, struct tcm_vhost_evt *evt) 556 + static void vhost_scsi_free_evt(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) 560 557 { 561 558 vs->vs_events_nr--; 562 559 kfree(evt); 563 560 } 564 561 565 - static struct tcm_vhost_evt * 566 - tcm_vhost_allocate_evt(struct vhost_scsi *vs, 562 + static struct vhost_scsi_evt * 563 + vhost_scsi_allocate_evt(struct vhost_scsi *vs, 567 564 u32 event, u32 reason) 568 565 { 569 566 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; 570 - struct tcm_vhost_evt *evt; 567 + struct vhost_scsi_evt *evt; 571 568 572 569 if (vs->vs_events_nr > VHOST_SCSI_MAX_EVENT) { 573 570 vs->vs_events_missed = true; ··· 576 573 577 574 evt = kzalloc(sizeof(*evt), GFP_KERNEL); 578 575 if (!evt) { 579 - vq_err(vq, "Failed to allocate tcm_vhost_evt\n"); 576 + vq_err(vq, "Failed to allocate vhost_scsi_evt\n"); 580 577 vs->vs_events_missed = true; 581 578 return NULL; 582 579 } ··· 588 585 return evt; 589 586 } 590 587 591 - static void vhost_scsi_free_cmd(struct tcm_vhost_cmd *cmd) 588 + static void vhost_scsi_free_cmd(struct vhost_scsi_cmd *cmd) 592 589 { 593 590 struct se_cmd *se_cmd = &cmd->tvc_se_cmd; 594 591 ··· 603 600 } 604 601 605 602 static void 606 - tcm_vhost_do_evt_work(struct vhost_scsi *vs, struct tcm_vhost_evt *evt) 603 + vhost_scsi_do_evt_work(struct vhost_scsi *vs, struct vhost_scsi_evt *evt) 607 604 { 608 605 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; 609 606 struct virtio_scsi_event *event = &evt->event; ··· 649 646 if (!ret) 650 647 vhost_add_used_and_signal(&vs->dev, vq, head, 0); 651 648 else 652 - vq_err(vq, "Faulted on tcm_vhost_send_event\n"); 649 + vq_err(vq, "Faulted on vhost_scsi_send_event\n"); 653 650 } 654 651 655 - static void tcm_vhost_evt_work(struct vhost_work *work) 652 + static void vhost_scsi_evt_work(struct vhost_work *work) 656 653 { 657 654 struct vhost_scsi *vs = container_of(work, struct vhost_scsi, 658 655 vs_event_work); 659 656 struct vhost_virtqueue *vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; 660 - struct tcm_vhost_evt *evt; 657 + struct vhost_scsi_evt *evt; 661 658 struct llist_node *llnode; 662 659 663 660 mutex_lock(&vq->mutex); 664 661 llnode = llist_del_all(&vs->vs_event_list); 665 662 while (llnode) { 666 - evt = llist_entry(llnode, struct tcm_vhost_evt, list); 663 + evt = llist_entry(llnode, struct vhost_scsi_evt, list); 667 664 llnode = llist_next(llnode); 668 - tcm_vhost_do_evt_work(vs, evt); 669 - tcm_vhost_free_evt(vs, evt); 665 + vhost_scsi_do_evt_work(vs, evt); 666 + vhost_scsi_free_evt(vs, evt); 670 667 } 671 668 mutex_unlock(&vq->mutex); 672 669 } ··· 682 679 vs_completion_work); 683 680 DECLARE_BITMAP(signal, VHOST_SCSI_MAX_VQ); 684 681 struct virtio_scsi_cmd_resp v_rsp; 685 - struct tcm_vhost_cmd *cmd; 682 + struct vhost_scsi_cmd *cmd; 686 683 struct llist_node *llnode; 687 684 struct se_cmd *se_cmd; 685 + struct iov_iter iov_iter; 688 686 int ret, vq; 689 687 690 688 bitmap_zero(signal, VHOST_SCSI_MAX_VQ); 691 689 llnode = llist_del_all(&vs->vs_completion_list); 692 690 while (llnode) { 693 - cmd = llist_entry(llnode, struct tcm_vhost_cmd, 691 + cmd = llist_entry(llnode, struct vhost_scsi_cmd, 694 692 tvc_completion_list); 695 693 llnode = llist_next(llnode); 696 694 se_cmd = &cmd->tvc_se_cmd; ··· 707 703 se_cmd->scsi_sense_length); 708 704 memcpy(v_rsp.sense, cmd->tvc_sense_buf, 709 705 se_cmd->scsi_sense_length); 710 - ret = copy_to_user(cmd->tvc_resp, &v_rsp, sizeof(v_rsp)); 711 - if (likely(ret == 0)) { 706 + 707 + iov_iter_init(&iov_iter, READ, cmd->tvc_resp_iov, 708 + cmd->tvc_in_iovs, sizeof(v_rsp)); 709 + ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); 710 + if (likely(ret == sizeof(v_rsp))) { 712 711 struct vhost_scsi_virtqueue *q; 713 712 vhost_add_used(cmd->tvc_vq, cmd->tvc_vq_desc, 0); 714 713 q = container_of(cmd->tvc_vq, struct vhost_scsi_virtqueue, vq); ··· 729 722 vhost_signal(&vs->dev, &vs->vqs[vq].vq); 730 723 } 731 724 732 - static struct tcm_vhost_cmd * 733 - vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct tcm_vhost_tpg *tpg, 725 + static struct vhost_scsi_cmd * 726 + vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg, 734 727 unsigned char *cdb, u64 scsi_tag, u16 lun, u8 task_attr, 735 728 u32 exp_data_len, int data_direction) 736 729 { 737 - struct tcm_vhost_cmd *cmd; 738 - struct tcm_vhost_nexus *tv_nexus; 730 + struct vhost_scsi_cmd *cmd; 731 + struct vhost_scsi_nexus *tv_nexus; 739 732 struct se_session *se_sess; 740 733 struct scatterlist *sg, *prot_sg; 741 734 struct page **pages; ··· 743 736 744 737 tv_nexus = tpg->tpg_nexus; 745 738 if (!tv_nexus) { 746 - pr_err("Unable to locate active struct tcm_vhost_nexus\n"); 739 + pr_err("Unable to locate active struct vhost_scsi_nexus\n"); 747 740 return ERR_PTR(-EIO); 748 741 } 749 742 se_sess = tv_nexus->tvn_se_sess; 750 743 751 744 tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); 752 745 if (tag < 0) { 753 - pr_err("Unable to obtain tag for tcm_vhost_cmd\n"); 746 + pr_err("Unable to obtain tag for vhost_scsi_cmd\n"); 754 747 return ERR_PTR(-ENOMEM); 755 748 } 756 749 757 - cmd = &((struct tcm_vhost_cmd *)se_sess->sess_cmd_map)[tag]; 750 + cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[tag]; 758 751 sg = cmd->tvc_sgl; 759 752 prot_sg = cmd->tvc_prot_sgl; 760 753 pages = cmd->tvc_upages; 761 - memset(cmd, 0, sizeof(struct tcm_vhost_cmd)); 754 + memset(cmd, 0, sizeof(struct vhost_scsi_cmd)); 762 755 763 756 cmd->tvc_sgl = sg; 764 757 cmd->tvc_prot_sgl = prot_sg; ··· 770 763 cmd->tvc_exp_data_len = exp_data_len; 771 764 cmd->tvc_data_direction = data_direction; 772 765 cmd->tvc_nexus = tv_nexus; 773 - cmd->inflight = tcm_vhost_get_inflight(vq); 766 + cmd->inflight = vhost_scsi_get_inflight(vq); 774 767 775 - memcpy(cmd->tvc_cdb, cdb, TCM_VHOST_MAX_CDB_SIZE); 768 + memcpy(cmd->tvc_cdb, cdb, VHOST_SCSI_MAX_CDB_SIZE); 776 769 777 770 return cmd; 778 771 } ··· 783 776 * Returns the number of scatterlist entries used or -errno on error. 784 777 */ 785 778 static int 786 - vhost_scsi_map_to_sgl(struct tcm_vhost_cmd *tv_cmd, 779 + vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, 780 + void __user *ptr, 781 + size_t len, 787 782 struct scatterlist *sgl, 788 - unsigned int sgl_count, 789 - struct iovec *iov, 790 - struct page **pages, 791 783 bool write) 792 784 { 793 - unsigned int npages = 0, pages_nr, offset, nbytes; 785 + unsigned int npages = 0, offset, nbytes; 786 + unsigned int pages_nr = iov_num_pages(ptr, len); 794 787 struct scatterlist *sg = sgl; 795 - void __user *ptr = iov->iov_base; 796 - size_t len = iov->iov_len; 788 + struct page **pages = cmd->tvc_upages; 797 789 int ret, i; 798 790 799 - pages_nr = iov_num_pages(iov); 800 - if (pages_nr > sgl_count) { 791 + if (pages_nr > VHOST_SCSI_PREALLOC_UPAGES) { 801 792 pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" 802 - " sgl_count: %u\n", pages_nr, sgl_count); 803 - return -ENOBUFS; 804 - } 805 - if (pages_nr > TCM_VHOST_PREALLOC_UPAGES) { 806 - pr_err("vhost_scsi_map_to_sgl() pages_nr: %u greater than" 807 - " preallocated TCM_VHOST_PREALLOC_UPAGES: %u\n", 808 - pages_nr, TCM_VHOST_PREALLOC_UPAGES); 793 + " preallocated VHOST_SCSI_PREALLOC_UPAGES: %u\n", 794 + pages_nr, VHOST_SCSI_PREALLOC_UPAGES); 809 795 return -ENOBUFS; 810 796 } 811 797 ··· 829 829 } 830 830 831 831 static int 832 - vhost_scsi_map_iov_to_sgl(struct tcm_vhost_cmd *cmd, 833 - struct iovec *iov, 834 - int niov, 835 - bool write) 832 + vhost_scsi_calc_sgls(struct iov_iter *iter, size_t bytes, int max_sgls) 836 833 { 837 - struct scatterlist *sg = cmd->tvc_sgl; 838 - unsigned int sgl_count = 0; 839 - int ret, i; 834 + int sgl_count = 0; 840 835 841 - for (i = 0; i < niov; i++) 842 - sgl_count += iov_num_pages(&iov[i]); 843 - 844 - if (sgl_count > TCM_VHOST_PREALLOC_SGLS) { 845 - pr_err("vhost_scsi_map_iov_to_sgl() sgl_count: %u greater than" 846 - " preallocated TCM_VHOST_PREALLOC_SGLS: %u\n", 847 - sgl_count, TCM_VHOST_PREALLOC_SGLS); 848 - return -ENOBUFS; 836 + if (!iter || !iter->iov) { 837 + pr_err("%s: iter->iov is NULL, but expected bytes: %zu" 838 + " present\n", __func__, bytes); 839 + return -EINVAL; 849 840 } 850 841 851 - pr_debug("%s sg %p sgl_count %u\n", __func__, sg, sgl_count); 852 - sg_init_table(sg, sgl_count); 853 - cmd->tvc_sgl_count = sgl_count; 842 + sgl_count = iov_iter_npages(iter, 0xffff); 843 + if (sgl_count > max_sgls) { 844 + pr_err("%s: requested sgl_count: %d exceeds pre-allocated" 845 + " max_sgls: %d\n", __func__, sgl_count, max_sgls); 846 + return -EINVAL; 847 + } 848 + return sgl_count; 849 + } 854 850 855 - pr_debug("Mapping iovec %p for %u pages\n", &iov[0], sgl_count); 851 + static int 852 + vhost_scsi_iov_to_sgl(struct vhost_scsi_cmd *cmd, bool write, 853 + struct iov_iter *iter, 854 + struct scatterlist *sg, int sg_count) 855 + { 856 + size_t off = iter->iov_offset; 857 + int i, ret; 856 858 857 - for (i = 0; i < niov; i++) { 858 - ret = vhost_scsi_map_to_sgl(cmd, sg, sgl_count, &iov[i], 859 - cmd->tvc_upages, write); 859 + for (i = 0; i < iter->nr_segs; i++) { 860 + void __user *base = iter->iov[i].iov_base + off; 861 + size_t len = iter->iov[i].iov_len - off; 862 + 863 + ret = vhost_scsi_map_to_sgl(cmd, base, len, sg, write); 860 864 if (ret < 0) { 861 - for (i = 0; i < cmd->tvc_sgl_count; i++) 862 - put_page(sg_page(&cmd->tvc_sgl[i])); 863 - 864 - cmd->tvc_sgl_count = 0; 865 + for (i = 0; i < sg_count; i++) { 866 + struct page *page = sg_page(&sg[i]); 867 + if (page) 868 + put_page(page); 869 + } 865 870 return ret; 866 871 } 867 872 sg += ret; 868 - sgl_count -= ret; 873 + off = 0; 869 874 } 870 875 return 0; 871 876 } 872 877 873 878 static int 874 - vhost_scsi_map_iov_to_prot(struct tcm_vhost_cmd *cmd, 875 - struct iovec *iov, 876 - int niov, 877 - bool write) 879 + vhost_scsi_mapal(struct vhost_scsi_cmd *cmd, 880 + size_t prot_bytes, struct iov_iter *prot_iter, 881 + size_t data_bytes, struct iov_iter *data_iter) 878 882 { 879 - struct scatterlist *prot_sg = cmd->tvc_prot_sgl; 880 - unsigned int prot_sgl_count = 0; 881 - int ret, i; 883 + int sgl_count, ret; 884 + bool write = (cmd->tvc_data_direction == DMA_FROM_DEVICE); 882 885 883 - for (i = 0; i < niov; i++) 884 - prot_sgl_count += iov_num_pages(&iov[i]); 886 + if (prot_bytes) { 887 + sgl_count = vhost_scsi_calc_sgls(prot_iter, prot_bytes, 888 + VHOST_SCSI_PREALLOC_PROT_SGLS); 889 + if (sgl_count < 0) 890 + return sgl_count; 885 891 886 - if (prot_sgl_count > TCM_VHOST_PREALLOC_PROT_SGLS) { 887 - pr_err("vhost_scsi_map_iov_to_prot() sgl_count: %u greater than" 888 - " preallocated TCM_VHOST_PREALLOC_PROT_SGLS: %u\n", 889 - prot_sgl_count, TCM_VHOST_PREALLOC_PROT_SGLS); 890 - return -ENOBUFS; 891 - } 892 + sg_init_table(cmd->tvc_prot_sgl, sgl_count); 893 + cmd->tvc_prot_sgl_count = sgl_count; 894 + pr_debug("%s prot_sg %p prot_sgl_count %u\n", __func__, 895 + cmd->tvc_prot_sgl, cmd->tvc_prot_sgl_count); 892 896 893 - pr_debug("%s prot_sg %p prot_sgl_count %u\n", __func__, 894 - prot_sg, prot_sgl_count); 895 - sg_init_table(prot_sg, prot_sgl_count); 896 - cmd->tvc_prot_sgl_count = prot_sgl_count; 897 - 898 - for (i = 0; i < niov; i++) { 899 - ret = vhost_scsi_map_to_sgl(cmd, prot_sg, prot_sgl_count, &iov[i], 900 - cmd->tvc_upages, write); 897 + ret = vhost_scsi_iov_to_sgl(cmd, write, prot_iter, 898 + cmd->tvc_prot_sgl, 899 + cmd->tvc_prot_sgl_count); 901 900 if (ret < 0) { 902 - for (i = 0; i < cmd->tvc_prot_sgl_count; i++) 903 - put_page(sg_page(&cmd->tvc_prot_sgl[i])); 904 - 905 901 cmd->tvc_prot_sgl_count = 0; 906 902 return ret; 907 903 } 908 - prot_sg += ret; 909 - prot_sgl_count -= ret; 904 + } 905 + sgl_count = vhost_scsi_calc_sgls(data_iter, data_bytes, 906 + VHOST_SCSI_PREALLOC_SGLS); 907 + if (sgl_count < 0) 908 + return sgl_count; 909 + 910 + sg_init_table(cmd->tvc_sgl, sgl_count); 911 + cmd->tvc_sgl_count = sgl_count; 912 + pr_debug("%s data_sg %p data_sgl_count %u\n", __func__, 913 + cmd->tvc_sgl, cmd->tvc_sgl_count); 914 + 915 + ret = vhost_scsi_iov_to_sgl(cmd, write, data_iter, 916 + cmd->tvc_sgl, cmd->tvc_sgl_count); 917 + if (ret < 0) { 918 + cmd->tvc_sgl_count = 0; 919 + return ret; 910 920 } 911 921 return 0; 912 922 } ··· 938 928 return TCM_SIMPLE_TAG; 939 929 } 940 930 941 - static void tcm_vhost_submission_work(struct work_struct *work) 931 + static void vhost_scsi_submission_work(struct work_struct *work) 942 932 { 943 - struct tcm_vhost_cmd *cmd = 944 - container_of(work, struct tcm_vhost_cmd, work); 945 - struct tcm_vhost_nexus *tv_nexus; 933 + struct vhost_scsi_cmd *cmd = 934 + container_of(work, struct vhost_scsi_cmd, work); 935 + struct vhost_scsi_nexus *tv_nexus; 946 936 struct se_cmd *se_cmd = &cmd->tvc_se_cmd; 947 937 struct scatterlist *sg_ptr, *sg_prot_ptr = NULL; 948 938 int rc; ··· 996 986 static void 997 987 vhost_scsi_handle_vq(struct vhost_scsi *vs, struct vhost_virtqueue *vq) 998 988 { 999 - struct tcm_vhost_tpg **vs_tpg; 989 + struct vhost_scsi_tpg **vs_tpg, *tpg; 1000 990 struct virtio_scsi_cmd_req v_req; 1001 991 struct virtio_scsi_cmd_req_pi v_req_pi; 1002 - struct tcm_vhost_tpg *tpg; 1003 - struct tcm_vhost_cmd *cmd; 992 + struct vhost_scsi_cmd *cmd; 993 + struct iov_iter out_iter, in_iter, prot_iter, data_iter; 1004 994 u64 tag; 1005 - u32 exp_data_len, data_first, data_num, data_direction, prot_first; 1006 - unsigned out, in, i; 1007 - int head, ret, data_niov, prot_niov, prot_bytes; 1008 - size_t req_size; 995 + u32 exp_data_len, data_direction; 996 + unsigned out, in; 997 + int head, ret, prot_bytes; 998 + size_t req_size, rsp_size = sizeof(struct virtio_scsi_cmd_resp); 999 + size_t out_size, in_size; 1009 1000 u16 lun; 1010 1001 u8 *target, *lunp, task_attr; 1011 - bool hdr_pi; 1002 + bool t10_pi = vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI); 1012 1003 void *req, *cdb; 1013 1004 1014 1005 mutex_lock(&vq->mutex); ··· 1025 1014 1026 1015 for (;;) { 1027 1016 head = vhost_get_vq_desc(vq, vq->iov, 1028 - ARRAY_SIZE(vq->iov), &out, &in, 1029 - NULL, NULL); 1017 + ARRAY_SIZE(vq->iov), &out, &in, 1018 + NULL, NULL); 1030 1019 pr_debug("vhost_get_vq_desc: head: %d, out: %u in: %u\n", 1031 - head, out, in); 1020 + head, out, in); 1032 1021 /* On error, stop handling until the next kick. */ 1033 1022 if (unlikely(head < 0)) 1034 1023 break; ··· 1040 1029 } 1041 1030 break; 1042 1031 } 1043 - 1044 - /* FIXME: BIDI operation */ 1045 - if (out == 1 && in == 1) { 1046 - data_direction = DMA_NONE; 1047 - data_first = 0; 1048 - data_num = 0; 1049 - } else if (out == 1 && in > 1) { 1050 - data_direction = DMA_FROM_DEVICE; 1051 - data_first = out + 1; 1052 - data_num = in - 1; 1053 - } else if (out > 1 && in == 1) { 1054 - data_direction = DMA_TO_DEVICE; 1055 - data_first = 1; 1056 - data_num = out - 1; 1057 - } else { 1058 - vq_err(vq, "Invalid buffer layout out: %u in: %u\n", 1059 - out, in); 1060 - break; 1061 - } 1062 - 1063 1032 /* 1064 - * Check for a sane resp buffer so we can report errors to 1065 - * the guest. 1033 + * Check for a sane response buffer so we can report early 1034 + * errors back to the guest. 1066 1035 */ 1067 - if (unlikely(vq->iov[out].iov_len != 1068 - sizeof(struct virtio_scsi_cmd_resp))) { 1069 - vq_err(vq, "Expecting virtio_scsi_cmd_resp, got %zu" 1070 - " bytes\n", vq->iov[out].iov_len); 1036 + if (unlikely(vq->iov[out].iov_len < rsp_size)) { 1037 + vq_err(vq, "Expecting at least virtio_scsi_cmd_resp" 1038 + " size, got %zu bytes\n", vq->iov[out].iov_len); 1071 1039 break; 1072 1040 } 1073 - 1074 - if (vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI)) { 1041 + /* 1042 + * Setup pointers and values based upon different virtio-scsi 1043 + * request header if T10_PI is enabled in KVM guest. 1044 + */ 1045 + if (t10_pi) { 1075 1046 req = &v_req_pi; 1047 + req_size = sizeof(v_req_pi); 1076 1048 lunp = &v_req_pi.lun[0]; 1077 1049 target = &v_req_pi.lun[1]; 1078 - req_size = sizeof(v_req_pi); 1079 - hdr_pi = true; 1080 1050 } else { 1081 1051 req = &v_req; 1052 + req_size = sizeof(v_req); 1082 1053 lunp = &v_req.lun[0]; 1083 1054 target = &v_req.lun[1]; 1084 - req_size = sizeof(v_req); 1085 - hdr_pi = false; 1086 1055 } 1056 + /* 1057 + * FIXME: Not correct for BIDI operation 1058 + */ 1059 + out_size = iov_length(vq->iov, out); 1060 + in_size = iov_length(&vq->iov[out], in); 1087 1061 1088 - if (unlikely(vq->iov[0].iov_len < req_size)) { 1089 - pr_err("Expecting virtio-scsi header: %zu, got %zu\n", 1090 - req_size, vq->iov[0].iov_len); 1091 - break; 1092 - } 1093 - ret = copy_from_user(req, vq->iov[0].iov_base, req_size); 1094 - if (unlikely(ret)) { 1095 - vq_err(vq, "Faulted on virtio_scsi_cmd_req\n"); 1096 - break; 1097 - } 1062 + /* 1063 + * Copy over the virtio-scsi request header, which for a 1064 + * ANY_LAYOUT enabled guest may span multiple iovecs, or a 1065 + * single iovec may contain both the header + outgoing 1066 + * WRITE payloads. 1067 + * 1068 + * copy_from_iter() will advance out_iter, so that it will 1069 + * point at the start of the outgoing WRITE payload, if 1070 + * DMA_TO_DEVICE is set. 1071 + */ 1072 + iov_iter_init(&out_iter, WRITE, vq->iov, out, out_size); 1098 1073 1074 + ret = copy_from_iter(req, req_size, &out_iter); 1075 + if (unlikely(ret != req_size)) { 1076 + vq_err(vq, "Faulted on copy_from_iter\n"); 1077 + vhost_scsi_send_bad_target(vs, vq, head, out); 1078 + continue; 1079 + } 1099 1080 /* virtio-scsi spec requires byte 0 of the lun to be 1 */ 1100 1081 if (unlikely(*lunp != 1)) { 1082 + vq_err(vq, "Illegal virtio-scsi lun: %u\n", *lunp); 1101 1083 vhost_scsi_send_bad_target(vs, vq, head, out); 1102 1084 continue; 1103 1085 } 1104 1086 1105 1087 tpg = ACCESS_ONCE(vs_tpg[*target]); 1106 - 1107 - /* Target does not exist, fail the request */ 1108 1088 if (unlikely(!tpg)) { 1089 + /* Target does not exist, fail the request */ 1109 1090 vhost_scsi_send_bad_target(vs, vq, head, out); 1110 1091 continue; 1111 1092 } 1112 - 1113 - data_niov = data_num; 1114 - prot_niov = prot_first = prot_bytes = 0; 1115 1093 /* 1116 - * Determine if any protection information iovecs are preceeding 1117 - * the actual data payload, and adjust data_first + data_niov 1118 - * values accordingly for vhost_scsi_map_iov_to_sgl() below. 1094 + * Determine data_direction by calculating the total outgoing 1095 + * iovec sizes + incoming iovec sizes vs. virtio-scsi request + 1096 + * response headers respectively. 1119 1097 * 1120 - * Also extract virtio_scsi header bits for vhost_scsi_get_tag() 1098 + * For DMA_TO_DEVICE this is out_iter, which is already pointing 1099 + * to the right place. 1100 + * 1101 + * For DMA_FROM_DEVICE, the iovec will be just past the end 1102 + * of the virtio-scsi response header in either the same 1103 + * or immediately following iovec. 1104 + * 1105 + * Any associated T10_PI bytes for the outgoing / incoming 1106 + * payloads are included in calculation of exp_data_len here. 1121 1107 */ 1122 - if (hdr_pi) { 1108 + prot_bytes = 0; 1109 + 1110 + if (out_size > req_size) { 1111 + data_direction = DMA_TO_DEVICE; 1112 + exp_data_len = out_size - req_size; 1113 + data_iter = out_iter; 1114 + } else if (in_size > rsp_size) { 1115 + data_direction = DMA_FROM_DEVICE; 1116 + exp_data_len = in_size - rsp_size; 1117 + 1118 + iov_iter_init(&in_iter, READ, &vq->iov[out], in, 1119 + rsp_size + exp_data_len); 1120 + iov_iter_advance(&in_iter, rsp_size); 1121 + data_iter = in_iter; 1122 + } else { 1123 + data_direction = DMA_NONE; 1124 + exp_data_len = 0; 1125 + } 1126 + /* 1127 + * If T10_PI header + payload is present, setup prot_iter values 1128 + * and recalculate data_iter for vhost_scsi_mapal() mapping to 1129 + * host scatterlists via get_user_pages_fast(). 1130 + */ 1131 + if (t10_pi) { 1123 1132 if (v_req_pi.pi_bytesout) { 1124 1133 if (data_direction != DMA_TO_DEVICE) { 1125 - vq_err(vq, "Received non zero do_pi_niov" 1126 - ", but wrong data_direction\n"); 1127 - goto err_cmd; 1134 + vq_err(vq, "Received non zero pi_bytesout," 1135 + " but wrong data_direction\n"); 1136 + vhost_scsi_send_bad_target(vs, vq, head, out); 1137 + continue; 1128 1138 } 1129 1139 prot_bytes = vhost32_to_cpu(vq, v_req_pi.pi_bytesout); 1130 1140 } else if (v_req_pi.pi_bytesin) { 1131 1141 if (data_direction != DMA_FROM_DEVICE) { 1132 - vq_err(vq, "Received non zero di_pi_niov" 1133 - ", but wrong data_direction\n"); 1134 - goto err_cmd; 1142 + vq_err(vq, "Received non zero pi_bytesin," 1143 + " but wrong data_direction\n"); 1144 + vhost_scsi_send_bad_target(vs, vq, head, out); 1145 + continue; 1135 1146 } 1136 1147 prot_bytes = vhost32_to_cpu(vq, v_req_pi.pi_bytesin); 1137 1148 } 1149 + /* 1150 + * Set prot_iter to data_iter, and advance past any 1151 + * preceeding prot_bytes that may be present. 1152 + * 1153 + * Also fix up the exp_data_len to reflect only the 1154 + * actual data payload length. 1155 + */ 1138 1156 if (prot_bytes) { 1139 - int tmp = 0; 1140 - 1141 - for (i = 0; i < data_num; i++) { 1142 - tmp += vq->iov[data_first + i].iov_len; 1143 - prot_niov++; 1144 - if (tmp >= prot_bytes) 1145 - break; 1146 - } 1147 - prot_first = data_first; 1148 - data_first += prot_niov; 1149 - data_niov = data_num - prot_niov; 1157 + exp_data_len -= prot_bytes; 1158 + prot_iter = data_iter; 1159 + iov_iter_advance(&data_iter, prot_bytes); 1150 1160 } 1151 1161 tag = vhost64_to_cpu(vq, v_req_pi.tag); 1152 1162 task_attr = v_req_pi.task_attr; ··· 1179 1147 cdb = &v_req.cdb[0]; 1180 1148 lun = ((v_req.lun[2] << 8) | v_req.lun[3]) & 0x3FFF; 1181 1149 } 1182 - exp_data_len = 0; 1183 - for (i = 0; i < data_niov; i++) 1184 - exp_data_len += vq->iov[data_first + i].iov_len; 1185 1150 /* 1186 - * Check that the recieved CDB size does not exceeded our 1187 - * hardcoded max for vhost-scsi 1151 + * Check that the received CDB size does not exceeded our 1152 + * hardcoded max for vhost-scsi, then get a pre-allocated 1153 + * cmd descriptor for the new virtio-scsi tag. 1188 1154 * 1189 1155 * TODO what if cdb was too small for varlen cdb header? 1190 1156 */ 1191 - if (unlikely(scsi_command_size(cdb) > TCM_VHOST_MAX_CDB_SIZE)) { 1157 + if (unlikely(scsi_command_size(cdb) > VHOST_SCSI_MAX_CDB_SIZE)) { 1192 1158 vq_err(vq, "Received SCSI CDB with command_size: %d that" 1193 1159 " exceeds SCSI_MAX_VARLEN_CDB_SIZE: %d\n", 1194 - scsi_command_size(cdb), TCM_VHOST_MAX_CDB_SIZE); 1195 - goto err_cmd; 1160 + scsi_command_size(cdb), VHOST_SCSI_MAX_CDB_SIZE); 1161 + vhost_scsi_send_bad_target(vs, vq, head, out); 1162 + continue; 1196 1163 } 1197 - 1198 1164 cmd = vhost_scsi_get_tag(vq, tpg, cdb, tag, lun, task_attr, 1199 1165 exp_data_len + prot_bytes, 1200 1166 data_direction); 1201 1167 if (IS_ERR(cmd)) { 1202 1168 vq_err(vq, "vhost_scsi_get_tag failed %ld\n", 1203 - PTR_ERR(cmd)); 1204 - goto err_cmd; 1169 + PTR_ERR(cmd)); 1170 + vhost_scsi_send_bad_target(vs, vq, head, out); 1171 + continue; 1205 1172 } 1206 - 1207 - pr_debug("Allocated tv_cmd: %p exp_data_len: %d, data_direction" 1208 - ": %d\n", cmd, exp_data_len, data_direction); 1209 - 1210 1173 cmd->tvc_vhost = vs; 1211 1174 cmd->tvc_vq = vq; 1212 - cmd->tvc_resp = vq->iov[out].iov_base; 1175 + cmd->tvc_resp_iov = &vq->iov[out]; 1176 + cmd->tvc_in_iovs = in; 1213 1177 1214 1178 pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n", 1215 - cmd->tvc_cdb[0], cmd->tvc_lun); 1179 + cmd->tvc_cdb[0], cmd->tvc_lun); 1180 + pr_debug("cmd: %p exp_data_len: %d, prot_bytes: %d data_direction:" 1181 + " %d\n", cmd, exp_data_len, prot_bytes, data_direction); 1216 1182 1217 - if (prot_niov) { 1218 - ret = vhost_scsi_map_iov_to_prot(cmd, 1219 - &vq->iov[prot_first], prot_niov, 1220 - data_direction == DMA_FROM_DEVICE); 1221 - if (unlikely(ret)) { 1222 - vq_err(vq, "Failed to map iov to" 1223 - " prot_sgl\n"); 1224 - goto err_free; 1225 - } 1226 - } 1227 1183 if (data_direction != DMA_NONE) { 1228 - ret = vhost_scsi_map_iov_to_sgl(cmd, 1229 - &vq->iov[data_first], data_niov, 1230 - data_direction == DMA_FROM_DEVICE); 1184 + ret = vhost_scsi_mapal(cmd, 1185 + prot_bytes, &prot_iter, 1186 + exp_data_len, &data_iter); 1231 1187 if (unlikely(ret)) { 1232 1188 vq_err(vq, "Failed to map iov to sgl\n"); 1233 - goto err_free; 1189 + vhost_scsi_release_cmd(&cmd->tvc_se_cmd); 1190 + vhost_scsi_send_bad_target(vs, vq, head, out); 1191 + continue; 1234 1192 } 1235 1193 } 1236 1194 /* 1237 1195 * Save the descriptor from vhost_get_vq_desc() to be used to 1238 1196 * complete the virtio-scsi request in TCM callback context via 1239 - * tcm_vhost_queue_data_in() and tcm_vhost_queue_status() 1197 + * vhost_scsi_queue_data_in() and vhost_scsi_queue_status() 1240 1198 */ 1241 1199 cmd->tvc_vq_desc = head; 1242 1200 /* 1243 - * Dispatch tv_cmd descriptor for cmwq execution in process 1244 - * context provided by tcm_vhost_workqueue. This also ensures 1245 - * tv_cmd is executed on the same kworker CPU as this vhost 1246 - * thread to gain positive L2 cache locality effects.. 1201 + * Dispatch cmd descriptor for cmwq execution in process 1202 + * context provided by vhost_scsi_workqueue. This also ensures 1203 + * cmd is executed on the same kworker CPU as this vhost 1204 + * thread to gain positive L2 cache locality effects. 1247 1205 */ 1248 - INIT_WORK(&cmd->work, tcm_vhost_submission_work); 1249 - queue_work(tcm_vhost_workqueue, &cmd->work); 1206 + INIT_WORK(&cmd->work, vhost_scsi_submission_work); 1207 + queue_work(vhost_scsi_workqueue, &cmd->work); 1250 1208 } 1251 - 1252 - mutex_unlock(&vq->mutex); 1253 - return; 1254 - 1255 - err_free: 1256 - vhost_scsi_free_cmd(cmd); 1257 - err_cmd: 1258 - vhost_scsi_send_bad_target(vs, vq, head, out); 1259 1209 out: 1260 1210 mutex_unlock(&vq->mutex); 1261 1211 } ··· 1248 1234 } 1249 1235 1250 1236 static void 1251 - tcm_vhost_send_evt(struct vhost_scsi *vs, 1252 - struct tcm_vhost_tpg *tpg, 1237 + vhost_scsi_send_evt(struct vhost_scsi *vs, 1238 + struct vhost_scsi_tpg *tpg, 1253 1239 struct se_lun *lun, 1254 1240 u32 event, 1255 1241 u32 reason) 1256 1242 { 1257 - struct tcm_vhost_evt *evt; 1243 + struct vhost_scsi_evt *evt; 1258 1244 1259 - evt = tcm_vhost_allocate_evt(vs, event, reason); 1245 + evt = vhost_scsi_allocate_evt(vs, event, reason); 1260 1246 if (!evt) 1261 1247 return; 1262 1248 ··· 1267 1253 * lun[4-7] need to be zero according to virtio-scsi spec. 1268 1254 */ 1269 1255 evt->event.lun[0] = 0x01; 1270 - evt->event.lun[1] = tpg->tport_tpgt & 0xFF; 1256 + evt->event.lun[1] = tpg->tport_tpgt; 1271 1257 if (lun->unpacked_lun >= 256) 1272 1258 evt->event.lun[2] = lun->unpacked_lun >> 8 | 0x40 ; 1273 1259 evt->event.lun[3] = lun->unpacked_lun & 0xFF; ··· 1288 1274 goto out; 1289 1275 1290 1276 if (vs->vs_events_missed) 1291 - tcm_vhost_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); 1277 + vhost_scsi_send_evt(vs, NULL, NULL, VIRTIO_SCSI_T_NO_EVENT, 0); 1292 1278 out: 1293 1279 mutex_unlock(&vq->mutex); 1294 1280 } ··· 1314 1300 int i; 1315 1301 1316 1302 /* Init new inflight and remember the old inflight */ 1317 - tcm_vhost_init_inflight(vs, old_inflight); 1303 + vhost_scsi_init_inflight(vs, old_inflight); 1318 1304 1319 1305 /* 1320 1306 * The inflight->kref was initialized to 1. We decrement it here to ··· 1322 1308 * when all the reqs are finished. 1323 1309 */ 1324 1310 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) 1325 - kref_put(&old_inflight[i]->kref, tcm_vhost_done_inflight); 1311 + kref_put(&old_inflight[i]->kref, vhost_scsi_done_inflight); 1326 1312 1327 1313 /* Flush both the vhost poll and vhost work */ 1328 1314 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) ··· 1337 1323 1338 1324 /* 1339 1325 * Called from vhost_scsi_ioctl() context to walk the list of available 1340 - * tcm_vhost_tpg with an active struct tcm_vhost_nexus 1326 + * vhost_scsi_tpg with an active struct vhost_scsi_nexus 1341 1327 * 1342 1328 * The lock nesting rule is: 1343 - * tcm_vhost_mutex -> vs->dev.mutex -> tpg->tv_tpg_mutex -> vq->mutex 1329 + * vhost_scsi_mutex -> vs->dev.mutex -> tpg->tv_tpg_mutex -> vq->mutex 1344 1330 */ 1345 1331 static int 1346 1332 vhost_scsi_set_endpoint(struct vhost_scsi *vs, 1347 1333 struct vhost_scsi_target *t) 1348 1334 { 1349 1335 struct se_portal_group *se_tpg; 1350 - struct tcm_vhost_tport *tv_tport; 1351 - struct tcm_vhost_tpg *tpg; 1352 - struct tcm_vhost_tpg **vs_tpg; 1336 + struct vhost_scsi_tport *tv_tport; 1337 + struct vhost_scsi_tpg *tpg; 1338 + struct vhost_scsi_tpg **vs_tpg; 1353 1339 struct vhost_virtqueue *vq; 1354 1340 int index, ret, i, len; 1355 1341 bool match = false; 1356 1342 1357 - mutex_lock(&tcm_vhost_mutex); 1343 + mutex_lock(&vhost_scsi_mutex); 1358 1344 mutex_lock(&vs->dev.mutex); 1359 1345 1360 1346 /* Verify that ring has been setup correctly. */ ··· 1375 1361 if (vs->vs_tpg) 1376 1362 memcpy(vs_tpg, vs->vs_tpg, len); 1377 1363 1378 - list_for_each_entry(tpg, &tcm_vhost_list, tv_tpg_list) { 1364 + list_for_each_entry(tpg, &vhost_scsi_list, tv_tpg_list) { 1379 1365 mutex_lock(&tpg->tv_tpg_mutex); 1380 1366 if (!tpg->tpg_nexus) { 1381 1367 mutex_unlock(&tpg->tv_tpg_mutex); ··· 1443 1429 1444 1430 out: 1445 1431 mutex_unlock(&vs->dev.mutex); 1446 - mutex_unlock(&tcm_vhost_mutex); 1432 + mutex_unlock(&vhost_scsi_mutex); 1447 1433 return ret; 1448 1434 } 1449 1435 ··· 1452 1438 struct vhost_scsi_target *t) 1453 1439 { 1454 1440 struct se_portal_group *se_tpg; 1455 - struct tcm_vhost_tport *tv_tport; 1456 - struct tcm_vhost_tpg *tpg; 1441 + struct vhost_scsi_tport *tv_tport; 1442 + struct vhost_scsi_tpg *tpg; 1457 1443 struct vhost_virtqueue *vq; 1458 1444 bool match = false; 1459 1445 int index, ret, i; 1460 1446 u8 target; 1461 1447 1462 - mutex_lock(&tcm_vhost_mutex); 1448 + mutex_lock(&vhost_scsi_mutex); 1463 1449 mutex_lock(&vs->dev.mutex); 1464 1450 /* Verify that ring has been setup correctly. */ 1465 1451 for (index = 0; index < vs->dev.nvqs; ++index) { ··· 1525 1511 vs->vs_tpg = NULL; 1526 1512 WARN_ON(vs->vs_events_nr); 1527 1513 mutex_unlock(&vs->dev.mutex); 1528 - mutex_unlock(&tcm_vhost_mutex); 1514 + mutex_unlock(&vhost_scsi_mutex); 1529 1515 return 0; 1530 1516 1531 1517 err_tpg: 1532 1518 mutex_unlock(&tpg->tv_tpg_mutex); 1533 1519 err_dev: 1534 1520 mutex_unlock(&vs->dev.mutex); 1535 - mutex_unlock(&tcm_vhost_mutex); 1521 + mutex_unlock(&vhost_scsi_mutex); 1536 1522 return ret; 1537 1523 } 1538 1524 ··· 1579 1565 goto err_vqs; 1580 1566 1581 1567 vhost_work_init(&vs->vs_completion_work, vhost_scsi_complete_cmd_work); 1582 - vhost_work_init(&vs->vs_event_work, tcm_vhost_evt_work); 1568 + vhost_work_init(&vs->vs_event_work, vhost_scsi_evt_work); 1583 1569 1584 1570 vs->vs_events_nr = 0; 1585 1571 vs->vs_events_missed = false; ··· 1594 1580 } 1595 1581 vhost_dev_init(&vs->dev, vqs, VHOST_SCSI_MAX_VQ); 1596 1582 1597 - tcm_vhost_init_inflight(vs, NULL); 1583 + vhost_scsi_init_inflight(vs, NULL); 1598 1584 1599 1585 f->private_data = vs; 1600 1586 return 0; ··· 1726 1712 return misc_deregister(&vhost_scsi_misc); 1727 1713 } 1728 1714 1729 - static char *tcm_vhost_dump_proto_id(struct tcm_vhost_tport *tport) 1715 + static char *vhost_scsi_dump_proto_id(struct vhost_scsi_tport *tport) 1730 1716 { 1731 1717 switch (tport->tport_proto_id) { 1732 1718 case SCSI_PROTOCOL_SAS: ··· 1743 1729 } 1744 1730 1745 1731 static void 1746 - tcm_vhost_do_plug(struct tcm_vhost_tpg *tpg, 1732 + vhost_scsi_do_plug(struct vhost_scsi_tpg *tpg, 1747 1733 struct se_lun *lun, bool plug) 1748 1734 { 1749 1735 ··· 1764 1750 vq = &vs->vqs[VHOST_SCSI_VQ_EVT].vq; 1765 1751 mutex_lock(&vq->mutex); 1766 1752 if (vhost_has_feature(vq, VIRTIO_SCSI_F_HOTPLUG)) 1767 - tcm_vhost_send_evt(vs, tpg, lun, 1753 + vhost_scsi_send_evt(vs, tpg, lun, 1768 1754 VIRTIO_SCSI_T_TRANSPORT_RESET, reason); 1769 1755 mutex_unlock(&vq->mutex); 1770 1756 mutex_unlock(&vs->dev.mutex); 1771 1757 } 1772 1758 1773 - static void tcm_vhost_hotplug(struct tcm_vhost_tpg *tpg, struct se_lun *lun) 1759 + static void vhost_scsi_hotplug(struct vhost_scsi_tpg *tpg, struct se_lun *lun) 1774 1760 { 1775 - tcm_vhost_do_plug(tpg, lun, true); 1761 + vhost_scsi_do_plug(tpg, lun, true); 1776 1762 } 1777 1763 1778 - static void tcm_vhost_hotunplug(struct tcm_vhost_tpg *tpg, struct se_lun *lun) 1764 + static void vhost_scsi_hotunplug(struct vhost_scsi_tpg *tpg, struct se_lun *lun) 1779 1765 { 1780 - tcm_vhost_do_plug(tpg, lun, false); 1766 + vhost_scsi_do_plug(tpg, lun, false); 1781 1767 } 1782 1768 1783 - static int tcm_vhost_port_link(struct se_portal_group *se_tpg, 1769 + static int vhost_scsi_port_link(struct se_portal_group *se_tpg, 1784 1770 struct se_lun *lun) 1785 1771 { 1786 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 1787 - struct tcm_vhost_tpg, se_tpg); 1772 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1773 + struct vhost_scsi_tpg, se_tpg); 1788 1774 1789 - mutex_lock(&tcm_vhost_mutex); 1775 + mutex_lock(&vhost_scsi_mutex); 1790 1776 1791 1777 mutex_lock(&tpg->tv_tpg_mutex); 1792 1778 tpg->tv_tpg_port_count++; 1793 1779 mutex_unlock(&tpg->tv_tpg_mutex); 1794 1780 1795 - tcm_vhost_hotplug(tpg, lun); 1781 + vhost_scsi_hotplug(tpg, lun); 1796 1782 1797 - mutex_unlock(&tcm_vhost_mutex); 1783 + mutex_unlock(&vhost_scsi_mutex); 1798 1784 1799 1785 return 0; 1800 1786 } 1801 1787 1802 - static void tcm_vhost_port_unlink(struct se_portal_group *se_tpg, 1788 + static void vhost_scsi_port_unlink(struct se_portal_group *se_tpg, 1803 1789 struct se_lun *lun) 1804 1790 { 1805 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 1806 - struct tcm_vhost_tpg, se_tpg); 1791 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1792 + struct vhost_scsi_tpg, se_tpg); 1807 1793 1808 - mutex_lock(&tcm_vhost_mutex); 1794 + mutex_lock(&vhost_scsi_mutex); 1809 1795 1810 1796 mutex_lock(&tpg->tv_tpg_mutex); 1811 1797 tpg->tv_tpg_port_count--; 1812 1798 mutex_unlock(&tpg->tv_tpg_mutex); 1813 1799 1814 - tcm_vhost_hotunplug(tpg, lun); 1800 + vhost_scsi_hotunplug(tpg, lun); 1815 1801 1816 - mutex_unlock(&tcm_vhost_mutex); 1802 + mutex_unlock(&vhost_scsi_mutex); 1817 1803 } 1818 1804 1819 1805 static struct se_node_acl * 1820 - tcm_vhost_make_nodeacl(struct se_portal_group *se_tpg, 1806 + vhost_scsi_make_nodeacl(struct se_portal_group *se_tpg, 1821 1807 struct config_group *group, 1822 1808 const char *name) 1823 1809 { 1824 1810 struct se_node_acl *se_nacl, *se_nacl_new; 1825 - struct tcm_vhost_nacl *nacl; 1811 + struct vhost_scsi_nacl *nacl; 1826 1812 u64 wwpn = 0; 1827 1813 u32 nexus_depth; 1828 1814 1829 - /* tcm_vhost_parse_wwn(name, &wwpn, 1) < 0) 1815 + /* vhost_scsi_parse_wwn(name, &wwpn, 1) < 0) 1830 1816 return ERR_PTR(-EINVAL); */ 1831 - se_nacl_new = tcm_vhost_alloc_fabric_acl(se_tpg); 1817 + se_nacl_new = vhost_scsi_alloc_fabric_acl(se_tpg); 1832 1818 if (!se_nacl_new) 1833 1819 return ERR_PTR(-ENOMEM); 1834 1820 ··· 1840 1826 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 1841 1827 name, nexus_depth); 1842 1828 if (IS_ERR(se_nacl)) { 1843 - tcm_vhost_release_fabric_acl(se_tpg, se_nacl_new); 1829 + vhost_scsi_release_fabric_acl(se_tpg, se_nacl_new); 1844 1830 return se_nacl; 1845 1831 } 1846 1832 /* 1847 - * Locate our struct tcm_vhost_nacl and set the FC Nport WWPN 1833 + * Locate our struct vhost_scsi_nacl and set the FC Nport WWPN 1848 1834 */ 1849 - nacl = container_of(se_nacl, struct tcm_vhost_nacl, se_node_acl); 1835 + nacl = container_of(se_nacl, struct vhost_scsi_nacl, se_node_acl); 1850 1836 nacl->iport_wwpn = wwpn; 1851 1837 1852 1838 return se_nacl; 1853 1839 } 1854 1840 1855 - static void tcm_vhost_drop_nodeacl(struct se_node_acl *se_acl) 1841 + static void vhost_scsi_drop_nodeacl(struct se_node_acl *se_acl) 1856 1842 { 1857 - struct tcm_vhost_nacl *nacl = container_of(se_acl, 1858 - struct tcm_vhost_nacl, se_node_acl); 1843 + struct vhost_scsi_nacl *nacl = container_of(se_acl, 1844 + struct vhost_scsi_nacl, se_node_acl); 1859 1845 core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1); 1860 1846 kfree(nacl); 1861 1847 } 1862 1848 1863 - static void tcm_vhost_free_cmd_map_res(struct tcm_vhost_nexus *nexus, 1849 + static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus, 1864 1850 struct se_session *se_sess) 1865 1851 { 1866 - struct tcm_vhost_cmd *tv_cmd; 1852 + struct vhost_scsi_cmd *tv_cmd; 1867 1853 unsigned int i; 1868 1854 1869 1855 if (!se_sess->sess_cmd_map) 1870 1856 return; 1871 1857 1872 - for (i = 0; i < TCM_VHOST_DEFAULT_TAGS; i++) { 1873 - tv_cmd = &((struct tcm_vhost_cmd *)se_sess->sess_cmd_map)[i]; 1858 + for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) { 1859 + tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i]; 1874 1860 1875 1861 kfree(tv_cmd->tvc_sgl); 1876 1862 kfree(tv_cmd->tvc_prot_sgl); ··· 1878 1864 } 1879 1865 } 1880 1866 1881 - static int tcm_vhost_make_nexus(struct tcm_vhost_tpg *tpg, 1867 + static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg, 1882 1868 const char *name) 1883 1869 { 1884 1870 struct se_portal_group *se_tpg; 1885 1871 struct se_session *se_sess; 1886 - struct tcm_vhost_nexus *tv_nexus; 1887 - struct tcm_vhost_cmd *tv_cmd; 1872 + struct vhost_scsi_nexus *tv_nexus; 1873 + struct vhost_scsi_cmd *tv_cmd; 1888 1874 unsigned int i; 1889 1875 1890 1876 mutex_lock(&tpg->tv_tpg_mutex); ··· 1895 1881 } 1896 1882 se_tpg = &tpg->se_tpg; 1897 1883 1898 - tv_nexus = kzalloc(sizeof(struct tcm_vhost_nexus), GFP_KERNEL); 1884 + tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL); 1899 1885 if (!tv_nexus) { 1900 1886 mutex_unlock(&tpg->tv_tpg_mutex); 1901 - pr_err("Unable to allocate struct tcm_vhost_nexus\n"); 1887 + pr_err("Unable to allocate struct vhost_scsi_nexus\n"); 1902 1888 return -ENOMEM; 1903 1889 } 1904 1890 /* 1905 1891 * Initialize the struct se_session pointer and setup tagpool 1906 - * for struct tcm_vhost_cmd descriptors 1892 + * for struct vhost_scsi_cmd descriptors 1907 1893 */ 1908 1894 tv_nexus->tvn_se_sess = transport_init_session_tags( 1909 - TCM_VHOST_DEFAULT_TAGS, 1910 - sizeof(struct tcm_vhost_cmd), 1895 + VHOST_SCSI_DEFAULT_TAGS, 1896 + sizeof(struct vhost_scsi_cmd), 1911 1897 TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS); 1912 1898 if (IS_ERR(tv_nexus->tvn_se_sess)) { 1913 1899 mutex_unlock(&tpg->tv_tpg_mutex); ··· 1915 1901 return -ENOMEM; 1916 1902 } 1917 1903 se_sess = tv_nexus->tvn_se_sess; 1918 - for (i = 0; i < TCM_VHOST_DEFAULT_TAGS; i++) { 1919 - tv_cmd = &((struct tcm_vhost_cmd *)se_sess->sess_cmd_map)[i]; 1904 + for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) { 1905 + tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i]; 1920 1906 1921 1907 tv_cmd->tvc_sgl = kzalloc(sizeof(struct scatterlist) * 1922 - TCM_VHOST_PREALLOC_SGLS, GFP_KERNEL); 1908 + VHOST_SCSI_PREALLOC_SGLS, GFP_KERNEL); 1923 1909 if (!tv_cmd->tvc_sgl) { 1924 1910 mutex_unlock(&tpg->tv_tpg_mutex); 1925 1911 pr_err("Unable to allocate tv_cmd->tvc_sgl\n"); ··· 1927 1913 } 1928 1914 1929 1915 tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) * 1930 - TCM_VHOST_PREALLOC_UPAGES, GFP_KERNEL); 1916 + VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL); 1931 1917 if (!tv_cmd->tvc_upages) { 1932 1918 mutex_unlock(&tpg->tv_tpg_mutex); 1933 1919 pr_err("Unable to allocate tv_cmd->tvc_upages\n"); ··· 1935 1921 } 1936 1922 1937 1923 tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) * 1938 - TCM_VHOST_PREALLOC_PROT_SGLS, GFP_KERNEL); 1924 + VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL); 1939 1925 if (!tv_cmd->tvc_prot_sgl) { 1940 1926 mutex_unlock(&tpg->tv_tpg_mutex); 1941 1927 pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n"); ··· 1944 1930 } 1945 1931 /* 1946 1932 * Since we are running in 'demo mode' this call with generate a 1947 - * struct se_node_acl for the tcm_vhost struct se_portal_group with 1933 + * struct se_node_acl for the vhost_scsi struct se_portal_group with 1948 1934 * the SCSI Initiator port name of the passed configfs group 'name'. 1949 1935 */ 1950 1936 tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl( ··· 1967 1953 return 0; 1968 1954 1969 1955 out: 1970 - tcm_vhost_free_cmd_map_res(tv_nexus, se_sess); 1956 + vhost_scsi_free_cmd_map_res(tv_nexus, se_sess); 1971 1957 transport_free_session(se_sess); 1972 1958 kfree(tv_nexus); 1973 1959 return -ENOMEM; 1974 1960 } 1975 1961 1976 - static int tcm_vhost_drop_nexus(struct tcm_vhost_tpg *tpg) 1962 + static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg) 1977 1963 { 1978 1964 struct se_session *se_sess; 1979 - struct tcm_vhost_nexus *tv_nexus; 1965 + struct vhost_scsi_nexus *tv_nexus; 1980 1966 1981 1967 mutex_lock(&tpg->tv_tpg_mutex); 1982 1968 tv_nexus = tpg->tpg_nexus; ··· 2008 1994 } 2009 1995 2010 1996 pr_debug("TCM_vhost_ConfigFS: Removing I_T Nexus to emulated" 2011 - " %s Initiator Port: %s\n", tcm_vhost_dump_proto_id(tpg->tport), 1997 + " %s Initiator Port: %s\n", vhost_scsi_dump_proto_id(tpg->tport), 2012 1998 tv_nexus->tvn_se_sess->se_node_acl->initiatorname); 2013 1999 2014 - tcm_vhost_free_cmd_map_res(tv_nexus, se_sess); 2000 + vhost_scsi_free_cmd_map_res(tv_nexus, se_sess); 2015 2001 /* 2016 2002 * Release the SCSI I_T Nexus to the emulated vhost Target Port 2017 2003 */ ··· 2023 2009 return 0; 2024 2010 } 2025 2011 2026 - static ssize_t tcm_vhost_tpg_show_nexus(struct se_portal_group *se_tpg, 2012 + static ssize_t vhost_scsi_tpg_show_nexus(struct se_portal_group *se_tpg, 2027 2013 char *page) 2028 2014 { 2029 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 2030 - struct tcm_vhost_tpg, se_tpg); 2031 - struct tcm_vhost_nexus *tv_nexus; 2015 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 2016 + struct vhost_scsi_tpg, se_tpg); 2017 + struct vhost_scsi_nexus *tv_nexus; 2032 2018 ssize_t ret; 2033 2019 2034 2020 mutex_lock(&tpg->tv_tpg_mutex); ··· 2044 2030 return ret; 2045 2031 } 2046 2032 2047 - static ssize_t tcm_vhost_tpg_store_nexus(struct se_portal_group *se_tpg, 2033 + static ssize_t vhost_scsi_tpg_store_nexus(struct se_portal_group *se_tpg, 2048 2034 const char *page, 2049 2035 size_t count) 2050 2036 { 2051 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 2052 - struct tcm_vhost_tpg, se_tpg); 2053 - struct tcm_vhost_tport *tport_wwn = tpg->tport; 2054 - unsigned char i_port[TCM_VHOST_NAMELEN], *ptr, *port_ptr; 2037 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 2038 + struct vhost_scsi_tpg, se_tpg); 2039 + struct vhost_scsi_tport *tport_wwn = tpg->tport; 2040 + unsigned char i_port[VHOST_SCSI_NAMELEN], *ptr, *port_ptr; 2055 2041 int ret; 2056 2042 /* 2057 2043 * Shutdown the active I_T nexus if 'NULL' is passed.. 2058 2044 */ 2059 2045 if (!strncmp(page, "NULL", 4)) { 2060 - ret = tcm_vhost_drop_nexus(tpg); 2046 + ret = vhost_scsi_drop_nexus(tpg); 2061 2047 return (!ret) ? count : ret; 2062 2048 } 2063 2049 /* 2064 2050 * Otherwise make sure the passed virtual Initiator port WWN matches 2065 - * the fabric protocol_id set in tcm_vhost_make_tport(), and call 2066 - * tcm_vhost_make_nexus(). 2051 + * the fabric protocol_id set in vhost_scsi_make_tport(), and call 2052 + * vhost_scsi_make_nexus(). 2067 2053 */ 2068 - if (strlen(page) >= TCM_VHOST_NAMELEN) { 2054 + if (strlen(page) >= VHOST_SCSI_NAMELEN) { 2069 2055 pr_err("Emulated NAA Sas Address: %s, exceeds" 2070 - " max: %d\n", page, TCM_VHOST_NAMELEN); 2056 + " max: %d\n", page, VHOST_SCSI_NAMELEN); 2071 2057 return -EINVAL; 2072 2058 } 2073 - snprintf(&i_port[0], TCM_VHOST_NAMELEN, "%s", page); 2059 + snprintf(&i_port[0], VHOST_SCSI_NAMELEN, "%s", page); 2074 2060 2075 2061 ptr = strstr(i_port, "naa."); 2076 2062 if (ptr) { 2077 2063 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_SAS) { 2078 2064 pr_err("Passed SAS Initiator Port %s does not" 2079 2065 " match target port protoid: %s\n", i_port, 2080 - tcm_vhost_dump_proto_id(tport_wwn)); 2066 + vhost_scsi_dump_proto_id(tport_wwn)); 2081 2067 return -EINVAL; 2082 2068 } 2083 2069 port_ptr = &i_port[0]; ··· 2088 2074 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_FCP) { 2089 2075 pr_err("Passed FCP Initiator Port %s does not" 2090 2076 " match target port protoid: %s\n", i_port, 2091 - tcm_vhost_dump_proto_id(tport_wwn)); 2077 + vhost_scsi_dump_proto_id(tport_wwn)); 2092 2078 return -EINVAL; 2093 2079 } 2094 2080 port_ptr = &i_port[3]; /* Skip over "fc." */ ··· 2099 2085 if (tport_wwn->tport_proto_id != SCSI_PROTOCOL_ISCSI) { 2100 2086 pr_err("Passed iSCSI Initiator Port %s does not" 2101 2087 " match target port protoid: %s\n", i_port, 2102 - tcm_vhost_dump_proto_id(tport_wwn)); 2088 + vhost_scsi_dump_proto_id(tport_wwn)); 2103 2089 return -EINVAL; 2104 2090 } 2105 2091 port_ptr = &i_port[0]; ··· 2115 2101 if (i_port[strlen(i_port)-1] == '\n') 2116 2102 i_port[strlen(i_port)-1] = '\0'; 2117 2103 2118 - ret = tcm_vhost_make_nexus(tpg, port_ptr); 2104 + ret = vhost_scsi_make_nexus(tpg, port_ptr); 2119 2105 if (ret < 0) 2120 2106 return ret; 2121 2107 2122 2108 return count; 2123 2109 } 2124 2110 2125 - TF_TPG_BASE_ATTR(tcm_vhost, nexus, S_IRUGO | S_IWUSR); 2111 + TF_TPG_BASE_ATTR(vhost_scsi, nexus, S_IRUGO | S_IWUSR); 2126 2112 2127 - static struct configfs_attribute *tcm_vhost_tpg_attrs[] = { 2128 - &tcm_vhost_tpg_nexus.attr, 2113 + static struct configfs_attribute *vhost_scsi_tpg_attrs[] = { 2114 + &vhost_scsi_tpg_nexus.attr, 2129 2115 NULL, 2130 2116 }; 2131 2117 2132 2118 static struct se_portal_group * 2133 - tcm_vhost_make_tpg(struct se_wwn *wwn, 2119 + vhost_scsi_make_tpg(struct se_wwn *wwn, 2134 2120 struct config_group *group, 2135 2121 const char *name) 2136 2122 { 2137 - struct tcm_vhost_tport *tport = container_of(wwn, 2138 - struct tcm_vhost_tport, tport_wwn); 2123 + struct vhost_scsi_tport *tport = container_of(wwn, 2124 + struct vhost_scsi_tport, tport_wwn); 2139 2125 2140 - struct tcm_vhost_tpg *tpg; 2141 - unsigned long tpgt; 2126 + struct vhost_scsi_tpg *tpg; 2127 + u16 tpgt; 2142 2128 int ret; 2143 2129 2144 2130 if (strstr(name, "tpgt_") != name) 2145 2131 return ERR_PTR(-EINVAL); 2146 - if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX) 2132 + if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET) 2147 2133 return ERR_PTR(-EINVAL); 2148 2134 2149 - tpg = kzalloc(sizeof(struct tcm_vhost_tpg), GFP_KERNEL); 2135 + tpg = kzalloc(sizeof(struct vhost_scsi_tpg), GFP_KERNEL); 2150 2136 if (!tpg) { 2151 - pr_err("Unable to allocate struct tcm_vhost_tpg"); 2137 + pr_err("Unable to allocate struct vhost_scsi_tpg"); 2152 2138 return ERR_PTR(-ENOMEM); 2153 2139 } 2154 2140 mutex_init(&tpg->tv_tpg_mutex); ··· 2156 2142 tpg->tport = tport; 2157 2143 tpg->tport_tpgt = tpgt; 2158 2144 2159 - ret = core_tpg_register(&tcm_vhost_fabric_configfs->tf_ops, wwn, 2145 + ret = core_tpg_register(&vhost_scsi_fabric_configfs->tf_ops, wwn, 2160 2146 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 2161 2147 if (ret < 0) { 2162 2148 kfree(tpg); 2163 2149 return NULL; 2164 2150 } 2165 - mutex_lock(&tcm_vhost_mutex); 2166 - list_add_tail(&tpg->tv_tpg_list, &tcm_vhost_list); 2167 - mutex_unlock(&tcm_vhost_mutex); 2151 + mutex_lock(&vhost_scsi_mutex); 2152 + list_add_tail(&tpg->tv_tpg_list, &vhost_scsi_list); 2153 + mutex_unlock(&vhost_scsi_mutex); 2168 2154 2169 2155 return &tpg->se_tpg; 2170 2156 } 2171 2157 2172 - static void tcm_vhost_drop_tpg(struct se_portal_group *se_tpg) 2158 + static void vhost_scsi_drop_tpg(struct se_portal_group *se_tpg) 2173 2159 { 2174 - struct tcm_vhost_tpg *tpg = container_of(se_tpg, 2175 - struct tcm_vhost_tpg, se_tpg); 2160 + struct vhost_scsi_tpg *tpg = container_of(se_tpg, 2161 + struct vhost_scsi_tpg, se_tpg); 2176 2162 2177 - mutex_lock(&tcm_vhost_mutex); 2163 + mutex_lock(&vhost_scsi_mutex); 2178 2164 list_del(&tpg->tv_tpg_list); 2179 - mutex_unlock(&tcm_vhost_mutex); 2165 + mutex_unlock(&vhost_scsi_mutex); 2180 2166 /* 2181 2167 * Release the virtual I_T Nexus for this vhost TPG 2182 2168 */ 2183 - tcm_vhost_drop_nexus(tpg); 2169 + vhost_scsi_drop_nexus(tpg); 2184 2170 /* 2185 2171 * Deregister the se_tpg from TCM.. 2186 2172 */ ··· 2189 2175 } 2190 2176 2191 2177 static struct se_wwn * 2192 - tcm_vhost_make_tport(struct target_fabric_configfs *tf, 2178 + vhost_scsi_make_tport(struct target_fabric_configfs *tf, 2193 2179 struct config_group *group, 2194 2180 const char *name) 2195 2181 { 2196 - struct tcm_vhost_tport *tport; 2182 + struct vhost_scsi_tport *tport; 2197 2183 char *ptr; 2198 2184 u64 wwpn = 0; 2199 2185 int off = 0; 2200 2186 2201 - /* if (tcm_vhost_parse_wwn(name, &wwpn, 1) < 0) 2187 + /* if (vhost_scsi_parse_wwn(name, &wwpn, 1) < 0) 2202 2188 return ERR_PTR(-EINVAL); */ 2203 2189 2204 - tport = kzalloc(sizeof(struct tcm_vhost_tport), GFP_KERNEL); 2190 + tport = kzalloc(sizeof(struct vhost_scsi_tport), GFP_KERNEL); 2205 2191 if (!tport) { 2206 - pr_err("Unable to allocate struct tcm_vhost_tport"); 2192 + pr_err("Unable to allocate struct vhost_scsi_tport"); 2207 2193 return ERR_PTR(-ENOMEM); 2208 2194 } 2209 2195 tport->tport_wwpn = wwpn; ··· 2234 2220 return ERR_PTR(-EINVAL); 2235 2221 2236 2222 check_len: 2237 - if (strlen(name) >= TCM_VHOST_NAMELEN) { 2223 + if (strlen(name) >= VHOST_SCSI_NAMELEN) { 2238 2224 pr_err("Emulated %s Address: %s, exceeds" 2239 - " max: %d\n", name, tcm_vhost_dump_proto_id(tport), 2240 - TCM_VHOST_NAMELEN); 2225 + " max: %d\n", name, vhost_scsi_dump_proto_id(tport), 2226 + VHOST_SCSI_NAMELEN); 2241 2227 kfree(tport); 2242 2228 return ERR_PTR(-EINVAL); 2243 2229 } 2244 - snprintf(&tport->tport_name[0], TCM_VHOST_NAMELEN, "%s", &name[off]); 2230 + snprintf(&tport->tport_name[0], VHOST_SCSI_NAMELEN, "%s", &name[off]); 2245 2231 2246 2232 pr_debug("TCM_VHost_ConfigFS: Allocated emulated Target" 2247 - " %s Address: %s\n", tcm_vhost_dump_proto_id(tport), name); 2233 + " %s Address: %s\n", vhost_scsi_dump_proto_id(tport), name); 2248 2234 2249 2235 return &tport->tport_wwn; 2250 2236 } 2251 2237 2252 - static void tcm_vhost_drop_tport(struct se_wwn *wwn) 2238 + static void vhost_scsi_drop_tport(struct se_wwn *wwn) 2253 2239 { 2254 - struct tcm_vhost_tport *tport = container_of(wwn, 2255 - struct tcm_vhost_tport, tport_wwn); 2240 + struct vhost_scsi_tport *tport = container_of(wwn, 2241 + struct vhost_scsi_tport, tport_wwn); 2256 2242 2257 2243 pr_debug("TCM_VHost_ConfigFS: Deallocating emulated Target" 2258 - " %s Address: %s\n", tcm_vhost_dump_proto_id(tport), 2244 + " %s Address: %s\n", vhost_scsi_dump_proto_id(tport), 2259 2245 tport->tport_name); 2260 2246 2261 2247 kfree(tport); 2262 2248 } 2263 2249 2264 2250 static ssize_t 2265 - tcm_vhost_wwn_show_attr_version(struct target_fabric_configfs *tf, 2251 + vhost_scsi_wwn_show_attr_version(struct target_fabric_configfs *tf, 2266 2252 char *page) 2267 2253 { 2268 2254 return sprintf(page, "TCM_VHOST fabric module %s on %s/%s" 2269 - "on "UTS_RELEASE"\n", TCM_VHOST_VERSION, utsname()->sysname, 2255 + "on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname, 2270 2256 utsname()->machine); 2271 2257 } 2272 2258 2273 - TF_WWN_ATTR_RO(tcm_vhost, version); 2259 + TF_WWN_ATTR_RO(vhost_scsi, version); 2274 2260 2275 - static struct configfs_attribute *tcm_vhost_wwn_attrs[] = { 2276 - &tcm_vhost_wwn_version.attr, 2261 + static struct configfs_attribute *vhost_scsi_wwn_attrs[] = { 2262 + &vhost_scsi_wwn_version.attr, 2277 2263 NULL, 2278 2264 }; 2279 2265 2280 - static struct target_core_fabric_ops tcm_vhost_ops = { 2281 - .get_fabric_name = tcm_vhost_get_fabric_name, 2282 - .get_fabric_proto_ident = tcm_vhost_get_fabric_proto_ident, 2283 - .tpg_get_wwn = tcm_vhost_get_fabric_wwn, 2284 - .tpg_get_tag = tcm_vhost_get_tag, 2285 - .tpg_get_default_depth = tcm_vhost_get_default_depth, 2286 - .tpg_get_pr_transport_id = tcm_vhost_get_pr_transport_id, 2287 - .tpg_get_pr_transport_id_len = tcm_vhost_get_pr_transport_id_len, 2288 - .tpg_parse_pr_out_transport_id = tcm_vhost_parse_pr_out_transport_id, 2289 - .tpg_check_demo_mode = tcm_vhost_check_true, 2290 - .tpg_check_demo_mode_cache = tcm_vhost_check_true, 2291 - .tpg_check_demo_mode_write_protect = tcm_vhost_check_false, 2292 - .tpg_check_prod_mode_write_protect = tcm_vhost_check_false, 2293 - .tpg_alloc_fabric_acl = tcm_vhost_alloc_fabric_acl, 2294 - .tpg_release_fabric_acl = tcm_vhost_release_fabric_acl, 2295 - .tpg_get_inst_index = tcm_vhost_tpg_get_inst_index, 2296 - .release_cmd = tcm_vhost_release_cmd, 2266 + static struct target_core_fabric_ops vhost_scsi_ops = { 2267 + .get_fabric_name = vhost_scsi_get_fabric_name, 2268 + .get_fabric_proto_ident = vhost_scsi_get_fabric_proto_ident, 2269 + .tpg_get_wwn = vhost_scsi_get_fabric_wwn, 2270 + .tpg_get_tag = vhost_scsi_get_tpgt, 2271 + .tpg_get_default_depth = vhost_scsi_get_default_depth, 2272 + .tpg_get_pr_transport_id = vhost_scsi_get_pr_transport_id, 2273 + .tpg_get_pr_transport_id_len = vhost_scsi_get_pr_transport_id_len, 2274 + .tpg_parse_pr_out_transport_id = vhost_scsi_parse_pr_out_transport_id, 2275 + .tpg_check_demo_mode = vhost_scsi_check_true, 2276 + .tpg_check_demo_mode_cache = vhost_scsi_check_true, 2277 + .tpg_check_demo_mode_write_protect = vhost_scsi_check_false, 2278 + .tpg_check_prod_mode_write_protect = vhost_scsi_check_false, 2279 + .tpg_alloc_fabric_acl = vhost_scsi_alloc_fabric_acl, 2280 + .tpg_release_fabric_acl = vhost_scsi_release_fabric_acl, 2281 + .tpg_get_inst_index = vhost_scsi_tpg_get_inst_index, 2282 + .release_cmd = vhost_scsi_release_cmd, 2297 2283 .check_stop_free = vhost_scsi_check_stop_free, 2298 - .shutdown_session = tcm_vhost_shutdown_session, 2299 - .close_session = tcm_vhost_close_session, 2300 - .sess_get_index = tcm_vhost_sess_get_index, 2284 + .shutdown_session = vhost_scsi_shutdown_session, 2285 + .close_session = vhost_scsi_close_session, 2286 + .sess_get_index = vhost_scsi_sess_get_index, 2301 2287 .sess_get_initiator_sid = NULL, 2302 - .write_pending = tcm_vhost_write_pending, 2303 - .write_pending_status = tcm_vhost_write_pending_status, 2304 - .set_default_node_attributes = tcm_vhost_set_default_node_attrs, 2305 - .get_task_tag = tcm_vhost_get_task_tag, 2306 - .get_cmd_state = tcm_vhost_get_cmd_state, 2307 - .queue_data_in = tcm_vhost_queue_data_in, 2308 - .queue_status = tcm_vhost_queue_status, 2309 - .queue_tm_rsp = tcm_vhost_queue_tm_rsp, 2310 - .aborted_task = tcm_vhost_aborted_task, 2288 + .write_pending = vhost_scsi_write_pending, 2289 + .write_pending_status = vhost_scsi_write_pending_status, 2290 + .set_default_node_attributes = vhost_scsi_set_default_node_attrs, 2291 + .get_task_tag = vhost_scsi_get_task_tag, 2292 + .get_cmd_state = vhost_scsi_get_cmd_state, 2293 + .queue_data_in = vhost_scsi_queue_data_in, 2294 + .queue_status = vhost_scsi_queue_status, 2295 + .queue_tm_rsp = vhost_scsi_queue_tm_rsp, 2296 + .aborted_task = vhost_scsi_aborted_task, 2311 2297 /* 2312 2298 * Setup callers for generic logic in target_core_fabric_configfs.c 2313 2299 */ 2314 - .fabric_make_wwn = tcm_vhost_make_tport, 2315 - .fabric_drop_wwn = tcm_vhost_drop_tport, 2316 - .fabric_make_tpg = tcm_vhost_make_tpg, 2317 - .fabric_drop_tpg = tcm_vhost_drop_tpg, 2318 - .fabric_post_link = tcm_vhost_port_link, 2319 - .fabric_pre_unlink = tcm_vhost_port_unlink, 2300 + .fabric_make_wwn = vhost_scsi_make_tport, 2301 + .fabric_drop_wwn = vhost_scsi_drop_tport, 2302 + .fabric_make_tpg = vhost_scsi_make_tpg, 2303 + .fabric_drop_tpg = vhost_scsi_drop_tpg, 2304 + .fabric_post_link = vhost_scsi_port_link, 2305 + .fabric_pre_unlink = vhost_scsi_port_unlink, 2320 2306 .fabric_make_np = NULL, 2321 2307 .fabric_drop_np = NULL, 2322 - .fabric_make_nodeacl = tcm_vhost_make_nodeacl, 2323 - .fabric_drop_nodeacl = tcm_vhost_drop_nodeacl, 2308 + .fabric_make_nodeacl = vhost_scsi_make_nodeacl, 2309 + .fabric_drop_nodeacl = vhost_scsi_drop_nodeacl, 2324 2310 }; 2325 2311 2326 - static int tcm_vhost_register_configfs(void) 2312 + static int vhost_scsi_register_configfs(void) 2327 2313 { 2328 2314 struct target_fabric_configfs *fabric; 2329 2315 int ret; 2330 2316 2331 - pr_debug("TCM_VHOST fabric module %s on %s/%s" 2332 - " on "UTS_RELEASE"\n", TCM_VHOST_VERSION, utsname()->sysname, 2317 + pr_debug("vhost-scsi fabric module %s on %s/%s" 2318 + " on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname, 2333 2319 utsname()->machine); 2334 2320 /* 2335 2321 * Register the top level struct config_item_type with TCM core ··· 2340 2326 return PTR_ERR(fabric); 2341 2327 } 2342 2328 /* 2343 - * Setup fabric->tf_ops from our local tcm_vhost_ops 2329 + * Setup fabric->tf_ops from our local vhost_scsi_ops 2344 2330 */ 2345 - fabric->tf_ops = tcm_vhost_ops; 2331 + fabric->tf_ops = vhost_scsi_ops; 2346 2332 /* 2347 2333 * Setup default attribute lists for various fabric->tf_cit_tmpl 2348 2334 */ 2349 - fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_vhost_wwn_attrs; 2350 - fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = tcm_vhost_tpg_attrs; 2335 + fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = vhost_scsi_wwn_attrs; 2336 + fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = vhost_scsi_tpg_attrs; 2351 2337 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; 2352 2338 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; 2353 2339 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; ··· 2367 2353 /* 2368 2354 * Setup our local pointer to *fabric 2369 2355 */ 2370 - tcm_vhost_fabric_configfs = fabric; 2371 - pr_debug("TCM_VHOST[0] - Set fabric -> tcm_vhost_fabric_configfs\n"); 2356 + vhost_scsi_fabric_configfs = fabric; 2357 + pr_debug("TCM_VHOST[0] - Set fabric -> vhost_scsi_fabric_configfs\n"); 2372 2358 return 0; 2373 2359 }; 2374 2360 2375 - static void tcm_vhost_deregister_configfs(void) 2361 + static void vhost_scsi_deregister_configfs(void) 2376 2362 { 2377 - if (!tcm_vhost_fabric_configfs) 2363 + if (!vhost_scsi_fabric_configfs) 2378 2364 return; 2379 2365 2380 - target_fabric_configfs_deregister(tcm_vhost_fabric_configfs); 2381 - tcm_vhost_fabric_configfs = NULL; 2382 - pr_debug("TCM_VHOST[0] - Cleared tcm_vhost_fabric_configfs\n"); 2366 + target_fabric_configfs_deregister(vhost_scsi_fabric_configfs); 2367 + vhost_scsi_fabric_configfs = NULL; 2368 + pr_debug("TCM_VHOST[0] - Cleared vhost_scsi_fabric_configfs\n"); 2383 2369 }; 2384 2370 2385 - static int __init tcm_vhost_init(void) 2371 + static int __init vhost_scsi_init(void) 2386 2372 { 2387 2373 int ret = -ENOMEM; 2388 2374 /* 2389 2375 * Use our own dedicated workqueue for submitting I/O into 2390 2376 * target core to avoid contention within system_wq. 2391 2377 */ 2392 - tcm_vhost_workqueue = alloc_workqueue("tcm_vhost", 0, 0); 2393 - if (!tcm_vhost_workqueue) 2378 + vhost_scsi_workqueue = alloc_workqueue("vhost_scsi", 0, 0); 2379 + if (!vhost_scsi_workqueue) 2394 2380 goto out; 2395 2381 2396 2382 ret = vhost_scsi_register(); 2397 2383 if (ret < 0) 2398 2384 goto out_destroy_workqueue; 2399 2385 2400 - ret = tcm_vhost_register_configfs(); 2386 + ret = vhost_scsi_register_configfs(); 2401 2387 if (ret < 0) 2402 2388 goto out_vhost_scsi_deregister; 2403 2389 ··· 2406 2392 out_vhost_scsi_deregister: 2407 2393 vhost_scsi_deregister(); 2408 2394 out_destroy_workqueue: 2409 - destroy_workqueue(tcm_vhost_workqueue); 2395 + destroy_workqueue(vhost_scsi_workqueue); 2410 2396 out: 2411 2397 return ret; 2412 2398 }; 2413 2399 2414 - static void tcm_vhost_exit(void) 2400 + static void vhost_scsi_exit(void) 2415 2401 { 2416 - tcm_vhost_deregister_configfs(); 2402 + vhost_scsi_deregister_configfs(); 2417 2403 vhost_scsi_deregister(); 2418 - destroy_workqueue(tcm_vhost_workqueue); 2404 + destroy_workqueue(vhost_scsi_workqueue); 2419 2405 }; 2420 2406 2421 2407 MODULE_DESCRIPTION("VHOST_SCSI series fabric driver"); 2422 2408 MODULE_ALIAS("tcm_vhost"); 2423 2409 MODULE_LICENSE("GPL"); 2424 - module_init(tcm_vhost_init); 2425 - module_exit(tcm_vhost_exit); 2410 + module_init(vhost_scsi_init); 2411 + module_exit(vhost_scsi_exit);
+1 -1
include/target/iscsi/iscsi_transport.h
··· 1 1 #include <linux/module.h> 2 2 #include <linux/list.h> 3 - #include "../../../drivers/target/iscsi/iscsi_target_core.h" 3 + #include "iscsi_target_core.h" 4 4 5 5 struct iscsit_transport { 6 6 #define ISCSIT_TRANSPORT_NAME 16
+1 -1
include/target/target_core_base.h
··· 407 407 /* Activate Persistence across Target Power Loss enabled 408 408 * for SCSI device */ 409 409 int pr_aptpl_active; 410 - #define PR_APTPL_BUF_LEN 8192 410 + #define PR_APTPL_BUF_LEN 262144 411 411 u32 pr_generation; 412 412 spinlock_t registration_lock; 413 413 spinlock_t aptpl_reg_lock;