a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER START
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * The contents of this file are subject to the terms of the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Common Development and Distribution License (the "License").
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You may not use this file except in compliance with the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * or http://www.opensolaris.org/os/licensing.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * See the License for the specific language governing permissions
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * and limitations under the License.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * When distributing Covered Code, include this CDDL HEADER in each
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If applicable, add the following below this CDDL HEADER, with the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * fields enclosed by brackets "[]" replaced with your own identifying
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * information: Portions Copyright [yyyy] [name of copyright owner]
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * CDDL HEADER END
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
42bf653b44c42fc6b637ae50e590489d69399241Peter Gill * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/cpuvar.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/types.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/conf.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/file.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/ddi.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/sunddi.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/socket.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <inet/tcp.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/sdt.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/stmf.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/stmf_ioctl.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/portif.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/idm/idm.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/idm/idm_so.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/iscsit/iscsit_common.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#include <sys/iscsit/isns_protocol.h>
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#include <sys/ksocket.h>
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "iscsit.h"
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan#include "iscsit_isns.h"
4558d122136f151d62acbbc02ddb42df89a5ef66Viswanathan Kannappan
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns.c -- isns client that is part of the iscsit server
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The COMSTAR iSCSI target uses four pieces of iSNS functionality:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * - DevAttrReg to notify the iSNS server of our targets and portals.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * - DeregDev to notify when a target goes away or we shut down
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * - DevAttrQry (self-query) to see if iSNS server still knows us.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * - Request ESI probes from iSNS server as a keepalive mechanism
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * We send only two kinds of DevAttrReg messages.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * REPLACE-ALL the info the iSNS server knows about us:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Set Flag in PDU header to ISNS_FLAG_REPLACE_REG
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Set "source" to same iSCSI target each time
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * EID (Entity Identifier) == our DNS name
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * "Delimiter"
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Object operated on = EID
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * "Entity Portals" owned by this "network entity"
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * List of targets
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * (Targets with TPGT are followed by PGT and PG portal info)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * UPDATE-EXISTING - used to register/change one target at a time
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Flag for replace reg not set
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Source and EID and Delimiter and Object Operated On as above
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Single Target
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * (Targets with TPGT are followed by PGT and PG portal info)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Interfaces to iscsit
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_init -- called when iscsi/target service goes online
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_fini -- called when iscsi/target service goes offline
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_register -- a new target comes online
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_deregister -- target goes offline
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_target_update -- called when a target is modified
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_portal_online -- called when defining a new portal
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_portal_offline -- no longer using a portal
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Copying Data Structures
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The above routines copy all the data they need, so iscsit can
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * proceed without interfering with us. This is moving in the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * direction of having this isns_client be a standalone user-mode
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * program. Specifically, we copy the target name, alias, and
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * tpgt+portal information.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The iscsit_isns_mutex protects the shadow copies of target and portal
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * information. The ISNS_GLOBAL_LOCK protects the iSNS run time structures
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * that the monitor thread uses. The routine isnst_copy_global_status_changes
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * has to acquire both locks and copy all the required information from the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * global structs to the per-server structs. Once it completes, the monitor
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * thread should run completely off the per-server copies.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Global State vs Per-Server state
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * There is a global list of targets and portals that is kept updated
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * by iscsit. Each svr keeps its own list of targets that have been
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * announced to the iSNS server.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Invariants
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * 1) If svr->svr_registered, then there is some itarget with
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * itarget->target_registered.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * 2) If itarget->target_delete_needed, then also itarget->target_registered.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * (Corollary: Any time you remove the last registered target, you have
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * to send an unregister-all message.)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * 3) If a target has a non-default portal, then the portal goes online
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * before the target goes online, and comes offline afterwards.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * (This is enforced by the iscsit state machines.)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/* local defines */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define MAX_XID (2^16)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define ISNS_IDLE_TIME 60
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define MAX_RETRY (3)
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap#define ISNS_RCV_TIMER_SECONDS 5
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define VALID_NAME(NAME, LEN) \
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap((LEN) > 0 && (NAME)[0] != 0 && (NAME)[(LEN) - 1] == 0)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap#define ISNST_LOG if (iscsit_isns_logging) cmn_err
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic kmutex_t isns_monitor_mutex;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesvolatile kthread_t *isns_monitor_thr_id;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapstatic kt_did_t isns_monitor_thr_did;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapstatic boolean_t isns_monitor_thr_running;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic kcondvar_t isns_idle_cv;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic uint16_t xid;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define GET_XID() atomic_inc_16_nv(&xid)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic clock_t monitor_idle_interval;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/* The ISNS_GLOBAL_LOCK protects the per-server data structures */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define ISNS_GLOBAL_LOCK() \
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap mutex_enter(&iscsit_global.global_isns_cfg.isns_mutex)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define ISNS_GLOBAL_LOCK_HELD() \
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap MUTEX_HELD(&iscsit_global.global_isns_cfg.isns_mutex)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap#define ISNS_GLOBAL_UNLOCK() \
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap mutex_exit(&iscsit_global.global_isns_cfg.isns_mutex)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * "Configurable" parameters (set in /etc/system for now).
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesboolean_t iscsit_isns_logging = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If fail this many times to send an update to the server, then
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * declare the server non-responsive and reregister everything with
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * the server when we next connect.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint isns_max_retry = MAX_RETRY;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The use of ESI probes to all active portals is not appropriate in
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * all network environments, since the iSNS server may not have
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * connectivity to all portals, so we turn it off by default.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesboolean_t isns_use_esi = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Interval to request ESI probes at, in seconds. The server is free
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * to specify a different frequency in its response.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint isns_default_esi_interval = ISNS_DEFAULT_ESI_INTERVAL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Registration Period -- we guarantee to check in with iSNS server at
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * least this often. Used when ESI probes are turned off.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint isns_registration_period = ISNS_DEFAULT_REGISTRATION_PERIOD;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Socket connect, PDU receive, and PDU send must complete
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * within this number of microseconds.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesuint32_t isns_timeout_usec = ISNS_RCV_TIMER_SECONDS * 1000000;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iSNS Message size -- we start with the max that can fit into one PDU.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If the message doesn't fit, we will expand at run time to a higher
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * value. This parameter could be set in /etc/system if some particular
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * installation knows it always goes over the standard limit.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesuint32_t isns_message_buf_size = ISNSP_MAX_PDU_SIZE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Number of seconds to wait after isnst_monitor thread starts up
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * before sending first DevAttrReg message.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint isns_initial_delay = ISNS_INITIAL_DELAY;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States/*
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * Because of a bug in the Solaris isns server (c 2009), we cannot send a
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * modify operation that changes the target's TPGTs. So just replace all.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * If the iSNS server does not have this bug, clear this flag.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * Changes take effect on each modify_target operation
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United Statesboolean_t isns_modify_must_replace = B_TRUE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/* If PDU sizes ever go over the following, we need to rearchitect */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States#define ISNST_MAX_MSG_SIZE (16 * ISNSP_MAX_PDU_SIZE)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iSNS ESI thread state
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_esi_tinfo_t esi;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Our list of targets. Kept in lock-step synch with iscsit.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The iscsit_isns_mutex protects the global data structures that are
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * kept in lock-step with iscsit.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * NOTE: Now that isnst runs independently of iscsit, we could remove the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * shadow copies of iscsit structures, such as isns_target_list and
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isns_tpg_portals, and have isnst_copy_global_status_changes reconcile
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst directly with the iscsit data structures.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic kmutex_t iscsit_isns_mutex;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic avl_tree_t isns_target_list;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t isns_targets_changed;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * List of portals from TPGs. Protected by iscsit_isns_mutex.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t isns_portals_changed;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic avl_tree_t isns_tpg_portals;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t default_portal_online;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/* List of all portals. Protected by ISNS_GLOBAL_LOCK */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic avl_tree_t isns_all_portals;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int num_default_portals;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int num_tpg_portals;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Our entity identifier (fully-qualified hostname). Passed in from libiscsit.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic char *isns_eid = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap/*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * in6addr_any is currently all zeroes, but use the macro in case this
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * ever changes.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_start();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_stop();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_set_isns(boolean_t state);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_add_isns(it_portal_t *cfg_svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_mark_delete_isns(iscsit_isns_svr_t *svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_finish_delete_isns(iscsit_isns_svr_t *svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic iscsit_isns_svr_t *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_svr_lookup(struct sockaddr_storage *sa);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_monitor(void *arg);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_monitor_one_server(iscsit_isns_svr_t *svr, boolean_t enabled);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_monitor_awaken(void);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_update_server_timestamp(struct sockaddr_storage *sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_copy_global_status_changes(void);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_mark_deleted_targets(iscsit_isns_svr_t *svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_update_one_server(iscsit_isns_svr_t *svr, isns_target_t *target,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_reg_type_t reg);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t isnst_retry_registration(int rsp_status_code);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int isnst_register(iscsit_isns_svr_t *svr, isns_target_t *itarget,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_reg_type_t regtype);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int isnst_deregister(iscsit_isns_svr_t *svr, isns_target_t *itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_dereg_pdu(iscsit_isns_svr_t *svr, isns_pdu_t **pdu,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarge);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int isnst_keepalive(iscsit_isns_svr_t *svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_keepalive_pdu(iscsit_isns_svr_t *svr, isns_pdu_t **pdu);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_get_registered_source(iscsit_isns_svr_t *srv);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_get_registered_source_locked(iscsit_isns_svr_t *srv);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_verify_rsp(iscsit_isns_svr_t *svr, isns_pdu_t *pdu,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_pdu_t *rsp, size_t rsp_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic uint16_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_pdu_get_op(isns_pdu_t *pdu, uint8_t **pp);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_reg_pdu(isns_pdu_t **pdu, isns_target_t *target,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_isns_svr_t *svr, isns_reg_type_t regtype);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_reg_pdu_add_entity_portals(isns_pdu_t *pdu, size_t pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_reg_pdu_add_pg(isns_pdu_t *pdu, size_t pdu_size, isns_target_t *target);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_default_pg(isns_pdu_t *pdu, size_t pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *null_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_tpg_pg(isns_pdu_t *pdu, size_t pdu_size,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_t *tig, avl_tree_t *null_portal_list);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_add_null_pg(isns_pdu_t *pdu, size_t pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *null_portal_list);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_add_portal_attr(isns_pdu_t *pdu, size_t pdu_size,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t ip_attr_id, uint32_t port_attr_id,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sockaddr_storage *ss, boolean_t esi_info);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_create_pdu_header(uint16_t func_id, isns_pdu_t **pdu, uint16_t flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_add_attr(isns_pdu_t *pdu,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t max_pdu_size,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_id,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_len,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap void *attr_data,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_numeric_data);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_send_pdu(void *so, isns_pdu_t *pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_rcv_pdu(void *so, isns_pdu_t **pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_open_so(struct sockaddr_storage *sa);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_close_so(void *);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_esi_thread(void *arg);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningisnst_handle_esi_req(ksocket_t so, isns_pdu_t *pdu, size_t pl_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void isnst_esi_start(void);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void isnst_esi_stop(void);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *isnst_latch_to_target_list(isns_target_t *target,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void isnst_clear_target_list(iscsit_isns_svr_t *svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void isnst_clear_from_target_list(isns_target_t *target,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int isnst_tgt_avl_compare(const void *t1, const void *t2);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void isnst_set_server_status(iscsit_isns_svr_t *svr,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap boolean_t registered);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void isnst_monitor_start(void);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapstatic void isnst_monitor_stop(void);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_monitor_default_portal_list(void);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_find_default_portals(idm_addr_list_t *alist);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_default_portals(idm_addr_list_t *alist);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_default_portals(void);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_portal_list(avl_tree_t *portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_copy_portal_list(avl_tree_t *t1, avl_tree_t *t2);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_portal_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_lookup_portal(struct sockaddr_storage *sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_portal_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_to_portal_list(struct sockaddr_storage *sa, avl_tree_t *portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_remove_from_portal_list(struct sockaddr_storage *sa,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_portal_avl_compare(const void *t1, const void *t2);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapit_cfg_status_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_config_merge(it_config_t *cfg)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap boolean_t new_isns_state = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *isns_svr, *next_isns_svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap it_portal_t *cfg_isns_svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Determine whether iSNS is enabled in the new config.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Isns property may not be set up yet.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) nvlist_lookup_boolean_value(cfg->config_global_properties,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap PROP_ISNS_ENABLED, &new_isns_state);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Delete iSNS servers that are no longer part of the config */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (isns_svr = list_head(&iscsit_global.global_isns_cfg.isns_svrs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_svr != NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_svr = next_isns_svr) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap next_isns_svr = list_next(
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap &iscsit_global.global_isns_cfg.isns_svrs, isns_svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (it_sns_svr_lookup(cfg, &isns_svr->svr_sa) == NULL)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_mark_delete_isns(isns_svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Add new iSNS servers */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (cfg_isns_svr = cfg->config_isns_svr_list;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap cfg_isns_svr != NULL;
42bf653b44c42fc6b637ae50e590489d69399241Peter Gill cfg_isns_svr = cfg_isns_svr->portal_next) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_svr = iscsit_isns_svr_lookup(&cfg_isns_svr->portal_addr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isns_svr == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_add_isns(cfg_isns_svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (isns_svr->svr_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If reactivating a server that was being
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * deleted, turn it into a reset.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_svr->svr_delete_needed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_svr->svr_reset_needed = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * There is no "modify case" since the user specifies a complete
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * server list each time. A modify is the same as a remove+add.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Start/Stop iSNS if necessary */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_set_isns(new_isns_state);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Wake up the monitor thread to complete the state change */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapint
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_init(iscsit_hostinfo_t *hostinfo)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap mutex_init(&iscsit_global.global_isns_cfg.isns_mutex, NULL,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap MUTEX_DEFAULT, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_init(&iscsit_isns_mutex, NULL, MUTEX_DEFAULT, NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_global.global_isns_cfg.isns_state = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap list_create(&iscsit_global.global_isns_cfg.isns_svrs,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (iscsit_isns_svr_t), offsetof(iscsit_isns_svr_t, svr_ln));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_create(&isns_tpg_portals, isnst_portal_avl_compare,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (isns_portal_t), offsetof(isns_portal_t, portal_node));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_create(&isns_all_portals, isnst_portal_avl_compare,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (isns_portal_t), offsetof(isns_portal_t, portal_node));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_default_portals = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (hostinfo->length > ISCSIT_MAX_HOSTNAME_LEN)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap hostinfo->length = ISCSIT_MAX_HOSTNAME_LEN;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_eid = kmem_alloc(hostinfo->length, KM_SLEEP);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (void) strlcpy(isns_eid, hostinfo->fqhn, hostinfo->length);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap avl_create(&isns_target_list, isnst_tgt_avl_compare,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (isns_target_t), offsetof(isns_target_t, target_node));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* initialize isns client */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_init(&isns_monitor_mutex, NULL, MUTEX_DEFAULT, NULL);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_init(&esi.esi_mutex, NULL, MUTEX_DEFAULT, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_monitor_thr_id = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap monitor_idle_interval = ISNS_IDLE_TIME * drv_usectohz(1000000);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap cv_init(&isns_idle_cv, NULL, CV_DEFAULT, NULL);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_init(&esi.esi_cv, NULL, CV_DEFAULT, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap xid = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapvoid
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_fini()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The following call to iscsit_set_isns waits until all the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iSNS servers have been fully deactivated and the monitor and esi
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * threads have stopped.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_set_isns(B_FALSE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Clean up data structures */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_destroy(&isns_monitor_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap cv_destroy(&isns_idle_cv);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_destroy(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_destroy(&esi.esi_cv);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_destroy(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Free our EID and target list.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isns_eid) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(isns_eid, strlen(isns_eid) + 1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_eid = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_global.global_isns_cfg.isns_state = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap avl_destroy(&isns_target_list);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap list_destroy(&iscsit_global.global_isns_cfg.isns_svrs);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_destroy(&isns_tpg_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_destroy(&isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_default_portals = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap mutex_destroy(&iscsit_global.global_isns_cfg.isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_set_isns(boolean_t state)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Update state and isns stop flag
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (iscsit_global.global_isns_cfg.isns_state != state) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* reset retry count for all servers */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap for (svr = list_head(&iscsit_global.global_isns_cfg.isns_svrs);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap svr != NULL;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap svr = list_next(&iscsit_global.global_isns_cfg.isns_svrs,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap svr)) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap svr->svr_retry_count = 0;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap iscsit_global.global_isns_cfg.isns_state = state;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (state) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_start();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_stop();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesvoid
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_add_isns(it_portal_t *cfg_svr)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr = kmem_zalloc(sizeof (iscsit_isns_svr_t), KM_SLEEP);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(&cfg_svr->portal_addr, &svr->svr_sa,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (struct sockaddr_storage));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_create(&svr->svr_target_list, isnst_tgt_avl_compare,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (isns_target_t), offsetof(isns_target_t, target_node));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_esi_interval = isns_default_esi_interval;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* put it on the global isns server list */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap list_insert_tail(&iscsit_global.global_isns_cfg.isns_svrs, svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesvoid
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_mark_delete_isns(iscsit_isns_svr_t *svr)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* If monitor thread not running, finish delete here */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (iscsit_global.global_isns_cfg.isns_state == B_FALSE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_finish_delete_isns(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_delete_needed = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapvoid
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_finish_delete_isns(iscsit_isns_svr_t *svr)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_target_list(svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap list_remove(&iscsit_global.global_isns_cfg.isns_svrs, svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* free the memory */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_destroy(&svr->svr_target_list);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(svr, sizeof (*svr));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic iscsit_isns_svr_t *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_svr_lookup(struct sockaddr_storage *sa)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap it_portal_t portal1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(sa, &portal1.portal_addr, sizeof (struct sockaddr_storage));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (svr = list_head(&iscsit_global.global_isns_cfg.isns_svrs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr != NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr = list_next(&iscsit_global.global_isns_cfg.isns_svrs, svr)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (it_sa_compare(&svr->svr_sa, sa) == 0)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_info_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_create_target_info(iscsit_tgt_t *target)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_t *tig;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_addr_t *tip;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_tpgt_t *tpgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_tpg_t *tpg;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_portal_t *tp;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States char *str;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Cannot hold the iscsit_isns_mutex here! */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(! mutex_owned(&iscsit_isns_mutex));
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ti = kmem_zalloc(sizeof (isns_target_info_t), KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_create(&ti->ti_tpgt_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (isns_tpgt_t), offsetof(isns_tpgt_t, ti_tpgt_ln));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_init(&ti->ti_refcnt, ti);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&target->target_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) strncpy(ti->ti_tgt_name, target->target_name,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States MAX_ISCSI_NODENAMELEN);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (nvlist_lookup_string(target->target_props, PROP_ALIAS,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &str) == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) strncpy(ti->ti_tgt_alias, str, MAX_ISCSI_NODENAMELEN);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tpgt = avl_first(&target->target_tpgt_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(tpgt != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States do {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tig = kmem_zalloc(sizeof (isns_tpgt_t), KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_create(&tig->ti_portal_list, sizeof (isns_tpgt_addr_t),
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States offsetof(isns_tpgt_addr_t, portal_ln));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tig->ti_tpgt_tag = tpgt->tpgt_tag;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Only need portal list for non-default portal.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (tpgt->tpgt_tag != ISCSIT_DEFAULT_TPGT) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tpg = tpgt->tpgt_tpg;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&tpg->tpg_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tp = avl_first(&tpg->tpg_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States do {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tip = kmem_zalloc(sizeof (isns_tpgt_addr_t),
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(&tp->portal_addr, &tip->portal_addr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (tip->portal_addr));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_insert_tail(&tig->ti_portal_list, tip);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tp = AVL_NEXT(&tpg->tpg_portal_list, tp);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } while (tp != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&tpg->tpg_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_insert_tail(&ti->ti_tpgt_list, tig);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tpgt = AVL_NEXT(&target->target_tpgt_list, tpgt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } while (tpgt != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&target->target_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (ti);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_target_info_cb(void *arg)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti = (isns_target_info_t *)arg;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_t *tig;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_addr_t *tip;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while ((tig = list_remove_head(&ti->ti_tpgt_list)) != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while ((tip = list_remove_head(&tig->ti_portal_list)) != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(tip, sizeof (isns_tpgt_addr_t));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_destroy(&tig->ti_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(tig, sizeof (isns_tpgt_t));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States list_destroy(&ti->ti_tpgt_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_destroy(&ti->ti_refcnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(ti, sizeof (isns_target_info_t));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_register
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * called by iscsit when a target goes online
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesiscsit_isns_register(iscsit_tgt_t *target)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, tmptgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_index_t where;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Create TI struct outside of isns_mutex */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ti = isnst_create_target_info(target);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((itarget = (isns_target_t *)avl_find(&isns_target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &tmptgt, &where)) == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = kmem_zalloc(sizeof (isns_target_t), KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target = target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_insert(&isns_target_list, (void *)itarget, where);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Copy the target info so it will last beyond deregister */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_info = ti;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_hold(&ti->ti_refcnt);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_targets_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_deregister
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * called by iscsit when a target goes offline
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesint
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesiscsit_isns_deregister(iscsit_tgt_t *target)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, tmptgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap tmptgt.target = target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_find(&isns_target_list, &tmptgt, NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(itarget != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ti = itarget->target_info;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The main thread is done with the target_info object.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Make sure the delete callback is called when
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * all the svrs are done with it.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_rele(&ti->ti_refcnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_async_wait_ref(&ti->ti_refcnt,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (idm_refcnt_cb_t *)&isnst_clear_target_info_cb);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_info = NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_remove(&isns_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(itarget, sizeof (isns_target_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_targets_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iscsit_isns_target_update
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * This function is called by iscsit when a target's configuration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * has changed.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapvoid
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_target_update(iscsit_tgt_t *target)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, tmptgt;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Create new TI struct outside of isns_mutex */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ti = isnst_create_target_info(target);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If iscsit calls us to modify a target, that target should
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * already exist in the isns_svr_list.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_find(&isns_target_list, &tmptgt, NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If target-update gets called while the target is still
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * offline, then there is nothing to do. The target will be
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * completely registered when it comes online.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Remove the target_info struct -- not needed */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_target_info_cb(ti);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Remove the old target_info struct */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_rele(&itarget->target_info->ti_refcnt);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_async_wait_ref(&itarget->target_info->ti_refcnt,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States (idm_refcnt_cb_t *)&isnst_clear_target_info_cb);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Link to new target_info struct */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_info = ti;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_hold(&ti->ti_refcnt);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_update_needed = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_targets_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_start()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "**** isnst_start");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Start ESI thread(s)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_esi_start();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Create a thread for monitoring server communications
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_monitor_start();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_stop()
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "**** isnst_stop");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNS_GLOBAL_UNLOCK();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_esi_stop();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_monitor_stop();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNS_GLOBAL_LOCK();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_monitor_start(void)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "isnst_monitor_start");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(!isns_monitor_thr_running);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isns_monitor_thr_id = thread_create(NULL, 0,
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isnst_monitor, NULL, 0, &p0, TS_RUN, minclsyspri);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap while (!isns_monitor_thr_running)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_wait(&isns_idle_cv, &isns_monitor_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&isns_monitor_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapisnst_monitor_stop(void)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "isnst_monitor_stop");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&isns_monitor_mutex);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap if (isns_monitor_thr_running) {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isns_monitor_thr_running = B_FALSE;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap cv_signal(&isns_idle_cv);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&isns_monitor_mutex);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap thread_join(isns_monitor_thr_did);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap return;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&isns_monitor_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * isnst_update_server_timestamp
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * When we receive an ESI request, update the timestamp for the server.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * If we don't receive one for the specified period of time, we'll attempt
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * to re-register.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic boolean_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_update_server_timestamp(struct sockaddr_storage *ss)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *svr;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Find the server and update the timestamp
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (svr = list_head(&iscsit_global.global_isns_cfg.isns_svrs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr != NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr = list_next(&iscsit_global.global_isns_cfg.isns_svrs, svr)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Note that the port number in incoming probe will be
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * different than the iSNS server's port number.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (idm_ss_compare(ss, &svr->svr_sa,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_TRUE /* v4_mapped_as_v4 */,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_FALSE /* don't compare_ports */) == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (svr != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Update the timestamp we keep for this server */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr->svr_last_msg = ddi_get_lbolt();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If we receive ESI probe from a server we are not
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * registered to, then cause a re-reg attempt.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!svr->svr_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (B_TRUE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (B_FALSE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_monitor_all_servers -- loop through all servers
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapisnst_monitor_all_servers()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_isns_svr_t *svr, *next_svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap boolean_t enabled;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap list_t *svr_list;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int rc;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr_list = &iscsit_global.global_isns_cfg.isns_svrs;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_copy_global_status_changes();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap enabled = iscsit_global.global_isns_cfg.isns_state;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (svr = list_head(svr_list); svr != NULL; svr = next_svr) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_monitor_hold = B_TRUE;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_monitor_one_server can release ISNS_GLOBAL_LOCK
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * internally. This allows isnst_config_merge to run
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * even when messages to iSNS servers are pending.
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_monitor_one_server(svr, enabled);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap svr->svr_retry_count++;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_registered &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_retry_count > isns_max_retry) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States char server_buf[IDM_SA_NTOP_BUFSIZ];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (! svr->svr_reset_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_WARN,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States "isnst: iSNS server %s"
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States " not responding (rc=%d).",
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sa_ntop(&svr->svr_sa,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States server_buf, sizeof (server_buf)),
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap } else {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap svr->svr_retry_count = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If we have finished unregistering this server,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * it is now OK to delete it.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_monitor_hold = B_FALSE;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States next_svr = list_next(svr_list, svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_delete_needed == B_TRUE &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_registered == B_FALSE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_finish_delete_isns(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap ISNS_GLOBAL_UNLOCK();
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_monitor_awaken(void)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_monitor_thr_running) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States DTRACE_PROBE(iscsit__isns__monitor__awaken);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States cv_signal(&isns_idle_cv);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_monitor -- the monitor thread for iSNS
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap/*ARGSUSED*/
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapstatic void
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapisnst_monitor(void *arg)
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&isns_monitor_mutex);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isns_monitor_thr_did = curthread->t_did;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isns_monitor_thr_running = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States cv_signal(&isns_idle_cv);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Start with a short pause (5 sec) to allow all targets
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * to be registered before we send register-all. This is
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * purely an optimization to cut down on the number of
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * messages we send to the iSNS server.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States delay(drv_usectohz(isns_initial_delay * 1000000));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Force an initialization of isns_all_portals */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portals_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap while (isns_monitor_thr_running) {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap /* Update servers */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&isns_monitor_mutex);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isnst_monitor_all_servers();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&isns_monitor_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* If something needs attention, go right to the top */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_targets_changed || isns_portals_changed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States DTRACE_PROBE(iscsit__isns__monitor__reenter);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* isns_monitor_mutex still held */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States continue;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap * Keep running until isns_monitor_thr_running is set to
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap * B_FALSE.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (! isns_monitor_thr_running)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap DTRACE_PROBE(iscsit__isns__monitor__sleep);
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni (void) cv_reltimedwait(&isns_idle_cv, &isns_monitor_mutex,
d3d50737e566cade9a08d73d2af95105ac7cd960Rafael Vanoni monitor_idle_interval, TR_CLOCK_TICK);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap DTRACE_PROBE1(iscsit__isns__monitor__wakeup,
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap boolean_t, isns_monitor_thr_running);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&isns_monitor_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap /* Update the servers one last time for deregistration */
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap isnst_monitor_all_servers();
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Clean up the all-portals list */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_default_portals();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* terminate the thread at the last */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap thread_exit();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_monitor_one_server(iscsit_isns_svr_t *svr, boolean_t enabled)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int rc = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * First, take care of the case where iSNS is no longer enabled.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (enabled == B_FALSE || svr->svr_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Just try one time to deregister all from server.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Doesn't matter if this fails. We're disabled.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) isnst_update_one_server(svr, NULL, ISNS_DEREGISTER_ALL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isnst_set_server_status(svr, B_FALSE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesretry_replace_all:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If the server needs replace-all, check if it should
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * be a DevDereg (i.e. if the last target is gone.)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_registered && svr->svr_reset_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Send DevDereg if last registered target */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *jtarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (jtarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jtarget != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jtarget = AVL_NEXT(&svr->svr_target_list, jtarget)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!jtarget->target_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * jtarget is null IFF all tgts need deletion,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * and there are no new targets to register.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (jtarget == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_update_one_server(svr, NULL,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_DEREGISTER_ALL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_set_server_status(svr, B_FALSE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If the server is not yet registered, do the registration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (! svr->svr_registered || svr->svr_reset_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (avl_numnodes(&svr->svr_target_list) == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* If no targets, nothing to register */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((rc = isnst_update_one_server(svr, NULL,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_REGISTER_ALL)) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Registration failed */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_set_server_status(svr, B_TRUE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* The following checks are expensive, so only do them if needed */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_targets_changed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *next_target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If there is a target to be deleted, send the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * deletion request for one target at a time.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (itarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = next_target) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States next_target = AVL_NEXT(&svr->svr_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget->target_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* See if last non-deleted target */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *jtarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(itarget->target_registered);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States for (jtarget =
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jtarget != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jtarget = AVL_NEXT(&svr->svr_target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jtarget)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (jtarget->target_registered &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States !jtarget->target_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* jtarget is null if last registered tgt */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (jtarget == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Removing last tgt -- deregister all.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Doesn't matter if this fails.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * We're disabled.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_update_one_server(svr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States NULL, ISNS_DEREGISTER_ALL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_set_server_status(svr, B_FALSE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_update_one_server(svr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget, ISNS_DEREGISTER_TARGET);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0 && isnst_retry_registration(rc)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Retryable code => try replace-all */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto retry_replace_all;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_from_target_list(itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* If any target needs a register or an update, do so */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (itarget) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!itarget->target_registered ||
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_update_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * Because of a bug in the isns
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * server, we cannot send a modify
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * operation that changes the target's
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * TPGTs. So just replace all.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_modify_must_replace) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States goto retry_replace_all;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Try to update existing info for one tgt */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_update_one_server(svr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_MODIFY_TARGET);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0 && isnst_retry_registration(rc)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Retryable code => try replace-all */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto retry_replace_all;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_update_needed =
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_registered = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = AVL_NEXT(&svr->svr_target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * We have gone through all the cases -- this server
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * is now up to date.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_targets_changed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_use_esi) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If using ESI, and no ESI request is received within
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * MAX_ESI_INTERVALS (3) number of intervals, we'll
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * try to re-register with the server. The server will
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * delete our information if we fail to respond for 2
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * ESI intervals.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (ddi_get_lbolt() >= (svr->svr_last_msg +
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap drv_usectohz(svr->svr_esi_interval * 1000000 *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap MAX_ESI_INTERVALS))) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* re-register everything */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto retry_replace_all;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If not using ESI, make sure to ping server during
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * each registration period. Do this at half the
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * registration interval, so we won't get timed out.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (ddi_get_lbolt() >= (svr->svr_last_msg +
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States drv_usectohz(isns_registration_period * (1000000/3)))) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Send a self-query as a keepalive. */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_keepalive(svr);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0 && isnst_retry_registration(rc)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Retryable code => try replace-all */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto retry_replace_all;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_mark_deleted_target -- find tgt in svr list but not global list
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_mark_deleted_targets(iscsit_isns_svr_t *svr)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, *nxt_target, tmptgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(mutex_owned(&iscsit_isns_mutex));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (itarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = nxt_target) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = itarget->target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States nxt_target = AVL_NEXT(&svr->svr_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (avl_find(&isns_target_list, &tmptgt, NULL) == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget->target_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_delete_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_from_target_list(itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_latch_to_target_list(isns_target_t *jtarget, avl_tree_t *target_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, tmptgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_index_t where;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(mutex_owned(&iscsit_isns_mutex));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Make sure this target isn't already in our list.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = jtarget->target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((itarget = (isns_target_t *)avl_find(target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &tmptgt, &where)) == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = kmem_zalloc(sizeof (isns_target_t), KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target = jtarget->target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_info = jtarget->target_info;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_hold(&itarget->target_info->ti_refcnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_insert(target_list, (void *)itarget, where);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_target_list(iscsit_isns_svr_t *svr)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while ((itarget = avl_first(&svr->svr_target_list)) != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_from_target_list(itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_from_target_list(isns_target_t *jtarget, avl_tree_t *target_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget, tmptgt;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = jtarget->target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((itarget = avl_find(target_list, &tmptgt, NULL))
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_remove(target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_rele(&itarget->target_info->ti_refcnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(itarget, sizeof (isns_target_t));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_copy_global_status_changes -- update svrs to match iscsit
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * At the end of this routine svr->svr_target_list has all the entries
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * in the current isns_target_list plus any targets that are marked
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * for deletion.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_copy_global_status_changes(void)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *ttarget, *itarget, tmptgt;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iscsit_isns_svr_t *svr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Copy info about recent transitions from global state to
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * per-server state. We use the global state so that iscsit
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * functions can proceed without blocking on slow-to-release
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * iSNS locks.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Periodically check for changed IP addresses. This function
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * sets isns_all_portals to the current set, and sets
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isns_portals_changed if a portal is added or removed.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_default_portal_list();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Initialize the per-server structs to some basic values */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap for (svr = list_head(&iscsit_global.global_isns_cfg.isns_svrs);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap svr != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr = list_next(&iscsit_global.global_isns_cfg.isns_svrs,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_portals_changed && svr->svr_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Cause re-register, for now, when portals change.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Eventually, we should add new portals one by one
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!svr->svr_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* To re-register, start with empty target list */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_target_list(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* And set flag to add all current targets, below */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_targets_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (isns_targets_changed || svr->svr_reset_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Mark to look for target changes */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_mark_deleted_targets(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_targets_changed = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If any target has been modified, tell all the svrs to
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * update that target.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_targets_changed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ttarget = avl_first(&isns_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (ttarget) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (svr = list_head(
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &iscsit_global.global_isns_cfg.isns_svrs);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr = list_next(
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &iscsit_global.global_isns_cfg.isns_svrs,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tmptgt.target = ttarget->target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_find(
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &svr->svr_target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &tmptgt, NULL);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Add a new target */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (void) isnst_latch_to_target_list(
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ttarget, &svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (ttarget->target_update_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Modify existing target */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_update_needed =
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_TRUE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Remove link to old target_info */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_rele(
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States &itarget->target_info->ti_refcnt);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Link to new target_info struct */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_info =
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ttarget->target_info;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_refcnt_hold(
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States &itarget->target_info->ti_refcnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ttarget->target_update_needed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ttarget = AVL_NEXT(&isns_target_list, ttarget);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Now we have updated the per-server state for all servers.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Clear the global state flags
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_targets_changed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portals_changed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States/*
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_update_one_server releases ISNS_GLOBAL_LOCK internally and
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * acquires it again as needed. This allows isnst_config_merge and
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_esi_thread to run even while waiting for a response from the
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * iSNS server (or a dead iSNS server).
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_update_one_server(iscsit_isns_svr_t *svr, isns_target_t *itarget,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_reg_type_t reg)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int rc = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap switch (reg) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_DEREGISTER_TARGET:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_deregister(svr, itarget);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_DEREGISTER_ALL:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rc = isnst_deregister(svr, NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States case ISNS_MODIFY_TARGET:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_REGISTER_TARGET:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_register(svr, itarget, reg);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_REGISTER_ALL:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rc = isnst_register(svr, NULL, reg);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap default:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* NOTREACHED */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * isnst_retry_registration
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * This function checks the return value from a registration pdu and
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * determines whether or not we should retry this request. If the
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * request is retried, it will do so as an "update", which means we
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * re-register everything.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic boolean_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_retry_registration(int rsp_status_code)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap boolean_t retry;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * The following are the error codes that indicate isns-client
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * and isns-server are out of synch. E.g. No-Such-Entry can
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * occur on a keepalive if the server has timed out our
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * connection. If we get one of these messages, we replace-all
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * right away to get back in synch faster.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap switch (rsp_status_code) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_RSP_INVALID_REGIS:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_RSP_SRC_UNAUTHORIZED:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_RSP_BUSY:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States case ISNS_RSP_INVALID_UPDATE:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States case ISNS_RSP_NO_SUCH_ENTRY:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap retry = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap default:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap retry = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (retry);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_register(iscsit_isns_svr_t *svr, isns_target_t *itarget,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_reg_type_t regtype)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap struct sonode *so;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int rc = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_pdu_t *pdu, *rsp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t pdu_size, rsp_size;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* create TCP connection to the isns server */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap so = isnst_open_so(&svr->svr_sa);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (so == NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States pdu_size = isnst_make_reg_pdu(&pdu, itarget, svr, regtype);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (pdu_size == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_send_pdu(so, pdu);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rsp_size = isnst_rcv_pdu(so, &rsp);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rsp_size == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_verify_rsp(svr, pdu, rsp, rsp_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(rsp, rsp_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_make_reg_pdu:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Cases:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * initial registration of all targets (replace-all)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * initial registration of a single target (update-existing)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * modify an existing target (update-existing)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_reg_pdu(isns_pdu_t **pdu, isns_target_t *itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iscsit_isns_svr_t *svr, isns_reg_type_t regtype)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t pdu_size;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap char *str;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *src;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap boolean_t reg_all = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t flags = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_monitor_hold);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * svr could have an empty target list if svr was added
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * by isnst_config_merge sometime after the last call to
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * copy_global_status_changes. Just skip this chance
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * to reregister. The next call to copy_global_status_changes
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States * will sort things out.
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States if (avl_numnodes(&svr->svr_target_list) == 0) {
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States /* If no targets, nothing to register */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Find a source attribute for this registration.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If updating a specific target for the first time, use that
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * target.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If already registered, use a registered target
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Otherwise, use the first target we are going to register.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget != NULL && ! svr->svr_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States src = itarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (svr->svr_registered) {
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States src = isnst_get_registered_source_locked(svr);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * When registering to a server, and we don't know which
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * of our targets the server might already know,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * cycle through each of our targets as source. The server
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * does source validation. If the server knows any of our
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * targets, it will eventually accept one of our registrations.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int i;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *jtarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_last_target_index >=
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_numnodes(&svr->svr_target_list) - 1) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_last_target_index = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_last_target_index++;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (i = 0, jtarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States i < svr->svr_last_target_index;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States i++, jtarget = AVL_NEXT(&svr->svr_target_list, jtarget)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(jtarget != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States src = jtarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(src != NULL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Null target means we're replacing everything.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget == NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap reg_all = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States flags = ISNS_FLAG_REPLACE_REG;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Reset itarget to the beginning of our list */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = (isns_target_t *)avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (regtype == ISNS_REGISTER_TARGET) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States flags = ISNS_FLAG_REPLACE_REG;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(!itarget->target_delete_needed);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu_size = isnst_create_pdu_header(ISNS_DEV_ATTR_REG, pdu, flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (pdu_size == 0) {
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Source Attribute */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strlen(src->target_info->ti_tgt_name) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len, src->target_info->ti_tgt_name, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Message Key Attributes - EID
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len = strlen(isns_eid) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_EID_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len, isns_eid, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Delimiter */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_DELIMITER_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap 0, 0, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Operating Attributes
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_EID_ATTR_ID, len,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_eid, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* ENTITY Protocol - Section 6.2.2 */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(*pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_ENTITY_PROTOCOL_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap 4, 0, ISNS_ENTITY_PROTOCOL_ISCSI) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (reg_all) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Registration Period -- use if not using ESI */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!isns_use_esi &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_add_attr(*pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_ENTITY_REG_PERIOD_ATTR_ID, 4,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States 0, isns_registration_period) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Network entity portal information - only when
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * replacing all. Since targets are only registered
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * to iSNS when their portals are already registered
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * to iSNS, we can assume entity portals exist.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_reg_pdu_add_entity_portals(*pdu, pdu_size) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Skip over delete-pending tgts. There must be at
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * least one non-deleted tgt, or it is an error.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (itarget->target_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = AVL_NEXT(&svr->svr_target_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(itarget != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Add information about each target or one target */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap do {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* iSCSI Name - Section 6.4.1 */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States str = itarget->target_info->ti_tgt_name;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len = strlen(str) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len, str, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* iSCSI Node Type */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_ISCSI_NODE_TYPE_ATTR_ID, 4, 0,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_TARGET_NODE_TYPE) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* iSCSI Alias */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States str = itarget->target_info->ti_tgt_alias;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strnlen(str,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (itarget->target_info->ti_tgt_alias));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (len) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Found alias in property list */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_ISCSI_ALIAS_ATTR_ID, len+1, str, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_reg_pdu_add_pg(*pdu, pdu_size, itarget) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap goto pdu_error;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* If registering one target, then we are done. */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!reg_all) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Skip over delete-pending tgts */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States do {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = AVL_NEXT(&svr->svr_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } while (itarget != NULL && itarget->target_delete_needed);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } while (itarget != NULL);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlappdu_error:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* packet too large, no memory (or other error) */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = ntohs((*pdu)->payload_len);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (len + 1000 > isns_message_buf_size) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Increase the PDU size we will ask for next time */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_message_buf_size * 2 <= ISNST_MAX_MSG_SIZE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_message_buf_size *= 2;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_NOTE,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States "Increasing isns_message_buf_size to %d",
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_message_buf_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States cmn_err(CE_WARN, "iscsit: isns: no space"
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States " to send required PDU");
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(*pdu, pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_reg_pdu_add_entity_portals(isns_pdu_t *pdu, size_t pdu_size)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int rc = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = (isns_portal_t *)avl_first(&isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (iportal != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Do not include ESI port if not using ESI */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_portal_attr(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PORTAL_IP_ADDR_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PORTAL_PORT_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &iportal->portal_addr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_use_esi /* ESI info */) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = -1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = AVL_NEXT(&isns_all_portals, iportal);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States/*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * isnst_reg_pdu_add_pg -- add the PG and PGT entries for one target.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_reg_pdu_add_pg(isns_pdu_t *pdu, size_t pdu_size, isns_target_t *itarget)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap int rval = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t null_portals;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_info_t *ti;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_t *tig;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ti = itarget->target_info;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If all registered targets only use the default TPGT, then
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * we can skip sending PG info to the iSNS server.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (num_tpg_portals == 0)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * For each target, we start with the full portal list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * and then remove portals as we add them to TPGTs for this target.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * At the end, all the remaining portals go into the "null pg".
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * We use the "null_portals" list to track this.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_create(&null_portals, isnst_portal_avl_compare,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (isns_portal_t), offsetof(isns_portal_t, portal_node));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_copy_portal_list(&isns_all_portals, &null_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (tig = list_head(&ti->ti_tpgt_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tig != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States tig = list_next(&ti->ti_tpgt_list, tig)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (tig->ti_tpgt_tag == ISCSIT_DEFAULT_TPGT) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Add portal info from list of default portals */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_default_pg(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &null_portals) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rval = 1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Add portal info from this TPGT's entries */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_tpg_pg(pdu, pdu_size, tig,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &null_portals) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rval = 1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Add the remaining portals (if any) to the null PG */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rval == 0 &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_add_null_pg(pdu, pdu_size, &null_portals) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rval = 1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_portal_list(&null_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_destroy(&null_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rval);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States/* Write one TPGT's info into the PDU */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_tpg_pg(isns_pdu_t *pdu, size_t pdu_size,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_t *tig, avl_tree_t *null_portal_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_tpgt_addr_t *tip;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int rval = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(tig->ti_tpgt_tag != ISCSIT_DEFAULT_TPGT);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Portal Group Tag */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_TAG_ATTR_ID, 4, 0, tig->ti_tpgt_tag) != 0) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States rval = 1;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States goto pg_done;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States tip = list_head(&tig->ti_portal_list);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(tip != NULL);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States do {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* PG Portal Addr and PG Portal Port */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_portal_attr(pdu, pdu_size,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_IP_ADDR_ATTR_ID,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_PORT_ATTR_ID,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States &tip->portal_addr, B_FALSE /* ESI */) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap rval = 1;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap goto pg_done;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States isnst_remove_from_portal_list(&tip->portal_addr,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States null_portal_list);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States tip = list_next(&tig->ti_portal_list, tip);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States } while (tip != NULL);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlappg_done:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (rval);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_default_pg(isns_pdu_t *pdu, size_t pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *null_portal_list)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (num_default_portals == 0) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * It is OK for a target with default-portals to be
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * online from an STMF perspective and yet all
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * default portals are down. if other (non-default)
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * portals do exist, we will still announce the target
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * to the isns server. In this case, we will specify
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * all the active non-default portals as NULL portals.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * This is an OK state.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States *
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * There is a corner case if non-default portals have
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * been marked online but the targets that use them
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * are not fully online yet, AND all the default portals
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * are down. In this case, the iSNS server will receive
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * a DevAttrReg pdu that announces both non-default
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * portals and default-portal-only targets. In other
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * words, there may be no target that has an active
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * portal. The iSNS spec does not forbid this case.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States *
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * Both of the above cases are somewhat theoretical.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * If the default portals are down we probably cannot
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * get any messages through to the iSNS server anyway.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Portal Group Tag */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_TAG_ATTR_ID, 4, 0, ISCSIT_DEFAULT_TPGT) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (iportal = avl_first(&isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = AVL_NEXT(&isns_all_portals, iportal)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (iportal->portal_default) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* PG Portal Addr and PG Portal Port */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_portal_attr(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_IP_ADDR_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_PORT_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &iportal->portal_addr, B_FALSE) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_remove_from_portal_list(&iportal->portal_addr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States null_portal_list);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_null_pg(isns_pdu_t *pdu, size_t pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *null_portal_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* If all portals accounted for, no NULL PG needed */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (avl_numnodes(null_portal_list) == 0) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* NULL Portal Group Tag means no access via these portals. */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_TAG_ATTR_ID, 0, 0, 0) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (iportal = avl_first(null_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = AVL_NEXT(null_portal_list, iportal)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_portal_attr(pdu, pdu_size,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_IP_ADDR_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_PG_PORTAL_PORT_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &iportal->portal_addr, B_FALSE) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (0);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_add_portal_attr(isns_pdu_t *pdu, size_t pdu_size,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t ip_attr_id, uint32_t port_attr_id,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sockaddr_storage *ss, boolean_t esi_info)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sockaddr_in *in;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sockaddr_in6 *in6;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t attr_numeric_data;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap void *inaddrp;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap in = (struct sockaddr_in *)ss;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap in6 = (struct sockaddr_in6 *)ss;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ASSERT((ss->ss_family == AF_INET) || (ss->ss_family == AF_INET6));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (ss->ss_family == AF_INET) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_numeric_data = sizeof (in_addr_t);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap inaddrp = (void *)&in->sin_addr;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else if (ss->ss_family == AF_INET6) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_numeric_data = sizeof (in6_addr_t);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap inaddrp = (void *)&in6->sin6_addr;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Portal Group Portal IP Address */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (isnst_add_attr(pdu, pdu_size, ip_attr_id,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap 16, inaddrp, attr_numeric_data) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Portal Group Portal Port */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size, port_attr_id,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States 4, 0, ntohs(in->sin_port)) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&esi.esi_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (esi_info && esi.esi_valid) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* ESI interval and port */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size, ISNS_ESI_INTERVAL_ATTR_ID, 4,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States NULL, isns_default_esi_interval) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(pdu, pdu_size, ISNS_ESI_PORT_ATTR_ID, 4,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States NULL, esi.esi_port) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&esi.esi_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_deregister(iscsit_isns_svr_t *svr, isns_target_t *itarget)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int rc;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_pdu_t *pdu, *rsp;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States size_t pdu_size, rsp_size;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sonode *so;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States so = isnst_open_so(&svr->svr_sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (so == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States pdu_size = isnst_make_dereg_pdu(svr, &pdu, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (pdu_size == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_send_pdu(so, pdu);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rc != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rsp_size = isnst_rcv_pdu(so, &rsp);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (rsp_size == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States rc = isnst_verify_rsp(svr, pdu, rsp, rsp_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_close_so(so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(rsp, rsp_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (rc);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap}
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_keepalive(iscsit_isns_svr_t *svr)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap int rc;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_pdu_t *pdu, *rsp;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap size_t pdu_size, rsp_size;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sonode *so;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap so = isnst_open_so(&svr->svr_sa);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (so == NULL) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (-1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States pdu_size = isnst_make_keepalive_pdu(svr, &pdu);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (pdu_size == 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_close_so(so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (-1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap rc = isnst_send_pdu(so, pdu);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (rc != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_close_so(so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp_size = isnst_rcv_pdu(so, &rsp);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (rsp_size == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isnst_close_so(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(pdu, pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap rc = isnst_verify_rsp(svr, pdu, rsp, rsp_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isnst_close_so(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(pdu, pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(rsp, rsp_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_dereg_pdu(iscsit_isns_svr_t *svr, isns_pdu_t **pdu,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t pdu_size;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *src;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * create DevDereg Message with all of target nodes
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu_size = isnst_create_pdu_header(ISNS_DEV_DEREG, pdu, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (pdu_size == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Source attribute - Must be a storage node in the same
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * network entity.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (svr->svr_registered) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States src = isnst_get_registered_source(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else if (itarget != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States src = itarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto dereg_pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strlen(src->target_info->ti_tgt_name) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len, src->target_info->ti_tgt_name, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto dereg_pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Delimiter */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_DELIMITER_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap 0, 0, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto dereg_pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Operating attributes
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget == NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* dereg everything */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len = strlen(isns_eid) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_EID_ATTR_ID,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap len, isns_eid, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto dereg_pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* dereg one target only */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strlen(itarget->target_info->ti_tgt_name) + 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (isnst_add_attr(*pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len, itarget->target_info->ti_tgt_name, 0) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto dereg_pdu_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapdereg_pdu_error:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(*pdu, pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic size_t
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_make_keepalive_pdu(iscsit_isns_svr_t *svr, isns_pdu_t **pdu)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States size_t pdu_size;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *src;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_registered);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * create DevAttrQuery Message
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States pdu_size = isnst_create_pdu_header(ISNS_DEV_ATTR_QRY, pdu, 0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (pdu_size == 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Source attribute - Must be a iscsi target in the same
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * network entity.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States src = isnst_get_registered_source(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strlen(src->target_info->ti_tgt_name) + 1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(*pdu, pdu_size, ISNS_ISCSI_NAME_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len, src->target_info->ti_tgt_name, 0) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto keepalive_pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* EID */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len = strlen(isns_eid) + 1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(*pdu, pdu_size, ISNS_EID_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States len, isns_eid, 0) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto keepalive_pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Delimiter */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(*pdu, pdu_size, ISNS_DELIMITER_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States 0, 0, 0) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto keepalive_pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Values to Fetch -- EID */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_add_attr(*pdu, pdu_size, ISNS_EID_ATTR_ID,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States 0, 0, 0) != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto keepalive_pdu_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Stateskeepalive_pdu_error:
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(*pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *pdu = NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_get_registered_source(iscsit_isns_svr_t *svr)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * If svr is registered, then there must be at least one
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * target that is registered to that svr.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_monitor_hold);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States itarget = isnst_get_registered_source_locked(svr);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States return (itarget);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States}
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_target_t *
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_get_registered_source_locked(iscsit_isns_svr_t *svr)
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States{
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_registered);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT((avl_numnodes(&svr->svr_target_list) != 0));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States do {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget->target_registered == B_TRUE)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = AVL_NEXT(&svr->svr_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } while (itarget != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(itarget != NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_verify_rsp(iscsit_isns_svr_t *svr, isns_pdu_t *pdu,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_pdu_t *rsp, size_t rsp_size)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t func_id;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States int payload_len, rsp_payload_len;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States int status;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_resp_t *resp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *pp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_tlv_t *attr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_len, attr_id, esi_interval;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Ensure we have at least a valid header (don't count the
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * "payload" field.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (rsp_size < offsetof(isns_pdu_t, payload)) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "Invalid iSNS PDU header, %d of %d bytes",
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (int)rsp_size, (int)offsetof(isns_pdu_t, payload));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (-1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Make sure we have the amount of data that the header specifies */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap payload_len = ntohs(rsp->payload_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (rsp_size < (payload_len + offsetof(isns_pdu_t, payload))) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "Invalid iSNS response, %d of %d bytes",
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (int)rsp_size,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (int)(payload_len + offsetof(isns_pdu_t, payload)));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (-1);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Find the start of all operational parameters */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States rsp_payload_len = isnst_pdu_get_op(rsp, &pp);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * Make sure isnst_pdu_get_op didn't encounter an error
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * in the attributes.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (pp == NULL) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* verify response transaction id */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (ntohs(rsp->xid) != ntohs(pdu->xid)) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* check the error code */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States resp = (isns_resp_t *)((void *)&rsp->payload[0]);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States status = ntohl(resp->status);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* validate response function id */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap func_id = ntohs(rsp->func_id);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap switch (ntohs(pdu->func_id)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_DEV_ATTR_REG:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (func_id != ISNS_DEV_ATTR_REG_RSP) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Only look through response if msg status says OK */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (status != 0) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Get the ESI interval returned by the server. It could
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * be different than what we asked for. We never know which
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * portal a request may come in on, and any server could demand
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * any interval. We'll simply keep track of the largest
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * interval for use in monitoring.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr = (isns_tlv_t *)((void *)pp);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States while (rsp_payload_len >= 8) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_len = ntohl(attr->attr_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_id = ntohl(attr->attr_id);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (attr_id == ISNS_ESI_INTERVAL_ATTR_ID) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (attr_len != 4 ||
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr_len > rsp_payload_len - 8) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Mal-formed packet */
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap esi_interval =
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ntohl(*((uint32_t *)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ((void *)(&attr->attr_value))));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_monitor_hold);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (esi_interval > svr->svr_esi_interval)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap svr->svr_esi_interval = esi_interval;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp_payload_len -= (8 + attr_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr = (isns_tlv_t *)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ((void *)((uint8_t *)attr + attr_len + 8));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_DEV_DEREG:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (func_id != ISNS_DEV_DEREG_RSP) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States case ISNS_DEV_ATTR_QRY:
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Keepalive Response */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (func_id != ISNS_DEV_ATTR_QRY_RSP) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (status == 0) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States boolean_t found_eid = B_FALSE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* Scan the operational parameters */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr = (isns_tlv_t *)((void *)pp);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States while (rsp_payload_len >= 8) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr_len = ntohl(attr->attr_len);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr_id = ntohl(attr->attr_id);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (attr_id == ISNS_EID_ATTR_ID &&
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr_len > 0 &&
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr_len <= rsp_payload_len - 8) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * If the isns server knows us, the
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * response will include our EID in
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * the operational parameters, i.e.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * after the delimiter.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * Just receiving this pattern
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * is good enough to tell the isns
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * server still knows us.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States found_eid = B_TRUE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States rsp_payload_len -= (8 + attr_len);
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States attr = (isns_tlv_t *)
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ((void *)((uint8_t *)attr + attr_len + 8));
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (! found_eid) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States status = ISNS_RSP_NO_SUCH_ENTRY;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (status == ISNS_RSP_NO_SUCH_ENTRY) {
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States char server_buf[IDM_SA_NTOP_BUFSIZ];
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /*
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * The iSNS server has forgotten about us.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * We will re-register everything.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * This can happen e.g. if ESI probes time out,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States * or if the iSNS server does a factory reset.
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_WARN, "iscsit: iSNS server %s"
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States " forgot about us and has to be reminded.",
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_sa_ntop(&svr->svr_sa,
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States server_buf, sizeof (server_buf)));
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* isnst_retry_registration will trigger the reset */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States }
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States break;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap default:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Update the last time we heard from this server */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States if (status == 0) {
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_LOCK();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(svr->svr_monitor_hold);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_last_msg = ddi_get_lbolt();
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States return (status);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic uint16_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_pdu_get_op(isns_pdu_t *pdu, uint8_t **pp)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_resp_t *resp;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_tlv_t *attr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_id;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t tlv_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* get payload */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = ntohs(pdu->payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap resp = (isns_resp_t *)((void *)&pdu->payload[0]);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* find the operating attributes */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (payload_len < sizeof (resp->status)) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "Invalid iSNS response, %d payload bytes",
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap payload_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap *pp = NULL;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return (0);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap payload_len -= sizeof (resp->status);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload = &resp->data[0];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap while (payload_len >= (sizeof (isns_tlv_t) - 1)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr = (isns_tlv_t *)((void *)payload);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap tlv_len = offsetof(isns_tlv_t, attr_value) +
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ntohl(attr->attr_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (payload_len >= tlv_len) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload += tlv_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len -= tlv_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_id = ntohl(attr->attr_id);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (attr_id == ISNS_DELIMITER_ATTR_ID) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* mal-formed packet */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pp = payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_create_pdu_header(uint16_t func_id, isns_pdu_t **pdu, uint16_t flags)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States size_t pdu_size = isns_message_buf_size;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = (isns_pdu_t *)kmem_zalloc(pdu_size, KM_NOSLEEP);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (*pdu != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->version = htons((uint16_t)ISNSP_VERSION);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->func_id = htons((uint16_t)func_id);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->payload_len = htons(0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->flags = htons(flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->xid = htons(GET_XID());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->seq = htons(0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu_size = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_add_attr(isns_pdu_t *pdu,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t max_pdu_size,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_id,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_len,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap void *attr_data,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t attr_numeric_data)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_tlv_t *attr_tlv;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *payload_ptr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint32_t normalized_attr_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint64_t attr_tlv_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* The attribute length must be 4-byte aligned. Section 5.1.3. */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap normalized_attr_len = (attr_len % 4) == 0 ?
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (attr_len) : (attr_len + (4 - (attr_len % 4)));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv_len = ISNS_TLV_ATTR_ID_LEN +
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ISNS_TLV_ATTR_LEN_LEN + normalized_attr_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Check if we are going to exceed the maximum PDU length. */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = ntohs(pdu->payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if ((payload_len + attr_tlv_len) > max_pdu_size) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv = (isns_tlv_t *)kmem_zalloc(attr_tlv_len, KM_SLEEP);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv->attr_id = htonl(attr_id);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap switch (attr_id) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_DELIMITER_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_PORTAL_IP_ADDR_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_PG_PORTAL_IP_ADDR_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (attr_numeric_data == sizeof (in_addr_t)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* IPv4 */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv->attr_value[10] = 0xFF;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv->attr_value[11] = 0xFF;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(attr_data, ((attr_tlv->attr_value) + 12),
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (in_addr_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (attr_numeric_data == sizeof (in6_addr_t)) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* IPv6 */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(attr_data, attr_tlv->attr_value,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sizeof (in6_addr_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (attr_numeric_data == 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* EMPTY */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Do nothing */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(attr_tlv, attr_tlv_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_EID_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_ISCSI_NAME_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_ISCSI_ALIAS_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap case ISNS_PG_ISCSI_NAME_ATTR_ID:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (attr_len && attr_data) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy((char *)attr_data,
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv->attr_value, attr_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap default:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (attr_len == 8) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *(uint64_t *)((void *)attr_tlv->attr_value) =
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap BE_64((uint64_t)attr_numeric_data);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (attr_len == 4) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *(uint32_t *)((void *)attr_tlv->attr_value) =
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap htonl((uint32_t)attr_numeric_data);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap break;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv->attr_len = htonl(normalized_attr_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Convert the network byte ordered payload length to host byte
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ordered for local address calculation.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = ntohs(pdu->payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_ptr = pdu->payload + payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(attr_tlv, payload_ptr, attr_tlv_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len += attr_tlv_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Convert the host byte ordered payload length back to network
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * byte ordered - it's now ready to be sent on the wire.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu->payload_len = htons(payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(attr_tlv, attr_tlv_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap attr_tlv = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapstatic void
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlapisnst_so_timeout(void *so)
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap{
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap /* Wake up any sosend or sorecv blocked on this socket */
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap idm_soshutdown(so);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap}
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_send_pdu(void *so, isns_pdu_t *pdu)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t total_len, payload_len, send_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t flags, seq;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap timeout_id_t send_timer;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iovec_t iov[2];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int rc;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(! ISNS_GLOBAL_LOCK_HELD());
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* update pdu flags */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags = ntohs(pdu->flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags |= ISNS_FLAG_CLIENT;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags |= ISNS_FLAG_FIRST_PDU;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* initalize sequence number */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap seq = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload = pdu->payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* total payload length */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_len = ntohs(pdu->payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* fill in the pdu header */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iov[0].iov_base = (void *)pdu;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iov[0].iov_len = ISNSP_HEADER_SIZE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap do {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* split the payload accordingly */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (total_len > ISNSP_MAX_PAYLOAD_SIZE) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = ISNSP_MAX_PAYLOAD_SIZE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = total_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* set the last pdu flag */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags |= ISNS_FLAG_LAST_PDU;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* set back the pdu flags */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu->flags = htons(flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* set the sequence number */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu->seq = htons(seq);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* set the payload length */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu->payload_len = htons(payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* fill in the payload */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iov[1].iov_base = (void *)payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap iov[1].iov_len = payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap DTRACE_PROBE3(isnst__pdu__send, uint16_t, ntohs(pdu->func_id),
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t, ntohs(pdu->payload_len), caddr_t, pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* send the pdu */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap send_len = ISNSP_HEADER_SIZE + payload_len;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap send_timer = timeout(isnst_so_timeout, so,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States drv_usectohz(isns_timeout_usec));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rc = idm_iov_sosend(so, &iov[0], 2, send_len);
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap (void) untimeout(send_timer);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags &= ~ISNS_FLAG_FIRST_PDU;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload += payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_len -= payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* increase the sequence number */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap seq ++;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } while (rc == 0 && total_len > 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (rc);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic size_t
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_rcv_pdu(void *so, isns_pdu_t **pdu)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t total_pdu_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t total_payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t combined_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_pdu_t tmp_pdu_hdr;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_pdu_t *combined_pdu;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *payload;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint8_t *combined_payload;
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap timeout_id_t rcv_timer;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t flags;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap uint16_t seq;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(! ISNS_GLOBAL_LOCK_HELD());
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_pdu_len = total_payload_len = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap seq = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap do {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* receive the pdu header */
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap rcv_timer = timeout(isnst_so_timeout, so,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States drv_usectohz(isns_timeout_usec));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (idm_sorecv(so, &tmp_pdu_hdr, ISNSP_HEADER_SIZE) != 0 ||
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ntohs(tmp_pdu_hdr.seq) != seq) {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap (void) untimeout(rcv_timer);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto rcv_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap (void) untimeout(rcv_timer);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* receive the payload */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload_len = ntohs(tmp_pdu_hdr.payload_len);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (payload_len > ISNST_MAX_MSG_SIZE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto rcv_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States payload = kmem_alloc(payload_len, KM_NOSLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (payload == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto rcv_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap rcv_timer = timeout(isnst_so_timeout, so,
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap drv_usectohz(ISNS_RCV_TIMER_SECONDS * 1000000));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (idm_sorecv(so, payload, payload_len) != 0) {
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap (void) untimeout(rcv_timer);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap goto rcv_error;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bf604c6405d5cbc4e94e3d0ecc9e6e074ed4ea67Peter Dunlap (void) untimeout(rcv_timer);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* combine the pdu if it is not the first one */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (total_pdu_len > 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap combined_len = total_pdu_len + payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap combined_pdu = kmem_alloc(combined_len, KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (combined_pdu == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto rcv_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(*pdu, combined_pdu, total_pdu_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap combined_payload =
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap &combined_pdu->payload[total_payload_len];
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(payload, combined_payload, payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(*pdu, total_pdu_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(payload, payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = combined_pdu;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_payload_len += payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_pdu_len += payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap (*pdu)->payload_len = htons(total_payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_payload_len = payload_len;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap total_pdu_len = ISNSP_HEADER_SIZE + payload_len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States *pdu = kmem_alloc(total_pdu_len, KM_NOSLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (*pdu == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States goto rcv_error;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(&tmp_pdu_hdr, *pdu, ISNSP_HEADER_SIZE);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bcopy(payload, &(*pdu)->payload[0], payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(payload, payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap payload = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* the flags of pdu which is just received */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap flags = ntohs(tmp_pdu_hdr.flags);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* increase sequence number by one */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap seq ++;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } while ((flags & ISNS_FLAG_LAST_PDU) == 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap DTRACE_PROBE3(isnst__pdu__recv, uint16_t, ntohs((*pdu)->func_id),
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t, total_payload_len, caddr_t, *pdu);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (total_pdu_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlaprcv_error:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (*pdu != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(*pdu, total_pdu_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *pdu = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (payload != NULL) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(payload, payload_len);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_open_so(struct sockaddr_storage *sa)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int sa_sz;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_t so;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(! ISNS_GLOBAL_LOCK_HELD());
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States /* determine local IP address */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (sa->ss_family == AF_INET) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* IPv4 */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sa_sz = sizeof (struct sockaddr_in);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Create socket */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap so = idm_socreate(AF_INET, SOCK_STREAM, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* IPv6 */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sa_sz = sizeof (struct sockaddr_in6);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Create socket */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap so = idm_socreate(AF_INET6, SOCK_STREAM, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (so != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (idm_so_timed_socket_connect(so, sa, sa_sz,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_timeout_usec) != 0) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* not calling isnst_close_so() to */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* make dtrace output look clear */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_soshutdown(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_sodestroy(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap so = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (so == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States char server_buf[IDM_SA_NTOP_BUFSIZ];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_WARN, "open iSNS Server %s failed",
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sa_ntop(sa, server_buf,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (server_buf)));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States DTRACE_PROBE1(isnst__connect__fail,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_storage *, sa);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_close_so(void *so)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_soshutdown(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_sodestroy(so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * ESI handling
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_esi_start(void)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_use_esi == B_FALSE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_NOTE, "ESI disabled by isns_use_esi=FALSE");
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "isnst_esi_start");
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(esi.esi_enabled == B_FALSE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(esi.esi_thread_running == B_FALSE);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_enabled = B_TRUE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_valid = B_FALSE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_thread = thread_create(NULL, 0, isnst_esi_thread,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (void *)&esi, 0, &p0, TS_RUN, minclsyspri);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Wait for the thread to start
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap while (!esi.esi_thread_running) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_wait(&esi.esi_cv, &esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_esi_stop()
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States boolean_t need_offline = B_FALSE;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_NOTE, "isnst_esi_stop");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Shutdown ESI listening socket, wait for thread to terminate */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (esi.esi_enabled) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States esi.esi_enabled = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (esi.esi_valid) {
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States need_offline = B_TRUE;
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States }
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&esi.esi_mutex);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States if (need_offline) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_soshutdown(esi.esi_so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sodestroy(esi.esi_so);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States thread_join(esi.esi_thread_did);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * isnst_esi_thread
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap *
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * This function listens on a socket for incoming connections from an
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * iSNS server until told to stop.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap/*ARGSUSED*/
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_esi_thread(void *arg)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ksocket_t newso;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap struct sockaddr_in6 sin6;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap socklen_t sin_addrlen;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t on = 1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap int rc;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap isns_pdu_t *pdu;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap size_t pl_size;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap bzero(&sin6, sizeof (struct sockaddr_in6));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap sin_addrlen = sizeof (struct sockaddr_in6);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_thread_did = curthread->t_did;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Mark the thread as running and the portal as no longer new.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_thread_running = B_TRUE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_signal(&esi.esi_cv);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap while (esi.esi_enabled) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Create a socket to listen for requests from the iSNS server.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if ((esi.esi_so = idm_socreate(PF_INET6, SOCK_STREAM, 0)) ==
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap NULL) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "isnst_esi_thread: Unable to create socket");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap delay(drv_usectohz(1000000));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap continue;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Set options, bind, and listen until we're told to stop
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap bzero(&sin6, sizeof (sin6));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sin6.sin6_family = AF_INET6;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap sin6.sin6_port = htons(0);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap sin6.sin6_addr = in6addr_any;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (void) ksocket_setsockopt(esi.esi_so, SOL_SOCKET,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning SO_REUSEADDR, (char *)&on, sizeof (on), CRED());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (ksocket_bind(esi.esi_so, (struct sockaddr *)&sin6,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sizeof (sin6), CRED()) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "Unable to bind socket for ESI");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap idm_sodestroy(esi.esi_so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap delay(drv_usectohz(1000000));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap continue;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Get the port (sin6 is meaningless at this point)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (void) ksocket_getsockname(esi.esi_so,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (struct sockaddr *)(&sin6), &sin_addrlen, CRED());
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_port =
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ntohs(((struct sockaddr_in6 *)(&sin6))->sin6_port);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if ((rc = ksocket_listen(esi.esi_so, 5, CRED())) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_esi_thread: listen "
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "failure 0x%x", rc);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap idm_sodestroy(esi.esi_so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap delay(drv_usectohz(1000000));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap continue;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ksocket_hold(esi.esi_so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_valid = B_TRUE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap while (esi.esi_enabled) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States DTRACE_PROBE3(iscsit__isns__esi__accept__wait,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States boolean_t, esi.esi_enabled,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ksocket_t, esi.esi_so,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_in6, &sin6);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if ((rc = ksocket_accept(esi.esi_so, NULL, NULL,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap &newso, CRED())) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap DTRACE_PROBE2(iscsit__isns__esi__accept__fail,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap int, rc, boolean_t, esi.esi_enabled);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * If we were interrupted with EINTR
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * it's not really a failure.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_esi_thread: "
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap "accept failure (0x%x)", rc);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (rc == EINTR) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap continue;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap DTRACE_PROBE2(iscsit__isns__esi__accept,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap boolean_t, esi.esi_enabled,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ksocket_t, newso);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap pl_size = isnst_rcv_pdu(newso, &pdu);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (pl_size == 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_esi_thread: "
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "rcv_pdu failure");
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_soshutdown(newso);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_sodestroy(newso);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap continue;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isnst_handle_esi_req(newso, pdu, pl_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_soshutdown(newso);
fada64958a3fe766ddcadb4de18610ae9c3e4c93Peter Cudhea - Sun Microsystems - Burlington, MA United States idm_sodestroy(newso);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_enter(&esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap idm_soshutdown(esi.esi_so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ksocket_rele(esi.esi_so);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_valid = B_FALSE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * If we're going to try to re-establish the listener then
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * destroy this socket. Otherwise isnst_esi_stop already
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * destroyed it.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (esi.esi_enabled)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap idm_sodestroy(esi.esi_so);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi.esi_thread_running = B_FALSE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap cv_signal(&esi.esi_cv);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap mutex_exit(&esi.esi_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapesi_thread_exit:
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap thread_exit();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Handle an incoming ESI request
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapstatic void
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlapisnst_handle_esi_req(ksocket_t ks, isns_pdu_t *pdu, size_t pdu_size)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_pdu_t *rsp_pdu;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_resp_t *rsp;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap isns_tlv_t *attr;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t attr_len, attr_id;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap size_t req_pl_len, rsp_size, tlv_len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_storage portal_ss;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_storage server_ss;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap struct sockaddr_in6 *portal_addr6;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap boolean_t portal_addr_valid = B_FALSE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap boolean_t portal_port_valid = B_FALSE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap uint32_t esi_response = ISNS_RSP_SUCCESSFUL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States socklen_t sa_len;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (ntohs(pdu->func_id) != ISNS_ESI) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_handle_esi_req: Unexpected func 0x%x",
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap pdu->func_id);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap req_pl_len = ntohs(pdu->payload_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (req_pl_len + offsetof(isns_pdu_t, payload) > pdu_size) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_handle_esi_req: "
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "payload exceeds PDU size (%d > %d)",
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (int)(req_pl_len + offsetof(isns_pdu_t, payload)),
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap (int)pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Not all data is present -- ignore */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (req_pl_len + sizeof (uint32_t) > ISNSP_MAX_PAYLOAD_SIZE) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "isnst_handle_esi_req: PDU payload exceeds max (%ld bytes)",
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap req_pl_len + sizeof (uint32_t));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Check portal in ESI request and make sure it is valid. Return
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * esi_response of ISNS_RSP_SUCCESSFUL if valid, otherwise don't
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * respond at all. Get IP addr and port. Format of ESI
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * is:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap *
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * ISNS_TIMESTAMP_ATTR_ID,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * ISNS_EID_ATTR_ID,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * ISNS_PORTAL_IP_ADDR_ATTR_ID,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * ISNS_PORTAL_PORT_ATTR_ID
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bzero(&portal_ss, sizeof (struct sockaddr_storage));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States portal_ss.ss_family = AF_INET6;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States portal_addr6 = (struct sockaddr_in6 *)&portal_ss;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr = (isns_tlv_t *)((void *)&pdu->payload);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_len = ntohl(attr->attr_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_id = ntohl(attr->attr_id);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap tlv_len = attr_len + offsetof(isns_tlv_t, attr_value);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap while (tlv_len <= req_pl_len) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap switch (attr_id) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap case ISNS_TIMESTAMP_ATTR_ID:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap case ISNS_EID_ATTR_ID:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap case ISNS_PORTAL_IP_ADDR_ATTR_ID:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (attr_len > sizeof (struct in6_addr)) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Bad attribute format */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi_response = ISNS_RSP_MSG_FORMAT_ERROR;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_addr6->sin6_family = AF_INET6;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_len = min(attr_len,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap sizeof (portal_addr6->sin6_addr));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap bcopy(attr->attr_value,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_addr6->sin6_addr.s6_addr, attr_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_addr_valid = B_TRUE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap case ISNS_PORTAL_PORT_ATTR_ID:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (attr_len > sizeof (uint32_t)) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Bad attribute format */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi_response = ISNS_RSP_MSG_FORMAT_ERROR;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap } else {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_addr6->sin6_port =
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap htons((uint16_t)BE_IN32(attr->attr_value));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_port_valid = B_TRUE;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap default:
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Bad request format */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi_response = ISNS_RSP_MSG_FORMAT_ERROR;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* If we've set an error then stop processing */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (esi_response != ISNS_RSP_SUCCESSFUL) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap break;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Get next attribute */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap req_pl_len -= tlv_len;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr = (isns_tlv_t *)((void *)((uint8_t *)attr + tlv_len));
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_len = ntohl(attr->attr_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap attr_id = ntohl(attr->attr_id);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap tlv_len = attr_len + offsetof(isns_tlv_t, attr_value);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (!portal_port_valid)
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap portal_addr6->sin6_port = htons(ISCSI_LISTEN_PORT);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (!portal_addr_valid) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap esi_response = ISNS_RSP_MSG_FORMAT_ERROR;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * If we've detected an error or if the portal does not
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * exist then drop the request. The server will eventually
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * timeout the portal and eliminate it from the list.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (esi_response != ISNS_RSP_SUCCESSFUL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Get the remote peer's IP address */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bzero(&server_ss, sizeof (server_ss));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sa_len = sizeof (server_ss);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (ksocket_getpeername(ks, (struct sockaddr *)&server_ss, &sa_len,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States CRED())) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (iscsit_isns_logging) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States char server_buf[IDM_SA_NTOP_BUFSIZ];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States char portal_buf[IDM_SA_NTOP_BUFSIZ];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_NOTE, "ESI: svr %s -> portal %s",
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sa_ntop(&server_ss, server_buf,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (server_buf)),
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_sa_ntop(&portal_ss, portal_buf,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States sizeof (portal_buf)));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNS_GLOBAL_LOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isnst_lookup_portal(&portal_ss) == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_WARN, "ESI req to non-active portal");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNS_GLOBAL_UNLOCK();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Update the server timestamp of how recently we have
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * received an ESI request from this iSNS server.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * We ignore requests from servers we don't know.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (! isnst_update_server_timestamp(&server_ss)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNST_LOG(CE_WARN, "ESI req from unknown server");
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(pdu, pdu_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ISNS_GLOBAL_UNLOCK();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Update ESI timestamps for all portals with same IP address.
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (iportal = avl_first(&isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal != NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = AVL_NEXT(&isns_all_portals, iportal)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (idm_ss_compare(&iportal->portal_addr, &portal_ss,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_TRUE, B_FALSE)) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States gethrestime(&iportal->portal_esi_timestamp);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNS_GLOBAL_UNLOCK();
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap * Build response validating the portal
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp_size = isnst_create_pdu_header(ISNS_ESI_RSP, &rsp_pdu, 0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (rsp_size == 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN, "isnst_handle_esi_req: Can't get rsp pdu");
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap return;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp = (isns_resp_t *)((void *)(&rsp_pdu->payload[0]));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Use xid from the request pdu */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp_pdu->xid = pdu->xid;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap rsp->status = htonl(ISNS_RSP_SUCCESSFUL);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /* Copy original data */
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap req_pl_len = ntohs(pdu->payload_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap bcopy(pdu->payload, rsp->data, req_pl_len);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap rsp_pdu->payload_len = htons(req_pl_len + sizeof (uint32_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (isnst_send_pdu(ks, rsp_pdu) != 0) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap ISNST_LOG(CE_WARN,
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap "isnst_handle_esi_req: Send response failed");
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap kmem_free(rsp_pdu, rsp_size);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap kmem_free(pdu, pdu_size);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapisnst_tgt_avl_compare(const void *t1, const void *t2)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap const isns_target_t *tgt1 = t1;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap const isns_target_t *tgt2 = t2;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * Sort by target (pointer to iscsit_tgt_t).
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap if (tgt1->target < tgt2->target) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (-1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap } else if (tgt1->target > tgt2->target) {
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (1);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap return (0);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_set_server_status(iscsit_isns_svr_t *svr, boolean_t registered)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *itarget;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_reset_needed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (registered == B_TRUE) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_registered = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_last_msg = ddi_get_lbolt();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = avl_first(&svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (itarget) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_target_t *next_target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States next_target = AVL_NEXT(&svr->svr_target_list, itarget);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (itarget->target_delete_needed) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* All deleted tgts removed */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_from_target_list(itarget,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &svr->svr_target_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Other tgts marked registered */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_registered = B_TRUE;
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States /* No updates needed -- clean slate */
ebf418d7ab5c89ce3e7fb31d6a454171f5f7f518Peter Cudhea - Sun Microsystems - Burlington, MA United States itarget->target_update_needed = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States itarget = next_target;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(avl_numnodes(&svr->svr_target_list) > 0);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States svr->svr_registered = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_target_list(svr);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_monitor_default_portal_list(void)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_addr_list_t *new_portal_list = NULL;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States uint32_t new_portal_list_size = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(mutex_owned(&iscsit_isns_mutex));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (default_portal_online) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States new_portal_list_size = idm_get_ipaddr(&new_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * We compute a new list of portals if
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * a) Something in itadm has changed a portal
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * b) there are new default portals
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * c) the default portal has gone offline
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (isns_portals_changed ||
2fcb892236b17e4db60b2044ec5431cad16b9b8ePeter Cudhea - Sun Microsystems - Burlington, MA United States ((new_portal_list_size != 0) &&
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States (isnst_find_default_portals(new_portal_list) !=
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_default_portals)) ||
2fcb892236b17e4db60b2044ec5431cad16b9b8ePeter Cudhea - Sun Microsystems - Burlington, MA United States ((new_portal_list_size == 0) && (num_default_portals > 0))) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_default_portals();
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_copy_portal_list(&isns_tpg_portals,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_tpg_portals = avl_numnodes(&isns_all_portals);
2fcb892236b17e4db60b2044ec5431cad16b9b8ePeter Cudhea - Sun Microsystems - Burlington, MA United States if (new_portal_list_size != 0) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_default_portals =
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_add_default_portals(new_portal_list);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Catch any case where we miss an update to TPG portals */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(num_tpg_portals == avl_numnodes(&isns_tpg_portals));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (new_portal_list != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(new_portal_list, new_portal_list_size);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_find_default_portals(idm_addr_list_t *alist)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_addr_t *dportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_storage sa;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int aidx;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int num_portals_found = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (aidx = 0; aidx < alist->al_out_cnt; aidx++) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States dportal = &alist->al_addrs[aidx];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States dportal->a_port = ISCSI_LISTEN_PORT;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_addr_to_sa(dportal, &sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = isnst_lookup_portal(&sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (iportal == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States /* Found a non-matching default portal */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (-1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if (iportal->portal_default) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_portals_found++;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (num_portals_found);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_default_portals(void)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap ASSERT(ISNS_GLOBAL_LOCK_HELD());
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_clear_portal_list(&isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_tpg_portals = 0;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States num_default_portals = 0;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_default_portals(idm_addr_list_t *alist)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap idm_addr_t *dportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States struct sockaddr_storage sa;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States int aidx;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States for (aidx = 0; aidx < alist->al_out_cnt; aidx++) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States dportal = &alist->al_addrs[aidx];
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States dportal->a_port = ISCSI_LISTEN_PORT;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States idm_addr_to_sa(dportal, &sa);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = isnst_add_to_portal_list(&sa, &isns_all_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal->portal_default = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (alist->al_out_cnt);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic int
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_portal_avl_compare(const void *p1, const void *p2)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States const isns_portal_t *portal1 = p1;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States const isns_portal_t *portal2 = p2;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (idm_ss_compare(&portal1->portal_addr, &portal2->portal_addr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States B_TRUE /* v4_mapped_as_v4 */, B_TRUE /* compare_ports */));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_clear_portal_list(avl_tree_t *portal_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States void *cookie = NULL;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while ((iportal = avl_destroy_nodes(portal_list, &cookie)) != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(iportal, sizeof (isns_portal_t));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_copy_portal_list(avl_tree_t *t1, avl_tree_t *t2)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal, *jportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = (isns_portal_t *)avl_first(t1);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States while (iportal) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jportal = isnst_add_to_portal_list(&iportal->portal_addr, t2);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States jportal->portal_iscsit = iportal->portal_iscsit;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = AVL_NEXT(t1, iportal);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_portal_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_lookup_portal(struct sockaddr_storage *sa)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal, tmp_portal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(ISNS_GLOBAL_LOCK_HELD());
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(sa, &tmp_portal.portal_addr, sizeof (*sa));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = avl_find(&isns_all_portals, &tmp_portal, NULL);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (iportal);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic isns_portal_t *
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_add_to_portal_list(struct sockaddr_storage *sa, avl_tree_t *portal_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal, tmp_portal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_index_t where;
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /*
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States * Make sure this portal isn't already in our list.
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(sa, &tmp_portal.portal_addr, sizeof (*sa));
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((iportal = (isns_portal_t *)avl_find(portal_list,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &tmp_portal, &where)) == NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = kmem_zalloc(sizeof (isns_portal_t), KM_SLEEP);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(sa, &iportal->portal_addr, sizeof (*sa));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_insert(portal_list, (void *)iportal, where);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States return (iportal);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States}
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesstatic void
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United Statesisnst_remove_from_portal_list(struct sockaddr_storage *sa,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_tree_t *portal_list)
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal, tmp_portal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States bcopy(sa, &tmp_portal.portal_addr, sizeof (*sa));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States if ((iportal = avl_find(portal_list, &tmp_portal, NULL))
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States != NULL) {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States avl_remove(portal_list, iportal);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States kmem_free(iportal, sizeof (isns_portal_t));
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States }
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap/*
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * These functions are called by iscsit proper when a portal comes online
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap * or goes offline.
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap */
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapvoid
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_portal_online(iscsit_portal_t *portal)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portal_t *iportal;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (portal->portal_default) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Portals should only be onlined once */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(default_portal_online == B_FALSE);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap default_portal_online = B_TRUE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal = isnst_add_to_portal_list(
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &portal->portal_addr, &isns_tpg_portals);
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States iportal->portal_iscsit = portal;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portals_changed = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapvoid
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlapiscsit_isns_portal_offline(iscsit_portal_t *portal)
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap{
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_enter(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap if (portal->portal_default) {
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap /* Portals should only be offlined once */
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States ASSERT(default_portal_online == B_TRUE);
e42a0851889d583925aa3bd2d9bd139189031cb0peter dunlap default_portal_online = B_FALSE;
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States } else {
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_remove_from_portal_list(&portal->portal_addr,
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States &isns_tpg_portals);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap }
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isns_portals_changed = B_TRUE;
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States mutex_exit(&iscsit_isns_mutex);
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap
bdbe8dc662f9700c12eafcbcceb5c724615278cfPeter Cudhea - Sun Microsystems - Burlington, MA United States isnst_monitor_awaken();
a6d42e7d71324c5193c3b94d57d96ba2925d52e1Peter Dunlap}