diff options
Diffstat (limited to 'kernel/drivers/target/iscsi')
17 files changed, 806 insertions, 1645 deletions
diff --git a/kernel/drivers/target/iscsi/iscsi_target.c b/kernel/drivers/target/iscsi/iscsi_target.c index 0ab6e2efd..72204fbf2 100644 --- a/kernel/drivers/target/iscsi/iscsi_target.c +++ b/kernel/drivers/target/iscsi/iscsi_target.c @@ -21,14 +21,14 @@ #include <linux/crypto.h> #include <linux/completion.h> #include <linux/module.h> +#include <linux/vmalloc.h> #include <linux/idr.h> #include <asm/unaligned.h> -#include <scsi/scsi_device.h> +#include <scsi/scsi_proto.h> #include <scsi/iscsi_proto.h> #include <scsi/scsi_tcq.h> #include <target/target_core_base.h> #include <target/target_core_fabric.h> -#include <target/target_core_configfs.h> #include <target/iscsi/iscsi_target_core.h> #include "iscsi_target_parameters.h" @@ -269,14 +269,14 @@ int iscsit_deaccess_np(struct iscsi_np *np, struct iscsi_portal_group *tpg, } bool iscsit_check_np_match( - struct __kernel_sockaddr_storage *sockaddr, + struct sockaddr_storage *sockaddr, struct iscsi_np *np, int network_transport) { struct sockaddr_in *sock_in, *sock_in_e; struct sockaddr_in6 *sock_in6, *sock_in6_e; bool ip_match = false; - u16 port; + u16 port, port_e; if (sockaddr->ss_family == AF_INET6) { sock_in6 = (struct sockaddr_in6 *)sockaddr; @@ -288,6 +288,7 @@ bool iscsit_check_np_match( ip_match = true; port = ntohs(sock_in6->sin6_port); + port_e = ntohs(sock_in6_e->sin6_port); } else { sock_in = (struct sockaddr_in *)sockaddr; sock_in_e = (struct sockaddr_in *)&np->np_sockaddr; @@ -296,9 +297,10 @@ bool iscsit_check_np_match( ip_match = true; port = ntohs(sock_in->sin_port); + port_e = ntohs(sock_in_e->sin_port); } - if (ip_match && (np->np_port == port) && + if (ip_match && (port_e == port) && (np->np_network_transport == network_transport)) return true; @@ -309,7 +311,7 @@ bool iscsit_check_np_match( * Called with mutex np_lock held */ static struct iscsi_np *iscsit_get_np( - struct __kernel_sockaddr_storage *sockaddr, + struct sockaddr_storage *sockaddr, int network_transport) { struct iscsi_np *np; @@ -340,12 +342,9 @@ static struct iscsi_np *iscsit_get_np( } struct iscsi_np *iscsit_add_np( - struct __kernel_sockaddr_storage *sockaddr, - char *ip_str, + struct sockaddr_storage *sockaddr, int network_transport) { - struct sockaddr_in *sock_in; - struct sockaddr_in6 *sock_in6; struct iscsi_np *np; int ret; @@ -368,16 +367,6 @@ struct iscsi_np *iscsit_add_np( } np->np_flags |= NPF_IP_NETWORK; - if (sockaddr->ss_family == AF_INET6) { - sock_in6 = (struct sockaddr_in6 *)sockaddr; - snprintf(np->np_ip, IPV6_ADDRESS_SPACE, "%s", ip_str); - np->np_port = ntohs(sock_in6->sin6_port); - } else { - sock_in = (struct sockaddr_in *)sockaddr; - sprintf(np->np_ip, "%s", ip_str); - np->np_port = ntohs(sock_in->sin_port); - } - np->np_network_transport = network_transport; spin_lock_init(&np->np_thread_lock); init_completion(&np->np_restart_comp); @@ -411,8 +400,8 @@ struct iscsi_np *iscsit_add_np( list_add_tail(&np->np_list, &g_np_list); mutex_unlock(&np_lock); - pr_debug("CORE[0] - Added Network Portal: %s:%hu on %s\n", - np->np_ip, np->np_port, np->np_transport->name); + pr_debug("CORE[0] - Added Network Portal: %pISpc on %s\n", + &np->np_sockaddr, np->np_transport->name); return np; } @@ -481,8 +470,8 @@ int iscsit_del_np(struct iscsi_np *np) list_del(&np->np_list); mutex_unlock(&np_lock); - pr_debug("CORE[0] - Removed Network Portal: %s:%hu on %s\n", - np->np_ip, np->np_port, np->np_transport->name); + pr_debug("CORE[0] - Removed Network Portal: %pISpc on %s\n", + &np->np_sockaddr, np->np_transport->name); iscsit_put_transport(np->np_transport); kfree(np); @@ -715,7 +704,7 @@ static int iscsit_add_reject_from_cmd( */ if (cmd->se_cmd.se_tfo != NULL) { pr_debug("iscsi reject: calling target_put_sess_cmd >>>>>>\n"); - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); + target_put_sess_cmd(&cmd->se_cmd); } return -1; } @@ -1001,13 +990,15 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, hdr->cmdsn, be32_to_cpu(hdr->data_length), payload_length, conn->cid); - target_get_sess_cmd(conn->sess->se_sess, &cmd->se_cmd, true); + target_get_sess_cmd(&cmd->se_cmd, true); cmd->sense_reason = transport_lookup_cmd_lun(&cmd->se_cmd, scsilun_to_int(&hdr->lun)); if (cmd->sense_reason) goto attach_cmd; + /* only used for printks or comparing with ->ref_task_tag */ + cmd->se_cmd.tag = (__force u32)cmd->init_task_tag; cmd->sense_reason = target_setup_cmd_from_cdb(&cmd->se_cmd, hdr->cdb); if (cmd->sense_reason) { if (cmd->sense_reason == TCM_OUT_OF_RESOURCES) { @@ -1067,7 +1058,7 @@ int iscsit_process_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, if (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) return -1; else if (cmdsn_ret == CMDSN_LOWER_THAN_EXP) { - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); + target_put_sess_cmd(&cmd->se_cmd); return 0; } } @@ -1083,7 +1074,7 @@ int iscsit_process_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, if (!cmd->sense_reason) return 0; - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); + target_put_sess_cmd(&cmd->se_cmd); return 0; } @@ -1114,7 +1105,6 @@ static int iscsit_get_immediate_data(struct iscsi_cmd *cmd, struct iscsi_scsi_req *hdr, bool dump_payload) { - struct iscsi_conn *conn = cmd->conn; int cmdsn_ret = 0, immed_ret = IMMEDIATE_DATA_NORMAL_OPERATION; /* * Special case for Unsupported SAM WRITE Opcodes and ImmediateData=Yes. @@ -1141,7 +1131,7 @@ after_immediate_data: rc = iscsit_dump_data_payload(cmd->conn, cmd->first_burst_len, 1); - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); + target_put_sess_cmd(&cmd->se_cmd); return rc; } else if (cmd->unsolicited_data) iscsit_set_unsoliticed_dataout(cmd); @@ -1208,7 +1198,6 @@ static u32 iscsit_do_crypto_hash_sg( u8 *pad_bytes) { u32 data_crc; - u32 i; struct scatterlist *sg; unsigned int page_off; @@ -1217,15 +1206,15 @@ static u32 iscsit_do_crypto_hash_sg( sg = cmd->first_data_sg; page_off = cmd->first_data_sg_off; - i = 0; while (data_length) { - u32 cur_len = min_t(u32, data_length, (sg[i].length - page_off)); + u32 cur_len = min_t(u32, data_length, (sg->length - page_off)); - crypto_hash_update(hash, &sg[i], cur_len); + crypto_hash_update(hash, sg, cur_len); data_length -= cur_len; page_off = 0; - i++; + /* iscsit_map_iovec has already checked for invalid sg pointers */ + sg = sg_next(sg); } if (padding) { @@ -1810,7 +1799,7 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd, conn->sess->se_sess, 0, DMA_NONE, TCM_SIMPLE_TAG, cmd->sense_buffer + 2); - target_get_sess_cmd(conn->sess->se_sess, &cmd->se_cmd, true); + target_get_sess_cmd(&cmd->se_cmd, true); sess_ref = true; switch (function) { @@ -1952,7 +1941,7 @@ attach: */ if (sess_ref) { pr_debug("Handle TMR, using sess_ref=true check\n"); - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); + target_put_sess_cmd(&cmd->se_cmd); } iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); @@ -2555,7 +2544,7 @@ static int iscsit_send_conn_drop_async_message( cmd->stat_sn = conn->stat_sn++; hdr->statsn = cpu_to_be32(cmd->stat_sn); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); hdr->async_event = ISCSI_ASYNC_MSG_DROPPING_CONNECTION; hdr->param1 = cpu_to_be16(cmd->logout_cid); hdr->param2 = cpu_to_be16(conn->sess->sess_ops->DefaultTime2Wait); @@ -2627,7 +2616,7 @@ iscsit_build_datain_pdu(struct iscsi_cmd *cmd, struct iscsi_conn *conn, hdr->statsn = cpu_to_be32(0xFFFFFFFF); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); hdr->datasn = cpu_to_be32(datain->data_sn); hdr->offset = cpu_to_be32(datain->offset); @@ -2736,11 +2725,7 @@ static int iscsit_send_datain(struct iscsi_cmd *cmd, struct iscsi_conn *conn) cmd->iov_data_count = iov_count; cmd->tx_size = tx_size; - /* sendpage is preferred but can't insert markers */ - if (!conn->conn_ops->IFMarker) - ret = iscsit_fe_sendpage_sg(cmd, conn); - else - ret = iscsit_send_tx_data(cmd, conn, 0); + ret = iscsit_fe_sendpage_sg(cmd, conn); iscsit_unmap_iovec(cmd); @@ -2842,7 +2827,7 @@ iscsit_build_logout_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, iscsit_increment_maxcmdsn(cmd, conn->sess); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Built Logout Response ITT: 0x%08x StatSN:" " 0x%08x Response: 0x%02x CID: %hu on CID: %hu\n", @@ -2905,7 +2890,7 @@ iscsit_build_nopin_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, iscsit_increment_maxcmdsn(cmd, conn->sess); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Built NOPIN %s Response ITT: 0x%08x, TTT: 0x%08x," " StatSN: 0x%08x, Length %u\n", (nopout_response) ? @@ -3052,7 +3037,7 @@ static int iscsit_send_r2t( hdr->ttt = cpu_to_be32(r2t->targ_xfer_tag); hdr->statsn = cpu_to_be32(conn->stat_sn); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); hdr->r2tsn = cpu_to_be32(r2t->r2t_sn); hdr->data_offset = cpu_to_be32(r2t->offset); hdr->data_length = cpu_to_be32(r2t->xfer_len); @@ -3205,7 +3190,7 @@ void iscsit_build_rsp_pdu(struct iscsi_cmd *cmd, struct iscsi_conn *conn, iscsit_increment_maxcmdsn(cmd, conn->sess); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Built SCSI Response, ITT: 0x%08x, StatSN: 0x%08x," " Response: 0x%02x, SAM Status: 0x%02x, CID: %hu\n", @@ -3324,7 +3309,7 @@ iscsit_build_task_mgt_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, iscsit_increment_maxcmdsn(cmd, conn->sess); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Built Task Management Response ITT: 0x%08x," " StatSN: 0x%08x, Response: 0x%02x, CID: %hu\n", @@ -3402,6 +3387,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, int target_name_printed; unsigned char buf[ISCSI_IQN_LEN+12]; /* iqn + "TargetName=" + \0 */ unsigned char *text_in = cmd->text_in_ptr, *text_ptr = NULL; + bool active; buffer_len = min(conn->conn_ops->MaxRecvDataSegmentLength, SENDTARGETS_BUF_LIMIT); @@ -3455,19 +3441,18 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, } spin_lock(&tpg->tpg_state_lock); - if ((tpg->tpg_state == TPG_STATE_FREE) || - (tpg->tpg_state == TPG_STATE_INACTIVE)) { - spin_unlock(&tpg->tpg_state_lock); - continue; - } + active = (tpg->tpg_state == TPG_STATE_ACTIVE); spin_unlock(&tpg->tpg_state_lock); + if (!active && tpg->tpg_attrib.tpg_enabled_sendtargets) + continue; + spin_lock(&tpg->tpg_np_lock); list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { struct iscsi_np *np = tpg_np->tpg_np; bool inaddr_any = iscsit_check_inaddr_any(np); - char *fmt_str; + struct sockaddr_storage *sockaddr; if (np->np_network_transport != network_transport) continue; @@ -3495,15 +3480,15 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd, } } - if (np->np_sockaddr.ss_family == AF_INET6) - fmt_str = "TargetAddress=[%s]:%hu,%hu"; + if (inaddr_any) + sockaddr = &conn->local_sockaddr; else - fmt_str = "TargetAddress=%s:%hu,%hu"; + sockaddr = &np->np_sockaddr; - len = sprintf(buf, fmt_str, - inaddr_any ? conn->local_ip : np->np_ip, - np->np_port, - tpg->tpgt); + len = sprintf(buf, "TargetAddress=" + "%pISpc,%hu", + sockaddr, + tpg->tpgt); len += 1; if ((len + payload_len) > buffer_len) { @@ -3579,7 +3564,7 @@ iscsit_build_text_rsp(struct iscsi_cmd *cmd, struct iscsi_conn *conn, */ cmd->maxcmdsn_inc = 0; hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Built Text Response: ITT: 0x%08x, TTT: 0x%08x, StatSN: 0x%08x," " Length: %u, CID: %hu F: %d C: %d\n", cmd->init_task_tag, @@ -3657,7 +3642,7 @@ iscsit_build_reject(struct iscsi_cmd *cmd, struct iscsi_conn *conn, cmd->stat_sn = conn->stat_sn++; hdr->statsn = cpu_to_be32(cmd->stat_sn); hdr->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - hdr->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + hdr->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); } EXPORT_SYMBOL(iscsit_build_reject); @@ -4078,17 +4063,9 @@ static int iscsi_target_rx_opcode(struct iscsi_conn *conn, unsigned char *buf) " opcode while ERL=0, closing iSCSI connection.\n"); return -1; } - if (!conn->conn_ops->OFMarker) { - pr_err("Unable to recover from unknown" - " opcode while OFMarker=No, closing iSCSI" - " connection.\n"); - return -1; - } - if (iscsit_recover_from_unknown_opcode(conn) < 0) { - pr_err("Unable to recover from unknown" - " opcode, closing iSCSI connection.\n"); - return -1; - } + pr_err("Unable to recover from unknown opcode while OFMarker=No," + " closing iSCSI connection.\n"); + ret = -1; break; } @@ -4097,6 +4074,17 @@ reject: return iscsit_add_reject(conn, ISCSI_REASON_BOOKMARK_NO_RESOURCES, buf); } +static bool iscsi_target_check_conn_state(struct iscsi_conn *conn) +{ + bool ret; + + spin_lock_bh(&conn->state_lock); + ret = (conn->conn_state != TARG_CONN_STATE_LOGGED_IN); + spin_unlock_bh(&conn->state_lock); + + return ret; +} + int iscsi_target_rx_thread(void *arg) { int ret, rc; @@ -4114,7 +4102,7 @@ int iscsi_target_rx_thread(void *arg) * incoming iscsi/tcp socket I/O, and/or failing the connection. */ rc = wait_for_completion_interruptible(&conn->rx_login_comp); - if (rc < 0) + if (rc < 0 || iscsi_target_check_conn_state(conn)) return 0; if (conn->conn_transport->transport_type == ISCSI_INFINIBAND) { diff --git a/kernel/drivers/target/iscsi/iscsi_target.h b/kernel/drivers/target/iscsi/iscsi_target.h index 7d0f9c00d..4cf2c0f2b 100644 --- a/kernel/drivers/target/iscsi/iscsi_target.h +++ b/kernel/drivers/target/iscsi/iscsi_target.h @@ -10,10 +10,10 @@ extern int iscsit_access_np(struct iscsi_np *, struct iscsi_portal_group *); extern void iscsit_login_kref_put(struct kref *); extern int iscsit_deaccess_np(struct iscsi_np *, struct iscsi_portal_group *, struct iscsi_tpg_np *); -extern bool iscsit_check_np_match(struct __kernel_sockaddr_storage *, +extern bool iscsit_check_np_match(struct sockaddr_storage *, struct iscsi_np *, int); -extern struct iscsi_np *iscsit_add_np(struct __kernel_sockaddr_storage *, - char *, int); +extern struct iscsi_np *iscsit_add_np(struct sockaddr_storage *, + int); extern int iscsit_reset_np_thread(struct iscsi_np *, struct iscsi_tpg_np *, struct iscsi_portal_group *, bool); extern int iscsit_del_np(struct iscsi_np *); diff --git a/kernel/drivers/target/iscsi/iscsi_target_configfs.c b/kernel/drivers/target/iscsi/iscsi_target_configfs.c index 469fce44e..b4bfd706a 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_configfs.c +++ b/kernel/drivers/target/iscsi/iscsi_target_configfs.c @@ -23,9 +23,6 @@ #include <linux/inet.h> #include <target/target_core_base.h> #include <target/target_core_fabric.h> -#include <target/target_core_fabric_configfs.h> -#include <target/target_core_configfs.h> -#include <target/configfs_macros.h> #include <target/iscsi/iscsi_transport.h> #include <target/iscsi/iscsi_target_core.h> @@ -38,20 +35,17 @@ #include "iscsi_target.h" #include <target/iscsi/iscsi_target_stat.h> -struct lio_target_configfs_attribute { - struct configfs_attribute attr; - ssize_t (*show)(void *, char *); - ssize_t (*store)(void *, const char *, size_t); -}; /* Start items for lio_target_portal_cit */ -static ssize_t lio_target_np_show_sctp( - struct se_tpg_np *se_tpg_np, - char *page) +static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) { - struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, - struct iscsi_tpg_np, se_tpg_np); + return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); +} + +static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) +{ + struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_tpg_np *tpg_np_sctp; ssize_t rb; @@ -64,15 +58,12 @@ static ssize_t lio_target_np_show_sctp( return rb; } -static ssize_t lio_target_np_store_sctp( - struct se_tpg_np *se_tpg_np, - const char *page, - size_t count) +static ssize_t lio_target_np_sctp_store(struct config_item *item, + const char *page, size_t count) { + struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_np *np; struct iscsi_portal_group *tpg; - struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, - struct iscsi_tpg_np, se_tpg_np); struct iscsi_tpg_np *tpg_np_sctp = NULL; u32 op; int ret; @@ -100,7 +91,7 @@ static ssize_t lio_target_np_store_sctp( * Use existing np->np_sockaddr for SCTP network portal reference */ tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, - np->np_ip, tpg_np, ISCSI_SCTP_TCP); + tpg_np, ISCSI_SCTP_TCP); if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) goto out; } else { @@ -120,14 +111,9 @@ out: return -EINVAL; } -TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR); - -static ssize_t lio_target_np_show_iser( - struct se_tpg_np *se_tpg_np, - char *page) +static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) { - struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, - struct iscsi_tpg_np, se_tpg_np); + struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_tpg_np *tpg_np_iser; ssize_t rb; @@ -140,15 +126,12 @@ static ssize_t lio_target_np_show_iser( return rb; } -static ssize_t lio_target_np_store_iser( - struct se_tpg_np *se_tpg_np, - const char *page, - size_t count) +static ssize_t lio_target_np_iser_store(struct config_item *item, + const char *page, size_t count) { + struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); struct iscsi_np *np; struct iscsi_portal_group *tpg; - struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, - struct iscsi_tpg_np, se_tpg_np); struct iscsi_tpg_np *tpg_np_iser = NULL; char *endptr; u32 op; @@ -178,7 +161,7 @@ static ssize_t lio_target_np_store_iser( } tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, - np->np_ip, tpg_np, ISCSI_INFINIBAND); + tpg_np, ISCSI_INFINIBAND); if (IS_ERR(tpg_np_iser)) { rc = PTR_ERR(tpg_np_iser); goto out; @@ -199,11 +182,12 @@ out: return rc; } -TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR); +CONFIGFS_ATTR(lio_target_np_, sctp); +CONFIGFS_ATTR(lio_target_np_, iser); static struct configfs_attribute *lio_target_portal_attrs[] = { - &lio_target_np_sctp.attr, - &lio_target_np_iser.attr, + &lio_target_np_attr_sctp, + &lio_target_np_attr_iser, NULL, }; @@ -221,7 +205,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( struct iscsi_portal_group *tpg; struct iscsi_tpg_np *tpg_np; char *str, *str2, *ip_str, *port_str; - struct __kernel_sockaddr_storage sockaddr; + struct sockaddr_storage sockaddr; struct sockaddr_in *sock_in; struct sockaddr_in6 *sock_in6; unsigned long port; @@ -236,7 +220,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( memset(buf, 0, MAX_PORTAL_LEN + 1); snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); - memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage)); + memset(&sockaddr, 0, sizeof(struct sockaddr_storage)); str = strstr(buf, "["); if (str) { @@ -249,8 +233,8 @@ static struct se_tpg_np *lio_target_call_addnptotpg( return ERR_PTR(-EINVAL); } str++; /* Skip over leading "[" */ - *str2 = '\0'; /* Terminate the IPv6 address */ - str2++; /* Skip over the "]" */ + *str2 = '\0'; /* Terminate the unbracketed IPv6 address */ + str2++; /* Skip over the \0 */ port_str = strstr(str2, ":"); if (!port_str) { pr_err("Unable to locate \":port\"" @@ -268,7 +252,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( sock_in6 = (struct sockaddr_in6 *)&sockaddr; sock_in6->sin6_family = AF_INET6; sock_in6->sin6_port = htons((unsigned short)port); - ret = in6_pton(str, IPV6_ADDRESS_SPACE, + ret = in6_pton(str, -1, (void *)&sock_in6->sin6_addr.in6_u, -1, &end); if (ret <= 0) { pr_err("in6_pton returned: %d\n", ret); @@ -317,7 +301,7 @@ static struct se_tpg_np *lio_target_call_addnptotpg( * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ * */ - tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL, + tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL, ISCSI_TCP); if (IS_ERR(tpg_np)) { iscsit_put_tpg(tpg); @@ -345,8 +329,8 @@ static void lio_target_call_delnpfromtpg( se_tpg = &tpg->tpg_se_tpg; pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" - " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), - tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port); + " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), + tpg->tpgt, &tpg_np->tpg_np->np_sockaddr); ret = iscsit_tpg_del_network_portal(tpg, tpg_np); if (ret < 0) @@ -361,22 +345,21 @@ out: /* Start items for lio_target_nacl_attrib_cit */ -#define DEF_NACL_ATTRIB(name) \ -static ssize_t iscsi_nacl_attrib_show_##name( \ - struct se_node_acl *se_nacl, \ - char *page) \ +#define ISCSI_NACL_ATTR(name) \ +static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\ + char *page) \ { \ + struct se_node_acl *se_nacl = attrib_to_nacl(item); \ struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ se_node_acl); \ \ return sprintf(page, "%u\n", nacl->node_attrib.name); \ } \ \ -static ssize_t iscsi_nacl_attrib_store_##name( \ - struct se_node_acl *se_nacl, \ - const char *page, \ - size_t count) \ +static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ + const char *page, size_t count) \ { \ + struct se_node_acl *se_nacl = attrib_to_nacl(item); \ struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ se_node_acl); \ u32 val; \ @@ -390,59 +373,28 @@ static ssize_t iscsi_nacl_attrib_store_##name( \ return ret; \ \ return count; \ -} +} \ + \ +CONFIGFS_ATTR(iscsi_nacl_attrib_, name) -#define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); -/* - * Define iscsi_node_attrib_s_dataout_timeout - */ -DEF_NACL_ATTRIB(dataout_timeout); -NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_dataout_timeout_retries - */ -DEF_NACL_ATTRIB(dataout_timeout_retries); -NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_default_erl - */ -DEF_NACL_ATTRIB(default_erl); -NACL_ATTR(default_erl, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_nopin_timeout - */ -DEF_NACL_ATTRIB(nopin_timeout); -NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_nopin_response_timeout - */ -DEF_NACL_ATTRIB(nopin_response_timeout); -NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_random_datain_pdu_offsets - */ -DEF_NACL_ATTRIB(random_datain_pdu_offsets); -NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_random_datain_seq_offsets - */ -DEF_NACL_ATTRIB(random_datain_seq_offsets); -NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR); -/* - * Define iscsi_node_attrib_s_random_r2t_offsets - */ -DEF_NACL_ATTRIB(random_r2t_offsets); -NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR); +ISCSI_NACL_ATTR(dataout_timeout); +ISCSI_NACL_ATTR(dataout_timeout_retries); +ISCSI_NACL_ATTR(default_erl); +ISCSI_NACL_ATTR(nopin_timeout); +ISCSI_NACL_ATTR(nopin_response_timeout); +ISCSI_NACL_ATTR(random_datain_pdu_offsets); +ISCSI_NACL_ATTR(random_datain_seq_offsets); +ISCSI_NACL_ATTR(random_r2t_offsets); static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { - &iscsi_nacl_attrib_dataout_timeout.attr, - &iscsi_nacl_attrib_dataout_timeout_retries.attr, - &iscsi_nacl_attrib_default_erl.attr, - &iscsi_nacl_attrib_nopin_timeout.attr, - &iscsi_nacl_attrib_nopin_response_timeout.attr, - &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, - &iscsi_nacl_attrib_random_datain_seq_offsets.attr, - &iscsi_nacl_attrib_random_r2t_offsets.attr, + &iscsi_nacl_attrib_attr_dataout_timeout, + &iscsi_nacl_attrib_attr_dataout_timeout_retries, + &iscsi_nacl_attrib_attr_default_erl, + &iscsi_nacl_attrib_attr_nopin_timeout, + &iscsi_nacl_attrib_attr_nopin_response_timeout, + &iscsi_nacl_attrib_attr_random_datain_pdu_offsets, + &iscsi_nacl_attrib_attr_random_datain_seq_offsets, + &iscsi_nacl_attrib_attr_random_r2t_offsets, NULL, }; @@ -451,7 +403,7 @@ static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { /* Start items for lio_target_nacl_auth_cit */ #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ -static ssize_t __iscsi_##prefix##_show_##name( \ +static ssize_t __iscsi_##prefix##_##name##_show( \ struct iscsi_node_acl *nacl, \ char *page) \ { \ @@ -462,7 +414,7 @@ static ssize_t __iscsi_##prefix##_show_##name( \ return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ } \ \ -static ssize_t __iscsi_##prefix##_store_##name( \ +static ssize_t __iscsi_##prefix##_##name##_store( \ struct iscsi_node_acl *nacl, \ const char *page, \ size_t count) \ @@ -488,8 +440,35 @@ static ssize_t __iscsi_##prefix##_store_##name( \ return count; \ } +#define DEF_NACL_AUTH_STR(name, flags) \ + __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ +static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ + char *page) \ +{ \ + struct se_node_acl *nacl = auth_to_nacl(item); \ + return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page); \ +} \ +static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \ + const char *page, size_t count) \ +{ \ + struct se_node_acl *nacl = auth_to_nacl(item); \ + return __iscsi_nacl_auth_##name##_store(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page, count); \ +} \ + \ +CONFIGFS_ATTR(iscsi_nacl_auth_, name) + +/* + * One-way authentication userid + */ +DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); +DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); +DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); +DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); + #define __DEF_NACL_AUTH_INT(prefix, name) \ -static ssize_t __iscsi_##prefix##_show_##name( \ +static ssize_t __iscsi_##prefix##_##name##_show( \ struct iscsi_node_acl *nacl, \ char *page) \ { \ @@ -501,69 +480,26 @@ static ssize_t __iscsi_##prefix##_show_##name( \ return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ } -#define DEF_NACL_AUTH_STR(name, flags) \ - __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ -static ssize_t iscsi_nacl_auth_show_##name( \ - struct se_node_acl *nacl, \ - char *page) \ -{ \ - return __iscsi_nacl_auth_show_##name(container_of(nacl, \ - struct iscsi_node_acl, se_node_acl), page); \ -} \ -static ssize_t iscsi_nacl_auth_store_##name( \ - struct se_node_acl *nacl, \ - const char *page, \ - size_t count) \ -{ \ - return __iscsi_nacl_auth_store_##name(container_of(nacl, \ - struct iscsi_node_acl, se_node_acl), page, count); \ -} - #define DEF_NACL_AUTH_INT(name) \ __DEF_NACL_AUTH_INT(nacl_auth, name) \ -static ssize_t iscsi_nacl_auth_show_##name( \ - struct se_node_acl *nacl, \ - char *page) \ +static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ + char *page) \ { \ - return __iscsi_nacl_auth_show_##name(container_of(nacl, \ - struct iscsi_node_acl, se_node_acl), page); \ -} - -#define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); -#define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); + struct se_node_acl *nacl = auth_to_nacl(item); \ + return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page); \ +} \ + \ +CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name) -/* - * One-way authentication userid - */ -DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); -AUTH_ATTR(userid, S_IRUGO | S_IWUSR); -/* - * One-way authentication password - */ -DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); -AUTH_ATTR(password, S_IRUGO | S_IWUSR); -/* - * Enforce mutual authentication - */ DEF_NACL_AUTH_INT(authenticate_target); -AUTH_ATTR_RO(authenticate_target); -/* - * Mutual authentication userid - */ -DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); -AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); -/* - * Mutual authentication password - */ -DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); -AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { - &iscsi_nacl_auth_userid.attr, - &iscsi_nacl_auth_password.attr, - &iscsi_nacl_auth_authenticate_target.attr, - &iscsi_nacl_auth_userid_mutual.attr, - &iscsi_nacl_auth_password_mutual.attr, + &iscsi_nacl_auth_attr_userid, + &iscsi_nacl_auth_attr_password, + &iscsi_nacl_auth_attr_authenticate_target, + &iscsi_nacl_auth_attr_userid_mutual, + &iscsi_nacl_auth_attr_password_mutual, NULL, }; @@ -571,11 +507,11 @@ static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { /* Start items for lio_target_nacl_param_cit */ -#define DEF_NACL_PARAM(name) \ -static ssize_t iscsi_nacl_param_show_##name( \ - struct se_node_acl *se_nacl, \ - char *page) \ +#define ISCSI_NACL_PARAM(name) \ +static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \ + char *page) \ { \ + struct se_node_acl *se_nacl = param_to_nacl(item); \ struct iscsi_session *sess; \ struct se_session *se_sess; \ ssize_t rb; \ @@ -593,55 +529,34 @@ static ssize_t iscsi_nacl_param_show_##name( \ spin_unlock_bh(&se_nacl->nacl_sess_lock); \ \ return rb; \ -} - -#define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); - -DEF_NACL_PARAM(MaxConnections); -NACL_PARAM_ATTR(MaxConnections); - -DEF_NACL_PARAM(InitialR2T); -NACL_PARAM_ATTR(InitialR2T); - -DEF_NACL_PARAM(ImmediateData); -NACL_PARAM_ATTR(ImmediateData); - -DEF_NACL_PARAM(MaxBurstLength); -NACL_PARAM_ATTR(MaxBurstLength); - -DEF_NACL_PARAM(FirstBurstLength); -NACL_PARAM_ATTR(FirstBurstLength); - -DEF_NACL_PARAM(DefaultTime2Wait); -NACL_PARAM_ATTR(DefaultTime2Wait); - -DEF_NACL_PARAM(DefaultTime2Retain); -NACL_PARAM_ATTR(DefaultTime2Retain); - -DEF_NACL_PARAM(MaxOutstandingR2T); -NACL_PARAM_ATTR(MaxOutstandingR2T); - -DEF_NACL_PARAM(DataPDUInOrder); -NACL_PARAM_ATTR(DataPDUInOrder); - -DEF_NACL_PARAM(DataSequenceInOrder); -NACL_PARAM_ATTR(DataSequenceInOrder); - -DEF_NACL_PARAM(ErrorRecoveryLevel); -NACL_PARAM_ATTR(ErrorRecoveryLevel); +} \ + \ +CONFIGFS_ATTR_RO(iscsi_nacl_param_, name) + +ISCSI_NACL_PARAM(MaxConnections); +ISCSI_NACL_PARAM(InitialR2T); +ISCSI_NACL_PARAM(ImmediateData); +ISCSI_NACL_PARAM(MaxBurstLength); +ISCSI_NACL_PARAM(FirstBurstLength); +ISCSI_NACL_PARAM(DefaultTime2Wait); +ISCSI_NACL_PARAM(DefaultTime2Retain); +ISCSI_NACL_PARAM(MaxOutstandingR2T); +ISCSI_NACL_PARAM(DataPDUInOrder); +ISCSI_NACL_PARAM(DataSequenceInOrder); +ISCSI_NACL_PARAM(ErrorRecoveryLevel); static struct configfs_attribute *lio_target_nacl_param_attrs[] = { - &iscsi_nacl_param_MaxConnections.attr, - &iscsi_nacl_param_InitialR2T.attr, - &iscsi_nacl_param_ImmediateData.attr, - &iscsi_nacl_param_MaxBurstLength.attr, - &iscsi_nacl_param_FirstBurstLength.attr, - &iscsi_nacl_param_DefaultTime2Wait.attr, - &iscsi_nacl_param_DefaultTime2Retain.attr, - &iscsi_nacl_param_MaxOutstandingR2T.attr, - &iscsi_nacl_param_DataPDUInOrder.attr, - &iscsi_nacl_param_DataSequenceInOrder.attr, - &iscsi_nacl_param_ErrorRecoveryLevel.attr, + &iscsi_nacl_param_attr_MaxConnections, + &iscsi_nacl_param_attr_InitialR2T, + &iscsi_nacl_param_attr_ImmediateData, + &iscsi_nacl_param_attr_MaxBurstLength, + &iscsi_nacl_param_attr_FirstBurstLength, + &iscsi_nacl_param_attr_DefaultTime2Wait, + &iscsi_nacl_param_attr_DefaultTime2Retain, + &iscsi_nacl_param_attr_MaxOutstandingR2T, + &iscsi_nacl_param_attr_DataPDUInOrder, + &iscsi_nacl_param_attr_DataSequenceInOrder, + &iscsi_nacl_param_attr_ErrorRecoveryLevel, NULL, }; @@ -649,14 +564,14 @@ static struct configfs_attribute *lio_target_nacl_param_attrs[] = { /* Start items for lio_target_acl_cit */ -static ssize_t lio_target_nacl_show_info( - struct se_node_acl *se_nacl, - char *page) +static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) { + struct se_node_acl *se_nacl = acl_to_nacl(item); struct iscsi_session *sess; struct iscsi_conn *conn; struct se_session *se_sess; ssize_t rb = 0; + u32 max_cmd_sn; spin_lock_bh(&se_nacl->nacl_sess_lock); se_sess = se_nacl->nacl_sess; @@ -704,11 +619,12 @@ static ssize_t lio_target_nacl_show_info( " Values]-----------------------\n"); rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" " : MaxCmdSN : ITT : TTT\n"); + max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" " 0x%08x 0x%08x\n", sess->cmdsn_window, - (sess->max_cmd_sn - sess->exp_cmd_sn) + 1, - sess->exp_cmd_sn, sess->max_cmd_sn, + (max_cmd_sn - sess->exp_cmd_sn) + 1, + sess->exp_cmd_sn, max_cmd_sn, sess->init_task_tag, sess->targ_xfer_tag); rb += sprintf(page+rb, "----------------------[iSCSI" " Connections]-------------------------\n"); @@ -752,7 +668,7 @@ static ssize_t lio_target_nacl_show_info( break; } - rb += sprintf(page+rb, " Address %s %s", conn->login_ip, + rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, (conn->network_transport == ISCSI_TCP) ? "TCP" : "SCTP"); rb += sprintf(page+rb, " StatSN: 0x%08x\n", @@ -765,20 +681,16 @@ static ssize_t lio_target_nacl_show_info( return rb; } -TF_NACL_BASE_ATTR_RO(lio_target, info); - -static ssize_t lio_target_nacl_show_cmdsn_depth( - struct se_node_acl *se_nacl, - char *page) +static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, + char *page) { - return sprintf(page, "%u\n", se_nacl->queue_depth); + return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); } -static ssize_t lio_target_nacl_store_cmdsn_depth( - struct se_node_acl *se_nacl, - const char *page, - size_t count) +static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, + const char *page, size_t count) { + struct se_node_acl *se_nacl = acl_to_nacl(item); struct se_portal_group *se_tpg = se_nacl->se_tpg; struct iscsi_portal_group *tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); @@ -828,20 +740,15 @@ static ssize_t lio_target_nacl_store_cmdsn_depth( return (!ret) ? count : (ssize_t)ret; } -TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR); - -static ssize_t lio_target_nacl_show_tag( - struct se_node_acl *se_nacl, - char *page) +static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page) { - return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag); + return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); } -static ssize_t lio_target_nacl_store_tag( - struct se_node_acl *se_nacl, - const char *page, - size_t count) +static ssize_t lio_target_nacl_tag_store(struct config_item *item, + const char *page, size_t count) { + struct se_node_acl *se_nacl = acl_to_nacl(item); int ret; ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); @@ -851,66 +758,30 @@ static ssize_t lio_target_nacl_store_tag( return count; } -TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR); +CONFIGFS_ATTR_RO(lio_target_nacl_, info); +CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth); +CONFIGFS_ATTR(lio_target_nacl_, tag); static struct configfs_attribute *lio_target_initiator_attrs[] = { - &lio_target_nacl_info.attr, - &lio_target_nacl_cmdsn_depth.attr, - &lio_target_nacl_tag.attr, + &lio_target_nacl_attr_info, + &lio_target_nacl_attr_cmdsn_depth, + &lio_target_nacl_attr_tag, NULL, }; -static struct se_node_acl *lio_tpg_alloc_fabric_acl( - struct se_portal_group *se_tpg) +static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, + const char *name) { - struct iscsi_node_acl *acl; - - acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL); - if (!acl) { - pr_err("Unable to allocate memory for struct iscsi_node_acl\n"); - return NULL; - } - - return &acl->se_node_acl; -} - -static struct se_node_acl *lio_target_make_nodeacl( - struct se_portal_group *se_tpg, - struct config_group *group, - const char *name) -{ - struct config_group *stats_cg; - struct iscsi_node_acl *acl; - struct se_node_acl *se_nacl_new, *se_nacl; - struct iscsi_portal_group *tpg = container_of(se_tpg, - struct iscsi_portal_group, tpg_se_tpg); - u32 cmdsn_depth; - - se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg); - if (!se_nacl_new) - return ERR_PTR(-ENOMEM); - - cmdsn_depth = tpg->tpg_attrib.default_cmdsn_depth; - /* - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() - * when converting a NdoeACL from demo mode -> explict - */ - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, - name, cmdsn_depth); - if (IS_ERR(se_nacl)) - return se_nacl; - - acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); - stats_cg = &se_nacl->acl_fabric_stat_group; + struct iscsi_node_acl *acl = + container_of(se_nacl, struct iscsi_node_acl, se_node_acl); + struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group; stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, GFP_KERNEL); if (!stats_cg->default_groups) { pr_err("Unable to allocate memory for" " stats_cg->default_groups\n"); - core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); - kfree(acl); - return ERR_PTR(-ENOMEM); + return -ENOMEM; } stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; @@ -918,13 +789,11 @@ static struct se_node_acl *lio_target_make_nodeacl( config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, "iscsi_sess_stats", &iscsi_stat_sess_cit); - return se_nacl; + return 0; } -static void lio_target_drop_nodeacl( - struct se_node_acl *se_nacl) +static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl) { - struct se_portal_group *se_tpg = se_nacl->se_tpg; struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); struct config_item *df_item; @@ -938,9 +807,6 @@ static void lio_target_drop_nodeacl( config_item_put(df_item); } kfree(stats_cg->default_groups); - - core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); - kfree(acl); } /* End items for lio_target_acl_cit */ @@ -949,10 +815,10 @@ static void lio_target_drop_nodeacl( #define DEF_TPG_ATTRIB(name) \ \ -static ssize_t iscsi_tpg_attrib_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ +static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \ + char *page) \ { \ + struct se_portal_group *se_tpg = attrib_to_tpg(item); \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ ssize_t rb; \ @@ -965,11 +831,10 @@ static ssize_t iscsi_tpg_attrib_show_##name( \ return rb; \ } \ \ -static ssize_t iscsi_tpg_attrib_store_##name( \ - struct se_portal_group *se_tpg, \ - const char *page, \ - size_t count) \ +static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\ + const char *page, size_t count) \ { \ + struct se_portal_group *se_tpg = attrib_to_tpg(item); \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ u32 val; \ @@ -990,84 +855,37 @@ static ssize_t iscsi_tpg_attrib_store_##name( \ out: \ iscsit_put_tpg(tpg); \ return ret; \ -} - -#define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode); +} \ +CONFIGFS_ATTR(iscsi_tpg_attrib_, name) -/* - * Define iscsi_tpg_attrib_s_authentication - */ DEF_TPG_ATTRIB(authentication); -TPG_ATTR(authentication, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_login_timeout - */ DEF_TPG_ATTRIB(login_timeout); -TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_netif_timeout - */ DEF_TPG_ATTRIB(netif_timeout); -TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_generate_node_acls - */ DEF_TPG_ATTRIB(generate_node_acls); -TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_default_cmdsn_depth - */ DEF_TPG_ATTRIB(default_cmdsn_depth); -TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR); -/* - Define iscsi_tpg_attrib_s_cache_dynamic_acls - */ DEF_TPG_ATTRIB(cache_dynamic_acls); -TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_demo_mode_write_protect - */ DEF_TPG_ATTRIB(demo_mode_write_protect); -TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_prod_mode_write_protect - */ DEF_TPG_ATTRIB(prod_mode_write_protect); -TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_demo_mode_discovery, - */ DEF_TPG_ATTRIB(demo_mode_discovery); -TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_default_erl - */ DEF_TPG_ATTRIB(default_erl); -TPG_ATTR(default_erl, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_t10_pi - */ DEF_TPG_ATTRIB(t10_pi); -TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR); -/* - * Define iscsi_tpg_attrib_s_fabric_prot_type - */ DEF_TPG_ATTRIB(fabric_prot_type); -TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR); +DEF_TPG_ATTRIB(tpg_enabled_sendtargets); static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { - &iscsi_tpg_attrib_authentication.attr, - &iscsi_tpg_attrib_login_timeout.attr, - &iscsi_tpg_attrib_netif_timeout.attr, - &iscsi_tpg_attrib_generate_node_acls.attr, - &iscsi_tpg_attrib_default_cmdsn_depth.attr, - &iscsi_tpg_attrib_cache_dynamic_acls.attr, - &iscsi_tpg_attrib_demo_mode_write_protect.attr, - &iscsi_tpg_attrib_prod_mode_write_protect.attr, - &iscsi_tpg_attrib_demo_mode_discovery.attr, - &iscsi_tpg_attrib_default_erl.attr, - &iscsi_tpg_attrib_t10_pi.attr, - &iscsi_tpg_attrib_fabric_prot_type.attr, + &iscsi_tpg_attrib_attr_authentication, + &iscsi_tpg_attrib_attr_login_timeout, + &iscsi_tpg_attrib_attr_netif_timeout, + &iscsi_tpg_attrib_attr_generate_node_acls, + &iscsi_tpg_attrib_attr_default_cmdsn_depth, + &iscsi_tpg_attrib_attr_cache_dynamic_acls, + &iscsi_tpg_attrib_attr_demo_mode_write_protect, + &iscsi_tpg_attrib_attr_prod_mode_write_protect, + &iscsi_tpg_attrib_attr_demo_mode_discovery, + &iscsi_tpg_attrib_attr_default_erl, + &iscsi_tpg_attrib_attr_t10_pi, + &iscsi_tpg_attrib_attr_fabric_prot_type, + &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets, NULL, }; @@ -1076,9 +894,8 @@ static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { /* Start items for lio_target_tpg_auth_cit */ #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ -static ssize_t __iscsi_##prefix##_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ +static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ + char *page) \ { \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ @@ -1090,10 +907,8 @@ static ssize_t __iscsi_##prefix##_show_##name( \ return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ } \ \ -static ssize_t __iscsi_##prefix##_store_##name( \ - struct se_portal_group *se_tpg, \ - const char *page, \ - size_t count) \ +static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\ + const char *page, size_t count) \ { \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ @@ -1117,10 +932,31 @@ static ssize_t __iscsi_##prefix##_store_##name( \ return count; \ } +#define DEF_TPG_AUTH_STR(name, flags) \ + __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ +static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ + char *page) \ +{ \ + return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ +} \ + \ +static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \ + const char *page, size_t count) \ +{ \ + return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \ +} \ + \ +CONFIGFS_ATTR(iscsi_tpg_auth_, name); + + +DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); +DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); +DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); +DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); + #define __DEF_TPG_AUTH_INT(prefix, name) \ -static ssize_t __iscsi_##prefix##_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ +static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ + char *page) \ { \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ @@ -1132,67 +968,23 @@ static ssize_t __iscsi_##prefix##_show_##name( \ return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ } -#define DEF_TPG_AUTH_STR(name, flags) \ - __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ -static ssize_t iscsi_tpg_auth_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ -{ \ - return __iscsi_tpg_auth_show_##name(se_tpg, page); \ -} \ - \ -static ssize_t iscsi_tpg_auth_store_##name( \ - struct se_portal_group *se_tpg, \ - const char *page, \ - size_t count) \ -{ \ - return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \ -} - #define DEF_TPG_AUTH_INT(name) \ __DEF_TPG_AUTH_INT(tpg_auth, name) \ -static ssize_t iscsi_tpg_auth_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ +static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ + char *page) \ { \ - return __iscsi_tpg_auth_show_##name(se_tpg, page); \ -} - -#define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode); -#define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name); + return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ +} \ +CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name); -/* - * * One-way authentication userid - * */ -DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); -TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); -/* - * * One-way authentication password - * */ -DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); -TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR); -/* - * * Enforce mutual authentication - * */ DEF_TPG_AUTH_INT(authenticate_target); -TPG_AUTH_ATTR_RO(authenticate_target); -/* - * * Mutual authentication userid - * */ -DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); -TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); -/* - * * Mutual authentication password - * */ -DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); -TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { - &iscsi_tpg_auth_userid.attr, - &iscsi_tpg_auth_password.attr, - &iscsi_tpg_auth_authenticate_target.attr, - &iscsi_tpg_auth_userid_mutual.attr, - &iscsi_tpg_auth_password_mutual.attr, + &iscsi_tpg_auth_attr_userid, + &iscsi_tpg_auth_attr_password, + &iscsi_tpg_auth_attr_authenticate_target, + &iscsi_tpg_auth_attr_userid_mutual, + &iscsi_tpg_auth_attr_password_mutual, NULL, }; @@ -1201,10 +993,10 @@ static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { /* Start items for lio_target_tpg_param_cit */ #define DEF_TPG_PARAM(name) \ -static ssize_t iscsi_tpg_param_show_##name( \ - struct se_portal_group *se_tpg, \ - char *page) \ +static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \ + char *page) \ { \ + struct se_portal_group *se_tpg = param_to_tpg(item); \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ struct iscsi_param *param; \ @@ -1224,11 +1016,10 @@ static ssize_t iscsi_tpg_param_show_##name( \ iscsit_put_tpg(tpg); \ return rb; \ } \ -static ssize_t iscsi_tpg_param_store_##name( \ - struct se_portal_group *se_tpg, \ - const char *page, \ - size_t count) \ +static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \ + const char *page, size_t count) \ { \ + struct se_portal_group *se_tpg = param_to_tpg(item); \ struct iscsi_portal_group *tpg = container_of(se_tpg, \ struct iscsi_portal_group, tpg_se_tpg); \ char *buf; \ @@ -1256,96 +1047,54 @@ static ssize_t iscsi_tpg_param_store_##name( \ out: \ kfree(buf); \ iscsit_put_tpg(tpg); \ - return -EINVAL; \ -} - -#define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode); + return -EINVAL; \ +} \ +CONFIGFS_ATTR(iscsi_tpg_param_, name) DEF_TPG_PARAM(AuthMethod); -TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(HeaderDigest); -TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(DataDigest); -TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(MaxConnections); -TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(TargetAlias); -TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(InitialR2T); -TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(ImmediateData); -TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(MaxRecvDataSegmentLength); -TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(MaxXmitDataSegmentLength); -TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(MaxBurstLength); -TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(FirstBurstLength); -TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(DefaultTime2Wait); -TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(DefaultTime2Retain); -TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(MaxOutstandingR2T); -TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(DataPDUInOrder); -TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(DataSequenceInOrder); -TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(ErrorRecoveryLevel); -TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(IFMarker); -TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(OFMarker); -TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(IFMarkInt); -TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR); - DEF_TPG_PARAM(OFMarkInt); -TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR); static struct configfs_attribute *lio_target_tpg_param_attrs[] = { - &iscsi_tpg_param_AuthMethod.attr, - &iscsi_tpg_param_HeaderDigest.attr, - &iscsi_tpg_param_DataDigest.attr, - &iscsi_tpg_param_MaxConnections.attr, - &iscsi_tpg_param_TargetAlias.attr, - &iscsi_tpg_param_InitialR2T.attr, - &iscsi_tpg_param_ImmediateData.attr, - &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, - &iscsi_tpg_param_MaxXmitDataSegmentLength.attr, - &iscsi_tpg_param_MaxBurstLength.attr, - &iscsi_tpg_param_FirstBurstLength.attr, - &iscsi_tpg_param_DefaultTime2Wait.attr, - &iscsi_tpg_param_DefaultTime2Retain.attr, - &iscsi_tpg_param_MaxOutstandingR2T.attr, - &iscsi_tpg_param_DataPDUInOrder.attr, - &iscsi_tpg_param_DataSequenceInOrder.attr, - &iscsi_tpg_param_ErrorRecoveryLevel.attr, - &iscsi_tpg_param_IFMarker.attr, - &iscsi_tpg_param_OFMarker.attr, - &iscsi_tpg_param_IFMarkInt.attr, - &iscsi_tpg_param_OFMarkInt.attr, + &iscsi_tpg_param_attr_AuthMethod, + &iscsi_tpg_param_attr_HeaderDigest, + &iscsi_tpg_param_attr_DataDigest, + &iscsi_tpg_param_attr_MaxConnections, + &iscsi_tpg_param_attr_TargetAlias, + &iscsi_tpg_param_attr_InitialR2T, + &iscsi_tpg_param_attr_ImmediateData, + &iscsi_tpg_param_attr_MaxRecvDataSegmentLength, + &iscsi_tpg_param_attr_MaxXmitDataSegmentLength, + &iscsi_tpg_param_attr_MaxBurstLength, + &iscsi_tpg_param_attr_FirstBurstLength, + &iscsi_tpg_param_attr_DefaultTime2Wait, + &iscsi_tpg_param_attr_DefaultTime2Retain, + &iscsi_tpg_param_attr_MaxOutstandingR2T, + &iscsi_tpg_param_attr_DataPDUInOrder, + &iscsi_tpg_param_attr_DataSequenceInOrder, + &iscsi_tpg_param_attr_ErrorRecoveryLevel, + &iscsi_tpg_param_attr_IFMarker, + &iscsi_tpg_param_attr_OFMarker, + &iscsi_tpg_param_attr_IFMarkInt, + &iscsi_tpg_param_attr_OFMarkInt, NULL, }; @@ -1353,10 +1102,9 @@ static struct configfs_attribute *lio_target_tpg_param_attrs[] = { /* Start items for lio_target_tpg_cit */ -static ssize_t lio_target_tpg_show_enable( - struct se_portal_group *se_tpg, - char *page) +static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page) { + struct se_portal_group *se_tpg = to_tpg(item); struct iscsi_portal_group *tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); ssize_t len; @@ -1369,11 +1117,10 @@ static ssize_t lio_target_tpg_show_enable( return len; } -static ssize_t lio_target_tpg_store_enable( - struct se_portal_group *se_tpg, - const char *page, - size_t count) +static ssize_t lio_target_tpg_enable_store(struct config_item *item, + const char *page, size_t count) { + struct se_portal_group *se_tpg = to_tpg(item); struct iscsi_portal_group *tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); u32 op; @@ -1411,20 +1158,19 @@ out: return -EINVAL; } -TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR); -static ssize_t lio_target_tpg_show_dynamic_sessions( - struct se_portal_group *se_tpg, - char *page) +static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item, + char *page) { - return target_show_dynamic_sessions(se_tpg, page); + return target_show_dynamic_sessions(to_tpg(item), page); } -TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions); +CONFIGFS_ATTR(lio_target_tpg_, enable); +CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions); static struct configfs_attribute *lio_target_tpg_attrs[] = { - &lio_target_tpg_enable.attr, - &lio_target_tpg_dynamic_sessions.attr, + &lio_target_tpg_attr_enable, + &lio_target_tpg_attr_dynamic_sessions, NULL, }; @@ -1463,8 +1209,7 @@ static struct se_portal_group *lio_target_tiqn_addtpg( if (!tpg) return NULL; - ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg, - tpg, TRANSPORT_TPG_TYPE_NORMAL); + ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); if (ret < 0) return NULL; @@ -1500,17 +1245,16 @@ static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) /* Start LIO-Target TIQN struct contig_item lio_target_cit */ -static ssize_t lio_target_wwn_show_attr_lio_version( - struct target_fabric_configfs *tf, - char *page) +static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, + char *page) { return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); } -TF_WWN_ATTR_RO(lio_target, lio_version); +CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); static struct configfs_attribute *lio_target_wwn_attrs[] = { - &lio_target_wwn_lio_version.attr, + &lio_target_wwn_attr_lio_version, NULL, }; @@ -1589,77 +1333,47 @@ static void lio_target_call_coredeltiqn( #define DEF_DISC_AUTH_STR(name, flags) \ __DEF_NACL_AUTH_STR(disc, name, flags) \ -static ssize_t iscsi_disc_show_##name( \ - struct target_fabric_configfs *tf, \ - char *page) \ +static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ { \ - return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ + return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\ page); \ } \ -static ssize_t iscsi_disc_store_##name( \ - struct target_fabric_configfs *tf, \ - const char *page, \ - size_t count) \ +static ssize_t iscsi_disc_##name##_store(struct config_item *item, \ + const char *page, size_t count) \ { \ - return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \ + return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \ page, count); \ -} + \ +} \ +CONFIGFS_ATTR(iscsi_disc_, name) + +DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); +DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); +DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); +DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); #define DEF_DISC_AUTH_INT(name) \ __DEF_NACL_AUTH_INT(disc, name) \ -static ssize_t iscsi_disc_show_##name( \ - struct target_fabric_configfs *tf, \ - char *page) \ +static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ { \ - return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ + return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \ page); \ -} - -#define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode) -#define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name) +} \ +CONFIGFS_ATTR_RO(iscsi_disc_, name) -/* - * One-way authentication userid - */ -DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); -DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); -/* - * One-way authentication password - */ -DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); -DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR); -/* - * Enforce mutual authentication - */ DEF_DISC_AUTH_INT(authenticate_target); -DISC_AUTH_ATTR_RO(authenticate_target); -/* - * Mutual authentication userid - */ -DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); -DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); -/* - * Mutual authentication password - */ -DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); -DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); -/* - * enforce_discovery_auth - */ -static ssize_t iscsi_disc_show_enforce_discovery_auth( - struct target_fabric_configfs *tf, - char *page) + +static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item, + char *page) { struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); } -static ssize_t iscsi_disc_store_enforce_discovery_auth( - struct target_fabric_configfs *tf, - const char *page, - size_t count) +static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, + const char *page, size_t count) { struct iscsi_param *param; struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; @@ -1714,15 +1428,15 @@ static ssize_t iscsi_disc_store_enforce_discovery_auth( return count; } -DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR); +CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth); static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { - &iscsi_disc_userid.attr, - &iscsi_disc_password.attr, - &iscsi_disc_authenticate_target.attr, - &iscsi_disc_userid_mutual.attr, - &iscsi_disc_password_mutual.attr, - &iscsi_disc_enforce_discovery_auth.attr, + &iscsi_disc_attr_userid, + &iscsi_disc_attr_password, + &iscsi_disc_attr_authenticate_target, + &iscsi_disc_attr_userid_mutual, + &iscsi_disc_attr_password_mutual, + &iscsi_disc_attr_enforce_discovery_auth, NULL, }; @@ -1735,14 +1449,6 @@ static char *iscsi_get_fabric_name(void) return "iSCSI"; } -static u32 iscsi_get_task_tag(struct se_cmd *se_cmd) -{ - struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); - - /* only used for printks or comparism with ->ref_task_tag */ - return (__force u32)cmd->init_task_tag; -} - static int iscsi_get_cmd_state(struct se_cmd *se_cmd) { struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); @@ -1832,82 +1538,63 @@ static void lio_aborted_task(struct se_cmd *se_cmd) cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); } -static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) +static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; + return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); +} - return &tpg->tpg_tiqn->tiqn[0]; +static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) +{ + return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; } static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpgt; + return iscsi_tpg(se_tpg)->tpgt; } static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_attrib.default_cmdsn_depth; + return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; } static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_attrib.generate_node_acls; + return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; } static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_attrib.cache_dynamic_acls; + return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; } static int lio_tpg_check_demo_mode_write_protect( struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_attrib.demo_mode_write_protect; + return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; } static int lio_tpg_check_prod_mode_write_protect( struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_attrib.prod_mode_write_protect; + return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; } static int lio_tpg_check_prot_fabric_only( struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; /* * Only report fabric_prot_type if t10_pi has also been enabled * for incoming ib_isert sessions. */ - if (!tpg->tpg_attrib.t10_pi) + if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) return 0; - - return tpg->tpg_attrib.fabric_prot_type; -} - -static void lio_tpg_release_fabric_acl( - struct se_portal_group *se_tpg, - struct se_node_acl *se_acl) -{ - struct iscsi_node_acl *acl = container_of(se_acl, - struct iscsi_node_acl, se_node_acl); - kfree(acl); + return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; } /* - * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. + * Called with spin_lock_irq(struct se_portal_group->session_lock) held + * or not held. * * Also, this function calls iscsit_inc_session_usage_count() on the * struct iscsi_session in question. @@ -1915,19 +1602,32 @@ static void lio_tpg_release_fabric_acl( static int lio_tpg_shutdown_session(struct se_session *se_sess) { struct iscsi_session *sess = se_sess->fabric_sess_ptr; + struct se_portal_group *se_tpg = se_sess->se_tpg; + bool local_lock = false; + + if (!spin_is_locked(&se_tpg->session_lock)) { + spin_lock_irq(&se_tpg->session_lock); + local_lock = true; + } spin_lock(&sess->conn_lock); if (atomic_read(&sess->session_fall_back_to_erl0) || atomic_read(&sess->session_logout) || (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { spin_unlock(&sess->conn_lock); + if (local_lock) + spin_unlock_irq(&sess->conn_lock); return 0; } atomic_set(&sess->session_reinstatement, 1); spin_unlock(&sess->conn_lock); iscsit_stop_time2retain_timer(sess); + spin_unlock_irq(&se_tpg->session_lock); + iscsit_stop_session(sess, 1, 1); + if (!local_lock) + spin_lock_irq(&se_tpg->session_lock); return 1; } @@ -1948,9 +1648,7 @@ static void lio_tpg_close_session(struct se_session *se_sess) static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) { - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; - - return tpg->tpg_tiqn->tiqn_index; + return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; } static void lio_set_default_node_attributes(struct se_node_acl *se_acl) @@ -1967,7 +1665,7 @@ static void lio_set_default_node_attributes(struct se_node_acl *se_acl) static int lio_check_stop_free(struct se_cmd *se_cmd) { - return target_put_sess_cmd(se_cmd->se_sess, se_cmd); + return target_put_sess_cmd(se_cmd); } static void lio_release_cmd(struct se_cmd *se_cmd) @@ -1981,14 +1679,11 @@ static void lio_release_cmd(struct se_cmd *se_cmd) const struct target_core_fabric_ops iscsi_ops = { .module = THIS_MODULE, .name = "iscsi", + .node_acl_size = sizeof(struct iscsi_node_acl), .get_fabric_name = iscsi_get_fabric_name, - .get_fabric_proto_ident = iscsi_get_fabric_proto_ident, .tpg_get_wwn = lio_tpg_get_endpoint_wwn, .tpg_get_tag = lio_tpg_get_tag, .tpg_get_default_depth = lio_tpg_get_default_depth, - .tpg_get_pr_transport_id = iscsi_get_pr_transport_id, - .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len, - .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id, .tpg_check_demo_mode = lio_tpg_check_demo_mode, .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, .tpg_check_demo_mode_write_protect = @@ -1996,8 +1691,6 @@ const struct target_core_fabric_ops iscsi_ops = { .tpg_check_prod_mode_write_protect = lio_tpg_check_prod_mode_write_protect, .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, - .tpg_alloc_fabric_acl = lio_tpg_alloc_fabric_acl, - .tpg_release_fabric_acl = lio_tpg_release_fabric_acl, .tpg_get_inst_index = lio_tpg_get_inst_index, .check_stop_free = lio_check_stop_free, .release_cmd = lio_release_cmd, @@ -2008,7 +1701,6 @@ const struct target_core_fabric_ops iscsi_ops = { .write_pending = lio_write_pending, .write_pending_status = lio_write_pending_status, .set_default_node_attributes = lio_set_default_node_attributes, - .get_task_tag = iscsi_get_task_tag, .get_cmd_state = iscsi_get_cmd_state, .queue_data_in = lio_queue_data_in, .queue_status = lio_queue_status, @@ -2020,8 +1712,8 @@ const struct target_core_fabric_ops iscsi_ops = { .fabric_drop_tpg = lio_target_tiqn_deltpg, .fabric_make_np = lio_target_call_addnptotpg, .fabric_drop_np = lio_target_call_delnpfromtpg, - .fabric_make_nodeacl = lio_target_make_nodeacl, - .fabric_drop_nodeacl = lio_target_drop_nodeacl, + .fabric_init_nodeacl = lio_target_init_nodeacl, + .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl, .tfc_discovery_attrs = lio_target_discovery_auth_attrs, .tfc_wwn_attrs = lio_target_wwn_attrs, diff --git a/kernel/drivers/target/iscsi/iscsi_target_device.c b/kernel/drivers/target/iscsi/iscsi_target_device.c index 34c3cd1b0..0382fa24b 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_device.c +++ b/kernel/drivers/target/iscsi/iscsi_target_device.c @@ -17,7 +17,6 @@ * GNU General Public License for more details. ******************************************************************************/ -#include <scsi/scsi_device.h> #include <target/target_core_base.h> #include <target/target_core_fabric.h> @@ -48,19 +47,19 @@ void iscsit_determine_maxcmdsn(struct iscsi_session *sess) * core_set_queue_depth_for_node(). */ sess->cmdsn_window = se_nacl->queue_depth; - sess->max_cmd_sn = (sess->max_cmd_sn + se_nacl->queue_depth) - 1; + atomic_add(se_nacl->queue_depth - 1, &sess->max_cmd_sn); } void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess) { + u32 max_cmd_sn; + if (cmd->immediate_cmd || cmd->maxcmdsn_inc) return; cmd->maxcmdsn_inc = 1; - mutex_lock(&sess->cmdsn_mutex); - sess->max_cmd_sn += 1; - pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn); - mutex_unlock(&sess->cmdsn_mutex); + max_cmd_sn = atomic_inc_return(&sess->max_cmd_sn); + pr_debug("Updated MaxCmdSN to 0x%08x\n", max_cmd_sn); } EXPORT_SYMBOL(iscsit_increment_maxcmdsn); diff --git a/kernel/drivers/target/iscsi/iscsi_target_erl0.c b/kernel/drivers/target/iscsi/iscsi_target_erl0.c index 959a14c9d..210f6e483 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_erl0.c +++ b/kernel/drivers/target/iscsi/iscsi_target_erl0.c @@ -956,56 +956,3 @@ void iscsit_take_action_for_connection_exit(struct iscsi_conn *conn) iscsit_handle_connection_cleanup(conn); } - -/* - * This is the simple function that makes the magic of - * sync and steering happen in the follow paradoxical order: - * - * 0) Receive conn->of_marker (bytes left until next OFMarker) - * bytes into an offload buffer. When we pass the exact number - * of bytes in conn->of_marker, iscsit_dump_data_payload() and hence - * rx_data() will automatically receive the identical u32 marker - * values and store it in conn->of_marker_offset; - * 1) Now conn->of_marker_offset will contain the offset to the start - * of the next iSCSI PDU. Dump these remaining bytes into another - * offload buffer. - * 2) We are done! - * Next byte in the TCP stream will contain the next iSCSI PDU! - * Cool Huh?! - */ -int iscsit_recover_from_unknown_opcode(struct iscsi_conn *conn) -{ - /* - * Make sure the remaining bytes to next maker is a sane value. - */ - if (conn->of_marker > (conn->conn_ops->OFMarkInt * 4)) { - pr_err("Remaining bytes to OFMarker: %u exceeds" - " OFMarkInt bytes: %u.\n", conn->of_marker, - conn->conn_ops->OFMarkInt * 4); - return -1; - } - - pr_debug("Advancing %u bytes in TCP stream to get to the" - " next OFMarker.\n", conn->of_marker); - - if (iscsit_dump_data_payload(conn, conn->of_marker, 0) < 0) - return -1; - - /* - * Make sure the offset marker we retrived is a valid value. - */ - if (conn->of_marker_offset > (ISCSI_HDR_LEN + (ISCSI_CRC_LEN * 2) + - conn->conn_ops->MaxRecvDataSegmentLength)) { - pr_err("OfMarker offset value: %u exceeds limit.\n", - conn->of_marker_offset); - return -1; - } - - pr_debug("Discarding %u bytes of TCP stream to get to the" - " next iSCSI Opcode.\n", conn->of_marker_offset); - - if (iscsit_dump_data_payload(conn, conn->of_marker_offset, 0) < 0) - return -1; - - return 0; -} diff --git a/kernel/drivers/target/iscsi/iscsi_target_erl0.h b/kernel/drivers/target/iscsi/iscsi_target_erl0.h index 21acc9a06..a9e2f9497 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_erl0.h +++ b/kernel/drivers/target/iscsi/iscsi_target_erl0.h @@ -10,6 +10,5 @@ extern void iscsit_connection_reinstatement_rcfr(struct iscsi_conn *); extern void iscsit_cause_connection_reinstatement(struct iscsi_conn *, int); extern void iscsit_fall_back_to_erl0(struct iscsi_session *); extern void iscsit_take_action_for_connection_exit(struct iscsi_conn *); -extern int iscsit_recover_from_unknown_opcode(struct iscsi_conn *); #endif /*** ISCSI_TARGET_ERL0_H ***/ diff --git a/kernel/drivers/target/iscsi/iscsi_target_login.c b/kernel/drivers/target/iscsi/iscsi_target_login.c index c3bccaddb..96e78c823 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_login.c +++ b/kernel/drivers/target/iscsi/iscsi_target_login.c @@ -331,7 +331,7 @@ static int iscsi_login_zero_tsih_s1( * The FFP CmdSN window values will be allocated from the TPG's * Initiator Node's ACL once the login has been successfully completed. */ - sess->max_cmd_sn = be32_to_cpu(pdu->cmdsn); + atomic_set(&sess->max_cmd_sn, be32_to_cpu(pdu->cmdsn)); sess->sess_ops = kzalloc(sizeof(struct iscsi_sess_ops), GFP_KERNEL); if (!sess->sess_ops) { @@ -411,8 +411,6 @@ static int iscsi_login_zero_tsih_s2( if (iscsi_change_param_sprintf(conn, "ErrorRecoveryLevel=%d", na->default_erl)) return -1; - if (iscsi_login_disable_FIM_keys(conn->param_list, conn) < 0) - return -1; /* * Set RDMAExtensions=Yes by default for iSER enabled network portals */ @@ -478,59 +476,6 @@ check_prot: return 0; } -/* - * Remove PSTATE_NEGOTIATE for the four FIM related keys. - * The Initiator node will be able to enable FIM by proposing them itself. - */ -int iscsi_login_disable_FIM_keys( - struct iscsi_param_list *param_list, - struct iscsi_conn *conn) -{ - struct iscsi_param *param; - - param = iscsi_find_param_from_key("OFMarker", param_list); - if (!param) { - pr_err("iscsi_find_param_from_key() for" - " OFMarker failed\n"); - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, - ISCSI_LOGIN_STATUS_NO_RESOURCES); - return -1; - } - param->state &= ~PSTATE_NEGOTIATE; - - param = iscsi_find_param_from_key("OFMarkInt", param_list); - if (!param) { - pr_err("iscsi_find_param_from_key() for" - " IFMarker failed\n"); - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, - ISCSI_LOGIN_STATUS_NO_RESOURCES); - return -1; - } - param->state &= ~PSTATE_NEGOTIATE; - - param = iscsi_find_param_from_key("IFMarker", param_list); - if (!param) { - pr_err("iscsi_find_param_from_key() for" - " IFMarker failed\n"); - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, - ISCSI_LOGIN_STATUS_NO_RESOURCES); - return -1; - } - param->state &= ~PSTATE_NEGOTIATE; - - param = iscsi_find_param_from_key("IFMarkInt", param_list); - if (!param) { - pr_err("iscsi_find_param_from_key() for" - " IFMarker failed\n"); - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, - ISCSI_LOGIN_STATUS_NO_RESOURCES); - return -1; - } - param->state &= ~PSTATE_NEGOTIATE; - - return 0; -} - static int iscsi_login_non_zero_tsih_s1( struct iscsi_conn *conn, unsigned char *buf) @@ -617,7 +562,7 @@ static int iscsi_login_non_zero_tsih_s2( if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt)) return -1; - return iscsi_login_disable_FIM_keys(conn->param_list, conn); + return 0; } int iscsi_login_post_auth_non_zero_tsih( @@ -766,7 +711,6 @@ void iscsi_post_login_handler( conn->conn_state = TARG_CONN_STATE_LOGGED_IN; iscsi_set_connection_parameters(conn->conn_ops, conn->param_list); - iscsit_set_sync_and_steering_values(conn); /* * SCSI Initiator -> SCSI Target Port Mapping */ @@ -785,9 +729,9 @@ void iscsi_post_login_handler( stop_timer = 1; } - pr_debug("iSCSI Login successful on CID: %hu from %s to" - " %s:%hu,%hu\n", conn->cid, conn->login_ip, - conn->local_ip, conn->local_port, tpg->tpgt); + pr_debug("iSCSI Login successful on CID: %hu from %pISpc to" + " %pISpc,%hu\n", conn->cid, &conn->login_sockaddr, + &conn->local_sockaddr, tpg->tpgt); list_add_tail(&conn->conn_list, &sess->sess_conn_list); atomic_inc(&sess->nconn); @@ -832,8 +776,8 @@ void iscsi_post_login_handler( pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n"); sess->session_state = TARG_SESS_STATE_LOGGED_IN; - pr_debug("iSCSI Login successful on CID: %hu from %s to %s:%hu,%hu\n", - conn->cid, conn->login_ip, conn->local_ip, conn->local_port, + pr_debug("iSCSI Login successful on CID: %hu from %pISpc to %pISpc,%hu\n", + conn->cid, &conn->login_sockaddr, &conn->local_sockaddr, tpg->tpgt); spin_lock_bh(&sess->conn_lock); @@ -879,8 +823,8 @@ static void iscsi_handle_login_thread_timeout(unsigned long data) struct iscsi_np *np = (struct iscsi_np *) data; spin_lock_bh(&np->np_thread_lock); - pr_err("iSCSI Login timeout on Network Portal %s:%hu\n", - np->np_ip, np->np_port); + pr_err("iSCSI Login timeout on Network Portal %pISpc\n", + &np->np_sockaddr); if (np->np_login_timer_flags & ISCSI_TF_STOP) { spin_unlock_bh(&np->np_thread_lock); @@ -933,7 +877,7 @@ static void iscsi_stop_login_thread_timer(struct iscsi_np *np) int iscsit_setup_np( struct iscsi_np *np, - struct __kernel_sockaddr_storage *sockaddr) + struct sockaddr_storage *sockaddr) { struct socket *sock = NULL; int backlog = ISCSIT_TCP_BACKLOG, ret, opt = 0, len; @@ -972,7 +916,7 @@ int iscsit_setup_np( * in iscsi_target_configfs.c code.. */ memcpy(&np->np_sockaddr, sockaddr, - sizeof(struct __kernel_sockaddr_storage)); + sizeof(struct sockaddr_storage)); if (sockaddr->ss_family == AF_INET6) len = sizeof(struct sockaddr_in6); @@ -1031,7 +975,7 @@ fail: int iscsi_target_setup_login_socket( struct iscsi_np *np, - struct __kernel_sockaddr_storage *sockaddr) + struct sockaddr_storage *sockaddr) { struct iscsit_transport *t; int rc; @@ -1071,44 +1015,42 @@ int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn) rc = conn->sock->ops->getname(conn->sock, (struct sockaddr *)&sock_in6, &err, 1); if (!rc) { - if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) - snprintf(conn->login_ip, sizeof(conn->login_ip), "[%pI6c]", - &sock_in6.sin6_addr.in6_u); - else - snprintf(conn->login_ip, sizeof(conn->login_ip), "%pI4", - &sock_in6.sin6_addr.s6_addr32[3]); - conn->login_port = ntohs(sock_in6.sin6_port); + if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) { + memcpy(&conn->login_sockaddr, &sock_in6, sizeof(sock_in6)); + } else { + /* Pretend to be an ipv4 socket */ + sock_in.sin_family = AF_INET; + sock_in.sin_port = sock_in6.sin6_port; + memcpy(&sock_in.sin_addr, &sock_in6.sin6_addr.s6_addr32[3], 4); + memcpy(&conn->login_sockaddr, &sock_in, sizeof(sock_in)); + } } rc = conn->sock->ops->getname(conn->sock, (struct sockaddr *)&sock_in6, &err, 0); if (!rc) { - if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) - snprintf(conn->local_ip, sizeof(conn->local_ip), "[%pI6c]", - &sock_in6.sin6_addr.in6_u); - else - snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI4", - &sock_in6.sin6_addr.s6_addr32[3]); - conn->local_port = ntohs(sock_in6.sin6_port); + if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) { + memcpy(&conn->local_sockaddr, &sock_in6, sizeof(sock_in6)); + } else { + /* Pretend to be an ipv4 socket */ + sock_in.sin_family = AF_INET; + sock_in.sin_port = sock_in6.sin6_port; + memcpy(&sock_in.sin_addr, &sock_in6.sin6_addr.s6_addr32[3], 4); + memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in)); + } } } else { memset(&sock_in, 0, sizeof(struct sockaddr_in)); rc = conn->sock->ops->getname(conn->sock, (struct sockaddr *)&sock_in, &err, 1); - if (!rc) { - sprintf(conn->login_ip, "%pI4", - &sock_in.sin_addr.s_addr); - conn->login_port = ntohs(sock_in.sin_port); - } + if (!rc) + memcpy(&conn->login_sockaddr, &sock_in, sizeof(sock_in)); rc = conn->sock->ops->getname(conn->sock, (struct sockaddr *)&sock_in, &err, 0); - if (!rc) { - sprintf(conn->local_ip, "%pI4", - &sock_in.sin_addr.s_addr); - conn->local_port = ntohs(sock_in.sin_port); - } + if (!rc) + memcpy(&conn->local_sockaddr, &sock_in, sizeof(sock_in)); } return 0; @@ -1358,8 +1300,8 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) spin_lock_bh(&np->np_thread_lock); if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) { spin_unlock_bh(&np->np_thread_lock); - pr_err("iSCSI Network Portal on %s:%hu currently not" - " active.\n", np->np_ip, np->np_port); + pr_err("iSCSI Network Portal on %pISpc currently not" + " active.\n", &np->np_sockaddr); iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); goto new_sess_out; @@ -1368,9 +1310,9 @@ static int __iscsi_target_login_thread(struct iscsi_np *np) conn->network_transport = np->np_network_transport; - pr_debug("Received iSCSI login request from %s on %s Network" - " Portal %s:%hu\n", conn->login_ip, np->np_transport->name, - conn->local_ip, conn->local_port); + pr_debug("Received iSCSI login request from %pISpc on %s Network" + " Portal %pISpc\n", &conn->login_sockaddr, np->np_transport->name, + &conn->local_sockaddr); pr_debug("Moving to TARG_CONN_STATE_IN_LOGIN.\n"); conn->conn_state = TARG_CONN_STATE_IN_LOGIN; diff --git a/kernel/drivers/target/iscsi/iscsi_target_login.h b/kernel/drivers/target/iscsi/iscsi_target_login.h index 55cbf4533..b597aa2c6 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_login.h +++ b/kernel/drivers/target/iscsi/iscsi_target_login.h @@ -5,9 +5,9 @@ extern int iscsi_login_setup_crypto(struct iscsi_conn *); extern int iscsi_check_for_session_reinstatement(struct iscsi_conn *); extern int iscsi_login_post_auth_non_zero_tsih(struct iscsi_conn *, u16, u32); extern int iscsit_setup_np(struct iscsi_np *, - struct __kernel_sockaddr_storage *); + struct sockaddr_storage *); extern int iscsi_target_setup_login_socket(struct iscsi_np *, - struct __kernel_sockaddr_storage *); + struct sockaddr_storage *); extern int iscsit_accept_np(struct iscsi_np *, struct iscsi_conn *); extern int iscsit_get_login_rx(struct iscsi_conn *, struct iscsi_login *); extern int iscsit_put_login_tx(struct iscsi_conn *, struct iscsi_login *, u32); @@ -17,6 +17,5 @@ extern void iscsi_post_login_handler(struct iscsi_np *, struct iscsi_conn *, u8) extern void iscsi_target_login_sess_out(struct iscsi_conn *, struct iscsi_np *, bool, bool); extern int iscsi_target_login_thread(void *); -extern int iscsi_login_disable_FIM_keys(struct iscsi_param_list *, struct iscsi_conn *); #endif /*** ISCSI_TARGET_LOGIN_H ***/ diff --git a/kernel/drivers/target/iscsi/iscsi_target_nego.c b/kernel/drivers/target/iscsi/iscsi_target_nego.c index f9cde9141..9fc9117d0 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_nego.c +++ b/kernel/drivers/target/iscsi/iscsi_target_nego.c @@ -341,7 +341,6 @@ static int iscsi_target_check_first_request( static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_login *login) { u32 padding = 0; - struct iscsi_session *sess = conn->sess; struct iscsi_login_rsp *login_rsp; login_rsp = (struct iscsi_login_rsp *) login->rsp; @@ -353,7 +352,7 @@ static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_log login_rsp->itt = login->init_task_tag; login_rsp->statsn = cpu_to_be32(conn->stat_sn++); login_rsp->exp_cmdsn = cpu_to_be32(conn->sess->exp_cmd_sn); - login_rsp->max_cmdsn = cpu_to_be32(conn->sess->max_cmd_sn); + login_rsp->max_cmdsn = cpu_to_be32((u32) atomic_read(&conn->sess->max_cmd_sn)); pr_debug("Sending Login Response, Flags: 0x%02x, ITT: 0x%08x," " ExpCmdSN; 0x%08x, MaxCmdSN: 0x%08x, StatSN: 0x%08x, Length:" @@ -382,10 +381,6 @@ static int iscsi_target_do_tx_login_io(struct iscsi_conn *conn, struct iscsi_log goto err; login->rsp_length = 0; - mutex_lock(&sess->cmdsn_mutex); - login_rsp->exp_cmdsn = cpu_to_be32(sess->exp_cmd_sn); - login_rsp->max_cmdsn = cpu_to_be32(sess->max_cmd_sn); - mutex_unlock(&sess->cmdsn_mutex); return 0; @@ -393,6 +388,7 @@ err: if (login->login_complete) { if (conn->rx_thread && conn->rx_thread_active) { send_sig(SIGINT, conn->rx_thread, 1); + complete(&conn->rx_login_comp); kthread_stop(conn->rx_thread); } if (conn->tx_thread && conn->tx_thread_active) { diff --git a/kernel/drivers/target/iscsi/iscsi_target_parameters.c b/kernel/drivers/target/iscsi/iscsi_target_parameters.c index d4f9e9645..2cbea2af7 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_parameters.c +++ b/kernel/drivers/target/iscsi/iscsi_target_parameters.c @@ -34,13 +34,6 @@ int iscsi_login_rx_data( iov.iov_len = length; iov.iov_base = buf; - /* - * Initial Marker-less Interval. - * Add the values regardless of IFMarker/OFMarker, considering - * it may not be negoitated yet. - */ - conn->of_marker += length; - rx_got = rx_data(conn, &iov, 1, length); if (rx_got != length) { pr_err("rx_data returned %d, expecting %d.\n", @@ -72,13 +65,6 @@ int iscsi_login_tx_data( iov_cnt++; } - /* - * Initial Marker-less Interval. - * Add the values regardless of IFMarker/OFMarker, considering - * it may not be negoitated yet. - */ - conn->if_marker += length; - tx_sent = tx_data(conn, &iov[0], iov_cnt, length); if (tx_sent != length) { pr_err("tx_data returned %d, expecting %d.\n", @@ -97,12 +83,6 @@ void iscsi_dump_conn_ops(struct iscsi_conn_ops *conn_ops) "CRC32C" : "None"); pr_debug("MaxRecvDataSegmentLength: %u\n", conn_ops->MaxRecvDataSegmentLength); - pr_debug("OFMarker: %s\n", (conn_ops->OFMarker) ? "Yes" : "No"); - pr_debug("IFMarker: %s\n", (conn_ops->IFMarker) ? "Yes" : "No"); - if (conn_ops->OFMarker) - pr_debug("OFMarkInt: %u\n", conn_ops->OFMarkInt); - if (conn_ops->IFMarker) - pr_debug("IFMarkInt: %u\n", conn_ops->IFMarkInt); } void iscsi_dump_sess_ops(struct iscsi_sess_ops *sess_ops) @@ -194,10 +174,6 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para case TYPERANGE_DIGEST: param->type = TYPE_VALUE_LIST | TYPE_STRING; break; - case TYPERANGE_MARKINT: - param->type = TYPE_NUMBER_RANGE; - param->type_range |= TYPERANGE_1_TO_65535; - break; case TYPERANGE_ISCSINAME: case TYPERANGE_SESSIONTYPE: case TYPERANGE_TARGETADDRESS: @@ -232,7 +208,7 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr) if (!pl) { pr_err("Unable to allocate memory for" " struct iscsi_param_list.\n"); - return -1 ; + return -ENOMEM; } INIT_LIST_HEAD(&pl->param_list); INIT_LIST_HEAD(&pl->extra_response_list); @@ -422,15 +398,16 @@ int iscsi_create_default_params(struct iscsi_param_list **param_list_ptr) param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT, PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH, - TYPERANGE_MARKINT, USE_INITIAL_ONLY); + TYPERANGE_UTF8, USE_INITIAL_ONLY); if (!param) goto out; param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT, PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH, - TYPERANGE_MARKINT, USE_INITIAL_ONLY); + TYPERANGE_UTF8, USE_INITIAL_ONLY); if (!param) goto out; + /* * Extra parameters for ISER from RFC-5046 */ @@ -520,13 +497,13 @@ int iscsi_set_keys_to_negotiate( } else if (!strcmp(param->name, SESSIONTYPE)) { SET_PSTATE_NEGOTIATE(param); } else if (!strcmp(param->name, IFMARKER)) { - SET_PSTATE_NEGOTIATE(param); + SET_PSTATE_REJECT(param); } else if (!strcmp(param->name, OFMARKER)) { - SET_PSTATE_NEGOTIATE(param); + SET_PSTATE_REJECT(param); } else if (!strcmp(param->name, IFMARKINT)) { - SET_PSTATE_NEGOTIATE(param); + SET_PSTATE_REJECT(param); } else if (!strcmp(param->name, OFMARKINT)) { - SET_PSTATE_NEGOTIATE(param); + SET_PSTATE_REJECT(param); } else if (!strcmp(param->name, RDMAEXTENSIONS)) { if (iser) SET_PSTATE_NEGOTIATE(param); @@ -601,7 +578,7 @@ int iscsi_copy_param_list( param_list = kzalloc(sizeof(struct iscsi_param_list), GFP_KERNEL); if (!param_list) { pr_err("Unable to allocate memory for struct iscsi_param_list.\n"); - return -1; + return -ENOMEM; } INIT_LIST_HEAD(¶m_list->param_list); INIT_LIST_HEAD(¶m_list->extra_response_list); @@ -652,7 +629,7 @@ int iscsi_copy_param_list( err_out: iscsi_release_param_list(param_list); - return -1; + return -ENOMEM; } static void iscsi_release_extra_responses(struct iscsi_param_list *param_list) @@ -752,7 +729,7 @@ static int iscsi_add_notunderstood_response( if (!extra_response) { pr_err("Unable to allocate memory for" " struct iscsi_extra_response.\n"); - return -1; + return -ENOMEM; } INIT_LIST_HEAD(&extra_response->er_list); @@ -906,91 +883,6 @@ static int iscsi_check_numerical_value(struct iscsi_param *param, char *value_pt return 0; } -static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value) -{ - char *left_val_ptr = NULL, *right_val_ptr = NULL; - char *tilde_ptr = NULL; - u32 left_val, right_val, local_left_val; - - if (strcmp(param->name, IFMARKINT) && - strcmp(param->name, OFMARKINT)) { - pr_err("Only parameters \"%s\" or \"%s\" may contain a" - " numerical range value.\n", IFMARKINT, OFMARKINT); - return -1; - } - - if (IS_PSTATE_PROPOSER(param)) - return 0; - - tilde_ptr = strchr(value, '~'); - if (!tilde_ptr) { - pr_err("Unable to locate numerical range indicator" - " \"~\" for \"%s\".\n", param->name); - return -1; - } - *tilde_ptr = '\0'; - - left_val_ptr = value; - right_val_ptr = value + strlen(left_val_ptr) + 1; - - if (iscsi_check_numerical_value(param, left_val_ptr) < 0) - return -1; - if (iscsi_check_numerical_value(param, right_val_ptr) < 0) - return -1; - - left_val = simple_strtoul(left_val_ptr, NULL, 0); - right_val = simple_strtoul(right_val_ptr, NULL, 0); - *tilde_ptr = '~'; - - if (right_val < left_val) { - pr_err("Numerical range for parameter \"%s\" contains" - " a right value which is less than the left.\n", - param->name); - return -1; - } - - /* - * For now, enforce reasonable defaults for [I,O]FMarkInt. - */ - tilde_ptr = strchr(param->value, '~'); - if (!tilde_ptr) { - pr_err("Unable to locate numerical range indicator" - " \"~\" for \"%s\".\n", param->name); - return -1; - } - *tilde_ptr = '\0'; - - left_val_ptr = param->value; - right_val_ptr = param->value + strlen(left_val_ptr) + 1; - - local_left_val = simple_strtoul(left_val_ptr, NULL, 0); - *tilde_ptr = '~'; - - if (param->set_param) { - if ((left_val < local_left_val) || - (right_val < local_left_val)) { - pr_err("Passed value range \"%u~%u\" is below" - " minimum left value \"%u\" for key \"%s\"," - " rejecting.\n", left_val, right_val, - local_left_val, param->name); - return -1; - } - } else { - if ((left_val < local_left_val) && - (right_val < local_left_val)) { - pr_err("Received value range \"%u~%u\" is" - " below minimum left value \"%u\" for key" - " \"%s\", rejecting.\n", left_val, right_val, - local_left_val, param->name); - SET_PSTATE_REJECT(param); - if (iscsi_update_param_value(param, REJECT) < 0) - return -1; - } - } - - return 0; -} - static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value) { if (IS_PSTATE_PROPOSER(param)) @@ -1027,33 +919,6 @@ static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *val return 0; } -/* - * This function is used to pick a value range number, currently just - * returns the lesser of both right values. - */ -static char *iscsi_get_value_from_number_range( - struct iscsi_param *param, - char *value) -{ - char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL; - u32 acceptor_right_value, proposer_right_value; - - tilde_ptr1 = strchr(value, '~'); - if (!tilde_ptr1) - return NULL; - *tilde_ptr1++ = '\0'; - proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0); - - tilde_ptr2 = strchr(param->value, '~'); - if (!tilde_ptr2) - return NULL; - *tilde_ptr2++ = '\0'; - acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0); - - return (acceptor_right_value >= proposer_right_value) ? - tilde_ptr1 : tilde_ptr2; -} - static char *iscsi_check_valuelist_for_support( struct iscsi_param *param, char *value) @@ -1103,7 +968,7 @@ static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value, struct iscsi_conn *conn) { u8 acceptor_boolean_value = 0, proposer_boolean_value = 0; - char *negoitated_value = NULL; + char *negotiated_value = NULL; if (IS_PSTATE_ACCEPTOR(param)) { pr_err("Received key \"%s\" twice, protocol error.\n", @@ -1203,24 +1068,16 @@ static int iscsi_check_acceptor_state(struct iscsi_param *param, char *value, pr_debug("Updated %s to target MXDSL value: %s\n", param->name, param->value); } - - } else if (IS_TYPE_NUMBER_RANGE(param)) { - negoitated_value = iscsi_get_value_from_number_range( - param, value); - if (!negoitated_value) - return -1; - if (iscsi_update_param_value(param, negoitated_value) < 0) - return -1; } else if (IS_TYPE_VALUE_LIST(param)) { - negoitated_value = iscsi_check_valuelist_for_support( + negotiated_value = iscsi_check_valuelist_for_support( param, value); - if (!negoitated_value) { + if (!negotiated_value) { pr_err("Proposer's value list \"%s\" contains" " no valid values from Acceptor's value list" " \"%s\".\n", value, param->value); return -1; } - if (iscsi_update_param_value(param, negoitated_value) < 0) + if (iscsi_update_param_value(param, negotiated_value) < 0) return -1; } else if (IS_PHASE_DECLARATIVE(param)) { if (iscsi_update_param_value(param, value) < 0) @@ -1239,47 +1096,7 @@ static int iscsi_check_proposer_state(struct iscsi_param *param, char *value) return -1; } - if (IS_TYPE_NUMBER_RANGE(param)) { - u32 left_val = 0, right_val = 0, recieved_value = 0; - char *left_val_ptr = NULL, *right_val_ptr = NULL; - char *tilde_ptr = NULL; - - if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) { - if (iscsi_update_param_value(param, value) < 0) - return -1; - return 0; - } - - tilde_ptr = strchr(value, '~'); - if (tilde_ptr) { - pr_err("Illegal \"~\" in response for \"%s\".\n", - param->name); - return -1; - } - tilde_ptr = strchr(param->value, '~'); - if (!tilde_ptr) { - pr_err("Unable to locate numerical range" - " indicator \"~\" for \"%s\".\n", param->name); - return -1; - } - *tilde_ptr = '\0'; - - left_val_ptr = param->value; - right_val_ptr = param->value + strlen(left_val_ptr) + 1; - left_val = simple_strtoul(left_val_ptr, NULL, 0); - right_val = simple_strtoul(right_val_ptr, NULL, 0); - recieved_value = simple_strtoul(value, NULL, 0); - - *tilde_ptr = '~'; - - if ((recieved_value < left_val) || - (recieved_value > right_val)) { - pr_err("Illegal response \"%s=%u\", value must" - " be between %u and %u.\n", param->name, - recieved_value, left_val, right_val); - return -1; - } - } else if (IS_TYPE_VALUE_LIST(param)) { + if (IS_TYPE_VALUE_LIST(param)) { char *comma_ptr = NULL, *tmp_ptr = NULL; comma_ptr = strchr(value, ','); @@ -1361,9 +1178,6 @@ static int iscsi_check_value(struct iscsi_param *param, char *value) } else if (IS_TYPE_NUMBER(param)) { if (iscsi_check_numerical_value(param, value) < 0) return -1; - } else if (IS_TYPE_NUMBER_RANGE(param)) { - if (iscsi_check_numerical_range_value(param, value) < 0) - return -1; } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) { if (iscsi_check_string_or_list_value(param, value) < 0) return -1; @@ -1483,8 +1297,6 @@ static int iscsi_enforce_integrity_rules( char *tmpptr; u8 DataSequenceInOrder = 0; u8 ErrorRecoveryLevel = 0, SessionType = 0; - u8 IFMarker = 0, OFMarker = 0; - u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1; u32 FirstBurstLength = 0, MaxBurstLength = 0; struct iscsi_param *param = NULL; @@ -1503,28 +1315,12 @@ static int iscsi_enforce_integrity_rules( if (!strcmp(param->name, MAXBURSTLENGTH)) MaxBurstLength = simple_strtoul(param->value, &tmpptr, 0); - if (!strcmp(param->name, IFMARKER)) - if (!strcmp(param->value, YES)) - IFMarker = 1; - if (!strcmp(param->name, OFMARKER)) - if (!strcmp(param->value, YES)) - OFMarker = 1; - if (!strcmp(param->name, IFMARKINT)) - if (!strcmp(param->value, REJECT)) - IFMarkInt_Reject = 1; - if (!strcmp(param->name, OFMARKINT)) - if (!strcmp(param->value, REJECT)) - OFMarkInt_Reject = 1; } list_for_each_entry(param, ¶m_list->param_list, p_list) { if (!(param->phase & phase)) continue; - if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) && - (strcmp(param->name, IFMARKER) && - strcmp(param->name, OFMARKER) && - strcmp(param->name, IFMARKINT) && - strcmp(param->name, OFMARKINT)))) + if (!SessionType && !IS_PSTATE_ACCEPTOR(param)) continue; if (!strcmp(param->name, MAXOUTSTANDINGR2T) && DataSequenceInOrder && (ErrorRecoveryLevel > 0)) { @@ -1556,38 +1352,6 @@ static int iscsi_enforce_integrity_rules( param->name, param->value); } } - if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) { - if (iscsi_update_param_value(param, NO) < 0) - return -1; - IFMarker = 0; - pr_debug("Reset \"%s\" to \"%s\".\n", - param->name, param->value); - } - if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) { - if (iscsi_update_param_value(param, NO) < 0) - return -1; - OFMarker = 0; - pr_debug("Reset \"%s\" to \"%s\".\n", - param->name, param->value); - } - if (!strcmp(param->name, IFMARKINT) && !IFMarker) { - if (!strcmp(param->value, REJECT)) - continue; - param->state &= ~PSTATE_NEGOTIATE; - if (iscsi_update_param_value(param, IRRELEVANT) < 0) - return -1; - pr_debug("Reset \"%s\" to \"%s\".\n", - param->name, param->value); - } - if (!strcmp(param->name, OFMARKINT) && !OFMarker) { - if (!strcmp(param->value, REJECT)) - continue; - param->state &= ~PSTATE_NEGOTIATE; - if (iscsi_update_param_value(param, IRRELEVANT) < 0) - return -1; - pr_debug("Reset \"%s\" to \"%s\".\n", - param->name, param->value); - } } return 0; @@ -1606,7 +1370,7 @@ int iscsi_decode_text_input( tmpbuf = kzalloc(length + 1, GFP_KERNEL); if (!tmpbuf) { pr_err("Unable to allocate %u + 1 bytes for tmpbuf.\n", length); - return -1; + return -ENOMEM; } memcpy(tmpbuf, textbuf, length); @@ -1824,24 +1588,6 @@ void iscsi_set_connection_parameters( */ pr_debug("MaxRecvDataSegmentLength: %u\n", ops->MaxRecvDataSegmentLength); - } else if (!strcmp(param->name, OFMARKER)) { - ops->OFMarker = !strcmp(param->value, YES); - pr_debug("OFMarker: %s\n", - param->value); - } else if (!strcmp(param->name, IFMARKER)) { - ops->IFMarker = !strcmp(param->value, YES); - pr_debug("IFMarker: %s\n", - param->value); - } else if (!strcmp(param->name, OFMARKINT)) { - ops->OFMarkInt = - simple_strtoul(param->value, &tmpptr, 0); - pr_debug("OFMarkInt: %s\n", - param->value); - } else if (!strcmp(param->name, IFMARKINT)) { - ops->IFMarkInt = - simple_strtoul(param->value, &tmpptr, 0); - pr_debug("IFMarkInt: %s\n", - param->value); } else if (!strcmp(param->name, INITIATORRECVDATASEGMENTLENGTH)) { ops->InitiatorRecvDataSegmentLength = simple_strtoul(param->value, &tmpptr, 0); diff --git a/kernel/drivers/target/iscsi/iscsi_target_parameters.h b/kernel/drivers/target/iscsi/iscsi_target_parameters.h index a47046a75..a0751e3f0 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_parameters.h +++ b/kernel/drivers/target/iscsi/iscsi_target_parameters.h @@ -138,8 +138,8 @@ extern void iscsi_set_session_parameters(struct iscsi_sess_ops *, #define INITIAL_SESSIONTYPE NORMAL #define INITIAL_IFMARKER NO #define INITIAL_OFMARKER NO -#define INITIAL_IFMARKINT "2048~65535" -#define INITIAL_OFMARKINT "2048~65535" +#define INITIAL_IFMARKINT REJECT +#define INITIAL_OFMARKINT REJECT /* * Initial values for iSER parameters following RFC-5046 Section 6 @@ -239,10 +239,9 @@ extern void iscsi_set_session_parameters(struct iscsi_sess_ops *, #define TYPERANGE_AUTH 0x0200 #define TYPERANGE_DIGEST 0x0400 #define TYPERANGE_ISCSINAME 0x0800 -#define TYPERANGE_MARKINT 0x1000 -#define TYPERANGE_SESSIONTYPE 0x2000 -#define TYPERANGE_TARGETADDRESS 0x4000 -#define TYPERANGE_UTF8 0x8000 +#define TYPERANGE_SESSIONTYPE 0x1000 +#define TYPERANGE_TARGETADDRESS 0x2000 +#define TYPERANGE_UTF8 0x4000 #define IS_TYPERANGE_0_TO_2(p) ((p)->type_range & TYPERANGE_0_TO_2) #define IS_TYPERANGE_0_TO_3600(p) ((p)->type_range & TYPERANGE_0_TO_3600) diff --git a/kernel/drivers/target/iscsi/iscsi_target_stat.c b/kernel/drivers/target/iscsi/iscsi_target_stat.c index 5e1349a3b..411cb266a 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_stat.c +++ b/kernel/drivers/target/iscsi/iscsi_target_stat.c @@ -21,7 +21,6 @@ #include <linux/export.h> #include <scsi/iscsi_proto.h> #include <target/target_core_base.h> -#include <target/configfs_macros.h> #include <target/iscsi/iscsi_target_core.h> #include "iscsi_target_parameters.h" @@ -50,76 +49,56 @@ /* * Instance Attributes Table */ -CONFIGFS_EATTR_STRUCT(iscsi_stat_instance, iscsi_wwn_stat_grps); -#define ISCSI_STAT_INSTANCE_ATTR(_name, _mode) \ -static struct iscsi_stat_instance_attribute \ - iscsi_stat_instance_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_instance_show_attr_##_name, \ - iscsi_stat_instance_store_attr_##_name); - -#define ISCSI_STAT_INSTANCE_ATTR_RO(_name) \ -static struct iscsi_stat_instance_attribute \ - iscsi_stat_instance_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_instance_show_attr_##_name); - -static ssize_t iscsi_stat_instance_show_attr_inst( - struct iscsi_wwn_stat_grps *igrps, char *page) -{ - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); +static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item) +{ + struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_wwn_stat_grps, iscsi_instance_group); + return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps); +} - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); +static ssize_t iscsi_stat_instance_inst_show(struct config_item *item, + char *page) +{ + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_instance_tiqn(item)->tiqn_index); } -ISCSI_STAT_INSTANCE_ATTR_RO(inst); -static ssize_t iscsi_stat_instance_show_attr_min_ver( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION); } -ISCSI_STAT_INSTANCE_ATTR_RO(min_ver); -static ssize_t iscsi_stat_instance_show_attr_max_ver( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION); } -ISCSI_STAT_INSTANCE_ATTR_RO(max_ver); -static ssize_t iscsi_stat_instance_show_attr_portals( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_portals_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); - - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_num_tpg_nps); + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_instance_tiqn(item)->tiqn_num_tpg_nps); } -ISCSI_STAT_INSTANCE_ATTR_RO(portals); -static ssize_t iscsi_stat_instance_show_attr_nodes( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES); } -ISCSI_STAT_INSTANCE_ATTR_RO(nodes); -static ssize_t iscsi_stat_instance_show_attr_sessions( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); - - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_nsessions); + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_instance_tiqn(item)->tiqn_nsessions); } -ISCSI_STAT_INSTANCE_ATTR_RO(sessions); -static ssize_t iscsi_stat_instance_show_attr_fail_sess( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; u32 sess_err_count; @@ -131,88 +110,84 @@ static ssize_t iscsi_stat_instance_show_attr_fail_sess( return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count); } -ISCSI_STAT_INSTANCE_ATTR_RO(fail_sess); -static ssize_t iscsi_stat_instance_show_attr_fail_type( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; return snprintf(page, PAGE_SIZE, "%u\n", sess_err->last_sess_failure_type); } -ISCSI_STAT_INSTANCE_ATTR_RO(fail_type); -static ssize_t iscsi_stat_instance_show_attr_fail_rem_name( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; return snprintf(page, PAGE_SIZE, "%s\n", sess_err->last_sess_fail_rem_name[0] ? sess_err->last_sess_fail_rem_name : NONE); } -ISCSI_STAT_INSTANCE_ATTR_RO(fail_rem_name); -static ssize_t iscsi_stat_instance_show_attr_disc_time( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME); } -ISCSI_STAT_INSTANCE_ATTR_RO(disc_time); -static ssize_t iscsi_stat_instance_show_attr_description( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_description_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR); } -ISCSI_STAT_INSTANCE_ATTR_RO(description); -static ssize_t iscsi_stat_instance_show_attr_vendor( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n"); } -ISCSI_STAT_INSTANCE_ATTR_RO(vendor); -static ssize_t iscsi_stat_instance_show_attr_version( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_instance_version_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION); } -ISCSI_STAT_INSTANCE_ATTR_RO(version); -CONFIGFS_EATTR_OPS(iscsi_stat_instance, iscsi_wwn_stat_grps, - iscsi_instance_group); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, portals); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, description); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor); +CONFIGFS_ATTR_RO(iscsi_stat_instance_, version); static struct configfs_attribute *iscsi_stat_instance_attrs[] = { - &iscsi_stat_instance_inst.attr, - &iscsi_stat_instance_min_ver.attr, - &iscsi_stat_instance_max_ver.attr, - &iscsi_stat_instance_portals.attr, - &iscsi_stat_instance_nodes.attr, - &iscsi_stat_instance_sessions.attr, - &iscsi_stat_instance_fail_sess.attr, - &iscsi_stat_instance_fail_type.attr, - &iscsi_stat_instance_fail_rem_name.attr, - &iscsi_stat_instance_disc_time.attr, - &iscsi_stat_instance_description.attr, - &iscsi_stat_instance_vendor.attr, - &iscsi_stat_instance_version.attr, + &iscsi_stat_instance_attr_inst, + &iscsi_stat_instance_attr_min_ver, + &iscsi_stat_instance_attr_max_ver, + &iscsi_stat_instance_attr_portals, + &iscsi_stat_instance_attr_nodes, + &iscsi_stat_instance_attr_sessions, + &iscsi_stat_instance_attr_fail_sess, + &iscsi_stat_instance_attr_fail_type, + &iscsi_stat_instance_attr_fail_rem_name, + &iscsi_stat_instance_attr_disc_time, + &iscsi_stat_instance_attr_description, + &iscsi_stat_instance_attr_vendor, + &iscsi_stat_instance_attr_version, NULL, }; -static struct configfs_item_operations iscsi_stat_instance_item_ops = { - .show_attribute = iscsi_stat_instance_attr_show, - .store_attribute = iscsi_stat_instance_attr_store, -}; - struct config_item_type iscsi_stat_instance_cit = { - .ct_item_ops = &iscsi_stat_instance_item_ops, .ct_attrs = iscsi_stat_instance_attrs, .ct_owner = THIS_MODULE, }; @@ -220,81 +195,61 @@ struct config_item_type iscsi_stat_instance_cit = { /* * Instance Session Failure Stats Table */ -CONFIGFS_EATTR_STRUCT(iscsi_stat_sess_err, iscsi_wwn_stat_grps); -#define ISCSI_STAT_SESS_ERR_ATTR(_name, _mode) \ -static struct iscsi_stat_sess_err_attribute \ - iscsi_stat_sess_err_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_sess_err_show_attr_##_name, \ - iscsi_stat_sess_err_store_attr_##_name); - -#define ISCSI_STAT_SESS_ERR_ATTR_RO(_name) \ -static struct iscsi_stat_sess_err_attribute \ - iscsi_stat_sess_err_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_sess_err_show_attr_##_name); - -static ssize_t iscsi_stat_sess_err_show_attr_inst( - struct iscsi_wwn_stat_grps *igrps, char *page) -{ - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); +static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item) +{ + struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_wwn_stat_grps, iscsi_sess_err_group); + return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps); +} - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); +static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item, + char *page) +{ + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_sess_err_tiqn(item)->tiqn_index); } -ISCSI_STAT_SESS_ERR_ATTR_RO(inst); -static ssize_t iscsi_stat_sess_err_show_attr_digest_errors( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors); } -ISCSI_STAT_SESS_ERR_ATTR_RO(digest_errors); -static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors); } -ISCSI_STAT_SESS_ERR_ATTR_RO(cxn_errors); -static ssize_t iscsi_stat_sess_err_show_attr_format_errors( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item); struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors); } -ISCSI_STAT_SESS_ERR_ATTR_RO(format_errors); -CONFIGFS_EATTR_OPS(iscsi_stat_sess_err, iscsi_wwn_stat_grps, - iscsi_sess_err_group); +CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors); +CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors); +CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors); static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = { - &iscsi_stat_sess_err_inst.attr, - &iscsi_stat_sess_err_digest_errors.attr, - &iscsi_stat_sess_err_cxn_errors.attr, - &iscsi_stat_sess_err_format_errors.attr, + &iscsi_stat_sess_err_attr_inst, + &iscsi_stat_sess_err_attr_digest_errors, + &iscsi_stat_sess_err_attr_cxn_errors, + &iscsi_stat_sess_err_attr_format_errors, NULL, }; -static struct configfs_item_operations iscsi_stat_sess_err_item_ops = { - .show_attribute = iscsi_stat_sess_err_attr_show, - .store_attribute = iscsi_stat_sess_err_attr_store, -}; - struct config_item_type iscsi_stat_sess_err_cit = { - .ct_item_ops = &iscsi_stat_sess_err_item_ops, .ct_attrs = iscsi_stat_sess_err_attrs, .ct_owner = THIS_MODULE, }; @@ -302,42 +257,30 @@ struct config_item_type iscsi_stat_sess_err_cit = { /* * Target Attributes Table */ -CONFIGFS_EATTR_STRUCT(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps); -#define ISCSI_STAT_TGT_ATTR(_name, _mode) \ -static struct iscsi_stat_tgt_attr_attribute \ - iscsi_stat_tgt_attr_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_tgt-attr_show_attr_##_name, \ - iscsi_stat_tgt_attr_store_attr_##_name); - -#define ISCSI_STAT_TGT_ATTR_RO(_name) \ -static struct iscsi_stat_tgt_attr_attribute \ - iscsi_stat_tgt_attr_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_tgt_attr_show_attr_##_name); - -static ssize_t iscsi_stat_tgt_attr_show_attr_inst( - struct iscsi_wwn_stat_grps *igrps, char *page) -{ - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); +static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item) +{ + struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group); + return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps); +} - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); +static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item, + char *page) +{ + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_tgt_attr_tiqn(item)->tiqn_index); } -ISCSI_STAT_TGT_ATTR_RO(inst); -static ssize_t iscsi_stat_tgt_attr_show_attr_indx( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); } -ISCSI_STAT_TGT_ATTR_RO(indx); -static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; u32 fail_count; @@ -349,13 +292,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails( return snprintf(page, PAGE_SIZE, "%u\n", fail_count); } -ISCSI_STAT_TGT_ATTR_RO(login_fails); -static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; u32 last_fail_time; @@ -367,13 +308,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time( return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time); } -ISCSI_STAT_TGT_ATTR_RO(last_fail_time); -static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; u32 last_fail_type; @@ -383,13 +322,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type( return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type); } -ISCSI_STAT_TGT_ATTR_RO(last_fail_type); -static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; unsigned char buf[224]; @@ -400,13 +337,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name( return snprintf(page, PAGE_SIZE, "%s\n", buf); } -ISCSI_STAT_TGT_ATTR_RO(fail_intr_name); -static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; int ret; @@ -419,46 +354,43 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type( return ret; } -ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr_type); -static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; int ret; spin_lock(&lstat->lock); - ret = snprintf(page, PAGE_SIZE, "%s\n", lstat->last_intr_fail_ip_addr); + ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr); spin_unlock(&lstat->lock); return ret; } -ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr); -CONFIGFS_EATTR_OPS(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps, - iscsi_tgt_attr_group); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type); +CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr); static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = { - &iscsi_stat_tgt_attr_inst.attr, - &iscsi_stat_tgt_attr_indx.attr, - &iscsi_stat_tgt_attr_login_fails.attr, - &iscsi_stat_tgt_attr_last_fail_time.attr, - &iscsi_stat_tgt_attr_last_fail_type.attr, - &iscsi_stat_tgt_attr_fail_intr_name.attr, - &iscsi_stat_tgt_attr_fail_intr_addr_type.attr, - &iscsi_stat_tgt_attr_fail_intr_addr.attr, + &iscsi_stat_tgt_attr_attr_inst, + &iscsi_stat_tgt_attr_attr_indx, + &iscsi_stat_tgt_attr_attr_login_fails, + &iscsi_stat_tgt_attr_attr_last_fail_time, + &iscsi_stat_tgt_attr_attr_last_fail_type, + &iscsi_stat_tgt_attr_attr_fail_intr_name, + &iscsi_stat_tgt_attr_attr_fail_intr_addr_type, + &iscsi_stat_tgt_attr_attr_fail_intr_addr, NULL, }; -static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = { - .show_attribute = iscsi_stat_tgt_attr_attr_show, - .store_attribute = iscsi_stat_tgt_attr_attr_store, -}; - struct config_item_type iscsi_stat_tgt_attr_cit = { - .ct_item_ops = &iscsi_stat_tgt_attr_item_ops, .ct_attrs = iscsi_stat_tgt_attr_attrs, .ct_owner = THIS_MODULE, }; @@ -466,42 +398,29 @@ struct config_item_type iscsi_stat_tgt_attr_cit = { /* * Target Login Stats Table */ -CONFIGFS_EATTR_STRUCT(iscsi_stat_login, iscsi_wwn_stat_grps); -#define ISCSI_STAT_LOGIN(_name, _mode) \ -static struct iscsi_stat_login_attribute \ - iscsi_stat_login_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_login_show_attr_##_name, \ - iscsi_stat_login_store_attr_##_name); - -#define ISCSI_STAT_LOGIN_RO(_name) \ -static struct iscsi_stat_login_attribute \ - iscsi_stat_login_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_login_show_attr_##_name); - -static ssize_t iscsi_stat_login_show_attr_inst( - struct iscsi_wwn_stat_grps *igrps, char *page) -{ - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); +static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item) +{ + struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_wwn_stat_grps, iscsi_login_stats_group); + return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps); +} - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); +static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page) +{ + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_login_stat_tiqn(item)->tiqn_index); } -ISCSI_STAT_LOGIN_RO(inst); -static ssize_t iscsi_stat_login_show_attr_indx( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_indx_show(struct config_item *item, + char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); } -ISCSI_STAT_LOGIN_RO(indx); -static ssize_t iscsi_stat_login_show_attr_accepts( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_accepts_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -511,13 +430,11 @@ static ssize_t iscsi_stat_login_show_attr_accepts( return ret; } -ISCSI_STAT_LOGIN_RO(accepts); -static ssize_t iscsi_stat_login_show_attr_other_fails( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -527,13 +444,11 @@ static ssize_t iscsi_stat_login_show_attr_other_fails( return ret; } -ISCSI_STAT_LOGIN_RO(other_fails); -static ssize_t iscsi_stat_login_show_attr_redirects( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_redirects_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -543,13 +458,11 @@ static ssize_t iscsi_stat_login_show_attr_redirects( return ret; } -ISCSI_STAT_LOGIN_RO(redirects); -static ssize_t iscsi_stat_login_show_attr_authorize_fails( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -559,13 +472,11 @@ static ssize_t iscsi_stat_login_show_attr_authorize_fails( return ret; } -ISCSI_STAT_LOGIN_RO(authorize_fails); -static ssize_t iscsi_stat_login_show_attr_authenticate_fails( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_authenticate_fails_show( + struct config_item *item, char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -575,13 +486,11 @@ static ssize_t iscsi_stat_login_show_attr_authenticate_fails( return ret; } -ISCSI_STAT_LOGIN_RO(authenticate_fails); -static ssize_t iscsi_stat_login_show_attr_negotiate_fails( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item); struct iscsi_login_stats *lstat = &tiqn->login_stats; ssize_t ret; @@ -591,30 +500,29 @@ static ssize_t iscsi_stat_login_show_attr_negotiate_fails( return ret; } -ISCSI_STAT_LOGIN_RO(negotiate_fails); -CONFIGFS_EATTR_OPS(iscsi_stat_login, iscsi_wwn_stat_grps, - iscsi_login_stats_group); +CONFIGFS_ATTR_RO(iscsi_stat_login_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_login_, indx); +CONFIGFS_ATTR_RO(iscsi_stat_login_, accepts); +CONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails); +CONFIGFS_ATTR_RO(iscsi_stat_login_, redirects); +CONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails); +CONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails); +CONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails); static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = { - &iscsi_stat_login_inst.attr, - &iscsi_stat_login_indx.attr, - &iscsi_stat_login_accepts.attr, - &iscsi_stat_login_other_fails.attr, - &iscsi_stat_login_redirects.attr, - &iscsi_stat_login_authorize_fails.attr, - &iscsi_stat_login_authenticate_fails.attr, - &iscsi_stat_login_negotiate_fails.attr, + &iscsi_stat_login_attr_inst, + &iscsi_stat_login_attr_indx, + &iscsi_stat_login_attr_accepts, + &iscsi_stat_login_attr_other_fails, + &iscsi_stat_login_attr_redirects, + &iscsi_stat_login_attr_authorize_fails, + &iscsi_stat_login_attr_authenticate_fails, + &iscsi_stat_login_attr_negotiate_fails, NULL, }; -static struct configfs_item_operations iscsi_stat_login_stats_item_ops = { - .show_attribute = iscsi_stat_login_attr_show, - .store_attribute = iscsi_stat_login_attr_store, -}; - struct config_item_type iscsi_stat_login_cit = { - .ct_item_ops = &iscsi_stat_login_stats_item_ops, .ct_attrs = iscsi_stat_login_stats_attrs, .ct_owner = THIS_MODULE, }; @@ -622,78 +530,56 @@ struct config_item_type iscsi_stat_login_cit = { /* * Target Logout Stats Table */ - -CONFIGFS_EATTR_STRUCT(iscsi_stat_logout, iscsi_wwn_stat_grps); -#define ISCSI_STAT_LOGOUT(_name, _mode) \ -static struct iscsi_stat_logout_attribute \ - iscsi_stat_logout_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_logout_show_attr_##_name, \ - iscsi_stat_logout_store_attr_##_name); - -#define ISCSI_STAT_LOGOUT_RO(_name) \ -static struct iscsi_stat_logout_attribute \ - iscsi_stat_logout_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_logout_show_attr_##_name); - -static ssize_t iscsi_stat_logout_show_attr_inst( - struct iscsi_wwn_stat_grps *igrps, char *page) +static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_wwn_stat_grps, iscsi_logout_stats_group); + return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps); +} - return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); +static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page) +{ + return snprintf(page, PAGE_SIZE, "%u\n", + iscsi_logout_stat_tiqn(item)->tiqn_index); } -ISCSI_STAT_LOGOUT_RO(inst); -static ssize_t iscsi_stat_logout_show_attr_indx( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page) { return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); } -ISCSI_STAT_LOGOUT_RO(indx); -static ssize_t iscsi_stat_logout_show_attr_normal_logouts( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item); struct iscsi_logout_stats *lstats = &tiqn->logout_stats; return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts); } -ISCSI_STAT_LOGOUT_RO(normal_logouts); -static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts( - struct iscsi_wwn_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item, + char *page) { - struct iscsi_tiqn *tiqn = container_of(igrps, - struct iscsi_tiqn, tiqn_stat_grps); + struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item); struct iscsi_logout_stats *lstats = &tiqn->logout_stats; return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts); } -ISCSI_STAT_LOGOUT_RO(abnormal_logouts); -CONFIGFS_EATTR_OPS(iscsi_stat_logout, iscsi_wwn_stat_grps, - iscsi_logout_stats_group); +CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_logout_, indx); +CONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts); +CONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts); static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = { - &iscsi_stat_logout_inst.attr, - &iscsi_stat_logout_indx.attr, - &iscsi_stat_logout_normal_logouts.attr, - &iscsi_stat_logout_abnormal_logouts.attr, + &iscsi_stat_logout_attr_inst, + &iscsi_stat_logout_attr_indx, + &iscsi_stat_logout_attr_normal_logouts, + &iscsi_stat_logout_attr_abnormal_logouts, NULL, }; -static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = { - .show_attribute = iscsi_stat_logout_attr_show, - .store_attribute = iscsi_stat_logout_attr_store, -}; - struct config_item_type iscsi_stat_logout_cit = { - .ct_item_ops = &iscsi_stat_logout_stats_item_ops, .ct_attrs = iscsi_stat_logout_stats_attrs, .ct_owner = THIS_MODULE, }; @@ -701,39 +587,26 @@ struct config_item_type iscsi_stat_logout_cit = { /* * Session Stats Table */ +static struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item) +{ + struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item), + struct iscsi_node_stat_grps, iscsi_sess_stats_group); + return container_of(igrps, struct iscsi_node_acl, node_stat_grps); +} -CONFIGFS_EATTR_STRUCT(iscsi_stat_sess, iscsi_node_stat_grps); -#define ISCSI_STAT_SESS(_name, _mode) \ -static struct iscsi_stat_sess_attribute \ - iscsi_stat_sess_##_name = \ - __CONFIGFS_EATTR(_name, _mode, \ - iscsi_stat_sess_show_attr_##_name, \ - iscsi_stat_sess_store_attr_##_name); - -#define ISCSI_STAT_SESS_RO(_name) \ -static struct iscsi_stat_sess_attribute \ - iscsi_stat_sess_##_name = \ - __CONFIGFS_EATTR_RO(_name, \ - iscsi_stat_sess_show_attr_##_name); - -static ssize_t iscsi_stat_sess_show_attr_inst( - struct iscsi_node_stat_grps *igrps, char *page) -{ - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); +static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page) +{ + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn; struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); } -ISCSI_STAT_SESS_RO(inst); -static ssize_t iscsi_stat_sess_show_attr_node( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -751,13 +624,10 @@ static ssize_t iscsi_stat_sess_show_attr_node( return ret; } -ISCSI_STAT_SESS_RO(node); -static ssize_t iscsi_stat_sess_show_attr_indx( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -775,13 +645,11 @@ static ssize_t iscsi_stat_sess_show_attr_indx( return ret; } -ISCSI_STAT_SESS_RO(indx); -static ssize_t iscsi_stat_sess_show_attr_cmd_pdus( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item, + char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -799,13 +667,11 @@ static ssize_t iscsi_stat_sess_show_attr_cmd_pdus( return ret; } -ISCSI_STAT_SESS_RO(cmd_pdus); -static ssize_t iscsi_stat_sess_show_attr_rsp_pdus( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item, + char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -823,13 +689,11 @@ static ssize_t iscsi_stat_sess_show_attr_rsp_pdus( return ret; } -ISCSI_STAT_SESS_RO(rsp_pdus); -static ssize_t iscsi_stat_sess_show_attr_txdata_octs( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item, + char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -847,13 +711,11 @@ static ssize_t iscsi_stat_sess_show_attr_txdata_octs( return ret; } -ISCSI_STAT_SESS_RO(txdata_octs); -static ssize_t iscsi_stat_sess_show_attr_rxdata_octs( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item, + char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -871,13 +733,11 @@ static ssize_t iscsi_stat_sess_show_attr_rxdata_octs( return ret; } -ISCSI_STAT_SESS_RO(rxdata_octs); -static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item, + char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -895,13 +755,11 @@ static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors( return ret; } -ISCSI_STAT_SESS_RO(conn_digest_errors); -static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors( - struct iscsi_node_stat_grps *igrps, char *page) +static ssize_t iscsi_stat_sess_conn_timeout_errors_show( + struct config_item *item, char *page) { - struct iscsi_node_acl *acl = container_of(igrps, - struct iscsi_node_acl, node_stat_grps); + struct iscsi_node_acl *acl = iscsi_stat_nacl(item); struct se_node_acl *se_nacl = &acl->se_node_acl; struct iscsi_session *sess; struct se_session *se_sess; @@ -919,31 +777,31 @@ static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors( return ret; } -ISCSI_STAT_SESS_RO(conn_timeout_errors); -CONFIGFS_EATTR_OPS(iscsi_stat_sess, iscsi_node_stat_grps, - iscsi_sess_stats_group); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, inst); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, node); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, indx); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors); +CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors); static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = { - &iscsi_stat_sess_inst.attr, - &iscsi_stat_sess_node.attr, - &iscsi_stat_sess_indx.attr, - &iscsi_stat_sess_cmd_pdus.attr, - &iscsi_stat_sess_rsp_pdus.attr, - &iscsi_stat_sess_txdata_octs.attr, - &iscsi_stat_sess_rxdata_octs.attr, - &iscsi_stat_sess_conn_digest_errors.attr, - &iscsi_stat_sess_conn_timeout_errors.attr, + &iscsi_stat_sess_attr_inst, + &iscsi_stat_sess_attr_node, + &iscsi_stat_sess_attr_indx, + &iscsi_stat_sess_attr_cmd_pdus, + &iscsi_stat_sess_attr_rsp_pdus, + &iscsi_stat_sess_attr_txdata_octs, + &iscsi_stat_sess_attr_rxdata_octs, + &iscsi_stat_sess_attr_conn_digest_errors, + &iscsi_stat_sess_attr_conn_timeout_errors, NULL, }; -static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = { - .show_attribute = iscsi_stat_sess_attr_show, - .store_attribute = iscsi_stat_sess_attr_store, -}; - struct config_item_type iscsi_stat_sess_cit = { - .ct_item_ops = &iscsi_stat_sess_stats_item_ops, .ct_attrs = iscsi_stat_sess_stats_attrs, .ct_owner = THIS_MODULE, }; diff --git a/kernel/drivers/target/iscsi/iscsi_target_tmr.c b/kernel/drivers/target/iscsi/iscsi_target_tmr.c index b0224a77e..11320df93 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_tmr.c +++ b/kernel/drivers/target/iscsi/iscsi_target_tmr.c @@ -17,7 +17,7 @@ ******************************************************************************/ #include <asm/unaligned.h> -#include <scsi/scsi_device.h> +#include <scsi/scsi_proto.h> #include <scsi/iscsi_proto.h> #include <target/target_core_base.h> #include <target/target_core_fabric.h> @@ -50,7 +50,7 @@ u8 iscsit_tmr_abort_task( pr_err("Unable to locate RefTaskTag: 0x%08x on CID:" " %hu.\n", hdr->rtt, conn->cid); return (iscsi_sna_gte(be32_to_cpu(hdr->refcmdsn), conn->sess->exp_cmd_sn) && - iscsi_sna_lte(be32_to_cpu(hdr->refcmdsn), conn->sess->max_cmd_sn)) ? + iscsi_sna_lte(be32_to_cpu(hdr->refcmdsn), (u32) atomic_read(&conn->sess->max_cmd_sn))) ? ISCSI_TMF_RSP_COMPLETE : ISCSI_TMF_RSP_NO_TASK; } if (ref_cmd->cmd_sn != be32_to_cpu(hdr->refcmdsn)) { @@ -120,7 +120,7 @@ u8 iscsit_tmr_task_reassign( struct iscsi_tmr_req *tmr_req = cmd->tmr_req; struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; struct iscsi_tm *hdr = (struct iscsi_tm *) buf; - int ret, ref_lun; + u64 ret, ref_lun; pr_debug("Got TASK_REASSIGN TMR ITT: 0x%08x," " RefTaskTag: 0x%08x, ExpDataSN: 0x%08x, CID: %hu\n", @@ -164,7 +164,7 @@ u8 iscsit_tmr_task_reassign( ref_lun = scsilun_to_int(&hdr->lun); if (ref_lun != ref_cmd->se_cmd.orig_fe_lun) { pr_err("Unable to perform connection recovery for" - " differing ref_lun: %d ref_cmd orig_fe_lun: %u\n", + " differing ref_lun: %llu ref_cmd orig_fe_lun: %llu\n", ref_lun, ref_cmd->se_cmd.orig_fe_lun); return ISCSI_TMF_RSP_REJECTED; } diff --git a/kernel/drivers/target/iscsi/iscsi_target_tpg.c b/kernel/drivers/target/iscsi/iscsi_target_tpg.c index 5e3295fe4..23c95cd14 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_tpg.c +++ b/kernel/drivers/target/iscsi/iscsi_target_tpg.c @@ -18,7 +18,6 @@ #include <target/target_core_base.h> #include <target/target_core_fabric.h> -#include <target/target_core_configfs.h> #include <target/iscsi/iscsi_target_core.h> #include "iscsi_target_erl0.h" @@ -67,9 +66,12 @@ int iscsit_load_discovery_tpg(void) pr_err("Unable to allocate struct iscsi_portal_group\n"); return -1; } - - ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg, - tpg, TRANSPORT_TPG_TYPE_DISCOVERY); + /* + * Save iscsi_ops pointer for special case discovery TPG that + * doesn't exist as se_wwn->wwn_group within configfs. + */ + tpg->tpg_se_tpg.se_tpg_tfo = &iscsi_ops; + ret = core_tpg_register(NULL, &tpg->tpg_se_tpg, -1); if (ret < 0) { kfree(tpg); return -1; @@ -224,6 +226,7 @@ static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg) a->default_erl = TA_DEFAULT_ERL; a->t10_pi = TA_DEFAULT_T10_PI; a->fabric_prot_type = TA_DEFAULT_FABRIC_PROT_TYPE; + a->tpg_enabled_sendtargets = TA_DEFAULT_TPG_ENABLED_SENDTARGETS; } int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg) @@ -280,8 +283,6 @@ int iscsit_tpg_del_portal_group( return -EPERM; } - core_tpg_clear_object_luns(&tpg->tpg_se_tpg); - if (tpg->param_list) { iscsi_release_param_list(tpg->param_list); tpg->param_list = NULL; @@ -430,7 +431,7 @@ struct iscsi_tpg_np *iscsit_tpg_locate_child_np( static bool iscsit_tpg_check_network_portal( struct iscsi_tiqn *tiqn, - struct __kernel_sockaddr_storage *sockaddr, + struct sockaddr_storage *sockaddr, int network_transport) { struct iscsi_portal_group *tpg; @@ -459,8 +460,7 @@ static bool iscsit_tpg_check_network_portal( struct iscsi_tpg_np *iscsit_tpg_add_network_portal( struct iscsi_portal_group *tpg, - struct __kernel_sockaddr_storage *sockaddr, - char *ip_str, + struct sockaddr_storage *sockaddr, struct iscsi_tpg_np *tpg_np_parent, int network_transport) { @@ -470,8 +470,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( if (!tpg_np_parent) { if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr, network_transport)) { - pr_err("Network Portal: %s already exists on a" - " different TPG on %s\n", ip_str, + pr_err("Network Portal: %pISc already exists on a" + " different TPG on %s\n", sockaddr, tpg->tpg_tiqn->tiqn); return ERR_PTR(-EEXIST); } @@ -484,7 +484,7 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( return ERR_PTR(-ENOMEM); } - np = iscsit_add_np(sockaddr, ip_str, network_transport); + np = iscsit_add_np(sockaddr, network_transport); if (IS_ERR(np)) { kfree(tpg_np); return ERR_CAST(np); @@ -514,8 +514,8 @@ struct iscsi_tpg_np *iscsit_tpg_add_network_portal( spin_unlock(&tpg_np_parent->tpg_np_parent_lock); } - pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n", - tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, + pr_debug("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n", + tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt, np->np_transport->name); return tpg_np; @@ -528,8 +528,8 @@ static int iscsit_tpg_release_np( { iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true); - pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n", - tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, + pr_debug("CORE[%s] - Removed Network Portal: %pISpc,%hu on %s\n", + tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt, np->np_transport->name); tpg_np->tpg_np = NULL; @@ -892,3 +892,21 @@ int iscsit_ta_fabric_prot_type( return 0; } + +int iscsit_ta_tpg_enabled_sendtargets( + struct iscsi_portal_group *tpg, + u32 flag) +{ + struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; + + if ((flag != 0) && (flag != 1)) { + pr_err("Illegal value %d\n", flag); + return -EINVAL; + } + + a->tpg_enabled_sendtargets = flag; + pr_debug("iSCSI_TPG[%hu] - TPG enabled bit required for SendTargets:" + " %s\n", tpg->tpgt, (a->tpg_enabled_sendtargets) ? "ON" : "OFF"); + + return 0; +} diff --git a/kernel/drivers/target/iscsi/iscsi_target_tpg.h b/kernel/drivers/target/iscsi/iscsi_target_tpg.h index 95ff5bdec..9db32bd24 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_tpg.h +++ b/kernel/drivers/target/iscsi/iscsi_target_tpg.h @@ -22,7 +22,7 @@ extern struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(struct iscsi_session extern void iscsit_tpg_del_external_nps(struct iscsi_tpg_np *); extern struct iscsi_tpg_np *iscsit_tpg_locate_child_np(struct iscsi_tpg_np *, int); extern struct iscsi_tpg_np *iscsit_tpg_add_network_portal(struct iscsi_portal_group *, - struct __kernel_sockaddr_storage *, char *, struct iscsi_tpg_np *, + struct sockaddr_storage *, struct iscsi_tpg_np *, int); extern int iscsit_tpg_del_network_portal(struct iscsi_portal_group *, struct iscsi_tpg_np *); @@ -40,5 +40,6 @@ extern int iscsit_ta_demo_mode_discovery(struct iscsi_portal_group *, u32); extern int iscsit_ta_default_erl(struct iscsi_portal_group *, u32); extern int iscsit_ta_t10_pi(struct iscsi_portal_group *, u32); extern int iscsit_ta_fabric_prot_type(struct iscsi_portal_group *, u32); +extern int iscsit_ta_tpg_enabled_sendtargets(struct iscsi_portal_group *, u32); #endif /* ISCSI_TARGET_TPG_H */ diff --git a/kernel/drivers/target/iscsi/iscsi_target_util.c b/kernel/drivers/target/iscsi/iscsi_target_util.c index b18edda3e..428b0d9e3 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_util.c +++ b/kernel/drivers/target/iscsi/iscsi_target_util.c @@ -22,7 +22,6 @@ #include <scsi/iscsi_proto.h> #include <target/target_core_base.h> #include <target/target_core_fabric.h> -#include <target/target_core_configfs.h> #include <target/iscsi/iscsi_transport.h> #include <target/iscsi/iscsi_target_core.h> @@ -234,6 +233,7 @@ struct iscsi_r2t *iscsit_get_holder_for_r2tsn( static inline int iscsit_check_received_cmdsn(struct iscsi_session *sess, u32 cmdsn) { + u32 max_cmdsn; int ret; /* @@ -242,10 +242,10 @@ static inline int iscsit_check_received_cmdsn(struct iscsi_session *sess, u32 cm * or order CmdSNs due to multiple connection sessions and/or * CRC failures. */ - if (iscsi_sna_gt(cmdsn, sess->max_cmd_sn)) { + max_cmdsn = atomic_read(&sess->max_cmd_sn); + if (iscsi_sna_gt(cmdsn, max_cmdsn)) { pr_err("Received CmdSN: 0x%08x is greater than" - " MaxCmdSN: 0x%08x, ignoring.\n", cmdsn, - sess->max_cmd_sn); + " MaxCmdSN: 0x%08x, ignoring.\n", cmdsn, max_cmdsn); ret = CMDSN_MAXCMDSN_OVERRUN; } else if (cmdsn == sess->exp_cmd_sn) { @@ -746,7 +746,7 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) rc = transport_generic_free_cmd(&cmd->se_cmd, shutdown); if (!rc && shutdown && se_cmd && se_cmd->se_sess) { __iscsit_free_cmd(cmd, true, shutdown); - target_put_sess_cmd(se_cmd->se_sess, se_cmd); + target_put_sess_cmd(se_cmd); } break; case ISCSI_OP_REJECT: @@ -762,7 +762,7 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) rc = transport_generic_free_cmd(&cmd->se_cmd, shutdown); if (!rc && shutdown && se_cmd->se_sess) { __iscsit_free_cmd(cmd, true, shutdown); - target_put_sess_cmd(se_cmd->se_sess, se_cmd); + target_put_sess_cmd(se_cmd); } break; } @@ -809,54 +809,6 @@ void iscsit_inc_session_usage_count(struct iscsi_session *sess) spin_unlock_bh(&sess->session_usage_lock); } -/* - * Setup conn->if_marker and conn->of_marker values based upon - * the initial marker-less interval. (see iSCSI v19 A.2) - */ -int iscsit_set_sync_and_steering_values(struct iscsi_conn *conn) -{ - int login_ifmarker_count = 0, login_ofmarker_count = 0, next_marker = 0; - /* - * IFMarkInt and OFMarkInt are negotiated as 32-bit words. - */ - u32 IFMarkInt = (conn->conn_ops->IFMarkInt * 4); - u32 OFMarkInt = (conn->conn_ops->OFMarkInt * 4); - - if (conn->conn_ops->OFMarker) { - /* - * Account for the first Login Command received not - * via iscsi_recv_msg(). - */ - conn->of_marker += ISCSI_HDR_LEN; - if (conn->of_marker <= OFMarkInt) { - conn->of_marker = (OFMarkInt - conn->of_marker); - } else { - login_ofmarker_count = (conn->of_marker / OFMarkInt); - next_marker = (OFMarkInt * (login_ofmarker_count + 1)) + - (login_ofmarker_count * MARKER_SIZE); - conn->of_marker = (next_marker - conn->of_marker); - } - conn->of_marker_offset = 0; - pr_debug("Setting OFMarker value to %u based on Initial" - " Markerless Interval.\n", conn->of_marker); - } - - if (conn->conn_ops->IFMarker) { - if (conn->if_marker <= IFMarkInt) { - conn->if_marker = (IFMarkInt - conn->if_marker); - } else { - login_ifmarker_count = (conn->if_marker / IFMarkInt); - next_marker = (IFMarkInt * (login_ifmarker_count + 1)) + - (login_ifmarker_count * MARKER_SIZE); - conn->if_marker = (next_marker - conn->if_marker); - } - pr_debug("Setting IFMarker value to %u based on Initial" - " Markerless Interval.\n", conn->if_marker); - } - - return 0; -} - struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *sess, u16 cid) { struct iscsi_conn *conn; @@ -1420,6 +1372,33 @@ int tx_data( return iscsit_do_tx_data(conn, &c); } +static bool sockaddr_equal(struct sockaddr_storage *x, struct sockaddr_storage *y) +{ + switch (x->ss_family) { + case AF_INET: { + struct sockaddr_in *sinx = (struct sockaddr_in *)x; + struct sockaddr_in *siny = (struct sockaddr_in *)y; + if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) + return false; + if (sinx->sin_port != siny->sin_port) + return false; + break; + } + case AF_INET6: { + struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x; + struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y; + if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr)) + return false; + if (sinx->sin6_port != siny->sin6_port) + return false; + break; + } + default: + return false; + } + return true; +} + void iscsit_collect_login_stats( struct iscsi_conn *conn, u8 status_class, @@ -1436,7 +1415,7 @@ void iscsit_collect_login_stats( ls = &tiqn->login_stats; spin_lock(&ls->lock); - if (!strcmp(conn->login_ip, ls->last_intr_fail_ip_addr) && + if (sockaddr_equal(&conn->login_sockaddr, &ls->last_intr_fail_sockaddr) && ((get_jiffies_64() - ls->last_fail_time) < 10)) { /* We already have the failure info for this login */ spin_unlock(&ls->lock); @@ -1476,8 +1455,7 @@ void iscsit_collect_login_stats( ls->last_intr_fail_ip_family = conn->login_family; - snprintf(ls->last_intr_fail_ip_addr, IPV6_ADDRESS_SPACE, - "%s", conn->login_ip); + ls->last_intr_fail_sockaddr = conn->login_sockaddr; ls->last_fail_time = get_jiffies_64(); } diff --git a/kernel/drivers/target/iscsi/iscsi_target_util.h b/kernel/drivers/target/iscsi/iscsi_target_util.h index 1ab754a67..995f1cb29 100644 --- a/kernel/drivers/target/iscsi/iscsi_target_util.h +++ b/kernel/drivers/target/iscsi/iscsi_target_util.h @@ -34,7 +34,6 @@ extern void iscsit_free_cmd(struct iscsi_cmd *, bool); extern int iscsit_check_session_usage_count(struct iscsi_session *); extern void iscsit_dec_session_usage_count(struct iscsi_session *); extern void iscsit_inc_session_usage_count(struct iscsi_session *); -extern int iscsit_set_sync_and_steering_values(struct iscsi_conn *); extern struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *, u16); extern struct iscsi_conn *iscsit_get_conn_from_cid_rcfr(struct iscsi_session *, u16); extern void iscsit_check_conn_usage_count(struct iscsi_conn *); |