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/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iSCSI Software Initiator
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Framework interface routines for iSCSI
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap#include "iscsi.h" /* main header */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap#include <sys/idm/idm_text.h> /* main header */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap#include <sys/iscsi_protocol.h> /* protocol structs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/iscsi_if.h> /* ioctl interfaces */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "persistent.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/scsi/adapters/iscsi_door.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "iscsi_targetparam.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/strsubr.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/socketvar.h>
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng#include <sys/bootprops.h>
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Mengextern ib_boot_prop_t *iscsiboot_prop;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_copyin -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_copyin(caddr_t arg, int mode, size_t size)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(arg != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(size != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = kmem_alloc(size, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, data, size, mode) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (data);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_copyout -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_copyout(void *data, size_t size, caddr_t arg, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyout(data, arg, size, mode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_list_get_copyin -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_conn_list_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get_copyin(caddr_t arg, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_list_t *cl_tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_list_t *cl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t alloc_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(arg != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl_tmp = (iscsi_conn_list_t *)kmem_zalloc(sizeof (*cl_tmp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, cl_tmp, sizeof (*cl_tmp), mode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_tmp->cl_vers == ISCSI_INTERFACE_VERSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_len = sizeof (*cl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl_tmp->cl_in_cnt != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_len += ((cl_tmp->cl_in_cnt - 1) *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (iscsi_if_conn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = (iscsi_conn_list_t *)kmem_zalloc(alloc_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(cl_tmp, cl, sizeof (*cl_tmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(cl_tmp, sizeof (*cl_tmp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (cl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_list_get_copyout -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get_copyout(iscsi_conn_list_t *cl, caddr_t arg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size_t alloc_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(cl != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(arg != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_len = sizeof (*cl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl->cl_in_cnt != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_len += ((cl->cl_in_cnt - 1) * sizeof (iscsi_if_conn_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyout(cl, arg, alloc_len, mode) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(cl, alloc_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_conn_oid_list_get -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_oid_list_get(iscsi_hba_t *ihp, iscsi_conn_list_t *cl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_if_conn_t *cnx;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t target_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's check the version. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl->cl_vers != ISCSI_INTERFACE_VERSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* We preinitialize the output connection counter. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl->cl_out_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* The list of sessions is walked holding the HBA mutex. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
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 if (isp->sess_target_oid == cl->cl_sess_oid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_oid = isp->sess_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte target_oid = cl->cl_sess_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_sig == ISCSI_SIG_SESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* return connections for NORMAL sessions only */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((isp->sess_type == ISCSI_SESS_TYPE_NORMAL) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((cl->cl_all_sess == B_TRUE) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (target_oid == isp->sess_oid))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The list of connections is walked holding
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the session mutex.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp->conn_sig == ISCSI_SIG_CONN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CONN_STATE_LOGGED_IN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl->cl_out_cnt < cl->cl_in_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* There's still room. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnx =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &cl->cl_list[
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl->cl_out_cnt];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(cnx, sizeof (*cnx));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnx->c_cid = icp->conn_cid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnx->c_oid = icp->conn_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cnx->c_sess_oid = isp->sess_oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ++cl->cl_out_cnt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl->cl_all_sess == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We got here because it was the only session
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we were looking for. We can exit now.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_conn_props_get -
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteboolean_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_conn_props_get(iscsi_hba_t *ihp, iscsi_conn_props_t *cp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rtn;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn_t *idm_conn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's check the version. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cp->cp_vers != ISCSI_INTERFACE_VERSION) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Let's find the session. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_sess_get(cp->cp_sess_oid, ihp, &isp) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(isp->sess_sig == ISCSI_SIG_SESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = isp->sess_conn_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp->cp_params_valid = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (icp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(icp->conn_sig == ISCSI_SIG_CONN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_oid == cp->cp_oid) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap struct sockaddr_storage *sal;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap struct sockaddr_storage *sar;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap idm_conn =
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (idm_conn_t *)icp->conn_ic;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sal = &idm_conn->ic_laddr;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sar = &idm_conn->ic_raddr;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Local Address */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (sal->ss_family == AF_INET) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&idm_conn->ic_laddr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap &cp->cp_local,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&idm_conn->ic_laddr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap &cp->cp_local,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in6));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Peer Address */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (sar->ss_family == AF_INET) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&idm_conn->ic_raddr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap &cp->cp_peer,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in));
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap } else {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&idm_conn->ic_raddr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap &cp->cp_peer,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap sizeof (struct sockaddr_in6));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state == ISCSI_CONN_STATE_LOGGED_IN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cp->cp_params_valid = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&icp->conn_params, &cp->cp_params,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (icp->conn_params));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_sendtgts_get - 0 on success; errno on failure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_sendtgts_get(iscsi_hba_t *ihp, iscsi_sendtgts_list_t *stl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define ISCSI_SENDTGTS_REQ_STR "SendTargets=All"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_status_t status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t oid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *data;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t rx_data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sockaddr_t addr_snd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(ihp != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(stl != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_addr_to_sockaddr(stl->stl_entry.e_insize,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &stl->stl_entry.e_u, stl->stl_entry.e_port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &addr_snd.sin);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* create discovery session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = iscsi_sess_create(ihp, iSCSIDiscoveryMethodSendTargets,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, SENDTARGETS_DISCOVERY, ISCSI_DEFAULT_TPGT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_SUN_ISID_5, ISCSI_SESS_TYPE_DISCOVERY, &oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!ISCSI_SUCCESS(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_sess_destroy(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* start login */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&icp->conn_state_mutex);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = iscsi_conn_online(icp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&icp->conn_state_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap if (status == ISCSI_STATUS_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_len = icp->conn_params.max_xmit_data_seg_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_sendtgts:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* alloc/init buffer for SendTargets req/resp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data = kmem_zalloc(data_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ISCSI_SENDTGTS_REQ_STR, data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (ISCSI_SENDTGTS_REQ_STR));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* execute SendTargets operation */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = iscsi_handle_text(icp, data, data_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (ISCSI_SENDTGTS_REQ_STR), &rx_data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check if allocated buffer is too small for response */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status == ISCSI_STATUS_DATA_OVERFLOW) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte data_len = rx_data_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_sendtgts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = iscsi_create_sendtgts_list(icp, data,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rx_data_len, stl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(status)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(data, data_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * check if session is still alive. It may have been destroyed
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * by a driver unload
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_WRITER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_sess_get(oid, ihp, &isp) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) iscsi_sess_destroy(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
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 Forte * response.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic iscsi_status_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_create_sendtgts_list(iscsi_conn_t *icp, char *data, int data_len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sendtgts_list_t *stl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *line = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t targetname_added = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sendtgts_entry_t *curr_ste = NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *prev_ste = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct hostent *hptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int error_num;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initialize number of targets found */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl->stl_out_cnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (data_len == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 if (prev_ste != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl->stl_out_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stl->stl_out_cnt >= stl->stl_in_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste = &(stl->stl_list[stl->stl_out_cnt]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy((char *)curr_ste->ste_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte line + strlen(TARGETNAME),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (curr_ste->ste_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_base_addr.sin.sa_family == AF_INET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in *addr_in =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &icp->conn_base_addr.sin4;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_addr.i_insize =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&addr_in->sin_addr.s_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &curr_ste->ste_ipaddr.a_addr.i_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_port =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htons(addr_in->sin_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in6 *addr_in6 =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &icp->conn_base_addr.sin6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_addr.i_insize =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(&addr_in6->sin6_addr.s6_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &curr_ste->ste_ipaddr.a_addr.i_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (struct in6_addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_port =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte htons(addr_in6->sin6_port);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_tpgt = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetname_added = B_TRUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strncmp(TARGETADDRESS, line,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen(TARGETADDRESS)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *in_str,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tmp_buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *addr_str,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *port_str,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *tpgt_str;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_buf_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte long result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_ste == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "SendTargets protocol error: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "TARGETADDRESS first");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we can't find an '=' then the sendtargets
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * response if invalid per spec. Return empty list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_str = strchr(line, '=');
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (in_str == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* move past the '=' */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte in_str++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Copy addr, port, and tpgt into temporary buffer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_buf_len = strlen(in_str) + 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp_buf = kmem_zalloc(tmp_buf_len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(tmp_buf, in_str, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Parse the addr, port, and tpgt from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sendtarget response
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (parse_addr_port_tpgt(tmp_buf, &addr_str, &type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &port_str, &tpgt_str) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Unable to extract addr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_buf, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now convert string addr to binary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hptr = kgetipnodebyname(addr_str, type,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AI_ALL, &error_num);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!hptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Unable to get valid address */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_buf, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if space for response */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (targetname_added == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl->stl_out_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stl->stl_out_cnt >= stl->stl_in_cnt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 * the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kfreehostent(hptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_buf, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste = &(stl->stl_list[stl->stl_out_cnt]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strcpy((char *)curr_ste->ste_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)prev_ste->ste_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_addr.i_insize = hptr->h_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(*hptr->h_addr_list,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(curr_ste->ste_ipaddr.a_addr.i_addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_addr.i_insize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kfreehostent(hptr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port_str != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_strtol(port_str, NULL, 0, &result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_port = (short)result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_ipaddr.a_port = ISCSI_LISTEN_PORT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tpgt_str != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_strtol(tpgt_str, NULL, 0, &result);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte curr_ste->ste_tpgt = (short)result;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "SendTargets protocol error: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "TPGT not specified");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_buf, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tmp_buf, tmp_buf_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte targetname_added = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strlen(line) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Any other string besides an empty string
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is a protocol error
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE, "SendTargets protocol error: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "unexpected response");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_PROTOCOL_ERROR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte prev_ste = curr_ste;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (prev_ste != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte stl->stl_out_cnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ISCSI_STATUS_SUCCESS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_set_param - This function is a helper to ISCSI_SET_PARAM
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * IOCTL
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_set_param(iscsi_login_params_t *params, iscsi_param_set_t *ipsp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_param_get_t *ipgp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipgp = (iscsi_param_get_t *)kmem_alloc(sizeof (*ipgp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipgp->g_param = ipsp->s_param;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_get_param(params, B_TRUE, ipgp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ipgp, sizeof (*ipgp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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
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 (ipsp->s_value.v_integer %
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipgp->g_value.v_integer.i_incr) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ipgp, sizeof (*ipgp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ipgp, sizeof (*ipgp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (ipsp->s_param) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Boolean parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_SEQUENCE_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->data_sequence_in_order = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_IMMEDIATE_DATA:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->immediate_data = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_INITIAL_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->initial_r2t = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_PDU_IN_ORDER:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->data_pdu_in_order = ipsp->s_value.v_bool;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Integer parameters
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_HEADER_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->header_digest = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DATA_DIGEST:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->data_digest = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_RETAIN:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->default_time_to_retain = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_DEFAULT_TIME_2_WAIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params->default_time_to_wait = ipsp->s_value.v_integer;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
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 break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_FIRST_BURST_LENGTH:
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 } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_MAX_BURST_LENGTH:
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 } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
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 case ISCSI_LOGIN_PARAM_OUTSTANDING_R2T:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case ISCSI_LOGIN_PARAM_ERROR_RECOVERY_LEVEL:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = ENOTSUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_set_params(iscsi_param_set_t *ils, iscsi_hba_t *ihp, boolean_t persist)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_login_params_t *params = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *name = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_param_get_t *ilg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn = 0;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* handle special case for Initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ils->s_param == ISCSI_LOGIN_PARAM_INITIATOR_NAME) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strlcpy((char *)ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ils->s_value.v_name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persist) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* save off old Initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = kmem_alloc(ISCSI_MAX_NAME_LEN, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_initiator_name_get(name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_initiator_name_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t *pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_chap_props_t *chap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_auth_props_t *auth;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* checking login params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp = kmem_zalloc(sizeof (persistent_param_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_param_get(name, pp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_param_clear(name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_param_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_name, pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pp, sizeof (persistent_param_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check chap params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap = kmem_zalloc(sizeof (iscsi_chap_props_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_chap_get(name, chap)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_chap_clear(name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int userSize;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userSize =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (chap->c_user);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp((char *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap->c_user, name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (chap->c_user))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(chap->c_user,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte userSize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy((char *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap->c_user,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte chap->c_user_len =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_chap_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_name, chap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(chap, sizeof (iscsi_chap_props_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check authentication params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte auth = kmem_zalloc(sizeof (iscsi_auth_props_t),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_auth_get(name, auth)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_auth_clear(name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_TRUE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_auth_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte auth);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(auth, sizeof (iscsi_auth_props_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (ils->s_param == ISCSI_LOGIN_PARAM_INITIATOR_ALIAS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strlcpy((char *)ihp->hba_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ils->s_value.v_name, ISCSI_MAX_NAME_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ihp->hba_alias_length =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strlen((char *)ils->s_value.v_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persist) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_alias_name_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_alias);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch login based if looking for initiator params */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ils->s_oid == ihp->hba_oid) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initiator */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params = &ihp->hba_params;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = ihp->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_set_param(params, ils);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = iscsi_targetparam_get_name(ils->s_oid);
f5fc5c043551e3eab595da7d8b5a53479207738fJack Meng if (name == NULL)
f5fc5c043551e3eab595da7d8b5a53479207738fJack Meng rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
f5fc5c043551e3eab595da7d8b5a53479207738fJack Meng if (persist && (rtn == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t *pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp = (persistent_param_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (*pp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!persistent_param_get((char *)name, pp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_set_default_login_params(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pp->p_params);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp->p_bitmap |= (1 << ils->s_param);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_set_param(&pp->p_params, ils);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_param_set(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)name, pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pp, sizeof (*pp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * MPxIO is enabled so capable
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of changing. All changes
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * will be applied later,
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * after this function
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng continue;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp((char *)isp->sess_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN) == 0) {
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengevent_count = atomic_inc_32_nv(&isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_enter_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_state_machine(isp, ISCSI_SESS_EVENT_N7, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Mengiscsi_sess_exit_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* end of 'else' */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (params && persist && (rtn == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte boolean_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte persistent_param_t *pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp = (persistent_param_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_zalloc(sizeof (*pp), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) persistent_param_get((char *)name, pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pp->p_bitmap |= (1 << ils->s_param);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(params, &pp->p_params, sizeof (*params));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = persistent_param_set((char *)name, pp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pp, sizeof (*pp));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if initiator parameter set, modify all associated
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sessions that don't already have the parameter
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * overriden
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
f5fc5c043551e3eab595da7d8b5a53479207738fJack Meng if ((ils->s_oid == ihp->hba_oid) && (rtn == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilg = (iscsi_param_get_t *)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_alloc(sizeof (*ilg), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (isp = ihp->hba_sess_list; isp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ilg->g_param = ils->s_param;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte params = &isp->sess_params;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (iscsi_get_persisted_param(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name, ilg, params) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_set_param(params, ils);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng if (iscsiboot_prop &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng isp->sess_boot &&
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng iscsi_chk_bootlun_mpxio(ihp)) {
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng /*
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * MPxIO is enabled so capable
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * of changing. Changes will
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * be applied later, right
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng * after this function
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng */
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng continue;
6cefaae1e90a413ba01560575bb3998e1a3df40eJack Meng }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Notify the session that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the login parameters have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * changed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N7, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ilg, sizeof (*ilg));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_target_prop_mod(iscsi_hba_t *ihp, iscsi_property_t *ipp, int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_conn_t *icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_sess_get(ipp->p_oid, ihp, &isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = iscsi_sess_get_by_target(ipp->p_oid, ihp, &isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rtn == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = (char *)isp->sess_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = (char *)iscsi_targetparam_get_name(ipp->p_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (name == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == ISCSI_TARGET_PROPS_GET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int conn_count = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(isp->sess_alias, ipp->p_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_alias_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(isp->sess_name, ipp->p_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_name_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_alias_len = isp->sess_alias_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_name_len = isp->sess_name_length;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_discovery = isp->sess_discovered_by;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_last_err = isp->sess_last_err;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_tpgt_conf = isp->sess_tpgt_conf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_tpgt_nego = isp->sess_tpgt_nego;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(isp->sess_isid, ipp->p_isid, ISCSI_ISID_LEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&isp->sess_conn_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (icp = isp->sess_conn_list; icp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte icp = icp->conn_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (icp->conn_state ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_CONN_STATE_LOGGED_IN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte conn_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&isp->sess_conn_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_num_of_connections = conn_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_connected = (conn_count > 0) ? B_TRUE : B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(name, ipp->p_name, strlen(name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_name_len = strlen(name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy("", ipp->p_alias, strlen(""));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_alias_len = strlen("");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_discovery = iSCSIDiscoveryMethodUnknown;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_last_err = NoError;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_tpgt_conf = ISCSI_DEFAULT_TPGT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_tpgt_nego = ISCSI_DEFAULT_TPGT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_num_of_connections = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_connected = B_FALSE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (isp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtn = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ISCSI_TARGET_PROPS_SET */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only update if new, otherwise could clear out alias
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if just updating the discovery.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ipp->p_alias_len != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ipp->p_alias, isp->sess_alias,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ipp->p_alias_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_alias_length = ipp->p_alias_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp->sess_discovered_by = ipp->p_discovery;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rtn);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_get_config_sess - gets configured session information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is an ioctl helper function to get the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * configured session information from the persistent store.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_get_config_sess(iscsi_hba_t *ihp, iscsi_config_sess_t *ics)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Get the matching iscsi node name for the oid */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_oid == ISCSI_INITIATOR_OID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* initiator name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = ihp->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* target name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = iscsi_targetparam_get_name(ics->ics_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (name == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid node name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get configured session information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session((char *)name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_oid != ISCSI_INITIATOR_OID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (persistent_get_config_session(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)ihp->hba_name, ics) == B_FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No initiator value is set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return the defaults.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_out = ISCSI_DEFAULT_SESS_NUM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_bound = ISCSI_DEFAULT_SESS_BOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_out = ISCSI_DEFAULT_SESS_NUM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ics->ics_bound = ISCSI_DEFAULT_SESS_BOUND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * iscsi_ioctl_set_config_sess - sets configured session information
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteiscsi_ioctl_set_config_sess(iscsi_hba_t *ihp, iscsi_config_sess_t *ics)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_t *isp;
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng uint32_t event_count;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check range infomration */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ics->ics_in < ISCSI_MIN_CONFIG_SESSIONS) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (ics->ics_in > ISCSI_MAX_CONFIG_SESSIONS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid range information */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_oid == ISCSI_INITIATOR_OID) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = ihp->hba_name;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* get target name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte name = iscsi_targetparam_get_name(ics->ics_oid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (name == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* invalid node name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
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 return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* notify existing sessions of change */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_enter(&ihp->hba_sess_list_rwlock, RW_READER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (isp != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ics->ics_oid == ISCSI_INITIATOR_OID) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strncmp((char *)isp->sess_name, (char *)name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ISCSI_MAX_NAME_LEN) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ics->ics_in <= isp->sess_isid[5]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* First attempt to destory the session */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ISCSI_SUCCESS(iscsi_sess_destroy(isp))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = ihp->hba_sess_list;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If we can't destroy it then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * atleast poke it to disconnect
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng event_count = atomic_inc_32_nv(
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng &isp->sess_state_event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_enter_state_zone(isp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsi_sess_state_machine(isp,
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng ISCSI_SESS_EVENT_N7, event_count);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng iscsi_sess_exit_state_zone(isp);
904e51f67bfac9f3ec88d9254757474c448808ebJack Meng
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte isp = isp->sess_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rw_exit(&ihp->hba_sess_list_rwlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
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 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_poke_discovery(ihp, iSCSIDiscoveryMethodUnknown);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* lock so only one config operation occrs */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_p(&iscsid_config_semaphore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iscsid_config_all(ihp, B_FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sema_v(&iscsid_config_semaphore);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing Chinaint
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{
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China uchar_t *name;
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
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 } else {
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 }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China pparam = (persistent_tunable_param_t *)kmem_zalloc(sizeof (*pparam),
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China KM_SLEEP);
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 }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
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 break;
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 break;
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 break;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China default:
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China break;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
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 }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
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 }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China
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 continue;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
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 } else {
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China /*
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 */
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 }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China icp = icp->conn_next;
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_exit(&isp->sess_conn_list_rwlock);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China }
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China rw_exit(&ihp->hba_sess_list_rwlock);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China kmem_free(pparam, sizeof (*pparam));
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China return (0);
aff4bce51ecc47df7e5a6351b7cee6bc20408c63yi zhang - Sun Microsystems - Beijing China}