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 Software Initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Framework interface routines for iSCSI
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap#include <sys/iscsi_protocol.h> /* protocol structs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/iscsi_if.h> /* ioctl interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t iscsi_create_sendtgts_list(iscsi_conn_t *icp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *data, int data_len, iscsi_sendtgts_list_t *stl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_copyin -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_copyin(caddr_t arg, int mode, size_t size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_copyout -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_copyout(void *data, size_t size, caddr_t arg, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_list_get_copyin -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get_copyin(caddr_t arg, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_tmp = (iscsi_conn_list_t *)kmem_zalloc(sizeof (*cl_tmp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, cl_tmp, sizeof (*cl_tmp), mode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_tmp->cl_vers == ISCSI_INTERFACE_VERSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_list_get_copyout -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get_copyout(iscsi_conn_list_t *cl, caddr_t arg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_len += ((cl->cl_in_cnt - 1) * sizeof (iscsi_if_conn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyout(cl, arg, alloc_len, mode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_oid_list_get -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get(iscsi_hba_t *ihp, iscsi_conn_list_t *cl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's check the version. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We preinitialize the output connection counter. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The list of sessions is walked holding the HBA mutex. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Check to see if oid references a target-param oid. If so,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * find the associated session oid before getting lu list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_targetparam_get_name(cl->cl_sess_oid) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp; isp = isp->sess_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return connections for NORMAL sessions only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isp->sess_type == ISCSI_SESS_TYPE_NORMAL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The list of connections is walked holding
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the session mutex.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* There's still room. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We got here because it was the only session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we were looking for. We can exit now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_conn_props_get -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_props_get(iscsi_hba_t *ihp, iscsi_conn_props_t *cp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's check the version. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's find the session. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_sess_get(cp->cp_sess_oid, ihp, &isp) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Local Address */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in6));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Peer Address */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in6));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_sendtgts_get - 0 on success; errno on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_sendtgts_get(iscsi_hba_t *ihp, iscsi_sendtgts_list_t *stl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create discovery session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = iscsi_sess_create(ihp, iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_SUN_ISID_5, ISCSI_SESS_TYPE_DISCOVERY, &oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create connection */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = iscsi_conn_create(&addr_snd.sin, isp, &icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start login */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_len = icp->conn_params.max_xmit_data_seg_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* alloc/init buffer for SendTargets req/resp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* execute SendTargets operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if allocated buffer is too small for response */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check if session is still alive. It may have been destroyed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by a driver unload
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_create_sendtgts_list - Based upon the given data, build a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * linked list of SendTarget information. The data passed into this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * function is expected to be the data portion(s) of SendTarget text
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_create_sendtgts_list(iscsi_conn_t *icp, char *data, int data_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize number of targets found */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((line = iscsi_get_next_text(data, data_len, line)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(TARGETNAME, line, strlen(TARGETNAME)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if this is first targetname */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue processing the data so that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the total number of targets are known
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and the caller can retry with the correct
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * number of entries in the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This entry will use the IP address and port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that was passed into this routine. If the next
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * line that we receive is a TargetAddress we will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * know to modify this entry with the new IP address,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * port and portal group tag. If this state flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is not set we'll just create a new entry using
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only the previous entries targetname.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_base_addr.sin.sa_family == AF_INET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If TARGETADDRESS is first line a SendTarget response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * (i.e. no TARGETNAME lines preceding), treat as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an error. To check this an assumption is made that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * at least one sendtarget_entry_t should exist prior
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to entering this code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "TARGETADDRESS first");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we can't find an '=' then the sendtargets
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * response if invalid per spec. Return empty list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move past the '=' */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy addr, port, and tpgt into temporary buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Parse the addr, port, and tpgt from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sendtarget response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (parse_addr_port_tpgt(tmp_buf, &addr_str, &type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Unable to extract addr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now convert string addr to binary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Unable to get valid address */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if space for response */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * continue processing the data so that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the total number of targets are
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * known and the caller can retry with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the correct number of entries in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_addr.i_insize = hptr->h_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "TPGT not specified");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Any other string besides an empty string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is a protocol error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "unexpected response");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If target found increment out count one more time because
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is the total number of entries in the list not an index
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * like it was used above
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_set_param - This function is a helper to ISCSI_SET_PARAM
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_set_param(iscsi_login_params_t *params, iscsi_param_set_t *ipsp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use get param to get the min, max and increment values for the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * given parameter so validation can be done on the new value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipgp = (iscsi_param_get_t *)kmem_alloc(sizeof (*ipgp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipsp->s_param == ISCSI_LOGIN_PARAM_HEADER_DIGEST ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_DATA_DIGEST ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_param == ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipsp->s_value.v_integer < ipgp->g_value.v_integer.i_min ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipsp->s_value.v_integer > ipgp->g_value.v_integer.i_max ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Boolean parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->data_sequence_in_order = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->data_pdu_in_order = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->default_time_to_retain = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->default_time_to_wait = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_RECV_DATA_SEGMENT_LENGTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->max_recv_data_seg_len = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipsp->s_value.v_integer <= params->max_burst_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->first_burst_length = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipsp->s_value.v_integer >= params->first_burst_length) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->max_burst_length = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters which currently are unsettable
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_set_params(iscsi_param_set_t *ils, iscsi_hba_t *ihp, boolean_t persist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* handle special case for Initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ils->s_param == ISCSI_LOGIN_PARAM_INITIATOR_NAME) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ils->s_value.v_name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save off old Initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check to see if we have login param,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chap param, or authentication params
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loaded in persistent that we have to change
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the name of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* checking login params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check chap params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Update CHAP user name only if the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * original username was set to the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initiator node name. Otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * leave it the way it is.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check authentication params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ils->s_param == ISCSI_LOGIN_PARAM_INITIATOR_ALIAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ils->s_value.v_name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch login based if looking for initiator params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initiator */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* session */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * Here may have multiple sessions with different
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * tpgt values. So it is needed to loop through
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the sessions and update all sessions.
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * MPxIO is enabled so capable
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of changing. All changes
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * will be applied later,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * after this function
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengevent_count = atomic_inc_32_nv(&isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_machine(isp, ISCSI_SESS_EVENT_N7, event_count);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end of 'else' */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if initiator parameter set, modify all associated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sessions that don't already have the parameter
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * MPxIO is enabled so capable
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of changing. Changes will
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * be applied later, right
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * after this function
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Notify the session that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the login parameters have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_target_prop_mod(iscsi_hba_t *ihp, iscsi_property_t *ipp, int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we're just attempting to get the target properties don't
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * create the session if it doesn't already exist. If we setting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the property then create the session if needed because we'll
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * most likely see an ISCSI_LOGIN in a few.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the oid does represent a session check to see
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it is a target oid. If so, return the target's
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * associated session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_sess_get_by_target(ipp->p_oid, ihp, &isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If rtn is zero then we have found an existing session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use the session name for database lookup. If rtn is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * non-zero then create a targetparam object and use
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * its name for database lookup.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = (char *)iscsi_targetparam_get_name(ipp->p_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If isp is not null get the session's parameters, otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the get is for a target-param object so defaults need to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(isp->sess_isid, ipp->p_isid, ISCSI_ISID_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_connected = (conn_count > 0) ? B_TRUE : B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ISCSI_TARGET_PROPS_SET */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only update if new, otherwise could clear out alias
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if just updating the discovery.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_get_config_sess - gets configured session information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is an ioctl helper function to get the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * configured session information from the persistent store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_get_config_sess(iscsi_hba_t *ihp, iscsi_config_sess_t *ics)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the matching iscsi node name for the oid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* target name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid node name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured session information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session((char *)name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * There might not be anything in the database yet. If
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is a request for the target check the initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * value. If neither is set return the default value.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No initiator value is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the defaults.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_set_config_sess - sets configured session information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is an ioctl helper function to set the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * configured session information in the persistent store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In addition it will notify any active sessions of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * changed so this can update binding information. It
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will also destroy sessions that were removed and add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * new sessions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_set_config_sess(iscsi_hba_t *ihp, iscsi_config_sess_t *ics)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check range infomration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid range information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get target name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid node name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* store the new information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_set_config_session((char *)name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* failed to store new information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* notify existing sessions of change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If this sessions least signficant byte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of the isid is less than or equal to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the the number of configured sessions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then we need to tear down this session.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First attempt to destory the session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we can't destroy it then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * atleast poke it to disconnect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The number of targets has changed. Since we don't expect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this to be a common operation lets keep the code simple and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just use a slightly larger hammer and poke discovery. This
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * force the reevaulation of this target and all other targets.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_poke_discovery(ihp, iSCSIDiscoveryMethodUnknown);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock so only one config operation occrs */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing Chinaiscsi_ioctl_set_tunable_param(iscsi_hba_t *ihp, iscsi_tunable_object_t *tpss)
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China iscsi_sess_t *isp;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China iscsi_conn_t *icp;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China int param_id = 0;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China persistent_tunable_param_t *pparam;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (tpss->t_oid == ihp->hba_oid) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China name = ihp->hba_name;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /* get target name */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China name = iscsi_targetparam_get_name(tpss->t_oid);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (name == NULL) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /* invalid node name */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China return (EINVAL);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam = (persistent_tunable_param_t *)kmem_zalloc(sizeof (*pparam),
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (persistent_get_tunable_param((char *)name, pparam) == B_FALSE) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /* use default value */
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.recv_login_rsp_timeout =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_RX_TIMEOUT_VALUE;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.polling_login_delay =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_LOGIN_POLLING_DELAY;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.conn_login_max =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China ISCSI_DEFAULT_CONN_DEFAULT_LOGIN_MAX;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_bitmap |= (1 << (tpss->t_param -1));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China param_id = 1 << (tpss->t_param -1);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China switch (param_id) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China case ISCSI_TUNABLE_PARAM_RX_TIMEOUT_VALUE:
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.recv_login_rsp_timeout =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China tpss->t_value.v_integer;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China case ISCSI_TUNABLE_PARAM_LOGIN_POLLING_DELAY:
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.polling_login_delay =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China tpss->t_value.v_integer;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China case ISCSI_TUNABLE_PARAM_CONN_LOGIN_MAX:
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam->p_params.conn_login_max =
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China tpss->t_value.v_integer;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (persistent_set_tunable_param((char *)name,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam) == B_FALSE) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China kmem_free(pparam, sizeof (*pparam));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China return (EINVAL);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (tpss->t_oid == ihp->hba_oid) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China bcopy(&pparam->p_params, &ihp->hba_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China sizeof (iscsi_tunable_params_t));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China for (isp = ihp->hba_sess_list; isp; isp = isp->sess_next) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (isp->sess_type != ISCSI_SESS_TYPE_NORMAL) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp = isp->sess_conn_list;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China while (icp != NULL) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China if (strcmp((const char *)name,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China (const char *)isp->sess_name) == 0) {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China bcopy(&pparam->p_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China &icp->conn_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China sizeof (iscsi_tunable_params_t));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China * this session connected target
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China * tunable parameters not set,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China * use initiator's default
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China bcopy(&ihp->hba_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China &icp->conn_tunable_params,
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China sizeof (iscsi_tunable_params_t));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp = icp->conn_next;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_exit(&isp->sess_conn_list_rwlock);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_exit(&ihp->hba_sess_list_rwlock);