fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI connection interfaces
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic void iscsi_client_notify_task(void *cn_task_void);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapstatic void iscsi_conn_flush_active_cmds(iscsi_conn_t *icp);
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))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | External Connection Interfaces |
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 Forteiscsi_conn_create(struct sockaddr *addr, iscsi_sess_t *isp, iscsi_conn_t **icpp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* See if this connection already exists */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (icp = isp->sess_conn_list; icp; icp = icp->conn_next) {
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 /* It's a match, record this connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If icp is found return it */
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 * Setup connection
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);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * IDM CN taskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp->conn_sess->sess_hba->hba_oid, icp->conn_sess->sess_oid,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ddi_taskq_create(icp->conn_sess->sess_hba->hba_dip, th_name, 1,
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_tx_thread = iscsi_thread_create(isp->sess_hba->hba_dip,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup connection queues */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_init_queue(&icp->conn_queue_idm_aborting);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(addr, &icp->conn_base_addr, sizeof (icp->conn_base_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Add new connection to the session connection list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_conn_list = isp->sess_conn_list_last_ptr = icp;
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 ASSERT(icp->conn_state == ISCSI_CONN_STATE_FREE);
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 iscsi_conn_update_state_locked(icp, ISCSI_CONN_STATE_IN_LOGIN);
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 bcopy(&icp->conn_base_addr, &icp->conn_curr_addr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap itp = kmem_zalloc(sizeof (iscsi_task_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_offline - This attempts to take a connection from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * any state to ISCSI_CONN_STATE_FREE.
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 * 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 delay = ddi_get_lbolt() + SEC_TO_TICK(SHUTDOWN_TIMEOUT);
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) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* wait for transition */
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);
92adbba74606fdfb5f11be2a6497e53ff2224507Peter Cudhea - Sun Microsystems - Burlington, MA United States } else {
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 /* Destroy transfer thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Terminate connection queues */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_destroy_queue(&icp->conn_queue_idm_aborting);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove connection from sessions linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* connection first item in list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check if this is also the last item in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * search session list for icp pointing
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to connection being removed. Then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update that connections next pointer.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this is the last connection in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * update the last_ptr to point to t_icp
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* couldn't find session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Free this Connections Data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_set_login_min_max - set min/max login window
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Used to set the min and max login window. Input values
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are in seconds.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_set_login_min_max(iscsi_conn_t *icp, int min, int max)
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);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Process the idm notifications
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_client_notify(idm_conn_t *ic, idm_client_notify_t icn, uintptr_t data)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Don't access icp if the notification is CN_CONNECT_DESTROY
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * since icp may have already been freed.
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 * Wakeup any thread waiting for login stuff to happen.
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);
5f7d09c6770c7413ed11bfa981c6d50666ca0f4dPeter Cudhea - Sun Microsystems - Burlington, MA United States
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
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
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.
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 * 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 iscsi_client_notify_task, cn, DDI_SLEEP) != DDI_SUCCESS) {
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);
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.
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 * 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 * Logout due to to user config change,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * we will not try to re-establish
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * the connection.
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.
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 iscsi_conn_update_state_locked(icp,
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China ISCSI_CONN_STATE_FAILED);
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.
19944f88b420ce331fd9dc839e0853848053cdb1yi zhang - Sun Microsystems - Beijing China (icp->conn_prev_state == ISCSI_CONN_STATE_IN_LOGIN)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release connect hold from CN_READY_FOR_LOGIN */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Any remaining commands are never going to finish */
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 if (icp->conn_state != ISCSI_CONN_STATE_FAILED) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_state_machine(isp, ISCSI_SESS_EVENT_N3,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * If session type is NORMAL, try to reestablish the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * connection.
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 /* Release connect hold from CN_READY_FOR_LOGIN */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iscsi_client_notify: unknown notification: "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "%x: NOT IMPLEMENTED YET: icp: %p ic: %p ",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* free the task notify structure we allocated in iscsi_client_notify */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release the hold we acquired in iscsi_client_notify */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_sync_params - used to update connection parameters
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.
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China persistent_tunable_param_t ptp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((icp->conn_state == ISCSI_CONN_STATE_IN_LOGIN) ||
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 /* First get a copy of the HBA params */
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 * 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 (void) persistent_param_get((char *)isp->sess_name, &pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (param_id = 0; param_id < ISCSI_NUM_LOGIN_PARAM;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng !iscsi_chk_bootlun_mpxio(ihp) && isp->sess_boot) {
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 " default login parameters in"
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " boot session as MPxIO is disabled");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Boolean parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters which currently are unsettable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (persistent_get_tunable_param((char *)isp->sess_name, &ptp) ==
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 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 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;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Skip binding checks on discovery sessions */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp->sess_type == ISCSI_SESS_TYPE_DISCOVERY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now we need to get the current optional connection
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * binding information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* setup initial buffer for configured session information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we were unable to get target level information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then check the initiator level information.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No hba information is found. So assume default
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one session unbound behavior.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (ics->ics_out > 1) && isp->sess_boot &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * iscsi booting session with mpxio disabled,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * no need set multiple sessions for booting session
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng " no need to configure multiple boot sessions");
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.)
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop && (idx == ISCSI_MAX_CONFIG_SESSIONS)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * This is temporary session for boot session propose
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * no need to bound IP for this session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No longer a configured session. Return a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * failure so we don't attempt to relogin.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If sessions are unbound set this information on
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the connection and return success.
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 /* record new size and free last buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* allocate new buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured sessions information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(name, ics) != B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "unable to get configured session information\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy correct binding information to the connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_bindings[idx].i_insize == sizeof (struct in_addr)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
1050fd6d7cf8ededf1816f2b4d8e5d047410260cJames Moore icp->conn_bound_addr.sin6.sin6_family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * | Internal Connection Interfaces |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * +--------------------------------------------------------------------+
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_flush_active_cmds - flush all active icmdps
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * for a connection.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mutex_owned(&icp->conn_queue_active.mutex)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Flush active queue */
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 mutex_exit(&icmdp->cmd_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Wait for active queue to drain */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Wait for IDM abort queue to drain (if necessary) */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_enter(&icp->conn_queue_idm_aborting.mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap mutex_exit(&icp->conn_queue_idm_aborting.mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_retry - retry connect/login
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_retry(iscsi_sess_t *isp, iscsi_conn_t *icp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set login min/max time values */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp->conn_tunable_params.conn_login_max);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISCSI_CONN_LOG(CE_NOTE, "DEBUG: iscsi_conn_retry: icp: %p icp: %p ",
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 bcopy(&icp->conn_base_addr, &icp->conn_curr_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* schedule login task */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte itp = kmem_zalloc(sizeof (iscsi_task_t), KM_SLEEP);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "iscsi connection(%u) failure - "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "unable to schedule login task", icp->conn_oid);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_conn_update_state(icp, ISCSI_CONN_STATE_FREE);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_conn_update_state(iscsi_conn_t *icp, iscsi_conn_state_t
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (void) iscsi_conn_update_state_locked(icp, next_state);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiscsi_conn_update_state_locked(iscsi_conn_t *icp,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap next_state = (next_state > ISCSI_CONN_STATE_MAX) ?
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_sm_audit_state_change(&icp->conn_state_audit,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iscsi_conn_update_state conn %p %s(%d) -> %s(%d)",
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iscsi_ics_name[icp->conn_state], icp->conn_state,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap cmn_err(CE_WARN, "Update state found illegal state: %x "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "prev_state: %x", next_state, icp->conn_prev_state);