fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI connection interfaces
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap#define ISCSI_ICS_NAMES
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#include <sys/bootprops.h>
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern ib_boot_prop_t *iscsiboot_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic void iscsi_client_notify_task(void *cn_task_void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic void iscsi_conn_flush_active_cmds(iscsi_conn_t *icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SHUTDOWN_TIMEOUT 180 /* seconds */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern int modrootloaded;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapboolean_t iscsi_conn_logging = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China#define ISCSI_LOGIN_TPGT_NEGO_ERROR(icp) \
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China (((icp)->conn_login_state == LOGIN_ERROR) && \
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China ((icp)->conn_login_status == ISCSI_STATUS_LOGIN_TPGT_NEGO_FAIL))
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | External Connection Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_create - This creates an iscsi connection structure and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associates it with a session structure. The session's sess_conn_list_rwlock
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * should be held as a writer before calling this function.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_create(struct sockaddr *addr, iscsi_sess_t *isp, iscsi_conn_t **icpp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char th_name[ISCSI_TH_MAX_NAME_LEN];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if this connection already exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (icp = isp->sess_conn_list; icp; icp = icp->conn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Compare the ioctl information to see if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * its a match for this connection. (This
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is done by making sure the IPs are of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the same size and then they are the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * same value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(&icp->conn_base_addr, addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SIZEOF_SOCKADDR(addr)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It's a match, record this connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If icp is found return it */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *icpp = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We are creating the connection, allocate, and setup */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = (iscsi_conn_t *)kmem_zalloc(sizeof (iscsi_conn_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Setup connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_sig = ISCSI_SIG_CONN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_state = ISCSI_CONN_STATE_FREE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&icp->conn_state_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&icp->conn_state_change, NULL, CV_DRIVER, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_init(&icp->conn_login_mutex, NULL, MUTEX_DRIVER, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_init(&icp->conn_login_cv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_state_destroy = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_init(&icp->conn_state_audit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_sess = isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&iscsi_oid_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_oid = iscsi_oid++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&iscsi_oid_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * IDM CN taskq
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (snprintf(th_name, sizeof (th_name) - 1,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_CN_TASKQ_NAME_FORMAT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_sess->sess_hba->hba_oid, icp->conn_sess->sess_oid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_oid) >= sizeof (th_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&icp->conn_state_change);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(icp, sizeof (iscsi_conn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *icpp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_cn_taskq =
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ddi_taskq_create(icp->conn_sess->sess_hba->hba_dip, th_name, 1,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap TASKQ_DEFAULTPRI, 0);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (icp->conn_cn_taskq == NULL) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_destroy(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_destroy(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap kmem_free(icp, sizeof (iscsi_conn_t));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap *icpp = NULL;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (ISCSI_STATUS_INTERNAL_ERROR);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Creation of the transfer thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (snprintf(th_name, sizeof (th_name) - 1, ISCSI_CONN_TXTH_NAME_FORMAT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_sess->sess_hba->hba_oid, icp->conn_sess->sess_oid,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_oid) >= sizeof (th_name)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&icp->conn_state_change);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(icp, sizeof (iscsi_conn_t));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ddi_taskq_destroy(icp->conn_cn_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *icpp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_tx_thread = iscsi_thread_create(isp->sess_hba->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte th_name, iscsi_tx_thread, icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup connection queues */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_init_queue(&icp->conn_queue_active);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_init_queue(&icp->conn_queue_idm_aborting);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(addr, &icp->conn_base_addr, sizeof (icp->conn_base_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Add new connection to the session connection list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_cid = isp->sess_conn_next_cid++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_conn_list == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list = isp->sess_conn_list_last_ptr = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list_last_ptr->conn_next = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list_last_ptr = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KSTAT_INC_SESS_CNTR_CONN(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_conn_kstat_init(icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *icpp = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap/*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iscsi_conn_online - This attempts to take a connection from
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * ISCSI_CONN_STATE_FREE to ISCSI_CONN_STATE_LOGGED_IN.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_status_t
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_conn_online(iscsi_conn_t *icp)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_task_t *itp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_status_t rval;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(icp != NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(mutex_owned(&icp->conn_state_mutex));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(icp->conn_state == ISCSI_CONN_STATE_FREE);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * If we are attempting to connect then for the purposes of the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * other initiator code we are effectively in ISCSI_CONN_STATE_IN_LOGIN.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state_locked(icp, ISCSI_CONN_STATE_IN_LOGIN);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Sync base connection information before login
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * A login redirection might have shifted the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * current information from the base.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&icp->conn_base_addr, &icp->conn_curr_addr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (icp->conn_curr_addr));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp = kmem_zalloc(sizeof (iscsi_task_t), KM_SLEEP);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(itp != NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp->t_arg = icp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp->t_blocking = B_TRUE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap rval = iscsi_login_start(itp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap kmem_free(itp, sizeof (iscsi_task_t));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (rval);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_offline - This attempts to take a connection from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any state to ISCSI_CONN_STATE_FREE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_offline(iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clock_t delay;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We can only destroy a connection if its either in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a state of FREE or LOGGED. The other states are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * transitionary and its unsafe to perform actions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the connection in those states. Set a flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * on the connection to influence the transitions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to quickly complete. Then wait for a state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * transition.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap *
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * ISCSI_CONN_STATE_LOGGED_IN is set immediately at the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * start of CN_NOTIFY_FFP processing. icp->conn_state_ffp
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * is set to true at the end of ffp processing, at which
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * point any session updates are complete. We don't
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * want to start offlining the connection before we're
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * done completing the FFP processing since this might
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * interrupt the discovery process.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay = ddi_get_lbolt() + SEC_TO_TICK(SHUTDOWN_TIMEOUT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_state_destroy = B_TRUE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap while ((((icp->conn_state != ISCSI_CONN_STATE_FREE) &&
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (icp->conn_state != ISCSI_CONN_STATE_LOGGED_IN)) ||
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ((icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) &&
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap !icp->conn_state_ffp)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ddi_get_lbolt() < delay)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for transition */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) cv_timedwait(&icp->conn_state_change,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &icp->conn_state_mutex, delay);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (icp->conn_state) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_FREE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_LOGGED_IN:
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States if (icp->conn_state_ffp) {
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Hold is released in iscsi_handle_logout */
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_conn_hold(icp->conn_ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void) iscsi_handle_logout(icp);
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_destroy = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (ISCSI_STATUS_INTERNAL_ERROR);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_IN_LOGIN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_IN_LOGOUT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_FAILED:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_CONN_STATE_POLLING:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_state_destroy = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_destroy - This destroys an iscsi connection structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and de-associates it with the session. The connection should
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * already been in the ISCSI_CONN_STATE_FREE when attempting this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_destroy(iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *t_icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = icp->conn_sess;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state != ISCSI_CONN_STATE_FREE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_INTERNAL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Destroy transfer thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_thread_destroy(icp->conn_tx_thread);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ddi_taskq_destroy(icp->conn_cn_taskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Terminate connection queues */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_destroy_queue(&icp->conn_queue_idm_aborting);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_destroy_queue(&icp->conn_queue_active);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_destroy(&icp->conn_login_cv);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_destroy(&icp->conn_login_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&icp->conn_state_change);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove connection from sessions linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_conn_list == icp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* connection first item in list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check if this is also the last item in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_conn_list_last_ptr == icp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list_last_ptr = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * search session list for icp pointing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to connection being removed. Then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update that connections next pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (t_icp->conn_next != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_icp->conn_next == icp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_icp = t_icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (t_icp->conn_next == icp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_icp->conn_next = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this is the last connection in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update the last_ptr to point to t_icp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_conn_list_last_ptr == icp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list_last_ptr = t_icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* couldn't find session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free this Connections Data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_kstat_term(icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(icp, sizeof (iscsi_conn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_set_login_min_max - set min/max login window
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Used to set the min and max login window. Input values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are in seconds.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_set_login_min_max(iscsi_conn_t *icp, int min, int max)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_login_min = ddi_get_lbolt() + SEC_TO_TICK(min);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_login_max = ddi_get_lbolt() + SEC_TO_TICK(max);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Process the idm notifications
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapidm_status_t
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_client_notify(idm_conn_t *ic, idm_client_notify_t icn, uintptr_t data)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_cn_task_t *cn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_t *icp = ic->ic_handle;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_sess_t *isp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Don't access icp if the notification is CN_CONNECT_DESTROY
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * since icp may have already been freed.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap *
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States * In particular, we cannot audit the CN_CONNECT_DESTROY event.
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States *
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States * Handle a few cases immediately, the rest in a task queue.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap switch (icn) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_CONNECT_FAIL:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_LOGIN_FAIL:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Wakeup any thread waiting for login stuff to happen.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(icp != NULL);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&icp->conn_state_mutex);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sm_audit_event(&icp->conn_state_audit,
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States SAS_ISCSI_CONN, icp->conn_state, icn, data);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_login_update_state(icp, LOGIN_ERROR);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (IDM_STATUS_SUCCESS);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_READY_FOR_LOGIN:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_hold(ic); /* Released in CN_CONNECT_LOST */
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(icp != NULL);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sm_audit_event(&icp->conn_state_audit,
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States SAS_ISCSI_CONN, icp->conn_state, icn, data);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_idm_connected = B_TRUE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_login_update_state(icp, LOGIN_READY);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (IDM_STATUS_SUCCESS);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_CONNECT_DESTROY:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * We released any dependecies we had on this object in
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * either CN_LOGIN_FAIL or CN_CONNECT_LOST so we just need
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * to destroy the IDM connection now.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_ini_conn_destroy(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (IDM_STATUS_SUCCESS);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&icp->conn_state_mutex);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sm_audit_event(&icp->conn_state_audit,
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States SAS_ISCSI_CONN, icp->conn_state, icn, data);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap isp = icp->conn_sess;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Dispatch notifications to the taskq since they often require
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * long blocking operations. In the case of CN_CONNECT_DESTROY
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * we actually just want to destroy the connection which we
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * can't do in the IDM taskq context.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cn = kmem_alloc(sizeof (*cn), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cn->ct_ic = ic;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cn->ct_icn = icn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cn->ct_data = data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_hold(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (ddi_taskq_dispatch(icp->conn_cn_taskq,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_client_notify_task, cn, DDI_SLEEP) != DDI_SUCCESS) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_rele(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "iscsi connection(%u) failure - "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "unable to schedule notify task", icp->conn_oid);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state(icp, ISCSI_CONN_STATE_FREE);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(&isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N6, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap return (IDM_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic void
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_client_notify_task(void *cn_task_void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_cn_task_t *cn_task = cn_task_void;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_t *icp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_sess_t *isp;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_t *ic;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_client_notify_t icn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap uintptr_t data;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_ffp_disable_t disable_type;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap boolean_t in_login;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ic = cn_task->ct_ic;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icn = cn_task->ct_icn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap data = cn_task->ct_data;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp = ic->ic_handle;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(icp != NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap isp = icp->conn_sess;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap switch (icn) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_FFP_ENABLED:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_async_logout = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_ffp = B_TRUE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This logic assumes that the IDM login-snooping code
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China * and the initiator login code will agree to go when
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China * the connection is in FFP or final error received.
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China * The reason we do this is that we don't want to process
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China * CN_FFP_DISABLED until CN_FFP_ENABLED has been full handled.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_login_mutex);
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China while ((icp->conn_login_state != LOGIN_FFP) &&
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China (icp->conn_login_state != LOGIN_ERROR)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_wait(&icp->conn_login_cv, &icp->conn_login_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_login_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_FFP_DISABLED:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap disable_type = (idm_ffp_disable_t)data;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap switch (disable_type) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case FD_SESS_LOGOUT:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case FD_CONN_LOGOUT:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (icp->conn_async_logout) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Our logout was in response to an
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * async logout request so treat this
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * like a connection failure (we will
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * try to re-establish the connection)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state_locked(icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_STATE_FAILED);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Logout due to to user config change,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * we will not try to re-establish
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * the connection.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state_locked(icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_STATE_IN_LOGOUT);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Hold off generating the ISCSI_SESS_EVENT_N3
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * event until we get the CN_CONNECT_LOST
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * notification. This matches the pre-IDM
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * implementation better.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case FD_CONN_FAIL:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap default:
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China if (icp->conn_state == ISCSI_CONN_STATE_IN_LOGIN) {
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China iscsi_conn_update_state_locked(icp,
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China ISCSI_CONN_STATE_FREE);
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China } else {
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China iscsi_conn_update_state_locked(icp,
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China ISCSI_CONN_STATE_FAILED);
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_ffp = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case CN_CONNECT_LOST:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * We only care about CN_CONNECT_LOST if we've logged in. IDM
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * sends a flag as the data payload to indicate whether we
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * were trying to login. The CN_LOGIN_FAIL notification
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * gives us what we need to know for login failures and
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * otherwise we will need to keep a bunch of state to know
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * what CN_CONNECT_LOST means to us.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap in_login = (boolean_t)data;
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China if (in_login ||
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China (icp->conn_prev_state == ISCSI_CONN_STATE_IN_LOGIN)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_idm_connected = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release connect hold from CN_READY_FOR_LOGIN */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_rele(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Any remaining commands are never going to finish */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_flush_active_cmds(icp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * The connection is no longer active so cleanup any
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * references to the connection and release any holds so
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * that IDM can finish cleanup.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (icp->conn_state != ISCSI_CONN_STATE_FAILED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&icp->conn_state_mutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_machine(isp, ISCSI_SESS_EVENT_N3,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state_locked(icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_STATE_FREE);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_exit(&icp->conn_state_mutex);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N5, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /*
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * If session type is NORMAL, try to reestablish the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * connection.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap */
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China if ((isp->sess_type == ISCSI_SESS_TYPE_NORMAL) &&
cc7ef4959916befd1d1197845b5b82284d96c450yi zhang - Sun Microsystems - Beijing China !(ISCSI_LOGIN_TPGT_NEGO_ERROR(icp))) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_retry(isp, icp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N6, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state_locked(icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_STATE_FREE);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void) iscsi_thread_stop(icp->conn_tx_thread);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state_idm_connected = B_FALSE;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release connect hold from CN_READY_FOR_LOGIN */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_rele(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_LOG(CE_WARN,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iscsi_client_notify: unknown notification: "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "%x: NOT IMPLEMENTED YET: icp: %p ic: %p ",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icn, (void *)icp, (void *)ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* free the task notify structure we allocated in iscsi_client_notify */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap kmem_free(cn_task, sizeof (*cn_task));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release the hold we acquired in iscsi_client_notify */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_rele(ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_sync_params - used to update connection parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Used to update connection parameters with current configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * parameters in the persistent store. This should be called
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before starting to make a new iscsi connection in iscsi_login.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_sync_params(iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_hba_t *ihp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int param_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t pp;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China persistent_tunable_param_t ptp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_config_sess_t *ics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int idx, size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((icp->conn_state == ISCSI_CONN_STATE_IN_LOGIN) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (icp->conn_state == ISCSI_CONN_STATE_FAILED) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (icp->conn_state == ISCSI_CONN_STATE_POLLING));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = icp->conn_sess;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp = isp->sess_hba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check if someone is trying to destroy this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * connection. If so fail the sync request,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as a method of fast fail.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state_destroy == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SHUTDOWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&pp, sizeof (pp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First get a copy of the HBA params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&ihp->hba_params, &icp->conn_params,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_login_params_t));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China bcopy(&ihp->hba_tunable_params, &icp->conn_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China sizeof (iscsi_tunable_params_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now we need to get the session configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * values from the persistent store and apply
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * them to our connection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_param_get((char *)isp->sess_name, &pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (param_id = 0; param_id < ISCSI_NUM_LOGIN_PARAM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte param_id++) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && modrootloaded &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng !iscsi_chk_bootlun_mpxio(ihp) && isp->sess_boot) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iscsi boot with mpxio disabled
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * while iscsi booting target's parameter overriden
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * do no update target's parameters.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (pp.p_bitmap) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "Adopting "
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " default login parameters in"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " boot session as MPxIO is disabled");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng break;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pp.p_bitmap & (1 << param_id)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap switch (param_id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Boolean parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.data_pdu_in_order =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.data_pdu_in_order;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_IMMEDIATE_DATA:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.immediate_data =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.immediate_data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_INITIAL_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.initial_r2t =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.initial_r2t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.data_pdu_in_order =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.data_pdu_in_order;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_HEADER_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.header_digest =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.header_digest;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.data_digest =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.data_digest;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.default_time_to_retain =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.default_time_to_retain;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.default_time_to_wait =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.default_time_to_wait;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.max_recv_data_seg_len =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.max_recv_data_seg_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.first_burst_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.first_burst_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_params.max_burst_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp.p_params.max_burst_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters which currently are unsettable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_CONNECTIONS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_OUTSTANDING_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (persistent_get_tunable_param((char *)isp->sess_name, &ptp) ==
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China B_TRUE) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (ptp.p_bitmap & ISCSI_TUNABLE_PARAM_RX_TIMEOUT_VALUE) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp->conn_tunable_params.recv_login_rsp_timeout =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ptp.p_params.recv_login_rsp_timeout;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (ptp.p_bitmap & ISCSI_TUNABLE_PARAM_CONN_LOGIN_MAX) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp->conn_tunable_params.conn_login_max =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ptp.p_params.conn_login_max;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (ptp.p_bitmap & ISCSI_TUNABLE_PARAM_LOGIN_POLLING_DELAY) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp->conn_tunable_params.polling_login_delay =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ptp.p_params.polling_login_delay;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip binding checks on discovery sessions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_DISCOVERY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now we need to get the current optional connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * binding information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup initial buffer for configured session information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = sizeof (*ics);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = kmem_zalloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_in = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = (char *)isp->sess_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we were unable to get target level information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then check the initiator level information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = (char *)isp->sess_hba->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No hba information is found. So assume default
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one session unbound behavior.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_out = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_bound = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (ics->ics_out > 1) && isp->sess_boot &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng !iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iscsi booting session with mpxio disabled,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * no need set multiple sessions for booting session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_out = 1;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng ics->ics_bound = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng cmn_err(CE_NOTE, "MPxIO is disabled,"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " no need to configure multiple boot sessions");
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check to make sure this session is still a configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session. The user might have decreased the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count. (NOTE: byte 5 of the sess_isid is the session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * count (via MS/T). This counter starts at 0.)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte idx = isp->sess_isid[5];
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (idx == ISCSI_MAX_CONFIG_SESSIONS)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * This is temporary session for boot session propose
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * no need to bound IP for this session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng icp->conn_bound = B_FALSE;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng kmem_free(ics, sizeof (iscsi_config_sess_t));
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng return (ISCSI_STATUS_SUCCESS);
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_out <= idx) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No longer a configured session. Return a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failure so we don't attempt to relogin.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SHUTDOWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If sessions are unbound set this information on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the connection and return success.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_bound == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_bound = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, sizeof (iscsi_config_sess_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Since the sessions are bound we need to find the matching
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * binding information for the session's isid. If this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session's isid is > 0 then we need to get more configured
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * session information to find the binding info.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (idx > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int ics_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics_out = ics->ics_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* record new size and free last buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = ISCSI_SESSION_CONFIG_SIZE(ics_out);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, sizeof (*ics));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate new buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics = kmem_zalloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_in = ics_out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) != B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "iscsi session(%d) - "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "unable to get configured session information\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SHUTDOWN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy correct binding information to the connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_bound = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_bindings[idx].i_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in4,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &icp->conn_bound_addr.sin4.sin_addr.s_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
1050fd6d7cf8ededf1816f2b4d8e5d047410260cJames Moore icp->conn_bound_addr.sin4.sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&ics->ics_bindings[idx].i_addr.in6,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &icp->conn_bound_addr.sin6.sin6_addr.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
1050fd6d7cf8ededf1816f2b4d8e5d047410260cJames Moore icp->conn_bound_addr.sin6.sin6_family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ics, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | Internal Connection Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_flush_active_cmds - flush all active icmdps
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for a connection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_flush_active_cmds(iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_cmd_t *icmdp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t lock_held = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = icp->conn_sess;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mutex_owned(&icp->conn_queue_active.mutex)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lock_held = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&icp->conn_queue_active.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Flush active queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icmdp = icp->conn_queue_active.head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icmdp != NULL) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_enter(&icmdp->cmd_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China if (icmdp->cmd_type == ISCSI_CMD_TYPE_SCSI) {
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China icmdp->cmd_un.scsi.pkt_stat |= STAT_ABORTED;
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China }
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China mutex_exit(&icmdp->cmd_mutex);
2b79d384d32b4ea1e278466cd9b0f3bb56daae22bing zhao - Sun Microsystems - Beijing China
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_cmd_state_machine(icmdp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CMD_EVENT_E7, isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icmdp = icp->conn_queue_active.head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Wait for active queue to drain */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap while (icp->conn_queue_active.count) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_queue_active.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap delay(drv_usectohz(100000));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_queue_active.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (lock_held == B_FALSE) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_queue_active.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Wait for IDM abort queue to drain (if necessary) */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap while (icp->conn_queue_idm_aborting.count) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap delay(drv_usectohz(100000));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_queue_idm_aborting.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_retry - retry connect/login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapvoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_retry(iscsi_sess_t *isp, iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_task_t *itp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set login min/max time values */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_set_login_min_max(icp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CONN_DEFAULT_LOGIN_MIN,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp->conn_tunable_params.conn_login_max);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_LOG(CE_NOTE, "DEBUG: iscsi_conn_retry: icp: %p icp: %p ",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void *)icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void *)icp->conn_ic);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Sync base connection information before login.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A login redirection might have shifted the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * current information from the base.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&icp->conn_base_addr, &icp->conn_curr_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (icp->conn_curr_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* schedule login task */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itp = kmem_zalloc(sizeof (iscsi_task_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itp->t_arg = icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itp->t_blocking = B_FALSE;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng if (ddi_taskq_dispatch(isp->sess_login_taskq,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void(*)())iscsi_login_start, itp, DDI_SLEEP) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(itp, sizeof (iscsi_task_t));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "iscsi connection(%u) failure - "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "unable to schedule login task", icp->conn_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state(icp, ISCSI_CONN_STATE_FREE);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N6, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapvoid
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_conn_update_state(iscsi_conn_t *icp, iscsi_conn_state_t
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap next_state)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void) iscsi_conn_update_state_locked(icp, next_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapvoid
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_conn_update_state_locked(iscsi_conn_t *icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_state_t next_state)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap{
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(mutex_owned(&icp->conn_state_mutex));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap next_state = (next_state > ISCSI_CONN_STATE_MAX) ?
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_STATE_MAX : next_state;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_state_change(&icp->conn_state_audit,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap SAS_ISCSI_CONN, icp->conn_state, next_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap switch (next_state) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_FREE:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_IN_LOGIN:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_LOGGED_IN:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_IN_LOGOUT:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_FAILED:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap case ISCSI_CONN_STATE_POLLING:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_LOG(CE_NOTE,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iscsi_conn_update_state conn %p %s(%d) -> %s(%d)",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void *)icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_ics_name[icp->conn_state], icp->conn_state,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_ics_name[next_state], next_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_prev_state = icp->conn_state;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap icp->conn_state = next_state;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cv_broadcast(&icp->conn_state_change);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap break;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap default:
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "Update state found illegal state: %x "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "prev_state: %x", next_state, icp->conn_prev_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ASSERT(0);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap}